response model optimize (#3357)

* Add gprc support-> add grpc log to distribution logback

* Add gprc support-> response model optimize
This commit is contained in:
nov.lzf 2020-07-17 12:03:30 +08:00 committed by GitHub
parent b10a24885e
commit 3f06a7a0f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 213 additions and 98 deletions

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.api.config.remote.request;
/** /**
* ConfigChangeListenRequest.
* @author liuzunfei * @author liuzunfei
* @version $Id: ConfigChangeListenRequest.java, v 0.1 2020年07月13日 9:01 PM liuzunfei Exp $ * @version $Id: ConfigChangeListenRequest.java, v 0.1 2020年07月13日 9:01 PM liuzunfei Exp $
*/ */

View File

@ -17,6 +17,7 @@
package com.alibaba.nacos.api.config.remote.response; package com.alibaba.nacos.api.config.remote.response;
import com.alibaba.nacos.api.remote.response.Response; import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.api.remote.response.ResponseCode;
/** /**
* ConfigChangeListenResponse. * ConfigChangeListenResponse.
@ -26,13 +27,37 @@ import com.alibaba.nacos.api.remote.response.Response;
*/ */
public class ConfigChangeListenResponse extends Response { public class ConfigChangeListenResponse extends Response {
public ConfigChangeListenResponse() { public ConfigChangeListenResponse() {
super(); super();
} }
public ConfigChangeListenResponse(int resultCode, String message) { @Override
super(ConfigResponseTypeConstants.CONFIG_CHANGE, resultCode, message); 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;
} }
} }

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.alibaba.nacos.api.config.remote.response; package com.alibaba.nacos.api.config.remote.response;
import com.alibaba.nacos.api.remote.response.Response; import com.alibaba.nacos.api.remote.response.Response;
@ -34,8 +35,9 @@ public class ConfigChangeNotifyResponse extends Response {
} }
public ConfigChangeNotifyResponse(int resultCode, String message) { @Override
super(ConfigResponseTypeConstants.CONFIG_CHANGE_NOTIFY, resultCode, message); public String getType() {
return ConfigResponseTypeConstants.CONFIG_CHANGE_NOTIFY;
} }
/** /**
@ -47,8 +49,7 @@ public class ConfigChangeNotifyResponse extends Response {
* @return ConfigChangeNotifyResponse * @return ConfigChangeNotifyResponse
*/ */
public static ConfigChangeNotifyResponse buildSuccessResponse(String dataId, String group, String tenant) { public static ConfigChangeNotifyResponse buildSuccessResponse(String dataId, String group, String tenant) {
ConfigChangeNotifyResponse response = new ConfigChangeNotifyResponse(ResponseCode.SUCCESS.getCode(), ConfigChangeNotifyResponse response = new ConfigChangeNotifyResponse();
"data changed");
response.setDataId(dataId); response.setDataId(dataId);
response.setGroup(group); response.setGroup(group);
response.setTenant(tenant); response.setTenant(tenant);

View File

@ -31,8 +31,9 @@ public class ConfigPubishResponse extends Response {
super(); super();
} }
public ConfigPubishResponse(int resultCode, String message) { @Override
super(ConfigResponseTypeConstants.CONFIG_PUBLISH, resultCode, message); public String getType() {
return ConfigResponseTypeConstants.CONFIG_PUBLISH;
} }
/** /**
@ -41,7 +42,7 @@ public class ConfigPubishResponse extends Response {
* @return * @return
*/ */
public static ConfigPubishResponse buildSuccessResponse() { public static ConfigPubishResponse buildSuccessResponse() {
return new ConfigPubishResponse(ResponseCode.SUCCESS.getCode(), ""); return new ConfigPubishResponse();
} }
/** /**
@ -50,6 +51,9 @@ public class ConfigPubishResponse extends Response {
* @return * @return
*/ */
public static ConfigPubishResponse buildFailResponse(String errorMsg) { 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;
} }
} }

View File

