X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fclients%2FA1ClientImpl.java;h=b3773b8e0910413c92461e916acae75ef6dfd5c8;hb=b47a7130c10bef2bf812366ca971e4eaa938b152;hp=7bbb4990ce3135672dd0be5a9fdd94bc210731b5;hpb=35e7ea7bb7a6e2890542f3535aa09b11b2f079a1;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientImpl.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientImpl.java index 7bbb4990..b3773b8e 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientImpl.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/A1ClientImpl.java @@ -22,6 +22,7 @@ package org.oransc.policyagent.clients; import java.lang.invoke.MethodHandles; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.json.JSONArray; @@ -29,8 +30,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; public class A1ClientImpl implements A1Client { @@ -40,26 +39,30 @@ public class A1ClientImpl implements A1Client { return nearRtRicUrl + "/A1-P/v1"; } + public AsyncRestClient createClient(final String nearRtRicUrl) { + return new AsyncRestClient(getBaseUrl(nearRtRicUrl)); + } + @Override - public Flux getPolicyTypeIdentities(String nearRtRicUrl) { + public Mono> getPolicyTypeIdentities(String nearRtRicUrl) { logger.debug("getPolicyTypeIdentities nearRtRicUrl = {}", nearRtRicUrl); - AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl)); - Mono response = client.get("/policytypes/identities"); - return response.flatMapMany(this::createFlux); + AsyncRestClient client = createClient(nearRtRicUrl); + return client.get("/policytypes/identities") // + .flatMap(this::parseJsonArrayOfString); } @Override - public Flux getPolicyIdentities(String nearRtRicUrl) { + public Mono> getPolicyIdentities(String nearRtRicUrl) { logger.debug("getPolicyIdentities nearRtRicUrl = {}", nearRtRicUrl); - AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl)); - Mono response = client.get("/policies/identities"); - return response.flatMapMany(this::createFlux); + AsyncRestClient client = createClient(nearRtRicUrl); + return client.get("/policies/identities") // + .flatMap(this::parseJsonArrayOfString); } @Override public Mono getPolicyType(String nearRtRicUrl, String policyTypeId) { logger.debug("getPolicyType nearRtRicUrl = {}, policyTypeId = {}", nearRtRicUrl, policyTypeId); - AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl)); + AsyncRestClient client = createClient(nearRtRicUrl); Mono response = client.get("/policytypes/" + policyTypeId); return response.flatMap(this::createMono); } @@ -68,19 +71,19 @@ public class A1ClientImpl implements A1Client { public Mono putPolicy(String nearRtRicUrl, String policyId, String policyString) { logger.debug("putPolicy nearRtRicUrl = {}, policyId = {}, policyString = {}", nearRtRicUrl, policyId, policyString); - AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl)); + AsyncRestClient client = createClient(nearRtRicUrl); Mono response = client.put("/policies/" + policyId, policyString); return response.flatMap(this::createMono); } @Override - public Mono deletePolicy(String nearRtRicUrl, String policyId) { + public Mono deletePolicy(String nearRtRicUrl, String policyId) { logger.debug("deletePolicy nearRtRicUrl = {}, policyId = {}", nearRtRicUrl, policyId); - AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl)); + AsyncRestClient client = createClient(nearRtRicUrl); return client.delete("/policies/" + policyId); } - private Flux createFlux(String inputString) { + private Mono> parseJsonArrayOfString(String inputString) { try { List arrayList = new ArrayList<>(); JSONArray jsonArray = new JSONArray(inputString); @@ -88,9 +91,9 @@ public class A1ClientImpl implements A1Client { arrayList.add(jsonArray.getString(i)); } logger.debug("A1 client: received list = {}", arrayList); - return Flux.fromIterable(arrayList); + return Mono.just(arrayList); } catch (JSONException ex) { // invalid json - return Flux.error(ex); + return Mono.error(ex); } }