From bc054e72de5bf2cca24dbd3f10f4bf5c8b81d242 Mon Sep 17 00:00:00 2001 From: Stavros Kanarakis Date: Fri, 29 Mar 2019 10:44:59 +0200 Subject: Externalized Logging Level. Corrected tag name for images Change-Id: Icfd8992f2fb620d80d5af2f79b9f847dc01f9938 Issue-ID: DCAEGEN2-1354 Signed-off-by: Stavros Kanarakis --- .../dpo/blueprints/bbs-event-processor-input.yaml | 2 +- .../k8s-bbs-event-processor.yaml-template | 6 ++- .../dpo/spec/bbs-event-processor-spec.json | 10 +++- components/bbs-event-processor/pom.xml | 14 +++++- .../processor/config/ApplicationConfiguration.java | 3 ++ .../config/ConsulConfigurationGateway.java | 3 ++ .../controllers/BbsEventProcessorController.java | 22 +++++++++ .../processor/model/GeneratedAppConfigObject.java | 3 ++ .../CpeAuthenticationDmaapConsumerJsonParser.java | 4 ++ .../bbs/event/processor/utilities/LoggingUtil.java | 54 ++++++++++++++++++++++ .../ReRegistrationDmaapConsumerJsonParser.java | 4 ++ .../config/ApplicationConfigurationTest.java | 1 + .../config/ConsulConfigurationGatewayTest.java | 2 + 13 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/LoggingUtil.java (limited to 'components/bbs-event-processor') diff --git a/components/bbs-event-processor/dpo/blueprints/bbs-event-processor-input.yaml b/components/bbs-event-processor/dpo/blueprints/bbs-event-processor-input.yaml index 36e69cf6..420b5018 100644 --- a/components/bbs-event-processor/dpo/blueprints/bbs-event-processor-input.yaml +++ b/components/bbs-event-processor/dpo/blueprints/bbs-event-processor-input.yaml @@ -16,7 +16,7 @@ # ============LICENSE_END========================================================= -tag_version: nexus3.onap.org:10003/dcae-services/org.onap.dcaegen2.services.components.bbs-event-processor:1.0.0-SNAPSHOT +tag_version: nexus3.onap.org:10003/onap/org.onap.dcaegen2.services.components.bbs-event-processor:1.0.0-SNAPSHOT pnf_reregistration_url: http:message-router:3904/events/unauthenticated.PNF_UPDATE cpe_authentication_url: http:message-router:3904/events/unauthenticated.CPE_AUTHENTICATION close_loop_url: http:message-router:3904/events/unauthenticated.DCAE_CL_OUTPUT diff --git a/components/bbs-event-processor/dpo/blueprints/k8s-bbs-event-processor.yaml-template b/components/bbs-event-processor/dpo/blueprints/k8s-bbs-event-processor.yaml-template index e9550314..2d2c7a5d 100644 --- a/components/bbs-event-processor/dpo/blueprints/k8s-bbs-event-processor.yaml-template +++ b/components/bbs-event-processor/dpo/blueprints/k8s-bbs-event-processor.yaml-template @@ -21,7 +21,7 @@ tosca_definitions_version: cloudify_dsl_1_3 imports: - "http://www.getcloudify.org/spec/cloudify/3.4/types.yaml" - - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R3/k8splugin/1.4.4/k8splugin_types.yaml + - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R4/k8splugin/1.4.11/k8splugin_types.yaml inputs: aai_enrichment_host: @@ -87,6 +87,9 @@ inputs: application_cbs_polling_interval_sec: type: integer default: 300 + application_logging_level: + type: string + default: "INFO" dmaap_consumer_id: type: string dmaap_consumer_group: @@ -138,6 +141,7 @@ node_templates: application.reregistration.configKey: "pnf_reregistration" application.cpeAuth.configKey: "cpe_authentication" application.closeLoop.configKey: "close_loop" + application.loggingLevel: { get_input: application_logging_level } host_port: { get_input: host_port } container_port: diff --git a/components/bbs-event-processor/dpo/spec/bbs-event-processor-spec.json b/components/bbs-event-processor/dpo/spec/bbs-event-processor-spec.json index 8710a877..49b0e8f6 100644 --- a/components/bbs-event-processor/dpo/spec/bbs-event-processor-spec.json +++ b/components/bbs-event-processor/dpo/spec/bbs-event-processor-spec.json @@ -280,6 +280,14 @@ "policy_editable": true, "sourced_at_deployment": true, "description": "Config-key for Close Loop" + }, + { + "name": "application.loggingLevel", + "value": "INFO", + "designer_editable": false, + "policy_editable": false, + "sourced_at_deployment": true, + "description": "Application Logging Level" } ], "auxilary": { @@ -292,7 +300,7 @@ }, "artifacts": [ { - "uri": "nexus3.onap.org:10003/dcae-services/org.onap.dcaegen2.services.components.bbs-event-processor:1.0.0-SNAPSHOT", + "uri": "nexus3.onap.org:10003/onap/org.onap.dcaegen2.services.components.bbs-event-processor:1.0.0-SNAPSHOT", "type": "docker image" } ] diff --git a/components/bbs-event-processor/pom.xml b/components/bbs-event-processor/pom.xml index 26a48787..ae9583ec 100644 --- a/components/bbs-event-processor/pom.xml +++ b/components/bbs-event-processor/pom.xml @@ -45,7 +45,7 @@ libs ${project.build.directory}/${dependency.dir.name} /opt - dcae-services/${project.groupId}.${project.artifactId} + onap/${project.groupId}.${project.artifactId} yyyyMMdd'T'HHmmss @@ -370,6 +370,18 @@ build + + tag-and-push-image-latest + deploy + + tag + + + ${docker.image.name}:latest + ${onap.nexus.dockerregistry.daily}/${docker.image.name}:latest + true + + tag-and-push-image-with-version deploy 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> 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 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 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 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 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(); -- cgit 1.2.3-korg