remove not required docs and .readthedocs.yaml
[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.common.RouteException;
21 import org.onap.msb.sdk.discovery.entity.Node;
22 import org.onap.msb.sdk.discovery.entity.NodeInfo;
23
24 /**
25  * @ClassName: MsbUtil
26  * @Description: Utils for MSB
27  * @author tanghua10186366
28  * @date 2017/6/26
29  *
30  */
31 public class MsbUtil {
32
33
34   /**
35    * @Title getConsulServiceName
36    * @Description
37    * @param serviceName
38    * @param namespace
39    * @return String
40    */
41   public static String getConsulServiceName(String serviceName, String namespace) {
42     if (StringUtils.isEmpty(namespace)) {
43       return serviceName;
44     } else {
45       return serviceName + "-" + namespace;
46     }
47   }
48
49   public static Set<NodeInfo> getLbNodes(Node lbNode) {
50     Set<NodeInfo> nodes = new HashSet<NodeInfo>();
51     NodeInfo nodeInfo = new NodeInfo();
52     nodeInfo.setIp(lbNode.getIp());
53     nodeInfo.setPort(lbNode.getPort());
54     nodes.add(nodeInfo);
55
56     return nodes;
57   }
58   
59   public static void checkServiceName(String serviceName) throws RouteException{
60         
61             if (StringUtils.isBlank(serviceName)) {
62               throw new RouteException("ServiceName  can't be empty", "DATA_FORMAT_ERROR");
63             }
64   }
65   
66   public static String checkVersion(String version) throws RouteException{
67             if (StringUtils.isNotBlank(version)) {
68               if (!RegExpTestUtil.versionRegExpTest(version)) {
69                 throw new RouteException("version is not a valid  format", "DATA_FORMAT_ERROR");
70               }
71             } else {
72               version = "null";
73             }
74             
75             return version;
76   }
77   
78   public static void checkHost(String ip,String port) throws RouteException{
79             if (StringUtils.isBlank(ip)) {
80               throw new RouteException("ip can't be empty", "DATA_FORMAT_ERROR");
81
82             }
83
84             if (StringUtils.isBlank(port)) {
85               throw new RouteException("port can't be empty", "DATA_FORMAT_ERROR");
86
87             }
88   }
89
90 }