X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cass%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fdao%2Fcass%2FCacheInfoDAO.java;h=6a32a365ed22057a3550e7bcc8a1699995289d2d;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=0ad15277f22020dcd78dca0837e440dc8b48e49d;hpb=688cf884979c1a7d753baf6a1223c1a3a87c39f5;p=aaf%2Fauthz.git diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java index 0ad15277..6a32a365 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java @@ -3,13 +3,15 @@ * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * + * Modification Copyright (c) 2019 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. @@ -67,12 +69,17 @@ public class CacheInfoDAO extends CassDAOImpl impl public static final Map info = new ConcurrentHashMap<>(); private static CacheUpdate cacheUpdate; - + // Hold current time stamps from Tables private final Date startTime; - private final boolean cacheNotify; + private final boolean cacheNotify; private PreparedStatement psCheck; - + + ////////////////////////////////////////// + // Data Definition, matches Cassandra DM + ////////////////////////////////////////// + private static final int KEYLIMIT = 2; + public CacheInfoDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { super(trans, CacheInfoDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE,readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); startTime = new Date(); @@ -80,31 +87,30 @@ public class CacheInfoDAO extends CassDAOImpl impl init(trans); } - public CacheInfoDAO(AuthzTrans trans, AbsCassDAO aDao) throws APIException, IOException { + public CacheInfoDAO(AuthzTrans trans, AbsCassDAO aDao) throws APIException, IOException { super(trans, CacheInfoDAO.class.getSimpleName(),aDao,Data.class,TABLE,readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); startTime = new Date(); init(trans); cacheNotify = noK8s(trans); } - /** - * Need a different point to point cache clear strategy for K8s... - * @param trans - * @return - */ + /** + * Need a different point to point cache clear strategy for K8s... + * @param trans + * @return + */ private boolean noK8s(AuthzTrans trans) { - String container = trans.getProperty(Config.AAF_LOCATOR_CONTAINER); - return ! ("helm".equals(container) || "oom".equals(container)); - } - - ////////////////////////////////////////// - // Data Definition, matches Cassandra DM - ////////////////////////////////////////// - private static final int KEYLIMIT = 2; + String container = trans.getProperty(Config.AAF_LOCATOR_CONTAINER); + return ! ("helm".equals(container) || "oom".equals(container)); + } /** * @author Jonathan */ public static class Data { + public String name; + public int seg; + public Date touched; + public Data() { name = null; touched = null; @@ -114,19 +120,15 @@ public class CacheInfoDAO extends CassDAOImpl impl this.seg = seg; touched = null; } - - public String name; - public int seg; - public Date touched; } private static class InfoLoader extends Loader { public static final InfoLoader dflt = new InfoLoader(KEYLIMIT); - + public InfoLoader(int keylimit) { super(keylimit); } - + @Override public Data load(Data data, Row row) { // Int more efficient @@ -137,8 +139,8 @@ public class CacheInfoDAO extends CassDAOImpl impl } @Override - protected void key(Data data, int _idx, Object[] obj) { - int idx = _idx; + protected void key(Data data, int idxParam, Object[] obj) { + int idx = idxParam; obj[idx]=data.name; obj[++idx]=data.seg; @@ -149,10 +151,11 @@ public class CacheInfoDAO extends CassDAOImpl impl obj[idx]=data.touched; } } - + public static synchronized void startUpdate(AuthzEnv env, HMangr hman, SecuritySetter ss, String ip, int port) { if (cacheUpdate==null) { - Thread t= new Thread(cacheUpdate = new CacheUpdate(env,hman,ss, ip,port),"CacheInfo Update Thread"); + cacheUpdate = new CacheUpdate(env,hman,ss, ip,port); + Thread t= new Thread(cacheUpdate,"CacheInfo Update Thread"); t.setDaemon(true); t.start(); } @@ -164,7 +167,7 @@ public class CacheInfoDAO extends CassDAOImpl impl } } - private final static class CacheUpdate extends Thread { + private static final class CacheUpdate extends Thread { public static BlockingQueue notifyDQ = new LinkedBlockingQueue(2000); private static final String VOID_CT="application/Void+json;q=1.0;charset=utf-8;version=2.0,application/json;q=1.0;version=2.0,*/*;q=1.0"; @@ -173,15 +176,15 @@ public class CacheInfoDAO extends CassDAOImpl impl private SecuritySetter ss; private final String authority; public boolean go = true; - + public CacheUpdate(AuthzEnv env, HMangr hman, SecuritySetter ss, String ip, int port) { this.env = env; this.hman = hman; this.ss = ss; - + this.authority = ip+':'+port; } - + private static class Transfer { public String table; public int segs[]; @@ -195,7 +198,7 @@ public class CacheInfoDAO extends CassDAOImpl impl private AuthzTrans trans; private String type; private String segs; - + public CacheClear(AuthzTrans trans) { this.trans = trans; } @@ -204,7 +207,7 @@ public class CacheInfoDAO extends CassDAOImpl impl type = es.getKey(); segs = es.getValue().toString(); } - + @Override public Integer code(Rcli client) throws APIException, CadiException { URI to = client.getURI(); @@ -219,11 +222,11 @@ public class CacheInfoDAO extends CassDAOImpl impl return total; } } - + private class IntHolder { private int[] raw; HashSet set; - + public IntHolder(int ints[]) { raw = ints; set = null; @@ -231,7 +234,7 @@ public class CacheInfoDAO extends CassDAOImpl impl public void add(int[] ints) { if (set==null) { set = new HashSet<>(); - + for (int i=0;i impl return sb.toString(); } } - + @Override public void run() { do { @@ -276,7 +279,7 @@ public class CacheInfoDAO extends CassDAOImpl impl if (data==null) { continue; } - + int count = 0; CacheClear cc = null; Map gather = null; @@ -316,7 +319,7 @@ public class CacheInfoDAO extends CassDAOImpl impl sb.append(count); if (count==1) { sb.append(" entry for "); - } else { + } else { sb.append(" entries for "); } int peers = count<=0?0:cc.total/count; @@ -351,13 +354,13 @@ public class CacheInfoDAO extends CassDAOImpl impl /* (non-Javadoc) * @see org.onap.aaf.auth.dao.cass.CIDAO#touch(org.onap.aaf.auth.env.test.AuthzTrans, java.lang.String, int) */ - + @Override public Result touch(AuthzTrans trans, String name, int ... seg) { ///////////// // Direct Service Cache Invalidation ///////////// - // ConcurrentQueues are open-ended. We don't want any Memory leaks + // ConcurrentQueues are open-ended. We don't want any Memory leaks // Note: we keep a separate counter, because "size()" on a Linked Queue is expensive if (cacheNotify && cacheUpdate!=null) { try { @@ -386,7 +389,7 @@ public class CacheInfoDAO extends CassDAOImpl impl sb.append(name); sb.append("' AND seg = "); sb.append(s); - sb.append(";\n"); + sb.append(";\n"); if (first) { first =false; } else { @@ -422,7 +425,7 @@ public class CacheInfoDAO extends CassDAOImpl impl } finally { tt.done(); } - + String lastName = null; Date[] dates = null; for (Row row : rs.all()) { @@ -448,7 +451,7 @@ public class CacheInfoDAO extends CassDAOImpl impl } return Result.ok(); } - + /* (non-Javadoc) * @see org.onap.aaf.auth.dao.cass.CIDAO#get(java.lang.String, int) */