diff options
author | Instrumental <jonathan.gathman@att.com> | 2019-04-30 10:19:21 -0500 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2019-04-30 10:52:03 -0500 |
commit | f64f482462b697e06a47ad55aa5447dc829ce727 (patch) | |
tree | c7f107b2791a91347cf8a91a61ebfdc95fcc6cdf /auth/auth-batch | |
parent | 2e76b4d7522a1fb2bf571eb8abcbcff4e97e06fc (diff) |
Clean LOCAL Dir based on VERSION
Issue-ID: AAF-821
Change-Id: I5fde81467d46130d3a39de415604c7702fecbaa8
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'auth/auth-batch')
4 files changed, 122 insertions, 15 deletions
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Approval.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Approval.java index 8aee4f8a..ce19865a 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Approval.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Approval.java @@ -231,18 +231,6 @@ public class Approval implements CacheChange.Data { } }; -// /** -// * @return the lastNotified -// */ -// public Date getLast_notified() { -// return add.last_notified; -// } -// /** -// * @param lastNotified the lastNotified to set -// */ -// public void setLastNotified(Date last_notified) { -// add.last_notified = last_notified; -// } /** * @return the status */ diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NS.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NS.java index 55fe22ce..dbafdc04 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NS.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NS.java @@ -28,9 +28,11 @@ import java.util.Map; import java.util.TreeMap; import org.onap.aaf.auth.dao.cass.NsDAO; +import org.onap.aaf.cadi.util.CSV; 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; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; @@ -67,17 +69,29 @@ public class NS implements Comparable<NS> { public static void load(Trans trans, Session session, Creator<NS> creator) { load(trans,session, "select name, description, parent, type, scope from authz.ns;" - ,creator); + ,creator + , v -> data.put(v.ndd.name,v) + ); } public static void loadOne(Trans trans, Session session, Creator<NS> creator, String ns) { load(trans,session, ("select name, description, parent, type, scope from authz.ns WHERE name='"+ns+"';") ,creator + , v -> data.put(v.ndd.name,v) ); } - private static void load(Trans trans, Session session, String query, Creator<NS> creator) { + public static void load(Trans trans, Session session, Creator<NS> creator, Visitor<NS> visitor) { + load(trans,session,creator.query(null),creator, visitor); + } + + public void row(final CSV.Writer csvw, String tag) { + csvw.row(tag,ndd.name,ndd.type,ndd.parent); + } + + + private static void load(Trans trans, Session session, String query, Creator<NS> creator, Visitor<NS> visitor) { trans.info().log( "query: " + query ); ResultSet results; TimeTaken tt; @@ -99,7 +113,7 @@ public class NS implements Comparable<NS> { while (iter.hasNext()) { row = iter.next(); NS ns = creator.create(row); - data.put(ns.ndd.name,ns); + visitor.visit(ns); } } finally { tt.done(); diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NsAttrib.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NsAttrib.java new file mode 100644 index 00000000..f5e36fa1 --- /dev/null +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/NsAttrib.java @@ -0,0 +1,85 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2018 IBM. + * =========================================================================== + * 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.helpers; + +import org.onap.aaf.misc.env.Env; +import org.onap.aaf.misc.env.TimeTaken; +import org.onap.aaf.misc.env.Trans; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; + +public class NsAttrib { + + public final String ns; + public final String key; + public final String value; + + + public NsAttrib(String ns, String key, String value) { + this.ns = ns; + this.key = key; + this.value = value; + } + + public static Creator<NsAttrib> v2_0_11 = new Creator<NsAttrib>() { + @Override + public NsAttrib create(Row row) { + return new NsAttrib(row.getString(0), row.getString(1), row.getString(2)); + } + + @Override + public String select() { + return "select ns,key,value from authz.ns_attrib"; + } + }; + + public static void load(Trans trans, Session session, Creator<NsAttrib> creator, Visitor<NsAttrib> visitor) { + trans.info().log( "query: " + creator.select() ); + ResultSet results; + TimeTaken tt = trans.start("Load NsAttributes", Env.REMOTE); + try { + Statement stmt = new SimpleStatement(creator.select()); + results = session.execute(stmt); + } finally { + tt.done(); + } + int count = 0; + tt = trans.start("Process NsAttributes", Env.SUB); + + try { + for (Row row : results.all()) { + ++count; + visitor.visit(creator.create(row)); + } + } finally { + tt.done(); + trans.info().log("Found",count,"NS Attributes"); + } + } +} + diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/UserRole.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/UserRole.java index b4e1a6d3..96169434 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/UserRole.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/UserRole.java @@ -21,6 +21,7 @@ package org.onap.aaf.auth.batch.helpers; +import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; import java.util.Date; @@ -32,6 +33,7 @@ import java.util.TreeMap; import org.onap.aaf.auth.dao.cass.UserRoleDAO; import org.onap.aaf.auth.dao.cass.UserRoleDAO.Data; import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.util.CSV; import org.onap.aaf.misc.env.Env; import org.onap.aaf.misc.env.TimeTaken; @@ -124,6 +126,14 @@ public class UserRole implements Cloneable, CacheChange.Data { load(trans,session,creator,"user='"+ user +'\'',visitor); } + public static void load(Trans trans, CSV csv, Creator<UserRole> creator, Visitor<UserRole> visitor) throws IOException, CadiException { +// public UserRole(String user, String role, String ns, String rname, Date expires) { + csv.visit( row -> { + visitor.visit(new UserRole(row.get(1),row.get(2),row.get(3),row.get(4), + new Date(Long.parseLong(row.get(6))))); + }); + } + private static void load(Trans trans, Session session, Creator<UserRole> creator, String where, Visitor<UserRole> visitor) { String query = creator.query(where); trans.debug().log( "query: " + query ); @@ -330,6 +340,16 @@ public class UserRole implements Cloneable, CacheChange.Data { sb.append("';\n"); } + public void batchExtend(StringBuilder sb, Date newDate) { + sb.append("UPDATE authz.user_role SET expires='"); + sb.append(Chrono.dateTime(newDate)); + sb.append("' WHERE user='"); + sb.append(user()); + sb.append("' AND role='"); + sb.append(role()); + sb.append("';\n"); + } + public void batchUpdateExpires(StringBuilder sb) { sb.append("UPDATE authz.user_role SET expires='"); sb.append(Chrono.dateTime(expires())); |