# Path: chaosmonkey/engine/cme_manager.py
# class CMEManager:
#     def __init__(self):
#     def configure(self, scheduler, sql_store, planners_store, attacks_store):
#     def scheduler(self):
#     def attacks_store(self):
#     def planners_store(self):
#     def sql_store(self):
#     def get_executors(self, executed=False):
#     def get_executor(self, executor_id):
#     def get_executors_for_plan(self, plan_id):
#     def update_executor_trigger(self, executor_id, trigger):
#     def remove_executor(self, executor_id):
#     def add_executor(self, date, name, attack_config, plan_id):
#     def get_attack_list(self):
#     def get_planner_list(self):
#     def execute_plan(self, name, planner_config, attack_config):
#     def add_plan(self, name):
#     def get_plan(self, plan_id):
#     def get_plans(self, show_all=None):
#     def delete_plan(self, plan_id):
#     def _job_to_executor(job):
# 
# Path: chaosmonkey/dal/executor_model.py
# class Executor(db.Model):
#     """
#     Executors are persistent representations of scheduled jobs.
#     This model is shared between the cme and apscheduler.
#     """
# 
#     __tablename__ = 'cme_executors'
# 
#     id = db.Column(db.String(80), primary_key=True)  #: unique identifier
#     next_run_time = db.Column(db.DateTime, index=True)  #: DateTime for the executor to be executed
#     job_state = db.Column(db.LargeBinary, nullable=False)  #: store the full state of the executor (with pickle)
#     plan_id = db.Column(db.Integer, db.ForeignKey('cme_plans.id'))  #: plan id reference
#     executed = db.Column(db.Boolean)  #: if the job was executed
# 
#     def __init__(self, job_id, next_run_time, plan_id, job_state=None):
#         self.id = job_id
#         self.next_run_time = next_run_time
#         self.job_state = job_state
#         self.plan_id = plan_id
#         self.executed = False
# 
#     def to_dict(self):
#         """
#         Return a :meth:`chaosmonkey.api.hal.document` representation for the Executor
# 
#         :return: :meth:`chaosmonkey.dal.executor_model.HalExecutor`
#         """
# 
#         return HalExecutor(data={
#             "id": self.id,
#             "next_run_time": self.next_run_time.strftime('%Y-%m-%dT%H:%M:%s'),
#             "plan_id": self.plan_id,
#             "executed": self.executed
#         }).to_dict()
# 
#     def __repr__(self):
#         return '<Executor %r>' % self.id
# 
# Path: chaosmonkey/dal/plan_model.py
# class Plan(db.Model):
#     """
#     Store information about the plan and its executors.
# 
#     This model is only used by the cme.
#     """
#     __tablename__ = 'cme_plans'
# 
#     id = db.Column(db.String(80), primary_key=True)  #: unique identifier
#     name = db.Column(db.String(200), unique=False)  #: plan name
#     created = db.Column(db.DateTime, unique=True)  #: creation datetime
#     executed = db.Column(db.Boolean)  #: if all the executors in the plan has been executed
# 
#     next_execution = None  #: DateTime for the next executor execution time
#     executors_count = None  #: number of pending executors
# 
#     jobs = relationship(Executor, cascade='all, delete, delete-orphan')
# 
#     # pylint: disable=too-many-arguments
#     def __init__(self, _id=None, name=None, created=None, next_execution=None, executors_count=0, executed=False):
#         self.id = _id or uuid4().hex
#         self.name = name
#         if created:
#             self.created = datetime.strptime(created, '%Y-%m-%d %H:%M:%S.%f')
#         else:
#             self.created = datetime.utcnow()
#         self.executed = executed
#         self.next_execution = next_execution
#         self.executors_count = executors_count
# 
#     def to_dict(self):
#         """
#         Returns a :meth:`chaosmonkey.api.hal.document` representation for the Executor
# 
#         :return: :meth:`chaosmonkey.dal.plan_model.HalPlan`
#         """
# 
#         return HalPlan(data={
#             'id': self.id,
#             'name': self.name,
#             'created': self.created.strftime('%Y-%m-%dT%H:%M:%s'),
#             'executors_count': self.executors_count,
#             'next_execution': self.next_execution,
#             'executed': self.executed
#         }).to_dict()
# 
#     def __repr__(self):
#         return '<Plan %r>' % self.name
# 
# Path: chaosmonkey/dal/database.py



import logging
    import cPickle as pickle
    import pickle
from apscheduler.job import Job
from apscheduler.jobstores.base import BaseJobStore, JobLookupError
from sqlalchemy import text
from chaosmonkey.engine.cme_manager import manager
from chaosmonkey.dal.executor_model import Executor
from chaosmonkey.dal.plan_model import Plan
from chaosmonkey.dal.database import db
                name=row[1],
                created=row[2],
                executors_count=row[3],
                next_execution=row[4],
                executed=row[5]
            )
            plans.append(plan)

        return plans

    def get_plan(self, plan_id):
        """
        Return a plan by its id

        :param plan_id: string
        :return: Plan
        """
        self.log.debug('get plan %s', plan_id)
        plan = Plan.query.get(plan_id)
        return plan

    def delete_plan(self, plan_id):
        """
        Delete a plan.

        All the executors related to the plan are deleted. (ON_DELETE constrain in db.Models)

        :param plan_id: string
        """
        self.log.debug('delete plan %s', plan_id)