@ -41,14 +41,18 @@ public class ConfigQueryResponse extends Response {
Map<String, String> labels = new HashMap<String, String>(); Map<String, String> labels = new HashMap<String, String>();
public ConfigQueryResponse() { public ConfigQueryResponse() {
super(ConfigResponseTypeConstants.CONFIG_QUERY); }
@Override
public String getType() {
return ConfigResponseTypeConstants.CONFIG_QUERY;
} }
/** /**
* add label to this response. * add label to this response.
* *
* @param key * @param key key.
* @param value * @param value value.
*/ */
public void addLabel(String key, String value) { public void addLabel(String key, String value) {
this.labels.put(key, value); this.labels.put(key, value);
@ -62,19 +66,21 @@ public class ConfigQueryResponse extends Response {
* @return * @return
*/ */
public static ConfigQueryResponse buildFailResponse(int errorCode, String message) { 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.setErrorCode(errorCode);
response.setMessage(message);
return response; return response;
} }
/** /**
* Buidl success resposne. * Buidl success resposne.
* *
* @param content. * @param content content.
* @return * @return
*/ */
public static ConfigQueryResponse buildSuccessResponse(String content) { public static ConfigQueryResponse buildSuccessResponse(String content) {
ConfigQueryResponse response = new ConfigQueryResponse(ResponseCode.SUCCESS.getCode(), ""); ConfigQueryResponse response = new ConfigQueryResponse();
response.setContent(content); response.setContent(content);
return response; return response;
} }
@ -115,10 +121,6 @@ public class ConfigQueryResponse extends Response {
this.content = content; this.content = content;
} }
public ConfigQueryResponse(int resultCode, String message) {
super(ConfigResponseTypeConstants.CONFIG_QUERY, resultCode, message);
}
/** /**
* Getter method for property <tt>contentType</tt>. * Getter method for property <tt>contentType</tt>.
* *

View File

@ -31,8 +31,9 @@ public class ConfigRemoveResponse extends Response {
super(); super();
} }
public ConfigRemoveResponse(int resultCode, String message) { @Override
super(ConfigResponseTypeConstants.CONFIG_REMOVE, resultCode, message); public String getType() {
return ConfigResponseTypeConstants.CONFIG_REMOVE;
} }
/** /**
@ -41,7 +42,7 @@ public class ConfigRemoveResponse extends Response {
* @return * @return
*/ */
public static ConfigRemoveResponse buildSuccessResponse() { public static ConfigRemoveResponse buildSuccessResponse() {
return new ConfigRemoveResponse(ResponseCode.SUCCESS.getCode(), ""); return new ConfigRemoveResponse();
} }
/** /**
@ -50,6 +51,9 @@ public class ConfigRemoveResponse extends Response {
* @return * @return
*/ */
public static ConfigRemoveResponse buildFailResponse(String errorMsg) { 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;
} }
} }

View File

@ -25,15 +25,18 @@ import com.alibaba.nacos.api.remote.response.Response;
*/ */
public class InstanceResponse extends Response { public class InstanceResponse extends Response {
private String type;
public InstanceResponse() { public InstanceResponse() {
} }
public InstanceResponse(int resultCode, String message, String type) { @Override
this(resultCode, 0, message, type); public String getType() {
return this.type;
} }
public InstanceResponse(int resultCode, int errorCode, String message, String type) { public InstanceResponse(String type) {
super(type, resultCode, message); this.type = type;
setErrorCode(errorCode);
} }
} }

View File

@ -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.pojo.ServiceInfo;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants; import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.alibaba.nacos.api.remote.response.Response; import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.api.remote.response.ResponseCode;
/** /**
* Nacos naming query request. * Nacos naming query request.
@ -30,16 +31,28 @@ public class ServiceQueryResponse extends Response {
private ServiceInfo serviceInfo; private ServiceInfo serviceInfo;
public ServiceQueryResponse() { public ServiceQueryResponse() {
setType(NamingRemoteConstants.QUERY_SERVICE); }
@Override
public String getType() {
return NamingRemoteConstants.QUERY_SERVICE;
} }
public ServiceQueryResponse(ServiceInfo serviceInfo) { public ServiceQueryResponse(ServiceInfo serviceInfo) {
this(200, "success");
this.serviceInfo = serviceInfo; this.serviceInfo = serviceInfo;
} }
public ServiceQueryResponse(int resultCode, String message) { public static ServiceQueryResponse buildSuccessResponse(ServiceInfo serviceInfo) {
super(NamingRemoteConstants.QUERY_SERVICE, resultCode, message); 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() { public ServiceInfo getServiceInfo() {

View File

@ -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.ConnectResetResponse;
import com.alibaba.nacos.api.remote.response.HeartBeatResponse; import com.alibaba.nacos.api.remote.response.HeartBeatResponse;
import com.alibaba.nacos.api.remote.response.ResponseTypeConstants; import com.alibaba.nacos.api.remote.response.ResponseTypeConstants;
import com.alibaba.nacos.api.remote.response.UnKnowResponse;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -47,6 +48,7 @@ public class ResponseRegistry {
//internal response regitry //internal response regitry
REGISTRY_RESPONSES.put(ResponseTypeConstants.HEART_BEAT, HeartBeatResponse.class); REGISTRY_RESPONSES.put(ResponseTypeConstants.HEART_BEAT, HeartBeatResponse.class);
REGISTRY_RESPONSES.put(ResponseTypeConstants.CONNECT_SWITCH, ConnectResetResponse.class); REGISTRY_RESPONSES.put(ResponseTypeConstants.CONNECT_SWITCH, ConnectResetResponse.class);
REGISTRY_RESPONSES.put(ResponseTypeConstants.UNKNOW, UnKnowResponse.class);
//config response registry //config response registry
REGISTRY_RESPONSES.put(ConfigResponseTypeConstants.CONFIG_CHANGE, ConfigChangeListenResponse.class); REGISTRY_RESPONSES.put(ConfigResponseTypeConstants.CONFIG_CHANGE, ConfigChangeListenResponse.class);

View File

@ -24,7 +24,8 @@ package com.alibaba.nacos.api.remote.response;
*/ */
public class ConnectResetResponse extends Response { public class ConnectResetResponse extends Response {
public ConnectResetResponse(int resultCode, String message) { @Override
super(ResponseTypeConstants.CONNECT_SWITCH, resultCode, message); public String getType() {
return ResponseTypeConstants.CONNECT_SWITCH;
} }
} }

