Fixed vnfapi install issue
[sdnc/northbound.git] / vnfapi / provider / src / main / java / org / onap / sdnc / vnfapi / vnfapiProvider.java
index a86def1..f64cb0b 100644 (file)
@@ -8,9 +8,9 @@
  * 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.
@@ -41,7 +41,7 @@ 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.NotificationProviderService;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.NetworkTopologyOperationInput;
 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.NetworkTopologyOperationInputBuilder;
@@ -139,6 +139,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
@@ -164,20 +165,22 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
     private ListenerRegistration<DataChangeListener> dclServices;
 
     protected DataBroker dataBroker;
-    protected NotificationProviderService notificationService;
+    protected NotificationPublishService notificationService;
     protected RpcProviderRegistry rpcRegistry;
     protected BindingAwareBroker.RpcRegistration<VNFAPIService> rpcRegistration;
 
+    private VNFSDNSvcLogicServiceClient svcLogicClient;
+
 
 
-    public vnfapiProvider(DataBroker dataBroker2,
-            NotificationProviderService notificationProviderService,
-            RpcProviderRegistry rpcProviderRegistry) {
+    public vnfapiProvider(DataBroker dataBroker2, NotificationPublishService notificationPublishService,
+            RpcProviderRegistry rpcProviderRegistry, VNFSDNSvcLogicServiceClient client) {
         this.log.info( "Creating provider for " + appName );
         executor = Executors.newFixedThreadPool(1);
         dataBroker = dataBroker2;
-        notificationService = notificationProviderService;
+        notificationService = notificationPublishService;
         rpcRegistry = rpcProviderRegistry;
+        this.svcLogicClient = client;
         initialize();
 
     }
@@ -189,9 +192,9 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         try {
             VnfSdnUtil.loadProperties();
         } catch (Exception e) {
-            log.error("Caught Exception while trying to load properties file");
+            log.error("Caught Exception while trying to load properties file: ", e);
         }
-        rpcRegistration = rpcRegistry.addRpcImplementation(VNFAPIService.class, this);
+        // rpcRegistration = rpcRegistry.addRpcImplementation(VNFAPIService.class, this);
 
         log.info( "Initialization complete for " + appName );
     }
@@ -242,7 +245,6 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         } catch (InterruptedException | ExecutionException e) {
             log.error("Create Containers Failed: " + e);
-            e.printStackTrace();
         }
     }
 
@@ -487,7 +489,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
             default:
                 log.error("Unknown RequestAction: " + requestInformation.getRequestAction() );
                 break;
-            };
+            }
         }
         if (requestInformation != null && requestInformation.getRequestSubAction() != null) {
             switch (requestInformation.getRequestSubAction())
@@ -501,7 +503,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
             default:
                 log.error("Unknown RequestSubAction: " + requestInformation.getRequestSubAction() );
                 break;
-            };
+            }
         }
     }
 
@@ -534,7 +536,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
             default:
                 log.error("Unknown SvcAction: " + requestHeader.getSvcAction() );
                 break;
-            };
+            }
         }
     }
 
@@ -550,7 +552,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // See if any data exists yet for this siid, if so grab it.
         InstanceIdentifier serviceInstanceIdentifier =
                 InstanceIdentifier.<Vnfs>builder(Vnfs.class)
-                .child(VnfList.class, new VnfListKey(siid)).toInstance();
+                .child(VnfList.class, new VnfListKey(siid)).build();
         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VnfList> data = null;
         try {
@@ -559,7 +561,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
             log.error("Caught Exception reading MD-SAL ("+type+") for ["+siid+"] " ,e);
         }
 
