Fixed Blocker Bugs
[sdnc/northbound.git] / vnfapi / provider / src / main / java / org / onap / sdnc / vnfapi / VnfApiProvider.java
index 46184b0..c14db88 100644 (file)
@@ -155,7 +155,8 @@ import java.util.concurrent.Future;
  * initialization / clean up methods.
  */
 
-public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeChangeListener {
+public class VnfApiProvider implements AutoCloseable, VNFAPIService {
+
     protected DataBroker dataBroker;
     protected NotificationPublishService notificationService;
     protected RpcProviderRegistry rpcRegistry;
@@ -277,175 +278,6 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
         log.info("Successfully closed provider for " + APP_NAME);
     }
 
-    // On data change not used
-       @Override
-       public void onDataTreeChanged(Collection changes) {
-
-               log.info("   IN ON DATA CHANGE: ");
-
-               for (Object changeObj : changes) {
-
-                       if (changeObj instanceof DataTreeModification) {
-                               
-                               DataTreeModification change = (DataTreeModification) changeObj;
-                               
-
-                               boolean changed = false;
-                               WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
-                               DataObject updatedSubTree = change.getRootNode().getDataAfter();
-
-                               if (updatedSubTree != null) {
-                                       if (log.isDebugEnabled()) {
-                                               log.debug("updatedSubTree was non-null:" + updatedSubTree);
-                                       }
-                                       if (updatedSubTree instanceof Vnfs) {
-                                               changed = isChanged(changed, (Vnfs) updatedSubTree);
-                                       }
-                                       if (updatedSubTree instanceof PreloadVnfs) {
-                                               changed = isChanged(changed, (PreloadVnfs) updatedSubTree);
-                                       }
-                                       // 1610
-                                       if (updatedSubTree instanceof PreloadVnfInstances) {
-                                               changed = isChanged(changed, (PreloadVnfInstances) updatedSubTree);
-                                       }
-                                       // 1610
-                                       if (updatedSubTree instanceof VnfInstances) {
-                                               changed = isChanged(changed, (VnfInstances) updatedSubTree);
-                                       }
-                                       // 1610
-                                       if (updatedSubTree instanceof PreloadVfModules) {
-                                               changed = isChanged(changed, (PreloadVfModules) updatedSubTree);
-                                       }
-                                       // 1610
-                                       if (updatedSubTree instanceof VfModules) {
-                                               changed = isChanged(changed, (VfModules) updatedSubTree);
-                                       }
-                               }
-
-                               // Do the write transaction only if something changed.
-                               if (changed) {
-                                       CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = writeTransaction.submit();
-                                       Futures.addCallback(checkedFuture, new FutureCallback<Void>() {
-
-                                               @Override
-                                               public void onSuccess(Void arg0) {
-                                                       log.debug("Successfully updated Service Status");
-                                               }
-
-                                               @Override
-                                               public void onFailure(Throwable e) {
-                                                       log.debug("Failed updating Service Status", e);
-                                               }
-                                       }, executor);
-                               }
-                       }
-               }
-       }
-
-    private boolean isChanged(boolean changed, VfModules updatedSubTree) {
-        ArrayList<VfModuleList> vfModuleList =
-            (ArrayList<VfModuleList>) updatedSubTree.getVfModuleList();
-        if (vfModuleList != null) {
-            for (VfModuleList entry : vfModuleList) {
-                VfModuleServiceData vfModuleServiceData = entry.getVfModuleServiceData();
-                ServiceStatus serviceStatus = entry.getServiceStatus();
-                if (vfModuleServiceData != null && serviceStatus != null) {
-                    // VfModuleServiceData change detected, check the AckFinal indicator and request-status to
-                    // see if we need to proceed.
-                    return isChanged(changed, serviceStatus);
-                }
-            }
-        }
-        return changed;
-    }
-
-    private boolean isChanged(boolean changed, PreloadVfModules updatedSubTree) {
-        ArrayList<VfModulePreloadList> vnfInstanceList =
-            (ArrayList<VfModulePreloadList>) updatedSubTree.getVfModulePreloadList();
-        if (vnfInstanceList != null) {
-            for (VfModulePreloadList entry : vnfInstanceList) {
-                VfModulePreloadData vnfInstancePreloadData = entry.getVfModulePreloadData();
-                if (vnfInstancePreloadData != null) {
-                    return true;
-                }
-            }
-        }
-        return changed;
-    }
-
-    private boolean isChanged(boolean changed, VnfInstances updatedSubTree) {
-        ArrayList<VnfInstanceList> vnfInstanceList =
-            (ArrayList<VnfInstanceList>) updatedSubTree.getVnfInstanceList();
-        if (vnfInstanceList != null) {
-            for (VnfInstanceList entry : vnfInstanceList) {
-                VnfInstanceServiceData vnfInstanceServiceData = entry.getVnfInstanceServiceData();
-                ServiceStatus serviceStatus = entry.getServiceStatus();
-                if (vnfInstanceServiceData != null && serviceStatus != null) {
-                    // VnfInstanceServiceData change detected, check the AckFinal indicator and request-status
-                    // to see if we need to proceed.
-                    return isChanged(changed, serviceStatus);
-                }
-            }
-        }
-        return changed;
-    }
-
-    private boolean isChanged(boolean changed, PreloadVnfInstances updatedSubTree) {
-        ArrayList<VnfInstancePreloadList> vnfInstanceList =
-            (ArrayList<VnfInstancePreloadList>) updatedSubTree
-                .getVnfInstancePreloadList();
-        if (vnfInstanceList != null) {
-            for (VnfInstancePreloadList entry : vnfInstanceList) {
-                VnfInstancePreloadData vnfInstancePreloadData = entry.getVnfInstancePreloadData();
-                if (vnfInstancePreloadData != null) {
-                    return true;
-                }
-            }
-        }
-        return changed;
-    }
-
-    private boolean isChanged(boolean changed, PreloadVnfs updatedSubTree) {
-        ArrayList<VnfPreloadList> vnfList =
-            (ArrayList<VnfPreloadList>) updatedSubTree.getVnfPreloadList();
-        if (vnfList != null) {
-            for (VnfPreloadList entry : vnfList) {
-                PreloadData preloadData = entry.getPreloadData();
-                if (preloadData != null) {
-                    return true;
-                }
-            }
-        }
-        return changed;
-    }
-
-    private boolean isChanged(boolean changed, Vnfs updatedSubTree) {
-        ArrayList<VnfList> vnfList = (ArrayList<VnfList>) updatedSubTree.getVnfList();
-        if (vnfList != null) {
-            for (VnfList entry : vnfList) {
-                ServiceData serviceData = entry.getServiceData();
-                ServiceStatus serviceStatus = entry.getServiceStatus();
-                if (serviceData != null && serviceStatus != null) {
-                    //
-                    // ServiceData change detected, check the AckFinal indicator and request-status to see if we need to proceed.
-                    //
-                    return isChanged(changed, serviceStatus);
-                }
-            }
-        }
-        return changed;
-    }
-
-    private boolean isChanged(boolean changed, ServiceStatus serviceStatus) {
-        if ((!"Y".equals(serviceStatus.getFinalIndicator())) && (RequestStatus.Synccomplete
-            .equals(serviceStatus.getRequestStatus()))) {
-            if (log.isDebugEnabled()) {
-                log.debug("Final Indicator is not Y, calling handleServiceDataUpdated");
-            }
-            return true;
-        }
-        return changed;
-    }
 
     private static class Iso8601Util {
 
@@ -581,11 +413,10 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
             .child(VnfList.class, new VnfListKey(siid))
             .build();
 
-        ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VnfList> data = Optional.absent();
-        try {
+        try (final ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) {
             data = readTx.read(type, serviceInstanceIdentifier).get();
-        } catch (InterruptedException | ExecutionException e) {
+        } catch (final InterruptedException | ExecutionException e) {
             log.error(EXCEPTION_READING_MD_SAL_STR + type + FOR_STR + siid + "] ", e);
         }
 
@@ -623,11 +454,10 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
             .child(VnfInstanceList.class, new VnfInstanceListKey(siid))
             .build();
 
-        ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VnfInstanceList> data = Optional.absent();
-        try {
+        try (final ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) {
             data = readTx.read(type, vnfInstanceIdentifier).get();
-        } catch (InterruptedException | ExecutionException e) {
+        } catch (final InterruptedException | ExecutionException e) {
             log.error(EXCEPTION_READING_MD_SAL_STR + type + FOR_STR + siid + "] ", e);
         }
 
@@ -668,11 +498,10 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
             .child(VfModuleList.class, new VfModuleListKey(siid))
             .build();
 
-        ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VfModuleList> data = Optional.absent();
-        try {
+        try (final ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) {
             data = readTx.read(type, vfModuleIdentifier).get();
-        } catch (InterruptedException | ExecutionException e) {
+        } catch (final InterruptedException | ExecutionException e) {
             log.error(EXCEPTION_READING_MD_SAL_STR + type + FOR_STR + siid + "] ", e);
         }
 
@@ -712,19 +541,17 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
             .child(VnfPreloadList.class, new VnfPreloadListKey(preloadName, preloadType))
             .build();
 
-        ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VnfPreloadList> data = Optional.absent();
-        try {
+        try (final ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) {
             data = readTx.read(type, preloadInstanceIdentifier).get();
-        } catch (InterruptedException | ExecutionException e) {
-            log.error(EXCEPTION_READING_MD_SAL_STR + type + FOR_STR + preloadName + "," + preloadType + "] ",
-                e);
+        } catch (final InterruptedException | ExecutionException e) {
+            log.error(EXCEPTION_READING_MD_SAL_STR + type + FOR_STR + preloadName + "," + preloadType + "] ", e);
         }
 
         if (data.isPresent()) {
             PreloadData preloadData = (PreloadData) data.get().getPreloadData();
             if (preloadData != null) {
-              log.info(READ_MD_SAL_STR + type + DATA_FOR_STR  + preloadName + "," + preloadType + PRELOAD_DATA
+                log.info(READ_MD_SAL_STR + type + DATA_FOR_STR + preloadName + "," + preloadType + PRELOAD_DATA
                     + preloadData);
                 preloadDataBuilder.setVnfTopologyInformation(preloadData.getVnfTopologyInformation());
                 preloadDataBuilder.setNetworkTopologyInformation(preloadData.getNetworkTopologyInformation());
@@ -754,13 +581,11 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
             .child(VnfInstancePreloadList.class, new VnfInstancePreloadListKey(preloadName, preloadType))
             .build();
 
-        ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VnfInstancePreloadList> data = Optional.absent();
-        try {
+        try (final ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) {
             data = readTx.read(type, preloadInstanceIdentifier).get();
-        } catch (InterruptedException | ExecutionException e) {
-            log.error(EXCEPTION_READING_MD_SAL_STR + type + FOR_STR + preloadName + "," + preloadType + "] ",
-                e);
+        } catch (final InterruptedException | ExecutionException e) {
+            log.error(EXCEPTION_READING_MD_SAL_STR + type + FOR_STR + preloadName + "," + preloadType + "] ", e);
         }
 
         if (data.isPresent()) {
@@ -794,14 +619,11 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
             .child(VfModulePreloadList.class, new VfModulePreloadListKey(preloadName, preloadType))
             .build();
 
-        ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
         Optional<VfModulePreloadList> data = Optional.absent();
-
-        try {
+        try (final ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction()) {
             data = readTx.read(type, preloadInstanceIdentifier).get();
-        } catch (InterruptedException | ExecutionException e) {
-            log.error(EXCEPTION_READING_MD_SAL_STR + type + FOR_STR + preloadName + "," + preloadType + "] ",
-                e);
+        } catch (final InterruptedException | ExecutionException e) {
+            log.error(EXCEPTION_READING_MD_SAL_STR + type + FOR_STR + preloadName + "," + preloadType + "] ", e);
         }
 
         if (data.isPresent()) {
@@ -845,15 +667,14 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
                 tryAgain = true;
 
             } catch (final TransactionCommitFailedException e) {
-               Throwable eCause = e.getCause();
-               
-               
-               if (eCause instanceof org.opendaylight.mdsal.common.api.TransactionCommitFailedException) {
-                       log.debug("Nested TransactionCommitFailed exception - getting next cause");
-                       eCause = eCause.getCause();
-               } else {
-                       log.debug("Got TransactionCommitFailedException, caused by {}", eCause.getClass().getName());
-               }
+                Throwable eCause = e.getCause();
+
+                if (eCause instanceof org.opendaylight.mdsal.common.api.TransactionCommitFailedException) {
+                    log.debug("Nested TransactionCommitFailed exception - getting next cause");
+                    eCause = eCause.getCause();
+                } else {
+                    log.debug("Got TransactionCommitFailedException, caused by {}", eCause.getClass().getName());
+                }
 
                 if (eCause instanceof ModifiedNodeDoesNotExistException) {
                     log.debug("Ignoring ModifiedNodeDoesNotExistException");
@@ -972,21 +793,21 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
 
     private Boolean validateVnfInstanceTopologyOperationInput(VnfInstanceTopologyOperationInput input) {
         return input != null
-                && input.getVnfInstanceRequestInformation() != null
-                && input.getVnfInstanceRequestInformation().getVnfInstanceId() != null
-                && input.getVnfInstanceRequestInformation().getVnfInstanceId().length() != 0;
+            && input.getVnfInstanceRequestInformation() != null
+            && input.getVnfInstanceRequestInformation().getVnfInstanceId() != null
+            && input.getVnfInstanceRequestInformation().getVnfInstanceId().length() != 0;
     }
 
     private ListenableFuture<RpcResult<VnfInstanceTopologyOperationOutput>> buildVnfInstanceTopologyOperationOutputWithtError(
-            String responseCode, String responseMessage, String ackFinalIndicator) {
+        String responseCode, String responseMessage, String ackFinalIndicator) {
         VnfInstanceTopologyOperationOutputBuilder responseBuilder = new VnfInstanceTopologyOperationOutputBuilder();
         responseBuilder.setResponseCode(responseCode);
         responseBuilder.setResponseMessage(responseMessage);
         responseBuilder.setAckFinalIndicator(ackFinalIndicator);
         return Futures.immediateFuture(RpcResultBuilder
-                .<VnfInstanceTopologyOperationOutput>status(true)
-                .withResult(responseBuilder.build())
-                .build());
+            .<VnfInstanceTopologyOperationOutput>status(true)
+            .withResult(responseBuilder.build())
+            .build());
     }
 
     @Override
@@ -1005,8 +826,8 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
         if (!validateVnfInstanceTopologyOperationInput(input)) {
             log.debug(EXITING_STR + svcOperation + " because of " + INVALID_INPUT_VNF_INSTANCE_STR);
             return buildVnfInstanceTopologyOperationOutputWithtError("403",
-                    INVALID_INPUT_VNF_INSTANCE_STR,
-                    "Y" );
+                INVALID_INPUT_VNF_INSTANCE_STR,
+                "Y");
         }
 
         // Grab the service instance ID from the input buffer
@@ -1074,7 +895,8 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
 
         try {
             if (svcLogicClient.hasGraph(VNF_API, svcOperation, null, "sync")) {
-                respProps = svcLogicClient.execute(VNF_API, svcOperation, null, "sync", vnfInstanceServiceDataBuilder, parms);
+                respProps = svcLogicClient
+                    .execute(VNF_API, svcOperation, null, "sync", vnfInstanceServiceDataBuilder, parms);
             } else {
                 errorMessage = "No service logic active for VNF-API: '" + svcOperation + "'";
                 errorCode = "503";
@@ -1310,7 +1132,8 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
 
         try {
             if (svcLogicClient.hasGraph(VNF_API, svcOperation, null, "sync")) {
-                respProps = svcLogicClient.execute(VNF_API, svcOperation, null, "sync", vfModuleServiceDataBuilder, parms);
+                respProps = svcLogicClient
+                    .execute(VNF_API, svcOperation, null, "sync", vfModuleServiceDataBuilder, parms);
             } else {
                 errorMessage = "No service logic active for VNF-API: '" + svcOperation + "'";
                 errorCode = "503";
@@ -1408,7 +1231,8 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
     }
 
     @Override
-    public ListenableFuture<RpcResult<VnfTopologyOperationOutput>> vnfTopologyOperation(VnfTopologyOperationInput input) {
+    public ListenableFuture<RpcResult<VnfTopologyOperationOutput>> vnfTopologyOperation(
+        VnfTopologyOperationInput input) {
         final String svcOperation = "vnf-topology-operation";
         ServiceData serviceData;
         ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
@@ -1671,7 +1495,7 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
 
         try {
             if (svcLogicClient.hasGraph(VNF_API, svcOperation, null, "sync")) {
-                respProps =  svcLogicClient.execute(VNF_API, svcOperation, null, "sync", preloadDataBuilder, parms);
+                respProps = svcLogicClient.execute(VNF_API, svcOperation, null, "sync", preloadDataBuilder, parms);
             } else {
                 errorMessage = "No service logic active for VNF-API: '" + svcOperation + "'";
                 errorCode = "503";
@@ -1832,7 +1656,7 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
 
         try {
             if (svcLogicClient.hasGraph(VNF_API, svcOperation, null, "sync")) {
-              respProps = svcLogicClient.execute(VNF_API, svcOperation, null, "sync", preloadDataBuilder, parms);
+                respProps = svcLogicClient.execute(VNF_API, svcOperation, null, "sync", preloadDataBuilder, parms);
             } else {
                 errorMessage = "No service logic active for VNF-API: '" + svcOperation + "'";
                 errorCode = "503";
@@ -2018,7 +1842,8 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
 
         try {
             if (svcLogicClient.hasGraph(VNF_API, svcOperation, null, "sync")) {
-                respProps = svcLogicClient.execute(VNF_API, svcOperation, null, "sync", vnfInstancePreloadDataBuilder, parms);
+                respProps = svcLogicClient
+                    .execute(VNF_API, svcOperation, null, "sync", vnfInstancePreloadDataBuilder, parms);
             } else {
                 errorMessage = "No service logic active for VNF-API: '" + svcOperation + "'";
                 errorCode = "503";
@@ -2210,7 +2035,8 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
 
         try {
             if (svcLogicClient.hasGraph(VNF_API, svcOperation, null, "sync")) {
-                respProps = svcLogicClient.execute(VNF_API, svcOperation, null, "sync", vfModulePreloadDataBuilder, parms);
+                respProps = svcLogicClient
+                    .execute(VNF_API, svcOperation, null, "sync", vfModulePreloadDataBuilder, parms);
             } else {
                 errorMessage = "No service logic active for VNF-API: '" + svcOperation + "'";
                 errorCode = "503";
@@ -2353,7 +2179,6 @@ public class VnfApiProvider implements AutoCloseable, VNFAPIService, DataTreeCha
             return Futures.immediateFuture(rpcResult);
         }
 
-
         if (preloadType == null || preloadType.length() == 0) {
             log.debug(EXITING_STR + svcOperation + " because of invalid preload-type");
             responseBuilder.setResponseCode("403");