- 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<ENV> rr : others) {
- meps.getMgmtEndpoint().add(rr.mep);
- }
- }
-
- @Override
- public Result<Void> update(ENV env) {
- try {
- Rcli<?> client = aafcon.client(locator);
- try {
- Future<MgmtEndpoints> 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());
- }
- }