X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=sdnc-a1-controller%2Fnorthbound%2Fnonrt-ric-api%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fsdnc%2Fnorthbound%2Fprovider%2FNonrtRicApiProvider.java;h=12704df6a85ac858dc3f0adbb7b9e212657d52b7;hb=f217fffad3db72759708ea68892357b46b8ed4a0;hp=7f29fd17939082c8e07b2b1c7579d9eb03bcd4cf;hpb=799dafa576935e93c262a20f2b055a94dd637ddd;p=nonrtric.git 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 7f29fd17..12704df6 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 @@ -20,72 +20,49 @@ package org.onap.sdnc.northbound.provider; -import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -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.restadpter.NearRicUrlProvider; -import org.onap.sdnc.northbound.restadpter.RestAdapter; -import org.onap.sdnc.northbound.restadpter.RestAdapterImpl; +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.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.DeleteA1PolicyInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.DeleteA1PolicyOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.DeleteA1PolicyOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyInputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyStatusInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyStatusOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyStatusOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyTypeInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyTypeOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.PutA1PolicyInput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.PutA1PolicyOutput; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.a1.adapter.rev200122.PutA1PolicyOutputBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; 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.ResponseEntity; /** - * Defines a base implementation for your provider. This class overrides the generated interface - * from the YANG model and implements the request model for the A1 interface. This class identifies - * the Near-RIC throught the IP passed over the payload and calls the corresponding Near-RIC over - * Rest API + * Defines a base implementation for your provider. This class overrides the + * generated interface from the YANG model and implements the request model for + * the A1 interface. This class identifies the Near-RT RIC throught the IP passed + * over the payload and calls the corresponding Near-RT RIC over Rest API * *
* @@ -93,14 +70,13 @@ import org.slf4j.LoggerFactory; * */ +@SuppressWarnings("squid:S1874") // "@Deprecated" code should not be used public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { protected static final String APP_NAME = "nonrt-ric-api"; protected static final String NO_SERVICE_LOGIC_ACTIVE = "No service logic active for "; private static final String NON_NULL_PARAM = "non-null"; private static final String NULL_PARAM = "null"; - private static final String RESPONSE_SUCCESS = "Success"; - private static final String RESPONSE_CODE_SUCCESS = "200"; private final Logger log = LoggerFactory.getLogger(NonrtRicApiProvider.class); private final ExecutorService executor; @@ -110,10 +86,8 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { protected RpcProviderRegistry rpcRegistry; protected BindingAwareBroker.RpcRegistration> rpcRegistration; private RestAdapter restAdapter; - private NearRicUrlProvider nearRicUrlProvider; - public NonrtRicApiProvider(DataBroker dataBroker, - NotificationPublishService notificationPublishService, + public NonrtRicApiProvider(DataBroker dataBroker, NotificationPublishService notificationPublishService, RpcProviderRegistry rpcProviderRegistry) { log.info("Creating provider for {}", APP_NAME); executor = Executors.newFixedThreadPool(1); @@ -128,7 +102,6 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { log.info("Initializing provider for {}", APP_NAME); createContainers(); restAdapter = new RestAdapterImpl(); - nearRicUrlProvider = new NearRicUrlProvider(); log.info("Initialization complete for {}", APP_NAME); } @@ -144,22 +117,6 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { log.info("Successfully closed provider for {}", APP_NAME); } - private static class Iso8601Util { - - private static TimeZone timeZone = TimeZone.getTimeZone("UTC"); - private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - - private Iso8601Util() {} - - static { - dateFormat.setTimeZone(timeZone); - } - - private static String now() { - return dateFormat.format(new Date()); - } - } - public void setDataBroker(DataBroker dataBroker) { this.dataBroker = dataBroker; if (log.isDebugEnabled()) { @@ -170,8 +127,7 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { public void setNotificationService(NotificationPublishService notificationService) { this.notificationService = notificationService; if (log.isDebugEnabled()) { - log.debug("Notification Service set to {}", - notificationService == null ? NULL_PARAM : NON_NULL_PARAM); + log.debug("Notification Service set to {}", notificationService == null ? NULL_PARAM : NON_NULL_PARAM); } } @@ -193,184 +149,96 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { } catch (InterruptedException | ExecutionException e) { log.error("Create containers failed: ", e); + Thread.currentThread().interrupt(); } } @Override - public ListenableFuture> createPolicyInstance( - CreatePolicyInstanceInput input) { - log.info("Start of createPolicyInstance"); - String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId())); - log.info("PUT Request input.getPolicyInstance() : {} ", input.getPolicyInstance()); - restAdapter.put(uri, input.getPolicyInstance()); - CreatePolicyInstanceOutputBuilder responseBuilder = new CreatePolicyInstanceOutputBuilder(); - log.info("End of createPolicyInstance"); - RpcResult rpcResult = RpcResultBuilder - . status(true).withResult(responseBuilder.build()).build(); + public ListenableFuture > putA1Policy(PutA1PolicyInput input) { + log.info("Start of putPolicy"); + final Uri uri = input.getNearRtRicUrl(); + + log.info("PUT Request input.GetA1Policy() : {} ", uri); + ResponseEntity response = restAdapter.put(uri.getValue(), input.getBody(), String.class); + PutA1PolicyOutputBuilder responseBuilder = new PutA1PolicyOutputBuilder(); + if (response.hasBody()) { + log.info("Response PutA1Policy : {} ", response.getBody()); + responseBuilder.setBody(response.getBody()); + } + responseBuilder.setHttpStatus(response.getStatusCodeValue()); + log.info("End of PutA1Policy"); + RpcResult rpcResult = RpcResultBuilder. status(true) + .withResult(responseBuilder.build()).build(); return Futures.immediateFuture(rpcResult); } @Override - public ListenableFuture > createPolicyType( - CreatePolicyTypeInput input) { - log.info("Start of createPolicyType"); - String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getNearRtRicId()), - String.valueOf(input.getPolicyTypeId())); - log.info("PUT Request input.getPolicyType() : {} ", input.getPolicyType()); - restAdapter.put(uri, input.getPolicyType()); - CreatePolicyTypeOutputBuilder responseBuilder = new CreatePolicyTypeOutputBuilder(); - responseBuilder.setCode(RESPONSE_CODE_SUCCESS); - responseBuilder.setStatus(RESPONSE_SUCCESS); - log.info("End of createPolicyType"); - RpcResult rpcResult = RpcResultBuilder - . status(true).withResult(responseBuilder.build()).build(); + public ListenableFuture > deleteA1Policy(DeleteA1PolicyInput input) { + log.info("Start of DeleteA1Policy"); + final Uri uri = input.getNearRtRicUrl(); + ResponseEntity