Exemplo n.º 1
0
def extract_common_args(command, parser, cl_args):
  """ extract common args """
  try:
    # do not pop like cli because ``topologies`` subcommand still needs it
    cluster_role_env = cl_args['cluster/[role]/[env]']
    config_path = cl_args['config_path']
  except KeyError:
    # if some of the arguments are not found, print error and exit
    subparser = config.get_subparser(parser, command)
    print subparser.format_help()
    return dict()
  cluster = config.get_heron_cluster(cluster_role_env)
  config_path = config.get_heron_cluster_conf_dir(cluster, config_path)

  new_cl_args = dict()
  try:
    cluster_tuple = config.parse_cluster_role_env(cluster_role_env, config_path)
    new_cl_args['cluster'] = cluster_tuple[0]
    new_cl_args['role'] = cluster_tuple[1]
    new_cl_args['environ'] = cluster_tuple[2]
    new_cl_args['config_path'] = config_path
  except Exception as e:
    Log.error("Unable to get valid topology location: %s" % str(e))
    return dict()

  cl_args.update(new_cl_args)
  return cl_args
Exemplo n.º 2
0
def extract_common_args(command, parser, cl_args):
  """ extract common args """
  try:
    # do not pop like cli because ``topologies`` subcommand still needs it
    cluster_role_env = cl_args['cluster/[role]/[env]']
    config_path = cl_args['config_path']
  except KeyError:
    # if some of the arguments are not found, print error and exit
    subparser = config.get_subparser(parser, command)
    print(subparser.format_help())
    return dict()
  cluster = config.get_heron_cluster(cluster_role_env)
  config_path = config.get_heron_cluster_conf_dir(cluster, config_path)

  new_cl_args = dict()
  try:
    cluster_tuple = config.parse_cluster_role_env(cluster_role_env, config_path)
    new_cl_args['cluster'] = cluster_tuple[0]
    new_cl_args['role'] = cluster_tuple[1]
    new_cl_args['environ'] = cluster_tuple[2]
    new_cl_args['config_path'] = config_path
  except Exception as e:
    Log.error("Unable to get valid topology location: %s", str(e))
    return dict()

  cl_args.update(new_cl_args)
  return cl_args
Exemplo n.º 3
0
def extract_common_args(command, parser, cl_args):
    '''
  Extract all the common args for all commands
  :param command:
  :param parser:
  :param cl_args:
  :return:
  '''
    try:
        cluster_role_env = cl_args.pop('cluster/[role]/[env]')
    except KeyError:
        try:
            cluster_role_env = cl_args.pop('cluster')  # for version command
        except KeyError:
            # if some of the arguments are not found, print error and exit
            subparser = config.get_subparser(parser, command)
            print subparser.format_help()
            return dict()

    new_cl_args = dict()
    cluster_tuple = config.get_cluster_role_env(cluster_role_env)
    new_cl_args['cluster'] = cluster_tuple[0]
    new_cl_args['role'] = cluster_tuple[1]
    new_cl_args['environ'] = cluster_tuple[2]
    new_cl_args['submit_user'] = getpass.getuser()

    cl_args.update(new_cl_args)
    return cl_args
Exemplo n.º 4
0
def extract_common_args(command, parser, cl_args):
  '''
  Extract all the common args for all commands
  :param command:
  :param parser:
  :param cl_args:
  :return:
  '''
  try:
    cluster_role_env = cl_args.pop('cluster/[role]/[env]')
  except KeyError:
    try:
      cluster_role_env = cl_args.pop('cluster')  # for version command
    except KeyError:
      # if some of the arguments are not found, print error and exit
      subparser = config.get_subparser(parser, command)
      print(subparser.format_help())
      return dict()

  new_cl_args = dict()
  cluster_tuple = config.get_cluster_role_env(cluster_role_env)
  new_cl_args['cluster'] = cluster_tuple[0]
  new_cl_args['role'] = cluster_tuple[1]
  new_cl_args['environ'] = cluster_tuple[2]
  new_cl_args['submit_user'] = getpass.getuser()

  cl_args.update(new_cl_args)
  return cl_args
