X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cass%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fdao%2FCassAccess.java;h=4246d3140e2942e77d78fd29e2ae3f5d9729870d;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=9b168a8373cd8f9c22d0dd5dbfcf03eb2be03a73;hpb=4b5a7d721d994a49057e9bfb403c7bff1b376660;p=aaf%2Fauthz.git diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java index 9b168a83..4246d314 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java @@ -7,9 +7,9 @@ * 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. @@ -34,6 +34,7 @@ import org.onap.aaf.misc.env.util.Split; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Cluster.Builder; +import com.datastax.driver.core.SocketOptions; import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; import com.datastax.driver.core.policies.TokenAwarePolicy; @@ -64,9 +65,9 @@ public class CassAccess { // @SuppressWarnings("deprecation") public static synchronized Cluster cluster(Env env, String prefix) throws APIException, IOException { - if(cb == null) { + if (cb == null) { String pre; - if(prefix==null) { + if (prefix==null) { pre=""; } else { env.info().log("Cassandra Connection for ",prefix); @@ -74,67 +75,67 @@ public class CassAccess { } cb = Cluster.builder(); String str = env.getProperty(pre+CASSANDRA_CLUSTERS_PORT,env.getProperty(CASSANDRA_CLUSTERS_PORT,"9042")); - if(str!=null) { + if (str!=null) { env.init().log("Cass Port = ",str ); cb.withPort(Integer.parseInt(str)); } str = env.getProperty(pre+CASSANDRA_CLUSTERS_USER_NAME,env.getProperty(CASSANDRA_CLUSTERS_USER_NAME,null)); - if(str!=null) { + if (str!=null) { env.init().log("Cass User = ",str ); String epass = env.getProperty(pre + CASSANDRA_CLUSTERS_PASSWORD,env.getProperty(CASSANDRA_CLUSTERS_PASSWORD,null)); - if(epass==null) { + if (epass==null) { throw new APIException("No Password configured for " + str); } //TODO Figure out way to ensure Decryptor setting in AuthzEnv - if(env instanceof AuthzEnv) { + if (env instanceof AuthzEnv) { cb.withCredentials(str,((AuthzEnv)env).decrypt(epass,true)); } else { cb.withCredentials(str, env.decryptor().decrypt(epass)); } } - + str = env.getProperty(pre+CASSANDRA_RESET_EXCEPTIONS,env.getProperty(CASSANDRA_RESET_EXCEPTIONS,null)); - if(str!=null) { + if (str!=null) { env.init().log("Cass ResetExceptions = ",str ); - for(String ex : Split.split(',', str)) { + for (String ex : Split.split(',', str)) { resetExceptions.add(new Resettable(env,ex)); } } - + str = env.getProperty(Config.CADI_LATITUDE); - Double lat = str!=null?Double.parseDouble(str):null; + Double lat = str!=null && !str.isEmpty()?Double.parseDouble(str):null; str = env.getProperty(Config.CADI_LONGITUDE); - Double lon = str!=null?Double.parseDouble(str):null; - if(lat == null || lon == null) { + Double lon = str!=null && !str.isEmpty()?Double.parseDouble(str):null; + if (lat == null || lon == null) { throw new APIException(Config.CADI_LATITUDE + " and/or " + Config.CADI_LONGITUDE + " are not set"); } - + env.init().printf("Service Latitude,Longitude = %f,%f",lat,lon); - + str = env.getProperty(pre+CASSANDRA_CLUSTERS,env.getProperty(CASSANDRA_CLUSTERS,"localhost")); - env.init().log("Cass Clusters = ",str ); + env.init().printf("Cass Clusters = '%s'\n",str ); String[] machs = Split.split(',', str); String[] cpoints = new String[machs.length]; String bestDC = null; int numInBestDC = 1; double mlat, mlon,temp,distance = Double.MAX_VALUE; - for(int i=0;i0) { + if (minfo.length>0) { cpoints[i]=minfo[0]; } - - if(minfo.length>3) { - if(minfo[1].equals(bestDC)) { + + if (minfo.length>3) { + if (minfo[1].equals(bestDC)) { ++numInBestDC; } else { // Calc closest DC with Great Circle mlat = Double.parseDouble(minfo[2]); mlon = Double.parseDouble(minfo[3]); // Note: GreatCircle Distance is always >= 0.0 (not negative) - if((temp=GreatCircle.calc(lat, lon, mlat, mlon)) < distance) { + if ((temp=GreatCircle.calc(lat, lon, mlat, mlon)) < distance) { distance = temp; - if(bestDC==null || !bestDC.equals(minfo[1])) { + if (bestDC==null || !bestDC.equals(minfo[1])) { bestDC = minfo[1]; numInBestDC = 1; } @@ -142,10 +143,10 @@ public class CassAccess { } } } - + cb.addContactPoints(cpoints); - - if(bestDC!=null) { + + if (bestDC!=null) { // 8/26/2016 Management has determined that Accuracy is preferred over speed in bad situations // Local DC Aware Load Balancing appears to have the highest normal performance, with the best // Degraded Accuracy @@ -162,27 +163,28 @@ public class CassAccess { env.init().printf("Cassandra is using Default Policy, which is not DC aware"); } } + cb.withSocketOptions(new SocketOptions().setReadTimeoutMillis(6500000)); return cb.build(); } - + private static class Resettable { private Class cls; private List messages; - + @SuppressWarnings("unchecked") public Resettable(Env env, String propData) throws APIException { - if(propData!=null && propData.length()>1) { + if (propData!=null && propData.length()>1) { String[] split = Split.split(':', propData); - if(split.length>0) { + if (split.length>0) { try { cls = (Class)Class.forName(split[0]); } catch (ClassNotFoundException e) { throw new APIException("Declared Cassandra Reset Exception, " + propData + ", cannot be ClassLoaded"); } } - if(split.length>1) { + if (split.length>1) { messages=new ArrayList<>(); - for(int i=1;i