Beispiel #1
0
    def test_ffkExecutionEvents(self):
        workflow_name = construct_workflow_name_key('basicWorkflowTest', 'helloWorldWorkflow')
        c = controller.Controller(name="testStepFFKEventsController")
        c.loadWorkflowsFromFile(path=config.testWorkflowsPath + "basicWorkflowTest.workflow")

        filter_sub = Subscription(events=['FilterSuccess', 'FilterError'])
        flag_sub = Subscription(events=['FlagArgsValid', 'FlagArgsInvalid'], subscriptions={'length': filter_sub})
        next_sub = Subscription(events=['NextStepTaken', 'NextStepNotTaken'], subscriptions={'regMatch': flag_sub})
        step_sub = Subscription(events=["FunctionExecutionSuccess", "InputValidated", "ConditionalsExecuted"],
                                subscriptions={'1': next_sub})
        subs = {'testStepFFKEventsController':
                    Subscription(subscriptions=
                                 {workflow_name:
                                      Subscription(subscriptions=
                                                   {'start': step_sub})})}

        case_subscription.set_subscriptions(
            {'testStepFFKEventsEvents': case_subscription.CaseSubscriptions(subscriptions=subs)})

        c.executeWorkflow('basicWorkflowTest', 'helloWorldWorkflow')

        step_ffk_events_case = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'testStepFFKEventsEvents').first()
        step_ffk_event_history = step_ffk_events_case.events.all()
        self.assertEqual(len(step_ffk_event_history), 6,
                         'Incorrect length of event history. '
                         'Expected {0}, got {1}'.format(6, len(step_ffk_event_history)))
    def test_flag_filters_execution_events(self):
        self.c.load_playbook(resource=config.test_workflows_path +
                             'basicWorkflowTest.playbook')
        workflow = self.c.get_workflow('basicWorkflowTest',
                                       'helloWorldWorkflow')
        step = workflow.steps['start']
        subs = {
            step.uid: [
                'Function Execution Success', 'Step Started',
                'Conditionals Executed'
            ]
        }
        next_step = next(conditional for conditional in step.next_steps
                         if conditional.name == '1')
        subs[next_step.uid] = ['Next Step Taken', 'Next Step Not Taken']
        flag = next(flag for flag in next_step.flags
                    if flag.action == 'regMatch')
        subs[flag.uid] = ['Flag Success', 'Flag Error']
        filter_ = next(filter_elem for filter_elem in flag.filters
                       if filter_elem.action == 'length')
        subs[filter_.uid] = ['Filter Success', 'Filter Error']

        case_subscription.set_subscriptions({'case1': subs})

        self.c.execute_workflow('basicWorkflowTest', 'helloWorldWorkflow')

        self.c.shutdown_pool(1)

        events = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'case1').first().events.all()
        self.assertEqual(
            len(events), 6, 'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(6, len(events)))
    def test_workflow_execution_events(self):

        self.c.load_playbook(resource=config.test_workflows_path +
                             'multiactionWorkflowTest.playbook')
        workflow_uid = self.c.get_workflow('multiactionWorkflowTest',
                                           'multiactionWorkflow').uid
        subs = {
            'case1': {
                workflow_uid: [
                    'App Instance Created', 'Step Execution Success',
                    'Next Step Found', 'Workflow Shutdown'
                ]
            }
        }
        case_subscription.set_subscriptions(subs)
        self.c.execute_workflow('multiactionWorkflowTest',
                                'multiactionWorkflow')

        self.c.shutdown_pool(1)
        execution_events = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'case1').first().events.all()

        self.assertEqual(
            len(execution_events), 6, 'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(6, len(execution_events)))
    def test_ffkExecutionEventsCase(self):
        c = Controller(name="testStepFFKEventsController")
        c.load_workflows_from_file(path=config.test_workflows_path +
                                   "basicWorkflowTest.playbook")
        workflow_name = construct_workflow_name_key('basicWorkflowTest',
                                                    'helloWorldWorkflow')
        filter_sub = Subscription(events=['Filter Error'])
        flag_sub = Subscription(events=['Flag Success', 'Flag Error'],
                                subscriptions={'length': filter_sub})
        next_sub = Subscription(
            events=['Next Step Taken', 'Next Step Not Taken'],
            subscriptions={'regMatch': flag_sub})
        step_sub = Subscription(events=[
            'Function Execution Success', 'Input Validated',
            'Conditionals Executed'
        ],
                                subscriptions={'1': next_sub})
        subs = {
            'testStepFFKEventsController':
            Subscription(
                subscriptions={
                    workflow_name: Subscription(
                        subscriptions={'start': step_sub})
                })
        }
        global_subs = case_subscription.GlobalSubscriptions(
            step=[
                'Function Execution Success', 'Input Validated',
                'Conditionals Executed'
            ],
            next_step=['Next Step Taken', 'Next Step Not Taken'],
            flag=['Flag Success', 'Flag Error'],
            filter=['Filter Error'])
        case_subscription.set_subscriptions({
            'testStepFFKEventsEvents':
            case_subscription.CaseSubscriptions(
                subscriptions=subs, global_subscriptions=global_subs)
        })

        c.execute_workflow('basicWorkflowTest', 'helloWorldWorkflow')

        shutdown_pool()

        step_ffk_events_case = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'testStepFFKEventsEvents').first()
        step_ffk_event_history = step_ffk_events_case.events.all()
        self.assertEqual(
            len(step_ffk_event_history), 5,
            'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(5, len(step_ffk_event_history)))
        step_json = [
            step.as_json() for step in step_ffk_event_history
            if step.as_json()['message'] == 'STEP'
        ]
        for step in step_json:
            if step['type'] == 'Function executed successfully':
                self.assertDictEqual(step['data'],
                                     {'result': 'REPEATING: Hello World'})
            else:
                self.assertEqual(step['data'], '')
    def test_workflowExecutionEvents(self):
        c = controller.Controller(name="testExecutionEventsController")
        c.loadWorkflowsFromFile(path=config.testWorkflowsPath +
                                "multiactionWorkflowTest.workflow")

        subs = {
            'testExecutionEventsController':
            Subscription(
                subscriptions={
                    'multiactionWorkflow':
                    Subscription(events=[
                        "InstanceCreated", "StepExecutionSuccess",
                        "NextStepFound", "WorkflowShutdown"
                    ])
                })
        }

        case_subscription.set_subscriptions({
            'testExecutionEvents':
            case_subscription.CaseSubscriptions(subscriptions=subs)
        })

        c.executeWorkflow(name="multiactionWorkflow")

        execution_events_case = case_database.case_db.session.query(case_database.Cases) \
            .filter(case_database.Cases.name == 'testExecutionEvents').first()
        execution_event_history = execution_events_case.events.all()
        self.assertEqual(
            len(execution_event_history), 6,
            'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(6, len(execution_event_history)))
Beispiel #6
0
    def test_action_execution_events(self):
        self.c.load_playbook(resource=config.test_workflows_path +
                             'basicWorkflowTest.playbook')
        workflow = self.c.get_workflow('basicWorkflowTest',
                                       'helloWorldWorkflow')
        action_uids = [action.uid for action in workflow.actions.values()]
        action_events = [
            WalkoffEvent.ActionExecutionSuccess.signal_name,
            WalkoffEvent.ActionStarted.signal_name
        ]
        subs = {
            'case1': {action_uid: action_events
                      for action_uid in action_uids}
        }
        case_subscription.set_subscriptions(subs)

        self.c.execute_workflow('basicWorkflowTest', 'helloWorldWorkflow')

        self.c.wait_and_reset(1)

        execution_events = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'case1').first().events.all()
        self.assertEqual(
            len(execution_events), 2, 'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(2, len(execution_events)))
    def test_stepExecutionEvents(self):
        workflow_name = construct_workflow_name_key('basicWorkflowTest', 'helloWorldWorkflow')
        c = controller.Controller(name="testStepExecutionEventsController")
        c.load_workflows_from_file(path=config.test_workflows_path + "basicWorkflowTest.workflow")

        subs = {'testStepExecutionEventsController':
            Subscription(subscriptions=
            {workflow_name:
                Subscription(subscriptions=
                {'start':
                    Subscription(
                        events=["Function Execution Success", "Input Validated",
                                "Conditionals Executed"])})})}

        case_subscription.set_subscriptions(
            {'testStepExecutionEvents': case_subscription.CaseSubscriptions(subscriptions=subs)})

        c.execute_workflow('basicWorkflowTest', 'helloWorldWorkflow')

        running_context.shutdown_threads()

        step_execution_events_case = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'testStepExecutionEvents').first()
        step_execution_event_history = step_execution_events_case.events.all()
        self.assertEqual(len(step_execution_event_history), 3,
                         'Incorrect length of event history. '
                         'Expected {0}, got {1}'.format(3, len(step_execution_event_history)))
    def test_pauseResumeSchedulerExecution(self):
        c = controller.Controller(name="pauseResumeController")
        c.load_workflows_from_file(path=config.test_workflows_path + "testScheduler.workflow")

        subs = {'pauseResumeController': Subscription(events=[EVENT_SCHEDULER_START, EVENT_SCHEDULER_SHUTDOWN,
                                                              EVENT_SCHEDULER_PAUSED, EVENT_SCHEDULER_RESUMED,
                                                              EVENT_JOB_ADDED, EVENT_JOB_REMOVED,
                                                              EVENT_JOB_EXECUTED, EVENT_JOB_ERROR])}
        case_subscription.set_subscriptions({'startStop': case_subscription.CaseSubscriptions(subscriptions=subs)})
        case_subscription.set_subscriptions({'pauseResume': case_subscription.CaseSubscriptions(subscriptions=subs)})

        c.start()
        c.pause()
        time.sleep(1)
        c.resume()
        time.sleep(1)
        c.stop(wait=False)

        pause_resume_events_case = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'pauseResume').first()
        pause_resume_event_history = pause_resume_events_case.events.all()

        self.assertEqual(len(pause_resume_event_history), 4,
                        'Incorrect length of event history. '
                        'Expected {0}, got {1}'.format(4, len(pause_resume_event_history)))
    def test_workflowExecutionEvents(self):
        workflow_name = construct_workflow_name_key('multiactionWorkflowTest',
                                                    'multiactionWorkflow')
        c = Controller(name="testExecutionEventsController")
        c.load_workflows_from_file(path=config.test_workflows_path +
                                   "multiactionWorkflowTest.playbook")

        subs = {
            'testExecutionEventsController':
            Subscription(
                subscriptions={
                    workflow_name:
                    Subscription(events=[
                        "App Instance Created", "Step Execution Success",
                        "Next Step Found", "Workflow Shutdown"
                    ])
                })
        }

        case_subscription.set_subscriptions({
            'testExecutionEvents':
            case_subscription.CaseSubscriptions(subscriptions=subs)
        })

        c.execute_workflow('multiactionWorkflowTest', 'multiactionWorkflow')

        shutdown_pool()

        execution_events_case = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'testExecutionEvents').first()
        execution_event_history = execution_events_case.events.all()
        self.assertEqual(
            len(execution_event_history), 6,
            'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(6, len(execution_event_history)))
Beispiel #10
0
 def test_rename_case(self):
     cases = copy.deepcopy(self.cases1)
     subs.set_subscriptions(self.cases1)
     self.assertTrue(subs.rename_case('case1', 'renamed'))
     cases['renamed'] = cases.pop('case1')
     self.assertInMemoryCasesAreCorrect(cases)
     self.assertDatabaseCasesAreCorrect({'renamed', 'case2'})
Beispiel #11
0
 def test_sync_to_subscriptions(self):
     case1 = [{
         'uid': 'uid1',
         'events': ['e1', 'e2', 'e3']
     }, {
         'uid': 'uid2',
         'events': ['e1']
     }]
     case2 = [{'uid': 'uid1', 'events': ['e2', 'e3']}]
     case3 = [{
         'uid': 'uid3',
         'events': ['e', 'b', 'c']
     }, {
         'uid': 'uid4',
         'events': ['d']
     }]
     case4 = [{'uid': 'uid1', 'events': ['a', 'b']}]
     cases = {'case1': case1, 'case2': case2}
     set_subscriptions(cases)
     case_db_entry_1 = CaseSubscription('case3', subscriptions=case3)
     case_db_entry_2 = CaseSubscription('case4', subscriptions=case4)
     server.running_context.db.session.add(case_db_entry_1)
     server.running_context.db.session.add(case_db_entry_2)
     server.running_context.db.session.commit()
     CaseSubscription.sync_to_subscriptions()
     self.assertIn('case3', case_subs.subscriptions)
     self.assertIn('case4', case_subs.subscriptions)
     self.assertNotIn('case1', case_subs.subscriptions)
     self.assertNotIn('case2', case_subs.subscriptions)
     self.assertDictEqual(case_subs.subscriptions['case3'],
                          {sub['uid']: sub['events']
                           for sub in case3})
     self.assertDictEqual(case_subs.subscriptions['case4'],
                          {sub['uid']: sub['events']
                           for sub in case4})
Beispiel #12
0
 def test_delete_cases_some_existing(self):
     subs.set_subscriptions(self.cases1)
     subs.add_cases(self.cases2)
     subs.delete_cases(['case2', 'case3'])
     expected_cases = {
         'case1': self.cases1['case1'],
         'case4': self.cases2['case4']
     }
     self.assertInMemoryCasesAreCorrect(expected_cases)
     self.assertDatabaseCasesAreCorrect(set(expected_cases.keys()))
Beispiel #13
0
 def __basic_case_setup():
     case1, _ = construct_case1()
     case2, _ = construct_case2()
     case3, _ = construct_case1()
     case4, _ = construct_case2()
     cases = {
         'case1': case1,
         'case2': case2,
         'case3': case3,
         'case4': case4
     }
     set_subscriptions(cases)
     return cases
Beispiel #14
0
def setup_subscriptions_for_step(workflow_uids,
                                 step_uids,
                                 step_events=None,
                                 workflow_events=None):
    step_events = step_events if step_events is not None else [
        'Function Execution Success'
    ]
    workflow_events = workflow_events if workflow_events is not None else []
    subs = {workflow_uid: workflow_events for workflow_uid in workflow_uids} \
        if isinstance(workflow_uids, list) else {workflow_uids: workflow_events}
    for step_uid in step_uids:
        subs[step_uid] = step_events
    case_subscription.set_subscriptions({'case1': subs})
Beispiel #15
0
    def test_add_case_duplicate_case_in_sync(self):
        set_subscriptions({'case1': {}})
        self.app.put('api/cases',
                     headers=self.headers,
                     data=json.dumps({'name': 'case1'}),
                     content_type='application/json')
        self.put_with_status_check('api/cases',
                                   headers=self.headers,
                                   data=json.dumps({'name': 'case1'}),
                                   status_code=OBJECT_EXISTS_ERROR,
                                   content_type='application/json')

        cases = [
            case.name for case in case_database.case_db.session.query(
                case_database.Case).all()
        ]
Beispiel #16
0
    def test_start_stop_execution_loop(self):
        c = controller.Controller()
        c.load_playbook(resource=config.test_workflows_path + "testScheduler.playbook")
        subs = {'controller': [EVENT_SCHEDULER_START, EVENT_SCHEDULER_SHUTDOWN, EVENT_SCHEDULER_PAUSED,
                               EVENT_SCHEDULER_RESUMED, EVENT_JOB_ADDED, EVENT_JOB_REMOVED, EVENT_JOB_EXECUTED,
                               EVENT_JOB_ERROR]}
        case_subscription.set_subscriptions({'case1': subs})
        c.scheduler.start()
        time.sleep(0.1)
        c.scheduler.stop(wait=False)

        start_stop_event_history = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'case1').first().events.all()
        self.assertEqual(len(start_stop_event_history), 2,
                         'Incorrect length of event history. '
                         'Expected {0}, got {1}'.format(2, len(start_stop_event_history)))
