def wait(cmd, timeout=None): SYNCHRONOUS_COMMAND_ID = -1 if cmd.id == SYNCHRONOUS_COMMAND_ID: return cmd SLEEP_SECS = 5 if timeout is None: deadline = None else: deadline = time.time() + timeout try: cmd_api_instance = cm_client.CommandsResourceApi(api_client) while True: cmd = cmd_api_instance.read_command(int(cmd.id)) pprint(cmd) if not cmd.active: return cmd if deadline is not None: now = time.time() if deadline < now: return cmd else: time.sleep(min(SLEEP_SECS, deadline - now)) else: time.sleep(SLEEP_SECS) except ApiException as e: print("Exception reading and waiting for command %s\n" % e)
def wait(cmd, timeout=None): SYNCHRONOUS_COMMAND_ID = -1 try: if cmd.id == SYNCHRONOUS_COMMAND_ID: return cmd except AttributeError: return cmd SLEEP_SECS = 5 if timeout is None: deadline = None else: deadline = time.time() + timeout try: cmd_api_instance = cm_client.CommandsResourceApi(api_client) while True: cmd = cmd_api_instance.read_command(long(cmd.id)) pprint(cmd) if not cmd.active: return cmd if deadline is not None: now = time.time() if deadline < now: return cmd else: time.sleep(min(SLEEP_SECS, deadline - now)) else: time.sleep(SLEEP_SECS) except ApiException as e: print( "Exception when calling ClouderaManagerResourceApi->import_cluster_template: %s\n" % e)
def wait(restartOozie, timeout=None): SYNCHRONOUS_COMMAND_ID = -1 if restartOozie.id == SYNCHRONOUS_COMMAND_ID: return restartOozie SLEEP_SECS = 5 if timeout is None: deadline = None else: deadline = time.time() + timeout try: cmd_api_instance = cm_client.CommandsResourceApi(api_client) while True: global restartOozie restartOozie = cmd_api_instance.read_command(long(restartOozie.id)) pprint(restartOozie) if not restartOozie.active: return restartOozie if deadline is not None: now = time.time() if deadline < now: return restartOozie else: time.sleep(min(SLEEP_SECS, deadline - now)) else: time.sleep(SLEEP_SECS) except ApiException, e: print "Exception reading and waiting for command %s\n" %e