Removal of useless files & bugfix
[clamp.git] / src / main / java / org / onap / clamp / clds / service / CldsService.java
index a0aadcc..19e3caa 100644 (file)
@@ -5,16 +5,16 @@
  * Copyright (C) 2017 AT&T Intellectual Property. All rights
  *                             reserved.
  * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); 
- * you may not use this file except in compliance with the License. 
+ * 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. 
- * See the License for the specific language governing permissions and 
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END============================================
  * ===================================================================
 package org.onap.clamp.clds.service;
 
 import com.att.ajsc.common.AjscService;
-import com.att.ajsc.filemonitor.AJSCPropertiesMap;
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+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;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.NotAuthorizedException;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.xml.transform.TransformerException;
+
+import org.apache.commons.lang3.StringUtils;
+import org.camunda.bpm.engine.RuntimeService;
+import org.camunda.bpm.engine.runtime.ProcessInstance;
+import org.json.simple.parser.ParseException;
+import org.onap.clamp.clds.client.DcaeDispatcherServices;
+import org.onap.clamp.clds.client.DcaeInventoryServices;
 import org.onap.clamp.clds.client.SdcCatalogServices;
 import org.onap.clamp.clds.dao.CldsDao;
+import org.onap.clamp.clds.exception.CldsConfigException;
+import org.onap.clamp.clds.exception.SdcCommunicationException;
+import org.onap.clamp.clds.model.CldsDBServiceCache;
+import org.onap.clamp.clds.model.CldsEvent;
+import org.onap.clamp.clds.model.CldsHealthCheck;
+import org.onap.clamp.clds.model.CldsInfo;
+import org.onap.clamp.clds.model.CldsModel;
+import org.onap.clamp.clds.model.CldsSdcResource;
+import org.onap.clamp.clds.model.CldsSdcServiceDetail;
+import org.onap.clamp.clds.model.CldsSdcServiceInfo;
+import org.onap.clamp.clds.model.CldsServiceData;
+import org.onap.clamp.clds.model.CldsTemplate;
+import org.onap.clamp.clds.model.DcaeEvent;
+import org.onap.clamp.clds.model.ValueItem;
 import org.onap.clamp.clds.model.prop.ModelProperties;
 import org.onap.clamp.clds.model.refprop.RefProp;
 import org.onap.clamp.clds.transform.XslTransformer;
-import org.apache.commons.lang3.StringUtils;
-import org.camunda.bpm.engine.RuntimeService;
-import org.camunda.bpm.engine.runtime.ProcessInstance;
-import org.jboss.resteasy.spi.BadRequestException;
-import org.onap.clamp.clds.model.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.onap.clamp.clds.util.LoggingUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ApplicationContext;
-import org.springframework.core.io.Resource;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.client.HttpClientErrorException;
 
-import javax.ws.rs.*;
-import javax.ws.rs.core.MediaType;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 
 /**
  * Service to save and retrieve the CLDS model attributes.
  */
 @AjscService
+@Api(value = "/clds")
 @Path("/clds")
 public class CldsService extends SecureServiceBase {
 
     @Autowired
-    private ApplicationContext appContext;
+    private ApplicationContext      appContext;
+
+    private static final String     RESOURCE_NAME = "clds-version.properties";
+
+    @Value("${CLDS_PERMISSION_TYPE_CL:permission-type-cl}")
+    private String                  cldsPersmissionTypeCl;
+
+    @Value("${CLDS_PERMISSION_TYPE_CL_MANAGE:permission-type-cl-manage}")
+    private String                  cldsPermissionTypeClManage;
 
-    private static final Logger logger = LoggerFactory.getLogger(CldsService.class);
+    @Value("${CLDS_PERMISSION_TYPE_CL_EVENT:permission-type-cl-event}")
+    private String                  cldsPermissionTypeClEvent;
 
-    @Value("${CLDS_PERMISSION_TYPE_CL:org.onap.clamp.clds.cl}")
-    private static String CLDS_PERMISSION_TYPE_CL;
+    @Value("${CLDS_PERMISSION_TYPE_FILTER_VF:permission-type-filter-vf}")
+    private String                  cldsPermissionTypeFilterVf;
 
-    @Value("${CLDS_PERMISSION_TYPE_CL_MANAGE:org.onap.clamp.clds.cl.manage}")
-    private static String CLDS_PERMISSION_TYPE_CL_MANAGE;
+    @Value("${CLDS_PERMISSION_TYPE_TEMPLATE:permission-type-template}")
+    private String                  cldsPermissionTypeTemplate;
 
-    @Value("${CLDS_PERMISSION_TYPE_CL_EVENT:/META-INF/securityFilterRules.json}")
-    private static String CLDS_PERMISSION_TYPE_CL_EVENT;
+    @Value("${CLDS_PERMISSION_INSTANCE:dev}")
+    private String                  cldsPermissionInstance;
 
-    @Value("${CLDS_PERMISSION_TYPE_FILTER_VF:/META-INF/securityFilterRules.json}")
-    private static String CLDS_PERMISSION_TYPE_FILTER_VF;
+    private SecureServicePermission permissionReadCl;
 
-    @Value("${CLDS_PERMISSION_INSTANCE:/META-INF/securityFilterRules.json}")
-    private static String CLDS_PERMISSION_INSTANCE;
+    private SecureServicePermission permissionUpdateCl;
 
-    private static final SecureServicePermission PERMISSION_READ_CL = SecureServicePermission.create(CLDS_PERMISSION_TYPE_CL, CLDS_PERMISSION_INSTANCE, "read");
+    private SecureServicePermission permissionReadTemplate;
+
+    private SecureServicePermission permissionUpdateTemplate;
+
+    @PostConstruct
+    private final void afterConstruction() {
+        permissionReadCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "read");
+        permissionUpdateCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "update");
+        permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance,
+                "read");
+        permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance,
+                "update");
+    }
 
-    private static final SecureServicePermission PERMISSION_UPDATE_CL = SecureServicePermission.create(CLDS_PERMISSION_TYPE_CL, CLDS_PERMISSION_INSTANCE, "update");
+    @Value("${org.onap.clamp.config.files.globalClds:'classpath:/clds/globalClds.properties'}")
+    private String                 globalClds;
 