Exemplo n.º 5
0
def direct_deployment_mode(command, parser, cluster, cl_args):
    '''
  check the direct deployment mode for the given cluster
  if it is valid return the valid set of args
  :param command:
  :param parser:
  :param cluster:
  :param cl_args:
  :return:
  '''

    cluster = cl_args['cluster']
    try:
        config_path = cl_args['config_path']
        override_config_file = config.parse_override_config_and_write_file(
            cl_args['config_property'])
    except KeyError:
        # if some of the arguments are not found, print error and exit
        subparser = config.get_subparser(parser, command)
        print(subparser.format_help())
        return dict()

    # check if the cluster config directory exists
    if not cdefs.check_direct_mode_cluster_definition(cluster, config_path):
        Log.error("Cluster config directory \'%s\' does not exist",
                  config_path)
        return dict()

    config_path = config.get_heron_cluster_conf_dir(cluster, config_path)
    if not os.path.isdir(config_path):
        Log.error("Cluster config directory \'%s\' does not exist",
                  config_path)
        return dict()

    Log.info("Using cluster definition in %s" % config_path)

    try:
        cluster_role_env = (cl_args['cluster'], cl_args['role'],
                            cl_args['environ'])
        config.direct_mode_cluster_role_env(cluster_role_env, config_path)
        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))
        return dict()

    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['config_path'] = config_path
    new_cl_args['override_config_file'] = override_config_file
    new_cl_args['deploy_mode'] = config.DIRECT_MODE

    cl_args.update(new_cl_args)
    return cl_args
Exemplo n.º 6
0
def direct_deployment_mode(command, parser, cluster, cl_args):
  '''
  check the direct deployment mode for the given cluster
  if it is valid return the valid set of args
  :param command:
  :param parser:
  :param cluster:
  :param cl_args:
  :return:
  '''

  cluster = cl_args['cluster']
  try:
    config_path = cl_args['config_path']
    override_config_file = config.parse_override_config_and_write_file(cl_args['config_property'])
  except KeyError:
    # if some of the arguments are not found, print error and exit
    subparser = config.get_subparser(parser, command)
    print(subparser.format_help())
    return dict()

  # check if the cluster config directory exists
  if not cdefs.check_direct_mode_cluster_definition(cluster, config_path):
    Log.error("Cluster config directory \'%s\' does not exist", config_path)
    return dict()

  config_path = config.get_heron_cluster_conf_dir(cluster, config_path)
  if not os.path.isdir(config_path):
    Log.error("Cluster config directory \'%s\' does not exist", config_path)
    return dict()

  Log.info("Using cluster definition in %s" % config_path)

  try:
    cluster_role_env = (cl_args['cluster'], cl_args['role'], cl_args['environ'])
    config.direct_mode_cluster_role_env(cluster_role_env, config_path)
    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))
    return dict()

  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['config_path'] = config_path
  new_cl_args['override_config_file'] = override_config_file
  new_cl_args['deploy_mode'] = config.DIRECT_MODE

  cl_args.update(new_cl_args)
  return cl_args
Exemplo n.º 7
0
def run(command, parser, args, unknown_args):
    """ run command """
    # get the command for detailed help
    command_help = args['help-command']

    # if no command is provided, just print main help
    if command_help == 'help':
        parser.print_help()
        return True

    # get the subparser for the specific command
    subparser = config.get_subparser(parser, command_help)
    if subparser:
        print(subparser.format_help())
        return True
    Log.error("Unknown subcommand \'%s\'" % command_help)
    return False
Exemplo n.º 8
0
def run(command, parser, args, unknown_args):
  """ run command """
  # get the command for detailed help
  command_help = args['help-command']

  # if no command is provided, just print main help
  if command_help == 'help':
    parser.print_help()
    return True

  # get the subparser for the specific command
  subparser = config.get_subparser(parser, command_help)
  if subparser:
    print subparser.format_help()
    return True
  else:
    Log.error("Unknown subcommand \'%s\'" % command_help)
    return False
