<commit_before>#!/usr/bin/python
import json
import logging
import requests

log = logging.getLogger("jbosscli")

def invoke_cli(controller, auth, command):
    url = "http://{0}/management".format(controller)
    headers = {"Content-type":"application/json"}
    credentials = auth.split(":")

    log.debug("Requesting %s -> %s", controller, command)

    r = requests.post(url, data=command, headers=headers, auth=requests.auth.HTTPDigestAuth(credentials[0], credentials[1]))

    log.debug("Finished request with response code: %i", r.status_code)
    log.debug("Request body:\n%s", r.text)

    if (r.status_code >= 400 and not r.text):
        raise CliError("Request responded a {0} code".format(r.status_code))

    return r.json()

def read_used_heap(controller, auth, host=None, server=None):
    command = '{{"operation":"read-resource", "include-runtime":"true", "address":[{0}"core-service", "platform-mbean", "type", "memory"]}}'
    address = ""

    if (host and server):
        address = '"host","{0}","server","{1}", '.format(host,server)

    command = command.format(address)

    result = invoke_cli(controller, auth, command)

    heap_memory_usage = result['result']['heap-memory-usage']
<commit_msg>Preventing a halting Exception if there was a error in operation.<commit_after>#!/usr/bin/python
import json
import logging
import requests

log = logging.getLogger("jbosscli")

def invoke_cli(controller, auth, command):
    url = "http://{0}/management".format(controller)
    headers = {"Content-type":"application/json"}
    credentials = auth.split(":")

    log.debug("Requesting %s -> %s", controller, command)

    r = requests.post(url, data=command, headers=headers, auth=requests.auth.HTTPDigestAuth(credentials[0], credentials[1]))

    log.debug("Finished request with response code: %i", r.status_code)
    log.debug("Request body:\n%s", r.text)

    if (r.status_code >= 400 and not r.text):
        raise CliError("Request responded a {0} code".format(r.status_code))

    return r.json()

def read_used_heap(controller, auth, host=None, server=None):
    command = '{{"operation":"read-resource", "include-runtime":"true", "address":[{0}"core-service", "platform-mbean", "type", "memory"]}}'
    address = ""

    if (host and server):
        address = '"host","{0}","server","{1}", '.format(host,server)

    command = command.format(address)

    result = invoke_cli(controller, auth, command)

    if 'result' not in result:
        raise CliError(result)

    heap_memory_usage = result['result']['heap-memory-usage']

{'fraction_non_alphanumeric': 0.1701131486539212, 'fraction_numerical': 0.007803355442840421, 'mean_word_length': 4.478632478632479, 'pattern_counts': {'":': 10, '<': 3, '<?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': '558554', 'n_tokens_mistral': 814, 'n_tokens_neox': 783, 'n_words': 181}