summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main/java
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2020-08-07 09:15:10 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2020-10-21 15:34:40 +0200
commitc5f81cf8dace9637702d6934db1a9f4ed32ff131 (patch)
tree7af0d09d7e456abc26dc82063b59eab4710eabef /a1-policy-management/src/main/java
parent5da27f37cff6df63582179aec6b4a4099135035c (diff)
Added support for ORAN A1-P Version 2.0
Change-Id: I82a00dced95b76c97bf93c61a65a8c9d8157a00f Issue-ID: CCSDK-2502 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management/src/main/java')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java3
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java9
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1UriBuilder.java6
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java5
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1Client.java113
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java18
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java208
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java2
8 files changed, 308 insertions, 56 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java
index 6f1bf357..4321ed48 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1Client.java
@@ -36,8 +36,10 @@ public interface A1Client {
public enum A1ProtocolType {
UNKNOWN, //
STD_V1_1, // STD A1 version 1.1
+ STD_V2_0_0, // STD A1 version 2.0.0
OSC_V1, // OSC 'A1'
SDNC_OSC_STD_V1_1, // SDNC_OSC with STD A1 version 1.1 southbound
+ SDNC_OSC_STD_V2_0_0, // SDNC_OSC with STD A1 version 2.0.0 southbound
SDNC_OSC_OSC_V1, // SDNC_OSC with OSC 'A1' southbound
SDNC_ONAP
}
@@ -57,4 +59,5 @@ public interface A1Client {
public Flux<String> deleteAllPolicies();
public Mono<String> getPolicyStatus(Policy policy);
+
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java
index f0f03cfe..66ba60c0 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java
@@ -73,10 +73,14 @@ public class A1ClientFactory {
if (version == A1ProtocolType.STD_V1_1) {
assertNoControllerConfig(ric, version);
return new StdA1ClientVersion1(ric.getConfig(), this.restClientFactory);
+ } else if (version == A1ProtocolType.STD_V2_0_0) {
+ assertNoControllerConfig(ric, version);
+ return new StdA1ClientVersion2(ric.getConfig(), this.restClientFactory);
} else if (version == A1ProtocolType.OSC_V1) {
assertNoControllerConfig(ric, version);
return new OscA1Client(ric.getConfig(), this.restClientFactory);
- } else if (version == A1ProtocolType.SDNC_OSC_STD_V1_1 || version == A1ProtocolType.SDNC_OSC_OSC_V1) {
+ } else if (version == A1ProtocolType.SDNC_OSC_STD_V1_1 || version == A1ProtocolType.SDNC_OSC_OSC_V1
+ || version == A1ProtocolType.SDNC_OSC_STD_V2_0_0) {
return new SdncOscA1Client(version, ric.getConfig(), getControllerConfig(ric), this.restClientFactory);
} else if (version == A1ProtocolType.SDNC_ONAP) {
return new SdncOnapA1Client(ric.getConfig(), getControllerConfig(ric), this.restClientFactory);
@@ -118,7 +122,8 @@ public class A1ClientFactory {
private Mono<A1Client.A1ProtocolType> getProtocolVersion(Ric ric) {
if (ric.getProtocolVersion() == A1ProtocolType.UNKNOWN) {
- return fetchVersion(ric, A1ProtocolType.STD_V1_1) //
+ return fetchVersion(ric, A1ProtocolType.STD_V2_0_0) //
+ .onErrorResume(notUsed -> fetchVersion(ric, A1ProtocolType.STD_V1_1)) //
.onErrorResume(notUsed -> fetchVersion(ric, A1ProtocolType.OSC_V1)) //
.onErrorResume(notUsed -> fetchVersion(ric, A1ProtocolType.SDNC_OSC_STD_V1_1)) //
.onErrorResume(notUsed -> fetchVersion(ric, A1ProtocolType.SDNC_ONAP)) //
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1UriBuilder.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1UriBuilder.java
index d29226c8..08ea0e8c 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1UriBuilder.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1UriBuilder.java
@@ -29,4 +29,10 @@ interface A1UriBuilder {
String createDeleteUri(String type, String policyId);
String createGetPolicyStatusUri(String type, String policyId);
+
+ String createPolicyTypesUri();
+
+ String createGetPolicyIdsUri(String type);
+
+ String createGetSchemaUri(String type);
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java
index 741ab1b9..3643b8d2 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java
@@ -37,7 +37,7 @@ import reactor.core.publisher.Mono;
*/
@SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
public class OscA1Client implements A1Client {
- static final int CONCURRENCY_RIC = 1; // How may paralell requests that is sent to one NearRT RIC
+ static final int CONCURRENCY_RIC = 1; // How many paralell requests that is sent to one NearRT RIC
public static class UriBuilder implements A1UriBuilder {
private final RicConfig ricConfig;
@@ -54,6 +54,7 @@ public class OscA1Client implements A1Client {
/**
* /a1-p/policytypes/{policy_type_id}/policies
*/
+ @Override
public String createGetPolicyIdsUri(String type) {
return createPolicyTypeUri(type) + "/policies";
}
@@ -81,6 +82,7 @@ public class OscA1Client implements A1Client {
/**
* /a1-p/policytypes/{policy_type_id}
*/
+ @Override
public String createGetSchemaUri(String type) {
return this.createPolicyTypeUri(type);
}
@@ -88,6 +90,7 @@ public class OscA1Client implements A1Client {
/**
* ​/a1-p​/policytypes​/{policy_type_id}
*/
+ @Override
public String createPolicyTypesUri() {
return baseUri() + "/policytypes";
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1Client.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1Client.java
index 3ba2ba7b..28c27843 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1Client.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/SdncOscA1Client.java
@@ -48,7 +48,7 @@ import reactor.core.publisher.Mono;
@SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
public class SdncOscA1Client implements A1Client {
- static final int CONCURRENCY_RIC = 1; // How may paralell requests that is sent to one NearRT RIC
+ static final int CONCURRENCY_RIC = 1; // How many paralell requests that is sent to one NearRT RIC
@Value.Immutable
@org.immutables.gson.Gson.TypeAdapters
@@ -81,7 +81,8 @@ public class SdncOscA1Client implements A1Client {
* Constructor that creates the REST client to use.
*
* @param protocolType the southbound protocol of the controller. Supported
- * protocols are SDNC_OSC_STD_V1_1 and SDNC_OSC_OSC_V1
+ * protocols are SDNC_OSC_STD_V1_1, SDNC_OSC_OSC_V1 and
+ * SDNC_OSC_STD_V2_0_0 with
* @param ricConfig the configuration of the Near-RT RIC to communicate
* with
* @param controllerConfig the configuration of the SDNC controller to use
@@ -92,32 +93,35 @@ public class SdncOscA1Client implements A1Client {
AsyncRestClientFactory restClientFactory) {
this(protocolType, ricConfig, controllerConfig,
restClientFactory.createRestClient(controllerConfig.baseUrl() + "/restconf/operations"));
- logger.debug("SdncOscA1Client for ric: {}, a1Controller: {}", ricConfig.ricId(), controllerConfig);
}
/**
* Constructor where the REST client to use is provided.
*
* @param protocolType the southbound protocol of the controller. Supported
- * protocols are SDNC_OSC_STD_V1_1 and SDNC_OSC_OSC_V1
+ * protocols are SDNC_OSC_STD_V1_1, SDNC_OSC_OSC_V1 and
+ * SDNC_OSC_STD_V2_0_0 with
* @param ricConfig the configuration of the Near-RT RIC to communicate
* with
* @param controllerConfig the configuration of the SDNC controller to use
* @param restClient the REST client to use
*
- * @throws IllegalArgumentException when the protocolType is wrong.
+ * @throws IllegalArgumentException when the protocolType is illegal.
*/
public SdncOscA1Client(A1ProtocolType protocolType, RicConfig ricConfig, ControllerConfig controllerConfig,
AsyncRestClient restClient) {
- if (!(A1ProtocolType.SDNC_OSC_STD_V1_1.equals(protocolType)
- || A1ProtocolType.SDNC_OSC_OSC_V1.equals(protocolType))) {
- throw new IllegalArgumentException("Protocol type must be " + A1ProtocolType.SDNC_OSC_STD_V1_1 + " or "
- + A1ProtocolType.SDNC_OSC_OSC_V1 + ", was: " + protocolType);
+ if (A1ProtocolType.SDNC_OSC_STD_V1_1.equals(protocolType) //
+ || A1ProtocolType.SDNC_OSC_OSC_V1.equals(protocolType) //
+ || A1ProtocolType.SDNC_OSC_STD_V2_0_0.equals(protocolType)) {
+ this.restClient = restClient;
+ this.ricConfig = ricConfig;
+ this.protocolType = protocolType;
+ this.controllerConfig = controllerConfig;
+ logger.debug("SdncOscA1Client for ric: {}, a1Controller: {}", ricConfig.ricId(), controllerConfig);
+ } else {
+ throw new IllegalArgumentException("Not handeled protocolversion: " + protocolType);
}
- this.restClient = restClient;
- this.ricConfig = ricConfig;
- this.protocolType = protocolType;
- this.controllerConfig = controllerConfig;
+
}
@Override
@@ -125,9 +129,7 @@ public class SdncOscA1Client implements A1Client {
if (this.protocolType == A1ProtocolType.SDNC_OSC_STD_V1_1) {
return Mono.just(Arrays.asList(""));
} else {
- OscA1Client.UriBuilder uri = new OscA1Client.UriBuilder(ricConfig);
- final String ricUrl = uri.createPolicyTypesUri();
- return post(GET_POLICY_RPC, ricUrl, Optional.empty()) //
+ return post(GET_POLICY_RPC, getUriBuilder().createPolicyTypesUri(), Optional.empty()) //
.flatMapMany(SdncJsonHelper::parseJsonArrayOfString) //
.collectList();
}
@@ -145,20 +147,27 @@ public class SdncOscA1Client implements A1Client {
if (this.protocolType == A1ProtocolType.SDNC_OSC_STD_V1_1) {
return Mono.just("{}");
} else {
- OscA1Client.UriBuilder uri = new OscA1Client.UriBuilder(ricConfig);
+ A1UriBuilder uri = this.getUriBuilder();
final String ricUrl = uri.createGetSchemaUri(policyTypeId);
return post(GET_POLICY_RPC, ricUrl, Optional.empty()) //
- .flatMap(response -> OscA1Client.extractCreateSchema(response, policyTypeId));
+ .flatMap(response -> extractCreateSchema(response, policyTypeId));
+ }
+ }
+
+ private Mono<String> extractCreateSchema(String controllerResponse, String policyTypeId) {
+ if (this.protocolType == A1ProtocolType.SDNC_OSC_OSC_V1) {
+ return OscA1Client.extractCreateSchema(controllerResponse, policyTypeId);
+ } else if (this.protocolType == A1ProtocolType.SDNC_OSC_STD_V2_0_0) {
+ return StdA1ClientVersion2.extractPolicySchema(controllerResponse, policyTypeId);
+ } else {
+ throw new NullPointerException("Not supported");
}
}
@Override
public Mono<String> putPolicy(Policy policy) {
- return getUriBuilder() //
- .flatMap(builder -> {
- String ricUrl = builder.createPutPolicyUri(policy.type().id(), policy.id());
- return post("putA1Policy", ricUrl, Optional.of(policy.json()));
- });
+ String ricUrl = getUriBuilder().createPutPolicyUri(policy.type().id(), policy.id());
+ return post("putA1Policy", ricUrl, Optional.of(policy.json()));
}
@Override
@@ -172,44 +181,46 @@ public class SdncOscA1Client implements A1Client {
return getPolicyIds() //
.flatMap(policyId -> deletePolicyById("", policyId), CONCURRENCY_RIC); //
} else {
- OscA1Client.UriBuilder uriBuilder = new OscA1Client.UriBuilder(ricConfig);
+ A1UriBuilder uriBuilder = this.getUriBuilder();
return getPolicyTypeIdentities() //
.flatMapMany(Flux::fromIterable) //
- .flatMap(type -> oscDeleteInstancesForType(uriBuilder, type), CONCURRENCY_RIC);
+ .flatMap(type -> deleteAllInstancesForType(uriBuilder, type), CONCURRENCY_RIC);
}
}
- private Flux<String> oscGetInstancesForType(OscA1Client.UriBuilder uriBuilder, String type) {
+ private Flux<String> getInstancesForType(A1UriBuilder uriBuilder, String type) {
return post(GET_POLICY_RPC, uriBuilder.createGetPolicyIdsUri(type), Optional.empty()) //
.flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
}
- private Flux<String> oscDeleteInstancesForType(OscA1Client.UriBuilder uriBuilder, String type) {
- return oscGetInstancesForType(uriBuilder, type) //
+ private Flux<String> deleteAllInstancesForType(A1UriBuilder uriBuilder, String type) {
+ return getInstancesForType(uriBuilder, type) //
.flatMap(instance -> deletePolicyById(type, instance), CONCURRENCY_RIC);
}
@Override
public Mono<A1ProtocolType> getProtocolVersion() {
- return tryStdProtocolVersion() //
+ return tryStdProtocolVersion2() //
+ .onErrorResume(t -> tryStdProtocolVersion1()) //
.onErrorResume(t -> tryOscProtocolVersion());
}
@Override
public Mono<String> getPolicyStatus(Policy policy) {
- return getUriBuilder() //
- .flatMap(builder -> {
- String ricUrl = builder.createGetPolicyStatusUri(policy.type().id(), policy.id());
- return post("getA1PolicyStatus", ricUrl, Optional.empty());
- });
+ String ricUrl = getUriBuilder().createGetPolicyStatusUri(policy.type().id(), policy.id());
+ return post("getA1PolicyStatus", ricUrl, Optional.empty());
+
}
- private Mono<A1UriBuilder> getUriBuilder() {
+ private A1UriBuilder getUriBuilder() {
if (protocolType == A1ProtocolType.SDNC_OSC_STD_V1_1) {
- return Mono.just(new StdA1ClientVersion1.UriBuilder(ricConfig));
- } else {
- return Mono.just(new OscA1Client.UriBuilder(ricConfig));
+ return new StdA1ClientVersion1.UriBuilder(ricConfig);
+ } else if (protocolType == A1ProtocolType.SDNC_OSC_STD_V2_0_0) {
+ return new StdA1ClientVersion2.UriBuilder(ricConfig);
+ } else if (protocolType == A1ProtocolType.SDNC_OSC_OSC_V1) {
+ return new OscA1Client.UriBuilder(ricConfig);
}
+ throw new NullPointerException();
}
private Mono<A1ProtocolType> tryOscProtocolVersion() {
@@ -218,20 +229,26 @@ public class SdncOscA1Client implements A1Client {
.flatMap(x -> Mono.just(A1ProtocolType.SDNC_OSC_OSC_V1));
}
- private Mono<A1ProtocolType> tryStdProtocolVersion() {
+ private Mono<A1ProtocolType> tryStdProtocolVersion1() {
StdA1ClientVersion1.UriBuilder uriBuilder = new StdA1ClientVersion1.UriBuilder(ricConfig);
- return post(GET_POLICY_RPC, uriBuilder.createGetPolicyIdsUri(), Optional.empty()) //
+ return post(GET_POLICY_RPC, uriBuilder.createGetPolicyIdsUri(""), Optional.empty()) //
.flatMap(x -> Mono.just(A1ProtocolType.SDNC_OSC_STD_V1_1));
}
+ private Mono<A1ProtocolType> tryStdProtocolVersion2() {
+ StdA1ClientVersion2.UriBuilder uriBuilder = new StdA1ClientVersion2.UriBuilder(ricConfig);
+ return post(GET_POLICY_RPC, uriBuilder.createPolicyTypesUri(), Optional.empty()) //
+ .flatMap(x -> Mono.just(A1ProtocolType.SDNC_OSC_STD_V2_0_0));
+ }
+
private Flux<String> getPolicyIds() {
if (this.protocolType == A1ProtocolType.SDNC_OSC_STD_V1_1) {
StdA1ClientVersion1.UriBuilder uri = new StdA1ClientVersion1.UriBuilder(ricConfig);
- final String ricUrl = uri.createGetPolicyIdsUri();
+ final String ricUrl = uri.createGetPolicyIdsUri("");
return post(GET_POLICY_RPC, ricUrl, Optional.empty()) //
.flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
} else {
- OscA1Client.UriBuilder uri = new OscA1Client.UriBuilder(ricConfig);
+ A1UriBuilder uri = this.getUriBuilder();
return getPolicyTypeIdentities() //
.flatMapMany(Flux::fromIterable)
.flatMap(type -> post(GET_POLICY_RPC, uri.createGetPolicyIdsUri(type), Optional.empty())) //
@@ -240,11 +257,8 @@ public class SdncOscA1Client implements A1Client {
}
private Mono<String> deletePolicyById(String type, String policyId) {
- return getUriBuilder() //
- .flatMap(builder -> {
- String ricUrl = builder.createDeleteUri(type, policyId);
- return post("deleteA1Policy", ricUrl, Optional.empty());
- });
+ String ricUrl = getUriBuilder().createDeleteUri(type, policyId);
+ return post("deleteA1Policy", ricUrl, Optional.empty());
}
private Mono<String> post(String rpcName, String ricUrl, Optional<String> body) {
@@ -270,8 +284,9 @@ public class SdncOscA1Client implements A1Client {
} else {
logger.debug("Error response: {} {}", output.httpStatus(), body);
byte[] responseBodyBytes = body.getBytes(StandardCharsets.UTF_8);
- WebClientResponseException responseException = new WebClientResponseException(output.httpStatus(),
- "statusText", null, responseBodyBytes, StandardCharsets.UTF_8, null);
+ HttpStatus httpStatus = HttpStatus.valueOf(output.httpStatus());
+ WebClientResponseException responseException = new WebClientResponseException(httpStatus.value(),
+ httpStatus.getReasonPhrase(), null, responseBodyBytes, StandardCharsets.UTF_8, null);
return Mono.error(responseException);
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java
index d094e7a1..94567234 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java
@@ -53,7 +53,8 @@ public class StdA1ClientVersion1 implements A1Client {
/**
* /A1-P/v1/policies
*/
- public String createGetPolicyIdsUri() {
+ @Override
+ public String createGetPolicyIdsUri(String type) {
return baseUri() + "/policies";
}
@@ -68,6 +69,7 @@ public class StdA1ClientVersion1 implements A1Client {
/**
* /A1-P/v1/policies/{policyId}/status
*/
+ @Override
public String createGetPolicyStatusUri(String type, String policyId) {
return policiesBaseUri() + policyId + "/status";
}
@@ -77,7 +79,17 @@ public class StdA1ClientVersion1 implements A1Client {
}
private String policiesBaseUri() {
- return createGetPolicyIdsUri() + "/";
+ return createGetPolicyIdsUri("") + "/";
+ }
+
+ @Override
+ public String createPolicyTypesUri() {
+ throw new NullPointerException("Not supported URI");
+ }
+
+ @Override
+ public String createGetSchemaUri(String type) {
+ throw new NullPointerException("Not supported URI");
}
}
@@ -137,7 +149,7 @@ public class StdA1ClientVersion1 implements A1Client {
}
private Flux<String> getPolicyIds() {
- return restClient.get(uri.createGetPolicyIdsUri()) //
+ return restClient.get(uri.createGetPolicyIdsUri("")) //
.flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
new file mode 100644
index 00000000..c475b22f
--- /dev/null
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java
@@ -0,0 +1,208 @@
+/*-
+ * ========================LICENSE_START=================================
+ * ONAP : ccsdk oran
+ * ======================================================================
+ * Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * ======================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================LICENSE_END===================================
+ */
+
+package org.onap.ccsdk.oran.a1policymanagementservice.clients;
+
+import java.lang.invoke.MethodHandles;
+import java.util.List;
+
+import org.json.JSONObject;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+/**
+ * Client for accessing ORAN A1-P Vesion 2.0 REST API
+ */
+@SuppressWarnings("squid:S2629") // Invoke method(s) only conditionally
+public class StdA1ClientVersion2 implements A1Client {
+ static final int CONCURRENCY_RIC = 1; // How many paralell requests that is sent to one NearRT RIC
+
+ public static class UriBuilder implements A1UriBuilder {
+ private final RicConfig ricConfig;
+
+ public UriBuilder(RicConfig ricConfig) {
+ this.ricConfig = ricConfig;
+ }
+
+ @Override
+ public String createPutPolicyUri(String type, String policyId) {
+ return createPolicyUri(type, policyId);
+ }
+
+ /**
+ * /A1-P/v2​/policytypes/{policy_type_id}/policies
+ */
+ @Override
+ public String createGetPolicyIdsUri(String type) {
+ return createPolicyTypeUri(type) + "/policies";
+ }
+
+ @Override
+ public String createDeleteUri(String type, String policyId) {
+ return createPolicyUri(type, policyId);
+ }
+
+ /**
+ * ​/A1-P/v2​/policytypes​/{policy_type_id}​/policies​/{policy_instance_id}​/status
+ */
+ @Override
+ public String createGetPolicyStatusUri(String type, String policyId) {
+ return createPolicyUri(type, policyId) + "/status";
+ }
+
+ /**
+ * /A1-P/v2/policytypes/{policy_type_id}
+ */
+ @Override
+ public String createGetSchemaUri(String type) {
+ return this.createPolicyTypeUri(type);
+ }
+
+ /**
+ * ​/A1-P/v2​/policytypes​/{policy_type_id}
+ */
+ @Override
+ public String createPolicyTypesUri() {
+ return baseUri() + "/policytypes";
+ }
+
+ /**
+ * ​/A1-P/v2​/policytypes​/{policy_type_id}​/policies​/{policy_instance_id}
+ */
+ private String createPolicyUri(String type, String id) {
+ return createPolicyTypeUri(type) + "/policies/" + id;
+ }
+
+ /**
+ * /A1-P/v2/policytypes/{policy_type_id}
+ */
+ private String createPolicyTypeUri(String type) {
+ return createPolicyTypesUri() + "/" + type;
+ }
+
+ private String baseUri() {
+ return ricConfig.baseUrl() + "/A1-P/v2";
+ }
+ }
+
+ private static final String TITLE = "title";
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ private final AsyncRestClient restClient;
+ private final UriBuilder uriBuiler;
+
+ public StdA1ClientVersion2(RicConfig ricConfig, AsyncRestClientFactory restClientFactory) {
+ this(ricConfig, restClientFactory.createRestClient(""));
+ }
+
+ public StdA1ClientVersion2(RicConfig ricConfig, AsyncRestClient restClient) {
+ this.restClient = restClient;
+ logger.debug("OscA1Client for ric: {}", ricConfig.ricId());
+
+ uriBuiler = new UriBuilder(ricConfig);
+ }
+
+ public static Mono<String> extractPolicySchema(String policyTypeResponse, String policyTypeId) {
+ try {
+ JSONObject obj = new JSONObject(policyTypeResponse);
+ JSONObject schemaObj = obj.getJSONObject("policySchema");
+ schemaObj.put(TITLE, policyTypeId);
+ return Mono.just(schemaObj.toString());
+ } catch (Exception e) {
+ String exceptionString = e.toString();
+ logger.error("Unexpected response for policy type: {}, exception: {}", policyTypeResponse, exceptionString);
+ return Mono.error(e);
+ }
+ }
+
+ @Override
+ public Mono<List<String>> getPolicyTypeIdentities() {
+ return getPolicyTypeIds() //
+ .collectList();
+ }
+
+ @Override
+ public Mono<List<String>> getPolicyIdentities() {
+ return getPolicyTypeIds() //
+ .flatMap(this::getPolicyIdentitiesByType) //
+ .collectList();
+ }
+
+ @Override
+ public Mono<String> getPolicyTypeSchema(String policyTypeId) {
+ String schemaUri = uriBuiler.createGetSchemaUri(policyTypeId);
+ return restClient.get(schemaUri) //
+ .flatMap(response -> extractPolicySchema(response, policyTypeId));
+ }
+
+ @Override
+ public Mono<String> putPolicy(Policy policy) {
+ String policyUri = this.uriBuiler.createPutPolicyUri(policy.type().id(), policy.id());
+ return restClient.put(policyUri, policy.json());
+ }
+
+ @Override
+ public Mono<String> deletePolicy(Policy policy) {
+ return deletePolicyById(policy.type().id(), policy.id());
+ }
+
+ @Override
+ public Mono<A1ProtocolType> getProtocolVersion() {
+ return restClient.get(uriBuiler.createPolicyTypesUri()) //
+ .flatMap(notUsed -> Mono.just(A1ProtocolType.STD_V2_0_0));
+ }
+
+ @Override
+ public Flux<String> deleteAllPolicies() {
+ return getPolicyTypeIds() //
+ .flatMap(this::deletePoliciesForType, CONCURRENCY_RIC);
+ }
+
+ @Override
+ public Mono<String> getPolicyStatus(Policy policy) {
+ String statusUri = uriBuiler.createGetPolicyStatusUri(policy.type().id(), policy.id());
+ return restClient.get(statusUri);
+
+ }
+
+ private Flux<String> getPolicyTypeIds() {
+ return restClient.get(uriBuiler.createPolicyTypesUri()) //
+ .flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
+ }
+
+ private Flux<String> getPolicyIdentitiesByType(String typeId) {
+ return restClient.get(uriBuiler.createGetPolicyIdsUri(typeId)) //
+ .flatMapMany(SdncJsonHelper::parseJsonArrayOfString);
+ }
+
+ private Mono<String> deletePolicyById(String typeId, String policyId) {
+ String policyUri = uriBuiler.createDeleteUri(typeId, policyId);
+ return restClient.delete(policyUri);
+ }
+
+ private Flux<String> deletePoliciesForType(String typeId) {
+ return getPolicyIdentitiesByType(typeId) //
+ .flatMap(policyId -> deletePolicyById(typeId, policyId), CONCURRENCY_RIC);
+ }
+}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java
index cf7ca74e..88d99232 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTask.java
@@ -59,7 +59,7 @@ import reactor.core.publisher.SignalType;
public class RicSynchronizationTask {
private static final Logger logger = LoggerFactory.getLogger(RicSynchronizationTask.class);
- static final int CONCURRENCY_RIC = 1; // How may paralell requests that is sent to one NearRT RIC
+ static final int CONCURRENCY_RIC = 1; // How many paralell requests that is sent to one NearRT RIC
private final A1ClientFactory a1ClientFactory;
private final PolicyTypes policyTypes;