From 8cc03e2c78639be5500ab50f3ebaaf7d64404775 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Fri, 5 Feb 2021 16:18:52 +0000 Subject: Update node and data types for SOL001 3.3.1 + CNF enhancements Types in 2.7.1 folder are types valid for v3.3.1 that have not changed from v2.7.1 Types in 4.1.1 folder are the CNF enhancements which it is assumed will be in v4.1.1 Includes some changes in functionality to support: 1. Deployment of both existing (2.5.1) versions of types and new versions of types through sdc-BE-init 2. Selection of the correct node type definition version at onboarding of an ETSI SOL004 VNF/CNF csar, based on the declared version supported in the csar (i.e. when a 3.3.1 csar is imported, the node type definitions valid for 3.3.1 are used (rather than current logic which always selects the latest version) Signed-off-by: MichaelMorris Issue-ID: SDC-3470 Change-Id: Iff835d230b173b9d44349caa6b0b11d783e8f8d3 --- .../sdc/be/dao/jsongraph/JanusGraphDao.java | 41 ++++++++++++---------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'catalog-dao') diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java index 729d3c57da..be1dc454f8 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.be.dao.jsongraph; import org.janusgraph.core.*; +import org.janusgraph.graphdb.query.JanusGraphPredicate; import fj.data.Either; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -461,6 +462,12 @@ public class JanusGraphDao { } public Either, JanusGraphOperationStatus> getByCriteria(VertexTypeEnum type, Map props, Map hasNotProps, JsonParseFlagEnum parseFlag) { + return getByCriteria(type, props, hasNotProps, null, parseFlag); + } + + public Either, JanusGraphOperationStatus> getByCriteria(final VertexTypeEnum type, + final Map hasProps, final Map hasNotProps, + final Map> predicates, final JsonParseFlagEnum parseFlag) { Either graph = janusGraphClient.getGraph(); if (graph.isLeft()) { try { @@ -471,8 +478,8 @@ public class JanusGraphDao { query = query.has(GraphPropertyEnum.LABEL.getProperty(), type.getName()); } - if (props != null && !props.isEmpty()) { - for (Map.Entry entry : props.entrySet()) { + if (hasProps != null && !hasProps.isEmpty()) { + for (Map.Entry entry : hasProps.entrySet()) { query = query.has(entry.getKey().getProperty(), entry.getValue()); } } @@ -485,40 +492,36 @@ public class JanusGraphDao { } } } + if (predicates != null && !predicates.isEmpty()) { + for (Map.Entry> entry : predicates.entrySet()) { + JanusGraphPredicate predicate = entry.getValue().getKey(); + Object object = entry.getValue().getValue(); + query = query.has(entry.getKey(), predicate, object); + } + } Iterable vertices = query.vertices(); - if (vertices == null) { + if (vertices == null || !vertices.iterator().hasNext()) { return Either.right(JanusGraphOperationStatus.NOT_FOUND); } - Iterator iterator = vertices.iterator(); List result = new ArrayList<>(); - - while (iterator.hasNext()) { - JanusGraphVertex vertex = iterator.next(); - - Map newProp = getVertexProperties(vertex); - GraphVertex graphVertex = createAndFill(vertex, parseFlag); - - result.add(graphVertex); - } + vertices.forEach(vertex -> result.add(createAndFill(vertex, parseFlag))); + if (logger.isDebugEnabled()) { - logger.debug("Number of fetced nodes in graph for criteria : from type = {} and properties = {} is {}", type, props, result.size()); - } - if (result.size() == 0) { - return Either.right(JanusGraphOperationStatus.NOT_FOUND); + logger.debug("Number of fetched nodes in graph for criteria : from type '{}' and properties '{}' is '{}'", type, hasProps, result.size()); } return Either.left(result); } catch (Exception e) { if (logger.isDebugEnabled()) { - logger.debug("Failed get by criteria for type = {} and properties = {}", type, props, e); + logger.debug("Failed to get by criteria for type '{}' and properties '{}'", type, hasProps, e); } return Either.right(JanusGraphClient.handleJanusGraphException(e)); } } else { if (logger.isDebugEnabled()) { - logger.debug("Failed get by criteria for type ={} and properties = {} error : {}", type, props, graph.right().value()); + logger.debug("Failed to get by criteria for type '{}' and properties '{}'. Error : '{}'", type, hasProps, graph.right().value()); } return Either.right(graph.right().value()); } -- cgit 1.2.3-korg