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


Python marathon.MarathonClient方法代码示例

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


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

示例1: get_marathon_app_deploy_status

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def get_marathon_app_deploy_status(
    client: MarathonClient, app: MarathonApp = None
) -> int:
    # Check the launch queue to see if an app is blocked
    is_overdue, backoff_seconds = get_app_queue_status(client, app.id)

    # Based on conditions at https://mesosphere.github.io/marathon/docs/marathon-ui.html
    if is_overdue:
        deploy_status = MarathonDeployStatus.Waiting
    elif backoff_seconds:
        deploy_status = MarathonDeployStatus.Delayed
    elif len(app.deployments) > 0:
        deploy_status = MarathonDeployStatus.Deploying
    elif app.instances == 0 and app.tasks_running == 0:
        deploy_status = MarathonDeployStatus.Stopped
    else:
        deploy_status = MarathonDeployStatus.Running

    return deploy_status 
开发者ID:Yelp,项目名称:paasta,代码行数:21,代码来源:marathon_tools.py

示例2: get_marathon_client

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def get_marathon_client(
    url: Sequence[str], user: str, passwd: str, cached: bool = False
) -> MarathonClient:
    """Get a new Marathon client connection in the form of a MarathonClient object.

    :param url: The url to connect to Marathon at
    :param user: The username to connect with
    :param passwd: The password to connect with
    :param cached: If true, return CachedMarathonClient
    :returns: A new marathon.MarathonClient object"""
    log.info("Connecting to Marathon server at: %s", url)

    session = requests.Session()
    session.headers.update({"User-Agent": get_user_agent()})

    if cached:
        return CachedMarathonClient(url, user, passwd, timeout=30, session=session)
    else:
        return MarathonClient(url, user, passwd, timeout=30, session=session) 
开发者ID:Yelp,项目名称:paasta,代码行数:21,代码来源:marathon_tools.py

示例3: kill_task

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def kill_task(
    client: MarathonClient, app_id: str, task_id: str, scale: bool
) -> Optional[MarathonTask]:
    """Wrapper to the official kill_task method that is tolerant of errors"""
    try:
        return client.kill_task(app_id=app_id, task_id=task_id, scale=True)
    except MarathonHttpError as e:
        # Marathon allows you to kill and scale in one action, but this is not
        # idempotent. If you kill&scale the same task ID twice, the number of instances
        # gets decremented twice. This can lead to a situation where kill&scaling the
        # last task decrements the number of instances below zero, causing an "Object is not
        # valid" message or a "Bean is not valid" message.
        if "is not valid" in e.error_message and e.status_code == 422:
            log.warning(
                "Got 'is not valid' when killing task %s. Continuing anyway." % task_id
            )
            return None
        elif "does not exist" in e.error_message and e.status_code == 404:
            log.warning(
                "Got 'does not exist' when killing task %s. Continuing anyway."
                % task_id
            )
            return None
        else:
            raise 
开发者ID:Yelp,项目名称:paasta,代码行数:27,代码来源:marathon_tools.py

示例4: kill_given_tasks

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def kill_given_tasks(
    client: MarathonClient, task_ids: Sequence[str], scale: bool
) -> bool:
    """Wrapper to the official kill_given_tasks method that is tolerant of errors"""
    if not task_ids:
        log.debug("No task_ids specified, not killing any tasks")
        return False
    try:
        return client.kill_given_tasks(task_ids=task_ids, scale=scale, force=True)
    except MarathonHttpError as e:
        # Marathon's interface is always async, so it is possible for you to see
        # a task in the interface and kill it, yet by the time it tries to kill
        # it, it is already gone. This is not really a failure condition, so we
        # swallow this error.
        if "is not valid" in e.error_message and e.status_code == 422:
            log.debug("Probably tried to kill a task id that didn't exist. Continuing.")
            return False
        else:
            raise 
开发者ID:Yelp,项目名称:paasta,代码行数:21,代码来源:marathon_tools.py

