class JobCancellationTracker(threading.Thread): """Thread to poll test status changes on the server and kill jobs if requested""" def __init__(self, server, test_id, check_interval=60): self.test_id = test_id self.stop_requested = False self.api_client = APIClient(server) self.check_interval = check_interval threading.Thread.__init__(self) log.info("Starting to watch for job status changes on the server for: {}".format(self.test_id)) def run(self): self.api_client.login() while not self.stop_requested: time.sleep(self.check_interval) # Check job status: status = self.api_client.get('/tests/status/id/'+self.test_id) if status.get('status', None) in ('cancelled', 'cancel_pending'): self.kill_jobs() def stop(self): self.stop_requested = True def kill_jobs(self): """Kill cstar_perf_stress and cassandra-stress""" for proc in psutil.process_iter(): if proc.name().startswith("cstar_perf_stre"): log.info("Killing cstar_perf_stress - pid:{}".format(proc.pid)) proc.kill() if proc.name() == "java": if "org.apache.cassandra.stress.Stress" in " ".join(proc.cmdline()): log.info("Killing cassandra-stress - pid:{}".format(proc.pid)) proc.kill()
class JobCancellationTracker(threading.Thread): """Thread to poll test status changes on the server and kill jobs if requested""" def __init__(self, server, test_id, check_interval=60): self.test_id = test_id self.stop_requested = False self.api_client = APIClient(server) self.check_interval = check_interval threading.Thread.__init__(self) log.info("Starting to watch for job status changes on the server for: {}".format(self.test_id)) def run(self): self.api_client.login() while self.stop_requested == False: time.sleep(self.check_interval) # Check job status: status = self.api_client.get('/tests/status/id/'+self.test_id) if status.get('status', None) in ('cancelled', 'cancel_pending'): self.kill_jobs() def stop(self): self.stop_requested = True def kill_jobs(self): """Kill cstar_perf_stress and cassandra-stress""" for proc in psutil.process_iter(): if proc.name().startswith("cstar_perf_stre"): log.info("Killing cstar_perf_stress - pid:{}".format(proc.pid)) proc.kill() if proc.name() == "java": if "org.apache.cassandra.stress.Stress" in " ".join(proc.cmdline()): log.info("Killing cassandra-stress - pid:{}".format(proc.pid)) proc.kill()
def get_job_status(test_id, api_endpoint_url): api_client = APIClient(api_endpoint_url) try: status = api_client.get('/tests/status/id/' + test_id) except Exception as e: log.error(e.message) status = None log.debug('JobStatusRetriever -- status of test_id {test_id} is: {s}'.format(s=status, test_id=test_id)) return status.get('status') if status else None
def get_job_status(test_id, api_endpoint_url): api_client = APIClient(api_endpoint_url) try: status = api_client.get('/tests/status/id/' + test_id) except Exception as e: log.error(e.message) status = None log.debug( 'JobStatusRetriever -- status of test_id {test_id} is: {s}'.format( s=status, test_id=test_id)) return status.get('status') if status else None