<commit_before>#!/usr/bin/env python

import json
import logging
import requests
import shutil
import sys
import time

from os import getenv

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s - %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S')

MARATHON_ROOT_URL = getenv('MARATHON_ROOT_URL', 'http://marathon.mesos:8080')
MARATHON_APP = getenv('MARATHON_APP', 'geoserver-slave')
MARATHON_APP_PORT = int(getenv('MARATHON_APP_PORT', '8080'))

FRAMEWORK_NAME = getenv('FRAMEWORK_NAME', 'geoserver')
EXTERNAL_VHOST = getenv('EXTERNAL_VHOST', 'geoserver.marathon.mesos')
SERVICE_PORT = int(getenv('SERVICE_PORT', 0))
GOSU_USER = getenv('GOSU_USER', 'root:root')
GEOSERVER_DATA_DIR = getenv('GEOSERVER_DATA_DIR', '/srv/geoserver')
GEOSERVER_MASTER_APP = FRAMEWORK_NAME + '-master'
GEOSERVER_SLAVE_APP = FRAMEWORK_NAME + '-slave'
GEOSERVER_IMAGE = 'gisjedi/geoserver:2.8'
GS_SLAVE_INSTANCES = int(getenv('GS_SLAVE_INSTANCES', 3))
HOST_GEOSERVER_DATA_DIR = getenv('HOST_GEOSERVER_DATA_DIR', '/shared/geoserver')

APPS_ENDPOINT = '%s/v2/apps' % MARATHON_ROOT_URL


def create_app_validate(apps_endpoint, marathon_json, app_type):
    response = requests.post(apps_endpoint, data=json.dumps(marathon_json))
    if response.status_code == 409:
        logging.info('Application for %s already created, moving on.' % app_type)
    elif response.status_code == 201:
        logging.info('Successfully created GeoServer %s app in Marathon.' % app_type)
    else:
        logging.critical('Unable to create new Marathon App for GeoServer %s.' % app_type)
        sys.exit(1)


def block_for_healthy_app(apps_endpoint, app_name):
    while json.loads(requests.get('%s/%s' % (apps_endpoint, app_name)).text)['app']['tasksHealthy'] == 0:
        logging.info("Waiting for healthy app %s." % app_name)
        time.sleep(5)

with open('configs/geoserver-master.json') as marathon_config:
    marathon_json = json.load(marathon_config)
    # Shim in the appropriate config values from environment
    marathon_json['id'] = GEOSERVER_MASTER_APP
    marathon_json['env']['GOSU_USER'] = GOSU_USER
    marathon_json['container']['docker']['image'] = GEOSERVER_IMAGE
    marathon_json['container']['docker']['portMappings'][0]['servicePort'] = SERVICE_PORT
    marathon_json['container']['volumes'][0]['hostPath'] = HOST_GEOSERVER_DATA_DIR<commit_msg>Extra error reporting for launch failures<commit_after>#!/usr/bin/env python

import json
import logging
import requests
import shutil
import sys
import time

from os import getenv

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s - %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S')

MARATHON_ROOT_URL = getenv('MARATHON_ROOT_URL', 'http://marathon.mesos:8080')
MARATHON_APP = getenv('MARATHON_APP', 'geoserver-slave')
MARATHON_APP_PORT = int(getenv('MARATHON_APP_PORT', '8080'))

FRAMEWORK_NAME = getenv('FRAMEWORK_NAME', 'geoserver')
EXTERNAL_VHOST = getenv('EXTERNAL_VHOST', 'geoserver.marathon.mesos')
SERVICE_PORT = int(getenv('SERVICE_PORT', 0))
GOSU_USER = getenv('GOSU_USER', 'root:root')
GEOSERVER_DATA_DIR = getenv('GEOSERVER_DATA_DIR', '/srv/geoserver')
GEOSERVER_MASTER_APP = FRAMEWORK_NAME + '-master'
GEOSERVER_SLAVE_APP = FRAMEWORK_NAME + '-slave'
GEOSERVER_IMAGE = 'gisjedi/geoserver:2.8'
GS_SLAVE_INSTANCES = int(getenv('GS_SLAVE_INSTANCES', 3))
HOST_GEOSERVER_DATA_DIR = getenv('HOST_GEOSERVER_DATA_DIR', '/shared/geoserver')

APPS_ENDPOINT = '%s/v2/apps' % MARATHON_ROOT_URL


def create_app_validate(apps_endpoint, marathon_json, app_type):
    response = requests.post(apps_endpoint, data=json.dumps(marathon_json))
    if response.status_code == 409:
        logging.info('Application for %s already created, moving on.' % app_type)
    elif response.status_code == 201:
        logging.info('Successfully created GeoServer %s app in Marathon.' % app_type)
    else:
        logging.critical('Unable to create new Marathon App for GeoServer %s. Response code %s and error: %s' %
                         (app_type, response.status_code, response.text))
        sys.exit(1)


def block_for_healthy_app(apps_endpoint, app_name):
    while json.loads(requests.get('%s/%s' % (apps_endpoint, app_name)).text)['app']['tasksHealthy'] == 0:
        logging.info("Waiting for healthy app %s." % app_name)
        time.sleep(5)

with open('configs/geoserver-master.json') as marathon_config:
    marathon_json = json.load(marathon_config)
    # Shim in the appropriate config values from environment
    marathon_json['id'] = GEOSERVER_MASTER_APP
    marathon_json['env']['GOSU_USER'] = GOSU_USER
    marathon_json['container']['docker']['image'] = GEOSERVER_IMAGE
    marathon_json['container']['docker']['portMappings'][0]['servicePort'] = SERVICE_PORT
    marathon_json['container']['volumes'][0]['hostPath'] = HOST_GEOSERVER_DATA_DIR
{'fraction_non_alphanumeric': 0.13469052025498662, 'fraction_numerical': 0.00987045033929673, 'mean_word_length': 5.227912932138285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '473765', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1690, 'n_words': 300}