From: PatrikBuhr Date: Fri, 27 Mar 2020 14:44:54 +0000 (+0100) Subject: Improved java class documentation X-Git-Tag: 2.0.0~99 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=643ba188e7c1d0c8ce097adfd94ced47b2da615e;p=nonrtric.git Improved java class documentation 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 --- diff --git a/policy-agent/docs/api.yaml b/policy-agent/docs/api.yaml index 3dd78621..8d5151e7 100644 --- a/policy-agent/docs/api.yaml +++ b/policy-agent/docs/api.yaml @@ -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 + diff --git a/policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java b/policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java index 8297b221..93e1739f 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/BeanFactory.java @@ -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 diff --git a/policy-agent/src/main/java/org/oransc/policyagent/SwaggerConfig.java b/policy-agent/src/main/java/org/oransc/policyagent/SwaggerConfig.java index a56892ab..ddcf0d35 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/SwaggerConfig.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/SwaggerConfig.java @@ -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(); } diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java index 84c75381..f94c2c1e 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1Client.java @@ -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 { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java index 2435ef08..0289db98 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java @@ -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; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/OscA1Client.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/OscA1Client.java index 9384726d..aaa9519c 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/OscA1Client.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/OscA1Client.java @@ -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 getPolicyTypeIds() { return restClient.get(uri.createPolicyTypesUri()) // - .flatMapMany(JsonHelper::parseJsonArrayOfString); + .flatMapMany(SdncJsonHelper::parseJsonArrayOfString); } private Flux getPolicyIdentitiesByType(String typeId) { return restClient.get(uri.createGetPolicyIdsUri(typeId)) // - .flatMapMany(JsonHelper::parseJsonArrayOfString); + .flatMapMany(SdncJsonHelper::parseJsonArrayOfString); } private Mono getCreateSchema(String policyTypeResponse, String policyTypeId) { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/JsonHelper.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncJsonHelper.java similarity index 90% rename from policy-agent/src/main/java/org/oransc/policyagent/clients/JsonHelper.java rename to policy-agent/src/main/java/org/oransc/policyagent/clients/SdncJsonHelper.java index 96c9ac96..7c669612 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/JsonHelper.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncJsonHelper.java @@ -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 parseJsonArrayOfString(String inputString) { @@ -87,13 +90,4 @@ class JsonHelper { return Mono.error(ex); } } - - public static Mono validateJson(String inputString) { - try { - new JSONObject(inputString); - return Mono.just(inputString); - } catch (JSONException ex) { // invalid json - return Mono.error(ex); - } - } } diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOnapA1Client.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOnapA1Client.java index af3c2a6d..cfabf512 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOnapA1Client.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOnapA1Client.java @@ -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 policyTypeId(); + + public Optional policyInstanceId(); + + public Optional policyInstance(); + + public Optional> 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()) // .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 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 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 index eb85de92..00000000 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOnapAdapterInput.java +++ /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 policyTypeId(); - - public Optional policyInstanceId(); - - public Optional policyInstance(); - - public Optional> properties(); -} diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOscA1Client.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOscA1Client.java index d9aea591..03fa97d1 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOscA1Client.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/SdncOscA1Client.java @@ -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) diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/StdA1ClientVersion1.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/StdA1ClientVersion1.java index 7480b939..f5486a58 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/StdA1ClientVersion1.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/StdA1ClientVersion1.java @@ -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 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 getPolicyIds() { return restClient.get(uri.createGetPolicyIdsUri()) // - .flatMapMany(JsonHelper::parseJsonArrayOfString); + .flatMapMany(SdncJsonHelper::parseJsonArrayOfString); } private Mono deletePolicyById(String policyId) { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java index c69c39d4..059016dc 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/configuration/ApplicationConfigParser.java @@ -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 ricConfigs; - @Getter - private Properties dmaapPublisherConfig = new Properties(); - @Getter - private Properties dmaapConsumerConfig = new Properties(); + @Value.Immutable + @Gson.TypeAdapters + public interface ConfigParserResult { + List 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 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 parseRics(JsonObject config) throws ServiceException { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java b/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java index cee93274..f03aa582 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/dmaap/DmaapMessageConsumer.java @@ -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 diff --git a/policy-agent/src/main/java/org/oransc/policyagent/exceptions/EnvironmentLoaderException.java b/policy-agent/src/main/java/org/oransc/policyagent/exceptions/EnvironmentLoaderException.java index df6f7def..80673f84 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/exceptions/EnvironmentLoaderException.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/exceptions/EnvironmentLoaderException.java @@ -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; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/tasks/EnvironmentProcessor.java b/policy-agent/src/main/java/org/oransc/policyagent/tasks/EnvironmentProcessor.java index 574656f6..afb273d7 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/tasks/EnvironmentProcessor.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/tasks/EnvironmentProcessor.java @@ -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; diff --git a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RefreshConfigTask.java b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RefreshConfigTask.java index de4a771c..176dd6c3 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RefreshConfigTask.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RefreshConfigTask.java @@ -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 parseConfiguration(JsonObject jsonObject) { + private Mono 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 updateConfig(ApplicationConfigParser config) { - return this.appConfig.setConfiguration(config.getRicConfigs(), config.getDmaapPublisherConfig(), - config.getDmaapConsumerConfig()); + private Flux updateConfig(ApplicationConfigParser.ConfigParserResult config) { + return this.appConfig.setConfiguration(config.ricConfigs(), config.dmaapPublisherConfig(), + config.dmaapConsumerConfig()); } boolean configFileExists() { diff --git a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSupervision.java b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSupervision.java index d368fc46..52780d7e 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSupervision.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/tasks/RicSupervision.java @@ -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 diff --git a/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOnapA1ClientTest.java b/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOnapA1ClientTest.java index 06de4617..ede65941 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOnapA1ClientTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/clients/SdncOnapA1ClientTest.java @@ -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); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/clients/StdA1ClientTest.java b/policy-agent/src/test/java/org/oransc/policyagent/clients/StdA1ClientTest.java index ca6c8a90..15fe05ae 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/clients/StdA1ClientTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/clients/StdA1ClientTest.java @@ -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 policyMono = clientUnderTest - .putPolicy(A1ClientHelper.createPolicy(RIC_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE)); + Mono 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 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(); diff --git a/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigParserTest.java b/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigParserTest.java index 02c84db8..47448d22 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigParserTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/configuration/ApplicationConfigParserTest.java @@ -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"),