diff options
author | Gabriel <adam.krysiak@nokia.com> | 2018-06-25 08:25:06 +0200 |
---|---|---|
committer | Gabriel <adam.krysiak@nokia.com> | 2018-07-03 07:53:03 +0200 |
commit | 2dc06bd93935107a84934d3ff4f3d4209160e68b (patch) | |
tree | 590ede87091641076e013ad84724a9c8750aa20a /src/main | |
parent | 21ebe86d82cb7e7700e45df9873ef5ca1834fc76 (diff) |
cleaned up clds service code
Change-Id: Id1688515986d96b35f4cc654a38d662b3d491240
Issue-ID: CLAMP-178
Signed-off-by: Gabriel <adam.krysiak@nokia.com>
Diffstat (limited to 'src/main')
4 files changed, 214 insertions, 131 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java index bf08a239..2ebab88b 100644 --- a/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java +++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java @@ -17,6 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ + * Modifications copyright (c) 2018 Nokia * =================================================================== * */ @@ -320,6 +321,6 @@ public class OperationalPolicyReq { if (prList == null || prList.isEmpty()) { return new PolicyResult[0]; } - return prList.stream().map(stringElem -> PolicyResult.toResult(stringElem)).toArray(PolicyResult[]::new); + return prList.stream().map(PolicyResult::toResult).toArray(PolicyResult[]::new); } }
\ No newline at end of file diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java index 9cad683a..8796bae1 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java @@ -17,6 +17,7 @@ * See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2018 Nokia
* ===================================================================
*
*/
@@ -149,10 +150,10 @@ public class SdcSingleController { if (this.getControllerStatus() != SdcSingleControllerStatus.STOPPED) {
throw new SdcControllerException("The controller is already initialized, call the closeSDC method first");
}
- if (this.distributionClient == null) {
+ if (distributionClient == null) {
distributionClient = DistributionClientFactory.createDistributionClient();
}
- IDistributionClientResult result = this.distributionClient.init(sdcConfig, new SdcNotificationCallBack(this));
+ IDistributionClientResult result = distributionClient.init(sdcConfig, new SdcNotificationCallBack(this));
if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) {
logger.error("SDC distribution client init failed with reason:" + result.getDistributionMessageResult());
this.changeControllerStatus(SdcSingleControllerStatus.STOPPED);
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java b/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java new file mode 100644 index 00000000..66890aa1 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 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. + * 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 + * limitations under the License. + * ============LICENSE_END============================================ + * Modifications copyright (c) 2018 Nokia + * =================================================================== + * + */ + +package org.onap.clamp.clds.service; + +import static org.onap.clamp.clds.service.CldsService.RESOURCE_NAME; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import java.io.InputStream; +import java.util.Properties; +import org.onap.clamp.clds.model.CldsInfo; +import org.onap.clamp.clds.util.ResourceFileUtil; + +class CldsInfoProvider { + + private static final String CLDS_VERSION = "clds.version"; + private final CldsService cldsService; + private final EELFLogger logger = EELFManager.getInstance().getLogger(CldsInfoProvider.class); + + + CldsInfoProvider(CldsService cldsService) { + this.cldsService = cldsService; + } + + CldsInfo getCldsInfo(){ + CldsInfo cldsInfo = new CldsInfo(); + cldsInfo.setUserName(cldsService.getUserName()); + cldsInfo.setCldsVersion(getCldsVersionFromProps()); + + cldsInfo.setPermissionReadCl(cldsService.isAuthorizedNoException(cldsService.permissionReadCl)); + cldsInfo.setPermissionUpdateCl(cldsService.isAuthorizedNoException(cldsService.permissionUpdateCl)); + cldsInfo.setPermissionReadTemplate(cldsService.isAuthorizedNoException(cldsService.permissionReadTemplate)); + cldsInfo.setPermissionUpdateTemplate(cldsService.isAuthorizedNoException(cldsService.permissionUpdateTemplate)); + return cldsInfo; + } + + private String getCldsVersionFromProps() { + String cldsVersion = ""; + Properties props = new Properties(); + try (InputStream resourceStream = ResourceFileUtil.getResourceAsStream(RESOURCE_NAME)) { + props.load(resourceStream); + cldsVersion = props.getProperty(CLDS_VERSION); + } catch (Exception ex) { + logger.error("Exception caught during the clds.version reading", ex); + } + return cldsVersion; + } +} 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 7cc9af9b..3bd771cd 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -17,6 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ + * Modifications copyright (c) 2018 Nokia * =================================================================== * */ @@ -32,6 +33,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; import java.io.InputStream; import java.security.GeneralSecurityException; +import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Properties; @@ -86,6 +88,7 @@ import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl; import org.onap.clamp.clds.transform.XslTransformer; import org.onap.clamp.clds.util.JacksonUtils; import org.onap.clamp.clds.util.LoggingUtils; +import org.onap.clamp.clds.util.ResourceFileUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; @@ -101,49 +104,57 @@ public class CldsService extends SecureServiceBase { @Produce(uri = "direct:processSubmit") private CamelProxy camelProxy; - protected static final EELFLogger securityLogger = EELFManager.getInstance().getSecurityLogger(); - private static final String RESOURCE_NAME = "clds-version.properties"; + protected static final EELFLogger securityLogger = EELFManager.getInstance() + .getSecurityLogger(); + static final String RESOURCE_NAME = "clds-version.properties"; public static final String GLOBAL_PROPERTIES_KEY = "files.globalProperties"; - @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") - private String cldsPersmissionTypeCl; - @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}") - private String cldsPermissionTypeClManage; - @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}") - private String cldsPermissionTypeClEvent; - @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}") - private String cldsPermissionTypeFilterVf; - @Value("${clamp.config.security.permission.type.template:permission-type-template}") - private String cldsPermissionTypeTemplate; - @Value("${clamp.config.security.permission.instance:dev}") - private String cldsPermissionInstance; - private SecureServicePermission permissionReadCl; - private SecureServicePermission permissionUpdateCl; - private SecureServicePermission permissionReadTemplate; - private SecureServicePermission permissionUpdateTemplate; - - @PostConstruct - private final void afterConstruction() { + private final String cldsPersmissionTypeCl; + private final String cldsPermissionTypeClManage; + private final String cldsPermissionTypeClEvent; + private final String cldsPermissionTypeFilterVf; + private final String cldsPermissionTypeTemplate; + private final String cldsPermissionInstance; + final SecureServicePermission permissionReadCl; + final SecureServicePermission permissionUpdateCl; + final SecureServicePermission permissionReadTemplate; + final SecureServicePermission permissionUpdateTemplate; + + private final CldsDao cldsDao; + private final XslTransformer cldsBpmnTransformer; + private final ClampProperties refProp; + private final SdcCatalogServices sdcCatalogServices; + private final DcaeDispatcherServices dcaeDispatcherServices; + private final DcaeInventoryServices dcaeInventoryServices; + + @Autowired + public CldsService(CldsDao cldsDao, XslTransformer cldsBpmnTransformer, ClampProperties refProp, + SdcCatalogServices sdcCatalogServices, DcaeDispatcherServices dcaeDispatcherServices, + DcaeInventoryServices dcaeInventoryServices, + @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") String cldsPersmissionTypeCl, + @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}") String cldsPermissionTypeClManage, + @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}") String cldsPermissionTypeClEvent, + @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}") String cldsPermissionTypeFilterVf, + @Value("${clamp.config.security.permission.type.template:permission-type-template}") String cldsPermissionTypeTemplate, + @Value("${clamp.config.security.permission.instance:dev}") String cldsPermissionInstance + ) { + this.cldsDao = cldsDao; + this.cldsBpmnTransformer = cldsBpmnTransformer; + this.refProp = refProp; + this.sdcCatalogServices = sdcCatalogServices; + this.dcaeDispatcherServices = dcaeDispatcherServices; + this.dcaeInventoryServices = dcaeInventoryServices; + this.cldsPersmissionTypeCl = cldsPersmissionTypeCl; + this.cldsPermissionTypeClManage = cldsPermissionTypeClManage; + this.cldsPermissionTypeClEvent = cldsPermissionTypeClEvent; + this.cldsPermissionTypeFilterVf = cldsPermissionTypeFilterVf; + this.cldsPermissionTypeTemplate = cldsPermissionTypeTemplate; + this.cldsPermissionInstance = cldsPermissionInstance; permissionReadCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "read"); permissionUpdateCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "update"); - permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance, - "read"); - permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance, - "update"); + permissionReadTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance, "read"); + permissionUpdateTemplate = SecureServicePermission.create(cldsPermissionTypeTemplate, cldsPermissionInstance, "update"); } - @Autowired - private CldsDao cldsDao; - @Autowired - private XslTransformer cldsBpmnTransformer; - @Autowired - private ClampProperties refProp; - @Autowired - private SdcCatalogServices sdcCatalogServices; - @Autowired - private DcaeDispatcherServices dcaeDispatcherServices; - @Autowired - private DcaeInventoryServices dcaeInventoryServices; - /* * @return list of CLDS-Monitoring-Details: CLOSELOOP_NAME | Close loop name * used in the CLDS application (prefix: ClosedLoop- + unique ClosedLoop ID) @@ -176,28 +187,13 @@ public class CldsService extends SecureServiceBase { @Path("/cldsInfo") @Produces(MediaType.APPLICATION_JSON) public CldsInfo getCldsInfo() { - CldsInfo cldsInfo = new CldsInfo(); Date startTime = new Date(); LoggingUtils.setRequestContext("CldsService: GET cldsInfo", getPrincipalName()); LoggingUtils.setTimeContext(startTime, new Date()); - // 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)); + + CldsInfoProvider cldsInfoProvider = new CldsInfoProvider(this); + CldsInfo cldsInfo = cldsInfoProvider.getCldsInfo(); + // audit log LoggingUtils.setTimeContext(startTime, new Date()); LoggingUtils.setResponseContext("0", "Get cldsInfo success", this.getClass().getName()); @@ -224,11 +220,13 @@ public class CldsService extends SecureServiceBase { cldsHealthCheck.setHealthCheckComponent("CLDS-APP"); cldsHealthCheck.setHealthCheckStatus("UP"); cldsHealthCheck.setDescription("OK"); - LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName()); + 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()); + LoggingUtils + .setResponseContext("999", "Get healthcheck failed", this.getClass().getName()); cldsHealthCheck.setHealthCheckComponent("CLDS-APP"); cldsHealthCheck.setHealthCheckStatus("DOWN"); cldsHealthCheck.setDescription("NOT-OK"); @@ -237,7 +235,8 @@ public class CldsService extends SecureServiceBase { LoggingUtils.setTimeContext(startTime, new Date()); logger.info("GET healthcheck completed"); if (healthcheckFailed) { - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(cldsHealthCheck).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(cldsHealthCheck) + .build(); } else { return Response.status(Response.Status.OK).entity(cldsHealthCheck).build(); } @@ -343,18 +342,10 @@ public class CldsService extends SecureServiceBase { logger.info("PUT propText={}", cldsModel.getPropText()); logger.info("PUT imageText={}", cldsModel.getImageText()); cldsModel.setName(modelName); - if (cldsModel.getTemplateName() != null) { - CldsTemplate template = cldsDao.getTemplate(cldsModel.getTemplateName()); - if (template != null) { - cldsModel.setTemplateId(template.getId()); - cldsModel.setDocText(template.getPropText()); - // This is to provide the Bpmn XML when Template part in UI is - // disabled - cldsModel.setBpmnText(template.getBpmnText()); - } - } - updateAndInsertNewEvent(cldsModel.getName(), cldsModel.getControlNamePrefix(), cldsModel.getEvent(), - CldsEvent.ACTION_MODIFY); + fillInCldsModel(cldsModel); + updateAndInsertNewEvent(cldsModel.getName(), cldsModel.getControlNamePrefix(), + cldsModel.getEvent(), + CldsEvent.ACTION_MODIFY); cldsModel.save(cldsDao, getUserId()); // audit log LoggingUtils.setTimeContext(startTime, new Date()); @@ -420,16 +411,16 @@ public class CldsService extends SecureServiceBase { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response putModelAndProcessAction(@PathParam("action") String action, - @PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model) - throws TransformerException, ParseException { + @PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model) + throws TransformerException, ParseException { Date startTime = new Date(); 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); + SecureServicePermission permisionManage = SecureServicePermission + .create(cldsPermissionTypeClManage, cldsPermissionInstance, actionCd); isAuthorized(permisionManage); isAuthorizedForVf(model); String userId = getUserId(); @@ -444,7 +435,8 @@ public class CldsService extends SecureServiceBase { this.fillInCldsModel(model); // save model to db model.setName(modelName); - updateAndInsertNewEvent(modelName, model.getControlNamePrefix(), model.getEvent(), CldsEvent.ACTION_MODIFY); + updateAndInsertNewEvent(modelName, model.getControlNamePrefix(), model.getEvent(), + CldsEvent.ACTION_MODIFY); model.save(cldsDao, getUserId()); // get vars and format if necessary String prop = model.getPropText(); @@ -456,30 +448,27 @@ public class CldsService extends SecureServiceBase { // Flag indicates whether it is triggered by Validation Test button // from // UI - boolean isTest = false; - if (test != null && test.equalsIgnoreCase("true")) { - isTest = true; - } else { + boolean isTest = Boolean.getBoolean(test); + if (!isTest) { String actionTestOverride = refProp.getStringValue("action.test.override"); - if (actionTestOverride != null && actionTestOverride.equalsIgnoreCase("true")) { + if (Boolean.getBoolean(actionTestOverride)) { 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; - } + boolean isInsertTestEvent = Boolean.getBoolean(insertTestEvent); + 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, + String result = camelProxy + .submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest, userId, isInsertTestEvent, model.getEvent().getActionCd()); logger.info("Starting Camel flow on request, result is: ", result); } catch (SdcCommunicationException | PolicyClientException | BadRequestException e) { @@ -548,10 +537,7 @@ public class CldsService extends SecureServiceBase { } // Flag indicates whether it is triggered by Validation Test button from // UI - boolean isTest = false; - if (test != null && test.equalsIgnoreCase("true")) { - isTest = true; - } + boolean isTest = Boolean.valueOf(test); int instanceCount = 0; if (dcaeEvent.getInstances() != null) { instanceCount = dcaeEvent.getInstances().size(); @@ -761,14 +747,15 @@ public class CldsService extends SecureServiceBase { return emptyServiceObjectNode; } - private void createVfObjectNode(ObjectNode vfObjectNode2, List<SdcResource> rawCldsSdcResourceList) { + private void createVfObjectNode(ObjectNode vfObjectNode2, + List<SdcResource> rawCldsSdcResourceList) { ObjectMapper mapper = JacksonUtils.getObjectMapperInstance(); ObjectNode vfNode = mapper.createObjectNode(); vfNode.put("", ""); // To remove repeated resource instance name from // resourceInstanceList List<SdcResource> cldsSdcResourceList = sdcCatalogServices - .removeDuplicateSdcResourceInstances(rawCldsSdcResourceList); + .removeDuplicateSdcResourceInstances(rawCldsSdcResourceList); /** * Creating vf resource node using cldsSdcResource Object */ @@ -785,12 +772,14 @@ public class CldsService extends SecureServiceBase { */ ObjectNode locationJsonNode; try { - locationJsonNode = (ObjectNode) mapper.readValue(refProp.getStringValue("ui.location.default"), + 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); + 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); + "Unable to load ui.location.default JSON in clds-references.properties properly", e); } vfObjectNode2.putPOJO("location", locationJsonNode); /** @@ -802,9 +791,10 @@ public class CldsService extends SecureServiceBase { 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); + 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); } @@ -840,12 +830,14 @@ public class CldsService extends SecureServiceBase { fillInCldsModel(model); String bpmnJson = cldsBpmnTransformer.doXslTransformToString(model.getBpmnText()); logger.info("PUT bpmnJson={}", bpmnJson); - SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage, + SecureServicePermission permisionManage = SecureServicePermission + .create(cldsPermissionTypeClManage, cldsPermissionInstance, CldsEvent.ACTION_DEPLOY); isAuthorized(permisionManage); isAuthorizedForVf(model); - ModelProperties modelProp = new ModelProperties(modelName, model.getControlName(), CldsEvent.ACTION_DEPLOY, - false, bpmnJson, model.getPropText()); + ModelProperties modelProp = new ModelProperties(modelName, model.getControlName(), + CldsEvent.ACTION_DEPLOY, + false, bpmnJson, model.getPropText()); checkForDuplicateServiceVf(modelName, model.getPropText()); String deploymentId = ""; // If model is already deployed then pass same deployment id @@ -854,9 +846,11 @@ public class CldsService extends SecureServiceBase { } else { deploymentId = "closedLoop_" + UUID.randomUUID() + "_deploymentId"; } - String createNewDeploymentStatusUrl = dcaeDispatcherServices.createNewDeployment(deploymentId, + String createNewDeploymentStatusUrl = dcaeDispatcherServices + .createNewDeployment(deploymentId, model.getTypeId(), modelProp.getGlobal().getDeployParameters()); - String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(createNewDeploymentStatusUrl); + String operationStatus = dcaeDispatcherServices + .getOperationStatusWithRetry(createNewDeploymentStatusUrl); if ("succeeded".equalsIgnoreCase(operationStatus)) { String artifactName = model.getControlName(); if (artifactName != null) { @@ -866,16 +860,20 @@ public class CldsService extends SecureServiceBase { /* set dcae events */ dcaeEvent.setArtifactName(artifactName); dcaeEvent.setEvent(DcaeEvent.EVENT_DEPLOYMENT); - CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), getUserId(), dcaeEvent.getCldsActionCd(), - CldsEvent.ACTION_STATE_RECEIVED, null); + 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); + 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); + "Deploy model (" + modelName + ") failed...Operation Status is - " + + operationStatus); } - logger.info("Deploy model (" + modelName + ") succeeded...Deployment Id is - " + deploymentId); + 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()); @@ -899,13 +897,16 @@ public class CldsService extends SecureServiceBase { LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName()); Boolean errorCase = false; try { - SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage, + SecureServicePermission permisionManage = SecureServicePermission + .create(cldsPermissionTypeClManage, cldsPermissionInstance, CldsEvent.ACTION_UNDEPLOY); isAuthorized(permisionManage); isAuthorizedForVf(model); - String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(), + String operationStatusUndeployUrl = dcaeDispatcherServices + .deleteExistingDeployment(model.getDeploymentId(), model.getTypeId()); - String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(operationStatusUndeployUrl); + String operationStatus = dcaeDispatcherServices + .getOperationStatusWithRetry(operationStatusUndeployUrl); if ("succeeded".equalsIgnoreCase(operationStatus)) { String artifactName = model.getControlName(); if (artifactName != null) { @@ -915,19 +916,23 @@ public class CldsService extends SecureServiceBase { // set dcae events dcaeEvent.setArtifactName(artifactName); dcaeEvent.setEvent(DcaeEvent.EVENT_UNDEPLOYMENT); - CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), dcaeEvent.getCldsActionCd(), - CldsEvent.ACTION_STATE_RECEIVED, null); + 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); + 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); + "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()); + LoggingUtils + .setResponseContext("0", "Undeploy model success", this.getClass().getName()); auditLogger.info("Undeploy model completed"); } catch (Exception e) { errorCase = true; @@ -939,21 +944,26 @@ public class CldsService extends SecureServiceBase { return Response.status(Response.Status.OK).entity(model).build(); } - private void checkForDuplicateServiceVf(String modelName, String modelPropText) throws IOException { - JsonNode globalNode = JacksonUtils.getObjectMapperInstance().readTree(modelPropText).get("global"); + private void checkForDuplicateServiceVf(String modelName, String modelPropText) + throws IOException { + JsonNode globalNode = JacksonUtils.getObjectMapperInstance().readTree(modelPropText) + .get("global"); String service = AbstractModelElement.getValueByName(globalNode, "service"); List<String> resourceVf = AbstractModelElement.getValuesByName(globalNode, "vf"); if (service != null && resourceVf != null && !resourceVf.isEmpty()) { List<CldsModelProp> cldsModelPropList = cldsDao.getDeployedModelProperties(); for (CldsModelProp cldsModelProp : cldsModelPropList) { - JsonNode currentNode = JacksonUtils.getObjectMapperInstance().readTree(cldsModelProp.getPropText()) - .get("global"); + JsonNode currentNode = JacksonUtils.getObjectMapperInstance() + .readTree(cldsModelProp.getPropText()) + .get("global"); String currentService = AbstractModelElement.getValueByName(currentNode, "service"); List<String> currentVf = AbstractModelElement.getValuesByName(currentNode, "vf"); if (currentVf != null && !currentVf.isEmpty()) { - if (!modelName.equalsIgnoreCase(cldsModelProp.getName()) && service.equalsIgnoreCase(currentService) - && resourceVf.get(0).equalsIgnoreCase(currentVf.get(0))) { - throw new BadRequestException("Same Service/VF already exists in " + cldsModelProp.getName() + if (!modelName.equalsIgnoreCase(cldsModelProp.getName()) && service + .equalsIgnoreCase(currentService) + && resourceVf.get(0).equalsIgnoreCase(currentVf.get(0))) { + throw new BadRequestException( + "Same Service/VF already exists in " + cldsModelProp.getName() + " model, please select different Service/VF."); } } @@ -961,13 +971,14 @@ public class CldsService extends SecureServiceBase { } } - private void updateAndInsertNewEvent(String cldsModelName, String cldsControlNamePrfx, CldsEvent event, - String newAction) { + private void updateAndInsertNewEvent(String cldsModelName, String cldsControlNamePrfx, + CldsEvent event, + String newAction) { // If model action is in submit/resubmit/distributed and user try // to save then we are changing action back to create. if (event != null && (CldsEvent.ACTION_SUBMIT.equalsIgnoreCase(event.getActionCd()) - || CldsEvent.ACTION_RESUBMIT.equalsIgnoreCase(event.getActionCd()) - || CldsEvent.ACTION_DISTRIBUTE.equalsIgnoreCase(event.getActionCd()))) { + || CldsEvent.ACTION_RESUBMIT.equalsIgnoreCase(event.getActionCd()) + || CldsEvent.ACTION_DISTRIBUTE.equalsIgnoreCase(event.getActionCd()))) { CldsEvent newEvent = new CldsEvent(); newEvent.setUserid(getUserId()); newEvent.setActionCd(newAction); |