# Path: freezer_api/api/common/resource.py
# class BaseResource(object):
#     def json_body(req):
# 
# Path: freezer_api/common/exceptions.py
# class FreezerAPIException(falcon.HTTPError):
# class BadDataFormat(FreezerAPIException):
# class DocumentExists(FreezerAPIException):
# class StorageEngineError(FreezerAPIException):
# class DocumentNotFound(FreezerAPIException):
# class AccessForbidden(FreezerAPIException):
# class MethodNotImplemented(FreezerAPIException):
#     def __init__(self, message=''):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
# 
# Path: freezer_api/policy.py
# DEFAULT_POLICY_FILE = 'policy.yaml'
# ENFORCER = None
#         ENFORCER = policy.Enforcer(conf)
# def setup_policy(conf):
# def enforce(rule):
#     def decorator(func):
#         def handler(*args, **kwargs):


import time
import falcon
from freezer_api.api.common import resource
from freezer_api.common import exceptions as freezer_api_exc
from freezer_api import policy
    def get_job_overall_result(self):
        """
        check the status of all the jobs and return the overall session result
        """
        for job in self.doc['jobs'].values():
            if job['status'] != 'completed':
                return 'running'
            if job['result'] != 'success':
                return 'fail'
        return 'success'

    def set_job_end(self, job_id, result, timestamp):
        try:
            job = self.doc['jobs'][job_id]
        except Exception:
            raise freezer_api_exc.BadDataFormat('job_id not found in session')
        job['status'] = 'completed'
        job['result'] = result
        job['time_ended'] = timestamp

    def set_job_start(self, job_id, timestamp):
        try:
            job = self.doc['jobs'][job_id]
        except Exception:
            raise freezer_api_exc.BadDataFormat('job_id not found in session')
        job['status'] = 'running'
        job['result'] = ''
        job['time_started'] = timestamp



# Path: freezer_api/api/common/resource.py
# class BaseResource(object):
#     def json_body(req):
# 
# Path: freezer_api/common/exceptions.py
# class FreezerAPIException(falcon.HTTPError):
# class BadDataFormat(FreezerAPIException):
# class DocumentExists(FreezerAPIException):
# class StorageEngineError(FreezerAPIException):
# class DocumentNotFound(FreezerAPIException):
# class AccessForbidden(FreezerAPIException):
# class MethodNotImplemented(FreezerAPIException):
#     def __init__(self, message=''):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
#     def handle(ex, req, resp, params):
# 
# Path: freezer_api/policy.py
# DEFAULT_POLICY_FILE = 'policy.yaml'
# ENFORCER = None
#         ENFORCER = policy.Enforcer(conf)
# def setup_policy(conf):
# def enforce(rule):
#     def decorator(func):
#         def handler(*args, **kwargs):


# Path: freezer_api/api/v1/sessions.py
import time
import falcon
from freezer_api.api.common import resource
from freezer_api.common import exceptions as freezer_api_exc
from freezer_api import policy

    def get_job_overall_result(self):
        """
        check the status of all the jobs and return the overall session result
        """
        for job in self.doc['jobs'].values():
            if job['status'] != 'completed':
                return 'running'
            if job['result'] != 'success':
                return 'fail'
        return 'success'

    def set_job_end(self, job_id, result, timestamp):
        try:
            job = self.doc['jobs'][job_id]
        except Exception:
            raise freezer_api_exc.BadDataFormat('job_id not found in session')
        job['status'] = 'completed'
        job['result'] = result
        job['time_ended'] = timestamp

    def set_job_start(self, job_id, timestamp):
        try:
            job = self.doc['jobs'][job_id]
        except Exception:
            raise freezer_api_exc.BadDataFormat('job_id not found in session')
        job['status'] = 'running'
        job['result'] = ''
        job['time_started'] = timestamp



class SessionsJob(resource.BaseResource):