示例5: test_deploy_marathon_service

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def test_deploy_marathon_service(self):
        with mock.patch(
            "paasta_tools.setup_marathon_job.setup_service", autospec=True
        ) as mock_setup_service, mock.patch(
            "paasta_tools.setup_marathon_job.bounce_lib.bounce_lock_zookeeper",
            autospec=True,
            side_effect=bounce_lib.LockHeldException,
        ):
            mock_clients: marathon_tools.MarathonClients = mock.Mock()
            mock_system_paasta_config = mock.Mock()
            mock_marathon_apps_with_clients: List[
                Tuple[MarathonApp, MarathonClient]
            ] = []
            ret = setup_marathon_job.deploy_marathon_service(
                "something",
                "main",
                mock_clients,
                "fake_soa",
                mock_marathon_apps_with_clients,
                mock_system_paasta_config,
            )
            assert not mock_setup_service.called
            assert ret == (0, None) 
开发者ID:Yelp,项目名称:paasta,代码行数:25,代码来源:test_setup_marathon_job.py

示例6: dcos_login

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def dcos_login():
    # Defaults servers for both DCOS 1.10+ CE and EE.
    servers = os.getenv('MARATHON_SERVERS',
                        'http://marathon.mesos:8080,https://marathon.mesos:8443').split(',')

    if SERVICE_SECRET:
        print('Attempting token auth to Marathon...')
        client = MarathonClient(servers, auth_token=DCOSServiceAuth(json.loads(SERVICE_SECRET)).token, verify=False)
    else:
        print('Attempting unauthenticated access to Marathon...')
        client = MarathonClient(servers, verify=False)

    return client 
开发者ID:ngageoint,项目名称:scale,代码行数:15,代码来源:bootstrap.py

示例7: marathon_app_status

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def marathon_app_status(
    app: MarathonApp,
    marathon_client: MarathonClient,
    dashboard_link: Optional[str],
    deploy_status: int,
    list_tasks: bool = False,
) -> MutableMapping[str, Any]:
    app_status = {
        "tasks_running": app.tasks_running,
        "tasks_healthy": app.tasks_healthy,
        "tasks_staged": app.tasks_staged,
        "tasks_total": app.instances,
        "create_timestamp": isodate.parse_datetime(app.version).timestamp(),
        "deploy_status": marathon_tools.MarathonDeployStatus.tostring(deploy_status),
    }

    app_queue = marathon_tools.get_app_queue(marathon_client, app.id)
    if deploy_status == marathon_tools.MarathonDeployStatus.Delayed:
        _, backoff_seconds = marathon_tools.get_app_queue_status_from_queue(app_queue)
        app_status["backoff_seconds"] = backoff_seconds

    unused_offers_summary = marathon_tools.summarize_unused_offers(app_queue)
    if unused_offers_summary is not None:
        app_status["unused_offers"] = unused_offers_summary

    if dashboard_link:
        app_status["dashboard_url"] = "{}/ui/#/apps/%2F{}".format(
            dashboard_link.rstrip("/"), app.id.lstrip("/")
        )

    if list_tasks is True:
        app_status["tasks"] = []
        for task in app.tasks:
            app_status["tasks"].append(build_marathon_task_dict(task))

    return app_status 
开发者ID:Yelp,项目名称:paasta,代码行数:38,代码来源:instance.py

示例8: __init__

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def __init__(
        self, current: Sequence[MarathonClient], previous: Sequence[MarathonClient]
    ) -> None:
        self.current = current
        self.previous = previous 
开发者ID:Yelp,项目名称:paasta,代码行数:7,代码来源:marathon_tools.py

示例9: get_current_client_for_service

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def get_current_client_for_service(
        self, job_config: "MarathonServiceConfig"
    ) -> MarathonClient:
        service_instance = compose_job_id(job_config.service, job_config.instance)
        if job_config.get_marathon_shard() is not None:
            return self.current[job_config.get_marathon_shard()]
        else:
            return rendezvous_hash(choices=self.current, key=service_instance) 
开发者ID:Yelp,项目名称:paasta,代码行数:10,代码来源:marathon_tools.py

