diff options
author | Stavros Kanarakis <stavros.kanarakis@nokia.com> | 2019-03-29 10:44:59 +0200 |
---|---|---|
committer | Stavros Kanarakis <stavros.kanarakis@nokia.com> | 2019-04-01 09:55:59 +0300 |
commit | bc054e72de5bf2cca24dbd3f10f4bf5c8b81d242 (patch) | |
tree | 1ff35e132cfa2b40303c40e9c8d1d188b2f64ffd /components/bbs-event-processor/src | |
parent | c755a434e1202cb8f1ce7a18062e31e0912f989a (diff) |
Externalized Logging Level. Corrected tag name for images
Change-Id: Icfd8992f2fb620d80d5af2f79b9f847dc01f9938
Issue-ID: DCAEGEN2-1354
Signed-off-by: Stavros Kanarakis <stavros.kanarakis@nokia.com>
Diffstat (limited to 'components/bbs-event-processor/src')
9 files changed, 96 insertions, 0 deletions
diff --git a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ApplicationConfiguration.java b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ApplicationConfiguration.java index 69fa83d2..981d9633 100644 --- a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ApplicationConfiguration.java +++ b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ApplicationConfiguration.java @@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull; import org.onap.bbs.event.processor.exceptions.ApplicationEnvironmentException; import org.onap.bbs.event.processor.exceptions.ConfigurationParsingException; import org.onap.bbs.event.processor.model.GeneratedAppConfigObject; +import org.onap.bbs.event.processor.utilities.LoggingUtil; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration; @@ -234,6 +235,8 @@ public class ApplicationConfiguration implements ConfigurationChangeObservable { genericProperties.getReRegistration().setClControlName(newConfiguration.reRegistrationClControlName()); genericProperties.getCpeAuthentication().setPolicyScope(newConfiguration.cpeAuthPolicyScope()); genericProperties.getCpeAuthentication().setClControlName(newConfiguration.cpeAuthClControlName()); + + LoggingUtil.changeLoggingLevel(newConfiguration.loggingLevel()); } notifyObservers(); diff --git a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ConsulConfigurationGateway.java b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ConsulConfigurationGateway.java index 6530f0b2..1d27fc0a 100644 --- a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ConsulConfigurationGateway.java +++ b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ConsulConfigurationGateway.java @@ -176,6 +176,8 @@ public class ConsulConfigurationGateway { final String cpeAuthConfigKey = configObject.get("application.cpeAuth.configKey").getAsString(); final String closeLoopConfigKey = configObject.get("application.closeLoop.configKey").getAsString(); + final String loggingLevel = configObject.get("application.loggingLevel").getAsString(); + final JsonObject streamsPublishes = configObject.getAsJsonObject("streams_publishes"); final JsonObject streamsSubscribes = configObject.getAsJsonObject("streams_subscribes"); @@ -208,6 +210,7 @@ public class ConsulConfigurationGateway { .reRegConfigKey(reRegConfigKey) .cpeAuthConfigKey(cpeAuthConfigKey) .closeLoopConfigKey(closeLoopConfigKey) + .loggingLevel(loggingLevel) .streamSubscribesMap(parseStreamsObjects(streamsSubscribes)) .streamPublishesMap(parseStreamsObjects(streamsPublishes)) .build(); diff --git a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/controllers/BbsEventProcessorController.java b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/controllers/BbsEventProcessorController.java index 09691c16..135b41d4 100644 --- a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/controllers/BbsEventProcessorController.java +++ b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/controllers/BbsEventProcessorController.java @@ -30,12 +30,14 @@ import java.util.concurrent.Executors; import org.onap.bbs.event.processor.pipelines.CpeAuthenticationPipeline; import org.onap.bbs.event.processor.pipelines.ReRegistrationPipeline; import org.onap.bbs.event.processor.pipelines.Scheduler; +import org.onap.bbs.event.processor.utilities.LoggingUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; @@ -171,4 +173,24 @@ public class BbsEventProcessorController { ); } } + + /** + * Change logging level for BBS code. + * @param level new logging level + * @return Proper HTTP response based on change logging level result + */ + @PostMapping("logging/{level}") + public Mono<ResponseEntity<String>> changeLoggingLevel(@PathVariable String level) { + return Mono.defer(() -> { + if (LoggingUtil.changeLoggingLevel(level)) { + LOGGER.info("Changed logging level to {}", level); + return Mono.just(new ResponseEntity<>("Changed BBS event processor logging level\n", + HttpStatus.OK)); + } else { + return Mono.just(new ResponseEntity<>("Unacceptable logging level\n", + HttpStatus.NOT_ACCEPTABLE)); + } + } + ); + } } diff --git a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/model/GeneratedAppConfigObject.java b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/model/GeneratedAppConfigObject.java index 12716ce4..4fdb81be 100644 --- a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/model/GeneratedAppConfigObject.java +++ b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/model/GeneratedAppConfigObject.java @@ -120,6 +120,9 @@ public interface GeneratedAppConfigObject { @SerializedName(value = "application.closeLoop.configKey", alternate = "application.closeLoop.configKey") String closeLoopConfigKey(); + @SerializedName(value = "application.loggingLevel", alternate = "application.loggingLevel") + String loggingLevel(); + @SerializedName(value = "streams_subscribes", alternate = "streams_subscribes") Map<String, StreamsObject> streamSubscribesMap(); diff --git a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/CpeAuthenticationDmaapConsumerJsonParser.java b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/CpeAuthenticationDmaapConsumerJsonParser.java index 62ab02d5..2bb5d98a 100644 --- a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/CpeAuthenticationDmaapConsumerJsonParser.java +++ b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/CpeAuthenticationDmaapConsumerJsonParser.java @@ -33,6 +33,7 @@ import static org.onap.bbs.event.processor.utilities.CpeAuthenticationEventField import static org.onap.bbs.event.processor.utilities.CpeAuthenticationEventFields.STATE_INTERFACE; import static org.onap.bbs.event.processor.utilities.CpeAuthenticationEventFields.SW_VERSION; +import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -54,6 +55,7 @@ import reactor.core.publisher.Mono; public class CpeAuthenticationDmaapConsumerJsonParser { private static final Logger LOGGER = LoggerFactory.getLogger(CpeAuthenticationDmaapConsumerJsonParser.class); + private static final Gson gson = new Gson(); private static final String CPE_AUTHENTICATION_DUMPING_TEMPLATE = "%n{" + "\"" + CORRELATION_ID + COMMON_FORMAT + "," @@ -111,6 +113,8 @@ public class CpeAuthenticationDmaapConsumerJsonParser { private Mono<CpeAuthenticationConsumerDmaapModel> transform(JsonObject dmaapResponseJsonObject) { + LOGGER.trace("Event from DMaaP to be parsed: \n{}", gson.toJson(dmaapResponseJsonObject)); + if (!containsProperHeaders(dmaapResponseJsonObject)) { LOGGER.warn("Incorrect CPE Authentication JSON event - missing headers"); return Mono.empty(); diff --git a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/LoggingUtil.java b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/LoggingUtil.java new file mode 100644 index 00000000..efb90d41 --- /dev/null +++ b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/LoggingUtil.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * BBS-RELOCATION-CPE-AUTHENTICATION-HANDLER + * ================================================================================ + * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.bbs.event.processor.utilities; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; + +import java.util.Arrays; +import java.util.List; + +import org.slf4j.LoggerFactory; + +public class LoggingUtil { + + private static final String BBS_EP_APPLICATION_PACKAGE = "org.onap.bbs"; + private static final Logger applicationLogger = (Logger) LoggerFactory.getLogger(BBS_EP_APPLICATION_PACKAGE); + private static final List<String> loggingLevels = + Arrays.asList("OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"); + + // Non-instantiable class + private LoggingUtil() { + } + + /** + * Change Application logging level. + * @param level logging level. Must be one of OFF, ERROR, WARN, INFO, DEBUG, TRACE + * @return Flag indicating if it changed the level or not + */ + public static boolean changeLoggingLevel(String level) { + if (loggingLevels.contains(level)) { + applicationLogger.setLevel(Level.toLevel(level)); + return true; + } + return false; + } +} diff --git a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/ReRegistrationDmaapConsumerJsonParser.java b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/ReRegistrationDmaapConsumerJsonParser.java index 7dd8a3d2..947d7a7c 100644 --- a/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/ReRegistrationDmaapConsumerJsonParser.java +++ b/components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/ReRegistrationDmaapConsumerJsonParser.java @@ -28,6 +28,7 @@ import static org.onap.bbs.event.processor.utilities.ReRegistrationEventFields.C import static org.onap.bbs.event.processor.utilities.ReRegistrationEventFields.REMOTE_ID; import static org.onap.bbs.event.processor.utilities.ReRegistrationEventFields.SVLAN; +import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -49,6 +50,7 @@ import reactor.core.publisher.Mono; public class ReRegistrationDmaapConsumerJsonParser { private static final Logger LOGGER = LoggerFactory.getLogger(ReRegistrationDmaapConsumerJsonParser.class); + private static final Gson gson = new Gson(); private static final String RE_REGISTRATION_DUMPING_TEMPLATE = "%n{" + "\"" + CORRELATION_ID + COMMON_FORMAT + "," @@ -104,6 +106,8 @@ public class ReRegistrationDmaapConsumerJsonParser { private Mono<ReRegistrationConsumerDmaapModel> transform(JsonObject dmaapResponseJsonObject) { + LOGGER.trace("Event from DMaaP to be parsed: \n{}", gson.toJson(dmaapResponseJsonObject)); + if (!containsProperHeaders(dmaapResponseJsonObject)) { LOGGER.warn("Incorrect JsonObject - missing headers"); return Mono.empty(); diff --git a/components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ApplicationConfigurationTest.java b/components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ApplicationConfigurationTest.java index 7b81b1be..220466bc 100644 --- a/components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ApplicationConfigurationTest.java +++ b/components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ApplicationConfigurationTest.java @@ -286,6 +286,7 @@ class ApplicationConfigurationTest { .reRegConfigKey("config_key_1") .cpeAuthConfigKey("config_key_2") .closeLoopConfigKey("config_key_3") + .loggingLevel("TRACE") .streamSubscribesMap(subscribes) .streamPublishesMap(Collections.singletonMap("config_key_3", streamsObject3)) .build(); diff --git a/components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ConsulConfigurationGatewayTest.java b/components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ConsulConfigurationGatewayTest.java index cd20d1e1..9f5ce6dc 100644 --- a/components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ConsulConfigurationGatewayTest.java +++ b/components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ConsulConfigurationGatewayTest.java @@ -83,6 +83,7 @@ class ConsulConfigurationGatewayTest { + "\"application.reregistration.configKey\": \"config_key_2\"," + "\"application.cpeAuth.configKey\": \"config_key_1\"," + "\"application.closeLoop.configKey\": \"config_key_3\"," + + "\"application.loggingLevel\": \"TRACE\"," + "\"streams_subscribes\": {" + "\"config_key_1\": {" + "\"type\": \"message_router\"," @@ -201,6 +202,7 @@ class ConsulConfigurationGatewayTest { .reRegConfigKey("config_key_2") .cpeAuthConfigKey("config_key_1") .closeLoopConfigKey("config_key_3") + .loggingLevel("TRACE") .streamSubscribesMap(subscribes) .streamPublishesMap(Collections.singletonMap("config_key_3", streamsObject3)) .build(); |