Improved java class documentation 35/3035/2
authorPatrikBuhr <patrik.buhr@est.tech>
Fri, 27 Mar 2020 14:44:54 +0000 (15:44 +0100)
committerPatrikBuhr <patrik.buhr@est.tech>
Mon, 30 Mar 2020 07:44:19 +0000 (09:44 +0200)
Removed sprinng boot actuator from the generated
open API documentation.

Bugfix, only one Application configuration object can exist.

Change-Id: Iabed9a95995a2e1aadf6f9e3b7188b04e73838ec
Issue-ID: NONRTRIC-164
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
20 files changed:
policy-agent/docs/api.yaml
policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java
policy-agent/src/main/java/org/oransc/policyagent/SwaggerConfig.java
policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java
policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java
policy-agent/src/main/java/org/oransc/policyagent/clients/OscA1Client.java
policy-agent/src/main/java/org/oransc/policyagent/clients/SdncJsonHelper.java [moved from policy-agent/src/main/java/org/oransc/policyagent/clients/JsonHelper.java with 90% similarity]
policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOnapA1Client.java
policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOnapAdapterInput.java [deleted file]
policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOscA1Client.java
policy-agent/src/main/java/org/oransc/policyagent/clients/StdA1ClientVersion1.java
policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java
policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java
policy-agent/src/main/java/org/oransc/policyagent/exceptions/EnvironmentLoaderException.java
policy-agent/src/main/java/org/oransc/policyagent/tasks/EnvironmentProcessor.java
policy-agent/src/main/java/org/oransc/policyagent/tasks/RefreshConfigTask.java
policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSupervision.java
policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOnapA1ClientTest.java
policy-agent/src/test/java/org/oransc/policyagent/clients/StdA1ClientTest.java
policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigParserTest.java

index 3dd7862..8d5151e 100644 (file)
@@ -14,317 +14,7 @@ tags:
     description: Ric Repository Controller
   - name: Service registry and supervision
     description: Service Controller
-  - name: operation-handler
-    description: Operation Handler
-  - name: web-mvc-links-handler
-    description: Web Mvc Links Handler
 paths:
-  /actuator:
-    get:
-      tags:
-        - web-mvc-links-handler
-      summary: links
-      operationId: linksUsingGET
-      produces:
-        - application/vnd.spring-boot.actuator.v3+json
-        - application/json
-        - application/vnd.spring-boot.actuator.v2+json
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-            additionalProperties:
-              type: object
-              additionalProperties:
-                $ref: '#/definitions/Link'
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
-  /actuator/health:
-    get:
-      tags:
-        - operation-handler
-      summary: handle
-      operationId: handleUsingGET_1
-      produces:
-        - application/vnd.spring-boot.actuator.v3+json
-        - application/json
-        - application/vnd.spring-boot.actuator.v2+json
-      parameters:
-        - in: body
-          name: body
-          description: body
-          required: false
-          schema:
-            type: object
-            additionalProperties:
-              type: string
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
-  /actuator/health/**:
-    get:
-      tags:
-        - operation-handler
-      summary: handle
-      operationId: handleUsingGET
-      produces:
-        - application/vnd.spring-boot.actuator.v3+json
-        - application/json
-        - application/vnd.spring-boot.actuator.v2+json
-      parameters:
-        - in: body
-          name: body
-          description: body
-          required: false
-          schema:
-            type: object
-            additionalProperties:
-              type: string
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
-  /actuator/info:
-    get:
-      tags:
-        - operation-handler
-      summary: handle
-      operationId: handleUsingGET_2
-      produces:
-        - application/vnd.spring-boot.actuator.v3+json
-        - application/json
-        - application/vnd.spring-boot.actuator.v2+json
-      parameters:
-        - in: body
-          name: body
-          description: body
-          required: false
-          schema:
-            type: object
-            additionalProperties:
-              type: string
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
-  /actuator/logfile:
-    get:
-      tags:
-        - operation-handler
-      summary: handle
-      operationId: handleUsingGET_3
-      produces:
-        - text/plain;charset=UTF-8
-      parameters:
-        - in: body
-          name: body
-          description: body
-          required: false
-          schema:
-            type: object
-            additionalProperties:
-              type: string
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
-  /actuator/loggers:
-    get:
-      tags:
-        - operation-handler
-      summary: handle
-      operationId: handleUsingGET_5
-      produces:
-        - application/vnd.spring-boot.actuator.v3+json
-        - application/json
-        - application/vnd.spring-boot.actuator.v2+json
-      parameters:
-        - in: body
-          name: body
-          description: body
-          required: false
-          schema:
-            type: object
-            additionalProperties:
-              type: string
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
-  '/actuator/loggers/{name}':
-    get:
-      tags:
-        - operation-handler
-      summary: handle
-      operationId: handleUsingGET_4
-      produces:
-        - application/vnd.spring-boot.actuator.v3+json
-        - application/json
-        - application/vnd.spring-boot.actuator.v2+json
-      parameters:
-        - in: body
-          name: body
-          description: body
-          required: false
-          schema:
-            type: object
-            additionalProperties:
-              type: string
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
-    post:
-      tags:
-        - operation-handler
-      summary: handle
-      operationId: handleUsingPOST
-      consumes:
-        - application/vnd.spring-boot.actuator.v3+json
-        - application/json
-        - application/vnd.spring-boot.actuator.v2+json
-      produces:
-        - '*/*'
-      parameters:
-        - in: body
-          name: body
-          description: body
-          required: false
-          schema:
-            type: object
-            additionalProperties:
-              type: string
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-        '201':
-          description: Created
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
-  /actuator/metrics:
-    get:
-      tags:
-        - operation-handler
-      summary: handle
-      operationId: handleUsingGET_7
-      produces:
-        - application/vnd.spring-boot.actuator.v3+json
-        - application/json
-        - application/vnd.spring-boot.actuator.v2+json
-      parameters:
-        - in: body
-          name: body
-          description: body
-          required: false
-          schema:
-            type: object
-            additionalProperties:
-              type: string
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
-  '/actuator/metrics/{requiredMetricName}':
-    get:
-      tags:
-        - operation-handler
-      summary: handle
-      operationId: handleUsingGET_6
-      produces:
-        - application/vnd.spring-boot.actuator.v3+json
-        - application/json
-        - application/vnd.spring-boot.actuator.v2+json
-      parameters:
-        - in: body
-          name: body
-          description: body
-          required: false
-          schema:
-            type: object
-            additionalProperties:
-              type: string
-      responses:
-        '200':
-          description: OK
-          schema:
-            type: object
-        '401':
-          description: Unauthorized
-        '403':
-          description: Forbidden
-        '404':
-          description: Not Found
-      deprecated: false
   /policies:
     get:
       tags:
