From 3f06a7a0f839e9b03143e93f3b085ce7002168c5 Mon Sep 17 00:00:00 2001 From: "nov.lzf" Date: Fri, 17 Jul 2020 12:03:30 +0800 Subject: [PATCH] response model optimize (#3357) * Add gprc support-> add grpc log to distribution logback * Add gprc support-> response model optimize --- .../request/ConfigChangeListenRequest.java | 1 + .../response/ConfigChangeListenResponse.java | 31 ++++++++++-- .../response/ConfigChangeNotifyResponse.java | 23 +++++---- .../remote/response/ConfigPubishResponse.java | 12 +++-- .../remote/response/ConfigQueryResponse.java | 22 ++++---- .../remote/response/ConfigRemoveResponse.java | 12 +++-- .../remote/response/InstanceResponse.java | 13 +++-- .../remote/response/ServiceQueryResponse.java | 21 ++++++-- .../nacos/api/remote/ResponseRegistry.java | 2 + .../remote/response/ConnectResetResponse.java | 5 +- .../remote/response/HeartBeatResponse.java | 6 +-- .../remote/response/PlainBodyResponse.java | 5 +- .../nacos/api/remote/response/Response.java | 38 +++----------- .../response/ResponseTypeConstants.java | 3 ++ .../api/remote/response/UnKnowResponse.java | 31 ++++++++++++ .../ConfigChangeListenRequestHandler.java | 2 +- .../core/remote/HeartBeatRequestHandler.java | 19 ++++--- .../nacos/core/remote/grpc/GrpcUtils.java | 9 ++-- distribution/conf/nacos-logback.xml | 50 ++++++++++++++++++- .../handler/InstanceRequestHandler.java | 6 +-- 20 files changed, 213 insertions(+), 98 deletions(-) create mode 100644 api/src/main/java/com/alibaba/nacos/api/remote/response/UnKnowResponse.java diff --git a/api/src/main/java/com/alibaba/nacos/api/config/remote/request/ConfigChangeListenRequest.java b/api/src/main/java/com/alibaba/nacos/api/config/remote/request/ConfigChangeListenRequest.java index 527c33d95..e318392de 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/remote/request/ConfigChangeListenRequest.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/remote/request/ConfigChangeListenRequest.java @@ -18,6 +18,7 @@ package com.alibaba.nacos.api.config.remote.request; /** + * ConfigChangeListenRequest. * @author liuzunfei * @version $Id: ConfigChangeListenRequest.java, v 0.1 2020年07月13日 9:01 PM liuzunfei Exp $ */ diff --git a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeListenResponse.java b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeListenResponse.java index 3c3ba8ea3..da6d1373e 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeListenResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeListenResponse.java @@ -17,6 +17,7 @@ package com.alibaba.nacos.api.config.remote.response; import com.alibaba.nacos.api.remote.response.Response; +import com.alibaba.nacos.api.remote.response.ResponseCode; /** * ConfigChangeListenResponse. @@ -26,13 +27,37 @@ import com.alibaba.nacos.api.remote.response.Response; */ public class ConfigChangeListenResponse extends Response { - public ConfigChangeListenResponse() { super(); } - public ConfigChangeListenResponse(int resultCode, String message) { - super(ConfigResponseTypeConstants.CONFIG_CHANGE, resultCode, message); + @Override + public String getType() { + return ConfigResponseTypeConstants.CONFIG_CHANGE; + } + + /** + * build sucess response. + * + * @return + */ + public static ConfigChangeListenResponse buildSucessResponse() { + ConfigChangeListenResponse response = new ConfigChangeListenResponse(); + response.setResultCode(ResponseCode.SUCCESS.getCode()); + return response; + } + + /** + * build fail response. + * + * @param errorMessage errorMessage. + * @return + */ + public static ConfigChangeListenResponse buildFailResponse(String errorMessage) { + ConfigChangeListenResponse response = new ConfigChangeListenResponse(); + response.setResultCode(ResponseCode.FAIL.getCode()); + response.setMessage(errorMessage); + return response; } } diff --git a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeNotifyResponse.java b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeNotifyResponse.java index 360dc3b95..6f6fe73b8 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeNotifyResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigChangeNotifyResponse.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.alibaba.nacos.api.config.remote.response; import com.alibaba.nacos.api.remote.response.Response; @@ -25,17 +26,18 @@ import com.alibaba.nacos.api.remote.response.ResponseCode; public class ConfigChangeNotifyResponse extends Response { private String dataId; - + private String group; - + private String tenant; public ConfigChangeNotifyResponse() { } - public ConfigChangeNotifyResponse(int resultCode, String message) { - super(ConfigResponseTypeConstants.CONFIG_CHANGE_NOTIFY, resultCode, message); + @Override + public String getType() { + return ConfigResponseTypeConstants.CONFIG_CHANGE_NOTIFY; } /** @@ -47,8 +49,7 @@ public class ConfigChangeNotifyResponse extends Response { * @return ConfigChangeNotifyResponse */ public static ConfigChangeNotifyResponse buildSuccessResponse(String dataId, String group, String tenant) { - ConfigChangeNotifyResponse response = new ConfigChangeNotifyResponse(ResponseCode.SUCCESS.getCode(), - "data changed"); + ConfigChangeNotifyResponse response = new ConfigChangeNotifyResponse(); response.setDataId(dataId); response.setGroup(group); response.setTenant(tenant); @@ -63,7 +64,7 @@ public class ConfigChangeNotifyResponse extends Response { public String getDataId() { return dataId; } - + /** * Setter method for property dataId. * @@ -72,7 +73,7 @@ public class ConfigChangeNotifyResponse extends Response { public void setDataId(String dataId) { this.dataId = dataId; } - + /** * Getter method for property group. * @@ -81,7 +82,7 @@ public class ConfigChangeNotifyResponse extends Response { public String getGroup() { return group; } - + /** * Setter method for property group. * @@ -90,7 +91,7 @@ public class ConfigChangeNotifyResponse extends Response { public void setGroup(String group) { this.group = group; } - + /** * Getter method for property tenant. * @@ -99,7 +100,7 @@ public class ConfigChangeNotifyResponse extends Response { public String getTenant() { return tenant; } - + /** * Setter method for property tenant. * diff --git a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigPubishResponse.java b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigPubishResponse.java index 9fa57819f..aa7baa94a 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigPubishResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigPubishResponse.java @@ -31,8 +31,9 @@ public class ConfigPubishResponse extends Response { super(); } - public ConfigPubishResponse(int resultCode, String message) { - super(ConfigResponseTypeConstants.CONFIG_PUBLISH, resultCode, message); + @Override + public String getType() { + return ConfigResponseTypeConstants.CONFIG_PUBLISH; } /** @@ -41,7 +42,7 @@ public class ConfigPubishResponse extends Response { * @return */ public static ConfigPubishResponse buildSuccessResponse() { - return new ConfigPubishResponse(ResponseCode.SUCCESS.getCode(), ""); + return new ConfigPubishResponse(); } /** @@ -50,6 +51,9 @@ public class ConfigPubishResponse extends Response { * @return */ public static ConfigPubishResponse buildFailResponse(String errorMsg) { - return new ConfigPubishResponse(ResponseCode.FAIL.getCode(), errorMsg); + ConfigPubishResponse configPubishResponse = new ConfigPubishResponse(); + configPubishResponse.setResultCode(ResponseCode.FAIL.getCode()); + configPubishResponse.setMessage(errorMsg); + return configPubishResponse; } } \ No newline at end of file diff --git a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigQueryResponse.java b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigQueryResponse.java index 36ccb9612..6a06d7b23 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigQueryResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigQueryResponse.java @@ -41,14 +41,18 @@ public class ConfigQueryResponse extends Response { Map labels = new HashMap(); public ConfigQueryResponse() { - super(ConfigResponseTypeConstants.CONFIG_QUERY); + } + + @Override + public String getType() { + return ConfigResponseTypeConstants.CONFIG_QUERY; } /** * add label to this response. * - * @param key - * @param value + * @param key key. + * @param value value. */ public void addLabel(String key, String value) { this.labels.put(key, value); @@ -62,19 +66,21 @@ public class ConfigQueryResponse extends Response { * @return */ public static ConfigQueryResponse buildFailResponse(int errorCode, String message) { - ConfigQueryResponse response = new ConfigQueryResponse(ResponseCode.FAIL.getCode(), message); + ConfigQueryResponse response = new ConfigQueryResponse(); + response.setResultCode(ResponseCode.FAIL.getCode()); response.setErrorCode(errorCode); + response.setMessage(message); return response; } /** * Buidl success resposne. * - * @param content. + * @param content content. * @return */ public static ConfigQueryResponse buildSuccessResponse(String content) { - ConfigQueryResponse response = new ConfigQueryResponse(ResponseCode.SUCCESS.getCode(), ""); + ConfigQueryResponse response = new ConfigQueryResponse(); response.setContent(content); return response; } @@ -115,10 +121,6 @@ public class ConfigQueryResponse extends Response { this.content = content; } - public ConfigQueryResponse(int resultCode, String message) { - super(ConfigResponseTypeConstants.CONFIG_QUERY, resultCode, message); - } - /** * Getter method for property contentType. * diff --git a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigRemoveResponse.java b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigRemoveResponse.java index 0b43f29aa..9e593aea5 100644 --- a/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigRemoveResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/config/remote/response/ConfigRemoveResponse.java @@ -31,8 +31,9 @@ public class ConfigRemoveResponse extends Response { super(); } - public ConfigRemoveResponse(int resultCode, String message) { - super(ConfigResponseTypeConstants.CONFIG_REMOVE, resultCode, message); + @Override + public String getType() { + return ConfigResponseTypeConstants.CONFIG_REMOVE; } /** @@ -41,7 +42,7 @@ public class ConfigRemoveResponse extends Response { * @return */ public static ConfigRemoveResponse buildSuccessResponse() { - return new ConfigRemoveResponse(ResponseCode.SUCCESS.getCode(), ""); + return new ConfigRemoveResponse(); } /** @@ -50,6 +51,9 @@ public class ConfigRemoveResponse extends Response { * @return */ public static ConfigRemoveResponse buildFailResponse(String errorMsg) { - return new ConfigRemoveResponse(ResponseCode.FAIL.getCode(), errorMsg); + ConfigRemoveResponse removeResponse = new ConfigRemoveResponse(); + removeResponse.setResultCode(ResponseCode.FAIL.getCode()); + removeResponse.setMessage(errorMsg); + return removeResponse; } } \ No newline at end of file diff --git a/api/src/main/java/com/alibaba/nacos/api/naming/remote/response/InstanceResponse.java b/api/src/main/java/com/alibaba/nacos/api/naming/remote/response/InstanceResponse.java index 4c7b11699..5f834a46e 100644 --- a/api/src/main/java/com/alibaba/nacos/api/naming/remote/response/InstanceResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/naming/remote/response/InstanceResponse.java @@ -25,15 +25,18 @@ import com.alibaba.nacos.api.remote.response.Response; */ public class InstanceResponse extends Response { + private String type; + public InstanceResponse() { } - public InstanceResponse(int resultCode, String message, String type) { - this(resultCode, 0, message, type); + @Override + public String getType() { + return this.type; } - public InstanceResponse(int resultCode, int errorCode, String message, String type) { - super(type, resultCode, message); - setErrorCode(errorCode); + public InstanceResponse(String type) { + this.type = type; } + } diff --git a/api/src/main/java/com/alibaba/nacos/api/naming/remote/response/ServiceQueryResponse.java b/api/src/main/java/com/alibaba/nacos/api/naming/remote/response/ServiceQueryResponse.java index 2ac9b9644..a485006a7 100644 --- a/api/src/main/java/com/alibaba/nacos/api/naming/remote/response/ServiceQueryResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/naming/remote/response/ServiceQueryResponse.java @@ -19,6 +19,7 @@ package com.alibaba.nacos.api.naming.remote.response; import com.alibaba.nacos.api.naming.pojo.ServiceInfo; import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants; import com.alibaba.nacos.api.remote.response.Response; +import com.alibaba.nacos.api.remote.response.ResponseCode; /** * Nacos naming query request. @@ -30,16 +31,28 @@ public class ServiceQueryResponse extends Response { private ServiceInfo serviceInfo; public ServiceQueryResponse() { - setType(NamingRemoteConstants.QUERY_SERVICE); + } + + @Override + public String getType() { + return NamingRemoteConstants.QUERY_SERVICE; } public ServiceQueryResponse(ServiceInfo serviceInfo) { - this(200, "success"); this.serviceInfo = serviceInfo; } - public ServiceQueryResponse(int resultCode, String message) { - super(NamingRemoteConstants.QUERY_SERVICE, resultCode, message); + public static ServiceQueryResponse buildSuccessResponse(ServiceInfo serviceInfo) { + ServiceQueryResponse serviceQueryResponse = new ServiceQueryResponse(); + serviceQueryResponse.setServiceInfo(serviceInfo); + return serviceQueryResponse; + } + + public static ServiceQueryResponse buildFailResponse(String message) { + ServiceQueryResponse serviceQueryResponse = new ServiceQueryResponse(); + serviceQueryResponse.setResultCode(ResponseCode.FAIL.getCode()); + serviceQueryResponse.setMessage(message); + return serviceQueryResponse; } public ServiceInfo getServiceInfo() { diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/ResponseRegistry.java b/api/src/main/java/com/alibaba/nacos/api/remote/ResponseRegistry.java index fb0285e44..22ab7fd4f 100644 --- a/api/src/main/java/com/alibaba/nacos/api/remote/ResponseRegistry.java +++ b/api/src/main/java/com/alibaba/nacos/api/remote/ResponseRegistry.java @@ -28,6 +28,7 @@ import com.alibaba.nacos.api.naming.remote.response.ServiceQueryResponse; import com.alibaba.nacos.api.remote.response.ConnectResetResponse; import com.alibaba.nacos.api.remote.response.HeartBeatResponse; import com.alibaba.nacos.api.remote.response.ResponseTypeConstants; +import com.alibaba.nacos.api.remote.response.UnKnowResponse; import java.util.HashMap; import java.util.Map; @@ -47,6 +48,7 @@ public class ResponseRegistry { //internal response regitry REGISTRY_RESPONSES.put(ResponseTypeConstants.HEART_BEAT, HeartBeatResponse.class); REGISTRY_RESPONSES.put(ResponseTypeConstants.CONNECT_SWITCH, ConnectResetResponse.class); + REGISTRY_RESPONSES.put(ResponseTypeConstants.UNKNOW, UnKnowResponse.class); //config response registry REGISTRY_RESPONSES.put(ConfigResponseTypeConstants.CONFIG_CHANGE, ConfigChangeListenResponse.class); diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/response/ConnectResetResponse.java b/api/src/main/java/com/alibaba/nacos/api/remote/response/ConnectResetResponse.java index fcdb2e6e2..70cb1c137 100644 --- a/api/src/main/java/com/alibaba/nacos/api/remote/response/ConnectResetResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/remote/response/ConnectResetResponse.java @@ -24,7 +24,8 @@ package com.alibaba.nacos.api.remote.response; */ public class ConnectResetResponse extends Response { - public ConnectResetResponse(int resultCode, String message) { - super(ResponseTypeConstants.CONNECT_SWITCH, resultCode, message); + @Override + public String getType() { + return ResponseTypeConstants.CONNECT_SWITCH; } } \ No newline at end of file diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/response/HeartBeatResponse.java b/api/src/main/java/com/alibaba/nacos/api/remote/response/HeartBeatResponse.java index 37f053d73..cb5ace0e4 100644 --- a/api/src/main/java/com/alibaba/nacos/api/remote/response/HeartBeatResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/remote/response/HeartBeatResponse.java @@ -24,8 +24,8 @@ package com.alibaba.nacos.api.remote.response; */ public class HeartBeatResponse extends Response { - public HeartBeatResponse(int resultCode, String message) { - super(ResponseTypeConstants.HEART_BEAT, resultCode, message); + @Override + public String getType() { + return ResponseTypeConstants.HEART_BEAT; } - } diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/response/PlainBodyResponse.java b/api/src/main/java/com/alibaba/nacos/api/remote/response/PlainBodyResponse.java index b88a6e9b6..65f81e576 100644 --- a/api/src/main/java/com/alibaba/nacos/api/remote/response/PlainBodyResponse.java +++ b/api/src/main/java/com/alibaba/nacos/api/remote/response/PlainBodyResponse.java @@ -30,8 +30,9 @@ public class PlainBodyResponse extends Response { } - public PlainBodyResponse(int resultCode, String message) { - super(ResponseTypeConstants.PLAIN_BODY_STRING, resultCode, message); + @Override + public String getType() { + return ResponseTypeConstants.PLAIN_BODY_STRING; } /** diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/response/Response.java b/api/src/main/java/com/alibaba/nacos/api/remote/response/Response.java index d3e8a9e95..e6af39629 100644 --- a/api/src/main/java/com/alibaba/nacos/api/remote/response/Response.java +++ b/api/src/main/java/com/alibaba/nacos/api/remote/response/Response.java @@ -24,14 +24,12 @@ package com.alibaba.nacos.api.remote.response; */ public class Response { - int resultCode; + int resultCode = ResponseCode.SUCCESS.getCode(); int errorCode; String message; - String type; - /** * Check Response is Successd. * @@ -42,18 +40,14 @@ public class Response { } public Response() { - } - public Response(String type) { - this.type = type; - } - - public Response(String type, int resultCode, String message) { - this.type = type; - this.resultCode = resultCode; - this.message = message; - } + /** + * get type. + * + * @return type value; + */ + public abstract String getType(); /** * Getter method for property resultCode. @@ -109,22 +103,4 @@ public class Response { this.errorCode = errorCode; } - /** - * Getter method for property type. - * - * @return property value of type - */ - public String getType() { - return type; - } - - /** - * Setter method for property type. - * - * @param type value to be assigned to property type - */ - public void setType(String type) { - this.type = type; - } - } diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/response/ResponseTypeConstants.java b/api/src/main/java/com/alibaba/nacos/api/remote/response/ResponseTypeConstants.java index 3f2ce2dc8..22e77e691 100644 --- a/api/src/main/java/com/alibaba/nacos/api/remote/response/ResponseTypeConstants.java +++ b/api/src/main/java/com/alibaba/nacos/api/remote/response/ResponseTypeConstants.java @@ -29,4 +29,7 @@ public class ResponseTypeConstants { public static final String CONNECT_SWITCH = "CONNECT_SWITCH"; + public static final String UNKNOW = "UNKNOW"; + + } diff --git a/api/src/main/java/com/alibaba/nacos/api/remote/response/UnKnowResponse.java b/api/src/main/java/com/alibaba/nacos/api/remote/response/UnKnowResponse.java new file mode 100644 index 000000000..7f9c5d7c1 --- /dev/null +++ b/api/src/main/java/com/alibaba/nacos/api/remote/response/UnKnowResponse.java @@ -0,0 +1,31 @@ +/* + * Copyright 1999-2020 Alibaba Group Holding Ltd. + * + * 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 com.alibaba.nacos.api.remote.response; + +/** + * UnKnowResponse. + * + * @author liuzunfei + * @version $Id: UnKnowResponse.java, v 0.1 2020年07月16日 9:47 PM liuzunfei Exp $ + */ +public class UnKnowResponse extends Response { + + @Override + public String getType() { + return ResponseTypeConstants.UNKNOW; + } +} \ No newline at end of file diff --git a/config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigChangeListenRequestHandler.java b/config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigChangeListenRequestHandler.java index 6cfee66ea..bcf78e368 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigChangeListenRequestHandler.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigChangeListenRequestHandler.java @@ -64,7 +64,7 @@ public class ConfigChangeListenRequestHandler extends RequestHandler { } else { asyncListenContext.addListen(NacosRemoteConstants.LISTEN_CONTEXT_CONFIG, configKey, connectionId); } - return new ConfigChangeListenResponse(200, "success"); + return ConfigChangeListenResponse.buildSucessResponse(); } @Override diff --git a/core/src/main/java/com/alibaba/nacos/core/remote/HeartBeatRequestHandler.java b/core/src/main/java/com/alibaba/nacos/core/remote/HeartBeatRequestHandler.java index 300e3863a..4532ed105 100644 --- a/core/src/main/java/com/alibaba/nacos/core/remote/HeartBeatRequestHandler.java +++ b/core/src/main/java/com/alibaba/nacos/core/remote/HeartBeatRequestHandler.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alibaba.nacos.core.remote; -import java.util.List; +package com.alibaba.nacos.core.remote; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.remote.request.HeartBeatRequest; @@ -25,32 +24,36 @@ import com.alibaba.nacos.api.remote.request.RequestTypeConstants; import com.alibaba.nacos.api.remote.response.HeartBeatResponse; import com.alibaba.nacos.api.remote.response.Response; import com.alibaba.nacos.common.utils.JacksonUtils; - import com.google.common.collect.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; + /** + * HeartBeatRequestHandler. + * * @author liuzunfei * @version $Id: HeartBeatRequestHandler.java, v 0.1 2020年07月14日 1:58 PM liuzunfei Exp $ */ @Component -public class HeartBeatRequestHandler extends RequestHandler{ - +public class HeartBeatRequestHandler extends RequestHandler { + @Autowired ConnectionManager connectionManager; - + @Override public Request parseBodyString(String bodyString) { return JacksonUtils.toObj(bodyString, HeartBeatRequest.class); } - + @Override public Response handle(Request request, RequestMeta meta) throws NacosException { String connectionId = meta.getConnectionId(); connectionManager.refreshActiveTime(connectionId); - return new HeartBeatResponse(200,"heart beat success"); + return new HeartBeatResponse(); } + @Override public List getRequestTypes() { return Lists.newArrayList(RequestTypeConstants.HEART_BEAT); diff --git a/core/src/main/java/com/alibaba/nacos/core/remote/grpc/GrpcUtils.java b/core/src/main/java/com/alibaba/nacos/core/remote/grpc/GrpcUtils.java index 04dccb19d..cfe5faa4b 100644 --- a/core/src/main/java/com/alibaba/nacos/core/remote/grpc/GrpcUtils.java +++ b/core/src/main/java/com/alibaba/nacos/core/remote/grpc/GrpcUtils.java @@ -16,17 +16,17 @@ package com.alibaba.nacos.core.remote.grpc; -import java.io.UnsupportedEncodingException; - import com.alibaba.nacos.api.grpc.GrpcMetadata; import com.alibaba.nacos.api.grpc.GrpcResponse; import com.alibaba.nacos.api.remote.response.Response; import com.alibaba.nacos.api.remote.response.ResponseCode; +import com.alibaba.nacos.api.remote.response.UnKnowResponse; import com.alibaba.nacos.common.utils.JacksonUtils; - import com.google.protobuf.Any; import com.google.protobuf.ByteString; +import java.io.UnsupportedEncodingException; + /** * GrpcUtils. * @@ -64,8 +64,7 @@ public class GrpcUtils { * @return */ public static GrpcResponse buildFailResponse(String msg) { - - Response response = new Response(); + UnKnowResponse response = new UnKnowResponse(); response.setErrorCode(ResponseCode.FAIL.getCode()); response.setMessage(msg); byte[] bytes = JacksonUtils.toJsonBytes(response); diff --git a/distribution/conf/nacos-logback.xml b/distribution/conf/nacos-logback.xml index b3b4fa772..848df8d96 100644 --- a/distribution/conf/nacos-logback.xml +++ b/distribution/conf/nacos-logback.xml @@ -476,7 +476,43 @@ UTF-8 - + + + + ${LOG_HOME}/grpc-core.log + true + + ${LOG_HOME}/grpc-core.log.%d{yyyy-MM-dd}.%i + 2GB + 7 + 7GB + true + + + %date %level %msg%n%n + UTF-8 + + + + + ${LOG_HOME}/grpc-digest.log + true + + ${LOG_HOME}/grpc-digest.log.%d{yyyy-MM-dd}.%i + 2GB + 7 + 7GB + true + + + %date %level %msg%n%n + UTF-8 + + + + @@ -486,7 +522,17 @@ - + + + + + + + + + + + diff --git a/naming/src/main/java/com/alibaba/nacos/naming/remote/handler/InstanceRequestHandler.java b/naming/src/main/java/com/alibaba/nacos/naming/remote/handler/InstanceRequestHandler.java index bead55e21..db24c596f 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/remote/handler/InstanceRequestHandler.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/remote/handler/InstanceRequestHandler.java @@ -81,18 +81,18 @@ public class InstanceRequestHandler extends RequestHandler { instance.setMarked(true); instance.validate(); serviceManager.addInstance(namespace, serviceName, instance.isEphemeral(), instance); - return new InstanceResponse(200, "success", NamingRemoteConstants.REGISTER_INSTANCE); + return new InstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE); } private Response deregisterInstance(String namespace, String serviceName, InstanceRequest instanceRequest, RequestMeta meta) throws NacosException { if (!serviceManager.containService(namespace, serviceName)) { Loggers.SRV_LOG.warn("remove instance from non-exist service: {}", serviceName); - return new InstanceResponse(200, "success", NamingRemoteConstants.DE_REGISTER_INSTANCE); + return new InstanceResponse(NamingRemoteConstants.DE_REGISTER_INSTANCE); } Instance instance = parseInstance(instanceRequest.getInstance()); serviceManager.removeInstance(namespace, serviceName, instance.isEphemeral(), instance); - return new InstanceResponse(200, "success", NamingRemoteConstants.DE_REGISTER_INSTANCE); + return new InstanceResponse(NamingRemoteConstants.DE_REGISTER_INSTANCE); } private Instance parseInstance(com.alibaba.nacos.api.naming.pojo.Instance instance) {