Code improvement

Improve logging message; Introduce timeout for deploy/undeploy CL;
Update allowed actions for deploy/undeploy/update action.

Issue-id: CLAMP-43
Change-Id: Ic876e835447cc495d4ca42d9401ee4bd503d5db7
Signed-off-by: xg353y <xg353y@intl.att.com>
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
index 343391e..e5144bf 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
@@ -129,25 +129,26 @@
      */

     public String getOperationStatus(String statusUrl) throws Exception {

 

-        String opStatus = null;

+        //Assigning processing status to monitor operation status further

+        String opStatus = "processing";

         InputStream in = null;

         try {

             URL obj = new URL(statusUrl);

             HttpsURLConnection conn = (HttpsURLConnection) obj.openConnection();

             conn.setRequestMethod("GET");

             int responseCode = conn.getResponseCode();

-            logger.debug("response code " + responseCode);

-            in = conn.getInputStream();

-            String res = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));

-            JSONParser parser = new JSONParser();

-            Object obj0 = parser.parse(res);

-            JSONObject jsonObj = (JSONObject) obj0;

-            String operationType = (String) jsonObj.get("operationType");

-            String status = (String) jsonObj.get("status");

-            logger.debug("Operation Type " + operationType);

-            logger.debug("Status " + status);

-            opStatus = status;

-

+            logger.debug("Deployment operation status response code - " + responseCode);

+            if(responseCode == 200){

+                in = conn.getInputStream();

+                String res = new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));

+                JSONParser parser = new JSONParser();

+                Object obj0 = parser.parse(res);

+                JSONObject jsonObj = (JSONObject) obj0;

+                String operationType = (String) jsonObj.get("operationType");

+                String status = (String) jsonObj.get("status");

+                logger.debug("Operation Type - " + operationType + ", Status " + status);

+                opStatus = status;

+            }

         } catch (Exception e) {

             logger.debug(e.getClass().getName() + " " + e.getMessage());

             logger.debug(e.getMessage()

diff --git a/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java b/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java
index a009f06..df86977 100644
--- a/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java
@@ -108,7 +108,7 @@
         } catch (Exception e) {
             LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());
             LoggingUtils.setErrorContext("900", "Get sdc services error");
-            logger.error("not able to get any service information from sdc for uuid:" + uuid);
+            logger.error("not able to get any service information from sdc for uuid:" + uuid + " , exception is - " + e.getMessage());
         }
         LoggingUtils.setTimeContext(startTime, new Date());
         LoggingUtils.setTargetContext("SDC", "Get Services");
diff --git a/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java b/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java
index 8a31a3b..08e196b 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java
@@ -143,6 +143,7 @@
 
         // "closedLoopControlName":"ClosedLoop-FRWL-SIG-0538e6f2-8c1b-4656-9999-3501b3c59ad7",
         configurationObjectNode.put("closedLoopControlName", prop.getControlName());
+        configurationObjectNode.put("messageReaderConsumerGroup", prop.getModelName());
         configurationObjectNode.set("serviceConfigurations", serviceConf);
         propsObject.put("deployment_JSON", deployJsonNode.toString());
         String blueprint = yaml.dump(loadedYaml);
diff --git a/src/main/java/org/onap/clamp/clds/model/CldsModel.java b/src/main/java/org/onap/clamp/clds/model/CldsModel.java
index e34f47d..59db9b5 100644
--- a/src/main/java/org/onap/clamp/clds/model/CldsModel.java
+++ b/src/main/java/org/onap/clamp/clds/model/CldsModel.java
@@ -243,17 +243,15 @@
                 permittedActionCd = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_RESUBMIT);
                 break;
             case CldsEvent.ACTION_UNDEPLOY:
-                permittedActionCd = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_DEPLOY);
+                permittedActionCd = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_RESUBMIT);
                 break;
             case CldsEvent.ACTION_DEPLOY:
-                permittedActionCd = Arrays.asList(CldsEvent.ACTION_UNDEPLOY, CldsEvent.ACTION_UPDATE,
-                        CldsEvent.ACTION_STOP);
+                permittedActionCd = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_UNDEPLOY, CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP);
                 break;
             case CldsEvent.ACTION_RESTART:
             case CldsEvent.ACTION_UPDATE:
                 // for 1702 delete is not currently implemented
