<commit_before>#!/usr/bin/env python
"""
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

"""
from resource_management import *
import sys
from copy import deepcopy
import requests
queueNames=[]

def parse_queue(queueList, parent):
    global queueNames
    for queue in queueList:
        name = queue['queueName']
        path = parent + '.' + name
        if 'queues' in queue and 'queue' in queue['queues']:
            parse_queue(queue['queues']['queue'], path)
        else:
            queueNames.append(path)

def yarn_scheduler(params):
    queueNameList=['root.default']
    try:
        r = requests.get('http://' + params.rm_host + ':' + params.rm_port + '/ws/v1/cluster/scheduler',timeout=1)
    except:
        print "Excpetion: Yarn Rest Api of Scheduler Connection Failed."
    else:
        if r.status_code == requests.codes.ok:
            output = r.json()
            rootQueue = output['scheduler']['schedulerInfo']['queueName']
            if 'queues' in output['scheduler']['schedulerInfo'] and 'queue' in output['scheduler']['schedulerInfo']['queues']:
                queues = output['scheduler']['schedulerInfo']['queues']['queue']
                parse_queue(queues, rootQueue)<commit_msg>Use urllib3 instead requests to fix request sys moudle not find error<commit_after>#!/usr/bin/env python
"""
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

"""
from resource_management import *
import json
import urllib3
queueNames=[]

def parse_queue(queueList, parent):
    global queueNames
    for queue in queueList:
        name = queue['queueName']
        path = parent + '.' + name
        if 'queues' in queue and 'queue' in queue['queues']:
            parse_queue(queue['queues']['queue'], path)
        else:
            queueNames.append(path)

def yarn_scheduler(params):
    queueNameList=['root.default']
    try:
        http = urllib3.PoolManager()
        r = http.request('GET', 'http://' + params.rm_host + ':' + params.rm_port + '/ws/v1/cluster/scheduler', timeout=5.0)
    except:
        print "Excpetion: Yarn Rest Api of Scheduler Connection Failed."
    else:
        if r.status == 200:
            output = json.loads(r.data.decode('utf-8'))
            rootQueue = output['scheduler']['schedulerInfo']['queueName']
            if 'queues' in output['scheduler']['schedulerInfo'] and 'queue' in output['scheduler']['schedulerInfo']['queues']:
                queues = output['scheduler']['schedulerInfo']['queues']['queue']
                parse_queue(queues, rootQueue)
{'fraction_non_alphanumeric': 0.10289634146341463, 'fraction_numerical': 0.00508130081300813, 'mean_word_length': 3.4942922374429224, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1972107', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1046, 'n_words': 392}