1 /*******************************************************************************
2 * Copyright 2017 ZTE, Inc. and others.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
13 ******************************************************************************/
14 package org.onap.msb.sdk.discovery.util;
16 import java.util.HashSet;
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;
26 * @Description: Utils for MSB
27 * @author tanghua10186366
31 public class MsbUtil {
35 * @Title getConsulServiceName
41 public static String getConsulServiceName(String serviceName, String namespace) {
42 if (StringUtils.isEmpty(namespace)) {
45 return serviceName + "-" + namespace;
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());
59 public static void checkServiceName(String serviceName) throws RouteException{
61 if (StringUtils.isBlank(serviceName)) {
62 throw new RouteException("ServiceName can't be empty", "DATA_FORMAT_ERROR");
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");
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");
84 if (StringUtils.isBlank(port)) {
85 throw new RouteException("port can't be empty", "DATA_FORMAT_ERROR");