* limitations under the License.
* ========================LICENSE_END===================================
*/
+
package org.oransc.policyagent.clients;
-import java.lang.invoke.MethodHandles;
-import java.util.ArrayList;
import java.util.List;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.oransc.policyagent.repository.Policy;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
-public class A1Client {
- private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+public interface A1Client {
- public String getBaseUrl(final String nearRtRicUrl) {
- return nearRtRicUrl + "/A1-P/v1";
+ public enum A1ProtocolType {
+ UNKNOWN, //
+ STD_V1_1, // version 1.1
+ OSC_V1, //
+ SDNC_OSC, //
+ SDNC_ONAP
}
- public Flux<String> getAllPolicyTypes(String nearRtRicUrl) {
- logger.debug("getAllPolicyTypes nearRtRicUrl = {}", nearRtRicUrl);
- AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl));
- Mono<String> response = client.get("/policytypes");
- return response.flatMapMany(this::createPolicyTypesFlux);
- }
+ public Mono<A1ProtocolType> getProtocolVersion();
- public Flux<String> getPoliciesForType(String nearRtRicUrl, String policyTypeId) {
- logger.debug("getPoliciesForType nearRtRicUrl = {}, policyTypeId = {}", nearRtRicUrl, policyTypeId);
- AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl));
- Mono<String> response = client.get("/policies");
- return response.flatMapMany(policiesString -> createPoliciesFlux(policiesString, policyTypeId));
- }
+ public Mono<List<String>> getPolicyTypeIdentities();
- public Mono<String> getPolicy(String nearRtRicUrl, String policyId) {
- logger.debug("getPolicy nearRtRicUrl = {}, policyId = {}", nearRtRicUrl, policyId);
- AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl));
- Mono<String> response = client.get("/policies/" + policyId);
- return response.flatMap(this::createPolicyMono);
- }
+ public Mono<List<String>> getPolicyIdentities();
- public Mono<String> putPolicy(String nearRtRicUrl, String policyId, String policyString) {
- logger.debug("putPolicy nearRtRicUrl = {}, policyId = {}, policyString = {}", nearRtRicUrl, policyId,
- policyString);
- AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl));
- Mono<String> response = client.put("/policies/" + policyId, policyString);
- return response.flatMap(this::createPolicyMono);
- }
+ public Mono<String> getPolicyTypeSchema(String policyTypeId);
- public Mono<Void> deletePolicy(String nearRtRicUrl, String policyId) {
- logger.debug("deletePolicy nearRtRicUrl = {}, policyId = {}", nearRtRicUrl, policyId);
- AsyncRestClient client = new AsyncRestClient(getBaseUrl(nearRtRicUrl));
- return client.delete("/policies/" + policyId);
- }
+ public Mono<String> putPolicy(Policy policy);
- private Flux<String> createPolicyTypesFlux(String policyTypesString) {
- List<String> policyTypesList = new ArrayList<>();
- JSONArray policyTypesArray = new JSONArray(policyTypesString);
- for (int i = 0; i < policyTypesArray.length(); i++) {
- policyTypesList.add(policyTypesArray.getJSONObject(i).toString());
- }
- logger.debug("A1 client: policyTypes = {}", policyTypesList);
- return Flux.fromIterable(policyTypesList);
- }
+ public Mono<String> deletePolicy(Policy policy);
- private Flux<String> createPoliciesFlux(String policiesString, String policyTypeId) {
- List<String> policiesList = new ArrayList<>();
- JSONArray policiesArray = new JSONArray(policiesString);
- for (int i = 0; i < policiesArray.length(); i++) {
- JSONObject policyObject = policiesArray.getJSONObject(i);
- if (policyObject.get("policyTypeId").equals(policyTypeId)) {
- policiesList.add(policyObject.toString());
- }
- }
- logger.debug("A1 client: policies = {}", policiesList);
- return Flux.fromIterable(policiesList);
- }
+ public Flux<String> deleteAllPolicies();
- private Mono<String> createPolicyMono(String policyString) {
- // remove white-spaces
- policyString = policyString.replaceAll("\\s+", "");
- logger.debug("A1 client: policy = {}", policyString);
- return Mono.just(policyString);
- }
+ public Mono<String> getPolicyStatus(Policy policy);
}