summaryrefslogtreecommitdiffstats
path: root/auth
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2019-03-19 14:48:55 -0500
committerInstrumental <jonathan.gathman@att.com>2019-03-19 15:07:41 -0500
commite3163b2d5609753f874e2f52fd5ef67fa063af7a (patch)
tree9c8cda886203745d6e959344515515457e457f18 /auth
parent68a514e92ea55e70241dc93cc5e9e46d3fc1b6c7 (diff)
Update Batch from Testing
Issue-ID: AAF-789 Change-Id: Ie26798de8b2afe2114f7712fb84798a7bff8e72b Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth')
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java26
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/ApprovalSet.java16
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/URApprovalSet.java6
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/LastNotified.java2
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java17
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java67
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Remove.java24
-rw-r--r--auth/auth-core/src/main/java/org/onap/aaf/auth/org/FileMailer.java5
8 files changed, 91 insertions, 72 deletions
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 d51ec600..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<String> specialNames;
@@ -105,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);
@@ -114,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()) ) {
@@ -367,8 +370,9 @@ public abstract class Batch {
_close(trans);
if(session!=null) {
session.close();
+ session = null;
}
- if(cluster!=null) {
+ if(cluster!=null && !cluster.isClosed()) {
cluster.close();
}
}
@@ -515,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();
@@ -531,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);
}
}
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/ApprovalSet.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/ApprovalSet.java
index 005397b2..45617f8b 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/ApprovalSet.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/ApprovalSet.java
@@ -21,14 +21,11 @@
package org.onap.aaf.auth.batch.approvalsets;
import java.nio.ByteBuffer;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import java.util.UUID;
import org.onap.aaf.auth.dao.cass.ApprovalDAO;
import org.onap.aaf.auth.dao.cass.FutureDAO;
@@ -45,23 +42,12 @@ public class ApprovalSet {
public ApprovalSet(final GregorianCalendar start, final String target, final DataView dv) throws CadiException {
dataview = dv;
fdd = new FutureDAO.Data();
- try {
- fdd.id = newID(target);
- } catch (NoSuchAlgorithmException e) {
- throw new CadiException(e);
- }
+ fdd.id = Chrono.dateToUUID(System.currentTimeMillis());
fdd.target = target;
fdd.start = start.getTime();
ladd = new ArrayList<>();
}
- protected UUID newID(String target) throws NoSuchAlgorithmException {
- StringBuilder sb = new StringBuilder(new String(SecureRandom.getInstanceStrong().generateSeed(10)));
- sb.append(target);
- sb.append(System.currentTimeMillis());
- return Chrono.dateToUUID(System.currentTimeMillis());
- }
-
protected void setConstruct(final ByteBuffer bytes) {
fdd.construct = bytes;
}
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/URApprovalSet.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/URApprovalSet.java
index 7f7bff28..a25ad6e7 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/URApprovalSet.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/approvalsets/URApprovalSet.java
@@ -41,8 +41,6 @@ import org.onap.aaf.misc.env.util.Chrono;
public class URApprovalSet extends ApprovalSet {
- private boolean ownerSuperApprove = true;
-
public URApprovalSet(final AuthzTrans trans, final GregorianCalendar start, final DataView dv, final Loader<UserRoleDAO.Data> lurdd) throws IOException, CadiException {
super(start, "user_role", dv);
Organization org = trans.org();
@@ -120,10 +118,6 @@ public class URApprovalSet extends ApprovalSet {
fdd.target_key = key;
}
- public void ownerSuperApprove(boolean set) {
- ownerSuperApprove = set;
- }
-
private ApprovalDAO.Data newApproval(UserRoleDAO.Data urdd) throws CadiException {
ApprovalDAO.Data add = new ApprovalDAO.Data();
add.id = Chrono.dateToUUID(System.currentTimeMillis());
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/LastNotified.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/LastNotified.java
index 6af1cbea..e108ec85 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/LastNotified.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/LastNotified.java
@@ -118,7 +118,7 @@ public class LastNotified {
query.append(target);
query.append("' AND key='");
query.append(key);
- query.append("';");
+ query.append("';\n");
}
public static String newKey(UserRoleDAO.Data urdd) {
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java
index 5a0b70a1..3c7634ff 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java
@@ -73,7 +73,7 @@ import org.onap.aaf.misc.env.util.Chrono;
public Notify(AuthzTrans trans) throws APIException, IOException, OrganizationException {
super(trans.env());
access = env.access();
- session = super.cluster.connect();
+ session = cluster.connect();
String mailerCls = env.getProperty("MAILER");
String mailFrom = env.getProperty("MAIL_FROM");
@@ -95,7 +95,11 @@ import org.onap.aaf.misc.env.util.Chrono;
String line;
StringBuilder sb = new StringBuilder();
- BufferedReader br = new BufferedReader(new FileReader(header_html));
+ File fhh = new File(header_html);
+ if(!fhh.exists()) {
+ throw new APIException(header_html + " does not exist");
+ }
+ BufferedReader br = new BufferedReader(new FileReader(fhh));
try {
while((line=br.readLine())!=null) {
sb.append(line);
@@ -130,7 +134,12 @@ import org.onap.aaf.misc.env.util.Chrono;
urgent = false;
sb.setLength(0);
- br = new BufferedReader(new FileReader(footer_html));
+ fhh = new File(footer_html);
+ if(!fhh.exists()) {
+ throw new APIException(footer_html + " does not exist");
+ }
+
+ br = new BufferedReader(new FileReader(fhh));
try {
while((line=br.readLine())!=null) {
sb.append(line);
@@ -142,7 +151,7 @@ import org.onap.aaf.misc.env.util.Chrono;
}
noAvg = trans.env().newTransNoAvg();
- cqlBatch = new CQLBatch(noAvg.info(),session);
+ cqlBatch = new CQLBatch(noAvg.debug(),session);
}
/*
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java
index 82c1f2cc..947312f1 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/bodies/NotifyBody.java
@@ -29,12 +29,15 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import org.onap.aaf.auth.batch.reports.Notify;
import org.onap.aaf.auth.env.AuthzTrans;
@@ -160,39 +163,45 @@ public abstract class NotifyBody {
Package pkg = NotifyBody.class.getPackage();
String path = pkg.getName().replace('.', '/');
URL url = cl.getResource(path);
- if(url == null) {
- throw new APIException("Cannot load resources from " + path);
- }
- File dir;
- try {
- dir = new File(url.toURI());
- } catch (URISyntaxException e) {
- throw new APIException(e);
+ List<String> classNames = new ArrayList<>();
+ String urlString = url.toString();
+ if(urlString.startsWith("jar:file:")) {
+ int exclam = urlString.lastIndexOf('!');
+ JarFile jf = new JarFile(urlString.substring(9,exclam));
+ try {
+ Enumeration<JarEntry> jfe = jf.entries();
+ while(jfe.hasMoreElements()) {
+ String name = jfe.nextElement().getName();
+ if(name.startsWith(path) && name.endsWith(".class")) {
+ classNames.add(name.substring(0,name.length()-6).replace('/', '.'));
+ }
+ }
+ } finally {
+ jf.close();
+ }
+ } else {
+ File dir = new File(url.getFile());
+ for( String f : dir.list()) {
+ if(f.endsWith(".class")) {
+ classNames.add(pkg.getName()+'.'+f.substring(0,f.length()-6));
+ }
+ }
}
- if(dir.exists()) {
- String[] files = dir.list();
- if(files!=null) {
- for(String sf : files) {
- int dot = sf.indexOf('.');
- if(dot>=0) {
- String cls = pkg.getName()+'.'+sf.substring(0,dot);
- try {
- Class<?> c = cl.loadClass(cls);
- if(c!=null) {
- if(!Modifier.isAbstract(c.getModifiers())) {
- Constructor<?> cst = c.getConstructor(Access.class);
- NotifyBody nb = (NotifyBody)cst.newInstance(access);
- if(nb!=null) {
- bodyMap.put("info|"+nb.name, nb);
- bodyMap.put(nb.type+'|'+nb.name, nb);
- }
- }
- }
- } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
- e.printStackTrace();
+ for(String cls : classNames) {
+ try {
+ Class<?> c = cl.loadClass(cls);
+ if(c!=null) {
+ if(!Modifier.isAbstract(c.getModifiers())) {
+ Constructor<?> cst = c.getConstructor(Access.class);
+ NotifyBody nb = (NotifyBody)cst.newInstance(access);
+ if(nb!=null) {
+ bodyMap.put("info|"+nb.name, nb);
+ bodyMap.put(nb.type+'|'+nb.name, nb);
}
}
}
+ } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ e.printStackTrace();
}
}
}
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Remove.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Remove.java
index 7a30dc5f..4472a314 100644
--- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Remove.java
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Remove.java
@@ -51,6 +51,7 @@ import org.onap.aaf.cadi.util.CSV;
import org.onap.aaf.misc.env.APIException;
import org.onap.aaf.misc.env.Env;
import org.onap.aaf.misc.env.TimeTaken;
+import org.onap.aaf.misc.env.Trans;
import org.onap.aaf.misc.env.util.Chrono;
public class Remove extends Batch {
@@ -74,7 +75,7 @@ public class Remove extends Batch {
} finally {
tt2.done();
}
- cqlBatch = new CQLBatch(noAvg.info(),session);
+ cqlBatch = new CQLBatch(noAvg.debug(),session);
} finally {
@@ -185,14 +186,19 @@ public class Remove extends Batch {
}
}
} finally {
- if(ur.get()) {
- cqlBatch.touch(UserRoleDAO.TABLE, 0, UserRoleDAO.CACHE_SEG, dryRun);
- }
- if(cred.get()) {
- cqlBatch.touch(CredDAO.TABLE, 0, CredDAO.CACHE_SEG, dryRun);
- }
- if(x509.get()) {
- cqlBatch.touch(CertDAO.TABLE, 0, CertDAO.CACHE_SEG, dryRun);
+ TimeTaken tt = trans.start("Touch UR,Cred and Cert Caches",Trans.REMOTE);
+ try {
+ if(ur.get()) {
+ cqlBatch.touch(UserRoleDAO.TABLE, 0, UserRoleDAO.CACHE_SEG, dryRun);
+ }
+ if(cred.get()) {
+ cqlBatch.touch(CredDAO.TABLE, 0, CredDAO.CACHE_SEG, dryRun);
+ }
+ if(x509.get()) {
+ cqlBatch.touch(CertDAO.TABLE, 0, CertDAO.CACHE_SEG, dryRun);
+ }
+ } finally {
+ tt.done();
}
}
}
diff --git a/auth/auth-core/src/main/java/org/onap/aaf/auth/org/FileMailer.java b/auth/auth-core/src/main/java/org/onap/aaf/auth/org/FileMailer.java
index 2e3801ed..6a648a8a 100644
--- a/auth/auth-core/src/main/java/org/onap/aaf/auth/org/FileMailer.java
+++ b/auth/auth-core/src/main/java/org/onap/aaf/auth/org/FileMailer.java
@@ -47,7 +47,10 @@ public class FileMailer implements Mailer {
throw new APIException("MAIL_FROM property is required for Email Notifications");
}
String env = access.getProperty("CASS_ENV", "UNKNOWN");
- String logdir = access.getProperty(env+".LOG_DIR", "logs/"+env);
+ String logdir = access.getProperty("LOG_DIR",null);
+ if(logdir==null) {
+ logdir=access.getProperty(env+".LOG_DIR", "logs/"+env);
+ }
dir = Paths.get(logdir+"/email/"+Chrono.dateOnlyStamp());
if(!Files.exists(dir)) {
try {