View File

@ -24,8 +24,8 @@ package com.alibaba.nacos.api.remote.response;
*/ */
public class HeartBeatResponse extends Response { public class HeartBeatResponse extends Response {
public HeartBeatResponse(int resultCode, String message) { @Override
super(ResponseTypeConstants.HEART_BEAT, resultCode, message); public String getType() {
return ResponseTypeConstants.HEART_BEAT;
} }
} }

View File

@ -30,8 +30,9 @@ public class PlainBodyResponse extends Response {
} }
public PlainBodyResponse(int resultCode, String message) { @Override
super(ResponseTypeConstants.PLAIN_BODY_STRING, resultCode, message); public String getType() {
return ResponseTypeConstants.PLAIN_BODY_STRING;
} }
/** /**

View File

@ -24,14 +24,12 @@ package com.alibaba.nacos.api.remote.response;
*/ */
public class Response { public class Response {
int resultCode; int resultCode = ResponseCode.SUCCESS.getCode();
int errorCode; int errorCode;
String message; String message;
String type;
/** /**
* Check Response is Successd. * Check Response is Successd.
* *
@ -42,18 +40,14 @@ public class Response {
} }
public Response() { public Response() {
} }
public Response(String type) { /**
this.type = type; * get type.
} *
* @return type value;
public Response(String type, int resultCode, String message) { */
this.type = type; public abstract String getType();
this.resultCode = resultCode;
this.message = message;
}
/** /**
* Getter method for property <tt>resultCode</tt>. * Getter method for property <tt>resultCode</tt>.
@ -109,22 +103,4 @@ public class Response {
this.errorCode = errorCode; this.errorCode = errorCode;
} }
/**
* Getter method for property <tt>type</tt>.
*
* @return property value of type
*/
public String getType() {
return type;
}
/**
* Setter method for property <tt>type</tt>.
*
* @param type value to be assigned to property type
*/
public void setType(String type) {
this.type = type;
}
} }

View File

@ -29,4 +29,7 @@ public class ResponseTypeConstants {
public static final String CONNECT_SWITCH = "CONNECT_SWITCH"; public static final String CONNECT_SWITCH = "CONNECT_SWITCH";
public static final String UNKNOW = "UNKNOW";
} }

View File

@ -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;
}
}

View File

@ -64,7 +64,7 @@ public class ConfigChangeListenRequestHandler extends RequestHandler {
} else { } else {
asyncListenContext.addListen(NacosRemoteConstants.LISTEN_CONTEXT_CONFIG, configKey, connectionId); asyncListenContext.addListen(NacosRemoteConstants.LISTEN_CONTEXT_CONFIG, configKey, connectionId);
} }
return new ConfigChangeListenResponse(200, "success"); return ConfigChangeListenResponse.buildSucessResponse();
} }
@Override @Override

View File

