|
91 | 91 | import java.io.File;
|
92 | 92 | import java.io.IOException;
|
93 | 93 | import java.io.UnsupportedEncodingException;
|
94 |
| -import java.net.URLEncoder; |
| 94 | +import java.net.*; |
95 | 95 | import java.nio.charset.StandardCharsets;
|
96 | 96 | import java.util.*;
|
97 | 97 | import java.util.concurrent.TimeUnit;
|
@@ -4240,6 +4240,32 @@ private void recreateTag(SystemTag tag, String token, String value, boolean inhe
|
4240 | 4240 | creator.create();
|
4241 | 4241 | }
|
4242 | 4242 |
|
| 4243 | + public ErrorCode isRemotePortOpen(String ip, int port, int timeout) { |
| 4244 | + Socket socket = new Socket(); |
| 4245 | + |
| 4246 | + try { |
| 4247 | + socket.setReuseAddress(true); |
| 4248 | + SocketAddress sa = new InetSocketAddress(ip, port); |
| 4249 | + socket.connect(sa, timeout); |
| 4250 | + if (socket.isConnected()) { |
| 4251 | + return null; |
| 4252 | + } |
| 4253 | + return operr("connect remote port[ip:%s, port:%s] is failed", ip, port); |
| 4254 | + } catch (SocketException e) { |
| 4255 | + logger.debug(String.format("unable to connect remote port[ip:%s, port:%s], %s", ip, port, e.getMessage())); |
| 4256 | + return operr("unable to connect remote port[ip:%s, port:%s], %s", ip, port, e.getMessage()); |
| 4257 | + } catch (IOException e) { |
| 4258 | + logger.debug(String.format("unable to connect remote port[ip:%s, port:%s], %s", ip, port, e.getMessage())); |
| 4259 | + return operr("unable to connect remote port[ip:%s, port:%s], %s", ip, port, e.getMessage()); |
| 4260 | + } finally { |
| 4261 | + try { |
| 4262 | + socket.close(); |
| 4263 | + } catch (IOException e) { |
| 4264 | + logger.warn(e.getMessage(), e); |
| 4265 | + } |
| 4266 | + } |
| 4267 | + } |
| 4268 | + |
4243 | 4269 | @Override
|
4244 | 4270 | public void connectHook(final ConnectHostInfo info, final Completion complete) {
|
4245 | 4271 | if (!info.isNewAdded()) {
|
@@ -4677,6 +4703,26 @@ public void run(FlowTrigger trigger, Map data) {
|
4677 | 4703 | }
|
4678 | 4704 | });
|
4679 | 4705 |
|
| 4706 | + flow(new NoRollbackFlow() { |
| 4707 | + String __name__ = "test-kvmagent-port-open"; |
| 4708 | + |
| 4709 | + @Override |
| 4710 | + public boolean skip(Map data) { |
| 4711 | + return CoreGlobalProperty.UNIT_TEST_ON; |
| 4712 | + } |
| 4713 | + |
| 4714 | + @Override |
| 4715 | + public void run(FlowTrigger trigger, Map data) { |
| 4716 | + long ctimeout = TimeUnit.SECONDS.toMillis(KVMGlobalConfig.TEST_KVMAGENT_PORT_ON_CONNECT_TIMEOUT.value(Integer.class).longValue()); |
| 4717 | + ErrorCode errorCode = isRemotePortOpen(getSelf().getManagementIp(), KVMGlobalProperty.AGENT_PORT, (int) ctimeout); |
| 4718 | + if (errorCode != null) { |
| 4719 | + trigger.fail(errorCode); |
| 4720 | + return; |
| 4721 | + } |
| 4722 | + trigger.next(); |
| 4723 | + } |
| 4724 | + }); |
| 4725 | + |
4680 | 4726 | flow(new NoRollbackFlow() {
|
4681 | 4727 | String __name__ = "echo-host";
|
4682 | 4728 |
|
|
0 commit comments