-        if ( data.isPresent()) {
+        if (data != null && data.isPresent()) {
             ServiceData serviceData = (ServiceData) data.get().getServiceData();
             if (serviceData != null) {
                 log.info("Read MD-SAL ("+type+") data for ["+siid+"] ServiceData: " + serviceData);
@@ -590,7 +592,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // See if any data exists yet for this siid, if so grab it.
         InstanceIdentifier vnfInstanceIdentifier =
                 InstanceIdentifier.<VnfInstances>builder(VnfInstances.class)
-                .child(VnfInstanceList.class, new VnfInstanceListKey(siid)).toInstance();
+                .child(VnfInstanceList.class, new VnfInstanceListKey(siid)).build();
         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VnfInstanceList> data = null;
         try {
@@ -599,7 +601,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
             log.error("Caught Exception reading MD-SAL ("+type+") for ["+siid+"] " ,e);
         }
 
-        if ( data.isPresent()) {
+        if (data != null && data.isPresent()) {
             VnfInstanceServiceData vnfInstanceServiceData = (VnfInstanceServiceData) data.get().getVnfInstanceServiceData();
             if (vnfInstanceServiceData != null) {
                 log.info("Read MD-SAL ("+type+") data for ["+siid+"] VnfInstanceServiceData: " + vnfInstanceServiceData);
@@ -630,7 +632,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // See if any data exists yet for this siid, if so grab it.
         InstanceIdentifier vfModuleIdentifier =
                 InstanceIdentifier.<VfModules>builder(VfModules.class)
-                .child(VfModuleList.class, new VfModuleListKey(siid)).toInstance();
+                .child(VfModuleList.class, new VfModuleListKey(siid)).build();
         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VfModuleList> data = null;
         try {
@@ -639,7 +641,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
             log.error("Caught Exception reading MD-SAL ("+type+") for ["+siid+"] " ,e);
         }
 
-        if ( data.isPresent()) {
+        if (data != null && data.isPresent()) {
             VfModuleServiceData vfModuleServiceData = (VfModuleServiceData) data.get().getVfModuleServiceData();
             if (vfModuleServiceData != null) {
                 log.info("Read MD-SAL ("+type+") data for ["+siid+"] VfModuleServiceData: " + vfModuleServiceData);
@@ -670,7 +672,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // See if any data exists yet for this name/type, if so grab it.
         InstanceIdentifier preloadInstanceIdentifier =
                 InstanceIdentifier.<PreloadVnfs>builder(PreloadVnfs.class)
-                .child(VnfPreloadList.class, new VnfPreloadListKey(preload_name, preload_type)).toInstance();
+                .child(VnfPreloadList.class, new VnfPreloadListKey(preload_name, preload_type)).build();
         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VnfPreloadList> data = null;
         try {
@@ -679,7 +681,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
             log.error("Caught Exception reading MD-SAL ("+type+") for ["+preload_name+","+preload_type+"] " ,e);
         }
 
-        if ( data.isPresent()) {
+        if (data != null && data.isPresent()) {
             PreloadData preloadData = (PreloadData) data.get().getPreloadData();
             if (preloadData != null) {
                 log.info("Read MD-SAL ("+type+") data for ["+preload_name+","+preload_type+"] PreloadData: " + preloadData);
@@ -707,7 +709,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // See if any data exists yet for this name/type, if so grab it.
         InstanceIdentifier preloadInstanceIdentifier =
                 InstanceIdentifier.<PreloadVnfInstances>builder(PreloadVnfInstances.class)
-                .child(VnfInstancePreloadList.class, new VnfInstancePreloadListKey(preload_name, preload_type)).toInstance();
+                .child(VnfInstancePreloadList.class, new VnfInstancePreloadListKey(preload_name, preload_type)).build();
         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VnfInstancePreloadList> data = null;
         try {
@@ -716,7 +718,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
             log.error("Caught Exception reading MD-SAL ("+type+") for ["+preload_name+","+preload_type+"] " ,e);
         }
 
-        if ( data.isPresent()) {
+        if (data != null && data.isPresent()) {
             VnfInstancePreloadData preloadData = (VnfInstancePreloadData) data.get().getVnfInstancePreloadData();
             if (preloadData != null) {
                 log.info("Read MD-SAL ("+type+") data for ["+preload_name+","+preload_type+"] VnfInstancePreloadData: " + preloadData);
@@ -742,7 +744,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // See if any data exists yet for this name/type, if so grab it.
         InstanceIdentifier preloadInstanceIdentifier =
                 InstanceIdentifier.<PreloadVfModules>builder(PreloadVfModules.class)
-                .child(VfModulePreloadList.class, new VfModulePreloadListKey(preload_name, preload_type)).toInstance();
+                .child(VfModulePreloadList.class, new VfModulePreloadListKey(preload_name, preload_type)).build();
         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VfModulePreloadList> data = null;
         try {
@@ -751,7 +753,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
             log.error("Caught Exception reading MD-SAL ("+type+") for ["+preload_name+","+preload_type+"] " ,e);
         }
 
-        if ( data.isPresent()) {
+        if (data != null && data.isPresent()) {
             VfModulePreloadData preloadData = (VfModulePreloadData) data.get().getVfModulePreloadData();
             if (preloadData != null) {
                 log.info("Read MD-SAL ("+type+") data for ["+preload_name+","+preload_type+"] VfModulePreloadData: " + preloadData);
@@ -770,7 +772,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         InstanceIdentifier.InstanceIdentifierBuilder<VnfList> vnfListIdBuilder =
                 InstanceIdentifier.<Vnfs>builder(Vnfs.class)
                 .child(VnfList.class, entry.getKey());
-        InstanceIdentifier<VnfList> path = vnfListIdBuilder.toInstance();
+        InstanceIdentifier<VnfList> path = vnfListIdBuilder.build();
 
         int tries = 2;
         while(true) {
@@ -804,7 +806,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         InstanceIdentifier.InstanceIdentifierBuilder<VnfList> vnfListIdBuilder =
                 InstanceIdentifier.<Vnfs>builder(Vnfs.class)
                 .child(VnfList.class, entry.getKey());
-        InstanceIdentifier<VnfList> path = vnfListIdBuilder.toInstance();
+        InstanceIdentifier<VnfList> path = vnfListIdBuilder.build();
 
         int tries = 2;
         while (true) {
@@ -835,7 +837,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         InstanceIdentifier.InstanceIdentifierBuilder<VnfInstanceList> vnfInstanceListIdBuilder =
                 InstanceIdentifier.<VnfInstances>builder(VnfInstances.class)
                 .child(VnfInstanceList.class, entry.getKey());
-        InstanceIdentifier<VnfInstanceList> path = vnfInstanceListIdBuilder.toInstance();
+        InstanceIdentifier<VnfInstanceList> path = vnfInstanceListIdBuilder.build();
 
         int tries = 2;
         while(true) {
@@ -870,7 +872,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         InstanceIdentifier.InstanceIdentifierBuilder<VfModuleList> vfModuleListIdBuilder =
                 InstanceIdentifier.<VfModules>builder(VfModules.class)
                 .child(VfModuleList.class, entry.getKey());
-        InstanceIdentifier<VfModuleList> path = vfModuleListIdBuilder.toInstance();
+        InstanceIdentifier<VfModuleList> path = vfModuleListIdBuilder.build();
 
         int tries = 2;
         while(true) {
@@ -905,7 +907,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         InstanceIdentifier.InstanceIdentifierBuilder<VnfPreloadList> vnfListIdBuilder =
                 InstanceIdentifier.<PreloadVnfs>builder(PreloadVnfs.class)
                 .child(VnfPreloadList.class, entry.getKey());
-        InstanceIdentifier<VnfPreloadList> path = vnfListIdBuilder.toInstance();
+        InstanceIdentifier<VnfPreloadList> path = vnfListIdBuilder.build();
         int tries = 2;
         while(true) {
             try {
@@ -940,7 +942,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         InstanceIdentifier.InstanceIdentifierBuilder<VnfInstancePreloadList> vnfInstanceListIdBuilder =
                 InstanceIdentifier.<PreloadVnfInstances>builder(PreloadVnfInstances.class)
                 .child(VnfInstancePreloadList.class, entry.getKey());
-        InstanceIdentifier<VnfInstancePreloadList> path = vnfInstanceListIdBuilder.toInstance();
+        InstanceIdentifier<VnfInstancePreloadList> path = vnfInstanceListIdBuilder.build();
         int tries = 2;
         while(true) {
             try {
@@ -975,7 +977,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         InstanceIdentifier.InstanceIdentifierBuilder<VfModulePreloadList> vfModuleListIdBuilder =
                 InstanceIdentifier.<PreloadVfModules>builder(PreloadVfModules.class)
                 .child(VfModulePreloadList.class, entry.getKey());
-        InstanceIdentifier<VfModulePreloadList> path = vfModuleListIdBuilder.toInstance();
+        InstanceIdentifier<VfModulePreloadList> path = vfModuleListIdBuilder.build();
         int tries = 2;
         while(true) {
             try {
@@ -1003,6 +1005,11 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         }
     }
 
+    //Save the requestId into MDC
+    private void setRequestIdAsMDC(String requestId){
+        MDC.put("RequestId", requestId);
+    }
+
     //1610 vnf-instance-topology-operation
     @Override
     public Future<RpcResult<VnfInstanceTopologyOperationOutput>> vnfInstanceTopologyOperation(
@@ -1051,6 +1058,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         if (input.getSdncRequestHeader() != null) {
             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
+            setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
         }
 
         // Get vnf-instance-preload-data
@@ -1099,7 +1107,6 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // Call SLI sync method
         // Get SvcLogicService reference
 
-        VNFSDNSvcLogicServiceClient svcLogicClient = new VNFSDNSvcLogicServiceClient();
         Properties respProps = null;
 
         String errorCode = "200";
@@ -1281,6 +1288,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         if (input.getSdncRequestHeader() != null) {
             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
+            setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
         }
 
         // Get vf-module-preload-data
@@ -1351,7 +1359,6 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // Call SLI sync method
         // Get SvcLogicService reference
 
-        VNFSDNSvcLogicServiceClient svcLogicClient = new VNFSDNSvcLogicServiceClient();
         Properties respProps = null;
 
         String errorCode = "200";
@@ -1535,6 +1542,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         if (input.getSdncRequestHeader() != null) {
             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
+            setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
         }
 
         PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
@@ -1580,7 +1588,6 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // Call SLI sync method
         // Get SvcLogicService reference
 
-        VNFSDNSvcLogicServiceClient svcLogicClient = new VNFSDNSvcLogicServiceClient();
         Properties respProps = null;
 
         String errorCode = "200";
@@ -1745,7 +1752,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         // Grab the service instance ID from the input buffer
         String siid = null;
-        if (input.getSdncRequestHeader().getSvcAction().equals("assign")) {
+        if (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Assign)) {
             siid = input.getNetworkRequestInformation().getNetworkName();
         }
         else {
@@ -1769,6 +1776,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         if (input.getSdncRequestHeader() != null) {
             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
+            setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
         }
 
         PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
@@ -1789,7 +1797,6 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // Call SLI sync method
         // Get SvcLogicService reference
 
-        VNFSDNSvcLogicServiceClient svcLogicClient = new VNFSDNSvcLogicServiceClient();
         Properties respProps = null;
 
         String errorCode = "200";
@@ -1932,6 +1939,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         if (input.getSdncRequestHeader() != null) {
             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
+            setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
         }
 
         PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
@@ -1964,7 +1972,6 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // Call SLI sync method
         // Get SvcLogicService reference
 
-        VNFSDNSvcLogicServiceClient svcLogicClient = new VNFSDNSvcLogicServiceClient();
         Properties respProps = null;
 
         String errorCode = "200";
@@ -2126,6 +2133,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         if (input.getSdncRequestHeader() != null) {
             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
+            setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
         }
 
         VnfInstancePreloadDataBuilder vnfInstancePreloadDataBuilder = new VnfInstancePreloadDataBuilder();
@@ -2158,7 +2166,6 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // Call SLI sync method
         // Get SvcLogicService reference
 
-        VNFSDNSvcLogicServiceClient svcLogicClient = new VNFSDNSvcLogicServiceClient();
         Properties respProps = null;
 
         String errorCode = "200";
@@ -2321,6 +2328,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         if (input.getSdncRequestHeader() != null) {
             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
+            setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
         }
 
         VfModulePreloadDataBuilder vfModulePreloadDataBuilder = new VfModulePreloadDataBuilder();
@@ -2353,7 +2361,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // Call SLI sync method
         // Get SvcLogicService reference
 
-        VNFSDNSvcLogicServiceClient svcLogicClient = new VNFSDNSvcLogicServiceClient();
+
         Properties respProps = null;
 
         String errorCode = "200";
@@ -2511,6 +2519,7 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
 
         if (input.getSdncRequestHeader() != null) {
             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
+            setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
         }
 
         PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
@@ -2542,7 +2551,6 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
         // Call SLI sync method
         // Get SvcLogicService reference
 
-        VNFSDNSvcLogicServiceClient svcLogicClient = new VNFSDNSvcLogicServiceClient();
         Properties respProps = null;
 
         String errorCode = "200";
@@ -2648,4 +2656,5 @@ public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeL
                 RpcResultBuilder.<PreloadNetworkTopologyOperationOutput> status(true).withResult(responseBuilder.build()).build();
         return Futures.immediateFuture(rpcResult);
     }
+
 }