@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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.exception.NacosException;
import com.alibaba.nacos.api.remote.request.HeartBeatRequest; import com.alibaba.nacos.api.remote.request.HeartBeatRequest;
@ -25,17 +24,20 @@ import com.alibaba.nacos.api.remote.request.RequestTypeConstants;
import com.alibaba.nacos.api.remote.response.HeartBeatResponse; import com.alibaba.nacos.api.remote.response.HeartBeatResponse;
import com.alibaba.nacos.api.remote.response.Response; import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.common.utils.JacksonUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
/** /**
* HeartBeatRequestHandler.
*
* @author liuzunfei * @author liuzunfei
* @version $Id: HeartBeatRequestHandler.java, v 0.1 2020年07月14日 1:58 PM liuzunfei Exp $ * @version $Id: HeartBeatRequestHandler.java, v 0.1 2020年07月14日 1:58 PM liuzunfei Exp $
*/ */
@Component @Component
public class HeartBeatRequestHandler extends RequestHandler{ public class HeartBeatRequestHandler extends RequestHandler {
@Autowired @Autowired
ConnectionManager connectionManager; ConnectionManager connectionManager;
@ -49,8 +51,9 @@ public class HeartBeatRequestHandler extends RequestHandler{
public Response handle(Request request, RequestMeta meta) throws NacosException { public Response handle(Request request, RequestMeta meta) throws NacosException {
String connectionId = meta.getConnectionId(); String connectionId = meta.getConnectionId();
connectionManager.refreshActiveTime(connectionId); connectionManager.refreshActiveTime(connectionId);
return new HeartBeatResponse(200,"heart beat success"); return new HeartBeatResponse();
} }
@Override @Override
public List<String> getRequestTypes() { public List<String> getRequestTypes() {
return Lists.newArrayList(RequestTypeConstants.HEART_BEAT); return Lists.newArrayList(RequestTypeConstants.HEART_BEAT);

View File

@ -16,17 +16,17 @@
package com.alibaba.nacos.core.remote.grpc; package com.alibaba.nacos.core.remote.grpc;
import java.io.UnsupportedEncodingException;
import com.alibaba.nacos.api.grpc.GrpcMetadata; import com.alibaba.nacos.api.grpc.GrpcMetadata;
import com.alibaba.nacos.api.grpc.GrpcResponse; import com.alibaba.nacos.api.grpc.GrpcResponse;
import com.alibaba.nacos.api.remote.response.Response; import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.api.remote.response.ResponseCode; 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.alibaba.nacos.common.utils.JacksonUtils;
import com.google.protobuf.Any; import com.google.protobuf.Any;
import com.google.protobuf.ByteString; import com.google.protobuf.ByteString;
import java.io.UnsupportedEncodingException;
/** /**
* GrpcUtils. * GrpcUtils.
* *
@ -64,8 +64,7 @@ public class GrpcUtils {
* @return * @return
*/ */
public static GrpcResponse buildFailResponse(String msg) { public static GrpcResponse buildFailResponse(String msg) {
UnKnowResponse response = new UnKnowResponse();
Response response = new Response();
response.setErrorCode(ResponseCode.FAIL.getCode()); response.setErrorCode(ResponseCode.FAIL.getCode());
response.setMessage(msg); response.setMessage(msg);
byte[] bytes = JacksonUtils.toJsonBytes(response); byte[] bytes = JacksonUtils.toJsonBytes(response);

View File

@ -477,6 +477,42 @@
</encoder> </encoder>
</appender> </appender>
<appender name="grpc-core"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/grpc-core.log</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/grpc-core.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>2GB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>7GB</totalSizeCap>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<encoder>
<Pattern>%date %level %msg%n%n</Pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<appender name="grpc-digest"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HOME}/grpc-digest.log</file>
<append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/grpc-digest.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>2GB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>7GB</totalSizeCap>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<encoder>
<Pattern>%date %level %msg%n%n</Pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<logger name="com.alibaba.nacos.address.main" additivity="false"> <logger name="com.alibaba.nacos.address.main" additivity="false">
<level value="INFO"/> <level value="INFO"/>
<appender-ref ref="nacos-address"/> <appender-ref ref="nacos-address"/>
@ -487,6 +523,16 @@
<appender-ref ref="cmdb-main"/> <appender-ref ref="cmdb-main"/>
</logger> </logger>
<logger name="com.alibaba.nacos.core.grpc" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="grpc-core"/>
</logger>
<logger name="com.alibaba.nacos.core.grpc.digest" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="grpc-digest"/>
</logger>
<logger name="com.alibaba.nacos.naming.main" additivity="false"> <logger name="com.alibaba.nacos.naming.main" additivity="false">
<level value="INFO"/> <level value="INFO"/>
<appender-ref ref="async-naming-server"/> <appender-ref ref="async-naming-server"/>

View File

@ -81,18 +81,18 @@ public class InstanceRequestHandler extends RequestHandler<InstanceRequest> {
instance.setMarked(true); instance.setMarked(true);
instance.validate(); instance.validate();
serviceManager.addInstance(namespace, serviceName, instance.isEphemeral(), instance); 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, private Response deregisterInstance(String namespace, String serviceName, InstanceRequest instanceRequest,
RequestMeta meta) throws NacosException { RequestMeta meta) throws NacosException {
if (!serviceManager.containService(namespace, serviceName)) { if (!serviceManager.containService(namespace, serviceName)) {
Loggers.SRV_LOG.warn("remove instance from non-exist service: {}", 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()); Instance instance = parseInstance(instanceRequest.getInstance());
serviceManager.removeInstance(namespace, serviceName, instance.isEphemeral(), instance); 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) { private Instance parseInstance(com.alibaba.nacos.api.naming.pojo.Instance instance) {