add new devicemanager
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / impl / conf / odlAkka / ClusterNodeInfo.java
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.conf.odlAkka;
19
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
22
23 public  class ClusterNodeInfo {
24     private final String protocol;
25     private final String clusterName;
26     private final String remoteAdr;
27     private final int port;
28     private final String seedNodeName;
29
30     public static ClusterNodeInfo defaultSingleNodeInfo() {
31         return new ClusterNodeInfo("akka.tcp","opendaylight-cluster-data","127.0.0.1",2550);
32     }
33
34     public ClusterNodeInfo(String s) throws Exception {
35         final String regex = "([a-z.]*):\\/\\/([a-zA-Z0-9-]*)@([a-zA-Z0-9.-]*):([0-9]*)";
36         final Pattern pattern = Pattern.compile(regex);
37         final Matcher matcher = pattern.matcher(s);
38         if (!matcher.find()) {
39             throw new Exception("invalid seedNode format");
40         }
41         this.seedNodeName = matcher.group();
42         this.protocol = matcher.group(1);
43         this.clusterName = matcher.group(2);
44         this.remoteAdr = matcher.group(3);
45         this.port = Integer.parseInt(matcher.group(4));
46     }
47
48     public ClusterNodeInfo(String protocol, String clustername, String remoteadr, int port) {
49         this.protocol=protocol;
50         this.clusterName=clustername;
51         this.remoteAdr=remoteadr;
52         this.port=port;
53         this.seedNodeName=this.protocol+"://"+this.clusterName+"@"+this.remoteAdr+":"+this.port;
54     }
55
56     public String getProtocol() {
57         return protocol;
58     }
59
60     public String getClusterName() {
61         return clusterName;
62     }
63
64     public String getRemoteAddress() {
65         return remoteAdr;
66     }
67     public String getSeedNodeName() {
68         return seedNodeName;
69     }
70
71     public int getPort() {
72         return port;
73     }
74
75     @Override
76     public String toString() {
77         return "ClusterNodeInfo [protocol=" + protocol + ", clusterName=" + clusterName + ", remoteAdr=" + remoteAdr
78                 + ", port=" + port + ", seedNodeName=" + seedNodeName + "]";
79     }
80
81 }