* 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.
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;
private HClient client;
private HClient lclient;
private RosettaDF<Endpoints> epsDF;
- private DNSLocator locatorLocator;
+ private SizedLocator<URI> locatorLocator;
private Item locatorItem;
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());
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);
+ }
}
}
}
protected final int maxIters() {
+
return locatorLocator.size();
}
for (Endpoint endpoint : fr.value.getEndpoint()) {
epl.add(new EP(endpoint,latitude,longitude));
}
-
+
Collections.sort(epl);
replace(epl);
return true;
protected URI getURI() {
return client.getURI();
}
-
+
protected HClient createClient(SecuritySetter<HttpURLConnection> ss, URI uri, int connectTimeout) throws LocatorException {
return new HClient(ss, uri, connectTimeout);
}
-
+
}