1. Support workflow artifact in distribution notification.
2. Only save unique artifacts by name per component in SDC irrespective of it being used in multiple operations under same component.
3. Any other call to save same artifact as part of same component will not upload a new artifact and will update the new operation to refer to existing artifact.
4. The generated CSAR and distribution notification will only have unique artifacts.
5. Delete or Update operation will only delete artifact if it is not being used in any other operation under same component.
Change-Id: I74d4ee4f8e543ea9e730301a210deb08b00c64bc
Issue-ID: SDC-2233
Signed-off-by: priyanshu <pagarwal@amdocs.com>
if (MapUtils.isNotEmpty(interfaces)) {
interfaceArtifacts = interfaces.values().stream()
.flatMap(inte -> inte.getOperationsMap().values().stream())
- .map(operation -> operation.getImplementationArtifact())
+ .map(operation -> operation.getImplementationArtifact()).filter(Objects::nonNull)
.collect(Collectors.toMap(artifactDefinition -> artifactDefinition.getUniqueId(),
- artifactDefinition -> artifactDefinition));
+ artifactDefinition -> artifactDefinition, (a1, a2) -> a1));
}
Map<String, ArtifactDefinition> serviceApiArtifacts = Collections.emptyMap();
import org.openecomp.sdc.be.info.ArtifactTemplateInfo;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.heat.HeatParameterType;
-import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation;
import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils;
import org.openecomp.sdc.be.model.operations.api.*;
}
}
NodeTypeEnum convertParentType = convertParentType(componentType);
- // fetch the resource from storage
- Either<Component, StorageOperationStatus> componentStorageOperationStatusEither =
- toscaOperationFacade.getToscaElement(parentId);
- if (componentStorageOperationStatusEither.isRight()) {
- StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value();
- log.debug("Failed to fetch resource information by resource id, error {}", errorStatus);
- return Either.right(componentsUtils
- .getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
+ // Set additional fields for artifact
+ artifactInfo.setArtifactLabel(artifactInfo.getArtifactName());
+ artifactInfo.setArtifactDisplayName(artifactInfo.getArtifactName());
+
+ Either<ArtifactDefinition, StorageOperationStatus> updateArtifactOnResourceEither =
+ artifactToscaOperation.updateArtifactOnResource(artifactInfo, parent.getUniqueId(), artifactId, convertParentType, parentId);
+ if(updateArtifactOnResourceEither.isRight()){
+ log.debug("Failed to persist operation artifact {} in resource, error is {}",artifactInfo.getArtifactName(), updateArtifactOnResourceEither.right().value());
+ ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(updateArtifactOnResourceEither.right().value());
+ return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse));
}
- Component storedComponent = componentStorageOperationStatusEither.left().value();
-
- Optional<InterfaceDefinition> optionalInterface = InterfaceOperationUtils
- .getInterfaceDefinitionFromComponentByInterfaceType(storedComponent, interfaceType);
- if(!optionalInterface.isPresent()) {
- log.debug("Failed to get resource interface for resource Id {}", parentId);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceType));
+ if (artifactData.getData() != null) {
+ CassandraOperationStatus cassandraOperationStatus = artifactCassandraDao.saveArtifact(artifactData);
+ if(cassandraOperationStatus != CassandraOperationStatus.OK){
+ log.debug("Failed to persist operation artifact {}, error is {}",artifactInfo.getArtifactName(),cassandraOperationStatus);
+ StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraOperationStatus);
+ ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
+ return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse));
+ }
}
- //fetch the operation from storage
- InterfaceDefinition gotInterface = optionalInterface.get();
- Map<String, Operation> operationsMap = gotInterface.getOperationsMap();
- Optional<Operation> optionalOperation = operationsMap.values()
- .stream()
- .filter(o -> o.getUniqueId().equals(operationUuid))
- .findFirst();
- if (!optionalOperation.isPresent()) {
- log.debug("Failed to get resource interface operation for resource Id {} " +
- " and operationId {}", parentId, operationUuid);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(
- ActionStatus.INTERFACE_OPERATION_NOT_FOUND, parentId);
- handleAuditing(auditingAction, parent, parentId, user, artifactInfo, prevArtifactId,
- currArtifactId, responseFormat, componentType, null);
- return Either.right(responseFormat);
+ Either<ArtifactDefinition, ResponseFormat> updateOprEither = updateOperationArtifact(parentId, interfaceType, operationUuid, updateArtifactOnResourceEither.left().value());
+ if(updateOprEither.isRight()){
+ return Either.right(updateOprEither.right().value());
}
- Operation operation = optionalOperation.get();
- ArtifactDefinition implementationArtifact = operation.getImplementationArtifact();
- implementationArtifact.setArtifactName(artifactInfo.getArtifactName());
- implementationArtifact.setDescription(artifactInfo.getDescription());
- implementationArtifact.setArtifactType(artifactInfo.getArtifactType());
- implementationArtifact.setArtifactLabel(artifactInfo.getUniqueId());
- implementationArtifact.setEsId(artifactInfo.getEsId());
- operation.setImplementation(implementationArtifact);
- gotInterface.setOperationsMap(operationsMap);
- Either<List<InterfaceDefinition>, StorageOperationStatus> interfaceDefinitionStorageOperationStatusEither =
- interfaceOperation.updateInterfaces(storedComponent.getUniqueId(), Collections.singletonList(gotInterface));
- if (interfaceDefinitionStorageOperationStatusEither.isRight()){
- StorageOperationStatus storageOperationStatus = interfaceDefinitionStorageOperationStatusEither.right().value();
- ActionStatus actionStatus =
- componentsUtils.convertFromStorageResponseForDataType(storageOperationStatus);
- return Either.right(componentsUtils.getResponseFormat(actionStatus));
- }
-
- String uniqueId = implementationArtifact.getUniqueId();
- artifactData.setId(uniqueId);
- CassandraOperationStatus cassandraOperationStatus = artifactCassandraDao.saveArtifact(artifactData);
- if(cassandraOperationStatus != CassandraOperationStatus.OK){
- log.debug("Failed to persist operation {} artifact, error is {}",operation.getName(),cassandraOperationStatus);
- StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraOperationStatus);
- ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
- return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse));
- }
- return Either.left(Either.left(implementationArtifact));
+ return Either.left(Either.left(updateOprEither.left().value()));
}
private Either<byte[], ResponseFormat> handlePayload(ArtifactDefinition artifactInfo, boolean isArtifactMetadataUpdate) {
return updateArtifactResult;
}
+ private Either<ArtifactDefinition, ResponseFormat> updateOperationArtifact(String componentId, String interfaceType, String operationUuid, ArtifactDefinition artifactInfo){
+ Either<Component, StorageOperationStatus> componentStorageOperationStatusEither = toscaOperationFacade.getToscaElement(componentId);
+ if (componentStorageOperationStatusEither.isRight()) {
+ StorageOperationStatus errorStatus = componentStorageOperationStatusEither.right().value();
+ log.debug("Failed to fetch resource information by resource id, error {}", errorStatus);
+ return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(errorStatus)));
+ }
+ Component storedComponent = componentStorageOperationStatusEither.left().value();
+
+ Optional<InterfaceDefinition> optionalInterface = InterfaceOperationUtils.getInterfaceDefinitionFromComponentByInterfaceType(storedComponent, interfaceType);
+ if(!optionalInterface.isPresent()) {
+ log.debug("Failed to get resource interface for resource Id {}", componentId);
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_NOT_FOUND_IN_COMPONENT, interfaceType));
+ }
+
+ //fetch the operation from storage
+ InterfaceDefinition gotInterface = optionalInterface.get();
+ Map<String, Operation> operationsMap = gotInterface.getOperationsMap();
+ Optional<Operation> optionalOperation = operationsMap.values()
+ .stream()
+ .filter(o -> o.getUniqueId().equals(operationUuid))
+ .findFirst();
+ if (!optionalOperation.isPresent()) {
+ log.debug("Failed to get resource interface operation for resource Id {} and operationId {}", componentId, operationUuid);
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId);
+ return Either.right(responseFormat);
+ }
+
+ Operation operation = optionalOperation.get();
+ ArtifactDefinition implementationArtifact = operation.getImplementationArtifact();
+ implementationArtifact.setArtifactUUID(artifactInfo.getArtifactUUID());
+ implementationArtifact.setUniqueId(artifactInfo.getUniqueId());
+ implementationArtifact.setArtifactName(artifactInfo.getArtifactName());
+ implementationArtifact.setDescription(artifactInfo.getDescription());
+ implementationArtifact.setArtifactType(artifactInfo.getArtifactType());
+ implementationArtifact.setArtifactLabel(artifactInfo.getArtifactLabel());
+ implementationArtifact.setArtifactDisplayName(artifactInfo.getArtifactDisplayName());
+ implementationArtifact.setEsId(artifactInfo.getEsId());
+ operation.setImplementation(implementationArtifact);
+ gotInterface.setOperationsMap(operationsMap);
+ Either<List<InterfaceDefinition>, StorageOperationStatus> interfaceDefinitionStorageOperationStatusEither =
+ interfaceOperation.updateInterfaces(storedComponent.getUniqueId(), Collections.singletonList(gotInterface));
+ if (interfaceDefinitionStorageOperationStatusEither.isRight()){
+ StorageOperationStatus storageOperationStatus = interfaceDefinitionStorageOperationStatusEither.right().value();
+ ActionStatus actionStatus =
+ componentsUtils.convertFromStorageResponseForDataType(storageOperationStatus);
+ return Either.right(componentsUtils.getResponseFormat(actionStatus));
+ }
+
+ return Either.left(artifactInfo);
+ }
+
/**
* updates an artifact on a component by UUID
*
ArtifactDefinition artifactInfo = RepresentationUtils.convertJsonToArtifactDefinitionForUpdate(data, ArtifactDefinition.class);
String origMd5 = request.getHeader(Constants.MD5_HEADER);
String userId = request.getHeader(Constants.USER_ID_HEADER);
+ ArtifactDefinition existingArtifactInfo = null;
+ String interfaceName = null;
Either<ComponentMetadataData, StorageOperationStatus> getComponentRes = toscaOperationFacade.getLatestComponentMetadataByUuid(componentUuid, JsonParseFlagEnum.ParseMetadata, true);
if (getComponentRes.isRight()) {
log.debug("Could not fetch component with type {} and uuid {}. Status is {}. ", componentType, componentUuid, status);
errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
}
+
if (errorWrapper.isEmpty()) {
componentId = getComponentRes.left().value().getMetadataDataDefinition().getUniqueId();
String componentName = getComponentRes.left().value().getMetadataDataDefinition().getName();
}
resourceCommonInfo.setResourceName(componentName);
}
- if (errorWrapper.isEmpty()) {
- Either<String, ResponseFormat> interfaceName = fetchInterfaceName(componentId, interfaceUUID);
- if (interfaceName.isRight()) {
- errorWrapper.setInnerElement(interfaceName.right().value());
+
+ if(errorWrapper.isEmpty()){
+ Either<String, ResponseFormat> interfaceNameEither = fetchInterfaceName(componentId, interfaceUUID);
+ if (interfaceNameEither.isRight()) {
+ errorWrapper.setInnerElement(interfaceNameEither.right().value());
}
- if (errorWrapper.isEmpty()) {
- actionResult = handleArtifactRequest(componentId, userId, componentType, operation,
- artifactUUID, artifactInfo, origMd5, data, interfaceName.left().value(),
- operationUUID, null, null);
- if (actionResult.isRight()) {
- log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, componentUuid, actionResult
- .right()
- .value());
- errorWrapper.setInnerElement(actionResult.right().value());
+ else {
+ interfaceName = interfaceNameEither.left().value();
+ }
+
+ if(errorWrapper.isEmpty()){
+ Either<Component, StorageOperationStatus> toscaComponentEither = toscaOperationFacade.getToscaElement(componentId);
+ if (toscaComponentEither.isRight()) {
+ StorageOperationStatus status = toscaComponentEither.right().value();
+ log.debug("Could not fetch component with type {} and id {}. Status is {}. ", componentType, componentId, status);
+ errorWrapper.setInnerElement(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status)));
}
+
+ if (errorWrapper.isEmpty()) {
+ NodeTypeEnum parentType = convertParentType(componentType);
+ List<ArtifactDefinition> existingDeploymentArtifacts = getDeploymentArtifacts(toscaComponentEither.left().value(), parentType,null);
+ for (ArtifactDefinition artifactDefinition: existingDeploymentArtifacts){
+ if(artifactDefinition.getArtifactName().equalsIgnoreCase(artifactInfo.getArtifactName())){
+ existingArtifactInfo = artifactDefinition;
+ break;
+ }
+ }
+ if(existingArtifactInfo != null){
+ return updateOperationArtifact(componentId, interfaceName, operationUUID, existingArtifactInfo);
+ }
+ }
+ }
+ }
+
+ if (errorWrapper.isEmpty()) {
+ actionResult = handleArtifactRequest(componentId, userId, componentType, operation,
+ artifactUUID, artifactInfo, origMd5, data, interfaceName,
+ operationUUID, null, null);
+ if (actionResult.isRight()) {
+ log.debug(FAILED_UPLOAD_ARTIFACT_TO_COMPONENT, componentType, componentUuid, actionResult
+ .right()
+ .value());
+ errorWrapper.setInnerElement(actionResult.right().value());
}
}
+
if (errorWrapper.isEmpty()) {
updateArtifact = actionResult.left().value().left().value();
updateArtifactResult = Either.left(updateArtifact);
import fj.data.Either;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
+import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils;
import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
if (validateDeleteOperationContainsNoMappedOutputResponse.isRight()) {
return Either.right(validateDeleteOperationContainsNoMappedOutputResponse.right().value());
}
- String artifactUuId = storedOperation.getImplementation().getArtifactUUID();
- CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUuId);
- if (cassandraStatus != CassandraOperationStatus.OK) {
- ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
- componentsUtils.convertFromStorageResponse(
- componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
- storedOperation.getImplementation().getArtifactDisplayName());
- return Either.right(responseFormatByArtifactId);
+
+ String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
+ if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, operationId, artifactUniqueId)){
+ Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
+ artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
+ if(getArtifactEither.isLeft()){
+ Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
+ artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
+ NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
+ true);
+ if(removeArifactFromComponent.isRight()){
+ titanDao.rollback();
+ ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
+ componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
+ storedOperation.getImplementation().getArtifactDisplayName());
+ return Either.right(responseFormatByArtifactId);
+ }
+
+ CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
+ if (cassandraStatus != CassandraOperationStatus.OK) {
+ titanDao.rollback();
+ ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
+ componentsUtils.convertFromStorageResponse(
+ componentsUtils.convertToStorageOperationStatus(cassandraStatus)),
+ storedOperation.getImplementation().getArtifactDisplayName());
+ return Either.right(responseFormatByArtifactId);
+ }
+ }
}
operationsCollection.put(operationId, interfaceDefinition.getOperationsMap().get(operationId));
Operation storedOperation = optionalOperation.get().getValue();
String artifactUuId = storedOperation.getImplementation().getArtifactUUID();
- Either<Long, CassandraOperationStatus> artifactCount =
- artifactCassandraDao.getCountOfArtifactById(artifactUuId);
- if (artifactCount.isLeft()) {
- CassandraOperationStatus cassandraStatus =
- artifactCassandraDao.deleteArtifact(artifactUuId);
- if (cassandraStatus != CassandraOperationStatus.OK) {
- titanDao.rollback();
- ResponseFormat responseFormatByArtifactId =
- componentsUtils.getResponseFormatByArtifactId(
- componentsUtils.convertFromStorageResponse(
- componentsUtils.convertToStorageOperationStatus(
- cassandraStatus)),
- storedOperation.getImplementation().getArtifactDisplayName());
- return Either.right(responseFormatByArtifactId);
+ String artifactUniqueId = storedOperation.getImplementation().getUniqueId();
+
+ if(!InterfaceOperationUtils.isArtifactInUse(storedComponent, storedOperation.getUniqueId(), artifactUniqueId)){
+ Either<ArtifactDefinition, StorageOperationStatus> getArtifactEither =
+ artifactToscaOperation.getArtifactById(storedComponent.getUniqueId(), artifactUniqueId);
+ if(getArtifactEither.isLeft()){
+ Either<ArtifactDefinition, StorageOperationStatus> removeArifactFromComponent =
+ artifactToscaOperation.removeArifactFromResource(componentId, artifactUniqueId,
+ NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()),
+ true);
+ if(removeArifactFromComponent.isRight()){
+ titanDao.rollback();
+ ResponseFormat responseFormatByArtifactId = componentsUtils.getResponseFormatByArtifactId(
+ componentsUtils.convertFromStorageResponse(removeArifactFromComponent.right().value()),
+ storedOperation.getImplementation().getArtifactDisplayName());
+ return Either.right(responseFormatByArtifactId);
+ }
+
+ CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUniqueId);
+ if (cassandraStatus != CassandraOperationStatus.OK) {
+ titanDao.rollback();
+ ResponseFormat responseFormatByArtifactId =
+ componentsUtils.getResponseFormatByArtifactId(
+ componentsUtils.convertFromStorageResponse(
+ componentsUtils.convertToStorageOperationStatus(
+ cassandraStatus)),
+ storedOperation.getImplementation().getArtifactDisplayName());
+ return Either.right(responseFormatByArtifactId);
+ }
}
}
updateOperationOnInterface(interfaceDef, operation, artifactUuId);
@Override
public void setDeploymentArtifactsPlaceHolder(Component component, User user) {
-
+ Service service = (Service) component;
+ Map<String, ArtifactDefinition> artifactMap = service.getDeploymentArtifacts();
+ if (artifactMap == null) {
+ artifactMap = new HashMap<>();
+ }
+ service.setDeploymentArtifacts(artifactMap);
}
@Override
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
-
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.MapUtils;
+import org.apache.commons.collections4.MapUtils;
import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
? fullOutputIdentifier.substring(fullOutputIdentifier.lastIndexOf('.') + 1)
: fullOutputIdentifier;
}
+
+ public static boolean isArtifactInUse(Component component, String operationId, String artifactUniqueId) {
+ return MapUtils.emptyIfNull(component.getInterfaces()).values().stream()
+ .filter(o -> MapUtils.isNotEmpty(o.getOperations()) && !o.getOperations().containsKey(operationId))
+ .flatMap(o -> o.getOperations().values().stream()).collect(Collectors.toList()).stream()
+ .anyMatch(op -> op.getImplementation().getUniqueId().equals(artifactUniqueId));
+ }
}
for (ArtifactTypeEnum artifactTypeEnum : artifactTypeEnumKeySet) {
List<ArtifactDefinition> artifactDefinitionList = artifactTypesMap.get(artifactTypeEnum);
String artifactTypeFolder = groupTypeFolder + artifactTypeEnum.toString() + File.separator;
+
+ if(artifactTypeEnum == ArtifactTypeEnum.WORKFLOW && path.contains(ARTIFACTS_PATH + RESOURCES_PATH)){
+ // Ignore this packaging as BPMN artifacts needs to be packaged in different manner
+ continue;
+ }
if (artifactTypeEnum == ArtifactTypeEnum.WORKFLOW) {
artifactTypeFolder += OperationArtifactUtil.BPMN_ARTIFACT_PATH + File.separator;
}
.flatMap(interfaceDefinition -> interfaceDefinition.getOperationsMap().values().stream())
.map(Operation::getImplementationArtifact).filter(Objects::nonNull)
.collect(Collectors.toMap(ArtifactDataDefinition::getUniqueId,
- artifactDefinition -> artifactDefinition));
+ artifactDefinition -> artifactDefinition, (a1, a2) -> a1));
if (MapUtils.isNotEmpty(interfaceArtifacts)) {
Set<String> artifactNameSet = new HashSet<>();
for (Map.Entry<String, ArtifactDefinition> interfaceArtifactEntry : interfaceArtifacts.entrySet()) {
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
+import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations;
import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
private InterfaceOperation interfaceOperation;
@Mock
private ArtifactCassandraDao artifactCassandraDao;
+ @Mock
+ protected ArtifactsOperations artifactToscaOperation;
private User user;
private Resource resource;
when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
.thenReturn(StorageOperationStatus.OK);
when(interfaceOperationValidation
- .validateInterfaceOperations(anyObject(), anyObject(), any(), anyMap(), anyBoolean()))
+ .validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean()))
.thenReturn(Either.left(true));
when(interfaceOperationValidation
- .validateDeleteOperationContainsNoMappedOutput(anyObject(), anyObject(), any()))
+ .validateDeleteOperationContainsNoMappedOutput(any(), any(), any()))
.thenReturn(Either.left(true));
when(titanDao.commit()).thenReturn(TitanOperationStatus.OK);
}
public void updateInterfaceOperationTestWithArtifactSuccess() {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
- when(artifactCassandraDao.getCountOfArtifactById(any(String.class))).thenReturn(Either.left(new Long(1)));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
public void updateInterfaceOperationTestWithArtifactFailure() {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
- when(artifactCassandraDao.getCountOfArtifactById(any(String.class))).thenReturn(Either.left(new Long(1)));
- when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR);
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
public void updateInterfaceOperationTestWithoutArtifact() {
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
- when(artifactCassandraDao.getCountOfArtifactById(any(String.class)))
- .thenReturn(Either.right(CassandraOperationStatus.NOT_FOUND));
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
.thenReturn(Either.left(Collections.emptyMap()));
when(interfaceOperationValidation
- .validateInterfaceOperations(anyObject(), anyObject(), any(), anyMap(), anyBoolean()))
+ .validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean()))
.thenReturn(Either.right(new ResponseFormat()));
Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
public void deleteInterfaceOperationTestSuccess() {
resource.getInterfaces().get(interfaceId).getOperations()
.putAll(InterfaceOperationTestUtils.createMockOperationMap(operationId1, operationName));
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
@Test
public void shouldFailWhenDeleteInterfaceOperationFailedTest() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any()))
.thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
@Test
public void deleteInterfaceOperationTestFailOnArtifactDeletion() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR);
Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
Collections.singletonList(operationId), user, true).isRight());
@Test
public void deleteInterfaceOperationTestFailOnException() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenThrow(new RuntimeException());
Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
Collections.singletonList(operationId), user, true).isRight());
@Test
public void deleteInterfaceTestSuccess() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
when(interfaceOperation.deleteInterface(any(), any())).thenReturn(Either.left(interfaceId));
@Test
public void deleteInterfaceTestFailure() {
+ when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
+ when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
+ .thenReturn(Either.left(new ArtifactDefinition()));
when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
when(interfaceOperation.deleteInterface(any(), any()))
.isPresent());
}
+ @Test
+ public void testIsArtifactInUse() {
+ Assert.assertTrue(InterfaceOperationUtils.isArtifactInUse(resource, operationId1, "uniqId"));
+ Assert.assertFalse(InterfaceOperationUtils.isArtifactInUse(resource, operationId1, "uniqId1"));
+ }
+
}
\ No newline at end of file