@@ -717,11 +407,13 @@ paths:
             $ref: '#/definitions/ServiceRegistrationInfo'
       responses:
         '200':
-          description: OK
+          description: Service updated
           schema:
             type: string
         '201':
-          description: Created
+          description: Service created
+          schema:
+            type: string
         '400':
           description: Cannot parse the ServiceRegistrationInfo
           schema:
@@ -845,19 +537,6 @@ paths:
           description: Not Found
       deprecated: false
 definitions:
-  Link:
-    type: object
-    properties:
-      href:
-        type: string
-      templated:
-        type: boolean
-    title: Link
-  'Map«string,Link»':
-    type: object
-    title: 'Map«string,Link»'
-    additionalProperties:
-      $ref: '#/definitions/Link'
   Mono«ResponseEntity«object»»:
     type: object
     title: Mono«ResponseEntity«object»»
@@ -937,3 +616,4 @@ definitions:
         format: int64
         description: time since last invocation by the service
     title: ServiceStatus
+
index 8297b22..93e1739 100644 (file)
@@ -33,6 +33,8 @@ import org.springframework.context.annotation.Configuration;
 
 @Configuration
 class BeanFactory {
+    private final ApplicationConfig applicationConfig = new ApplicationConfig();
+
     @Bean
     public Policies getPolicies() {
         return new Policies();
@@ -50,7 +52,7 @@ class BeanFactory {
 
     @Bean
     public ApplicationConfig getApplicationConfig() {
-        return new ApplicationConfig();
+        return this.applicationConfig;
     }
 
     @Bean
@@ -60,7 +62,7 @@ class BeanFactory {
 
     @Bean
     A1ClientFactory getA1ClientFactory() {
-        return new A1ClientFactory(getApplicationConfig());
+        return new A1ClientFactory(this.applicationConfig);
     }
 
     @Bean
index a56892a..ddcf0d3 100644 (file)
@@ -68,6 +68,8 @@ public class SwaggerConfig extends WebMvcConfigurationSupport {
             .paths(PathSelectors.any()) //
             .paths(Predicates.not(PathSelectors.regex("/error"))) //
             // this endpoint is not implemented, but was visible for Swagger
+            .paths(Predicates.not(PathSelectors.regex("/actuator.*"))) //
+            // this endpoint is implemented by spring framework, exclude for now
             .build();
     }
 
index 84c7538..f94c2c1 100644 (file)
@@ -27,6 +27,10 @@ import org.oransc.policyagent.repository.Policy;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+/**
+ * Common interface for 'A1' Policy access. Implementations of this interface
+ * adapts to the different southbound REST APIs supported.
+ */
 public interface A1Client {
 
     public enum A1ProtocolType {
index 2435ef0..0289db9 100644 (file)
@@ -31,6 +31,9 @@ import org.springframework.web.reactive.function.client.WebClient;
 import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
 import reactor.core.publisher.Mono;
 
+/**
+ * Generic reactive REST client.
+ */
 public class AsyncRestClient {
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
     private final WebClient client;
index 9384726..aaa9519 100644 (file)
@@ -32,6 +32,9 @@ import org.slf4j.LoggerFactory;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+/**
+ * Client for accessing OSC A1 REST API
+ */
 @SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
 public class OscA1Client implements A1Client {
 
@@ -47,6 +50,9 @@ public class OscA1Client implements A1Client {
             return createPolicyUri(type, policyId);
         }
 
+        /**
+         * /a1-p/policytypes/{policy_type_id}/policies
+         */
         public String createGetPolicyIdsUri(String type) {
             return createPolicyTypeUri(type) + "/policies";
         }
@@ -56,27 +62,45 @@ public class OscA1Client implements A1Client {
             return createPolicyUri(type, policyId);
         }
 
+        /**
+         * ​/a1-p​/policytypes​/{policy_type_id}​/policies​/{policy_instance_id}​/status
+         */
         @Override
         public String createGetPolicyStatusUri(String type, String policyId) {
             return createPolicyUri(type, policyId) + "/status";
         }
 
+        /**
+         * ​/a1-p​/healthcheck
+         */
         public String createHealtcheckUri() {
             return baseUri() + "/healthcheck";
         }
 
+        /**
+         * /a1-p/policytypes/{policy_type_id}
+         */
         public String createGetSchemaUri(String type) {
             return this.createPolicyTypeUri(type);
         }
 
+        /**
+         * ​/a1-p​/policytypes​/{policy_type_id}
+         */
         public String createPolicyTypesUri() {
             return baseUri() + "/policytypes";
         }
 
+        /**
+         * ​/a1-p​/policytypes​/{policy_type_id}​/policies​/{policy_instance_id}
+         */
         private String createPolicyUri(String type, String id) {
             return createPolicyTypeUri(type) + "/policies/" + id;
         }
 
+        /**
+         * /a1-p/policytypes/{policy_type_id}
+         */
         private String createPolicyTypeUri(String type) {
             return createPolicyTypesUri() + "/" + type;
         }
@@ -154,12 +178,12 @@ public class OscA1Client implements A1Client {
 
     private Flux<String> getPolicyTypeIds() {
         return restClient.get(uri.createPolicyTypesUri()) //
-            .flatMapMany(JsonHelper::parseJsonArrayOfString);
+            .flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
     }
 
     private Flux<String> getPolicyIdentitiesByType(String typeId) {
         return restClient.get(uri.createGetPolicyIdsUri(typeId)) //
-            .flatMapMany(JsonHelper::parseJsonArrayOfString);
+            .flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
     }
 
     private Mono<String> getCreateSchema(String policyTypeResponse, String policyTypeId) {
@@ -34,12 +34,15 @@ import org.json.JSONObject;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
-class JsonHelper {
+/**
+ * Common json functionality used by the SDNC clients
+ */
+class SdncJsonHelper {
     private static Gson gson = new GsonBuilder() //
         .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES) //
         .create();
 
-    private JsonHelper() {
+    private SdncJsonHelper() {
     }
 
     public static Flux<String> parseJsonArrayOfString(String inputString) {
@@ -87,13 +90,4 @@ class JsonHelper {
             return Mono.error(ex);
         }
     }
-
-    public static Mono<String> validateJson(String inputString) {
-        try {
-            new JSONObject(inputString);
-            return Mono.just(inputString);
-        } catch (JSONException ex) { // invalid json
-            return Mono.error(ex);
-        }
-    }
 }
index af3c2a6..cfabf51 100644 (file)
@@ -23,7 +23,10 @@ package org.oransc.policyagent.clients;
 import java.lang.invoke.MethodHandles;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
 import org.oransc.policyagent.configuration.RicConfig;
 import org.oransc.policyagent.repository.Policy;
 import org.slf4j.Logger;
@@ -32,8 +35,25 @@ import org.slf4j.LoggerFactory;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+/**
+ * Client for accessing the A1 adapter in the SDNC controller in ONAP
+ */
 @SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
 public class SdncOnapA1Client implements A1Client {
+    @Value.Immutable
+    @Gson.TypeAdapters
+    interface SdncOnapAdapterInput {
+        public String nearRtRicId();
+
+        public Optional<String> policyTypeId();
+
+        public Optional<String> policyInstanceId();
+
+        public Optional<String> policyInstance();
+
+        public Optional<List<String>> properties();
+    }
+
     private static final String URL_PREFIX = "/A1-ADAPTER-API:";
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -74,14 +94,14 @@ public class SdncOnapA1Client implements A1Client {
             .nearRtRicId(ricConfig.baseUrl()) //
             .policyTypeId(policyTypeId) //
             .build();
-        String inputJsonString = JsonHelper.createInputJsonString(inputParams);
+        String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
         logger.debug("POST getPolicyType inputJsonString = {}", inputJsonString);
 
         return restClient
             .postWithAuthHeader(URL_PREFIX + "getPolicyType", inputJsonString, a1ControllerUsername,
                 a1ControllerPassword) //
-            .flatMap(response -> JsonHelper.getValueFromResponse(response, "policy-type")) //
-            .flatMap(JsonHelper::extractPolicySchema);
+            .flatMap(response -> SdncJsonHelper.getValueFromResponse(response, "policy-type")) //
+            .flatMap(SdncJsonHelper::extractPolicySchema);
     }
 
     @Override
@@ -94,7 +114,7 @@ public class SdncOnapA1Client implements A1Client {
             .properties(new ArrayList<String>()) //
             .build();
 
-        String inputJsonString = JsonHelper.createInputJsonString(inputParams);
+        String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
         logger.debug("POST putPolicy inputJsonString = {}", inputJsonString);
 
         return restClient.postWithAuthHeader(URL_PREFIX + "createPolicyInstance", inputJsonString, a1ControllerUsername,
@@ -127,14 +147,14 @@ public class SdncOnapA1Client implements A1Client {
         SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
             .nearRtRicId(ricConfig.baseUrl()) //
             .build();
-        String inputJsonString = JsonHelper.createInputJsonString(inputParams);
+        String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
         logger.debug("POST getPolicyTypeIdentities inputJsonString = {}", inputJsonString);
 
         return restClient
             .postWithAuthHeader("/A1-ADAPTER-API:getPolicyTypes", inputJsonString, a1ControllerUsername,
                 a1ControllerPassword) //
-            .flatMap(response -> JsonHelper.getValueFromResponse(response, "policy-type-id-list")) //
-            .flatMapMany(JsonHelper::parseJsonArrayOfString);
+            .flatMap(response -> SdncJsonHelper.getValueFromResponse(response, "policy-type-id-list")) //
+            .flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
     }
 
     private Flux<String> getPolicyIdentitiesByType(String policyTypeId) {
@@ -142,14 +162,14 @@ public class SdncOnapA1Client implements A1Client {
             .nearRtRicId(ricConfig.baseUrl()) //
             .policyTypeId(policyTypeId) //
             .build();
-        String inputJsonString = JsonHelper.createInputJsonString(inputParams);
+        String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
         logger.debug("POST getPolicyIdentities inputJsonString = {}", inputJsonString);
 
         return restClient
             .postWithAuthHeader("/A1-ADAPTER-API:getPolicyInstances", inputJsonString, a1ControllerUsername,
                 a1ControllerPassword) //
-            .flatMap(response -> JsonHelper.getValueFromResponse(response, "policy-instance-id-list")) //
-            .flatMapMany(JsonHelper::parseJsonArrayOfString);
+            .flatMap(response -> SdncJsonHelper.getValueFromResponse(response, "policy-instance-id-list")) //
+            .flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
     }
 
     private Flux<String> deletePoliciesForType(String typeId) {
@@ -163,7 +183,7 @@ public class SdncOnapA1Client implements A1Client {
             .policyTypeId(policyTypeId) //
             .policyInstanceId(policyId) //
             .build();
-        String inputJsonString = JsonHelper.createInputJsonString(inputParams);
+        String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
         logger.debug("POST deletePolicy inputJsonString = {}", inputJsonString);
 
         return restClient.postWithAuthHeader("/A1-ADAPTER-API:deletePolicyInstance", inputJsonString,
diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOnapAdapterInput.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOnapAdapterInput.java
deleted file mode 100644 (file)
index eb85de9..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*-
- * ========================LICENSE_START=================================
- * O-RAN-SC
- * %%
- * Copyright (C) 2020 Nordix Foundation
- * %%
- * 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.oransc.policyagent.clients;
-
-import java.util.List;
-import java.util.Optional;
-
-import org.immutables.gson.Gson;
-import org.immutables.value.Value;
-
-@Value.Immutable
-@Gson.TypeAdapters
-interface SdncOnapAdapterInput {
-    public String nearRtRicId();
-
-    public Optional<String> policyTypeId();
-
-    public Optional<String> policyInstanceId();
-
-    public Optional<String> policyInstance();
-
-    public Optional<List<String>> properties();
-}
index d9aea59..03fa97d 100644 (file)
@@ -40,6 +40,9 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+/**
+ * Client for accessing the A1 adapter in the SDNC controller in OSC.
+ */
 @SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
 public class SdncOscA1Client implements A1Client {
 
@@ -72,6 +75,16 @@ public class SdncOscA1Client implements A1Client {
     private final RicConfig ricConfig;
     private final A1ProtocolType protocolType;
 
+    /**
+     * Constructor
+     * 
+     * @param protocolType the southbound protocol of the controller. Supported
+     *        protocols are SDNC_OSC_STD_V1_1 and SDNC_OSC_OSC_V1
+     * @param ricConfig
+     * @param controllerBaseUrl the base URL of the SDNC controller
+     * @param username username to accesss the SDNC controller
+     * @param password password to accesss the SDNC controller
+     */
     public SdncOscA1Client(A1ProtocolType protocolType, RicConfig ricConfig, String controllerBaseUrl, String username,
         String password) {
         this(protocolType, ricConfig, username, password,
@@ -97,7 +110,7 @@ public class SdncOscA1Client implements A1Client {
             OscA1Client.UriBuilder uri = new OscA1Client.UriBuilder(ricConfig);
             final String ricUrl = uri.createPolicyTypesUri();
             return post(GET_POLICY_RPC, ricUrl, Optional.empty()) //
-                .flatMapMany(JsonHelper::parseJsonArrayOfString) //
+                .flatMapMany(SdncJsonHelper::parseJsonArrayOfString) //
                 .collectList();
         }
         throw new NullPointerException(UNHANDELED_PROTOCOL + this.protocolType);
@@ -142,7 +155,7 @@ public class SdncOscA1Client implements A1Client {
             return getPolicyTypeIdentities() //
                 .flatMapMany(Flux::fromIterable)
                 .flatMap(type -> post(GET_POLICY_RPC, uriBuilder.createGetPolicyIdsUri(type), Optional.empty())) //
-                .flatMap(JsonHelper::parseJsonArrayOfString);
+                .flatMap(SdncJsonHelper::parseJsonArrayOfString);
         }
         throw new NullPointerException(UNHANDELED_PROTOCOL + this.protocolType);
     }
@@ -185,13 +198,13 @@ public class SdncOscA1Client implements A1Client {
             StdA1ClientVersion1.UriBuilder uri = new StdA1ClientVersion1.UriBuilder(ricConfig);
             final String ricUrl = uri.createGetPolicyIdsUri();
             return post(GET_POLICY_RPC, ricUrl, Optional.empty()) //
-                .flatMapMany(JsonHelper::parseJsonArrayOfString);
+                .flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
         } else if (this.protocolType == A1ProtocolType.SDNC_OSC_OSC_V1) {
             OscA1Client.UriBuilder uri = new OscA1Client.UriBuilder(ricConfig);
             return getPolicyTypeIdentities() //
                 .flatMapMany(Flux::fromIterable)
                 .flatMap(type -> post(GET_POLICY_RPC, uri.createGetPolicyIdsUri(type), Optional.empty())) //
-                .flatMap(JsonHelper::parseJsonArrayOfString);
+                .flatMap(SdncJsonHelper::parseJsonArrayOfString);
         }
         throw new NullPointerException(UNHANDELED_PROTOCOL + this.protocolType);
     }
@@ -206,7 +219,7 @@ public class SdncOscA1Client implements A1Client {
             .nearRtRicUrl(ricUrl) //
             .body(body) //
             .build();
-        final String inputJsonString = JsonHelper.createInputJsonString(inputParams);
+        final String inputJsonString = SdncJsonHelper.createInputJsonString(inputParams);
 
         return restClient
             .postWithAuthHeader(controllerUrl(rpcName), inputJsonString, a1ControllerUsername, a1ControllerPassword)
index 7480b93..f5486a5 100644 (file)
@@ -29,6 +29,9 @@ import org.oransc.policyagent.repository.Policy;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+/**
+ * Client for accessing standard A1 REST API version 1.1
+ */
 public class StdA1ClientVersion1 implements A1Client {
 
     public static class UriBuilder implements A1UriBuilder {
@@ -39,20 +42,32 @@ public class StdA1ClientVersion1 implements A1Client {
             this.ricConfig = ricConfig;
         }
 
+        /**
+         * /A1-P/v1/policies/{policyId}
+         */
         @Override
         public String createPutPolicyUri(String type, String policyId) {
             return policiesBaseUri() + policyId;
         }
 
+        /**
+         * /A1-P/v1/policies
+         */
         public String createGetPolicyIdsUri() {
             return baseUri() + "/policies";
         }
 
+        /**
+         * /A1-P/v1/policies/{policyId}
+         */
         @Override
         public String createDeleteUri(String type, String policyId) {
             return policiesBaseUri() + policyId;
         }
 
+        /**
+         * /A1-P/v1/policies/{policyId}/status
+         */
         public String createGetPolicyStatusUri(String type, String policyId) {
             return policiesBaseUri() + policyId + "/status";
         }
@@ -86,8 +101,7 @@ public class StdA1ClientVersion1 implements A1Client {
 
     @Override
     public Mono<String> putPolicy(Policy policy) {
-        return restClient.put(uri.createPutPolicyUri(policy.type().name(), policy.id()), policy.json()) //
-            .flatMap(JsonHelper::validateJson);
+        return restClient.put(uri.createPutPolicyUri(policy.type().name(), policy.id()), policy.json());
     }
 
     @Override
@@ -124,7 +138,7 @@ public class StdA1ClientVersion1 implements A1Client {
 
     private Flux<String> getPolicyIds() {
         return restClient.get(uri.createGetPolicyIdsUri()) //
-            .flatMapMany(JsonHelper::parseJsonArrayOfString);
+            .flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
     }
 
     private Mono<String> deletePolicyById(String policyId) {
index c69c39d..059016d 100644 (file)
@@ -35,37 +35,52 @@ import java.util.Set;
 
 import javax.validation.constraints.NotNull;
 
-import lombok.Getter;
-
+import org.immutables.gson.Gson;
+import org.immutables.value.Value;
 import org.onap.dmaap.mr.test.clients.ProtocolTypeConstants;
 import org.oransc.policyagent.exceptions.ServiceException;
 import org.springframework.http.MediaType;
 
+/**
+ * Parser for the Json representing of the component configuration.
+ */
 public class ApplicationConfigParser {
 
     private static final String CONFIG = "config";
 
-    @Getter
-    private List<RicConfig> ricConfigs;
-    @Getter
-    private Properties dmaapPublisherConfig = new Properties();
-    @Getter
-    private Properties dmaapConsumerConfig = new Properties();
+    @Value.Immutable
+    @Gson.TypeAdapters
+    public interface ConfigParserResult {
+        List<RicConfig> ricConfigs();
+
+        Properties dmaapPublisherConfig();
+
+        Properties dmaapConsumerConfig();
+    }
+
+    public ConfigParserResult parse(JsonObject root) throws ServiceException {
+
+        Properties dmaapPublisherConfig = new Properties();
+        Properties dmaapConsumerConfig = new Properties();
 
-    public void parse(JsonObject root) throws ServiceException {
         JsonObject agentConfigJson = root.getAsJsonObject(CONFIG);
-        ricConfigs = parseRics(agentConfigJson);
+        List<RicConfig> ricConfigs = parseRics(agentConfigJson);
 
         JsonObject json = agentConfigJson.getAsJsonObject("streams_publishes");
         if (json != null) {
-            this.dmaapPublisherConfig = parseDmaapConfig(json);
+            dmaapPublisherConfig = parseDmaapConfig(json);
         }
 
         json = agentConfigJson.getAsJsonObject("streams_subscribes");
         if (json != null) {
-            this.dmaapConsumerConfig = parseDmaapConfig(json);
+            dmaapConsumerConfig = parseDmaapConfig(json);
         }
 
+        return ImmutableConfigParserResult.builder() //
+            .dmaapConsumerConfig(dmaapConsumerConfig) //
+            .dmaapPublisherConfig(dmaapPublisherConfig) //
+            .ricConfigs(ricConfigs) //
+            .build();
     }
 
     private List<RicConfig> parseRics(JsonObject config) throws ServiceException {
index cee9327..f03aa58 100644 (file)
@@ -40,7 +40,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 /**
- * The class fetched incoming requests from DMAAP on regular intervals. Each
+ * The class fetches incoming requests from DMAAP on regular intervals. Each
  * received request is proceesed by DmaapMessageHandler.
  */
 @Component
index df6f7de..80673f8 100644 (file)
@@ -20,7 +20,7 @@
 
 package org.oransc.policyagent.exceptions;
 
-public class EnvironmentLoaderException extends Exception {
+public class EnvironmentLoaderException extends ServiceException {
 
     private static final long serialVersionUID = 1L;
 
index 574656f..afb273d 100644 (file)
@@ -30,6 +30,10 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import reactor.core.publisher.Mono;
 
+/**
+ * This class reads a few environment variables used for locating the Consul
+ * (Config Binding Service).
+ */
 class EnvironmentProcessor {
 
     private static final int DEFAULT_CONSUL_PORT = 8500;
index de4a771..176dd6c 100644 (file)
@@ -70,7 +70,8 @@ import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 /**
- * Regularly refreshes the configuration from Consul.
+ * Regularly refreshes the configuration from Consul or from a local
+ * configuration file.
  */
 @Component
 public class RefreshConfigTask {
@@ -164,20 +165,19 @@ public class RefreshConfigTask {
         return Mono.empty();
     }
 
-    private Mono<ApplicationConfigParser> parseConfiguration(JsonObject jsonObject) {
+    private Mono<ApplicationConfigParser.ConfigParserResult> parseConfiguration(JsonObject jsonObject) {
         try {
             ApplicationConfigParser parser = new ApplicationConfigParser();
-            parser.parse(jsonObject);
-            return Mono.just(parser);
+            return Mono.just(parser.parse(jsonObject));
         } catch (ServiceException e) {
             logger.error("Could not parse configuration {}", e.toString(), e);
             return Mono.error(e);
         }
     }
 
-    private Flux<RicConfigUpdate> updateConfig(ApplicationConfigParser config) {
-        return this.appConfig.setConfiguration(config.getRicConfigs(), config.getDmaapPublisherConfig(),
-            config.getDmaapConsumerConfig());
+    private Flux<RicConfigUpdate> updateConfig(ApplicationConfigParser.ConfigParserResult config) {
+        return this.appConfig.setConfiguration(config.ricConfigs(), config.dmaapPublisherConfig(),
+            config.dmaapConsumerConfig());
     }
 
     boolean configFileExists() {
index d368fc4..52780d7 100644 (file)
@@ -43,7 +43,8 @@ import reactor.core.publisher.Mono;
 
 /**
  * Regularly checks the existing rics towards the local repository to keep it
- * consistent.
+ * consistent. When the policy types or instances in the Near-RT RIC is not
+ * consistent, a synchronization is performed.
  */
 @Component
 @EnableScheduling
index 06de461..ede6594 100644 (file)
@@ -72,7 +72,7 @@ public class SdncOnapA1ClientTest {
 
     @Test
     public void testGetPolicyTypeIdentities() {
-        SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+        SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
             .nearRtRicId(RIC_1_URL) //
             .build();
         String inputJsonString = A1ClientHelper.createInputJsonString(inputParams);
@@ -90,7 +90,7 @@ public class SdncOnapA1ClientTest {
 
     @Test
     public void testGetPolicyIdentities() {
-        SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+        SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
             .nearRtRicId(RIC_1_URL) //
             .build();
         String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams);
@@ -128,7 +128,7 @@ public class SdncOnapA1ClientTest {
 
     @Test
     public void testGetValidPolicyType() {
-        SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+        SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
             .nearRtRicId(RIC_1_URL) //
             .policyTypeId(POLICY_TYPE_1_ID) //
             .build();
@@ -146,7 +146,7 @@ public class SdncOnapA1ClientTest {
 
     @Test
     public void testGetInvalidPolicyType() {
-        SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+        SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
             .nearRtRicId(RIC_1_URL) //
             .policyTypeId(POLICY_TYPE_1_ID) //
             .build();
@@ -164,7 +164,7 @@ public class SdncOnapA1ClientTest {
 
     @Test
     public void testPutPolicy() {
-        SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+        SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
             .nearRtRicId(RIC_1_URL) //
             .policyTypeId(POLICY_TYPE_1_ID) //
             .policyInstanceId(POLICY_1_ID) //
@@ -184,7 +184,7 @@ public class SdncOnapA1ClientTest {
 
     @Test
     public void testDeletePolicy() {
-        SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+        SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
             .nearRtRicId(RIC_1_URL) //
             .policyTypeId(POLICY_TYPE_1_ID) //
             .policyInstanceId(POLICY_1_ID) //
@@ -202,7 +202,7 @@ public class SdncOnapA1ClientTest {
 
     @Test
     public void testDeleteAllPolicies() {
-        SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+        SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
             .nearRtRicId(RIC_1_URL) //
             .build();
         String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams);
index ca6c8a9..15fe05a 100644 (file)
@@ -29,7 +29,6 @@ import static org.mockito.Mockito.when;
 import java.util.Arrays;
 import java.util.List;
 
-import org.json.JSONException;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -48,8 +47,7 @@ public class StdA1ClientTest {
     private static final String POLICY_TYPE_1_NAME = "type1";
     private static final String POLICY_1_ID = "policy1";
     private static final String POLICY_2_ID = "policy2";
-    private static final String POLICY_JSON_VALID = "{\"policyId\":\"policy1\"}";
-    private static final String POLICY_JSON_INVALID = "\"policyId\":\"policy1\"}";
+    private static final String POLICY_JSON = "{\"policyId\":\"policy1\"}";
     private static final String POLICY_TYPE = "typeName";
 
     StdA1ClientVersion1 clientUnderTest;
@@ -101,23 +99,13 @@ public class StdA1ClientTest {
     @Test
     public void testPutPolicyValidResponse() {
         doReturn(RIC_URL).when(ricConfigMock).baseUrl();
-        when(asyncRestClientMock.put(anyString(), anyString())).thenReturn(Mono.just(POLICY_JSON_VALID));
+        when(asyncRestClientMock.put(anyString(), anyString())).thenReturn(Mono.just(POLICY_JSON));
 
-        Mono<String> policyMono = clientUnderTest
-            .putPolicy(A1ClientHelper.createPolicy(RIC_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE));
+        Mono<String> policyMono =
+            clientUnderTest.putPolicy(A1ClientHelper.createPolicy(RIC_URL, POLICY_1_ID, POLICY_JSON, POLICY_TYPE));
 
-        verify(asyncRestClientMock).put(policiesBaseUrl() + POLICY_1_ID, POLICY_JSON_VALID);
-        StepVerifier.create(policyMono).expectNext(POLICY_JSON_VALID).expectComplete().verify();
-    }
-
-    @Test
-    public void testPutPolicyInvalidResponse() {
-        when(asyncRestClientMock.put(anyString(), anyString())).thenReturn(Mono.just(POLICY_JSON_INVALID));
-
-        Mono<String> policyMono = clientUnderTest
-            .putPolicy(A1ClientHelper.createPolicy(RIC_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE));
-
-        StepVerifier.create(policyMono).expectErrorMatches(throwable -> throwable instanceof JSONException).verify();
+        verify(asyncRestClientMock).put(policiesBaseUrl() + POLICY_1_ID, POLICY_JSON);
+        StepVerifier.create(policyMono).expectNext(POLICY_JSON).expectComplete().verify();
     }
 
     @Test
@@ -126,7 +114,7 @@ public class StdA1ClientTest {
         final String url = policiesBaseUrl() + POLICY_1_ID;
         when(asyncRestClientMock.delete(url)).thenReturn(Mono.empty());
 
-        Policy policy = A1ClientHelper.createPolicy(RIC_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE);
+        Policy policy = A1ClientHelper.createPolicy(RIC_URL, POLICY_1_ID, POLICY_JSON, POLICY_TYPE);
         Mono<?> responseMono = clientUnderTest.deletePolicy(policy);
         verify(asyncRestClientMock).delete(url);
         StepVerifier.create(responseMono).expectComplete().verify();
index 02c84db..47448d2 100644 (file)
@@ -54,9 +54,9 @@ public class ApplicationConfigParserTest {
     public void whenCorrectDmaapConfig() throws Exception {
         JsonObject jsonRootObject = getJsonRootObject();
 
-        parserUnderTest.parse(jsonRootObject);
+        ApplicationConfigParser.ConfigParserResult result = parserUnderTest.parse(jsonRootObject);
 
-        Properties actualPublisherConfig = parserUnderTest.getDmaapPublisherConfig();
+        Properties actualPublisherConfig = result.dmaapPublisherConfig();
         assertAll("publisherConfig",
             () -> assertEquals("localhost:6845/events", actualPublisherConfig.get("ServiceName"), "Wrong ServiceName"),
             () -> assertEquals("A1-POLICY-AGENT-WRITE", actualPublisherConfig.get("topic"), "Wrong topic"),
@@ -70,7 +70,7 @@ public class ApplicationConfigParserTest {
             () -> assertEquals(15000, actualPublisherConfig.get("timeout"), "Wrong timeout"),
             () -> assertEquals(100, actualPublisherConfig.get("limit"), "Wrong limit"));
 
-        Properties actualConsumerConfig = parserUnderTest.getDmaapConsumerConfig();
+        Properties actualConsumerConfig = result.dmaapConsumerConfig();
         assertAll("consumerConfig",
             () -> assertEquals("localhost:6845/events", actualConsumerConfig.get("ServiceName"), "Wrong ServiceName"),
             () -> assertEquals("A1-POLICY-AGENT-READ", actualConsumerConfig.get("topic"), "Wrong topic"),