-    @Value("${org.onap.clamp.config.files.globalClds:classpath:/clds/globalClds.properties}")
-    private String globalClds;
-    private Properties globalCldsProperties;
+    private Properties             globalCldsProperties;
 
     @Autowired
-    private CldsDao cldsDao;
+    private CldsDao                cldsDao;
     @Autowired
-    private RuntimeService runtimeService;
+    private RuntimeService         runtimeService;
     @Autowired
-    private XslTransformer cldsBpmnTransformer;
+    private XslTransformer         cldsBpmnTransformer;
 
     @Autowired
-    private RefProp refProp;
+    private RefProp                refProp;
 
     @Autowired
-    private SdcCatalogServices asdcCatalogServices;
-    //
+    private SdcCatalogServices     sdcCatalogServices;
+
+    @Autowired
+    private DcaeDispatcherServices dcaeDispatcherServices;
+
+    @Autowired
+    private DcaeInventoryServices  dcaeInventoryServices;
 
     public CldsService() {
     }
@@ -112,79 +167,167 @@ public class CldsService extends SecureServiceBase {
         this.refProp = refProp;
     }
 
+    /*
+     *
+     * CLDS IFO service will return 3 things 1. User Name 2. CLDS code version
+     * that is currently installed from pom.xml file 3. User permissions
+     *
+     */
+
+    @GET
+    @Path("/cldsInfo")
+    @Produces(MediaType.APPLICATION_JSON)
+    public CldsInfo getCldsInfo() {
+
+        CldsInfo cldsInfo = new CldsInfo();
+
+        // Get the user info
+        cldsInfo.setUserName(getUserName());
+
+        // Get CLDS application version
+        String cldsVersion = "";
+        Properties props = new Properties();
+
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+        try (InputStream resourceStream = loader.getResourceAsStream(RESOURCE_NAME)) {
+            props.load(resourceStream);
+            cldsVersion = props.getProperty("clds.version");
+        } catch (Exception ex) {
+            logger.error("Exception caught during the clds.version reading", ex);
+        }
+        cldsInfo.setCldsVersion(cldsVersion);
+
+        // Get the user list of permissions
+        cldsInfo.setPermissionReadCl(isAuthorizedNoException(permissionReadCl));
+        cldsInfo.setPermissionUpdateCl(isAuthorizedNoException(permissionUpdateCl));
+        cldsInfo.setPermissionReadTemplate(isAuthorizedNoException(permissionReadTemplate));
+        cldsInfo.setPermissionUpdateTemplate(isAuthorizedNoException(permissionUpdateTemplate));
+        return cldsInfo;
+    }
+
+    @GET
+    @Path("/healthcheck")
+    @Produces(MediaType.APPLICATION_JSON)
+    public CldsHealthCheck gethealthcheck() {
+
+        CldsHealthCheck cldsHealthCheck = new CldsHealthCheck();
+
+        try {
+            cldsDao.doHealthCheck();
+            cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
+            cldsHealthCheck.setHealthCheckStatus("UP");
+            cldsHealthCheck.setDescription("OK");
+        } catch (Exception e) {
+            logger.error("CLAMP application DB Error", e);
+            cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
+            cldsHealthCheck.setHealthCheckStatus("DOWN");
+            cldsHealthCheck.setDescription("NOT-OK");
+        }
+        return cldsHealthCheck;
+
+    }
+
     /**
      * REST service that retrieves BPMN for a CLDS model name from the database.
-     * This is subset of the json getModel.
-     * This is only expected to be used for testing purposes, not by the UI.
+     * This is subset of the json getModel. This is only expected to be used for
+     * testing purposes, not by the UI.
      *
      * @param modelName
      * @return bpmn xml text - content of bpmn given name
      */
+    @ApiOperation(value = "Retrieves BPMN for a CLDS model name from the database", notes = "This is only expected to be used for testing purposes, not by the UI", response = String.class)
     @GET
     @Path("/model/bpmn/{modelName}")
     @Produces(MediaType.TEXT_XML)
     public String getBpmnXml(@PathParam("modelName") String modelName) {
-        isAuthorized(PERMISSION_READ_CL);
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: GET model bpmn", getPrincipalName());
+        isAuthorized(permissionReadCl);
         logger.info("GET bpmnText for modelName={}", modelName);
         CldsModel model = CldsModel.retrieve(cldsDao, modelName, false);
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Get model bpmn success", this.getClass().getName());
+        auditLogger.info("GET model bpmn completed");
         return model.getBpmnText();
     }
 
     /**
      * REST service that saves BPMN for a CLDS model by name in the database.
-     * This is subset of the json putModel.
-     * This is only expected to be used for testing purposes, not by the UI.
+     * This is subset of the json putModel. This is only expected to be used for
+     * testing purposes, not by the UI.
      *
      * @param modelName
      */
+    @ApiOperation(value = "Saves BPMN for a CLDS model by name in the database", notes = "This is only expected to be used for testing purposes, not by the UI", response = String.class)
     @PUT
     @Path("/model/bpmn/{modelName}")
     @Consumes(MediaType.TEXT_XML)
     public String putBpmnXml(@PathParam("modelName") String modelName, String bpmnText) {
-        isAuthorized(PERMISSION_UPDATE_CL);
+        LoggingUtils.setRequestContext("CldsService: PUT model bpmn", getPrincipalName());
+        isAuthorized(permissionUpdateCl);
         logger.info("PUT bpmnText for modelName={}", modelName);
         logger.info("PUT bpmnText={}", bpmnText);
         CldsModel cldsModel = CldsModel.retrieve(cldsDao, modelName, true);
         cldsModel.setBpmnText(bpmnText);
-        cldsModel.save(cldsDao, getUserid());
+        cldsModel.save(cldsDao, getUserId());
+        // audit log
+        LoggingUtils.setTimeContext(new Date(), new Date());
+        LoggingUtils.setResponseContext("0", "Put model bpmn success", this.getClass().getName());
+        auditLogger.info("PUT model bpmn completed");
         return "wrote bpmnText for modelName=" + modelName;
     }
 
     /**
-     * REST service that retrieves image for a CLDS model name from the database.
-     * This is subset of the json getModel.
-     * This is only expected to be used for testing purposes, not by the UI.
+     * REST service that retrieves image for a CLDS model name from the
+     * database. This is subset of the json getModel. This is only expected to
+     * be used for testing purposes, not by the UI.
      *
      * @param modelName
      * @return image xml text - content of image given name
      */