# Path: chaosmonkey/engine/cme_manager.py
# class CMEManager:
#     def __init__(self):
#     def configure(self, scheduler, sql_store, planners_store, attacks_store):
#     def scheduler(self):
#     def attacks_store(self):
#     def planners_store(self):
#     def sql_store(self):
#     def get_executors(self, executed=False):
#     def get_executor(self, executor_id):
#     def get_executors_for_plan(self, plan_id):
#     def update_executor_trigger(self, executor_id, trigger):
#     def remove_executor(self, executor_id):
#     def add_executor(self, date, name, attack_config, plan_id):
#     def get_attack_list(self):
#     def get_planner_list(self):
#     def execute_plan(self, name, planner_config, attack_config):
#     def add_plan(self, name):
#     def get_plan(self, plan_id):
#     def get_plans(self, show_all=None):
#     def delete_plan(self, plan_id):
#     def _job_to_executor(job):
# 
# Path: chaosmonkey/dal/executor_model.py
# class Executor(db.Model):
#     """
#     Executors are persistent representations of scheduled jobs.
#     This model is shared between the cme and apscheduler.
#     """
# 
#     __tablename__ = 'cme_executors'
# 
#     id = db.Column(db.String(80), primary_key=True)  #: unique identifier
#     next_run_time = db.Column(db.DateTime, index=True)  #: DateTime for the executor to be executed
#     job_state = db.Column(db.LargeBinary, nullable=False)  #: store the full state of the executor (with pickle)
#     plan_id = db.Column(db.Integer, db.ForeignKey('cme_plans.id'))  #: plan id reference
#     executed = db.Column(db.Boolean)  #: if the job was executed
# 
#     def __init__(self, job_id, next_run_time, plan_id, job_state=None):
#         self.id = job_id
#         self.next_run_time = next_run_time
#         self.job_state = job_state
#         self.plan_id = plan_id
#         self.executed = False
# 
#     def to_dict(self):
#         """
#         Return a :meth:`chaosmonkey.api.hal.document` representation for the Executor
# 
#         :return: :meth:`chaosmonkey.dal.executor_model.HalExecutor`
#         """
# 
#         return HalExecutor(data={
#             "id": self.id,
#             "next_run_time": self.next_run_time.strftime('%Y-%m-%dT%H:%M:%s'),
#             "plan_id": self.plan_id,
#             "executed": self.executed
#         }).to_dict()
# 
#     def __repr__(self):
#         return '<Executor %r>' % self.id
# 
# Path: chaosmonkey/dal/plan_model.py
# class Plan(db.Model):
#     """
#     Store information about the plan and its executors.
# 
#     This model is only used by the cme.
#     """
#     __tablename__ = 'cme_plans'
# 
#     id = db.Column(db.String(80), primary_key=True)  #: unique identifier
#     name = db.Column(db.String(200), unique=False)  #: plan name
#     created = db.Column(db.DateTime, unique=True)  #: creation datetime
#     executed = db.Column(db.Boolean)  #: if all the executors in the plan has been executed
# 
#     next_execution = None  #: DateTime for the next executor execution time
#     executors_count = None  #: number of pending executors
# 
#     jobs = relationship(Executor, cascade='all, delete, delete-orphan')
# 
#     # pylint: disable=too-many-arguments
#     def __init__(self, _id=None, name=None, created=None, next_execution=None, executors_count=0, executed=False):
#         self.id = _id or uuid4().hex
#         self.name = name
#         if created:
#             self.created = datetime.strptime(created, '%Y-%m-%d %H:%M:%S.%f')
#         else:
#             self.created = datetime.utcnow()
#         self.executed = executed
#         self.next_execution = next_execution
#         self.executors_count = executors_count
# 
#     def to_dict(self):
#         """
#         Returns a :meth:`chaosmonkey.api.hal.document` representation for the Executor
# 
#         :return: :meth:`chaosmonkey.dal.plan_model.HalPlan`
#         """
# 
#         return HalPlan(data={
#             'id': self.id,
#             'name': self.name,
#             'created': self.created.strftime('%Y-%m-%dT%H:%M:%s'),
#             'executors_count': self.executors_count,
#             'next_execution': self.next_execution,
#             'executed': self.executed
#         }).to_dict()
# 
#     def __repr__(self):
#         return '<Plan %r>' % self.name
# 
# Path: chaosmonkey/dal/database.py



# Path: chaosmonkey/dal/cme_sqlalchemy_store.py
import logging
    import cPickle as pickle
    import pickle
from apscheduler.job import Job
from apscheduler.jobstores.base import BaseJobStore, JobLookupError
from sqlalchemy import text
from chaosmonkey.engine.cme_manager import manager
from chaosmonkey.dal.executor_model import Executor
from chaosmonkey.dal.plan_model import Plan
from chaosmonkey.dal.database import db

                name=row[1],
                created=row[2],
                executors_count=row[3],
                next_execution=row[4],
                executed=row[5]
            )
            plans.append(plan)

        return plans

    def get_plan(self, plan_id):
        """
        Return a plan by its id

        :param plan_id: string
        :return: Plan
        """
        self.log.debug('get plan %s', plan_id)
        plan = Plan.query.get(plan_id)
        return plan

    def delete_plan(self, plan_id):
        """
        Delete a plan.

        All the executors related to the plan are deleted. (ON_DELETE constrain in db.Models)

        :param plan_id: string
        """
        self.log.debug('delete plan %s', plan_id)

        plan = Plan.query.get(plan_id)