Esempio n. 1
0
def resolve_application_ids(applications: dict, application_registry: str):
    with FuturesSession(max_workers=10, session=session) as futures_session:
        auth = cluster_discovery.OAuthTokenAuth("read-only")

        future_to_app = {}
        for app_id, app in applications.items():
            if app_id:
                future_to_app[futures_session.get(application_registry +
                                                  "/apps/" + app_id,
                                                  auth=auth,
                                                  timeout=5)] = app

        for future in concurrent.futures.as_completed(future_to_app):
            app = future_to_app[future]
            try:
                response = future.result()
                response.raise_for_status()
                data = response.json()
                if not isinstance(data, dict):
                    data = {}
            except Exception as e:
                logger.warning(
                    f"Failed to look up application {app['id']}: {e}")
                data = {}
            team_id = data.get("team_id", "")
            app["team"] = team_id
            app["active"] = data.get("active")
Esempio n. 2
0
def resolve_application_ids(applications: dict, teams: dict, application_registry: str):
    with FuturesSession(max_workers=10, session=session) as futures_session:
        auth = cluster_discovery.OAuthTokenAuth("read-only")

        future_to_app = {}
        for app_id, app in applications.items():
            if app_id:
                future_to_app[
                    futures_session.get(
                        application_registry + "/apps/" + app_id, auth=auth, timeout=5
                    )
                ] = app

        for future in concurrent.futures.as_completed(future_to_app):
            app = future_to_app[future]
            try:
                response = future.result()
                response.raise_for_status()
                data = response.json()
                if not isinstance(data, dict):
                    data = {}
            except Exception as e:
                logger.warning(
                    "Failed to look up application {}: {}".format(app["id"], e)
                )
                data = {}
            team_id = data.get("team_id", "")
            app["team"] = team_id
            app["active"] = data.get("active")
            team = teams.get(
                team_id,
                {
                    "clusters": set(),
                    "applications": set(),
                    "cost": 0,
                    "pods": 0,
                    "requests": {},
                    "usage": {},
                    "slack_cost": 0,
                },
            )
            team["applications"].add(app["id"])
            team["clusters"] |= app["clusters"]
            team["pods"] += app["pods"]
            for r in "cpu", "memory":
                team["requests"][r] = team["requests"].get(r, 0) + app["requests"][r]
                team["usage"][r] = team["usage"].get(r, 0) + app.get("usage", {}).get(
                    r, 0
                )
            team["cost"] += app["cost"]
            team["slack_cost"] += app["slack_cost"]
            teams[team_id] = team