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=a993109ad7abbbe1f5b074492049ebfe8b2877bb;hb=6309ef454e6960d95d13534645e1f15904de6862;hp=00a4056857d3d381cec8784324500b0d0fbc6627;hpb=6261a19e61138e861f5c7eaf37835205f19f1fe0;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 00a40568..a993109a 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 @@ -28,6 +28,8 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +import org.onap.aaf.cadi.Access; +import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.SecuritySetter; @@ -35,6 +37,8 @@ import org.onap.aaf.cadi.client.Future; 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.util.FixURIinfo; import org.onap.aaf.cadi.util.Split; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.Data.TYPE; @@ -46,95 +50,137 @@ import locate.v1_0.Endpoint; import locate.v1_0.Endpoints; public class AAFLocator extends AbsAAFLocator { - private static RosettaEnv env; - HClient client; - private RosettaDF epsDF; + private static RosettaEnv env; + private HClient client; + private HClient lclient; + private RosettaDF epsDF; + private DNSLocator locatorLocator; + private Item locatorItem; - public AAFLocator(SecurityInfoC si, URI locatorURI) throws LocatorException { - super(si.access, nameFromLocatorURI(locatorURI), 10000L /* Wait at least 10 seconds between refreshes */); - synchronized(sr) { - if(env==null) { - 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()); - String host = locatorURI.getHost(); - if(host==null) { - host = locatorURI.getAuthority(); // this happens when no port - } - if("AAF_LOCATE_URL".equals(host)) { - URI uri = new URI( - locatorURI.getScheme(), - locatorURI.getUserInfo(), - aaf_locator_uri.getHost(), - aaf_locator_uri.getPort(), - "/locate"+locatorURI.getPath(), - null, - null - ); - client = createClient(si.defSS, uri, connectTimeout); - } else if(path.length>1 && "locate".equals(path[1])) { - StringBuilder sb = new StringBuilder(); - for(int i=3;i fr = client.futureRead(epsDF, TYPE.JSON); - if(fr.get(client.timeout())) { - List epl = new LinkedList<>(); - for(Endpoint endpoint : fr.value.getEndpoint()) { - epl.add(new EP(endpoint,latitude,longitude)); - } - - Collections.sort(epl); - replace(epl); - return true; - } else { - env.error().printf("Error reading location information from %s: %d %s\n",client.getURI().toString(),fr.code(),fr.body()); - } - } catch (CadiException | URISyntaxException | APIException e) { - env.error().log(e,"Error connecting " + client.getURI() + " for location."); - } - return false; - } + public AAFLocator(SecurityInfoC si, URI locatorURI) throws LocatorException { + super(si.access, nameFromLocatorURI(locatorURI), 10000L /* Wait at least 10 seconds between refreshes */); + synchronized(sr) { + if (env==null) { + 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()); + FixURIinfo fui = new FixURIinfo(locatorURI); + if ("AAF_LOCATE_URL".equals(fui.getHost())) { + client = createClient(si.defSS, locatorURI, connectTimeout); + } else if (path.length>1 && "locate".equals(path[1])) { + StringBuilder sb = new StringBuilder(); + for (int i=3;i ss, URI uri, int connectTimeout) throws LocatorException { - return new HClient(ss, uri, connectTimeout); - } + private URI locatorFail(URI uri) throws LocatorException, URISyntaxException { + locatorLocator.invalidate(locatorItem); + locatorItem = locatorLocator.best(); + URI newURI = locatorLocator.get(locatorItem); + return new URI(uri.getScheme(), + uri.getUserInfo(), + newURI.getHost(), + newURI.getPort(), + uri.getPath(), + uri.getQuery(), + uri.getFragment()); + } + + protected final int maxIters() { + return locatorLocator.size(); + } + + + @Override + public boolean refresh() { + try { + int max = locatorLocator.size(); + for(int i=0;i fr = lclient.futureRead(epsDF, TYPE.JSON); + if (fr.get(lclient.timeout())) { + List epl = new LinkedList<>(); + for (Endpoint endpoint : fr.value.getEndpoint()) { + epl.add(new EP(endpoint,latitude,longitude)); + } + + Collections.sort(epl); + replace(epl); + return true; + } else { + env.error().printf("Error reading location information from %s: %d %s\n",client.getURI().toString(),fr.code(),fr.body()); + } + } catch (CadiException | URISyntaxException | APIException e) { + env.error().log(e,"Error connecting " + client.getURI() + " for location."); + } + return false; + } + + /* (non-Javadoc) + * @see org.onap.aaf.cadi.aaf.v2_0.AbsAAFLocator#getURI() + */ + @Override + protected URI getURI() { + return client.getURI(); + } + + protected HClient createClient(SecuritySetter ss, URI uri, int connectTimeout) throws LocatorException { + return new HClient(ss, uri, connectTimeout); + } + }