X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=generic-resource-api%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fsdnc%2Fnorthbound%2FGenericResourceApiProvider.java;h=7eb4f2b0197425cbe74c6db8d40369e24e90dac2;hb=0c7427d61a9ba80527460e9bf6cda7a5bc6cc122;hp=583c6335714e0be7f0ed3083757a6347c3868d54;hpb=a1f1bbb18ab529649d0a4a006e8ab8a84d3306ae;p=sdnc%2Fnorthbound.git diff --git a/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java b/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java index 583c6335..7eb4f2b0 100644 --- a/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java +++ b/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java @@ -1,110 +1,36 @@ package org.onap.sdnc.northbound; -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.Date; +import java.util.Optional; import java.util.Properties; import java.util.TimeZone; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -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.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException; -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.generic.resource.rev170824.BrgTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ConnectionAttachmentTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GENERICRESOURCEAPIService; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GenericConfigurationNotificationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GenericConfigurationNotificationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GenericConfigurationNotificationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GenericConfigurationTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GenericConfigurationTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GenericConfigurationTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GenericConfigurationTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GetpathsegmentTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GetpathsegmentTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GetpathsegmentTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GetpathsegmentTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PolicyUpdateNotifyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PolicyUpdateNotifyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PolicyUpdateNotifyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PolicyUpdateNotifyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PortMirrorTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PortMirrorTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PortMirrorTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PortMirrorTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadInformation; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadInformationBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVfModuleTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVfModuleTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVfModuleTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVfModuleTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.Services; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServicesBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfGetResourceRequestInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfGetResourceRequestInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfGetResourceRequestOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfGetResourceRequestOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationOutputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PnfTopologyOperationInput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PnfTopologyOperationInputBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PnfTopologyOperationOutput; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PnfTopologyOperationOutputBuilder; + +import com.google.common.util.concurrent.FluentFuture; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; + +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.common.api.OptimisticLockFailedException; +import org.opendaylight.mdsal.common.api.TransactionCommitFailedException; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.*; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.brg.response.information.BrgResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.connection.attachment.response.information.ConnectionAttachmentResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.contrail.route.response.information.ContrailRouteResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.gc.response.information.GcResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.response.information.NetworkResponseInformationBuilder; +import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.pnf.response.information.PnfResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.port.mirror.response.information.PortMirrorResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.data.PreloadData; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.data.PreloadDataBuilder; @@ -127,7 +53,7 @@ import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.re import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.tunnelxconn.response.information.TunnelxconnResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vf.module.response.information.VfModuleResponseInformationBuilder; import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.vnf.response.information.VnfResponseInformationBuilder; -import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.pnf.response.information.PnfResponseInformationBuilder; +import org.opendaylight.yangtools.concepts.ObjectRegistration; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -153,7 +79,7 @@ import org.slf4j.LoggerFactory; * final GenericResourceApiProvider provider = new GenericResourceApiProvider(); * provider.setDataBroker(getDataBrokerDependency()); * provider.setNotificationService(getNotificationServiceDependency()); - * provider.setRpcRegistry(getRpcRegistryDependency()); + * provider.setRpcService(getRpcServiceDependency()); * provider.initialize(); * return new AutoCloseable() { * @@ -214,16 +140,16 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC protected DataBroker dataBroker; protected NotificationPublishService notificationService; - protected RpcProviderRegistry rpcRegistry; - protected BindingAwareBroker.RpcRegistration rpcRegistration; + protected RpcProviderService rpcService; + protected ObjectRegistration rpcRegistration; public GenericResourceApiProvider(DataBroker dataBroker, NotificationPublishService notificationPublishService, - RpcProviderRegistry rpcProviderRegistry, GenericResourceApiSvcLogicServiceClient client) { + RpcProviderService rpcProviderService, GenericResourceApiSvcLogicServiceClient client) { log.info("Creating provider for {}", APP_NAME); executor = Executors.newFixedThreadPool(1); setDataBroker(dataBroker); setNotificationService(notificationPublishService); - setRpcRegistry(rpcProviderRegistry); + setRpcService(rpcProviderService); svcLogicClient = client; initialize(); @@ -239,6 +165,12 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC log.error("Caught Exception while trying to load properties file", e); } + if (rpcRegistration == null) { + if (rpcService != null) { + rpcRegistration = rpcService.registerRpcImplementation(GENERICRESOURCEAPIService.class, this); + } + } + log.info("Initialization complete for {}", APP_NAME); } @@ -285,10 +217,10 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } } - public void setRpcRegistry(RpcProviderRegistry rpcRegistry) { - this.rpcRegistry = rpcRegistry; + public void setRpcService(RpcProviderService rpcService) { + this.rpcService = rpcService; if (log.isDebugEnabled()) { - log.debug("RpcRegistry set to {}", rpcRegistry == null ? NULL_PARAM : NON_NULL_PARAM); + log.debug("rpcService set to {}", rpcService == null ? NULL_PARAM : NON_NULL_PARAM); } } @@ -309,7 +241,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC new PreloadInformationBuilder().build()); try { - CheckedFuture checkedFuture = t.submit(); + FluentFuture checkedFuture = t.commit(); checkedFuture.get(); log.info("Create containers succeeded!"); @@ -367,12 +299,13 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC private void getServiceData(String siid, ServiceDataBuilder serviceDataBuilder, LogicalDatastoreType type) { // See if any data exists yet for this siid, if so grab it. - InstanceIdentifier serviceInstanceIdentifier = InstanceIdentifier.builder(Services.class) + InstanceIdentifier serviceInstanceIdentifier = InstanceIdentifier.builder(Services.class) .child(Service.class, new ServiceKey(siid)).build(); - Optional data = Optional.absent(); - try (final ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) { - data = readTx.read(type, serviceInstanceIdentifier).get(); + Optional data = null; + + try (final ReadTransaction readTx = dataBroker.newReadOnlyTransaction()) { + data = (Optional) readTx.read(type, serviceInstanceIdentifier).get(); } catch (final InterruptedException | ExecutionException e) { log.error("Caught Exception reading MD-SAL ({}) data for [{}] ", type, siid, e); } @@ -426,7 +359,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC throw new IllegalStateException(e); } log.debug("Got OptimisticLockFailedException - trying again "); - } catch (TransactionCommitFailedException ex) { + } catch (TransactionCommitFailedException|InterruptedException|ExecutionException ex) { log.debug("Update DataStore failed"); throw new IllegalStateException(ex); } @@ -434,14 +367,15 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } private void save(T entry, boolean merge, LogicalDatastoreType storeType, - InstanceIdentifier path) throws TransactionCommitFailedException { + InstanceIdentifier path) throws TransactionCommitFailedException, InterruptedException, + ExecutionException { WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); if (merge) { tx.merge(storeType, path, entry); } else { tx.put(storeType, path, entry); } - tx.submit().checkedGet(); + tx.commit().get(); log.debug("Update DataStore succeeded"); } @@ -466,7 +400,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC throw new IllegalStateException(e); } log.debug("Got OptimisticLockFailedException - trying again "); - } catch (TransactionCommitFailedException ex) { + } catch (TransactionCommitFailedException|InterruptedException|ExecutionException ex) { log.debug("Update DataStore failed"); throw new IllegalStateException(ex); } @@ -474,10 +408,10 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } private void delete(LogicalDatastoreType storeType, InstanceIdentifier path) - throws TransactionCommitFailedException { + throws TransactionCommitFailedException, InterruptedException, ExecutionException { WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.delete(storeType, path); - tx.submit().checkedGet(); + tx.commit().get(); log.debug("DataStore delete succeeded"); } @@ -494,7 +428,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC .child(PreloadList.class, new PreloadListKey(preloadName, preloadType)).build(); Optional data = null; - try (final ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) { + try (final ReadTransaction readTx = dataBroker.newReadOnlyTransaction()) { data = (Optional) readTx.read(type, preloadInstanceIdentifier).get(); } catch (final InterruptedException | ExecutionException e) { log.error("Caught Exception reading MD-SAL ({}) for [{},{}] ", type, preloadName, preloadType, e); @@ -535,10 +469,10 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } else { tx.put(storeType, path, entry); } - tx.submit().checkedGet(); + tx.commit().get(); log.debug("Update DataStore succeeded"); break; - } catch (final TransactionCommitFailedException e) { + } catch (final InterruptedException | ExecutionException e) { if (e instanceof OptimisticLockFailedException) { if (--tries <= 0) { log.debug("Got OptimisticLockFailedException on last try - failing "); @@ -574,7 +508,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC throw new IllegalStateException(e); } log.debug("Got OptimisticLockFailedException - trying again "); - } catch (TransactionCommitFailedException ex) { + } catch (TransactionCommitFailedException|InterruptedException|ExecutionException ex) { log.debug("Update DataStore failed"); throw new IllegalStateException(ex); } @@ -582,10 +516,10 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC } private void deletePreloadList(LogicalDatastoreType storeType, InstanceIdentifier path) - throws TransactionCommitFailedException { + throws TransactionCommitFailedException, InterruptedException, ExecutionException { WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); tx.delete(storeType, path); - tx.submit().checkedGet(); + tx.commit().get(); log.debug("DataStore delete succeeded"); } @@ -3995,4 +3929,74 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC || input.getServiceInformation().getServiceInstanceId() == null || input.getServiceInformation().getServiceInstanceId().length() == 0; } + + @Override + public ListenableFuture> collectPerformanceData(CollectPerformanceDataInput input) { + final String svcOperation = "performance-data-collector"; + Properties parms = new Properties(); + + log.info(CALLED_STR, svcOperation); + // create a new response object + CollectPerformanceDataOutputBuilder responseBuilder = new CollectPerformanceDataOutputBuilder(); + + if (hasInvalidService(input)) { + log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation); + RpcResult rpcResult = RpcResultBuilder + .status(true).withResult(responseBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + ServiceDataBuilder serviceDataBuilder = new ServiceDataBuilder(); + serviceDataBuilder.setControllerIpv4Address(input.getControllerIpv4Address()); + + ServiceDataBuilder operDataBuilder = new ServiceDataBuilder(); + + log.info(ADDING_INPUT_DATA_LOG, svcOperation, input.getControllerIpv4Address(), input); + CollectPerformanceDataInputBuilder inputBuilder = new CollectPerformanceDataInputBuilder(input); + GenericResourceApiUtil.toProperties(parms, inputBuilder.build()); + + log.info(ADDING_OPERATIONAL_DATA_LOG, svcOperation, input.getControllerIpv4Address(), operDataBuilder.build()); + GenericResourceApiUtil.toProperties(parms, OPERATIONAL_DATA_PARAM, operDataBuilder); + + // Call SLI sync method + ResponseObject responseObject = new ResponseObject("200", ""); + String ackFinal = "Y"; + Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, responseObject); + + if (respProps != null) { + responseObject.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM)); + responseObject.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM)); + ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y"); + } + + if (failed(responseObject)) { + responseBuilder.setResponseCode(responseObject.getStatusCode()); + responseBuilder.setResponseMessage(responseObject.getMessage()); + responseBuilder.setAckFinalIndicator(ackFinal); + + log.error(RETURNED_FAILED_MESSAGE, svcOperation, input.getControllerIpv4Address(), responseBuilder.build()); + RpcResult rpcResult = RpcResultBuilder + .status(true).withResult(responseBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + // Got success from SLI + log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, input.getControllerIpv4Address(), responseBuilder.build()); + + if (respProps != null) { + GenericResourceApiUtil.toBuilder(respProps, responseBuilder); + } + + RpcResult rpcResult = RpcResultBuilder.status(true) + .withResult(responseBuilder.build()).build(); + + // return success + return Futures.immediateFuture(rpcResult); + } + + private boolean hasInvalidService(CollectPerformanceDataInput input) { + return input == null || input.getControllerIpv4Address() == null; + } }