aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2021-10-27 16:37:19 +0100
committerMichael Morris <michael.morris@est.tech>2021-12-07 09:24:54 +0000
commit5c9d068e66264be8db6018cb551db7c05e8e2596 (patch)
treecf2e5408b1fe76bbd9c83d81883f99b0188e7666 /catalog-be
parente97081649ac9b8655d45fe7781800a5e717dea07 (diff)
Update import service to import substitution filters
Issue-ID: SDC-3774 Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech> Change-Id: I7f747a07c82db6cec80db7ec1cb69fe9a5c8743a
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java19
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java17
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java22
4 files changed, 91 insertions, 6 deletions
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 cb3057b49a..5120834b1e 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
@@ -44,6 +44,7 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.NODE_TYPE;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.POLICIES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.PROPERTIES;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.REQUIREMENTS;
+import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_FILTERS;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TARGETS;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.TOPOLOGY_TEMPLATE;
@@ -62,7 +63,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -81,8 +81,10 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.model.CapabilityDefinition;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.GroupDefinition;
@@ -145,6 +147,7 @@ public class YamlTemplateParsingHandler {
if (getSubstitutionMappings(mappedToscaTemplate) != null) {
if (component.isService() && !interfaceTemplateYaml.isEmpty()) {
parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml)));
+ parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate));
}
parsedToscaYamlInfo.setSubstitutionMappingNodeType((String) getSubstitutionMappings(mappedToscaTemplate).get(NODE_TYPE.getElementName()));
}
@@ -189,6 +192,40 @@ public class YamlTemplateParsingHandler {
return ImportUtils.getProperties(toscaJson).left().on(err -> new HashMap<>());
}
+ private ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> getSubstitutionFilterProperties(Map<String, Object> toscaJson) {
+ ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> propertyList = new ListDataDefinition<>();
+ Map<String, Object> substitutionFilters = findFirstToscaMapElement(toscaJson, SUBSTITUTION_FILTERS).left().on(err -> new HashMap<>());
+ if (MapUtils.isEmpty(substitutionFilters)) {
+ return propertyList;
+ }
+ ArrayList<Map<String, List<Map<String, Object>>>> substitutionFilterProperties =
+ (ArrayList<Map<String, List<Map<String, Object>>>>) substitutionFilters.get("properties");
+ if (CollectionUtils.isEmpty(substitutionFilterProperties)) {
+ return propertyList;
+ }
+ for (Map<String, List<Map<String, Object>>> filterProps : substitutionFilterProperties) {
+ for (Map.Entry<String, List<Map<String, Object>>> filterPropsMap : filterProps.entrySet()) {
+ for (Map<String, Object> mapValue : filterPropsMap.getValue()) {
+ RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition =
+ new RequirementSubstitutionFilterPropertyDataDefinition();
+ requirementSubstitutionFilterPropertyDataDefinition.setName(filterPropsMap.getKey());
+ requirementSubstitutionFilterPropertyDataDefinition.setConstraints(
+ getSubstitutionFilterConstraints(filterPropsMap.getKey(), mapValue));
+ propertyList.add(requirementSubstitutionFilterPropertyDataDefinition);
+ }
+ }
+ }
+ return propertyList;
+ }
+
+ private List<String> getSubstitutionFilterConstraints(String name, Map<String, Object> value) {
+ List<String> constraints = new ArrayList<>();
+ for (Map.Entry<String, Object> valueMap : value.entrySet()) {
+ constraints.add(name + ": {" + valueMap.getKey() + ": " + valueMap.getValue() + "}");
+ }
+ return constraints;
+ }
+
private Map<String, PolicyDefinition> getPolicies(String fileName, Map<String, Object> toscaJson, String model) {
Map<String, Object> foundPolicies = findFirstToscaMapElement(toscaJson, POLICIES).left().on(err -> logPoliciesNotFound(fileName));
if (MapUtils.isNotEmpty(foundPolicies)) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
index c88746347e..74b353ec85 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogic.java
@@ -31,6 +31,7 @@ import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.validation.NodeFilterValidator;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@@ -248,4 +249,22 @@ public class ComponentSubstitutionFilterBusinessLogic extends BaseBusinessLogic
requirementSubstitutionFilterPropertyDataDefinition.setConstraints(Arrays.asList(constraint));
return requirementSubstitutionFilterPropertyDataDefinition;
}
+
+ public void addSubstitutionFilterInGraph(String componentId,
+ ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties)
+ throws BusinessLogicException {
+ Either<SubstitutionFilterDataDefinition, StorageOperationStatus> updateSubstitutionFilter;
+ Optional<SubstitutionFilterDataDefinition> substitutionFilter = createSubstitutionFilterIfNotExist(componentId, true,
+ ComponentTypeEnum.SERVICE);
+ if (substitutionFilter.isPresent()) {
+ for (RequirementSubstitutionFilterPropertyDataDefinition filter : substitutionFilterProperties.getListToscaDataDefinition()) {
+ updateSubstitutionFilter = substitutionFilterOperation.addPropertyFilter(componentId, substitutionFilter.get(), filter);
+ if (updateSubstitutionFilter.isRight()) {
+ throw new BusinessLogicException(componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(updateSubstitutionFilter.right().value())));
+ }
+ }
+ }
+ }
+
}
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 2fa20ea3a9..d7e5d0b9c1 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
@@ -46,6 +46,7 @@ import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils;
@@ -71,7 +72,9 @@ 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;
import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
@@ -247,7 +250,7 @@ public class ServiceImportBusinessLogic {
protected Service createServiceFromYaml(Service service, String topologyTemplateYaml, String yamlName, Map<String, NodeTypeInfo> nodeTypesInfo,
CsarInfo csarInfo,
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
- boolean shouldLock, boolean inTransaction, String nodeName) {
+ boolean shouldLock, boolean inTransaction, String nodeName) throws BusinessLogicException {
List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
Service createdService;
CreateServiceFromYamlParameter csfyp = new CreateServiceFromYamlParameter();
@@ -264,8 +267,8 @@ public class ServiceImportBusinessLogic {
csfyp.setNodeName(nodeName);
createdService = createServiceAndRIsFromYaml(service, false, nodeTypesArtifactsToCreate, shouldLock, inTransaction, csfyp);
log.debug("#createResourceFromYaml - The resource {} has been created ", service.getName());
- } catch (ComponentException e) {
- log.debug("create Service From Yaml failed,get ComponentException:{}", e);
+ } catch (ComponentException | BusinessLogicException e) {
+ log.debug("Create Service from yaml failed", e);
throw e;
} catch (StorageException e) {
log.debug("create Service From Yaml failed,get StorageException:{}", e);
@@ -276,7 +279,8 @@ public class ServiceImportBusinessLogic {
protected Service createServiceAndRIsFromYaml(Service service, boolean isNormative,
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate,
- boolean shouldLock, boolean inTransaction, CreateServiceFromYamlParameter csfyp) {
+ boolean shouldLock, boolean inTransaction, CreateServiceFromYamlParameter csfyp)
+ throws BusinessLogicException {
List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
String yamlName = csfyp.getYamlName();
ParsedToscaYamlInfo parsedToscaYamlInfo = csfyp.getParsedToscaYamlInfo();
@@ -310,6 +314,9 @@ public class ServiceImportBusinessLogic {
Map<String, InputDefinition> inputs = parsedToscaYamlInfo.getInputs();
service = serviceImportParseLogic.createInputsOnService(service, inputs);
log.trace("************* Finish to add inputs from yaml {}", yamlName);
+ ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties = parsedToscaYamlInfo.getSubstitutionFilterProperties();
+ service = serviceImportParseLogic.createSubstitutionFilterOnService(service, substitutionFilterProperties);
+ log.trace("************* Added Substitution filter from interface yaml {}", yamlName);
Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = parsedToscaYamlInfo.getInstances();
log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName);
service = createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap, topologyTemplateYaml,
@@ -345,7 +352,7 @@ public class ServiceImportBusinessLogic {
service = serviceImportParseLogic.getServiceWithGroups(createArtifactsEither.left().value().getUniqueId());
ASDCKpiApi.countCreatedResourcesKPI();
return service;
- } catch (ComponentException | StorageException e) {
+ } catch (ComponentException | StorageException | BusinessLogicException e) {
serviceImportParseLogic.rollback(inTransaction, service, createdArtifacts, nodeTypesNewCreatedArtifacts);
throw e;
} finally {
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 d9f5e1a5b9..a5db57287f 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
@@ -42,6 +42,7 @@ import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
+import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
@@ -54,9 +55,11 @@ 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;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -147,6 +150,8 @@ public class ServiceImportParseLogic {
@Autowired
private ResourceImportManager resourceImportManager;
@Autowired
+ private ComponentSubstitutionFilterBusinessLogic substitutionFilterBusinessLogic;
+ @Autowired
private IInterfaceLifecycleOperation interfaceTypeOperation = null;
@Autowired
private ICapabilityTypeOperation capabilityTypeOperation = null;
@@ -1376,6 +1381,23 @@ public class ServiceImportParseLogic {
return updatedResource.left().value();
}
+ public Service createSubstitutionFilterOnService(Service service,
+ ListDataDefinition<RequirementSubstitutionFilterPropertyDataDefinition> substitutionFilterProperties)
+ throws BusinessLogicException {
+ if (substitutionFilterProperties.isEmpty()) {
+ return service;
+ }
+ substitutionFilterBusinessLogic.addSubstitutionFilterInGraph(service.getUniqueId(), substitutionFilterProperties);
+ Either<Service, StorageOperationStatus> updatedResource = toscaOperationFacade.getToscaElement(service.getUniqueId());
+ if (updatedResource.isRight()) {
+ throw new ComponentException(componentsUtils
+ .getResponseFormatByComponent(componentsUtils.convertFromStorageResponse(updatedResource.right().value()), service,
+ ComponentTypeEnum.SERVICE));
+ }
+ return updatedResource.left().value();
+ }
+
+
public Service createServiceTransaction(Service service, User user, boolean isNormative) {
// validate resource name uniqueness
log.debug("validate resource name");