Skip to content

Commit 860d005

Browse files
committed
retry jmx, switch prints to logger
Patch by brandonwilliams; reviewed by jmckenzie for CASSANDRA-17922
1 parent 8490a74 commit 860d005

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

tools/jmxutils.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import subprocess
44
import socket
5+
import time
56
import urllib.request
67
import urllib.parse
78
import logging
@@ -204,20 +205,31 @@ def start(self):
204205
if not port:
205206
raise Exception("Port 8778 still in use on {}, unable to find another available port in range 8000-9000, cannot launch jolokia".format(socket.gethostname()))
206207

208+
logger.info("Port %s open for jolokia" % port)
207209
args = (java_bin(),
208210
'-cp', jolokia_classpath(),
209211
'org.jolokia.jvmagent.client.AgentLauncher',
210212
'--host', self.node.network_interfaces['binary'][0],
211213
'--port', str(port),
212214
'start', str(self.node.pid))
213215

214-
try:
215-
subprocess.check_output(args, stderr=subprocess.STDOUT)
216-
except subprocess.CalledProcessError as exc:
217-
print("Failed to start jolokia agent (command was: %s): %s" % (' '.join(args), exc))
218-
print("Exit status was: %d" % (exc.returncode,))
219-
print("Output was: %s" % (exc.output,))
220-
raise
216+
tries = 3
217+
for i in range(tries):
218+
try:
219+
subprocess.check_output(args, stderr=subprocess.STDOUT, text=True)
220+
logger.info("Jolokia successful on try %s" % i )
221+
return
222+
except subprocess.CalledProcessError as exc:
223+
if 'Jolokia is already attached' in exc.output:
224+
logger.info("Jolokia reports being attached on try %s, returning successfully" % i)
225+
return;
226+
if i < tries - 1:
227+
logger.warn("Failed to start jolokia agent (command was: %s): %s" % (' '.join(args), exc))
228+
logger.warn("Exit status was: %d" % (exc.returncode,))
229+
logger.warn("Output was: %s" % (exc.output,))
230+
time.sleep(2)
231+
else:
232+
raise
221233

222234
def stop(self):
223235
"""
@@ -230,9 +242,9 @@ def stop(self):
230242
try:
231243
subprocess.check_output(args, stderr=subprocess.STDOUT)
232244
except subprocess.CalledProcessError as exc:
233-
print("Failed to stop jolokia agent (command was: %s): %s" % (' '.join(args), exc))
234-
print("Exit status was: %d" % (exc.returncode,))
235-
print("Output was: %s" % (exc.output,))
245+
logger.error("Failed to stop jolokia agent (command was: %s): %s" % (' '.join(args), exc))
246+
logger.error("Exit status was: %d" % (exc.returncode,))
247+
logger.error("Output was: %s" % (exc.output,))
236248
raise
237249

238250
def _query(self, body, verbose=True):

0 commit comments

Comments
 (0)