X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fservice%2FCldsService.java;h=c23d2ec87e068e9a968787eb00c896d05d3b74fa;hb=4b3477b503f4effed467765e41026f247c565cbd;hp=a9b1b771ae338b32f8a4e1d2e8fbf9e7ad1b8edf;hpb=b79ce61729c0422ab9d3909439538b000157f721;p=clamp.git 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 a9b1b771..c23d2ec8 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -52,6 +52,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.xml.transform.TransformerException; import org.apache.camel.Produce; @@ -62,18 +63,18 @@ import org.onap.clamp.clds.camel.CamelProxy; import org.onap.clamp.clds.client.DcaeDispatcherServices; import org.onap.clamp.clds.client.DcaeInventoryServices; import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; -import org.onap.clamp.clds.config.CldsReferenceProperties; +import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.dao.CldsDao; import org.onap.clamp.clds.exception.CldsConfigException; import org.onap.clamp.clds.exception.policy.PolicyClientException; import org.onap.clamp.clds.exception.sdc.SdcCommunicationException; -import org.onap.clamp.clds.model.CLDSMonitoringDetails; -import org.onap.clamp.clds.model.CldsDBServiceCache; +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.CldsModelProp; +import org.onap.clamp.clds.model.CldsMonitoringDetails; import org.onap.clamp.clds.model.CldsServiceData; import org.onap.clamp.clds.model.CldsTemplate; import org.onap.clamp.clds.model.DcaeEvent; @@ -87,7 +88,6 @@ import org.onap.clamp.clds.transform.XslTransformer; 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.http.HttpStatus; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; @@ -102,20 +102,19 @@ public class CldsService extends SecureServiceBase { @Produce(uri = "direct:processSubmit") private CamelProxy camelProxy; protected static final EELFLogger securityLogger = EELFManager.getInstance().getSecurityLogger(); - @Autowired - private ApplicationContext appContext; private static final String RESOURCE_NAME = "clds-version.properties"; - @Value("${CLDS_PERMISSION_TYPE_CL:permission-type-cl}") + public static final String GLOBAL_PROPERTIES_KEY = "files.globalProperties"; + @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") private String cldsPersmissionTypeCl; - @Value("${CLDS_PERMISSION_TYPE_CL_MANAGE:permission-type-cl-manage}") + @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}") private String cldsPermissionTypeClManage; - @Value("${CLDS_PERMISSION_TYPE_CL_EVENT:permission-type-cl-event}") + @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}") private String cldsPermissionTypeClEvent; - @Value("${CLDS_PERMISSION_TYPE_FILTER_VF:permission-type-filter-vf}") + @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}") private String cldsPermissionTypeFilterVf; - @Value("${CLDS_PERMISSION_TYPE_TEMPLATE:permission-type-template}") + @Value("${clamp.config.security.permission.type.template:permission-type-template}") private String cldsPermissionTypeTemplate; - @Value("${CLDS_PERMISSION_INSTANCE:dev}") + @Value("${clamp.config.security.permission.instance:dev}") private String cldsPermissionInstance; private SecureServicePermission permissionReadCl; private SecureServicePermission permissionUpdateCl; @@ -132,15 +131,12 @@ public class CldsService extends SecureServiceBase { "update"); } - @Value("${org.onap.clamp.config.files.globalClds:'classpath:/clds/globalClds.properties'}") - private String globalClds; - private Properties globalCldsProperties; @Autowired private CldsDao cldsDao; @Autowired private XslTransformer cldsBpmnTransformer; @Autowired - private CldsReferenceProperties refProp; + private ClampProperties refProp; @Autowired private SdcCatalogServices sdcCatalogServices; @Autowired @@ -161,10 +157,10 @@ public class CldsService extends SecureServiceBase { @GET @Path("/cldsDetails") @Produces(MediaType.APPLICATION_JSON) - public List getCLDSDetails() { + public List getCLDSDetails() { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: GET model details", getPrincipalName()); - List cldsMonitoringDetailsList = new ArrayList(); + List cldsMonitoringDetailsList = new ArrayList(); cldsMonitoringDetailsList = cldsDao.getCLDSMonitoringDetails(); // audit log LoggingUtils.setTimeContext(startTime, new Date()); @@ -212,7 +208,7 @@ public class CldsService extends SecureServiceBase { /** * REST service that retrieves clds healthcheck information. - * + * * @return CldsHealthCheck class containing healthcheck info */ @GET @@ -401,95 +397,104 @@ public class CldsService extends SecureServiceBase { @Path("/action/{action}/{modelName}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - public CldsModel putModelAndProcessAction(@PathParam("action") String action, + public Response putModelAndProcessAction(@PathParam("action") String action, @PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model) throws TransformerException, ParseException, GeneralSecurityException, DecoderException { Date startTime = new Date(); - LoggingUtils.setRequestContext("CldsService: Process model action", getPrincipalName()); - String actionCd = action.toUpperCase(); - SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage, - cldsPermissionInstance, actionCd); - isAuthorized(permisionManage); - isAuthorizedForVf(model); - String userId = getUserId(); - String actionStateCd = CldsEvent.ACTION_STATE_INITIATED; - String processDefinitionKey = "clds-process-action-wf"; - logger.info("PUT actionCd={}", actionCd); - logger.info("PUT actionStateCd={}", actionStateCd); - logger.info("PUT processDefinitionKey={}", processDefinitionKey); - logger.info("PUT modelName={}", modelName); - logger.info("PUT test={}", test); - 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()); - if (template != null) { - model.setTemplateId(template.getId()); - model.setDocText(template.getPropText()); - // This is to provide the Bpmn XML when Template part in UI is - // disabled - model.setBpmnText(template.getBpmnText()); + CldsModel retrievedModel = null; + Boolean errorCase = false; + try { + LoggingUtils.setRequestContext("CldsService: Process model action", getPrincipalName()); + String actionCd = action.toUpperCase(); + SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage, + cldsPermissionInstance, actionCd); + isAuthorized(permisionManage); + isAuthorizedForVf(model); + String userId = getUserId(); + String actionStateCd = CldsEvent.ACTION_STATE_INITIATED; + logger.info("PUT actionCd={}", actionCd); + logger.info("PUT actionStateCd={}", actionStateCd); + logger.info("PUT modelName={}", modelName); + logger.info("PUT test={}", test); + 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()); + if (template != null) { + model.setTemplateId(template.getId()); + model.setDocText(template.getPropText()); + // This is to provide the Bpmn XML when Template part in UI is + // disabled + model.setBpmnText(template.getBpmnText()); + } } - } - // save model to db - model.setName(modelName); - model.save(cldsDao, getUserId()); - // get vars and format if necessary - String prop = model.getPropText(); - String bpmn = model.getBpmnText(); - String docText = model.getDocText(); - String controlName = model.getControlName(); - 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 { - String actionTestOverride = refProp.getStringValue("action.test.override"); - if (actionTestOverride != null && actionTestOverride.equalsIgnoreCase("true")) { - logger.info("PUT actionTestOverride={}", actionTestOverride); - logger.info("PUT override test indicator and setting it to true"); + // save model to db + model.setName(modelName); + model.save(cldsDao, getUserId()); + // get vars and format if necessary + String prop = model.getPropText(); + String bpmn = model.getBpmnText(); + String docText = model.getDocText(); + String controlName = model.getControlName(); + 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 { + String actionTestOverride = refProp.getStringValue("action.test.override"); + if (actionTestOverride != null && actionTestOverride.equalsIgnoreCase("true")) { + logger.info("PUT actionTestOverride={}", actionTestOverride); + logger.info("PUT override test indicator and setting it to true"); + isTest = true; + } } + logger.info("PUT isTest={}", isTest); + boolean isInsertTestEvent = false; + String insertTestEvent = refProp.getStringValue("action.insert.test.event"); + if (insertTestEvent != null && insertTestEvent.equalsIgnoreCase("true")) { + isInsertTestEvent = true; + } + logger.info("PUT isInsertTestEvent={}", isInsertTestEvent); + // determine if requested action is permitted + model.validateAction(actionCd); + logger.info("modelProp - " + prop); + logger.info("docText - " + docText); + try { + String result = camelProxy.submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest, userId, + isInsertTestEvent); + logger.info("Starting Camel flow on request, result is: ", result); + } catch (SdcCommunicationException | PolicyClientException | BadRequestException e) { + errorCase = true; + logger.error("Exception occured during invoking Camel process", e); + } + // refresh model info from db (get fresh event info) + retrievedModel = CldsModel.retrieve(cldsDao, modelName, false); + 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()); + } + // audit log + LoggingUtils.setTimeContext(startTime, new Date()); + LoggingUtils.setResponseContext("0", "Process model action success", this.getClass().getName()); + auditLogger.info("Process model action completed"); + } catch (Exception e) { + errorCase = true; + logger.error("Exception occured during putModelAndProcessAction", e); } - logger.info("PUT isTest={}", isTest); - boolean isInsertTestEvent = false; - String insertTestEvent = refProp.getStringValue("action.insert.test.event"); - if (insertTestEvent != null && insertTestEvent.equalsIgnoreCase("true")) { - isInsertTestEvent = true; - } - logger.info("PUT isInsertTestEvent={}", isInsertTestEvent); - // determine if requested action is permitted - model.validateAction(actionCd); - logger.info("modelProp - " + prop); - logger.info("docText - " + docText); - try { - String result = camelProxy.submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest, userId, - isInsertTestEvent); - logger.info("Starting Camel flow on request, result is: ", result); - } catch (SdcCommunicationException | PolicyClientException | BadRequestException e) { - logger.error("Exception occured during invoking Camel process", e); - throw new CldsConfigException(e.getMessage(), e); - } - // refresh model info from db (get fresh event info) - CldsModel retreivedModel = CldsModel.retrieve(cldsDao, modelName, false); - 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(retreivedModel, getUserId()); - retreivedModel.save(cldsDao, getUserId()); + + if (errorCase) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(retrievedModel).build(); } - // 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; + return Response.status(Response.Status.OK).entity(retrievedModel).build(); } /** @@ -547,7 +552,7 @@ public class CldsService extends SecureServiceBase { /** * REST service that retrieves sdc services - * + * * @throws GeneralSecurityException * In case of issue when decryting the SDC password * @throws DecoderException @@ -577,7 +582,7 @@ public class CldsService extends SecureServiceBase { /** * REST service that retrieves total properties required by UI - * + * * @throws IOException * In case of issues */ @@ -585,13 +590,13 @@ public class CldsService extends SecureServiceBase { @Path("/properties") @Produces(MediaType.APPLICATION_JSON) public String getSdcProperties() throws IOException { - return createPropertiesObjectByUUID(getGlobalCldsString(), "{}"); + return createPropertiesObjectByUUID("{}"); } /** * REST service that retrieves total properties by using invariantUUID based * on refresh and non refresh - * + * * @throws GeneralSecurityException * In case of issues with the decryting the encrypted password * @throws DecoderException @@ -615,12 +620,12 @@ public class CldsService extends SecureServiceBase { } if (sdcCatalogServices.isCldsSdcCacheDataExpired(cldsServiceData)) { cldsServiceData = sdcCatalogServices.getCldsServiceDataWithAlarmConditions(serviceInvariantUUID); - cldsDao.setCldsServiceCache(new CldsDBServiceCache(cldsServiceData)); + cldsDao.setCldsServiceCache(new CldsDbServiceCache(cldsServiceData)); } // filter out VFs the user is not authorized for cldsServiceData.filterVfs(this); // format retrieved data into properties json - String sdcProperties = sdcCatalogServices.createPropertiesObjectByUUID(getGlobalCldsString(), cldsServiceData); + String sdcProperties = sdcCatalogServices.createPropertiesObjectByUUID(cldsServiceData); // audit log LoggingUtils.setTimeContext(startTime, new Date()); LoggingUtils.setResponseContext("0", "Get sdc properties by uuid success", this.getClass().getName()); @@ -689,10 +694,10 @@ public class CldsService extends SecureServiceBase { return serviceNode.toString(); } - private String createPropertiesObjectByUUID(String globalProps, String cldsResponseStr) throws IOException { + private String createPropertiesObjectByUUID(String cldsResponseStr) throws IOException { ObjectMapper mapper = new ObjectMapper(); SdcServiceDetail cldsSdcServiceDetail = mapper.readValue(cldsResponseStr, SdcServiceDetail.class); - ObjectNode globalPropsJson = null; + ObjectNode globalPropsJson = (ObjectNode) refProp.getJsonTemplate(GLOBAL_PROPERTIES_KEY); if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getUuid() != null) { /** * to create json with vf, alarm and locations @@ -711,14 +716,8 @@ public class CldsService extends SecureServiceBase { */ 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 - */ - globalPropsJson = (ObjectNode) mapper.readValue(globalProps, JsonNode.class); } return globalPropsJson.toString(); } @@ -805,115 +804,123 @@ public class CldsService extends SecureServiceBase { @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) { + public Response deployModel(@PathParam("modelName") String modelName, + CldsModel model) { Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: Deploy model", getPrincipalName()); + Boolean errorCase = false; try { - checkForDuplicateServiceVf(modelName, model.getPropText()); - } catch (IOException | BadRequestException e) { - logger.error("Exception occured during duplicate check for service and VF", e); - throw new CldsConfigException(e.getMessage(), e); - } - String deploymentId = ""; - // If model is already deployed then pass same deployment id - if (model.getDeploymentId() != null && !model.getDeploymentId().isEmpty()) { - deploymentId = model.getDeploymentId(); - } else { - 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; + try { + checkForDuplicateServiceVf(modelName, model.getPropText()); + } catch (IOException | BadRequestException e) { + errorCase = true; + logger.error("Exception occured during duplicate check for service and VF", e); } - operationStatus = dcaeDispatcherServices.getOperationStatus(createNewDeploymentStatusUrl); - } - if ("succeeded".equalsIgnoreCase(operationStatus)) { - String artifactName = model.getControlName(); - if (artifactName != null) { - artifactName = artifactName + ".yml"; + String deploymentId = ""; + // If model is already deployed then pass same deployment id + if (model.getDeploymentId() != null && !model.getDeploymentId().isEmpty()) { + deploymentId = model.getDeploymentId(); + } else { + deploymentId = "closedLoop_" + UUID.randomUUID() + "_deploymentId"; } - 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); + 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"); + } catch (Exception e) { + errorCase = true; + logger.error("Exception occured during deployModel", e); } - 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; + + if (errorCase) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(model).build(); + } + return Response.status(Response.Status.OK).entity(model).build(); } @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 { + public Response unDeployModel(@PathParam("modelName") String modelName, + CldsModel model) { 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; + + Boolean errorCase = false; + 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); } - operationStatus = dcaeDispatcherServices.getOperationStatus(operationStatusUndeployUrl); - } - if ("succeeded".equalsIgnoreCase(operationStatus)) { - String artifactName = model.getControlName(); - if (artifactName != null) { - artifactName = artifactName + ".yml"; + 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); } - 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"); + } catch (Exception e) { + errorCase = true; + logger.error("Exception occured during unDeployModel", e); } - 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); + if (errorCase) { + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(model).build(); } + return Response.status(Response.Status.OK).entity(model).build(); } private void checkForDuplicateServiceVf(String modelName, String modelPropText) throws IOException {