+    @ApiOperation(value = "Retrieves image for a CLDS model name from the database", notes = "This is only expected to be used for testing purposes, not by the UI", response = String.class)
     @GET
     @Path("/model/image/{modelName}")
     @Produces(MediaType.TEXT_XML)
     public String getImageXml(@PathParam("modelName") String modelName) {
-        isAuthorized(PERMISSION_READ_CL);
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: GET model image", getPrincipalName());
+        isAuthorized(permissionReadCl);
         logger.info("GET imageText for modelName={}", modelName);
         CldsModel model = CldsModel.retrieve(cldsDao, modelName, false);
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Get model image success", this.getClass().getName());
+        auditLogger.info("GET model image completed");
         return model.getImageText();
     }
 
     /**
      * REST service that saves image for a CLDS model by name in the database.
-     * This is subset of the json putModel.
-     * This is only expected to be used for testing purposes, not by the UI.
+     * This is subset of the json putModel. This is only expected to be used for
+     * testing purposes, not by the UI.
      *
      * @param modelName
      */
+    @ApiOperation(value = "Saves image for a CLDS model by name in the database", notes = "This is only expected to be used for testing purposes, not by the UI", response = String.class)
     @PUT
     @Path("/model/image/{modelName}")
     @Consumes(MediaType.TEXT_XML)
     public String putImageXml(@PathParam("modelName") String modelName, String imageText) {
-        isAuthorized(PERMISSION_UPDATE_CL);
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: PUT model image", getPrincipalName());
+        isAuthorized(permissionUpdateCl);
         logger.info("PUT iamgeText for modelName={}", modelName);
         logger.info("PUT imageText={}", imageText);
         CldsModel cldsModel = CldsModel.retrieve(cldsDao, modelName, true);
         cldsModel.setImageText(imageText);
-        cldsModel.save(cldsDao, getUserid());
+        cldsModel.save(cldsDao, getUserId());
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Put model image success", this.getClass().getName());
+        auditLogger.info("PUT model image completed");
         return "wrote imageText for modelName=" + modelName;
     }
 
