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=f67508f9cc4675809391705b3ba820dc8b1aeaf9;hb=28b508e5df22fd468d18769449710bd0764a778d;hp=206b096acc22d43d14211ae3faae39c03a555249;hpb=b6fe5a1bbad372357f6b441e1657dd8bbe48dc1a;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 206b096a..f67508f9 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,6 +20,9 @@ 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 java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -28,67 +31,45 @@ import java.util.TimeZone; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.apache.commons.lang3.StringUtils; -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.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.oransc.ric.a1med.client.model.PolicyTypeSchema; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -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 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 - * + * *
- * + * * @author lathishbabu.ganesan@est.tech * */ @@ -99,8 +80,6 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { 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; @@ -197,164 +176,84 @@ public class NonrtRicApiProvider implements AutoCloseable, A1ADAPTERAPIService { } @Override - public ListenableFuture> createPolicyInstance( - CreatePolicyInstanceInput input) { - log.debug("Start of createPolicyInstance"); - String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getPolicyTypeId()), - String.valueOf(input.getPolicyInstanceId())); - restAdapter.put(uri, input.getPolicyInstance()); - CreatePolicyInstanceOutputBuilder responseBuilder = new CreatePolicyInstanceOutputBuilder(); - log.debug("End of createPolicyInstance"); - RpcResult rpcResult = RpcResultBuilder - . status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture > createPolicyType( - CreatePolicyTypeInput input) { - log.debug("Start of createPolicyType"); - String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getPolicyTypeId())); - PolicyTypeSchema policyTypeSchema = new PolicyTypeSchema(); - restAdapter.put(uri, policyTypeSchema); - CreatePolicyTypeOutputBuilder responseBuilder = new CreatePolicyTypeOutputBuilder(); - responseBuilder.setCode(RESPONSE_CODE_SUCCESS); - responseBuilder.setStatus(RESPONSE_SUCCESS); - log.debug("End of createPolicyType"); - RpcResult rpcResult = RpcResultBuilder - . status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture > deletePolicyInstance( - DeletePolicyInstanceInput input) { - log.debug("Start of deletePolicyInstance"); - String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getPolicyTypeId()), - String.valueOf(input.getPolicyInstanceId())); - restAdapter.delete(uri); - DeletePolicyInstanceOutputBuilder responseBuilder = new DeletePolicyInstanceOutputBuilder(); - log.debug("End of deletePolicyInstance"); - RpcResult rpcResult = RpcResultBuilder - . status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture > deletePolicyType( - DeletePolicyTypeInput input) { - log.debug("Start of deletePolicyType"); - String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getPolicyTypeId())); - restAdapter.delete(uri); - DeletePolicyTypeOutputBuilder responseBuilder = new DeletePolicyTypeOutputBuilder(); - log.debug("End of deletePolicyType"); - RpcResult rpcResult = RpcResultBuilder - . status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture > getHealthCheck( - GetHealthCheckInput input) { - log.debug("Start of getHealthCheck"); - String uri = nearRicUrlProvider.getHealthCheck(); - Optional heathCheckStatus = restAdapter.get(uri, String.class); - GetHealthCheckOutputBuilder responseBuilder = new GetHealthCheckOutputBuilder(); - if (heathCheckStatus.get().equals("")) { - responseBuilder.setHealthStatus(true); + public ListenableFuture > getPolicyTypeIdentities( + GetPolicyTypeIdentitiesInput input) { + log.info("Start of getPolicyTypeIdentities"); + GetPolicyTypeIdentitiesOutputBuilder responseBuilder = new GetPolicyTypeIdentitiesOutputBuilder(); + String uri = nearRicUrlProvider.policyTypesUrl(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.debug("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) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ListenableFuture > getPolicyInstance( - GetPolicyInstanceInput input) { - log.debug("Start of getPolicyInstance"); - String uri = nearRicUrlProvider.getPolicyInstanceId(String.valueOf(input.getPolicyTypeId()), - String.valueOf(input.getPolicyInstanceId())); - Optional policyInstance = restAdapter.get(uri, String.class); - GetPolicyInstanceOutputBuilder responseBuilder = new GetPolicyInstanceOutputBuilder(); - responseBuilder - .setPolicyInstance(policyInstance.isPresent() ? policyInstance.get() : StringUtils.EMPTY); - log.debug("End of getPolicyInstance"); - RpcResult rpcResult = RpcResultBuilder - . status(true).withResult(responseBuilder.build()).build(); - return Futures.immediateFuture(rpcResult); - } - - @Override - public ListenableFuture > getPolicyInstances( - GetPolicyInstancesInput input) { - log.debug("Start of getPolicyInstances"); - String uri = nearRicUrlProvider.getPolicyInstances(String.valueOf(input.getPolicyTypeId())); - Optional > policyInstances = restAdapter.get(uri, List.class); - GetPolicyInstancesOutputBuilder responseBuilder = new GetPolicyInstancesOutputBuilder(); - if (policyInstances.isPresent()) { - responseBuilder.setPolicyInstanceIdList(policyInstances.get()); + public ListenableFuture
> getPolicyIdentities(GetPolicyIdentitiesInput input) { + log.info("Start of getPolicyIdentities"); + GetPolicyIdentitiesOutputBuilder responseBuilder = new GetPolicyIdentitiesOutputBuilder(); + String uri = nearRicUrlProvider.policiesUrl(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.debug("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); } @Override public ListenableFuture > getPolicyType(GetPolicyTypeInput input) { - log.debug("Start of getPolicyType"); - log.debug("Policy Type Id : ", input.getPolicyTypeId()); - String uri = nearRicUrlProvider.getPolicyTypeId(String.valueOf(input.getPolicyTypeId())); - Optional policyTypeSchema = restAdapter.get(uri, PolicyTypeSchema.class); + log.info("Start of getPolicyType"); + log.info("Policy Type Id : {} ", input.getPolicyTypeId()); GetPolicyTypeOutputBuilder responseBuilder = new GetPolicyTypeOutputBuilder(); - if (policyTypeSchema.isPresent()) { - responseBuilder.setDescription(policyTypeSchema.get().getDescription()); - responseBuilder.setName(policyTypeSchema.get().getName()); - responseBuilder.setPolicyType(policyTypeSchema.get().getCreateSchema().toString()); + 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.debug("End of getPolicyType"); + log.info("End of getPolicyType"); RpcResult rpcResult = RpcResultBuilder. status(true) .withResult(responseBuilder.build()).build(); return Futures.immediateFuture(rpcResult); } @Override - public ListenableFuture > getPolicyTypes( - GetPolicyTypesInput input) { - log.debug("Start of getPolicyTypes"); - String uri = nearRicUrlProvider.getPolicyTypes(); - Optional > policyTypes = restAdapter.get(uri, List.class); - GetPolicyTypesOutputBuilder responseBuilder = new GetPolicyTypesOutputBuilder(); - responseBuilder.setPolicyTypeIdList(policyTypes.get()); - log.debug("End of getPolicyTypes"); - RpcResult
rpcResult = RpcResultBuilder. status(true) - .withResult(responseBuilder.build()).build(); + public ListenableFuture > putPolicy(PutPolicyInput input) { + log.info("Start of putPolicy"); + PutPolicyOutputBuilder responseBuilder = new PutPolicyOutputBuilder(); + String uri = nearRicUrlProvider.putPolicyUrl(String.valueOf(input.getNearRtRicUrl()), + String.valueOf(input.getPolicyId()), String.valueOf(input.getPolicyTypeId())); + log.info("PUT Request input.getPolicy() : {} ", input.getPolicy()); + ResponseEntity response = restAdapter.put(uri, input.getPolicy(), String.class); + if (response.hasBody()) { + log.info("Response putPolicy : {} ", response.getBody()); + responseBuilder.setReturnedPolicy(response.getBody()); + } + 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.debug("Start of getStatus"); - String uri = nearRicUrlProvider.getPolicyInstanceIdStatus( - String.valueOf(input.getPolicyTypeId()), String.valueOf(input.getPolicyInstanceId())); - Optional > policyTypes = restAdapter.get(uri, List.class); - GetStatusOutputBuilder responseBuilder = new GetStatusOutputBuilder(); - // TODO: - /* - * No Schema defined for the response so Identify a way to parse the schema or create the java - * object - */ - responseBuilder.setStatus(RESPONSE_SUCCESS); - log.debug("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.deletePolicyUrl(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); } }