Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy support stop #925

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void stop() {
if(tlsFuture != null) {
tlsFuture.channel().close();
}
tunnelManager.removeAll();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ctrip.xpipe.redis.proxy.controller;

import com.ctrip.xpipe.codec.JsonCodec;
import com.ctrip.xpipe.redis.proxy.ProxyServer;
import com.ctrip.xpipe.redis.proxy.Tunnel;
import com.ctrip.xpipe.redis.proxy.model.TunnelMeta;
import com.ctrip.xpipe.redis.proxy.monitor.TunnelMonitorManager;
Expand Down Expand Up @@ -30,6 +31,30 @@ public class ProxyController {
@Autowired
private TunnelMonitorManager tunnelMonitorManager;

@Autowired
private ProxyServer proxyServer;

@PostMapping(value = "/server/start")
public RetMessage startServer() {
try {
proxyServer.start();
return RetMessage.createSuccessMessage();
} catch (Throwable th) {
return RetMessage.createFailMessage(th.getMessage());
}
}

@PostMapping(value = "/server/stop")
public RetMessage stopServer() {
try {
proxyServer.stop();
return RetMessage.createSuccessMessage();
} catch (Throwable th) {
return RetMessage.createFailMessage(th.getMessage());
}
}


@RequestMapping(value = "/tunnels", method = RequestMethod.GET)
public String getTunnelMetas() {
List<Tunnel> tunnels = tunnelManager.tunnels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -154,6 +155,14 @@ public void remove(Channel frontendChannel) {
}
}

@Override
public void removeAll() {
Set<Channel> toCloseChannels = new HashSet<>(cache.keySet());
for (Channel channel: toCloseChannels) {
remove(channel);
}
}

@Override
public List<Tunnel> tunnels() {
return Lists.newArrayList(cache.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface TunnelManager extends Releasable, Observer {

void remove(Channel frontendChannel);

void removeAll();

List<Tunnel> tunnels();

Tunnel getById(String id);
Expand Down
Loading