<commit_before>from __future__ import print_function

import os
import sys

from dcos import http, util
import toml

from dcos.errors import DCOSException

def get_arangodb_framework(name):
    url = util.get_config().get('core.dcos_url') + "/mesos/state.json"
    try:
        response = http.get(url, timeout=15)
    except DCOSException as e:
        print("cannot connect to '" + url + "'", e)
        sys.exit(1)

    if response.status_code >= 200 and response.status_code < 300:
        json = response.json()

        if 'frameworks' not in json:
            print(json)
            sys.exit(1)

        frameworks = json['frameworks']

        for framework in frameworks:
            if name == framework['name']:
                return framework

        print("ArangoDB framework '" + name + "' is not running yet.")
        sys.exit(1)
    else:
        print("Bad response getting master state. Status code: "
              + str(response.status_code))
        sys.exit(1)


def get_arangodb_webui(name, internal):
    if name is None:
        name = "arangodb"

    if internal:
        arangodb_framework = get_arangodb_framework(name)
        return arangodb_framework['webui_url'].rstrip("/")
    else:
        base_url = util.get_config().get('core.dcos_url').rstrip("/")
        return base_url + "/service/" + name


def get_mode(name, internal):
    url = get_arangodb_webui(name, internal) + "/v1/mode.json"

    try:
        response = http.get(url, timeout=15)
    except DCOSException as e:
        print("cannot connect to '" + url + "'", e)
        sys.exit(1)

    if response.status_code >= 200 and response.status_code < 300:
        json = response.json()
        return json["mode"]
    else:
        print("Bad response getting mode. Status code: "
              + str(response.status_code))
        sys.exit(1)

def get_endpoints_coordinators(name, internal):
    url = get_arangodb_webui(name, internal) + "/v1/endpoints.json"

    try:
        response = http.get(url, timeout=15)
    except DCOSException as e:<commit_msg>Implement switch so that it supports old and new (3.0) frameworks<commit_after>from __future__ import print_function

import os
import sys

from dcos import http, util
import toml

from dcos.errors import DCOSException

def get_arangodb_framework(name):
    url = util.get_config().get('core.dcos_url') + "/mesos/state.json"
    try:
        response = http.get(url, timeout=15)
    except DCOSException as e:
        print("cannot connect to '" + url + "'", e)
        sys.exit(1)

    if response.status_code >= 200 and response.status_code < 300:
        json = response.json()

        if 'frameworks' not in json:
            print(json)
            sys.exit(1)

        frameworks = json['frameworks']

        for framework in frameworks:
            if name == framework['name']:
                return framework

        print("ArangoDB framework '" + name + "' is not running yet.")
        sys.exit(1)
    else:
        print("Bad response getting master state. Status code: "
              + str(response.status_code))
        sys.exit(1)


def get_arangodb_webui(name, internal):
    if name is None:
        name = "arangodb"

    if internal:
        arangodb_framework = get_arangodb_framework(name)
        service_url = arangodb_framework['webui_url'].rstrip("/")
    else:
        base_url = util.get_config().get('core.dcos_url').rstrip("/")
        service_url = base_url + "/service/" + name

    
    # find out if arangodb is mounted (new world) or if the framework is mounted
    version_url = service_url + "/_db/_system/_api/version"

    try:
        response = http.get(version_url, timeout=15)
    except DCOSException as e:
        # mop: as far as I get it I can't access the original http response because a completely new
        # exception has been raised. what I would want to check is if there is a 404 which would
        # indicate that this is an "old" version of the framework
        return service_url

    return service_url + "/framework"

def get_mode(name, internal):
    url = get_arangodb_webui(name, internal) + "/v1/mode.json"

    try:
        response = http.get(url, timeout=15)
    except DCOSException as e:
        print("cannot connect to '" + url + "'", e)
        sys.exit(1)

    if response.status_code >= 200 and response.status_code < 300:
        json = response.json()
        return json["mode"]
    else:
        print("Bad response getting mode. Status code: "
              + str(response.status_code))
        sys.exit(1)

def get_endpoints_coordinators(name, internal):
    url = get_arangodb_webui(name, internal) + "/v1/endpoints.json"

    try:
        response = http.get(url, timeout=15)
    except DCOSException as e:
{'fraction_non_alphanumeric': 0.10681244743481917, 'fraction_numerical': 0.0124053826745164, 'mean_word_length': 2.50811209439528, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4196416', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1420, 'n_words': 403}