def check(self, instance):
    rm_address = instance.get('resourcemanager_uri')
    if (rm_address is None):
        raise Exception('The ResourceManager URL must be specified in the instance configuration')
    collect_task_metrics = _is_affirmative(instance.get('collect_task_metrics', False))
    tags = instance.get('tags', [])
    if (tags is None):
        tags = []
    else:
        tags = list(set(tags))
    cluster_name = instance.get('cluster_name')
    if (cluster_name is None):
        self.warning(("The cluster_name must be specified in the instance configuration, defaulting to '%s'" % DEFAULT_CUSTER_NAME))
        cluster_name = DEFAULT_CUSTER_NAME
    tags.append(('cluster_name:%s' % cluster_name))
    running_apps = self._get_running_app_ids(rm_address)
    self.service_check(YARN_SERVICE_CHECK, AgentCheck.OK, tags=[('url:%s' % rm_address)], message=('Connection to ResourceManager "%s" was successful' % rm_address))
    running_jobs = self._mapreduce_job_metrics(running_apps, tags)
    self._mapreduce_job_counters_metrics(running_jobs, tags)
    if collect_task_metrics:
        self._mapreduce_task_metrics(running_jobs, tags)
    if running_jobs:
        (job_id, metrics) = running_jobs.items()[0]
        am_address = self._get_url_base(metrics['tracking_url'])
        self.service_check(MAPREDUCE_SERVICE_CHECK, AgentCheck.OK, tags=[('url:%s' % am_address)], message=('Connection to ApplicationManager "%s" was successful' % am_address))
def check(self, instance):
    rm_address = instance.get('resourcemanager_uri')
    if (rm_address is None):
        raise Exception('The ResourceManager URL must be specified in the instance configuration')
    collect_task_metrics = _is_affirmative(instance.get('collect_task_metrics', False))
    tags = instance.get('tags', [])
    if (tags is None):
        tags = []
    else:
        tags = list(set(tags))
    cluster_name = instance.get('cluster_name')
    if (cluster_name is None):
        self.warning(("The cluster_name must be specified in the instance configuration, defaulting to '%s'" % DEFAULT_CUSTER_NAME))
        cluster_name = DEFAULT_CUSTER_NAME
    tags.append(('cluster_name:%s' % cluster_name))
    running_apps = self._get_running_app_ids(rm_address)
    self.service_check(YARN_SERVICE_CHECK, AgentCheck.OK, tags=[('url:%s' % rm_address)], message=('Connection to ResourceManager "%s" was successful' % rm_address))
    running_jobs = self._mapreduce_job_metrics(running_apps, tags)
    self._mapreduce_job_counters_metrics(running_jobs, tags)
    if collect_task_metrics:
        self._mapreduce_task_metrics(running_jobs, tags)
    if running_jobs:
        (job_id, metrics) = running_jobs.items()[0]
        am_address = self._get_url_base(metrics['tracking_url'])
        self.service_check(MAPREDUCE_SERVICE_CHECK, AgentCheck.OK, tags=[('url:%s' % am_address)], message=('Connection to ApplicationManager "%s" was successful' % am_address))