-                permittedActionCd = Arrays.asList(CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP,
-                        CldsEvent.ACTION_UNDEPLOY);
+                permittedActionCd = Arrays.asList(CldsEvent.ACTION_DEPLOY, CldsEvent.ACTION_UPDATE, CldsEvent.ACTION_STOP, CldsEvent.ACTION_UNDEPLOY);
                 break;
             case CldsEvent.ACTION_DELETE:
                 if (getCurrentActionStateCd().equals(CldsEvent.ACTION_STATE_SENT)) {
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java
index aaeb03f..509535c 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java
@@ -32,6 +32,7 @@
 import java.util.Map;
 import java.util.Properties;
 import java.util.UUID;
+import java.util.concurrent.TimeUnit;
 
 import javax.annotation.PostConstruct;
 import javax.ws.rs.Consumes;
@@ -916,7 +917,12 @@
         String createNewDeploymentStatusUrl = dcaeDispatcherServices.createNewDeployment(deploymentId,
                 model.getTypeId());
         String operationStatus = "processing";
+        long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10);
         while (operationStatus.equalsIgnoreCase("processing")) {
+            //Break the loop if waiting for more than 10 mins
+            if(waitingTime < System.nanoTime()){
+                break;
+            }
             operationStatus = dcaeDispatcherServices.getOperationStatus(createNewDeploymentStatusUrl);
         }
         if (operationStatus != null && operationStatus.equalsIgnoreCase("succeeded")) {
@@ -956,7 +962,11 @@
         String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(),
                 model.getTypeId());
         String operationStatus = "processing";
