import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
-import static java.util.stream.Collectors.toSet;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
import static org.apache.commons.collections.MapUtils.isEmpty;
import static org.apache.commons.collections.MapUtils.isNotEmpty;
import static org.openecomp.sdc.be.tosca.CsarUtils.VF_NODE_TYPE_ARTIFACTS_PATH_PATTERN;
import static org.openecomp.sdc.common.api.Constants.DEFAULT_GROUP_VF_MODULE;
+import com.google.common.annotations.VisibleForTesting;
+import fj.data.Either;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.components.csar.CsarArtifactsAndGroupsBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
+import org.openecomp.sdc.be.components.csar.OnboardedCsarInfo;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
import org.openecomp.sdc.be.components.merge.TopologyComparator;
import org.openecomp.sdc.be.components.merge.property.PropertyDataValueMergeBusinessLogic;
import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic;
-import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
import org.openecomp.sdc.be.components.property.PropertyConstraintsUtils;
import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator;
import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
-import com.google.common.annotations.VisibleForTesting;
-
-import fj.data.Either;
-
@org.springframework.stereotype.Component("resourceBusinessLogic")
public class ResourceBusinessLogic extends ComponentBusinessLogic {
private final CompositionBusinessLogic compositionBusinessLogic;
private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic;
private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic;
- private final MergeInstanceUtils mergeInstanceUtils;
private final UiComponentDataConverter uiComponentDataConverter;
private final CsarBusinessLogic csarBusinessLogic;
private final PropertyBusinessLogic propertyBusinessLogic;
private final PolicyBusinessLogic policyBusinessLogic;
private final ModelBusinessLogic modelBusinessLogic;
- private IInterfaceLifecycleOperation interfaceTypeOperation;
- private LifecycleBusinessLogic lifecycleBusinessLogic;
private final DataTypeBusinessLogic dataTypeBusinessLogic;
private final PolicyTypeBusinessLogic policyTypeBusinessLogic;
-
+ private final ModelOperation modelOperation;
+ private IInterfaceLifecycleOperation interfaceTypeOperation;
+ private LifecycleBusinessLogic lifecycleBusinessLogic;
@Autowired
private ICapabilityTypeOperation capabilityTypeOperation;
@Autowired
final OutputsBusinessLogic outputsBusinessLogic, final CompositionBusinessLogic compositionBusinessLogic,
final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic,
final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic,
- final MergeInstanceUtils mergeInstanceUtils, final UiComponentDataConverter uiComponentDataConverter,
- final CsarBusinessLogic csarBusinessLogic, final ArtifactsOperations artifactToscaOperation,
- final PropertyBusinessLogic propertyBusinessLogic, final ComponentContactIdValidator componentContactIdValidator,
- final ComponentNameValidator componentNameValidator, final ComponentTagsValidator componentTagsValidator,
- final ComponentValidator componentValidator, final ComponentIconValidator componentIconValidator,
+ final UiComponentDataConverter uiComponentDataConverter, final CsarBusinessLogic csarBusinessLogic,
+ final ArtifactsOperations artifactToscaOperation, final PropertyBusinessLogic propertyBusinessLogic,
+ final ComponentContactIdValidator componentContactIdValidator, final ComponentNameValidator componentNameValidator,
+ final ComponentTagsValidator componentTagsValidator, final ComponentValidator componentValidator,
+ final ComponentIconValidator componentIconValidator,
final ComponentProjectCodeValidator componentProjectCodeValidator,
final ComponentDescriptionValidator componentDescriptionValidator, final PolicyBusinessLogic policyBusinessLogic,
- final ModelBusinessLogic modelBusinessLogic,
- final DataTypeBusinessLogic dataTypeBusinessLogic, final PolicyTypeBusinessLogic policyTypeBusinessLogic) {
+ final ModelBusinessLogic modelBusinessLogic, final DataTypeBusinessLogic dataTypeBusinessLogic,
+ final PolicyTypeBusinessLogic policyTypeBusinessLogic, final ModelOperation modelOperation) {
super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation,
interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator, componentNameValidator,
componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator);
this.compositionBusinessLogic = compositionBusinessLogic;
this.resourceDataMergeBusinessLogic = resourceDataMergeBusinessLogic;
this.csarArtifactsAndGroupsBusinessLogic = csarArtifactsAndGroupsBusinessLogic;
- this.mergeInstanceUtils = mergeInstanceUtils;
this.uiComponentDataConverter = uiComponentDataConverter;
this.csarBusinessLogic = csarBusinessLogic;
this.propertyBusinessLogic = propertyBusinessLogic;
this.modelBusinessLogic = modelBusinessLogic;
this.dataTypeBusinessLogic = dataTypeBusinessLogic;
this.policyTypeBusinessLogic = policyTypeBusinessLogic;
+ this.modelOperation = modelOperation;
}
static <T> Either<T, RuntimeException> rollbackWithEither(final JanusGraphDao janusGraphDao, final ActionStatus actionStatus,
this.artifactsBusinessLogic = artifactsManager;
}
- public ApplicationDataTypeCache getApplicationDataTypeCache() {
- return applicationDataTypeCache;
- }
-
@Autowired
@Override
public void setApplicationDataTypeCache(ApplicationDataTypeCache applicationDataTypeCache) {
validateLifecycleState(oldResource, user);
String lockedResourceId = oldResource.getUniqueId();
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
- CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(newResource, oldResource, user, csarUIPayload, csarUUID);
+ CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(newResource, oldResource, user, csarUIPayload, csarUUID, null);
lockComponent(lockedResourceId, oldResource, "update Resource From Csar");
Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(
loggerSupportability
.log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML, StatusCode.STARTED, "Starting to create Resource From Csar by user {}",
user.getUserId());
- CsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, csarUIPayload, csarUUID);
+ OnboardedCsarInfo csarInfo = csarBusinessLogic.getCsarInfo(resource, null, user, csarUIPayload, csarUUID, null);
+
Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo();
final String model = resource.getModel();
if (StringUtils.isNotEmpty(model)) {
policyTypeBusinessLogic.createPolicyTypeFromYaml(new Yaml().dump(policyTypesToCreate), model, true);
}
}
-
Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = findNodeTypesArtifactsToHandle(
nodeTypesInfo, csarInfo, resource);
if (findNodeTypesArtifactsToHandleRes.isRight()) {
final Map<String, Object> dataTypesToCreate = new HashMap<>();
for (final String dataType : dataTypes.keySet()) {
final Either<DataTypeDefinition, StorageOperationStatus> result =
- propertyOperation.getDataTypeByName(dataType, model);
+ propertyOperation.getDataTypeByName(dataType, model);
if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
dataTypesToCreate.put(dataType, dataTypes.get(dataType));
}
final Map<String, Object> policyTypesToCreate = new HashMap<>();
for (final String policyType : policyTypes.keySet()) {
final Either<PolicyTypeDefinition, StorageOperationStatus> result =
- policyTypeOperation.getLatestPolicyTypeByType(policyType, model);
+ policyTypeOperation.getLatestPolicyTypeByType(policyType, model);
if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) {
policyTypesToCreate.put(policyType, policyTypes.get(policyType));
}
Function<Resource, Boolean> validator = resource -> validateResourceCreationFromNodeType(resource, creator);
return resourceImportManager
.importCertifiedResource(nodeTypeYaml, resourceMetaData, creator, validator, lifecycleChangeInfo, isInTransaction, true, needLock,
- nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo, nodeName, isNested);
+ nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, forceCertificationAllowed, csarInfo, nodeName, isNested, null);
}
/**
resourceMetaData.setIcon(ImportUtils.Constants.DEFAULT_ICON);
resourceMetaData.setContactId(user.getUserId());
resourceMetaData.setVendorName(resourceVf.getVendorName());
+ resourceMetaData.setTenant(resourceVf.getTenant());
resourceMetaData.setVendorRelease(resourceVf.getVendorRelease());
resourceMetaData.setModel(resourceVf.getModel());
// Setting tag
cvfc.setContactId(csarInfo.getModifier().getUserId());
cvfc.setCreatorUserId(csarInfo.getModifier().getUserId());
cvfc.setVendorName(resourceVf.getVendorName());
+ cvfc.setTenant(resourceVf.getTenant());
cvfc.setVendorRelease(resourceVf.getVendorRelease());
cvfc.setModel(resourceVf.getModel());
cvfc.setResourceVendorModelNumber(resourceVf.getResourceVendorModelNumber());
createResourcePropertiesOnGraph(resource);
final Map<String, UploadComponentInstanceInfo> instancesToCreate = getInstancesToCreate(parsedToscaYamlInfo, resource.getModel());
- log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName);
- loggerSupportability
- .log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML, resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,
- "Start create nodes, RI and Relations from yaml: {}", yamlName);
- resource = createRIAndRelationsFromYaml(yamlName, resource, instancesToCreate, topologyTemplateYaml,
- nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName,
- parsedToscaYamlInfo.getSubstitutionMappingNodeType());
+ if (MapUtils.isNotEmpty(instancesToCreate)) {
+ log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName);
+ loggerSupportability
+ .log(LoggerSupportabilityActions.CREATE_RESOURCE_FROM_YAML, resource.getComponentMetadataForSupportLog(), StatusCode.STARTED,
+ "Start create nodes, RI and Relations from yaml: {}", yamlName);
+ resource = createRIAndRelationsFromYaml(yamlName, resource, instancesToCreate, topologyTemplateYaml,
+ nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName,
+ parsedToscaYamlInfo.getSubstitutionMappingNodeType());
+ }
} else {
final Resource genericResource = fetchAndSetDerivedFromGenericType(resource, null);
resource = createResourceTransaction(resource, csarInfo.getModifier(), isNormative);
Map<String, UploadArtifactInfo> artifactsMap = instance.getValue().getArtifacts()
.get(ToscaTagNamesEnum.ARTIFACTS.getElementName());
if (isNotEmpty(artifactsMap) || artifactsMap != null) {
- for (Map.Entry<String , UploadArtifactInfo> artifact : artifactsMap.entrySet()) {
+ for (Map.Entry<String, UploadArtifactInfo> artifact : artifactsMap.entrySet()) {
if (artifact.getValue().getType().equals(Constants.ASD_DEPLOYMENT_ITEM)) {
GroupDefinition groupDefinition = new GroupDefinition();
groupDefinition.setName(artifact.getKey());
}
private Resource createPoliciesOnResource(Resource resource, Map<String, PolicyDefinition> policies) {
- policyBusinessLogic.createPoliciesFromParsedCsar(resource, policies);
+ policyBusinessLogic.createPolicies(resource, policies);
return resource;
}
final List<PropertyDefinition> resourceProperties = resource.getProperties();
for (PropertyDefinition propertyDefinition : resourceProperties) {
final Either<PropertyDefinition, StorageOperationStatus> addPropertyEither = toscaOperationFacade
- .addPropertyToComponent(propertyDefinition.getName(), propertyDefinition, resource);
+ .addPropertyToComponent(propertyDefinition, resource);
if (addPropertyEither.isRight()) {
- final String error = String.format("failed to add properties from yaml: {}", addPropertyEither.right().value());
+ final String error = String.format("failed to add properties from yaml: %s", addPropertyEither.right().value());
loggerSupportability.log(LoggerSupportabilityActions.CREATE_PROPERTIES, resource.getComponentMetadataForSupportLog(),
StatusCode.ERROR,
error);
List<GroupDefinition> result = new ArrayList<>();
List<ComponentInstance> componentInstances = component.getComponentInstances();
if (groups != null) {
- Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies = validateCyclicGroupsDependencies(groups);
- if (validateCyclicGroupsDependencies.isRight()) {
- throw new ByResponseFormatComponentException(validateCyclicGroupsDependencies.right().value());
- }
for (Entry<String, GroupDefinition> entry : groups.entrySet()) {
String groupName = entry.getKey();
GroupDefinition groupDefinition = entry.getValue();
GroupDefinition updatedGroupDefinition = new GroupDefinition(groupDefinition);
+
updatedGroupDefinition.setMembers(null);
Map<String, String> members = groupDefinition.getMembers();
if (members != null) {
updatedGroupDefinition.setMembers(relevantInstances);
}
- /**
- * This Method validates that there is no cyclic group dependencies. meaning group A as member in group B which is member in group A
- *
- * @param allGroups
- * @return
- */
- private Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies(Map<String, GroupDefinition> allGroups) {
- Either<Boolean, ResponseFormat> result = Either.left(true);
- try {
- Iterator<Entry<String, GroupDefinition>> allGroupsItr = allGroups.entrySet().iterator();
- while (allGroupsItr.hasNext() && result.isLeft()) {
- Entry<String, GroupDefinition> groupAEntry = allGroupsItr.next();
- // Fetches a group member A
- String groupAName = groupAEntry.getKey();
- // Finds all group members in group A
- Set<String> allGroupAMembersNames = new HashSet<>();
- fillAllGroupMemebersRecursivly(groupAEntry.getKey(), allGroups, allGroupAMembersNames);
- // If A is a group member of itself found cyclic dependency
- if (allGroupAMembersNames.contains(groupAName)) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GROUP_HAS_CYCLIC_DEPENDENCY, groupAName);
- result = Either.right(responseFormat);
- }
- }
- } catch (Exception e) {
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR);
- result = Either.right(responseFormat);
- log.debug("Exception occurred when validateCyclicGroupsDependencies, error is:{}", e.getMessage(), e);
- }
- return result;
- }
-
- /**
- * This Method fills recursively the set groupMembers with all the members of the given group which are also of type group.
- *
- * @param groupName
- * @param allGroups
- * @param allGroupMembers
- * @return
- */
- private void fillAllGroupMemebersRecursivly(String groupName, Map<String, GroupDefinition> allGroups, Set<String> allGroupMembers) {
- // Found Cyclic dependency
- if (isfillGroupMemebersRecursivlyStopCondition(groupName, allGroups, allGroupMembers)) {
- return;
- }
- GroupDefinition groupDefinition = allGroups.get(groupName);
- // All Members Of Current Group Resource Instances & Other Groups
- Set<String> currGroupMembers = groupDefinition.getMembers().keySet();
- // Filtered Members Of Current Group containing only members which
-
- // are groups
- List<String> currGroupFilteredMembers = currGroupMembers.stream().
- // Keep Only Elements of type group and not Resource Instances
- filter(allGroups::containsKey).
- // Add Filtered Elements to main Set
- peek(allGroupMembers::add).
- // Collect results
- collect(toList());
- // Recursively call the method for all the filtered group members
- for (String innerGroupName : currGroupFilteredMembers) {
- fillAllGroupMemebersRecursivly(innerGroupName, allGroups, allGroupMembers);
- }
- }
-
- private boolean isfillGroupMemebersRecursivlyStopCondition(String groupName, Map<String, GroupDefinition> allGroups,
- Set<String> allGroupMembers) {
- boolean stop = !allGroups.containsKey(groupName);
- // In Case Not Group Stop
- // In Case Group Has no members stop
- if (!stop) {
- GroupDefinition groupDefinition = allGroups.get(groupName);
- stop = isEmpty(groupDefinition.getMembers());
- }
- // In Case all group members already contained stop
- if (!stop) {
- final Set<String> allMembers = allGroups.get(groupName).getMembers().keySet();
- Set<String> membersOfTypeGroup = allMembers.stream().
- // Filter In Only Group members
- filter(allGroups::containsKey).
- // Collect
- collect(toSet());
- stop = allGroupMembers.containsAll(membersOfTypeGroup);
- }
- return stop;
- }
-
private Resource createRIAndRelationsFromYaml(String yamlName, Resource resource,
Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap,
String topologyTemplateYaml, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts,
Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME, Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId,
artifactOperation, null, true, shouldLock, inTransaction);
- createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL,
- ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VF_LICENSE_LABEL,
- Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId, artifactOperation, null, true, shouldLock,
- inTransaction);
- Either<Resource, ResponseFormat> eitherCreateResult = createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, shouldLock,
- inTransaction, artifactOperation);
+ createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL,
+ Constants.VF_LICENSE_MODEL, ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT,
+ Constants.VF_LICENSE_LABEL, Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId,
+ artifactOperation, null, true, shouldLock, inTransaction);
+ Either<Resource, ResponseFormat> eitherCreateResult
+ = createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, shouldLock, inTransaction, artifactOperation);
if (eitherCreateResult.isRight()) {
return Either.right(eitherCreateResult.right().value());
}
ToscaArtifactDataDefinition to = new ToscaArtifactDataDefinition();
to.setFile(entry.getValue().getFile());
to.setType(entry.getValue().getType());
- if(isNotEmpty(entry.getValue().getProperties())) {
+ if (isNotEmpty(entry.getValue().getProperties())) {
Map<String, Object> newPropertiesMap = new HashMap<>();
List<UploadPropInfo> artifactPropsInfo = entry.getValue().getProperties();
- for(UploadPropInfo propInfo: artifactPropsInfo) {
+ for (UploadPropInfo propInfo : artifactPropsInfo) {
newPropertiesMap.put(propInfo.getName(), propInfo.getValue());
}
to.setProperties(newPropertiesMap);
} else {
Either<Resource, StorageOperationStatus> findResourceEither = StringUtils.isEmpty(resource.getModel()) ?
toscaOperationFacade.getByToscaResourceNameMatchingVendorRelease(uploadComponentInstanceInfo.getType(),
- ((ResourceMetadataDataDefinition) resource.getComponentMetadataDefinition().getMetadataDataDefinition()).getVendorRelease()):
+ ((ResourceMetadataDataDefinition) resource.getComponentMetadataDefinition().getMetadataDataDefinition()).getVendorRelease()) :
toscaOperationFacade.getLatestByToscaResourceNameAndModel(uploadComponentInstanceInfo.getType(), resource.getModel());
if (findResourceEither.isRight()) {
log.debug("validateResourceInstanceBeforeCreate - not found latest version for resource instance with name {} and type {}",
nodeForceCertification(resource, user, lifecycleChangeInfo, inTransaction, needLock);
}
if (resource.getLifecycleState() == LifecycleStateEnum.CERTIFIED) {
- Either<ArtifactDefinition, Operation> eitherPopulated = populateToscaArtifacts(resource, user, false, inTransaction, needLock, false);
+ populateToscaArtifacts(resource, user, false, inTransaction, needLock, false);
return resource;
}
return nodeFullCertification(resource.getUniqueId(), user, lifecycleChangeInfo, inTransaction, needLock);
if (MapUtils.isEmpty(newResource.getToscaArtifacts())) {
setToscaArtifactsPlaceHolders(newResource, user);
}
- if (MapUtils.isEmpty(newResource.getInterfaces())) {
- newResource.setInterfaces(oldResource.getInterfaces());
- }
+
if (CollectionUtils.isEmpty(newResource.getAttributes())) {
newResource.setAttributes(oldResource.getAttributes());
}
if (newResource.getContactId() == null) {
newResource.setContactId(oldResource.getContactId());
}
+ newResource.setIcon(oldResource.getIcon());
newResource.setCategories(oldResource.getCategories());
if (newResource.getVendorName() == null) {
newResource.setVendorName(oldResource.getVendorName());
while (intItr.hasNext() && eitherResult.isLeft()) {
InterfaceDefinition interfaceDefinition = intItr.next();
String intType = interfaceDefinition.getUniqueId();
- Either<InterfaceDefinition, StorageOperationStatus> eitherCapTypeFound = interfaceTypeOperation.getInterface(intType);
+ Either<InterfaceDefinition, StorageOperationStatus> eitherCapTypeFound = interfaceTypeOperation.getInterface(UniqueIdBuilder.buildInterfaceTypeUid(resource.getModel(), intType));
if (eitherCapTypeFound.isRight()) {
if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
BeEcompErrorManager.getInstance()
Resource resource, List<?> validationObjects, AuditingActionEnum actionEnum,
Either<Boolean, ResponseFormat> eitherResult, String type,
boolean inTransaction) {
- Either<CapabilityTypeDefinition, StorageOperationStatus> eitherCapTypeFound = capabilityTypeOperation.getCapabilityType(UniqueIdBuilder.buildCapabilityTypeUid(resource.getModel(), type), inTransaction);
+ Either<CapabilityTypeDefinition, StorageOperationStatus> eitherCapTypeFound = capabilityTypeOperation.getCapabilityType(
+ UniqueIdBuilder.buildCapabilityTypeUid(resource.getModel(), type), inTransaction);
if (eitherCapTypeFound.isRight()) {
if (eitherCapTypeFound.right().value() == StorageOperationStatus.NOT_FOUND) {
BeEcompErrorManager.getInstance().logBeGraphObjectMissingError(CREATE_RESOURCE_VALIDATE_CAPABILITY_TYPES, "Capability Type", type);
componentsUtils.auditResource(componentsUtils.getResponseFormat(ActionStatus.CREATED), user, createdResource, actionEnum);
ASDCKpiApi.countCreatedResourcesKPI();
} catch (ComponentException e) {
+ janusGraphDao.rollback();
ResponseFormat responseFormat =
e.getResponseFormat() == null ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat();
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
throw e;
} catch (StorageException e) {
+ janusGraphDao.rollback();
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(componentsUtils.convertFromStorageResponse(e.getStorageOperationStatus()));
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
return componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(resourceStatus.right().value()), "");
}
Resource resource = resourceStatus.left().value();
- if (isComponentSystemDeployed(resource)) {
- throw new ByActionStatusComponentException(ActionStatus.CANNOT_DELETE_SYSTEM_DEPLOYED_RESOURCES, ComponentTypeEnum.RESOURCE.getValue(),
- resource.getName());
- }
StorageOperationStatus result = StorageOperationStatus.OK;
lockComponent(resourceId, resource, "Mark resource to delete");
try {
return resource.getComponentMetadataDefinition().getMetadataDataDefinition().isNormative();
}
+ /**
+ * Deletes every version of the provided resource
+ *
+ * @param resourceId the resource identifier
+ * @param user the user that performs the deletion
+ * @return
+ * @throws ComponentException if there is any error in the deletion of the resource operation
+ */
+ public void deleteResourceAllVersions(String resourceId, User user) {
+ validateUserExists(user);
+ Either<Resource, StorageOperationStatus> resourceStatus = toscaOperationFacade.getToscaElement(resourceId);
+ if (resourceStatus.isRight()) {
+ log.debug("Failed to get resource {}", resourceId);
+ componentException(resourceStatus.right().value());
+ }
+ Resource resource = resourceStatus.left().value();
+ if (isComponentSystemDeployed(resource)) {
+ throw new ByActionStatusComponentException(ActionStatus.CANNOT_DELETE_SYSTEM_DEPLOYED_RESOURCES, ComponentTypeEnum.RESOURCE.getValue(),
+ resource.getName());
+ }
+ if (Boolean.FALSE.equals(resource.isArchived())) {
+ log.debug("The resource, {}, requested for delete has not been archived.", resourceId);
+ throw new ComponentException(ActionStatus.COMPONENT_NOT_ARCHIVED, resourceId);
+ }
+ try {
+ String model = resource.getModel();
+ final Optional<Model> modelOptional = modelOperation.findModelByName(model);
+ List<String> deletedResourceList = toscaOperationFacade.deleteComponent(resource.getInvariantUUID(), NodeTypeEnum.Resource, true);
+ if (log.isDebugEnabled()) {
+ deletedResourceList.forEach(deletedR -> log.debug("Component {} was deleted.", deletedR));
+ }
+ if (modelOptional.isPresent() && modelOptional.get().getModelType() == ModelTypeEnum.NORMATIVE_EXTENSION) {
+ modelOperation.deleteModel(modelOptional.get(), true);
+ }
+ toscaOperationFacade.commitAndCheck(resource.getUniqueId());
+ updateCatalog(resource, ChangeTypeEnum.DELETE);
+ } catch (ComponentException exception) {
+ log.debug("Failed to delete resource, {} ", resourceId);
+ janusGraphDao.rollback();
+ throw exception;
+ }
+ }
+
public ResponseFormat deleteResourceByNameAndVersion(String resourceName, String version, User user) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NO_CONTENT);
validateUserExists(user);
} else {
newResource.setDerivedFrom(null);
}
- Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource, user, currentResource, false,
+ Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource, user, currentResource,
true);
if (dataModelResponse.isRight()) {
log.debug("failed to update resource metadata!!!");
}
private Either<Resource, ResponseFormat> updateResourceMetadata(String resourceIdToUpdate, Resource newResource, User user,
- Resource currentResource, boolean shouldLock, boolean inTransaction) {
+ Resource currentResource, boolean inTransaction) {
updateVfModuleGroupsNames(currentResource, newResource);
validateResourceFieldsBeforeUpdate(currentResource, newResource, inTransaction, false);
// Setting last updater and uniqueId
}
public void iterateOverProperties(List<PropertyDefinition> properties, String model) {
- String type = null;
- String innerType = null;
for (PropertyDefinition property : properties) {
if (!propertyOperation.isPropertyTypeValid(property, model)) {
log.info("Invalid type for property {}", property);
throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName());
}
Map<String, DataTypeDefinition> allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, model);
- type = property.getType();
+ String type = property.getType();
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- ResponseFormat responseFormat = validateMapOrListPropertyType(property, innerType, allDataTypes);
+ ResponseFormat responseFormat = validateMapOrListPropertyType(property, allDataTypes);
if (responseFormat != null) {
break;
}
}
- validateDefaultPropertyValue(property, allDataTypes, type, innerType);
+ validateDefaultPropertyValue(property, allDataTypes, type);
}
}
- private void validateDefaultPropertyValue(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes, String type,
- String innerType) {
+ private void validateDefaultPropertyValue(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes, String type) {
if (!propertyOperation.isPropertyDefaultValueValid(property, allDataTypes)) {
log.info("Invalid default value for property {}", property);
ResponseFormat responseFormat;
if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) {
- throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType,
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type,
property.getDefaultValue());
}
throw new ByActionStatusComponentException(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue());
}
}
- private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property, String innerType,
+ private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property,
Map<String, DataTypeDefinition> allDataTypes) {
ResponseFormat responseFormat = null;
ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, allDataTypes);
- innerType = propertyInnerTypeValid.getLeft();
- if (!propertyInnerTypeValid.getRight()) {
+ String innerType = propertyInnerTypeValid.getLeft();
+ if (Boolean.FALSE.equals(propertyInnerTypeValid.getRight())) {
log.info("Invalid inner type for property {}", property);
responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName());
}