From 3608fa7d186a3acffda0f3040abaad068a081410 Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Thu, 2 Sep 2021 13:15:51 +0100 Subject: Error re-importing VSP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: SDC-3728 Signed-off-by: KrupaNagabhushan Signed-off-by: André Schmid Change-Id: I22d6186b8e6922511a7ede584d009cfae041fabd --- .../org/openecomp/sdc/be/dao/api/ActionStatus.java | 2 +- .../be/dao/api/exception/JanusGraphException.java | 36 +++++++++++++++ .../cassandra/ToscaModelImportCassandraDao.java | 5 ++ .../be/dao/janusgraph/JanusGraphGenericDao.java | 54 ++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/exception/JanusGraphException.java (limited to 'catalog-dao') diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java index 30fcfac03e..2a71089b74 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java @@ -54,7 +54,7 @@ public enum ActionStatus { // Model related MODEL_ALREADY_EXISTS, INVALID_MODEL, MODEL_IMPORTS_IS_EMPTY, COULD_NOT_READ_MODEL_IMPORTS, MODEL_NOT_FOUND, MODEL_NAME_CANNOT_BE_EMPTY, COMPONENT_WITH_MODEL_ALREADY_EXIST, COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS, COMPONENT_WITH_VENDOR_RELEASE_ALREADY_EXISTS_IN_MODEL, - UNKNOWN_MODEL_TYPE, + UNKNOWN_MODEL_TYPE, COULD_NOT_DELETE_MODEL, COULD_NOT_DELETE_MODEL_ELEMENTS, // Service API URL INVALID_SERVICE_API_URL, // Property related diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/exception/JanusGraphException.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/exception/JanusGraphException.java new file mode 100644 index 0000000000..fb37b54d2e --- /dev/null +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/exception/JanusGraphException.java @@ -0,0 +1,36 @@ +/* + * - + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.dao.api.exception; + +import lombok.Getter; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; + +@Getter +public class JanusGraphException extends RuntimeException { + + private final JanusGraphOperationStatus status; + + public JanusGraphException(final JanusGraphOperationStatus status, final String message) { + super(message); + this.status = status; + } +} diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ToscaModelImportCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ToscaModelImportCassandraDao.java index c250aecdef..d21b561094 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ToscaModelImportCassandraDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ToscaModelImportCassandraDao.java @@ -122,4 +122,9 @@ public class ToscaModelImportCassandraDao extends CassandraDao { return toscaImportByModelAccessor.findAllByModel(modelId).all(); } + public void deleteAllByModel(final String modelId) { + final List allByModel = findAllByModel(modelId); + allByModel.forEach(toscaImportByModelMapper::delete); + } + } diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java index 2116dcc27e..8382af5e8b 100644 --- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java +++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java @@ -48,6 +48,7 @@ import org.janusgraph.core.JanusGraphVertexQuery; import org.janusgraph.core.PropertyKey; import org.janusgraph.graphdb.query.JanusGraphPredicate; import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.dao.api.exception.JanusGraphException; import org.openecomp.sdc.be.dao.graph.GraphElementFactory; import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum; @@ -59,6 +60,7 @@ import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.resources.data.GraphNodeLock; +import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.beans.factory.annotation.Qualifier; @@ -1318,6 +1320,58 @@ public class JanusGraphGenericDao { return Either.left(immutablePairs); } + public JanusGraphOperationStatus deleteAllChildrenNodes(String key, String uniqueId, GraphEdgeLabels edgeType) { + final JanusGraph janusGraph = getJanusGraph(); + final Iterable vertices = janusGraph.query().has(key, uniqueId).vertices(); + if (vertices == null || !vertices.iterator().hasNext()) { + return JanusGraphOperationStatus.NOT_FOUND; + } + final Vertex rootVertex = vertices.iterator().next(); + final Iterator outEdges = rootVertex.edges(Direction.OUT, edgeType.getProperty()); + while (outEdges.hasNext()) { + final Edge edge = outEdges.next(); + final Vertex vertexIn = edge.inVertex(); + final Iterator outSubEdges = vertexIn.edges(Direction.OUT); + while (outSubEdges.hasNext()) { + Edge subEdge = outSubEdges.next(); + Vertex vertex = subEdge.inVertex(); + Map properties = getProperties(vertex); + if (properties != null) { + String label = (String) properties.get(GraphPropertiesDictionary.LABEL.getProperty()); + if (label.equals("property")) { + vertex.remove(); + } + } + } + Map properties = getProperties(vertexIn); + if (properties != null) { + String label = (String) properties.get(GraphPropertiesDictionary.LABEL.getProperty()); + GraphNode node = GraphElementFactory + .createElement(label, GraphElementTypeEnum.Node, properties, GraphNode.class); + if (node != null) { + vertexIn.remove(); + } + } + } + return JanusGraphOperationStatus.OK; + } + + /** + * Gets the JanusGraph instance. + * + * @return the JanusGraph instance + * @throws JanusGraphException when the graph was not created + */ + public JanusGraph getJanusGraph() { + final Either graphRes = janusGraphClient.getGraph(); + if (graphRes.isRight()) { + final var errorMsg = String.format("Failed to retrieve graph. Status was '%s'", graphRes.right().value()); + log.error(EcompLoggerErrorCode.SCHEMA_ERROR, JanusGraphGenericDao.class.getName(), errorMsg); + throw new JanusGraphException(graphRes.right().value(), errorMsg); + } + return graphRes.left().value(); + } + public Either>, JanusGraphOperationStatus> getChildrenVertecies(String key, String uniqueId, GraphEdgeLabels edgeType) { List> immutablePairs = new ArrayList<>(); -- cgit 1.2.3-korg