Fix Sdc controller
[clamp.git] / src / main / java / org / onap / clamp / clds / service / CldsService.java
index ef78875..888b782 100644 (file)
@@ -36,7 +36,6 @@ import java.util.Date;
 import java.util.List;
 import java.util.Properties;
 import java.util.UUID;
-import java.util.concurrent.TimeUnit;
 
 import javax.annotation.PostConstruct;
 import javax.ws.rs.BadRequestException;
@@ -121,7 +120,6 @@ public class CldsService extends SecureServiceBase {
     private SecureServicePermission permissionUpdateCl;
     private SecureServicePermission permissionReadTemplate;
     private SecureServicePermission permissionUpdateTemplate;
-    private static final long DCAE_DEPLOY_WAITING_TIME = TimeUnit.SECONDS.toNanos(30);
 
     @PostConstruct
     private final void afterConstruction() {
@@ -491,18 +489,19 @@ public class CldsService extends SecureServiceBase {
                     || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT)
                     || actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) {
                 if (retrievedModel.getTemplateName().startsWith(CsarInstallerImpl.TEMPLATE_NAME_PREFIX)) {
-                    // This should be done only when the call to DCAE
-                    // has not yet been done. When CL comes from SDC
-                    // this is not required as the DCAE inventory call is done
-                    // during the CL deployment.
-                    dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
-                } else {
+                    // SDC artifact case
                     logger.info("Skipping DCAE inventory call as closed loop has been created from SDC notification");
                     DcaeEvent dcaeEvent = new DcaeEvent();
-                    dcaeEvent.setArtifactName("SDC artifact-" + retrievedModel.getName());
+                    dcaeEvent.setArtifactName(retrievedModel.getControlName() + ".yml");
                     dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);
                     CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(),
                             CldsEvent.ACTION_STATE_RECEIVED, null);
+                } else {
+                    // This should be done only when the call to DCAE
+                    // has not yet been done. When CL comes from SDC
+                    // this is not required as the DCAE inventory call is done
+                    // during the CL deployment.
+                    dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
                 }
                 retrievedModel.save(cldsDao, getUserId());
             }
@@ -848,17 +847,7 @@ public class CldsService extends SecureServiceBase {
             }
             String createNewDeploymentStatusUrl = dcaeDispatcherServices.createNewDeployment(deploymentId,
                     model.getTypeId(), modelProp.getGlobal().getDeployParameters());
-            String operationStatus = "processing";
-            long waitingTime = System.nanoTime() + DCAE_DEPLOY_WAITING_TIME;
-            while ("processing".equalsIgnoreCase(operationStatus)) {
-                if (waitingTime < System.nanoTime()) {
-                    logger.info("Waiting is over for DCAE deployment");
-                    break;
-                }
-                logger.info("Waiting 5s before sending query to DCAE");
-                Thread.sleep(5000);
-                operationStatus = dcaeDispatcherServices.getOperationStatus(createNewDeploymentStatusUrl);
-            }
+            String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(createNewDeploymentStatusUrl);
             if ("succeeded".equalsIgnoreCase(operationStatus)) {
                 String artifactName = model.getControlName();
                 if (artifactName != null) {
@@ -903,14 +892,7 @@ public class CldsService extends SecureServiceBase {
         try {
             String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(),
                     model.getTypeId());
-            String operationStatus = "processing";
-            long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10);
-            while ("processing".equalsIgnoreCase(operationStatus)) {
-                if (waitingTime < System.nanoTime()) {
-                    break;
-                }
-                operationStatus = dcaeDispatcherServices.getOperationStatus(operationStatusUndeployUrl);
-            }
+            String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(operationStatusUndeployUrl);
             if ("succeeded".equalsIgnoreCase(operationStatus)) {
                 String artifactName = model.getControlName();
                 if (artifactName != null) {