From c58657cd2a5d14389ab235c65a43283300ac3cfe Mon Sep 17 00:00:00 2001 From: HuabingZhao Date: Fri, 18 Aug 2017 17:27:07 +0800 Subject: Change comments to English Issue_Id: MSB-22 Change-Id: I9cc5eee1adeb3c271f543ff6a8ff717764ccd5a7 Signed-off-by: HuabingZhao --- .../sdk/discovery/entity/MicroServiceFullInfo.java | 2 +- .../msb/sdk/httpclient/RetrofitServiceCreater.java | 10 +- .../msb/sdk/httpclient/conf/HttpClientConf.java | 4 - .../handler/RetrofitServiceHandlerContext.java | 8 +- .../handler/RetrofitServiceHandlerFactory.java | 4 +- .../msb/sdk/httpclient/msb/MSBServiceClient.java | 106 ++++++++++++++ .../httpclient/msb/MSBServiceWrapperClient.java | 162 --------------------- 7 files changed, 116 insertions(+), 180 deletions(-) create mode 100644 src/main/java/org/onap/msb/sdk/httpclient/msb/MSBServiceClient.java delete mode 100644 src/main/java/org/onap/msb/sdk/httpclient/msb/MSBServiceWrapperClient.java (limited to 'src') diff --git a/src/main/java/org/onap/msb/sdk/discovery/entity/MicroServiceFullInfo.java b/src/main/java/org/onap/msb/sdk/discovery/entity/MicroServiceFullInfo.java index 698092e..e874962 100644 --- a/src/main/java/org/onap/msb/sdk/discovery/entity/MicroServiceFullInfo.java +++ b/src/main/java/org/onap/msb/sdk/discovery/entity/MicroServiceFullInfo.java @@ -24,7 +24,7 @@ public class MicroServiceFullInfo extends Service implements Serializa private Set nodes; - // 状态 0:不可用 1:可用,预留 + //Reserved private String status = "1"; public Set getNodes() { diff --git a/src/main/java/org/onap/msb/sdk/httpclient/RetrofitServiceCreater.java b/src/main/java/org/onap/msb/sdk/httpclient/RetrofitServiceCreater.java index 413189c..fba8518 100644 --- a/src/main/java/org/onap/msb/sdk/httpclient/RetrofitServiceCreater.java +++ b/src/main/java/org/onap/msb/sdk/httpclient/RetrofitServiceCreater.java @@ -24,22 +24,18 @@ import java.util.List; import org.onap.msb.sdk.httpclient.conf.HttpClientConf; import org.onap.msb.sdk.httpclient.handler.RetrofitServiceHandlerContext; import org.onap.msb.sdk.httpclient.handler.RetrofitServiceHandlerFactory; -import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; +import org.onap.msb.sdk.httpclient.msb.MSBServiceClient; -/** - * @author 10071214 - * - */ public class RetrofitServiceCreater { private RetrofitServiceHandlerFactory factory = new RetrofitServiceHandlerFactory(); - private MSBServiceWrapperClient msbClient; + private MSBServiceClient msbClient; public RetrofitServiceCreater(HttpClientConf globalHttpClientConf, - MSBServiceWrapperClient msbClient) { + MSBServiceClient msbClient) { RetrofitServiceHandlerContext.setGlobalHttpClientConf(globalHttpClientConf); this.msbClient = msbClient; diff --git a/src/main/java/org/onap/msb/sdk/httpclient/conf/HttpClientConf.java b/src/main/java/org/onap/msb/sdk/httpclient/conf/HttpClientConf.java index f3e5006..3e6b491 100644 --- a/src/main/java/org/onap/msb/sdk/httpclient/conf/HttpClientConf.java +++ b/src/main/java/org/onap/msb/sdk/httpclient/conf/HttpClientConf.java @@ -18,10 +18,6 @@ package org.onap.msb.sdk.httpclient.conf; import com.fasterxml.jackson.annotation.JsonProperty; -/** - * @author 10071214 - * - */ public class HttpClientConf { @JsonProperty diff --git a/src/main/java/org/onap/msb/sdk/httpclient/handler/RetrofitServiceHandlerContext.java b/src/main/java/org/onap/msb/sdk/httpclient/handler/RetrofitServiceHandlerContext.java index 68ee16c..713d0f6 100644 --- a/src/main/java/org/onap/msb/sdk/httpclient/handler/RetrofitServiceHandlerContext.java +++ b/src/main/java/org/onap/msb/sdk/httpclient/handler/RetrofitServiceHandlerContext.java @@ -23,7 +23,7 @@ import org.onap.msb.sdk.httpclient.conf.HttpClientConf; import org.onap.msb.sdk.httpclient.convert.IConverterFactoryBuilder; import org.onap.msb.sdk.httpclient.lb.ILoadBalanceStrategy; import org.onap.msb.sdk.httpclient.metric.MetricManager; -import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; +import org.onap.msb.sdk.httpclient.msb.MSBServiceClient; /** @@ -65,7 +65,7 @@ public class RetrofitServiceHandlerContext { private HttpClientConf httpClientConf; - private MSBServiceWrapperClient msbClient; + private MSBServiceClient msbClient; @@ -79,11 +79,11 @@ public class RetrofitServiceHandlerContext { - public MSBServiceWrapperClient getMsbClient() { + public MSBServiceClient getMsbClient() { return msbClient; } - public void setMsbClient(MSBServiceWrapperClient msbClient) { + public void setMsbClient(MSBServiceClient msbClient) { this.msbClient = msbClient; } diff --git a/src/main/java/org/onap/msb/sdk/httpclient/handler/RetrofitServiceHandlerFactory.java b/src/main/java/org/onap/msb/sdk/httpclient/handler/RetrofitServiceHandlerFactory.java index fb78820..1d65661 100644 --- a/src/main/java/org/onap/msb/sdk/httpclient/handler/RetrofitServiceHandlerFactory.java +++ b/src/main/java/org/onap/msb/sdk/httpclient/handler/RetrofitServiceHandlerFactory.java @@ -28,7 +28,7 @@ import org.onap.msb.sdk.httpclient.handler.impl.LBBuilder; import org.onap.msb.sdk.httpclient.handler.impl.MetricmanagerBuilder; import org.onap.msb.sdk.httpclient.handler.impl.RetrofitHandlerContextBuilder; import org.onap.msb.sdk.httpclient.handler.impl.ServiceHttpEndPointBeanObjectBuilder; -import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; +import org.onap.msb.sdk.httpclient.msb.MSBServiceClient; import com.google.common.collect.Lists; @@ -89,7 +89,7 @@ public class RetrofitServiceHandlerFactory { public InvocationHandler buildInvocationHandler(Class retrofitSrvInterfaceClazz, ServiceHttpEndPointBeanObject serviceHttpEndPointBeanObject, HttpClientConf httpClientConf, - MSBServiceWrapperClient msbClient) { + MSBServiceClient msbClient) { RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext(); ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz); diff --git a/src/main/java/org/onap/msb/sdk/httpclient/msb/MSBServiceClient.java b/src/main/java/org/onap/msb/sdk/httpclient/msb/MSBServiceClient.java new file mode 100644 index 0000000..34aae64 --- /dev/null +++ b/src/main/java/org/onap/msb/sdk/httpclient/msb/MSBServiceClient.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright 2017 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + ******************************************************************************/ +package org.onap.msb.sdk.httpclient.msb; + +import java.util.concurrent.Callable; + +import org.onap.msb.sdk.discovery.MSBService; +import org.onap.msb.sdk.discovery.common.RouteException; +import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo; +import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; +import org.onap.msb.sdk.discovery.entity.NodeAddress; +import org.onap.msb.sdk.discovery.entity.RouteResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class MSBServiceClient { + + private static final Logger logger = LoggerFactory.getLogger(MSBServiceClient.class); + + private String msbSvrAddress; + + private MSBService msbService = new MSBService(); + + public MSBServiceClient(String msbSvrIp, int msbSvrPort) { + super(); + this.msbSvrAddress = msbSvrIp + ":" + msbSvrPort; + + logger.info("msb service info:msbSvrAddress:{}", this.msbSvrAddress); + } + + public MicroServiceFullInfo queryMicroServiceInfo(String serviceName, String version) + throws RouteException { + return invokeMsb(() -> msbService.queryMicroServiceInfo(msbSvrAddress, serviceName, version)); + } + + private V invokeMsb(Callable callable) throws RouteException { + try { + return callable.call(); + } catch (Exception e) { + logger.error("msb service info:msbSvrAddress:" + this.msbSvrAddress, e); + if (e instanceof RouteException) { + throw (RouteException) e; + } else { + throw new RuntimeException(e); + } + } + + } + + + public MicroServiceFullInfo registerMicroServiceInfo(MicroServiceInfo msinfo) + throws RouteException { + + return invokeMsb(() -> msbService.registerMicroServiceInfo(msbSvrAddress, msinfo)); + } + + + + public MicroServiceFullInfo registerMicroServiceInfo(MicroServiceInfo msinfo, + boolean createOrUpdate) throws RouteException { + + return invokeMsb( + () -> msbService.registerMicroServiceInfo(msbSvrAddress, msinfo, createOrUpdate)); + } + + + + /** + * unregister all the instances of a service + */ + public RouteResult cancelMicroServiceInfo(String serviceName, String version) + throws RouteException { + return invokeMsb(() -> msbService.cancelMicroServiceInfo(msbSvrAddress, serviceName, version)); + } + + + + /** + * unregister the specified instance of a service + */ + + public RouteResult cancelMicroServiceInfo(String serviceName, String version, String ip, + String port) throws RouteException { + + return invokeMsb( + () -> msbService.cancelMicroServiceInfo(msbSvrAddress, serviceName, version, ip, port)); + } + + + public String getMsbSvrAddress() { + return msbSvrAddress; + } + +} diff --git a/src/main/java/org/onap/msb/sdk/httpclient/msb/MSBServiceWrapperClient.java b/src/main/java/org/onap/msb/sdk/httpclient/msb/MSBServiceWrapperClient.java deleted file mode 100644 index f72f711..0000000 --- a/src/main/java/org/onap/msb/sdk/httpclient/msb/MSBServiceWrapperClient.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright 2017 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - ******************************************************************************/ -package org.onap.msb.sdk.httpclient.msb; - -import java.util.concurrent.Callable; - -import org.onap.msb.sdk.discovery.MSBService; -import org.onap.msb.sdk.discovery.common.RouteException; -import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo; -import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; -import org.onap.msb.sdk.discovery.entity.NodeAddress; -import org.onap.msb.sdk.discovery.entity.RouteResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class MSBServiceWrapperClient { - - private static final Logger logger = LoggerFactory.getLogger(MSBServiceWrapperClient.class); - - private String msbSvrAddress; - - private MSBService msbService = new MSBService(); - - private String nameSpace; - - public MSBServiceWrapperClient(String msbSvrIp, int msbSvrPort) { - super(); - this.msbSvrAddress = msbSvrIp + ":" + msbSvrPort; - - logger.info("msb service info:msbSvrAddress:{},nameSpace:{}", this.msbSvrAddress, - this.nameSpace); - - } - - public MicroServiceFullInfo queryMicroServiceInfo(String serviceName, String version) - throws RouteException { - - return invokeMsb(() -> msbService.queryMicroServiceInfo(msbSvrAddress, serviceName, version)); - - - } - - private V invokeMsb(Callable callable) throws RouteException { - try { - return callable.call(); - } catch (Exception e) { - logger.error("msb service info:msbSvrAddress:" + this.msbSvrAddress, e); - if (e instanceof RouteException) { - throw (RouteException) e; - } else { - throw new RuntimeException(e); - } - } - - } - - - /** - * 注册微服务-默认追加方式,在msb上注册服务信息,服务的信息都可以填充在MicroServiceInfo上,包括:租户的信息等 - * - * @param microServiceInfo 微服务注册实体类 - * @throws RouteException - * @return MicroServiceFullInfo - */ - public MicroServiceFullInfo registerMicroServiceInfo(MicroServiceInfo msinfo) - throws RouteException { - - return invokeMsb(() -> msbService.registerMicroServiceInfo(msbSvrAddress, msinfo)); - } - - - - /** - * 注册微服务,在msb上注册服务信息,服务的信息都可以填充在MicroServiceInfo上,包括:租户的信息等 - * - * @param microServiceInfo 微服务注册实体类 - * @param createOrUpdate true:新增或追加更新 ,false:重新添加 - * @throws RouteException - * @return MicroServiceFullInfo - */ - public MicroServiceFullInfo registerMicroServiceInfo(MicroServiceInfo msinfo, - boolean createOrUpdate) throws RouteException { - - return invokeMsb( - () -> msbService.registerMicroServiceInfo(msbSvrAddress, msinfo, createOrUpdate)); - } - - - - /** - * @Title cancelMicroServiceInfo - * @Description TODO(注销全部微服务) - * @param serviceName 服务名[必填,若自定义服务名包含/,用*代替] - * @param version 版本号[若无版本号,传空字符串] - * @throws RouteException - * @return RouteResult - */ - public RouteResult cancelMicroServiceInfo(String serviceName, String version) - throws RouteException { - return invokeMsb(() -> msbService.cancelMicroServiceInfo(msbSvrAddress, serviceName, version)); - } - - - - /** - * 注销单个微服务 - * - * @param serviceName 服务名[必填,若自定义服务名包含/,用*代替] - * @param version 版本号[若无版本号,传空字符串] - * @param ip - * @param port - * @throws RouteException - * @return RouteResult - */ - - public RouteResult cancelMicroServiceInfo(String serviceName, String version, String ip, - String port) throws RouteException { - - return invokeMsb( - () -> msbService.cancelMicroServiceInfo(msbSvrAddress, serviceName, version, ip, port)); - } - - - public String getMsbSvrAddress() { - return msbSvrAddress; - } - - - - /** - * 请求服务实例TTL健康检查,默认使用本租户的信息 - * - * @param serviceName 服务名 - * @param version 版本号[若无版本号,传空字符串] - * @param ip 实例IP - * @param port 实例端口 - * @throws RouteException - * @return CheckNode - */ - public NodeAddress healthCheckbyTTL(String serviceName, String version, String ip, String port) - throws RouteException { - - return invokeMsb( - () -> msbService.healthCheckbyTTL(msbSvrAddress, serviceName, version, ip, port)); - - } - - - -} -- cgit 1.2.3-korg