Skip to content

Commit

Permalink
switch server optimize and loader balance base on max client count (#…
Browse files Browse the repository at this point in the history
…3420)

* Add gprc support-> authentication on client

* Add gprc support-> optimize switch server and submit loader balance base on up limit clients count.
  • Loading branch information
shiyiyue1102 authored Jul 23, 2020
1 parent 5029429 commit 50a298c
Show file tree
Hide file tree
Showing 23 changed files with 735 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse;
import com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse;
import com.alibaba.nacos.api.remote.response.ConnectResetResponse;
import com.alibaba.nacos.api.remote.response.ConnectionUnregisterResponse;
import com.alibaba.nacos.api.remote.response.HeartBeatResponse;
import com.alibaba.nacos.api.remote.response.ResponseTypeConstants;
import com.alibaba.nacos.api.remote.response.UnKnowResponse;
Expand All @@ -51,6 +52,7 @@ public class ResponseRegistry {
REGISTRY_RESPONSES.put(ResponseTypeConstants.HEART_BEAT, HeartBeatResponse.class);
REGISTRY_RESPONSES.put(ResponseTypeConstants.CONNECT_SWITCH, ConnectResetResponse.class);
REGISTRY_RESPONSES.put(ResponseTypeConstants.UNKNOW, UnKnowResponse.class);
REGISTRY_RESPONSES.put(ResponseTypeConstants.CONNECION_UNREGISTER, ConnectionUnregisterResponse.class);

//config response registry
REGISTRY_RESPONSES.put(ConfigResponseTypeConstants.CONFIG_CHANGE, ConfigChangeListenResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,40 @@
*/
public abstract class Connection {

public static final String HEALTHY = "healthy";

public static final String UNHEALTHY = "unhealthy";

public static final String SWITCHING = "swtiching";

private String status;

public boolean isHealthy() {
return HEALTHY.equals(this.status);
}

public boolean isSwitching() {
return HEALTHY.equals(this.status);
}

/**
* Getter method for property <tt>status</tt>.
*
* @return property value of status
*/
public String getStatus() {
return status;
}

/**
* Setter method for property <tt>status</tt>.
*
* @param status value to be assigned to property status
*/
public void setStatus(String status) {
this.status = status;
}

private final ConnectionMetaInfo metaInfo;

public Connection(ConnectionMetaInfo metaInfo) {
Expand Down Expand Up @@ -53,6 +87,7 @@ public void freshActiveTime() {

/**
* return last active time, include request occurs and.
*
* @return
*/
public long getLastActiveTimestamp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.exception;

/**
* connection already closed exception.
*
* @author liuzunfei
* @version $Id: ConnectionAlreadyClosedException.java, v 0.1 2020年07月22日 7:28 PM liuzunfei Exp $
*/
public class ConnectionAlreadyClosedException extends RemoteException {

private static final int CONNECTION_ALREADY_CLOSED = 600;

public ConnectionAlreadyClosedException() {
super(CONNECTION_ALREADY_CLOSED);
}

public ConnectionAlreadyClosedException(Throwable throwable) {
super(CONNECTION_ALREADY_CLOSED, throwable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.exception;

import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;

/**
* super exception in remote module.
*
* @author liuzunfei
* @version $Id: RemoteException.java, v 0.1 2020年07月22日 7:24 PM liuzunfei Exp $
*/
public class RemoteException extends NacosRuntimeException {

public RemoteException(int errorCode) {
super(errorCode);
}

public RemoteException(int errorCode, Throwable throwable) {
super(errorCode, throwable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@

/**
* HeartBeatRequest.
*
* @author liuzunfei
* @version $Id: HeartBeatRequest.java, v 0.1 2020年07月14日 11:38 AM liuzunfei Exp $
*/
public class HeartBeatRequest extends Request {

public class HeartBeatRequest extends InternalRequest {
@Override
public String getType() {
return RequestTypeConstants.HEART_BEAT;
}

@Override
public String getModule() {
return "internal";
}

}
Original file line number Diff line number Diff line change
@@ -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.request;

/**
* internal request .
*
* @author liuzunfei
* @version $Id: InternalRequest.java, v 0.1 2020年07月22日 8:33 PM liuzunfei Exp $
*/
public abstract class InternalRequest extends Request {

@Override
public String getModule() {
return "internal";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,59 @@

package com.alibaba.nacos.api.remote.request;

import java.util.HashMap;
import java.util.Map;

/**
* Request.
*
* @author liuzunfei
*/
public abstract class Request {

private final Map<String, String> headers = new HashMap<String, String>();

/**
* put header.
*
* @param key key of value.
* @param value value.
*/
public void putHeader(String key, String value) {
headers.put(key, value);
}

/**
* put headers .
*
* @param headers headers to put.
*/
public void putAllHeader(Map<String, String> headers) {
headers.putAll(headers);
}

/**
* get a header value .
*
* @param key key of value.
* @return return value of key. return null if not exist.
*/
public String getHeader(String key) {
return headers.get(key);
}

/**
* get a header value of defaut value.
*
* @param key key of value.
* @param defaultValue default value if key is not exist.
* @return return final value.
*/
public String getHeader(String key, String defaultValue) {
String value = headers.get(key);
return (value == null) ? defaultValue : value;
}

/**
* Getter method for property <tt>type</tt>.
*
Expand All @@ -37,4 +83,12 @@ public abstract class Request {
*/
public abstract String getModule();

/**
* Getter method for property <tt>headers</tt>.
*
* @return property value of headers
*/
public Map<String, String> getHeaders() {
return headers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public class RequestTypeConstants {

public static final String HEART_BEAT = "HEART_BEAT";

public static final String SERVER_CHECK = "SERVER_CHECK";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.request;

/**
* request to check server if unimpeded.
*
* @author liuzunfei
* @version $Id: ServerCheckRequest.java, v 0.1 2020年07月22日 8:32 PM liuzunfei Exp $
*/
public class ServerCheckRequest extends InternalRequest {

@Override
public String getType() {
return RequestTypeConstants.SERVER_CHECK;
}

}
Original file line number Diff line number Diff line change
@@ -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;

/**
* response indicates that the connection of the request is unregisterd.
*
* @author liuzunfei
* @version $Id: ConnectionUnregisterResponse.java, v 0.1 2020年07月22日 8:44 PM liuzunfei Exp $
*/
public class ConnectionUnregisterResponse extends Response {

@Override
public String getType() {
return ResponseTypeConstants.CONNECION_UNREGISTER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ public class ResponseTypeConstants {

public static final String UNKNOW = "UNKNOW";

public static final String SERVER_CHECK = "SERVER_CHECK";

public static final String CONNECION_UNREGISTER = "CONNECION_UNREGISTER";


}
Original file line number Diff line number Diff line change
@@ -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;

/**
* response of server check.
*
* @author liuzunfei
* @version $Id: ServerCheckResponse.java, v 0.1 2020年07月22日 8:37 PM liuzunfei Exp $
*/
public class ServerCheckResponse extends Response {

@Override
public String getType() {
return ResponseTypeConstants.SERVER_CHECK;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public enum RpcClientStatus {
INITED(1, "server list factory is ready,wait to start"),
STARTING(2, "server list factory is ready,wait to start"),
RUNNING(3, "client is running..."),
RE_CONNECTING(4, "reconnecting...");
SWITCHING_SERVER(5, "reconnecting...");


int status;

Expand Down
Loading

0 comments on commit 50a298c

Please sign in to comment.