Remove DCAE call
[clamp.git] / src / main / java / org / onap / clamp / clds / service / CldsService.java
index cfea253..6da3cb6 100644 (file)
@@ -18,7 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END============================================
  * ===================================================================
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * 
  */
 
 package org.onap.clamp.clds.service;
@@ -214,27 +214,34 @@ public class CldsService extends SecureServiceBase {
     @GET
     @Path("/healthcheck")
     @Produces(MediaType.APPLICATION_JSON)
-    public CldsHealthCheck gethealthcheck() {
+    public Response gethealthcheck() {
         CldsHealthCheck cldsHealthCheck = new CldsHealthCheck();
         Date startTime = new Date();
-        LoggingUtils.setRequestContext("CldsService: GET healthcheck", getPrincipalName());
+        LoggingUtils.setRequestContext("CldsService: GET healthcheck", "Clamp-Health-Check");
         LoggingUtils.setTimeContext(startTime, new Date());
+        boolean healthcheckFailed = false;
         try {
             cldsDao.doHealthCheck();
             cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
             cldsHealthCheck.setHealthCheckStatus("UP");
             cldsHealthCheck.setDescription("OK");
+            LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName());
         } catch (Exception e) {
+            healthcheckFailed = true;
             logger.error("CLAMP application DB Error", e);
+            LoggingUtils.setResponseContext("999", "Get healthcheck failed", this.getClass().getName());
             cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
             cldsHealthCheck.setHealthCheckStatus("DOWN");
             cldsHealthCheck.setDescription("NOT-OK");
         }
         // audit log
         LoggingUtils.setTimeContext(startTime, new Date());
-        LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName());
-        securityLogger.info("GET healthcheck completed");
-        return cldsHealthCheck;
+        logger.info("GET healthcheck completed");
+        if (healthcheckFailed) {
+            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(cldsHealthCheck).build();
+        } else {
+            return Response.status(Response.Status.OK).entity(cldsHealthCheck).build();
+        }
     }
 
     /**
@@ -482,10 +489,16 @@ public class CldsService extends SecureServiceBase {
             if (!isTest && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT)
                     || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT)
                     || actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) {
-                // To verify inventory status and modify model status to
-                // distribute
-                dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
-                retrievedModel.save(cldsDao, getUserId());
+                if (retrievedModel.getDeploymentId() == null) {
+                    // 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());
+                } else {
+                    logger.info("Skipping DCAE inventory call as closed loop has been created from SDC notification");
+                }
             }
             // audit log
             LoggingUtils.setTimeContext(startTime, new Date());