diff options
Diffstat (limited to 'auth/auth-batch/src')
4 files changed, 50 insertions, 8 deletions
diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java index b626bae7..d62c7781 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java @@ -20,6 +20,7 @@ package org.onap.aaf.auth.batch.helpers; +import org.onap.aaf.cadi.Access; import org.onap.aaf.misc.env.LogTarget; import com.datastax.driver.core.ResultSet; @@ -30,12 +31,15 @@ public class CQLBatch { private StringBuilder sb; private int hasAdded; private LogTarget log; + private long sleep; + private long last; public CQLBatch(LogTarget log, Session session) { this.log = log; this.session = session; sb = new StringBuilder(); hasAdded = 0; + sleep = 0L; } public StringBuilder begin() { sb.setLength(0); @@ -56,6 +60,17 @@ public class CQLBatch { public ResultSet execute() { if(end()) { + if(sleep>0) { + long left = last - System.currentTimeMillis(); + if(left>0) { + try { + Thread.sleep(left); + } catch (InterruptedException e) { + Access.NULL.log(e); // Keep code check idiocy at bay + } + } + last = System.currentTimeMillis()+sleep; + } return session.execute(sb.toString()); } else { return null; @@ -65,6 +80,17 @@ public class CQLBatch { public ResultSet execute(boolean dryRun) { ResultSet rv = null; if(dryRun) { + if(sleep>0) { + long left = last - System.currentTimeMillis(); + if(left>0) { + try { + Thread.sleep(left); + } catch (InterruptedException e) { + Access.NULL.log(e); // Keep code check idiocy at bay + } + } + last = System.currentTimeMillis()+sleep; + } end(); } else { rv = execute(); @@ -93,6 +119,10 @@ public class CQLBatch { execute(dryRun); } + public void sleep(int j) { + sleep = j*1000; + } + public String toString() { return sb.toString(); } diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatchLoop.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatchLoop.java index 2604364b..1a1bdf33 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatchLoop.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatchLoop.java @@ -32,7 +32,7 @@ public class CQLBatchLoop { private int batches; private final StringBuilder current; private boolean showProgress; - + public CQLBatchLoop(CQLBatch cb, int max, boolean dryRun) { cqlBatch = cb; i=0; diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java index 1f5a1f40..83638cc7 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java @@ -21,6 +21,7 @@ package org.onap.aaf.auth.batch.helpers; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.GregorianCalendar; @@ -139,7 +140,7 @@ public class Cred { } public static void loadOneNS(Trans trans, Session session, String ns,int ... types ) { - load(trans, session,"select id, type, expires, other, writetime(cred), tag from authz.cred WHERE ns='" + ns + "';"); + load(trans, session,"select id, type, expires, other, writetime(cred), tag from authz.cred WHERE ns='" + ns + "';", types); } private static void load(Trans trans, Session session, String query, int ...types) { @@ -315,16 +316,22 @@ public class Cred { inst.expires.getTime(),inst.tag,reason); } - + static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+SSSS"); public static void batchDelete(StringBuilder sb, List<String> row) { + Long l = Long.parseLong(row.get(5)); + String date = sdf.format(new Date(l)); sb.append("DELETE from authz.cred WHERE id='"); sb.append(row.get(1)); sb.append("' AND type="); sb.append(Integer.parseInt(row.get(3))); // Note: We have to work with long, because Expires is part of Key... can't easily do date. - sb.append(" AND expires=dateof(maxtimeuuid("); - sb.append(row.get(5)); - sb.append("));\n"); + sb.append(" AND expires='"); + sb.append(date); + sb.append("';\n"); +// sb.append(" AND expires=dateof(maxtimeuuid("); +// sb.append(row.get(5)); +// sb.append("));\n"); + } public String toString() { diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/X509.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/X509.java index c68a9945..e2d86947 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/X509.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/X509.java @@ -59,10 +59,15 @@ public class X509 { public static void load(Trans trans, Session session, Visitor<X509> visitor) { - load(trans,session,"select ca, id, x500, x509, serial from authz.x509;", visitor); + load(trans,session, "" , visitor); } + + public static void load(Trans trans, Session session, String where, Visitor<X509> visitor) { + load(trans,session, visitor,"select ca, id, x500, x509, serial from authz.x509 " + where +';'); + } + - private static void load(Trans trans, Session session, String query, Visitor<X509> visitor) { + private static void load(Trans trans, Session session, Visitor<X509> visitor, String query) { trans.info().log( "query: " + query ); TimeTaken tt = trans.start("Read X509", Env.REMOTE); |