@@ -193,16 +336,39 @@ public class CldsService extends SecureServiceBase {
      *
      * @param modelName
      * @return clds model - clds model for the given model name
-     * @throws NotAuthorizedException
      */
+    @ApiOperation(value = "Retrieves a CLDS model by name from the database", notes = "", response = String.class)
     @GET
     @Path("/model/{modelName}")
     @Produces(MediaType.APPLICATION_JSON)
-    public CldsModel getModel(@PathParam("modelName") String modelName) throws NotAuthorizedException {
-        isAuthorized(PERMISSION_READ_CL);
+    public CldsModel getModel(@PathParam("modelName") String modelName) {
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: GET model", getPrincipalName());
+        isAuthorized(permissionReadCl);
         logger.debug("GET model for  modelName={}", modelName);
         CldsModel cldsModel = CldsModel.retrieve(cldsDao, modelName, false);
         isAuthorizedForVf(cldsModel);
+        cldsModel.setUserAuthorizedToUpdate(isAuthorizedNoException(permissionUpdateCl));
+
+        /**
+         * Checking condition whether our CLDS model can call INventory Method
+         */
+        if (cldsModel.canInventoryCall()) {
+            try {
+                /*
+                 * Below is the method to for inventory call and DB insert for
+                 * event methods
+                 */
+                dcaeInventoryServices.setEventInventory(cldsModel, getUserId());
+            } catch (Exception e) {
+                LoggingUtils.setErrorContext("900", "Set event inventory error");
+                logger.error("getModel set event Inventory error:" + e);
+            }
+        }
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Get model success", this.getClass().getName());
+        auditLogger.info("GET model completed");
         return cldsModel;
     }
 
@@ -210,15 +376,16 @@ public class CldsService extends SecureServiceBase {
      * REST service that saves a CLDS model by name in the database.
      *
      * @param modelName
-     * @throws TransformerException
-     * @throws TransformerConfigurationException
      */
+    @ApiOperation(value = "Saves a CLDS model by name in the database", notes = "", response = String.class)
     @PUT
     @Path("/model/{modelName}")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
-    public CldsModel putModel(@PathParam("modelName") String modelName, CldsModel cldsModel) throws TransformerException {
-        isAuthorized(PERMISSION_UPDATE_CL);
+    public CldsModel putModel(@PathParam("modelName") String modelName, CldsModel cldsModel) {
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: PUT model", getPrincipalName());
+        isAuthorized(permissionUpdateCl);
         isAuthorizedForVf(cldsModel);
         logger.info("PUT model for  modelName={}", modelName);
         logger.info("PUT bpmnText={}", cldsModel.getBpmnText());
@@ -234,7 +401,11 @@ public class CldsService extends SecureServiceBase {
                 cldsModel.setDocId(template.getPropId());
             }
         }
-        cldsModel.save(cldsDao, getUserid());
+        cldsModel.save(cldsDao, getUserId());
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Put model success", this.getClass().getName());
+        auditLogger.info("PUT model completed");
         return cldsModel;
     }
 
@@ -243,13 +414,21 @@ public class CldsService extends SecureServiceBase {
      *
      * @return model names in JSON
      */
+    @ApiOperation(value = "Retrieves a list of CLDS model names", notes = "", response = String.class)
     @GET
     @Path("/model-names")
     @Produces(MediaType.APPLICATION_JSON)
     public List<ValueItem> getModelNames() {
-//             isAuthorized(PERMISSION_READ_CL);
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: GET model names", getPrincipalName());
+        isAuthorized(permissionReadCl);
         logger.info("GET list of model names");
-        return cldsDao.getBpmnNames();
+        List<ValueItem> names = cldsDao.getBpmnNames();
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Get model names success", this.getClass().getName());
+        auditLogger.info("GET model names completed");
+        return names;
     }
 
     /**
@@ -260,22 +439,25 @@ public class CldsService extends SecureServiceBase {
      * @param test
      * @param model
      * @return
-     * @throws TransformerConfigurationException
      * @throws TransformerException
-     * @throws IOException
-     * @throws JsonProcessingException
-     * @throws NotAuthorizedException
+     * @throws ParseException
      */
+    @ApiOperation(value = "Saves and processes an action for a CLDS model by name", notes = "", response = String.class)
     @PUT
     @Path("/action/{action}/{modelName}")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
-    public CldsModel putModelAndProcessAction(@PathParam("action") String action, @PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model) throws TransformerException, NotAuthorizedException, IOException {
+    public CldsModel putModelAndProcessAction(@PathParam("action") String action,
+            @PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model)
+            throws TransformerException, ParseException {
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: Process model action", getPrincipalName());
         String actionCd = action.toUpperCase();
-        SecureServicePermission permisionManage = SecureServicePermission.create(CLDS_PERMISSION_TYPE_CL_MANAGE, CLDS_PERMISSION_INSTANCE, actionCd);
+        SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage,
+                cldsPermissionInstance, actionCd);
         isAuthorized(permisionManage);
         isAuthorizedForVf(model);
-        String userid = getUserid();
+        String userid = getUserId();
         String actionStateCd = CldsEvent.ACTION_STATE_INITIATED;
         String processDefinitionKey = "clds-process-action-wf";
 
@@ -287,6 +469,8 @@ public class CldsService extends SecureServiceBase {
         logger.info("PUT bpmnText={}", model.getBpmnText());
         logger.info("PUT propText={}", model.getPropText());
         logger.info("PUT userid={}", userid);
+        logger.info("PUT getTypeId={}", model.getTypeId());
+        logger.info("PUT deploymentId={}", model.getDeploymentId());
 
         if (model.getTemplateName() != null) {
             CldsTemplate template = cldsDao.getTemplate(model.getTemplateName());
@@ -298,7 +482,7 @@ public class CldsService extends SecureServiceBase {
         }
         // save model to db
         model.setName(modelName);
-        model.save(cldsDao, getUserid());
+        model.save(cldsDao, getUserId());
 
         // get vars and format if necessary
         String prop = model.getPropText();
@@ -309,11 +493,12 @@ public class CldsService extends SecureServiceBase {
         String bpmnJson = cldsBpmnTransformer.doXslTransformToString(bpmn);
         logger.info("PUT bpmnJson={}", bpmnJson);
 
+        // Flag indicates whether it is triggered by Validation Test button from
+        // UI
         boolean isTest = false;
         if (test != null && test.equalsIgnoreCase("true")) {
             isTest = true;
         } else {
-            // if action.test.override is true, then any action will be marked as test=true (even if incoming action request had test=false); otherwise, test flag will be unchanged on the action request
             String actionTestOverride = refProp.getStringValue("action.test.override");
             if (actionTestOverride != null && actionTestOverride.equalsIgnoreCase("true")) {
                 logger.info("PUT actionTestOverride={}", actionTestOverride);
@@ -323,7 +508,6 @@ public class CldsService extends SecureServiceBase {
         }
         logger.info("PUT isTest={}", isTest);
 
-
         boolean isInsertTestEvent = false;
         String insertTestEvent = refProp.getStringValue("action.insert.test.event");
         if (insertTestEvent != null && insertTestEvent.equalsIgnoreCase("true")) {
@@ -331,30 +515,45 @@ public class CldsService extends SecureServiceBase {
         }
         logger.info("PUT isInsertTestEvent={}", isInsertTestEvent);
 
-
         // determine if requested action is permitted
         model.validateAction(actionCd);
 
         // input variables to camunda process
         Map<String, Object> variables = new HashMap<>();
         variables.put("actionCd", actionCd);
-        variables.put("modelProp", prop);
+        variables.put("modelProp", prop.getBytes());
         variables.put("modelBpmnProp", bpmnJson);
         variables.put("modelName", modelName);
         variables.put("controlName", controlName);
-        variables.put("docText", docText);
+        variables.put("docText", docText.getBytes());
         variables.put("isTest", isTest);
         variables.put("userid", userid);
         variables.put("isInsertTestEvent", isInsertTestEvent);
+        logger.info("modelProp - " + prop);
+        logger.info("docText - " + docText);
 
         // start camunda process
         ProcessInstance pi = runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);
 
         // log process info
-        logger.info("Started processDefinitionId={}, processInstanceId={}", pi.getProcessDefinitionId(), pi.getProcessInstanceId());
+        logger.info("Started processDefinitionId={}, processInstanceId={}", pi.getProcessDefinitionId(),
+                pi.getProcessInstanceId());
 
         // refresh model info from db (get fresh event info)
-        return CldsModel.retrieve(cldsDao, modelName, false);
+        CldsModel retreivedModel = CldsModel.retrieve(cldsDao, modelName, false);
+
+        if (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT)
+                || actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT)) {
+            // To verify inventory status and modify model status to distribute
+            dcaeInventoryServices.setEventInventory(retreivedModel, getUserId());
+            retreivedModel.save(cldsDao, getUserId());
+        }
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Process model action success", this.getClass().getName());
+        auditLogger.info("Process model action completed");
+
+        return retreivedModel;
     }
 
     /**
@@ -362,21 +561,27 @@ public class CldsService extends SecureServiceBase {
      *
      * @param test
      * @param dcaeEvent
-     * @throws BadRequestException
      */
+    @ApiOperation(value = "Accepts events for a model", notes = "", response = String.class)
     @POST
     @Path("/dcae/event")
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces(MediaType.APPLICATION_JSON)
-    public String postDcaeEvent(@QueryParam("test") String test, DcaeEvent dcaeEvent) throws BadRequestException {
+    public String postDcaeEvent(@QueryParam("test") String test, DcaeEvent dcaeEvent) {
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: Post dcae event", getPrincipalName());
         String userid = null;
-        // TODO: allow auth checking to be turned off by removing the permission type property
-        if (CLDS_PERMISSION_TYPE_CL_EVENT != null && CLDS_PERMISSION_TYPE_CL_EVENT.length() > 0) {
-            SecureServicePermission permissionEvent = SecureServicePermission.create(CLDS_PERMISSION_TYPE_CL_EVENT, CLDS_PERMISSION_INSTANCE, dcaeEvent.getEvent());
+        // TODO: allow auth checking to be turned off by removing the permission
+        // type property
+        if (cldsPermissionTypeClEvent != null && cldsPermissionTypeClEvent.length() > 0) {
+            SecureServicePermission permissionEvent = SecureServicePermission.create(cldsPermissionTypeClEvent,
+                    cldsPermissionInstance, dcaeEvent.getEvent());
             isAuthorized(permissionEvent);
-            userid = getUserid();
+            userid = getUserId();
         }
 
+        // Flag indicates whether it is triggered by Validation Test button from
+        // UI
         boolean isTest = false;
         if (test != null && test.equalsIgnoreCase("true")) {
             isTest = true;
@@ -386,7 +591,9 @@ public class CldsService extends SecureServiceBase {
         if (dcaeEvent.getInstances() != null) {
             instanceCount = dcaeEvent.getInstances().size();
         }
-        String msgInfo = "event=" + dcaeEvent.getEvent() + " serviceUUID=" + dcaeEvent.getServiceUUID() + " resourceUUID=" + dcaeEvent.getResourceUUID() + " artifactName=" + dcaeEvent.getArtifactName() + " instance count=" + instanceCount + " isTest=" + isTest;
+        String msgInfo = "event=" + dcaeEvent.getEvent() + " serviceUUID=" + dcaeEvent.getServiceUUID()
+                + " resourceUUID=" + dcaeEvent.getResourceUUID() + " artifactName=" + dcaeEvent.getArtifactName()
+                + " instance count=" + instanceCount + " isTest=" + isTest;
         logger.info("POST dcae event {}", msgInfo);
 
         if (isTest) {
@@ -395,79 +602,99 @@ public class CldsService extends SecureServiceBase {
             if (DcaeEvent.EVENT_DEPLOYMENT.equalsIgnoreCase(dcaeEvent.getEvent())) {
                 CldsModel.insertModelInstance(cldsDao, dcaeEvent, userid);
             } else {
-                CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userid, dcaeEvent.getCldsActionCd(), CldsEvent.ACTION_STATE_RECEIVED, null);
+                CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userid, dcaeEvent.getCldsActionCd(),
+                        CldsEvent.ACTION_STATE_RECEIVED, null);
             }
-            // EVENT_UNDEPLOYMENT is defunct - DCAE Proxy will not undeploy individual instances.  It will send an empty list of
-            // deployed instances to indicate all have been removed.  Or it will send an updated list to indicate those that
-            // are still deployed with any not on the list considered undeployed.
-            //else if(DcaeEvent.EVENT_UNDEPLOYMENT.equalsIgnoreCase(dcaeEvent.getEvent()))
-            //{
-            // CldsModel.removeModelInstance(cldsDao, dcaeEvent);
-            //}
         }
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Post dcae event success", this.getClass().getName());
+        auditLogger.info("Post dcae event completed");
 
         return msgInfo;
     }
 
     /**
-     * REST service that retrieves asdc services
+     * REST service that retrieves sdc services
      *
      * @throws Exception
      */
+    @ApiOperation(value = "Retrieves sdc services", notes = "", response = String.class)
     @GET
-    @Path("/asdc/services")
+    @Path("/sdc/services")
     @Produces(MediaType.APPLICATION_JSON)
-    public String getAsdcServices() throws Exception {
+    public String getSdcServices() {
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: GET sdc services", getPrincipalName());
         String retStr;
+
+        String responseStr = sdcCatalogServices.getSdcServicesInformation(null);
         try {
-            String responseStr = asdcCatalogServices.getAsdcServicesInformation(null);
             retStr = createUiServiceFormatJson(responseStr);
-        } catch (Exception e) {
-            logger.info("{} {}", e.getClass().getName(), e.getMessage());
-            throw e;
+        } catch (IOException e) {
+            logger.error("IOException during SDC communication", e);
+            throw new SdcCommunicationException("IOException during SDC communication", e);
         }
-        logger.info("value of asdcServices : {}", retStr);
+
+        logger.info("value of sdcServices : {}", retStr);
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());
+        auditLogger.info("GET sdc services completed");
         return retStr;
     }
 
     /**
      * REST service that retrieves total properties required by UI
+     * 
+     * @throws IOException
+     *             In case of issues
      *
-     * @throws Exception
      */
+    @ApiOperation(value = "Retrieves total properties required by UI", notes = "", response = String.class)
     @GET
     @Path("/properties")
     @Produces(MediaType.APPLICATION_JSON)
-    public String getAsdcProperties() throws Exception {
+    public String getSdcProperties() throws IOException {
         return createPropertiesObjectByUUID(getGlobalCldsString(), "{}");
     }
 
     /**
-     * REST service that retrieves total properties by using invariantUUID based on refresh and non refresh
-     *
-     * @throws Exception
+     * REST service that retrieves total properties by using invariantUUID based
+     * on refresh and non refresh
+     * 
      */
+    @ApiOperation(value = "Retrieves total properties by using invariantUUID based on refresh and non refresh", notes = "", response = String.class)
     @GET
     @Path("/properties/{serviceInvariantUUID}")
     @Produces(MediaType.APPLICATION_JSON)
-    public String getAsdcPropertiesByServiceUUIDForRefresh(@PathParam("serviceInvariantUUID") String serviceInvariantUUID, @DefaultValue("false") @QueryParam("refresh") String refresh) throws Exception {
+    public String getSdcPropertiesByServiceUUIDForRefresh(
+            @PathParam("serviceInvariantUUID") String serviceInvariantUUID,
+            @DefaultValue("false") @QueryParam("refresh") String refresh) {
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: GET sdc properties by uuid", getPrincipalName());
         CldsServiceData cldsServiceData = new CldsServiceData();
         cldsServiceData.setServiceInvariantUUID(serviceInvariantUUID);
 
-        boolean isCldsAsdcDataExpired = true;
-        //  To getcldsService information from database cache using invariantUUID only when refresh = false
+        boolean isCldsSdcDataExpired = true;
+        // To getcldsService information from database cache using invariantUUID
+        // only when refresh = false
         if (refresh != null && refresh.equalsIgnoreCase("false")) {
             cldsServiceData = cldsServiceData.getCldsServiceCache(cldsDao, serviceInvariantUUID);
-            // If cldsService is available in database Cache , verify is data expired or not
+            // If cldsService is available in database Cache , verify is data
+            // expired or not
             if (cldsServiceData != null) {
-                isCldsAsdcDataExpired = asdcCatalogServices.isCldsAsdcCacheDataExpired(cldsServiceData);
+                isCldsSdcDataExpired = sdcCatalogServices.isCldsSdcCacheDataExpired(cldsServiceData);
             }
         }
-        // If user Requested for refresh or database cache expired , get all data from asdc api.
-        if ((refresh != null && refresh.equalsIgnoreCase("true")) || isCldsAsdcDataExpired) {
-            cldsServiceData = asdcCatalogServices.getCldsServiceDataWithAlarmConditions(serviceInvariantUUID);
-            CldsDBServiceCache cldsDBServiceCache = asdcCatalogServices.getCldsDBServiceCacheUsingCldsServiceData(cldsServiceData);
-            if (cldsDBServiceCache != null && cldsDBServiceCache.getInvariantId() != null && cldsDBServiceCache.getServiceId() != null) {
+        // If user Requested for refresh or database cache expired , get all
+        // data from sdc api.
+        if ((refresh != null && refresh.equalsIgnoreCase("true")) || isCldsSdcDataExpired) {
+            cldsServiceData = sdcCatalogServices.getCldsServiceDataWithAlarmConditions(serviceInvariantUUID);
+            CldsDBServiceCache cldsDBServiceCache = sdcCatalogServices
+                    .getCldsDbServiceCacheUsingCldsServiceData(cldsServiceData);
+            if (cldsDBServiceCache != null && cldsDBServiceCache.getInvariantId() != null
+                    && cldsDBServiceCache.getServiceId() != null) {
                 cldsServiceData.setCldsServiceCache(cldsDao, cldsDBServiceCache);
             }
         }
@@ -476,35 +703,45 @@ public class CldsService extends SecureServiceBase {
         cldsServiceData.filterVfs(this);
 
         // format retrieved data into properties json
-        return asdcCatalogServices.createPropertiesObjectByUUID(getGlobalCldsString(), cldsServiceData);
+        String sdcProperties = sdcCatalogServices.createPropertiesObjectByUUID(getGlobalCldsString(), cldsServiceData);
+
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Get sdc properties by uuid success", this.getClass().getName());
+        auditLogger.info("GET sdc properties by uuid completed");
+
+        return sdcProperties;
     }
 
     /**
-     * Determine if the user is authorized for a particular VF by its invariant UUID.
+     * Determine if the user is authorized for a particular VF by its invariant
+     * UUID.
      *
      * @param vfInvariantUuid
      * @throws NotAuthorizedException
      * @return
      */
-    public boolean isAuthorizedForVf(String vfInvariantUuid) throws NotAuthorizedException {
-        if (CLDS_PERMISSION_TYPE_FILTER_VF != null && CLDS_PERMISSION_TYPE_FILTER_VF.length() > 0) {
-            SecureServicePermission permission = SecureServicePermission.create(CLDS_PERMISSION_TYPE_FILTER_VF, CLDS_PERMISSION_INSTANCE, vfInvariantUuid);
+    public boolean isAuthorizedForVf(String vfInvariantUuid) {
+        if (cldsPermissionTypeFilterVf != null && !cldsPermissionTypeFilterVf.isEmpty()) {
+            SecureServicePermission permission = SecureServicePermission.create(cldsPermissionTypeFilterVf,
+                    cldsPermissionInstance, vfInvariantUuid);
             return isAuthorized(permission);
         } else {
-            // if CLDS_PERMISSION_TYPE_FILTER_VF property is not provided, then VF filtering is turned off
+            // if CLDS_PERMISSION_TYPE_FILTER_VF property is not provided, then
+            // VF filtering is turned off
             logger.warn("VF filtering turned off");
             return true;
         }
     }
 
     /**
-     * Determine if the user is authorized for a particular VF by its invariant UUID.
-     * If not authorized, then NotAuthorizedException is thrown.
+     * Determine if the user is authorized for a particular VF by its invariant
+     * UUID. If not authorized, then NotAuthorizedException is thrown.
      *
      * @param model
      * @return
      */
-    private boolean isAuthorizedForVf(CldsModel model) throws NotAuthorizedException {
+    private boolean isAuthorizedForVf(CldsModel model) {
         String vf = ModelProperties.getVf(model);
         if (vf == null || vf.length() == 0) {
             logger.info("VF not found in model");
@@ -519,16 +756,18 @@ public class CldsService extends SecureServiceBase {
             return "";
         }
         ObjectMapper objectMapper = new ObjectMapper();
-        List<CldsAsdcServiceInfo> rawList = objectMapper.readValue(responseStr, objectMapper.getTypeFactory().constructCollectionType(List.class, CldsAsdcServiceInfo.class));
+        List<CldsSdcServiceInfo> rawList = objectMapper.readValue(responseStr,
+                objectMapper.getTypeFactory().constructCollectionType(List.class, CldsSdcServiceInfo.class));
         ObjectNode invariantIdServiceNode = objectMapper.createObjectNode();
         ObjectNode serviceNode = objectMapper.createObjectNode();
         logger.info("value of cldsserviceiNfolist: {}", rawList);
-        if (rawList != null && rawList.size() > 0) {
-            List<CldsAsdcServiceInfo> cldsAsdcServiceInfoList = asdcCatalogServices.removeDuplicateServices(rawList);
+        if (rawList != null && !rawList.isEmpty()) {
+            List<CldsSdcServiceInfo> cldsSdcServiceInfoList = sdcCatalogServices.removeDuplicateServices(rawList);
 
-            for (CldsAsdcServiceInfo currCldsAsdcServiceInfo : cldsAsdcServiceInfoList) {
-                if (currCldsAsdcServiceInfo != null) {
-                    invariantIdServiceNode.put(currCldsAsdcServiceInfo.getInvariantUUID(), currCldsAsdcServiceInfo.getName());
+            for (CldsSdcServiceInfo currCldsSdcServiceInfo : cldsSdcServiceInfoList) {
+                if (currCldsSdcServiceInfo != null) {
+                    invariantIdServiceNode.put(currCldsSdcServiceInfo.getInvariantUUID(),
+                            currCldsSdcServiceInfo.getName());
                 }
             }
             serviceNode.putPOJO("service", invariantIdServiceNode);
@@ -538,9 +777,9 @@ public class CldsService extends SecureServiceBase {
 
     private String createPropertiesObjectByUUID(String globalProps, String cldsResponseStr) throws IOException {
         ObjectMapper mapper = new ObjectMapper();
-        CldsAsdcServiceDetail cldsAsdcServiceDetail = mapper.readValue(cldsResponseStr, CldsAsdcServiceDetail.class);
+        CldsSdcServiceDetail cldsSdcServiceDetail = mapper.readValue(cldsResponseStr, CldsSdcServiceDetail.class);
         ObjectNode globalPropsJson = null;
-        if (cldsAsdcServiceDetail != null && cldsAsdcServiceDetail.getUuid() != null) {
+        if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getUuid() != null) {
             /**
              * to create json with vf, alarm and locations
              */
@@ -550,22 +789,22 @@ public class CldsService extends SecureServiceBase {
             /**
              * to create json with vf and vfresourceId
              */
-            createVfObjectNode(vfObjectNode, mapper, cldsAsdcServiceDetail.getResources());
-            serviceObjectNode.putPOJO(cldsAsdcServiceDetail.getInvariantUUID(), vfObjectNode);
+            createVfObjectNode(vfObjectNode, mapper, cldsSdcServiceDetail.getResources());
+            serviceObjectNode.putPOJO(cldsSdcServiceDetail.getInvariantUUID(), vfObjectNode);
             ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
             byServiceBasicObjetNode.putPOJO("byService", serviceObjectNode);
 
             /**
              * to create json with VFC Node
              */
-            ObjectNode emptyvfcobjectNode = createByVFCObjectNode(mapper, cldsAsdcServiceDetail.getResources());
+            ObjectNode emptyvfcobjectNode = createByVFCObjectNode(mapper, cldsSdcServiceDetail.getResources());
             byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
             globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
             globalPropsJson.putPOJO("shared", byServiceBasicObjetNode);
             logger.info("valuie of objNode: {}", globalPropsJson);
         } else {
             /**
-             *  to create json with total properties when no serviceUUID passed
+             * to create json with total properties when no serviceUUID passed
              */
             globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class);
         }
@@ -584,63 +823,176 @@ public class CldsService extends SecureServiceBase {
         return emptyServiceObjectNode;
     }
 
-    private void createVfObjectNode(ObjectNode vfObjectNode2, ObjectMapper mapper, List<CldsAsdcResource> rawCldsAsdcResourceList) throws IOException {
+    private void createVfObjectNode(ObjectNode vfObjectNode2, ObjectMapper mapper,
+            List<CldsSdcResource> rawCldsSdcResourceList) {
         ObjectNode vfNode = mapper.createObjectNode();
         vfNode.put("", "");
 
-        // To remove repeated resource instance name from resourceInstanceList
-        List<CldsAsdcResource> cldsAsdcResourceList = asdcCatalogServices.removeDuplicateAsdcResourceInstances(rawCldsAsdcResourceList);
+        // To remove repeated resource instance name from
+        // resourceInstanceList
+        List<CldsSdcResource> cldsSdcResourceList = sdcCatalogServices
+                .removeDuplicateSdcResourceInstances(rawCldsSdcResourceList);
         /**
-         * Creating vf resource node using cldsAsdcResource Object
+         * Creating vf resource node using cldsSdcResource Object
          */
-        if (cldsAsdcResourceList != null && cldsAsdcResourceList.size() > 0) {
-            for (CldsAsdcResource cldsAsdcResource : cldsAsdcResourceList) {
-                if (cldsAsdcResource != null && cldsAsdcResource.getResoucreType() != null && cldsAsdcResource.getResoucreType().equalsIgnoreCase("VF")) {
-                    vfNode.put(cldsAsdcResource.getResourceUUID(), cldsAsdcResource.getResourceName());
+        if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {
+            for (CldsSdcResource cldsSdcResource : cldsSdcResourceList) {
+                if (cldsSdcResource != null && "VF".equalsIgnoreCase(cldsSdcResource.getResoucreType())) {
+                    vfNode.put(cldsSdcResource.getResourceUUID(), cldsSdcResource.getResourceName());
                 }
             }
         }
         vfObjectNode2.putPOJO("vf", vfNode);
-        String locationStringValue = refProp.getStringValue("ui.location.default");
-        String alarmStringValue = refProp.getStringValue("ui.alarm.default");
 
         /**
-         *  creating location json object using properties file value
+         * creating location json object using properties file value
          */
-        ObjectNode locationJsonNode = (ObjectNode) mapper.readValue(locationStringValue, JsonNode.class);
+        ObjectNode locationJsonNode;
+        try {
+            locationJsonNode = (ObjectNode) mapper.readValue(refProp.getStringValue("ui.location.default"),
+                    JsonNode.class);
+        } catch (IOException e) {
+            logger.error("Unable to load ui.location.default JSON in clds-references.properties properly", e);
+            throw new CldsConfigException(
+                    "Unable to load ui.location.default JSON in clds-references.properties properly", e);
+        }
         vfObjectNode2.putPOJO("location", locationJsonNode);
 
         /**
          * creating alarm json object using properties file value
          */
+        String alarmStringValue = refProp.getStringValue("ui.alarm.default");
         logger.info("value of alarm: {}", alarmStringValue);
-        ObjectNode alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class);
+        ObjectNode alarmStringJsonNode;
+        try {
+            alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class);
+        } catch (IOException e) {
+            logger.error("Unable to ui.alarm.default JSON in clds-references.properties properly", e);
+            throw new CldsConfigException("Unable to load ui.alarm.default JSON in clds-references.properties properly",
+                    e);
+        }
         vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode);
+
     }
 
-    private ObjectNode createByVFCObjectNode(ObjectMapper mapper, List<CldsAsdcResource> cldsAsdcResourceList) {
+    private ObjectNode createByVFCObjectNode(ObjectMapper mapper, List<CldsSdcResource> cldsSdcResourceList) {
         ObjectNode emptyObjectNode = mapper.createObjectNode();
         ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
         ObjectNode vfCObjectNode = mapper.createObjectNode();
         vfCObjectNode.putPOJO("vfC", emptyObjectNode);
         ObjectNode subVfCObjectNode = mapper.createObjectNode();
         subVfCObjectNode.putPOJO("vfc", emptyObjectNode);
-        if (cldsAsdcResourceList != null && cldsAsdcResourceList.size() > 0) {
-            for (CldsAsdcResource cldsAsdcResource : cldsAsdcResourceList) {
-                if (cldsAsdcResource != null && cldsAsdcResource.getResoucreType() != null && cldsAsdcResource.getResoucreType().equalsIgnoreCase("VF")) {
-                    vfCObjectNode.putPOJO(cldsAsdcResource.getResourceUUID(), subVfCObjectNode);
+        if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {
+            for (CldsSdcResource cldsSdcResource : cldsSdcResourceList) {
+                if (cldsSdcResource != null && "VF".equalsIgnoreCase(cldsSdcResource.getResoucreType())) {
+                    vfCObjectNode.putPOJO(cldsSdcResource.getResourceUUID(), subVfCObjectNode);
                 }
             }
         }
         emptyvfcobjectNode.putPOJO("", vfCObjectNode);
         return emptyvfcobjectNode;
     }
-    
-    private String getGlobalCldsString() throws Exception {
-       if  (null == globalCldsProperties) {
-            globalCldsProperties = new Properties();
-            globalCldsProperties.load(appContext.getResource(globalClds).getInputStream());
-       }
-       return (String) globalCldsProperties.get("globalCldsProps");
+
+    @PUT
+    @Path("/deploy/{modelName}")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public CldsModel deployModel(@PathParam("action") String action, @PathParam("modelName") String modelName,
+            @QueryParam("test") String test, CldsModel model) throws IOException {
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: Deploy model", getPrincipalName());
+        String deploymentId = "closedLoop_" + UUID.randomUUID() + "_deploymentId";
+        String createNewDeploymentStatusUrl = dcaeDispatcherServices.createNewDeployment(deploymentId,
+                model.getTypeId());
+        String operationStatus = "processing";
+        long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10);
+        while ("processing".equalsIgnoreCase(operationStatus)) {
+            // Break the loop if waiting for more than 10 mins
+            if (waitingTime < System.nanoTime()) {
+                break;
+            }
+            operationStatus = dcaeDispatcherServices.getOperationStatus(createNewDeploymentStatusUrl);
+        }
+        if ("succeeded".equalsIgnoreCase(operationStatus)) {
+            String artifactName = model.getControlName();
+            if (artifactName != null) {
+                artifactName = artifactName + ".yml";
+            }
+            DcaeEvent dcaeEvent = new DcaeEvent();
+            /* set dcae events */
+            dcaeEvent.setArtifactName(artifactName);
+            dcaeEvent.setEvent(DcaeEvent.EVENT_DEPLOYMENT);
+            CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), getUserId(), dcaeEvent.getCldsActionCd(),
+                    CldsEvent.ACTION_STATE_RECEIVED, null);
+            model.setDeploymentId(deploymentId);
+            model.save(cldsDao, getUserId());
+        } else {
+            logger.info("Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+            throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR,
+                    "Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+        }
+        logger.info("Deploy model (" + modelName + ") succeeded...Deployment Id is - " + deploymentId);
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Deploy model success", this.getClass().getName());
+        auditLogger.info("Deploy model completed");
+        return model;
+    }
+
+    @PUT
+    @Path("/undeploy/{modelName}")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public CldsModel unDeployModel(@PathParam("action") String action, @PathParam("modelName") String modelName,
+            @QueryParam("test") String test, CldsModel model) throws IOException {
+        Date startTime = new Date();
+        LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName());
+        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);
+        }
+        if ("succeeded".equalsIgnoreCase(operationStatus)) {
+            String artifactName = model.getControlName();
+            if (artifactName != null) {
+                artifactName = artifactName + ".yml";
+            }
+            DcaeEvent dcaeEvent = new DcaeEvent();
+            // set dcae events
+            dcaeEvent.setArtifactName(artifactName);
+            dcaeEvent.setEvent(DcaeEvent.EVENT_UNDEPLOYMENT);
+            CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), dcaeEvent.getCldsActionCd(),
+                    CldsEvent.ACTION_STATE_RECEIVED, null);
+            model.setDeploymentId(null);
+            model.save(cldsDao, getUserId());
+        } else {
+            logger.info("Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+            throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR,
+                    "Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+        }
+        logger.info("Undeploy model (" + modelName + ") succeeded.");
+        // audit log
+        LoggingUtils.setTimeContext(startTime, new Date());
+        LoggingUtils.setResponseContext("0", "Undeploy model success", this.getClass().getName());
+        auditLogger.info("Undeploy model completed");
+        return model;
+    }
+
+    private String getGlobalCldsString() {
+        try {
+            if (null == globalCldsProperties) {
+                globalCldsProperties = new Properties();
+                globalCldsProperties.load(appContext.getResource(globalClds).getInputStream());
+            }
+            return (String) globalCldsProperties.get("globalCldsProps");
+        } catch (IOException e) {
+            logger.error("Unable to load the globalClds due to an exception", e);
+            throw new CldsConfigException("Unable to load the globalClds due to an exception", e);
+        }
     }
 }