diff options
Diffstat (limited to 'prh-app-server/src/main')
12 files changed, 71 insertions, 23 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java index b774f545..bc4bbf80 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/CloudConfiguration.java @@ -36,10 +36,10 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import reactor.core.publisher.Flux; import reactor.core.scheduler.Schedulers; - /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 8/9/18 */ diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java index ad040f6e..2fb61c06 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java @@ -20,29 +20,30 @@ package org.onap.dcaegen2.services.prh.configuration; +import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.INVOCATION_ID; +import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.REQUEST_ID; + import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import com.google.gson.TypeAdapterFactory; - import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; - import java.nio.charset.StandardCharsets; import java.util.ServiceLoader; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; - import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; @@ -140,4 +141,11 @@ public abstract class PrhAppConfig implements Config { this.filepath = filepath; } + public void setXOnapRequestId(String xOnapRequestId) { + MDC.put(REQUEST_ID, xOnapRequestId); + } + + public void setXInvocationId(String xInvocationId) { + MDC.put(INVOCATION_ID, xInvocationId); + } }
\ No newline at end of file diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SchedulerConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SchedulerConfig.java index a27feefb..6132a674 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SchedulerConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SchedulerConfig.java @@ -28,6 +28,10 @@ import java.util.List; import java.util.concurrent.ScheduledFuture; import javax.annotation.PostConstruct; import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Configuration; @@ -49,6 +53,8 @@ public class SchedulerConfig { private static final int SCHEDULING_DELAY_FOR_PRH_TASKS = 5; private static final int SCHEDULING_REQUEST_FOR_CONFIGURATION_DELAY = 5; private static volatile List<ScheduledFuture> scheduledPrhTaskFutureList = new ArrayList<>(); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Marker ENTRY = MarkerFactory.getMarker("ENRTY"); private final ConcurrentTaskScheduler taskScheduler; private final ScheduledTasks scheduledTask; @@ -88,6 +94,7 @@ public class SchedulerConfig { @PostConstruct @ApiOperation(value = "Start task if possible") public synchronized boolean tryToStartTask() { + logger.info(ENTRY,"Start scheduling PRH workflow"); if (scheduledPrhTaskFutureList.isEmpty()) { scheduledPrhTaskFutureList.add(cloudTaskScheduler .scheduleAtFixedRate(cloudConfiguration::runTask, Instant.now(), diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java index 10bf2755..ecd2ef4c 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/SwaggerConfig.java @@ -50,6 +50,7 @@ public class SwaggerConfig extends WebMvcConfigurationSupport { /** * Swagger configuration function for hosting it next to spring http website. + * * @return Docket */ @Bean diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java index 0135ef76..573724d8 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/controllers/HeartbeatController.java @@ -54,7 +54,7 @@ public class HeartbeatController { @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"), @ApiResponse(code = 404, message = "The resource you were trying to reach is not found") - } + } ) public Mono<ResponseEntity<String>> heartbeat() { logger.trace("Receiving heartbeat request"); diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java index 379d10c6..f5b8307b 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java @@ -30,6 +30,8 @@ import org.onap.dcaegen2.services.prh.model.utils.HttpUtils; import org.onap.dcaegen2.services.prh.service.producer.AaiProducerReactiveHttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; @@ -42,6 +44,8 @@ public class AaiProducerTaskImpl extends AaiProducerTask { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); + private final Config config; private AaiProducerReactiveHttpClient aaiProducerReactiveHttpClient; @@ -80,7 +84,7 @@ public class AaiProducerTaskImpl extends throw new DmaapNotFoundException("Invoked null object to DMaaP task"); } aaiProducerReactiveHttpClient = resolveClient(); - logger.trace("Method called with arg {}", consumerDmaapModel); + logger.info(INVOKE, "Method called with arg {}", consumerDmaapModel); return publish(consumerDmaapModel); } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java index bf3acccc..9e1fadf1 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java @@ -20,14 +20,19 @@ package org.onap.dcaegen2.services.prh.tasks; +import java.util.Map; import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; import org.onap.dcaegen2.services.prh.configuration.Config; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.model.logging.MDCVariables; import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser; import org.onap.dcaegen2.services.prh.service.consumer.DMaaPConsumerReactiveHttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; @@ -39,6 +44,7 @@ import reactor.core.publisher.Mono; public class DmaapConsumerTaskImpl extends DmaapConsumerTask { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); private final Config config; private DmaapConsumerJsonParser dmaapConsumerJsonParser; private DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient; @@ -62,8 +68,8 @@ public class DmaapConsumerTaskImpl extends DmaapConsumerTask { @Override public Mono<ConsumerDmaapModel> execute(String object) { dmaaPConsumerReactiveHttpClient = resolveClient(); - logger.trace("Method called with arg {}", object); - return consume((dmaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse())); + logger.info(INVOKE, "Method called with arg {}", object); + return consume(dmaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()); } @Override diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java index d4e1c1e3..73260381 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java @@ -27,6 +27,8 @@ import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.service.producer.DMaaPProducerReactiveHttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; @@ -38,6 +40,7 @@ import reactor.core.publisher.Mono; public class DmaapPublisherTaskImpl extends DmaapPublisherTask { private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Marker INVOKE = MarkerFactory.getMarker("INVOKE"); private final Config config; private DMaaPProducerReactiveHttpClient dmaapProducerReactiveHttpClient; @@ -61,7 +64,7 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask { throw new DmaapNotFoundException("Invoked null object to DMaaP task"); } dmaapProducerReactiveHttpClient = resolveClient(); - logger.trace("Method called with arg {}", consumerDmaapModel); + logger.info(INVOKE, "Method called with arg {}", consumerDmaapModel); return publish(consumerDmaapModel); } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java index c021abe2..6432a338 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/ScheduledTasks.java @@ -20,12 +20,21 @@ package org.onap.dcaegen2.services.prh.tasks; +import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.INSTANCE_UUID; +import static org.onap.dcaegen2.services.prh.model.logging.MDCVariables.RESPONSE_CODE; + +import java.util.Map; +import java.util.UUID; import java.util.concurrent.Callable; import org.onap.dcaegen2.services.prh.exceptions.DmaapEmptyResponseException; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.prh.model.logging.MDCVariables; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; @@ -38,10 +47,10 @@ import reactor.core.scheduler.Schedulers; public class ScheduledTasks { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private final DmaapConsumerTask dmaapConsumerTask; private final DmaapPublisherTask dmaapProducerTask; private final AaiProducerTask aaiProducerTask; + private Map<String, String> contextMap = MDC.getCopyOfContextMap(); /** * Constructor for tasks registration in PRHWorkflow. @@ -62,6 +71,7 @@ public class ScheduledTasks { * Main function for scheduling prhWorkflow. */ public void scheduleMainPrhEventTask() { + MDCVariables.setMdcContextMap(contextMap); logger.trace("Execution of tasks was registered"); Mono<String> dmaapProducerResponse = Mono.fromCallable(consumeFromDMaaPMessage()) @@ -78,6 +88,7 @@ public class ScheduledTasks { } private void onSuccess(String responseCode) { + MDC.put(RESPONSE_CODE, responseCode); logger.info("Prh consumed tasks. HTTP Response code {}", responseCode); } @@ -89,6 +100,8 @@ public class ScheduledTasks { private Callable<Mono<ConsumerDmaapModel>> consumeFromDMaaPMessage() { return () -> { + MDCVariables.setMdcContextMap(contextMap); + MDC.put(INSTANCE_UUID, UUID.randomUUID().toString()); dmaapConsumerTask.initConfigs(); return dmaapConsumerTask.execute(""); }; diff --git a/prh-app-server/src/main/resources/application.properties b/prh-app-server/src/main/resources/application.properties index fa38d188..ac0192ca 100644 --- a/prh-app-server/src/main/resources/application.properties +++ b/prh-app-server/src/main/resources/application.properties @@ -9,4 +9,6 @@ logging.level.root=ERROR logging.level.org.springframework=ERROR logging.level.org.springframework.data=ERROR logging.level.org.onap.dcaegen2.services.prh=INFO -app.filepath=config/prh_endpoints.json
\ No newline at end of file +app.filepath=config/prh_endpoints.json +app.xonaprequestid=requestID +app.xinvocationid=invocationID diff --git a/prh-app-server/src/main/resources/logback-spring.xml b/prh-app-server/src/main/resources/logback-spring.xml index 74c386b6..427373fd 100644 --- a/prh-app-server/src/main/resources/logback-spring.xml +++ b/prh-app-server/src/main/resources/logback-spring.xml @@ -1,7 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/defaults.xml"/> - <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}"/> + <property name="LOG_FILE" + value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/spring.log}"/> <property name="FILE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN}"/> <Property name="outputFilename" value="prh-app-server_output"/> <Property name="log-path" value="/var/log/ONAP/prh/prh-app-server"/> @@ -11,7 +12,7 @@ <property name="totalSizeCap" value="10GB"/> <springProfile name="dev"> - <appender name="CONSOLE" target="SYSTEM_OUT" class="ch.qos.logback.core.ConsoleAppender"> + <appender class="ch.qos.logback.core.ConsoleAppender" name="CONSOLE" target="SYSTEM_OUT"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <Pattern>%nopexception%logger |%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} @@ -21,10 +22,11 @@ |%replace(%replace(%rootException){'\t','\\\\t'}){'\n','\\\\n'} |%replace(%replace(%marker){'\t','\\\\t'}){'\n','\\\\n'} |%thread - |%n</Pattern> + |%n + </Pattern> </encoder> </appender> - <appender name="ROLLING-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <appender class="ch.qos.logback.core.rolling.RollingFileAppender" name="ROLLING-FILE"> <encoder> <pattern>%nopexception%logger |%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} @@ -34,7 +36,8 @@ |%replace(%replace(%rootException){'\t','\\\\t'}){'\n','\\\\n'} |%replace(%replace(%marker){'\t','\\\\t'}){'\n','\\\\n'} |%thread - |%n</pattern> + |%n + </pattern> </encoder> <file>${LOG_FILE}</file> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> @@ -51,7 +54,7 @@ </springProfile> <springProfile name="prod"> - <appender name="ROLLING-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <appender class="ch.qos.logback.core.rolling.RollingFileAppender" name="ROLLING-FILE"> <encoder> <pattern>%nopexception%logger |%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC} @@ -61,7 +64,8 @@ |%replace(%replace(%rootException){'\t','\\\\t'}){'\n','\\\\n'} |%replace(%replace(%marker){'\t','\\\\t'}){'\n','\\\\n'} |%thread - |%n</pattern> + |%n + </pattern> </encoder> <File>${log-path}/${outputFilename}.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> diff --git a/prh-app-server/src/main/resources/scheduled-context.xml b/prh-app-server/src/main/resources/scheduled-context.xml index 91919aa2..82067c17 100644 --- a/prh-app-server/src/main/resources/scheduled-context.xml +++ b/prh-app-server/src/main/resources/scheduled-context.xml @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" +<beans xmlns:context="http://www.springframework.org/schema/context" xmlns:task="http://www.springframework.org/schema/task" - xmlns:context="http://www.springframework.org/schema/context" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> @@ -10,7 +10,7 @@ <context:component-scan base-package="org.onap.dcaegen2.services.prh"/> <task:scheduled-tasks> - <task:scheduled ref="scheduleController" method="startTasks" - fixed-rate="1000"/> + <task:scheduled fixed-rate="1000" method="startTasks" + ref="scheduleController"/> </task:scheduled-tasks> </beans> |