diff options
author | Instrumental <jonathan.gathman@att.com> | 2019-01-22 10:27:32 -0600 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2019-01-22 10:32:14 -0600 |
commit | 12414fe43077e12d7ef711951b1633ad31d73573 (patch) | |
tree | 475166cee68c104b2f36625ef864a912aab50fa4 /auth/auth-batch | |
parent | a5bcce655e339151445fbce2c129687e3bc8610a (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')
9 files changed, 244 insertions, 125 deletions
diff --git a/auth/auth-batch/pom.xml b/auth/auth-batch/pom.xml index c30a32af..1994d9e8 100644 --- a/auth/auth-batch/pom.xml +++ b/auth/auth-batch/pom.xml @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.aaf.authz</groupId> <artifactId>authparent</artifactId> - <version>2.1.9-SNAPSHOT</version> + <version>2.1.10-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> 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) { diff --git a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/creators/RowCreator.java b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/creators/RowCreator.java index 661105d3..6902a426 100644 --- a/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/creators/RowCreator.java +++ b/auth/auth-batch/src/test/java/org/onap/aaf/auth/batch/helpers/creators/RowCreator.java @@ -45,367 +45,367 @@ public class RowCreator { Row row = new Row() { @Override - public boolean isNull(String name) { + public boolean isNull(int i) { // TODO Auto-generated method stub return false; } @Override - public BigInteger getVarint(String name) { + public boolean getBool(int i) { // TODO Auto-generated method stub - return null; + return false; } @Override - public UUID getUUID(String name) { + public byte getByte(int i) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public UDTValue getUDTValue(String name) { + public short getShort(int i) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public TupleValue getTupleValue(String name) { + public int getInt(int i) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public Date getTimestamp(String name) { + public long getLong(int i) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public long getTime(String name) { + public Date getTimestamp(int i) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public String getString(String name) { + public LocalDate getDate(int i) { // TODO Auto-generated method stub return null; } @Override - public short getShort(String name) { + public long getTime(int i) { // TODO Auto-generated method stub return 0; } @Override - public <T> Set<T> getSet(String name, TypeToken<T> elementsType) { + public float getFloat(int i) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public <T> Set<T> getSet(String name, Class<T> elementsClass) { + public double getDouble(int i) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public Object getObject(String name) { + public ByteBuffer getBytesUnsafe(int i) { // TODO Auto-generated method stub return null; } @Override - public <K, V> Map<K, V> getMap(String name, TypeToken<K> keysType, TypeToken<V> valuesType) { + public ByteBuffer getBytes(int i) { // TODO Auto-generated method stub return null; } @Override - public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass) { + public String getString(int i) { // TODO Auto-generated method stub return null; } @Override - public long getLong(String name) { + public BigInteger getVarint(int i) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public <T> List<T> getList(String name, TypeToken<T> elementsType) { + public BigDecimal getDecimal(int i) { // TODO Auto-generated method stub return null; } @Override - public <T> List<T> getList(String name, Class<T> elementsClass) { + public UUID getUUID(int i) { // TODO Auto-generated method stub return null; } @Override - public int getInt(String name) { + public InetAddress getInet(int i) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public InetAddress getInet(String name) { + public <T> List<T> getList(int i, Class<T> elementsClass) { // TODO Auto-generated method stub return null; } @Override - public float getFloat(String name) { + public <T> List<T> getList(int i, TypeToken<T> elementsType) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public double getDouble(String name) { + public <T> Set<T> getSet(int i, Class<T> elementsClass) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public BigDecimal getDecimal(String name) { + public <T> Set<T> getSet(int i, TypeToken<T> elementsType) { // TODO Auto-generated method stub return null; } @Override - public LocalDate getDate(String name) { + public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass) { // TODO Auto-generated method stub return null; } @Override - public ByteBuffer getBytesUnsafe(String name) { + public <K, V> Map<K, V> getMap(int i, TypeToken<K> keysType, TypeToken<V> valuesType) { // TODO Auto-generated method stub return null; } @Override - public ByteBuffer getBytes(String name) { + public UDTValue getUDTValue(int i) { // TODO Auto-generated method stub return null; } @Override - public byte getByte(String name) { + public TupleValue getTupleValue(int i) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public boolean getBool(String name) { + public Object getObject(int i) { // TODO Auto-generated method stub - return false; + return null; } @Override - public <T> T get(String name, TypeCodec<T> codec) { + public <T> T get(int i, Class<T> targetClass) { // TODO Auto-generated method stub return null; } @Override - public <T> T get(String name, TypeToken<T> targetType) { + public <T> T get(int i, TypeToken<T> targetType) { // TODO Auto-generated method stub return null; } @Override - public <T> T get(String name, Class<T> targetClass) { + public <T> T get(int i, TypeCodec<T> codec) { // TODO Auto-generated method stub return null; } @Override - public boolean isNull(int i) { + public boolean isNull(String name) { // TODO Auto-generated method stub return false; } @Override - public BigInteger getVarint(int i) { + public boolean getBool(String name) { // TODO Auto-generated method stub - return null; + return false; } @Override - public UUID getUUID(int i) { + public byte getByte(String name) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public UDTValue getUDTValue(int i) { + public short getShort(String name) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public TupleValue getTupleValue(int i) { + public int getInt(String name) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public Date getTimestamp(int i) { + public long getLong(String name) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public long getTime(int i) { + public Date getTimestamp(String name) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public String getString(int i) { + public LocalDate getDate(String name) { // TODO Auto-generated method stub return null; } @Override - public short getShort(int i) { + public long getTime(String name) { // TODO Auto-generated method stub return 0; } @Override - public <T> Set<T> getSet(int i, TypeToken<T> elementsType) { + public float getFloat(String name) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public <T> Set<T> getSet(int i, Class<T> elementsClass) { + public double getDouble(String name) { // TODO Auto-generated method stub - return null; + return 0; } @Override - public Object getObject(int i) { + public ByteBuffer getBytesUnsafe(String name) { // TODO Auto-generated method stub return null; } @Override - public <K, V> Map<K, V> getMap(int i, TypeToken<K> keysType, TypeToken<V> valuesType) { + public ByteBuffer getBytes(String name) { // TODO Auto-generated method stub return null; } @Override - public <K, V> Map<K, V> getMap(int i, Class<K> keysClass, Class<V> valuesClass) { + public String getString(String name) { // TODO Auto-generated method stub return null; } @Override - public long getLong(int i) { + public BigInteger getVarint(String name) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public <T> List<T> getList(int i, TypeToken<T> elementsType) { + public BigDecimal getDecimal(String name) { // TODO Auto-generated method stub return null; } @Override - public <T> List<T> getList(int i, Class<T> elementsClass) { + public UUID getUUID(String name) { // TODO Auto-generated method stub return null; } @Override - public int getInt(int i) { + public InetAddress getInet(String name) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public InetAddress getInet(int i) { + public <T> List<T> getList(String name, Class<T> elementsClass) { // TODO Auto-generated method stub return null; } @Override - public float getFloat(int i) { + public <T> List<T> getList(String name, TypeToken<T> elementsType) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public double getDouble(int i) { + public <T> Set<T> getSet(String name, Class<T> elementsClass) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public BigDecimal getDecimal(int i) { + public <T> Set<T> getSet(String name, TypeToken<T> elementsType) { // TODO Auto-generated method stub return null; } @Override - public LocalDate getDate(int i) { + public <K, V> Map<K, V> getMap(String name, Class<K> keysClass, Class<V> valuesClass) { // TODO Auto-generated method stub return null; } @Override - public ByteBuffer getBytesUnsafe(int i) { + public <K, V> Map<K, V> getMap(String name, TypeToken<K> keysType, TypeToken<V> valuesType) { // TODO Auto-generated method stub return null; } @Override - public ByteBuffer getBytes(int i) { + public UDTValue getUDTValue(String name) { // TODO Auto-generated method stub return null; } @Override - public byte getByte(int i) { + public TupleValue getTupleValue(String name) { // TODO Auto-generated method stub - return 0; + return null; } @Override - public boolean getBool(int i) { + public Object getObject(String name) { // TODO Auto-generated method stub - return false; + return null; } @Override - public <T> T get(int i, TypeCodec<T> codec) { + public <T> T get(String name, Class<T> targetClass) { // TODO Auto-generated method stub return null; } @Override - public <T> T get(int i, TypeToken<T> targetType) { + public <T> T get(String name, TypeToken<T> targetType) { // TODO Auto-generated method stub return null; } @Override - public <T> T get(int i, Class<T> targetClass) { + public <T> T get(String name, TypeCodec<T> codec) { // TODO Auto-generated method stub return null; } @Override - public Token getToken(String name) { + public ColumnDefinitions getColumnDefinitions() { // TODO Auto-generated method stub return null; } @@ -417,16 +417,17 @@ public class RowCreator { } @Override - public Token getPartitionKeyToken() { + public Token getToken(String name) { // TODO Auto-generated method stub return null; } @Override - public ColumnDefinitions getColumnDefinitions() { + public Token getPartitionKeyToken() { // TODO Auto-generated method stub return null; } + }; return row; } |