From 2dcfb0996a8345de5c8be73a5600ee995309664a Mon Sep 17 00:00:00 2001 From: vasraz Date: Tue, 21 Jun 2022 12:16:22 +0100 Subject: Support Groups during Import Service Signed-off-by: Vasyl Razinkov Change-Id: I6752ebf23920fda1395f4cb7f458ecb29f8ecd51 Issue-ID: SDC-4054 --- .../csar/CsarArtifactsAndGroupsBusinessLogic.java | 71 +++++++--------- .../csar/YamlTemplateParsingHandler.java | 36 ++++---- .../be/components/impl/GroupTypeImportManager.java | 26 +++--- .../be/components/impl/ResourceBusinessLogic.java | 96 +-------------------- .../impl/ServiceImportBusinessLogic.java | 18 ++-- .../components/impl/ServiceImportParseLogic.java | 97 ++-------------------- 6 files changed, 73 insertions(+), 271 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java index eefe47f69c..448077b6b5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java @@ -135,22 +135,16 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { } private Either checkoutRes(Component component) { - Either checkoutRes = getResourcetFromGraph(component); - Resource resource1 = (Resource) checkoutRes.left().value(); - Either checkoutRes1 = Either.left(resource1); - return checkoutRes1; + return Either.left((Resource) getResourcetFromGraph(component).left().value()); } public Either createResourceArtifactsFromCsar(CsarInfo csarInfo, Service resource, String artifactsMetaFile, String artifactsMetaFileName, List createdArtifacts) { log.debug("parseResourceArtifactsInfoFromFile start"); return parseResourceArtifactsInfoFromFile(resource, artifactsMetaFile, artifactsMetaFileName).left() - .bind(p -> createResourceArtifacts(csarInfo, resource, p, createdArtifacts)).right().map(rf -> rf).left().bind(c -> { - Either checkoutRes = getResourcetFromGraph(c); - Service resource1 = (Service) checkoutRes.left().value(); - Either checkoutRes1 = Either.left(resource1); - return checkoutRes1; - }); + .bind(p -> createResourceArtifacts(csarInfo, resource, p, createdArtifacts)).right().map(rf -> rf).left().bind(c -> + Either.left((Service) getResourcetFromGraph(c).left().value()) + ); } public Either updateResourceArtifactsFromCsar(CsarInfo csarInfo, Component resource, String artifactsMetaFile, @@ -1040,8 +1034,6 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { private void findArtifactToDelete(Map> parsedGroup, Set artifactsToDelete, ArtifactDefinition artifact, List createdDeploymentArtifacts) { - boolean isNeedToDeleteArtifact = true; - String artifactType = artifact.getArtifactType(); ArtifactDefinition generatedFromArt = null; if (artifact.getGeneratedFromId() != null && !artifact.getGeneratedFromId().isEmpty()) { Optional op = createdDeploymentArtifacts.stream().filter(p -> p.getUniqueId().equals(artifact.getGeneratedFromId())) @@ -1050,23 +1042,25 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { generatedFromArt = op.get(); } } - isNeedToDeleteArtifact(parsedGroup, artifactsToDelete, artifact, isNeedToDeleteArtifact, artifactType, generatedFromArt); + isNeedToDeleteArtifact(parsedGroup, artifactsToDelete, artifact, generatedFromArt); } private void isNeedToDeleteArtifact(Map> parsedGroup, Set artifactsToDelete, - ArtifactDefinition artifact, boolean isNeedToDeleteArtifact, String artifactType, - ArtifactDefinition generatedFromArt) { - for (Entry> parsedGroupSetEntry : parsedGroup.entrySet()) { - Set artifactsNames = parsedGroupSetEntry.getValue(); - for (ArtifactTemplateInfo template : artifactsNames) { - if (artifact.getArtifactName().equalsIgnoreCase(template.getFileName()) && artifactType.equalsIgnoreCase(template.getType())) { - isNeedToDeleteArtifact = false; - break; - } else { - if (generatedFromArt != null && generatedFromArt.getArtifactName().equalsIgnoreCase(template.getFileName()) && generatedFromArt - .getArtifactType().equalsIgnoreCase(template.getType())) { - isNeedToDeleteArtifact = false; - break; + ArtifactDefinition artifact, ArtifactDefinition generatedFromArt) { + final String artifactType = artifact.getArtifactType(); + final String artifactName = artifact.getArtifactName(); + boolean isNeedToDeleteArtifact = true; + for (final Entry> parsedGroupSetEntry : parsedGroup.entrySet()) { + if (isNeedToDeleteArtifact) { + for (final ArtifactTemplateInfo template : parsedGroupSetEntry.getValue()) { + if (isNeedToDeleteArtifact) { + final String fileName = template.getFileName(); + final String type = template.getType(); + if ((artifactName.equalsIgnoreCase(fileName) && artifactType.equalsIgnoreCase(type)) + || (generatedFromArt != null && generatedFromArt.getArtifactName().equalsIgnoreCase(fileName) && + generatedFromArt.getArtifactType().equalsIgnoreCase(type))) { + isNeedToDeleteArtifact = false; + } } } } @@ -1559,19 +1553,20 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { if (groupsToDelete != null && !groupsToDelete.isEmpty()) { List vfGroupsToDelete = groupsToDelete.stream().filter(g -> g.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE)) .collect(Collectors.toList()); - Either eitherGetResource = deleteVfGroups(vfGroupsToDelete, updatedResource, csarInfo, shouldLock, - inTransaction); - if (eitherGetResource.isRight()) { - return Either.right(eitherGetResource.right().value()); + if (CollectionUtils.isNotEmpty(vfGroupsToDelete)) { + Either eitherGetResource = deleteVfGroups(vfGroupsToDelete, updatedResource, csarInfo, shouldLock, + inTransaction); + if (eitherGetResource.isRight()) { + return Either.right(eitherGetResource.right().value()); + } + updatedResource = eitherGetResource.left().value(); } - updatedResource = eitherGetResource.left().value(); } return Either.left(updatedResource); } private Either deleteVfGroups(List vfGroupsToDelete, Service resource, CsarInfo csarInfo, boolean shouldLock, boolean inTransaction) { - ResponseFormat responseFormat; if (vfGroupsToDelete != null && !vfGroupsToDelete.isEmpty()) { for (GroupDefinition gr : vfGroupsToDelete) { List artifacts = gr.getArtifacts(); @@ -1587,16 +1582,12 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { groupBusinessLogic.deleteGroups(resource, vfGroupsToDelete); Either eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId()); if (eitherGetResource.isRight()) { - responseFormat = componentsUtils - .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource, - resource.getComponentType()); - return Either.right(responseFormat); + return Either.right(componentsUtils.getResponseFormatByComponent( + componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource, resource.getComponentType())); } - resource = eitherGetResource.left().value(); - return Either.left(resource); + return Either.left(eitherGetResource.left().value()); } - responseFormat = componentsUtils.getResponseFormatByComponent(ActionStatus.INVALID_CONTENT, resource, resource.getComponentType()); - return Either.right(responseFormat); + return Either.right(componentsUtils.getResponseFormatByComponent(ActionStatus.INVALID_CONTENT, resource, resource.getComponentType())); } private Either getResourcetFromGraph(Component component) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index 3faf750a73..6752586b80 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -138,11 +138,13 @@ public class YamlTemplateParsingHandler { log.debug("#parseResourceInfoFromYAML - Going to parse yaml {} ", fileName); Map mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName); ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo(); - Map mappedTopologyTemplate = (Map) findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL).left().on(err -> failIfNotTopologyTemplate(fileName)); - Map mappedTopologyTemplateInputs = mappedTopologyTemplate.entrySet().stream().filter(entry -> entry.getKey().equals(INPUTS.getElementName())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + Map mappedTopologyTemplate = (Map) findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, + ToscaElementTypeEnum.ALL).left().on(err -> failIfNotTopologyTemplate(fileName)); + Map mappedTopologyTemplateInputs = mappedTopologyTemplate.entrySet().stream() + .filter(entry -> entry.getKey().equals(INPUTS.getElementName())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); parsedToscaYamlInfo.setInputs(getInputs(mappedTopologyTemplateInputs)); - parsedToscaYamlInfo.setInstances(getInstances(fileName, mappedToscaTemplate, createdNodesToscaResourceNames)); - parsedToscaYamlInfo.setGroups(getGroups(fileName, mappedToscaTemplate, component.getModel())); + parsedToscaYamlInfo.setInstances(getInstances(mappedToscaTemplate, createdNodesToscaResourceNames)); + parsedToscaYamlInfo.setGroups(getGroups(mappedToscaTemplate, component.getModel())); if (component instanceof Resource) { parsedToscaYamlInfo.setPolicies(getPolicies(fileName, mappedToscaTemplate, component.getModel())); } @@ -319,7 +321,7 @@ public class YamlTemplateParsingHandler { return targets; } - private Map getInstances(String yamlName, Map toscaJson, + private Map getInstances(Map toscaJson, Map createdNodesToscaResourceNames) { Map nodeTemplates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES).left().on(err -> new HashMap<>()); if (nodeTemplates.isEmpty()) { @@ -330,27 +332,26 @@ public class YamlTemplateParsingHandler { private Map getInstances(Map toscaJson, Map createdNodesToscaResourceNames, Map nodeTemplates) { - Map moduleComponentInstances; Map substitutionMappings = getSubstitutionMappings(toscaJson); - moduleComponentInstances = nodeTemplates.entrySet().stream() + return nodeTemplates.entrySet().stream() .map(node -> buildModuleComponentInstanceInfo(node, substitutionMappings, createdNodesToscaResourceNames)) .collect(Collectors.toMap(UploadComponentInstanceInfo::getName, i -> i)); - return moduleComponentInstances; } private Map getSubstitutionMappings(Map toscaJson) { - Map substitutionMappings = null; Either, ResultStatusEnum> eitherSubstitutionMappings = findFirstToscaMapElement(toscaJson, SUBSTITUTION_MAPPINGS); if (eitherSubstitutionMappings.isLeft()) { - substitutionMappings = eitherSubstitutionMappings.left().value(); + return eitherSubstitutionMappings.left().value(); } - return substitutionMappings; + return null; } @SuppressWarnings("unchecked") - private Map getGroups(String fileName, Map toscaJson, String model) { - Map foundGroups = findFirstToscaMapElement(toscaJson, GROUPS).left().on(err -> logGroupsNotFound(fileName)); - if (MapUtils.isNotEmpty(foundGroups) && matcheKey(foundGroups)) { + private Map getGroups(Map toscaJson, String model) { + Map mappedTopologyTemplate = (Map) findToscaElement(toscaJson, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL) + .left().on(err -> new HashMap<>()); + Map foundGroups = (Map) mappedTopologyTemplate.get(GROUPS.getElementName()); + if (MapUtils.isNotEmpty(foundGroups)) { Map groups = foundGroups.entrySet().stream().map(groupToCreate -> createGroup(groupToCreate, model)) .collect(Collectors.toMap(GroupDefinition::getName, g -> g)); Map substitutionMappings = getSubstitutionMappings(toscaJson); @@ -411,7 +412,7 @@ public class YamlTemplateParsingHandler { rollbackWithException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE); } } catch (ClassCastException e) { - log.debug("#createGroup - Failed to create the group {}. The exception occure", groupNameValue.getKey(), e); + log.debug("#createGroup - Failed to create the group {}. The exception occurres", groupNameValue.getKey(), e); rollbackWithException(ActionStatus.INVALID_YAML); } return group; @@ -1088,11 +1089,6 @@ public class YamlTemplateParsingHandler { return propValue == null || !pattern.matcher(propValue.toString()).find(); } - private Map failIfNoNodeTemplates(String fileName) { - janusGraphDao.rollback(); - throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName); - } - private Object failIfNotTopologyTemplate(String fileName) { janusGraphDao.rollback(); throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java index 8ff7d994e2..135003e7f8 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java @@ -25,6 +25,9 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; @@ -116,11 +119,9 @@ public class GroupTypeImportManager { } private Either validateGroupType(GroupTypeDefinition groupType) { - Either result = Either.left(ActionStatus.OK); if (groupType.getMembers() != null) { if (groupType.getMembers().isEmpty()) { - ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.GROUP_MEMBER_EMPTY, groupType.getType()); - result = Either.right(responseFormat); + return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_MEMBER_EMPTY, groupType.getType())); } else { for (String member : groupType.getMembers()) { // Verify that such Resource exist @@ -131,13 +132,12 @@ public class GroupTypeImportManager { log.debug("Error when fetching parent resource {}, error: {}", member, operationStatus); ActionStatus convertFromStorageResponse = componentsUtils.convertFromStorageResponse(operationStatus); BeEcompErrorManager.getInstance().logBeComponentMissingError("Import GroupType", "resource", member); - result = Either.right(componentsUtils.getResponseFormat(convertFromStorageResponse, member)); - break; + return Either.right(componentsUtils.getResponseFormat(convertFromStorageResponse, member)); } } } } - return result; + return Either.left(ActionStatus.OK); } private GroupTypeDefinition createGroupType(String groupTypeName, Map toscaJson) { @@ -152,8 +152,7 @@ public class GroupTypeImportManager { // Metadata commonImportManager.setField(toscaJson, TypeUtils.ToscaTagNamesEnum.METADATA.getElementName(), groupType::setMetadata); // Capabilities - Map capabilities = createCapabilities(toscaJson); - groupType.setCapabilities(capabilities); + groupType.setCapabilities(createCapabilities(toscaJson)); // Members commonImportManager.setField(toscaJson, TypeUtils.ToscaTagNamesEnum.MEMBERS.getElementName(), groupType::setMembers); groupType.setType(groupTypeName); @@ -198,18 +197,13 @@ public class GroupTypeImportManager { return pl.stream().map(ComponentInstanceProperty::new).collect(Collectors.toList()); } + @NoArgsConstructor + @Getter + @Setter private class CapabilityTypeToscaJsonHolder { private Map capabilityTypeToscaJson; - public Map getCapabilityTypeToscaJson() { - return capabilityTypeToscaJson; - } - - public void setCapabilityTypeToscaJson(Map capabilityTypeToscaJson) { - this.capabilityTypeToscaJson = capabilityTypeToscaJson; - } - public boolean isEmpty() { return capabilityTypeToscaJson == null; } 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 d916dc6f64..6d5829e0fd 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 @@ -21,7 +21,6 @@ package org.openecomp.sdc.be.components.impl; 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; @@ -220,12 +219,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { 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 @@ -1945,14 +1943,11 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { List result = new ArrayList<>(); List componentInstances = component.getComponentInstances(); if (groups != null) { - Either validateCyclicGroupsDependencies = validateCyclicGroupsDependencies(groups); - if (validateCyclicGroupsDependencies.isRight()) { - throw new ByResponseFormatComponentException(validateCyclicGroupsDependencies.right().value()); - } for (Entry entry : groups.entrySet()) { String groupName = entry.getKey(); GroupDefinition groupDefinition = entry.getValue(); GroupDefinition updatedGroupDefinition = new GroupDefinition(groupDefinition); + updatedGroupDefinition.setMembers(null); Map members = groupDefinition.getMembers(); if (members != null) { @@ -1990,91 +1985,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { 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 validateCyclicGroupsDependencies(Map allGroups) { - Either result = Either.left(true); - try { - Iterator> allGroupsItr = allGroups.entrySet().iterator(); - while (allGroupsItr.hasNext() && result.isLeft()) { - Entry groupAEntry = allGroupsItr.next(); - // Fetches a group member A - String groupAName = groupAEntry.getKey(); - // Finds all group members in group A - Set 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 allGroups, Set 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 currGroupMembers = groupDefinition.getMembers().keySet(); - // Filtered Members Of Current Group containing only members which - - // are groups - List 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 allGroups, - Set 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 allMembers = allGroups.get(groupName).getMembers().keySet(); - Set 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 uploadComponentInstanceInfoMap, String topologyTemplateYaml, List nodeTypesNewCreatedArtifacts, diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index d7e5d0b9c1..9a8c181377 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -69,7 +69,6 @@ import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils; import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter; -import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; @@ -917,10 +916,6 @@ public class ServiceImportBusinessLogic { List result = new ArrayList<>(); List componentInstances = component.getComponentInstances(); if (groups != null) { - Either validateCyclicGroupsDependencies = serviceImportParseLogic.validateCyclicGroupsDependencies(groups); - if (validateCyclicGroupsDependencies.isRight()) { - throw new ComponentException(validateCyclicGroupsDependencies.right().value()); - } for (Map.Entry entry : groups.entrySet()) { String groupName = entry.getKey(); GroupDefinition groupDefinition = entry.getValue(); @@ -1353,7 +1348,8 @@ public class ServiceImportBusinessLogic { uploadResInstancesMap.values().forEach( i -> processComponentInstance(yamlName, finalResource, componentInstancesList, componentsUtils.getAllDataTypes(applicationDataTypeCache, finalResource.getModel()), instProperties, - instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, instNodeFilter, i)); + instCapabilities, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, instInputs, + instNodeFilter, i)); } serviceImportParseLogic.associateComponentInstancePropertiesToComponent(yamlName, service, instProperties); serviceImportParseLogic.associateComponentInstanceInputsToComponent(yamlName, service, instInputs); @@ -1698,7 +1694,7 @@ public class ServiceImportBusinessLogic { if (MapUtils.isNotEmpty(capabilitiesNamesToUpdate)) { for (Map.Entry> requirements : instance.getCapabilities().entrySet()) { updatedCapabilities.put(requirements.getKey(), requirements.getValue().stream().filter( - c -> capabilitiesNamesToUpdate.containsKey(c.getName()) && !updatedCapNames.contains(capabilitiesNamesToUpdate.get(c.getName()))) + c -> capabilitiesNamesToUpdate.containsKey(c.getName()) && !updatedCapNames.contains(capabilitiesNamesToUpdate.get(c.getName()))) .map(c -> { c.setParentName(c.getName()); c.setName(capabilitiesNamesToUpdate.get(c.getName())); @@ -1719,7 +1715,7 @@ public class ServiceImportBusinessLogic { if (MapUtils.isNotEmpty(requirementsNamesToUpdate)) { for (Map.Entry> requirements : instance.getRequirements().entrySet()) { updatedRequirements.put(requirements.getKey(), requirements.getValue().stream().filter( - r -> requirementsNamesToUpdate.containsKey(r.getName()) && !updatedReqNames.contains(requirementsNamesToUpdate.get(r.getName()))) + r -> requirementsNamesToUpdate.containsKey(r.getName()) && !updatedReqNames.contains(requirementsNamesToUpdate.get(r.getName()))) .map(r -> { r.setParentName(r.getName()); r.setName(requirementsNamesToUpdate.get(r.getName())); @@ -1790,7 +1786,7 @@ public class ServiceImportBusinessLogic { regCapRelDef.setFromNode(resourceInstanceId); log.debug("try to find available requirement {} ", regName); Either eitherReqStatus = serviceImportParseLogic - .findAviableRequiremen(regName, yamlName, nodesInfoValue, currentCompInstance, uploadRegInfo.getCapabilityName()); + .findAvailableRequirement(regName, yamlName, nodesInfoValue, currentCompInstance, uploadRegInfo.getCapabilityName()); if (eitherReqStatus.isRight()) { log.debug("failed to find available requirement {} status is {}", regName, eitherReqStatus.right().value()); return eitherReqStatus.right().value(); @@ -2316,10 +2312,6 @@ public class ServiceImportBusinessLogic { List result = new ArrayList<>(); List componentInstances = component.getComponentInstances(); if (groups != null) { - Either validateCyclicGroupsDependencies = serviceImportParseLogic.validateCyclicGroupsDependencies(groups); - if (validateCyclicGroupsDependencies.isRight()) { - throw new ComponentException(validateCyclicGroupsDependencies.right().value()); - } for (Map.Entry entry : groups.entrySet()) { String groupName = entry.getKey(); GroupDefinition groupDefinition = entry.getValue(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java index 29758b6bc5..63abf26ef4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java @@ -18,15 +18,12 @@ package org.openecomp.sdc.be.components.impl; import static java.util.stream.Collectors.joining; 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 fj.data.Either; import java.util.ArrayList; -import java.util.Collections; import java.util.EnumMap; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -51,7 +48,6 @@ import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; @@ -451,31 +447,6 @@ public class ServiceImportParseLogic { return componentTypeForResponse; } - protected boolean isfillGroupMemebersRecursivlyStopCondition(String groupName, Map allGroups, - Set allGroupMembers) { - boolean stop = false; - // In Case Not Group Stop - if (!allGroups.containsKey(groupName)) { - stop = true; - } - // In Case Group Has no members stop - if (!stop) { - GroupDefinition groupDefinition = allGroups.get(groupName); - stop = MapUtils.isEmpty(groupDefinition.getMembers()); - } - // In Case all group members already contained stop - if (!stop) { - final Set allMembers = allGroups.get(groupName).getMembers().keySet(); - Set membersOfTypeGroup = allMembers.stream(). - // Filter In Only Group members - filter(allGroups::containsKey). - // Collect - collect(toSet()); - stop = allGroupMembers.containsAll(membersOfTypeGroup); - } - return stop; - } - public Resource buildValidComplexVfc(Resource resource, CsarInfo csarInfo, String nodeName, Map nodesInfo) { Resource complexVfc = buildComplexVfcMetadata(resource, csarInfo, nodeName, nodesInfo); log.debug("************* Going to validate complex VFC from yaml {}", complexVfc.getName()); @@ -1028,9 +999,9 @@ public class ServiceImportParseLogic { } } - public Either findAviableRequiremen(String regName, String yamlName, - UploadComponentInstanceInfo uploadComponentInstanceInfo, - ComponentInstance currentCompInstance, String capName) { + public Either findAvailableRequirement(String regName, String yamlName, + UploadComponentInstanceInfo uploadComponentInstanceInfo, + ComponentInstance currentCompInstance, String capName) { Map> comInstRegDefMap = currentCompInstance.getRequirements(); List list = comInstRegDefMap.get(capName); RequirementDefinition validRegDef = null; @@ -1232,7 +1203,7 @@ public class ServiceImportParseLogic { String propertyName = property.getName().toLowerCase(); String propertyType = property.getType(); ComponentInstanceProperty validProperty; - if (defaultProperties.containsKey(propertyName) && propertTypeEqualsTo(defaultProperties, propertyName, propertyType)) { + if (defaultProperties.containsKey(propertyName) && propertyTypeEqualsTo(defaultProperties, propertyName, propertyType)) { throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS, propertyName)); } validProperty = new ComponentInstanceProperty(); @@ -1247,7 +1218,7 @@ public class ServiceImportParseLogic { defaultCapability.setProperties(validProperties); } - private boolean propertTypeEqualsTo(Map defaultProperties, String propertyName, String propertyType) { + private boolean propertyTypeEqualsTo(Map defaultProperties, String propertyName, String propertyType) { return propertyType != null && !defaultProperties.get(propertyName).getType().equals(propertyType); } @@ -1710,10 +1681,6 @@ public class ServiceImportParseLogic { List result = new ArrayList<>(); List componentInstances = component.getComponentInstances(); if (groups != null) { - Either validateCyclicGroupsDependencies = validateCyclicGroupsDependencies(groups); - if (validateCyclicGroupsDependencies.isRight()) { - throw new ComponentException(validateCyclicGroupsDependencies.right().value()); - } for (Map.Entry entry : groups.entrySet()) { String groupName = entry.getKey(); GroupDefinition groupDefinition = entry.getValue(); @@ -1760,55 +1727,6 @@ public class ServiceImportParseLogic { updatedGroupDefinition.setMembers(relevantInstances); } - public Either validateCyclicGroupsDependencies(Map allGroups) { - Either result = Either.left(true); - try { - Iterator> allGroupsItr = allGroups.entrySet().iterator(); - while (allGroupsItr.hasNext() && result.isLeft()) { - Map.Entry groupAEntry = allGroupsItr.next(); - // Fetches a group member A - String groupAName = groupAEntry.getKey(); - // Finds all group members in group A - Set 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 occured when validateCyclicGroupsDependencies, error is:{}", e.getMessage(), e); - } - return result; - } - - protected void fillAllGroupMemebersRecursivly(String groupName, Map allGroups, Set 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 currGroupMembers = groupDefinition.getMembers().keySet(); - // Filtered Members Of Current Group containing only members which - - // are groups - List 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); - } - } - public ImmutablePair createResourceFromNodeType(String nodeTypeYaml, UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction, boolean needLock, Map> nodeTypeArtifactsToHandle, @@ -2157,7 +2075,8 @@ public class ServiceImportParseLogic { public void associateCINodeFilterToComponent(String yamlName, Service service, Map nodeFilter) { log.trace("************* Going to associate all resource node filters {}", yamlName); if (MapUtils.isNotEmpty(nodeFilter)) { - StorageOperationStatus status = componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(service.getUniqueId(), nodeFilter); + StorageOperationStatus status = componentNodeFilterBusinessLogic.associateNodeFilterToComponentInstance(service.getUniqueId(), + nodeFilter); if (status != StorageOperationStatus.OK) { throw new ComponentException( componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), yamlName)); @@ -2342,7 +2261,7 @@ public class ServiceImportParseLogic { RequirementCapabilityRelDef regCapRelDef = new RequirementCapabilityRelDef(); regCapRelDef.setFromNode(resourceInstanceId); log.debug("try to find available requirement {} ", regName); - Either eitherReqStatus = findAviableRequiremen(regName, yamlName, nodesInfoValue, + Either eitherReqStatus = findAvailableRequirement(regName, yamlName, nodesInfoValue, currentCompInstance, uploadRegInfo.getCapabilityName()); if (eitherReqStatus.isRight()) { return eitherReqStatus.right().value(); -- cgit 1.2.3-korg