# 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/exceptions.py
# 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
# 
# 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 NotAuthorizedError(HopliteError):
#     def __init__(self):
#         pass
# 
#     def __str__(self):
#         return "You are not authorized to perform this action"
# 
# Path: hoplite/client/status_updater.py
# class StatusUpdater(object):
#     """
#     Used to update the status of the job running on the daemon.
#     This is passed in to the job's run() function when it is invoked.
#     """
#     def __init__(self, addr, uuid, api_key):
#         self.addr = addr
#         self._uuid = uuid
#         self._daemon_addr = 'http://{0}'.format(self.addr)
#         self._api_key = api_key
#         self.status = {}
# 
#     def update(self, status):
#         """
#         Updates the job's status on the server that created it.
# 
#         :param dict status: The new status of the job
#         """
#         self.status = status
#         body = hoplite_dumps({
#             "api_key": self._api_key,
#             "status": status
#         })
#         url = self._daemon_addr + '/jobs/{0}'.format(self._uuid)
#         headers = {'content-type': 'application/json'}
#         r = requests.put(url, data=body, headers=headers)
#         if r.status_code == 404:
#             raise JobDoesNotExistError
# 
# Path: hoplite/plugin_manager.py
# class EntryPointManager(object):
#     """
#     Interface to the hoplite.jobs set of entry points
#     """
#     def __init__(self, group_name='hoplite.jobs'):
#         self.entry_point_group_name = group_name
# 
#     def get_plugin_names(self):
#         names = []
#         for entry_point in self._entry_points():
#             names.append(entry_point.name)
#         return names
# 
#     def get_plugin_module_by_name(self, name):
#         # TODO: Should we validate the module implements the correct methods
#         # before returning it to the caller?
#         for entry_point in self._entry_points():
#             if entry_point.name == name:
#                 return entry_point.load()
# 
#     def _entry_points(self):
#         # TODO: If it takes too long to reload pkg_resources, it might be worth
#         # looking into only loading if a package
#         # TODO: isn't found and then try again.
#         reload(pkg_resources)  # makes sure entry points are up-to-date
#         for entry_point in pkg_resources.iter_entry_points(group=self.entry_point_group_name):
#             logger.debug("Found entry point: {0}".format(entry_point.name))
#             yield entry_point


from multiprocessing import Process
from multiprocessing import Pipe
from hoplite.utils import server_logging
from hoplite.exceptions import (
    JobAlreadyStartedError,
    JobNotStartedError,
    NotAuthorizedError)
from job_wrapper import job_wrapper
from hoplite.client.status_updater import StatusUpdater
from hoplite.plugin_manager import EntryPointManager
    def kill(self):
        """
        Kills the job if has been started. Raises a JobNotStartedError if it
        has not started yet. If the job has already finished, the job will
        still be flagged as killed, but it will not have any further
        consequences.
        """
        if self._process is None:
            raise JobNotStartedError(self.uuid)
        self._logger.debug(
            "Terminating Job:{0} UUID:{1}".format(self.name, self.uuid))
        self._process.terminate()
        self._pipe_to_process = None
        self._pipe_to_self = None
        self._killed = True

    def to_dict(self):
        """
        Returns a dictionary representation of the job.
        Used to serialize job data using JSON for sending over the network.
        """
        d = {}
        d["uuid"] = self.uuid
        d["name"] = self.name
        d["config"] = self.config
        d["status"] = self.status()
        d["running"] = self.running()
        d["killed"] = self.killed()
        try:
            d["finished"] = self.finished()

# 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/exceptions.py
# 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
# 
# 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 NotAuthorizedError(HopliteError):
#     def __init__(self):
#         pass
# 
#     def __str__(self):
#         return "You are not authorized to perform this action"
# 
# Path: hoplite/client/status_updater.py
# class StatusUpdater(object):
#     """
#     Used to update the status of the job running on the daemon.
#     This is passed in to the job's run() function when it is invoked.
#     """
#     def __init__(self, addr, uuid, api_key):
#         self.addr = addr
#         self._uuid = uuid
#         self._daemon_addr = 'http://{0}'.format(self.addr)
#         self._api_key = api_key
#         self.status = {}
# 
#     def update(self, status):
#         """
#         Updates the job's status on the server that created it.
# 
#         :param dict status: The new status of the job
#         """
#         self.status = status
#         body = hoplite_dumps({
#             "api_key": self._api_key,
#             "status": status
#         })
#         url = self._daemon_addr + '/jobs/{0}'.format(self._uuid)
#         headers = {'content-type': 'application/json'}
#         r = requests.put(url, data=body, headers=headers)
#         if r.status_code == 404:
#             raise JobDoesNotExistError
# 
# Path: hoplite/plugin_manager.py
# class EntryPointManager(object):
#     """
#     Interface to the hoplite.jobs set of entry points
#     """
#     def __init__(self, group_name='hoplite.jobs'):
#         self.entry_point_group_name = group_name
# 
#     def get_plugin_names(self):
#         names = []
#         for entry_point in self._entry_points():
#             names.append(entry_point.name)
#         return names
# 
#     def get_plugin_module_by_name(self, name):
#         # TODO: Should we validate the module implements the correct methods
#         # before returning it to the caller?
#         for entry_point in self._entry_points():
#             if entry_point.name == name:
#                 return entry_point.load()
# 
#     def _entry_points(self):
#         # TODO: If it takes too long to reload pkg_resources, it might be worth
#         # looking into only loading if a package
#         # TODO: isn't found and then try again.
#         reload(pkg_resources)  # makes sure entry points are up-to-date
#         for entry_point in pkg_resources.iter_entry_points(group=self.entry_point_group_name):
#             logger.debug("Found entry point: {0}".format(entry_point.name))
#             yield entry_point


# Path: hoplite/server/jobs/job.py
from multiprocessing import Process
from multiprocessing import Pipe
from hoplite.utils import server_logging
from hoplite.exceptions import (
    JobAlreadyStartedError,
    JobNotStartedError,
    NotAuthorizedError)
from job_wrapper import job_wrapper
from hoplite.client.status_updater import StatusUpdater
from hoplite.plugin_manager import EntryPointManager

    def kill(self):
        """
        Kills the job if has been started. Raises a JobNotStartedError if it
        has not started yet. If the job has already finished, the job will
        still be flagged as killed, but it will not have any further
        consequences.
        """
        if self._process is None:
            raise JobNotStartedError(self.uuid)
        self._logger.debug(
            "Terminating Job:{0} UUID:{1}".format(self.name, self.uuid))
        self._process.terminate()
        self._pipe_to_process = None
        self._pipe_to_self = None
        self._killed = True

    def to_dict(self):
        """
        Returns a dictionary representation of the job.
        Used to serialize job data using JSON for sending over the network.
        """
        d = {}
        d["uuid"] = self.uuid
        d["name"] = self.name
        d["config"] = self.config
        d["status"] = self.status()
        d["running"] = self.running()
        d["killed"] = self.killed()
        try:
            d["finished"] = self.finished()

        except JobNotStartedError: