From bdeb28f273da2494d7eeabbb5329222dfd168e3b Mon Sep 17 00:00:00 2001 From: aribeiro Date: Wed, 24 Jun 2020 08:34:22 +0100 Subject: Add support for substitution_filter business logic Tosca simple YAML profile allows for substitution_filter to be specified for a topology template to provide processing instructions to the orchestrator. Issue-ID: SDC-3147 Signed-off-by: aribeiro Change-Id: Ia94b8c447d3157e614f9d1524ad4520b3980ba4d --- .../java/org/openecomp/sdc/be/model/Component.java | 2 + .../openecomp/sdc/be/model/ComponentInstance.java | 104 +++------------ .../sdc/be/model/ComponentParametersView.java | 31 +++++ .../jsonjanusgraph/datamodel/TopologyTemplate.java | 10 ++ .../jsonjanusgraph/operations/BaseOperation.java | 34 ++--- .../operations/NodeFilterOperation.java | 49 ++++---- .../operations/SubstitutionFilterOperation.java | 139 +++++++++++++++++++++ .../operations/TopologyTemplateOperation.java | 48 ++++--- .../model/jsonjanusgraph/utils/ModelConverter.java | 37 +++++- .../sdc/be/ui/model/UiComponentDataTransfer.java | 3 + 10 files changed, 302 insertions(+), 155 deletions(-) create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java (limited to 'catalog-model/src') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java index 477d903652..dc0fb51d7c 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java @@ -48,6 +48,7 @@ import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType; import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; @@ -83,6 +84,7 @@ public abstract class Component implements PropertiesOwner { private String derivedFromGenericVersion; private String toscaType; private Map nodeFilterComponents; + private Map substitutionFilterComponents; private Map interfaces; private List dataTypes; diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java index 3eefcc1505..5b99f99bd2 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java @@ -20,20 +20,24 @@ package org.openecomp.sdc.be.model; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import lombok.Getter; +import lombok.Setter; import org.apache.commons.collections.MapUtils; +import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner; +import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition; import org.openecomp.sdc.be.datatypes.enums.CreatedFrom; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.common.log.api.ILogConfiguration; -import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ComponentInstance extends ComponentInstanceDataDefinition implements PropertiesOwner{ +@Getter +@Setter +public class ComponentInstance extends ComponentInstanceDataDefinition implements PropertiesOwner { private Map> capabilities; private Map> requirements; @@ -43,6 +47,7 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement private Map interfaces; private List properties; private CINodeFilterDataDefinition nodeFilter; + private SubstitutionFilterDataDefinition substitutionFilter; private List inputs; public ComponentInstance() { @@ -53,26 +58,6 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement super(r); } - public Map> getCapabilities() { - return capabilities; - } - - public void setCapabilities(Map> capabilities) { - this.capabilities = capabilities; - } - - public Map> getRequirements() { - return requirements; - } - - public void setRequirements(Map> requirements) { - this.requirements = requirements; - } - - public Map getDeploymentArtifacts() { - return deploymentArtifacts; - } - public Map safeGetDeploymentArtifacts() { return deploymentArtifacts == null ? Collections.emptyMap() : deploymentArtifacts; } @@ -81,30 +66,10 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement return artifacts == null ? Collections.emptyMap() : deploymentArtifacts; } - public void setDeploymentArtifacts(Map deploymentArtifacts) { - this.deploymentArtifacts = deploymentArtifacts; - } - - public Map getArtifacts() { - return artifacts; - } - public Map safeGetArtifacts() { return artifacts == null ? Collections.emptyMap() : artifacts; } - public void setArtifacts(Map artifacts) { - this.artifacts = artifacts; - } - - public List getGroupInstances() { - return groupInstances; - } - - public void setGroupInstances(List groupInstances) { - this.groupInstances = groupInstances; - } - public String getActualComponentUid() { return getIsProxy() ? getSourceModelUid() : getComponentUid(); } @@ -116,57 +81,24 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement return safeGetInformationalArtifacts().get(artifactLabel) != null; } - public Map getInterfaces() { - return interfaces; - } - - public void setInterfaces(Map interfaces) { - this.interfaces = interfaces; - } - public void addInterface(String interfaceName, Object interfaceDefinition) { - if(MapUtils.isEmpty(this.interfaces)) { + if (MapUtils.isEmpty(this.interfaces)) { this.interfaces = new HashMap<>(); } - this.interfaces.put(interfaceName, interfaceDefinition); } - public List getProperties() { - return properties; - } - - public void setProperties(List properties) { - this.properties = properties; - } - - public CINodeFilterDataDefinition getNodeFilter() { - return nodeFilter; - } - - public void setNodeFilter(CINodeFilterDataDefinition nodeFilter) { - this.nodeFilter = nodeFilter; - } - //supportability log method return map of component metadata teddy.h - public Map getComponentMetadataForSupportLog(){ - MapcomponentMetadata=new HashMap<>(); - componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME,getName()); - componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION,getVersion()); + public Map getComponentMetadataForSupportLog() { + Map componentMetadata = new HashMap<>(); + componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME, getName()); + componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_VERSION, getVersion()); componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_UUID, getSourceModelUuid()); return componentMetadata; } - public boolean isCreatedFromCsar(){ + public boolean isCreatedFromCsar() { return CreatedFrom.CSAR.equals(this.getCreatedFrom()); } - public List getInputs() { - return inputs; - } - - public void setInputs(List inputs) { - this.inputs = inputs; - } - } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java index 4e7903a890..f1785c76f8 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentParametersView.java @@ -50,7 +50,9 @@ public class ComponentParametersView { private boolean ignoreServicePath = true; private boolean ignorePolicies = false; private boolean ignoreNodeFilterRequirements = false; + private boolean ignoreSubstitutionFilterRequirements = false; private boolean ignoreNodeFilter = false; + private boolean ignoreSubstitutionFilter = false; private boolean ignoreDataType = false; public ComponentParametersView() { @@ -95,6 +97,7 @@ public class ComponentParametersView { this.setIgnoreCapabilities(false); this.setIgnoreRequirements(false); this.setIgnoreNodeFilter(false); + this.setIgnoreSubstitutionFilter(false); this.setIgnoreCapabiltyProperties(false); break; case COMPONENT_INSTANCES_PROPERTIES: @@ -153,6 +156,10 @@ public class ComponentParametersView { this.setIgnoreNodeFilterRequirements(false); this.setIgnoreNodeFilter(false); break; + case SUBSTITUTION_FILTER: + this.setIgnoreSubstitutionFilterRequirements(false); + this.setIgnoreSubstitutionFilter(false); + break; case COMPONENT_INSTANCES_INTERFACES: this.setIgnoreComponentInstances(false); this.setIgnoreComponentInstancesInterfaces(false); @@ -216,6 +223,9 @@ public class ComponentParametersView { if (ignoreNodeFilterRequirements){ component.setNodeFilterComponents(null); } + if (ignoreSubstitutionFilterRequirements){ + component.setSubstitutionFilterComponents(null); + } if (ignoreInterfaces && ignoreInterfaceInstances && componentType == ComponentTypeEnum.RESOURCE) { component.setInterfaces(null); @@ -241,6 +251,9 @@ public class ComponentParametersView { if (ignoreNodeFilter){ component.setNodeFilterComponents(null); } + if (ignoreSubstitutionFilter){ + component.setSubstitutionFilterComponents(null); + } if (ignoreDataType) { component.setDataTypes(null); } @@ -255,6 +268,14 @@ public class ComponentParametersView { this.ignoreNodeFilterRequirements = ignoreNodeFilter; } + public boolean isIgnoreSubstitutionFilterRequirements() { + return ignoreSubstitutionFilterRequirements; + } + + public void setIgnoreSubstitutionFilterRequirements(boolean ignoreSubstitutionFilterRequirements) { + this.ignoreSubstitutionFilterRequirements = ignoreSubstitutionFilterRequirements; + } + public void disableAll() { ignoreUsers = true; ignoreGroups = true; @@ -278,7 +299,9 @@ public class ComponentParametersView { ignoreCapabiltyProperties = true; ignoreServicePath = true; ignoreNodeFilterRequirements = true; + ignoreSubstitutionFilterRequirements = true; ignoreNodeFilter = true; + ignoreSubstitutionFilter = true; ignoreDataType = true; } @@ -462,6 +485,14 @@ public class ComponentParametersView { this.ignoreNodeFilter = ignoreNodeFilter; } + public boolean isIgnoreSubstitutionFilter() { + return ignoreSubstitutionFilter; + } + + public void setIgnoreSubstitutionFilter(boolean ignoreSubstitutionFilter) { + this.ignoreSubstitutionFilter = ignoreSubstitutionFilter; + } + public boolean isIgnoreDataType() { return ignoreDataType; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java index a02b07df15..db330e9b19 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/datamodel/TopologyTemplate.java @@ -60,6 +60,7 @@ public class TopologyTemplate extends ToscaElement{ private Map dataTypes; private Map nodeFilterComponents; + private Map substitutionFilterDataDefinitionMap; //Component Instances External References (instanceId -> ExternalRefsMap) //----------------------------------------------------------------------- private Map mapComponentInstancesExternalRefs; @@ -240,6 +241,15 @@ public class TopologyTemplate extends ToscaElement{ this.nodeFilterComponents = nodeFilters; } + public Map getSubstitutionFilterDataDefinitionMap() { + return substitutionFilterDataDefinitionMap; + } + + public void setSubstitutionFilterDataDefinitionMap( + Map substitutionFilterDataDefinitionMap) { + this.substitutionFilterDataDefinitionMap = substitutionFilterDataDefinitionMap; + } + /** * Gets data types. * @return Current data types. diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java index 14ce6be609..9e12e6e67d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/BaseOperation.java @@ -882,7 +882,12 @@ public abstract class BaseOperation { } @SuppressWarnings("unchecked") - private StorageOperationStatus updateOrAddToscaData(GraphVertex toscaElement, EdgeLabelEnum edgeLabel, VertexTypeEnum vertexLabel, List toscaDataList, JsonPresentationFields mapKeyField, boolean isUpdate) { + private StorageOperationStatus updateOrAddToscaData(GraphVertex toscaElement, + EdgeLabelEnum edgeLabel, + VertexTypeEnum vertexLabel, + List toscaDataList, + JsonPresentationFields mapKeyField, + boolean isUpdate) { StorageOperationStatus result = null; GraphVertex toscaDataVertex = null; Map existingToscaDataMap = null; @@ -892,7 +897,9 @@ public abstract class BaseOperation { .getChildVertex(toscaElement, edgeLabel, JsonParseFlagEnum.ParseJson); if (toscaDataVertexRes.isRight() && toscaDataVertexRes.right().value() != JanusGraphOperationStatus.NOT_FOUND) { JanusGraphOperationStatus status = toscaDataVertexRes.right().value(); - CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, FAILED_TO_GET_CHILD_VERTEX_OF_THE_TOSCA_ELEMENT_BY_LABEL_STATUS_IS, toscaElement.getUniqueId(), edgeLabel, status); + CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, + FAILED_TO_GET_CHILD_VERTEX_OF_THE_TOSCA_ELEMENT_BY_LABEL_STATUS_IS, toscaElement.getUniqueId(), + edgeLabel, status); result = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(toscaDataVertexRes.right().value()); } if (result == null) { @@ -1423,14 +1430,6 @@ public abstract class BaseOperation { return status; } -// public StorageOperationStatus updateDataOnGraph(GraphVertex dataVertex) { -// Either updateVertex = janusGraphDao.updateVertex(dataVertex); -// if (updateVertex.isRight()) { -// return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(updateVertex.right().value()); -// } -// return StorageOperationStatus.OK; -// } - protected GroupInstanceDataDefinition buildGroupInstanceDataDefinition(GroupDataDefinition group, ComponentInstanceDataDefinition componentInstance, Map instDeplArtifMap) { String componentInstanceName = componentInstance.getName(); @@ -1449,21 +1448,6 @@ public abstract class BaseOperation { groupInstance.setUniqueId(UniqueIdBuilder.buildResourceInstanceUniuqeId(componentInstance.getUniqueId(), groupUid, groupInstance.getNormalizedName())); groupInstance.setArtifacts(group.getArtifacts()); -// List fixedArtifactsUuid; -// List artifactsUuid = group.getArtifactsUuid(); -// if (instDeplArtifMap != null) { -// fixedArtifactsUuid = new ArrayList<>(); -// artifactsUuid.forEach(u -> { -// Optional findFirst = instDeplArtifMap.values().stream().filter(a -> u.equals(a.getUniqueId())).findFirst(); -// if (findFirst.isPresent()) { -// fixedArtifactsUuid.add(findFirst.get().getArtifactUUID()); -// } else { -// fixedArtifactsUuid.add(u); -// } -// }); -// } else { -// fixedArtifactsUuid = artifactsUuid; -// } groupInstance.setArtifactsUuid(group.getArtifactsUuid()); groupInstance.setProperties(group.getProperties()); convertPropertiesToInstanceProperties(groupInstance.getProperties()); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java index 5f0284a159..69c9f4e59d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeFilterOperation.java @@ -41,7 +41,7 @@ import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; import org.openecomp.sdc.common.jsongraph.util.CommonUtility; import org.openecomp.sdc.common.log.wrappers.Logger; -@org.springframework.stereotype.Component("service-filter-operations") +@org.springframework.stereotype.Component("node-filter-operations") public class NodeFilterOperation extends BaseOperation { private static Logger logger = Logger.getLogger(NodeFilterOperation.class); @@ -82,14 +82,16 @@ public class NodeFilterOperation extends BaseOperation { } - public Either createNodeFilter(String serviceId, - String componentInstanceId) { + public Either createNodeFilter(final String componentId, + final String componentInstanceId) { CINodeFilterDataDefinition nodeFilterDataDefinition = new CINodeFilterDataDefinition(); - return addOrUpdateNodeFilter(false, serviceId, componentInstanceId, nodeFilterDataDefinition); + return addOrUpdateNodeFilter(false, componentId, componentInstanceId, nodeFilterDataDefinition); } - public Either deleteConstraint(String serviceId, - String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition, int propertyIndex) { + public Either deleteConstraint(final String serviceId, + final String componentInstanceId, + final CINodeFilterDataDefinition nodeFilterDataDefinition, + final int propertyIndex) { ListDataDefinition properties = nodeFilterDataDefinition.getProperties(); properties.getListToscaDataDefinition().remove(propertyIndex); @@ -113,9 +115,11 @@ public class NodeFilterOperation extends BaseOperation { return addOrUpdateNodeFilter(true, componentId, componentInstanceId, nodeFilterDataDefinition); } - public Either updateProperties(String serviceId, - String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition, - List requirementNodeFilterPropertyDataDefinition) { + public Either updateProperties( + final String serviceId, final String componentInstanceId, + final CINodeFilterDataDefinition nodeFilterDataDefinition, + final List requirementNodeFilterPropertyDataDefinition) { + ListDataDefinition properties = nodeFilterDataDefinition.getProperties(); properties.getListToscaDataDefinition().clear(); @@ -124,22 +128,24 @@ public class NodeFilterOperation extends BaseOperation { return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition); } - public Either updateNodeFilter(String serviceId, - String componentInstanceId, CINodeFilterDataDefinition ciNodeFilterDataDefinition) { + public Either updateNodeFilter(final String serviceId, + final String componentInstanceId, + final CINodeFilterDataDefinition ciNodeFilterDataDefinition) { return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, ciNodeFilterDataDefinition); } - private Either addOrUpdateNodeFilter(boolean isUpdateAction, - String serviceId, String componentInstanceId, CINodeFilterDataDefinition ciNodeFilterDataDefinition) { + private Either addOrUpdateNodeFilter( + final boolean isUpdateAction, final String componentId, final String componentInstanceId, + final CINodeFilterDataDefinition ciNodeFilterDataDefinition) { StorageOperationStatus statusRes; Either getToscaElementRes; - getToscaElementRes = janusGraphDao.getVertexById(serviceId, JsonParseFlagEnum.NoParse); + getToscaElementRes = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); if (getToscaElementRes.isRight()) { JanusGraphOperationStatus status = getToscaElementRes.right().value(); CommonUtility.addRecordToLog(logger, CommonUtility.LogLevelEnum.DEBUG, - "Failed to get tosca element {} upon adding the properties. Status is {}. ", serviceId, status); + "Failed to get tosca element {} upon adding the properties. Status is {}. ", componentId, status); statusRes = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status); return Either.right(statusRes); } @@ -150,23 +156,22 @@ public class NodeFilterOperation extends BaseOperation { janusGraphDao.rollback(); logger.error( " Failed to perform tosca update for node filter in service {} , component instance {}. status is {}", - serviceId, componentInstanceId, statusRes); + componentId, componentInstanceId, statusRes); return Either.right(statusRes); } janusGraphDao.commit(); return Either.left(ciNodeFilterDataDefinition); - } - - private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex, - List toscaDataList) { + private StorageOperationStatus performUpdateToscaAction(final boolean isUpdate, + final GraphVertex graphVertex, + final List toscaDataList) { if (isUpdate) { return updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.NODE_FILTER_TEMPLATE, - VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID); + VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID); } else { return addToscaDataToToscaElement(graphVertex, EdgeLabelEnum.NODE_FILTER_TEMPLATE, - VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID); + VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID); } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java new file mode 100644 index 0000000000..9007e20998 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/SubstitutionFilterOperation.java @@ -0,0 +1,139 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.model.jsonjanusgraph.operations; + +import com.google.common.collect.ImmutableList; +import fj.data.Either; +import java.util.List; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +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.JsonPresentationFields; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; +import org.openecomp.sdc.common.jsongraph.util.CommonUtility; +import org.openecomp.sdc.common.log.enums.EcompErrorSeverity; +import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; +import org.openecomp.sdc.common.log.wrappers.Logger; + +@org.springframework.stereotype.Component("substitution-filter-operations") +public class SubstitutionFilterOperation extends BaseOperation { + + private static final Logger LOGGER = Logger.getLogger(SubstitutionFilterOperation.class); + + public Either createSubstitutionFilter( + final String componentId, final String componentInstanceId) { + + return addOrUpdateSubstitutionFilter(false, componentId, componentInstanceId, + new SubstitutionFilterDataDefinition()); + } + + public Either deleteConstraint( + final String serviceId, final String componentInstanceId, + final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, final int propertyIndex) { + + final ListDataDefinition properties = + substitutionFilterDataDefinition.getProperties(); + properties.getListToscaDataDefinition().remove(propertyIndex); + substitutionFilterDataDefinition.setProperties(properties); + return addOrUpdateSubstitutionFilter(true, serviceId, componentInstanceId, substitutionFilterDataDefinition); + } + + public Either addNewProperty( + final String componentId, final String componentInstanceId, + final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, + final RequirementSubstitutionFilterPropertyDataDefinition requirementSubstitutionFilterPropertyDataDefinition) { + + ListDataDefinition properties = + substitutionFilterDataDefinition.getProperties(); + if (properties == null) { + properties = new ListDataDefinition<>(); + substitutionFilterDataDefinition.setProperties(properties); + } + properties.getListToscaDataDefinition().add(requirementSubstitutionFilterPropertyDataDefinition); + substitutionFilterDataDefinition.setProperties(properties); + return addOrUpdateSubstitutionFilter(true, componentId, componentInstanceId, substitutionFilterDataDefinition); + } + + public Either updateSubstitutionFilter( + final String serviceId, final String componentInstanceId, + final SubstitutionFilterDataDefinition substitutionFilterDataDefinition, + final List requirementSubstitutionFilterPropertyDataDefinitions) { + + final ListDataDefinition properties = + substitutionFilterDataDefinition.getProperties(); + properties.getListToscaDataDefinition().clear(); + properties.getListToscaDataDefinition().addAll(requirementSubstitutionFilterPropertyDataDefinitions); + substitutionFilterDataDefinition.setProperties(properties); + return addOrUpdateSubstitutionFilter(true, serviceId, componentInstanceId, + substitutionFilterDataDefinition); + } + + private Either addOrUpdateSubstitutionFilter( + final boolean isUpdateAction, final String componentId, final String componentInstanceId, + final SubstitutionFilterDataDefinition substitutionFilterDataDefinition) { + + StorageOperationStatus statusRes; + Either getToscaElementRes; + + getToscaElementRes = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); + if (getToscaElementRes.isRight()) { + final JanusGraphOperationStatus status = getToscaElementRes.right().value(); + CommonUtility.addRecordToLog(LOGGER, CommonUtility.LogLevelEnum.DEBUG, + "Failed to get tosca element {} upon adding the properties. Status is {}. ", componentId, status); + statusRes = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status); + return Either.right(statusRes); + } + final GraphVertex serviceVertex = getToscaElementRes.left().value(); + substitutionFilterDataDefinition.setID(componentInstanceId); + statusRes = performUpdateToscaAction(isUpdateAction, serviceVertex, + ImmutableList.of(substitutionFilterDataDefinition)); + if (!statusRes.equals(StorageOperationStatus.OK)) { + janusGraphDao.rollback(); + LOGGER.error(EcompErrorSeverity.ERROR, EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, + " Failed to perform tosca update for substitution filter in service {} , component instance {}. status is {}", + componentId, componentInstanceId, statusRes); + return Either.right(statusRes); + } + janusGraphDao.commit(); + return Either.left(substitutionFilterDataDefinition); + } + + private StorageOperationStatus performUpdateToscaAction(final boolean isUpdate, + final GraphVertex graphVertex, + final List toscaDataList) { + if (isUpdate) { + return updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE, + VertexTypeEnum.SUBSTITUTION_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID); + } else { + return addToscaDataToToscaElement(graphVertex, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE, + VertexTypeEnum.SUBSTITUTION_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID); + } + } + +} + + + diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java index 3f28d72ef4..cc6cd1d430 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperation.java @@ -31,15 +31,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import java.util.stream.Collectors; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.stream.Collectors; import org.apache.commons.collections.MapUtils; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; @@ -48,8 +39,6 @@ import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty; -import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; @@ -62,13 +51,16 @@ import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapArtifactDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty; import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapGroupsDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapInterfaceDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.MapListCapabilityDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapListRequirementDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; @@ -791,6 +783,14 @@ public class TopologyTemplateOperation extends ToscaElementOperation { } } + if (!componentParametersView.isIgnoreSubstitutionFilter()) { + status = setSubstitutionFilterComponentFromGraph(componentV, toscaElement); + if (status != JanusGraphOperationStatus.OK) { + return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); + + } + } + if (!componentParametersView.isIgnoreInterfaces()) { JanusGraphOperationStatus storageStatus = setInterfacesFromGraph(componentV, toscaElement); if (storageStatus != JanusGraphOperationStatus.OK) { @@ -996,11 +996,11 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return JanusGraphOperationStatus.OK; } - private JanusGraphOperationStatus setNodeFilterComponentFromGraph(GraphVertex componentV, - TopologyTemplate topologyTemplate) { - Either, JanusGraphOperationStatus> result = - getDataFromGraph(componentV, - EdgeLabelEnum.NODE_FILTER_TEMPLATE); + private JanusGraphOperationStatus setNodeFilterComponentFromGraph(final GraphVertex componentV, + final TopologyTemplate topologyTemplate) { + + final Either, JanusGraphOperationStatus> result = + getDataFromGraph(componentV, EdgeLabelEnum.NODE_FILTER_TEMPLATE); if (result.isLeft()) { topologyTemplate.setNodeFilterComponents(result.left().value()); } else { @@ -1011,6 +1011,22 @@ public class TopologyTemplateOperation extends ToscaElementOperation { return JanusGraphOperationStatus.OK; } + private JanusGraphOperationStatus setSubstitutionFilterComponentFromGraph(final GraphVertex componentV, + final TopologyTemplate topologyTemplate) { + + final Either, JanusGraphOperationStatus> result = + getDataFromGraph(componentV, EdgeLabelEnum.SUBSTITUTION_FILTER_TEMPLATE); + if (result.isLeft()) { + topologyTemplate.setSubstitutionFilterDataDefinitionMap(result.left().value()); + } else { + if (result.right().value() != JanusGraphOperationStatus.NOT_FOUND) { + return result.right().value(); + } + } + return JanusGraphOperationStatus.OK; + } + + @Override protected JanusGraphOperationStatus setRequirementsFromGraph(GraphVertex componentV, T toscaElement) { Either, JanusGraphOperationStatus> result = getDataFromGraph(componentV, EdgeLabelEnum.CALCULATED_REQUIREMENTS); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java index ae854254c2..272d664b8e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/utils/ModelConverter.java @@ -71,6 +71,7 @@ import org.openecomp.sdc.be.datatypes.elements.ProductMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RelationshipInstDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.CreatedFrom; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; @@ -217,6 +218,9 @@ public class ModelConverter { convertDataTypes(topologyTemplate, service); convertNodeFiltersComponents(topologyTemplate, service); + + convertSubstitutionFiltersComponents(topologyTemplate, service); + setCapabilitiesToComponent(topologyTemplate, service); setRequirementsToComponent(topologyTemplate, service); return service; @@ -879,17 +883,33 @@ public class ModelConverter { component.setDeploymentArtifacts(copy); } - private static void convertNodeFiltersComponents(TopologyTemplate topologyTemplate, Component component) { - Map filters = topologyTemplate.getNodeFilterComponents(); - Map copy; - if (filters != null) { - copy = filters.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new CINodeFilterDataDefinition(e.getValue()))); + private static void convertNodeFiltersComponents(final TopologyTemplate topologyTemplate, + final Component component) { + final Map filters = topologyTemplate.getNodeFilterComponents(); + final Map copy; + if (MapUtils.isNotEmpty(filters)) { + copy = filters.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> new CINodeFilterDataDefinition(e.getValue()))); } else { copy = new HashMap<>(); } component.setNodeFilterComponents(copy); } + private static void convertSubstitutionFiltersComponents(final TopologyTemplate topologyTemplate, + final Component component) { + final Map filters = topologyTemplate + .getSubstitutionFilterDataDefinitionMap(); + final Map copy; + if (MapUtils.isNotEmpty(filters)) { + copy = filters.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> new SubstitutionFilterDataDefinition(e.getValue()))); + } else { + copy = new HashMap<>(); + } + component.setSubstitutionFilterComponents(copy); + } + private static void convertServiceApiArtifacts(TopologyTemplate topologyTemplate, Service service) { Map serviceApiArtifacts = topologyTemplate.getServiceApiArtifacts(); Map copy; @@ -1328,6 +1348,8 @@ public class ModelConverter { List componentInstances = new ArrayList<>(); ComponentInstance currComponentInstance; Map nodeFilterComponents = topologyTemplate.getNodeFilterComponents(); + Map substitutionFilterDataDefinitionMap = topologyTemplate + .getSubstitutionFilterDataDefinitionMap(); for (Map.Entry entry : topologyTemplate.getComponentInstances().entrySet()) { String key = entry.getKey(); @@ -1337,9 +1359,12 @@ public class ModelConverter { currComponentInstance.setGroupInstances(groupInstances); } setComponentInstanceSource(currComponentInstance, component); - if(nodeFilterComponents != null && nodeFilterComponents.containsKey(key)){ + if(MapUtils.isNotEmpty(nodeFilterComponents) && nodeFilterComponents.containsKey(key)){ currComponentInstance.setNodeFilter(nodeFilterComponents.get(key)); } + if(MapUtils.isNotEmpty(substitutionFilterDataDefinitionMap) && substitutionFilterDataDefinitionMap.containsKey(key)) { + currComponentInstance.setSubstitutionFilter(substitutionFilterDataDefinitionMap.get(key)); + } if(topologyTemplate.getInstProperties() != null && topologyTemplate.getInstProperties().containsKey(key) && topologyTemplate.getInstProperties().get(key) != null ){ List instanceProps = topologyTemplate.getInstProperties().get(key).getMapToscaDataDefinition().entrySet().stream().map(e -> new PropertyDefinition(e.getValue())).collect(Collectors.toList()); currComponentInstance.setProperties(instanceProps); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java index 38d5a90742..f03a5e724f 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java @@ -26,6 +26,7 @@ import java.util.Map; import lombok.Getter; import lombok.Setter; import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.model.AdditionalInformationDefinition; import org.openecomp.sdc.be.model.ArtifactDefinition; @@ -71,8 +72,10 @@ public class UiComponentDataTransfer { private Map interfaces; private Map nodeFilter; + private Map substitutionFilter; private Map nodeFilterforNode; + private Map substitutionFilterForTopologyTemplate; private List properties; private Map> componentInstancesInterfaces; -- cgit 1.2.3-korg