Externalized Logging Level. Corrected tag name for images 85/83685/2
authorStavros Kanarakis <stavros.kanarakis@nokia.com>
Fri, 29 Mar 2019 08:44:59 +0000 (10:44 +0200)
committerStavros Kanarakis <stavros.kanarakis@nokia.com>
Mon, 1 Apr 2019 06:55:59 +0000 (09:55 +0300)
Change-Id: Icfd8992f2fb620d80d5af2f79b9f847dc01f9938
Issue-ID: DCAEGEN2-1354
Signed-off-by: Stavros Kanarakis <stavros.kanarakis@nokia.com>
13 files changed:
components/bbs-event-processor/dpo/blueprints/bbs-event-processor-input.yaml
components/bbs-event-processor/dpo/blueprints/k8s-bbs-event-processor.yaml-template
components/bbs-event-processor/dpo/spec/bbs-event-processor-spec.json
components/bbs-event-processor/pom.xml
components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ApplicationConfiguration.java
components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/config/ConsulConfigurationGateway.java
components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/controllers/BbsEventProcessorController.java
components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/model/GeneratedAppConfigObject.java
components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/CpeAuthenticationDmaapConsumerJsonParser.java
components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/LoggingUtil.java [new file with mode: 0644]
components/bbs-event-processor/src/main/java/org/onap/bbs/event/processor/utilities/ReRegistrationDmaapConsumerJsonParser.java
components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ApplicationConfigurationTest.java
components/bbs-event-processor/src/test/java/org/onap/bbs/event/processor/config/ConsulConfigurationGatewayTest.java

index 36e69cf..420b501 100644 (file)
@@ -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
index e955031..2d2c7a5 100644 (file)
@@ -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:
index 8710a87..49b0e8f 100644 (file)
       "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": {
   },
   "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"
     }
   ]
index 26a4878..ae9583e 100644 (file)
@@ -45,7 +45,7 @@
         <dependency.dir.name>libs</dependency.dir.name>
         <dependency.dir.location>${project.build.directory}/${dependency.dir.name}</dependency.dir.location>
         <docker.artifact.dir>/opt</docker.artifact.dir>
-        <docker.image.name>dcae-services/${project.groupId}.${project.artifactId}</docker.image.name>
+        <docker.image.name>onap/${project.groupId}.${project.artifactId}</docker.image.name>
         <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
     </properties>
 
                             <goal>build</goal>
                         </goals>
                     </execution>
+                    <execution>
+                        <id>tag-and-push-image-latest</id>
+                        <phase>deploy</phase>
+                        <goals>
+                            <goal>tag</goal>
+                        </goals>
+                        <configuration>
+                            <image>${docker.image.name}:latest</image>
+                            <newName>${onap.nexus.dockerregistry.daily}/${docker.image.name}:latest</newName>
+                            <pushImage>true</pushImage>
+                        </configuration>
+                    </execution>
                     <execution>
                         <id>tag-and-push-image-with-version</id>
                         <phase>deploy</phase>
index 69fa83d..981d963 100644 (file)
@@ -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();
index 6530f0b..1d27fc0 100644 (file)
@@ -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();
index 09691c1..135b41d 100644 (file)
@@ -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));
+                }
+            }
+        );
+    }
 }
index 12716ce..4fdb81b 100644 (file)
@@ -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();
 
index 62ab02d..2bb5d98 100644 (file)
@@ -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 (file)
index 0000000..efb90d4
--- /dev/null
@@ -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;
+    }
+}
index 7dd8a3d..947d7a7 100644 (file)
@@ -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();
index 7b81b1b..220466b 100644 (file)
@@ -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();
index cd20d1e..9f5ce6d 100644 (file)
@@ -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();