X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fclients%2FOscA1Client.java;h=a388267e344dbe362e4446591262c09bfbdbc016;hb=6d503afd38bdf9823bda3dfe3d307adaeb6f7eee;hp=aaa9519ca22155ace880f6f1437771927ef36170;hpb=f700867fa65c7172cee7fca229eb10f2ecdf77dd;p=nonrtric.git 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 aaa9519c..a388267e 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 @@ -25,6 +25,7 @@ import java.util.List; import org.json.JSONObject; import org.oransc.policyagent.configuration.RicConfig; +import org.oransc.policyagent.configuration.WebClientConfig; import org.oransc.policyagent.repository.Policy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,6 +38,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 public static class UriBuilder implements A1UriBuilder { private final RicConfig ricConfig; @@ -115,8 +117,8 @@ public class OscA1Client implements A1Client { private final AsyncRestClient restClient; private final UriBuilder uri; - public OscA1Client(RicConfig ricConfig) { - this(ricConfig, new AsyncRestClient("")); + public OscA1Client(RicConfig ricConfig, WebClientConfig clientConfig) { + this(ricConfig, new AsyncRestClient("", clientConfig)); } public OscA1Client(RicConfig ricConfig, AsyncRestClient restClient) { @@ -126,6 +128,19 @@ public class OscA1Client implements A1Client { uri = new UriBuilder(ricConfig); } + public static Mono extractCreateSchema(String policyTypeResponse, String policyTypeId) { + try { + JSONObject obj = new JSONObject(policyTypeResponse); + JSONObject schemaObj = obj.getJSONObject("create_schema"); + 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> getPolicyTypeIdentities() { return getPolicyTypeIds() // @@ -143,7 +158,7 @@ public class OscA1Client implements A1Client { public Mono getPolicyTypeSchema(String policyTypeId) { String schemaUri = uri.createGetSchemaUri(policyTypeId); return restClient.get(schemaUri) // - .flatMap(response -> getCreateSchema(response, policyTypeId)); + .flatMap(response -> extractCreateSchema(response, policyTypeId)); } @Override @@ -166,7 +181,7 @@ public class OscA1Client implements A1Client { @Override public Flux deleteAllPolicies() { return getPolicyTypeIds() // - .flatMap(this::deletePoliciesForType); + .flatMap(this::deletePoliciesForType, CONCURRENCY_RIC); } @Override @@ -186,19 +201,6 @@ public class OscA1Client implements A1Client { .flatMapMany(SdncJsonHelper::parseJsonArrayOfString); } - private Mono getCreateSchema(String policyTypeResponse, String policyTypeId) { - try { - JSONObject obj = new JSONObject(policyTypeResponse); - JSONObject schemaObj = obj.getJSONObject("create_schema"); - 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); - } - } - private Mono deletePolicyById(String typeId, String policyId) { String policyUri = uri.createDeleteUri(typeId, policyId); return restClient.delete(policyUri); @@ -206,6 +208,6 @@ public class OscA1Client implements A1Client { private Flux deletePoliciesForType(String typeId) { return getPolicyIdentitiesByType(typeId) // - .flatMap(policyId -> deletePolicyById(typeId, policyId)); + .flatMap(policyId -> deletePolicyById(typeId, policyId), CONCURRENCY_RIC); } }