X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Faaf%2Fv2_0%2FAAFLocator.java;h=3611e481a414b9c5ccf01de7e16ef142eb24517c;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=a993109ad7abbbe1f5b074492049ebfe8b2877bb;hpb=1aba148a7ff88c8f43762da19fa4c757c62732c5;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.java index a993109a..3611e481 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.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. @@ -38,6 +38,8 @@ import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.config.SecurityInfoC; import org.onap.aaf.cadi.http.HClient; import org.onap.aaf.cadi.locator.DNSLocator; +import org.onap.aaf.cadi.locator.SingleEndpointLocator; +import org.onap.aaf.cadi.locator.SizedLocator; import org.onap.aaf.cadi.util.FixURIinfo; import org.onap.aaf.cadi.util.Split; import org.onap.aaf.misc.env.APIException; @@ -54,7 +56,7 @@ public class AAFLocator extends AbsAAFLocator { private HClient client; private HClient lclient; private RosettaDF epsDF; - private DNSLocator locatorLocator; + private SizedLocator locatorLocator; private Item locatorItem; @@ -65,7 +67,7 @@ public class AAFLocator extends AbsAAFLocator { env = new RosettaEnv(access.getProperties()); } } - + int connectTimeout = Integer.parseInt(si.access.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); try { String[] path = Split.split('/',locatorURI.getPath()); @@ -84,27 +86,32 @@ public class AAFLocator extends AbsAAFLocator { client = new HClient(si.defSS, locatorURI, connectTimeout); } epsDF = env.newDataFactory(Endpoints.class); - + } catch (APIException /*| URISyntaxException*/ e) { throw new LocatorException(e); } lclient = new HClient(si.defSS, locatorURI, connectTimeout); - + if(si.access.willLog(Access.Level.DEBUG)) { si.access.log(Access.Level.DEBUG, "Root URI:",client.getURI()); } - + String dnsString; if(locatorURI.getPort()<0) { - dnsString=locatorURI.getScheme() + "://" + locatorURI.getHost(); + dnsString=locatorURI.getScheme() + "://" + locatorURI.getHost(); } else { - dnsString=locatorURI.getScheme() + "://" +locatorURI.getHost()+':'+locatorURI.getPort(); + dnsString=locatorURI.getScheme() + "://" +locatorURI.getHost()+':'+locatorURI.getPort(); } if(dnsString.contains("null")) { // for Testing Purposes, mostly. - locatorLocator = null; + locatorLocator = null; } else { - locatorLocator = new DNSLocator(access, dnsString); - locatorItem = locatorLocator.best(); + locatorLocator = new DNSLocator(access, dnsString); + if(locatorLocator.hasItems()) { + locatorItem = locatorLocator.best(); + } else { + // For when DNS doesn't work, including some K8s Installations + locatorLocator = new SingleEndpointLocator(dnsString); + } } } @@ -122,6 +129,7 @@ public class AAFLocator extends AbsAAFLocator { } protected final int maxIters() { + return locatorLocator.size(); } @@ -158,7 +166,7 @@ public class AAFLocator extends AbsAAFLocator { for (Endpoint endpoint : fr.value.getEndpoint()) { epl.add(new EP(endpoint,latitude,longitude)); } - + Collections.sort(epl); replace(epl); return true; @@ -178,9 +186,9 @@ public class AAFLocator extends AbsAAFLocator { protected URI getURI() { return client.getURI(); } - + protected HClient createClient(SecuritySetter ss, URI uri, int connectTimeout) throws LocatorException { return new HClient(ss, uri, connectTimeout); } - + }