Exemplo n.º 9
0
def extract_common_args(command, parser, cl_args):
    '''
  Extract all the common args for all commands
  :param command:
  :param parser:
  :param cl_args:
  :return:
  '''
    try:
        cluster_role_env = cl_args.pop('cluster/[role]/[env]')
        config_path = cl_args['config_path']
        override_config_file = config.parse_override_config(
            cl_args['config_property'])
    except KeyError:
        # if some of the arguments are not found, print error and exit
        subparser = config.get_subparser(parser, command)
        print subparser.format_help()
        return dict()

    cluster = config.get_heron_cluster(cluster_role_env)
    config_path = config.get_heron_cluster_conf_dir(cluster, config_path)
    if not os.path.isdir(config_path):
        Log.error("Config path cluster directory does not exist: %s",
                  config_path)
        return dict()

    new_cl_args = dict()
    try:
        cluster_tuple = config.parse_cluster_role_env(cluster_role_env,
                                                      config_path)
        new_cl_args['cluster'] = cluster_tuple[0]
        new_cl_args['role'] = cluster_tuple[1]
        new_cl_args['environ'] = cluster_tuple[2]
        new_cl_args['submit_user'] = getpass.getuser()
        new_cl_args['config_path'] = config_path
        new_cl_args['override_config_file'] = override_config_file
    except Exception as ex:
        Log.error("Argument cluster/[role]/[env] is not correct: %s", str(ex))
        return dict()

    cl_args.update(new_cl_args)
    return cl_args
Exemplo n.º 10
0
def extract_common_args(command, parser, cl_args):
  '''
  Extract all the common args for all commands
  :param command:
  :param parser:
  :param cl_args:
  :return:
  '''
  try:
    cluster_role_env = cl_args.pop('cluster/[role]/[env]')
    config_path = cl_args['config_path']
    override_config_file = config.parse_override_config(cl_args['config_property'])
  except KeyError:
    # if some of the arguments are not found, print error and exit
    subparser = config.get_subparser(parser, command)
    print subparser.format_help()
    return dict()

  cluster = config.get_heron_cluster(cluster_role_env)
  config_path = config.get_heron_cluster_conf_dir(cluster, config_path)
  if not os.path.isdir(config_path):
    Log.error("Config path cluster directory does not exist: %s", config_path)
    return dict()

  new_cl_args = dict()
  try:
    cluster_tuple = config.parse_cluster_role_env(cluster_role_env, config_path)
    new_cl_args['cluster'] = cluster_tuple[0]
    new_cl_args['role'] = cluster_tuple[1]
    new_cl_args['environ'] = cluster_tuple[2]
    new_cl_args['config_path'] = config_path
    new_cl_args['override_config_file'] = override_config_file
  except Exception as ex:
    Log.error("Argument cluster/[role]/[env] is not correct: %s", str(ex))
    return dict()

  cl_args.update(new_cl_args)
  return cl_args
Exemplo n.º 11
0
def run(command, parser, args, unknown_args):
  '''
  :param command:
  :param parser:
  :param args:
  :param unknown_args:
  :return:
  '''
  # get the command for detailed help
  command_help = args['help-command']

  # if no command is provided, just print main help
  if command_help == 'help':
    parser.print_help()
    return SimpleResult(Status.Ok)

  # get the subparser for the specific command
  subparser = config.get_subparser(parser, command_help)
  if subparser:
    print(subparser.format_help())
    return SimpleResult(Status.Ok)
  Log.error("Unknown subcommand \'%s\'", command_help)
  return SimpleResult(Status.InvocationError)
Exemplo n.º 12
0
def run(command, parser, args, unknown_args):
  '''
  :param command:
  :param parser:
  :param args:
  :param unknown_args:
  :return:
  '''
  # get the command for detailed help
  command_help = args['help-command']

  # if no command is provided, just print main help
  if command_help == 'help':
    parser.print_help()
    return SimpleResult(Status.Ok)

  # get the subparser for the specific command
  subparser = config.get_subparser(parser, command_help)
  if subparser:
    print subparser.format_help()
    return SimpleResult(Status.Ok)
  else:
    Log.error("Unknown subcommand \'%s\'", command_help)
    return SimpleResult(Status.InvocationError)