def __init__(self, config): """Initializes a new Context object. This acts as an interface for objects to access other event specific variables that might be needed. Args: config (Config): A config object """ self.execution_db = walkoff.executiondb.ExecutionDatabase( config.EXECUTION_DB_TYPE, config.EXECUTION_DB_PATH) self.case_db = walkoff.case.database.CaseDatabase( config.CASE_DB_TYPE, config.CASE_DB_PATH) self.subscription_cache = SubscriptionCache() self.case_logger = CaseLogger(self.case_db, self.subscription_cache) self.cache = walkoff.cache.make_cache(config.CACHE) self.executor = executor.MultiprocessedExecutor( self.cache, self.case_logger) self.scheduler = walkoff.scheduler.Scheduler(self.case_logger)
def __init__(self, id_, config_path): """Initialize a Workfer object, which will be managing the execution of Workflows Args: id_ (str): The ID of the worker config_path (str): The path to the configuration file to be loaded """ logger.info('Spawning worker {}'.format(id_)) self.id_ = id_ self._lock = Lock() signal.signal(signal.SIGINT, self.exit_handler) signal.signal(signal.SIGABRT, self.exit_handler) if os.name == 'nt': walkoff.config.initialize(config_path=config_path) else: walkoff.config.Config.load_config(config_path) self.execution_db = ExecutionDatabase( walkoff.config.Config.EXECUTION_DB_TYPE, walkoff.config.Config.EXECUTION_DB_PATH) self.case_db = CaseDatabase(walkoff.config.Config.CASE_DB_TYPE, walkoff.config.Config.CASE_DB_PATH) @WalkoffEvent.CommonWorkflowSignal.connect def handle_data_sent(sender, **kwargs): self.on_data_sent(sender, **kwargs) self.handle_data_sent = handle_data_sent self.thread_exit = False server_secret_file = os.path.join( walkoff.config.Config.ZMQ_PRIVATE_KEYS_PATH, "server.key_secret") server_public, server_secret = auth.load_certificate( server_secret_file) client_secret_file = os.path.join( walkoff.config.Config.ZMQ_PRIVATE_KEYS_PATH, "client.key_secret") client_public, client_secret = auth.load_certificate( client_secret_file) socket_id = u"Worker-{}".format(id_).encode("ascii") key = PrivateKey( client_secret[:nacl.bindings.crypto_box_SECRETKEYBYTES]) server_key = PrivateKey( server_secret[:nacl.bindings.crypto_box_SECRETKEYBYTES]).public_key self.cache = walkoff.cache.make_cache(walkoff.config.Config.CACHE) self.capacity = walkoff.config.Config.NUMBER_THREADS_PER_PROCESS self.subscription_cache = SubscriptionCache() case_logger = CaseLogger(self.case_db, self.subscription_cache) self.workflow_receiver = WorkflowReceiver(key, server_key, walkoff.config.Config.CACHE) self.workflow_results_sender = WorkflowResultsHandler( socket_id, client_secret, client_public, server_public, walkoff.config.Config.ZMQ_RESULTS_ADDRESS, self.execution_db, case_logger) self.workflow_communication_receiver = WorkflowCommunicationReceiver( socket_id, client_secret, client_public, server_public, walkoff.config.Config.ZMQ_COMMUNICATION_ADDRESS) self.comm_thread = threading.Thread(target=self.receive_communications) self.comm_thread.start() self.workflows = {} self.threadpool = ThreadPoolExecutor(max_workers=self.capacity) self.receive_workflows()
def get_case_logger(subscriptions): repo = create_autospec(CaseDatabase) return CaseLogger(repo, subscriptions=subscriptions)