summaryrefslogtreecommitdiffstats
path: root/auth/auth-batch/src/main
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2019-01-22 10:27:32 -0600
committerInstrumental <jonathan.gathman@att.com>2019-01-22 10:32:14 -0600
commit12414fe43077e12d7ef711951b1633ad31d73573 (patch)
tree475166cee68c104b2f36625ef864a912aab50fa4 /auth/auth-batch/src/main
parenta5bcce655e339151445fbce2c129687e3bc8610a (diff)
Public and Private Locate entries
Issue-ID: AAF-723 Change-Id: I9dcd2e732ce64b39aaa57a6e9404f275f7ad540c Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth/auth-batch/src/main')
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/Batch.java28
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Expiring.java7
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NotInOrg.java7
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/Notify.java2
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NsRoleUserReport.java127
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/NotifyCredExpiring.java11
-rw-r--r--auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/update/Remove.java2
7 files changed, 151 insertions, 33 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 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<String, CSV.Writer> 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<Range> 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<String, Set<UserRole>> owners = new TreeMap<String, Set<UserRole>>();
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<String, CSV.Writer> writerList;
private Map<String, CSV.Writer> 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<args().length;++i) {
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NsRoleUserReport.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NsRoleUserReport.java
new file mode 100644
index 00000000..8281e747
--- /dev/null
+++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/reports/NsRoleUserReport.java
@@ -0,0 +1,127 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+
+package org.onap.aaf.auth.batch.reports;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+
+import org.onap.aaf.auth.batch.Batch;
+import org.onap.aaf.auth.batch.helpers.NS;
+import org.onap.aaf.auth.batch.helpers.Role;
+import org.onap.aaf.auth.batch.helpers.UserRole;
+import org.onap.aaf.auth.batch.helpers.Visitor;
+import org.onap.aaf.auth.env.AuthzTrans;
+import org.onap.aaf.auth.org.OrganizationException;
+import org.onap.aaf.cadi.util.CSV;
+import org.onap.aaf.cadi.util.CSV.Writer;
+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.util.Chrono;
+
+
+public class NsRoleUserReport extends Batch {
+
+ private static final String REPORT = NsRoleUserReport.class.getSimpleName();
+ private static final String CSV = ".csv";
+ private Date now;
+ private Writer report;
+ private Map<String,Map<String,Integer>> 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<UserRole>() {
+ @Override
+ public void visit(UserRole ur) {
+ if(ur.expires().after(now)) {
+ Map<String, Integer> 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<String, Map<String, Integer>> ns_es : theMap.entrySet()) {
+ for(Entry<String, Integer> 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<File> remove = new ArrayList<>();
if(args().length>0) {