X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Fregister%2FRemoteRegistrant.java;h=b49b911b78e6cc033ff49e959f1ac4237a14f103;hb=c5aaaeeb8a4c008fa4a576c55da4c3bf703acdac;hp=bed201aa32f63cccc4cb1b47ac175d27031c840b;hpb=6261a19e61138e861f5c7eaf37835205f19f1fe0;p=aaf%2Fauthz.git 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 bed201aa..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 @@ -22,7 +22,6 @@ package org.onap.aaf.cadi.register; import java.net.HttpURLConnection; -import java.net.Inet4Address; import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; @@ -37,147 +36,99 @@ import org.onap.aaf.cadi.client.Future; import org.onap.aaf.cadi.client.Rcli; import org.onap.aaf.cadi.client.Result; import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.config.RegistrationPropHolder; import org.onap.aaf.cadi.locator.PropertyLocator; import org.onap.aaf.cadi.locator.SingleEndpointLocator; -import org.onap.aaf.cadi.util.Split; import org.onap.aaf.misc.env.APIException; import org.onap.aaf.misc.env.impl.BasicEnv; import org.onap.aaf.misc.rosetta.env.RosettaDF; -import locate.v1_0.MgmtEndpoint; import locate.v1_0.MgmtEndpoints; public class RemoteRegistrant implements Registrant { - private final MgmtEndpoint mep; - private final MgmtEndpoints meps; - private final AAFCon aafcon; - private final RosettaDF mgmtEndpointsDF; - private final Locator locator; - private final Access access; - private final int timeout; + private final MgmtEndpoints meps; + private final AAFCon aafcon; + private final RosettaDF mgmtEndpointsDF; + private final Locator locator; + private final Access access; + private final int timeout; - @SafeVarargs - public RemoteRegistrant(AAFCon aafcon, String name, String version, int port, RemoteRegistrant ... others) throws CadiException, LocatorException { - this.aafcon = aafcon; - access = aafcon.access; - try { - mgmtEndpointsDF = aafcon.env.newDataFactory(MgmtEndpoints.class); - } catch (APIException e1) { - throw new CadiException(e1); - } - timeout = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); - String aaf_locate = access.getProperty(Config.AAF_LOCATE_URL,null); - if(aaf_locate==null) { - throw new CadiException(Config.AAF_LOCATE_URL + " is required."); - } else { - // Note: want Property Locator or Single, not AAFLocator, because we want the core service, not what it can find - try { - if(aaf_locate.indexOf(',')>=0) { - locator = new PropertyLocator(aaf_locate); - } else { - locator = new SingleEndpointLocator(aaf_locate); - } - } catch (URISyntaxException e) { - throw new CadiException(e); - } - } - - mep = new MgmtEndpoint(); - mep.setName(name); - mep.setPort(port); + public RemoteRegistrant(AAFCon aafcon, int port) throws CadiException, LocatorException { + this.aafcon = aafcon; + access = aafcon.access; + try { + mgmtEndpointsDF = aafcon.env.newDataFactory(MgmtEndpoints.class); + } catch (APIException e1) { + throw new CadiException(e1); + } + timeout = Integer.parseInt(access.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); + String aaf_locate = access.getProperty(Config.AAF_LOCATE_URL,null); + if (aaf_locate==null) { + throw new CadiException(Config.AAF_LOCATE_URL + " is required."); + } else { + // Note: want Property Locator or Single, not AAFLocator, because we want the core service, not what it can find + try { + RegistrationPropHolder rph = new RegistrationPropHolder(access, 0); + aaf_locate = rph.replacements(getClass().getSimpleName(),aaf_locate, null,null); + if (aaf_locate.indexOf(',')>=0) { + locator = new PropertyLocator(aaf_locate); + } else { + locator = new SingleEndpointLocator(aaf_locate); + } + } catch (UnknownHostException e) { + throw new CadiException(e); + } + } + + RegistrationCreator rcreator = new RegistrationCreator(access); + meps = rcreator.create(port); + } + - try { - String hostnameToRegister = access.getProperty(Config.CADI_REGISTRATION_HOSTNAME, null); - if(hostnameToRegister==null) { - hostnameToRegister = access.getProperty(Config.HOSTNAME, null); - } - if(hostnameToRegister==null) { - hostnameToRegister = Inet4Address.getLocalHost().getHostName(); - } - mep.setHostname(hostnameToRegister); - - String latitude = access.getProperty(Config.CADI_LATITUDE, null); - if(latitude==null) { - latitude = access.getProperty("AFT_LATITUDE", null); - } - String longitude = access.getProperty(Config.CADI_LONGITUDE, null); - if(longitude==null) { - longitude = access.getProperty("AFT_LONGITUDE", null); - } - if(latitude==null || longitude==null) { - throw new CadiException(Config.CADI_LATITUDE + " and " + Config.CADI_LONGITUDE + " is required"); - } else { - mep.setLatitude(Float.parseFloat(latitude)); - mep.setLongitude(Float.parseFloat(longitude)); - } - String split[] = Split.split('.', version); - mep.setPkg(split.length>3?Integer.parseInt(split[3]):0); - mep.setPatch(split.length>2?Integer.parseInt(split[2]):0); - mep.setMinor(split.length>1?Integer.parseInt(split[1]):0); - mep.setMajor(split.length>0?Integer.parseInt(split[0]):0); - - String subprotocols = access.getProperty(Config.CADI_PROTOCOLS, null); - if(subprotocols==null) { - mep.setProtocol("http"); - } else { - mep.setProtocol("https"); - for(String s : Split.split(',', subprotocols)) { - mep.getSubprotocol().add(s); - } - } - } catch (NumberFormatException | UnknownHostException e) { - throw new CadiException("Error extracting Data from Properties for Registrar",e); - } - meps = new MgmtEndpoints(); - meps.getMgmtEndpoint().add(mep); - for(RemoteRegistrant rr : others) { - meps.getMgmtEndpoint().add(rr.mep); - } - } - - @Override - public Result update(ENV env) { - try { - Rcli client = aafcon.client(locator); - try { - Future fup = client.update("/registration",mgmtEndpointsDF,meps); - if(fup.get(timeout)) { - access.log(Level.INFO, "Registration complete to",client.getURI()); - return Result.ok(fup.code(),null); - } else { - access.log(Level.ERROR,"Error registering to AAF Locator on ", client.getURI()); - return Result.err(fup.code(),fup.body()); - } - } catch (APIException e) { - access.log(e, "Error registering service to AAF Locator"); - return Result.err(503,e.getMessage()); - } - - } catch (CadiException e) { - return Result.err(503,e.getMessage()); - } - } - @Override - public Result cancel(ENV env) { - try { - Rcli client = aafcon.client(locator); - try { - Future fup = client.delete("/registration",mgmtEndpointsDF,meps); - if(fup.get(timeout)) { - access.log(Level.INFO, "Deregistration complete on",client.getURI()); - return Result.ok(fup.code(),null); - } else { - return Result.err(fup.code(),fup.body()); - } - } catch (APIException e) { - access.log(e, "Error deregistering service on AAF Locator"); - return Result.err(503,e.getMessage()); - } - - } catch (CadiException e) { - return Result.err(503,e.getMessage()); - } - } + @Override + public Result update(ENV env) { + try { + Rcli client = aafcon.client(locator); + try { + Future fup = client.update("/registration",mgmtEndpointsDF,meps); + if (fup.get(timeout)) { + access.log(Level.INFO, "Registration complete to",client.getURI()); + return Result.ok(fup.code(),null); + } else { + access.log(Level.ERROR,"Error registering to AAF Locator on ", client.getURI()); + return Result.err(fup.code(),fup.body()); + } + } catch (APIException e) { + access.log(e, "Error registering service to AAF Locator"); + return Result.err(503,e.getMessage()); + } + + } catch (CadiException e) { + return Result.err(503,e.getMessage()); + } + } + + @Override + public Result cancel(ENV env) { + try { + Rcli client = aafcon.client(locator); + try { + Future fup = client.delete("/registration",mgmtEndpointsDF,meps); + if (fup.get(timeout)) { + access.log(Level.INFO, "Deregistration complete on",client.getURI()); + return Result.ok(fup.code(),null); + } else { + return Result.err(fup.code(),fup.body()); + } + } catch (APIException e) { + access.log(e, "Error deregistering service on AAF Locator"); + return Result.err(503,e.getMessage()); + } + + } catch (CadiException e) { + return Result.err(503,e.getMessage()); + } + } }