Fix Sonar and CheckStyle warnings
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / clients / SdncOscA1Client.java
index fcb3236..a5735f7 100644 (file)
@@ -48,6 +48,8 @@ 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
+
     @Value.Immutable
     @org.immutables.gson.Gson.TypeAdapters
     public interface AdapterRequest {
@@ -76,14 +78,12 @@ public class SdncOscA1Client implements A1Client {
     private final A1ProtocolType protocolType;
 
     /**
-     * Constructor
-     * 
+     * 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
-     * @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
+     * @param ricConfig the configuration of the Ric to communicate with
+     * @param controllerConfig the configuration of the SDNC controller to use
      */
     public SdncOscA1Client(A1ProtocolType protocolType, RicConfig ricConfig, ControllerConfig controllerConfig) {
         this(protocolType, ricConfig, controllerConfig,
@@ -91,6 +91,15 @@ public class SdncOscA1Client implements A1Client {
         logger.debug("SdncOscA1Client for ric: {}, a1Controller: {}", ricConfig.name(), 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
+     * @param ricConfig the configuration of the Ric to communicate with
+     * @param controllerConfig the configuration of the SDNC controller to use
+     * @param restClient the REST client to use
+     */
     public SdncOscA1Client(A1ProtocolType protocolType, RicConfig ricConfig, ControllerConfig controllerConfig,
         AsyncRestClient restClient) {
         this.restClient = restClient;
@@ -157,18 +166,27 @@ public class SdncOscA1Client implements A1Client {
     public Flux<String> deleteAllPolicies() {
         if (this.protocolType == A1ProtocolType.SDNC_OSC_STD_V1_1) {
             return getPolicyIds() //
-                .flatMap(policyId -> deletePolicyById("", policyId)); //
+                .flatMap(policyId -> deletePolicyById("", policyId), CONCURRENCY_RIC); //
         } else if (this.protocolType == A1ProtocolType.SDNC_OSC_OSC_V1) {
             OscA1Client.UriBuilder uriBuilder = new OscA1Client.UriBuilder(ricConfig);
             return getPolicyTypeIdentities() //
-                .flatMapMany(Flux::fromIterable)
-                .flatMap(type -> post(GET_POLICY_RPC, uriBuilder.createGetPolicyIdsUri(type), Optional.empty())) //
-                .flatMap(SdncJsonHelper::parseJsonArrayOfString);
+                .flatMapMany(Flux::fromIterable) //
+                .flatMap(type -> oscDeleteInstancesForType(uriBuilder, type), CONCURRENCY_RIC);
         } else {
             return Flux.error(createIllegalProtocolException());
         }
     }
 
+    private Flux<String> oscGetInstancesForType(OscA1Client.UriBuilder 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) //
+            .flatMap(instance -> deletePolicyById(type, instance), CONCURRENCY_RIC);
+    }
+
     @Override
     public Mono<A1ProtocolType> getProtocolVersion() {
         return tryStdProtocolVersion() //