X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-model%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fmodel%2Fjsonjanusgraph%2Foperations%2FToscaElementOperation.java;h=24e1e910d3486baf9030d6fadee9d2b94fe858ae;hb=438650c3a958c9176db3720204ec1ff9af94fc3a;hp=bfb6cae3aa802a24c4466cfef7d8f681f5baeae4;hpb=4f4f7fb796475bb4a332e798c80438b33ce7712a;p=sdc.git diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java index bfb6cae3aa..24e1e910d3 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java @@ -39,6 +39,7 @@ import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; @@ -150,6 +151,17 @@ public abstract class ToscaElementOperation extends BaseOperation { return Either.left(vertexG); } + protected GraphVertex getHighestVersionFrom(GraphVertex v) { + Either childVertexE = janusGraphDao + .getChildVertex(v, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse); + GraphVertex highestVersionVertex = v; + while (childVertexE.isLeft()) { + highestVersionVertex = childVertexE.left().value(); + childVertexE = janusGraphDao.getChildVertex(highestVersionVertex, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse); + } + return highestVersionVertex; + } + public Either getToscaElement(String uniqueId) { return getToscaElement(uniqueId, new ComponentParametersView()); } @@ -206,7 +218,10 @@ public abstract class ToscaElementOperation extends BaseOperation { } } if (result == null) { - result = createModelEdge(previousToscaElement, nextToscaElement, user, createdToscaElementVertex); + result = + VertexTypeEnum.TOPOLOGY_TEMPLATE.equals(previousToscaElement.getLabel()) + ? createModelEdge(previousToscaElement, nextToscaElement, user, createdToscaElementVertex, EdgeLabelEnum.MODEL) + : createModelEdge(previousToscaElement, nextToscaElement, user, createdToscaElementVertex, EdgeLabelEnum.MODEL_ELEMENT); } if (result == null) { status = janusGraphDao.createEdge(user.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.LAST_MODIFIER, new HashMap<>()); @@ -265,24 +280,28 @@ public abstract class ToscaElementOperation extends BaseOperation { /** * Creates the MODEL in case it exits on the previous version - * @param previousToscaElement previous element version - * @param nextToscaElement latest element version - * @param user user + * + * @param previousToscaElement previous element version + * @param nextToscaElement latest element version + * @param user user * @param createdToscaElementVertex created tosca element + * @param edgeLabelEnum * @return */ private Either createModelEdge(final GraphVertex previousToscaElement, final GraphVertex nextToscaElement, GraphVertex user, - final GraphVertex createdToscaElementVertex) { + final GraphVertex createdToscaElementVertex, + final EdgeLabelEnum edgeLabelEnum) { Either result = null; final Either modelElementVertexResponse = janusGraphDao - .getParentVertex(previousToscaElement, EdgeLabelEnum.MODEL, JsonParseFlagEnum.NoParse); + .getParentVertex(previousToscaElement, edgeLabelEnum, JsonParseFlagEnum.NoParse); if (modelElementVertexResponse.isLeft()) { final JanusGraphOperationStatus status = janusGraphDao - .createEdge(nextToscaElement.getVertex(), createdToscaElementVertex.getVertex(), EdgeLabelEnum.MODEL, new HashMap<>()); + .createEdge(modelElementVertexResponse.left().value().getVertex(), createdToscaElementVertex.getVertex(), edgeLabelEnum, + new HashMap<>()); if (JanusGraphOperationStatus.OK != status) { CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, - FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, EdgeLabelEnum.MODEL, + FAILED_TO_CREATE_EDGE_WITH_LABEL_FROM_USER_VERTEX_TO_TOSCA_ELEMENT_VERTEX_ON_GRAPH_STATUS_IS, edgeLabelEnum, user.getUniqueId(), nextToscaElement.getMetadataProperty(GraphPropertyEnum.NORMALIZED_NAME), status); result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status)); } @@ -457,10 +476,11 @@ public abstract class ToscaElementOperation extends BaseOperation { protected StorageOperationStatus associateComponentToModel(final GraphVertex nodeTypeVertex, final ToscaElement nodeType, final EdgeLabelEnum edgeLabelEnum) { - if (nodeType.getMetadataValue(JsonPresentationFields.MODEL) == null) { + Object metadataValue = nodeType.getMetadataValue(JsonPresentationFields.MODEL); + if (metadataValue == null || StringUtils.isEmpty((String) metadataValue)) { return StorageOperationStatus.OK; } - final String model = ((String) nodeType.getMetadataValue(JsonPresentationFields.MODEL)); + final String model = ((String) metadataValue); final JanusGraphOperationStatus createEdge = janusGraphDao.createEdge(getModelVertex(model), nodeTypeVertex, edgeLabelEnum, new HashMap<>()); if (createEdge != JanusGraphOperationStatus.OK) { log.trace("Failed to associate resource {} to model {}", nodeType.getUniqueId(), model); @@ -1004,8 +1024,7 @@ public abstract class ToscaElementOperation extends BaseOperation { protected JanusGraphOperationStatus setResourceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) { List categories = new ArrayList<>(); SubCategoryDefinition subcategory; - Either childVertex = janusGraphDao - .getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse); + Either childVertex = janusGraphDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY); if (childVertex.isRight()) { log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(), childVertex.right().value()); @@ -1024,8 +1043,7 @@ public abstract class ToscaElementOperation extends BaseOperation { .fromJson((String) subCategoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(), listTypeSubcat) : Collections.emptyList(); subcategory.setMetadataKeys(metadataKeys); - Either parentVertex = janusGraphDao - .getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse); + Either parentVertex = janusGraphDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY); Vertex categoryV = parentVertex.left().value(); String categoryNormalizedName = (String) categoryV.property(GraphPropertyEnum.NORMALIZED_NAME.getProperty()).value(); catalogComponent.setCategoryNormalizedName(categoryNormalizedName); @@ -1041,8 +1059,7 @@ public abstract class ToscaElementOperation extends BaseOperation { protected JanusGraphOperationStatus setServiceCategoryFromGraphV(Vertex vertex, CatalogComponent catalogComponent) { List categories = new ArrayList<>(); - Either childVertex = janusGraphDao - .getChildVertex(vertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.NoParse); + Either childVertex = janusGraphDao.getChildVertex(vertex, EdgeLabelEnum.CATEGORY); if (childVertex.isRight()) { log.debug(FAILED_TO_FETCH_FOR_TOSCA_ELEMENT_WITH_ID_ERROR, EdgeLabelEnum.CATEGORY, catalogComponent.getUniqueId(), childVertex.right().value()); @@ -1054,6 +1071,9 @@ public abstract class ToscaElementOperation extends BaseOperation { CategoryDefinition category = new CategoryDefinition(); category.setUniqueId((String) categoryV.property(GraphPropertyEnum.UNIQUE_ID.getProperty()).value()); category.setNormalizedName(categoryNormalizedName); + category.setModels(categoryV.property(GraphPropertyEnum.MODEL.getProperty()).isPresent() ? getGson() + .fromJson((String) categoryV.property(GraphPropertyEnum.MODEL.getProperty()).value(), new TypeToken>() { + }.getType()) : Collections.emptyList()); category.setName((String) categoryV.property(GraphPropertyEnum.NAME.getProperty()).value()); category.setUseServiceSubstitutionForNestedServices( (Boolean) categoryV.property(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES.getProperty()).orElse(false)); @@ -1062,6 +1082,10 @@ public abstract class ToscaElementOperation extends BaseOperation { List metadataKeys = categoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).isPresent() ? getGson() .fromJson((String) categoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(), listTypeCat) : Collections.emptyList(); category.setMetadataKeys(metadataKeys); + VertexProperty property = categoryV.property(GraphPropertyEnum.NOT_APPLICABLE_METADATA_KEYS.getProperty()); + category.setNotApplicableMetadataKeys( + property.isPresent() ? getGson().fromJson((String) property.value(), new TypeToken>() { + }.getType()) : Collections.emptyList()); categories.add(category); catalogComponent.setCategories(categories); return JanusGraphOperationStatus.OK; @@ -1223,9 +1247,13 @@ public abstract class ToscaElementOperation extends BaseOperation { } private void generateNewToscaFileName(String componentType, String componentName, ArtifactDataDefinition artifactInfo) { - Map getConfig = (Map) ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts() - .entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel())).findAny().get().getValue(); - artifactInfo.setArtifactName(componentType + "-" + componentName + getConfig.get("artifactName")); + Optional> oConfig = ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts() + .entrySet().stream().filter(p -> p.getKey().equalsIgnoreCase(artifactInfo.getArtifactLabel())).findAny(); + if (oConfig.isPresent()) { + artifactInfo.setArtifactName(componentType + "-" + componentName + ((Map) oConfig.get().getValue()).get("artifactName")); + } else { + artifactInfo.setArtifactName(componentType + "-" + componentName); + } } protected StorageOperationStatus validateResourceCategory(T toscaElementToUpdate, GraphVertex elementV) { @@ -1313,7 +1341,7 @@ public abstract class ToscaElementOperation extends BaseOperation { StopWatch stopWatch = new StopWatch(); stopWatch.start(); Map existInCatalog = new HashMap<>(); - Either, JanusGraphOperationStatus> verticesEither = janusGraphDao.getCatalogOrArchiveVerticies(isCatalog); + Either, JanusGraphOperationStatus> verticesEither = janusGraphDao.getCatalogOrArchiveVertices(isCatalog); if (verticesEither.isRight()) { return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(verticesEither.right().value())); } @@ -1336,6 +1364,7 @@ public abstract class ToscaElementOperation extends BaseOperation { if (isAddToCatalog(excludeTypes, metadatObj) && (existInCatalog.get(uniqueId) == null && (isDeleted == null || !isDeleted.booleanValue()))) { CatalogComponent catalogComponent = new CatalogComponent(); catalogComponent.setUniqueId(uniqueId); + catalogComponent.setModel((String) metadatObj.get(JsonPresentationFields.MODEL.getPresentation())); catalogComponent .setComponentType(ComponentTypeEnum.valueOf((String) metadatObj.get(JsonPresentationFields.COMPONENT_TYPE.getPresentation()))); catalogComponent.setVersion((String) metadatObj.get(JsonPresentationFields.VERSION.getPresentation())); @@ -1346,6 +1375,7 @@ public abstract class ToscaElementOperation extends BaseOperation { catalogComponent.setLastUpdateDate((lastUpdateDate != null ? (Long) lastUpdateDate : 0L)); catalogComponent.setDistributionStatus((String) metadatObj.get(JsonPresentationFields.DISTRIBUTION_STATUS.getPresentation())); catalogComponent.setDescription((String) metadatObj.get(JsonPresentationFields.DESCRIPTION.getPresentation())); + catalogComponent.setTenant((String) metadatObj.get(JsonPresentationFields.TENANT.getPresentation())); catalogComponent.setSystemName((String) metadatObj.get(JsonPresentationFields.SYSTEM_NAME.getPresentation())); catalogComponent.setUuid((String) metadatObj.get(JsonPresentationFields.UUID.getPresentation())); catalogComponent.setInvariantUUID((String) metadatObj.get(JsonPresentationFields.INVARIANT_UUID.getPresentation())); @@ -1387,7 +1417,7 @@ public abstract class ToscaElementOperation extends BaseOperation { return isAddToCatalog; } - public Either, JanusGraphOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType, + private Either, JanusGraphOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType, List excludeTypes, JsonParseFlagEnum parseFlag) { Map propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class); @@ -1404,7 +1434,7 @@ public abstract class ToscaElementOperation extends BaseOperation { } // highest + (certified && !highest) - public Either, JanusGraphOperationStatus> getListOfHighestAndAllCertifiedComponents(ComponentTypeEnum componentType, + private Either, JanusGraphOperationStatus> getListOfHighestAndAllCertifiedComponents(ComponentTypeEnum componentType, List excludeTypes) { long startFetchAllStates = System.currentTimeMillis(); Either, JanusGraphOperationStatus> highestNodes = getListOfHighestComponents(componentType, excludeTypes,