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=b5e3deed6560645211d9bf9ad42a0b4e7e354582;hpb=1eec0d44e5961b7ff17bf9169005e1de08fc2a74;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 b5e3deed..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 @@ -23,74 +23,46 @@ 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.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.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.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 - * 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 * *
* @@ -98,6 +70,7 @@ import org.springframework.web.client.RestClientResponseException; * */ +@SuppressWarnings("squid:S1874") // "@Deprecated" code should not be used public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { protected static final String APP_NAME = "nonrt-ric-api"; @@ -113,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); @@ -131,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); } @@ -147,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()) { @@ -173,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); } } @@ -196,282 +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"); - 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(); + 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"); - 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(); + public ListenableFuture > deleteA1Policy(DeleteA1PolicyInput input) { + log.info("Start of DeleteA1Policy"); + final Uri uri = input.getNearRtRicUrl(); + ResponseEntity