diff options
author | HuabingZhao <zhao.huabing@zte.com.cn> | 2018-03-13 10:19:52 +0800 |
---|---|---|
committer | HuabingZhao <zhao.huabing@zte.com.cn> | 2018-03-13 10:27:20 +0800 |
commit | c9b3c2d143621f25a670049aadf61830d3ed321c (patch) | |
tree | bb76129f0ef5101b8fd69431bb6aab61c8101479 /apiroute/apiroute-service/src/main/java | |
parent | 556ec2e4d3fa31b96fe0d3f5a842254ad906af68 (diff) |
Support multiple versions under a service name
Modify the service name when sync service route from consul
Issue-ID: MSB-178
Change-Id: I5a1a3efe02a8cf7f56518d1b745505b049553810
Signed-off-by: HuabingZhao <zhao.huabing@zte.com.cn>
Diffstat (limited to 'apiroute/apiroute-service/src/main/java')
2 files changed, 21 insertions, 11 deletions
diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/serviceListener/MicroServiceChangeListener.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/serviceListener/MicroServiceChangeListener.java index 2e1b8ff..55b6676 100644 --- a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/serviceListener/MicroServiceChangeListener.java +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/serviceListener/MicroServiceChangeListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2016-2017 ZTE, Inc. and others. + * Copyright 2016-2018 ZTE, Inc. and others. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -105,8 +105,8 @@ public class MicroServiceChangeListener implements IMicroServiceChangeListener { return true; String protocol = microServiceInfo.getProtocol(); - String routeName = - RouteUtil.getRouteNameByns(microServiceInfo.getServiceName(), microServiceInfo.getNamespace()); + String routeName = RouteUtil.getRouteNameByns(microServiceInfo.getServiceName(), microServiceInfo.getVersion(), + microServiceInfo.getNamespace()); String publishUrl = ""; String version = ""; if (StringUtils.isNotBlank(microServiceInfo.getVersion())) { @@ -156,8 +156,8 @@ public class MicroServiceChangeListener implements IMicroServiceChangeListener { */ private void saveServiceByProtocol(MicroServiceFullInfo microServiceInfo, String routeWay) throws Exception { String protocol = microServiceInfo.getProtocol(); - String routeName = - RouteUtil.getRouteNameByns(microServiceInfo.getServiceName(), microServiceInfo.getNamespace()); + String routeName = RouteUtil.getRouteNameByns(microServiceInfo.getServiceName(), microServiceInfo.getVersion(), + microServiceInfo.getNamespace()); switch (protocol) { case RouteUtil.PROTOCOL_UI: @@ -195,8 +195,8 @@ public class MicroServiceChangeListener implements IMicroServiceChangeListener { private void deleteServiceByProtocol(MicroServiceFullInfo microServiceInfo, String routeWay) { String protocol = microServiceInfo.getProtocol(); String host = getHost(microServiceInfo); - String routeName = - RouteUtil.getRouteNameByns(microServiceInfo.getServiceName(), microServiceInfo.getNamespace()); + String routeName = RouteUtil.getRouteNameByns(microServiceInfo.getServiceName(), microServiceInfo.getVersion(), + microServiceInfo.getNamespace()); if (RouteUtil.PROTOCOL_UI.equals(protocol)) { @@ -502,7 +502,7 @@ public class MicroServiceChangeListener implements IMicroServiceChangeListener { if (RouteUtil.ROUTEWAY_DOMAIN.equals(routeWay)) { String discoverServiceName = RouteUtil.getRouteNameByns(microServiceInfo.getServiceName(), - microServiceInfo.getNamespace()); + microServiceInfo.getVersion(), microServiceInfo.getNamespace()); List<Node> publishNodes = getPublishNodes(discoverServiceName, microServiceInfo.getVersion(), microServiceInfo.getNamespace()); if (publishNodes != null && publishNodes.size() > 0) { diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/util/RouteUtil.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/util/RouteUtil.java index ae60f50..5f9557f 100644 --- a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/util/RouteUtil.java +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/util/RouteUtil.java @@ -294,14 +294,24 @@ public class RouteUtil { * @return * @return String */ - public static String getRouteNameByns(String consul_serviceName, String namespace) { + public static String getRouteNameByns(String consul_serviceName, String version, String namespace) { String serviceName = consul_serviceName; - if (StringUtils.isNotBlank(namespace)) { + // Remove version and namespace from consul service name + // Consul_serviceName Format: serviceName-version-namespace + if (StringUtils.isNotBlank(version) && StringUtils.isNotBlank(namespace)) { + if (consul_serviceName.endsWith("-" + version + "-" + namespace)) { + serviceName = consul_serviceName.substring(0, + consul_serviceName.length() - version.length() - namespace.length() - 2); + } + } else if (StringUtils.isNotBlank(version)) { + if (consul_serviceName.endsWith("-" + version)) { + serviceName = consul_serviceName.substring(0, consul_serviceName.length() - version.length() - 1); + } + } else if (StringUtils.isNotBlank(namespace)) { if (consul_serviceName.endsWith("-" + namespace)) { serviceName = consul_serviceName.substring(0, consul_serviceName.length() - namespace.length() - 1); } } - return serviceName; } |