diff options
Diffstat (limited to 'asdctool/src/main/java')
-rw-r--r-- | asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java | 95 | ||||
-rw-r--r-- | asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java | 3 |
2 files changed, 37 insertions, 61 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java index e60640fa26..d757d81744 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java @@ -7,9 +7,9 @@ * 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. @@ -20,79 +20,56 @@ package org.openecomp.sdc.asdctool.impl; +import java.util.ArrayList; +import java.util.List; +import org.apache.tinkerpop.gremlin.structure.Transaction; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphFactory; -import org.janusgraph.core.JanusGraphVertex; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.common.log.wrappers.Logger; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - /** * Created by mlando on 2/23/2016. */ public class ProductLogic { - private static Logger log = Logger.getLogger(ProductLogic.class.getName()); + private static final Logger log = Logger.getLogger(ProductLogic.class.getName()); - public boolean deleteAllProducts(String janusGraphFile, String beHost, String bePort, String adminUser) { - log.debug("retrieving all products from graph"); - RestUtils restUtils = null; + public boolean deleteAllProducts(String janusGraphFile, String beHost, String bePort, String adminUser) { + log.debug("retrieving all products from graph"); List<String> productList = getAllProducts(janusGraphFile); - restUtils = new RestUtils(); - if (productList != null) { - for (String productUid : productList) { - restUtils.deleteProduct(productUid, beHost, bePort, adminUser); - } - return true; - } - else { + if (productList.isEmpty()) { log.error("failed to get products from graph"); return false; } - } - - private List<String> getAllProducts(String janusGraphFile) { - JanusGraph graph = null; - try { - graph = openGraph(janusGraphFile); - List<String> productsToDelete = new ArrayList<String>(); - Iterable vertices = graph.query() - .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices(); - if (vertices != null) { - Iterator<JanusGraphVertex> iter = vertices.iterator(); - while (iter.hasNext()) { - Vertex vertex = iter.next(); - String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); - productsToDelete.add(id); - } - } - - graph.tx().commit(); - return productsToDelete; - } catch (Exception e) { - e.printStackTrace(); - log.info("get All Products failed - {}" , e); - if(graph != null) { - graph.tx().rollback(); - } - return null; - - } finally { - if (graph != null) { - graph.close(); - } - } - } - - private JanusGraph openGraph(String janusGraphFileLocation) { - - return JanusGraphFactory.open(janusGraphFileLocation); - - } + for (String productUid : productList) { + new RestUtils().deleteProduct(productUid, beHost, bePort, adminUser); + } + return true; + } + private List<String> getAllProducts(String janusGraphFile) { + List<String> productsToDelete = new ArrayList<>(); + Transaction transac = null; + try (JanusGraph graph = JanusGraphFactory.open(janusGraphFile)) { + transac = graph.tx(); + Iterable vertices = graph.query() + .has(GraphPropertiesDictionary.LABEL.getProperty(), NodeTypeEnum.Product.getName()).vertices(); + if (vertices != null) { + for (Vertex vertex : (Iterable<Vertex>) vertices) { + String id = vertex.value(GraphPropertiesDictionary.UNIQUE_ID.getProperty()); + productsToDelete.add(id); + } + } + transac.commit(); + } catch (Exception e) { + log.error("get All Products failed", e); + if (transac != null) { + transac.rollback(); + } + } + return productsToDelete; + } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java index aaafdd2367..3332131e79 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java @@ -51,8 +51,7 @@ public class RestUtils { return status; } catch (Exception e) { log.error("Product uid:{} delete failed with exception", productUid, e); + return HttpStatus.SC_INTERNAL_SERVER_ERROR; } - return null; } - } |