From c5009ade9e35d9d03131f55dafc9f0fd79c2246a Mon Sep 17 00:00:00 2001 From: "Maharajh, Robby (rx2202)" Date: Tue, 27 Jun 2017 17:07:50 -0400 Subject: [AAI-14] Force delete tool now uses Tinkerpop vertex vs titan vertex Updates now always add aai-node-type to vertex Stop using hbase.table.timestamp.format=YYYYMMdd-HH:mm:ss:SSS for date format Define new endpoint in ajsc to process the v8 models from Model Loader Change-Id: I7f6986e12d0f4c74256fe24629e1f1851541d7e4 Signed-off-by: Maharajh, Robby (rx2202) --- .../org/openecomp/aai/dbgen/ForceDeleteTool.java | 701 +++++++++++---------- .../aai/interceptors/AAILogJAXRSInInterceptor.java | 2 +- .../interceptors/AAILogJAXRSOutInterceptor.java | 2 +- .../java/org/openecomp/aai/rest/db/HttpEntry.java | 2 - .../aai/rest/tools/ModelVersionTransformer.java | 412 ++++++++++++ .../aai/util/AAIAppServletContextListener.java | 25 +- 6 files changed, 772 insertions(+), 372 deletions(-) create mode 100644 aai-resources/src/main/java/org/openecomp/aai/rest/tools/ModelVersionTransformer.java (limited to 'aai-resources/src/main/java/org') diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/ForceDeleteTool.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/ForceDeleteTool.java index 20d5c9f..bced2bc 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/dbgen/ForceDeleteTool.java +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/ForceDeleteTool.java @@ -23,15 +23,19 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.Properties; import java.util.Scanner; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; 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.slf4j.MDC; - import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.serialization.db.EdgeProperties; +import org.openecomp.aai.serialization.db.EdgeProperty; import org.openecomp.aai.util.AAIConfig; import org.openecomp.aai.util.AAIConstants; +import org.slf4j.MDC; + import com.att.eelf.configuration.Configuration; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -39,16 +43,11 @@ import com.thinkaurelius.titan.core.TitanEdge; import com.thinkaurelius.titan.core.TitanFactory; import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanGraphQuery; -import com.thinkaurelius.titan.core.TitanVertex; public class ForceDeleteTool { - - - private static final int MAXDESCENDENTDEPTH = 15; - - /** + /* * The main method. * * @param args the arguments @@ -206,7 +205,7 @@ public class ForceDeleteTool { System.out.println(msg); logger.info(msg); - + ForceDelete fd = new ForceDelete(graph); if( actionVal.equals("COLLECT_DATA") ){ // When doing COLLECT_DATA, we expect the dataString string to be comma separated // name value pairs like this: @@ -241,13 +240,13 @@ public class ForceDeleteTool { } } if( (tgQ != null) && (tgQ instanceof TitanGraphQuery) ){ - Iterable verts = (Iterable) tgQ.vertices(); - Iterator vertItor = verts.iterator(); + Iterable verts = (Iterable) tgQ.vertices(); + Iterator vertItor = verts.iterator(); while( vertItor.hasNext() ){ resCount++; - TitanVertex v = (TitanVertex)vertItor.next(); - showNodeInfo( logger, v, displayAllVidsFlag ); - int descendantCount = countDescendants( logger, v, 0 ); + Vertex v = vertItor.next(); + fd.showNodeInfo( logger, v, displayAllVidsFlag ); + int descendantCount = fd.countDescendants( logger, v, 0 ); String infMsg = " Found " + descendantCount + " descendant nodes \n"; System.out.println( infMsg ); logger.info( infMsg ); @@ -268,20 +267,20 @@ public class ForceDeleteTool { Iterator vtxItr = graph.vertices( vertexIdLong ); if( vtxItr != null && vtxItr.hasNext() ) { Vertex vtx = vtxItr.next(); - showNodeInfo( logger, vtx, displayAllVidsFlag ); - int descendantCount = countDescendants( logger, (TitanVertex)vtx, 0 ); + fd.showNodeInfo( logger, vtx, displayAllVidsFlag ); + int descendantCount = fd.countDescendants( logger, vtx, 0 ); String infMsg = " Found " + descendantCount + " descendant nodes. Note - forceDelete does not cascade to " + " child nodes, but they may become unreachable after the delete. \n"; System.out.println( infMsg ); logger.info( infMsg ); - int edgeCount = countEdges( logger, vtx ); + int edgeCount = fd.countEdges( logger, vtx ); infMsg = " Found total of " + edgeCount + " edges incident on this node. \n"; System.out.println( infMsg ); logger.info( infMsg ); - if( getNodeDelConfirmation(logger, userIdVal, vtx, descendantCount, edgeCount, overRideProtection) ){ + if( fd.getNodeDelConfirmation(logger, userIdVal, vtx, descendantCount, edgeCount, overRideProtection) ){ vtx.remove(); graph.tx().commit(); infMsg = ">>>>>>>>>> Removed node with vertexId = " + vertexIdLong; @@ -314,7 +313,7 @@ public class ForceDeleteTool { System.exit(0); } - if( getEdgeDelConfirmation(logger, userIdVal, thisEdge, overRideProtection) ){ + if( fd.getEdgeDelConfirmation(logger, userIdVal, thisEdge, overRideProtection) ){ thisEdge.remove(); graph.tx().commit(); String infMsg = ">>>>>>>>>> Removed edge with edgeId = " + edgeIdStr; @@ -339,383 +338,389 @@ public class ForceDeleteTool { }// end of main() - - public static void showNodeInfo(EELFLogger logger, Vertex tVert, Boolean displayAllVidsFlag ){ + public static class ForceDelete { - try { - Iterator> pI = tVert.properties(); - String infStr = ">>> Found Vertex with VertexId = " + tVert.id() + ", properties: "; - System.out.println( infStr ); - logger.info(infStr); - while( pI.hasNext() ){ - VertexProperty tp = pI.next(); - infStr = " [" + tp.key() + "|" + tp.value() + "] "; - System.out.println( infStr ); + private final int MAXDESCENDENTDEPTH = 15; + private final TitanGraph graph; + public ForceDelete(TitanGraph graph) { + this.graph = graph; + } + public void showNodeInfo(EELFLogger logger, Vertex tVert, Boolean displayAllVidsFlag ){ + + try { + Iterator> pI = tVert.properties(); + String infStr = ">>> Found Vertex with VertexId = " + tVert.id() + ", properties: "; + System.out.println( infStr ); logger.info(infStr); + while( pI.hasNext() ){ + VertexProperty tp = pI.next(); + infStr = " [" + tp.key() + "|" + tp.value() + "] "; + System.out.println( infStr ); + logger.info(infStr); + } + + ArrayList retArr = collectEdgeInfoForNode( logger, tVert, displayAllVidsFlag ); + for( String infoStr : retArr ){ + System.out.println( infoStr ); + logger.info(infoStr); + } } - - ArrayList retArr = collectEdgeInfoForNode( logger, tVert, displayAllVidsFlag ); - for( String infoStr : retArr ){ - System.out.println( infoStr ); - logger.info(infoStr); + catch (Exception e){ + String warnMsg = " -- Error -- trying to display edge info. [" + e.getMessage() + "]"; + System.out.println( warnMsg ); + logger.warn(warnMsg); } - } - catch (Exception e){ - String warnMsg = " -- Error -- trying to display edge info. [" + e.getMessage() + "]"; - System.out.println( warnMsg ); - logger.warn(warnMsg); - } - - }// End of showNodeInfo() + + }// End of showNodeInfo() - - public static void showPropertiesForEdge( EELFLogger logger, TitanEdge tEd ){ - String infMsg = ""; - if( tEd == null ){ - infMsg = "null Edge object passed to showPropertiesForEdge()"; - System.out.print(infMsg); - logger.info(infMsg); - return; - } - // Try to show the edge properties - try { - infMsg =" Label for this Edge = [" + tEd.label() + "] "; - System.out.print(infMsg); - logger.info(infMsg); + public void showPropertiesForEdge( EELFLogger logger, TitanEdge tEd ){ + String infMsg = ""; + if( tEd == null ){ + infMsg = "null Edge object passed to showPropertiesForEdge()"; + System.out.print(infMsg); + logger.info(infMsg); + return; + } - infMsg =" EDGE Properties for edgeId = " + tEd.id() + ": "; - System.out.print(infMsg); - logger.info(infMsg); - Iterator pI = tEd.keys().iterator(); - while( pI.hasNext() ){ - String propKey = pI.next(); - infMsg = "Prop: [" + propKey + "], val = [" - + tEd.property(propKey) + "] "; + // Try to show the edge properties + try { + infMsg =" Label for this Edge = [" + tEd.label() + "] "; System.out.print(infMsg); logger.info(infMsg); + + infMsg =" EDGE Properties for edgeId = " + tEd.id() + ": "; + System.out.print(infMsg); + logger.info(infMsg); + Iterator pI = tEd.keys().iterator(); + while( pI.hasNext() ){ + String propKey = pI.next(); + infMsg = "Prop: [" + propKey + "], val = [" + + tEd.property(propKey) + "] "; + System.out.print(infMsg); + logger.info(infMsg); + } } - } - catch( Exception ex ){ - infMsg = " Could not retrieve properties for this edge. exMsg = [" - + ex.getMessage() + "] "; - System.out.println( infMsg ); - logger.info(infMsg); - } - - // Try to show what's connected to the IN side of this Edge - try { - infMsg = " Looking for the Vertex on the IN side of the edge: "; - System.out.print(infMsg); - logger.info(infMsg); - TitanVertex inVtx = tEd.inVertex(); - Iterator> pI = inVtx.properties(); - String infStr = ">>> Found Vertex with VertexId = " + inVtx.id() - + ", properties: "; - System.out.println( infStr ); - logger.info(infStr); - while( pI.hasNext() ){ - VertexProperty tp = pI.next(); - infStr = " [" + tp.key() + "|" + tp.value() + "] "; - System.out.println( infStr ); + catch( Exception ex ){ + infMsg = " Could not retrieve properties for this edge. exMsg = [" + + ex.getMessage() + "] "; + System.out.println( infMsg ); + logger.info(infMsg); + } + + // Try to show what's connected to the IN side of this Edge + try { + infMsg = " Looking for the Vertex on the IN side of the edge: "; + System.out.print(infMsg); + logger.info(infMsg); + Vertex inVtx = tEd.inVertex(); + Iterator> pI = inVtx.properties(); + String infStr = ">>> Found Vertex with VertexId = " + inVtx.id() + + ", properties: "; + System.out.println( infStr ); logger.info(infStr); + while( pI.hasNext() ){ + VertexProperty tp = pI.next(); + infStr = " [" + tp.key() + "|" + tp.value() + "] "; + System.out.println( infStr ); + logger.info(infStr); + } } - } - catch( Exception ex ){ - infMsg = " Could not retrieve vertex data for the IN side of " - + "the edge. exMsg = [" + ex.getMessage() + "] "; - System.out.println( infMsg ); - logger.info(infMsg); - } - - // Try to show what's connected to the OUT side of this Edge - try { - infMsg = " Looking for the Vertex on the OUT side of the edge: "; - System.out.print(infMsg); - logger.info(infMsg); - TitanVertex outVtx = tEd.outVertex(); - Iterator> pI = outVtx.properties(); - String infStr = ">>> Found Vertex with VertexId = " + outVtx.id() - + ", properties: "; - System.out.println( infStr ); - logger.info(infStr); - while( pI.hasNext() ){ - VertexProperty tp = pI.next(); - infStr = " [" + tp.key() + "|" + tp.value() + "] "; - System.out.println( infStr ); + catch( Exception ex ){ + infMsg = " Could not retrieve vertex data for the IN side of " + + "the edge. exMsg = [" + ex.getMessage() + "] "; + System.out.println( infMsg ); + logger.info(infMsg); + } + + // Try to show what's connected to the OUT side of this Edge + try { + infMsg = " Looking for the Vertex on the OUT side of the edge: "; + System.out.print(infMsg); + logger.info(infMsg); + Vertex outVtx = tEd.outVertex(); + Iterator> pI = outVtx.properties(); + String infStr = ">>> Found Vertex with VertexId = " + outVtx.id() + + ", properties: "; + System.out.println( infStr ); logger.info(infStr); + while( pI.hasNext() ){ + VertexProperty tp = pI.next(); + infStr = " [" + tp.key() + "|" + tp.value() + "] "; + System.out.println( infStr ); + logger.info(infStr); + } } - } - catch( Exception ex ){ - infMsg = " Could not retrieve vertex data for the OUT side of " - + "the edge. exMsg = [" + ex.getMessage() + "] "; - System.out.println( infMsg ); - logger.info(infMsg); - } - - }// end showPropertiesForEdge() + catch( Exception ex ){ + infMsg = " Could not retrieve vertex data for the OUT side of " + + "the edge. exMsg = [" + ex.getMessage() + "] "; + System.out.println( infMsg ); + logger.info(infMsg); + } + + }// end showPropertiesForEdge() - - - public static ArrayList collectEdgeInfoForNode( EELFLogger logger, Vertex tVert, boolean displayAllVidsFlag ){ - ArrayList retArr = new ArrayList (); - Direction dir = Direction.OUT; - for ( int i = 0; i <= 1; i++ ){ - if( i == 1 ){ - // Second time through we'll look at the IN edges. - dir = Direction.IN; - } - Iterator eI = tVert.edges(dir); - if( ! eI.hasNext() ){ - retArr.add("No " + dir + " edges were found for this vertex. "); - } - while( eI.hasNext() ){ - Edge ed = eI.next(); - String lab = ed.label(); - Vertex vtx = null; - if( dir == Direction.OUT ){ - // get the vtx on the "other" side - vtx = ed.inVertex(); - } - else { - // get the vtx on the "other" side - vtx = ed.outVertex(); + + + public ArrayList collectEdgeInfoForNode( EELFLogger logger, Vertex tVert, boolean displayAllVidsFlag ){ + ArrayList retArr = new ArrayList (); + Direction dir = Direction.OUT; + for ( int i = 0; i <= 1; i++ ){ + if( i == 1 ){ + // Second time through we'll look at the IN edges. + dir = Direction.IN; } - if( vtx == null ){ - retArr.add(" >>> COULD NOT FIND VERTEX on the other side of this edge edgeId = " + ed.id() + " <<< "); + Iterator eI = tVert.edges(dir); + if( ! eI.hasNext() ){ + retArr.add("No " + dir + " edges were found for this vertex. "); } - else { - String nType = vtx.property("aai-node-type").orElse(null); - if( displayAllVidsFlag ){ - // This should rarely be needed - String vid = vtx.id().toString(); - retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node with VtxId = " + vid ); + while( eI.hasNext() ){ + Edge ed = eI.next(); + String lab = ed.label(); + Vertex vtx = null; + if( dir == Direction.OUT ){ + // get the vtx on the "other" side + vtx = ed.inVertex(); } else { - // This is the normal case - retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node. "); + // get the vtx on the "other" side + vtx = ed.outVertex(); + } + if( vtx == null ){ + retArr.add(" >>> COULD NOT FIND VERTEX on the other side of this edge edgeId = " + ed.id() + " <<< "); + } + else { + String nType = vtx.property("aai-node-type").orElse(null); + if( displayAllVidsFlag ){ + // This should rarely be needed + String vid = vtx.id().toString(); + retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node with VtxId = " + vid ); + } + else { + // This is the normal case + retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node. "); + } } } } - } - return retArr; - - }// end of collectEdgeInfoForNode() + return retArr; + + }// end of collectEdgeInfoForNode() - - public static int countEdges( EELFLogger logger, Vertex vtx ){ - int edgeCount = 0; - try { - Iterator edgesItr = vtx.edges(Direction.BOTH); - while( edgesItr.hasNext() ){ - edgesItr.next(); - edgeCount++; + + public int countEdges( EELFLogger logger, Vertex vtx ){ + int edgeCount = 0; + try { + Iterator edgesItr = vtx.edges(Direction.BOTH); + while( edgesItr.hasNext() ){ + edgesItr.next(); + edgeCount++; + } } - } - catch (Exception e) { - String wMsg = "-- ERROR -- Stopping the counting of edges because of Exception [" + e.getMessage() + "]"; - System.out.println( wMsg ); - logger.warn( wMsg ); - } - return edgeCount; + catch (Exception e) { + String wMsg = "-- ERROR -- Stopping the counting of edges because of Exception [" + e.getMessage() + "]"; + System.out.println( wMsg ); + logger.warn( wMsg ); + } + return edgeCount; + + }// end of countEdges() - }// end of countEdges() - - public static int countDescendants(EELFLogger logger, TitanVertex vtx, int levelVal ){ - int totalCount = 0; - int thisLevel = levelVal + 1; - - if( thisLevel > MAXDESCENDENTDEPTH ){ - String wMsg = "Warning -- Stopping the counting of descendents because we reached the max depth of " + MAXDESCENDENTDEPTH; - System.out.println( wMsg ); - logger.warn( wMsg ); - return totalCount; - } - - try { - Iterable verts = vtx.query().direction(Direction.OUT).has("isParent",true).vertices(); - Iterator vertI = verts.iterator(); - while( vertI != null && vertI.hasNext() ){ - totalCount++; - TitanVertex childVtx = (TitanVertex) vertI.next(); - totalCount = totalCount + countDescendants( logger, childVtx, thisLevel ); + public int countDescendants(EELFLogger logger, Vertex vtx, int levelVal ){ + int totalCount = 0; + int thisLevel = levelVal + 1; + + if( thisLevel > MAXDESCENDENTDEPTH ){ + String wMsg = "Warning -- Stopping the counting of descendents because we reached the max depth of " + MAXDESCENDENTDEPTH; + System.out.println( wMsg ); + logger.warn( wMsg ); + return totalCount; } - } - catch (Exception e) { - String wMsg = "Error -- Stopping the counting of descendents because of Exception [" + e.getMessage() + "]"; - System.out.println( wMsg ); - logger.warn( wMsg ); - } - - return totalCount; - }// end of countDescendants() + + try { + Iterator vertI = graph.traversal().V(vtx).union(__.outE().has(EdgeProperties.out(EdgeProperty.IS_PARENT), true).inV(), __.inE().has(EdgeProperties.in(EdgeProperty.IS_PARENT), true).outV()); + while( vertI != null && vertI.hasNext() ){ + totalCount++; + Vertex childVtx = vertI.next(); + totalCount = totalCount + countDescendants( logger, childVtx, thisLevel ); + } + } + catch (Exception e) { + String wMsg = "Error -- Stopping the counting of descendents because of Exception [" + e.getMessage() + "]"; + System.out.println( wMsg ); + logger.warn( wMsg ); + } + + return totalCount; + }// end of countDescendants() - - public static boolean getEdgeDelConfirmation( EELFLogger logger, String uid, TitanEdge ed, - Boolean overRideProtection ) { - - showPropertiesForEdge( logger, ed ); - System.out.print("\n Are you sure you want to delete this EDGE? (y/n): "); - Scanner s = new Scanner(System.in); - s.useDelimiter(""); - String confirm = s.next(); - s.close(); - if (!confirm.equalsIgnoreCase("y")) { - String infMsg = " User [" + uid + "] has chosen to abandon this delete request. "; - System.out.println("\n" + infMsg); - logger.info(infMsg); - return false; - } - else { - String infMsg = " User [" + uid + "] has confirmed this delete request. "; - System.out.println("\n" + infMsg); - logger.info(infMsg); - return true; - } - - } // End of getEdgeDelConfirmation() + public boolean getEdgeDelConfirmation( EELFLogger logger, String uid, TitanEdge ed, + Boolean overRideProtection ) { + + showPropertiesForEdge( logger, ed ); + System.out.print("\n Are you sure you want to delete this EDGE? (y/n): "); + Scanner s = new Scanner(System.in); + s.useDelimiter(""); + String confirm = s.next(); + s.close(); + + if (!confirm.equalsIgnoreCase("y")) { + String infMsg = " User [" + uid + "] has chosen to abandon this delete request. "; + System.out.println("\n" + infMsg); + logger.info(infMsg); + return false; + } + else { + String infMsg = " User [" + uid + "] has confirmed this delete request. "; + System.out.println("\n" + infMsg); + logger.info(infMsg); + return true; + } + } // End of getEdgeDelConfirmation() + - public static boolean getNodeDelConfirmation( EELFLogger logger, String uid, Vertex vtx, int edgeCount, - int descendantCount, Boolean overRideProtection ) { - String thisNodeType = ""; - try { - thisNodeType = vtx.property("aai-node-type").orElse(null); - } - catch ( Exception nfe ){ - // Let the user know something is going on - but they can confirm the delete if they want to. - String infMsg = " -- WARNING -- could not get an aai-node-type for this vertex. -- WARNING -- "; - System.out.println( infMsg ); - logger.warn( infMsg ); - } - - String ntListString = ""; - String maxDescString = ""; - String maxEdgeString = ""; - - int maxDescCount = 10; // default value - int maxEdgeCount = 10; // default value - ArrayList protectedNTypes = new ArrayList (); - protectedNTypes.add("cloud-region"); // default value - - try { - ntListString = AAIConfig.get("aai.forceDel.protected.nt.list"); - maxDescString = AAIConfig.get("aai.forceDel.protected.descendant.count"); - maxEdgeString = AAIConfig.get("aai.forceDel.protected.edge.count"); - } - catch ( Exception nfe ){ - // Don't worry, we will use default values - String infMsg = "-- WARNING -- could not get aai.forceDel.protected values from aaiconfig.properties -- will use default values. "; - System.out.println( infMsg ); - logger.warn( infMsg ); - } - - if( maxDescString != null && !maxDescString.equals("") ){ + public boolean getNodeDelConfirmation( EELFLogger logger, String uid, Vertex vtx, int edgeCount, + int descendantCount, Boolean overRideProtection ) { + String thisNodeType = ""; try { - maxDescCount = Integer.parseInt(maxDescString); + thisNodeType = vtx.property("aai-node-type").orElse(null); } catch ( Exception nfe ){ - // Don't worry, we will leave "maxDescCount" set to the default value + // Let the user know something is going on - but they can confirm the delete if they want to. + String infMsg = " -- WARNING -- could not get an aai-node-type for this vertex. -- WARNING -- "; + System.out.println( infMsg ); + logger.warn( infMsg ); } - } - - if( maxEdgeString != null && !maxEdgeString.equals("") ){ + + String ntListString = ""; + String maxDescString = ""; + String maxEdgeString = ""; + + int maxDescCount = 10; // default value + int maxEdgeCount = 10; // default value + ArrayList protectedNTypes = new ArrayList (); + protectedNTypes.add("cloud-region"); // default value + try { - maxEdgeCount = Integer.parseInt(maxEdgeString); + ntListString = AAIConfig.get("aai.forceDel.protected.nt.list"); + maxDescString = AAIConfig.get("aai.forceDel.protected.descendant.count"); + maxEdgeString = AAIConfig.get("aai.forceDel.protected.edge.count"); } catch ( Exception nfe ){ - // Don't worry, we will leave "maxEdgeCount" set to the default value + // Don't worry, we will use default values + String infMsg = "-- WARNING -- could not get aai.forceDel.protected values from aaiconfig.properties -- will use default values. "; + System.out.println( infMsg ); + logger.warn( infMsg ); } - } - - if( ntListString != null && !ntListString.trim().equals("") ){ - String [] nodeTypes = ntListString.split("\\|"); - for( int i = 0; i < nodeTypes.length; i++ ){ - protectedNTypes.add(nodeTypes[i]); + + if( maxDescString != null && !maxDescString.equals("") ){ + try { + maxDescCount = Integer.parseInt(maxDescString); + } + catch ( Exception nfe ){ + // Don't worry, we will leave "maxDescCount" set to the default value + } } - } - - boolean giveProtOverRideMsg = false; - boolean giveProtErrorMsg = false; - if( descendantCount > maxDescCount ){ - // They are trying to delete a node with a lots of descendants - String infMsg = " >> WARNING >> This node has more descendant edges than the max ProtectedDescendantCount: " + edgeCount + ". Max = " + - maxEdgeCount + ". It can be DANGEROUS to delete one of these. << WARNING << "; - System.out.println(infMsg); - logger.info(infMsg); - if( ! overRideProtection ){ - // They cannot delete this kind of node without using the override option - giveProtErrorMsg = true; + + if( maxEdgeString != null && !maxEdgeString.equals("") ){ + try { + maxEdgeCount = Integer.parseInt(maxEdgeString); + } + catch ( Exception nfe ){ + // Don't worry, we will leave "maxEdgeCount" set to the default value + } } - else { - giveProtOverRideMsg = true; + + if( ntListString != null && !ntListString.trim().equals("") ){ + String [] nodeTypes = ntListString.split("\\|"); + for( int i = 0; i < nodeTypes.length; i++ ){ + protectedNTypes.add(nodeTypes[i]); + } } - } - - if( edgeCount > maxEdgeCount ){ - // They are trying to delete a node with a lot of edges - String infMsg = " >> WARNING >> This node has more edges than the max ProtectedEdgeCount: " + edgeCount + ". Max = " + - maxEdgeCount + ". It can be DANGEROUS to delete one of these. << WARNING << "; - System.out.println(infMsg); - logger.info(infMsg); - if( ! overRideProtection ){ - // They cannot delete this kind of node without using the override option - giveProtErrorMsg = true; + + boolean giveProtOverRideMsg = false; + boolean giveProtErrorMsg = false; + if( descendantCount > maxDescCount ){ + // They are trying to delete a node with a lots of descendants + String infMsg = " >> WARNING >> This node has more descendant edges than the max ProtectedDescendantCount: " + edgeCount + ". Max = " + + maxEdgeCount + ". It can be DANGEROUS to delete one of these. << WARNING << "; + System.out.println(infMsg); + logger.info(infMsg); + if( ! overRideProtection ){ + // They cannot delete this kind of node without using the override option + giveProtErrorMsg = true; + } + else { + giveProtOverRideMsg = true; + } } - else { - giveProtOverRideMsg = true; + + if( edgeCount > maxEdgeCount ){ + // They are trying to delete a node with a lot of edges + String infMsg = " >> WARNING >> This node has more edges than the max ProtectedEdgeCount: " + edgeCount + ". Max = " + + maxEdgeCount + ". It can be DANGEROUS to delete one of these. << WARNING << "; + System.out.println(infMsg); + logger.info(infMsg); + if( ! overRideProtection ){ + // They cannot delete this kind of node without using the override option + giveProtErrorMsg = true; + } + else { + giveProtOverRideMsg = true; + } } - } - - if( thisNodeType != null && !thisNodeType.equals("") && protectedNTypes.contains(thisNodeType) ){ - // They are trying to delete a protected Node Type - String infMsg = " >> WARNING >> This node is a PROTECTED NODE-TYPE (" + thisNodeType + "). " + - " It can be DANGEROUS to delete one of these. << WARNING << "; - System.out.println(infMsg); - logger.info(infMsg); - if( ! overRideProtection ){ - // They cannot delete this kind of node without using the override option - giveProtErrorMsg = true; + + if( thisNodeType != null && !thisNodeType.equals("") && protectedNTypes.contains(thisNodeType) ){ + // They are trying to delete a protected Node Type + String infMsg = " >> WARNING >> This node is a PROTECTED NODE-TYPE (" + thisNodeType + "). " + + " It can be DANGEROUS to delete one of these. << WARNING << "; + System.out.println(infMsg); + logger.info(infMsg); + if( ! overRideProtection ){ + // They cannot delete this kind of node without using the override option + giveProtErrorMsg = true; + } + else { + giveProtOverRideMsg = true; + } + } + + if( giveProtOverRideMsg ){ + String infMsg = " !!>> WARNING >>!! you are using the overRideProtection parameter which will let you do this potentially dangerous delete."; + System.out.println("\n" + infMsg); + logger.info(infMsg); + } + else if( giveProtErrorMsg ) { + String errMsg = " ERROR >> this kind of node can only be deleted if you pass the overRideProtection parameter."; + System.out.println("\n" + errMsg); + logger.error(errMsg); + return false; + } + + System.out.print("\n Are you sure you want to do this delete? (y/n): "); + Scanner s = new Scanner(System.in); + s.useDelimiter(""); + String confirm = s.next(); + s.close(); + + if (!confirm.equalsIgnoreCase("y")) { + String infMsg = " User [" + uid + "] has chosen to abandon this delete request. "; + System.out.println("\n" + infMsg); + logger.info(infMsg); + return false; } else { - giveProtOverRideMsg = true; + String infMsg = " User [" + uid + "] has confirmed this delete request. "; + System.out.println("\n" + infMsg); + logger.info(infMsg); + return true; } - } - - if( giveProtOverRideMsg ){ - String infMsg = " !!>> WARNING >>!! you are using the overRideProtection parameter which will let you do this potentially dangerous delete."; - System.out.println("\n" + infMsg); - logger.info(infMsg); - } - else if( giveProtErrorMsg ) { - String errMsg = " ERROR >> this kind of node can only be deleted if you pass the overRideProtection parameter."; - System.out.println("\n" + errMsg); - logger.error(errMsg); - return false; - } - - System.out.print("\n Are you sure you want to do this delete? (y/n): "); - Scanner s = new Scanner(System.in); - s.useDelimiter(""); - String confirm = s.next(); - s.close(); - if (!confirm.equalsIgnoreCase("y")) { - String infMsg = " User [" + uid + "] has chosen to abandon this delete request. "; - System.out.println("\n" + infMsg); - logger.info(infMsg); - return false; - } - else { - String infMsg = " User [" + uid + "] has confirmed this delete request. "; - System.out.println("\n" + infMsg); - logger.info(infMsg); - return true; - } - - } // End of getNodeDelConfirmation() + } // End of getNodeDelConfirmation() + } } diff --git a/aai-resources/src/main/java/org/openecomp/aai/interceptors/AAILogJAXRSInInterceptor.java b/aai-resources/src/main/java/org/openecomp/aai/interceptors/AAILogJAXRSInInterceptor.java index 7480c05..050283d 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/interceptors/AAILogJAXRSInInterceptor.java +++ b/aai-resources/src/main/java/org/openecomp/aai/interceptors/AAILogJAXRSInInterceptor.java @@ -263,7 +263,7 @@ public class AAILogJAXRSInInterceptor extends JAXRSInInterceptor { * @return the string */ protected String genDate() { - FormatDate fd = new FormatDate(AAIConfig.get(AAIConstants.HBASE_TABLE_TIMESTAMP_FORMAT, "YYMMdd-HH:mm:ss:SSS")); + FormatDate fd = new FormatDate( "YYMMdd-HH:mm:ss:SSS"); return fd.getDateTime(); } diff --git a/aai-resources/src/main/java/org/openecomp/aai/interceptors/AAILogJAXRSOutInterceptor.java b/aai-resources/src/main/java/org/openecomp/aai/interceptors/AAILogJAXRSOutInterceptor.java index 563500e..b1d7ac9 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/interceptors/AAILogJAXRSOutInterceptor.java +++ b/aai-resources/src/main/java/org/openecomp/aai/interceptors/AAILogJAXRSOutInterceptor.java @@ -267,7 +267,7 @@ public class AAILogJAXRSOutInterceptor extends JAXRSOutInterceptor { } protected String genDate() { - FormatDate fd = new FormatDate(AAIConfig.get(AAIConstants.HBASE_TABLE_TIMESTAMP_FORMAT, "YYMMdd-HH:mm:ss:SSS")); + FormatDate fd = new FormatDate( "YYMMdd-HH:mm:ss:SSS"); return fd.getDateTime(); } diff --git a/aai-resources/src/main/java/org/openecomp/aai/rest/db/HttpEntry.java b/aai-resources/src/main/java/org/openecomp/aai/rest/db/HttpEntry.java index ef305b0..945a6f3 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/rest/db/HttpEntry.java +++ b/aai-resources/src/main/java/org/openecomp/aai/rest/db/HttpEntry.java @@ -271,8 +271,6 @@ public class HttpEntry { case PUT: if (isNewVertex) { v = serializer.createNewVertex(obj); - } else { - serializer.touchStandardVertexProperties(v, false); } serializer.serializeToDb(obj, v, query, uri.getRawPath(), requestContext); status = Status.OK; diff --git a/aai-resources/src/main/java/org/openecomp/aai/rest/tools/ModelVersionTransformer.java b/aai-resources/src/main/java/org/openecomp/aai/rest/tools/ModelVersionTransformer.java new file mode 100644 index 0000000..956fb41 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/rest/tools/ModelVersionTransformer.java @@ -0,0 +1,412 @@ +/*- + * ============LICENSE_START======================================================= + * org.openecomp.aai + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.aai.rest.tools; + +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.Encoded; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; + +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.openecomp.aai.db.props.AAIProperties; +import org.openecomp.aai.dbmap.DBConnectionType; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.introspection.Introspector; +import org.openecomp.aai.introspection.Loader; +import org.openecomp.aai.introspection.MarshallerProperties; +import org.openecomp.aai.introspection.ModelType; +import org.openecomp.aai.introspection.Version; +import org.openecomp.aai.introspection.exceptions.AAIUnknownObjectException; +import org.openecomp.aai.logging.ErrorLogHelper; +import org.openecomp.aai.rest.db.HttpEntry; +import org.openecomp.aai.rest.exceptions.AAIInvalidXMLNamespace; +import org.openecomp.aai.rest.util.ValidateEncoding; +import org.openecomp.aai.restcore.RESTAPI; +import org.openecomp.aai.serialization.db.EdgeType; +import org.openecomp.aai.serialization.db.exceptions.NoEdgeRuleFoundException; +import org.openecomp.aai.serialization.engines.QueryStyle; +import org.openecomp.aai.serialization.engines.TransactionalGraphEngine; +import org.radeox.util.logging.Logger; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.base.Joiner; +import com.thinkaurelius.titan.core.TitanTransaction; + + +/** + * The Class ModelVersionTransformer. + */ +@Path("tools") +public class ModelVersionTransformer extends RESTAPI { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ModelVersionTransformer.class.getName()); + protected static String authPolicyFunctionName = "REST"; + private ModelType introspectorFactoryType = ModelType.MOXY; + private QueryStyle queryStyle = QueryStyle.TRAVERSAL; + + + /** + * POST for model transformation. + * + * @param content the content + * @param uri the uri + * @param headers the headers + * @param info the info + * @param req the req + * @return the transformed model + * @Path("/{uri: modeltransform}") + * @throws UnsupportedEncodingException + */ + @POST + @Path("/{uri: modeltransform}") + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + public Response modelTransform (String content, @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest req) throws UnsupportedEncodingException { + Response response = null; + TransactionalGraphEngine dbEngine = null; + Loader loader = null; + MediaType mediaType = headers.getMediaType(); + String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId"); + String transId = headers.getRequestHeaders().getFirst("X-TransactionId"); + String realTime = headers.getRequestHeaders().getFirst("Real-Time"); + TitanTransaction g = null; + Boolean success = true; + AAIException ex; + + try { + validateRequest(info); + + DBConnectionType type = this.determineConnectionType(sourceOfTruth, realTime); + HttpEntry httpEntry = new HttpEntry(Version.v8, introspectorFactoryType, queryStyle, type); + loader = httpEntry.getLoader(); + dbEngine = httpEntry.getDbEngine(); + if (content.length() == 0) { + if (mediaType.toString().contains(MediaType.APPLICATION_JSON)) { + content = "{}"; + } else { + content = ""; + } + } + + //Unmarshall the received model and store properties and values in a map. + Introspector obj = loader.unmarshal("Model", content, org.openecomp.aai.restcore.MediaType.getEnum(this.getInputMediaType(mediaType))); + if (obj == null) { + throw new AAIException("AAI_3000", "object could not be unmarshalled:" + content); + } + + if (mediaType.toString().contains(MediaType.APPLICATION_XML) && !content.equals("") && isEmptyObject(obj)) { + throw new AAIInvalidXMLNamespace(content); + } + + Set properties = obj.getProperties(); + java.util.Iterator propItr = properties.iterator(); + + Map v8PropMap = new HashMap(); + while (propItr.hasNext()){ + String property = propItr.next(); + Object propertyValue = obj.getValue(property); + if (propertyValue != null) { + v8PropMap.put(propItr.next(), propertyValue); + } + } + // Get the current models and create a map of model-ver to model keys, this allows us + // to easily figure out and construct the relationships on the supplied v8 model + Map modelVersionIdToModelInvariantIdMap = getCurrentModelsFromGraph(headers, transId, info); + + // Build the v10 - TODO + HttpEntry newHttpEntry = new HttpEntry(Version.v10, introspectorFactoryType, queryStyle, type); + Loader newLoader = newHttpEntry.getLoader(); + Introspector newModelObj = newLoader.introspectorFromName("Model"); + + // pull the attributes we need to apply to the model + model-ver objects + // model specific attrs + String oldModelInvariantId = obj.getValue("model-id"); + String oldModelType = obj.getValue("model-type"); + // model-ver specific + String oldModelName = obj.getValue("model-name"); + String oldModelVersionId = obj.getValue("model-name-version-id"); + String oldModelVersion = obj.getValue("model-version"); + + // copy attributes from the v8 model object to the v10 model object + newModelObj.setValue("model-invariant-id", oldModelInvariantId); + newModelObj.setValue("model-type", oldModelType); + + Introspector modelVersObj = newModelObj.newIntrospectorInstanceOfProperty("model-vers"); + + newModelObj.setValue("model-vers", modelVersObj.getUnderlyingObject()); + + List modelVerList = (List)modelVersObj.getValue("model-ver"); + + //create a model-ver object + Introspector modelVerObj = newLoader.introspectorFromName("ModelVer"); + // load attributes from the v8 model object into the v10 model-ver object + modelVerObj.setValue("model-version-id", oldModelVersionId); + modelVerObj.setValue("model-name", oldModelName); + modelVerObj.setValue("model-version", oldModelVersion); + + + if (obj.hasProperty("model-elements")) { + Introspector oldModelElements = obj.getWrappedValue("model-elements"); + if (oldModelElements != null) { + Introspector newModelElements = modelVerObj.newIntrospectorInstanceOfProperty("model-elements"); + modelVerObj.setValue("model-elements", newModelElements.getUnderlyingObject()); + repackModelElements(oldModelElements, newModelElements, modelVersionIdToModelInvariantIdMap); + } + } + + modelVerList.add(modelVerObj.getUnderlyingObject()); + + String outputMediaType = getMediaType(headers.getAcceptableMediaTypes()); + MarshallerProperties marshallerProperties = + new MarshallerProperties.Builder(org.openecomp.aai.restcore.MediaType.getEnum(outputMediaType)).build(); + + String result = newModelObj.marshal(marshallerProperties); + response = Response.ok(result).build(); + + } catch (AAIException e) { + + ArrayList templateVars = new ArrayList(2); + templateVars.add("POST modeltransform"); + templateVars.add("model-ver.model-version-id"); + response = Response + .status(e.getErrorObject().getHTTPResponseCode()) + .entity(ErrorLogHelper.getRESTAPIErrorResponse( + headers.getAcceptableMediaTypes(), e, + templateVars)).build(); + success = false; + } catch (Exception e) { + ArrayList templateVars = new ArrayList(2); + templateVars.add("POST modeltransform"); + templateVars.add("model-ver.model-version-id"); + ex = new AAIException("AAI_4000", e); + response = Response + .status(Status.INTERNAL_SERVER_ERROR) + .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars)) + .build(); + e.printStackTrace(); + success = false; + } finally { + if (dbEngine != null) { + if (success) { + dbEngine.commit(); + } else { + dbEngine.rollback(); + } + } + } + return response; + } + + + private void repackModelElements(Introspector oldModelElements, Introspector newModelElements, Map modelVersionIdToModelInvariantIdMap) + throws AAIUnknownObjectException, AAIException { + + List oldModelElementList = oldModelElements.getWrappedListValue("model-element"); + List newModelElementList = (List)newModelElements.getValue("model-element"); + + for (Introspector oldModelElement : oldModelElementList) { + Introspector newModelElement = newModelElements.getLoader().introspectorFromName("model-element"); + + ArrayList attrs = new ArrayList(); + + attrs.add("model-element-uuid"); + attrs.add("new-data-del-flag"); + attrs.add("cardinality"); + attrs.add("linkage-points"); + + for (String attr : attrs) { + if (oldModelElement.hasProperty(attr)) { + newModelElement.setValue(attr, oldModelElement.getValue(attr)); + } + } + + if (oldModelElement.hasProperty("relationship-list")) { + + Introspector oldRelationshipList = oldModelElement.getWrappedValue("relationship-list"); + Introspector newRelationshipList = newModelElements.getLoader().introspectorFromName("relationship-list"); + newModelElement.setValue("relationship-list", newRelationshipList.getUnderlyingObject()); + + List oldRelationshipListList = oldRelationshipList.getWrappedListValue("relationship"); + List newRelationshipListList = (List)newRelationshipList.getValue("relationship"); + + for (Introspector oldRelationship : oldRelationshipListList) { + + Introspector newRelationship = newModelElements.getLoader().introspectorFromName("relationship"); + newRelationshipListList.add(newRelationship.getUnderlyingObject()); + + List oldRelationshipData = oldRelationship.getWrappedListValue("relationship-data"); + List newRelationshipData = (List)newRelationship.getValue("relationship-data"); + + newRelationship.setValue("related-to", "model-ver"); + + for (Introspector oldRelationshipDatum : oldRelationshipData) { + + String oldProp = null; + String oldVal = null; + + if (oldRelationshipDatum.hasProperty("relationship-key")) { + oldProp = oldRelationshipDatum.getValue("relationship-key"); + } + if (oldRelationshipDatum.hasProperty("relationship-value")) { + oldVal = oldRelationshipDatum.getValue("relationship-value"); + } + + if (oldProp.equals("model.model-name-version-id")) { + // make two new relationshipDatum for use w/ the new style model + + // you should have the model in the list of models we collected earlier + if (modelVersionIdToModelInvariantIdMap.containsKey(oldVal)) { + Introspector newRelationshipDatum1 = newModelElements.getLoader().introspectorFromName("relationship-data"); + Introspector newRelationshipDatum2 = newModelElements.getLoader().introspectorFromName("relationship-data"); + + String modelId = modelVersionIdToModelInvariantIdMap.get(oldVal); + + // the first one points at the model-invariant-id of found model + newRelationshipDatum1.setValue("relationship-key", "model.model-invariant-id"); + newRelationshipDatum1.setValue("relationship-value", modelId); + + // the second one points at the model-version-id which corresponds to the old model-name-version-id + newRelationshipDatum2.setValue("relationship-key", "model-ver.model-version-id"); + newRelationshipDatum2.setValue("relationship-value", oldVal); + + newRelationshipData.add(newRelationshipDatum1.getUnderlyingObject()); + newRelationshipData.add(newRelationshipDatum2.getUnderlyingObject()); + } else { + throw new AAIException("AAI_6114", "No model-ver found using model-ver.model-version-id=" + oldVal); + } + } + } + + } + } + + if (oldModelElement.hasProperty("model-elements")) { + Introspector nextOldModelElements = oldModelElement.getWrappedValue("model-elements"); + if (nextOldModelElements != null) { + Introspector nextNewModelElements = newModelElement.newIntrospectorInstanceOfProperty("model-elements"); + newModelElement.setValue("model-elements", nextNewModelElements.getUnderlyingObject()); + repackModelElements(nextOldModelElements, nextNewModelElements, modelVersionIdToModelInvariantIdMap); + } + } + newModelElementList.add(newModelElement.getUnderlyingObject()); + } + return; + + } + + private Map getCurrentModelsFromGraph(HttpHeaders headers, String transactionId, UriInfo info) throws NoEdgeRuleFoundException, AAIException { + + TransactionalGraphEngine dbEngine = null; + Map modelVerModelMap = new HashMap() ; + try { + + Version version = AAIProperties.LATEST; + DBConnectionType type = DBConnectionType.REALTIME; + + final HttpEntry httpEntry = new HttpEntry(version, introspectorFactoryType, queryStyle, type); + dbEngine = httpEntry.getDbEngine(); + + List modelVertices = dbEngine.asAdmin().getTraversalSource().V().has(AAIProperties.NODE_TYPE,"model").toList(); + for (Vertex modelVtx : modelVertices) { + + List modelVerVerts = dbEngine.getQueryBuilder(modelVtx).createEdgeTraversal(EdgeType.TREE, "model", "model-ver").toList(); + for (Vertex v : modelVerVerts) { + modelVerModelMap.put(v.value("model-version-id"), modelVtx.value("model-invariant-id")); + } + } + } catch (NoSuchElementException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception e1) { + e1.printStackTrace(); + } + return modelVerModelMap; + + } + + /** + * Validate request. + * + * @param uri the uri + * @param headers the headers + * @param req the req + * @param action the action + * @param info the info + * @throws AAIException the AAI exception + * @throws UnsupportedEncodingException the unsupported encoding exception + */ + private void validateRequest(UriInfo info) throws AAIException, UnsupportedEncodingException { + + if (!ValidateEncoding.getInstance().validate(info)) { + throw new AAIException("AAI_3008", "uri=" + getPath(info)); + } + } + + /** + * Gets the path. + * + * @param info the info + * @return the path + */ + private String getPath(UriInfo info) { + String path = info.getPath(false); + MultivaluedMap map = info.getQueryParameters(false); + String params = "?"; + List parmList = new ArrayList<>(); + for (String key : map.keySet()) { + for (String value : map.get(key)) { + parmList.add(key + "=" + value); + } + } + String queryParams = Joiner.on("&").join(parmList); + if (map.keySet().size() > 0) { + path += params + queryParams; + } + + return path; + + } + + protected boolean isEmptyObject(Introspector obj) { + return "{}".equals(obj.marshal(false)); + } + + +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/AAIAppServletContextListener.java b/aai-resources/src/main/java/org/openecomp/aai/util/AAIAppServletContextListener.java index 773b4a6..3184da8 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/util/AAIAppServletContextListener.java +++ b/aai-resources/src/main/java/org/openecomp/aai/util/AAIAppServletContextListener.java @@ -25,12 +25,11 @@ import java.io.IOException; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; -//import org.apache.activemq.broker.BrokerService; - import org.openecomp.aai.dbmap.AAIGraph; import org.openecomp.aai.exceptions.AAIException; import org.openecomp.aai.introspection.ModelInjestor; import org.openecomp.aai.logging.ErrorLogHelper; +import org.openecomp.aai.migration.MigrationControllerInternal; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; @@ -38,8 +37,6 @@ public class AAIAppServletContextListener implements ServletContextListener { private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIAppServletContextListener.class.getName()); - //private BrokerService broker = new BrokerService(); - /** * Destroys Context * @@ -49,13 +46,6 @@ public class AAIAppServletContextListener implements ServletContextListener { LOGGER.info("AAIGraph shutting down"); AAIGraph.getInstance().graphShutdown(); LOGGER.info("AAIGraph shutdown"); - - try { -// broker.stop(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } } /** @@ -79,17 +69,12 @@ public class AAIAppServletContextListener implements ServletContextListener { AAIGraph.getInstance(); ModelInjestor.getInstance(); - // Jsm internal broker for aai events - //broker = new BrokerService(); - //broker.addConnector("tcp://localhost:61447"); - //broker.setPersistent(false); - //broker.setUseJmx(false); - //broker.setSchedulerSupport(false); - //broker.start(); - LOGGER.info("A&AI Server initialization succcessful."); System.setProperty("org.openecomp.aai.serverStarted", "true"); - + if ("true".equals(AAIConfig.get("aai.run.migrations", "false"))) { + MigrationControllerInternal migrations = new MigrationControllerInternal(); + migrations.run(new String[]{"--commit"}); + } } catch (AAIException e) { ErrorLogHelper.logException(e); throw new RuntimeException("AAIException caught while initializing A&AI server", e); -- cgit 1.2.3-korg