summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--aai-core/src/main/java/org/onap/aai/db/schema/ManageJanusGraphSchema.java79
-rw-r--r--aai-core/src/main/java/org/onap/aai/dbgen/DataGrooming.java212
2 files changed, 119 insertions, 172 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/db/schema/ManageJanusGraphSchema.java b/aai-core/src/main/java/org/onap/aai/db/schema/ManageJanusGraphSchema.java
index bf2d4107..c4061b3f 100644
--- a/aai-core/src/main/java/org/onap/aai/db/schema/ManageJanusGraphSchema.java
+++ b/aai-core/src/main/java/org/onap/aai/db/schema/ManageJanusGraphSchema.java
@@ -46,7 +46,7 @@ public class ManageJanusGraphSchema {
private List<EdgeProperty> aaiEdgeProperties;
private Auditor oxmInfo = null;
private Auditor graphInfo = null;
-
+
/**
* Instantiates a new manage JanusGraph schema.
*
@@ -86,28 +86,9 @@ public class ManageJanusGraphSchema {
* Creates the property keys.
*/
private void createPropertyKeys() {
-
-
+
for (DBProperty prop : aaiProperties) {
-
- if (graphMgmt.containsPropertyKey(prop.getName())) {
- PropertyKey key = graphMgmt.getPropertyKey(prop.getName());
- boolean isChanged = false;
- if (!prop.getCardinality().equals(key.cardinality())) {
- isChanged = true;
- }
- if (!prop.getTypeClass().equals(key.dataType())) {
- isChanged = true;
- }
- if (isChanged) {
- //must modify!
- this.replaceProperty(prop);
- }
- } else {
- //create a new property key
- System.out.println("Key: " + prop.getName() + " not found - adding");
- graphMgmt.makePropertyKey(prop.getName()).dataType(prop.getTypeClass()).cardinality(prop.getCardinality()).make();
- }
+ this.createProperty(graphMgmt, prop);
}
}
@@ -126,8 +107,8 @@ public class ManageJanusGraphSchema {
keyList.add(graphMgmt.getPropertyKey(prop.getName()));
}
if (graphMgmt.containsGraphIndex(index.getName())) {
- JanusGraphIndex JanusGraphIndex = graphMgmt.getGraphIndex(index.getName());
- PropertyKey[] dbKeys = JanusGraphIndex.getFieldKeys();
+ JanusGraphIndex janusGraphIndex = graphMgmt.getGraphIndex(index.getName());
+ PropertyKey[] dbKeys = janusGraphIndex.getFieldKeys();
if (dbKeys.length != keyList.size()) {
isChanged = true;
} else {
@@ -143,7 +124,7 @@ public class ManageJanusGraphSchema {
} else {
isNew = true;
}
- if (keyList.size() > 0) {
+ if (!keyList.isEmpty()) {
this.createIndex(graphMgmt, index.getName(), keyList, index.isUnique(), isNew, isChanged);
}
}
@@ -194,7 +175,7 @@ public class ManageJanusGraphSchema {
}
} else {
//create a new property key
- System.out.println("Key: " + prop.getName() + " not found - adding");
+ logger.info("Key: " + prop.getName() + " not found - adding");
mgmt.makePropertyKey(prop.getName()).dataType(prop.getTypeClass()).cardinality(prop.getCardinality()).make();
}
}
@@ -210,15 +191,7 @@ public class ManageJanusGraphSchema {
* @param isChanged the is changed
*/
private void createIndex(JanusGraphManagement mgmt, String indexName, List<PropertyKey> keys, boolean isUnique, boolean isNew, boolean isChanged) {
-
- /*if (isChanged) {
- System.out.println("Changing index: " + indexName);
- JanusGraphIndex oldIndex = mgmt.getGraphIndex(indexName);
- mgmt.updateIndex(oldIndex, SchemaAction.DISABLE_INDEX);
- mgmt.commit();
- //cannot remove indexes
- //graphMgmt.updateIndex(oldIndex, SchemaAction.REMOVE_INDEX);
- }*/
+
if (isNew || isChanged) {
if (isNew) {
@@ -230,31 +203,8 @@ public class ManageJanusGraphSchema {
builder.unique();
}
builder.buildCompositeIndex();
- System.out.println("Built index for " + indexName + " with keys: " + keys);
-
- //mgmt.commit();
- }
-
- //mgmt = graph.asAdmin().getManagementSystem();
- //mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.REGISTER_INDEX);
- //mgmt.commit();
-
- try {
- //waitForCompletion(indexName);
- //JanusGraphIndexRepair.hbaseRepair(AAIConstants.AAI_CONFIG_FILENAME, indexName, "");
- } catch (Exception e) {
- graph.tx().rollback();
- graph.close();
- logger.error(e.getMessage(),e);
+ logger.info("Built index for " + indexName + " with keys: " + keys);
}
-
- //mgmt = graph.asAdmin().getManagementSystem();
- //mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.REINDEX);
-
- //mgmt.updateIndex(mgmt.getGraphIndex(indexName), SchemaAction.ENABLE_INDEX);
-
- //mgmt.commit();
-
}
}
@@ -279,19 +229,16 @@ public class ManageJanusGraphSchema {
}
mgmt.rollback();
}
- System.out.println("Index REGISTERED in " + (System.currentTimeMillis() - before) + " ms");
+ logger.info("Index REGISTERED in " + (System.currentTimeMillis() - before) + " ms");
}
-
+
/**
* Replace property.
*
* @param key the key
*/
private void replaceProperty(DBProperty key) {
-
-
-
-
+
}
/**
@@ -310,7 +257,7 @@ public class ManageJanusGraphSchema {
keys.add(mgmt.getPropertyKey(prop.getName()));
}
if (mgmt.containsGraphIndex(index.getName())) {
- System.out.println("index already exists");
+ logger.info("index already exists");
isNew = false;
isChanged = true;
} else {
diff --git a/aai-core/src/main/java/org/onap/aai/dbgen/DataGrooming.java b/aai-core/src/main/java/org/onap/aai/dbgen/DataGrooming.java
index 61ef8544..d46aa7ae 100644
--- a/aai-core/src/main/java/org/onap/aai/dbgen/DataGrooming.java
+++ b/aai-core/src/main/java/org/onap/aai/dbgen/DataGrooming.java
@@ -26,6 +26,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -72,6 +73,7 @@ import org.janusgraph.core.JanusGraph;
public class DataGrooming {
+ public static final String AAI_EXCEPTION_NUMBER = "AAI_6101";
private static EELFLogger logger;
private static final String FROMAPPID = "AAI-DB";
private static final String TRANSID = UUID.randomUUID().toString();
@@ -143,101 +145,67 @@ public class DataGrooming {
if (args.length > 0) {
// They passed some arguments in that will affect processing
- for (int i = 0; i < args.length; i++) {
- String thisArg = args[i];
- if ("-edgesOnly".equals(thisArg)) {
- edgesOnlyFlag = true;
- } else if (thisArg.equals("-autoFix")) {
- doAutoFix = true;
- } else if ("-skipHostCheck".equals(thisArg)) {
- skipHostCheck = true;
- } else if ("-dontFixOrphans".equals(thisArg)) {
- dontFixOrphansFlag = true;
- } else if ("-singleCommits".equals(thisArg)) {
- singleCommits = true;
- } else if ("-dupeCheckOff".equals(thisArg)) {
- dupeCheckOff = true;
- } else if ("-dupeFixOn".equals(thisArg)) {
- dupeFixOn = true;
- } else if ("-ghost2CheckOff".equals(thisArg)) {
- ghost2CheckOff = true;
- } else if ("-neverUseCache".equals(thisArg)) {
- neverUseCache = true;
- } else if ("-ghost2FixOn".equals(thisArg)) {
- ghost2FixOn = true;
- } else if ("-skipEdgeChecks".equals(thisArg)) {
- skipEdgeCheckFlag = true;
- } else if ("-maxFix".equals(thisArg)) {
- i++;
- if (i >= args.length) {
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
- logger.error(" No value passed with -maxFix option. ");
- AAISystemExitUtil.systemExitCloseAAIGraph(0);
- }
- String nextArg = args[i];
- try {
- maxRecordsToFix = Integer.parseInt(nextArg);
- } catch (Exception e) {
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
- logger.error("Bad value passed with -maxFix option: ["
- + nextArg + "]");
- AAISystemExitUtil.systemExitCloseAAIGraph(0);
- }
- } else if (thisArg.equals("-sleepMinutes")) {
- i++;
- if (i >= args.length) {
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
- logger.error("No value passed with -sleepMinutes option.");
- AAISystemExitUtil.systemExitCloseAAIGraph(0);
- }
- String nextArg = args[i];
- try {
- sleepMinutes = Integer.parseInt(nextArg);
- } catch (Exception e) {
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
- logger.error("Bad value passed with -sleepMinutes option: ["
- + nextArg + "]");
- AAISystemExitUtil.systemExitCloseAAIGraph(0);
- }
- } else if ("-timeWindowMinutes".equals(thisArg)) {
- i++;
- if (i >= args.length) {
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
- logger.error("No value passed with -timeWindowMinutes option.");
- AAISystemExitUtil.systemExitCloseAAIGraph(0);
- }
- String nextArg = args[i];
- try {
- timeWindowMinutes = Integer.parseInt(nextArg);
- } catch (Exception e) {
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
- logger.error("Bad value passed with -timeWindowMinutes option: ["
- + nextArg + "]");
- AAISystemExitUtil.systemExitCloseAAIGraph(0);
- }
-
- } else if ("-f".equals(thisArg)) {
- i++;
- if (i >= args.length) {
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
- logger.error(" No value passed with -f option. ");
- AAISystemExitUtil.systemExitCloseAAIGraph(0);
- }
- prevFileName = args[i];
- } else {
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
- logger.error(" Unrecognized argument passed to DataGrooming: ["
- + thisArg + "]. ");
- logger.error(" Valid values are: -f -autoFix -maxFix -edgesOnly -skipEdgeChecks -dupeFixOn -donFixOrphans -timeWindowMinutes -sleepMinutes -neverUseCache");
- AAISystemExitUtil.systemExitCloseAAIGraph(0);
+
+ List<String> arguments = Arrays.asList(args);
+ Iterator<String> argsIterator = arguments.iterator();
+ while (argsIterator.hasNext()){
+ String argument = argsIterator.next();
+ String nextArg;
+ switch(argument){
+ case "-edgesOnly":
+ edgesOnlyFlag = true;
+ break;
+ case "-autoFix":
+ doAutoFix = true;
+ break;
+ case "-skipHostCheck":
+ skipHostCheck = true;
+ break;
+ case "-dontFixOrphans":
+ dontFixOrphansFlag = true;
+ break;
+ case "-singleCommits":
+ singleCommits = true;
+ break;
+ case "-dupeCheckOff":
+ dupeCheckOff = true;
+ break;
+ case "-dupeFixOn":
+ dupeFixOn = true;
+ break;
+ case "-ghost2CheckOff":
+ ghost2CheckOff = true;
+ break;
+ case "-neverUseCache":
+ neverUseCache = true;
+ break;
+ case "-ghost2FixOn":
+ ghost2FixOn = true;
+ break;
+ case "-skipEdgeChecks":
+ skipEdgeCheckFlag = true;
+ break;
+ case "-maxFix":
+ handleNoPassedArgument(argsIterator, argument);
+ nextArg = argsIterator.next();
+ maxRecordsToFix = handleNumericArgument(maxRecordsToFix, nextArg, argument);
+ break;
+ case "-sleepMinutes":
+ handleNoPassedArgument(argsIterator, argument);
+ nextArg = argsIterator.next();
+ sleepMinutes = handleNumericArgument(sleepMinutes, nextArg, argument);
+ break;
+ case "-timeWindowMinutes":
+ handleNoPassedArgument(argsIterator, argument);
+ nextArg = argsIterator.next();
+ timeWindowMinutes = handleNumericArgument(timeWindowMinutes, nextArg, argument);
+ break;
+ case "-f":
+ handleNoPassedArgument(argsIterator, argument);
+ prevFileName = argsIterator.next();
+ break;
+ default:
+ handleUnrecognizedArguments(argument);
}
}
}
@@ -349,6 +317,38 @@ public class DataGrooming {
}// End of main()
+ private static void handleUnrecognizedArguments(String argument) {
+ LoggingContext.statusCode(StatusCode.ERROR);
+ LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
+ logger.error(" Unrecognized argument passed to DataGrooming: ["
+ + argument + "]. ");
+ logger.error(
+ " Valid values are: -f -autoFix -maxFix -edgesOnly -skipEdgeChecks -dupeFixOn -donFixOrphans -timeWindowMinutes -sleepMinutes -neverUseCache");
+ AAISystemExitUtil.systemExitCloseAAIGraph(0);
+ }
+
+ private static int handleNumericArgument(int numericArgumentValue, String nextArg, String argument) {
+ try {
+ numericArgumentValue = Integer.parseInt(nextArg);
+ } catch (Exception e) {
+ LoggingContext.statusCode(StatusCode.ERROR);
+ LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
+ logger.error("Bad value passed with" + argument + "option: ["
+ + nextArg + "]");
+ AAISystemExitUtil.systemExitCloseAAIGraph(0);
+ }
+ return numericArgumentValue;
+ }
+
+ private static void handleNoPassedArgument(Iterator argsIterator, String argument) {
+ if (!argsIterator.hasNext()) {
+ LoggingContext.statusCode(StatusCode.ERROR);
+ LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
+ logger.error("No value passed with" + argument + "option.");
+ AAISystemExitUtil.systemExitCloseAAIGraph(0);
+ }
+ }
+
/**
* Do the grooming.
*
@@ -449,7 +449,7 @@ public class DataGrooming {
}
if (graph == null) {
String emsg = "null graph object in DataGrooming\n";
- throw new AAIException("AAI_6101", emsg);
+ throw new AAIException(AAI_EXCEPTION_NUMBER, emsg);
}
logger.debug(" Got the graph object. ");
@@ -457,18 +457,18 @@ public class DataGrooming {
g = graph.newTransaction();
if (g == null) {
String emsg = "null graphTransaction object in DataGrooming\n";
- throw new AAIException("AAI_6101", emsg);
+ throw new AAIException(AAI_EXCEPTION_NUMBER, emsg);
}
GraphTraversalSource source1 = g.traversal();
ArrayList<String> errArr = new ArrayList<>();
int totalNodeCount = 0;
- HashMap<String, String> misMatchedHash = new HashMap<String, String>();
- HashMap<String, Vertex> orphanNodeHash = new HashMap<String, Vertex>();
- HashMap<String, Vertex> missingDepNodeHash = new HashMap<String, Vertex>();
- HashMap<String, Edge> oneArmedEdgeHash = new HashMap<String, Edge>();
- HashMap<String, String> emptyVertexHash = new HashMap<String, String>();
- HashMap<String, Vertex> ghostNodeHash = new HashMap<String, Vertex>();
+ HashMap<String, String> misMatchedHash = new HashMap<>();
+ HashMap<String, Vertex> orphanNodeHash = new HashMap<>();
+ HashMap<String, Vertex> missingDepNodeHash = new HashMap<>();
+ HashMap<String, Edge> oneArmedEdgeHash = new HashMap<>();
+ HashMap<String, String> emptyVertexHash = new HashMap<>();
+ HashMap<String, Vertex> ghostNodeHash = new HashMap<>();
ArrayList<String> dupeGroups = new ArrayList<>();
Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST);
@@ -494,7 +494,7 @@ public class DataGrooming {
// Determine what the key fields are for this nodeType - use an arrayList so they
// can be gotten out in a consistent order.
Set <String> keyPropsSet = entry.getValue().getKeys();
- ArrayList <String> keyProps = new ArrayList <String> ();
+ ArrayList <String> keyProps = new ArrayList<>();
keyProps.addAll(keyPropsSet);
// Get the types of nodes that this nodetype depends on for uniqueness (if any)
@@ -772,14 +772,14 @@ public class DataGrooming {
graph2 = JanusGraphFactory.open(new AAIGraphConfig.Builder(AAIConstants.REALTIME_DB_CONFIG).forService(DataGrooming.class.getSimpleName()).withGraphType("realtime2").buildConfiguration());
if (graph2 == null) {
String emsg = "null graph2 object in DataGrooming\n";
- throw new AAIException("AAI_6101", emsg);
+ throw new AAIException(AAI_EXCEPTION_NUMBER, emsg);
} else {
logger.debug("Got the graph2 object... \n");
}
g2 = graph2.newTransaction();
if (g2 == null) {
String emsg = "null graphTransaction2 object in DataGrooming\n";
- throw new AAIException("AAI_6101", emsg);
+ throw new AAIException(AAI_EXCEPTION_NUMBER, emsg);
}
ArrayList<Vertex> vertList = new ArrayList<>();