Beispiel #17
0
def execute_workflow_worker(workflow, subs, start=None):
    """Executes the workflow in a multi-threaded fashion.
    
    Args:
        workflow (Workflow): The workflow to be executed.
        start (str, otpional): Name of the first step to be executed in the workflow.
        subs (Subscription): The current subscriptions. This is necessary for resetting the subscriptions.
        
    Returns:
        "Done" when the workflow has finished execution.
    """
    subscription.set_subscriptions(subs)
    if start is not None:
        workflow.execute(start=start)
    else:
        workflow.execute()
    return "done"
Beispiel #18
0
    def test_startStopExecutionLoop(self):
        c = controller.Controller(name="startStopController")
        c.loadWorkflowsFromFile(path=config.testWorkflowsPath + "testScheduler.workflow")
        subs = {'startStopController': Subscription(events=[EVENT_SCHEDULER_START, EVENT_SCHEDULER_SHUTDOWN,
                                                            EVENT_SCHEDULER_PAUSED, EVENT_SCHEDULER_RESUMED,
                                                            EVENT_JOB_ADDED, EVENT_JOB_REMOVED,
                                                            EVENT_JOB_EXECUTED, EVENT_JOB_ERROR])}
        case_subscription.set_subscriptions({'startStop': case_subscription.CaseSubscriptions(subscriptions=subs)})
        c.start()
        time.sleep(1)
        c.stop(wait=False)

        start_stop_event_history = case_database.case_db.session.query(case_database.Cases) \
            .filter(case_database.Cases.name == 'startStop').first().events.all()
        self.assertEqual(len(start_stop_event_history), 2,
                         'Incorrect length of event history. '
                         'Expected {0}, got {1}'.format(2, len(start_stop_event_history)))
