No functional changes made in this commit.
Removed CheckStyle and Sonar warnings.
Formatted code.
Renamed methods and classes for better understanding.
Removed unnecessary classes.
Moved all code to single project.
Change-Id: Ie3feb6c6a985e94a382812aa083dcf57bc46c7b3
Issue-ID: DCAEGEN2-1367
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
"ftpesConfiguration": {
"keyCert": "config/dfc.jks",
"keyPassword": "secret",
- "trustedCA": "config/ftp.jks",
- "trustedCAPassword": "secret"
+ "trustedCa": "config/ftp.jks",
+ "trustedCaPassword": "secret"
}
},
"security": {
application_config:
dmaap.ftp.ftpesConfiguration.keyCert: "/config/dfc.jks"
dmaap.ftp.ftpesConfiguration.keyPassword: "secret"
- dmaap.ftp.ftpesConfiguration.trustedCA: "/config/ftp.jks"
- dmaap.ftp.ftpesConfiguration.trustedCAPassword: "secret"
+ dmaap.ftp.ftpesConfiguration.trustedCa: "/config/ftp.jks"
+ dmaap.ftp.ftpesConfiguration.trustedCaPassword: "secret"
dmaap.security.trustStorePath: "/opt/app/datafile/etc/cert/trust.jks"
dmaap.security.trustStorePasswordPath: "/opt/app/datafile/etc/cert/trust.pass"
dmaap.security.keyStorePath: "/opt/app/datafile/etc/cert/key.p12"
"required": true
},
{
- "name": "ftp.ftpesConfiguration.trustedCA",
+ "name": "ftp.ftpesConfiguration.trustedCa",
"value": "config/ftp.jks",
"description": "",
"designer_editable": true,
"required": true
},
{
- "name": "ftp.ftpesConfiguration.trustedCAPassword",
+ "name": "ftp.ftpesConfiguration.trustedCaPassword",
"value": "secret",
"description": "",
"designer_editable": true,
type: string
ftp.ftpesConfiguration.keyPassword:
type: string
- ftp.ftpesConfiguration.trustedCA:
+ ftp.ftpesConfiguration.trustedCa:
type: string
- ftp.ftpesConfiguration.trustedCAPassword:
+ ftp.ftpesConfiguration.trustedCaPassword:
type: string
security.enableDmaapCertAuth:
type: string
datafile.policy: ''
ftp.ftpesConfiguration.keyCert: config/dfc.jks
ftp.ftpesConfiguration.keyPassword: secret
- ftp.ftpesConfiguration.trustedCA: config/ftp.jks
- ftp.ftpesConfiguration.trustedCAPassword: secret
+ ftp.ftpesConfiguration.trustedCa: config/ftp.jks
+ ftp.ftpesConfiguration.trustedCaPassword: secret
location_id:
get_property:
- SELF
type: string
ftp.ftpesConfiguration.keyPassword:
type: string
- ftp.ftpesConfiguration.trustedCA:
+ ftp.ftpesConfiguration.trustedCa:
type: string
- ftp.ftpesConfiguration.trustedCAPassword:
+ ftp.ftpesConfiguration.trustedCaPassword:
type: string
image:
type: string
get_input: ftp.ftpesConfiguration.keyCert
ftp.ftpesConfiguration.keyPassword:
get_input: ftp.ftpesConfiguration.keyPassword
- ftp.ftpesConfiguration.trustedCA:
- get_input: ftp.ftpesConfiguration.trustedCA
- ftp.ftpesConfiguration.trustedCAPassword:
- get_input: ftp.ftpesConfiguration.trustedCAPassword
+ ftp.ftpesConfiguration.trustedCa:
+ get_input: ftp.ftpesConfiguration.trustedCa
+ ftp.ftpesConfiguration.trustedCaPassword:
+ get_input: ftp.ftpesConfiguration.trustedCaPassword
security.enableDmaapCertAuth:
get_input: security.enableDmaapCertAuth
security.keyStorePasswordPath:
<groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
<artifactId>cbs-client</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpasyncclient</artifactId>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
- <groupId>org.onap.dcaegen2.collectors.datafile</groupId>
- <artifactId>datafile-dmaap-client</artifactId>
- <version>${project.parent.version}</version>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jsch</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
</dependency>
<!--TESTS DEPENDENCIES -->
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
+ <dependency>
+ <groupId>com.github.stefanbirkner</groupId>
+ <artifactId>fake-sftp-server-rule</artifactId>
+ <scope>test</scope>
+ </dependency>
<!--REQUIRED TO GENERATE DOCUMENTATION -->
<dependency>
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
* ===============================================================================================
import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler;
/**
+ * The main app of DFC.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
-@SpringBootApplication(exclude = {JacksonAutoConfiguration.class})
+@SpringBootApplication(exclude = { JacksonAutoConfiguration.class })
@EnableScheduling
public class MainApp {
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapterFactory;
-
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ServiceLoader;
-
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
-
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
import org.slf4j.Logger;
-/*
+/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
* ================================================================================
/**
+ * Parses the cloud configuration.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 9/19/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
public class CloudConfigParser {
+ private static final String DMAAP_SECURITY_TRUST_STORE_PATH = "dmaap.security.trustStorePath";
+ private static final String DMAAP_SECURITY_TRUST_STORE_PASS_PATH = "dmaap.security.trustStorePasswordPath";
+ private static final String DMAAP_SECURITY_KEY_STORE_PATH = "dmaap.security.keyStorePath";
+ private static final String DMAAP_SECURITY_KEY_STORE_PASS_PATH = "dmaap.security.keyStorePasswordPath";
+ private static final String DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH = "dmaap.security.enableDmaapCertAuth";
+
private final JsonObject jsonObject;
CloudConfigParser(JsonObject jsonObject) {
.dmaapContentType(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapContentType").getAsString())
.dmaapHostName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapHostName").getAsString())
.dmaapUserName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserName").getAsString())
- .trustStorePath(jsonObject.get("dmaap.security.trustStorePath").getAsString())
- .trustStorePasswordPath(jsonObject.get("dmaap.security.trustStorePasswordPath").getAsString())
- .keyStorePath(jsonObject.get("dmaap.security.keyStorePath").getAsString())
- .keyStorePasswordPath(jsonObject.get("dmaap.security.keyStorePasswordPath").getAsString())
- .enableDmaapCertAuth(jsonObject.get("dmaap.security.enableDmaapCertAuth").getAsBoolean())
+ .trustStorePath(jsonObject.get(DMAAP_SECURITY_TRUST_STORE_PATH).getAsString())
+ .trustStorePasswordPath(jsonObject.get(DMAAP_SECURITY_TRUST_STORE_PASS_PATH).getAsString())
+ .keyStorePath(jsonObject.get(DMAAP_SECURITY_KEY_STORE_PATH).getAsString())
+ .keyStorePasswordPath(jsonObject.get(DMAAP_SECURITY_KEY_STORE_PASS_PATH).getAsString())
+ .enableDmaapCertAuth(jsonObject.get(DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) //
.build();
}
.dmaapProtocol(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapProtocol").getAsString())
.consumerId(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerId").getAsString())
.consumerGroup(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerGroup").getAsString())
- .trustStorePath(jsonObject.get("dmaap.security.trustStorePath").getAsString())
- .trustStorePasswordPath(jsonObject.get("dmaap.security.trustStorePasswordPath").getAsString())
- .keyStorePath(jsonObject.get("dmaap.security.keyStorePath").getAsString())
- .keyStorePasswordPath(jsonObject.get("dmaap.security.keyStorePasswordPath").getAsString())
- .enableDmaapCertAuth(jsonObject.get("dmaap.security.enableDmaapCertAuth").getAsBoolean())
+ .trustStorePath(jsonObject.get(DMAAP_SECURITY_TRUST_STORE_PATH).getAsString())
+ .trustStorePasswordPath(jsonObject.get(DMAAP_SECURITY_TRUST_STORE_PASS_PATH).getAsString())
+ .keyStorePath(jsonObject.get(DMAAP_SECURITY_KEY_STORE_PATH).getAsString())
+ .keyStorePasswordPath(jsonObject.get(DMAAP_SECURITY_KEY_STORE_PASS_PATH).getAsString())
+ .enableDmaapCertAuth(jsonObject.get(DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) //
.build();
}
- public FtpesConfig getFtpesConfig() {
- return new ImmutableFtpesConfig.Builder()
+ FtpesConfig getFtpesConfig() {
+ return new ImmutableFtpesConfig.Builder() //
.keyCert(jsonObject.get("dmaap.ftpesConfig.keyCert").getAsString())
.keyPassword(jsonObject.get("dmaap.ftpesConfig.keyPassword").getAsString())
- .trustedCA(jsonObject.get("dmaap.ftpesConfig.trustedCA").getAsString())
- .trustedCAPassword(jsonObject.get("dmaap.ftpesConfig.trustedCAPassword").getAsString())
+ .trustedCa(jsonObject.get("dmaap.ftpesConfig.trustedCa").getAsString())
+ .trustedCaPassword(jsonObject.get("dmaap.ftpesConfig.trustedCaPassword").getAsString()) //
.build();
}
-}
\ No newline at end of file
+}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
package org.onap.dcaegen2.collectors.datafile.configuration;
import com.google.gson.JsonObject;
-
import java.util.Map;
import java.util.Properties;
-
import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.ReactiveCloudConfigurationProvider;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.annotation.EnableScheduling;
-
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
/**
+ * Gets the DFC configuration from the ConfigBindingService/Consul and parses it to the configurations needed in DFC.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 9/19/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
this.reactiveCloudConfigurationProvider = reactiveCloudConfigurationProvider;
}
+ /**
+ * Reads the cloud configuration.
+ */
public void runTask() {
Map<String,String> context = MappedDiagnosticContext.initializeTraceContext();
EnvironmentProcessor.readEnvironmentVariables(systemEnvironment, context) //
-/*
+/*-
* ============LICENSE_START========================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* =================================================================================================
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
-
import org.onap.dcaegen2.collectors.datafile.exceptions.EnvironmentLoaderException;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.EnvProperties;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.ImmutableEnvProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
-
import reactor.core.publisher.Mono;
/**
+ * Handling the Consul connection.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 9/19/18
*/
class EnvironmentProcessor {
}
private static Integer getConsultPort(Properties systemEnvironments) {
- return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_PORT")).map(Integer::valueOf)
+ return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_PORT")) //
+ .map(Integer::valueOf) //
.orElseGet(EnvironmentProcessor::getDefaultPortOfConsul);
}
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.collectors.datafile.configuration;
import java.io.Serializable;
-
import org.immutables.gson.Gson;
import org.immutables.value.Value;
import org.springframework.stereotype.Component;
public abstract String keyPassword();
@Value.Parameter
- public abstract String trustedCA();
+ public abstract String trustedCa();
@Value.Parameter
- public abstract String trustedCAPassword();
-}
\ No newline at end of file
+ public abstract String trustedCaPassword();
+}
package org.onap.dcaegen2.collectors.datafile.configuration;
+import io.swagger.annotations.ApiOperation;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;
-
import javax.annotation.PostConstruct;
-
import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
import org.slf4j.Logger;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
-
-import io.swagger.annotations.ApiOperation;
import reactor.core.publisher.Mono;
/**
private static final Duration SCHEDULING_DELAY_FOR_DATAFILE_PURGE_CACHE = Duration.ofHours(1);
private static final Logger logger = LoggerFactory.getLogger(SchedulerConfig.class);
private static List<ScheduledFuture<?>> scheduledFutureList = new ArrayList<>();
- private Map<String, String> contextMap;
+ private Map<String, String> contextMap = new HashMap<>();
private final TaskScheduler taskScheduler;
private final ScheduledTasks scheduledTask;
scheduledFutureList
.add(taskScheduler.scheduleWithFixedDelay(() -> scheduledTask.purgeCachedInformation(Instant.now()),
SCHEDULING_DELAY_FOR_DATAFILE_PURGE_CACHE));
-
return true;
} else {
return false;
}
+ }
+ static void setScheduledFutureList(List<ScheduledFuture<?>> scheduledFutureList) {
+ SchedulerConfig.scheduledFutureList = scheduledFutureList;
}
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
* ===============================================================================================
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
-
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
@EnableSwagger2
@Configuration
@Profile("prod")
-public class SwaggerConfig extends WebMvcConfigurationSupport{
-
- public static final String PACKAGE_PATH = "org.onap.dcaegen2.collectors.datafile";
- public static final String API_TITLE = "DATAFILE app server";
- public static final String DESCRIPTION = "This page lists all the rest apis for DATAFILE app server.";
- public static final String VERSION = "1.0";
- public static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
- public static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
- public static final String SWAGGER_UI = "swagger-ui.html";
- public static final String WEBJARS = "/webjars/**";
+public class SwaggerConfig extends WebMvcConfigurationSupport {
- @Bean
- public Docket api() {
- return new Docket(DocumentationType.SWAGGER_2)
- .apiInfo(apiInfo())
- .select()
- .apis(RequestHandlerSelectors.basePackage(PACKAGE_PATH))
- .paths(PathSelectors.any())
- .build();
- }
+ public static final String PACKAGE_PATH = "org.onap.dcaegen2.collectors.datafile";
+ public static final String API_TITLE = "DATAFILE app server";
+ public static final String DESCRIPTION = "This page lists all the rest apis for DATAFILE app server.";
+ public static final String VERSION = "1.0";
+ public static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
+ public static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
+ public static final String SWAGGER_UI = "swagger-ui.html";
+ public static final String WEBJARS = "/webjars/**";
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- .title(API_TITLE)
- .description(DESCRIPTION)
- .version(VERSION)
- .build();
- }
+ /**
+ * Gets the API info.
+ *
+ * @return the API info.
+ */
+ @Bean
+ public Docket api() {
+ return new Docket(DocumentationType.SWAGGER_2) //
+ .apiInfo(apiInfo()) //
+ .select().apis(RequestHandlerSelectors.basePackage(PACKAGE_PATH)) //
+ .paths(PathSelectors.any()) //
+ .build();
+ }
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder() //
+ .title(API_TITLE) //
+ .description(DESCRIPTION) //
+ .version(VERSION) //
+ .build();
+ }
- @Override
- protected void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler(SWAGGER_UI)
- .addResourceLocations(RESOURCES_PATH);
+ @Override
+ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler(SWAGGER_UI) //
+ .addResourceLocations(RESOURCES_PATH);
- registry.addResourceHandler(WEBJARS)
- .addResourceLocations(WEBJARS_PATH);
- }
+ registry.addResourceHandler(WEBJARS) //
+ .addResourceLocations(WEBJARS_PATH);
+ }
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
* ===============================================================================================
import org.springframework.context.annotation.Configuration;
/**
+ * Configuration of Tomcat.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/18/18
*/
@Configuration
public class TomcatHttpConfig {
-
+ /**
+ * Creates a Tomcat server factory.
+ *
+ * @return a Tomcat server factory.
+ */
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
* ===============================================================================================
package org.onap.dcaegen2.collectors.datafile.controllers;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
import reactor.core.publisher.Mono;
/**
+ * Controller to check the heartbeat of DFC.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/19/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
private static final Logger logger = LoggerFactory.getLogger(HeartbeatController.class);
+ /**
+ * Checks the heartbeat of DFC.
+ *
+ * @return the heartbeat status of DFC.
+ */
@GetMapping("/heartbeat")
@ApiOperation(value = "Returns liveness of DATAFILE service")
@ApiResponses(value = { //
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
package org.onap.dcaegen2.collectors.datafile.controllers;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
import org.onap.dcaegen2.collectors.datafile.configuration.SchedulerConfig;
import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
import org.slf4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
import reactor.core.publisher.Mono;
/**
+ * The HTTP api to start and stop DFC.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/5/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
this.schedulerConfig = schedulerConfig;
}
+ /**
+ * Start the DFC.
+ *
+ * @param headers the request headers.
+ * @return the response.
+ */
@GetMapping("/start")
@ApiOperation(value = "Start scheduling worker request")
public Mono<ResponseEntity<String>> startTasks(@RequestHeader HttpHeaders headers) {
.map(this::createStartTaskResponse);
}
+ /**
+ * Stop the DFC.
+ *
+ * @return the response.
+ */
@GetMapping("/stopDatafile")
@ApiOperation(value = "Receiving stop scheduling worker request")
public Mono<ResponseEntity<String>> stopTask(@RequestHeader HttpHeaders headers) {
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
package org.onap.dcaegen2.collectors.datafile.exceptions;
-/**
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- */
public class DatafileTaskException extends Exception {
private static final long serialVersionUID = 1L;
super(message);
}
- public DatafileTaskException(String message, Exception e) {
- super(message, e);
+ public DatafileTaskException(String message, Exception originalException) {
+ super(message, originalException);
}
}
-/*
+/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
* ================================================================================
package org.onap.dcaegen2.collectors.datafile.exceptions;
/**
+ * Exception thrown when there is a problem with the Consul environment.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 9/19/18
*/
public class EnvironmentLoaderException extends Exception {
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
package org.onap.dcaegen2.collectors.datafile.ftp;
import java.nio.file.Path;
-
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
/**
+ * A closeable file client.
+ *
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
public interface FileCollectClient extends AutoCloseable {
public void collectFile(String remoteFile, Path localFile) throws DatafileTaskException;
+
public void open() throws DatafileTaskException;
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
package org.onap.dcaegen2.collectors.datafile.ftp;
import java.util.Optional;
-
import org.immutables.value.Value;
/**
+ * Data about the file server to collect a file from.
+ *
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*
*/
@Value.Immutable
public interface FileServerData {
public String serverAddress();
+
public String userId();
+
public String password();
+
public Optional<Integer> port();
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.util.Optional;
-
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
-
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
*/
public class FtpsClient implements FileCollectClient {
private static final Logger logger = LoggerFactory.getLogger(FtpsClient.class);
+
+ private static final int FTPS_DEFAULT_PORT = 21;
+
FTPSClient realFtpsClient = new FTPSClient();
private final FileServerData fileServerData;
private static TrustManager theTrustManager = null;
private final String keyCertPath;
private final String keyCertPassword;
- private final Path trustedCAPath;
- private final String trustedCAPassword;
-
- public FtpsClient(FileServerData fileServerData, String keyCertPath, String keyCertPassword, Path trustedCAPath,
- String trustedCAPassword) {
+ private final Path trustedCaPath;
+ private final String trustedCaPassword;
+
+ /**
+ * Constructor.
+ *
+ * @param fileServerData info needed to connect to the PNF.
+ * @param keyCertPath path to DFC's key cert.
+ * @param keyCertPassword password for DFC's key cert.
+ * @param trustedCaPath path to the PNF's trusted keystore.
+ * @param trustedCaPassword password for the PNF's trusted keystore.
+ */
+ public FtpsClient(FileServerData fileServerData, String keyCertPath, String keyCertPassword, Path trustedCaPath,
+ String trustedCaPassword) {
this.fileServerData = fileServerData;
this.keyCertPath = keyCertPath;
this.keyCertPassword = keyCertPassword;
- this.trustedCAPath = trustedCAPath;
- this.trustedCAPassword = trustedCAPassword;
+ this.trustedCaPath = trustedCaPath;
+ this.trustedCaPassword = trustedCaPassword;
}
@Override
try {
realFtpsClient.setNeedClientAuth(true);
realFtpsClient.setKeyManager(createKeyManager(keyCertPath, keyCertPassword));
- realFtpsClient.setTrustManager(getTrustManager(trustedCAPath, trustedCAPassword));
+ realFtpsClient.setTrustManager(getTrustManager(trustedCaPath, trustedCaPassword));
setUpConnection();
} catch (DatafileTaskException e) {
throw e;
}
private int getPort(Optional<Integer> port) {
- final int FTPS_DEFAULT_PORT = 21;
return port.isPresent() ? port.get() : FTPS_DEFAULT_PORT;
}
logger.trace("setUpConnection successfully!");
}
- private TrustManager createTrustManager(Path trustedCAPath, String trustedCAPassword)
+ private TrustManager createTrustManager(Path trustedCaPath, String trustedCaPassword)
throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException {
- logger.trace("Creating trust manager from file: {}", trustedCAPath);
- try (InputStream fis = createInputStream(trustedCAPath)) {
+ logger.trace("Creating trust manager from file: {}", trustedCaPath);
+ try (InputStream fis = createInputStream(trustedCaPath)) {
KeyStore keyStore = KeyStore.getInstance("JKS");
- keyStore.load(fis, trustedCAPassword.toCharArray());
+ keyStore.load(fis, trustedCaPassword.toCharArray());
TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
factory.init(keyStore);
return factory.getTrustManagers()[0];
return output;
}
- protected TrustManager getTrustManager(Path trustedCAPath, String trustedCAPassword)
+ protected TrustManager getTrustManager(Path trustedCaPath, String trustedCaPassword)
throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException {
synchronized (FtpsClient.class) {
if (theTrustManager == null) {
- theTrustManager = createTrustManager(trustedCAPath, trustedCAPassword);
+ theTrustManager = createTrustManager(trustedCaPath, trustedCaPassword);
}
return theTrustManager;
}
} else if ("SFTP".equalsIgnoreCase(schemeString)) {
result = Scheme.SFTP;
} else {
- throw new DatafileTaskException("DFC does not support protocol " + schemeString
- + ". Supported protocols are FTPES , FTPS, and SFTP");
+ throw new DatafileTaskException(
+ "DFC does not support protocol " + schemeString + ". Supported protocols are FTPES , FTPS, and SFTP");
}
return result;
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
-
import java.nio.file.Path;
import java.util.Optional;
-
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public class SftpClient implements FileCollectClient {
private static final Logger logger = LoggerFactory.getLogger(SftpClient.class);
+
+ private static final int FTPS_DEFAULT_PORT = 22;
+
private final FileServerData fileServerData;
private Session session = null;
private ChannelSftp sftpChannel = null;
}
private int getPort(Optional<Integer> port) {
- final int FTPS_DEFAULT_PORT = 22;
return port.isPresent() ? port.get() : FTPS_DEFAULT_PORT;
}
private Session setUpSession(FileServerData fileServerData) throws JSchException {
JSch jsch = new JSch();
- Session newSession = jsch.getSession(fileServerData.userId(), fileServerData.serverAddress(),
- getPort(fileServerData.port()));
+ Session newSession =
+ jsch.getSession(fileServerData.userId(), fileServerData.serverAddress(), getPort(fileServerData.port()));
newSession.setConfig("StrictHostKeyChecking", "no");
newSession.setPassword(fileServerData.password());
newSession.connect();
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
-
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
import org.apache.http.impl.nio.client.HttpAsyncClients;
-/**
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- */
-public class HttpAsyncClientBuilderWrapper implements IHttpAsyncClientBuilder {
+public class HttpAsyncClientBuilderWrapper {
HttpAsyncClientBuilder builder = HttpAsyncClients.custom();
- @Override
- public IHttpAsyncClientBuilder setRedirectStrategy(RedirectStrategy redirectStrategy) {
+ public HttpAsyncClientBuilderWrapper setRedirectStrategy(RedirectStrategy redirectStrategy) {
builder.setRedirectStrategy(redirectStrategy);
return this;
}
- @Override
- public IHttpAsyncClientBuilder setSSLContext(SSLContext sslcontext) {
+ public HttpAsyncClientBuilderWrapper setSslContext(SSLContext sslcontext) {
builder.setSSLContext(sslcontext);
return this;
}
- @Override
- public IHttpAsyncClientBuilder setSSLHostnameVerifier(HostnameVerifier hostnameVerifier) {
+ public HttpAsyncClientBuilderWrapper setSslHostnameVerifier(HostnameVerifier hostnameVerifier) {
builder.setSSLHostnameVerifier(hostnameVerifier);
return this;
}
- @Override
- public IHttpAsyncClientBuilder setDefaultRequestConfig(RequestConfig config) {
+ public HttpAsyncClientBuilderWrapper setDefaultRequestConfig(RequestConfig config) {
builder.setDefaultRequestConfig(config);
return this;
}
- @Override
public CloseableHttpAsyncClient build() {
return builder.build();
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
-
import java.lang.reflect.Type;
import java.nio.file.Path;
}
/**
- * Serializes a <code>ConsumerDmaapModel</code>.
+ * Serializes a <code>filePublishInformation</code>.
*
- * @param consumerDmaapModel model to serialize.
+ * @param filePublishInformation info to serialize.
*
* @return a string with the serialized model.
*/
- public static String createJsonBody(ConsumerDmaapModel consumerDmaapModel) {
- return gson.toJson(consumerDmaapModel);
+ public static String createJsonBody(FilePublishInformation filePublishInformation) {
+ return gson.toJson(filePublishInformation);
}
/**
-/*
- * ============LICENSE_START======================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
- * ===============================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- * ============LICENSE_END========================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
*/
package org.onap.dcaegen2.collectors.datafile.model;
public static final String DATAFILE_TMPDIR = "/tmp/onap_datafile/";
/**
+ * Get the file name with no path.
+ *
* @return the file name with no path
*/
public abstract String name();
/**
+ * Get the URL to use to fetch the file from the PNF.
+ *
* @return the URL to use to fetch the file from the PNF
*/
public abstract String location();
/**
+ * Get the file transfer protocol to use for fetching the file.
+ *
* @return the file transfer protocol to use for fetching the file
*/
public abstract Scheme scheme();
public abstract MessageMetaData messageMetaData();
/**
+ * Get the name of the PNF, must be unique in the network.
+ *
* @return the name of the PNF, must be unique in the network
*/
public String sourceName() {
return messageMetaData().sourceName();
}
+ /**
+ * Get the path to file to get from the PNF.
+ *
+ * @return the path to the file on the PNF.
+ */
public String remoteFilePath() {
return URI.create(location()).getPath();
}
+ /**
+ * Get the path to the locally stored file.
+ *
+ * @return the path to the locally stored file.
+ */
public Path getLocalFilePath() {
- return Paths.get(DATAFILE_TMPDIR, name());
+ return Paths.get(DATAFILE_TMPDIR, name());
}
+ /**
+ * Get the data about the file server where the file should be collected from.
+ *
+ * @return the data about the file server where the file should be collected from.
+ */
public FileServerData fileServerData() {
URI uri = URI.create(location());
Optional<String[]> userInfo = getUserNameAndPasswordIfGiven(uri.getUserInfo());
- // @formatter:off
- ImmutableFileServerData.Builder builder = ImmutableFileServerData.builder()
- .serverAddress(uri.getHost())
- .userId(userInfo.isPresent() ? userInfo.get()[0] : "")
+ ImmutableFileServerData.Builder builder = ImmutableFileServerData.builder() //
+ .serverAddress(uri.getHost()) //
+ .userId(userInfo.isPresent() ? userInfo.get()[0] : "") //
.password(userInfo.isPresent() ? userInfo.get()[1] : "");
if (uri.getPort() > 0) {
builder.port(uri.getPort());
}
return builder.build();
- // @formatter:on
}
+ /**
+ * Extracts user name and password from the user info, if it they are given in the URI.
+ *
+ * @param userInfoString the user info string from the URI.
+ *
+ * @return An <code>Optional</code> containing a String array with the user name and password if given, or an empty
+ * <code>Optional</code> if not given.
+ */
private Optional<String[]> getUserNameAndPasswordIfGiven(String userInfoString) {
if (userInfoString != null) {
String[] userAndPassword = userInfoString.split(":");
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
package org.onap.dcaegen2.collectors.datafile.model;
import com.google.gson.annotations.SerializedName;
-
import java.nio.file.Path;
-
import org.immutables.gson.Gson;
import org.immutables.value.Value;
import org.onap.dcaegen2.services.sdk.rest.services.model.DmaapModel;
/**
+ * Information needed to publish a file to DataRouter.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Value.Immutable
@Gson.TypeAdapters
-public interface ConsumerDmaapModel extends DmaapModel {
+public interface FilePublishInformation extends DmaapModel {
@SerializedName("productName")
String getProductName();
@SerializedName("fileFormatVersion")
String getFileFormatVersion();
-
-
}
package org.onap.dcaegen2.collectors.datafile.model;
import java.util.List;
-
import org.immutables.gson.Gson;
import org.immutables.value.Value;
/**
+ * Contains all the info about a fileReady message.
+ *
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Value.Immutable
@Gson.TypeAdapters
+@FunctionalInterface
public interface FileReadyMessage {
public List<FileData> files();
}
import org.immutables.value.Value;
/**
+ * Meta data about a fileReady message.
+ *
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Value.Immutable
import java.util.Map;
import java.util.UUID;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpRequestBase;
+import org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.http.HttpHeaders;
/**
- * Support functions for MDC
+ * Support functions for MDC.
*/
public final class MappedDiagnosticContext {
- private static final String X_ONAP_REQUEST_ID = "X-ONAP-RequestID";
- private static final String X_INVOCATION_ID = "X-InvocationID";
- private static final String REQUEST_ID = "RequestID";
- private static final String INVOCATION_ID = "InvocationID";
- public static final String RESPONSE_CODE = "ResponseCode";
- public static final String SERVICE_NAME = "ServiceName";
-
public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
private static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
private MappedDiagnosticContext() {}
/**
- * Inserts the relevant trace information in the HTTP header
+ * Inserts the relevant trace information in the HTTP header.
+ *
* @param httpRequest a request
*/
public static void appendTraceInfo(HttpRequestBase httpRequest) {
- String requestId = MDC.get(REQUEST_ID);
- httpRequest.addHeader(X_ONAP_REQUEST_ID, requestId);
+ String requestId = MDC.get(MdcVariables.REQUEST_ID);
+ httpRequest.addHeader(MdcVariables.X_ONAP_REQUEST_ID, requestId);
httpRequest.addHeader("X-RequestID", requestId); // deprecated
httpRequest.addHeader("X-TransactionID", requestId); // deprecated
String invocationId = UUID.randomUUID().toString();
- httpRequest.addHeader(X_INVOCATION_ID, invocationId);
+ httpRequest.addHeader(MdcVariables.X_INVOCATION_ID, invocationId);
logger.info(INVOKE, "Invoking request with invocation ID {}", invocationId);
}
/**
- * Initialize MDC from relevant information in a received HTTP header
+ * Initialize MDC from relevant information in a received HTTP header.
+ *
* @param headers a received HTPP header
*/
public static void initializeTraceContext(HttpHeaders headers) {
- String requestId = headers.getFirst(X_ONAP_REQUEST_ID);
+ String requestId = headers.getFirst(MdcVariables.X_ONAP_REQUEST_ID);
if (StringUtils.isBlank(requestId)) {
requestId = UUID.randomUUID().toString();
}
- String invocationId = headers.getFirst(X_INVOCATION_ID);
+ String invocationId = headers.getFirst(MdcVariables.X_INVOCATION_ID);
if (StringUtils.isBlank(invocationId)) {
invocationId = UUID.randomUUID().toString();
}
- MDC.put(REQUEST_ID, requestId);
- MDC.put(INVOCATION_ID, invocationId);
+ MDC.put(MdcVariables.REQUEST_ID, requestId);
+ MDC.put(MdcVariables.INVOCATION_ID, invocationId);
}
/**
*/
public static Map<String, String> initializeTraceContext() {
MDC.clear();
- MDC.put(REQUEST_ID, UUID.randomUUID().toString());
+ MDC.put(MdcVariables.REQUEST_ID, UUID.randomUUID().toString());
return MDC.getCopyOfContextMap();
}
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
package org.onap.dcaegen2.collectors.datafile.service;
-import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.RESPONSE_CODE;
-import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.SERVICE_NAME;
+import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.RESPONSE_CODE;
+import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.SERVICE_NAME;
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapCustomConfig;
import reactor.core.publisher.Mono;
/**
+ * Web client for the DMaaP MessageRouter.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18
*/
-public class DmaapReactiveWebClient {
+public class DmaapWebClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
- private String dmaaPContentType;
- private String dmaaPUserName;
- private String dmaaPUserPassword;
+ private String contentType;
+ private String dmaapUserName;
+ private String dmaapUserPassword;
/**
* Creating DmaapReactiveWebClient passing to them basic DmaapConfig.
* @param dmaapCustomConfig - configuration object
* @return DmaapReactiveWebClient
*/
- public DmaapReactiveWebClient fromConfiguration(DmaapCustomConfig dmaapCustomConfig) {
- this.dmaaPContentType = dmaapCustomConfig.dmaapContentType();
+ public DmaapWebClient fromConfiguration(DmaapCustomConfig dmaapCustomConfig) {
+ this.contentType = dmaapCustomConfig.dmaapContentType();
return this;
}
* @return WebClient
*/
public WebClient build() {
- Builder webClientBuilder = WebClient.builder()
- .defaultHeader(HttpHeaders.CONTENT_TYPE, dmaaPContentType) //
- .filter(logRequest()) //
- .filter(logResponse());
- if (dmaaPUserName != null && !dmaaPUserName.isEmpty() && dmaaPUserPassword != null
- && !dmaaPUserPassword.isEmpty()) {
- webClientBuilder.filter(basicAuthentication(dmaaPUserName, dmaaPUserPassword));
+ Builder webClientBuilder = WebClient.builder() //
+ .defaultHeader(HttpHeaders.CONTENT_TYPE, contentType) //
+ .filter(logRequest()) //
+ .filter(logResponse());
+ if (dmaapUserName != null && !dmaapUserName.isEmpty() && dmaapUserPassword != null
+ && !dmaapUserPassword.isEmpty()) {
+ webClientBuilder.filter(basicAuthentication(dmaapUserName, dmaapUserPassword));
}
return webClientBuilder.build();
}
return Mono.just(clientRequest);
});
}
-
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
public final class HttpUtils implements HttpStatus {
- private HttpUtils() {}
+ private HttpUtils() {
+ }
public static boolean isSuccessfulResponseCode(Integer statusCode) {
return statusCode >= 200 && statusCode < 300;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.StreamSupport;
-
import org.onap.dcaegen2.collectors.datafile.ftp.Scheme;
import org.onap.dcaegen2.collectors.datafile.model.FileData;
import org.onap.dcaegen2.collectors.datafile.model.FileReadyMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
-
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
.location(location) //
.scheme(scheme) //
.compression(getValueFromJson(data, COMPRESSION, missingValues)) //
- .messageMetaData(messageMetaData)
+ .messageMetaData(messageMetaData) //
.build();
if (missingValues.isEmpty()) {
return Optional.of(fileData);
}
/**
- * Gets data from the event name.
- * Defined as: {DomainAbbreviation}_{productName}-{vendorName}_{Description}, example:
- * Noti_RnNode-Ericsson_FileReady
+ * Gets data from the event name. Defined as: {DomainAbbreviation}_{productName}-{vendorName}_{Description},
+ * example: Noti_RnNode-Ericsson_FileReady
*
* @param dataType The type of data to get, {@link DmaapConsumerJsonParser.EventNameDataType}.
* @param eventName The event name to get the data from.
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import java.util.Map;
/**
- * A cache of all files that already has been published. Key is the local file path and the value is
- * a time stamp, when the key was last used.
+ * A cache of all files that already has been published. Key is the local file path and the value is a time stamp, when
+ * the key was last used.
*/
public class PublishedFileCache {
private final Map<Path, Instant> publishedFiles = Collections.synchronizedMap(new HashMap<Path, Instant>());
final int timeToKeepInfoInSeconds = 60 * 60 * 24;
return now.getEpochSecond() - then.getEpochSecond() > timeToKeepInfoInSeconds;
}
-
-
}
-/*
- * ============LICENSE_START======================================================================
+/*-
+ * ============LICENSE_START=======================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
- * ===============================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- * ============LICENSE_END========================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
*/
package org.onap.dcaegen2.collectors.datafile.service.producer;
import java.time.Duration;
import java.util.Map;
import java.util.concurrent.Future;
-
import javax.net.ssl.SSLContext;
-
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.ssl.SSLContextBuilder;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.http.HttpAsyncClientBuilderWrapper;
-import org.onap.dcaegen2.collectors.datafile.http.IHttpAsyncClientBuilder;
import org.onap.dcaegen2.collectors.datafile.web.PublishRedirectStrategy;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
import org.slf4j.Logger;
import org.springframework.web.util.UriBuilder;
/**
+ * Client used to send requests to DataRouter.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
this.configuration = dmaapPublisherConfiguration;
}
+ /**
+ * Executes the given request and handles redirects.
+ *
+ * @param request the request to execute.
+ * @param contextMap context for logging.
+ *
+ * @return the response from the request.
+ *
+ * @throws DatafileTaskException if anything goes wrong.
+ */
public HttpResponse getDmaapProducerResponseWithRedirect(HttpUriRequest request, Map<String, String> contextMap)
throws DatafileTaskException {
MDC.setContextMap(contextMap);
}
}
+ /**
+ * Executes the given request using the given timeout time.
+ *
+ * @param request the request to execute.
+ * @param requestTimeout the timeout time for the request.
+ * @param contextMap context for logging.
+ *
+ * @return the response from the request.
+ *
+ * @throws DatafileTaskException if anything goes wrong.
+ */
public HttpResponse getDmaapProducerResponseWithCustomTimeout(HttpUriRequest request, Duration requestTimeout,
Map<String, String> contextMap) throws DatafileTaskException {
MDC.setContextMap(contextMap);
}
}
+ /**
+ * Adds the user credentials needed to talk to DataRouter to the provided request.
+ *
+ * @param request the request to add credentials to.
+ */
public void addUserCredentialsToHead(HttpUriRequest request) {
String plainCreds = configuration.dmaapUserName() + ":" + configuration.dmaapUserPassword();
byte[] plainCredsBytes = plainCreds.getBytes(StandardCharsets.ISO_8859_1);
request.addHeader("Authorization", "Basic " + base64Creds);
}
+ /**
+ * Gets a <code>UriBuilder</code> containing the base URI needed talk to DataRouter. Specific parts can then be
+ * added to the URI by the user.
+ *
+ * @return a <code>UriBuilder</code> containing the base URI needed talk to DataRouter.
+ */
public UriBuilder getBaseUri() {
return new DefaultUriBuilderFactory().builder() //
.scheme(configuration.dmaapProtocol()) //
SSLContext sslContext =
new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build();
- IHttpAsyncClientBuilder clientBuilder = getHttpClientBuilder();
- clientBuilder.setSSLContext(sslContext) //
- .setSSLHostnameVerifier(new NoopHostnameVerifier());
+ HttpAsyncClientBuilderWrapper clientBuilder = getHttpClientBuilder();
+ clientBuilder.setSslContext(sslContext) //
+ .setSslHostnameVerifier(new NoopHostnameVerifier());
if (expectRedirect) {
clientBuilder.setRedirectStrategy(PublishRedirectStrategy.INSTANCE);
}
if (requestTimeout.toMillis() > 0) {
- int millis = (int)requestTimeout.toMillis();
+ int millis = (int) requestTimeout.toMillis();
RequestConfig requestConfig = RequestConfig.custom() //
.setSocketTimeout(millis) //
.setConnectTimeout(millis) //
return clientBuilder.build();
}
- IHttpAsyncClientBuilder getHttpClientBuilder() {
+ HttpAsyncClientBuilderWrapper getHttpClientBuilder() {
return new HttpAsyncClientBuilderWrapper();
}
-}
\ No newline at end of file
+}
package org.onap.dcaegen2.collectors.datafile.tasks;
-
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.model.FileReadyMessage;
-import org.onap.dcaegen2.collectors.datafile.service.DmaapReactiveWebClient;
+import org.onap.dcaegen2.collectors.datafile.service.DmaapWebClient;
import org.onap.dcaegen2.collectors.datafile.service.JsonMessageParser;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer.DMaaPConsumerReactiveHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.reactive.function.client.WebClient;
-
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/**
+ * Component used to get messages from the MessageRouter.
+ *
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
-public class DMaaPMessageConsumerTask {
- private static final Logger logger = LoggerFactory.getLogger(DMaaPMessageConsumerTask.class);
+public class DMaaPMessageConsumer {
+ private static final Logger logger = LoggerFactory.getLogger(DMaaPMessageConsumer.class);
private final JsonMessageParser jsonMessageParser;
private final DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient;
- public DMaaPMessageConsumerTask(AppConfig datafileAppConfig) {
+ public DMaaPMessageConsumer(AppConfig datafileAppConfig) {
this.jsonMessageParser = new JsonMessageParser();
this.dmaaPConsumerReactiveHttpClient = createHttpClient(datafileAppConfig);
}
- protected DMaaPMessageConsumerTask(DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient,
+ protected DMaaPMessageConsumer(DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient,
JsonMessageParser messageParser) {
this.dmaaPConsumerReactiveHttpClient = dmaaPConsumerReactiveHttpClient;
this.jsonMessageParser = messageParser;
}
- public Flux<FileReadyMessage> execute() {
- logger.trace("execute called");
+ /**
+ * Gets the response from the MessageRouter and turns it into a stream of fileReady messages.
+ *
+ * @return a stream of fileReady messages.
+ */
+ public Flux<FileReadyMessage> getMessageRouterResponse() {
+ logger.trace("getMessageRouterResponse called");
return consume((dmaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()));
}
private static DMaaPConsumerReactiveHttpClient createHttpClient(AppConfig datafileAppConfig) {
DmaapConsumerConfiguration config = datafileAppConfig.getDmaapConsumerConfiguration();
- WebClient client = new DmaapReactiveWebClient().fromConfiguration(config).build();
+ WebClient client = new DmaapWebClient().fromConfiguration(config).build();
return new DMaaPConsumerReactiveHttpClient(config, client);
}
import org.apache.http.entity.ByteArrayEntity;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.model.CommonFunctions;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.model.FilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
import org.onap.dcaegen2.collectors.datafile.service.HttpUtils;
import org.onap.dcaegen2.collectors.datafile.service.producer.DmaapProducerHttpClient;
this.datafileAppConfig = datafileAppConfig;
}
-
/**
* Publish one file.
*
* @param numRetries the maximal number of retries if the publishing fails
* @param firstBackoff the time to delay the first retry
* @param contextMap tracing context variables
- * @return the (same) ConsumerDmaapModel
+ * @return the (same) filePublishInformation
*/
- public Mono<ConsumerDmaapModel> execute(ConsumerDmaapModel model, long numRetries, Duration firstBackoff,
- Map<String, String> contextMap) {
+ public Mono<FilePublishInformation> publishFile(FilePublishInformation model, long numRetries,
+ Duration firstBackoff, Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
- logger.trace("Publish called with arg {}", model);
+ logger.trace("publishFile called with arg {}", model);
dmaapProducerReactiveHttpClient = resolveClient();
- return Mono.just(model)
- .cache()
+ return Mono.just(model) //
+ .cache() //
.flatMap(m -> publishFile(m, contextMap)) //
.flatMap(httpStatus -> handleHttpResponse(httpStatus, model, contextMap)) //
.retryBackoff(numRetries, firstBackoff);
}
- private Mono<HttpStatus> publishFile(ConsumerDmaapModel consumerDmaapModel, Map<String, String> contextMap) {
- logger.trace("Entering publishFile with {}", consumerDmaapModel);
+ private Mono<HttpStatus> publishFile(FilePublishInformation filePublishInformation,
+ Map<String, String> contextMap) {
+ logger.trace("Entering publishFile with {}", filePublishInformation);
try {
HttpPut put = new HttpPut();
- prepareHead(consumerDmaapModel, put);
- prepareBody(consumerDmaapModel, put);
+ prepareHead(filePublishInformation, put);
+ prepareBody(filePublishInformation, put);
dmaapProducerReactiveHttpClient.addUserCredentialsToHead(put);
HttpResponse response =
logger.trace("{}", response);
return Mono.just(HttpStatus.valueOf(response.getStatusLine().getStatusCode()));
} catch (Exception e) {
- logger.warn("Unable to send file to DataRouter. Data: {}", consumerDmaapModel.getInternalLocation(), e);
+ logger.warn("Unable to send file to DataRouter. Data: {}", filePublishInformation.getInternalLocation(), e);
return Mono.error(e);
}
}
- private void prepareHead(ConsumerDmaapModel model, HttpPut put) {
+ private void prepareHead(FilePublishInformation model, HttpPut put) {
put.addHeader(HttpHeaders.CONTENT_TYPE, CONTENT_TYPE);
JsonElement metaData = new JsonParser().parse(CommonFunctions.createJsonBody(model));
metaData.getAsJsonObject().remove(NAME_JSON_TAG).getAsString();
MappedDiagnosticContext.appendTraceInfo(put);
}
- private void prepareBody(ConsumerDmaapModel model, HttpPut put) throws IOException {
+ private void prepareBody(FilePublishInformation model, HttpPut put) throws IOException {
Path fileLocation = model.getInternalLocation();
try (InputStream fileInputStream = createInputStream(fileLocation)) {
put.setEntity(new ByteArrayEntity(IOUtils.toByteArray(fileInputStream)));
.pathSegment(fileName).build();
}
- private Mono<ConsumerDmaapModel> handleHttpResponse(HttpStatus response, ConsumerDmaapModel model,
+ private Mono<FilePublishInformation> handleHttpResponse(HttpStatus response, FilePublishInformation model,
Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
if (HttpUtils.isSuccessfulResponseCode(response.value())) {
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Map;
-
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.configuration.FtpesConfig;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.ftp.FileCollectClient;
import org.onap.dcaegen2.collectors.datafile.ftp.FtpsClient;
import org.onap.dcaegen2.collectors.datafile.ftp.SftpClient;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.model.FileData;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.model.FilePublishInformation;
+import org.onap.dcaegen2.collectors.datafile.model.ImmutableFilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
-
import reactor.core.publisher.Mono;
/**
+ * Collects a file from a PNF.
+ *
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
public class FileCollector {
private static final Logger logger = LoggerFactory.getLogger(FileCollector.class);
private final AppConfig datafileAppConfig;
+ /**
+ * Constructor.
+ *
+ * @param datafileAppConfig application configuration
+ */
public FileCollector(AppConfig datafileAppConfig) {
this.datafileAppConfig = datafileAppConfig;
}
- public Mono<ConsumerDmaapModel> execute(FileData fileData, long maxNumberOfRetries, Duration firstBackoffTimeout,
+ /**
+ * Collects a file from the PNF and stores it in the local file system.
+ *
+ * @param fileData data about the file to collect.
+ * @param numRetries the number of retries if the publishing fails
+ * @param firstBackoff the time to delay the first retry
+ * @param contextMap context for logging.
+ *
+ * @return the data needed to publish the file.
+ */
+ public Mono<FilePublishInformation> collectFile(FileData fileData, long numRetries, Duration firstBackoff,
Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
- logger.trace("Entering execute with {}", fileData);
+ logger.trace("Entering collectFile with {}", fileData);
return Mono.just(fileData) //
.cache() //
.flatMap(fd -> collectFile(fileData, contextMap)) //
- .retryBackoff(maxNumberOfRetries, firstBackoffTimeout);
+ .retryBackoff(numRetries, firstBackoff);
}
- private Mono<ConsumerDmaapModel> collectFile(FileData fileData, Map<String, String> contextMap) {
+ private Mono<FilePublishInformation> collectFile(FileData fileData, Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
logger.trace("starting to collectFile {}", fileData.name());
currentClient.open();
localFile.getParent().toFile().mkdir(); // Create parent directories
currentClient.collectFile(remoteFile, localFile);
- return Mono.just(getConsumerDmaapModel(fileData, localFile));
+ return Mono.just(getFilePublishInformation(fileData, localFile));
} catch (Exception throwable) {
- logger.warn("Failed to download file: {} {}, reason: {}", fileData.sourceName(), fileData.name(), throwable.toString());
+ logger.warn("Failed to download file: {} {}, reason: {}", fileData.sourceName(), fileData.name(),
+ throwable.toString());
return Mono.error(throwable);
}
}
}
}
- private ConsumerDmaapModel getConsumerDmaapModel(FileData fileData, Path localFile) {
+ private FilePublishInformation getFilePublishInformation(FileData fileData, Path localFile) {
String location = fileData.location();
MessageMetaData metaData = fileData.messageMetaData();
- return ImmutableConsumerDmaapModel.builder() //
+ return ImmutableFilePublishInformation.builder() //
.productName(metaData.productName()) //
.vendorName(metaData.vendorName()) //
.lastEpochMicrosec(metaData.lastEpochMicrosec()) //
}
protected SftpClient createSftpClient(FileData fileData) {
- return new SftpClient(fileData.fileServerData());
+ return new SftpClient(fileData.fileServerData());
}
protected FtpsClient createFtpsClient(FileData fileData) {
FtpesConfig config = datafileAppConfig.getFtpesConfiguration();
return new FtpsClient(fileData.fileServerData(), config.keyCert(), config.keyPassword(),
- Paths.get(config.trustedCA()), config.trustedCAPassword());
+ Paths.get(config.trustedCa()), config.trustedCaPassword());
}
}
import java.net.URI;
import java.time.Duration;
import java.util.Map;
-
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
*
* @return <code>true</code> if the file has been published before, <code>false</code> otherwise.
*/
- public boolean execute(String fileName, Map<String, String> contextMap) {
+ public boolean isFilePublished(String fileName, Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
DmaapProducerHttpClient producerClient = resolveClient();
producerClient.addUserCredentialsToHead(getRequest);
try {
- HttpResponse response =
- producerClient.getDmaapProducerResponseWithCustomTimeout(getRequest, WEB_CLIENT_TIMEOUT, contextMap);
+ HttpResponse response = producerClient.getDmaapProducerResponseWithCustomTimeout(getRequest,
+ WEB_CLIENT_TIMEOUT, contextMap);
logger.trace("{}", response);
int status = response.getStatusLine().getStatusCode();
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.model.FileData;
+import org.onap.dcaegen2.collectors.datafile.model.FilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.FileReadyMessage;
import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
import org.onap.dcaegen2.collectors.datafile.service.PublishedFileCache;
import reactor.core.scheduler.Schedulers;
/**
- * This implements the main flow of the data file collector. Fetch file ready events from the
- * message router, fetch new files from the PNF publish these in the data router.
+ * This implements the main flow of the data file collector. Fetch file ready events from the message router, fetch new
+ * files from the PNF publish these in the data router.
*/
@Component
public class ScheduledTasks {
applicationConfiguration.loadConfigurationFromFile();
createMainTask(context) //
.subscribe(model -> onSuccess(model, context), //
- thr -> onError(thr, context), //
- () -> onComplete(context));
+ thr -> onError(thr, context), //
+ () -> onComplete(context));
} catch (Exception e) {
logger.error("Unexpected exception: ", e);
}
}
- Flux<ConsumerDmaapModel> createMainTask(Map<String, String> contextMap) {
+ Flux<FilePublishInformation> createMainTask(Map<String, String> contextMap) {
return fetchMoreFileReadyMessages() //
.parallel(NUMBER_OF_WORKER_THREADS) // Each FileReadyMessage in a separate thread
.runOn(scheduler) //
return currentNumberOfTasks.get();
}
- protected DMaaPMessageConsumerTask createConsumerTask() {
- return new DMaaPMessageConsumerTask(this.applicationConfiguration);
+ protected DMaaPMessageConsumer createConsumerTask() {
+ return new DMaaPMessageConsumer(this.applicationConfiguration);
}
protected FileCollector createFileCollector() {
logger.trace("Datafile tasks have been completed");
}
- private synchronized void onSuccess(ConsumerDmaapModel model, Map<String, String> contextMap) {
+ private synchronized void onSuccess(FilePublishInformation model, Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
logger.info("Datafile file published {}", model.getInternalLocation());
}
boolean result = false;
Path localFilePath = fileData.getLocalFilePath();
if (alreadyPublishedFiles.put(localFilePath) == null) {
- result = !createPublishedChecker().execute(fileData.name(), contextMap);
+ result = !createPublishedChecker().isFilePublished(fileData.name(), contextMap);
}
return result;
}
- private Mono<ConsumerDmaapModel> fetchFile(FileData fileData, Map<String, String> contextMap) {
+ private Mono<FilePublishInformation> fetchFile(FileData fileData, Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
return createFileCollector()
- .execute(fileData, FILE_TRANSFER_MAX_RETRIES, FILE_TRANSFER_INITIAL_RETRY_TIMEOUT, contextMap)
+ .collectFile(fileData, FILE_TRANSFER_MAX_RETRIES, FILE_TRANSFER_INITIAL_RETRY_TIMEOUT, contextMap)
.onErrorResume(exception -> handleFetchFileFailure(fileData, contextMap));
}
- private Mono<ConsumerDmaapModel> handleFetchFileFailure(FileData fileData, Map<String, String> contextMap) {
+ private Mono<FilePublishInformation> handleFetchFileFailure(FileData fileData, Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
Path localFilePath = fileData.getLocalFilePath();
logger.error("File fetching failed, fileData {}", fileData);
return Mono.empty();
}
- private Mono<ConsumerDmaapModel> publishToDataRouter(ConsumerDmaapModel model, Map<String, String> contextMap) {
+ private Mono<FilePublishInformation> publishToDataRouter(FilePublishInformation model,
+ Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
return createDataRouterPublisher()
- .execute(model, DATA_ROUTER_MAX_RETRIES, DATA_ROUTER_INITIAL_RETRY_TIMEOUT, contextMap)
+ .publishFile(model, DATA_ROUTER_MAX_RETRIES, DATA_ROUTER_INITIAL_RETRY_TIMEOUT, contextMap)
.onErrorResume(exception -> handlePublishFailure(model, contextMap));
}
- private Mono<ConsumerDmaapModel> handlePublishFailure(ConsumerDmaapModel model, Map<String, String> contextMap) {
+ private Mono<FilePublishInformation> handlePublishFailure(FilePublishInformation model,
+ Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
logger.error("File publishing failed: {}", model);
Path internalFileName = model.getInternalLocation();
Map<String, String> contextMap = MDC.getCopyOfContextMap();
return createConsumerTask() //
- .execute() //
+ .getMessageRouterResponse() //
.onErrorResume(exception -> handleConsumeMessageFailure(exception, contextMap));
}
try {
Files.delete(localFile);
} catch (Exception e) {
- logger.trace("Could not delete file: {}", localFile);
+ logger.trace("Could not delete file: {}", localFile, e);
}
}
-
}
* the License.
* ============LICENSE_END========================================================================
*/
+
package org.onap.dcaegen2.collectors.datafile.web;
import java.net.URI;
-
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolException;
/**
* Redirectable methods.
*/
- private static final String[] REDIRECT_METHODS = new String[] {
- HttpPut.METHOD_NAME,
- HttpGet.METHOD_NAME,
- HttpPost.METHOD_NAME,
- HttpHead.METHOD_NAME,
- HttpDelete.METHOD_NAME
+ private static final String[] REDIRECT_METHODS = new String[] { //
+ HttpPut.METHOD_NAME, //
+ HttpGet.METHOD_NAME, //
+ HttpPost.METHOD_NAME, //
+ HttpHead.METHOD_NAME, //
+ HttpDelete.METHOD_NAME //
};
@Override
protected boolean isRedirectable(final String method) {
- for (final String m: REDIRECT_METHODS) {
+ for (final String m : REDIRECT_METHODS) {
if (m.equalsIgnoreCase(method)) {
return true;
}
}
@Override
- public HttpUriRequest getRedirect(
- final HttpRequest request,
- final HttpResponse response,
- final HttpContext context) throws ProtocolException {
+ public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context)
+ throws ProtocolException {
final URI uri = getLocationURI(request, response, context);
logger.trace("getRedirect...: {}", request);
return RequestBuilder.copy(request).setUri(uri).build();
"ftpesConfiguration": {
"keyCert": "config/dfc.jks",
"keyPassword": "secret",
- "trustedCA": "config/ftp.jks",
- "trustedCAPassword": "secret"
+ "trustedCa": "config/ftp.jks",
+ "trustedCaPassword": "secret"
}
}
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito.MockitoExtension;
/**
+ * Tests the AppConfig.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
-@ExtendWith({MockitoExtension.class})
class AppConfigTest {
private static final String DATAFILE_ENDPOINTS = "datafile_endpoints.json";
JsonObject ftpesConfigData = new JsonObject();
ftpesConfigData.addProperty("keyCert", "config/dfc.jks");
ftpesConfigData.addProperty("keyPassword", "secret");
- ftpesConfigData.addProperty("trustedCA", "config/ftp.jks");
- ftpesConfigData.addProperty("trustedCAPassword", "secret");
+ ftpesConfigData.addProperty("trustedCa", "config/ftp.jks");
+ ftpesConfigData.addProperty("trustedCaPassword", "secret");
JsonObject security = new JsonObject();
security.addProperty("trustStorePath", "trustStorePath");
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
* ===============================================================================================
new ImmutableFtpesConfig.Builder() //
.keyCert("/config/dfc.jks") //
.keyPassword("secret") //
- .trustedCA("config/ftp.jks") //
- .trustedCAPassword("secret") //
+ .trustedCa("config/ftp.jks") //
+ .trustedCaPassword("secret") //
.build();
private CloudConfigParser cloudConfigParser = new CloudConfigParser(getCloudConfigJsonObject());
config.addProperty("dmaap.dmaapProducerConfiguration.dmaapUserPassword", "dradmin");
config.addProperty("dmaap.ftpesConfig.keyCert", "/config/dfc.jks");
config.addProperty("dmaap.ftpesConfig.keyPassword", "secret");
- config.addProperty("dmaap.ftpesConfig.trustedCA", "config/ftp.jks");
- config.addProperty("dmaap.ftpesConfig.trustedCAPassword", "secret");
+ config.addProperty("dmaap.ftpesConfig.trustedCa", "config/ftp.jks");
+ config.addProperty("dmaap.ftpesConfig.trustedCaPassword", "secret");
config.addProperty("dmaap.security.trustStorePath", "trustStorePath");
config.addProperty("dmaap.security.trustStorePasswordPath", "trustStorePasswordPath");
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.collectors.datafile.configuration;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ScheduledFuture;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.scheduling.TaskScheduler;
+import reactor.test.StepVerifier;
+
+public class SchedulerConfigTest {
+
+ @Test
+ public void getResponseFromCancellationOfTasks_success() {
+ List<ScheduledFuture<?>> scheduledFutureList = new ArrayList<>();
+ ScheduledFuture<?> scheduledFutureMock = mock(ScheduledFuture.class);
+ scheduledFutureList.add(scheduledFutureMock);
+
+ SchedulerConfig.setScheduledFutureList(scheduledFutureList);
+
+ SchedulerConfig schedulerUnderTest = new SchedulerConfig(null, null, null);
+
+ String msg = "Datafile Service has already been stopped!";
+ StepVerifier.create(schedulerUnderTest.getResponseFromCancellationOfTasks())
+ .expectNext(new ResponseEntity<String>(msg, HttpStatus.CREATED)) //
+ .verifyComplete();
+
+ verify(scheduledFutureMock).cancel(false);
+ verifyNoMoreInteractions(scheduledFutureMock);
+
+ assertEquals(0, scheduledFutureList.size());
+ }
+
+ @Test
+ public void tryToStartTaskWhenNotStarted_success() {
+ TaskScheduler taskSchedulerMock = mock(TaskScheduler.class);
+ ScheduledTasks scheduledTasksMock = mock(ScheduledTasks.class);
+ CloudConfiguration cloudConfigurationMock = mock(CloudConfiguration.class);
+ List<ScheduledFuture<?>> scheduledFutureList = new ArrayList<>();
+
+ SchedulerConfig.setScheduledFutureList(scheduledFutureList);
+
+ SchedulerConfig schedulerUnderTestSpy =
+ spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, cloudConfigurationMock));
+
+ boolean actualResult = schedulerUnderTestSpy.tryToStartTask();
+
+ assertTrue(actualResult);
+
+ ArgumentCaptor<Runnable> runTaskRunnableCaptor = ArgumentCaptor.forClass(Runnable.class);
+ verify(taskSchedulerMock).scheduleAtFixedRate(runTaskRunnableCaptor.capture(), any(Instant.class),
+ eq(Duration.ofMinutes(5)));
+
+ ArgumentCaptor<Runnable> scheduleMainDatafileEventTaskCaptor = ArgumentCaptor.forClass(Runnable.class);
+ verify(taskSchedulerMock).scheduleWithFixedDelay(scheduleMainDatafileEventTaskCaptor.capture(),
+ eq(Duration.ofSeconds(15)));
+ ArgumentCaptor<Runnable> purgeCachedInformationCaptor = ArgumentCaptor.forClass(Runnable.class);
+ verify(taskSchedulerMock).scheduleWithFixedDelay(purgeCachedInformationCaptor.capture(),
+ eq(Duration.ofHours(1)));
+ verifyNoMoreInteractions(taskSchedulerMock);
+
+ scheduleMainDatafileEventTaskCaptor.getValue().run();
+ purgeCachedInformationCaptor.getValue().run();
+ verify(scheduledTasksMock).purgeCachedInformation(any(Instant.class));
+ verify(scheduledTasksMock).executeDatafileMainTask();
+ verifyNoMoreInteractions(scheduledTasksMock);
+
+ runTaskRunnableCaptor.getValue().run();
+ verify(cloudConfigurationMock).runTask();
+ verifyNoMoreInteractions(cloudConfigurationMock);
+
+ assertEquals(3, scheduledFutureList.size());
+ }
+
+ @Test
+ public void tryToStartTaskWhenAlreadyStarted_shouldReturnFalse() {
+ List<ScheduledFuture<?>> scheduledFutureList = new ArrayList<>();
+ ScheduledFuture<?> scheduledFutureMock = mock(ScheduledFuture.class);
+ scheduledFutureList.add(scheduledFutureMock);
+
+ SchedulerConfig.setScheduledFutureList(scheduledFutureList);
+
+ SchedulerConfig schedulerUnderTest = new SchedulerConfig(null, null, null);
+
+ boolean actualResult = schedulerUnderTest.tryToStartTask();
+
+ assertFalse(actualResult);
+ }
+}
import java.io.OutputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
-
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;
-
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPSClient;
import org.junit.jupiter.api.BeforeEach;
private static final int PORT = 8021;
private static final String FTP_KEY_PATH = "ftpKeyPath";
private static final String FTP_KEY_PASSWORD = "ftpKeyPassword";
- private static final Path TRUSTED_CA_PATH = Paths.get("trustedCAPath");
- private static final String TRUSTED_CA_PASSWORD = "trustedCAPassword";
+ private static final Path TRUSTED_CA_PATH = Paths.get("trustedCaPath");
+ private static final String TRUSTED_CA_PASSWORD = "trustedCaPassword";
private static final String USERNAME = "bob";
private static final String PASSWORD = "123";
-
private FTPSClient ftpsClientMock = mock(FTPSClient.class);
private KeyManager keyManagerMock = mock(KeyManager.class);
private TrustManager trustManagerMock = mock(TrustManager.class);
FtpsClient clientUnderTestSpy;
private ImmutableFileServerData createFileServerData() {
- return ImmutableFileServerData.builder().serverAddress(XNF_ADDRESS).userId(USERNAME).password(PASSWORD)
- .port(PORT).build();
+ return ImmutableFileServerData.builder() //
+ .serverAddress(XNF_ADDRESS) //
+ .userId(USERNAME).password(PASSWORD) //
+ .port(PORT) //
+ .build();
}
@BeforeEach
protected void setUp() throws Exception {
clientUnderTestSpy = spy(new FtpsClient(createFileServerData(), FTP_KEY_PATH, FTP_KEY_PASSWORD, TRUSTED_CA_PATH,
- TRUSTED_CA_PASSWORD));
+ TRUSTED_CA_PASSWORD));
clientUnderTestSpy.realFtpsClient = ftpsClientMock;
}
- private void verifyFtpsClientMock_openOK() throws Exception {
+ private void verifyFtpsClientMock_openOk() throws Exception {
doReturn(outputStreamMock).when(clientUnderTestSpy).createOutputStream(LOCAL_FILE_PATH);
when(ftpsClientMock.retrieveFile(ArgumentMatchers.eq(REMOTE_FILE_PATH),
- ArgumentMatchers.any(OutputStream.class))).thenReturn(true);
+ ArgumentMatchers.any(OutputStream.class))).thenReturn(true);
verify(ftpsClientMock).setNeedClientAuth(true);
verify(ftpsClientMock).setKeyManager(keyManagerMock);
verify(ftpsClientMock).setTrustManager(trustManagerMock);
doReturn(true).when(ftpsClientMock).isConnected();
clientUnderTestSpy.close();
- verifyFtpsClientMock_openOK();
+ verifyFtpsClientMock_openOk();
verify(ftpsClientMock, times(1)).isConnected();
verify(ftpsClientMock, times(1)).logout();
verify(ftpsClientMock, times(1)).disconnect();
doReturn(outputStreamMock).when(clientUnderTestSpy).createOutputStream(LOCAL_FILE_PATH);
assertThatThrownBy(() -> clientUnderTestSpy.open())
- .hasMessageContaining("Could not open connection: java.io.FileNotFoundException:");
+ .hasMessageContaining("Could not open connection: java.io.FileNotFoundException:");
verify(ftpsClientMock).setNeedClientAuth(true);
doThrow(new IOException("problem")).when(clientUnderTestSpy).createInputStream(TRUSTED_CA_PATH);
assertThatThrownBy(() -> clientUnderTestSpy.open())
- .hasMessage("Could not open connection: java.io.IOException: problem");
+ .hasMessage("Could not open connection: java.io.IOException: problem");
}
@Test
doReturn(inputStreamMock).when(clientUnderTestSpy).createInputStream(TRUSTED_CA_PATH);
assertThatThrownBy(() -> clientUnderTestSpy.open())
- .hasMessage("Could not open connection: java.io.EOFException");
+ .hasMessage("Could not open connection: java.io.EOFException");
}
@Test
doReturn(503).when(ftpsClientMock).getReplyCode();
assertThatThrownBy(() -> clientUnderTestSpy.open())
- .hasMessage("Unable to connect to xNF. 127.0.0.1 xNF reply code: 503");
+ .hasMessage("Unable to connect to xNF. 127.0.0.1 xNF reply code: 503");
verify(ftpsClientMock).setNeedClientAuth(true);
verify(ftpsClientMock).setKeyManager(keyManagerMock);
doReturn(false).when(ftpsClientMock).retrieveFile(REMOTE_FILE_PATH, outputStreamMock);
assertThatThrownBy(() -> clientUnderTestSpy.collectFile(REMOTE_FILE_PATH, LOCAL_FILE_PATH))
- .hasMessage("Could not retrieve file /dir/sample.txt");
+ .hasMessage("Could not retrieve file /dir/sample.txt");
- verifyFtpsClientMock_openOK();
+ verifyFtpsClientMock_openOk();
verify(ftpsClientMock, times(1)).retrieveFile(ArgumentMatchers.eq(REMOTE_FILE_PATH), any());
verifyNoMoreInteractions(ftpsClientMock);
}
doThrow(new IOException("problem")).when(ftpsClientMock).retrieveFile(REMOTE_FILE_PATH, outputStreamMock);
assertThatThrownBy(() -> clientUnderTestSpy.collectFile(REMOTE_FILE_PATH, LOCAL_FILE_PATH))
- .hasMessage("Could not fetch file: java.io.IOException: problem");
+ .hasMessage("Could not fetch file: java.io.IOException: problem");
- verifyFtpsClientMock_openOK();
+ verifyFtpsClientMock_openOk();
verify(ftpsClientMock, times(1)).retrieveFile(ArgumentMatchers.eq(REMOTE_FILE_PATH), any());
verifyNoMoreInteractions(ftpsClientMock);
}
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
-/**
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- *
- */
public class SchemeTest {
@Test
public void getSchemeFromString_properScheme() throws DatafileTaskException {
@Test
public void getSchemeFromString_invalidScheme() {
assertTrue(assertThrows(DatafileTaskException.class, () -> Scheme.getSchemeFromString("invalid")).getMessage()
- .startsWith("DFC does not support protocol invalid"));
+ .startsWith("DFC does not support protocol invalid"));
}
}
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
-
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-
import org.junit.Rule;
import org.junit.Test;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
@Test
public void collectFile_withOKresponse()
- throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
- FileServerData expectedFileServerData = ImmutableFileServerData.builder().serverAddress("127.0.0.1")
- .userId(USERNAME).password(PASSWORD).port(sftpServer.getPort()).build();
+ throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
+ FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
+ .serverAddress("127.0.0.1") //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(sftpServer.getPort()) //
+ .build();
try (SftpClient sftpClient = new SftpClient(expectedFileServerData)) {
sftpClient.open();
sftpServer.putFile(REMOTE_DUMMY_FILE, DUMMY_CONTENT, UTF_8);
@Test
public void collectFile_withWrongUserName_shouldFail() throws DatafileTaskException, IOException {
- FileServerData expectedFileServerData = ImmutableFileServerData.builder().serverAddress("127.0.0.1")
- .userId("wrong").password(PASSWORD).port(sftpServer.getPort()).build();
+ FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
+ .serverAddress("127.0.0.1") //
+ .userId("wrong") //
+ .password(PASSWORD) //
+ .port(sftpServer.getPort()) //
+ .build();
try (SftpClient sftpClient = new SftpClient(expectedFileServerData)) {
sftpServer.putFile(REMOTE_DUMMY_FILE, DUMMY_CONTENT, UTF_8);
-
assertThatThrownBy(() -> sftpClient.open())
- .hasMessageContaining("Could not open Sftp clientcom.jcraft.jsch.JSchException: Auth fail");
+ .hasMessageContaining("Could not open Sftp clientcom.jcraft.jsch.JSchException: Auth fail");
}
}
@Test
public void collectFile_withWrongFileName_shouldFail()
- throws IOException, JSchException, SftpException, DatafileTaskException {
- FileServerData expectedFileServerData = ImmutableFileServerData.builder().serverAddress("127.0.0.1")
- .userId(USERNAME).password(PASSWORD).port(sftpServer.getPort()).build();
+ throws IOException, JSchException, SftpException, DatafileTaskException {
+ FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
+ .serverAddress("127.0.0.1") //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(sftpServer.getPort()) //
+ .build();
try (SftpClient sftpClient = new SftpClient(expectedFileServerData)) {
sftpServer.putFile(REMOTE_DUMMY_FILE, DUMMY_CONTENT, UTF_8);
sftpClient.open();
- assertThatThrownBy(() -> sftpClient.collectFile("wrong", LOCAL_DUMMY_FILE)).hasMessageStartingWith(
- "Unable to get file from xNF. Data: FileServerData{serverAddress=127.0.0.1, "
- + "userId=bob, password=123, port=");
+ assertThatThrownBy(() -> sftpClient.collectFile("wrong", LOCAL_DUMMY_FILE))
+ .hasMessageStartingWith("Unable to get file from xNF. Data: FileServerData{serverAddress=127.0.0.1, "
+ + "userId=bob, password=123, port=");
}
}
}
private static Session createSessionWithCredentials(String username, String password, int port)
- throws JSchException {
+ throws JSchException {
Session session = JSCH.getSession(username, "127.0.0.1", port);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
}
private static byte[] downloadFile(FakeSftpServerRule server, String path)
- throws JSchException, SftpException, IOException {
+ throws JSchException, SftpException, IOException {
Session session = connectToServer(server);
ChannelSftp channel = connectSftpChannel(session);
try {
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito.MockitoExtension;
import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
/**
+ * Integration test for the ScheduledXmlContext.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@Configuration
@ComponentScan
-@ExtendWith({MockitoExtension.class, SpringExtension.class})
-@ContextConfiguration(locations = {"classpath:scheduled-context.xml"})
+@ExtendWith({ SpringExtension.class })
+@ContextConfiguration(locations = { "classpath:scheduled-context.xml" })
class ScheduledXmlContextITest extends AbstractTestNGSpringContextTests {
private static final int WAIT_FOR_SCHEDULING = 1;
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018-2019 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.integration;
-
-import static org.mockito.Mockito.mock;
-
-import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/10/18
- */
-@Configuration
-class ServiceMockProvider {
-
- @Bean
- public AppConfig getDatafileAppConfig() {
- return mock(AppConfig.class);
- }
-
- @Bean
- public ConsumerDmaapModel getRequestDetails() {
- return mock(ConsumerDmaapModel.class);
- }
-}
+++ /dev/null
-/*
- * ============LICENSE_START======================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
- * ===============================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END========================================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito;
-
-import static org.mockito.Mockito.mock;
-
-import java.lang.reflect.Parameter;
-
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
-import org.junit.jupiter.api.extension.ExtensionContext.Store;
-import org.junit.jupiter.api.extension.ParameterContext;
-import org.junit.jupiter.api.extension.ParameterResolver;
-import org.junit.jupiter.api.extension.TestInstancePostProcessor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
- *
- * {@code MockitoExtension} showcases the {@link TestInstancePostProcessor} and
- * {@link ParameterResolver} extension APIs of JUnit 5 by providing dependency injection
- * support at the field level and at the method parameter level via Mockito 2.x's
- * {@link Mock @Mock} annotation.
- */
-public class MockitoExtension implements TestInstancePostProcessor, ParameterResolver {
-
- @Override
- public void postProcessTestInstance(Object testInstance, ExtensionContext context) {
- MockitoAnnotations.initMocks(testInstance);
- }
-
- @Override
- public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
- return parameterContext.getParameter().isAnnotationPresent(Mock.class);
- }
-
- @Override
- public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) {
- return getMock(parameterContext.getParameter(), extensionContext);
- }
-
- private Object getMock(Parameter parameter, ExtensionContext extensionContext) {
- Class<?> mockType = parameter.getType();
- Store mocks = extensionContext.getStore(Namespace.create(MockitoExtension.class, mockType));
- String mockName = getMockName(parameter);
-
- if (mockName != null) {
- return mocks.getOrComputeIfAbsent(mockName, key -> mock(mockType, mockName));
- } else {
- return mocks.getOrComputeIfAbsent(mockType.getCanonicalName(), key -> mock(mockType));
- }
- }
-
- private String getMockName(Parameter parameter) {
- String explicitMockName = parameter.getAnnotation(Mock.class).name().trim();
- if (!explicitMockName.isEmpty()) {
- return explicitMockName;
- } else if (parameter.isNamePresent()) {
- return parameter.getName();
- }
- return null;
- }
-
-
-}
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Paths;
-
import org.junit.jupiter.api.Test;
public class CommonFunctionsTest {
@Test
public void createJsonBody_success() {
- ImmutableConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel //
- .builder() //
- .productName("") //
- .vendorName("") //
- .lastEpochMicrosec("") //
- .sourceName("") //
- .startEpochMicrosec("") //
- .timeZoneOffset("") //
- .name("") //
- .location("") //
- .internalLocation(Paths.get("internalLocation")) //
- .compression("") //
- .fileFormatType("") //
- .fileFormatVersion("") //
- .build();
- String actualBody = CommonFunctions.createJsonBody(consumerDmaapModel);
+ ImmutableFilePublishInformation filePublishInformation = ImmutableFilePublishInformation //
+ .builder() //
+ .productName("") //
+ .vendorName("") //
+ .lastEpochMicrosec("") //
+ .sourceName("") //
+ .startEpochMicrosec("") //
+ .timeZoneOffset("") //
+ .name("") //
+ .location("") //
+ .internalLocation(Paths.get("internalLocation")) //
+ .compression("") //
+ .fileFormatType("") //
+ .fileFormatVersion("") //
+ .build();
+ String actualBody = CommonFunctions.createJsonBody(filePublishInformation);
assertTrue(actualBody.contains("\"internalLocation\":\"internalLocation\""));
}
import org.onap.dcaegen2.collectors.datafile.ftp.ImmutableFileServerData;
import org.onap.dcaegen2.collectors.datafile.ftp.Scheme;
-/**
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- *
- */
public class FileDataTest {
private static final String FTPES_SCHEME = "ftpes://";
private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz";
private MessageMetaData messageMetaData() {
- return ImmutableMessageMetaData.builder()
- .productName("PRODUCT_NAME")
- .vendorName("VENDOR_NAME")
- .lastEpochMicrosec("LAST_EPOCH_MICROSEC")
- .sourceName("SOURCE_NAME")
- .startEpochMicrosec("START_EPOCH_MICROSEC")
- .timeZoneOffset("TIME_ZONE_OFFSET")
- .changeIdentifier("PM_MEAS_CHANGE_IDENTIFIER")
- .changeType("FILE_READY_CHANGE_TYPE")
- .build();
+ return ImmutableMessageMetaData.builder() //
+ .productName("PRODUCT_NAME") //
+ .vendorName("VENDOR_NAME") //
+ .lastEpochMicrosec("LAST_EPOCH_MICROSEC") //
+ .sourceName("SOURCE_NAME") //
+ .startEpochMicrosec("START_EPOCH_MICROSEC") //
+ .timeZoneOffset("TIME_ZONE_OFFSET") //
+ .changeIdentifier("PM_MEAS_CHANGE_IDENTIFIER") //
+ .changeType("FILE_READY_CHANGE_TYPE") //
+ .build();
}
private FileData properFileDataWithUser() {
- // @formatter:off
- return ImmutableFileData.builder()
- .name("name")
- .location(LOCATION_WITH_USER)
- .compression("comp")
- .fileFormatType("type")
- .fileFormatVersion("version")
- .scheme(Scheme.FTPS)
- .messageMetaData(messageMetaData())
- .build();
- // @formatter:on
+ return ImmutableFileData.builder() //
+ .name("name") //
+ .location(LOCATION_WITH_USER) //
+ .compression("comp") //
+ .fileFormatType("type") //
+ .fileFormatVersion("version") //
+ .scheme(Scheme.FTPS) //
+ .messageMetaData(messageMetaData()) //
+ .build();
}
private FileData properFileDataWithoutUser() {
- // @formatter:off
- return ImmutableFileData.builder()
- .name("name")
- .location(LOCATION_WITHOUT_USER)
- .compression("comp")
- .fileFormatType("type")
- .fileFormatVersion("version")
- .scheme(Scheme.FTPS)
- .messageMetaData(messageMetaData())
- .build();
- // @formatter:on
+ return ImmutableFileData.builder() //
+ .name("name") //
+ .location(LOCATION_WITHOUT_USER) //
+ .compression("comp") //
+ .fileFormatType("type") //
+ .fileFormatVersion("version") //
+ .scheme(Scheme.FTPS) //
+ .messageMetaData(messageMetaData()) //
+ .build();
}
@Test
public void fileServerData_properLocationWithUser() {
- // @formatter:off
- ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder()
- .serverAddress(SERVER_ADDRESS)
- .port(PORT_22)
- .userId(USER)
- .password(PWD)
+ ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() //
+ .serverAddress(SERVER_ADDRESS) //
+ .port(PORT_22) //
+ .userId(USER) //
+ .password(PWD) //
.build();
- // @formatter:on
FileServerData actualFileServerData = properFileDataWithUser().fileServerData();
assertEquals(expectedFileServerData, actualFileServerData);
@Test
public void fileServerData_properLocationWithoutUser() {
- // @formatter:off
- ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder()
- .serverAddress(SERVER_ADDRESS)
- .port(PORT_22)
- .userId("")
- .password("")
+ ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() //
+ .serverAddress(SERVER_ADDRESS) //
+ .port(PORT_22) //
+ .userId("") //
+ .password("") //
.build();
- // @formatter:on
FileServerData actualFileServerData = properFileDataWithoutUser().fileServerData();
assertEquals(expectedFileServerData, actualFileServerData);
@Test
public void fileServerData_properLocationWithoutPort() {
- // @formatter:off
- ImmutableFileServerData fileServerData = ImmutableFileServerData.builder()
- .serverAddress(SERVER_ADDRESS)
- .userId("")
- .password("")
+ ImmutableFileServerData fileServerData = ImmutableFileServerData.builder() //
+ .serverAddress(SERVER_ADDRESS) //
+ .userId("") //
+ .password("") //
.build();
- // @formatter:on
assertFalse(fileServerData.port().isPresent());
}
-
-
}
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import java.nio.file.Path;
import java.nio.file.Paths;
-
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-public class ConsumerDmaapModelTest {
+public class FilePublishInformationTest {
private static final String PRODUCT_NAME = "NrRadio";
private static final String VENDOR_NAME = "Ericsson";
private static final String LAST_EPOCH_MICROSEC = "8745745764578";
private static final String FILE_FORMAT_VERSION = "V10";
@Test
- public void consumerDmaapModelBuilder_shouldBuildAnObject() {
- ConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .name(NAME) //
- .location(LOCATION) //
- .internalLocation(INTERNAL_LOCATION) //
- .compression(COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ public void filePublishInformationBuilder_shouldBuildAnObject() {
+ FilePublishInformation filePublishInformation = ImmutableFilePublishInformation.builder() //
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .name(NAME) //
+ .location(LOCATION) //
+ .internalLocation(INTERNAL_LOCATION) //
+ .compression(COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
- Assertions.assertNotNull(consumerDmaapModel);
- Assertions.assertEquals(PRODUCT_NAME, consumerDmaapModel.getProductName());
- Assertions.assertEquals(VENDOR_NAME, consumerDmaapModel.getVendorName());
- Assertions.assertEquals(LAST_EPOCH_MICROSEC, consumerDmaapModel.getLastEpochMicrosec());
- Assertions.assertEquals(SOURCE_NAME, consumerDmaapModel.getSourceName());
- Assertions.assertEquals(START_EPOCH_MICROSEC, consumerDmaapModel.getStartEpochMicrosec());
- Assertions.assertEquals(TIME_ZONE_OFFSET, consumerDmaapModel.getTimeZoneOffset());
- Assertions.assertEquals(NAME, consumerDmaapModel.getName());
- Assertions.assertEquals(LOCATION, consumerDmaapModel.getLocation());
- Assertions.assertEquals(INTERNAL_LOCATION, consumerDmaapModel.getInternalLocation());
- Assertions.assertEquals(COMPRESSION, consumerDmaapModel.getCompression());
- Assertions.assertEquals(FILE_FORMAT_TYPE, consumerDmaapModel.getFileFormatType());
- Assertions.assertEquals(FILE_FORMAT_VERSION, consumerDmaapModel.getFileFormatVersion());
+ Assertions.assertNotNull(filePublishInformation);
+ Assertions.assertEquals(PRODUCT_NAME, filePublishInformation.getProductName());
+ Assertions.assertEquals(VENDOR_NAME, filePublishInformation.getVendorName());
+ Assertions.assertEquals(LAST_EPOCH_MICROSEC, filePublishInformation.getLastEpochMicrosec());
+ Assertions.assertEquals(SOURCE_NAME, filePublishInformation.getSourceName());
+ Assertions.assertEquals(START_EPOCH_MICROSEC, filePublishInformation.getStartEpochMicrosec());
+ Assertions.assertEquals(TIME_ZONE_OFFSET, filePublishInformation.getTimeZoneOffset());
+ Assertions.assertEquals(NAME, filePublishInformation.getName());
+ Assertions.assertEquals(LOCATION, filePublishInformation.getLocation());
+ Assertions.assertEquals(INTERNAL_LOCATION, filePublishInformation.getInternalLocation());
+ Assertions.assertEquals(COMPRESSION, filePublishInformation.getCompression());
+ Assertions.assertEquals(FILE_FORMAT_TYPE, filePublishInformation.getFileFormatType());
+ Assertions.assertEquals(FILE_FORMAT_VERSION, filePublishInformation.getFileFormatVersion());
}
}
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
-
-
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
import org.springframework.web.reactive.function.client.WebClient;
-class DmaapReactiveWebClientTest {
+class DmaapWebClientTest {
@Mock
private DmaapConsumerConfiguration dmaapConsumerConfiguration;
dmaapConsumerConfiguration = mock(DmaapConsumerConfiguration.class);
}
-
@Test
void buildsDMaaPReactiveWebClientProperly() {
when(dmaapConsumerConfiguration.dmaapContentType()).thenReturn("*/*");
- WebClient dmaapReactiveWebClient = new DmaapReactiveWebClient()
- .fromConfiguration(dmaapConsumerConfiguration)
+ WebClient dmaapWebClient = new DmaapWebClient() //
+ .fromConfiguration(dmaapConsumerConfiguration) //
.build();
verify(dmaapConsumerConfiguration, times(1)).dmaapContentType();
- assertNotNull(dmaapReactiveWebClient);
+ assertNotNull(dmaapWebClient);
}
-}
\ No newline at end of file
+}
public void shouldReturnBadResponse() {
assertFalse(HttpUtils.isSuccessfulResponseCode(404));
}
-}
\ No newline at end of file
+}
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
-
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.dcaegen2.collectors.datafile.ftp.Scheme;
import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField;
-
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
/**
+ * Tests the JsonMessageParser.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
.compression(GZIP_COMPRESSION) //
.fileFormatType(FILE_FORMAT_TYPE) //
.fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData)
+ .messageMetaData(messageMetaData) //
.build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
- FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder()
+ FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() //
.files(files) //
.build();
.compression(GZIP_COMPRESSION) //
.fileFormatType(FILE_FORMAT_TYPE) //
.fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData)
+ .messageMetaData(messageMetaData) //
.build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
.compression(GZIP_COMPRESSION) //
.fileFormatType(FILE_FORMAT_TYPE) //
.fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData)
+ .messageMetaData(messageMetaData) //
.build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
.compression(GZIP_COMPRESSION) //
.fileFormatType(FILE_FORMAT_TYPE) //
.fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData)
+ .messageMetaData(messageMetaData) //
.build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
.name(PM_FILE_NAME) //
.location(LOCATION) //
- .compression(GZIP_COMPRESSION)
+ .compression(GZIP_COMPRESSION) //
.fileFormatVersion(FILE_FORMAT_VERSION) //
.build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
-/*
+/*-
* ============LICENSE_START======================================================================
* Copyright (C) 2019 Nordix Foundation. All rights reserved.
* ===============================================================================================
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Instant;
-
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Future;
-
import javax.net.ssl.SSLContext;
-
import org.apache.commons.codec.binary.Base64;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
-import org.onap.dcaegen2.collectors.datafile.http.IHttpAsyncClientBuilder;
+import org.onap.dcaegen2.collectors.datafile.http.HttpAsyncClientBuilderWrapper;
import org.onap.dcaegen2.collectors.datafile.web.PublishRedirectStrategy;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
/**
+ * Test for DmaapProducerHttpClient.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(DmaapPublisherConfiguration.class);
- private IHttpAsyncClientBuilder clientBuilderMock;
+ private HttpAsyncClientBuilderWrapper clientBuilderMock;
private CloseableHttpAsyncClient clientMock;
@SuppressWarnings("unchecked")
producerClientUnderTestSpy = spy(new DmaapProducerHttpClient(dmaapPublisherConfigurationMock));
- clientBuilderMock = mock(IHttpAsyncClientBuilder.class);
+ clientBuilderMock = mock(HttpAsyncClientBuilderWrapper.class);
clientMock = mock(CloseableHttpAsyncClient.class);
}
@Test
void getHttpResponseWithRederict_Success() throws Exception {
doReturn(clientBuilderMock).when(producerClientUnderTestSpy).getHttpClientBuilder();
- when(clientBuilderMock.setSSLContext(any(SSLContext.class))).thenReturn(clientBuilderMock);
- when(clientBuilderMock.setSSLHostnameVerifier(any(NoopHostnameVerifier.class))).thenReturn(clientBuilderMock);
+ when(clientBuilderMock.setSslContext(any(SSLContext.class))).thenReturn(clientBuilderMock);
+ when(clientBuilderMock.setSslHostnameVerifier(any(NoopHostnameVerifier.class))).thenReturn(clientBuilderMock);
when(clientBuilderMock.build()).thenReturn(clientMock);
when(clientMock.execute(any(HttpUriRequest.class), any())).thenReturn(futureMock);
HttpResponse responseMock = mock(HttpResponse.class);
HttpGet request = new HttpGet();
producerClientUnderTestSpy.getDmaapProducerResponseWithRedirect(request, CONTEXT_MAP);
- verify(clientBuilderMock).setSSLContext(any(SSLContext.class));
- verify(clientBuilderMock).setSSLHostnameVerifier(any(NoopHostnameVerifier.class));
+ verify(clientBuilderMock).setSslContext(any(SSLContext.class));
+ verify(clientBuilderMock).setSslHostnameVerifier(any(NoopHostnameVerifier.class));
verify(clientBuilderMock).setRedirectStrategy(PublishRedirectStrategy.INSTANCE);
verify(clientBuilderMock).setDefaultRequestConfig(any());
verify(clientBuilderMock).build();
@Test
void getHttpResponseWithCustomTimeout_Success() throws Exception {
doReturn(clientBuilderMock).when(producerClientUnderTestSpy).getHttpClientBuilder();
- when(clientBuilderMock.setSSLContext(any(SSLContext.class))).thenReturn(clientBuilderMock);
+ when(clientBuilderMock.setSslContext(any(SSLContext.class))).thenReturn(clientBuilderMock);
when(clientBuilderMock.setDefaultRequestConfig(any(RequestConfig.class))).thenReturn(clientBuilderMock);
when(clientBuilderMock.build()).thenReturn(clientMock);
when(clientMock.execute(any(HttpUriRequest.class), any())).thenReturn(futureMock);
producerClientUnderTestSpy.getDmaapProducerResponseWithCustomTimeout(request, TWO_SECOND_TIMEOUT, CONTEXT_MAP);
ArgumentCaptor<RequestConfig> requestConfigCaptor = ArgumentCaptor.forClass(RequestConfig.class);
- verify(clientBuilderMock).setSSLContext(any(SSLContext.class));
- verify(clientBuilderMock).setSSLHostnameVerifier(any(NoopHostnameVerifier.class));
+ verify(clientBuilderMock).setSslContext(any(SSLContext.class));
+ verify(clientBuilderMock).setSslHostnameVerifier(any(NoopHostnameVerifier.class));
verify(clientBuilderMock).setDefaultRequestConfig(requestConfigCaptor.capture());
RequestConfig requestConfig = requestConfigCaptor.getValue();
assertEquals(TWO_SECOND_TIMEOUT.toMillis(), requestConfig.getSocketTimeout());
public void getResponseWithException_throwsException() throws Exception {
doReturn(clientBuilderMock).when(producerClientUnderTestSpy).getHttpClientBuilder();
when(clientBuilderMock.setDefaultRequestConfig(any(RequestConfig.class))).thenReturn(clientBuilderMock);
- when(clientBuilderMock.setSSLContext(any(SSLContext.class))).thenReturn(clientBuilderMock);
+ when(clientBuilderMock.setSslContext(any(SSLContext.class))).thenReturn(clientBuilderMock);
when(clientBuilderMock.build()).thenReturn(clientMock);
HttpPut request = new HttpPut();
when(clientMock.execute(any(HttpPut.class), any())).thenReturn(futureMock);
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
-
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.ftp.Scheme;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.model.FileData;
+import org.onap.dcaegen2.collectors.datafile.model.FilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.FileReadyMessage;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileData;
+import org.onap.dcaegen2.collectors.datafile.model.ImmutableFilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileReadyMessage;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableMessageMetaData;
import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer.DMaaPConsumerReactiveHttpClient;
-
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
-/**
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- */
-public class DMaaPMessageConsumerTaskImplTest {
+public class DMaaPMessageConsumerTest {
private static final String NR_RADIO_ERICSSON_EVENT_NAME = "Noti_NrRadio-Ericsson_FileReady";
private static final String PRODUCT_NAME = "NrRadio";
private static final String VENDOR_NAME = "Ericsson";
private static final String GZIP_COMPRESSION = "gzip";
private static final String MEAS_COLLECT_FILE_FORMAT_TYPE = "org.3GPP.32.435#measCollec";
private static final String FILE_FORMAT_VERSION = "V10";
- private static List<ConsumerDmaapModel> listOfConsumerDmaapModel = new ArrayList<ConsumerDmaapModel>();
+ private static List<FilePublishInformation> listOfFilePublishInformation = new ArrayList<FilePublishInformation>();
- private DMaaPMessageConsumerTask messageConsumerTask;
private DMaaPConsumerReactiveHttpClient httpClientMock;
+ private DMaaPMessageConsumer messageConsumer;
private static String ftpesMessageString;
private static FileData ftpesFileData;
private static FileReadyMessage expectedFtpesMessage;
*/
@BeforeAll
public static void setUp() {
-
AdditionalField ftpesAdditionalField = new JsonMessage.AdditionalFieldBuilder() //
.location(FTPES_LOCATION) //
.compression(GZIP_COMPRESSION) //
.compression(GZIP_COMPRESSION) //
.fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
.fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData)
+ .messageMetaData(messageMetaData) //
.build();
List<FileData> files = new ArrayList<>();
.compression(GZIP_COMPRESSION) //
.fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
.fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData)
+ .messageMetaData(messageMetaData) //
.build();
- ImmutableConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder() //
+ ImmutableFilePublishInformation filePublishInformation = ImmutableFilePublishInformation.builder() //
.productName(PRODUCT_NAME) //
.vendorName(VENDOR_NAME) //
.lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
.fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
.fileFormatVersion(FILE_FORMAT_VERSION) //
.build();
- listOfConsumerDmaapModel.add(consumerDmaapModel);
+ listOfFilePublishInformation.add(filePublishInformation);
files = new ArrayList<>();
files.add(sftpFileData);
public void whenPassedObjectDoesntFit_ThrowsDatafileTaskException() {
prepareMocksForDmaapConsumer("", null);
- StepVerifier.create(messageConsumerTask.execute()) //
+ StepVerifier.create(messageConsumer.getMessageRouterResponse()) //
.expectSubscription() //
.expectError(DatafileTaskException.class) //
.verify();
public void whenFtpes_ReturnsCorrectResponse() throws DatafileTaskException {
prepareMocksForDmaapConsumer(ftpesMessageString, expectedFtpesMessage);
- StepVerifier.create(messageConsumerTask.execute()) //
+ StepVerifier.create(messageConsumer.getMessageRouterResponse()) //
.expectNext(expectedFtpesMessage) //
.verifyComplete();
public void whenSftp_ReturnsCorrectResponse() throws DatafileTaskException {
prepareMocksForDmaapConsumer(sftpMessageString, expectedSftpMessage);
- StepVerifier.create(messageConsumerTask.execute()) //
+ StepVerifier.create(messageConsumer.getMessageRouterResponse()) //
.expectNext(expectedSftpMessage) //
.verifyComplete();
.thenReturn(Flux.error(new DatafileTaskException("problemas")));
}
- messageConsumerTask = spy(new DMaaPMessageConsumerTask(httpClientMock, jsonMessageParserMock));
+ messageConsumer = spy(new DMaaPMessageConsumer(httpClientMock, jsonMessageParserMock));
}
}
import org.mockito.ArgumentCaptor;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.model.FilePublishInformation;
+import org.onap.dcaegen2.collectors.datafile.model.ImmutableFilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.service.producer.DmaapProducerHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
import org.springframework.http.HttpStatus;
import reactor.test.StepVerifier;
/**
+ * Tests the DataRouter publisher.
+ *
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
private static final String FEED_ID = "1";
private static final String FILE_CONTENT = "Just a string.";
- private static ConsumerDmaapModel consumerDmaapModel;
+ private static FilePublishInformation filePublishInformation;
private static DmaapProducerHttpClient httpClientMock;
private static AppConfig appConfig;
private static DmaapPublisherConfiguration publisherConfigurationMock = mock(DmaapPublisherConfiguration.class);
private final Map<String, String> contextMap = new HashMap<>();
private static DataRouterPublisher publisherTaskUnderTestSpy;
- /**
- * Sets up data for tests.
- */
@BeforeAll
public static void setUp() {
when(publisherConfigurationMock.dmaapHostName()).thenReturn(HOST);
when(publisherConfigurationMock.dmaapProtocol()).thenReturn(HTTPS_SCHEME);
when(publisherConfigurationMock.dmaapPortNumber()).thenReturn(PORT);
- consumerDmaapModel = ImmutableConsumerDmaapModel.builder() //
+ filePublishInformation = ImmutableFilePublishInformation.builder() //
.productName(PRODUCT_NAME) //
.vendorName(VENDOR_NAME) //
.lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
public void whenPassedObjectFits_ReturnsCorrectStatus() throws Exception {
prepareMocksForTests(null, Integer.valueOf(HttpStatus.OK.value()));
StepVerifier
- .create(publisherTaskUnderTestSpy.execute(consumerDmaapModel, 1, Duration.ofSeconds(0), contextMap))
- .expectNext(consumerDmaapModel) //
+ .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0),
+ contextMap))
+ .expectNext(filePublishInformation) //
.verifyComplete();
ArgumentCaptor<HttpUriRequest> requestCaptor = ArgumentCaptor.forClass(HttpUriRequest.class);
prepareMocksForTests(new DatafileTaskException("Error"), HttpStatus.OK.value());
StepVerifier
- .create(publisherTaskUnderTestSpy.execute(consumerDmaapModel, 2, Duration.ofSeconds(0), contextMap))
- .expectNext(consumerDmaapModel) //
+ .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 2, Duration.ofSeconds(0),
+ contextMap))
+ .expectNext(filePublishInformation) //
.verifyComplete();
}
Integer.valueOf(HttpStatus.OK.value()));
StepVerifier
- .create(publisherTaskUnderTestSpy.execute(consumerDmaapModel, 1, Duration.ofSeconds(0), contextMap))
- .expectNext(consumerDmaapModel) //
+ .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0),
+ contextMap))
+ .expectNext(filePublishInformation) //
.verifyComplete();
verify(httpClientMock, times(2)).getBaseUri();
Integer.valueOf((HttpStatus.BAD_GATEWAY.value())));
StepVerifier
- .create(publisherTaskUnderTestSpy.execute(consumerDmaapModel, 1, Duration.ofSeconds(0), contextMap))
+ .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0),
+ contextMap))
.expectErrorMessage("Retries exhausted: 1/1") //
.verify();
import org.onap.dcaegen2.collectors.datafile.ftp.FtpsClient;
import org.onap.dcaegen2.collectors.datafile.ftp.Scheme;
import org.onap.dcaegen2.collectors.datafile.ftp.SftpClient;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.model.FileData;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
+import org.onap.dcaegen2.collectors.datafile.model.FilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileData;
+import org.onap.dcaegen2.collectors.datafile.model.ImmutableFilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableMessageMetaData;
import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData;
import reactor.test.StepVerifier;
-/**
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- *
- */
public class FileCollectorTest {
private static final String PRODUCT_NAME = "NrRadio";
private static final String VENDOR_NAME = "Ericsson";
private static final String SERVER_ADDRESS = "192.168.0.101";
private static final int PORT_22 = 22;
private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz";
- private static final String REMOTE_FILE_LOCATION = "/ftp/rop/" + PM_FILE_NAME;
private static final Path LOCAL_FILE_LOCATION = Paths.get(FileData.DATAFILE_TMPDIR, PM_FILE_NAME);
+ private static final String REMOTE_FILE_LOCATION = "/ftp/rop/" + PM_FILE_NAME;
private static final String USER = "usr";
private static final String PWD = "pwd";
private static final String FTPES_LOCATION =
private MessageMetaData createMessageMetaData() {
- // @formatter:off
- return ImmutableMessageMetaData.builder()
- .productName(PRODUCT_NAME)
- .vendorName(VENDOR_NAME)
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC)
- .sourceName(SOURCE_NAME)
- .startEpochMicrosec(START_EPOCH_MICROSEC)
- .timeZoneOffset(TIME_ZONE_OFFSET)
- .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER)
- .changeType(FILE_READY_CHANGE_TYPE)
+ return ImmutableMessageMetaData.builder() //
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
+ .changeType(FILE_READY_CHANGE_TYPE) //
.build();
- // @formatter:on
}
private FileData createFileData(String location, Scheme scheme) {
- // @formatter:off
- return ImmutableFileData.builder()
- .name(PM_FILE_NAME)
- .location(location)
- .compression(GZIP_COMPRESSION)
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE)
- .fileFormatVersion(FILE_FORMAT_VERSION)
- .scheme(scheme)
- .messageMetaData(createMessageMetaData())
- .build();
- // @formatter:on
+ return ImmutableFileData.builder() //
+ .name(PM_FILE_NAME) //
+ .location(location) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .scheme(scheme) //
+ .messageMetaData(createMessageMetaData()) //
+ .build();
}
- private ConsumerDmaapModel createExpectedConsumerDmaapModel(String location) {
- // @formatter:off
- return ImmutableConsumerDmaapModel.builder()
- .productName(PRODUCT_NAME)
- .vendorName(VENDOR_NAME)
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC)
- .sourceName(SOURCE_NAME)
- .startEpochMicrosec(START_EPOCH_MICROSEC)
- .timeZoneOffset(TIME_ZONE_OFFSET)
- .name(PM_FILE_NAME)
- .location(location)
- .internalLocation(LOCAL_FILE_LOCATION)
- .compression(GZIP_COMPRESSION)
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE)
- .fileFormatVersion(FILE_FORMAT_VERSION)
- .build();
- // @formatter:on
+ private FilePublishInformation createExpectedFilePublishInformation(String location) {
+ return ImmutableFilePublishInformation.builder() //
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .name(PM_FILE_NAME) //
+ .location(location) //
+ .internalLocation(LOCAL_FILE_LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
}
+ /**
+ * Sets up the configuration.
+ */
@BeforeAll
public static void setUpConfiguration() {
when(appConfigMock.getFtpesConfiguration()).thenReturn(ftpesConfigMock);
when(ftpesConfigMock.keyCert()).thenReturn(FTP_KEY_PATH);
when(ftpesConfigMock.keyPassword()).thenReturn(FTP_KEY_PASSWORD);
- when(ftpesConfigMock.trustedCA()).thenReturn(TRUSTED_CA_PATH);
- when(ftpesConfigMock.trustedCAPassword()).thenReturn(TRUSTED_CA_PASSWORD);
+ when(ftpesConfigMock.trustedCa()).thenReturn(TRUSTED_CA_PATH);
+ when(ftpesConfigMock.trustedCaPassword()).thenReturn(TRUSTED_CA_PASSWORD);
}
@Test
FileData fileData = createFileData(FTPES_LOCATION_NO_PORT, Scheme.FTPS);
- ConsumerDmaapModel expectedConsumerDmaapModel = createExpectedConsumerDmaapModel(FTPES_LOCATION_NO_PORT);
+ FilePublishInformation expectedfilePublishInformation =
+ createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
- StepVerifier.create(
- collectorUndetTest.execute(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedConsumerDmaapModel).verifyComplete();
+ StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
verify(ftpsClientMock, times(1)).open();
verify(ftpsClientMock, times(1)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
FileData fileData = createFileData(SFTP_LOCATION_NO_PORT, Scheme.SFTP);
- ConsumerDmaapModel expectedConsumerDmaapModel = createExpectedConsumerDmaapModel(SFTP_LOCATION_NO_PORT);
+ FilePublishInformation expectedfilePublishInformation =
+ createExpectedFilePublishInformation(SFTP_LOCATION_NO_PORT);
- StepVerifier
- .create(collectorUndetTest.execute(fileData, 3, Duration.ofSeconds(0),
- contextMap))
- .expectNext(expectedConsumerDmaapModel) //
+ StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
+ .expectNext(expectedfilePublishInformation) //
.verifyComplete();
// The same again, but with port
fileData = createFileData(SFTP_LOCATION, Scheme.SFTP);
- expectedConsumerDmaapModel = createExpectedConsumerDmaapModel(SFTP_LOCATION);
+ expectedfilePublishInformation = createExpectedFilePublishInformation(SFTP_LOCATION);
- StepVerifier
- .create(collectorUndetTest.execute(fileData, 3, Duration.ofSeconds(0),
- contextMap))
- .expectNext(expectedConsumerDmaapModel) //
+ StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
+ .expectNext(expectedfilePublishInformation) //
.verifyComplete();
verify(sftpClientMock, times(2)).open();
doThrow(new DatafileTaskException("Unable to collect file.")).when(ftpsClientMock)
.collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
- StepVerifier.create(
- collectorUndetTest.execute(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectErrorMessage("Retries exhausted: 3/3").verify();
+ StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
+ .expectErrorMessage("Retries exhausted: 3/3") //
+ .verify();
verify(ftpsClientMock, times(4)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
}
doThrow(new DatafileTaskException("Unable to collect file.")).doNothing().when(ftpsClientMock)
.collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
- ConsumerDmaapModel expectedConsumerDmaapModel = createExpectedConsumerDmaapModel(FTPES_LOCATION_NO_PORT);
+ FilePublishInformation expectedfilePublishInformation =
+ createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
FileData fileData = createFileData(FTPES_LOCATION_NO_PORT, Scheme.FTPS);
- StepVerifier.create(
- collectorUndetTest.execute(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedConsumerDmaapModel).verifyComplete();
+ StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
verify(ftpsClientMock, times(2)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
}
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriBuilder;
-/**
- * @author <a href="mailto:maxime.bonneau@est.tech">Maxime Bonneau</a>
- *
- */
public class PublishedCheckerTest {
private static final String EMPTY_CONTENT = "[]";
private static final String FEEDLOG_TOPIC = "feedlog";
public void executeWhenNotPublished_returnsFalse() throws Exception {
prepareMocksForTests(HttpUtils.SC_OK, EMPTY_CONTENT, null);
- boolean isPublished = publishedCheckerUnderTestSpy.execute(LOCAL_FILE_NAME, CONTEXT_MAP);
+ boolean isPublished = publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CONTEXT_MAP);
assertFalse(isPublished);
public void executeWhenDataRouterReturnsNok_returnsFalse() throws Exception {
prepareMocksForTests(HttpUtils.SC_BAD_REQUEST, EMPTY_CONTENT, null);
- boolean isPublished = publishedCheckerUnderTestSpy.execute(LOCAL_FILE_NAME, CONTEXT_MAP);
+ boolean isPublished = publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CONTEXT_MAP);
assertFalse(isPublished);
}
public void executeWhenPublished_returnsTrue() throws Exception {
prepareMocksForTests(HttpUtils.SC_OK, "[" + LOCAL_FILE_NAME + "]", null);
- boolean isPublished = publishedCheckerUnderTestSpy.execute(LOCAL_FILE_NAME, CONTEXT_MAP);
+ boolean isPublished = publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CONTEXT_MAP);
assertTrue(isPublished);
}
public void executeWhenErrorInDataRouter_returnsFalse() throws Exception {
prepareMocksForTests(HttpUtils.SC_OK, EMPTY_CONTENT, new DatafileTaskException(""));
- boolean isPublished = publishedCheckerUnderTestSpy.execute(LOCAL_FILE_NAME, CONTEXT_MAP);
+ boolean isPublished = publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CONTEXT_MAP);
assertFalse(isPublished);
}
-/*
- * ============LICENSE_START======================================================================
- * Copyright (C) 2019 Nordix Foundation. All rights reserved.
- * ===============================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- * ============LICENSE_END========================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
*/
package org.onap.dcaegen2.collectors.datafile.tasks;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.ftp.Scheme;
-import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.model.FileData;
+import org.onap.dcaegen2.collectors.datafile.model.FilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.FileReadyMessage;
-import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileData;
+import org.onap.dcaegen2.collectors.datafile.model.ImmutableFilePublishInformation;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileReadyMessage;
import org.onap.dcaegen2.collectors.datafile.model.ImmutableMessageMetaData;
import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
-
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
private ScheduledTasks testedObject = spy(new ScheduledTasks(appConfig));
private int uniqueValue = 0;
- private DMaaPMessageConsumerTask consumerMock;
+ private DMaaPMessageConsumer consumerMock;
private PublishedChecker publishedCheckerMock;
private FileCollector fileCollectorMock;
private DataRouterPublisher dataRouterMock;
.build(); //
doReturn(dmaapPublisherConfiguration).when(appConfig).getDmaapPublisherConfiguration();
- consumerMock = mock(DMaaPMessageConsumerTask.class);
+ consumerMock = mock(DMaaPMessageConsumer.class);
publishedCheckerMock = mock(PublishedChecker.class);
fileCollectorMock = mock(FileCollector.class);
dataRouterMock = mock(DataRouterPublisher.class);
.location("ftpes://192.168.0.101/ftp/rop/" + PM_FILE_NAME + instanceNumber) //
.scheme(Scheme.FTPS) //
.compression("") //
- .messageMetaData(messageMetaData())
+ .messageMetaData(messageMetaData()) //
.build();
}
return Flux.fromIterable(list);
}
- private ConsumerDmaapModel consumerData() {
- return ImmutableConsumerDmaapModel //
+ private FilePublishInformation filePublishInformation() {
+ return ImmutableFilePublishInformation //
.builder() //
.productName("") //
.vendorName("") //
@Test
public void notingToConsume() {
doReturn(consumerMock).when(testedObject).createConsumerTask();
- doReturn(Flux.empty()).when(consumerMock).execute();
+ doReturn(Flux.empty()).when(consumerMock).getMessageRouterResponse();
testedObject.executeDatafileMainTask();
assertEquals(0, testedObject.getCurrentNumberOfTasks());
- verify(consumerMock, times(1)).execute();
+ verify(consumerMock, times(1)).getMessageRouterResponse();
verifyNoMoreInteractions(consumerMock);
}
final int noOfFiles = noOfEvents * noOfFilesPerEvent;
Flux<FileReadyMessage> fileReadyMessages = fileReadyMessageFlux(noOfEvents, noOfFilesPerEvent, true);
- doReturn(fileReadyMessages).when(consumerMock).execute();
+ doReturn(fileReadyMessages).when(consumerMock).getMessageRouterResponse();
- doReturn(false).when(publishedCheckerMock).execute(anyString(), any());
+ doReturn(false).when(publishedCheckerMock).isFilePublished(anyString(), any());
- Mono<ConsumerDmaapModel> collectedFile = Mono.just(consumerData());
- doReturn(collectedFile).when(fileCollectorMock).execute(notNull(), anyLong(), notNull(), notNull());
- doReturn(collectedFile).when(dataRouterMock).execute(notNull(), anyLong(), notNull(), any());
+ Mono<FilePublishInformation> collectedFile = Mono.just(filePublishInformation());
+ doReturn(collectedFile).when(fileCollectorMock).collectFile(notNull(), anyLong(), notNull(), notNull());
+ doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull(), any());
StepVerifier.create(testedObject.createMainTask(contextMap)).expectSubscription() //
.expectNextCount(noOfFiles) //
.verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
- verify(consumerMock, times(1)).execute();
- verify(fileCollectorMock, times(noOfFiles)).execute(notNull(), anyLong(), notNull(), notNull());
- verify(dataRouterMock, times(noOfFiles)).execute(notNull(), anyLong(), notNull(), any());
+ verify(consumerMock, times(1)).getMessageRouterResponse();
+ verify(fileCollectorMock, times(noOfFiles)).collectFile(notNull(), anyLong(), notNull(), notNull());
+ verify(dataRouterMock, times(noOfFiles)).publishFile(notNull(), anyLong(), notNull(), any());
verifyNoMoreInteractions(dataRouterMock);
verifyNoMoreInteractions(fileCollectorMock);
verifyNoMoreInteractions(consumerMock);
@Test
public void consume_fetchFailedOnce() {
Flux<FileReadyMessage> fileReadyMessages = fileReadyMessageFlux(2, 2, true); // 4 files
- doReturn(fileReadyMessages).when(consumerMock).execute();
+ doReturn(fileReadyMessages).when(consumerMock).getMessageRouterResponse();
- doReturn(false).when(publishedCheckerMock).execute(anyString(), any());
+ doReturn(false).when(publishedCheckerMock).isFilePublished(anyString(), any());
- Mono<ConsumerDmaapModel> collectedFile = Mono.just(consumerData());
+ Mono<FilePublishInformation> collectedFile = Mono.just(filePublishInformation());
Mono<Object> error = Mono.error(new Exception("problem"));
// First file collect will fail, 3 will succeed
doReturn(error, collectedFile, collectedFile, collectedFile) //
.when(fileCollectorMock) //
- .execute(any(FileData.class), anyLong(), any(Duration.class), notNull());
+ .collectFile(any(FileData.class), anyLong(), any(Duration.class), notNull());
- doReturn(collectedFile).when(dataRouterMock).execute(notNull(), anyLong(), notNull(), any());
- doReturn(collectedFile).when(dataRouterMock).execute(notNull(), anyLong(), notNull(), any());
+ doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull(), any());
+ doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull(), any());
StepVerifier.create(testedObject.createMainTask(contextMap)).expectSubscription() //
.expectNextCount(3) //
.verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
- verify(consumerMock, times(1)).execute();
- verify(fileCollectorMock, times(4)).execute(notNull(), anyLong(), notNull(), notNull());
- verify(dataRouterMock, times(3)).execute(notNull(), anyLong(), notNull(), any());
+ verify(consumerMock, times(1)).getMessageRouterResponse();
+ verify(fileCollectorMock, times(4)).collectFile(notNull(), anyLong(), notNull(), notNull());
+ verify(dataRouterMock, times(3)).publishFile(notNull(), anyLong(), notNull(), any());
verifyNoMoreInteractions(dataRouterMock);
verifyNoMoreInteractions(fileCollectorMock);
verifyNoMoreInteractions(consumerMock);
public void consume_publishFailedOnce() {
Flux<FileReadyMessage> fileReadyMessages = fileReadyMessageFlux(2, 2, true); // 4 files
- doReturn(fileReadyMessages).when(consumerMock).execute();
+ doReturn(fileReadyMessages).when(consumerMock).getMessageRouterResponse();
- doReturn(false).when(publishedCheckerMock).execute(anyString(), any());
+ doReturn(false).when(publishedCheckerMock).isFilePublished(anyString(), any());
- Mono<ConsumerDmaapModel> collectedFile = Mono.just(consumerData());
- doReturn(collectedFile).when(fileCollectorMock).execute(notNull(), anyLong(), notNull(), notNull());
+ Mono<FilePublishInformation> collectedFile = Mono.just(filePublishInformation());
+ doReturn(collectedFile).when(fileCollectorMock).collectFile(notNull(), anyLong(), notNull(), notNull());
Mono<Object> error = Mono.error(new Exception("problem"));
// One publish will fail, the rest will succeed
doReturn(collectedFile, error, collectedFile, collectedFile) //
.when(dataRouterMock) //
- .execute(notNull(), anyLong(), notNull(), any());
+ .publishFile(notNull(), anyLong(), notNull(), any());
StepVerifier.create(testedObject.createMainTask(contextMap)).expectSubscription() //
.expectNextCount(3) // 3 completed files
.verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
- verify(consumerMock, times(1)).execute();
- verify(fileCollectorMock, times(4)).execute(notNull(), anyLong(), notNull(), notNull());
- verify(dataRouterMock, times(4)).execute(notNull(), anyLong(), notNull(), any());
+ verify(consumerMock, times(1)).getMessageRouterResponse();
+ verify(fileCollectorMock, times(4)).collectFile(notNull(), anyLong(), notNull(), notNull());
+ verify(dataRouterMock, times(4)).publishFile(notNull(), anyLong(), notNull(), any());
verifyNoMoreInteractions(dataRouterMock);
verifyNoMoreInteractions(fileCollectorMock);
verifyNoMoreInteractions(consumerMock);
// 100 files with the same name
Flux<FileReadyMessage> fileReadyMessages = fileReadyMessageFlux(noOfEvents, noOfFilesPerEvent, false);
- doReturn(fileReadyMessages).when(consumerMock).execute();
+ doReturn(fileReadyMessages).when(consumerMock).getMessageRouterResponse();
- doReturn(false).when(publishedCheckerMock).execute(anyString(), any());
+ doReturn(false).when(publishedCheckerMock).isFilePublished(anyString(), any());
- Mono<ConsumerDmaapModel> collectedFile = Mono.just(consumerData());
- doReturn(collectedFile).when(fileCollectorMock).execute(notNull(), anyLong(), notNull(), notNull());
- doReturn(collectedFile).when(dataRouterMock).execute(notNull(), anyLong(), notNull(), any());
+ Mono<FilePublishInformation> collectedFile = Mono.just(filePublishInformation());
+ doReturn(collectedFile).when(fileCollectorMock).collectFile(notNull(), anyLong(), notNull(), notNull());
+ doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull(), any());
StepVerifier.create(testedObject.createMainTask(contextMap)).expectSubscription() //
.expectNextCount(1) // 99 is skipped
.verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
- verify(consumerMock, times(1)).execute();
- verify(fileCollectorMock, times(1)).execute(notNull(), anyLong(), notNull(), notNull());
- verify(dataRouterMock, times(1)).execute(notNull(), anyLong(), notNull(), any());
+ verify(consumerMock, times(1)).getMessageRouterResponse();
+ verify(fileCollectorMock, times(1)).collectFile(notNull(), anyLong(), notNull(), notNull());
+ verify(dataRouterMock, times(1)).publishFile(notNull(), anyLong(), notNull(), any());
verifyNoMoreInteractions(dataRouterMock);
verifyNoMoreInteractions(fileCollectorMock);
verifyNoMoreInteractions(consumerMock);
}
-
-
}
-/*
- * ============LICENSE_START======================================================================
- * Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
- * ===============================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
+/*-
+ * ============LICENSE_START=======================================================
+ * 2018-2019 Nordix Foundation. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- * ============LICENSE_END========================================================================
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
*/
package org.onap.dcaegen2.collectors.datafile.utils;
}
additionalFieldsString.append("]");
}
- // @formatter:off
- return "{" + "\"event\":{"
- + "\"commonEventHeader\":{"
- + "\"domain\":\"notification\","
- + "\"eventId\":\"<<SerialNumber>>-reg\","
- + "\"eventName\":\"" + eventName + "\","
- + "\"eventType\":\"fileReady\","
- + "\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,"
- + "\"nfNamingCode\":\"5GRAN\","
- + "\"nfcNamingCode\":\"5DU\","
- + "\"priority\":\"Normal\","
- + "\"reportingEntityName\":\"5GRAN_DU\","
- + "\"sequence\":0,"
- + "\"sourceId\":\"<<SerialNumber>>\","
- + "\"sourceName\":\"5GRAN_DU\","
- + "\"timeZoneOffset\":\"UTC+05:00\","
- + "\"startEpochMicrosec\":\"1519837825682\","
- + "\"version\":3"
- + "},"
- + "\"notificationFields\":{"
+ return "{" //
+ + "\"event\":" //
+ + "{" //
+ + "\"commonEventHeader\":" //
+ + "{" //
+ + "\"domain\":\"notification\"," //
+ + "\"eventId\":\"<<SerialNumber>>-reg\"," //
+ + "\"eventName\":\"" + eventName + "\"," //
+ + "\"eventType\":\"fileReady\"," //
+ + "\"internalHeaderFields\":{}," //
+ + "\"lastEpochMicrosec\":1519837825682," //
+ + "\"nfNamingCode\":\"5GRAN\"," //
+ + "\"nfcNamingCode\":\"5DU\"," //
+ + "\"priority\":\"Normal\"," //
+ + "\"reportingEntityName\":\"5GRAN_DU\"," //
+ + "\"sequence\":0," //
+ + "\"sourceId\":\"<<SerialNumber>>\"," //
+ + "\"sourceName\":\"5GRAN_DU\"," //
+ + "\"timeZoneOffset\":\"UTC+05:00\"," //
+ + "\"startEpochMicrosec\":\"1519837825682\"," //
+ + "\"version\":3" //
+ + "}," //
+ + "\"notificationFields\":" //
+ + "{" //
+ getAsStringIfParameterIsSet("changeIdentifier", changeIdentifier,
changeType != null || notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0)
+ getAsStringIfParameterIsSet("changeType", changeType,
notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0)
+ getAsStringIfParameterIsSet("notificationFieldsVersion", notificationFieldsVersion,
arrayOfAdditionalFields.size() > 0)
- + additionalFieldsString.toString() + "}" + "}" + "}";
- // @formatter:on
+ + additionalFieldsString.toString() //
+ + "}" //
+ + "}" //
+ + "}";
}
private JsonMessage(final JsonMessageBuilder builder) {
@Override
public String toString() {
- return "{" + getAsStringIfParameterIsSet("name", name, true) + "\"hashMap\":{"
+ return "{" //
+ + getAsStringIfParameterIsSet("name", name, true) //
+ + "\"hashMap\":" //
+ + "{"
+ getAsStringIfParameterIsSet("location", location,
compression != null || fileFormatType != null || fileFormatVersion != null)
+ getAsStringIfParameterIsSet("compression", compression,
fileFormatType != null || fileFormatVersion != null)
+ getAsStringIfParameterIsSet("fileFormatType", fileFormatType, fileFormatVersion != null)
- + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) + "}}";
+ + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) //
+ + "}" //
+ + "}";
}
-
private AdditionalField(AdditionalFieldBuilder builder) {
this.name = builder.name;
this.location = builder.location;
/**
* Can be used to produce a correct test Json message. Tip! Check the formatting with
- * <a href="https://jsonformatter.org/">Json fomatter</a>
+ * <a href="https://jsonformatter.org/">Json formatter</a>
*
* @param args Not used
*/
public static void main(String[] args) {
- // @formatter:off
- AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder()
- .name("A20161224.1030-1045.bin.gz")
- .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz")
- .compression("gzip")
- .fileFormatType("org.3GPP.32.435#measCollec")
- .fileFormatVersion("V10")
+ AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
+ .name("A20161224.1030-1045.bin.gz") //
+ .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz") //
+ .compression("gzip") //
+ .fileFormatType("org.3GPP.32.435#measCollec") //
+ .fileFormatVersion("V10") //
.build();
- AdditionalField secondAdditionalField = new JsonMessage.AdditionalFieldBuilder()
- .name("A20161224.1030-1045.bin.gz")
- .location("sftp://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz")
- .compression("gzip")
- .fileFormatType("org.3GPP.32.435#measCollec")
- .fileFormatVersion("V10")
+ AdditionalField secondAdditionalField = new JsonMessage.AdditionalFieldBuilder() //
+ .name("A20161224.1030-1045.bin.gz") //
+ .location("sftp://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz") //
+ .compression("gzip") //
+ .fileFormatType("org.3GPP.32.435#measCollec") //
+ .fileFormatVersion("V10") //
.build();
- JsonMessage message = new JsonMessage.JsonMessageBuilder()
- .eventName("Noti_NrRadio-Ericsson_FileReady")
- .changeIdentifier("PM_MEAS_FILES")
- .changeType("FileReady")
- .notificationFieldsVersion("2.0")
- .addAdditionalField(additionalField)
- .addAdditionalField(secondAdditionalField)
+ JsonMessage message = new JsonMessage.JsonMessageBuilder() //
+ .eventName("Noti_NrRadio-Ericsson_FileReady") //
+ .changeIdentifier("PM_MEAS_FILES") //
+ .changeType("FileReady") //
+ .notificationFieldsVersion("2.0") //
+ .addAdditionalField(additionalField) //
+ .addAdditionalField(secondAdditionalField) //
.build();
- // @formatter:on
System.out.println(message.toString());
}
}
private static PublishRedirectStrategy publishRedirectStrategy;
-
@BeforeAll
static void setUp() {
publishRedirectStrategy = new PublishRedirectStrategy();
"ftpesConfiguration": {
"keyCert": "/config/dfc.jks",
"keyPassword": "secret",
- "trustedCA": "/config/ftp.jks",
- "trustedCAPassword": "secret"
+ "trustedCa": "/config/ftp.jks",
+ "trustedCaPassword": "secret"
}
},
"security": {
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ ============LICENSE_START=======================================================
- ~ Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
- ~ ================================================================================
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- ~ ============LICENSE_END=========================================================
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.dcaegen2.collectors</groupId>
- <artifactId>datafile</artifactId>
- <version>1.1.1-SNAPSHOT</version>
- </parent>
-
- <groupId>org.onap.dcaegen2.collectors.datafile</groupId>
- <artifactId>datafile-commons</artifactId>
- <packaging>jar</packaging>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
- <artifactId>common-dependency</artifactId>
- </dependency>
- <dependency>
- <groupId>org.immutables</groupId>
- <artifactId>value</artifactId>
- </dependency>
- <dependency>
- <groupId>org.immutables</groupId>
- <artifactId>gson</artifactId>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jul-to-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>log4j-over-slf4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- </dependency>
- </dependencies>
-</project>
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018-2019 Nordix Foundation. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.model;
-
-import org.immutables.gson.Gson;
-import org.immutables.value.Value;
-
-/**
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- */
-@Value.Immutable
-@Gson.TypeAdapters
-public interface FileMetaData {
- String productName();
-
- String vendorName();
-
- String lastEpochMicrosec();
-
- String sourceName();
-
- String startEpochMicrosec();
-
- String timeZoneOffset();
-
- String changeIdentifier();
-
- String changeType();
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ ============LICENSE_START=======================================================
- ~ Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
- ~ ================================================================================
- ~ Licensed under the Apache License, Version 2.0 (the "License");
- ~ you may not use this file except in compliance with the License.
- ~ You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- ~ ============LICENSE_END=========================================================
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.dcaegen2.collectors</groupId>
- <artifactId>datafile</artifactId>
- <version>1.1.1-SNAPSHOT</version>
- </parent>
-
- <groupId>org.onap.dcaegen2.collectors.datafile</groupId>
- <artifactId>datafile-dmaap-client</artifactId>
- <packaging>jar</packaging>
-
-
- <properties>
- <main.basedir>${project.parent.basedir}</main.basedir>
- </properties>
-
- <dependencies>
- <!-- DEVELOPMENT DEPENDENCIES -->
- <dependency>
- <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId>
- <artifactId>dmaap-client</artifactId>
- </dependency>
- <dependency>
- <groupId>org.asynchttpclient</groupId>
- <artifactId>async-http-client</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpasyncclient</artifactId>
- </dependency>
- <dependency>
- <groupId>org.onap.dcaegen2.collectors.datafile</groupId>
- <artifactId>datafile-commons</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.immutables</groupId>
- <artifactId>value</artifactId>
- </dependency>
- <dependency>
- <groupId>org.immutables</groupId>
- <artifactId>gson</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-webflux</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-reactor-netty</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- </dependency>
- <dependency>
- <groupId>com.jcraft</groupId>
- <artifactId>jsch</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-net</groupId>
- <artifactId>commons-net</artifactId>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
-
- <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpmime</artifactId>
- </dependency>
- <dependency>
- <groupId>io.projectreactor</groupId>
- <artifactId>reactor-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.github.stefanbirkner</groupId>
- <artifactId>fake-sftp-server-rule</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.google.code.findbugs</groupId>
- <artifactId>jsr305</artifactId>
- <version>2.0.1</version>
- </dependency>
- </dependencies>
-</project>
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.http;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLContext;
-
-import org.apache.http.client.RedirectStrategy;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
-
-/**
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- */
-public interface IHttpAsyncClientBuilder {
- public IHttpAsyncClientBuilder setRedirectStrategy(final RedirectStrategy redirectStrategy);
-
- public IHttpAsyncClientBuilder setSSLContext(final SSLContext sslcontext);
-
- public IHttpAsyncClientBuilder setSSLHostnameVerifier(final HostnameVerifier hostnameVerifier);
-
- public IHttpAsyncClientBuilder setDefaultRequestConfig(final RequestConfig config);
-
- public CloseableHttpAsyncClient build();
-}
</properties>
<modules>
- <module>datafile-commons</module>
- <module>datafile-dmaap-client</module>
<module>datafile-app-server</module>
</modules>