* @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 {
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.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
+
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
+
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.EnvProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
+
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@Autowired
public synchronized void setCloudConfigurationProvider(
- CloudConfigurationProvider reactiveCloudConfigurationProvider) {
+ CloudConfigurationProvider reactiveCloudConfigurationProvider) {
this.cloudConfigurationProvider = reactiveCloudConfigurationProvider;
}
loadConfigurationFromFile();
refreshConfigTask = Flux.interval(Duration.ZERO, Duration.ofMinutes(5))
- .flatMap(count -> createRefreshConfigurationTask(count, context))
- .subscribe(e -> logger.info("Refreshed configuration data"),
- throwable -> logger.error("Configuration refresh terminated due to exception", throwable),
- () -> logger.error("Configuration refresh terminated"));
+ .flatMap(count -> createRefreshConfigurationTask(count, context))
+ .subscribe(e -> logger.info("Refreshed configuration data"),
+ throwable -> logger.error("Configuration refresh terminated due to exception", throwable),
+ () -> logger.error("Configuration refresh terminated"));
}
public void stop() {
}
public synchronized PublisherConfiguration getPublisherConfiguration(String changeIdentifier)
- throws DatafileTaskException {
+ throws DatafileTaskException {
if (publishingConfiguration == null) {
throw new DatafileTaskException("No PublishingConfiguration loaded, changeIdentifier: " + changeIdentifier);
PublisherConfiguration cfg = publishingConfiguration.get(changeIdentifier);
if (cfg == null) {
throw new DatafileTaskException(
- "Cannot find getPublishingConfiguration for changeIdentifier: " + changeIdentifier);
+ "Cannot find getPublishingConfiguration for changeIdentifier: " + changeIdentifier);
}
return cfg;
}
Flux<AppConfig> createRefreshConfigurationTask(Long counter, Map<String, String> context) {
return Flux.just(counter) //
- .doOnNext(cnt -> logger.debug("Refresh config {}", cnt)) //
- .flatMap(cnt -> readEnvironmentVariables(systemEnvironment, context)) //
- .flatMap(this::fetchConfiguration);
+ .doOnNext(cnt -> logger.debug("Refresh config {}", cnt)) //
+ .flatMap(cnt -> readEnvironmentVariables(systemEnvironment, context)) //
+ .flatMap(this::fetchConfiguration);
}
Mono<EnvProperties> readEnvironmentVariables(Properties systemEnvironment, Map<String, String> context) {
return EnvironmentProcessor.readEnvironmentVariables(systemEnvironment, context)
- .onErrorResume(AppConfig::onErrorResume);
+ .onErrorResume(AppConfig::onErrorResume);
}
private static <R> Mono<R> onErrorResume(Throwable trowable) {
private Mono<AppConfig> fetchConfiguration(EnvProperties env) {
Mono<JsonObject> serviceCfg = cloudConfigurationProvider.callForServiceConfigurationReactive(env) //
- .onErrorResume(AppConfig::onErrorResume);
+ .onErrorResume(AppConfig::onErrorResume);
// Note, have to use this callForServiceConfigurationReactive with EnvProperties, since the
// other ones does not work
EnvProperties dmaapEnv = ImmutableEnvProperties.builder() //
- .consulHost(env.consulHost()) //
- .consulPort(env.consulPort()) //
- .cbsName(env.cbsName()) //
- .appName(env.appName() + ":dmaap") //
- .build(); //
+ .consulHost(env.consulHost()) //
+ .consulPort(env.consulPort()) //
+ .cbsName(env.cbsName()) //
+ .appName(env.appName() + ":dmaap") //
+ .build(); //
Mono<JsonObject> dmaapCfg = cloudConfigurationProvider.callForServiceConfigurationReactive(dmaapEnv)
- .onErrorResume(t -> Mono.just(new JsonObject()));
+ .onErrorResume(t -> Mono.just(new JsonObject()));
return serviceCfg.zipWith(dmaapCfg, this::parseCloudConfig) //
- .onErrorResume(AppConfig::onErrorResume);
+ .onErrorResume(AppConfig::onErrorResume);
}
/**
try {
CloudConfigParser parser = new CloudConfigParser(serviceConfigRootObject, dmaapConfigRootObject);
setConfiguration(parser.getDmaapConsumerConfig(), parser.getDmaapPublisherConfig(),
- parser.getFtpesConfig());
+ parser.getFtpesConfig());
} catch (DatafileTaskException e) {
logger.error("Could not parse configuration {}", e.toString(), e);
}
}
private synchronized void setConfiguration(ConsumerConfiguration consumerConfiguration,
- Map<String, PublisherConfiguration> publisherConfiguration, FtpesConfig ftpesConfig) {
+ Map<String, PublisherConfiguration> publisherConfiguration, FtpesConfig ftpesConfig) {
if (consumerConfiguration == null || publisherConfiguration == null || ftpesConfig == null) {
logger.error(
- "Problem with configuration consumerConfiguration: {}, publisherConfiguration: {}, ftpesConfig: {}",
- consumerConfiguration, publisherConfiguration, ftpesConfig);
+ "Problem with configuration consumerConfiguration: {}, publisherConfiguration: {}, ftpesConfig: {}",
+ consumerConfiguration, publisherConfiguration, ftpesConfig);
} else {
this.dmaapConsumerConfiguration = consumerConfiguration;
this.publishingConfiguration = publisherConfiguration;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
+import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
/**
* Parses the cloud configuration.
public Map<String, PublisherConfiguration> getDmaapPublisherConfig() throws DatafileTaskException {
Iterator<JsonElement> producerCfgs =
- toArray(serviceConfigurationRoot.get("dmaap.dmaapProducerConfiguration")).iterator();
+ toArray(serviceConfigurationRoot.get("dmaap.dmaapProducerConfiguration")).iterator();
Map<String, PublisherConfiguration> result = new HashMap<>();
JsonObject feedConfig = getFeedConfig(feedName);
PublisherConfiguration cfg = ImmutablePublisherConfiguration.builder() //
- .publishUrl(getAsString(feedConfig, "publish_url")) //
- .passWord(getAsString(feedConfig, "password")) //
- .userName(getAsString(feedConfig, "username")) //
- .trustStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PATH)) //
- .trustStorePasswordPath(
- getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PASS_PATH)) //
- .keyStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PATH)) //
- .keyStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PASS_PATH)) //
- .enableDmaapCertAuth(
- get(serviceConfigurationRoot, DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) //
- .changeIdentifier(getAsString(producerCfg, "changeIdentifier")) //
- .logUrl(getAsString(feedConfig, "log_url")) //
- .build();
+ .publishUrl(getAsString(feedConfig, "publish_url")) //
+ .passWord(getAsString(feedConfig, "password")) //
+ .userName(getAsString(feedConfig, "username")) //
+ .trustStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PATH)) //
+ .trustStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PASS_PATH)) //
+ .keyStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PATH)) //
+ .keyStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PASS_PATH)) //
+ .enableDmaapCertAuth(
+ get(serviceConfigurationRoot, DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) //
+ .changeIdentifier(getAsString(producerCfg, "changeIdentifier")) //
+ .logUrl(getAsString(feedConfig, "log_url")) //
+ .build();
result.put(cfg.changeIdentifier(), cfg);
}
String topicUrl = getAsString(dmaapInfo, "topic_url");
return ImmutableConsumerConfiguration.builder().topicUrl(topicUrl)
- .trustStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PATH))
- .trustStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PASS_PATH))
- .keyStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PATH))
- .keyStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PASS_PATH))
- .enableDmaapCertAuth(
- get(serviceConfigurationRoot, DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) //
- .build();
+ .trustStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PATH))
+ .trustStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PASS_PATH))
+ .keyStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PATH))
+ .keyStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PASS_PATH))
+ .enableDmaapCertAuth(get(serviceConfigurationRoot, DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) //
+ .build();
}
public FtpesConfig getFtpesConfig() throws DatafileTaskException {
return new ImmutableFtpesConfig.Builder() //
- .keyCert(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.keyCert"))
- .keyPassword(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.keyPassword"))
- .trustedCa(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.trustedCa"))
- .trustedCaPassword(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.trustedCaPassword")) //
- .build();
+ .keyCert(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.keyCert"))
+ .keyPassword(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.keyPassword"))
+ .trustedCa(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.trustedCa"))
+ .trustedCaPassword(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.trustedCaPassword")) //
+ .build();
}
private static JsonElement get(JsonObject obj, String memberName) throws DatafileTaskException {
import java.net.MalformedURLException;
import java.net.URL;
+
import org.immutables.gson.Gson;
import org.immutables.value.Value;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
DmaapConsumerUrlPath path = parseDmaapUrlPath(urlPath);
return new ImmutableDmaapConsumerConfiguration.Builder() //
- .dmaapContentType("application/json") //
- .dmaapPortNumber(url.getPort()) //
- .dmaapHostName(url.getHost()) //
- .dmaapTopicName(path.dmaapTopicName) //
- .dmaapProtocol(url.getProtocol()) //
- .dmaapUserName(userName) //
- .dmaapUserPassword(passwd) //
- .trustStorePath(this.trustStorePath()) //
- .trustStorePasswordPath(this.trustStorePasswordPath()) //
- .keyStorePath(this.keyStorePath()) //
- .keyStorePasswordPath(this.keyStorePasswordPath()) //
- .enableDmaapCertAuth(this.enableDmaapCertAuth()) //
- .consumerId(path.consumerId) //
- .consumerGroup(path.consumerGroup) //
- .timeoutMs(-1) //
- .messageLimit(-1) //
- .build();
+ .dmaapContentType("application/json") //
+ .dmaapPortNumber(url.getPort()) //
+ .dmaapHostName(url.getHost()) //
+ .dmaapTopicName(path.dmaapTopicName) //
+ .dmaapProtocol(url.getProtocol()) //
+ .dmaapUserName(userName) //
+ .dmaapUserPassword(passwd) //
+ .trustStorePath(this.trustStorePath()) //
+ .trustStorePasswordPath(this.trustStorePasswordPath()) //
+ .keyStorePath(this.keyStorePath()) //
+ .keyStorePasswordPath(this.keyStorePasswordPath()) //
+ .enableDmaapCertAuth(this.enableDmaapCertAuth()) //
+ .consumerId(path.consumerId) //
+ .consumerGroup(path.consumerGroup) //
+ .timeoutMs(-1) //
+ .messageLimit(-1) //
+ .build();
} catch (MalformedURLException e) {
throw new DatafileTaskException("Could not parse the URL", e);
}
}
private DmaapConsumerUrlPath parseDmaapUrlPath(String urlPath) throws DatafileTaskException {
- String[] tokens = urlPath.split("/"); // UrlPath: /events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12
+ String[] tokens = urlPath.split("/"); // UrlPath:
+ // /events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12
if (tokens.length != 5) {
throw new DatafileTaskException("The path has incorrect syntax: " + urlPath);
}
- final String dmaapTopicName = tokens[1] + "/" + tokens[2]; // e.g. /events/unauthenticated.VES_NOTIFICATION_OUTPUT
+ final String dmaapTopicName = tokens[1] + "/" + tokens[2]; // e.g.
+ // /events/unauthenticated.VES_NOTIFICATION_OUTPUT
final String consumerGroup = tokens[3]; // ex. OpenDcae-c12
final String consumerId = tokens[4]; // ex. C12
return new DmaapConsumerUrlPath(dmaapTopicName, consumerGroup, consumerId);
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
-
import reactor.core.publisher.Mono;
/**
private static final int DEFAULT_CONSUL_PORT = 8500;
private static final Logger logger = LoggerFactory.getLogger(EnvironmentProcessor.class);
- private EnvironmentProcessor() {}
+ private EnvironmentProcessor() {
+ }
static Mono<EnvProperties> readEnvironmentVariables(Properties systemEnvironment, Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
EnvProperties envProperties;
try {
envProperties = ImmutableEnvProperties.builder() //
- .consulHost(getConsulHost(systemEnvironment)) //
- .consulPort(getConsultPort(systemEnvironment)) //
- .cbsName(getConfigBindingService(systemEnvironment)) //
- .appName(getService(systemEnvironment)) //
- .build();
+ .consulHost(getConsulHost(systemEnvironment)) //
+ .consulPort(getConsultPort(systemEnvironment)) //
+ .cbsName(getConfigBindingService(systemEnvironment)) //
+ .appName(getService(systemEnvironment)) //
+ .build();
} catch (EnvironmentLoaderException e) {
return Mono.error(e);
}
private static String getConsulHost(Properties systemEnvironments) throws EnvironmentLoaderException {
return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_HOST"))
- .orElseThrow(() -> new EnvironmentLoaderException("$CONSUL_HOST environment has not been defined"));
+ .orElseThrow(() -> new EnvironmentLoaderException("$CONSUL_HOST environment has not been defined"));
}
private static Integer getConsultPort(Properties systemEnvironments) {
return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_PORT")) //
- .map(Integer::valueOf) //
- .orElseGet(EnvironmentProcessor::getDefaultPortOfConsul);
+ .map(Integer::valueOf) //
+ .orElseGet(EnvironmentProcessor::getDefaultPortOfConsul);
}
private static String getConfigBindingService(Properties systemEnvironments) throws EnvironmentLoaderException {
return Optional.ofNullable(systemEnvironments.getProperty("CONFIG_BINDING_SERVICE")) //
- .orElseThrow(() -> new EnvironmentLoaderException(
- "$CONFIG_BINDING_SERVICE environment has not been defined"));
+ .orElseThrow(
+ () -> new EnvironmentLoaderException("$CONFIG_BINDING_SERVICE environment has not been defined"));
}
private static String getService(Properties systemEnvironments) throws EnvironmentLoaderException {
return Optional
- .ofNullable(Optional.ofNullable(systemEnvironments.getProperty("HOSTNAME"))
- .orElse(systemEnvironments.getProperty("SERVICE_NAME")))
- .orElseThrow(() -> new EnvironmentLoaderException(
- "Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment"));
+ .ofNullable(Optional.ofNullable(systemEnvironments.getProperty("HOSTNAME"))
+ .orElse(systemEnvironments.getProperty("SERVICE_NAME")))
+ .orElseThrow(() -> new EnvironmentLoaderException(
+ "Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment"));
}
private static Integer getDefaultPortOfConsul() {
import org.immutables.value.Value;
import org.springframework.stereotype.Component;
-
@Component
@Value.Immutable
@Value.Style(builder = "new", redactedMask = "####")
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
-
@Value.Immutable
@Value.Style(redactedMask = "####")
@Gson.TypeAdapters
String urlPath = url.getPath();
return new ImmutableDmaapPublisherConfiguration.Builder() //
- .dmaapContentType("application/octet-stream") //
- .dmaapPortNumber(url.getPort()) //
- .dmaapHostName(url.getHost()) //
- .dmaapTopicName(urlPath) //
- .dmaapProtocol(url.getProtocol()) //
- .dmaapUserName(this.userName()) //
- .dmaapUserPassword(this.passWord()) //
- .trustStorePath(this.trustStorePath()) //
- .trustStorePasswordPath(this.trustStorePasswordPath()) //
- .keyStorePath(this.keyStorePath()) //
- .keyStorePasswordPath(this.keyStorePasswordPath()) //
- .enableDmaapCertAuth(this.enableDmaapCertAuth()) //
- .build();
+ .dmaapContentType("application/octet-stream") //
+ .dmaapPortNumber(url.getPort()) //
+ .dmaapHostName(url.getHost()) //
+ .dmaapTopicName(urlPath) //
+ .dmaapProtocol(url.getProtocol()) //
+ .dmaapUserName(this.userName()) //
+ .dmaapUserPassword(this.passWord()) //
+ .trustStorePath(this.trustStorePath()) //
+ .trustStorePasswordPath(this.trustStorePasswordPath()) //
+ .keyStorePath(this.keyStorePath()) //
+ .keyStorePasswordPath(this.keyStorePasswordPath()) //
+ .enableDmaapCertAuth(this.enableDmaapCertAuth()) //
+ .build();
}
}
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.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;
* @param configuration The DFC configuration.
*/
@Autowired
- public SchedulerConfig(TaskScheduler taskScheduler, ScheduledTasks scheduledTasks,
- AppConfig configuration) {
+ public SchedulerConfig(TaskScheduler taskScheduler, ScheduledTasks scheduledTasks, AppConfig configuration) {
this.taskScheduler = taskScheduler;
this.scheduledTask = scheduledTasks;
this.configuration = configuration;
if (scheduledFutureList.isEmpty()) {
scheduledFutureList.add(taskScheduler.scheduleWithFixedDelay(scheduledTask::executeDatafileMainTask,
- SCHEDULING_DELAY_FOR_DATAFILE_COLLECTOR_TASKS));
- scheduledFutureList
- .add(taskScheduler.scheduleWithFixedDelay(() -> scheduledTask.purgeCachedInformation(Instant.now()),
- SCHEDULING_DELAY_FOR_DATAFILE_PURGE_CACHE));
+ SCHEDULING_DELAY_FOR_DATAFILE_COLLECTOR_TASKS));
+ scheduledFutureList.add(taskScheduler.scheduleWithFixedDelay(
+ () -> scheduledTask.purgeCachedInformation(Instant.now()), SCHEDULING_DELAY_FOR_DATAFILE_PURGE_CACHE));
return true;
} else {
return false;
package org.onap.dcaegen2.collectors.datafile.configuration;
import com.google.common.base.Predicates;
+
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
-
@EnableSwagger2
@Configuration
@Profile("prod")
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2) //
- .apiInfo(apiInfo()) //
- .select() //
- .apis(RequestHandlerSelectors.any()) //
- .paths(PathSelectors.any()) //
- .paths(Predicates.not(PathSelectors.regex("/error"))) //
- // this endpoint is not implemented, but was visible for Swagger
- .build();
+ .apiInfo(apiInfo()) //
+ .select() //
+ .apis(RequestHandlerSelectors.any()) //
+ .paths(PathSelectors.any()) //
+ .paths(Predicates.not(PathSelectors.regex("/error"))) //
+ // this endpoint is not implemented, but was visible for Swagger
+ .build();
}
private static ApiInfo apiInfo() {
return new ApiInfoBuilder() //
- .title(API_TITLE) //
- .description(DESCRIPTION) //
- .version(VERSION) //
- .build();
+ .title(API_TITLE) //
+ .description(DESCRIPTION) //
+ .version(VERSION) //
+ .build();
}
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(SWAGGER_UI) //
- .addResourceLocations(RESOURCES_PATH);
+ .addResourceLocations(RESOURCES_PATH);
registry.addResourceHandler(WEBJARS) //
- .addResourceLocations(WEBJARS_PATH);
+ .addResourceLocations(WEBJARS_PATH);
}
}
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;
public Mono<ResponseEntity<String>> startTasks() {
return Mono.fromSupplier(schedulerConfig::tryToStartTask) //
- .map(ScheduleController::createStartTaskResponse);
+ .map(ScheduleController::createStartTaskResponse);
}
/**
public Mono<ResponseEntity<String>> stopTask(@RequestHeader HttpHeaders headers) {
MappedDiagnosticContext.initializeTraceContext(headers);
logger.info(MappedDiagnosticContext.ENTRY, "Stop request");
- Mono<ResponseEntity<String>> response = schedulerConfig.getResponseFromCancellationOfTasks();
+ Mono<ResponseEntity<String>> response = schedulerConfig.getResponseFromCancellationOfTasks();
logger.info(MappedDiagnosticContext.EXIT, "Stop request");
return response;
}
import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.ENTRY;
import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.EXIT;
-import org.onap.dcaegen2.collectors.datafile.model.Counters;
-
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.Counters;
import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext;
import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks;
import org.slf4j.Logger;
*/
@GetMapping("/heartbeat")
@ApiOperation(value = "Returns liveness of DATAFILE service")
- @ApiResponses(value = { //
+ @ApiResponses(
+ value = { //
@ApiResponse(code = 200, message = "DATAFILE service is living"),
@ApiResponse(code = 401, message = "You are not authorized to view the resource"),
@ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
*/
@GetMapping("/status")
@ApiOperation(value = "Returns status and statistics of DATAFILE service")
- @ApiResponses(value = { //
+ @ApiResponses(
+ value = { //
@ApiResponse(code = 200, message = "DATAFILE service is living"),
@ApiResponse(code = 401, message = "You are not authorized to view the resource"),
@ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
return response;
}
-
-
}
package org.onap.dcaegen2.collectors.datafile.exceptions;
-
public class NonRetryableDatafileTaskException extends DatafileTaskException {
private static final long serialVersionUID = 1L;
package org.onap.dcaegen2.collectors.datafile.ftp;
import java.nio.file.Path;
+
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
/**
*
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
-public interface FileCollectClient extends AutoCloseable {
+public interface FileCollectClient extends AutoCloseable {
public void collectFile(String remoteFile, Path localFile) throws DatafileTaskException;
public void open() throws DatafileTaskException;
* @param trustedCaPassword password for the PNF's trusted keystore.
*/
public FtpsClient(FileServerData fileServerData, String keyCertPath, String keyCertPassword, Path trustedCaPath,
- String trustedCaPassword) {
+ String trustedCaPassword) {
this.fileServerData = fileServerData;
this.keyCertPath = keyCertPath;
this.keyCertPassword = keyCertPassword;
try (OutputStream output = createOutputStream(localFileName)) {
logger.trace("begin to retrieve from xNF.");
if (!realFtpsClient.retrieveFile(remoteFileName, output)) {
- throw new NonRetryableDatafileTaskException("Could not retrieve file. No retry attempts will be done, file :" + remoteFileName);
+ throw new NonRetryableDatafileTaskException(
+ "Could not retrieve file. No retry attempts will be done, file :" + remoteFileName);
}
} catch (IOException e) {
throw new DatafileTaskException("Could not fetch file: " + e, e);
realFtpsClient.setBufferSize(1024 * 1024);
} else {
throw new DatafileTaskException("Unable to connect to xNF. " + fileServerData.serverAddress()
- + " xNF reply code: " + realFtpsClient.getReplyCode());
+ + " xNF reply code: " + realFtpsClient.getReplyCode());
}
logger.trace("setUpConnection successfully!");
}
private TrustManager createTrustManager(Path trustedCaPath, String trustedCaPassword)
- throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException {
+ throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException {
logger.trace("Creating trust manager from file: {}", trustedCaPath);
try (InputStream fis = createInputStream(trustedCaPath)) {
KeyStore keyStore = KeyStore.getInstance("JKS");
}
protected TrustManager getTrustManager(Path trustedCaPath, String trustedCaPassword)
- throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException {
+ throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException {
synchronized (FtpsClient.class) {
if (theTrustManager == null) {
theTrustManager = createTrustManager(trustedCaPath, trustedCaPassword);
}
protected KeyManager createKeyManager(String keyCertPath, String keyCertPassword)
- throws IOException, GeneralSecurityException {
+ throws IOException, GeneralSecurityException {
return KeyManagerUtils.createClientKeyManager(new File(keyCertPath), keyCertPassword);
}
}
FTPS, SFTP;
public static final String DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG = "DFC does not support protocol ";
- public static final String SUPPORTED_PROTOCOLS_ERROR_MESSAGE =
- ". Supported protocols are FTPES, FTPS, and SFTP";
+ public static final String SUPPORTED_PROTOCOLS_ERROR_MESSAGE = ". Supported protocols are FTPES, FTPS, and SFTP";
/**
* Get a <code>Scheme</code> from a string.
} else if ("SFTP".equalsIgnoreCase(schemeString)) {
result = Scheme.SFTP;
} else {
- throw new DatafileTaskException(DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + schemeString
- + SUPPORTED_PROTOCOLS_ERROR_MESSAGE);
+ throw new DatafileTaskException(
+ DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + schemeString + SUPPORTED_PROTOCOLS_ERROR_MESSAGE);
}
return result;
}
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
+
import java.nio.file.Path;
import java.util.Optional;
+
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.exceptions.NonRetryableDatafileTaskException;
import org.slf4j.Logger;
logger.trace("File {} Download Successfull from xNF", localFile.getFileName());
} catch (SftpException e) {
boolean retry = e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE && e.id != ChannelSftp.SSH_FX_PERMISSION_DENIED
- && e.id != ChannelSftp.SSH_FX_OP_UNSUPPORTED;
+ && e.id != ChannelSftp.SSH_FX_OP_UNSUPPORTED;
if (retry) {
throw new DatafileTaskException("Unable to get file from xNF. Data: " + fileServerData, e);
} else {
throw new NonRetryableDatafileTaskException(
- "Unable to get file from xNF. No retry attempts will be done. Data: " + fileServerData, e);
+ "Unable to get file from xNF. No retry attempts will be done. Data: " + fileServerData, e);
}
}
throw new DatafileTaskException("Could not open Sftp client. " + e);
} else {
throw new NonRetryableDatafileTaskException(
- "Could not open Sftp client, no retry attempts will be done " + e);
+ "Could not open Sftp client, no retry attempts will be done " + e);
}
}
}
private Session setUpSession(FileServerData fileServerData) throws JSchException {
JSch jsch = createJsch();
- 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 java.time.Instant;
import java.util.concurrent.atomic.AtomicInteger;
-
/**
*
* Various counters that can be shown via a REST API.
URI uri = URI.create(location());
Optional<String[]> userInfo = getUserNameAndPasswordIfGiven(uri.getUserInfo());
ImmutableFileServerData.Builder builder = ImmutableFileServerData.builder() //
- .serverAddress(uri.getHost()) //
- .userId(userInfo.isPresent() ? userInfo.get()[0] : "") //
- .password(userInfo.isPresent() ? userInfo.get()[1] : "");
+ .serverAddress(uri.getHost()) //
+ .userId(userInfo.isPresent() ? userInfo.get()[0] : "") //
+ .password(userInfo.isPresent() ? userInfo.get()[1] : "");
if (uri.getPort() > 0) {
builder.port(uri.getPort());
}
@Value.Immutable
@Gson.TypeAdapters
@Value.Style(redactedMask = "####")
-public interface FilePublishInformation {
+public interface FilePublishInformation {
@SerializedName("productName")
String getProductName();
package org.onap.dcaegen2.collectors.datafile.model;
import java.util.List;
+
import org.immutables.gson.Gson;
import org.immutables.value.Value;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+
import java.util.Set;
/**
public abstract class JsonSerializer {
private static Gson gson = new GsonBuilder() //
- .serializeNulls() //
- .addSerializationExclusionStrategy(new FilePublishInformationExclusionStrategy()) //
- .create(); //
+ .serializeNulls() //
+ .addSerializationExclusionStrategy(new FilePublishInformationExclusionStrategy()) //
+ .create(); //
- private JsonSerializer() {}
+ private JsonSerializer() {
+ }
/**
* Serializes a <code>filePublishInformation</code>.
* Elements in FilePublishInformation to include in the file publishing Json string.
*/
private final Set<String> inclusions =
- Sets.newHashSet("productName", "vendorName", "lastEpochMicrosec", "sourceName", "startEpochMicrosec",
- "timeZoneOffset", "location", "compression", "fileFormatType", "fileFormatVersion");
+ Sets.newHashSet("productName", "vendorName", "lastEpochMicrosec", "sourceName", "startEpochMicrosec",
+ "timeZoneOffset", "location", "compression", "fileFormatType", "fileFormatVersion");
@Override
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
private static final Logger logger = LoggerFactory.getLogger(MappedDiagnosticContext.class);
- private MappedDiagnosticContext() {}
+ private MappedDiagnosticContext() {
+ }
/**
* Inserts the relevant trace information in the HTTP header.
/**
* Initialize the MDC when a new context is started.
+ *
* @return a copy of the new trace context
*/
public static Map<String, String> initializeTraceContext() {
/**
* Updates the request ID in the current context.
+ *
* @param newRequestId the new value of the request ID
* @return a copy the updated context
*/
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClient.Builder;
-
import reactor.core.publisher.Mono;
/**
MDC.put(SERVICE_NAME, String.valueOf(clientRequest.url()));
logger.trace("Request: {} {}", clientRequest.method(), clientRequest.url());
clientRequest.headers()
- .forEach((name, values) -> values.forEach(value -> logger.trace("{}={}", name, value)));
+ .forEach((name, values) -> values.forEach(value -> logger.trace("{}={}", name, value)));
logger.trace("HTTP request headers: {}", clientRequest.headers());
MDC.remove(SERVICE_NAME);
return Mono.just(clientRequest);
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;
private Flux<FileReadyMessage> getMessagesFromJsonArray(JsonElement jsonElement) {
return createMessages(Flux.fromStream(StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false)
- .map(jsonElementFromArray -> getJsonObjectFromAnArray(jsonElementFromArray)
- .orElseGet(JsonObject::new))));
+ .map(jsonElementFromArray -> getJsonObjectFromAnArray(jsonElementFromArray).orElseGet(JsonObject::new))));
}
/**
*/
private Flux<FileReadyMessage> createMessageData(JsonElement jsonElement) {
return jsonElement.isJsonObject() ? createMessages(Flux.just(jsonElement.getAsJsonObject()))
- : getMessagesFromJsonArray(jsonElement);
+ : getMessagesFromJsonArray(jsonElement);
}
private static Mono<JsonElement> getJsonParserMessage(String message) {
private static Flux<FileReadyMessage> createMessages(Flux<JsonObject> jsonObject) {
return jsonObject.flatMap(monoJsonP -> containsNotificationFields(monoJsonP) ? transformMessages(monoJsonP)
- : logErrorAndReturnEmptyMessageFlux("Incorrect JsonObject - missing header. " + jsonObject));
+ : logErrorAndReturnEmptyMessageFlux("Incorrect JsonObject - missing header. " + jsonObject));
}
-
private static Mono<FileReadyMessage> transformMessages(JsonObject message) {
Optional<MessageMetaData> optionalMessageMetaData = getMessageMetaData(message);
if (optionalMessageMetaData.isPresent()) {
List<FileData> allFileDataFromJson = getAllFileDataFromJson(arrayOfNamedHashMap, messageMetaData);
if (!allFileDataFromJson.isEmpty()) {
return Mono.just(ImmutableFileReadyMessage.builder() //
- .files(allFileDataFromJson) //
- .build());
+ .files(allFileDataFromJson) //
+ .build());
} else {
return Mono.empty();
}
return Mono.empty();
}
-
private static Optional<MessageMetaData> getMessageMetaData(JsonObject message) {
List<String> missingValues = new ArrayList<>();
JsonObject commonEventHeader = message.getAsJsonObject(EVENT).getAsJsonObject(COMMON_EVENT_HEADER);
getValueFromJson(notificationFields, NOTIFICATION_FIELDS_VERSION, missingValues);
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(getDataFromEventName(EventNameDataType.PRODUCT_NAME, eventName, missingValues)) //
- .vendorName(getDataFromEventName(EventNameDataType.VENDOR_NAME, eventName, missingValues)) //
- .lastEpochMicrosec(getValueFromJson(commonEventHeader, LAST_EPOCH_MICROSEC, missingValues)) //
- .sourceName(getValueFromJson(commonEventHeader, SOURCE_NAME, missingValues)) //
- .startEpochMicrosec(getValueFromJson(commonEventHeader, START_EPOCH_MICROSEC, missingValues)) //
- .timeZoneOffset(getValueFromJson(commonEventHeader, TIME_ZONE_OFFSET, missingValues)) //
- .changeIdentifier(changeIdentifier) //
- .changeType(changeType) //
- .build();
+ .productName(getDataFromEventName(EventNameDataType.PRODUCT_NAME, eventName, missingValues)) //
+ .vendorName(getDataFromEventName(EventNameDataType.VENDOR_NAME, eventName, missingValues)) //
+ .lastEpochMicrosec(getValueFromJson(commonEventHeader, LAST_EPOCH_MICROSEC, missingValues)) //
+ .sourceName(getValueFromJson(commonEventHeader, SOURCE_NAME, missingValues)) //
+ .startEpochMicrosec(getValueFromJson(commonEventHeader, START_EPOCH_MICROSEC, missingValues)) //
+ .timeZoneOffset(getValueFromJson(commonEventHeader, TIME_ZONE_OFFSET, missingValues)) //
+ .changeIdentifier(changeIdentifier) //
+ .changeType(changeType) //
+ .build();
if (missingValues.isEmpty() && isChangeTypeCorrect(changeType)) {
return Optional.of(messageMetaData);
} else {
}
private static List<FileData> getAllFileDataFromJson(JsonArray arrayOfAdditionalFields,
- MessageMetaData messageMetaData) {
+ MessageMetaData messageMetaData) {
List<FileData> res = new ArrayList<>();
for (int i = 0; i < arrayOfAdditionalFields.size(); i++) {
JsonObject fileInfo = (JsonObject) arrayOfAdditionalFields.get(i);
String location = getValueFromJson(data, LOCATION, missingValues);
if (StringUtils.isEmpty(location)) {
logger.error(ERROR_MSG_VES_EVENT_PARSING + "File information wrong. Missing location. Data: {} {}",
- messageMetaData, fileInfo);
+ messageMetaData, fileInfo);
return Optional.empty();
}
Scheme scheme;
scheme = Scheme.getSchemeFromString(URI.create(location).getScheme());
} catch (Exception e) {
logger.error(ERROR_MSG_VES_EVENT_PARSING + "{}. Location: {} Data: {}", e.getMessage(), location,
- messageMetaData, e);
+ messageMetaData, e);
return Optional.empty();
}
FileData fileData = ImmutableFileData.builder() //
- .name(getValueFromJson(fileInfo, NAME, missingValues)) //
- .fileFormatType(getValueFromJson(data, FILE_FORMAT_TYPE, missingValues)) //
- .fileFormatVersion(getValueFromJson(data, FILE_FORMAT_VERSION, missingValues)) //
- .location(location) //
- .scheme(scheme) //
- .compression(getValueFromJson(data, COMPRESSION, missingValues)) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(getValueFromJson(fileInfo, NAME, missingValues)) //
+ .fileFormatType(getValueFromJson(data, FILE_FORMAT_TYPE, missingValues)) //
+ .fileFormatVersion(getValueFromJson(data, FILE_FORMAT_VERSION, missingValues)) //
+ .location(location) //
+ .scheme(scheme) //
+ .compression(getValueFromJson(data, COMPRESSION, missingValues)) //
+ .messageMetaData(messageMetaData) //
+ .build();
if (missingValues.isEmpty()) {
return Optional.of(fileData);
}
logger.error(ERROR_MSG_VES_EVENT_PARSING + "File information wrong. Missing data: {} Data: {}", missingValues,
- fileInfo);
+ fileInfo);
return Optional.empty();
}
* @return String of data from event name
*/
private static String getDataFromEventName(EventNameDataType dataType, String eventName,
- List<String> missingValues) {
+ List<String> missingValues) {
String[] eventArray = eventName.split("_|-");
if (eventArray.length >= 4) {
return eventArray[dataType.index];
} else {
missingValues.add(dataType.toString());
logger.error(
- ERROR_MSG_VES_EVENT_PARSING
- + "Can not get {} from eventName, eventName is not in correct format: {}",
- dataType, eventName);
+ ERROR_MSG_VES_EVENT_PARSING + "Can not get {} from eventName, eventName is not in correct format: {}",
+ dataType, eventName);
}
return "";
}
import java.nio.file.Path;
import java.time.Instant;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
* @throws DatafileTaskException if anything goes wrong.
*/
public HttpResponse getDmaapProducerResponseWithRedirect(HttpUriRequest request, Map<String, String> contextMap)
- throws DatafileTaskException {
+ throws DatafileTaskException {
MDC.setContextMap(contextMap);
try (CloseableHttpAsyncClient webClient = createWebClient(true, DEFAULT_REQUEST_TIMEOUT, contextMap)) {
webClient.start();
* @throws DatafileTaskException if anything goes wrong.
*/
public HttpResponse getDmaapProducerResponseWithCustomTimeout(HttpUriRequest request, Duration requestTimeout,
- Map<String, String> contextMap) throws DatafileTaskException {
+ Map<String, String> contextMap) throws DatafileTaskException {
MDC.setContextMap(contextMap);
try (CloseableHttpAsyncClient webClient = createWebClient(false, requestTimeout, contextMap)) {
webClient.start();
}
private CloseableHttpAsyncClient createWebClient(boolean expectRedirect, Duration requestTimeout,
- Map<String, String> contextMap) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
+ Map<String, String> contextMap) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
SSLContext sslContext =
- new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build();
+ new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build();
HttpAsyncClientBuilderWrapper clientBuilder = getHttpClientBuilder();
clientBuilder.setSslContext(sslContext) //
- .setSslHostnameVerifier(new NoopHostnameVerifier());
+ .setSslHostnameVerifier(new NoopHostnameVerifier());
if (expectRedirect) {
clientBuilder.setRedirectStrategy(new PublishRedirectStrategy(contextMap));
if (requestTimeout.toMillis() > 0) {
int millis = (int) requestTimeout.toMillis();
RequestConfig requestConfig = RequestConfig.custom() //
- .setSocketTimeout(millis) //
- .setConnectTimeout(millis) //
- .setConnectionRequestTimeout(millis) //
- .build();
+ .setSocketTimeout(millis) //
+ .setConnectTimeout(millis) //
+ .setConnectionRequestTimeout(millis) //
+ .build();
clientBuilder.setDefaultRequestConfig(requestConfig);
} else {
}
protected DMaaPMessageConsumer(DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient,
- JsonMessageParser messageParser) {
+ JsonMessageParser messageParser) {
this.dmaaPConsumerReactiveHttpClient = dmaaPConsumerReactiveHttpClient;
this.jsonMessageParser = messageParser;
}
}
private static DMaaPConsumerReactiveHttpClient createHttpClient(AppConfig datafileAppConfig)
- throws DatafileTaskException {
+ throws DatafileTaskException {
DmaapConsumerConfiguration config = datafileAppConfig.getDmaapConsumerConfiguration().toDmaap();
WebClient client = new DmaapWebClient().fromConfiguration(config).build();
return new DMaaPConsumerReactiveHttpClient(config, client);
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
+
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.nio.file.Path;
import java.time.Duration;
+
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
* @return the (same) filePublishInformation
*/
public Mono<FilePublishInformation> publishFile(FilePublishInformation publishInfo, long numRetries,
- Duration firstBackoff) {
+ Duration firstBackoff) {
MDC.setContextMap(publishInfo.getContext());
return Mono.just(publishInfo) //
- .cache() //
- .flatMap(this::publishFile) //
- .flatMap(httpStatus -> handleHttpResponse(httpStatus, publishInfo)) //
- .retryBackoff(numRetries, firstBackoff);
+ .cache() //
+ .flatMap(this::publishFile) //
+ .flatMap(httpStatus -> handleHttpResponse(httpStatus, publishInfo)) //
+ .retryBackoff(numRetries, firstBackoff);
}
private Mono<HttpStatus> publishFile(FilePublishInformation publishInfo) {
dmaapProducerHttpClient.addUserCredentialsToHead(put);
HttpResponse response =
- dmaapProducerHttpClient.getDmaapProducerResponseWithRedirect(put, publishInfo.getContext());
+ dmaapProducerHttpClient.getDmaapProducerResponseWithRedirect(put, publishInfo.getContext());
logger.trace("{}", response);
counters.incTotalPublishedFiles();
return Mono.just(HttpStatus.valueOf(response.getStatusLine().getStatusCode()));
JsonElement metaData = new JsonParser().parse(JsonSerializer.createJsonBodyForDataRouter(publishInfo));
put.addHeader(X_DMAAP_DR_META, metaData.toString());
URI uri = new DefaultUriBuilderFactory(
- datafileAppConfig.getPublisherConfiguration(publishInfo.getChangeIdentifier()).publishUrl()) //
- .builder() //
- .pathSegment(publishInfo.getName()) //
- .build();
+ datafileAppConfig.getPublisherConfiguration(publishInfo.getChangeIdentifier()).publishUrl()) //
+ .builder() //
+ .pathSegment(publishInfo.getName()) //
+ .build();
put.setURI(uri);
MappedDiagnosticContext.appendTraceInfo(put);
}
private static Mono<FilePublishInformation> handleHttpResponse(HttpStatus response,
- FilePublishInformation publishInfo) {
+ FilePublishInformation publishInfo) {
MDC.setContextMap(publishInfo.getContext());
if (HttpUtils.isSuccessfulResponseCode(response.value())) {
logger.trace("Publishing file {} to DR successful!", publishInfo.getName());
} else {
logger.warn("Publishing file {} to DR unsuccessful. Response code: {}", publishInfo.getName(), response);
return Mono.error(new Exception(
- "Publishing file " + publishInfo.getName() + " to DR unsuccessful. Response code: " + response));
+ "Publishing file " + publishInfo.getName() + " to DR unsuccessful. Response code: " + response));
}
}
import java.time.Duration;
import java.util.Map;
import java.util.Optional;
+
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.configuration.FtpesConfig;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
* @return the data needed to publish the file.
*/
public Mono<FilePublishInformation> collectFile(FileData fileData, long numRetries, Duration firstBackoff,
- Map<String, String> contextMap) {
+ Map<String, String> contextMap) {
MDC.setContextMap(contextMap);
logger.trace("Entering collectFile with {}", fileData);
return Mono.just(fileData) //
- .cache() //
- .flatMap(fd -> tryCollectFile(fileData, contextMap)) //
- .retryBackoff(numRetries, firstBackoff) //
- .flatMap(FileCollector::checkCollectedFile);
+ .cache() //
+ .flatMap(fd -> tryCollectFile(fileData, contextMap)) //
+ .retryBackoff(numRetries, firstBackoff) //
+ .flatMap(FileCollector::checkCollectedFile);
}
private static Mono<FilePublishInformation> checkCollectedFile(Optional<FilePublishInformation> info) {
return Mono.just(Optional.of(getFilePublishInformation(fileData, localFile, context)));
} catch (DatafileTaskException e) {
logger.warn("Failed to download file: {} {}, reason: {}", fileData.sourceName(), fileData.name(),
- e.toString());
+ e.toString());
counters.incNoOfFailedFtpAttempts();
if (e instanceof NonRetryableDatafileTaskException) {
return Mono.just(Optional.empty()); // Give up
}
} catch (Exception throwable) {
logger.warn("Failed to close ftp client: {} {}, reason: {}", fileData.sourceName(), fileData.name(),
- throwable.toString(), throwable);
+ throwable.toString(), throwable);
return Mono.just(Optional.of(getFilePublishInformation(fileData, localFile, context)));
}
}
}
private static FilePublishInformation getFilePublishInformation(FileData fileData, Path localFile,
- Map<String, String> context) {
+ Map<String, String> context) {
String location = fileData.location();
MessageMetaData metaData = fileData.messageMetaData();
return ImmutableFilePublishInformation.builder() //
- .productName(metaData.productName()) //
- .vendorName(metaData.vendorName()) //
- .lastEpochMicrosec(metaData.lastEpochMicrosec()) //
- .sourceName(metaData.sourceName()) //
- .startEpochMicrosec(metaData.startEpochMicrosec()) //
- .timeZoneOffset(metaData.timeZoneOffset()) //
- .name(fileData.name()) //
- .location(location) //
- .internalLocation(localFile) //
- .compression(fileData.compression()) //
- .fileFormatType(fileData.fileFormatType()) //
- .fileFormatVersion(fileData.fileFormatVersion()) //
- .changeIdentifier(fileData.messageMetaData().changeIdentifier()) //
- .context(context) //
- .build();
+ .productName(metaData.productName()) //
+ .vendorName(metaData.vendorName()) //
+ .lastEpochMicrosec(metaData.lastEpochMicrosec()) //
+ .sourceName(metaData.sourceName()) //
+ .startEpochMicrosec(metaData.startEpochMicrosec()) //
+ .timeZoneOffset(metaData.timeZoneOffset()) //
+ .name(fileData.name()) //
+ .location(location) //
+ .internalLocation(localFile) //
+ .compression(fileData.compression()) //
+ .fileFormatType(fileData.fileFormatType()) //
+ .fileFormatVersion(fileData.fileFormatVersion()) //
+ .changeIdentifier(fileData.messageMetaData().changeIdentifier()) //
+ .context(context) //
+ .build();
}
protected SftpClient createSftpClient(FileData fileData) {
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());
}
}
* @throws DatafileTaskException if the check fails
*/
public boolean isFilePublished(String fileName, String changeIdentifier, Map<String, String> contextMap)
- throws DatafileTaskException {
+ throws DatafileTaskException {
MDC.setContextMap(contextMap);
PublisherConfiguration publisherConfig = resolveConfiguration(changeIdentifier);
getRequest.setURI(getPublishedQueryUri(fileName, publisherConfig));
producerClient.addUserCredentialsToHead(getRequest);
- 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();
private static URI getPublishedQueryUri(String fileName, PublisherConfiguration config) throws URISyntaxException {
return new URIBuilder(config.logUrl()) //
- .addParameter("type", "pub") //
- .addParameter("filename", fileName) //
- .build();
+ .addParameter("type", "pub") //
+ .addParameter("filename", fileName) //
+ .build();
}
protected PublisherConfiguration resolveConfiguration(String changeIdentifier) throws DatafileTaskException {
}
protected DmaapProducerHttpClient resolveClient(PublisherConfiguration publisherConfig)
- throws DatafileTaskException {
+ throws DatafileTaskException {
try {
return new DmaapProducerHttpClient(publisherConfig.toDmaap());
} catch (MalformedURLException e) {
import java.time.Instant;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
+
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.model.Counters;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
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.
try {
if (getCurrentNumberOfTasks() > MAX_TASKS_FOR_POLLING || this.threadPoolQueueSize.get() > 0) {
logger.info(
- "Skipping consuming new files; current number of tasks: {}, number of subscriptions: {}, "
- + "published files: {}, number of queued VES events: {}",
- getCurrentNumberOfTasks(), this.currentNumberOfSubscriptions.get(), publishedFilesCache.size(),
- threadPoolQueueSize.get());
+ "Skipping consuming new files; current number of tasks: {}, number of subscriptions: {}, "
+ + "published files: {}, number of queued VES events: {}",
+ getCurrentNumberOfTasks(), this.currentNumberOfSubscriptions.get(), publishedFilesCache.size(),
+ threadPoolQueueSize.get());
return;
}
if (this.applicationConfiguration.getDmaapConsumerConfiguration() == null) {
Map<String, String> context = MappedDiagnosticContext.initializeTraceContext();
logger.trace("Execution of tasks was registered");
createMainTask(context) //
- .subscribe(ScheduledTasks::onSuccess, //
- throwable -> {
- onError(throwable, context);
- currentNumberOfSubscriptions.decrementAndGet();
- }, //
- () -> {
- onComplete(context);
- currentNumberOfSubscriptions.decrementAndGet();
- });
+ .subscribe(ScheduledTasks::onSuccess, //
+ throwable -> {
+ onError(throwable, context);
+ currentNumberOfSubscriptions.decrementAndGet();
+ }, //
+ () -> {
+ onComplete(context);
+ currentNumberOfSubscriptions.decrementAndGet();
+ });
} catch (Exception e) {
logger.error("Unexpected exception: {}", e.toString(), e);
}
Flux<FilePublishInformation> createMainTask(Map<String, String> context) {
return fetchMoreFileReadyMessages() //
- .doOnNext(fileReadyMessage -> threadPoolQueueSize.incrementAndGet()) //
- .doOnNext(fileReadyMessage -> counters.incNoOfReceivedEvents()) //
- .parallel(NUMBER_OF_WORKER_THREADS) // Each FileReadyMessage in a separate thread
- .runOn(scheduler) //
- .doOnNext(fileReadyMessage -> threadPoolQueueSize.decrementAndGet()) //
- .flatMap(fileReadyMessage -> Flux.fromIterable(fileReadyMessage.files())) //
- .flatMap(fileData -> createMdcContext(fileData, context)) //
- .filter(this::isFeedConfigured) //
- .filter(this::shouldBePublished) //
- .doOnNext(fileData -> currentNumberOfTasks.incrementAndGet()) //
- .flatMap(this::fetchFile, false, 1, 1) //
- .flatMap(this::publishToDataRouter, false, 1, 1) //
- .doOnNext(publishInfo -> deleteFile(publishInfo.getInternalLocation(), publishInfo.getContext())) //
- .doOnNext(publishInfo -> currentNumberOfTasks.decrementAndGet()) //
- .sequential();
+ .doOnNext(fileReadyMessage -> threadPoolQueueSize.incrementAndGet()) //
+ .doOnNext(fileReadyMessage -> counters.incNoOfReceivedEvents()) //
+ .parallel(NUMBER_OF_WORKER_THREADS) // Each FileReadyMessage in a separate thread
+ .runOn(scheduler) //
+ .doOnNext(fileReadyMessage -> threadPoolQueueSize.decrementAndGet()) //
+ .flatMap(fileReadyMessage -> Flux.fromIterable(fileReadyMessage.files())) //
+ .flatMap(fileData -> createMdcContext(fileData, context)) //
+ .filter(this::isFeedConfigured) //
+ .filter(this::shouldBePublished) //
+ .doOnNext(fileData -> currentNumberOfTasks.incrementAndGet()) //
+ .flatMap(this::fetchFile, false, 1, 1) //
+ .flatMap(this::publishToDataRouter, false, 1, 1) //
+ .doOnNext(publishInfo -> deleteFile(publishInfo.getInternalLocation(), publishInfo.getContext())) //
+ .doOnNext(publishInfo -> currentNumberOfTasks.decrementAndGet()) //
+ .sequential();
}
private class FileDataWithContext {
return this.counters;
}
-
protected DMaaPMessageConsumer createConsumerTask() throws DatafileTaskException {
return new DMaaPMessageConsumer(this.applicationConfiguration);
}
return true;
} else {
logger.info("No feed is configured for: {}, file ignored: {}",
- fileData.fileData.messageMetaData().changeIdentifier(), fileData.fileData.name());
+ fileData.fileData.messageMetaData().changeIdentifier(), fileData.fileData.name());
return false;
}
}
if (publishedFilesCache.put(localFilePath) == null) {
try {
boolean result = !createPublishedChecker().isFilePublished(fileData.fileData.name(),
- fileData.fileData.messageMetaData().changeIdentifier(), fileData.context);
+ fileData.fileData.messageMetaData().changeIdentifier(), fileData.context);
return result;
} catch (DatafileTaskException e) {
logger.error("Cannot check if a file {} is published", fileData.fileData.name(), e);
private Mono<FilePublishInformation> fetchFile(FileDataWithContext fileData) {
MDC.setContextMap(fileData.context);
return createFileCollector() //
- .collectFile(fileData.fileData, FILE_TRANSFER_MAX_RETRIES, FILE_TRANSFER_INITIAL_RETRY_TIMEOUT,
- fileData.context) //
- .onErrorResume(exception -> handleFetchFileFailure(fileData));
+ .collectFile(fileData.fileData, FILE_TRANSFER_MAX_RETRIES, FILE_TRANSFER_INITIAL_RETRY_TIMEOUT,
+ fileData.context) //
+ .onErrorResume(exception -> handleFetchFileFailure(fileData));
}
private Mono<FilePublishInformation> handleFetchFileFailure(FileDataWithContext fileData) {
MDC.setContextMap(publishInfo.getContext());
return createDataRouterPublisher()
- .publishFile(publishInfo, DATA_ROUTER_MAX_RETRIES, DATA_ROUTER_INITIAL_RETRY_TIMEOUT)
- .onErrorResume(exception -> handlePublishFailure(publishInfo));
+ .publishFile(publishInfo, DATA_ROUTER_MAX_RETRIES, DATA_ROUTER_INITIAL_RETRY_TIMEOUT)
+ .onErrorResume(exception -> handlePublishFailure(publishInfo));
}
private Mono<FilePublishInformation> handlePublishFailure(FilePublishInformation publishInfo) {
*/
Flux<FileReadyMessage> fetchMoreFileReadyMessages() {
logger.info(
- "Consuming new file ready messages, current number of tasks: {}, published files: {}, "
- + "number of subscriptions: {}",
- getCurrentNumberOfTasks(), publishedFilesCache.size(), this.currentNumberOfSubscriptions.get());
+ "Consuming new file ready messages, current number of tasks: {}, published files: {}, "
+ + "number of subscriptions: {}",
+ getCurrentNumberOfTasks(), publishedFilesCache.size(), this.currentNumberOfSubscriptions.get());
Map<String, String> context = MDC.getCopyOfContextMap();
try {
return createConsumerTask() //
- .getMessageRouterResponse() //
- .onErrorResume(exception -> handleConsumeMessageFailure(exception, context));
+ .getMessageRouterResponse() //
+ .onErrorResume(exception -> handleConsumeMessageFailure(exception, context));
} catch (Exception e) {
logger.error("Could not create message consumer task", e);
return Flux.empty();
private Flux<FileReadyMessage> handleConsumeMessageFailure(Throwable exception, Map<String, String> context) {
MDC.setContextMap(context);
logger.error("Polling for file ready message failed, exception: {}, config: {}", exception.toString(),
- this.applicationConfiguration.getDmaapConsumerConfiguration());
+ this.applicationConfiguration.getDmaapConsumerConfiguration());
return Flux.empty();
}
import java.net.URI;
import java.util.Map;
+
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 //
+ HttpPut.METHOD_NAME, //
+ HttpGet.METHOD_NAME, //
+ HttpPost.METHOD_NAME, //
+ HttpHead.METHOD_NAME, //
+ HttpDelete.METHOD_NAME //
};
/**
@Override
public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context)
- throws ProtocolException {
+ throws ProtocolException {
MDC.setContextMap(contextMap);
final URI uri = getLocationURI(request, response, context);
logger.trace("getRedirect...: {}", request);
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Properties;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationProvider;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration;
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 static final String CHANGE_IDENTIFIER = "PM_MEAS_FILES";
-
private static final ImmutableDmaapConsumerConfiguration CORRECT_DMAAP_CONSUMER_CONFIG = //
- new ImmutableDmaapConsumerConfiguration.Builder() //
- .timeoutMs(-1) //
- .dmaapHostName("message-router.onap.svc.cluster.local") //
- .dmaapUserName("admin") //
- .dmaapUserPassword("admin") //
- .dmaapTopicName("events/unauthenticated.VES_NOTIFICATION_OUTPUT") //
- .dmaapPortNumber(2222) //
- .dmaapContentType("application/json") //
- .messageLimit(-1) //
- .dmaapProtocol("http") //
- .consumerId("C12") //
- .consumerGroup("OpenDcae-c12") //
- .trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .build();
-
- private static final ConsumerConfiguration CORRECT_CONSUMER_CONFIG = ImmutableConsumerConfiguration.builder() //
- .topicUrl(
- "http://admin:admin@message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12")
+ new ImmutableDmaapConsumerConfiguration.Builder() //
+ .timeoutMs(-1) //
+ .dmaapHostName("message-router.onap.svc.cluster.local") //
+ .dmaapUserName("admin") //
+ .dmaapUserPassword("admin") //
+ .dmaapTopicName("events/unauthenticated.VES_NOTIFICATION_OUTPUT") //
+ .dmaapPortNumber(2222) //
+ .dmaapContentType("application/json") //
+ .messageLimit(-1) //
+ .dmaapProtocol("http") //
+ .consumerId("C12") //
+ .consumerGroup("OpenDcae-c12") //
.trustStorePath("trustStorePath") //
.trustStorePasswordPath("trustStorePasswordPath") //
.keyStorePath("keyStorePath") //
.enableDmaapCertAuth(true) //
.build();
+ private static final ConsumerConfiguration CORRECT_CONSUMER_CONFIG = ImmutableConsumerConfiguration.builder() //
+ .topicUrl(
+ "http://admin:admin@message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12")
+ .trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .build();
+
private static final PublisherConfiguration CORRECT_PUBLISHER_CONFIG = //
- ImmutablePublisherConfiguration.builder() //
- .publishUrl("https://message-router.onap.svc.cluster.local:3907/publish/1") //
- .logUrl("https://dmaap.example.com/feedlog/972").trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .changeIdentifier("PM_MEAS_FILES") //
- .userName("user") //
- .passWord("password") //
- .build();
+ ImmutablePublisherConfiguration.builder() //
+ .publishUrl("https://message-router.onap.svc.cluster.local:3907/publish/1") //
+ .logUrl("https://dmaap.example.com/feedlog/972").trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .changeIdentifier("PM_MEAS_FILES") //
+ .userName("user") //
+ .passWord("password") //
+ .build();
private static final ImmutableFtpesConfig CORRECT_FTPES_CONFIGURATION = //
- new ImmutableFtpesConfig.Builder() //
- .keyCert("/config/dfc.jks") //
- .keyPassword("secret") //
- .trustedCa("config/ftp.jks") //
- .trustedCaPassword("secret") //
- .build();
+ new ImmutableFtpesConfig.Builder() //
+ .keyCert("/config/dfc.jks") //
+ .keyPassword("secret") //
+ .trustedCa("config/ftp.jks") //
+ .trustedCaPassword("secret") //
+ .build();
private static final ImmutableDmaapPublisherConfiguration CORRECT_DMAAP_PUBLISHER_CONFIG = //
- new ImmutableDmaapPublisherConfiguration.Builder() //
- .dmaapTopicName("/publish/1") //
- .dmaapUserPassword("password") //
- .dmaapPortNumber(3907) //
- .dmaapProtocol("https") //
- .dmaapContentType("application/octet-stream") //
- .dmaapHostName("message-router.onap.svc.cluster.local") //
- .dmaapUserName("user") //
- .trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .build();
+ new ImmutableDmaapPublisherConfiguration.Builder() //
+ .dmaapTopicName("/publish/1") //
+ .dmaapUserPassword("password") //
+ .dmaapPortNumber(3907) //
+ .dmaapProtocol("https") //
+ .dmaapContentType("application/octet-stream") //
+ .dmaapHostName("message-router.onap.svc.cluster.local") //
+ .dmaapUserName("user") //
+ .trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .build();
private static EnvProperties properties() {
return ImmutableEnvProperties.builder() //
- .consulHost("host") //
- .consulPort(123) //
- .cbsName("cbsName") //
- .appName("appName") //
- .build();
+ .consulHost("host") //
+ .consulPort(123) //
+ .cbsName("cbsName") //
+ .appName("appName") //
+ .build();
}
private AppConfig appConfigUnderTest;
private CloudConfigurationProvider cloudConfigurationProvider = mock(CloudConfigurationProvider.class);
private final Map<String, String> context = MappedDiagnosticContext.initializeTraceContext();
-
@BeforeEach
public void setUp() {
appConfigUnderTest = spy(AppConfig.class);
Assertions.assertNotNull(appConfigUnderTest.getPublisherConfiguration("YY_FILES"));
assertThat(appConfigUnderTest.getPublisherConfiguration("XX_FILES").publishUrl())
- .isEqualTo("feed01::publish_url");
+ .isEqualTo("feed01::publish_url");
assertThat(appConfigUnderTest.getPublisherConfiguration("YY_FILES").publishUrl())
- .isEqualTo("feed01::publish_url");
+ .isEqualTo("feed01::publish_url");
}
@Test
// Then
assertTrue("Error message missing in log.",
- logAppender.list.toString().contains("[WARN] Local configuration file not loaded: /temp.json"));
+ logAppender.list.toString().contains("[WARN] Local configuration file not loaded: /temp.json"));
logAppender.stop();
Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration());
assertThatThrownBy(() -> appConfigUnderTest.getPublisherConfiguration(CHANGE_IDENTIFIER))
- .hasMessageContaining("No PublishingConfiguration loaded, changeIdentifier: PM_MEAS_FILES");
+ .hasMessageContaining("No PublishingConfiguration loaded, changeIdentifier: PM_MEAS_FILES");
Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration());
}
verify(appConfigUnderTest, times(1)).loadConfigurationFromFile();
Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration());
assertThatThrownBy(() -> appConfigUnderTest.getPublisherConfiguration(CHANGE_IDENTIFIER))
- .hasMessageContaining(CHANGE_IDENTIFIER);
+ .hasMessageContaining(CHANGE_IDENTIFIER);
Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration());
}
verify(appConfigUnderTest, times(1)).loadConfigurationFromFile();
Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration());
assertThatThrownBy(() -> appConfigUnderTest.getPublisherConfiguration(CHANGE_IDENTIFIER))
- .hasMessageContaining(CHANGE_IDENTIFIER);
+ .hasMessageContaining(CHANGE_IDENTIFIER);
Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration());
}
Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context);
StepVerifier //
- .create(task) //
- .expectSubscription() //
- .expectNextCount(0) //
- .verifyComplete();
+ .create(task) //
+ .expectSubscription() //
+ .expectNextCount(0) //
+ .verifyComplete();
assertTrue(logAppender.list.toString().contains("$CONSUL_HOST environment has not been defined"));
}
Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context);
StepVerifier //
- .create(task) //
- .expectSubscription() //
- .expectNextCount(0) //
- .verifyComplete();
+ .create(task) //
+ .expectSubscription() //
+ .expectNextCount(0) //
+ .verifyComplete();
- assertTrue(logAppender.list.toString()
- .contains("Could not refresh application configuration java.io.IOException"));
+ assertTrue(
+ logAppender.list.toString().contains("Could not refresh application configuration java.io.IOException"));
}
@Test
Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context);
StepVerifier //
- .create(task) //
- .expectSubscription() //
- .expectNext(appConfigUnderTest) //
- .verifyComplete();
+ .create(task) //
+ .expectSubscription() //
+ .expectNext(appConfigUnderTest) //
+ .verifyComplete();
Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration());
}
Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context);
StepVerifier //
- .create(task) //
- .expectSubscription() //
- .expectNext(appConfigUnderTest) //
- .verifyComplete();
+ .create(task) //
+ .expectSubscription() //
+ .expectNext(appConfigUnderTest) //
+ .verifyComplete();
Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration());
}
private static InputStream getIncorrectJson() {
String string = "{" + //
- " \"configs\": {" + //
- " \"dmaap\": {"; //
+ " \"configs\": {" + //
+ " \"dmaap\": {"; //
return new ByteArrayInputStream((string.getBytes(StandardCharsets.UTF_8)));
}
}
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.TaskScheduler;
-
import reactor.test.StepVerifier;
public class SchedulerConfigTest {
private final TaskScheduler taskSchedulerMock = mock(TaskScheduler.class);
private final ScheduledTasks scheduledTasksMock = mock(ScheduledTasks.class);
private final SchedulerConfig schedulerUnderTest =
- spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock));
+ spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock));
@BeforeEach
public void setUp() {
String msg = "Datafile Service has already been stopped!";
StepVerifier.create(schedulerUnderTest.getResponseFromCancellationOfTasks())
- .expectNext(new ResponseEntity<String>(msg, HttpStatus.CREATED)) //
- .verifyComplete();
+ .expectNext(new ResponseEntity<String>(msg, HttpStatus.CREATED)) //
+ .verifyComplete();
verify(scheduledFutureMock).cancel(false);
verifyNoMoreInteractions(scheduledFutureMock);
SchedulerConfig.setScheduledFutureList(scheduledFutureList);
SchedulerConfig schedulerUnderTestSpy =
- spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock));
+ spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock));
boolean actualResult = schedulerUnderTestSpy.tryToStartTask();
ArgumentCaptor<Runnable> scheduleMainDatafileEventTaskCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(taskSchedulerMock).scheduleWithFixedDelay(scheduleMainDatafileEventTaskCaptor.capture(),
- eq(Duration.ofSeconds(15)));
+ eq(Duration.ofSeconds(15)));
ArgumentCaptor<Runnable> purgeCachedInformationCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(taskSchedulerMock).scheduleWithFixedDelay(purgeCachedInformationCaptor.capture(),
- eq(Duration.ofHours(1)));
+ eq(Duration.ofHours(1)));
verifyNoMoreInteractions(taskSchedulerMock);
scheduleMainDatafileEventTaskCaptor.getValue().run();
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.collectors.datafile.controllers.StatusController;
assertFalse(StringUtils.isBlank(MDC.get(MdcVariables.INVOCATION_ID)));
}
-
@Test
public void status() {
ScheduledTasks scheduledTasksMock = mock(ScheduledTasks.class);
assertFalse(StringUtils.isBlank(MDC.get(MdcVariables.INVOCATION_ID)));
}
-
private void validateLogging(ListAppender<ILoggingEvent> logAppender) {
assertEquals(logAppender.list.get(0).getMarker().getName(), "ENTRY");
assertNotNull(logAppender.list.get(0).getMDCPropertyMap().get("InvocationID"));
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;
doReturn(false).when(ftpsClientMock).retrieveFile(REMOTE_FILE_PATH, outputStreamMock);
assertThatThrownBy(() -> clientUnderTestSpy.collectFile(REMOTE_FILE_PATH, LOCAL_FILE_PATH))
- .hasMessageContaining(REMOTE_FILE_PATH)
- .hasMessageContaining("No retry");
+ .hasMessageContaining(REMOTE_FILE_PATH).hasMessageContaining("No retry");
verifyFtpsClientMock_openOk();
verify(ftpsClientMock, times(1)).retrieveFile(ArgumentMatchers.eq(REMOTE_FILE_PATH), any());
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
+
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Optional;
+
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@Test
public void openWithPort_success()
- throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
+ throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(SFTP_PORT) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(SFTP_PORT) //
+ .build();
SftpClient sftpClientSpy = spy(new SftpClient(expectedFileServerData));
@Test
public void openWithoutPort_success()
- throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
+ throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(Optional.empty()) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(Optional.empty()) //
+ .build();
SftpClient sftpClientSpy = spy(new SftpClient(expectedFileServerData));
@Test
public void open_throwsException()
- throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
+ throws DatafileTaskException, IOException, JSchException, SftpException, Exception {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(SFTP_PORT) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(SFTP_PORT) //
+ .build();
SftpClient sftpClientSpy = spy(new SftpClient(expectedFileServerData));
@Test
public void collectFile_succes() throws DatafileTaskException, SftpException {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(SFTP_PORT) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(SFTP_PORT) //
+ .build();
SftpClient sftpClient = new SftpClient(expectedFileServerData);
sftpClient.sftpChannel = channelMock;
@Test
public void collectFile_throwsExceptionWithoutRetry()
- throws IOException, JSchException, SftpException, DatafileTaskException {
+ throws IOException, JSchException, SftpException, DatafileTaskException {
FileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(HOST) //
- .userId(USERNAME) //
- .password(PASSWORD) //
- .port(SFTP_PORT) //
- .build();
+ .serverAddress(HOST) //
+ .userId(USERNAME) //
+ .password(PASSWORD) //
+ .port(SFTP_PORT) //
+ .build();
try (SftpClient sftpClient = new SftpClient(expectedFileServerData)) {
sftpClient.sftpChannel = channelMock;
doThrow(new SftpException(ChannelSftp.SSH_FX_NO_SUCH_FILE, "Failed")).when(channelMock).get(anyString(),
- anyString());
+ anyString());
assertThatThrownBy(() -> sftpClient.collectFile("remoteFile", Paths.get("localFile")))
- .isInstanceOf(DatafileTaskException.class)
- .hasMessageStartingWith("Unable to get file from xNF. No retry attempts will be done")
- .hasMessageContaining("Data: FileServerData{serverAddress=" + HOST + ", " + "userId=" + USERNAME
- + ", password=####, port=" + SFTP_PORT);
+ .isInstanceOf(DatafileTaskException.class)
+ .hasMessageStartingWith("Unable to get file from xNF. No retry attempts will be done")
+ .hasMessageContaining("Data: FileServerData{serverAddress=" + HOST + ", " + "userId=" + USERNAME
+ + ", password=####, port=" + SFTP_PORT);
}
}
private static final String SERVER_ADDRESS = "192.168.0.101";
private static final int PORT_22 = 22;
private static final String LOCATION_WITH_USER =
- FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
+ FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
private static final String LOCATION_WITHOUT_USER =
- FTPES_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
-
+ FTPES_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
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();
+ .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() {
return ImmutableFileData.builder() //
- .name("name") //
- .location(LOCATION_WITH_USER) //
- .compression("comp") //
- .fileFormatType("type") //
- .fileFormatVersion("version") //
- .scheme(Scheme.FTPS) //
- .messageMetaData(messageMetaData()) //
- .build();
+ .name("name") //
+ .location(LOCATION_WITH_USER) //
+ .compression("comp") //
+ .fileFormatType("type") //
+ .fileFormatVersion("version") //
+ .scheme(Scheme.FTPS) //
+ .messageMetaData(messageMetaData()) //
+ .build();
}
private FileData properFileDataWithoutUser() {
return ImmutableFileData.builder() //
- .name("name") //
- .location(LOCATION_WITHOUT_USER) //
- .compression("comp") //
- .fileFormatType("type") //
- .fileFormatVersion("version") //
- .scheme(Scheme.FTPS) //
- .messageMetaData(messageMetaData()) //
- .build();
+ .name("name") //
+ .location(LOCATION_WITHOUT_USER) //
+ .compression("comp") //
+ .fileFormatType("type") //
+ .fileFormatVersion("version") //
+ .scheme(Scheme.FTPS) //
+ .messageMetaData(messageMetaData()) //
+ .build();
}
@Test
public void fileServerData_properLocationWithUser() {
ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(SERVER_ADDRESS) //
- .port(PORT_22) //
- .userId(USER) //
- .password(PWD) //
- .build();
+ .serverAddress(SERVER_ADDRESS) //
+ .port(PORT_22) //
+ .userId(USER) //
+ .password(PWD) //
+ .build();
FileServerData actualFileServerData = properFileDataWithUser().fileServerData();
assertEquals(expectedFileServerData, actualFileServerData);
@Test
public void fileServerData_properLocationWithoutUser() {
ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() //
- .serverAddress(SERVER_ADDRESS) //
- .port(PORT_22) //
- .userId("") //
- .password("") //
- .build();
+ .serverAddress(SERVER_ADDRESS) //
+ .port(PORT_22) //
+ .userId("") //
+ .password("") //
+ .build();
FileServerData actualFileServerData = properFileDataWithoutUser().fileServerData();
assertEquals(expectedFileServerData, actualFileServerData);
@Test
public void fileServerData_properLocationWithoutPort() {
ImmutableFileServerData fileServerData = ImmutableFileServerData.builder() //
- .serverAddress(SERVER_ADDRESS) //
- .userId("") //
- .password("") //
- .build();
+ .serverAddress(SERVER_ADDRESS) //
+ .userId("") //
+ .password("") //
+ .build();
assertFalse(fileServerData.port().isPresent());
}
}
-
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
+
import java.net.URISyntaxException;
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.utils.JsonMessage;
import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField;
import org.onap.dcaegen2.collectors.datafile.utils.LoggingUtils;
+
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@Test
void whenPassingCorrectJson_oneFileReadyMessage() throws URISyntaxException {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .build();
FileData expectedFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNext(expectedMessage).verifyComplete();
+ .expectSubscription().expectNext(expectedMessage).verifyComplete();
}
@Test
void whenPassingCorrectJsonWithTwoEvents_twoMessages() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .build();
FileData expectedFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
String parsedString = message.getParsed();
String messageString = "[" + parsedString + "," + parsedString + "]";
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNext(expectedMessage).expectNext(expectedMessage).verifyComplete();
+ .expectSubscription().expectNext(expectedMessage).expectNext(expectedMessage).verifyComplete();
}
@Test
void whenPassingCorrectJsonWithoutLocation_noMessage() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue(logAppender.list.toString()
- .contains("[ERROR] VES event parsing. File information wrong. " + "Missing location."));
+ .contains("[ERROR] VES event parsing. File information wrong. " + "Missing location."));
assertTrue(logAppender.list.get(0).toString().contains("sourceName=5GRAN_DU"));
}
@Test
void whenPassingCorrectJsonWrongScheme_noMessage() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location("http://location.xml") //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location("http://location.xml") //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + Scheme.DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + "http"
- + Scheme.SUPPORTED_PROTOCOLS_ERROR_MESSAGE + ". Location: http://location.xml"));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + Scheme.DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + "http" + Scheme.SUPPORTED_PROTOCOLS_ERROR_MESSAGE
+ + ". Location: http://location.xml"));
assertTrue("Missing sourceName in log", logAppender.list.toString().contains("sourceName=5GRAN_DU"));
}
@Test
void whenPassingCorrectJsonWithTwoEventsFirstNoHeader_oneFileDatan() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .build();
FileData expectedFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
String parsedString = message.getParsed();
String messageString = "[{\"event\":{}}," + parsedString + "]";
JsonMessageParser jsonMessageParserUnderTest = new JsonMessageParser();
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNext(expectedMessage).verifyComplete();
+ .expectSubscription().expectNext(expectedMessage).verifyComplete();
}
@Test
void whenPassingCorrectJsonWithFaultyEventName_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName("Faulty event name") //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName("Faulty event name") //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectComplete().verify();
+ .expectSubscription().expectComplete().verify();
- assertTrue("Error missing in log", logAppender.list.toString().contains(ERROR_LOG_TAG
- + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ assertTrue("Error missing in log",
+ logAppender.list.toString().contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ "Can not get PRODUCT_NAME from eventName, eventName is not in correct format: Faulty event name"));
}
@Test
void whenPassingCorrectJsonWithoutName_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "File information wrong. Missing data: [name] Data: "
- + message.getAdditionalFields().get(0).toString()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "File information wrong. Missing data: [name] Data: "
+ + message.getAdditionalFields().get(0).toString()));
}
@Test
void whenPassingCorrectJsonWithoutAdditionalFields_noFileData() {
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString().contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "Missing arrayOfNamedHashMap in message. " + message.getParsed()));
+ logAppender.list.toString().contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "Missing arrayOfNamedHashMap in message. " + message.getParsed()));
}
@Test
void whenPassingCorrectJsonWithoutCompression_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "File information wrong. Missing data: [compression] Data: "
- + message.getAdditionalFields().get(0).toString()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "File information wrong. Missing data: [compression] Data: "
+ + message.getAdditionalFields().get(0).toString()));
}
@Test
void whenPassingCorrectJsonWithoutFileFormatType_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).verifyComplete();
+ .expectSubscription().expectNextCount(0).verifyComplete();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "File information wrong. Missing data: [fileFormatType] Data: "
- + message.getAdditionalFields().get(0).toString()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "File information wrong. Missing data: [fileFormatType] Data: "
+ + message.getAdditionalFields().get(0).toString()));
}
@Test
void whenPassingOneCorrectJsonWithoutFileFormatVersionAndOneCorrect_oneFileData() {
AdditionalField additionalFaultyField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .build();
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalFaultyField) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalFaultyField) //
+ .addAdditionalField(additionalField) //
+ .build();
MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() //
- .productName(PRODUCT_NAME) //
- .vendorName(VENDOR_NAME) //
- .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
- .sourceName(SOURCE_NAME) //
- .startEpochMicrosec(START_EPOCH_MICROSEC) //
- .timeZoneOffset(TIME_ZONE_OFFSET) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(CHANGE_TYPE) //
- .build();
+ .productName(PRODUCT_NAME) //
+ .vendorName(VENDOR_NAME) //
+ .lastEpochMicrosec(LAST_EPOCH_MICROSEC) //
+ .sourceName(SOURCE_NAME) //
+ .startEpochMicrosec(START_EPOCH_MICROSEC) //
+ .timeZoneOffset(TIME_ZONE_OFFSET) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(CHANGE_TYPE) //
+ .build();
FileData expectedFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(expectedFileData);
FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNext(expectedMessage).verifyComplete();
+ .expectSubscription().expectNext(expectedMessage).verifyComplete();
}
@Test
void whenPassingJsonWithoutMandatoryHeaderInformation_noFileData() {
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .build();
String incorrectMessageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(incorrectMessageString)))
- .expectSubscription().expectComplete().verify();
+ .expectSubscription().expectComplete().verify();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + "Missing data: [changeIdentifier, changeType, notificationFieldsVersion]. "
- + "Change type is wrong: Expected: FileReady Message: " + message.getParsed()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
+ + "Missing data: [changeIdentifier, changeType, notificationFieldsVersion]. "
+ + "Change type is wrong: Expected: FileReady Message: " + message.getParsed()));
}
@Test
JsonElement jsonElement = new JsonParser().parse("{}");
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just("[{}]"))).expectSubscription()
- .expectComplete().verify();
+ .expectComplete().verify();
assertTrue("Error missing in log",
- logAppender.list.toString().contains(ERROR_LOG_TAG + "Incorrect JsonObject - missing header. "));
+ logAppender.list.toString().contains(ERROR_LOG_TAG + "Incorrect JsonObject - missing header. "));
}
@Test
void whenPassingCorrectJsonWithIncorrectChangeType_noFileData() {
AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() //
- .name(PM_FILE_NAME) //
- .location(LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage message = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType(INCORRECT_CHANGE_TYPE) //
- .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
- .addAdditionalField(additionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType(INCORRECT_CHANGE_TYPE) //
+ .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) //
+ .addAdditionalField(additionalField) //
+ .build();
String messageString = message.toString();
String parsedString = message.getParsed();
JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser());
JsonElement jsonElement = new JsonParser().parse(parsedString);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest)
- .getJsonObjectFromAnArray(jsonElement);
+ .getJsonObjectFromAnArray(jsonElement);
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class);
StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString)))
- .expectSubscription().expectNextCount(0).expectComplete().verify();
+ .expectSubscription().expectNextCount(0).expectComplete().verify();
assertTrue("Error missing in log",
- logAppender.list.toString()
- .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING
- + " Change type is wrong: " + INCORRECT_CHANGE_TYPE + " Expected: FileReady Message: "
- + message.getParsed()));
+ logAppender.list.toString()
+ .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + " Change type is wrong: "
+ + INCORRECT_CHANGE_TYPE + " Expected: FileReady Message: " + message.getParsed()));
}
}
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;
private static final Map<String, String> CONTEXT_MAP = new HashMap<>();
-
private DmaapProducerHttpClient producerClientUnderTestSpy;
private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(DmaapPublisherConfiguration.class);
when(futureMock.get()).thenThrow(new InterruptedException("Interrupted"));
producerClientUnderTestSpy.getDmaapProducerResponseWithCustomTimeout(request, TWO_SECOND_TIMEOUT,
- CONTEXT_MAP);
+ CONTEXT_MAP);
fail("Should have got an exception.");
} catch (DatafileTaskException e) {
@BeforeAll
public static void setUp() {
AdditionalField ftpesAdditionalField = new JsonMessage.AdditionalFieldBuilder() //
- .location(FTPES_LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .location(FTPES_LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage ftpesJsonMessage = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
- .changeType(FILE_READY_CHANGE_TYPE) //
- .notificationFieldsVersion("1.0") //
- .addAdditionalField(ftpesAdditionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
+ .changeType(FILE_READY_CHANGE_TYPE) //
+ .notificationFieldsVersion("1.0") //
+ .addAdditionalField(ftpesAdditionalField) //
+ .build();
ftpesMessageString = ftpesJsonMessage.toString();
MessageMetaData messageMetaData = 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();
+ .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();
ftpesFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(FTPES_LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(FTPES_LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
List<FileData> files = new ArrayList<>();
files.add(ftpesFileData);
expectedFtpesMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
AdditionalField sftpAdditionalField = new JsonMessage.AdditionalFieldBuilder() //
- .location(SFTP_LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .build();
+ .location(SFTP_LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .build();
JsonMessage sftpJsonMessage = new JsonMessage.JsonMessageBuilder() //
- .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
- .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
- .changeType(FILE_READY_CHANGE_TYPE) //
- .notificationFieldsVersion("1.0") //
- .addAdditionalField(sftpAdditionalField) //
- .build();
+ .eventName(NR_RADIO_ERICSSON_EVENT_NAME) //
+ .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) //
+ .changeType(FILE_READY_CHANGE_TYPE) //
+ .notificationFieldsVersion("1.0") //
+ .addAdditionalField(sftpAdditionalField) //
+ .build();
sftpMessageString = sftpJsonMessage.toString();
sftpFileData = ImmutableFileData.builder() //
- .name(PM_FILE_NAME) //
- .location(SFTP_LOCATION) //
- .scheme(Scheme.FTPS) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .messageMetaData(messageMetaData) //
- .build();
+ .name(PM_FILE_NAME) //
+ .location(SFTP_LOCATION) //
+ .scheme(Scheme.FTPS) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .messageMetaData(messageMetaData) //
+ .build();
ImmutableFilePublishInformation 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(PM_FILE_NAME) //
- .location(FTPES_LOCATION) //
- .internalLocation(LOCAL_FILE_LOCATION) //
- .compression(GZIP_COMPRESSION) //
- .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .context(new HashMap<String,String>()) //
- .build();
+ .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(FTPES_LOCATION) //
+ .internalLocation(LOCAL_FILE_LOCATION) //
+ .compression(GZIP_COMPRESSION) //
+ .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .context(new HashMap<String, String>()) //
+ .build();
listOfFilePublishInformation.add(filePublishInformation);
files = new ArrayList<>();
files.add(sftpFileData);
expectedSftpMessage = ImmutableFileReadyMessage.builder() //
- .files(files) //
- .build();
+ .files(files) //
+ .build();
}
@Test
prepareMocksForDmaapConsumer("", null);
StepVerifier.create(messageConsumer.getMessageRouterResponse()) //
- .expectSubscription() //
- .expectError(DatafileTaskException.class) //
- .verify();
+ .expectSubscription() //
+ .expectError(DatafileTaskException.class) //
+ .verify();
verify(httpClientMock, times(1)).getDMaaPConsumerResponse();
}
prepareMocksForDmaapConsumer(ftpesMessageString, expectedFtpesMessage);
StepVerifier.create(messageConsumer.getMessageRouterResponse()) //
- .expectNext(expectedFtpesMessage) //
- .verifyComplete();
+ .expectNext(expectedFtpesMessage) //
+ .verifyComplete();
verify(httpClientMock, times(1)).getDMaaPConsumerResponse();
verifyNoMoreInteractions(httpClientMock);
prepareMocksForDmaapConsumer(sftpMessageString, expectedSftpMessage);
StepVerifier.create(messageConsumer.getMessageRouterResponse()) //
- .expectNext(expectedSftpMessage) //
- .verifyComplete();
+ .expectNext(expectedSftpMessage) //
+ .verifyComplete();
verify(httpClientMock, times(1)).getDMaaPConsumerResponse();
verifyNoMoreInteractions(httpClientMock);
if (!message.isEmpty()) {
when(jsonMessageParserMock.getMessagesFromJson(messageAsMono))
- .thenReturn(Flux.just(fileReadyMessageAfterConsume));
+ .thenReturn(Flux.just(fileReadyMessageAfterConsume));
} else {
when(jsonMessageParserMock.getMessagesFromJson(messageAsMono))
- .thenReturn(Flux.error(new DatafileTaskException("problemas")));
+ .thenReturn(Flux.error(new DatafileTaskException("problemas")));
}
messageConsumer = spy(new DMaaPMessageConsumer(httpClientMock, jsonMessageParserMock));
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import java.io.File;
-
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
+import java.io.File;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
// "https://54.45.333.2:1234/publish/1";
private static final String PUBLISH_URL =
- HTTPS_SCHEME + "://" + HOST + ":" + PORT + "/" + PUBLISH_TOPIC + "/" + FEED_ID;
+ HTTPS_SCHEME + "://" + HOST + ":" + PORT + "/" + PUBLISH_TOPIC + "/" + FEED_ID;
@BeforeAll
public static void setUp() {
when(publisherConfigurationMock.publishUrl()).thenReturn(PUBLISH_URL);
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(PM_FILE_NAME) //
- .location(FTPES_ADDRESS) //
- .internalLocation(Paths.get("target/" + PM_FILE_NAME)) //
- .compression("gzip") //
- .fileFormatType(FILE_FORMAT_TYPE) //
- .fileFormatVersion(FILE_FORMAT_VERSION) //
- .context(context) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .build(); //
+ .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(FTPES_ADDRESS) //
+ .internalLocation(Paths.get("target/" + PM_FILE_NAME)) //
+ .compression("gzip") //
+ .fileFormatType(FILE_FORMAT_TYPE) //
+ .fileFormatVersion(FILE_FORMAT_VERSION) //
+ .context(context) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .build(); //
appConfig = mock(AppConfig.class);
publisherTaskUnderTestSpy = spy(new DataRouterPublisher(appConfig, new Counters()));
}
public void whenPassedObjectFits_ReturnsCorrectStatus() throws Exception {
prepareMocksForTests(null, Integer.valueOf(HttpStatus.OK.value()));
StepVerifier //
- .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
- .expectNext(filePublishInformation) //
- .verifyComplete();
+ .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
+ .expectNext(filePublishInformation) //
+ .verifyComplete();
ArgumentCaptor<HttpUriRequest> requestCaptor = ArgumentCaptor.forClass(HttpUriRequest.class);
verify(httpClientMock).addUserCredentialsToHead(any(HttpUriRequest.class));
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(DataRouterPublisher.class);
StepVerifier.create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 2, Duration.ofSeconds(0)))
- .expectNext(filePublishInformation) //
- .verifyComplete();
+ .expectNext(filePublishInformation) //
+ .verifyComplete();
- assertTrue("Warning missing in log", logAppender.list.toString()
- .contains("[WARN] Publishing file " + PM_FILE_NAME + " to DR unsuccessful."));
+ assertTrue("Warning missing in log",
+ logAppender.list.toString().contains("[WARN] Publishing file " + PM_FILE_NAME + " to DR unsuccessful."));
}
@Test
public void whenPassedObjectFits_firstFailsThenSucceeds() throws Exception {
prepareMocksForTests(null, Integer.valueOf(HttpStatus.BAD_GATEWAY.value()),
- Integer.valueOf(HttpStatus.OK.value()));
+ Integer.valueOf(HttpStatus.OK.value()));
StepVerifier //
- .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
- .expectNext(filePublishInformation) //
- .verifyComplete();
+ .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
+ .expectNext(filePublishInformation) //
+ .verifyComplete();
verify(httpClientMock, times(2)).addUserCredentialsToHead(any(HttpUriRequest.class));
verify(httpClientMock, times(2)).getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any());
@Test
public void whenPassedObjectFits_firstFailsThenFails() throws Exception {
prepareMocksForTests(null, Integer.valueOf(HttpStatus.BAD_GATEWAY.value()),
- Integer.valueOf((HttpStatus.BAD_GATEWAY.value())));
+ Integer.valueOf((HttpStatus.BAD_GATEWAY.value())));
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(DataRouterPublisher.class);
StepVerifier.create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0)))
- .expectErrorMessage("Retries exhausted: 1/1") //
- .verify();
+ .expectErrorMessage("Retries exhausted: 1/1") //
+ .verify();
assertTrue("Warning missing in log", logAppender.list.toString().contains("[WARN] Publishing file "
- + PM_FILE_NAME + " to DR unsuccessful. Response code: " + HttpStatus.BAD_GATEWAY));
+ + PM_FILE_NAME + " to DR unsuccessful. Response code: " + HttpStatus.BAD_GATEWAY));
verify(httpClientMock, times(2)).addUserCredentialsToHead(any(HttpUriRequest.class));
verify(httpClientMock, times(2)).getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any());
@SafeVarargs
final void prepareMocksForTests(Exception exception, Integer firstResponse, Integer... nextHttpResponses)
- throws Exception {
+ throws Exception {
httpClientMock = mock(DmaapProducerHttpClient.class);
when(appConfig.getPublisherConfiguration(CHANGE_IDENTIFIER)).thenReturn(publisherConfigurationMock);
doReturn(publisherConfigurationMock).when(publisherTaskUnderTestSpy).resolveConfiguration(CHANGE_IDENTIFIER);
HttpResponse httpResponseMock = mock(HttpResponse.class);
if (exception == null) {
when(httpClientMock.getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any()))
- .thenReturn(httpResponseMock);
+ .thenReturn(httpResponseMock);
} else {
when(httpClientMock.getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any()))
- .thenThrow(exception).thenReturn(httpResponseMock);
+ .thenThrow(exception).thenReturn(httpResponseMock);
}
StatusLine statusLineMock = mock(StatusLine.class);
when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock);
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;
public class FileCollectorTest {
private static final String USER = "usr";
private static final String PWD = "pwd";
private static final String FTPES_LOCATION =
- FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
+ FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
private static final String FTPES_LOCATION_NO_PORT =
- FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + REMOTE_FILE_LOCATION;
+ FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + REMOTE_FILE_LOCATION;
private static final String SFTP_LOCATION = SFTP_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION;
private static final String SFTP_LOCATION_NO_PORT = SFTP_SCHEME + SERVER_ADDRESS + REMOTE_FILE_LOCATION;
private MessageMetaData createMessageMetaData() {
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();
+ .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 createFileData(String location, Scheme scheme) {
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();
+ .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 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) //
- .context(new HashMap<String, String>()) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .build();
+ .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) //
+ .context(new HashMap<String, String>()) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .build();
}
/**
FileData fileData = createFileData(FTPES_LOCATION_NO_PORT, Scheme.FTPS);
FilePublishInformation expectedfilePublishInformation =
- createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
+ createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedfilePublishInformation) //
- .verifyComplete();
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
verify(ftpsClientMock, times(1)).open();
verify(ftpsClientMock, times(1)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
FileCollector collectorUndetTest = spy(new FileCollector(appConfigMock, counters));
doReturn(sftpClientMock).when(collectorUndetTest).createSftpClient(any());
-
FileData fileData = createFileData(SFTP_LOCATION_NO_PORT, Scheme.SFTP);
FilePublishInformation expectedfilePublishInformation =
- createExpectedFilePublishInformation(SFTP_LOCATION_NO_PORT);
+ createExpectedFilePublishInformation(SFTP_LOCATION_NO_PORT);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedfilePublishInformation) //
- .verifyComplete();
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
// The same again, but with port
fileData = createFileData(SFTP_LOCATION, Scheme.SFTP);
expectedfilePublishInformation = createExpectedFilePublishInformation(SFTP_LOCATION);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedfilePublishInformation) //
- .verifyComplete();
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
verify(sftpClientMock, times(2)).open();
verify(sftpClientMock, times(2)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
FileData fileData = createFileData(FTPES_LOCATION, Scheme.FTPS);
doThrow(new DatafileTaskException("Unable to collect file.")).when(ftpsClientMock)
- .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
+ .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectErrorMessage("Retries exhausted: 3/3") //
- .verify();
+ .expectErrorMessage("Retries exhausted: 3/3") //
+ .verify();
verify(ftpsClientMock, times(4)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
}
FileData fileData = createFileData(FTPES_LOCATION, Scheme.FTPS);
doThrow(new NonRetryableDatafileTaskException("Unable to collect file.")).when(ftpsClientMock)
- .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
+ .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectErrorMessage("Non retryable file transfer failure") //
- .verify();
+ .expectErrorMessage("Non retryable file transfer failure") //
+ .verify();
verify(ftpsClientMock, times(1)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
}
FileCollector collectorUndetTest = spy(new FileCollector(appConfigMock, counters));
doReturn(ftpsClientMock).when(collectorUndetTest).createFtpsClient(any());
doThrow(new DatafileTaskException("Unable to collect file.")).doNothing().when(ftpsClientMock)
- .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
+ .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
FilePublishInformation expectedfilePublishInformation =
- createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
+ createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT);
FileData fileData = createFileData(FTPES_LOCATION_NO_PORT, Scheme.FTPS);
StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap))
- .expectNext(expectedfilePublishInformation) //
- .verifyComplete();
+ .expectNext(expectedfilePublishInformation) //
+ .verifyComplete();
verify(ftpsClientMock, times(2)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION);
}
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
+
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
private PublishedChecker publishedCheckerUnderTestSpy;
-
@BeforeAll
private static void setUp() throws DatafileTaskException {
when(publisherConfigurationMock.publishUrl()).thenReturn(PUBLISH_URL);
prepareMocksForTests(HttpUtils.SC_OK, EMPTY_CONTENT, null);
boolean isPublished =
- publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
+ publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
assertFalse(isPublished);
prepareMocksForTests(HttpUtils.SC_BAD_REQUEST, EMPTY_CONTENT, null);
boolean isPublished =
- publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
+ publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
assertFalse(isPublished);
}
prepareMocksForTests(HttpUtils.SC_OK, "[" + LOCAL_FILE_NAME + "]", null);
boolean isPublished =
- publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
+ publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
assertTrue(isPublished);
}
prepareMocksForTests(HttpUtils.SC_OK, EMPTY_CONTENT, new DatafileTaskException(""));
boolean isPublished =
- publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
+ publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP);
assertFalse(isPublished);
}
HttpResponse httpResponseMock = mock(HttpResponse.class);
if (exception == null) {
when(httpClientMock.getDmaapProducerResponseWithCustomTimeout(any(HttpUriRequest.class), any(), any()))
- .thenReturn(httpResponseMock);
+ .thenReturn(httpResponseMock);
} else {
when(httpClientMock.getDmaapProducerResponseWithCustomTimeout(any(HttpUriRequest.class), any(), any()))
- .thenThrow(exception);
+ .thenThrow(exception);
}
HttpEntity httpEntityMock = mock(HttpEntity.class);
StatusLine statusLineMock = mock(StatusLine.class);
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.collectors.datafile.utils.LoggingUtils;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables;
import org.slf4j.MDC;
+
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
private void setUpConfiguration() throws DatafileTaskException {
final PublisherConfiguration dmaapPublisherConfiguration = ImmutablePublisherConfiguration.builder() //
- .publishUrl(publishUrl) //
- .logUrl("") //
- .userName("userName") //
- .passWord("passWord") //
- .trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .build(); //
+ .publishUrl(publishUrl) //
+ .logUrl("") //
+ .userName("userName") //
+ .passWord("passWord") //
+ .trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .build(); //
final ConsumerConfiguration dmaapConsumerConfiguration = ImmutableConsumerConfiguration.builder() //
- .topicUrl("topicUrl").trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .build();
+ .topicUrl("topicUrl").trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .build();
doReturn(dmaapPublisherConfiguration).when(appConfig).getPublisherConfiguration(CHANGE_IDENTIFIER);
doReturn(dmaapConsumerConfiguration).when(appConfig).getDmaapConsumerConfiguration();
private MessageMetaData messageMetaData() {
return ImmutableMessageMetaData.builder() //
- .productName("productName") //
- .vendorName("") //
- .lastEpochMicrosec("") //
- .sourceName("") //
- .startEpochMicrosec("") //
- .timeZoneOffset("") //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .changeType("") //
- .build();
+ .productName("productName") //
+ .vendorName("") //
+ .lastEpochMicrosec("") //
+ .sourceName("") //
+ .startEpochMicrosec("") //
+ .timeZoneOffset("") //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .changeType("") //
+ .build();
}
private FileData fileData(int instanceNumber) {
return ImmutableFileData.builder() //
- .name(PM_FILE_NAME + instanceNumber) //
- .fileFormatType("") //
- .fileFormatVersion("") //
- .location("ftpes://192.168.0.101/ftp/rop/" + PM_FILE_NAME + instanceNumber) //
- .scheme(Scheme.FTPS) //
- .compression("") //
- .messageMetaData(messageMetaData()) //
- .build();
+ .name(PM_FILE_NAME + instanceNumber) //
+ .fileFormatType("") //
+ .fileFormatVersion("") //
+ .location("ftpes://192.168.0.101/ftp/rop/" + PM_FILE_NAME + instanceNumber) //
+ .scheme(Scheme.FTPS) //
+ .compression("") //
+ .messageMetaData(messageMetaData()) //
+ .build();
}
private List<FileData> files(int size, boolean uniqueNames) {
private FilePublishInformation filePublishInformation() {
return ImmutableFilePublishInformation //
- .builder() //
- .productName("") //
- .vendorName("") //
- .lastEpochMicrosec("") //
- .sourceName("") //
- .startEpochMicrosec("") //
- .timeZoneOffset("") //
- .name("") //
- .location("") //
- .internalLocation(Paths.get("internalLocation")) //
- .compression("") //
- .fileFormatType("") //
- .fileFormatVersion("") //
- .changeIdentifier(CHANGE_IDENTIFIER) //
- .context(new HashMap<String, String>()).build();
+ .builder() //
+ .productName("") //
+ .vendorName("") //
+ .lastEpochMicrosec("") //
+ .sourceName("") //
+ .startEpochMicrosec("") //
+ .timeZoneOffset("") //
+ .name("") //
+ .location("") //
+ .internalLocation(Paths.get("internalLocation")) //
+ .compression("") //
+ .fileFormatType("") //
+ .fileFormatVersion("") //
+ .changeIdentifier(CHANGE_IDENTIFIER) //
+ .context(new HashMap<String, String>()).build();
}
@Test
@Test
public void executeDatafileMainTask_unconfiguredChangeIdentifier() throws DatafileTaskException {
final PublisherConfiguration dmaapPublisherConfiguration = ImmutablePublisherConfiguration.builder() //
- .publishUrl(publishUrl) //
- .logUrl("") //
- .userName("userName") //
- .passWord("passWord") //
- .trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .changeIdentifier("Different changeIdentifier") //
- .build(); //
+ .publishUrl(publishUrl) //
+ .logUrl("") //
+ .userName("userName") //
+ .passWord("passWord") //
+ .trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .changeIdentifier("Different changeIdentifier") //
+ .build(); //
final ConsumerConfiguration dmaapConsumerConfiguration = ImmutableConsumerConfiguration.builder() //
- .topicUrl("topicUrl").trustStorePath("trustStorePath") //
- .trustStorePasswordPath("trustStorePasswordPath") //
- .keyStorePath("keyStorePath") //
- .keyStorePasswordPath("keyStorePasswordPath") //
- .enableDmaapCertAuth(true) //
- .build();
+ .topicUrl("topicUrl").trustStorePath("trustStorePath") //
+ .trustStorePasswordPath("trustStorePasswordPath") //
+ .keyStorePath("keyStorePath") //
+ .keyStorePasswordPath("keyStorePasswordPath") //
+ .enableDmaapCertAuth(true) //
+ .build();
doReturn(dmaapPublisherConfiguration).when(appConfig).getPublisherConfiguration(CHANGE_IDENTIFIER);
doReturn(dmaapConsumerConfiguration).when(appConfig).getDmaapConsumerConfiguration();
await().untilAsserted(() -> assertEquals(0, testedObject.getCurrentNumberOfSubscriptions()));
assertTrue("Error missing in log", logAppender.list.toString().contains(
- "[INFO] No feed is configured for: " + CHANGE_IDENTIFIER + ", file ignored: " + PM_FILE_NAME + "1"));
+ "[INFO] No feed is configured for: " + CHANGE_IDENTIFIER + ", file ignored: " + PM_FILE_NAME + "1"));
}
@Test
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(ScheduledTasks.class);
StepVerifier //
- .create(testedObject.createMainTask(contextMap)) //
- .expectSubscription() //
- .expectNextCount(0) //
- .expectComplete() //
- .verify(); //
-
- assertTrue("Error missing in log", logAppender.list.toString().contains(
- "[ERROR] Polling for file ready message failed, " + "exception: java.lang.Exception: Failed"));
+ .create(testedObject.createMainTask(contextMap)) //
+ .expectSubscription() //
+ .expectNextCount(0) //
+ .expectComplete() //
+ .verify(); //
+
+ assertTrue("Error missing in log", logAppender.list.toString()
+ .contains("[ERROR] Polling for file ready message failed, " + "exception: java.lang.Exception: Failed"));
}
@Test
doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull());
StepVerifier //
- .create(testedObject.createMainTask(contextMap)) //
- .expectSubscription() //
- .expectNextCount(noOfFiles) //
- .expectComplete() //
- .verify(); //
+ .create(testedObject.createMainTask(contextMap)) //
+ .expectSubscription() //
+ .expectNextCount(noOfFiles) //
+ .expectComplete() //
+ .verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
assertEquals(0, testedObject.getThreadPoolQueueSize());
// First file collect will fail, 3 will succeed
doReturn(error, collectedFile, collectedFile, collectedFile) //
- .when(fileCollectorMock) //
- .collectFile(any(FileData.class), anyLong(), any(Duration.class), notNull());
+ .when(fileCollectorMock) //
+ .collectFile(any(FileData.class), anyLong(), any(Duration.class), notNull());
doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull());
doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull());
StepVerifier //
- .create(testedObject.createMainTask(contextMap)) //
- .expectSubscription() //
- .expectNextCount(3) //
- .expectComplete() //
- .verify(); //
+ .create(testedObject.createMainTask(contextMap)) //
+ .expectSubscription() //
+ .expectNextCount(3) //
+ .expectComplete() //
+ .verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
verify(consumerMock, times(1)).getMessageRouterResponse();
Mono<Object> error = Mono.error(new Exception("problem"));
// One publish will fail, the rest will succeed
doReturn(collectedFile, error, collectedFile, collectedFile) //
- .when(dataRouterMock) //
- .publishFile(notNull(), anyLong(), notNull());
+ .when(dataRouterMock) //
+ .publishFile(notNull(), anyLong(), notNull());
ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(ScheduledTasks.class);
StepVerifier //
- .create(testedObject.createMainTask(contextMap)) //
- .expectSubscription() //
- .expectNextCount(3) // 3 completed files
- .expectComplete() //
- .verify(); //
+ .create(testedObject.createMainTask(contextMap)) //
+ .expectSubscription() //
+ .expectNextCount(3) // 3 completed files
+ .expectComplete() //
+ .verify(); //
assertTrue("Error missing in log", logAppender.list.toString().contains("[ERROR] File publishing failed: "));
doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull());
StepVerifier //
- .create(testedObject.createMainTask(contextMap)).expectSubscription() //
- .expectNextCount(1) // 99 is skipped
- .expectComplete() //
- .verify(); //
+ .create(testedObject.createMainTask(contextMap)).expectSubscription() //
+ .expectNextCount(1) // 99 is skipped
+ .expectComplete() //
+ .verify(); //
assertEquals(0, testedObject.getCurrentNumberOfTasks());
verify(consumerMock, times(1)).getMessageRouterResponse();
additionalFieldsString.append("]");
}
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() //
- + "}" //
- + "}" //
- + "}";
+ + "\"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() //
+ + "}" //
+ + "}" //
+ + "}";
}
private JsonMessage(final JsonMessageBuilder builder) {
@Override
public String toString() {
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("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) //
+ + "}" //
+ + "}";
}
private AdditionalField(AdditionalFieldBuilder builder) {
}
private static String getAsStringIfParameterIsSet(String parameterName, String parameterValue,
- boolean withSeparator) {
+ boolean withSeparator) {
String result = "";
if (parameterValue != null) {
result = "\"" + parameterName + "\":\"" + parameterValue + "\"";
*/
public static void main(String[] args) {
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();
+ .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") //
- .build();
+ .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) //
- .build();
+ .eventName("Noti_NrRadio-Ericsson_FileReady") //
+ .changeIdentifier("PM_MEAS_FILES") //
+ .changeType("FileReady") //
+ .notificationFieldsVersion("2.0") //
+ .addAdditionalField(additionalField) //
+ .addAdditionalField(secondAdditionalField) //
+ .build();
System.out.println(message.toString());
}
}
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+
import org.slf4j.LoggerFactory;
public class LoggingUtils {
/**
* Returns a ListAppender that contains all logging events. Call this method at the very beginning of the test
- * */
+ */
public static ListAppender<ILoggingEvent> getLogListAppender(Class<?> logClass) {
Logger logger = (Logger) LoggerFactory.getLogger(logClass);
ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
import java.util.HashMap;
import java.util.Map;
+
import org.apache.http.Header;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;