# Path: hoplite/utils/server_logging.py
# def get_server_logger(name=""):
# def get_job_logger(name="", uuid=""):
# def _get_base_logger(name=""):
# def add_remote_function_logging_handlers(function_namespace, timestamp, filename=None):
# def get_log_filename(function_namespace, timestamp):
# def get_formatter_verbose():
# def get_formatter_limited():
# 
# Path: hoplite/serializer.py
# def hoplite_loads(s, *args, **kwargs):
#     """
#     Decodes a serialized dictionary.
#     :param s: serialized dictionary
#     :return: unserialized dictionary
#     """
#     compile_re = kwargs.pop('compile_re', True)
#     ensure_tzinfo = kwargs.pop('ensure_tzinfo', False)
#     encoding = kwargs.pop('encoding', 'utf-8')
#     kwargs['object_hook'] = lambda dct: object_hook(dct, compile_re, ensure_tzinfo, encoding)
#     return json.loads(s, *args, **kwargs)
# 
# Path: hoplite/api/helpers.py
# def jsonify(*args, **kwargs):
# def get_job_manager():
# 
# Path: hoplite/exceptions.py
# class JobDoesNotExistError(HopliteError):
#     def __init__(self, message="Job does not exist"):
#         self.message = message
# 
#     def __str__(self):
#         return self.message
# 
# class JobPluginDoesNotExistError(HopliteError):
#     def __init__(self, name):
#         self.job_plugin_name = name
# 
#     def __str__(self):
#         return "Job plugin '{0}' does not exist".format(self.job_plugin_name)
# 
# class JobNotStartedError(HopliteError):
#     def __init__(self, uuid):
#         self.msg = "Job UUID: {0} has not been started".format(uuid)
# 
#     def __str__(self):
#         return self.msg
# 
# class JobAlreadyStartedError(HopliteError):
#     def __init__(self, uuid):
#         self.msg = "Job UUID: {0} you cannot start a job more than once".format(uuid)
# 
#     def __str__(self):
#         return self.msg


from hoplite.utils import server_logging
from hoplite.serializer import hoplite_loads
from flask import Blueprint, request
from hoplite.api.helpers import job_manager, jsonify
from hoplite.exceptions import (
    JobDoesNotExistError,
    JobPluginDoesNotExistError,
    JobNotStartedError,
    JobAlreadyStartedError)
    return jsonify(jobs=jobs_as_dict)


@bp.route("", methods=['POST'])
def create_job():
    job_dict = hoplite_loads(request.data)
    name = job_dict.get('name', "default")
    config = job_dict.get('config', {})
    running = job_dict.get('running', False)
    port = job_dict.get('port', 5000)
    try:
        logger.debug(
            "HTTP: Request Create Job:{0} - From: {1}".format(
                name, request.remote_addr))
        job = job_manager.create_job(name, config, running, port)
    except JobPluginDoesNotExistError, e:
        return jsonify(error=str(e)), 400
    return jsonify(**job.to_dict())


@bp.route("/<job_uuid_string>", methods=['GET', 'PUT'])
def created_job(job_uuid_string):
    logger.debug(
        "HTTP: {0} Status Job UUID:{1} - From: {2}".format(
            request.method, job_uuid_string, request.remote_addr))
    try:
        job = job_manager.get_job(job_uuid_string)
    except (JobDoesNotExistError, ValueError) as e:
        return jsonify(error=str(e)), 404
    if request.method == 'PUT':

# Path: hoplite/utils/server_logging.py
# def get_server_logger(name=""):
# def get_job_logger(name="", uuid=""):
# def _get_base_logger(name=""):
# def add_remote_function_logging_handlers(function_namespace, timestamp, filename=None):
# def get_log_filename(function_namespace, timestamp):
# def get_formatter_verbose():
# def get_formatter_limited():
# 
# Path: hoplite/serializer.py
# def hoplite_loads(s, *args, **kwargs):
#     """
#     Decodes a serialized dictionary.
#     :param s: serialized dictionary
#     :return: unserialized dictionary
#     """
#     compile_re = kwargs.pop('compile_re', True)
#     ensure_tzinfo = kwargs.pop('ensure_tzinfo', False)
#     encoding = kwargs.pop('encoding', 'utf-8')
#     kwargs['object_hook'] = lambda dct: object_hook(dct, compile_re, ensure_tzinfo, encoding)
#     return json.loads(s, *args, **kwargs)
# 
# Path: hoplite/api/helpers.py
# def jsonify(*args, **kwargs):
# def get_job_manager():
# 
# Path: hoplite/exceptions.py
# class JobDoesNotExistError(HopliteError):
#     def __init__(self, message="Job does not exist"):
#         self.message = message
# 
#     def __str__(self):
#         return self.message
# 
# class JobPluginDoesNotExistError(HopliteError):
#     def __init__(self, name):
#         self.job_plugin_name = name
# 
#     def __str__(self):
#         return "Job plugin '{0}' does not exist".format(self.job_plugin_name)
# 
# class JobNotStartedError(HopliteError):
#     def __init__(self, uuid):
#         self.msg = "Job UUID: {0} has not been started".format(uuid)
# 
#     def __str__(self):
#         return self.msg
# 
# class JobAlreadyStartedError(HopliteError):
#     def __init__(self, uuid):
#         self.msg = "Job UUID: {0} you cannot start a job more than once".format(uuid)
# 
#     def __str__(self):
#         return self.msg


# Path: hoplite/api/jobs.py
from hoplite.utils import server_logging
from hoplite.serializer import hoplite_loads
from flask import Blueprint, request
from hoplite.api.helpers import job_manager, jsonify
from hoplite.exceptions import (
    JobDoesNotExistError,
    JobPluginDoesNotExistError,
    JobNotStartedError,
    JobAlreadyStartedError)

    return jsonify(jobs=jobs_as_dict)


@bp.route("", methods=['POST'])
def create_job():
    job_dict = hoplite_loads(request.data)
    name = job_dict.get('name', "default")
    config = job_dict.get('config', {})
    running = job_dict.get('running', False)
    port = job_dict.get('port', 5000)
    try:
        logger.debug(
            "HTTP: Request Create Job:{0} - From: {1}".format(
                name, request.remote_addr))
        job = job_manager.create_job(name, config, running, port)
    except JobPluginDoesNotExistError, e:
        return jsonify(error=str(e)), 400
    return jsonify(**job.to_dict())


@bp.route("/<job_uuid_string>", methods=['GET', 'PUT'])
def created_job(job_uuid_string):
    logger.debug(
        "HTTP: {0} Status Job UUID:{1} - From: {2}".format(
            request.method, job_uuid_string, request.remote_addr))
    try:
        job = job_manager.get_job(job_uuid_string)
    except (JobDoesNotExistError, ValueError) as e:
        return jsonify(error=str(e)), 404
    if request.method == 'PUT':

        r_json = hoplite_loads(request.data)