From aae70f4bfb7126a6fc562604bf48fcd01d6d7af8 Mon Sep 17 00:00:00 2001 From: vasraz Date: Tue, 14 Sep 2021 16:40:39 +0100 Subject: Allow multiple base types for a service Change-Id: I2e37818a432295a6e9f795f38d730d60f66eef78 Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3727 --- .../java/org/openecomp/sdc/be/model/Service.java | 9 ++- .../be/model/operations/impl/ElementOperation.java | 72 ++++++++++++---------- 2 files changed, 45 insertions(+), 36 deletions(-) (limited to 'catalog-model/src/main') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java index 9728e8ccb8..a06f737c83 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java @@ -19,9 +19,11 @@ */ package org.openecomp.sdc.be.model; +import static java.util.Optional.ofNullable; + import java.util.HashMap; +import java.util.List; import java.util.Map; -import java.util.Optional; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -165,8 +167,9 @@ public class Service extends Component { } private String fetchToscaNameFromConfigBasedOnService(final String serviceCategory) { - return Optional.ofNullable(ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes()) - .map(serviceNames -> serviceNames.get(serviceCategory)).orElse(null); + final Map> serviceNodeTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes(); + final List stringList = ofNullable(serviceNodeTypes).map(serviceNames -> serviceNames.get(serviceCategory)).orElse(null); + return stringList != null ? stringList.get(0) : null; } @Override diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java index 4c97b45830..b98f8d9dea 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ElementOperation.java @@ -40,10 +40,10 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; import org.openecomp.sdc.be.dao.graph.datatype.GraphNode; import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; +import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; 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; @@ -80,10 +80,12 @@ public class ElementOperation implements IElementOperation { private static final String COULDN_T_FETCH_janusGraph_GRAPH = "Couldn't fetch janusgraph graph"; private static final String UNKNOWN_CATEGORY_TYPE = "Unknown category type {}"; private static final Logger log = Logger.getLogger(ElementOperation.class.getName()); + private static final String PROBLEM_WHILE_CREATING_CATEGORY_REASON = "Problem while creating category, reason {}"; private JanusGraphGenericDao janusGraphGenericDao; private HealingJanusGraphDao janusGraphDao; - public ElementOperation(@Qualifier("janusgraph-generic-dao") JanusGraphGenericDao janusGraphGenericDao, @Qualifier("janusgraph-dao") HealingJanusGraphDao janusGraphDao) { + public ElementOperation(@Qualifier("janusgraph-generic-dao") JanusGraphGenericDao janusGraphGenericDao, + @Qualifier("janusgraph-dao") HealingJanusGraphDao janusGraphDao) { super(); this.janusGraphGenericDao = janusGraphGenericDao; this.janusGraphDao = janusGraphDao; @@ -143,7 +145,7 @@ public class ElementOperation implements IElementOperation { if (createNode.isRight()) { JanusGraphOperationStatus value = createNode.right().value(); ActionStatus actionStatus = ActionStatus.GENERAL_ERROR; - log.debug("Problem while creating category, reason {}", value); + log.debug(PROBLEM_WHILE_CREATING_CATEGORY_REASON, value); if (value == JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION) { actionStatus = ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS; } @@ -179,7 +181,7 @@ public class ElementOperation implements IElementOperation { if (updatedNode.isRight()) { JanusGraphOperationStatus value = updatedNode.right().value(); ActionStatus actionStatus = ActionStatus.GENERAL_ERROR; - log.debug("Problem while creating category, reason {}", value); + log.debug(PROBLEM_WHILE_CREATING_CATEGORY_REASON, value); result = Either.right(actionStatus); return result; } @@ -228,7 +230,7 @@ public class ElementOperation implements IElementOperation { .createNode(subCategoryData, SubCategoryData.class); if (subCategoryNode.isRight()) { JanusGraphOperationStatus janusGraphOperationStatus = subCategoryNode.right().value(); - log.debug("Problem while creating category, reason {}", janusGraphOperationStatus); + log.debug(PROBLEM_WHILE_CREATING_CATEGORY_REASON, janusGraphOperationStatus); if (janusGraphOperationStatus == JanusGraphOperationStatus.JANUSGRAPH_SCHEMA_VIOLATION) { actionStatus = ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY; } @@ -380,50 +382,54 @@ public class ElementOperation implements IElementOperation { } @Override - public List getBaseTypes(final String categoryName, final String modelName){ + public List getBaseTypes(final String categoryName, final String modelName) { final ArrayList baseTypes = new ArrayList<>(); - final Map categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes(); - final String categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName); + final Map> categoriesSpecificBaseTypes = ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes(); + final List categorySpecificBaseType = categoriesSpecificBaseTypes == null ? null : categoriesSpecificBaseTypes.get(categoryName); final String generalBaseType = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes().get("Service"); - final String baseToscaResourceName = categorySpecificBaseType == null? generalBaseType : categorySpecificBaseType; + final List baseToscaResourceNames = categorySpecificBaseType == null ? List.of(generalBaseType) : categorySpecificBaseType; - final Map props = new EnumMap<>(GraphPropertyEnum.class); - props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName); - props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); - final Either, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao + baseToscaResourceNames.forEach(baseToscaResourceName -> { + final Map props = new EnumMap<>(GraphPropertyEnum.class); + props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName); + props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + final Either, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao .getByCriteria(VertexTypeEnum.NODE_TYPE, props, null, JsonParseFlagEnum.ParseAll, modelName); - - if (baseTypeVertex.isLeft()) { - BaseType baseType = new BaseType(baseToscaResourceName); - baseTypes.add(baseType); - - final Map> typesDerivedFromBaseType = new LinkedHashMap<>(); - baseTypeVertex.left().value().forEach(v -> { - baseType.addVersion((String)v.getMetadataProperty(GraphPropertyEnum.VERSION)); - addTypesDerivedFromVertex(typesDerivedFromBaseType, v); - }); - - typesDerivedFromBaseType.forEach((k,v) -> baseTypes.add(new BaseType(k, v))); - } + + if (baseTypeVertex.isLeft()) { + BaseType baseType = new BaseType(baseToscaResourceName); + baseTypes.add(baseType); + + final Map> typesDerivedFromBaseType = new LinkedHashMap<>(); + baseTypeVertex.left().value().forEach(v -> { + baseType.addVersion((String) v.getMetadataProperty(GraphPropertyEnum.VERSION)); + addTypesDerivedFromVertex(typesDerivedFromBaseType, v); + }); + + typesDerivedFromBaseType.forEach((k, v) -> baseTypes.add(new BaseType(k, v))); + } + }); return baseTypes; } private Map> addTypesDerivedFromVertex(final Map> types, final GraphVertex vertex) { final Either, JanusGraphOperationStatus> derivedFromVertex = - janusGraphDao.getParentVertices(vertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll); + janusGraphDao.getParentVertices(vertex, EdgeLabelEnum.DERIVED_FROM, JsonParseFlagEnum.ParseAll); if (derivedFromVertex.isLeft()) { - derivedFromVertex.left().value().stream().filter(v -> v.getMetadataProperty(GraphPropertyEnum.STATE).equals(LifecycleStateEnum.CERTIFIED.name())) + derivedFromVertex.left().value().stream() + .filter(v -> v.getMetadataProperty(GraphPropertyEnum.STATE).equals(LifecycleStateEnum.CERTIFIED.name())) .forEach(v -> { - addBaseTypeVersion(types, (String) v.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME), (String) v.getMetadataProperty(GraphPropertyEnum.VERSION)); - addTypesDerivedFromVertex(types, v); + addBaseTypeVersion(types, (String) v.getMetadataProperty(GraphPropertyEnum.TOSCA_RESOURCE_NAME), + (String) v.getMetadataProperty(GraphPropertyEnum.VERSION)); + addTypesDerivedFromVertex(types, v); }); } return types; } private void addBaseTypeVersion(final Map> baseTypes, final String baseTypeToscaResourceName, final String baseTypeVersion) { - List versions = baseTypes.get(baseTypeToscaResourceName) == null ? new ArrayList<>(): baseTypes.get(baseTypeToscaResourceName); + List versions = baseTypes.get(baseTypeToscaResourceName) == null ? new ArrayList<>() : baseTypes.get(baseTypeToscaResourceName); versions.add(baseTypeVersion); baseTypes.put(baseTypeToscaResourceName, versions); } @@ -619,7 +625,7 @@ public class ElementOperation implements IElementOperation { } Vertex artifactV = iterator.next(); artifactV.remove(); - ; + SubCategoryDefinition deleted = new SubCategoryDefinition(subCategoryDataEither.left().value().getSubCategoryDataDefinition()); result = Either.left(deleted); return result; @@ -664,7 +670,7 @@ public class ElementOperation implements IElementOperation { } Vertex artifactV = iterator.next(); artifactV.remove(); - ; + GroupingDefinition deleted = new GroupingDefinition(groupingDataEither.left().value().getGroupingDataDefinition()); result = Either.left(deleted); return result; -- cgit 1.2.3-korg