+        long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10);
         while (operationStatus.equalsIgnoreCase("processing")) {
+            if(waitingTime < System.nanoTime()){
+                break;
+            }
             operationStatus = dcaeDispatcherServices.getOperationStatus(operationStatusUndeployUrl);
         }
         if (operationStatus != null && operationStatus.equalsIgnoreCase("succeeded")) {
diff --git a/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
index c474006..8ceaa3d 100644
--- a/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
+++ b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
@@ -35,21 +35,21 @@
 

     /**

      * Set request related logging variables in thread local data via MDC

-     * 

+     *

      * @param service

      *            Service Name of API (ex. "PUT template")

      * @param partner

      *            Partner name (client or user invoking API)

      */

     public static void setRequestContext(String service, String partner) {

-        MDC.put("RequestId", "clds-" + UUID.randomUUID().toString());

+        MDC.put("RequestId",  UUID.randomUUID().toString());

         MDC.put("ServiceName", service);

         MDC.put("PartnerName", partner);

     }

 

     /**

      * Set time related logging variables in thread local data via MDC

-     * 

+     *

      * @param beginTimeStamp

      *            Start time

      * @param endTimeStamp

diff --git a/src/main/resources/META-INF/processes.xml b/src/main/resources/META-INF/processes.xml
index fddc60d..bd3547d 100644
--- a/src/main/resources/META-INF/processes.xml
+++ b/src/main/resources/META-INF/processes.xml
@@ -33,5 +33,13 @@
 			<property name="isScanForProcessDefinitions">false</property>
 		</properties>
 	</process-archive>
+	<process-archive name="clds-process-archive">
+		<process-engine>default</process-engine>
+		<resource>bpmn/clds-process-action.bpmn</resource>
+		<properties>
+			<property name="isDeleteUponUndeploy">true</property>
+			<property name="isScanForProcessDefinitions">false</property>
+		</properties>
+	</process-archive>
 
 </process-application>
diff --git a/src/main/resources/clds/globalClds.properties b/src/main/resources/clds/globalClds.properties
index 3402db3..f6607cb 100644
--- a/src/main/resources/clds/globalClds.properties
+++ b/src/main/resources/clds/globalClds.properties
@@ -21,4 +21,4 @@
 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
 ###
 
-globalCldsProps ={"collector":{"topicPublishes":{"DCAE-COLLECTOR-UCSNMP":"DCAE-COLLECTOR-UCSNMP"}},"string_match":{"topicPublishes":{"DCAE-CL-EVENT":"DCAE-CL-EVENT"},"aaiMatchingFields":{"cloud-region.identity-url":"cloud-region.identity-url","complex.city":"complex.city","complex.physical-location-id":"complex.physical-location-id","complex.state":"complex.state","generic-vnf.service-id":"generic-vnf.service-id","generic-vnf.vnf-name":"generic-vnf.vnf-name","generic-vnf.vnf-type":"generic-vnf.vnf-type","tenant.tenant-id":"tenant.tenant-id","vserver.in-maint":"vserver.in-maint","vserver.is-closed-loop-disabled":"vserver.is-closed-loop-disabled","vserver.l-interface.interface-name":"vserver.l-interface.interface-name","vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address":"vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address","vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address":"vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address","vserver.l-interface.network-name":"vserver.l-interface.network-name","vserver.prov-status":"vserver.prov-status","vserver.selflink":"vserver.selflink","vserver.vserver-id":"vserver.vserver-id","vserver.vserver-name":"vserver.vserver-name"},"aaiSendFields":{"cloud-region.identity-url":"cloud-region.identity-url","complex.city":"complex.city","complex.physical-location-id":"complex.physical-location-id","complex.state":"complex.state","generic-vnf.service-id":"generic-vnf.service-id","generic-vnf.vnf-name":"generic-vnf.vnf-name","generic-vnf.vnf-type":"generic-vnf.vnf-type","tenant.tenant-id":"tenant.tenant-id","vserver.in-maint":"vserver.in-maint","vserver.is-closed-loop-disabled":"vserver.is-closed-loop-disabled","vserver.l-interface.interface-name":"vserver.l-interface.interface-name","vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address":"vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address","vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address":"vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address","vserver.l-interface.network-name":"vserver.l-interface.network-name","vserver.prov-status":"vserver.prov-status","vserver.selflink":"vserver.selflink","vserver.vserver-id":"vserver.vserver-id","vserver.vserver-name":"vserver.vserver-name"},"eventSourceType":{"f5BigIP":"f5BigIP","vSBG_Alarms":"vSBG_Alarms","vCTS_Alarms":"vCTS_Alarms"},"eventSeverity":{"NORMAL":"NORMAL","not-NORMAL":"not-NORMAL","OK":"OK","WARNING":"WARNING","MINOR":"MINOR","MAJOR":"MAJOR","CRITICAL":"CRITICAL"},"timeWindow":0,"ageLimit":1600,"outputEventName":{"":"","ONSET":"ONSET","ABATED":"ABATED"},"createClosedLoopEventId":{"Initial":"Initial","Close":"Close"}},"tca":{"tname":"New_Set","tcaInt":"1","tcaVio":"1","tcaSev":{"Normal":"Normal","Critical":"Critical","Major":"Major","Minor":"Minor","Warning":"Warning"},"fieldPath":{"FIELDPATH_test_1":"FIELDPATH_test_1","FIELDPATH_test_2":"FIELDPATH_test_2"},"operator":{">":"GREATER","=":"EQUAL","<":"LESS"},"opsPolicy":{"POLICY_test_X":"POLICY_test_X","POLICY_test_Y":"POLICY_test_Y"}},"global":{"actionSet":{"vnfRecipe":"VNF", "enbRecipe":"eNodeB"},"location":{"SNDGCA64":"San Diego SAN3","ALPRGAED":"Alpharetta PDK1","LSLEILAA":"Lisle DPA3","MDTWNJC1":"FTL_C_location1","MDTWNJC2":"FTL_C_location2","MDTWNJ21":"FTL_L_location1","MDTWNJ22":"FTL_L_location2","RDM2WAGPLCP":"ISTFTL_location","RDM3":"RDM3WAGPLCP"}},"policy":{"pname":"0","timeout":345,"vnfRecipe":{"":"","restart":"Restart","rebuild":"Rebuild","migrate":"Migrate","healthCheck":"Health Check"},"enbRecipe":{"":"","reset":"Reset"},"maxRetries":"3","retryTimeLimit":180,"resource":{"vCTS":"vCTS","v3CDB":"v3CDB","vUDR":"vUDR","vCOM":"vCOM","vRAR":"vRAR","vLCS":"vLCS","vUDR-BE":"vUDR-BE","vDBE":"vDBE"},"parentPolicyConditions":{"Failure_Retries":"Failure: Max Retries Exceeded","Failure_Timeout":"Failure: Time Limit Exceeded","Failure_Guard":"Failure: Guard","Failure_Exception":"Failure: Exception","Failure":"Failure: Other","Success":"Success"}},"shared":{"byService":{"":{"vf":{"":""},"location":{"":""},"alarmCondition":{"":""}}},"byVf":{"":{"vfc":{"":""}}}}}
\ No newline at end of file
+globalCldsProps ={"collector":{"topicPublishes":{"DCAE-COLLECTOR-UCSNMP":"DCAE-COLLECTOR-UCSNMP"}},"string_match":{"topicPublishes":{"DCAE-CL-EVENT":"DCAE-CL-EVENT"},"aaiMatchingFields":{"cloud-region.identity-url":"cloud-region.identity-url","complex.city":"complex.city","complex.physical-location-id":"complex.physical-location-id","complex.state":"complex.state","generic-vnf.service-id":"generic-vnf.service-id","generic-vnf.vnf-name":"generic-vnf.vnf-name","generic-vnf.vnf-type":"generic-vnf.vnf-type","tenant.tenant-id":"tenant.tenant-id","vserver.in-maint":"vserver.in-maint","vserver.is-closed-loop-disabled":"vserver.is-closed-loop-disabled","vserver.l-interface.interface-name":"vserver.l-interface.interface-name","vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address":"vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address","vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address":"vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address","vserver.l-interface.network-name":"vserver.l-interface.network-name","vserver.prov-status":"vserver.prov-status","vserver.selflink":"vserver.selflink","vserver.vserver-id":"vserver.vserver-id","vserver.vserver-name":"vserver.vserver-name"},"aaiSendFields":{"cloud-region.identity-url":"cloud-region.identity-url","complex.city":"complex.city","complex.physical-location-id":"complex.physical-location-id","complex.state":"complex.state","generic-vnf.service-id":"generic-vnf.service-id","generic-vnf.vnf-name":"generic-vnf.vnf-name","generic-vnf.vnf-type":"generic-vnf.vnf-type","tenant.tenant-id":"tenant.tenant-id","vserver.in-maint":"vserver.in-maint","vserver.is-closed-loop-disabled":"vserver.is-closed-loop-disabled","vserver.l-interface.interface-name":"vserver.l-interface.interface-name","vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address":"vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address","vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address":"vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address","vserver.l-interface.network-name":"vserver.l-interface.network-name","vserver.prov-status":"vserver.prov-status","vserver.selflink":"vserver.selflink","vserver.vserver-id":"vserver.vserver-id","vserver.vserver-name":"vserver.vserver-name"},"eventSourceType":{"f5BigIP":"f5BigIP","vSBG_Alarms":"vSBG_Alarms","vCTS_Alarms":"vCTS_Alarms"},"eventSeverity":{"NORMAL":"NORMAL","not-NORMAL":"not-NORMAL","OK":"OK","WARNING":"WARNING","MINOR":"MINOR","MAJOR":"MAJOR","CRITICAL":"CRITICAL"},"timeWindow":0,"ageLimit":1600,"outputEventName":{"":"","ONSET":"ONSET","ABATED":"ABATED"},"createClosedLoopEventId":{"Initial":"Initial","Close":"Close"}},"tca":{"tname":"New_Set","tcaInt":"1","tcaVio":"1","tcaSev":{"NORMAL":"NORMAL","CRITICAL":"CRITICAL","MAJOR":"MAJOR","MINOR":"MINOR","WARNING":"WARNING"},"fieldPath":{"FIELDPATH_test_1":"FIELDPATH_test_1","FIELDPATH_test_2":"FIELDPATH_test_2"},"operator":{">":"GREATER","=":"EQUAL","<":"LESS"},"opsPolicy":{"POLICY_test_X":"POLICY_test_X","POLICY_test_Y":"POLICY_test_Y"}},"global":{"actionSet":{"vnfRecipe":"VNF", "enbRecipe":"eNodeB"},"location":{"SNDGCA64":"San Diego SAN3","ALPRGAED":"Alpharetta PDK1","LSLEILAA":"Lisle DPA3","MDTWNJC1":"FTL_C_location1","MDTWNJC2":"FTL_C_location2","MDTWNJ21":"FTL_L_location1","MDTWNJ22":"FTL_L_location2","RDM2WAGPLCP":"ISTFTL_location","RDM3":"RDM3WAGPLCP"}},"policy":{"pname":"0","timeout":345,"vnfRecipe":{"":"","restart":"Restart","rebuild":"Rebuild","migrate":"Migrate","healthCheck":"Health Check"},"enbRecipe":{"":"","reset":"Reset"},"maxRetries":"3","retryTimeLimit":180,"resource":{"vCTS":"vCTS","v3CDB":"v3CDB","vUDR":"vUDR","vCOM":"vCOM","vRAR":"vRAR","vLCS":"vLCS","vUDR-BE":"vUDR-BE","vDBE":"vDBE"},"parentPolicyConditions":{"Failure_Retries":"Failure: Max Retries Exceeded","Failure_Timeout":"Failure: Time Limit Exceeded","Failure_Guard":"Failure: Guard","Failure_Exception":"Failure: Exception","Failure":"Failure: Other","Success":"Success"}},"shared":{"byService":{"":{"vf":{"":""},"location":{"":""},"alarmCondition":{"":""}}},"byVf":{"":{"vfc":{"":""}}}}}
\ No newline at end of file