From: RehanRaza Date: Wed, 22 Jan 2020 13:44:55 +0000 (+0100) Subject: Adapt A1 controller to new interface X-Git-Tag: 1.0.1~35^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=d61ace5d61f7cc0231e163df98e6cb867b838642;p=nonrtric.git Adapt A1 controller to new interface Change-Id: Ie73a72f4b0882b0d741b405d8736dc3b64d6b9af Signed-off-by: RehanRaza --- diff --git a/pom.xml b/pom.xml index 0a9184fa..933411f8 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,7 @@ nonrtric policy-agent + sdnc-a1-controller dashboard near-rt-ric-simulator diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/model/src/main/yang/NONRT-RIC-API.yang b/sdnc-a1-controller/northbound/nonrt-ric-api/model/src/main/yang/NONRT-RIC-API.yang index 986e2017..d8704e33 100644 --- a/sdnc-a1-controller/northbound/nonrt-ric-api/model/src/main/yang/NONRT-RIC-API.yang +++ b/sdnc-a1-controller/northbound/nonrt-ric-api/model/src/main/yang/NONRT-RIC-API.yang @@ -27,238 +27,87 @@ module A1-ADAPTER-API { import ietf-yang-types { prefix yang; } - revision "2019-10-02" { + revision "2020-01-22" { description "A1 adapter"; } - //Flattend interface using RPC - - //Get an array of near-rt-ric IDs, - //Each item in the returned array will be regarded as one near-rt-ric-id. - rpc getNearRT-RICs { - output { - leaf-list near-rt-ric-id-list { - type string; - } - leaf code { - type string; - } - } - } - - //Get health status for a Near-RT-RIC. true - health ok, false - health is not ok. - rpc getHealthCheck { - input { - leaf near-rt-ric-id { - type string; - } - } - - output { - leaf health-status { - type boolean; - } - leaf code { - type string; - } - } - } - //Get an array of integer policy type ids //Each item in the returned array will be regarded as one policy-type-id. - rpc getPolicyTypes { + rpc getPolicyTypeIdentities { input { - leaf near-rt-ric-id { + leaf near-rt-ric-url { type string; } } output { leaf-list policy-type-id-list { - type uint32; - } - leaf code { - type string; - } - } - } - - //Create a policy type - rpc createPolicyType { - input { - leaf near-rt-ric-id { - type string; - } - leaf policy-type-id { - type uint32; - } - leaf description { - type string; - } - leaf name { - type string; - } - leaf policy-type { - type string; - } - } - output { - leaf code { - type string; - } - } - } - - //Get a policy type - rpc getPolicyType { - input { - leaf near-rt-ric-id { - type string; - } - leaf policy-type-id { - type uint32; - } - } - output { - leaf description { - type string; - } - leaf name { - type string; - } - leaf policy-type { - type string; - } - leaf code { type string; } } } - //Delete a policy type - rpc deletePolicyType { + //Get an array of integer policy ids + //Each item in the returned array will be regarded as one policy-id. + rpc getPolicyIdentities { input { - leaf near-rt-ric-id { + leaf near-rt-ric-url { type string; } - leaf policy-type-id { - type uint32; - } - } - output { - leaf code { - type string; - } - } - } - - //Get an array of string policy instance ids - //Each item in the returned array will be regarded as one policy-instance-id. - rpc getPolicyInstances { - input { - leaf near-rt-ric-id { - type string; - } - leaf policy-type-id { - type uint32; - } } output { - leaf-list policy-instance-id-list { - type string; - } - leaf code { + leaf-list policy-id-list { type string; } } } - //Create a policy instance - rpc createPolicyInstance { + //Get a policy type + rpc getPolicyType { input { - leaf near-rt-ric-id { + leaf near-rt-ric-url { type string; } leaf policy-type-id { - type uint32; - } - leaf policy-instance-id { - type string; - } - leaf policy-instance { type string; } } output { - leaf code { + leaf policy-type { type string; } } } - ///Get a policy instance - rpc getPolicyInstance { + //Create a policy + rpc putPolicy { input { - leaf near-rt-ric-id { + leaf near-rt-ric-url { type string; } - leaf policy-type-id { - type uint32; - } - leaf policy-instance-id { - type string; - } - } - output { - leaf policy-instance { - type string; - } - leaf code { - type string; - } - } - } - - //Delete a policy instance - rpc deletePolicyInstance { - input { - leaf near-rt-ric-id { + leaf policy-id { type string; } - leaf policy-type-id { - type uint32; - } - leaf policy-instance-id { + leaf policy { type string; } } output { - leaf code { + leaf returned-policy { type string; } } } - //Get the status for a policy instance - rpc getStatus { + //Delete a policy + rpc deletePolicy { input { - leaf near-rt-ric-id { - type string; - } - leaf policy-type-id { - type uint32; - } - leaf policy-instance-id { - type string; - } - } - output { - leaf status { + leaf near-rt-ric-url { type string; } - leaf code { + leaf policy-id { type string; } } diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/exceptions/NearRtRicNotFoundException.java b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/exceptions/NearRtRicNotFoundException.java deleted file mode 100644 index 1754bfa4..00000000 --- a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/exceptions/NearRtRicNotFoundException.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.onap.sdnc.northbound.exceptions; - -public class NearRtRicNotFoundException extends RuntimeException { - - /** - * - */ - private static final long serialVersionUID = -4503072266424371087L; - - public NearRtRicNotFoundException(String message) { - super(message); - } - -} diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/provider/NonrtRicApiProvider.java b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/provider/NonrtRicApiProvider.java index b5e3deed..9f69f56b 100644 --- a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/provider/NonrtRicApiProvider.java +++ b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/provider/NonrtRicApiProvider.java @@ -23,68 +23,44 @@ package org.onap.sdnc.northbound.provider; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import com.google.gson.Gson; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.TimeZone; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.json.JSONObject; -import org.onap.sdnc.northbound.exceptions.NearRtRicNotFoundException; -import org.onap.sdnc.northbound.restadpter.NearRicUrlProvider; -import org.onap.sdnc.northbound.restadpter.RestAdapter; -import org.onap.sdnc.northbound.restadpter.RestAdapterImpl; +import org.onap.sdnc.northbound.restadapter.NearRicUrlProvider; +import org.onap.sdnc.northbound.restadapter.RestAdapter; +import org.onap.sdnc.northbound.restadapter.RestAdapterImpl; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.A1ADAPTERAPIService; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyInstanceInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyInstanceOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyInstanceOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyTypeInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyTypeOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyTypeOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyInstanceInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyInstanceOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyInstanceOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyTypeInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyTypeOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyTypeOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetHealthCheckInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetHealthCheckOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetHealthCheckOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetNearRTRICsInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetNearRTRICsOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetNearRTRICsOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstanceInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstanceOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstanceOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstancesInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstancesOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstancesOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypeInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypeOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypeOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypesInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypesOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypesOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetStatusInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetStatusOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetStatusOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.A1ADAPTERAPIService; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.DeletePolicyInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.DeletePolicyOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.DeletePolicyOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyIdentitiesInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyIdentitiesOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyIdentitiesOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeIdentitiesInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeIdentitiesOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeIdentitiesOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.PutPolicyInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.PutPolicyOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.PutPolicyOutputBuilder; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestClientResponseException; /** * Defines a base implementation for your provider. This class overrides the generated interface @@ -200,189 +176,35 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { } @Override - public ListenableFuture> createPolicyInstance( - CreatePolicyInstanceInput input) { - log.info("Start of createPolicyInstance"); - CreatePolicyInstanceOutputBuilder responseBuilder = new CreatePolicyInstanceOutputBuilder(); - try { - String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId())); - log.info("PUT Request input.getPolicyInstance() : {} ", input.getPolicyInstance()); - ResponseEntity response = restAdapter.put(uri, input.getPolicyInstance()); - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); - } - log.info("End of createPolicyInstance"); - RpcResult rpcResult = RpcResultBuilder - .status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture> createPolicyType( - CreatePolicyTypeInput input) { - log.info("Start of createPolicyType"); - CreatePolicyTypeOutputBuilder responseBuilder = new CreatePolicyTypeOutputBuilder(); - try { - String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId())); - log.info("PUT Request input.getPolicyType() : {} ", input.getPolicyType()); - ResponseEntity response = restAdapter.put(uri, input.getPolicyType()); - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); - } - log.info("End of createPolicyType"); - RpcResult rpcResult = RpcResultBuilder - .status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture> deletePolicyInstance( - DeletePolicyInstanceInput input) { - log.info("Start of deletePolicyInstance"); - DeletePolicyInstanceOutputBuilder responseBuilder = new DeletePolicyInstanceOutputBuilder(); - try { - String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId())); - ResponseEntity response = restAdapter.delete(uri); - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); - } - log.info("End of deletePolicyInstance"); - RpcResult rpcResult = RpcResultBuilder - .status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture> deletePolicyType( - DeletePolicyTypeInput input) { - log.info("Start of deletePolicyType"); - DeletePolicyTypeOutputBuilder responseBuilder = new DeletePolicyTypeOutputBuilder(); - try { - String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId())); - ResponseEntity response = restAdapter.delete(uri); - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); - } - log.info("End of deletePolicyType"); - RpcResult rpcResult = RpcResultBuilder - .status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture> getHealthCheck( - GetHealthCheckInput input) { - log.info("Start of getHealthCheck"); - GetHealthCheckOutputBuilder responseBuilder = new GetHealthCheckOutputBuilder(); - try { - String uri = nearRicUrlProvider.getHealthCheck(String.valueOf(input.getNearRtRicId())); - ResponseEntity response = restAdapter.get(uri, Object.class); - responseBuilder.setHealthStatus(false); - if (response.getStatusCode().equals(HttpStatus.OK)) { - responseBuilder.setHealthStatus(true); - } - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); + public ListenableFuture> getPolicyTypeIdentities( + GetPolicyTypeIdentitiesInput input) { + log.info("Start of getPolicyTypeIdentities"); + GetPolicyTypeIdentitiesOutputBuilder responseBuilder = new GetPolicyTypeIdentitiesOutputBuilder(); + String uri = nearRicUrlProvider.getPolicyTypeIdentitiesUrl(String.valueOf(input.getNearRtRicUrl())); + ResponseEntity> response = restAdapter.get(uri, List.class); + if (response.hasBody()) { + log.info("Response getPolicyTypeIdentities : {} ", response.getBody()); + responseBuilder.setPolicyTypeIdList(response.getBody()); } - log.info("End of getHealthCheck"); - RpcResult rpcResult = RpcResultBuilder.status(true) + log.info("End of getPolicyTypeIdentities"); + RpcResult rpcResult = RpcResultBuilder.status(true) .withResult(responseBuilder.build()).build(); return Futures.immediateFuture(rpcResult); } @Override - public ListenableFuture> getNearRTRICs(GetNearRTRICsInput input) { - log.info("Start of getNearRTRICs"); - GetNearRTRICsOutputBuilder responseBuilder = new GetNearRTRICsOutputBuilder(); - responseBuilder.setNearRtRicIdList(nearRicUrlProvider.getNearRTRicIdsList()); - responseBuilder.setCode(HttpStatus.OK.toString()); - log.info("End of getNearRTRICs"); - RpcResult rpcResult = RpcResultBuilder.status(true) - .withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture> getPolicyInstance( - GetPolicyInstanceInput input) { - log.info("Start of getPolicyInstance"); - log.info("Policy Type Id : {}, Policy Instance Id : {}", input.getPolicyTypeId(), input.getPolicyInstanceId()); - GetPolicyInstanceOutputBuilder responseBuilder = new GetPolicyInstanceOutputBuilder(); - try { - String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId())); - ResponseEntity response = restAdapter.get(uri, String.class); - if (response.hasBody()) { - log.info("Response getPolicyInstance : {} ", response.getBody()); - responseBuilder.setPolicyInstance(response.getBody()); - } - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); - } - log.info("End of getPolicyInstance"); - RpcResult rpcResult = RpcResultBuilder - .status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture> getPolicyInstances( - GetPolicyInstancesInput input) { - log.info("Start of getPolicyInstances"); - GetPolicyInstancesOutputBuilder responseBuilder = new GetPolicyInstancesOutputBuilder(); - try { - String uri = nearRicUrlProvider.getPolicyInstances(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId())); - ResponseEntity> response = restAdapter.get(uri, List.class); - if (response.hasBody()) { - log.info("Response getPolicyInstances : {} ", response.getBody()); - responseBuilder.setPolicyInstanceIdList(response.getBody()); - } - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); + public ListenableFuture> getPolicyIdentities(GetPolicyIdentitiesInput input) { + log.info("Start of getPolicyIdentities"); + GetPolicyIdentitiesOutputBuilder responseBuilder = new GetPolicyIdentitiesOutputBuilder(); + String uri = nearRicUrlProvider.getPolicyIdentitiesUrl(String.valueOf(input.getNearRtRicUrl())); + ResponseEntity> response = restAdapter.get(uri, List.class); + if (response.hasBody()) { + log.info("Response getPolicyIdentities : {} ", response.getBody()); + responseBuilder.setPolicyIdList(response.getBody()); } - log.info("End of getPolicyInstances"); - RpcResult rpcResult = RpcResultBuilder - .status(true).withResult(responseBuilder.build()).build(); + log.info("End of getPolicyIdentities"); + RpcResult rpcResult = RpcResultBuilder + .status(true).withResult(responseBuilder.build()).build(); return Futures.immediateFuture(rpcResult); } @@ -391,24 +213,12 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { log.info("Start of getPolicyType"); log.info("Policy Type Id : {} ", input.getPolicyTypeId()); GetPolicyTypeOutputBuilder responseBuilder = new GetPolicyTypeOutputBuilder(); - try { - String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId())); - ResponseEntity response = restAdapter.get(uri, String.class); - if (response.hasBody()) { - log.info("Response getPolicyType : {} ", response.getBody()); - JSONObject policyTypeObj = new JSONObject(response.getBody()); - responseBuilder.setDescription(policyTypeObj.getString("description")); - responseBuilder.setName(policyTypeObj.getString("name")); - responseBuilder.setPolicyType(policyTypeObj.getJSONObject("create_schema").toString()); - } - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); + String uri = nearRicUrlProvider.getPolicyTypeUrl(String.valueOf(input.getNearRtRicUrl()), + String.valueOf(input.getPolicyTypeId())); + ResponseEntity response = restAdapter.get(uri, String.class); + if (response.hasBody()) { + log.info("Response getPolicyType : {} ", response.getBody()); + responseBuilder.setPolicyType(response.getBody()); } log.info("End of getPolicyType"); RpcResult rpcResult = RpcResultBuilder.status(true) @@ -417,61 +227,33 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { } @Override - public ListenableFuture> getPolicyTypes( - GetPolicyTypesInput input) { - log.info("Start of getPolicyTypes"); - GetPolicyTypesOutputBuilder responseBuilder = new GetPolicyTypesOutputBuilder(); - try { - String uri = nearRicUrlProvider.getPolicyTypes(String.valueOf(input.getNearRtRicId())); - ResponseEntity> response = restAdapter.get(uri, List.class); - if (response.hasBody()) { - log.info("Response getPolicyTypes : {} ", response.getBody()); - List policyTypesListInteger = response.getBody(); - List policyTypesListLong = new ArrayList<>(); - for(Integer i : policyTypesListInteger){ - policyTypesListLong.add(i.longValue()); - } - responseBuilder.setPolicyTypeIdList(policyTypesListLong); - } - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); + public ListenableFuture> putPolicy(PutPolicyInput input) { + log.info("Start of putPolicy"); + PutPolicyOutputBuilder responseBuilder = new PutPolicyOutputBuilder(); + String uri = nearRicUrlProvider.getPolicyUrl(String.valueOf(input.getNearRtRicUrl()), + String.valueOf(input.getPolicyId())); + log.info("PUT Request input.getPolicy() : {} ", input.getPolicy()); + ResponseEntity response = restAdapter.put(uri, input.getPolicy()); + if (response.hasBody()) { + log.info("Response putPolicy : {} ", response.getBody()); + responseBuilder.setReturnedPolicy(response.getBody()); } - log.info("End of getPolicyTypes"); - RpcResult rpcResult = RpcResultBuilder.status(true) - .withResult(responseBuilder.build()).build(); + log.info("End of putPolicy"); + RpcResult rpcResult = RpcResultBuilder + .status(true).withResult(responseBuilder.build()).build(); return Futures.immediateFuture(rpcResult); } @Override - public ListenableFuture> getStatus(GetStatusInput input) { - log.info("Start of getStatus"); - GetStatusOutputBuilder responseBuilder = new GetStatusOutputBuilder(); - try { - String uri = nearRicUrlProvider.getPolicyInstanceIdStatus(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId())); - ResponseEntity> response = restAdapter.get(uri, List.class); - if (response.hasBody()) { - log.info("Response getStatus : {} ", response.getBody()); - // only return the status of first handler for compliance with current yang model, ignore handler_id - JSONObject statusObj = new JSONObject(new Gson().toJson(response.getBody().get(0))); - responseBuilder.setStatus(statusObj.getString("status")); - } - responseBuilder.setCode(response.getStatusCode().toString()); - } catch (NearRtRicNotFoundException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(HttpStatus.INTERNAL_SERVER_ERROR.toString()); - } catch (RestClientResponseException ex) { - log.error("Caught exception: {}", ex); - responseBuilder.setCode(String.valueOf(ex.getRawStatusCode())); - } - log.info("End of getStatus"); - RpcResult rpcResult = - RpcResultBuilder.status(true).withResult(responseBuilder.build()).build(); + public ListenableFuture> deletePolicy(DeletePolicyInput input) { + log.info("Start of deletePolicy"); + DeletePolicyOutputBuilder responseBuilder = new DeletePolicyOutputBuilder(); + String uri = nearRicUrlProvider.getPolicyUrl(String.valueOf(input.getNearRtRicUrl()), + String.valueOf(input.getPolicyId())); + ResponseEntity response = restAdapter.delete(uri); + log.info("End of deletePolicy"); + RpcResult rpcResult = RpcResultBuilder + .status(true).withResult(responseBuilder.build()).build(); return Futures.immediateFuture(rpcResult); } } diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadapter/NearRicUrlProvider.java b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadapter/NearRicUrlProvider.java new file mode 100644 index 00000000..46d489bb --- /dev/null +++ b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadapter/NearRicUrlProvider.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.sdnc.northbound.restadapter; + +import org.springframework.web.util.UriComponentsBuilder; + +/** + * This class provides Near-RIC api to invoke the A1 interface + * + * @author lathishbabu.ganesan@est.tech + * + */ + +public class NearRicUrlProvider { + + public NearRicUrlProvider() { + } + + /** + * Retrieve the base url of the Near-RIC + * + * @return the base url + */ + public String getBaseUrl(final String nearRtRicUrl) { + String baseUrl = nearRtRicUrl + "/A1-P/v1"; + return UriComponentsBuilder.fromUriString(baseUrl).build().toString(); + } + + /** + * Retrieve the policy type ids url + * + * @return the policytype ids url + */ + public String getPolicyTypeIdentitiesUrl(final String nearRtRicUrl) { + return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policytypes") + .pathSegment("identities").build().toString(); + } + + /** + * Retrieve the url of the policy instances + * + * @param policyTypeId Policy Type Id + * @return the policy ids url + */ + public String getPolicyIdentitiesUrl(final String nearRtRicUrl) { + return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policies") + .pathSegment("identities").build().toString(); + } + + /** + * Retrieve the url of policy type + * + * @param policyTypeId Policy Type Id + * @return the policy type url + */ + public String getPolicyTypeUrl(final String nearRtRicUrl, final String policyTypeId) { + return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policytypes") + .pathSegment(policyTypeId).build().toString(); + } + + /** + * Retrieve the url of the policy instance id + * + * @param policyId Policy Id + * @return the policy id url + */ + public String getPolicyUrl(final String nearRtRicUrl, final String policyId) { + return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policies") + .pathSegment(policyId).build().toString(); + } +} diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/RestAdapter.java b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadapter/RestAdapter.java similarity index 97% rename from sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/RestAdapter.java rename to sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadapter/RestAdapter.java index 8f13f22d..c93caf2f 100644 --- a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/RestAdapter.java +++ b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadapter/RestAdapter.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.sdnc.northbound.restadpter; +package org.onap.sdnc.northbound.restadapter; import org.springframework.http.ResponseEntity; diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/RestAdapterImpl.java b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadapter/RestAdapterImpl.java similarity index 98% rename from sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/RestAdapterImpl.java rename to sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadapter/RestAdapterImpl.java index c2c9522a..7e7c88f1 100644 --- a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/RestAdapterImpl.java +++ b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadapter/RestAdapterImpl.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.sdnc.northbound.restadpter; +package org.onap.sdnc.northbound.restadapter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/NearRicUrlProvider.java b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/NearRicUrlProvider.java deleted file mode 100644 index 8c2d6923..00000000 --- a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/onap/sdnc/northbound/restadpter/NearRicUrlProvider.java +++ /dev/null @@ -1,164 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.sdnc.northbound.restadpter; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; -import org.onap.sdnc.northbound.exceptions.NearRtRicNotFoundException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.util.UriComponentsBuilder; - -/** - * This class provides Near-RIC api to invoke the A1 interface - * - * @author lathishbabu.ganesan@est.tech - * - */ - -public class NearRicUrlProvider { - - // nearRicMap provides mapping from nearRtRicId to domainname:port of nearRTRics - private HashMap nearRicMap = new HashMap<>(); - private static final String NEAR_RIC_LIST_FILE = "NearRtRicList.properties"; - private final Logger log = LoggerFactory.getLogger(NearRicUrlProvider.class); - - public NearRicUrlProvider() { - try { - readNearRtRicConfigFile(); - } catch (IOException ex) { - log.error("Exception while reading nearRtRicConfigFile: {}", ex); - } - } - - private void readNearRtRicConfigFile() throws IOException { - InputStream inputStream = NearRicUrlProvider.class.getClassLoader().getResourceAsStream(NEAR_RIC_LIST_FILE); - if (inputStream == null) { - log.error("The file {} not found in classpath", NEAR_RIC_LIST_FILE); - } else { - Properties properties = new Properties(); - properties.load(inputStream); - Enumeration keys = properties.propertyNames(); - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - nearRicMap.put(key, properties.getProperty(key)); - } - inputStream.close(); - } - } - - /** - * Retrieve the list of Near-RICs - * - * @return the list of Near-RICs - */ - public List getNearRTRicIdsList () { - return new ArrayList<>(nearRicMap.keySet()); - } - - /** - * Retrieve the base url of the Near-RIC - * - * @return the base url - */ - public String getBaseUrl(final String nearRtRicId) { - if (!nearRicMap.containsKey(nearRtRicId)) { - throw new NearRtRicNotFoundException("NearRtRic with this ID is not known by the A1 controller"); - } - String baseUrl = "http://" + nearRicMap.get(nearRtRicId) + "/a1-p/"; - return UriComponentsBuilder.fromUriString(baseUrl).build().toString(); - } - - /** - * Retrieve the url of A1 healthcheck - * - * @return the health check url - */ - public String getHealthCheck(final String nearRtRicId) { - return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("healthcheck").build() - .toString(); - } - - /** - * Retrieve the policy type url - * - * @return the base url with the policytypes - */ - public String getPolicyTypes(final String nearRtRicId) { - return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes/").build() - .toString(); - } - - /** - * Retrieve the url of policy type id - * - * @param policyTypeId Policy Type Id - * @return the policy type id url - */ - public String getPolicyTypeId(final String nearRtRicId, - final String policyTypeId) { - return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes") - .pathSegment(policyTypeId).build().toString(); - } - - /** - * Retrieve the url of the policy instances - * - * @param policyTypeId Policy Type Id - * @return the policy instances for the given policy type - */ - public String getPolicyInstances(final String nearRtRicId, - final String policyTypeId) { - return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies") - .build().toString(); - } - - /** - * Retrieve the url of the policy instance id - * - * @param policyTypeId Policy Type Id - * @param policyInstanceId Policy Instance Id - * @return the policy instance id for the given policy type - */ - public String getPolicyInstanceId(final String nearRtRicId, final String policyTypeId, - final String policyInstanceId) { - return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies") - .pathSegment(policyInstanceId).build().toString(); - } - - /** - * Retrieve the url of the policy instance id status - * - * @param policyTypeId Policy Type Id - * @param policyInstanceId Policy Instance Id - * @return the policy instance id status for the given policy type - */ - public String getPolicyInstanceIdStatus(final String nearRtRicId, final String policyTypeId, - final String policyInstanceId) { - return UriComponentsBuilder.fromUriString(getPolicyInstanceId(nearRtRicId, policyTypeId, policyInstanceId)) - .pathSegment("status").build().toString(); - } -} diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/test/java/org/onap/sdnc/northbound/NonrtRicApiProviderTest.java b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/test/java/org/onap/sdnc/northbound/NonrtRicApiProviderTest.java index e9b86be4..1caa6f64 100644 --- a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/test/java/org/onap/sdnc/northbound/NonrtRicApiProviderTest.java +++ b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/test/java/org/onap/sdnc/northbound/NonrtRicApiProviderTest.java @@ -20,11 +20,9 @@ package org.onap.sdnc.northbound; -import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; import com.google.common.util.concurrent.ListenableFuture; -import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; @@ -36,34 +34,20 @@ import org.mockito.Mock; import org.mockito.internal.util.reflection.Whitebox; import org.mockito.runners.MockitoJUnitRunner; import org.onap.sdnc.northbound.provider.NonrtRicApiProvider; -import org.onap.sdnc.northbound.restadpter.NearRicUrlProvider; -import org.onap.sdnc.northbound.restadpter.RestAdapter; +import org.onap.sdnc.northbound.restadapter.NearRicUrlProvider; +import org.onap.sdnc.northbound.restadapter.RestAdapter; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyInstanceInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyInstanceOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyTypeInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.CreatePolicyTypeOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyInstanceInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyInstanceOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyTypeInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.DeletePolicyTypeOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetHealthCheckInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetHealthCheckOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetNearRTRICsInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetNearRTRICsOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstanceInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstanceOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstancesInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyInstancesOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypeInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypeOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypesInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetPolicyTypesOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetStatusInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev191002.GetStatusOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyIdentitiesInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyIdentitiesOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeIdentitiesInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeIdentitiesOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetPolicyTypeOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.PutPolicyInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.PutPolicyOutput; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,9 +74,9 @@ public class NonrtRicApiProviderTest extends AbstractConcurrentDataBrokerTest { @Mock private RestAdapter restAdapter; private NearRicUrlProvider nearRicUrlProvider; - private static String nearRtRicId = "NearRtRic1"; - private static Long policyTypeId = 11L; - private static String policyTypeInstanceId = "12"; + private static String nearRtRicUrl = "http://ric1:8085"; + private static String policyTypeId = "STD_QoSNudging_0.1.0"; + private static String policyId = "3d2157af-6a8f-4a7c-810f-38c2f824bf12"; @Before @@ -104,178 +88,65 @@ public class NonrtRicApiProviderTest extends AbstractConcurrentDataBrokerTest { } @Test - public void testCreatePolicyInstance() throws InterruptedException, ExecutionException { - CreatePolicyInstanceInputBuilder inputBuilder = new CreatePolicyInstanceInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); - inputBuilder.setPolicyTypeId(policyTypeId); - inputBuilder.setPolicyInstanceId(policyTypeInstanceId); - Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getPolicyInstanceId(inputBuilder.build().getNearRtRicId(), - String.valueOf(inputBuilder.build().getPolicyTypeId()), inputBuilder.getPolicyInstanceId()); - ResponseEntity createPolicyInstanceResponse = new ResponseEntity<>(HttpStatus.CREATED); - when(restAdapter.put(eq(uri), anyObject())).thenReturn(createPolicyInstanceResponse); - ListenableFuture> result = - nonrtRicApiProvider.createPolicyInstance(inputBuilder.build()); - Assert.assertEquals(String.valueOf(HttpStatus.CREATED.value()), result.get().getResult().getCode()); - } - - @Test - public void testDeletePolicyInstance() throws InterruptedException, ExecutionException { - DeletePolicyInstanceInputBuilder inputBuilder = new DeletePolicyInstanceInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); - inputBuilder.setPolicyTypeId(policyTypeId); - inputBuilder.setPolicyInstanceId(policyTypeInstanceId); - Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getPolicyInstanceId(inputBuilder.build().getNearRtRicId(), - String.valueOf(inputBuilder.build().getPolicyTypeId()), inputBuilder.getPolicyInstanceId()); - ResponseEntity deletePolicyInstanceResponse = new ResponseEntity<>(HttpStatus.NO_CONTENT); - when(restAdapter.delete(eq(uri))).thenReturn(deletePolicyInstanceResponse); - ListenableFuture> result = - nonrtRicApiProvider.deletePolicyInstance(inputBuilder.build()); - Assert.assertEquals(String.valueOf(HttpStatus.NO_CONTENT.value()), result.get().getResult().getCode()); - } - - @Test - public void testGetNearRTRICs() throws InterruptedException, ExecutionException { - GetNearRTRICsInputBuilder inputBuilder = new GetNearRTRICsInputBuilder(); - ListenableFuture> result = - nonrtRicApiProvider.getNearRTRICs(inputBuilder.build()); - Assert.assertEquals(String.valueOf(HttpStatus.OK.value()), result.get().getResult().getCode()); - } - - @Test - public void testCreatePolicyType() throws InterruptedException, ExecutionException { - CreatePolicyTypeInputBuilder inputBuilder = new CreatePolicyTypeInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); - inputBuilder.setPolicyTypeId(policyTypeId); + public void testGetPolicyTypeIdentities() throws InterruptedException, ExecutionException { + GetPolicyTypeIdentitiesInputBuilder inputBuilder = new GetPolicyTypeIdentitiesInputBuilder(); + inputBuilder.setNearRtRicUrl(nearRtRicUrl); Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getPolicyTypeId(inputBuilder.build().getNearRtRicId(), - String.valueOf(inputBuilder.build().getPolicyTypeId())); - ResponseEntity createPolicyTypeResponse = new ResponseEntity<>(HttpStatus.CREATED); - when(restAdapter.put(eq(uri), anyObject())).thenReturn(createPolicyTypeResponse); - ListenableFuture> result = - nonrtRicApiProvider.createPolicyType(inputBuilder.build()); - Assert.assertEquals(String.valueOf(HttpStatus.CREATED.value()), result.get().getResult().getCode()); + String uri = nearRicUrlProvider.getPolicyTypeIdentitiesUrl(inputBuilder.build().getNearRtRicUrl()); + List policyTypeIdentities = new ArrayList<>(); + policyTypeIdentities.add(policyTypeId); + ResponseEntity getPolicyTypeIdentitiesResponse = new ResponseEntity<>(policyTypeIdentities, HttpStatus.OK); + when(restAdapter.get(eq(uri), eq(List.class))).thenReturn(getPolicyTypeIdentitiesResponse); + ListenableFuture> result = + nonrtRicApiProvider.getPolicyTypeIdentities(inputBuilder.build()); + Assert.assertEquals(policyTypeIdentities, result.get().getResult().getPolicyTypeIdList()); } @Test - public void testDeletePolicyType() throws InterruptedException, ExecutionException { - DeletePolicyTypeInputBuilder inputBuilder = new DeletePolicyTypeInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); - inputBuilder.setPolicyTypeId(policyTypeId); + public void testGetPolicyIdentities() throws InterruptedException, ExecutionException { + GetPolicyIdentitiesInputBuilder inputBuilder = new GetPolicyIdentitiesInputBuilder(); + inputBuilder.setNearRtRicUrl(nearRtRicUrl); Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getPolicyTypeId(inputBuilder.build().getNearRtRicId(), - String.valueOf(inputBuilder.build().getPolicyTypeId())); - ResponseEntity deletePolicyTypeResponse = new ResponseEntity<>(HttpStatus.NO_CONTENT); - when(restAdapter.delete(eq(uri))).thenReturn(deletePolicyTypeResponse); - ListenableFuture> result = - nonrtRicApiProvider.deletePolicyType(inputBuilder.build()); - Assert.assertEquals(String.valueOf(HttpStatus.NO_CONTENT.value()), result.get().getResult().getCode()); + String uri = nearRicUrlProvider.getPolicyIdentitiesUrl(inputBuilder.build().getNearRtRicUrl()); + List policyIdentities = new ArrayList<>(); + policyIdentities.add(policyId); + ResponseEntity getPolicyIdentitiesResponse = new ResponseEntity<>(policyIdentities, HttpStatus.OK); + when(restAdapter.get(eq(uri), eq(List.class))).thenReturn(getPolicyIdentitiesResponse); + ListenableFuture> result = + nonrtRicApiProvider.getPolicyIdentities(inputBuilder.build()); + Assert.assertEquals(policyIdentities, result.get().getResult().getPolicyIdList()); } @Test public void testGetPolicyType() throws InterruptedException, ExecutionException { GetPolicyTypeInputBuilder inputBuilder = new GetPolicyTypeInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); + inputBuilder.setNearRtRicUrl(nearRtRicUrl); inputBuilder.setPolicyTypeId(policyTypeId); Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getPolicyTypeId(inputBuilder.build().getNearRtRicId(), + String uri = nearRicUrlProvider.getPolicyTypeUrl(inputBuilder.build().getNearRtRicUrl(), String.valueOf(inputBuilder.build().getPolicyTypeId())); - String policyType = - "{\"name\":\"Policy type 1\",\"description\":\"PT 1\",\"policy_type_id\":1,\"create_schema\":{}}"; - ResponseEntity getPolicyTypeResponse = new ResponseEntity<>(policyType, HttpStatus.OK); + String testPolicyType = "{}"; + ResponseEntity getPolicyTypeResponse = new ResponseEntity<>(testPolicyType, HttpStatus.OK); when(restAdapter.get(eq(uri), eq(String.class))).thenReturn(getPolicyTypeResponse); ListenableFuture> result = nonrtRicApiProvider.getPolicyType(inputBuilder.build()); - Assert.assertEquals("Policy type 1", result.get().getResult().getName()); - Assert.assertEquals(String.valueOf(HttpStatus.OK.value()), result.get().getResult().getCode()); - } - - @Test - public void testGetPolicyTypes() throws InterruptedException, ExecutionException { - GetPolicyTypesInputBuilder inputBuilder = new GetPolicyTypesInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); - Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getPolicyTypes(inputBuilder.build().getNearRtRicId()); - List policyTypesInteger = new ArrayList<>(); - policyTypesInteger.add(20001); - List policyTypesLong = new ArrayList<>(); - policyTypesLong.add(20001L); - ResponseEntity getPolicyTypesResponse = new ResponseEntity<>(policyTypesInteger, HttpStatus.OK); - when(restAdapter.get(eq(uri), eq(List.class))).thenReturn(getPolicyTypesResponse); - ListenableFuture> result = - nonrtRicApiProvider.getPolicyTypes(inputBuilder.build()); - Assert.assertEquals(policyTypesLong, result.get().getResult().getPolicyTypeIdList()); - Assert.assertEquals(String.valueOf(HttpStatus.OK.value()), result.get().getResult().getCode()); - } - - @Test - public void testGetPolicyInstance() throws InterruptedException, ExecutionException { - GetPolicyInstanceInputBuilder inputBuilder = new GetPolicyInstanceInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); - inputBuilder.setPolicyTypeId(policyTypeId); - inputBuilder.setPolicyInstanceId(policyTypeInstanceId); - Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getPolicyInstanceId(inputBuilder.build().getNearRtRicId(), - String.valueOf(inputBuilder.build().getPolicyTypeId()), inputBuilder.getPolicyInstanceId()); - String policyInstance = - "{\"scope\":{\"ue_id\":\"2\"},\"statement\":{\"priority_level\":\"1\"},\"policy_id\":\"pi12\"}"; - ResponseEntity getPolicyInstanceResponse = new ResponseEntity<>(policyInstance, HttpStatus.OK); - when(restAdapter.get(eq(uri), eq(String.class))).thenReturn(getPolicyInstanceResponse); - ListenableFuture> result = - nonrtRicApiProvider.getPolicyInstance(inputBuilder.build()); - Assert.assertEquals(policyInstance, result.get().getResult().getPolicyInstance()); - Assert.assertEquals(String.valueOf(HttpStatus.OK.value()), result.get().getResult().getCode()); - } - - @Test - public void testGetPolicyInstances() throws InterruptedException, ExecutionException { - GetPolicyInstancesInputBuilder inputBuilder = new GetPolicyInstancesInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); - inputBuilder.setPolicyTypeId(policyTypeId); - Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getPolicyInstances(inputBuilder.build().getNearRtRicId(), - String.valueOf(inputBuilder.build().getPolicyTypeId())); - List policyInstances = new ArrayList<>(); - policyInstances.add("3d2157af-6a8f-4a7c-810f-38c2f824bf12"); - ResponseEntity getPolicyInstancesResponse = new ResponseEntity<>(policyInstances, HttpStatus.OK); - when(restAdapter.get(eq(uri), eq(List.class))).thenReturn(getPolicyInstancesResponse); - ListenableFuture> result = - nonrtRicApiProvider.getPolicyInstances(inputBuilder.build()); - Assert.assertEquals(policyInstances, result.get().getResult().getPolicyInstanceIdList()); - Assert.assertEquals(String.valueOf(HttpStatus.OK.value()), result.get().getResult().getCode()); - } - - @Test - public void testGetStatus() throws InterruptedException, ExecutionException { - GetStatusInputBuilder inputBuilder = new GetStatusInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); - inputBuilder.setPolicyTypeId(policyTypeId); - inputBuilder.setPolicyInstanceId(policyTypeInstanceId); - Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getPolicyInstanceIdStatus(inputBuilder.build().getNearRtRicId(), - String.valueOf(inputBuilder.build().getPolicyTypeId()), inputBuilder.getPolicyInstanceId()); - String policyInstanceStatus = "[{\"handler_id\":\"NearRTRIC-1\",\"status\":\"enforced\"}]"; - ResponseEntity getStatusResponse = - new ResponseEntity<>(new Gson().fromJson(policyInstanceStatus, List.class), HttpStatus.OK); - when(restAdapter.get(eq(uri), eq(List.class))).thenReturn(getStatusResponse); - ListenableFuture> result = - nonrtRicApiProvider.getStatus(inputBuilder.build()); - Assert.assertEquals("enforced", result.get().getResult().getStatus()); - Assert.assertEquals(String.valueOf(HttpStatus.OK.value()), result.get().getResult().getCode()); + Assert.assertEquals(testPolicyType, result.get().getResult().getPolicyType()); } @Test - public void testGetHealthCheck() throws InterruptedException, ExecutionException { - GetHealthCheckInputBuilder inputBuilder = new GetHealthCheckInputBuilder(); - inputBuilder.setNearRtRicId(nearRtRicId); + public void testPutPolicy() throws InterruptedException, ExecutionException { + PutPolicyInputBuilder inputBuilder = new PutPolicyInputBuilder(); + String testPolicy = "{}"; + inputBuilder.setNearRtRicUrl(nearRtRicUrl); + inputBuilder.setPolicyId(policyId); + inputBuilder.setPolicy(testPolicy); Whitebox.setInternalState(nonrtRicApiProvider, "restAdapter", restAdapter); - String uri = nearRicUrlProvider.getHealthCheck(inputBuilder.build().getNearRtRicId()); - ResponseEntity getHealthCheckResponse = new ResponseEntity<>(HttpStatus.OK); - when(restAdapter.get(eq(uri), eq(Object.class))).thenReturn(getHealthCheckResponse); - ListenableFuture> result = - nonrtRicApiProvider.getHealthCheck(inputBuilder.build()); - Assert.assertEquals(true, result.get().getResult().isHealthStatus()); - Assert.assertEquals(String.valueOf(HttpStatus.OK.value()), result.get().getResult().getCode()); + String uri = nearRicUrlProvider.getPolicyUrl(inputBuilder.build().getNearRtRicUrl(), + inputBuilder.getPolicyId()); + ResponseEntity putPolicyResponse = new ResponseEntity<>(testPolicy, HttpStatus.CREATED); + when(restAdapter.put(eq(uri), eq(testPolicy))).thenReturn(putPolicyResponse); + ListenableFuture> result = + nonrtRicApiProvider.putPolicy(inputBuilder.build()); + Assert.assertEquals(testPolicy, result.get().getResult().getReturnedPolicy()); } }