import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import org.oransc.policyagent.repository.Policy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public class A1ClientImpl implements A1Client {
return nearRtRicUrl + "/A1-P/v1";
}
- public AsyncRestClient createClient(final String nearRtRicUrl) {
+ protected AsyncRestClient createClient(final String nearRtRicUrl) {
return new AsyncRestClient(getBaseUrl(nearRtRicUrl));
}
@Override
- public Flux<String> getPolicyTypeIdentities(String nearRtRicUrl) {
+ public Mono<Collection<String>> getPolicyTypeIdentities(String nearRtRicUrl) {
logger.debug("getPolicyTypeIdentities nearRtRicUrl = {}", nearRtRicUrl);
AsyncRestClient client = createClient(nearRtRicUrl);
- Mono<String> response = client.get("/policytypes/identities");
- return response.flatMapMany(this::createFlux);
+ return client.get("/policytypes/identities") //
+ .flatMap(this::parseJsonArrayOfString);
}
@Override
- public Flux<String> getPolicyIdentities(String nearRtRicUrl) {
+ public Mono<Collection<String>> getPolicyIdentities(String nearRtRicUrl) {
logger.debug("getPolicyIdentities nearRtRicUrl = {}", nearRtRicUrl);
AsyncRestClient client = createClient(nearRtRicUrl);
- Mono<String> response = client.get("/policies/identities");
- return response.flatMapMany(this::createFlux);
+ return client.get("/policies/identities") //
+ .flatMap(this::parseJsonArrayOfString);
}
@Override
}
@Override
- public Mono<String> putPolicy(String nearRtRicUrl, String policyId, String policyString) {
- logger.debug("putPolicy nearRtRicUrl = {}, policyId = {}, policyString = {}", nearRtRicUrl, policyId,
- policyString);
- AsyncRestClient client = createClient(nearRtRicUrl);
- Mono<String> response = client.put("/policies/" + policyId, policyString);
+ public Mono<String> putPolicy(Policy policy) {
+ logger.debug("putPolicy nearRtRicUrl = {}, policyId = {}, policyString = {}", //
+ policy.ric().getConfig().baseUrl(), policy.id(), policy.json());
+ AsyncRestClient client = createClient(policy.ric().getConfig().baseUrl());
+ // TODO update when simulator is updated to include policy type
+ // Mono<String> response = client.put("/policies/" + policy.id() + "?policyTypeId=" + policy.type().name(),
+ // policy.json());
+ Mono<String> response = client.put("/policies/" + policy.id(), policy.json());
+
return response.flatMap(this::createMono);
}
return client.delete("/policies/" + policyId);
}
- private Flux<String> createFlux(String inputString) {
+ private Mono<Collection<String>> parseJsonArrayOfString(String inputString) {
try {
List<String> arrayList = new ArrayList<>();
JSONArray jsonArray = new JSONArray(inputString);
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);
}
}