chaosmonkey.dal package

Submodules

chaosmonkey.dal.cme_sqlalchemy_store module

CMESQLAlchemyStore replaces the default SQLAlchemyJobstore from apscheduler

It controls the persistence layer.

class chaosmonkey.dal.cme_sqlalchemy_store.CMESQLAlchemyStore(pickle_protocol=4)[source]

Bases: apscheduler.jobstores.base.BaseJobStore

Manage persistence for apscheduler and CMEEngine.

This class is used by the apscheduler, all overridden methods should return appscheduler.job.Job objects.

The store handles 2 types of models: plans and executors. Internally apscheduler names the executors as jobs.

TODO: executors are marked as executed when they are processed
(no mather if they fail or succeed. We need to handle execution errors in order to know whats going on with the execution and what was its result.)
add_job(job)[source]
add_plan(name)[source]

Create a plan in the db.

Parameters:name – string
Returns:Plan created
delete_plan(plan_id)[source]

Delete a plan.

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

Parameters:plan_id – string
get_all_jobs()[source]
get_due_jobs(now)[source]
get_executor(executor_id)[source]

Get an executor

Parameters:executor_id – string
Returns:List of Executor
get_executors(executed=False)[source]

Get a list of executors

Returns:List of Executor
get_executors_for_plan(plan_id)[source]

Get a list of executors related to a plan by its plan_id

Parameters:plan_id – string
Returns:List of Executor
get_next_run_time()[source]
get_plan(plan_id)[source]

Return a plan by its id

Parameters:plan_id – string
Returns:Plan
get_plans(show_all=False)[source]

Return a list of plans created on db. For each plan return the number of pending executors and the next_run_time of the first executor

Returns:List of Plans
lookup_job(job_id)[source]
real_remove_job(job_id)[source]
remove_all_jobs()[source]
remove_job(job_id)[source]

Instead of deleting a job when its executed or it has failed, check it as executed.

TODO: delete the executor and save to a historic table the executed attacks with its logs and results.

shutdown()[source]
start(scheduler, alias)[source]

Start the SQLAlchemy engine

update_job(job)[source]
exception chaosmonkey.dal.cme_sqlalchemy_store.PlanLookupError(job_id)[source]

Bases: KeyError

Raised when the store cannot find a plan for update or removal.

chaosmonkey.dal.database module

SQLAlchemy database

chaosmonkey.dal.executor_model module

class chaosmonkey.dal.executor_model.Executor(job_id, next_run_time, plan_id, job_state=None)[source]

Bases: flask_sqlalchemy.Model

Executors are persistent representations of scheduled jobs. This model is shared between the cme and apscheduler.

executed

if the job was executed

id

unique identifier

job_state

store the full state of the executor (with pickle)

next_run_time

DateTime for the executor to be executed

plan_id

plan id reference

to_dict()[source]

Return a chaosmonkey.api.hal.document() representation for the Executor

Returns:chaosmonkey.dal.executor_model.HalExecutor()
class chaosmonkey.dal.executor_model.HalExecutor(data=None, links=None, embedded=None)[source]

Bases: chaosmonkey.api.hal.BaseDocument

Class to represent an Executor as a chaosmonkey.api.hal.document()

chaosmonkey.dal.plan_model module

class chaosmonkey.dal.plan_model.HalPlan(data=None, links=None, embedded=None)[source]

Bases: chaosmonkey.api.hal.BaseDocument

Class to represent a Plan as a chaosmonkey.api.hal.document()

class chaosmonkey.dal.plan_model.Plan(_id=None, name=None, created=None, next_execution=None, executors_count=0, executed=False)[source]

Bases: flask_sqlalchemy.Model

Store information about the plan and its executors.

This model is only used by the cme.

created

creation datetime

executed

if all the executors in the plan has been executed

executors_count = None

number of pending executors

id

unique identifier

jobs
name

plan name

next_execution = None

DateTime for the next executor execution time

to_dict()[source]

Returns a chaosmonkey.api.hal.document() representation for the Executor

Returns:chaosmonkey.dal.plan_model.HalPlan()

Module contents

Data Access Layer package.

Modules related to data access