summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-06-21 12:16:22 +0100
committerMichael Morris <michael.morris@est.tech>2022-06-24 12:53:56 +0000
commit2dcfb0996a8345de5c8be73a5600ee995309664a (patch)
tree1c30a3db787043e3d963651dfa2224d0a88acc1c /catalog-be/src/main/java/org
parentfd3e0e4d9f8badf7632dbfebd39574810ba83e9a (diff)
Support Groups during Import Service
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I6752ebf23920fda1395f4cb7f458ecb29f8ecd51 Issue-ID: SDC-4054
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java71
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java36
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java26
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java96
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java18
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java97
6 files changed, 73 insertions, 271 deletions
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<Resource, ResponseFormat> checkoutRes(Component component) {
- Either<? extends Component, ResponseFormat> checkoutRes = getResourcetFromGraph(component);
- Resource resource1 = (Resource) checkoutRes.left().value();
- Either<Resource, ResponseFormat> checkoutRes1 = Either.left(resource1);
- return checkoutRes1;
+ return Either.left((Resource) getResourcetFromGraph(component).left().value());
}
public Either<Service, ResponseFormat> createResourceArtifactsFromCsar(CsarInfo csarInfo, Service resource, String artifactsMetaFile,
String artifactsMetaFileName, List<ArtifactDefinition> 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<? extends Component, ResponseFormat> checkoutRes = getResourcetFromGraph(c);
- Service resource1 = (Service) checkoutRes.left().value();
- Either<Service, ResponseFormat> 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<Component, ResponseFormat> updateResourceArtifactsFromCsar(CsarInfo csarInfo, Component resource, String artifactsMetaFile,
@@ -1040,8 +1034,6 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
private void findArtifactToDelete(Map<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup, Set<ArtifactDefinition> artifactsToDelete,
ArtifactDefinition artifact, List<ArtifactDefinition> createdDeploymentArtifacts) {
- boolean isNeedToDeleteArtifact = true;
- String artifactType = artifact.getArtifactType();
ArtifactDefinition generatedFromArt = null;
if (artifact.getGeneratedFromId() != null && !artifact.getGeneratedFromId().isEmpty()) {
Optional<ArtifactDefinition> 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<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroup, Set<ArtifactDefinition> artifactsToDelete,
- ArtifactDefinition artifact, boolean isNeedToDeleteArtifact, String artifactType,
- ArtifactDefinition generatedFromArt) {
- for (Entry<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> parsedGroupSetEntry : parsedGroup.entrySet()) {
- Set<ArtifactTemplateInfo> 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<ArtifactTemplateInfo, Set<ArtifactTemplateInfo>> 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<GroupDefinition> vfGroupsToDelete = groupsToDelete.stream().filter(g -> g.getType().equals(Constants.DEFAULT_GROUP_VF_MODULE))
.collect(Collectors.toList());
- Either<Service, ResponseFormat> eitherGetResource = deleteVfGroups(vfGroupsToDelete, updatedResource, csarInfo, shouldLock,
- inTransaction);
- if (eitherGetResource.isRight()) {
- return Either.right(eitherGetResource.right().value());
+ if (CollectionUtils.isNotEmpty(vfGroupsToDelete)) {
+ Either<Service, ResponseFormat> 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<Service, ResponseFormat> deleteVfGroups(List<GroupDefinition> vfGroupsToDelete, Service resource, CsarInfo csarInfo,
boolean shouldLock, boolean inTransaction) {
- ResponseFormat responseFormat;
if (vfGroupsToDelete != null && !vfGroupsToDelete.isEmpty()) {
for (GroupDefinition gr : vfGroupsToDelete) {
List<String> artifacts = gr.getArtifacts();
@@ -1587,16 +1582,12 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic {
groupBusinessLogic.deleteGroups(resource, vfGroupsToDelete);
Either<Service, StorageOperationStatus> 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<? extends Component, ResponseFormat> 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<String, Object> mappedToscaTemplate = getMappedToscaTemplate(fileName, resourceYml, nodeTypesInfo, nodeName);
ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
- Map<String, Object> mappedTopologyTemplate = (Map<String, Object>) findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL).left().on(err -> failIfNotTopologyTemplate(fileName));
- Map<String, Object> mappedTopologyTemplateInputs = mappedTopologyTemplate.entrySet().stream().filter(entry -> entry.getKey().equals(INPUTS.getElementName())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ Map<String, Object> mappedTopologyTemplate = (Map<String, Object>) findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE,
+ ToscaElementTypeEnum.ALL).left().on(err -> failIfNotTopologyTemplate(fileName));
+ Map<String, Object> 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<String, UploadComponentInstanceInfo> getInstances(String yamlName, Map<String, Object> toscaJson,
+ private Map<String, UploadComponentInstanceInfo> getInstances(Map<String, Object> toscaJson,
Map<String, String> createdNodesToscaResourceNames) {
Map<String, Object> nodeTemplates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES).left().on(err -> new HashMap<>());
if (nodeTemplates.isEmpty()) {
@@ -330,27 +332,26 @@ public class YamlTemplateParsingHandler {
private Map<String, UploadComponentInstanceInfo> getInstances(Map<String, Object> toscaJson, Map<String, String> createdNodesToscaResourceNames,
Map<String, Object> nodeTemplates) {
- Map<String, UploadComponentInstanceInfo> moduleComponentInstances;
Map<String, Object> 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<String, Object> getSubstitutionMappings(Map<String, Object> toscaJson) {
- Map<String, Object> substitutionMappings = null;
Either<Map<String, Object>, 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<String, GroupDefinition> getGroups(String fileName, Map<String, Object> toscaJson, String model) {
- Map<String, Object> foundGroups = findFirstToscaMapElement(toscaJson, GROUPS).left().on(err -> logGroupsNotFound(fileName));
- if (MapUtils.isNotEmpty(foundGroups) && matcheKey(foundGroups)) {
+ private Map<String, GroupDefinition> getGroups(Map<String, Object> toscaJson, String model) {
+ Map<String, Object> mappedTopologyTemplate = (Map<String, Object>) findToscaElement(toscaJson, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL)
+ .left().on(err -> new HashMap<>());
+ Map<String, Object> foundGroups = (Map<String, Object>) mappedTopologyTemplate.get(GROUPS.getElementName());
+ if (MapUtils.isNotEmpty(foundGroups)) {
Map<String, GroupDefinition> groups = foundGroups.entrySet().stream().map(groupToCreate -> createGroup(groupToCreate, model))
.collect(Collectors.toMap(GroupDefinition::getName, g -> g));
Map<String, Object> 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<String, Object> 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<ActionStatus, ResponseFormat> validateGroupType(GroupTypeDefinition groupType) {
- Either<ActionStatus, ResponseFormat> 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<String, Object> toscaJson) {
@@ -152,8 +152,7 @@ public class GroupTypeImportManager {
// Metadata
commonImportManager.setField(toscaJson, TypeUtils.ToscaTagNamesEnum.METADATA.getElementName(), groupType::setMetadata);
// Capabilities
- Map<String, CapabilityDefinition> 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<String, Object> capabilityTypeToscaJson;
- public Map<String, Object> getCapabilityTypeToscaJson() {
- return capabilityTypeToscaJson;
- }
-
- public void setCapabilityTypeToscaJson(Map<String, Object> 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<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) {
@@ -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<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,
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<GroupDefinition> result = new ArrayList<>();
List<ComponentInstance> componentInstances = component.getComponentInstances();
if (groups != null) {
- Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies = serviceImportParseLogic.validateCyclicGroupsDependencies(groups);
- if (validateCyclicGroupsDependencies.isRight()) {
- throw new ComponentException(validateCyclicGroupsDependencies.right().value());
- }
for (Map.Entry<String, GroupDefinition> 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<String, List<CapabilityDefinition>> 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<String, List<RequirementDefinition>> 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<RequirementDefinition, ResponseFormat> 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<GroupDefinition> result = new ArrayList<>();
List<ComponentInstance> componentInstances = component.getComponentInstances();
if (groups != null) {
- Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies = serviceImportParseLogic.validateCyclicGroupsDependencies(groups);
- if (validateCyclicGroupsDependencies.isRight()) {
- throw new ComponentException(validateCyclicGroupsDependencies.right().value());
- }
for (Map.Entry<String, GroupDefinition> 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<String, GroupDefinition> allGroups,
- Set<String> 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<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;
- }
-
public Resource buildValidComplexVfc(Resource resource, CsarInfo csarInfo, String nodeName, Map<String, NodeTypeInfo> 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<RequirementDefinition, ResponseFormat> findAviableRequiremen(String regName, String yamlName,
- UploadComponentInstanceInfo uploadComponentInstanceInfo,
- ComponentInstance currentCompInstance, String capName) {
+ public Either<RequirementDefinition, ResponseFormat> findAvailableRequirement(String regName, String yamlName,
+ UploadComponentInstanceInfo uploadComponentInstanceInfo,
+ ComponentInstance currentCompInstance, String capName) {
Map<String, List<RequirementDefinition>> comInstRegDefMap = currentCompInstance.getRequirements();
List<RequirementDefinition> 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<String, PropertyDefinition> defaultProperties, String propertyName, String propertyType) {
+ private boolean propertyTypeEqualsTo(Map<String, PropertyDefinition> defaultProperties, String propertyName, String propertyType) {
return propertyType != null && !defaultProperties.get(propertyName).getType().equals(propertyType);
}
@@ -1710,10 +1681,6 @@ public class ServiceImportParseLogic {
List<GroupDefinition> result = new ArrayList<>();
List<ComponentInstance> componentInstances = component.getComponentInstances();
if (groups != null) {
- Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies = validateCyclicGroupsDependencies(groups);
- if (validateCyclicGroupsDependencies.isRight()) {
- throw new ComponentException(validateCyclicGroupsDependencies.right().value());
- }
for (Map.Entry<String, GroupDefinition> entry : groups.entrySet()) {
String groupName = entry.getKey();
GroupDefinition groupDefinition = entry.getValue();
@@ -1760,55 +1727,6 @@ public class ServiceImportParseLogic {
updatedGroupDefinition.setMembers(relevantInstances);
}
- public Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies(Map<String, GroupDefinition> allGroups) {
- Either<Boolean, ResponseFormat> result = Either.left(true);
- try {
- Iterator<Map.Entry<String, GroupDefinition>> allGroupsItr = allGroups.entrySet().iterator();
- while (allGroupsItr.hasNext() && result.isLeft()) {
- Map.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 occured when validateCyclicGroupsDependencies, error is:{}", e.getMessage(), e);
- }
- return result;
- }
-
- protected 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);
- }
- }
-
public ImmutablePair<Resource, ActionStatus> createResourceFromNodeType(String nodeTypeYaml, UploadResourceInfo resourceMetaData, User creator,
boolean isInTransaction, boolean needLock,
Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle,
@@ -2157,7 +2075,8 @@ public class ServiceImportParseLogic {
public void associateCINodeFilterToComponent(String yamlName, Service service, Map<String, UploadNodeFilterInfo> 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<RequirementDefinition, ResponseFormat> eitherReqStatus = findAviableRequiremen(regName, yamlName, nodesInfoValue,
+ Either<RequirementDefinition, ResponseFormat> eitherReqStatus = findAvailableRequirement(regName, yamlName, nodesInfoValue,
currentCompInstance, uploadRegInfo.getCapabilityName());
if (eitherReqStatus.isRight()) {
return eitherReqStatus.right().value();