X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-batch%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fbatch%2FBatch.java;h=36a88b648e9820a17e80050894e09c8d641f5ce8;hb=e3163b2d5609753f874e2f52fd5ef67fa063af7a;hp=1c65c0586e095a0581ec3da0be79e9fb5d66e6b1;hpb=d9c0bb04b77f6a637f1fc07b69c90898d672bd34;p=aaf%2Fauthz.git diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java index 1c65c058..36a88b64 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java @@ -73,7 +73,7 @@ public abstract class Batch { protected static final String STARS = "*****"; - protected final Cluster cluster; + protected static Cluster cluster; protected static AuthzEnv env; protected static Session session; protected static Set specialNames; @@ -91,7 +91,9 @@ public abstract class Batch { protected final Organization org; protected String version; - + protected static final Date now = new Date(); + protected static final Date never = new Date(0); + protected Batch(AuthzEnv env) throws APIException, IOException, OrganizationException { if (batchEnv != null) { env.info().log("Redirecting to ",batchEnv,"environment"); @@ -103,7 +105,8 @@ public abstract class Batch { CassAccess.CASSANDRA_CLUSTERS_PASSWORD, VERSION,GUI_URL,MAX_EMAILS, LOG_DIR, - "SPECIAL_NAMES" + "SPECIAL_NAMES", + "MAIL_TEST_TO" }) { if ((str = env.getProperty(batchEnv+'.'+key))!=null) { env.setProperty(key, str); @@ -112,7 +115,9 @@ public abstract class Batch { } // Setup for Dry Run - cluster = CassAccess.cluster(env,batchEnv); + if(cluster==null) { + cluster = CassAccess.cluster(env,batchEnv); + } env.info().log("cluster name - ",cluster.getClusterName()); String dryRunStr = env.getProperty( "DRY_RUN" ); if ( dryRunStr == null || "false".equals(dryRunStr.trim()) ) { @@ -149,7 +154,7 @@ public abstract class Batch { } protected abstract void run(AuthzTrans trans); - protected abstract void _close(AuthzTrans trans); + protected void _close(AuthzTrans trans) {} public String[] args() { return env.get(ssargs); @@ -363,7 +368,13 @@ public abstract class Batch { public final void close(AuthzTrans trans) { _close(trans); - cluster.close(); + if(session!=null) { + session.close(); + session = null; + } + if(cluster!=null && !cluster.isClosed()) { + cluster.close(); + } } public static void main(String[] args) { @@ -508,7 +519,14 @@ public abstract class Batch { } if (batch != null) { - batch.run(trans); + try { + batch.run(trans); + } catch (Exception e) { + if(cluster!=null && !cluster.isClosed()) { + cluster.close(); + } + trans.error().log(e); + } } } finally { tt.done(); @@ -524,9 +542,10 @@ public abstract class Batch { } } catch (Exception e) { + if(cluster!=null && !cluster.isClosed()) { + cluster.close(); + } e.printStackTrace(System.err); - // Exceptions thrown by DB aren't stopping the whole process. - System.exit(1); } }