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:
$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:
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»»
format: int64
description: time since last invocation by the service
title: ServiceStatus
+
@Configuration
class BeanFactory {
+ private final ApplicationConfig applicationConfig = new ApplicationConfig();
+
@Bean
public Policies getPolicies() {
return new Policies();
@Bean
public ApplicationConfig getApplicationConfig() {
- return new ApplicationConfig();
+ return this.applicationConfig;
}
@Bean
@Bean
A1ClientFactory getA1ClientFactory() {
- return new A1ClientFactory(getApplicationConfig());
+ return new A1ClientFactory(this.applicationConfig);
}
@Bean
.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();
}
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 {
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;
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 {
return createPolicyUri(type, policyId);
}
+ /**
+ * /a1-p/policytypes/{policy_type_id}/policies
+ */
public String createGetPolicyIdsUri(String type) {
return createPolicyTypeUri(type) + "/policies";
}
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;
}
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) {
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) {
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);
- }
- }
}
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;
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());
.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
.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,
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) {
.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) {
.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,
+++ /dev/null
-/*-
- * ========================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();
-}
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 {
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,
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);
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);
}
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);
}
.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)
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 {
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";
}
@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
private Flux<String> getPolicyIds() {
return restClient.get(uri.createGetPolicyIdsUri()) //
- .flatMapMany(JsonHelper::parseJsonArrayOfString);
+ .flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
}
private Mono<String> deletePolicyById(String policyId) {
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 {
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
package org.oransc.policyagent.exceptions;
-public class EnvironmentLoaderException extends Exception {
+public class EnvironmentLoaderException extends ServiceException {
private static final long serialVersionUID = 1L;
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;
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 {
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() {
/**
* 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
@Test
public void testGetPolicyTypeIdentities() {
- SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+ SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.build();
String inputJsonString = A1ClientHelper.createInputJsonString(inputParams);
@Test
public void testGetPolicyIdentities() {
- SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+ SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.build();
String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams);
@Test
public void testGetValidPolicyType() {
- SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+ SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_1_ID) //
.build();
@Test
public void testGetInvalidPolicyType() {
- SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+ SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.policyTypeId(POLICY_TYPE_1_ID) //
.build();
@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) //
@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) //
@Test
public void testDeleteAllPolicies() {
- SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
+ SdncOnapA1Client.SdncOnapAdapterInput inputParams = ImmutableSdncOnapAdapterInput.builder() //
.nearRtRicId(RIC_1_URL) //
.build();
String inputJsonStringGetTypeIds = A1ClientHelper.createInputJsonString(inputParams);
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;
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;
@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
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();
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"),
() -> 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"),