summaryrefslogtreecommitdiffstats
path: root/cadi
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2019-09-04 19:41:24 -0500
committerInstrumental <jonathan.gathman@att.com>2019-09-04 19:41:51 -0500
commitc5aaaeeb8a4c008fa4a576c55da4c3bf703acdac (patch)
treedf48d917f868dc110734afc48c50478b58c697ad /cadi
parent4fbae1b6a5de191a9e26361ce6d1b8958be53f9e (diff)
K8s doesn't necessarily support DNS
Issue-ID: AAF-963 Change-Id: I65248837fc217b0ccc09f2afe02e14c716ca5bcc 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.java12
-rw-r--r--cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java2
-rw-r--r--cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RemoteRegistrant.java2
-rw-r--r--cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java3
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java9
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java16
-rw-r--r--cadi/client/src/main/java/org/onap/aaf/cadi/locator/SizedLocator.java28
-rw-r--r--cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java31
8 files changed, 78 insertions, 25 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 a993109a..38f6bcea 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
@@ -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<BasicTrans> {
private HClient client;
private HClient lclient;
private RosettaDF<Endpoints> epsDF;
- private DNSLocator locatorLocator;
+ private SizedLocator<URI> locatorLocator;
private Item locatorItem;
@@ -104,7 +106,12 @@ public class AAFLocator extends AbsAAFLocator<BasicTrans> {
locatorLocator = null;
} else {
locatorLocator = new DNSLocator(access, dnsString);
- locatorItem = locatorLocator.best();
+ 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<BasicTrans> {
}
protected final int maxIters() {
+
return locatorLocator.size();
}
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java
index 1f6937bb..7d149fca 100644
--- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java
+++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java
@@ -1017,7 +1017,7 @@ public class Agent {
}
}
- public static List<Props> aafProps(Trans trans, AAFCon<?> aafcon, String locator, String fqi) throws CadiException, APIException, URISyntaxException {
+ public static List<Props> aafProps(Trans trans, AAFCon<?> aafcon, String locator, String fqi) throws CadiException, APIException, LocatorException {
Future<Configuration> acf = aafcon.client(new SingleEndpointLocator(locator))
.read("/configure/"+fqi+"/aaf", configDF);
if (acf.get(TIMEOUT)) {
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RemoteRegistrant.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RemoteRegistrant.java
index 0e4945d0..b49b911b 100644
--- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RemoteRegistrant.java
+++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RemoteRegistrant.java
@@ -75,7 +75,7 @@ public class RemoteRegistrant<ENV extends BasicEnv> implements Registrant<ENV> {
} else {
locator = new SingleEndpointLocator(aaf_locate);
}
- } catch (URISyntaxException | UnknownHostException e) {
+ } catch (UnknownHostException e) {
throw new CadiException(e);
}
}
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java
index a472ed5b..c9b21b2a 100644
--- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java
+++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java
@@ -29,7 +29,6 @@ import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
@@ -398,7 +397,7 @@ public class AAFSSO {
} else {
access.log(Level.INFO,acf.body());
}
- } catch (LocatorException | APIException | URISyntaxException e) {
+ } catch (LocatorException | APIException e) {
access.log(e);
}
}
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 d64de699..8053dabf 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
@@ -27,11 +27,10 @@ import java.net.URI;
import java.net.URISyntaxException;
import org.onap.aaf.cadi.Access;
-import org.onap.aaf.cadi.Locator;
-import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.Access.Level;
+import org.onap.aaf.cadi.LocatorException;
-public class DNSLocator implements Locator<URI> {
+public class DNSLocator implements SizedLocator<URI> {
private static enum Status {UNTRIED, OK, INVALID, SLOW};
private static final int CHECK_TIME = 3000;
@@ -63,11 +62,11 @@ public class DNSLocator implements Locator<URI> {
throw new LocatorException("Null passed into DNSLocator constructor");
}
int start, defPort;
- if (aaf_locate.startsWith("https:")) {
+ if (aaf_locate.startsWith("https://")) {
protocol = "https";
start = 8; // https://
defPort = 443;
- } else if (aaf_locate.startsWith("http:")) {
+ } else if (aaf_locate.startsWith("http://")) {
protocol = "http";
start = 7; // http://
defPort = 80;
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java
index 3b79dba5..b0654cfa 100644
--- a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java
@@ -24,10 +24,9 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
-import org.onap.aaf.cadi.Locator;
import org.onap.aaf.cadi.LocatorException;
-public class SingleEndpointLocator implements Locator<URI> {
+public class SingleEndpointLocator implements SizedLocator<URI> {
private final URI uri;
private final static Item item = new Item() {};
private Date noRetryUntil;
@@ -36,8 +35,12 @@ public class SingleEndpointLocator implements Locator<URI> {
this.uri = uri;
}
- public SingleEndpointLocator(final String endpoint) throws URISyntaxException {
- this.uri = new URI(endpoint);
+ public SingleEndpointLocator(final String endpoint) throws LocatorException {
+ try {
+ this.uri = new URI(endpoint);
+ } catch (URISyntaxException e) {
+ throw new LocatorException(e);
+ }
}
@Override
@@ -84,6 +87,11 @@ public class SingleEndpointLocator implements Locator<URI> {
// Never refreshed
return true;
}
+
+ @Override
+ public int size() {
+ return 1;
+ }
@Override
public void destroy() {
diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SizedLocator.java b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SizedLocator.java
new file mode 100644
index 00000000..65a34738
--- /dev/null
+++ b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/SizedLocator.java
@@ -0,0 +1,28 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+
+package org.onap.aaf.cadi.locator;
+
+import org.onap.aaf.cadi.Locator;
+
+public interface SizedLocator<T> extends Locator<T> {
+ public abstract int size();
+}
diff --git a/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java b/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java
index dfc7142a..b786cf68 100644
--- a/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java
+++ b/cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java
@@ -21,17 +21,20 @@
package org.onap.aaf.cadi.locator.test;
-import static org.junit.Assert.*;
-import static org.hamcrest.CoreMatchers.*;
-import org.junit.*;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.URI;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.aaf.cadi.Access.Level;
+import org.onap.aaf.cadi.Locator.Item;
import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.Locator.Item;
import org.onap.aaf.cadi.locator.DNSLocator;
public class JU_DNSLocator {
@@ -73,12 +76,20 @@ public class JU_DNSLocator {
new DNSLocator(access, "https", "localhost", "8100");
new DNSLocator(access, "https", "localhost", "8100-8101");
- new DNSLocator(access, "http:localhost");
- new DNSLocator(access, "https:localhost");
- new DNSLocator(access, "https:localhost:8100");
- new DNSLocator(access, "https:localhost:[8100]");
- new DNSLocator(access, "https:localhost:[8100-8101]");
- new DNSLocator(access, "https:localhost:8000/");
+ new DNSLocator(access, "http://localhost");
+ new DNSLocator(access, "https://localhost");
+ new DNSLocator(access, "https://localhost:8100");
+ new DNSLocator(access, "https://localhost:[8100]");
+ new DNSLocator(access, "https://localhost:[8100-8101]");
+ new DNSLocator(access, "https://localhost:8000/");
+ new DNSLocator(access, "https://aaf-locatexx.onapxxx:8095/locate");
+ try {
+ new DNSLocator(access, "https:localhost:8000");
+ fail("Invalid URL should not pass");
+ } catch (LocatorException e) {
+ access.log(Level.DEBUG, "Valid Exception");
+
+ }
}
@Test