Fixed handling InterruptedException and NullPointerException; added closing connection with graph
Change-Id: I8c317842550f62955b68347fd6f4e954e390ad1a
Issue-ID: AAI-1362
Signed-off-by: Wiktor Garbarek <wiktor.garbarek@nokia.com>
Thread.sleep(5000);
} catch (java.lang.InterruptedException ie) {
System.out.println(" DB Clearing has been aborted. ");
+ Thread.currentThread().interrupt();
AAISystemExitUtil.systemExitCloseAAIGraph(1);
}
LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
logger.error(emsg);
exit(0);
- } else {
- obj = loader.introspectorFromName(nodeTypeVal);
}
+ obj = loader.introspectorFromName(nodeTypeVal);
if (skipHostCheck) {
logger.info(" We will skip the HostCheck as requested. ");
Thread.sleep(sleepMsec);
} catch (InterruptedException ie) {
msg = "\n >>> Sleep Thread has been Interrupted <<< ";
+ Thread.currentThread().interrupt();
logger.info( msg );
System.out.println( msg );
exit(0);
Graph gt = null;
try {
- if( graph == null ){
+ if( graph != null ){
+ gt = graph.newTransaction();
+ } else {
String emsg = "could not get graph object in DupeTool. \n";
System.out.println(emsg);
LoggingContext.statusCode(StatusCode.ERROR);
logger.error(emsg);
exit(0);
}
- gt = graph.newTransaction();
- if (gt == null) {
- String emsg = "null graphTransaction object in DupeTool. \n";
- throw new AAIException("AAI_6101", emsg);
- }
-
}
- catch (AAIException e1) {
- String msg = e1.getErrorObject().toString();
- System.out.println(msg);
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.DATA_ERROR);
- logger.error(msg);
- exit(0);
- }
- catch (Exception e2) {
- String msg = e2.toString();
+ catch (Exception e) {
+ String msg = e.toString();
System.out.println(msg);
LoggingContext.statusCode(StatusCode.ERROR);
LoggingContext.responseCode(LoggingContext.UNKNOWN_ERROR);
}
}
}
-
- if(tgQ == null){
- msg = "Bad JanusGraphQuery object. ";
- System.out.println(msg);
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.AVAILABILITY_TIMEOUT_ERROR);
- logger.error(msg);
- exit(0);
- }
+ if(tgQ != null) {
Iterator<Vertex> vertItor = tgQ;
- while( vertItor.hasNext() ){
+ while (vertItor.hasNext()) {
Vertex tiV = vertItor.next();
- if( windowStartTime <= 0 ){
+ if (windowStartTime <= 0) {
// We're not applying a time-window
retVertList.add(tiV);
continue;
}
- Object objTimeStamp = tiV.property("aai-created-ts").orElse(null);
- if( objTimeStamp == null ){
- // No timestamp - so just take it
- retVertList.add(tiV);
- continue;
- }
-
- long thisNodeCreateTime = (long)objTimeStamp;
- if( thisNodeCreateTime > windowStartTime ){
- // It is in our window, so we can take it
- retVertList.add(tiV);
- }
- }
+ Object objTimeStamp = tiV.property("aai-created-ts").orElse(null);
+ if (objTimeStamp == null) {
+ // No timestamp - so just take it
+ retVertList.add(tiV);
+ continue;
+ }
+ long thisNodeCreateTime = (long) objTimeStamp;
+ if (thisNodeCreateTime > windowStartTime) {
+ // It is in our window, so we can take it
+ retVertList.add(tiV);
+ }
+ }
+ } else {
+ msg = "Bad JanusGraphQuery object. ";
+ System.out.println(msg);
+ LoggingContext.statusCode(StatusCode.ERROR);
+ LoggingContext.responseCode(LoggingContext.AVAILABILITY_TIMEOUT_ERROR);
+ logger.error(msg);
+ exit(0);
+ }
if( retVertList.isEmpty() ){
logger.debug("DEBUG No node found for: [" + qStringForMsg + ", with aai-created-ts > " + windowStartTime );
// name value pairs like this:
// "propName1|propVal1,propName2|propVal2" etc. We will look for a node or nodes
// that have properties that ALL match what was passed in.
-
+
int resCount = 0;
int firstPipeLoc = dataString.indexOf("|");
if( firstPipeLoc <= 0 ){
logger.error(msg);
exit(0);
}
- GraphTraversal<Vertex, Vertex> g = graph.traversal().V();
- String qStringForMsg = " graph.traversal().V()";
- // Note - if they're only passing on parameter, there won't be any commas
- String [] paramArr = dataString.split(",");
- for( int i = 0; i < paramArr.length; i++ ){
- int pipeLoc = paramArr[i].indexOf("|");
- if( pipeLoc <= 0 ){
- msg = "Must use the -params4Collect option when collecting data with data string in a format like: 'propName1|propVal1,propName2|propVal2'";
- System.out.println(msg);
- LoggingContext.statusCode(StatusCode.ERROR);
- LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
- logger.error(msg);
- exit(0);
- }
- else {
- String propName = paramArr[i].substring(0,pipeLoc);
- String propVal = paramArr[i].substring(pipeLoc + 1);
- g = g.has(propName,propVal);
- qStringForMsg = qStringForMsg + ".has(" + propName + "," + propVal + ")";
- }
- }
+ GraphTraversal<Vertex, Vertex> g = null;
+ String qStringForMsg = null;
+ if (graph != null) {
+ g = graph.traversal().V();
+ qStringForMsg = " graph.traversal().V()";
+ // Note - if they're only passing on parameter, there won't be any commas
+ String[] paramArr = dataString.split(",");
+ for (int i = 0; i < paramArr.length; i++) {
+ int pipeLoc = paramArr[i].indexOf("|");
+ if (pipeLoc <= 0) {
+ msg = "Must use the -params4Collect option when collecting data with data string in a format like: 'propName1|propVal1,propName2|propVal2'";
+ System.out.println(msg);
+ LoggingContext.statusCode(StatusCode.ERROR);
+ LoggingContext.responseCode(LoggingContext.BUSINESS_PROCESS_ERROR);
+ logger.error(msg);
+ exit(0);
+ } else {
+ String propName = paramArr[i].substring(0, pipeLoc);
+ String propVal = paramArr[i].substring(pipeLoc + 1);
+ g = g.has(propName, propVal);
+ qStringForMsg = qStringForMsg + ".has(" + propName + "," + propVal + ")";
+ }
+ }
+ }
if( (g != null)){
Iterator<Vertex> vertItor = g;
while( vertItor.hasNext() ){
Thread.sleep(5000);
} catch (java.lang.InterruptedException ie) {
logAndPrint(logger, " DB Schema Update has been aborted. ");
+ Thread.currentThread().interrupt();
System.exit(1);
}
- logAndPrint(logger, " ---- NOTE --- about to open graph (takes a little while)\n");
-
- Version version = Version.getLatest();
- QueryStyle queryStyle = QueryStyle.TRAVERSAL;
- ModelType introspectorFactoryType = ModelType.MOXY;
- Loader loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
- TransactionalGraphEngine engine = null;
- try {
- engine = new JanusGraphDBEngine(queryStyle, DBConnectionType.REALTIME, loader);
- SchemaModInternal internal = new SchemaModInternal(engine, logger, propName, targetDataType, targetIndexInfo, new Boolean(preserveDataFlag));
- internal.execute();
- engine.startTransaction();
- engine.tx().close();
- } catch (Exception e) {
- String emsg = "Not able to get a graph object in SchemaMod.java\n";
- logAndPrint(logger, e.getMessage());
- logAndPrint(logger, emsg);
- System.exit(1);
- }
+ logAndPrint(logger, " ---- NOTE --- about to open graph (takes a little while)\n");
+
+ Version version = Version.getLatest();
+ QueryStyle queryStyle = QueryStyle.TRAVERSAL;
+ ModelType introspectorFactoryType = ModelType.MOXY;
+ Loader loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version);
+ TransactionalGraphEngine engine = null;
+ try {
+ engine = new JanusGraphDBEngine(queryStyle, DBConnectionType.REALTIME, loader);
+ SchemaModInternal internal = new SchemaModInternal(engine, logger, propName, targetDataType, targetIndexInfo, new Boolean(preserveDataFlag));
+ internal.execute();
+ engine.startTransaction();
+ engine.tx().close();
+ } catch (Exception e) {
+ String emsg = "Not able to get a graph object in SchemaMod.java\n";
+ logAndPrint(logger, e.getMessage());
+ logAndPrint(logger, emsg);
+ System.exit(1);
+ }
}
/**
* Log and print.
}
return;
}
+ finally {
+ try {
+ g.close();
+ }
+ catch (Exception e) {
+ logger.error("Error occured while closing Transaction with graph" + e.getMessage());
+ }
+ }
}
success= false;
logger.error("Found Exception" , a);
} finally {
- try {
- br.close();
- } catch (IOException e) {
- success = false;
- logger.error("Found Exception" , e);
+ if (br != null){
+ try {
+ br.close();
+ } catch (IOException e) {
+ success = false;
+ logger.error("Found Exception" , e);
+ }
}
}