summaryrefslogtreecommitdiffstats
path: root/cadi
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2019-09-03 12:31:32 -0500
committerInstrumental <jonathan.gathman@att.com>2019-09-03 13:04:31 -0500
commit6309ef454e6960d95d13534645e1f15904de6862 (patch)
tree50086c164436cf2e65c8eb9a90180b1d4a34bbbc /cadi
parentc3b26083686b22724767c4056735d425e4360d0e (diff)
Update Fixes from testing
Issue-ID: AAF-961 Change-Id: I142e460607bf32a785037fa2360b1c0efc3948b1 Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'cadi')
-rw-r--r--cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.java76
-rw-r--r--cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java7
-rw-r--r--cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AbsAAFLocator.java17
-rw-r--r--cadi/aaf/src/test/java/org/onap/aaf/cadi/oauth/test/JU_TzHClient.java17
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java7
5 files changed, 94 insertions, 30 deletions
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 ed24b1ee..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
@@ -29,6 +29,7 @@ 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;
@@ -36,6 +37,7 @@ 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;
@@ -49,8 +51,12 @@ import locate.v1_0.Endpoints;
public class AAFLocator extends AbsAAFLocator<BasicTrans> {
private static RosettaEnv env;
- HClient client;
+ private HClient client;
+ private HClient lclient;
private RosettaDF<Endpoints> epsDF;
+ private DNSLocator locatorLocator;
+ private Item locatorItem;
+
public AAFLocator(SecurityInfoC<HttpURLConnection> si, URI locatorURI) throws LocatorException {
super(si.access, nameFromLocatorURI(locatorURI), 10000L /* Wait at least 10 seconds between refreshes */);
@@ -73,13 +79,6 @@ public class AAFLocator extends AbsAAFLocator<BasicTrans> {
sb.append(path[i]);
}
setPathInfo(sb.toString());
-// URI uri = new URI(
-// locatorURI.getScheme(),
-// locatorURI.getAuthority(),
-// locatorURI.getPath(),
-// null,
-// null
-// );
client = createClient(si.defSS, locatorURI, connectTimeout);
} else {
client = new HClient(si.defSS, locatorURI, connectTimeout);
@@ -89,19 +88,72 @@ public class AAFLocator extends AbsAAFLocator<BasicTrans> {
} 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();
+ } else {
+ dnsString=locatorURI.getScheme() + "://" +locatorURI.getHost()+':'+locatorURI.getPort();
+ }
+ if(dnsString.contains("null")) { // for Testing Purposes, mostly.
+ locatorLocator = null;
+ } else {
+ locatorLocator = new DNSLocator(access, dnsString);
+ locatorItem = locatorLocator.best();
+ }
+ }
+
+ 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 {
- client.setMethod("GET");
- client.send();
- Future<Endpoints> fr = client.futureRead(epsDF, TYPE.JSON);
- if (fr.get(client.timeout())) {
+ int max = locatorLocator.size();
+ for(int i=0;i<max;) {
+ ++i;
+ try {
+ lclient.setMethod("GET");
+ lclient.send();
+ break;
+ } catch (APIException connectE) {
+ Throwable ce = connectE.getCause();
+ if(ce!=null && ce instanceof java.net.ConnectException && i< maxIters()) {
+ try {
+ URI old = client.getURI();
+ lclient.setURI(locatorFail(old));
+ access.printf(Level.INFO, "AAF Locator changed from %s to %s",old, lclient.getURI());
+ continue;
+ } catch (LocatorException e) {
+ throw connectE;
+ }
+ }
+ // last one, just throw
+ throw connectE;
+ }
+ }
+ Future<Endpoints> fr = lclient.futureRead(epsDF, TYPE.JSON);
+ if (fr.get(lclient.timeout())) {
List<EP> epl = new LinkedList<>();
for (Endpoint endpoint : fr.value.getEndpoint()) {
epl.add(new EP(endpoint,latitude,longitude));
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java
index 2fe3ffdb..5ef25bcd 100644
--- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java
+++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AbsAAFLocator.java
@@ -72,6 +72,7 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
} catch (UnknownHostException | CadiException e1) {
throw new LocatorException(e1);
}
+ URI aaf_locator_uri;
try {
aaf_locator_host = rph.replacements(getClass().getSimpleName(),"https://"+Config.AAF_LOCATE_URL_TAG,null,null);
if(aaf_locator_host.endsWith("/locate")) {
@@ -79,7 +80,6 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
} else {
aaf_locator_uri = new URI(aaf_locator_host+"/locate");
}
-
access.printf(Level.INFO, "AbsAAFLocator AAF URI is %s",aaf_locator_uri);
} catch (URISyntaxException e) {
throw new LocatorException(e);
@@ -110,9 +110,8 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
this.name = split[0];
this.version = (split.length > 1) ? split[1] : access.getProperty(Config.AAF_API_VERSION,Config.AAF_DEFAULT_API_VERSION);
}
-
}
-
+
/**
* This is the way to setup specialized AAFLocators ahead of time.
* @param preload
@@ -368,7 +367,7 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI>
}
return null;
}
-
+
protected static class AAFLItem implements Item {
private Iterator<EP> iter;
private URI uri;
diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AbsAAFLocator.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AbsAAFLocator.java
index 64e9572e..004eed3a 100644
--- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AbsAAFLocator.java
+++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AbsAAFLocator.java
@@ -21,18 +21,23 @@
package org.onap.aaf.cadi.aaf.v2_0.test;
-import static org.junit.Assert.*;
-import static org.hamcrest.CoreMatchers.*;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
-import org.junit.*;
-import org.mockito.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
import org.onap.aaf.cadi.Access;
import org.onap.aaf.cadi.Locator.Item;
import org.onap.aaf.cadi.LocatorException;
diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/oauth/test/JU_TzHClient.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/oauth/test/JU_TzHClient.java
index 11dce825..805b13f1 100644
--- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/oauth/test/JU_TzHClient.java
+++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/oauth/test/JU_TzHClient.java
@@ -21,12 +21,13 @@
package org.onap.aaf.cadi.oauth.test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.mockito.Mockito.when;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
@@ -38,7 +39,6 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-
import org.onap.aaf.cadi.CadiException;
import org.onap.aaf.cadi.Locator;
import org.onap.aaf.cadi.Locator.Item;
@@ -46,11 +46,11 @@ import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.PropAccess;
import org.onap.aaf.cadi.client.Rcli;
import org.onap.aaf.cadi.client.Retryable;
+import org.onap.aaf.cadi.config.Config;
+import org.onap.aaf.cadi.config.SecurityInfoC;
import org.onap.aaf.cadi.oauth.TimedToken;
import org.onap.aaf.cadi.oauth.TzHClient;
import org.onap.aaf.misc.env.APIException;
-import org.onap.aaf.cadi.config.Config;
-import org.onap.aaf.cadi.config.SecurityInfoC;
public class JU_TzHClient {
@@ -72,8 +72,9 @@ public class JU_TzHClient {
MockitoAnnotations.initMocks(this);
access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]);
access.setProperty(Config.CADI_LATITUDE, "38.62"); // St Louis approx lat
- access.setProperty(Config.CADI_LONGITUDE, "90.19"); // St Louis approx lon }
-
+ access.setProperty(Config.CADI_LONGITUDE, "90.19"); // St Louis approx long
+ //access.setProperty("tag", "http://aaf.something.com");
+
errStream = new ByteArrayOutputStream();
System.setErr(new PrintStream(errStream));
}
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java
index 4711aee6..d64de699 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java
@@ -40,6 +40,8 @@ public class DNSLocator implements Locator<URI> {
private Host[] hosts;
private int startPort, endPort;
private String suffix;
+
+ private int size = 1; // initial, until refreshed.
public DNSLocator(Access access, String protocol, String host, String range) {
this.host = host;
@@ -156,6 +158,7 @@ public class DNSLocator implements Locator<URI> {
}
}
hosts = temp;
+ size = temp.length * (endPort-startPort+1);
return true;
} catch (Exception e) {
access.log(Level.ERROR, e);
@@ -238,4 +241,8 @@ public class DNSLocator implements Locator<URI> {
}
public void destroy() {}
+
+ public int size() {
+ return size;
+ }
}