Beispiel #19
0
def setup_subscriptions_for_step(workflow_names, step_names, step_events=None, workflow_events=None):
    step_events = step_events if step_events is not None else ['Function Execution Success']
    workflow_events = workflow_events if workflow_events is not None else []
    step_sub = case_subscription.Subscription(events=step_events)
    if isinstance(step_names, list):
        step_subs = case_subscription.Subscription(subscriptions={name: step_sub for name in step_names},
                                                   events=workflow_events)
    else:
        step_subs = case_subscription.Subscription(subscriptions={step_names: step_sub},
                                                   events=workflow_events)
    if isinstance(workflow_names, list):
        workflow_subs = case_subscription.Subscription(subscriptions={workflow_name: step_subs
                                                                      for workflow_name in workflow_names})
    else:
        workflow_subs = case_subscription.Subscription(subscriptions={workflow_names: step_subs})
    subs = {'defaultController': workflow_subs}
    case_subscription.set_subscriptions({'case1': case_subscription.CaseSubscriptions(subscriptions=subs)})
Beispiel #20
0
    def test_condition_transform_execution_events(self):
        self.c.load_playbook(resource=config.test_workflows_path +
                             'basicWorkflowTest.playbook')
        workflow = self.c.get_workflow('basicWorkflowTest',
                                       'helloWorldWorkflow')
        action = workflow.actions['c5a7c29a0f844b69a59901bb542e9305']
        subs = {
            action.uid: [
                WalkoffEvent.ActionExecutionSuccess.signal_name,
                WalkoffEvent.ActionStarted.signal_name
            ]
        }
        branches = [
            branch for sublist in workflow.branches.values()
            for branch in sublist
        ]
        branch = branches[0]
        subs[branch.uid] = [
            WalkoffEvent.BranchTaken.signal_name,
            WalkoffEvent.BranchNotTaken.signal_name
        ]
        condition = next(condition for condition in branch.conditions
                         if condition.action_name == 'regMatch')
        subs[condition.uid] = [
            WalkoffEvent.ConditionSuccess.signal_name,
            WalkoffEvent.ConditionError.signal_name
        ]
        transform = next(transform for transform in condition.transforms
                         if transform.action_name == 'length')
        subs[transform.uid] = [
            WalkoffEvent.TransformSuccess.signal_name,
            WalkoffEvent.TransformError.signal_name
        ]

        case_subscription.set_subscriptions({'case1': subs})

        self.c.execute_workflow('basicWorkflowTest', 'helloWorldWorkflow')

        self.c.wait_and_reset(1)

        events = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'case1').first().events.all()
        self.assertEqual(
            len(events), 5, 'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(5, len(events)))
Beispiel #21
0
 def test_add_case_existing_cases(self):
     set_subscriptions(self.cases1)
     response = self.put_with_status_check('api/cases',
                                           headers=self.headers,
                                           data=json.dumps(
                                               {'name': 'case3'}),
                                           status_code=OBJECT_CREATED,
                                           content_type='application/json')
     self.assertEqual(response, {
         'id': 1,
         'name': 'case3',
         'note': '',
         'subscriptions': []
     })
     cases = [
         case.name for case in case_database.case_db.session.query(
             case_database.Case).all()
     ]
Beispiel #22
0
    def test_delete_case_invalid_case(self):
        set_subscriptions(self.cases1)
        self.app.put('api/cases',
                     headers=self.headers,
                     data=json.dumps({'name': 'case1'}),
                     content_type='application/json')
        self.app.put('api/cases',
                     headers=self.headers,
                     data=json.dumps({'name': 'case2'}),
                     content_type='application/json')
        self.delete_with_status_check('api/cases/3',
                                      error='Case does not exist.',
                                      headers=self.headers,
                                      status_code=OBJECT_DNE_ERROR)

        db_cases = [
            case.name for case in case_database.case_db.session.query(
                case_database.Case).all()
        ]
 def test_sync_to_subscriptions(self):
     case1, _ = construct_case1()
     case2, _ = construct_case2()
     case3, _ = construct_case2()
     case4, _ = construct_case1()
     cases = {'case1': case1, 'case2': case2}
     set_subscriptions(cases)
     case_db_entry_1 = CaseSubscription('case3', subscription=json.dumps(case3.as_json()))
     case_db_entry_2 = CaseSubscription('case4', subscription=json.dumps(case4.as_json()))
     server.running_context.db.session.add(case_db_entry_1)
     server.running_context.db.session.add(case_db_entry_2)
     server.running_context.db.session.commit()
     CaseSubscription.sync_to_subscriptions()
     result_subscriptions = subscriptions_as_json()
     self.assertIn('case3', result_subscriptions)
     self.assertIn('case4', result_subscriptions)
     self.assertNotIn('case1', result_subscriptions)
     self.assertNotIn('case2', result_subscriptions)
     self.assertDictEqual(result_subscriptions['case3'], case3.as_json())
     self.assertDictEqual(result_subscriptions['case4'], case4.as_json())
Beispiel #24
0
    def test_add_case_duplicate_case_out_of_sync(self):
        set_subscriptions({'case1': {}})
        expected_json = {
            'id': 1,
            'name': 'case1',
            'note': '',
            'subscriptions': []
        }
        response = self.put_with_status_check('api/cases',
                                              headers=self.headers,
                                              data=json.dumps(
                                                  {'name': 'case1'}),
                                              status_code=OBJECT_CREATED,
                                              content_type='application/json')
        self.assertEqual(response, expected_json)

        cases = [
            case.name for case in case_database.case_db.session.query(
                case_database.Case).all()
        ]
Beispiel #25
0
def setup_subscriptions_for_step(workflow_names, step_names):
    step_sub = case_subscription.Subscription(
        events=['FunctionExecutionSuccess'])
    if type(step_names) == list:
        step_subs = case_subscription.Subscription(
            subscriptions={name: step_sub
                           for name in step_names})
    else:
        step_subs = case_subscription.Subscription(
            subscriptions={step_names: step_sub})
    if type(workflow_names) == list:
        workflow_subs = case_subscription.Subscription(subscriptions={
            workflow_name: step_subs
            for workflow_name in workflow_names
        })
    else:
        workflow_subs = case_subscription.Subscription(
            subscriptions={workflow_names: step_subs})

    subs = {'defaultController': workflow_subs}
    case_subscription.set_subscriptions(
        {'case1': case_subscription.CaseSubscriptions(subscriptions=subs)})
    def test_step_execution_events(self):
        self.c.load_playbook(resource=config.test_workflows_path +
                             'basicWorkflowTest.playbook')
        workflow = self.c.get_workflow('basicWorkflowTest',
                                       'helloWorldWorkflow')
        step_uids = [step.uid for step in workflow.steps.values()]
        step_events = [
            'Function Execution Success', 'Step Started',
            'Conditionals Executed'
        ]
        subs = {'case1': {step_uid: step_events for step_uid in step_uids}}
        case_subscription.set_subscriptions(subs)

        self.c.execute_workflow('basicWorkflowTest', 'helloWorldWorkflow')

        self.c.shutdown_pool(1)

        execution_events = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'case1').first().events.all()
        self.assertEqual(
            len(execution_events), 3, 'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(3, len(execution_events)))
Beispiel #27
0
def execute_workflow_worker(workflow, subs, uid, start=None, start_input=None):
    """Executes the workflow in a multi-threaded fashion.
    
    Args:
        workflow (Workflow): The workflow to be executed.
        uid (str): The unique identifier of the workflow
        start (str, optional): Name of the first step to be executed in the workflow.
        subs (Subscription): The current subscriptions. This is necessary for resetting the subscriptions.
        start_input (dict, optional): The input to the starting step of the workflow
        
    Returns:
        "Done" when the workflow has finished execution.
    """
    args = {'start': start, 'start_input': start_input}
    subscription.set_subscriptions(subs)
    workflow.uid = uid
    try:
        workflow.execute(**args)
    except Exception as e:
        logger.error('Caught error while executing workflow {0}. {1}'.format(workflow.name,
                                                                             format_exception_message(e)))
    return "done"
Beispiel #28
0
    def test_workflow_execution_events(self):
        self.c.load_playbook(resource=config.test_workflows_path +
                             'multiactionWorkflowTest.playbook')
        workflow_uid = self.c.get_workflow('multiactionWorkflowTest',
                                           'multiactionWorkflow').uid
        subs = {
            'case1': {
                workflow_uid: [
                    WalkoffEvent.AppInstanceCreated.signal_name,
                    WalkoffEvent.WorkflowShutdown.signal_name
                ]
            }
        }
        case_subscription.set_subscriptions(subs)
        self.c.execute_workflow('multiactionWorkflowTest',
                                'multiactionWorkflow')

        self.c.wait_and_reset(1)
        execution_events = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'case1').first().events.all()

        self.assertEqual(
            len(execution_events), 2, 'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(2, len(execution_events)))
Beispiel #29
0
    def test_ffkExecutionEventsCase(self):
        c = controller.Controller(name="testStepFFKEventsController")
        c.loadWorkflowsFromFile(path=config.testWorkflowsPath +
                                "basicWorkflowTest.workflow")
        filter_sub = Subscription(disabled=['FilterSuccess'])
        flag_sub = Subscription(subscriptions={'length': filter_sub})
        next_sub = Subscription(subscriptions={'regMatch': flag_sub})
        step_sub = Subscription(subscriptions={'1': next_sub})
        subs = {
            'testStepFFKEventsController':
            Subscription(
                subscriptions={
                    'helloWorldWorkflow':
                    Subscription(subscriptions={'start': step_sub})
                })
        }
        global_subs = case_subscription.GlobalSubscriptions(
            step='*',
            next_step=['NextStepTaken', 'NextStepNotTaken'],
            flag=['FlagArgsValid', 'FlagArgsInvalid'],
            filter=['FilterSuccess', 'FilterError'])
        case_subscription.set_subscriptions({
            'testStepFFKEventsEvents':
            case_subscription.CaseSubscriptions(
                subscriptions=subs, global_subscriptions=global_subs)
        })

        c.executeWorkflow(name="helloWorldWorkflow")

        step_ffk_events_case = case_database.case_db.session.query(case_database.Cases) \
            .filter(case_database.Cases.name == 'testStepFFKEventsEvents').first()
        step_ffk_event_history = step_ffk_events_case.events.all()
        self.assertEqual(
            len(step_ffk_event_history), 5,
            'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(5, len(step_ffk_event_history)))
Beispiel #30
0
    def test_stepExecutionEvents(self):
        c = controller.Controller(name="testStepExecutionEventsController")
        c.loadWorkflowsFromFile(path=config.testWorkflowsPath +
                                "basicWorkflowTest.workflow")

        subs = {
            'testStepExecutionEventsController':
            Subscription(
                subscriptions={
                    'helloWorldWorkflow':
                    Subscription(
                        subscriptions={
                            'start':
                            Subscription(events=[
                                "FunctionExecutionSuccess", "InputValidated",
                                "ConditionalsExecuted"
                            ])
                        })
                })
        }

        case_subscription.set_subscriptions({
            'testStepExecutionEvents':
            case_subscription.CaseSubscriptions(subscriptions=subs)
        })

        c.executeWorkflow(name="helloWorldWorkflow")

        step_execution_events_case = case_database.case_db.session.query(case_database.Cases) \
            .filter(case_database.Cases.name == 'testStepExecutionEvents').first()
        step_execution_event_history = step_execution_events_case.events.all()
        self.assertEqual(
            len(step_execution_event_history), 3,
            'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(3,
                                           len(step_execution_event_history)))