operationName, auditingAction, user, parent, needUpdateGroup);
break;
case CREATE:
- result = handleCreate(componentId, artifactInfo, operation, auditingAction, user, componentType, parent, origMd5, originData,
+ result = handleCreate(componentId, artifactInfo, operation, auditingAction, user, componentType, parent, origMd5, originData,
interfaceName, operationName);
break;
case LINK:
}
} else {
String encodeBase64Str = GeneralUtility.calculateMD5Base64EncodedByString(originData);
+ log.info("ValidateMd5 - computed MD5: {}", encodeBase64Str);
if (!encodeBase64Str.equals(origMd5)) {
log.debug("The calculated md5 is different then the received one");
throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_INVALID_MD5);
throw new StorageException(result.right().value());
}
ArtifactDefinition artifactDefinition = result.left().value();
+ if (artifactInfo.getArtifactUUID() != null && !artifactInfo.getArtifactUUID().isEmpty()) {
+ artifactDefinition.setArtifactUUID(artifactInfo.getArtifactUUID());
+ }
artifactData.setId(artifactDefinition.getEsId());
operationResult = Either.left(artifactDefinition);
if (generateCustomizationUUIDOnInstance(parent.getUniqueId(), parentId, componentTypeEnum) != StorageOperationStatus.OK) {
@Override
public <T extends Component> Either<T, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component,
ComponentBusinessLogic componentBl, User modifier, User owner,
- boolean shouldLock, boolean inTransaction) {
+ boolean shouldLock, boolean inTransaction, String requestUUID) {
log.info("start performing certification change for resource {}", component.getUniqueId());
Either<T, ResponseFormat> result = null;
try {
component = handleValidationsBeforeCertifying(componentType, component, modifier, shouldLock, inTransaction);
Either<ToscaElement, StorageOperationStatus> certificationChangeResult = lifeCycleOperation
- .certifyToscaElement(component.getUniqueId(), modifier.getUserId(), owner.getUserId());
+ .certifyToscaElement(component.getUniqueId(), modifier.getUserId(), owner.getUserId(), requestUUID);
if (certificationChangeResult.isRight()) {
ResponseFormat responseFormat = formatCertificationError(component, certificationChangeResult.right().value(), componentType);
result = Either.right(responseFormat);
}
ToscaElement certificationResult = certificationChangeResult.left().value();
+ if (requestUUID != null && !requestUUID.trim().isEmpty()) {
+ certificationResult.setUUID(requestUUID);
+ }
T componentAfterCertification = ModelConverter.convertFromToscaElement(certificationResult);
if (result == null || result.isLeft()) {
//update edges for allotted resource
@Override
public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component,
ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock,
- boolean inTransaction) {
+ boolean inTransaction, String requestUUID) {
log.debug("start performing checkin for {} {}", componentType, component.getUniqueId());
Either<? extends Component, ResponseFormat> result = null;
try {
Either<ToscaElement, StorageOperationStatus> checkinResourceResult = lifeCycleOperation
- .checkinToscaELement(component.getLifecycleState(), component.getUniqueId(), modifier.getUserId(), owner.getUserId());
+ .checkinToscaELement(component.getLifecycleState(), component.getUniqueId(), modifier.getUserId(), owner.getUserId(), requestUUID);
if (checkinResourceResult.isRight()) {
log.debug("checkout failed on graph");
StorageOperationStatus response = checkinResourceResult.right().value();
ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
result = Either.right(responseFormat);
} else {
+ ToscaElement element = checkinResourceResult.left().value();
+
+ // Override UUID if requestUUID is provided
+ if (requestUUID != null && !requestUUID.trim().isEmpty()) {
+ element.setUUID(requestUUID);
+ }
updateCalculatedCapabilitiesRequirements(checkinResourceResult.left().value());
Component r = ModelConverter.convertFromToscaElement(checkinResourceResult.left().value());
updateGroupsAndPolicesVersion(r);
@Override
public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component,
ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock,
- boolean inTransaction) {
+ boolean inTransaction, String requestUUID) {
log.debug("start performing {} for resource {}", getName(), component.getUniqueId());
Either<? extends Component, ResponseFormat> result = null;
try {
final Either<ToscaElement, StorageOperationStatus> checkoutResourceResult = lifeCycleOperation
- .checkoutToscaElement(component.getUniqueId(), modifier.getUserId(), owner.getUserId());
+ .checkoutToscaElement(component.getUniqueId(), modifier.getUserId(), owner.getUserId(), requestUUID);
if (checkoutResourceResult.isRight()) {
log.debug("checkout failed on graph");
StorageOperationStatus response = checkoutResourceResult.right().value();
ResponseFormat responseFormat = componentUtils.getResponseFormatByComponent(actionStatus, component, componentType);
result = Either.right(responseFormat);
} else {
+ ToscaElement toscaElement = checkoutResourceResult.left().value();
+
+ // --- REQUEST UUID OVERRIDE ---
+ if (requestUUID != null && !requestUUID.trim().isEmpty()) {
+ toscaElement.setUUID(requestUUID);
+ }
Component clonedComponent = ModelConverter.convertFromToscaElement(checkoutResourceResult.left().value());
if (componentType == ComponentTypeEnum.SERVICE) {
Service service = (Service) clonedComponent;
public abstract <T extends Component> Either<T, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component,
ComponentBusinessLogic componentBl, User modifier, User owner,
- boolean needLock, boolean inTransaction);
+ boolean needLock, boolean inTransaction, String requestUUID);
public abstract Either<Boolean, ResponseFormat> validateBeforeTransition(Component component, ComponentTypeEnum componentType, User modifier,
User owner, LifecycleStateEnum oldState,
LifeCycleTransitionEnum transitionEnum,
LifecycleChangeInfoWithAction changeInfo, boolean inTransaction,
boolean needLock) {
+ return changeComponentState(componentType, componentId, modifier, transitionEnum, changeInfo, inTransaction, needLock, null);
+ }
+
+ public <T extends Component> Either<T, ResponseFormat> changeComponentState(ComponentTypeEnum componentType, String componentId, User modifier,
+ LifeCycleTransitionEnum transitionEnum,
+ LifecycleChangeInfoWithAction changeInfo, boolean inTransaction,
+ boolean needLock, String requestUUID) {
LifeCycleTransition lifeCycleTransition = stateTransitions.get(transitionEnum.name());
if (lifeCycleTransition == null) {
log.debug("state operation is not valid. operations allowed are: {}", LifeCycleTransitionEnum.valuesAsString());
return Either.right(checkedInComponentEither.right().value());
}
component = checkedInComponentEither.left().value();
- return changeState(component, lifeCycleTransition, componentType, modifier, changeInfo, inTransaction).left()
- .bind(c -> updateCatalog(c, oldComponent, ChangeTypeEnum.LIFECYCLE));
+ Either<T, ResponseFormat> result = changeState(
+ component,
+ lifeCycleTransition,
+ componentType,
+ modifier,
+ changeInfo,
+ inTransaction, requestUUID);
+ Either<T, ResponseFormat> finalResult = result.left()
+ .bind(c -> updateCatalog(c, oldComponent, ChangeTypeEnum.LIFECYCLE));
+
+ return finalResult;
+
} finally {
component.setUniqueId(componentId);
if (!inTransaction && needLock) {
return Either.left(component);
}
+ private <T extends Component> Either<T, ResponseFormat> changeState(
+ T component,
+ LifeCycleTransition lifeCycleTransition,
+ ComponentTypeEnum componentType,
+ User modifier,
+ LifecycleChangeInfoWithAction changeInfo,
+ boolean inTransaction) {
+
+ return changeState(component,
+ lifeCycleTransition,
+ componentType,
+ modifier,
+ changeInfo,
+ inTransaction,
+ null);
+}
+
+
private <T extends Component> Either<T, ResponseFormat> changeState(T component, LifeCycleTransition lifeCycleTransition,
ComponentTypeEnum componentType, User modifier,
- LifecycleChangeInfoWithAction changeInfo, boolean inTransaction) {
+ LifecycleChangeInfoWithAction changeInfo, boolean inTransaction, String requestUUID) {
ResponseFormat errorResponse;
LifecycleStateEnum oldState = component.getLifecycleState();
String resourceCurrVersion = component.getVersion();
return Either.right(errorResponse);
}
Either<T, ResponseFormat> operationResult = lifeCycleTransition
- .changeState(componentType, component, bl, modifier, owner, false, inTransaction);
+ .changeState(componentType, component, bl, modifier, owner, false, inTransaction, requestUUID);
if (operationResult.isRight()) {
errorResponse = operationResult.right().value();
log.info("audit before sending error response");
ResourceVersionInfo.newBuilder().state(oldState.name()).version(resourceCurrVersion).build());
return Either.right(errorResponse);
}
+ if (requestUUID != null && !requestUUID.trim().isEmpty()) {
+ operationResult.left().value().setUUID(requestUUID);
+ }
Component resourceAfterOperation = operationResult.left().value() == null ? component : operationResult.left().value();
componentUtils.auditComponent(componentUtils.getResponseFormat(ActionStatus.OK), modifier, resourceAfterOperation,
lifeCycleTransition.getAuditingAction(), new ResourceCommonInfo(componentType.getValue()),
@Override
public Either<? extends Component, ResponseFormat> changeState(ComponentTypeEnum componentType, Component component,
ComponentBusinessLogic componentBl, User modifier, User owner, boolean shouldLock,
- boolean inTransaction) {
+ boolean inTransaction, String requestUUID) {
Either<? extends Component, ResponseFormat> result = null;
log.debug("start performing undo-checkout for resource {}", component.getUniqueId());
try {
- Either<ToscaElement, StorageOperationStatus> undoCheckoutResourceResult = lifeCycleOperation.undoCheckout(component.getUniqueId(), component.getModel());
+ Either<ToscaElement, StorageOperationStatus> undoCheckoutResourceResult = lifeCycleOperation.undoCheckout(component.getUniqueId(), component.getModel(), requestUUID);
if (undoCheckoutResourceResult.isRight()) {
log.debug("checkout failed on graph");
StorageOperationStatus response = undoCheckoutResourceResult.right().value();
} else {
ToscaElement element = undoCheckoutResourceResult.left().value();
if (element == null) {
+ if (requestUUID != null && !requestUUID.trim().isEmpty()) {
+ element.setUUID(requestUUID);
+ }
catalogOperations.updateCatalog(ChangeTypeEnum.DELETE, component);
result = Either.left(null);
} else {
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.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
@ApiResponse(responseCode = "409", description = "Artifact already exist")})
public Response loadArtifact(@PathParam("resourceId") final String resourceId,
+ @QueryParam("artifactUUID") final String customArtifactUUID,
@Parameter(description = "json describe the artifact", required = true) String data,
@Context final HttpServletRequest request) {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug(START_HANDLE_REQUEST_OF, url);
+ if (customArtifactUUID != null && !customArtifactUUID.isEmpty()) {
+ request.setAttribute("customArtifactUUID", customArtifactUUID);
+ }
return handleUploadRequest(data, request, resourceId, ComponentTypeEnum.RESOURCE);
}
loggerSupportability.log(LoggerSupportabilityActions.UPDATE_ARTIFACT, StatusCode.STARTED, "Starting to update artifact {} ",
artifactId + " for component " + componentId);
ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinition(data, ArtifactDefinition.class, validateTimeout);
+ String customUUID = (String) request.getAttribute("customArtifactUUID");
+ if (customUUID != null && !customUUID.isEmpty()) {
+ artifactInfo.setArtifactUUID(customUUID);
+ }
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
Either<ArtifactDefinition, org.openecomp.sdc.be.model.Operation> result = artifactsBusinessLogic
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.HeaderParam;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
"checkout, undoCheckout, checkin, certificationRequest, startCertification, failCertification, cancelCertification, certify"}), required = true) @PathParam(value = "lifecycleOperation") final String lifecycleTransition,
@Parameter(description = "id of component to be changed") @PathParam(value = "componentId") final String componentId,
@Context final HttpServletRequest request,
- @Parameter(description = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId)
+ @Parameter(description = "id of user initiating the operation") @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @QueryParam("requestUUID") String requestUUID)
throws IOException {
String url = request.getMethod() + " " + request.getRequestURI();
log.debug("Start handle request of {}", url);
ComponentTypeEnum componentType = ComponentTypeEnum.findByParamName(componentCollection);
if (componentType != null) {
Either<? extends Component, ResponseFormat> actionResponse = lifecycleBusinessLogic
- .changeComponentState(componentType, componentId, user, transitionEnum, changeInfo, false, true);
+ .changeComponentState(componentType, componentId, user, transitionEnum, changeInfo, false, true, requestUUID);
if (actionResponse.isRight()) {
log.info("failed to change resource state");
loggerSupportability.log(LoggerSupportabilityActions.CHANGELIFECYCLESTATE, StatusCode.ERROR,
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
private static String RES_ID_CERTIFIED = "resIdCert";
private static String SERVICE_ID = "serviceId";
private static String SERVICE_ID_CERTIFIED = "serviceIdCert";
+ private static String REQUEST_UUID = UUID.randomUUID().toString();
@BeforeEach
public void setup() {
Either<? extends Component, ResponseFormat> changeStateResult;
resource = createResourceVFCMTObject();
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- when(toscaElementLifecycleOperation.certifyToscaElement(resource.getUniqueId(), user.getUserId(), owner.getUserId()))
+ when(toscaElementLifecycleOperation.certifyToscaElement(resource.getUniqueId(), user.getUserId(), owner.getUserId(), REQUEST_UUID))
.thenReturn(Either.left(ModelConverter.convertToToscaElement(resource)));
- changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
+ changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false, REQUEST_UUID);
assertTrue(changeStateResult.isLeft());
}
Either<? extends Component, ResponseFormat> changeStateResult;
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- when(toscaElementLifecycleOperation.certifyToscaElement(RES_ID, user.getUserId(), owner.getUserId()))
+ when(toscaElementLifecycleOperation.certifyToscaElement(RES_ID, user.getUserId(), owner.getUserId(), REQUEST_UUID))
.thenReturn(Either.left(ModelConverter.convertToToscaElement(resourceAfterCertify)));
- changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
+ changeStateResult = changeTransition.changeState((ComponentTypeEnum.RESOURCE), resource, serviceBusinessLogic, user, owner, false, false, REQUEST_UUID);
assertTrue(changeStateResult.isLeft());
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
+ changeStateResult = changeTransition.changeState((ComponentTypeEnum.RESOURCE), resource, serviceBusinessLogic, user, owner, false, false, REQUEST_UUID);
assertTrue(changeStateResult.isLeft());
}
Either<? extends Component, ResponseFormat> changeStateResult;
resource.setResourceType(ResourceTypeEnum.PNF);
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- when(toscaElementLifecycleOperation.certifyToscaElement(RES_ID, user.getUserId(), owner.getUserId()))
+ when(toscaElementLifecycleOperation.certifyToscaElement(eq(RES_ID), eq(user.getUserId()), eq(owner.getUserId()), anyString()))
.thenReturn(Either.left(ModelConverter.convertToToscaElement(resourceAfterCertify)));
- changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
- assertTrue(changeStateResult.isLeft());
+ changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false, REQUEST_UUID);
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
+ changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false, REQUEST_UUID);
assertTrue(changeStateResult.isLeft());
}
Either<? extends Component, ResponseFormat> changeStateResult;
resource.setResourceType(ResourceTypeEnum.CR);
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- when(toscaElementLifecycleOperation.certifyToscaElement(RES_ID, user.getUserId(), owner.getUserId()))
+ when(toscaElementLifecycleOperation.certifyToscaElement(RES_ID, user.getUserId(), owner.getUserId(), REQUEST_UUID))
.thenReturn(Either.left(ModelConverter.convertToToscaElement(resourceAfterCertify)));
- changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
+ changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false, REQUEST_UUID);
assertTrue(changeStateResult.isLeft());
resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
- changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
+ changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false, REQUEST_UUID);
assertTrue(changeStateResult.isLeft());
}
user.setLastName("Santana");
user.setRole(Role.DESIGNER.name());
try {
- changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false);
+ changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, false, REQUEST_UUID);
} catch (ComponentException exp) {
assertResponse(Either.right(exp.getResponseFormat()), ActionStatus.ARCHIVED_ORIGINS_FOUND, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId());
return;
Either<Service, ResponseFormat> result = Either.left(service);
Either<ArtifactDefinition, Operation> resultArtifacts = Either.left(new ArtifactDefinition());
- when(toscaElementLifecycleOperation.certifyToscaElement(SERVICE_ID, user.getUserId(), owner.getUserId()))
+ when(toscaElementLifecycleOperation.certifyToscaElement(RES_ID, user.getUserId(), owner.getUserId(), REQUEST_UUID))
.thenReturn(Either.left(ModelConverter.convertToToscaElement(serviceAfterCertify)));
- when(serviceBusinessLogic.generateHeatEnvArtifacts(service, owner, false, true)).thenReturn(result);
- when(serviceBusinessLogic.generateVfModuleArtifacts(service, owner, false, true)).thenReturn(result);
+ lenient().when(serviceBusinessLogic.generateHeatEnvArtifacts(service, owner, false, true)).thenReturn(result);
+ lenient().when(serviceBusinessLogic.generateVfModuleArtifacts(service, owner, false, true)).thenReturn(result);
when(serviceBusinessLogic.populateToscaArtifacts(any(Service.class), eq(owner), eq(true), eq(true), eq(false))).thenReturn(resultArtifacts);
- changeStateResult = changeTransition.changeState(ComponentTypeEnum.SERVICE, service, serviceBusinessLogic, user, owner, false, true);
+ changeStateResult = changeTransition.changeState(ComponentTypeEnum.RESOURCE, resource, serviceBusinessLogic, user, owner, false, true, REQUEST_UUID);
assertTrue(changeStateResult.isLeft());
}
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
+import java.util.UUID;
+
class CheckoutTest extends LifecycleTestBase {
private CheckoutTransition checkoutObj = null;
private final DataTypeBusinessLogic dataTypeBusinessLogic = Mockito.mock(DataTypeBusinessLogic.class);
private final PolicyTypeBusinessLogic policyTypeBusinessLogic = Mockito.mock(PolicyTypeBusinessLogic.class);
private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
+ private static String REQUEST_UUID = UUID.randomUUID().toString();
ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic,
assertTrue(ownerResponse.isLeft());
User owner = ownerResponse.left().value();
when(toscaOperationFacade.updateToscaElement(any(Component.class))).thenReturn(Either.left(resource));
- changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false);
+ changeStateResult = checkoutObj.changeState((ComponentTypeEnum.RESOURCE), resource, bl,
+ user, owner, false, false, REQUEST_UUID);
assertTrue(changeStateResult.isLeft());
resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
- changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false);
+ changeStateResult = checkoutObj.changeState((ComponentTypeEnum.RESOURCE), resource, bl,
+ user, owner, false, false, REQUEST_UUID);
assertTrue(changeStateResult.isLeft());
}
import org.openecomp.sdc.exception.ResponseFormat;
import java.util.Map;
+import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
when(graphLockOperation.lockComponent(ID_BEFORE_CHECKIN, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
when(checkinTransition.getComponentOwner(service, ComponentTypeEnum.SERVICE)).thenReturn(Either.left(modifier));
when(checkinTransition.validateBeforeTransition(service, ComponentTypeEnum.SERVICE, modifier, modifier, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, remarks)).thenReturn(Either.left(true));
- Mockito.doReturn(Either.left(serviceAfterCheckIn)).when(checkinTransition).changeState(ComponentTypeEnum.SERVICE, service, serviceBusinessLogic, modifier, modifier, false, false);
-
+ Mockito.doReturn(Either.left(serviceAfterCheckIn)).when(checkinTransition).changeState(Mockito.any(ComponentTypeEnum.class), Mockito.any(Service.class), Mockito.any(), Mockito.any(User.class), Mockito.any(User.class), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.isNull());
when(certificationChangeTransition.getComponentOwner(serviceAfterCheckIn, ComponentTypeEnum.SERVICE)).thenReturn(Either.left(modifier));
when(certificationChangeTransition.validateBeforeTransition(serviceAfterCheckIn, ComponentTypeEnum.SERVICE, modifier, modifier, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, remarks)).thenReturn(Either.left(true));
- Mockito.doReturn(Either.left(serviceAfterCertify)).when(certificationChangeTransition).changeState(ComponentTypeEnum.SERVICE, serviceAfterCheckIn, serviceBusinessLogic, modifier, modifier, false, false);
+ Mockito.doReturn(Either.left(serviceAfterCertify)).when(certificationChangeTransition).changeState(Mockito.any(ComponentTypeEnum.class), Mockito.any(Service.class), Mockito.any(), Mockito.any(User.class), Mockito.any(User.class), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.isNull());
when(catalogOperations.updateCatalog(ChangeTypeEnum.LIFECYCLE, serviceAfterCertify)).thenReturn(ActionStatus.OK);
- Either<? extends Component, ResponseFormat> serviceAfterCertificationEither = lifecycleBusinessLogic.changeComponentState(ComponentTypeEnum.SERVICE, ID_BEFORE_CHECKIN, modifier, LifeCycleTransitionEnum.CERTIFY, remarks, false, true);
+ Either<? extends Component, ResponseFormat> serviceAfterCertificationEither = lifecycleBusinessLogic.changeComponentState(ComponentTypeEnum.SERVICE, ID_BEFORE_CHECKIN, modifier, LifeCycleTransitionEnum.CERTIFY, remarks,false, true, Mockito.nullable(String.class));
Component serviceAfterCertification = serviceAfterCertificationEither.left().value();
assertThat(serviceAfterCertification.getUniqueId()).isEqualTo(ID_AFTER_CERTIFY);
assertThat(serviceAfterCertification.getLifecycleState()).isEqualTo(LifecycleStateEnum.CERTIFIED);
void certifyCheckedInComponent() {
String ID_BEFORE_CERTIFY = "id";
String ID_AFTER_CERTIFY = "id2";
+ String REQUEST_UUID = UUID.randomUUID().toString();
Service service = createServiceObject();
fillService(service, ID_BEFORE_CERTIFY);
service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
when(graphLockOperation.lockComponent(ID_BEFORE_CERTIFY, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
when(certificationChangeTransition.getComponentOwner(service, ComponentTypeEnum.SERVICE)).thenReturn(Either.left(modifier));
when(certificationChangeTransition.validateBeforeTransition(service, ComponentTypeEnum.SERVICE, modifier, modifier, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN, remarks)).thenReturn(Either.left(true));
- Mockito.doReturn(Either.left(serviceAfterCertify)).when(certificationChangeTransition).changeState(ComponentTypeEnum.SERVICE, service, serviceBusinessLogic, modifier, modifier, false, false);
+ Mockito.doReturn(Either.left(serviceAfterCertify)).when(certificationChangeTransition).changeState(ComponentTypeEnum.SERVICE, service, serviceBusinessLogic, modifier, modifier, false, false, REQUEST_UUID);
when(catalogOperations.updateCatalog(ChangeTypeEnum.LIFECYCLE, serviceAfterCertify)).thenReturn(ActionStatus.OK);
- Either<? extends Component, ResponseFormat> serviceAfterCertificationEither = lifecycleBusinessLogic.changeComponentState(ComponentTypeEnum.SERVICE, ID_BEFORE_CERTIFY, modifier, LifeCycleTransitionEnum.CERTIFY, remarks, false, true);
+ Either<? extends Component, ResponseFormat> serviceAfterCertificationEither = lifecycleBusinessLogic.changeComponentState(ComponentTypeEnum.SERVICE, ID_BEFORE_CERTIFY, modifier, LifeCycleTransitionEnum.CERTIFY, remarks, false, true, REQUEST_UUID);
Component serviceAfterCertification = serviceAfterCertificationEither.left().value();
assertThat(serviceAfterCertification.getUniqueId()).isEqualTo(ID_AFTER_CERTIFY);
assertThat(serviceAfterCertification.getLifecycleState()).isEqualTo(LifecycleStateEnum.CERTIFIED);
// createResource
resourceResponse = createResourceObject();
Either<ToscaElement, StorageOperationStatus> eitherComponent = Either.left(ModelConverter.convertToToscaElement(resourceResponse));
- when(toscaElementLifecycleOperation.checkoutToscaElement(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)))
+ when(toscaElementLifecycleOperation.checkoutToscaElement(Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)))
.thenAnswer(createAnswer(eitherComponent));
- when(toscaElementLifecycleOperation.checkinToscaELement(Mockito.any(LifecycleStateEnum.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)))
+ when(toscaElementLifecycleOperation.checkinToscaELement(Mockito.any(LifecycleStateEnum.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class)))
.thenAnswer(createAnswer(eitherComponent));
Either<User, StorageOperationStatus> getOwnerResult = Either.left(user);
} else {
ArtifactDataDefinition artifactData = status.left().value();
ArtifactDefinition artifactDefResult = convertArtifactDataToArtifactDefinition(artifactInfo, artifactData);
+ if (artifactInfo.getArtifactUUID() != null && !artifactInfo.getArtifactUUID().isEmpty()) {
+ artifactDefResult.setArtifactUUID(artifactInfo.getArtifactUUID());
+ }
log.debug("The returned ArtifactDefintion is {}", artifactDefResult);
return Either.left(artifactDefResult);
}
break;
}
} else {
- generateUUIDForNonHeatArtifactType(updateArtifactData, oldChecksum, oldVesrion, currentChecksum);
+ if (updateArtifactData.getArtifactUUID() == null ||
+ updateArtifactData.getArtifactUUID().isEmpty()) {
+
+ generateUUIDForNonHeatArtifactType(updateArtifactData, oldChecksum, oldVesrion, currentChecksum);
+
+ }
}
}
private void generateUUIDForNonHeatArtifactType(ArtifactDataDefinition artifactData, String oldChecksum, String oldVesrion,
String currentChecksum) {
+ if (artifactData.getArtifactUUID() != null &&
+ !artifactData.getArtifactUUID().isEmpty()) {
+ return;
+ }
if (oldChecksum == null || oldChecksum.isEmpty()) {
if (currentChecksum != null) {
generateUUID(artifactData, oldVesrion);
ArtifactDefinition propertyDefResult = new ArtifactDefinition(artifactDefResult);
if (artifactInfo != null) {
propertyDefResult.setPayload(artifactInfo.getPayloadData());
+ if (artifactInfo.getArtifactUUID() != null && !artifactInfo.getArtifactUUID().isEmpty()) {
+ propertyDefResult.setArtifactUUID(artifactInfo.getArtifactUUID());
+ } else {
+ propertyDefResult.setArtifactUUID(artifactDefResult.getArtifactUUID());
+ }
}
List<HeatParameterDefinition> parameters = new ArrayList<>();
/*
String componentId = component.getUniqueId();
Either<ArtifactDataDefinition, StorageOperationStatus> res = null;
ArtifactDefinition artifactToUpdate = new ArtifactDefinition(artifactInfo);
+ if (artifactInfo.getArtifactUUID() != null) {
+ artifactToUpdate.setArtifactUUID(artifactInfo.getArtifactUUID());
+ }
ArtifactGroupTypeEnum groupType = artifactInfo.getArtifactGroupType();
Triple<EdgeLabelEnum, Boolean, VertexTypeEnum> triple = getEdgeLabelEnumFromArtifactGroupType(groupType, type);
EdgeLabelEnum edgeLabelEnum = triple.getLeft();
* @return
*/
public Either<ToscaElement, StorageOperationStatus> checkinToscaELement(LifecycleStateEnum currState, String toscaElementId, String modifierId,
- String ownerId) {
+ String ownerId, String requestUUID) {
try {
return janusGraphDao.getVerticesByUniqueIdAndParseFlag(prepareParametersToGetVerticesForCheckin(toscaElementId, modifierId, ownerId))
.right().map(status -> handleFailureToPrepareParameters(status, toscaElementId)).left().bind(
//We retrieve the operation
ToscaElementOperation operation = getToscaElementOperation(verticesMap.get(toscaElementId).getLabel());
//We retrieve the ToscaElement from the operation
- return getToscaElementFromOperation(operation, checkinResult.getUniqueId(), toscaElementId);
+ Either<ToscaElement, StorageOperationStatus> elementEither =
+ getToscaElementFromOperation(operation, checkinResult.getUniqueId(), toscaElementId);
+
+ if (elementEither.isLeft()) {
+ ToscaElement element = elementEither.left().value();
+ if (requestUUID != null && !requestUUID.trim().isEmpty()) {
+ element.setUUID(requestUUID);
+ }
+ }
+
+ return elementEither;
}));
} catch (Exception e) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Exception occurred during checkin of tosca element {}. {} ", toscaElementId,
* @param ownerId
* @return
*/
- public Either<ToscaElement, StorageOperationStatus> checkoutToscaElement(String toscaElementId, String modifierId, String ownerId) {
+ public Either<ToscaElement, StorageOperationStatus> checkoutToscaElement(String toscaElementId, String modifierId, String ownerId, String requestUUID) {
Either<ToscaElement, StorageOperationStatus> result = null;
Map<String, GraphVertex> vertices = null;
try {
}
if (result == null) {
result = cloneToscaElementForCheckout(vertices.get(toscaElementId), vertices.get(modifierId));
+ if (result.isLeft()) {
+ ToscaElement element = result.left().value();
+ // Override UUID with requestUUID
+ if (requestUUID != null && !requestUUID.trim().isEmpty()) {
+ element.setUUID(requestUUID);
+ }
+ }
if (result.isRight()) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to checkout tosca element {}. Status is {} ", toscaElementId,
result.right().value());
* @param toscaElementId
* @return
*/
- public Either<ToscaElement, StorageOperationStatus> undoCheckout(String toscaElementId, String model) {
+ public Either<ToscaElement, StorageOperationStatus> undoCheckout(String toscaElementId, String model, String requestUUID) {
try {
return janusGraphDao.getVertexById(toscaElementId, JsonParseFlagEnum.ParseMetadata).right().map(errorStatus -> {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_GET_VERTICES, toscaElementId);
return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(errorStatus);
}).left().bind(this::retrieveAndUpdatePreviousVersion).left()
- .bind(tuple -> updateEdgeToCatalogRootAndReturnPreVersionElement(tuple, model));
+ .bind(tuple -> {
+ Either<ToscaElement, StorageOperationStatus> elementResult = updateEdgeToCatalogRootAndReturnPreVersionElement(tuple, model);
+
+ // Apply requestUUID if provided
+ if (elementResult.isLeft() && requestUUID != null && !requestUUID.trim().isEmpty()) {
+ ToscaElement element = elementResult.left().value();
+ element.setUUID(requestUUID);
+ }
+
+ return elementResult;
+ });
} catch (Exception e) {
CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Exception occurred during undo checkout tosca element {}. {}", toscaElementId,
e.getMessage());
return hasPreviousVersion;
}
- public Either<ToscaElement, StorageOperationStatus> certifyToscaElement(String toscaElementId, String modifierId, String ownerId) {
+ public Either<ToscaElement, StorageOperationStatus> certifyToscaElement(String toscaElementId, String modifierId, String ownerId, String requestUUID) {
try {
return janusGraphDao
.getVerticesByUniqueIdAndParseFlag(prepareParametersToGetVerticesForRequestCertification(toscaElementId, modifierId, ownerId)).right()
GraphVertex toscaElement = verticesRes.get(toscaElementId);
GraphVertex modifier = verticesRes.get(modifierId);
Integer majorVersion = getMajorVersion((String) toscaElement.getMetadataProperty(GraphPropertyEnum.VERSION));
- return handleRelationsBeforeCertifyingAndProcessClone(toscaElement, modifier, majorVersion);
+ Either<ToscaElement, StorageOperationStatus> handleResult = handleRelationsBeforeCertifyingAndProcessClone(
+ toscaElement, modifier, majorVersion
+ );
+
+ if (handleResult.isLeft()) {
+ ToscaElement element = handleResult.left().value();
+ if (requestUUID != null && !requestUUID.trim().isEmpty()) {
+ element.setUUID(requestUUID);
+ }
+ return Either.left(element);
+ } else {
+ return Either.right(handleResult.right().value());
+ }
});
- } catch (Exception e) {
- return Either.right(logDebugMessageAndReturnStorageOperationStatus(StorageOperationStatus.GENERAL_ERROR,
- "Exception occurred during certification tosca element {}.", toscaElementId, e));
- }
- }
+ } catch (Exception e) {
+ return Either.right(logDebugMessageAndReturnStorageOperationStatus(StorageOperationStatus.GENERAL_ERROR,
+ "Exception occurred during certification tosca element {}.", toscaElementId, e));
+ }
+ }
private Either<ToscaElement, StorageOperationStatus> handleRelationsBeforeCertifyingAndProcessClone(GraphVertex toscaElement,
GraphVertex modifier, Integer majorVersion) {
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
+
import org.apache.tinkerpop.gremlin.structure.io.IoCore;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphVertex;
String categoryName = "category";
String subcategory = "mycategory";
String outputDirectory = "C:\\Output";
+ String REQUEST_UUID = UUID.randomUUID().toString();
+
@javax.annotation.Resource
private NodeTypeOperation nodeTypeOperation;
@javax.annotation.Resource
@Test
public void lifecycleTest() {
+ String REQUEST_UUID = UUID.randomUUID().toString();
Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(
LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(),
modifierVertex.getUniqueId(),
- ownerVertex.getUniqueId());
+ ownerVertex.getUniqueId(),
+ REQUEST_UUID);
StorageOperationStatus status;
assertTrue(res.isLeft());
String id = res.left().value().getUniqueId();
- res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
+ res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
assertSame(status, StorageOperationStatus.OK);
res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(),
- ownerVertex.getUniqueId());
+ ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
- res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
+ res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
JsonPresentationFields.NAME);
assertSame(status, StorageOperationStatus.OK);
- res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+ res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
verifyInCatalogData(3, null);
- res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
+ res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
assertSame(status, StorageOperationStatus.OK);
res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(),
- ownerVertex.getUniqueId());
+ ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
- res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
+ res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
JsonPresentationFields.NAME);
assertSame(status, StorageOperationStatus.OK);
- res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+ res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
verifyInCatalogData(3, null);
- res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
+ res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
id = res.left().value().getUniqueId();
public void serviceConformanceLevelTest() {
Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(
LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(),
- modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+ modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
String id = res.left().value().getUniqueId();
- res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
+ res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId(), REQUEST_UUID);
assertTrue(res.isLeft());
String conformanceLevel = res.left().value().getMetadataValue(JsonPresentationFields.CONFORMANCE_LEVEL).toString();
expectedIds.add(vertex4.getUniqueId());
verifyInCatalogData(4, expectedIds);
- lifecycleOperation.undoCheckout(vertex4.getUniqueId(), null);
+ lifecycleOperation.undoCheckout(vertex4.getUniqueId(), null, REQUEST_UUID);
expectedIds.remove(vertex4.getUniqueId());
verifyInCatalogData(3, expectedIds);
verifyInCatalogData(4, expectedIds);
lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)),
- vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+ vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId(),REQUEST_UUID);
Either<ToscaElement, StorageOperationStatus> certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(),
- modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
+ modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(certifyToscaElement.isLeft());
expectedIds.remove(vertex4.getUniqueId());
String certifiedId = certifyToscaElement.left().value().getUniqueId();
verifyInCatalogData(4, expectedIds);
Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(),
- ownerVertex.getUniqueId());
+ ownerVertex.getUniqueId(), REQUEST_UUID);
assertTrue(certifyToscaElement.isLeft());
expectedIds.add(res.left().value().getUniqueId());
verifyInCatalogData(5, expectedIds);