当前位置: 首页>>代码示例>>Python>>正文


Python AuroraClientAPI.get_safe_hosts方法代码示例

本文整理汇总了Python中apache.aurora.client.api.AuroraClientAPI.get_safe_hosts方法的典型用法代码示例。如果您正苦于以下问题:Python AuroraClientAPI.get_safe_hosts方法的具体用法?Python AuroraClientAPI.get_safe_hosts怎么用?Python AuroraClientAPI.get_safe_hosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apache.aurora.client.api.AuroraClientAPI的用法示例。


在下文中一共展示了AuroraClientAPI.get_safe_hosts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sla_list_safe_domain

# 需要导入模块: from apache.aurora.client.api import AuroraClientAPI [as 别名]
# 或者: from apache.aurora.client.api.AuroraClientAPI import get_safe_hosts [as 别名]
def sla_list_safe_domain(cluster, percentage, duration):
    """usage: sla_list_safe_domain
            [--exclude_file=FILENAME]
            [--exclude_hosts=HOSTS]
            [--grouping=GROUPING]
            [--include_file=FILENAME]
            [--include_hosts=HOSTS]
            [--list_jobs]
            [--min_job_instance_count=COUNT]
            [--override_jobs=FILENAME]
            cluster percentage duration

  Returns a list of relevant hosts where it would be safe to kill
  tasks without violating their job SLA. The SLA is defined as a pair of
  percentage and duration, where:

  percentage - Percentage of tasks required to be up within the duration.
  Applied to all jobs except those listed in --override_jobs file;

  duration - Time interval (now - value) for the percentage of up tasks.
  Applied to all jobs except those listed in --override_jobs file.
  Format: XdYhZmWs (each field is optional but must be in that order.)
  Examples: 5m, 1d3h45m.

  NOTE: if --grouping option is specified and is set to anything other than
        default (by_host) the results will be processed and filtered based
        on the grouping function on a all-or-nothing basis. In other words,
        the group is 'safe' IFF it is safe to kill tasks on all hosts in the
        group at the same time.
  """

    def parse_jobs_file(filename):
        result = {}
        with open(filename, "r") as overrides:
            for line in overrides:
                if not line.strip():
                    continue

                tokens = line.split()
                if len(tokens) != 3:
                    die("Invalid line in %s:%s" % (filename, line))
                job_key = AuroraJobKey.from_path(tokens[0])
                result[job_key] = JobUpTimeLimit(
                    job=job_key,
                    percentage=parse_sla_percentage(tokens[1]),
                    duration_secs=parse_time(tokens[2]).as_(Time.SECONDS),
                )
        return result

    options = app.get_options()

    sla_percentage = parse_sla_percentage(percentage)
    sla_duration = parse_time(duration)

    exclude_hosts = parse_hostnames_optional(options.exclude_hosts, options.exclude_filename)
    include_hosts = parse_hostnames_optional(options.include_hosts, options.include_filename)
    override_jobs = parse_jobs_file(options.override_filename) if options.override_filename else {}
    get_grouping_or_die(options.grouping)

    vector = AuroraClientAPI(CLUSTERS[cluster], options.verbosity).sla_get_safe_domain_vector(
        options.min_instance_count, include_hosts
    )
    groups = vector.get_safe_hosts(sla_percentage, sla_duration.as_(Time.SECONDS), override_jobs, options.grouping)

    results = []
    for group in groups:
        for host in sorted(group.keys()):
            if exclude_hosts and host in exclude_hosts:
                continue

            if options.list_jobs:
                results.append(
                    "\n".join(
                        [
                            "%s\t%s\t%.2f\t%d" % (host, d.job.to_path(), d.percentage, d.duration_secs)
                            for d in sorted(group[host])
                        ]
                    )
                )
            else:
                results.append("%s" % host)

    print_results(results)
开发者ID:mkacik,项目名称:incubator-aurora,代码行数:85,代码来源:admin.py

示例2: sla_list_safe_domain

# 需要导入模块: from apache.aurora.client.api import AuroraClientAPI [as 别名]
# 或者: from apache.aurora.client.api.AuroraClientAPI import get_safe_hosts [as 别名]
def sla_list_safe_domain(cluster, percentage, duration):
    """usage: sla_list_safe_domain
            [--exclude_hosts=filename]
            [--include_hosts=filename]
            [--list_jobs]
            [--override_jobs=filename]
            cluster percentage duration

  Returns a list of relevant hosts where it would be safe to kill
  tasks without violating their job SLA. The SLA is defined as a pair of
  percentage and duration, where:

  percentage - Percentage of tasks required to be up within the duration.
  Applied to all jobs except those listed in --override_jobs file;

  duration - Time interval (now - value) for the percentage of up tasks.
  Applied to all jobs except those listed in --override_jobs file.
  Format: XdYhZmWs (each field is optional but must be in that order.)
  Examples: 5m, 1d3h45m.
  """

    def parse_jobs_file(filename):
        result = {}
        with open(filename, "r") as overrides:
            for line in overrides:
                if not line.strip():
                    continue

                tokens = line.split()
                if len(tokens) != 3:
                    die("Invalid line in %s:%s" % (filename, line))
                job_key = AuroraJobKey.from_path(tokens[0])
                result[job_key] = DomainUpTimeSlaVector.JobUpTimeLimit(
                    job=job_key,
                    percentage=parse_sla_percentage(tokens[1]),
                    duration_secs=parse_time(tokens[2]).as_(Time.SECONDS),
                )
        return result

    options = app.get_options()

    sla_percentage = parse_sla_percentage(percentage)
    sla_duration = parse_time(duration)

    exclude_hosts = parse_hosts_optional(options.exclude_hosts, options.exclude_filename)
    include_hosts = parse_hosts_optional(options.include_hosts, options.include_filename)
    override_jobs = parse_jobs_file(options.override_filename) if options.override_filename else {}

    vector = AuroraClientAPI(CLUSTERS[cluster], options.verbosity).sla_get_safe_domain_vector(include_hosts)
    hosts = vector.get_safe_hosts(sla_percentage, sla_duration.as_(Time.SECONDS), override_jobs)

    results = []
    for host in sorted(hosts.keys()):
        if exclude_hosts and host in exclude_hosts:
            continue

        if options.list_jobs:
            results.append(
                "\n".join(
                    [
                        "%s\t%s\t%.2f\t%d" % (host, d.job.to_path(), d.percentage, d.duration_secs)
                        for d in sorted(hosts[host])
                    ]
                )
            )
        else:
            results.append("%s" % host)

    print_results(results)
开发者ID:retrack,项目名称:incubator-aurora,代码行数:71,代码来源:admin.py


注:本文中的apache.aurora.client.api.AuroraClientAPI.get_safe_hosts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。