diff options
Diffstat (limited to 'cadi')
7 files changed, 158 insertions, 53 deletions
diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFCon.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFCon.java index 4fe05f71..9e21f6cd 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFCon.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/aaf/v2_0/AAFCon.java @@ -111,7 +111,7 @@ public abstract class AAFCon<CLIENT> implements Connector { } try { RegistrationPropHolder rph = new RegistrationPropHolder(access, 0); - str = rph.replacements(str, null,null); + str = rph.replacements("AAFCon",str, null,null); } catch (UnknownHostException e) { throw new CadiException(e); } 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 14878d38..5214ddba 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 @@ -73,14 +73,14 @@ public abstract class AbsAAFLocator<TRANS extends Trans> implements Locator<URI> throw new LocatorException(e1); } try { - aaf_locator_host = rph.replacements("https://"+Config.AAF_LOCATE_URL_TAG,null,null); + aaf_locator_host = rph.replacements(getClass().getSimpleName(),"https://"+Config.AAF_LOCATE_URL_TAG,null,null); aaf_locator_uri = new URI(aaf_locator_host); access.printf(Level.INFO, "AbsAAFLocator AAF URI is %s",aaf_locator_uri); } catch (URISyntaxException e) { throw new LocatorException(e); } - name = rph.replacements(name, null,null); + name = rph.replacements(getClass().getSimpleName(),name, null,null); access.printf(Level.INFO, "AbsAAFLocator name is %s",aaf_locator_uri); epList = new LinkedList<>(); diff --git a/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RegistrationCreator.java b/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RegistrationCreator.java index aba13fb4..ac715163 100644 --- a/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RegistrationCreator.java +++ b/cadi/aaf/src/main/java/org/onap/aaf/cadi/register/RegistrationCreator.java @@ -24,6 +24,7 @@ import java.net.UnknownHostException; 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.aaf.Defaults; import org.onap.aaf.cadi.config.Config; @@ -31,6 +32,7 @@ import org.onap.aaf.cadi.config.RegistrationPropHolder; import org.onap.aaf.cadi.util.Split; import locate.v1_0.MgmtEndpoint; +import locate.v1_0.MgmtEndpoint.SpecialPorts; import locate.v1_0.MgmtEndpoints; public class RegistrationCreator { @@ -110,10 +112,75 @@ public class RegistrationCreator { } catch (NumberFormatException | UnknownHostException e) { throw new CadiException("Error extracting Data from Properties for Registrar",e); } - + + if(access.willLog(Level.INFO)) { + access.log(Level.INFO, print(new StringBuilder(),me.getMgmtEndpoint())); + } return me; } + private StringBuilder print(StringBuilder sb, List<MgmtEndpoint> lme) { + int cnt = 0; + for(MgmtEndpoint m : lme) { + print(sb,cnt++,m); + } + return sb; + } + + private void print(StringBuilder out, int cnt, MgmtEndpoint mep) { + out.append("\nManagement Endpoint - "); + out.append(cnt); + out.append("\n\tName: "); + out.append(mep.getName()); + out.append("\n\tHostname: "); + out.append(mep.getHostname()); + out.append("\n\tLatitude: "); + out.append(mep.getLatitude()); + out.append("\n\tLongitude: "); + out.append(mep.getLongitude()); + out.append("\n\tVersion: "); + out.append(mep.getMajor()); + out.append('.'); + out.append(mep.getMinor()); + out.append('.'); + out.append(mep.getPkg()); + out.append('.'); + out.append(mep.getPatch()); + out.append("\n\tPort: "); + out.append(mep.getPort()); + out.append("\n\tProtocol: "); + out.append(mep.getProtocol()); + out.append("\n\tSpecial Ports:"); + for( SpecialPorts sp : mep.getSpecialPorts()) { + out.append("\n\t\tName: "); + out.append(sp.getName()); + out.append("\n\t\tPort: "); + out.append(sp.getPort()); + out.append("\n\t\tProtocol: "); + out.append(sp.getProtocol()); + out.append("\n\t\t Versions: "); + boolean first = true; + for(String s : sp.getProtocolVersions()) { + if(first) { + first = false; + } else { + out.append(','); + } + out.append(s); + } + } + boolean first = true; + out.append("\n\tSubProtocol: "); + for(String s : mep.getSubprotocol()) { + if(first) { + first = false; + } else { + out.append(','); + } + out.append(s); + } + } + private MgmtEndpoint copy(MgmtEndpoint mep) { MgmtEndpoint out = new MgmtEndpoint(); out.setName(mep.getName()); diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/register/test/JU_RegistrationCreator.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/register/test/JU_RegistrationCreator.java index dc671c83..06ef0ca5 100644 --- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/register/test/JU_RegistrationCreator.java +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/register/test/JU_RegistrationCreator.java @@ -27,6 +27,7 @@ import java.net.Inet4Address; import java.net.UnknownHostException; import org.junit.Test; +import org.mockito.internal.configuration.DefaultInjectionEngine; import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.config.Config; @@ -142,6 +143,7 @@ public class JU_RegistrationCreator { pa.setProperty(Config.AAF_LOCATOR_PUBLIC_HOSTNAME,k8s_public_hostname); pa.setProperty(Config.AAF_LOCATOR_PUBLIC_PORT+DOT_OOM,Integer.toString(public_port)); + pa.setProperty(Config.AAF_LOCATOR_APP_NS, Config.AAF_ROOT_NS_DEF); rc = new RegistrationCreator(pa); for(MgmtEndpoint me : rc.create(port).getMgmtEndpoint()) { switch(me.getName()) { diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java index 26305e91..3dc7f06c 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/Config.java @@ -175,7 +175,7 @@ public class Config { public static final String AAF_LOCATOR_VERSION = "aaf_locator_version"; public static final String AAF_LOCATOR_PROTOCOL = "aaf_locator_protocol"; public static final String AAF_LOCATOR_SUBPROTOCOL = "aaf_locator_subprotocol"; - public static final String AAF_LOCATOR_NS = "aaf_locator_ns"; + public static final String AAF_LOCATOR_APP_NS = "aaf_locator_app_ns"; public static final String AAF_LOCATOR_ENTRIES = "aaf_locator_entries"; public static final String AAF_LOCATOR_FQDN = "aaf_locator_fqdn"; public static final String AAF_LOCATOR_NAME = "aaf_locator_name"; @@ -574,7 +574,7 @@ public class Config { if (rv == null) { rph.access().log(Level.INIT,tag,"is not explicitly set"); } else { - rv = rph.replacements(rv, null, null); + rv = rph.replacements("Config.logProp",rv, null, null); rph.access().log(Level.INIT,tag,"is set to",rv); } return rv; @@ -848,7 +848,7 @@ public class Config { RegistrationPropHolder rph; try { rph = new RegistrationPropHolder(access, 0); - url = rph.replacements(_url, null, null); + url = rph.replacements("Config.loadLocator",_url, null, null); access.printf(Level.INFO, "loadLocator URL is %s",url); } catch (UnknownHostException | CadiException e1) { throw new LocatorException(e1); diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java b/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java index 68a018d6..87abb963 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/config/RegistrationPropHolder.java @@ -25,10 +25,12 @@ import java.net.UnknownHostException; import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.Access.Level; import org.onap.aaf.cadi.util.Split; public class RegistrationPropHolder { private final String PUBLIC_NAME="%NS.%N"; + private final String REGI="RegistrationProperty: %s='%s'"; private final Access access; public String hostname; private int port; @@ -42,6 +44,7 @@ public class RegistrationPropHolder { public final String lentries; public final String lcontainer; public final String default_container; + private static boolean firstlog = true; public RegistrationPropHolder(final Access access, final int port) throws UnknownHostException, CadiException { this.access = access; @@ -50,8 +53,10 @@ public class RegistrationPropHolder { this.port = port; lentries=access.getProperty(Config.AAF_LOCATOR_ENTRIES,""); - default_container = access.getProperty(Config.AAF_LOCATOR_CONTAINER, ""); + if(firstlog) { + access.printf(Level.INIT, REGI,"default_container",default_container); + } if(!default_container.isEmpty()) { lcontainer=',' + default_container; // "" makes a blank default Public Entry str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_PORT+'.'+default_container, null); @@ -65,7 +70,10 @@ public class RegistrationPropHolder { if(str!=null) { public_port=Integer.decode(str); } - + if(firstlog) { + access.printf(Level.INIT, "RegistrationProperty: public_port='%d'",public_port); + } + hostname = access.getProperty(Config.HOSTNAME, null); if (hostname==null) { hostname = Inet4Address.getLocalHost().getHostName(); @@ -73,10 +81,19 @@ public class RegistrationPropHolder { if (hostname==null) { mustBeDefined(errs,Config.HOSTNAME); } + if(firstlog) { + access.printf(Level.INIT, REGI,"hostname",hostname); + } public_hostname = access.getProperty(Config.AAF_LOCATOR_PUBLIC_HOSTNAME, hostname); + if(firstlog) { + access.printf(Level.INIT, REGI,"public_hostname",public_hostname); + } - default_name = access.getProperty(Config.AAF_LOCATOR_NAME, "%CNS.%NS.%N"); + default_name = access.getProperty(Config.AAF_LOCATOR_NAME, PUBLIC_NAME); + if(firstlog) { + access.printf(Level.INIT, REGI,"default_name",default_name); + } latitude=null; String slatitude = access.getProperty(Config.CADI_LATITUDE, null); @@ -85,6 +102,9 @@ public class RegistrationPropHolder { } else { latitude = Float.parseFloat(slatitude); } + if(firstlog) { + access.printf(Level.INIT, REGI,"latitude",slatitude); + } longitude=null; String slongitude = access.getProperty(Config.CADI_LONGITUDE, null); @@ -93,23 +113,35 @@ public class RegistrationPropHolder { } else { longitude = Float.parseFloat(slongitude); } + if(firstlog) { + access.printf(Level.INIT, REGI,"longitude",slongitude); + } String dot_le; // Note: only one of the ports can be public... Therefore, only the last for(String le : Split.splitTrim(',', lcontainer)) { - dot_le = le.isEmpty()?"":"."+le; + dot_le = le.isEmpty()?le :"."+le; str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_HOSTNAME+dot_le,null); - if( str != null) { + if( str != null && !str.isEmpty()) { public_hostname=str; + if(firstlog) { + access.printf(Level.INIT, "RegistrationProperty: public_hostname(overloaded by %s)='%s'",dot_le,public_hostname); + } } } default_fqdn = access.getProperty(Config.AAF_LOCATOR_FQDN, hostname); + if(firstlog) { + access.printf(Level.INIT, REGI,"default_fqdn",default_fqdn); + } default_container_ns = access.getProperty(Config.AAF_LOCATOR_CONTAINER_NS,""); - + if(firstlog) { + access.printf(Level.INIT, REGI,"default_container_ns",default_container_ns); + } if(errs.length()>0) { throw new CadiException(errs.toString()); } + firstlog = false; } private void mustBeDefined(StringBuilder errs, String propname) { @@ -126,7 +158,7 @@ public class RegistrationPropHolder { } else { str = access.getProperty(Config.AAF_LOCATOR_FQDN+dot_le, default_fqdn); } - return replacements(str,entry,dot_le); + return replacements("RegistrationPropHolder.getEntryFQDN",str,entry,dot_le); } public String getEntryName(final String entry, final String dot_le) { @@ -136,27 +168,27 @@ public class RegistrationPropHolder { } else { str = access.getProperty(Config.AAF_LOCATOR_NAME+dot_le, default_name); } - return replacements(str,entry,dot_le); + return replacements("RegistrationPropHolder.getEntryName",str,entry,dot_le); } private String getNS(String dot_le) { String ns; - ns = access.getProperty(Config.AAF_LOCATOR_NS+dot_le,null); + ns = access.getProperty(Config.AAF_LOCATOR_APP_NS+dot_le,null); if(ns==null) { - ns = access.getProperty(Config.AAF_ROOT_NS, ""); + ns = access.getProperty(Config.AAF_LOCATOR_APP_NS, ""); } return ns; } - public String replacements(String source, final String name, final String _dot_le) { + public String replacements(final String fromCode, final String source, final String name, final String _dot_le) { if(source == null) { return ""; } else if(source.isEmpty()) { return source; } - + String value = source; String dot_le; if(_dot_le==null) { dot_le = default_container.isEmpty()?"":'.'+default_container; @@ -171,71 +203,75 @@ public class RegistrationPropHolder { String str; if(aaf_locator_host!=null) { - if("https://AAF_LOCATE_URL".equals(source)) { - source = aaf_locator_host; + if("https://AAF_LOCATE_URL".equals(value)) { + value = aaf_locator_host; } else { str = aaf_locator_host; - if(source.indexOf(Config.AAF_LOCATE_URL_TAG)>=0) { + if(value.indexOf(Config.AAF_LOCATE_URL_TAG)>=0) { if(!str.endsWith("/")) { str+='/'; } if(!str.endsWith("/locate/")) { str+="locate/"; } - source = source.replace("https://AAF_LOCATE_URL/", str); + value = value.replace("https://AAF_LOCATE_URL/", str); } } } - int atC = source.indexOf("%C"); + int atC = value.indexOf("%C"); if(atC>=0) { // aaf_locator_container_ns str = access.getProperty(Config.AAF_LOCATOR_CONTAINER_NS+dot_le, default_container_ns); if(str.isEmpty()) { - source = source.replace("%CNS"+'.', str); + value = value.replace("%CNS"+'.', str); } - source = source.replace("%CNS", str); + value = value.replace("%CNS", str); str = access.getProperty(Config.AAF_LOCATOR_CONTAINER+dot_le,default_container); if(str.isEmpty()) { - source = source.replace("%C"+'.', str); + value = value.replace("%C"+'.', str); } - source = source.replace("%C", str); + value = value.replace("%C", str); } - if(source.indexOf("%NS")>=0) { + if(value.indexOf("%NS")>=0) { str = getNS(dot_le); if(str==null || str.isEmpty()) { - source = source.replace("%NS"+'.', str); + value = value.replace("%NS"+'.', str); } - source = source.replace("%NS", str); + value = value.replace("%NS", str); } // aaf_root_ns - if(source.indexOf("AAF_NS")>=0) { + if(value.indexOf("AAF_NS")>=0) { str = access.getProperty(Config.AAF_ROOT_NS, Config.AAF_ROOT_NS_DEF); - String temp = source.replace("%AAF_NS", str); - if(temp.equals(source)) { // intended - source = source.replace("AAF_NS", str); // Backward Compatibility + String temp = value.replace("%AAF_NS", str); + if(temp.equals(value)) { // intended + value = value.replace("AAF_NS", str); // Backward Compatibility } else { - source = temp; + value = temp; } } - if(source.indexOf('%')>=0) { + if(value.indexOf('%')>=0) { // These shouldn't be expected to have dot elements if(name!=null) { - source = source.replace("%N", name); + value = value.replace("%N", name); } if(default_fqdn!=null) { - source = source.replace("%DF", default_fqdn); + value = value.replace("%DF", default_fqdn); } if(public_hostname!=null) { - source = source.replace("%PH", public_hostname); + value = value.replace("%PH", public_hostname); } } - return source; + access.printf(Level.DEBUG, + "RegistrationReplacement from %s, source: %s, dot_le: %s, value: %s", + fromCode,source,dot_le,value); + + return value; } public int getEntryPort(final String dot_le) { diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java b/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java index 18e26f55..359b3c2d 100644 --- a/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java +++ b/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java @@ -73,7 +73,7 @@ public class JU_RegistrationPropHolder { } String ns = "myns"; - pa.setProperty(Config.AAF_LOCATOR_NS, ns); + pa.setProperty(Config.AAF_LOCATOR_APP_NS, ns); for(String dot_le : new String[] {"",".helm"}) { assertEquals(rph.hostname,rph.default_fqdn); assertEquals("",rph.lcontainer); @@ -83,7 +83,7 @@ public class JU_RegistrationPropHolder { } String ns2 = "onap"; - pa.setProperty(Config.AAF_LOCATOR_NS+".helm", ns2); + pa.setProperty(Config.AAF_LOCATOR_APP_NS+".helm", ns2); for(String dot_le : new String[] {"",".helm"}) { assertEquals(rph.hostname,rph.default_fqdn); assertEquals("",rph.lcontainer); @@ -106,37 +106,37 @@ public class JU_RegistrationPropHolder { final String url = "https://aaf.osaaf.org:8095/org.osaaf.aaf.service:2.1"; String name="theName"; - assertEquals(url,rph.replacements(url, name, "")); + assertEquals(url,rph.replacements(getClass().getSimpleName(),url, name, "")); String alu = "aaf.osaaf.org:8095"; String curl = url.replace(alu, Config.AAF_LOCATE_URL_TAG); pa.setProperty(Config.AAF_LOCATE_URL,"https://"+alu); - assertEquals(url.replace("8095","8095/locate"),rph.replacements(curl, name, "")); + assertEquals(url.replace("8095","8095/locate"),rph.replacements(getClass().getSimpleName(),curl, name, "")); String root_ns = "org.osaaf.aaf"; curl = url.replace(root_ns, "AAF_NS"); pa.setProperty(Config.AAF_ROOT_NS,root_ns); - assertEquals(url,rph.replacements(curl, name, "")); + assertEquals(url,rph.replacements(getClass().getSimpleName(),curl, name, "")); curl = url.replace(root_ns, "%AAF_NS"); pa.setProperty(Config.AAF_ROOT_NS,root_ns); - assertEquals(url,rph.replacements(curl, name, "")); + assertEquals(url,rph.replacements(getClass().getSimpleName(),curl, name, "")); final String fqdn = "%C.%CNS.%NS.%N"; String target = "myns.theName"; - assertEquals(target,rph.replacements(fqdn, name, "")); + assertEquals(target,rph.replacements(getClass().getSimpleName(),fqdn, name, "")); pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS+".hello", "mycontns"); - target = "mycontns.org.osaaf.aaf.theName"; - assertEquals(target,rph.replacements(fqdn, name, ".hello")); + target = "mycontns.myns.theName"; + assertEquals(target,rph.replacements(getClass().getSimpleName(),fqdn, name, ".hello")); pa.setProperty(Config.AAF_LOCATOR_CONTAINER+".hello","helloC"); - target = "helloC.mycontns.org.osaaf.aaf.theName"; - assertEquals(target,rph.replacements(fqdn, name, ".hello")); + target = "helloC.mycontns.myns.theName"; + assertEquals(target,rph.replacements(getClass().getSimpleName(),fqdn, name, ".hello")); pa.setProperty(Config.AAF_LOCATOR_CONTAINER_NS,"c_ns"); target = "c_ns.myns.theName"; - assertEquals(target,rph.replacements(fqdn, name, "")); + assertEquals(target,rph.replacements(getClass().getSimpleName(),fqdn, name, "")); } catch (UnknownHostException | CadiException e) { |