aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java24
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java113
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationCatalogTest.java31
3 files changed, 95 insertions, 73 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java
index 38dc522247..606caeb576 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphDao.java
@@ -619,31 +619,31 @@ public class JanusGraphDao {
}
public Either<Iterator<Vertex>, JanusGraphOperationStatus> getCatalogOrArchiveVertices(boolean isCatalog) {
- Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
- if (graph.isLeft()) {
+ Either<JanusGraph, JanusGraphOperationStatus> graphEither = janusGraphClient.getGraph();
+ if (graphEither.isLeft()) {
try {
- JanusGraph tGraph = graph.left().value();
- String name = isCatalog ? VertexTypeEnum.CATALOG_ROOT.getName() : VertexTypeEnum.ARCHIVE_ROOT.getName();
- Iterable<JanusGraphVertex> vCatalogIter = tGraph.query().has(GraphPropertyEnum.LABEL.getProperty(), name).vertices();
- if (vCatalogIter == null) {
+ JanusGraph graph = graphEither.left().value();
+ String vertexType = isCatalog ? VertexTypeEnum.CATALOG_ROOT.getName() : VertexTypeEnum.ARCHIVE_ROOT.getName();
+ Iterable<JanusGraphVertex> vertexIterable = graph.query().has(GraphPropertyEnum.LABEL.getProperty(), vertexType).vertices();
+ if (vertexIterable == null) {
logger.debug("Failed to fetch catalog vertex");
return Either.right(JanusGraphOperationStatus.GENERAL_ERROR);
}
- JanusGraphVertex catalogV = vCatalogIter.iterator().next();
- if (catalogV == null) {
+ JanusGraphVertex catalogVertex = vertexIterable.iterator().next();
+ if (catalogVertex == null) {
logger.debug("Failed to fetch catalog vertex");
return Either.right(JanusGraphOperationStatus.GENERAL_ERROR);
}
String edgeLabel = isCatalog ? EdgeLabelEnum.CATALOG_ELEMENT.name() : EdgeLabelEnum.ARCHIVE_ELEMENT.name();
- Iterator<Vertex> vertices = catalogV.vertices(Direction.OUT, edgeLabel);
- return Either.left(vertices);
+ Iterator<Vertex> adjacentVertices = catalogVertex.vertices(Direction.OUT, edgeLabel);
+ return Either.left(adjacentVertices);
} catch (Exception e) {
logger.debug("Failed get by criteria: ", e);
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
} else {
- logger.debug("Failed get by criteria : {}", graph.right().value());
- return Either.right(graph.right().value());
+ logger.debug("Failed get by criteria : {}", graphEither.right().value());
+ return Either.right(graphEither.right().value());
}
}
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 24e1e910d3..0bc84506ee 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
@@ -37,13 +37,13 @@ import java.util.Map.Entry;
import java.util.Optional;
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;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyVertexProperty;
import org.janusgraph.core.JanusGraphVertex;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -83,6 +83,7 @@ import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility;
import org.openecomp.sdc.common.jsongraph.util.CommonUtility.LogLevelEnum;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.common.util.ValidationUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -1347,7 +1348,13 @@ public abstract class ToscaElementOperation extends BaseOperation {
}
Iterator<Vertex> vertices = verticesEither.left().value();
while (vertices.hasNext()) {
- handleCatalogComponent(existInCatalog, vertices.next(), excludeTypes);
+ Vertex vertex = vertices.next();
+ VertexProperty<?> vertexProperty = vertex.property(GraphPropertiesDictionary.METADATA.getProperty());
+ if(!(vertexProperty instanceof EmptyVertexProperty)) {
+ handleCatalogComponent(existInCatalog, vertex, excludeTypes);
+ } else {
+ logVertex(vertex);
+ }
}
stopWatch.stop();
String timeToFetchElements = stopWatch.prettyPrint();
@@ -1355,64 +1362,76 @@ public abstract class ToscaElementOperation extends BaseOperation {
return Either.left(existInCatalog.values().stream().collect(Collectors.toList()));
}
+ private void logVertex(Vertex vertex) {
+ StringBuilder sb = new StringBuilder();
+ vertex.keys().forEach(key -> {
+ Object value = vertex.property(key);
+ sb.append("[").append(key).append(": ").append(value).append("] ");
+ });
+ log.warn(EcompLoggerErrorCode.DATA_ERROR, "catalog-model", "Vertex has no metadata property: ", sb.toString());
+ }
+
private void handleCatalogComponent(Map<String, CatalogComponent> existInCatalog, Vertex vertex, List<ResourceTypeEnum> excludeTypes) {
VertexProperty<Object> property = vertex.property(GraphPropertiesDictionary.METADATA.getProperty());
String json = (String) property.value();
Map<String, Object> metadatObj = JsonParserUtils.toMap(json);
String uniqueId = (String) metadatObj.get(JsonPresentationFields.UNIQUE_ID.getPresentation());
Boolean isDeleted = (Boolean) metadatObj.get(JsonPresentationFields.IS_DELETED.getPresentation());
- 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()));
- catalogComponent.setName((String) metadatObj.get(JsonPresentationFields.NAME.getPresentation()));
- catalogComponent.setIcon((String) metadatObj.get(JsonPresentationFields.ICON.getPresentation()));
- catalogComponent.setLifecycleState((String) metadatObj.get(JsonPresentationFields.LIFECYCLE_STATE.getPresentation()));
- Object lastUpdateDate = metadatObj.get(JsonPresentationFields.LAST_UPDATE_DATE.getPresentation());
- 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()));
- catalogComponent.setIsHighestVersion((Boolean) metadatObj.get(JsonPresentationFields.HIGHEST_VERSION.getPresentation()));
- Iterator<Edge> edges = vertex.edges(Direction.IN, EdgeLabelEnum.STATE.name());
- if (edges.hasNext()) {
- catalogComponent
- .setLastUpdaterUserId((String) edges.next().outVertex().property(GraphPropertiesDictionary.USERID.getProperty()).value());
- }
- Object resourceType = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
- if (resourceType != null) {
- catalogComponent.setResourceType((String) resourceType);
- }
- if (catalogComponent.getComponentType() == ComponentTypeEnum.SERVICE) {
- setServiceCategoryFromGraphV(vertex, catalogComponent);
- } else {
- setResourceCategoryFromGraphV(vertex, catalogComponent);
- }
- List<String> tags = (List<String>) metadatObj.get(JsonPresentationFields.TAGS.getPresentation());
- if (tags != null) {
- catalogComponent.setTags(tags);
- }
+ if (isNotExcluded(excludeTypes, metadatObj) && (existInCatalog.get(uniqueId) == null && (isDeleted == null || !isDeleted.booleanValue()))) {
+ CatalogComponent catalogComponent = createCatalogComponent(vertex, metadatObj, uniqueId);
existInCatalog.put(uniqueId, catalogComponent);
}
}
- private boolean isAddToCatalog(List<ResourceTypeEnum> excludeTypes, Map<String, Object> metadatObj) {
+ private CatalogComponent createCatalogComponent(Vertex vertex, Map<String, Object> metadatObj, String uniqueId) {
+ 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()));
+ catalogComponent.setName((String) metadatObj.get(JsonPresentationFields.NAME.getPresentation()));
+ catalogComponent.setIcon((String) metadatObj.get(JsonPresentationFields.ICON.getPresentation()));
+ catalogComponent.setLifecycleState((String) metadatObj.get(JsonPresentationFields.LIFECYCLE_STATE.getPresentation()));
+ Object lastUpdateDate = metadatObj.get(JsonPresentationFields.LAST_UPDATE_DATE.getPresentation());
+ 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()));
+ catalogComponent.setIsHighestVersion((Boolean) metadatObj.get(JsonPresentationFields.HIGHEST_VERSION.getPresentation()));
+ Iterator<Edge> edges = vertex.edges(Direction.IN, EdgeLabelEnum.STATE.name());
+ if (edges.hasNext()) {
+ catalogComponent
+ .setLastUpdaterUserId((String) edges.next().outVertex().property(GraphPropertiesDictionary.USERID.getProperty()).value());
+ }
+ Object resourceType = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
+ if (resourceType != null) {
+ catalogComponent.setResourceType((String) resourceType);
+ }
+ if (catalogComponent.getComponentType() == ComponentTypeEnum.SERVICE) {
+ setServiceCategoryFromGraphV(vertex, catalogComponent);
+ } else {
+ setResourceCategoryFromGraphV(vertex, catalogComponent);
+ }
+ List<String> tags = (List<String>) metadatObj.get(JsonPresentationFields.TAGS.getPresentation());
+ if (tags != null) {
+ catalogComponent.setTags(tags);
+ }
+ return catalogComponent;
+ }
+
+ private boolean isNotExcluded(List<ResourceTypeEnum> excludeTypes, Map<String, Object> metadatObj) {
boolean isAddToCatalog = true;
Object resourceTypeStr = metadatObj.get(JsonPresentationFields.RESOURCE_TYPE.getPresentation());
- if (resourceTypeStr != null) {
+ if (resourceTypeStr != null && excludeTypes != null) {
ResourceTypeEnum resourceType = ResourceTypeEnum.getType((String) resourceTypeStr);
- if (!CollectionUtils.isEmpty(excludeTypes)) {
- Optional<ResourceTypeEnum> op = excludeTypes.stream().filter(rt -> rt == resourceType).findAny();
- if (op.isPresent()) {
- isAddToCatalog = false;
- }
- }
+ return !excludeTypes.stream()
+ .filter(type -> type == resourceType)
+ .findAny()
+ .isPresent();
}
return isAddToCatalog;
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationCatalogTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationCatalogTest.java
index 28f9fc8652..571a6d4b1f 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationCatalogTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationCatalogTest.java
@@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyVertexProperty;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -51,20 +52,13 @@ public class ToscaElementOperationCatalogTest {
private static final String UPDATER_ID = "m08740";
private ArrayList<Vertex> vertexList = new ArrayList<>();
- @Mock
- Vertex vertex;
- @Mock
- Edge edge;
- @Mock
- Vertex outVertex;
- @Mock
- Iterator<Edge> edges;
- @Mock
- JanusGraphDao janusGraphDao;
- @Mock
- VertexProperty<Object> property;
- @Mock
- VertexProperty<Object> updaterProperty;
+ @Mock Edge edge;
+ @Mock Vertex vertex;
+ @Mock Vertex outVertex;
+ @Mock Iterator<Edge> edges;
+ @Mock JanusGraphDao janusGraphDao;
+ @Mock VertexProperty<Object> property;
+ @Mock VertexProperty<Object> updaterProperty;
@InjectMocks
private ToscaElementOperation toscaOperation = new TopologyTemplateOperation();
@@ -119,4 +113,13 @@ public class ToscaElementOperationCatalogTest {
assertEquals(UPDATER_ID, componentList.get(0).getLastUpdaterUserId());
}
+ @Test
+ public void thatVertexIsSkippedIfItHasNoMetadataProperty() {
+ VertexProperty<Object> emptyVertexProperty = new EmptyVertexProperty<>();
+ when(vertex.property(GraphPropertiesDictionary.METADATA.getProperty())).thenReturn(emptyVertexProperty);
+
+ List<CatalogComponent> componentList = toscaOperation.getElementCatalogData(true, null).left().value();
+ assertEquals(0, componentList.size());
+ }
+
}