You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by br...@apache.org on 2022/09/07 17:50:53 UTC
[cassandra-dtest] 01/02: Try random ports if 8778 isn't available
This is an automated email from the ASF dual-hosted git repository.
brandonwilliams pushed a commit to branch CASSANDRA-17872
in repository https://gitbox.apache.org/repos/asf/cassandra-dtest.git
commit c46089bbff2d53d81cb86515c6db6c1e82e18275
Author: Brandon Williams <br...@apache.org>
AuthorDate: Thu Sep 1 15:01:58 2022 -0500
Try random ports if 8778 isn't available
---
tools/jmxutils.py | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/tools/jmxutils.py b/tools/jmxutils.py
index 1b603447..b10bfa9c 100644
--- a/tools/jmxutils.py
+++ b/tools/jmxutils.py
@@ -1,9 +1,12 @@
import json
import os
import subprocess
+import socket
+import time
import urllib.request
import urllib.parse
import logging
+import random
import ccmlib.common as common
@@ -172,15 +175,40 @@ class JolokiaAgent(object):
def __init__(self, node):
self.node = node
+ # See CASSANDRA-17872 for the reason behind this
+ def get_port(self, default=8778):
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ available = None
+ port = default
+ for _ in range(5):
+ try:
+ s.bind((self.node.network_interfaces['binary'][0], port))
+ available = port
+ except socket.error as e:
+ newport = random.randint(8000, 9000)
+ logger.info("Port %s in use, trying again on %s" % (port, newport))
+ port = newport
+ s.close()
+ if available:
+ break
+ time.sleep(2)
+ return available
+
+
def start(self):
"""
Starts the Jolokia agent. The process will fork from the parent
and continue running until stop() is called.
"""
+ port = self.get_port()
+ if not port:
+ raise Exception("Port 8778 still in use on {}, unable to find another available port in range 8000-9000, cannot launch jolokia".format(socket.gethostname()))
+
args = (java_bin(),
'-cp', jolokia_classpath(),
'org.jolokia.jvmagent.client.AgentLauncher',
'--host', self.node.network_interfaces['binary'][0],
+ '--port', str(port),
'start', str(self.node.pid))
try:
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org