msb discovery java client
[msb/java-sdk.git] / src / main / java / org / onap / msb / sdk / discovery / util / MsbUtil.java
1 /*******************************************************************************
2  * Copyright 2017 ZTE, Inc. and others.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  * 
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * 
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  ******************************************************************************/
14 package org.onap.msb.sdk.discovery.util;
15
16 import java.util.HashSet;
17 import java.util.Set;
18
19 import org.apache.commons.lang3.StringUtils;
20 import org.onap.msb.sdk.discovery.entity.Node;
21 import org.onap.msb.sdk.discovery.entity.NodeInfo;
22
23 /**
24  * @ClassName: MsbUtil
25  * @Description: TODO(msb功能工具方法类)
26  * @author tanghua10186366
27  * @date 2017年6月26日
28  * 
29  */
30 public class MsbUtil {
31
32
33   /**
34    * @Title getConsulServiceName
35    * @Description TODO(通过服务名和命名空间组装conusl存储名,用于服务变化监听)
36    * @param serviceName
37    * @param namespace
38    * @return String
39    */
40   public static String getConsulServiceName(String serviceName, String namespace) {
41     if (StringUtils.isEmpty(namespace)) {
42       return serviceName;
43     } else {
44       return serviceName + "-" + namespace;
45     }
46   }
47
48   public static Set<NodeInfo> getLbNodes(Node lbNode) {
49     Set<NodeInfo> nodes = new HashSet<NodeInfo>();
50     NodeInfo nodeInfo = new NodeInfo();
51     nodeInfo.setIp(lbNode.getIp());
52     nodeInfo.setPort(lbNode.getPort());
53     nodes.add(nodeInfo);
54
55     return nodes;
56   }
57
58 }