def run(command, parser, cl_args, unknown_args): ''' :param command: :param parser: :param args: :param unknown_args: :return: ''' cluster = cl_args['cluster'] # server mode if cluster: config_file = config.heron_rc_file() client_confs = {} # Read the cluster definition, if not found client_confs = cdefs.read_server_mode_cluster_definition( cluster, cl_args, config_file) if not client_confs[cluster]: Log.error( 'Neither service url nor %s cluster definition in %s file', cluster, config_file) return SimpleResult(Status.HeronError) # if cluster definition exists, but service_url is not set, it is an error if not 'service_url' in client_confs[cluster]: Log.error('No service url for %s cluster in %s', cluster, config_file) sys.exit(1) service_endpoint = cl_args['service_url'] service_apiurl = service_endpoint + rest.ROUTE_SIGNATURES[command][1] service_method = rest.ROUTE_SIGNATURES[command][0] try: r = service_method(service_apiurl) if r.status_code != requests.codes.ok: Log.error(r.json().get( 'message', f"Unknown error from API server {r.status_code}")) sorted_items = sorted(list(r.json().items()), key=lambda tup: tup[0]) for key, value in sorted_items: print(f"{key} : {value}") except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as err: Log.error(err) return SimpleResult(Status.HeronError) else: config.print_build_info() return SimpleResult(Status.Ok)
def server_deployment_mode(command, parser, cluster, cl_args): ''' check the server deployment mode for the given cluster if it is valid return the valid set of args :param cluster: :param cl_args: :return: ''' config_file = config.heron_rc_file() # Read the cluster definition, if not found client_confs = cdefs.read_server_mode_cluster_definition( cluster, cl_args, config_file) if not client_confs[cluster]: return dict() # tell the user which definition that we are using if not cl_args['service_url']: Log.info("Using cluster definition from file %s" % config_file) else: Log.info("Using cluster service url %s" % cl_args['service_url']) # if cluster definition exists, but service_url is not set, it is an error if not 'service_url' in client_confs[cluster]: Log.error('No service url for %s cluster in %s', cluster, config_file) sys.exit(1) try: cluster_role_env = (cl_args['cluster'], cl_args['role'], cl_args['environ']) config.server_mode_cluster_role_env(cluster_role_env, client_confs, config_file) cluster_tuple = config.defaults_cluster_role_env(cluster_role_env) except Exception as ex: Log.error("Argument cluster/[role]/[env] is not correct: %s", str(ex)) sys.exit(1) new_cl_args = dict() new_cl_args['cluster'] = cluster_tuple[0] new_cl_args['role'] = cluster_tuple[1] new_cl_args['environ'] = cluster_tuple[2] new_cl_args['service_url'] = client_confs[cluster]['service_url'].rstrip( '/') new_cl_args['deploy_mode'] = config.SERVER_MODE cl_args.update(new_cl_args) return cl_args
def run(command, parser, cl_args, unknown_args): ''' :param command: :param parser: :param args: :param unknown_args: :return: ''' cluster = cl_args['cluster'] # server mode if cluster: config_file = config.heron_rc_file() client_confs = dict() # Read the cluster definition, if not found client_confs = cdefs.read_server_mode_cluster_definition(cluster, cl_args, config_file) if not client_confs[cluster]: Log.error('Neither service url nor %s cluster definition in %s file', cluster, config_file) return SimpleResult(Status.HeronError) # if cluster definition exists, but service_url is not set, it is an error if not 'service_url' in client_confs[cluster]: Log.error('No service url for %s cluster in %s', cluster, config_file) sys.exit(1) service_endpoint = cl_args['service_url'] service_apiurl = service_endpoint + rest.ROUTE_SIGNATURES[command][1] service_method = rest.ROUTE_SIGNATURES[command][0] try: r = service_method(service_apiurl) if r.status_code != requests.codes.ok: Log.error(r.json().get('message', "Unknown error from api server %d" % r.status_code)) sorted_items = sorted(r.json().items(), key=lambda tup: tup[0]) for key, value in sorted_items: print("%s : %s" % (key, value)) except (requests.exceptions.ConnectionError, requests.exceptions.HTTPError) as err: Log.error(err) return SimpleResult(Status.HeronError) else: config.print_build_info() return SimpleResult(Status.Ok)