示例10: get_previous_clients_for_service

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def get_previous_clients_for_service(
        self, job_config: "MarathonServiceConfig"
    ) -> Sequence[MarathonClient]:
        service_instance = compose_job_id(job_config.service, job_config.instance)
        if job_config.get_previous_marathon_shards() is not None:
            return [self.previous[i] for i in job_config.get_previous_marathon_shards()]
        else:
            try:
                return [rendezvous_hash(choices=self.previous, key=service_instance)]
            except ValueError:
                return [] 
开发者ID:Yelp,项目名称:paasta,代码行数:13,代码来源:marathon_tools.py

示例11: get_all_clients_for_service

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def get_all_clients_for_service(
        self, job_config: "MarathonServiceConfig"
    ) -> Sequence[MarathonClient]:
        """Return the set of all clients that a service might have apps on, with no duplicate clients."""
        all_clients = [self.get_current_client_for_service(job_config)]
        all_clients.extend(self.get_previous_clients_for_service(job_config))

        return dedupe_clients(all_clients) 
开发者ID:Yelp,项目名称:paasta,代码行数:10,代码来源:marathon_tools.py

示例12: dedupe_clients

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def dedupe_clients(all_clients: Iterable[MarathonClient],) -> Sequence[MarathonClient]:
    """Return a subset of the clients with no servers in common. The assumption here is that if there's any overlap in
    servers, then two clients are talking about the same cluster."""
    all_seen_servers: Set[str] = set()
    deduped_clients: List[MarathonClient] = []
    for client in all_clients:
        if not any(server in all_seen_servers for server in client.servers):
            all_seen_servers.update(client.servers)
            deduped_clients.append(client)

    return deduped_clients 
开发者ID:Yelp,项目名称:paasta,代码行数:13,代码来源:marathon_tools.py

示例13: get_list_of_marathon_clients

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def get_list_of_marathon_clients(
    system_paasta_config: Optional[SystemPaastaConfig] = None, cached: bool = False
) -> Sequence[MarathonClient]:
    if system_paasta_config is None:
        system_paasta_config = load_system_paasta_config()
    marathon_servers = get_marathon_servers(system_paasta_config)
    return get_marathon_clients(marathon_servers, cached=cached).get_all_clients() 
开发者ID:Yelp,项目名称:paasta,代码行数:9,代码来源:marathon_tools.py

示例14: list_all_marathon_app_ids

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def list_all_marathon_app_ids(client: MarathonClient,) -> Sequence[str]:
    """List all marathon app_ids, regardless of state

    The raw marathon API returns app ids in their URL form, with leading '/'s
    conforming to the Application Group format:
    https://github.com/mesosphere/marathon/blob/master/docs/docs/application-groups.md

    This function wraps the full output of list_apps to return a list
    in the original form, without leading "/"'s.

    returns: List of app ids in the same format they are POSTed."""
    return [app.id.lstrip("/") for app in get_all_marathon_apps(client)] 
开发者ID:Yelp,项目名称:paasta,代码行数:14,代码来源:marathon_tools.py

示例15: app_has_tasks

# 需要导入模块: import marathon [as 别名]
# 或者: from marathon import MarathonClient [as 别名]
def app_has_tasks(
    client: MarathonClient,
    app_id: str,
    expected_tasks: int,
    exact_matches_only: bool = False,
) -> bool:
    """A predicate function indicating whether an app has launched *at least* expected_tasks
    tasks.

    Raises a marathon.NotFoundError when no app with matching id is found.

    :param client: the marathon client
    :param app_id: the app_id to which the tasks should belong. The leading / that marathon appends to
        app_ids is added here.
    :param expected_tasks: the number of tasks to check for
    :param exact_matches_only: a boolean indicating whether we require exactly expected_tasks to be running
    :returns: a boolean indicating whether there are atleast expected_tasks tasks with
        an app id matching app_id
    """
    app_id = "/%s" % app_id
    try:
        tasks = client.list_tasks(app_id=app_id)
    except NotFoundError:
        print("no app with id %s found" % app_id)
        raise
    print("app %s has %d of %d expected tasks" % (app_id, len(tasks), expected_tasks))
    if exact_matches_only:
        return len(tasks) == expected_tasks
    else:
        return len(tasks) >= expected_tasks 
开发者ID:Yelp,项目名称:paasta,代码行数:32,代码来源:marathon_tools.py


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