Skip to content

Commit

Permalink
update console api of redis proxy (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Nov 6, 2023
1 parent 9ae2114 commit 4c0b7a4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -29,14 +30,6 @@ public class ConsoleServiceAdaptor implements ConsoleService {

private static final Logger logger = LoggerFactory.getLogger(ConsoleServiceAdaptor.class);

private int serverPort;
public ConsoleServiceAdaptor(int serverPort) {
this.serverPort = serverPort;
}

public ConsoleServiceAdaptor() {
}

@Override
public ConsoleResult status() {
ServerStatus.Status status = ServerStatus.getStatus();
Expand Down Expand Up @@ -81,30 +74,38 @@ public ConsoleResult offline() {

@Override
public ConsoleResult check() {
int port = serverPort;
if (port <= 0) {
port = GlobalRedisProxyEnv.getPort();
List<Integer> ports = new ArrayList<>();
if (GlobalRedisProxyEnv.getPort() > 0) {
ports.add(GlobalRedisProxyEnv.getPort());
}
if (port <= 0) {
if (GlobalRedisProxyEnv.getTlsPort() > 0) {
ports.add(GlobalRedisProxyEnv.getTlsPort());
}
if (GlobalRedisProxyEnv.getCport() > 0) {
ports.add(GlobalRedisProxyEnv.getCport());
}
if (ports.isEmpty()) {
return ConsoleResult.success();
}
Socket socket = new Socket();
try {
socket.connect(new InetSocketAddress("127.0.0.1", port), 200);
if (logger.isDebugEnabled()) {
logger.debug("check serverPort = " + port + " success");
}
return ConsoleResult.success("check serverPort = " + port + " success");
} catch (IOException e) {
logger.error("check serverPort = " + port + " fail");
return ConsoleResult.error("check serverPort = " + port + " error");
} finally {
for (Integer port : ports) {
Socket socket = new Socket();
try {
socket.close();
socket.connect(new InetSocketAddress("127.0.0.1", port), 200);
if (logger.isDebugEnabled()) {
logger.debug("check serverPort = " + port + " success");
}
} catch (IOException e) {
logger.error("close error", e);
logger.error("check serverPort = " + port + " fail");
return ConsoleResult.error("check serverPort = " + port + " error");
} finally {
try {
socket.close();
} catch (IOException e) {
logger.error("close error", e);
}
}
}
return ConsoleResult.success();
}

@Override
Expand Down Expand Up @@ -175,23 +176,28 @@ public ConsoleResult detect(Map<String, List<String>> params) {

@Override
public ConsoleResult shutdownUpstreamClient(Map<String, List<String>> params) {
List<String> list = params.get("resource");
if (list == null) {
return ConsoleResult.error("resource param missing");
if (logger.isDebugEnabled()) {
logger.debug("shutdownUpstreamClient, params = {}", params);
}
if (list.isEmpty()) {
return ConsoleResult.error("illegal resource param");
String url = null;
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
if (entry.getKey().equalsIgnoreCase("url")) {
url = entry.getValue().get(0);
}
}
String resource = list.get(0);
IUpstreamClient upstreamClient = GlobalRedisProxyEnv.getClientTemplateFactory().getEnv().getClientFactory().remove(resource);
if (upstreamClient == null) {
return ConsoleResult.error("upstream client not found, resource = " + resource);
if (url != null) {
try {
IUpstreamClient upstreamClient = GlobalRedisProxyEnv.getClientTemplateFactory().getEnv().getClientFactory().remove(url);
if (upstreamClient == null) {
return ConsoleResult.error("upstream client not found, url = " + url);
}
upstreamClient.shutdown();
return ConsoleResult.success();
} catch (Exception e) {
logger.error(e.getMessage(), e);
return ConsoleResult.error("internal error");
}
}
upstreamClient.shutdown();
return ConsoleResult.success();
}

public void setServerPort(int serverPort) {
this.serverPort = serverPort;
return ConsoleResult.error("param wrong");
}
}
2 changes: 1 addition & 1 deletion update-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* provide camellia-redis-proxy-nacos-bootstrap, so Operations Engineer can use nacos to manager camellia-redis-proxy cluster without java development
* provide camellia-redis-proxy-etcd-bootstrap, so Operations Engineer can use etcd to manager camellia-redis-proxy cluster without java development
* camelia-feign, add util GlobalCamelliaFeignEnv, so you can calc load balance code before request when use hash policy
* camellia-redis-proxy console add api `/shutdownUpstreamClient?resource=redis://@127.0.0.1:6379`, so you can shutdown upstream client
* camellia-redis-proxy console add api `/shutdownUpstreamClient?url=redis://@127.0.0.1:6379`, so you can shutdown upstream client
* camellia-redis-proxy support shard-pubsub, support `SSUBSCRIBE/SUNSUBSCRIBE/SPUBLISH` commands
* camellia-redis-proxy support `FUNCTION/TFUNCTION` commands
* camellia-redis-proxy support `SCRIPT KILL` command
Expand Down
2 changes: 1 addition & 1 deletion update-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 新增camellia-redis-proxy-nacos-bootstrap,从而方便运维人员不需要进行java开发即可使用nacos管理proxy集群
* 新增camellia-redis-proxy-etcd-bootstrap,从而方便运维人员不需要进行java开发即可使用etcd管理proxy集群
* camelia-feign,新增GlobalCamelliaFeignEnv类,从而在使用哈希策略时,可以提前进行负载均衡计算,从而可以在调用前就知道调用的服务实例分布情况,方便进行请求合并
* camellia-redis-proxy的console新增`/shutdownUpstreamClient?resource=redis://@127.0.0.1:6379`接口,用于卸载到某个redis集群的连接
* camellia-redis-proxy的console新增`/shutdownUpstreamClient?url=redis://@127.0.0.1:6379`接口,用于卸载到某个redis集群的连接
* camellia-redis-proxy支持shard-pubsub,也就是支持`SSUBSCRIBE/SUNSUBSCRIBE/SPUBLISH`命令
* camellia-redis-proxy支持`FUNCTION/TFUNCTION`相关命令
* camellia-redis-proxy支持`SCRIPT KILL`命令
Expand Down

0 comments on commit 4c0b7a4

Please sign in to comment.