summaryrefslogtreecommitdiffstats
path: root/catalog-dao/src
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2021-09-02 13:15:51 +0100
committerMichael Morris <michael.morris@est.tech>2021-09-20 13:35:20 +0000
commit3608fa7d186a3acffda0f3040abaad068a081410 (patch)
treef7591a69f107b42a2b82f8ff923f136eea4ea024 /catalog-dao/src
parent79165dcada554b625553e982b39d817c7f9d1747 (diff)
Error re-importing VSP
Issue-ID: SDC-3728 Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech> Signed-off-by: André Schmid <andre.schmid@est.tech> Change-Id: I22d6186b8e6922511a7ede584d009cfae041fabd
Diffstat (limited to 'catalog-dao/src')
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java2
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/exception/JanusGraphException.java36
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ToscaModelImportCassandraDao.java5
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java54
4 files changed, 96 insertions, 1 deletions
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<ToscaImportByModel> 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 <T extends GraphNode> JanusGraphOperationStatus deleteAllChildrenNodes(String key, String uniqueId, GraphEdgeLabels edgeType) {
+ final JanusGraph janusGraph = getJanusGraph();
+ final Iterable<JanusGraphVertex> 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<Edge> outEdges = rootVertex.edges(Direction.OUT, edgeType.getProperty());
+ while (outEdges.hasNext()) {
+ final Edge edge = outEdges.next();
+ final Vertex vertexIn = edge.inVertex();
+ final Iterator<Edge> outSubEdges = vertexIn.edges(Direction.OUT);
+ while (outSubEdges.hasNext()) {
+ Edge subEdge = outSubEdges.next();
+ Vertex vertex = subEdge.inVertex();
+ Map<String, Object> properties = getProperties(vertex);
+ if (properties != null) {
+ String label = (String) properties.get(GraphPropertiesDictionary.LABEL.getProperty());
+ if (label.equals("property")) {
+ vertex.remove();
+ }
+ }
+ }
+ Map<String, Object> 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<JanusGraph, JanusGraphOperationStatus> 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<List<ImmutablePair<JanusGraphVertex, Edge>>, JanusGraphOperationStatus> getChildrenVertecies(String key, String uniqueId,
GraphEdgeLabels edgeType) {
List<ImmutablePair<JanusGraphVertex, Edge>> immutablePairs = new ArrayList<>();