2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
21 package org.onap.aaf.cadi.register;
23 import java.net.UnknownHostException;
24 import java.util.List;
26 import org.onap.aaf.cadi.Access;
27 import org.onap.aaf.cadi.CadiException;
28 import org.onap.aaf.cadi.aaf.Defaults;
29 import org.onap.aaf.cadi.config.Config;
30 import org.onap.aaf.cadi.config.RegistrationPropHolder;
31 import org.onap.aaf.cadi.util.Split;
33 import locate.v1_0.MgmtEndpoint;
34 import locate.v1_0.MgmtEndpoints;
36 public class RegistrationCreator {
37 private Access access;
39 public RegistrationCreator(Access access) {
43 public MgmtEndpoints create(final int port) throws CadiException {
44 MgmtEndpoints me = new MgmtEndpoints();
45 List<MgmtEndpoint> lme = me.getMgmtEndpoint();
46 MgmtEndpoint defData = null;
47 MgmtEndpoint locate = null;
53 RegistrationPropHolder ph = new RegistrationPropHolder(access, port);
55 // Now, loop through by Container
56 for(String le : Split.splitTrim(',', ph.lcontainer)) {
63 for(String entry : Split.splitTrim(',', ph.lentries)) {
65 defData = locate = new MgmtEndpoint();
67 version = access.getProperty(Config.AAF_LOCATOR_VERSION, Defaults.AAF_VERSION);
68 locate.setProtocol(access.getProperty(Config.AAF_LOCATOR_PROTOCOL,null));
69 List<String> ls = locate.getSubprotocol();
70 for(String sp : Split.splitTrim(',', access.getProperty(Config.AAF_LOCATOR_SUBPROTOCOL,""))) {
73 locate.setLatitude(ph.latitude);
74 locate.setLongitude(ph.longitude);
77 locate = copy(defData);
80 locate.setName(ph.getEntryName(entry,dot_le));
81 locate.setHostname(ph.getEntryFQDN(entry,dot_le));
82 locate.setPort(ph.getEntryPort(dot_le));
84 String specificVersion = access.getProperty(Config.AAF_LOCATOR_VERSION + dot_le,null);
85 if(specificVersion == null && locate == defData) {
86 specificVersion = version;
88 if(specificVersion!=null) {
89 String split[] = Split.splitTrim('.', specificVersion);
90 locate.setPkg(split.length>3?Integer.parseInt(split[3]):0);
91 locate.setPatch(split.length>2?Integer.parseInt(split[2]):0);
92 locate.setMinor(split.length>1?Integer.parseInt(split[1]):0);
93 locate.setMajor(split.length>0?Integer.parseInt(split[0]):0);
96 String protocol = access.getProperty(Config.AAF_LOCATOR_PROTOCOL + dot_le, null);
98 locate.setProtocol(protocol);
99 String subprotocols = access.getProperty(Config.AAF_LOCATOR_SUBPROTOCOL + dot_le, null);
100 if(subprotocols!=null) {
101 List<String> ls = locate.getSubprotocol();
102 for (String s : Split.split(',', subprotocols)) {
110 } catch (NumberFormatException | UnknownHostException e) {
111 throw new CadiException("Error extracting Data from Properties for Registrar",e);
117 private MgmtEndpoint copy(MgmtEndpoint mep) {
118 MgmtEndpoint out = new MgmtEndpoint();
119 out.setName(mep.getName());
120 out.setHostname(mep.getHostname());
121 out.setLatitude(mep.getLatitude());
122 out.setLongitude(mep.getLongitude());
123 out.setMajor(mep.getMajor());
124 out.setMinor(mep.getMinor());
125 out.setPkg(mep.getPkg());
126 out.setPatch(mep.getPatch());
127 out.setPort(mep.getPort());
128 out.setProtocol(mep.getProtocol());
129 out.getSpecialPorts().addAll(mep.getSpecialPorts());
130 out.getSubprotocol().addAll(mep.getSubprotocol());