Merge "NBI documentation using swagger UI"
authorHenrik Andersson <henrik.b.andersson@est.tech>
Wed, 29 Jan 2020 16:08:38 +0000 (16:08 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Wed, 29 Jan 2020 16:08:38 +0000 (16:08 +0000)
policy-agent/dpo/blueprints/k8s-policy-agent.yaml [new file with mode: 0644]
policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java
policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumerImpl.java
policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageHandler.java
policy-agent/src/main/java/org/oransc/policyagent/tasks/StartupService.java

diff --git a/policy-agent/dpo/blueprints/k8s-policy-agent.yaml b/policy-agent/dpo/blueprints/k8s-policy-agent.yaml
new file mode 100644 (file)
index 0000000..0121d27
--- /dev/null
@@ -0,0 +1,111 @@
+
+#description: Docker application of policy agent managing policies
+#blueprint_version: 1.0.0
+---
+tosca_definitions_version: cloudify_dsl_1_3
+description: Docker application to collect log file from PNF
+imports:
+  - http://www.getcloudify.org/spec/cloudify/4.3.1/types.yaml
+  - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.dcaegen2.platform.plugins/R5/k8splugin/1.6.0/k8splugin_types.yaml
+  - https://nexus.onap.org/service/local/repositories/raw/content/org.onap.ccsdk.platform.plugins/type_files/dmaap/dmaap.yaml
+inputs:
+  policy-agent_cpu_limit:
+    type: string
+    default: "250m"
+  policy-agent_cpu_request:
+    type: string
+    default: "250m"
+  policy-agent_memory_limit:
+    type: string
+    default: "256Mi"
+  policy-agent_memory_request:
+    type: string
+    default: "256Mi"
+  envs:
+    default: {}
+  external_port:
+    type: string
+    default: ":0"
+  publish_topic_name:
+    type: string
+    default: "A1-POLICY-AGENT-WRITE"
+  subscribe_topic_name:
+    type: string
+    default: "A1-POLICY-AGENT-READ"
+  consumer_group:
+    type: string
+    default: "users"
+  consumer_id:
+    type: string
+    default: "policy-agent"
+  log_directory:
+    type: string
+    default: "/var/log/policy-agent"
+  replicas:
+    type: integer
+    description: number of instances
+    default: 1
+  tag_version:
+    type: string
+    default: "nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-policy-agent:1.0.0"
+node_templates:
+  policy-agent:
+    type: dcae.nodes.ContainerizedServiceComponentUsingDmaap
+    interfaces:
+      cloudify.interfaces.lifecycle:
+        start:
+          inputs:
+            envs:
+              get_input: envs
+    properties:
+      application_config:
+        streams_publishes:
+          dmaap_publisher:
+            dmaap_info:
+              topic_url: { concat: ['https://message-router:3905/events/',{ get_input: publish_topic_name }] }
+            type: message_router
+        streams_subscribes:
+          dmaap_subscriber:
+            dmaap_info:
+              topic_url: { concat: ['https://message-router:3905/events/',{ get_input: subscribe_topic_name }, '/', { get_input: consumer_group }, "/", { get_input: consumer_id }] }
+            type: message_router
+        ric:
+          - name: ric1
+            baseUrl: http://localhost:8083/
+            managedElementIds:
+              - kista_1
+              - kista_2
+          - name: ric2
+            baseUrl: http://localhost:8085/
+            managedElementIds:
+              - kista_3
+              - kista_4
+      docker_config:
+        healthcheck:
+          interval: 15s
+          timeout: 1s
+          type: http
+          endpoint: /status
+        ports:
+          - concat: ["8081", {get_input: external_port}]
+      image:
+        get_input: tag_version
+      service_component_type: policy-agent
+      log_info:
+        log_directory:
+          get_input: log_directory
+      replicas:
+        get_input: replicas
+      resource_config:
+        limits:
+          cpu:
+            get_input: policy-agent_cpu_limit
+          memory:
+            get_input: policy-agent_memory_limit
+        requests:
+          cpu:
+            get_input: policy-agent_cpu_request
+          memory:
+            get_input: policy-agent_memory_request
+
+
index 1352cb5..ae83bc0 100644 (file)
@@ -91,13 +91,14 @@ public class ApplicationConfigParser {
         return get(obj, memberName).getAsJsonArray();
     }
 
-    private Properties parseDmaapConfig(JsonObject consumerCfg) throws ServiceException {
-        Set<Entry<String, JsonElement>> topics = consumerCfg.entrySet();
-        if (topics.size() != 1) {
-            throw new ServiceException("Invalid configuration, number of topic must be one, config: " + topics);
+    private Properties parseDmaapConfig(JsonObject streamCfg) throws ServiceException {
+        Set<Entry<String, JsonElement>> streamConfigEntries = streamCfg.entrySet();
+        if (streamConfigEntries.size() != 1) {
+            throw new ServiceException(
+                "Invalid configuration. Number of streams must be one, config: " + streamConfigEntries);
         }
-        JsonObject topic = topics.iterator().next().getValue().getAsJsonObject();
-        JsonObject dmaapInfo = get(topic, "dmaap_info").getAsJsonObject();
+        JsonObject streamConfigEntry = streamConfigEntries.iterator().next().getValue().getAsJsonObject();
+        JsonObject dmaapInfo = get(streamConfigEntry, "dmaap_info").getAsJsonObject();
         String topicUrl = getAsString(dmaapInfo, "topic_url");
 
         Properties dmaapProps = new Properties();
index 503ddab..c7dab58 100644 (file)
@@ -84,8 +84,6 @@ public class DmaapMessageConsumerImpl implements DmaapMessageConsumer {
         return response.getActualMessages();
     }
 
-    // Properties are not loaded in first atempt. Need to fix this and then uncomment the post construct annotation
-    // @PostConstruct
     @Override
     public void init() {
         Properties dmaapConsumerProperties = applicationConfig.getDmaapConsumerConfig();
@@ -98,8 +96,8 @@ public class DmaapMessageConsumerImpl implements DmaapMessageConsumer {
         }
         try {
             logger.debug("Creating DMAAP Client");
-            System.out.println("dmaapConsumerProperties--->"+dmaapConsumerProperties.getProperty("topic"));
-            System.out.println("dmaapPublisherProperties--->"+dmaapPublisherProperties.getProperty("topic"));
+            logger.debug("dmaapConsumerProperties---> {}", dmaapConsumerProperties.getProperty("topic"));
+            logger.debug("dmaapPublisherProperties---> {}", dmaapPublisherProperties.getProperty("topic"));
             consumer = MRClientFactory.createConsumer(dmaapConsumerProperties);
             this.alive = true;
         } catch (IOException e) {
index 713d483..172fe98 100644 (file)
@@ -50,17 +50,14 @@ public class DmaapMessageHandler {
     @Autowired
     private PolicyController policyController;
     private AsyncRestClient restClient;
+    @Autowired
     private ApplicationConfig applicationConfig;
     private String topic = "";
 
-    @Autowired
-    public DmaapMessageHandler(ApplicationConfig applicationConfig) {
-        this.applicationConfig = applicationConfig;
-    }
-
     // The publish properties is corrupted. It contains the subscribe property values.
     @Async("threadPoolTaskExecutor")
     public void handleDmaapMsg(String msg) {
+        logger.debug("Message  ---------->{}", msg);
         init();
         DmaapRequestMessage dmaapRequestMessage = null;
         Optional<String> dmaapResponse = null;
@@ -71,7 +68,7 @@ public class DmaapMessageHandler {
          * "apiVersion": "1.0", "originatorId": "849e6c6b420", "requestId": "23343221", "operation": "getPolicySchemas",
          * "payload": "{\"ricName\":\"ric1\"}" }
          *
-         * --------------------------------------------------------------------------------------------------------------
+         * -------------------------------------------------------------------------------------------------------------
          * Sample Response Message to DMAAP {type=response, correlationId=c09ac7d1-de62-0016-2000-e63701125557-201,
          * timestamp=null, originatorId=849e6c6b420, requestId=23343221, status=200 OK, message=[]}
          * -------------------------------------------------------------------------------------------------------------
@@ -162,15 +159,11 @@ public class DmaapMessageHandler {
         return Optional.empty();
     }
 
-    // @PostConstruct
-    // The application properties value is always NULL for the first time
-    // Need to fix this
     public void init() {
         logger.debug("Reading DMAAP Publisher bus details from Application Config");
         Properties dmaapPublisherConfig = applicationConfig.getDmaapPublisherConfig();
         String host = (String) dmaapPublisherConfig.get("ServiceName");
         topic = dmaapPublisherConfig.getProperty("topic");
-        System.out.println("\"Read the topic ---------->" + topic);
         logger.debug("Read the topic & Service Name - {} , {}", host, topic);
         this.restClient = new AsyncRestClient("http://" + host + "/"); // get this value from application config
 
index c0ffcbd..54fd79f 100644 (file)
@@ -65,7 +65,7 @@ public class StartupService implements ApplicationConfig.Observer {
     @Autowired
     private Services services;
 
-    // Only for unittesting
+    // Only for unit testing
     StartupService(ApplicationConfig appConfig, RefreshConfigTask refreshTask, Rics rics, PolicyTypes policyTypes,
         A1ClientFactory a1ClientFactory, Policies policies, Services services) {
         this.applicationConfig = appConfig;