From 0902d2829ce984730085c816b649bed957ac0d99 Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Thu, 10 Mar 2022 19:42:39 +0000 Subject: Create vfModules for ASD Issue-ID: SDC-3906 Signed-off-by: KrupaNagabhushan Change-Id: I37560a6d672d3ec07af23b3405bbcb7ab195c9dc --- .../be/components/impl/ResourceBusinessLogic.java | 75 ++++++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 77d17ca76a..86d4e0aea1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -117,6 +117,7 @@ import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.GroupProperty; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; @@ -168,6 +169,7 @@ import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer; import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.be.utils.CommonBeUtils; import org.openecomp.sdc.be.utils.TypeUtils; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.common.api.ArtifactTypeEnum; import org.openecomp.sdc.common.api.Constants; @@ -1553,13 +1555,17 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { resource = createRIAndRelationsFromYaml(yamlName, resource, instancesToCreate, topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, nodeName, null); } - log.trace("************* Finished to create nodes, RI and Relation from yaml {}", yamlName); loggerSupportability.log(LoggerSupportabilityActions.CREATE_RELATIONS, resource.getComponentMetadataForSupportLog(), StatusCode.COMPLETE, "Finished to create nodes, RI and Relation from yaml: {}", yamlName); // validate update vf module group names + Optional> asdGroups = checkAndCreateAsdTypeVfModules(parsedToscaYamlInfo.getInstances()); + Map parsedGroups = parsedToscaYamlInfo.getGroups(); + if (asdGroups.isPresent()) { + parsedGroups.putAll(asdGroups.get()); + } final Either, ResponseFormat> validateUpdateVfGroupNamesRes = groupBusinessLogic - .validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), resource.getSystemName()); + .validateUpdateVfGroupNames(parsedGroups, resource.getSystemName()); if (validateUpdateVfGroupNamesRes.isRight()) { rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts); throw new ByResponseFormatComponentException(validateUpdateVfGroupNamesRes.right().value()); @@ -1572,7 +1578,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { if (!validateUpdateVfGroupNamesRes.left().value().isEmpty()) { groups = validateUpdateVfGroupNamesRes.left().value(); } else { - groups = parsedToscaYamlInfo.getGroups(); + groups = parsedGroups; } final Either createGroupsOnResource = createGroupsOnResource(resource, groups); if (createGroupsOnResource.isRight()) { @@ -1635,6 +1641,67 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } } + private Optional> checkAndCreateAsdTypeVfModules(Map instances) { + Map addAsdGroups = new HashMap<>(); + if (isNotEmpty(instances) || instances != null) { + for (Map.Entry instance : instances.entrySet()) { + if (isNotEmpty(instance.getValue().getArtifacts()) || instance.getValue().getArtifacts() != null) { + Map artifactsMap = instance.getValue().getArtifacts() + .get(ToscaTagNamesEnum.ARTIFACTS.getElementName()); + if (isNotEmpty(artifactsMap) || artifactsMap != null) { + for (Map.Entry artifact : artifactsMap.entrySet()) { + if (artifact.getValue().getType().equals(Constants.ASD_DEPLOYMENT_ITEM)) { + GroupDefinition groupDefinition = new GroupDefinition(); + groupDefinition.setName(artifact.getKey()); + groupDefinition.setType(Constants.DEFAULT_GROUP_VF_MODULE); + addAsdTypeProperties(groupDefinition); + addAsdGroups.put(groupDefinition.getName(), groupDefinition); + } + } + } + } + } + } + return Optional.of(addAsdGroups); + } + + private void addAsdTypeProperties(GroupDefinition groupDefinition) { + List properties = new ArrayList<>(); + GroupProperty propIsBase = new GroupProperty(); + propIsBase.setName(Constants.IS_BASE); + propIsBase.setValue("true"); + properties.add(propIsBase); + GroupProperty propVfModuleLabel = new GroupProperty(); + propVfModuleLabel.setName(Constants.VF_MODULE_LABEL); + propVfModuleLabel.setValue(groupDefinition.getName()); + properties.add(propVfModuleLabel); + GroupProperty propVfModuleDescription = new GroupProperty(); + propVfModuleDescription.setName(Constants.VF_MODULE_DESCRIPTION); + propVfModuleDescription.setValue("VF Module representing deployment item " + groupDefinition.getName()); + properties.add(propVfModuleDescription); + GroupProperty propMinVfModuleInstances = new GroupProperty(); + propMinVfModuleInstances.setName(Constants.MIN_VF_MODULE_INSTANCES); + propMinVfModuleInstances.setValue("1"); + properties.add(propMinVfModuleInstances); + GroupProperty propMaxVfModuleInstances = new GroupProperty(); + propMaxVfModuleInstances.setName(Constants.MAX_VF_MODULE_INSTANCES); + propMaxVfModuleInstances.setValue("1"); + properties.add(propMaxVfModuleInstances); + GroupProperty propInitialCount = new GroupProperty(); + propInitialCount.setName(Constants.INITIAL_COUNT); + propInitialCount.setValue("1"); + properties.add(propInitialCount); + GroupProperty propVfModuleType = new GroupProperty(); + propVfModuleType.setName(Constants.VF_MODULE_TYPE); + propVfModuleType.setValue("Base"); + properties.add(propVfModuleType); + GroupProperty propVolumeGroup = new GroupProperty(); + propVolumeGroup.setName(Constants.VOLUME_GROUP); + propVolumeGroup.setValue("false"); + properties.add(propVolumeGroup); + groupDefinition.convertFromGroupProperties(properties); + } + private boolean processSubstitutableAsNodeType(final Resource resource, final ParsedToscaYamlInfo parsedToscaYamlInfo) { return !resource.getResourceType().isAtomicType() && StringUtils.isNotEmpty(resource.getModel()) && parsedToscaYamlInfo.getSubstitutionMappingNodeType() != null; @@ -2140,8 +2207,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { return Either.right(createArtifactsFromCsar.right().value()); } return Either.left(createArtifactsFromCsar.left().value()); - } else { - return csarArtifactsAndGroupsBusinessLogic.deleteVFModules(resource, csarInfo, shouldLock, inTransaction); } } return Either.left(resource); -- cgit 1.2.3-korg