def status_marathon_job(service, instance, app_id, normal_instance_count, client): status = marathon_tools.get_marathon_app_deploy_status(client, app_id) app_queue = marathon_tools.get_app_queue(client, app_id) unused_offers_summary = marathon_tools.summarize_unused_offers(app_queue) if status == marathon_tools.MarathonDeployStatus.Delayed: _, backoff_seconds = marathon_tools.get_app_queue_status_from_queue( app_queue) deploy_status_human = marathon_app_deploy_status_human( status, backoff_seconds) else: deploy_status_human = marathon_app_deploy_status_human(status) if status == marathon_tools.MarathonDeployStatus.NotRunning: running_instances = 0 else: running_instances = client.get_app(app_id).tasks_running return status_marathon_job_human( service, instance, deploy_status_human, app_id, running_instances, normal_instance_count, unused_offers_summary, )
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
def status_marathon_app( marathon_client: marathon_tools.MarathonClient, app: marathon_tools.MarathonApp, service: str, instance: str, cluster: str, soa_dir: str, dashboards: Dict[marathon_tools.MarathonClient, str], verbose: int, ) -> Tuple[int, int, str]: """Takes a given marathon app object and returns the details about start, times, hosts, etc""" output = [] create_datetime = datetime_from_utc_to_local(isodate.parse_datetime(app.version)) output.append(get_marathon_dashboard(marathon_client, dashboards, app.id)) output.append( " " + " ".join( [ f"{app.tasks_running} running,", f"{app.tasks_healthy} healthy,", f"{app.tasks_staged} staged", f"out of {app.instances}", ] ) ) output.append( " App created: {} ({})".format( str(create_datetime), humanize.naturaltime(create_datetime) ) ) deploy_status = marathon_tools.get_marathon_app_deploy_status(marathon_client, app) app_queue = marathon_tools.get_app_queue(marathon_client, app.id) unused_offers_summary = marathon_tools.summarize_unused_offers(app_queue) if deploy_status == marathon_tools.MarathonDeployStatus.Delayed: _, backoff_seconds = marathon_tools.get_app_queue_status_from_queue(app_queue) deploy_status_human = marathon_app_deploy_status_human( deploy_status, backoff_seconds ) else: deploy_status_human = marathon_app_deploy_status_human(deploy_status) output.append(f" Status: {deploy_status_human}") if unused_offers_summary is not None and len(unused_offers_summary) > 0: output.append(" Possibly stalled for:") output.append( " ".join([f"{k}: {n} times" for k, n in unused_offers_summary.items()]) ) if verbose > 0: output.append(" Tasks:") rows = [ ( "Mesos Task ID", "Host deployed to", "Deployed at what localtime", "Health", ) ] for task in app.tasks: local_deployed_datetime = datetime_from_utc_to_local(task.staged_at) if task.host is not None: hostname = "{}:{}".format(task.host.split(".")[0], task.ports[0]) else: hostname = "Unknown" if not task.health_check_results: health_check_status = PaastaColors.grey("N/A") elif marathon_tools.is_task_healthy(task): health_check_status = PaastaColors.green("Healthy") else: health_check_status = PaastaColors.red("Unhealthy") rows.append( ( get_short_task_id(task.id), hostname, "{} ({})".format( local_deployed_datetime.strftime("%Y-%m-%dT%H:%M"), humanize.naturaltime(local_deployed_datetime), ), health_check_status, ) ) output.append("\n".join([" %s" % line for line in format_table(rows)])) if len(app.tasks) == 0: output.append(" No tasks associated with this marathon app") return deploy_status, app.tasks_running, "\n".join(output)