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;
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);
}
// 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()) ) {
_close(trans);
if(session!=null) {
session.close();
+ session = null;
}
- if(cluster!=null) {
+ if(cluster!=null && !cluster.isClosed()) {
cluster.close();
}
}
}
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();
}
} 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);
}
}
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;
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;
}
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();
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());
query.append(target);
query.append("' AND key='");
query.append(key);
- query.append("';");
+ query.append("';\n");
}
public static String newKey(UserRoleDAO.Data urdd) {
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");
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);
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);
}
noAvg = trans.env().newTransNoAvg();
- cqlBatch = new CQLBatch(noAvg.info(),session);
+ cqlBatch = new CQLBatch(noAvg.debug(),session);
}
/*
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;
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();
}
}
}
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 {
} finally {
tt2.done();
}
- cqlBatch = new CQLBatch(noAvg.info(),session);
+ cqlBatch = new CQLBatch(noAvg.debug(),session);
} finally {
}
}
} 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();
}
}
}
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 {
<parent>
<groupId>org.onap.oparent</groupId>
<artifactId>oparent</artifactId>
- <version>2.0.0</version>
+ <version>1.2.3</version>
</parent>
<properties>