Merge "major-Extract the assignment out of this expression"
authorJonathan Gathman <jonathan.gathman@att.com>
Mon, 9 Sep 2019 12:42:04 +0000 (12:42 +0000)
committerGerrit Code Review <gerrit@onap.org>
Mon, 9 Sep 2019 12:42:04 +0000 (12:42 +0000)
auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java
cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFLocator.java
cadi/aaf/src/main/java/org/onap/aaf/cadi/configure/Agent.java
cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RemoteRegistrant.java
cadi/aaf/src/main/java/org/onap/aaf/cadi/sso/AAFSSO.java
cadi/client/src/main/java/org/onap/aaf/cadi/locator/DNSLocator.java
cadi/client/src/main/java/org/onap/aaf/cadi/locator/SingleEndpointLocator.java
cadi/client/src/main/java/org/onap/aaf/cadi/locator/SizedLocator.java [new file with mode: 0644]
cadi/client/src/test/java/org/onap/aaf/cadi/locator/test/JU_DNSLocator.java

index 14d65d4..6f23c51 100644 (file)
@@ -273,11 +273,9 @@ public class Cred  {
         public void inc(int type, Date start, Date expires) {
             for (int i=0;i<dates.length-1;++i) {
                 if (start.before(dates[i])) {
-                    if (type==CredDAO.CERT_SHA256_RSA) {
-                        if (start.after(dates[i+1])) {
+                    if ((type==CredDAO.CERT_SHA256_RSA)&&(start.after(dates[i+1]))) {
                             ++x509Added[i];
-                        }
-                    }
+                         }
                     if (expires.after(dates[i])) {
                         switch(type) {
                             case CredDAO.RAW:
index a993109..38f6bce 100644 (file)
@@ -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();
     }
 
index 1f6937b..7d149fc 100644 (file)
@@ -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)) {
index 0e4945d..b49b911 100644 (file)
@@ -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);
             }
         }
index a472ed5..c9b21b2 100644 (file)
@@ -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);
             }
         }
index d64de69..8053dab 100644 (file)
@@ -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;
index 3b79dba..b0654cf 100644 (file)
@@ -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 (file)
index 0000000..65a3473
--- /dev/null
@@ -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();
+}
index dfc7142..b786cf6 100644 (file)
 
 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