aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java270
1 files changed, 160 insertions, 110 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
index 703e0f9aa5..b0247a26e2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/lifecycle/LifecycleBusinessLogic.java
@@ -20,17 +20,11 @@
package org.openecomp.sdc.be.components.lifecycle;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.annotation.PostConstruct;
-
+import fj.data.Either;
+import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
-import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ProductBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.*;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
@@ -39,13 +33,9 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
-import org.openecomp.sdc.be.model.Component;
-import org.openecomp.sdc.be.model.LifeCycleTransitionEnum;
-import org.openecomp.sdc.be.model.LifecycleStateEnum;
-import org.openecomp.sdc.be.model.Resource;
-import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
+import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.jsontitan.utils.ModelConverter;
@@ -54,16 +44,18 @@ import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.CapabilityOperation;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.resources.data.auditing.model.ResourceAuditData;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
+import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
import org.openecomp.sdc.be.tosca.ToscaExportHandler;
import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import fj.data.Either;
+import javax.annotation.PostConstruct;
+import java.util.HashMap;
+import java.util.Map;
@org.springframework.stereotype.Component("lifecycleBusinessLogic")
public class LifecycleBusinessLogic {
@@ -82,7 +74,7 @@ public class LifecycleBusinessLogic {
@Autowired
private CapabilityOperation capabilityOperation;
- private static final Logger log = LoggerFactory.getLogger(LifecycleBusinessLogic.class);
+ private static final Logger log = Logger.getLogger(LifecycleBusinessLogic.class);
@javax.annotation.Resource
private ComponentsUtils componentUtils;
@@ -112,6 +104,9 @@ public class LifecycleBusinessLogic {
@Autowired
ToscaOperationFacade toscaOperationFacade;
+
+ @Autowired
+ NodeTemplateOperation nodeTemplateOperation;
private Map<String, LifeCycleTransition> stateTransitions;
private static volatile boolean isInitialized = false;
@@ -130,7 +125,7 @@ public class LifecycleBusinessLogic {
}
private void initStateOperations() {
- stateTransitions = new HashMap<String, LifeCycleTransition>();
+ stateTransitions = new HashMap<>();
LifeCycleTransition checkoutOp = new CheckoutTransition(componentUtils, lifecycleOperation, toscaOperationFacade, titanDao);
stateTransitions.put(checkoutOp.getName().name(), checkoutOp);
@@ -142,7 +137,8 @@ public class LifecycleBusinessLogic {
LifeCycleTransition checkinOp = new CheckinTransition(componentUtils, lifecycleOperation, toscaOperationFacade, titanDao);
stateTransitions.put(checkinOp.getName().name(), checkinOp);
- LifeCycleTransition certificationRequest = new CertificationRequestTransition(componentUtils, lifecycleOperation, serviceDistributionArtifactsBuilder, serviceBusinessLogic, capabilityOperation, toscaExportUtils, toscaOperationFacade, titanDao);
+ LifeCycleTransition certificationRequest = new CertificationRequestTransition(componentUtils, lifecycleOperation, serviceBusinessLogic, toscaOperationFacade,
+ titanDao);
stateTransitions.put(certificationRequest.getName().name(), certificationRequest);
LifeCycleTransition startCertification = new StartCertificationTransition(componentUtils, lifecycleOperation, toscaOperationFacade, titanDao);
@@ -156,6 +152,7 @@ public class LifecycleBusinessLogic {
CertificationChangeTransition successCertification = new CertificationChangeTransition(LifeCycleTransitionEnum.CERTIFY, componentUtils, lifecycleOperation, toscaOperationFacade, titanDao);
successCertification.setArtifactsManager(artifactsBusinessLogic);
+ successCertification.setNodeTemplateOperation(nodeTemplateOperation);
stateTransitions.put(successCertification.getName().name(), successCertification);
}
@@ -172,10 +169,10 @@ public class LifecycleBusinessLogic {
return (Either<Resource, ResponseFormat>) changeComponentState(ComponentTypeEnum.RESOURCE, resourceId, modifier, transitionEnum, changeInfo, inTransaction, needLock);
}
- private boolean isComponentVFCMT(Component component, ComponentTypeEnum componentType){
- if (componentType.equals(ComponentTypeEnum.RESOURCE)){
- ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition)component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType();
- if (resourceType.equals(ResourceTypeEnum.VFCMT)){
+ private boolean isComponentVFCMT(Component component, ComponentTypeEnum componentType) {
+ if (componentType.equals(ComponentTypeEnum.RESOURCE)) {
+ ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType();
+ if (resourceType.equals(ResourceTypeEnum.VFCMT)) {
return true;
}
}
@@ -188,11 +185,11 @@ public class LifecycleBusinessLogic {
LifeCycleTransition lifeCycleTransition = stateTransitions.get(transitionEnum.name());
if (lifeCycleTransition == null) {
log.debug("state operation is not valid. operations allowed are: {}", LifeCycleTransitionEnum.valuesAsString());
- ResponseFormat error = componentUtils.getInvalidContentErrorAndAudit(modifier,componentId, AuditingActionEnum.CHECKOUT_RESOURCE);
+ ResponseFormat error = componentUtils.getInvalidContentErrorAndAudit(modifier, componentId, AuditingActionEnum.CHECKOUT_RESOURCE);
return Either.right(error);
}
Component component = null;
- log.info("get resource from graph");
+ log.debug("get resource from graph");
ResponseFormat errorResponse;
Either<? extends Component, ResponseFormat> eitherResourceResponse = getComponentForChange(componentType, componentId, modifier, lifeCycleTransition, changeInfo);
@@ -205,12 +202,17 @@ public class LifecycleBusinessLogic {
// lock resource
if (!inTransaction && needLock) {
- log.info("lock component {}", componentId);
+ log.debug("lock component {}", componentId);
Either<Boolean, ResponseFormat> eitherLockResource = lockComponent(componentType, component);
if (eitherLockResource.isRight()) {
errorResponse = eitherLockResource.right().value();
- componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(), componentType,
- ResourceAuditData.newBuilder().state(resourceCurrState.name()).version(resourceCurrVersion).build());
+ componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(),
+ new ResourceCommonInfo(componentType.getValue()),
+ ResourceVersionInfo.newBuilder()
+ .state(resourceCurrState.name())
+ .version(resourceCurrVersion)
+ .build());
+
log.error("lock component {} failed", componentId);
return Either.right(errorResponse);
@@ -221,9 +223,13 @@ public class LifecycleBusinessLogic {
Either<String, ResponseFormat> commentValidationResult = validateComment(changeInfo, transitionEnum);
if (commentValidationResult.isRight()) {
errorResponse = commentValidationResult.right().value();
- componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(), componentType,
- ResourceAuditData.newBuilder()
- .state(resourceCurrState.name()).version(resourceCurrVersion).build(), changeInfo.getUserRemarks());
+ componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(),
+ new ResourceCommonInfo(componentType.getValue()),
+ ResourceVersionInfo.newBuilder()
+ .state(resourceCurrState.name())
+ .version(resourceCurrVersion)
+ .build(),
+ changeInfo.getUserRemarks());
return Either.right(errorResponse);
}
changeInfo.setUserRemarks(commentValidationResult.left().value());
@@ -233,12 +239,12 @@ public class LifecycleBusinessLogic {
return Either.right(validateHighestVersion.right().value());
}
log.debug("after validate Highest Version");
- if (isComponentVFCMT(component,componentType)){
- Either<? extends Component, ResponseFormat> changeVFCMTStateResponse = changeVFCMTState(componentType, modifier, transitionEnum, changeInfo, true, component);
- if (changeVFCMTStateResponse.isRight()){
- return changeVFCMTStateResponse;
+ if (componentType == ComponentTypeEnum.RESOURCE) {
+ Either<? extends Component, ResponseFormat> changeResourceResponse = changeResourceState(componentType, modifier, transitionEnum, changeInfo, true, component);
+ if (changeResourceResponse.isRight()) {
+ return changeResourceResponse;
}
- component = changeVFCMTStateResponse.left().value();
+ component = changeResourceResponse.left().value();
}
return changeState(component, lifeCycleTransition, componentType, modifier, changeInfo, inTransaction);
} finally {
@@ -255,49 +261,75 @@ public class LifecycleBusinessLogic {
}
/*
- * special case for certification of VFCMT - VFCMT can be certified by Designer or Tester right after checkin
- * in case the operation "submit for test" / "start testing" is done to "VFCMT" - please return error 400
+ * special case for certification of VFCMT - VFCMT can be certified by Designer or Tester right after checkin in case the operation "submit for test" / "start testing" is done to "VFCMT" - please return error 400
*/
- private Either<? extends Component, ResponseFormat> changeVFCMTState(ComponentTypeEnum componentType, User modifier,
- LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction,
+ private Either<? extends Component, ResponseFormat> changeResourceState(ComponentTypeEnum componentType, User modifier, LifeCycleTransitionEnum transitionEnum, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction,
Component component) {
LifecycleStateEnum oldState = component.getLifecycleState();
Component updatedComponent = component;
- if (transitionEnum.equals(LifeCycleTransitionEnum.START_CERTIFICATION) ||
- transitionEnum.equals(LifeCycleTransitionEnum.CERTIFICATION_REQUEST)){
- return Either.right(componentUtils.getResponseFormat(
- ActionStatus.RESOURCE_VFCMT_LIFECYCLE_STATE_NOT_VALID, transitionEnum.getDisplayName()));
- } //certify is done directly from checkin
- else if (transitionEnum.equals(LifeCycleTransitionEnum.CERTIFY) && oldState.equals(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN)){
- //we will call for submit for testing first and then for certify
- Either<? extends Component, ResponseFormat> actionResponse = changeState(component,
- stateTransitions.get(LifeCycleTransitionEnum.CERTIFICATION_REQUEST.name()),
- componentType, modifier, changeInfo, inTransaction);
- if (actionResponse.isRight()) {
- return actionResponse;
+ if (transitionEnum == LifeCycleTransitionEnum.START_CERTIFICATION || transitionEnum == LifeCycleTransitionEnum.CERTIFICATION_REQUEST) {
+ //for VFCMT use old error for backward comp.
+ ActionStatus status = isComponentVFCMT(component, componentType) ? ActionStatus.RESOURCE_VFCMT_LIFECYCLE_STATE_NOT_VALID : ActionStatus.RESOURCE_LIFECYCLE_STATE_NOT_VALID;
+ return Either.right(componentUtils.getResponseFormat(status, transitionEnum.getDisplayName()));
+ } // certify is done directly from checkin
+ else if (transitionEnum == LifeCycleTransitionEnum.CERTIFY) {
+ log.debug("Certification request for resource {} ", component.getUniqueId());
+ if (oldState == LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT) {
+ log.debug("Resource {} is in Checkout state perform checkin", component.getUniqueId());
+ Either<? extends Component, ResponseFormat> actionResponse = changeState(component, stateTransitions.get(LifeCycleTransitionEnum.CHECKIN.name()), componentType, modifier, changeInfo, inTransaction);
+ if (actionResponse.isRight()) {
+ log.debug("Failed to check in Resource {} error {}", component.getUniqueId(), actionResponse.right().value());
+ return actionResponse;
+ }
+ updatedComponent = actionResponse.left().value();
+ oldState = updatedComponent.getLifecycleState();
}
- updatedComponent = actionResponse.left().value();
- actionResponse = changeState(updatedComponent,
- stateTransitions.get(LifeCycleTransitionEnum.START_CERTIFICATION.name()),
- componentType, modifier, changeInfo, inTransaction);
- if (actionResponse.isRight()) {
- return actionResponse;
+ if (oldState == LifecycleStateEnum.NOT_CERTIFIED_CHECKIN) {
+ // we will call for submit for testing first and then for certify
+ Either<? extends Component, ResponseFormat> actionResponse = changeState(updatedComponent, stateTransitions.get(LifeCycleTransitionEnum.CERTIFICATION_REQUEST.name()), componentType, modifier, changeInfo, inTransaction);
+ if (actionResponse.isRight()) {
+ return actionResponse;
+ }
+ updatedComponent = actionResponse.left().value();
+ actionResponse = changeState(updatedComponent, stateTransitions.get(LifeCycleTransitionEnum.START_CERTIFICATION.name()), componentType, modifier, changeInfo, inTransaction);
+ if (actionResponse.isRight()) {
+ return actionResponse;
+ }
+ updatedComponent = actionResponse.left().value();
+ }
+ if(oldState == LifecycleStateEnum.CERTIFIED){
+ failOnAlreadyCertifiedResource(component);
}
- updatedComponent = actionResponse.left().value();
-
}
return Either.left(updatedComponent);
}
- private Either<? extends Component, ResponseFormat> changeState(Component component, LifeCycleTransition lifeCycleTransition,
- ComponentTypeEnum componentType, User modifier, LifecycleChangeInfoWithAction changeInfo,boolean inTransaction){
+ private void failOnAlreadyCertifiedResource(Component component) {
+ String firstName = null;
+ String lastName = null;
+ if(StringUtils.isNotEmpty(component.getLastUpdaterFullName())){
+ String[] fullName = component.getLastUpdaterFullName().split(" ");
+ if(fullName.length == 2){
+ firstName = fullName[0];
+ lastName = fullName[1];
+ }
+ }
+ throw new ComponentException(ActionStatus.COMPONENT_ALREADY_CERTIFIED,
+ component.getName(),
+ component.getComponentType().name().toLowerCase(),
+ firstName,
+ lastName,
+ component.getLastUpdaterUserId());
+ }
+
+ private Either<? extends Component, ResponseFormat> changeState(Component component, LifeCycleTransition lifeCycleTransition, ComponentTypeEnum componentType, User modifier, LifecycleChangeInfoWithAction changeInfo, boolean inTransaction) {
ResponseFormat errorResponse;
LifecycleStateEnum oldState = component.getLifecycleState();
String resourceCurrVersion = component.getVersion();
ComponentBusinessLogic bl = getComponentBL(componentType);
- Either<User, ResponseFormat> ownerResult = lifeCycleTransition.getComponentOwner(component, componentType, inTransaction);
+ Either<User, ResponseFormat> ownerResult = lifeCycleTransition.getComponentOwner(component, componentType);
if (ownerResult.isRight()) {
return Either.right(ownerResult.right().value());
}
@@ -308,29 +340,43 @@ public class LifecycleBusinessLogic {
if (stateValidationResult.isRight()) {
log.error("Failed to validateBeforeTransition");
errorResponse = stateValidationResult.right().value();
- componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(), componentType,
- ResourceAuditData.newBuilder().version(resourceCurrVersion).state(oldState.name()).build(), changeInfo.getUserRemarks());
+ componentUtils.auditComponent(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(),
+ new ResourceCommonInfo(componentType.getValue()),
+ ResourceVersionInfo.newBuilder()
+ .version(resourceCurrVersion)
+ .state(oldState.name())
+ .build(),
+ changeInfo.getUserRemarks());
return Either.right(errorResponse);
}
-
+
Either<? extends Component, ResponseFormat> operationResult = lifeCycleTransition.changeState(componentType, component, bl, modifier, owner, false, inTransaction);
if (operationResult.isRight()) {
errorResponse = operationResult.right().value();
log.info("audit before sending error response");
componentUtils.auditComponentAdmin(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(), componentType,
- ResourceAuditData.newBuilder().state(oldState.name()).version(resourceCurrVersion).build());
+ ResourceVersionInfo.newBuilder()
+ .state(oldState.name())
+ .version(resourceCurrVersion)
+ .build());
return Either.right(errorResponse);
}
Component resourceAfterOperation = operationResult.left().value();
- componentUtils.auditComponent(componentUtils.getResponseFormat(ActionStatus.OK), modifier, resourceAfterOperation, lifeCycleTransition.getAuditingAction(), componentType,
- ResourceAuditData.newBuilder().state(oldState.name()).version(resourceCurrVersion).build(), changeInfo.getUserRemarks());
+ componentUtils.auditComponent(componentUtils.getResponseFormat(ActionStatus.OK), modifier, resourceAfterOperation,
+ lifeCycleTransition.getAuditingAction(), new ResourceCommonInfo(componentType.getValue()),
+ ResourceVersionInfo.newBuilder()
+ .state(oldState.name())
+ .version(resourceCurrVersion)
+ .build(),
+ changeInfo.getUserRemarks());
return operationResult;
}
- private Either<? extends Component, ResponseFormat> getComponentForChange(ComponentTypeEnum componentType, String componentId, User modifier, LifeCycleTransition lifeCycleTransition, LifecycleChangeInfoWithAction changeInfo) {
+
+ private Either<? extends Component, ResponseFormat> getComponentForChange(ComponentTypeEnum componentType, String componentId, User modifier, LifeCycleTransition lifeCycleTransition, LifecycleChangeInfoWithAction changeInfo) {
Either<? extends Component, StorageOperationStatus> eitherResourceResponse = toscaOperationFacade.getToscaElement(componentId);
@@ -339,7 +385,8 @@ public class LifecycleBusinessLogic {
ActionStatus actionStatus = componentUtils.convertFromStorageResponse(eitherResourceResponse.right().value(), componentType);
errorResponse = componentUtils.getResponseFormat(actionStatus, Constants.EMPTY_STRING);
log.debug("audit before sending response");
- componentUtils.auditComponent(errorResponse, modifier, lifeCycleTransition.getAuditingAction(), componentId, componentType, changeInfo.getUserRemarks());
+ componentUtils.auditComponent(errorResponse, modifier, lifeCycleTransition.getAuditingAction(),
+ new ResourceCommonInfo(componentId, componentType.getValue()), changeInfo.getUserRemarks());
return Either.right(errorResponse);
}
@@ -352,8 +399,11 @@ public class LifecycleBusinessLogic {
log.debug("Component version {} is not the last version of component {}", component.getComponentMetadataDefinition().getMetadataDataDefinition().getVersion(),
component.getComponentMetadataDefinition().getMetadataDataDefinition().getName());
errorResponse = componentUtils.getResponseFormat(ActionStatus.COMPONENT_HAS_NEWER_VERSION, component.getComponentMetadataDefinition().getMetadataDataDefinition().getName(), componentType.getValue().toLowerCase());
- componentUtils.auditComponentAdmin(errorResponse, modifier, component,lifeCycleTransition.getAuditingAction(), componentType,
- ResourceAuditData.newBuilder().state(component.getLifecycleState().name()).version(resourceCurrVersion).build());
+ componentUtils.auditComponentAdmin(errorResponse, modifier, component, lifeCycleTransition.getAuditingAction(), componentType,
+ ResourceVersionInfo.newBuilder()
+ .state(component.getLifecycleState().name())
+ .version(resourceCurrVersion)
+ .build());
return Either.right(errorResponse);
}
return Either.left(true);
@@ -405,17 +455,17 @@ public class LifecycleBusinessLogic {
private ComponentBusinessLogic getComponentBL(ComponentTypeEnum componentTypeEnum) {
ComponentBusinessLogic businessLogic;
switch (componentTypeEnum) {
- case RESOURCE:
- businessLogic = this.resourceBusinessLogic;
- break;
- case SERVICE:
- businessLogic = this.serviceBusinessLogic;
- break;
- case PRODUCT:
- businessLogic = this.productBusinessLogic;
- break;
- default:
- throw new IllegalArgumentException("Illegal component type:" + componentTypeEnum.getValue());
+ case RESOURCE:
+ businessLogic = this.resourceBusinessLogic;
+ break;
+ case SERVICE:
+ businessLogic = this.serviceBusinessLogic;
+ break;
+ case PRODUCT:
+ businessLogic = this.productBusinessLogic;
+ break;
+ default:
+ throw new IllegalArgumentException("Illegal component type:" + componentTypeEnum.getValue());
}
return businessLogic;
}
@@ -433,41 +483,41 @@ public class LifecycleBusinessLogic {
return Either.left(latestComponent);
}
-/**
- * Performs Force certification.
- * Note that a Force certification is allowed for the first certification only,
- * as only a state and a version is promoted due a Force certification,
- * skipping other actions required if a previous certified version exists.
- * @param resource
- * @param user
- * @param lifecycleChangeInfo
- * @param inTransaction
- * @param needLock
- * @return
- */
+
+ /**
+ * Performs Force certification. Note that a Force certification is allowed for the first certification only, as only a state and a version is promoted due a Force certification, skipping other actions required if a previous certified version
+ * exists.
+ *
+ * @param resource
+ * @param user
+ * @param lifecycleChangeInfo
+ * @param inTransaction
+ * @param needLock
+ * @return
+ */
public Either<Resource, ResponseFormat> forceResourceCertification(Resource resource, User user, LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean inTransaction, boolean needLock) {
Either<Resource, ResponseFormat> result = null;
Either<ToscaElement, StorageOperationStatus> certifyResourceRes = null;
- if(lifecycleChangeInfo.getAction() != LifecycleChanceActionEnum.CREATE_FROM_CSAR){
+ if (lifecycleChangeInfo.getAction() != LifecycleChanceActionEnum.CREATE_FROM_CSAR) {
log.debug("Force certification is not allowed for the action {}. ", lifecycleChangeInfo.getAction());
result = Either.right(componentUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
}
- if(!isFirstCertification(resource.getVersion())){
+ if (!isFirstCertification(resource.getVersion())) {
log.debug("Failed to perform a force certification of resource{}. Force certification is allowed for the first certification only. ", resource.getName());
result = Either.right(componentUtils.getResponseFormat(ActionStatus.NOT_ALLOWED));
}
// lock resource
- if(result == null && !inTransaction && needLock){
+ if (result == null && !inTransaction && needLock) {
log.info("lock component {}", resource.getUniqueId());
Either<Boolean, ResponseFormat> eitherLockResource = lockComponent(resource.getComponentType(), resource);
if (eitherLockResource.isRight()) {
log.error("lock component {} failed", resource.getUniqueId());
- result = Either.right(eitherLockResource.right().value());
+ result = Either.right(eitherLockResource.right().value());
}
log.info("after lock component {}", resource.getUniqueId());
}
- try{
- if(result == null){
+ try {
+ if (result == null) {
certifyResourceRes = lifecycleOperation.forceCerificationOfToscaElement(resource.getUniqueId(), user.getUserId(), user.getUserId(), resource.getVersion());
if (certifyResourceRes.isRight()) {
StorageOperationStatus status = certifyResourceRes.right().value();
@@ -475,18 +525,18 @@ public class LifecycleBusinessLogic {
result = Either.right(componentUtils.getResponseFormatByResource(componentUtils.convertFromStorageResponse(status), resource));
}
}
- if(result == null){
+ if (result == null) {
result = Either.left(ModelConverter.convertFromToscaElement(certifyResourceRes.left().value()));
}
} finally {
log.info("unlock component {}", resource.getUniqueId());
if (!inTransaction) {
- if(result.isLeft()){
+ if (result.isLeft()) {
titanDao.commit();
- } else{
+ } else {
titanDao.rollback();
}
- if(needLock){
+ if (needLock) {
NodeTypeEnum nodeType = resource.getComponentType().getNodeType();
log.info("During change state, another component {} has been created/updated", resource.getUniqueId());
graphLockOperation.unlockComponent(resource.getUniqueId(), nodeType);