From 12414fe43077e12d7ef711951b1633ad31d73573 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Tue, 22 Jan 2019 10:27:32 -0600 Subject: Public and Private Locate entries Issue-ID: AAF-723 Change-Id: I9dcd2e732ce64b39aaa57a6e9404f275f7ad540c Signed-off-by: Instrumental --- .../main/java/org/onap/aaf/auth/batch/Batch.java | 28 +++-- .../org/onap/aaf/auth/batch/reports/Expiring.java | 7 +- .../org/onap/aaf/auth/batch/reports/NotInOrg.java | 7 +- .../org/onap/aaf/auth/batch/reports/Notify.java | 2 +- .../aaf/auth/batch/reports/NsRoleUserReport.java | 127 +++++++++++++++++++++ .../aaf/auth/batch/update/NotifyCredExpiring.java | 11 -- .../org/onap/aaf/auth/batch/update/Remove.java | 2 +- 7 files changed, 151 insertions(+), 33 deletions(-) create mode 100644 auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NsRoleUserReport.java (limited to 'auth/auth-batch/src/main/java') 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 ff605203..d49f4faf 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 @@ -81,6 +81,8 @@ public abstract class Batch { protected static boolean dryRun; protected static String batchEnv; + private static File logdir; + public static final String CASS_ENV = "CASS_ENV"; public static final String LOG_DIR = "LOG_DIR"; protected static final String MAX_EMAILS="MAX_EMAILS"; @@ -324,16 +326,22 @@ public abstract class Batch { } } - protected static String logDir() { - String ld = env.getProperty(LOG_DIR); - if (ld==null) { - if (batchEnv==null) { // Deployed Batch doesn't use different ENVs, and a common logdir - ld = "logs/"; - } else { - ld = "logs/"+batchEnv; - } - } - return ld; + protected static File logDir() { + if(logdir == null) { + String ld = env.getProperty(LOG_DIR); + if (ld==null) { + if (batchEnv==null) { // Deployed Batch doesn't use different ENVs, and a common logdir + ld = "logs/"; + } else { + ld = "logs/"+batchEnv; + } + } + logdir = new File(ld); + if(!logdir.exists()) { + logdir.mkdirs(); + } + } + return logdir; } protected int count(String str, char c) { if (str==null || str.isEmpty()) { diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Expiring.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Expiring.java index 7ed26ce5..e171d174 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Expiring.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Expiring.java @@ -63,7 +63,6 @@ public class Expiring extends Batch { private static final String EXPIRED_OWNERS = "ExpiredOwners"; private int minOwners; private Map writerList; - private File logDir; private ExpireRange expireRange; private Date deleteDate; @@ -87,15 +86,13 @@ public class Expiring extends Batch { // Create Intermediate Output writerList = new HashMap<>(); - logDir = new File(logDir()); - logDir.mkdirs(); expireRange = new ExpireRange(trans.env().access()); String sdate = Chrono.dateOnlyStamp(expireRange.now); for( List lr : expireRange.ranges.values()) { for(Range r : lr ) { if(writerList.get(r.name())==null) { - File file = new File(logDir,r.name() + sdate +CSV); + File file = new File(logDir(),r.name() + sdate +CSV); CSV csv = new CSV(file); CSV.Writer cw = csv.writer(false); cw.row(INFO,r.name(),Chrono.dateOnlyStamp(expireRange.now),r.reportingLevel()); @@ -116,7 +113,7 @@ public class Expiring extends Batch { @Override protected void run(AuthzTrans trans) { try { - File file = new File(logDir, EXPIRED_OWNERS + Chrono.dateOnlyStamp(expireRange.now) + CSV); + File file = new File(logDir(), EXPIRED_OWNERS + Chrono.dateOnlyStamp(expireRange.now) + CSV); final CSV ownerCSV = new CSV(file); Map> owners = new TreeMap>(); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NotInOrg.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NotInOrg.java index 2ba5d022..fe754c10 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NotInOrg.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NotInOrg.java @@ -52,7 +52,6 @@ public class NotInOrg extends Batch { private static final String INFO = "info"; private Map writerList; private Map whichWriter; - private File logDir; private Date now; private Writer notInOrgW; private Writer notInOrgDeleteW; @@ -76,12 +75,10 @@ public class NotInOrg extends Batch { // Create Intermediate Output writerList = new HashMap<>(); whichWriter = new TreeMap<>(); - logDir = new File(logDir()); - logDir.mkdirs(); now = new Date(); String sdate = Chrono.dateOnlyStamp(now); - File file = new File(logDir,NOT_IN_ORG + sdate +CSV); + File file = new File(logDir(),NOT_IN_ORG + sdate +CSV); CSV csv = new CSV(file); notInOrgW = csv.writer(false); notInOrgW.row(INFO,NOT_IN_ORG,Chrono.dateOnlyStamp(now),0); @@ -89,7 +86,7 @@ public class NotInOrg extends Batch { // These will have been double-checked by the Organization, and can be deleted immediately. String fn = NOT_IN_ORG+"Delete"; - file = new File(logDir,fn + sdate +CSV); + file = new File(logDir(),fn + sdate +CSV); CSV csvDelete = new CSV(file); notInOrgDeleteW = csvDelete.writer(false); notInOrgDeleteW.row(INFO,fn,Chrono.dateOnlyStamp(now),0); 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 daf51925..547b657f 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 @@ -95,7 +95,7 @@ public class Notify extends Batch { NotifyBody.load(env.access()); // Create Intermediate Output - File logDir = new File(logDir()); + File logDir = logDir(); notifyFile = new ArrayList<>(); if(args().length>0) { for(int i=0;i> theMap; + + public NsRoleUserReport(AuthzTrans trans) throws APIException, IOException, OrganizationException { + super(trans.env()); + trans.info().log("Starting Connection Process"); + + TimeTaken tt0 = trans.start("Cassandra Initialization", Env.SUB); + try { + TimeTaken tt = trans.start("Connect to Cluster", Env.REMOTE); + try { + session = cluster.connect(); + } finally { + tt.done(); + } + + // Create Intermediate Output + now = new Date(); + String sdate = Chrono.dateOnlyStamp(now); + File file = new File(logDir(),REPORT + sdate +CSV); + CSV csv = new CSV(file); + report = csv.writer(false); + + theMap = new TreeMap<>(); + + NS.load(trans, session, NS.v2_0_11); + Role.load(trans, session); + } finally { + tt0.done(); + } + } + + @Override + protected void run(AuthzTrans trans) { + try { + trans.info().log("Create Report on Roles by NS"); + + final AuthzTrans transNoAvg = trans.env().newTransNoAvg(); + UserRole.load(transNoAvg, session, UserRole.v2_0_11, new Visitor() { + @Override + public void visit(UserRole ur) { + if(ur.expires().after(now)) { + Map roleCount = theMap.get(ur.ns()); + Integer count; + if(roleCount==null) { + roleCount = new TreeMap<>(); + theMap.put(ur.ns(),roleCount); + count = 0; + } else { + count = roleCount.get(ur.rname()); + if(count == null) { + count = 0; + } + } + roleCount.put(ur.rname(), count+1); + } + } + }); + + for(Entry> ns_es : theMap.entrySet()) { + for(Entry r_es : ns_es.getValue().entrySet()) { + report.row(ns_es.getKey(),r_es.getKey(),r_es.getValue()); + } + } + + + } finally { + } + } + + @Override + protected void _close(AuthzTrans trans) { + session.close(); + report.close(); + } + +} diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/NotifyCredExpiring.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/NotifyCredExpiring.java index ce008164..4288b2e7 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/NotifyCredExpiring.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/NotifyCredExpiring.java @@ -29,12 +29,10 @@ import java.io.IOException; import java.io.PrintStream; import java.text.ParseException; import java.util.ArrayList; -import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; @@ -42,19 +40,10 @@ import org.onap.aaf.auth.batch.Batch; import org.onap.aaf.auth.batch.BatchPrincipal; import org.onap.aaf.auth.batch.actions.Email; import org.onap.aaf.auth.batch.actions.EmailPrint; -import org.onap.aaf.auth.batch.actions.Message; -import org.onap.aaf.auth.batch.helpers.Cred; -import org.onap.aaf.auth.batch.helpers.NS; import org.onap.aaf.auth.batch.helpers.Notification; import org.onap.aaf.auth.batch.helpers.UserRole; -import org.onap.aaf.auth.batch.helpers.Notification.TYPE; -import org.onap.aaf.auth.dao.hl.Question; import org.onap.aaf.auth.env.AuthzTrans; -import org.onap.aaf.auth.layer.Result; -import org.onap.aaf.auth.org.Organization; -import org.onap.aaf.auth.org.Organization.Identity; import org.onap.aaf.auth.org.OrganizationException; -import org.onap.aaf.auth.org.OrganizationFactory; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.util.CSV; import org.onap.aaf.misc.env.APIException; 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 5f6021b3..f2425f4a 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 @@ -84,7 +84,7 @@ public class Remove extends Batch { final int maxBatch = 25; // Create Intermediate Output - File logDir = new File(logDir()); + File logDir = logDir(); List remove = new ArrayList<>(); if(args().length>0) { -- cgit 1.2.3-korg