|
16 | 16 | import java.io.FileInputStream; |
17 | 17 | import java.io.FileNotFoundException; |
18 | 18 | import java.io.IOException; |
| 19 | +import java.net.ConnectException; |
| 20 | +import java.net.InetSocketAddress; |
| 21 | +import java.nio.channels.SocketChannel; |
19 | 22 | import java.rmi.RemoteException; |
20 | 23 | import java.sql.Connection; |
21 | 24 | import java.sql.SQLException; |
@@ -1366,28 +1369,40 @@ private boolean pingManagementNode(ManagementServerHostVO mshost) { |
1366 | 1369 | s_logger.info("ping management node cluster service can not be performed on self"); |
1367 | 1370 | return false; |
1368 | 1371 | } |
1369 | | - |
1370 | | - String targetPeer = String.valueOf(mshost.getMsid()); |
1371 | | - ClusterService peerService = null; |
1372 | | - for(int i = 0; i < 2; i++) { |
| 1372 | + |
| 1373 | + int retry = 10; |
| 1374 | + while (--retry > 0) { |
| 1375 | + SocketChannel sch = null; |
1373 | 1376 | try { |
1374 | | - peerService = getPeerService(targetPeer); |
1375 | | - } catch (RemoteException e) { |
1376 | | - s_logger.error("cluster service for peer " + targetPeer + " no longer exists"); |
1377 | | - } |
| 1377 | + s_logger.info("Trying to connect to " + targetIp); |
| 1378 | + sch = SocketChannel.open(); |
| 1379 | + sch.configureBlocking(true); |
| 1380 | + sch.socket().setSoTimeout(5000); |
1378 | 1381 |
|
1379 | | - if(peerService != null) { |
1380 | | - try { |
1381 | | - return peerService.ping(getSelfPeerName()); |
1382 | | - } catch (RemoteException e) { |
1383 | | - s_logger.warn("Exception in performing remote call, ", e); |
1384 | | - invalidatePeerService(targetPeer); |
| 1382 | + InetSocketAddress addr = new InetSocketAddress(targetIp, mshost.getServicePort()); |
| 1383 | + sch.connect(addr); |
| 1384 | + return true; |
| 1385 | + } catch (IOException e) { |
| 1386 | + if (e instanceof ConnectException) { |
| 1387 | + s_logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException", e); |
| 1388 | + return false; |
| 1389 | + } |
| 1390 | + } finally { |
| 1391 | + if (sch != null) { |
| 1392 | + try { |
| 1393 | + sch.close(); |
| 1394 | + } catch (IOException e) { |
| 1395 | + } |
1385 | 1396 | } |
1386 | | - } else { |
1387 | | - s_logger.warn("Remote peer " + mshost.getMsid() + " no longer exists"); |
1388 | 1397 | } |
1389 | | - } |
1390 | 1398 |
|
| 1399 | + try { |
| 1400 | + Thread.sleep(1000); |
| 1401 | + } catch (InterruptedException ex) { |
| 1402 | + } |
| 1403 | + } |
| 1404 | + |
| 1405 | + s_logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " after retries"); |
1391 | 1406 | return false; |
1392 | 1407 | } |
1393 | 1408 |
|
|
0 commit comments