From df1e300dad94d65a88d2012df9096961619d8272 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 30 Jul 2021 13:06:11 +0100 Subject: Update base types based on model Also made some changes where model was not being considered Signed-off-by: MichaelMorris Issue-ID: SDC-3666 Change-Id: I450c5261239cf4104c494abe6711cb61368a2b4a --- .../operations/NodeTypeOperation.java | 2 +- .../operations/ToscaOperationFacade.java | 40 ++++++++++------------ .../be/model/operations/api/IElementOperation.java | 2 +- .../be/model/operations/impl/ElementOperation.java | 6 ++-- 4 files changed, 24 insertions(+), 26 deletions(-) (limited to 'catalog-model/src/main/java/org') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java index b74b290295..76d8e71c69 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTypeOperation.java @@ -934,7 +934,7 @@ public class NodeTypeOperation extends ToscaElementOperation { Map propsHasNot = new HashMap<>(); propsHasNot.put(GraphPropertyEnum.IS_DELETED, true); Either, JanusGraphOperationStatus> byCriteria = janusGraphDao - .getByCriteria(VertexTypeEnum.NODE_TYPE, props, propsHasNot, JsonParseFlagEnum.NoParse); + .getByCriteria(VertexTypeEnum.NODE_TYPE, props, propsHasNot, JsonParseFlagEnum.NoParse, nodeType.getModel()); if (byCriteria.isRight()) { log.debug("Failed to fetch derived by props {} error {}", props, byCriteria.right().value()); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(byCriteria.right().value())); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index faedba5363..6466683db6 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -364,10 +364,9 @@ public class ToscaOperationFacade { final Map propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesToMatch.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, nodeName); propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - propertiesToMatch.put(GraphPropertyEnum.MODEL, model); propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); final Either, JanusGraphOperationStatus> highestResources = janusGraphDao - .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag); + .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag, model); if (highestResources.isRight()) { final JanusGraphOperationStatus status = highestResources.right().value(); log.debug("failed to find resource with name {}. status={} ", nodeName, status); @@ -388,8 +387,8 @@ public class ToscaOperationFacade { return getToscaElementByOperation(highestResource, filter); } - public Either getLatestByToscaResourceName(String toscaResourceName) { - return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, null); + public Either getLatestByToscaResourceName(String toscaResourceName, String modelName) { + return getLatestByName(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName, modelName); } public Either getFullLatestComponentByToscaResourceName(String toscaResourceName) { @@ -459,7 +458,7 @@ public class ToscaOperationFacade { props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); Map> predicateCriteria = getVendorVersionPredicate(vendorRelease); Either, JanusGraphOperationStatus> getLatestRes = janusGraphDao - .getByCriteria(vertexType, props, null, predicateCriteria, parseFlag); + .getByCriteria(vertexType, props, null, predicateCriteria, parseFlag, null); if (getLatestRes.isRight() || CollectionUtils.isEmpty(getLatestRes.left().value())) { getLatestRes = janusGraphDao.getByCriteria(vertexType, props, parseFlag); } @@ -486,7 +485,7 @@ public class ToscaOperationFacade { }); } - public Either getByToscaResourceNameAndVersion(final String toscaResourceName, final String version) { + public Either getByToscaResourceNameAndVersion(final String toscaResourceName, final String version, final String model) { Either result; Map hasProperties = new EnumMap<>(GraphPropertyEnum.class); @@ -497,7 +496,7 @@ public class ToscaOperationFacade { hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true); Either, JanusGraphOperationStatus> getResourceRes = janusGraphDao - .getByCriteria(VertexTypeEnum.NODE_TYPE, hasProperties, hasNotProperties, JsonParseFlagEnum.ParseAll); + .getByCriteria(VertexTypeEnum.NODE_TYPE, hasProperties, hasNotProperties, JsonParseFlagEnum.ParseAll, model); if (getResourceRes.isRight()) { JanusGraphOperationStatus status = getResourceRes.right().value(); log.debug("failed to find resource with toscaResourceName {}, version {}. Status is {} ", toscaResourceName, version, status); @@ -807,10 +806,9 @@ public class ToscaOperationFacade { Map propertiesNotToMatch = new EnumMap<>(GraphPropertyEnum.class); propertiesToMatch.put(property, nodeName); propertiesToMatch.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); - propertiesToMatch.put(GraphPropertyEnum.MODEL, model); propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); Either, JanusGraphOperationStatus> highestResources = janusGraphDao - .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag); + .getByCriteria(null, propertiesToMatch, propertiesNotToMatch, parseFlag, model); if (highestResources.isRight()) { JanusGraphOperationStatus status = highestResources.right().value(); log.debug("failed to find resource with name {}. status={} ", nodeName, status); @@ -905,7 +903,7 @@ public class ToscaOperationFacade { public Either getComponentByNameAndVendorRelease(final ComponentTypeEnum componentType, final String name, final String vendorRelease, - final JsonParseFlagEnum parseFlag) { + final JsonParseFlagEnum parseFlag, final String modelName) { Map hasProperties = new EnumMap<>(GraphPropertyEnum.class); Map hasNotProperties = new EnumMap<>(GraphPropertyEnum.class); hasProperties.put(GraphPropertyEnum.NAME, name); @@ -915,7 +913,7 @@ public class ToscaOperationFacade { } Map> predicateCriteria = getVendorVersionPredicate(vendorRelease); Either, JanusGraphOperationStatus> getResourceRes = janusGraphDao.getByCriteria(null, hasProperties, hasNotProperties, - predicateCriteria, parseFlag); + predicateCriteria, parseFlag, modelName); if (getResourceRes.isRight()) { JanusGraphOperationStatus status = getResourceRes.right().value(); log.debug("failed to find resource with name {}, version {}. Status is {} ", name, predicateCriteria, status); @@ -1947,7 +1945,7 @@ public class ToscaOperationFacade { Map hasNotProps = new EnumMap<>(GraphPropertyEnum.class); fillPropsMap(hasProps, hasNotProps, internalComponentType, componentTypeEnum, isAbstract, vertexType, modelName); Either, JanusGraphOperationStatus> getRes = janusGraphDao - .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata); + .getByCriteria(vertexType, hasProps, hasNotProps, JsonParseFlagEnum.ParseMetadata, modelName); if (getRes.isRight() && !JanusGraphOperationStatus.NOT_FOUND.equals(getRes.right().value())) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value())); } @@ -1969,7 +1967,7 @@ public class ToscaOperationFacade { ComponentParametersView params = new ComponentParametersView(true); params.setIgnoreAllVersions(false); if (getRes.isLeft()) { - for (GraphVertex vertexComponent : getVerticesForModel(modelName, getRes.left().value())) { + for (GraphVertex vertexComponent : getRes.left().value()) { Either componentRes = topologyTemplateOperation .getLightComponent(vertexComponent, componentTypeEnum, params); if (componentRes.isRight()) { @@ -2129,13 +2127,13 @@ public class ToscaOperationFacade { final ComponentTypeEnum componentType) { final String normalizedName = ValidationUtils.normaliseComponentName(resourceName); final Either, JanusGraphOperationStatus> vertexEither = janusGraphDao - .getByCriteria(getVertexTypeEnum(resourceType), propertiesToMatch(normalizedName, componentType), null, null, JsonParseFlagEnum.NoParse); + .getByCriteria(getVertexTypeEnum(resourceType), propertiesToMatch(normalizedName, componentType), null, null, JsonParseFlagEnum.NoParse, modelName); if (vertexEither.isRight() && vertexEither.right().value() != JanusGraphOperationStatus.NOT_FOUND) { log.debug("failed to get vertex from graph with property normalizedName: {} and model: {}", normalizedName, modelName); return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(vertexEither.right().value())); } return Either.left(CollectionUtils.isEmpty(vertexEither.isLeft() ? vertexEither.left().value().stream() - .filter(graphVertex -> graphVertex.getMetadataProperty(GraphPropertyEnum.NAME).equals(modelName)).collect(Collectors.toList()) : null)); + .collect(Collectors.toList()) : null)); } private VertexTypeEnum getVertexTypeEnum(final ResourceTypeEnum resourceType) { @@ -2359,7 +2357,7 @@ public class ToscaOperationFacade { } public Either getLatestByNameAndVersion(String name, String version, - JsonParseFlagEnum parseFlag) { + JsonParseFlagEnum parseFlag, String model) { Either result; Map hasProperties = new EnumMap<>(GraphPropertyEnum.class); Map hasNotProperties = new EnumMap<>(GraphPropertyEnum.class); @@ -2368,7 +2366,7 @@ public class ToscaOperationFacade { hasProperties.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); hasNotProperties.put(GraphPropertyEnum.IS_DELETED, true); Either, JanusGraphOperationStatus> getResourceRes = janusGraphDao - .getByCriteria(null, hasProperties, hasNotProperties, parseFlag); + .getByCriteria(null, hasProperties, hasNotProperties, parseFlag, model); if (getResourceRes.isRight()) { JanusGraphOperationStatus status = getResourceRes.right().value(); log.debug("failed to find resource with name {}, version {}. Status is {} ", name, version, status); @@ -2471,10 +2469,10 @@ public class ToscaOperationFacade { return null; } - public Either validateToscaResourceNameExtends(String templateNameCurrent, String templateNameExtends) { + public Either validateToscaResourceNameExtends(String templateNameCurrent, String templateNameExtends, String model) { String currentTemplateNameChecked = templateNameExtends; while (currentTemplateNameChecked != null && !currentTemplateNameChecked.equalsIgnoreCase(templateNameCurrent)) { - Either latestByToscaResourceName = getLatestByToscaResourceName(currentTemplateNameChecked); + Either latestByToscaResourceName = getLatestByToscaResourceName(currentTemplateNameChecked, model); if (latestByToscaResourceName.isRight()) { return latestByToscaResourceName.right().value() == StorageOperationStatus.NOT_FOUND ? Either.left(false) : Either.right(latestByToscaResourceName.right().value()); @@ -2593,7 +2591,7 @@ public class ToscaOperationFacade { Map propertiesNotToMatch, String modelName) { Either, JanusGraphOperationStatus> getRes = janusGraphDao - .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll); + .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll, modelName); if (getRes.isRight()) { if (getRes.right().value() != JanusGraphOperationStatus.NOT_FOUND) { CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, @@ -2602,7 +2600,7 @@ public class ToscaOperationFacade { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getRes.right().value())); } } else { - for (final GraphVertex vertex : getVerticesForModel(modelName, getRes.left().value())) { + for (final GraphVertex vertex : getRes.left().value()) { Either getServiceRes = topologyTemplateOperation .getLightComponent(vertex, ComponentTypeEnum.SERVICE, new ComponentParametersView(true)); if (getServiceRes.isRight()) { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java index aac14625c5..7457ed727e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IElementOperation.java @@ -86,7 +86,7 @@ public interface IElementOperation { Either, ActionStatus> getAllCategories(NodeTypeEnum nodeType, boolean inTransaction); - List getBaseTypes(String categoryName); + List getBaseTypes(String categoryName, String modelName); Either getCategory(NodeTypeEnum nodeType, String categoryId); 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 054788a519..42f1b03028 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 @@ -380,7 +380,7 @@ public class ElementOperation implements IElementOperation { } @Override - public List getBaseTypes(final String categoryName){ + 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); @@ -391,8 +391,8 @@ public class ElementOperation implements IElementOperation { props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, baseToscaResourceName); props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); final Either, JanusGraphOperationStatus> baseTypeVertex = janusGraphDao - .getByCriteria(VertexTypeEnum.NODE_TYPE, props, JsonParseFlagEnum.ParseAll); - + .getByCriteria(VertexTypeEnum.NODE_TYPE, props, null, JsonParseFlagEnum.ParseAll, modelName); + if (baseTypeVertex.isLeft()) { BaseType baseType = new BaseType(baseToscaResourceName); baseTypes.add(baseType); -- cgit 1.2.3-korg