Exemplo n.º 1
0
    def _start_workflow(self, triggers, payload, metadata):
        """Start workflows defined in event triggers."""
        for t in triggers:
            LOG.info('Start to process event trigger: %s', t['id'])

            workflow_params = t.get('workflow_params', {})
            workflow_params.update(
                {'event_payload': payload, 'event_metadata': metadata}
            )

            # Setup context before schedule triggers.
            ctx = security.create_context(t['trust_id'], t['project_id'])
            auth_ctx.set_ctx(ctx)

            try:
                self.engine_client.start_workflow(
                    t['workflow_id'],
                    t['workflow_input'],
                    description="Workflow execution created by event "
                                "trigger %s." % t['id'],
                    **workflow_params
                )
            except Exception as e:
                LOG.exception("Failed to process event trigger %s, "
                              "error: %s", t['id'], str(e))
            finally:
                auth_ctx.set_ctx(None)
Exemplo n.º 2
0
    def process_cron_triggers_v2(self, ctx):
        for t in triggers.get_next_cron_triggers():
            LOG.debug("Processing cron trigger: %s" % t)

            # Setup admin context before schedule triggers.
            ctx = security.create_context(t.trust_id, t.project_id)

            auth_ctx.set_ctx(ctx)

            LOG.debug("Cron trigger security context: %s" % ctx)

            try:
                rpc.get_engine_client().start_workflow(
                    t.workflow.name,
                    t.workflow_input,
                    description="Workflow execution created by cron trigger.",
                    **t.workflow_params
                )
            finally:
                if t.remaining_executions is not None and t.remaining_executions > 0:
                    t.remaining_executions -= 1
                if t.remaining_executions == 0:
                    db_api_v2.delete_cron_trigger(t.name)
                else:  # if remaining execution = None or > 0
                    next_time = triggers.get_next_execution_time(t.pattern, t.next_execution_time)

                    db_api_v2.update_cron_trigger(
                        t.name, {"next_execution_time": next_time, "remaining_executions": t.remaining_executions}
                    )

                    auth_ctx.set_ctx(None)
Exemplo n.º 3
0
    def process_cron_triggers_v2(self, ctx):
        for t in triggers.get_next_cron_triggers():
            LOG.debug("Processing cron trigger: %s" % t)

            # Setup admin context before schedule triggers.
            ctx = security.create_context(t.trust_id, t.project_id)

            auth_ctx.set_ctx(ctx)

            LOG.debug("Cron trigger security context: %s" % ctx)

            try:
                # Try to advance the cron trigger next_execution_time and
                # remaining_executions if relevant.
                modified = advance_cron_trigger(t)

                # If cron trigger was not already modified by another engine.
                if modified:
                    LOG.debug(
                        "Starting workflow '%s' by cron trigger '%s'",
                        t.workflow.name, t.name
                    )

                    rpc.get_engine_client().start_workflow(
                        t.workflow.name,
                        t.workflow_input,
                        description="Workflow execution created "
                                    "by cron trigger.",
                        **t.workflow_params
                    )
            except Exception:
                # Log and continue to next cron trigger.
                LOG.exception("Failed to process cron trigger %s" % str(t))
            finally:
                auth_ctx.set_ctx(None)
Exemplo n.º 4
0
    def process_cron_triggers_v2(self, ctx):
        for t in triggers.get_next_cron_triggers():
            LOG.debug("Processing cron trigger: %s" % t)
            # Setup admin context before schedule triggers.
            ctx = security.create_context(t.trust_id, t.project_id)
            auth_ctx.set_ctx(ctx)

            LOG.debug("Cron trigger security context: %s" % ctx)

            try:
                rpc.get_engine_client().start_workflow(
                    t.workflow.name,
                    t.workflow_input,
                    description="workflow execution by cron trigger.",
                    **t.workflow_params
                )
            finally:
                if t.remaining_executions > 0:
                    t.remaining_executions -= 1
                if t.remaining_executions == 0:
                    db_api_v2.delete_cron_trigger(t.name)
                else:  # if remaining execution = None or > 0
                    next_time = triggers.get_next_execution_time(
                        t.pattern,
                        t.next_execution_time
                    )

                    db_api_v2.update_cron_trigger(
                        t.name,
                        {'next_execution_time': next_time,
                         'remaining_executions': t.remaining_executions}
                    )

                    auth_ctx.set_ctx(None)
Exemplo n.º 5
0
    def _start_workflow(self, triggers, event_params):
        """Start workflows defined in event triggers."""
        for t in triggers:
            LOG.info('Start to process event trigger: %s', t['id'])

            workflow_params = t.get('workflow_params', {})
            workflow_params.update({'event_params': event_params})

            # Setup context before schedule triggers.
            ctx = security.create_context(t['trust_id'], t['project_id'])
            auth_ctx.set_ctx(ctx)

            try:
                self.engine_client.start_workflow(
                    t['workflow_id'],
                    t['workflow_input'],
                    description="Workflow execution created by event "
                                "trigger %s." % t['id'],
                    **workflow_params
                )
            except Exception as e:
                LOG.exception("Failed to process event trigger %s, "
                              "error: %s", t['id'], str(e))
            finally:
                auth_ctx.set_ctx(None)
Exemplo n.º 6
0
    def _dtw_schedule_immediately(self, ctx):

        for d in dtw.get_unscheduled_delay_tolerant_workload():
            LOG.debug("Processing delay tolerant workload: %s" % d)

            # Setup admin context before schedule triggers.
            ctx = security.create_context(d.trust_id, d.project_id)

            auth_ctx.set_ctx(ctx)

            LOG.debug("Delay tolerant workload security context: %s" % ctx)

            try:
                # execute the workload

                db_api_v2.update_delay_tolerant_workload(
                    d.name,
                    {'executed': True}
                )

                rpc.get_engine_client().start_workflow(
                    d.workflow.name,
                    d.workflow_input,
                    description="DTW Workflow execution created.",
                    **d.workflow_params
                )
            except Exception:
                # Log and continue to next cron trigger.
                LOG.exception(
                    "Failed to process delay tolerant workload %s" % str(d))
            finally:
                auth_ctx.set_ctx(None)
Exemplo n.º 7
0
    def _dtw_last_minute_scheduling(self, ctx):

        for d in dtw.get_unscheduled_delay_tolerant_workload():
            LOG.debug("Processing delay tolerant workload: %s" % d)

            # Setup admin context before schedule triggers.
            ctx = security.create_context(d.trust_id, d.project_id)

            auth_ctx.set_ctx(ctx)

            LOG.debug("Delay tolerant workload security context: %s" % ctx)

            # calculate last time for running this - deadline less the
            # duration of the work
            # TODO(murp): check the status of the security context on this
            # TODO(murp): convert job_duration to timedelta
            start_time = d.deadline - datetime.timedelta(seconds=d.job_duration)
            
            triggers.create_cron_trigger(d.name, d.workflow_name, 
                                         d.workflow_input,
                                         workflow_params=d.workflow_params, 
                                         count=1, 
                                         first_time=start_time,
                                         start_time=start_time, 
                                         workflow_id=d.workflow_id)
Exemplo n.º 8
0
    def _start_workflow(self, triggers, event_params):
        """Start workflows defined in event triggers."""
        for t in triggers:
            LOG.info('Start to process event trigger: %s', t['id'])

            workflow_params = t.get('workflow_params', {})
            workflow_params.update({'event_params': event_params})

            # Setup context before schedule triggers.
            ctx = security.create_context(t['trust_id'], t['project_id'])
            auth_ctx.set_ctx(ctx)

            description = {
                "description": ("Workflow execution created by event"
                                " trigger '(%s)'." % t['id']),
                "triggered_by": {
                    "type": "event_trigger",
                    "id": t['id'],
                    "name": t['name']
                }
            }

            try:
                self.engine_client.start_workflow(
                    t['workflow_id'],
                    t['workflow_namespace'],
                    t['workflow_input'],
                    description=json.dumps(description),
                    **workflow_params)
            except Exception as e:
                LOG.exception(
                    "Failed to process event trigger %s, "
                    "error: %s", t['id'], str(e))
            finally:
                auth_ctx.set_ctx(None)
Exemplo n.º 9
0
def process_cron_triggers_v2(self, ctx):
    LOG.debug("Processing cron triggers...")

    for trigger in triggers.get_next_cron_triggers():
        LOG.debug("Processing cron trigger: %s", trigger)

        try:
            # Setup admin context before schedule triggers.
            ctx = security.create_context(
                trigger.trust_id,
                trigger.project_id
            )

            auth_ctx.set_ctx(ctx)

            LOG.debug("Cron trigger security context: %s", ctx)

            # Try to advance the cron trigger next_execution_time and
            # remaining_executions if relevant.
            modified = advance_cron_trigger(trigger)

            # If cron trigger was not already modified by another engine.
            if modified:
                LOG.debug(
                    "Starting workflow '%s' by cron trigger '%s'",
                    trigger.workflow.name,
                    trigger.name
                )

                description = {
                    "description": (
                        "Workflow execution created by cron"
                        " trigger '(%s)'." % trigger.id
                    ),
                    "triggered_by": {
                        "type": "cron_trigger",
                        "id": trigger.id,
                        "name": trigger.name,
                    }
                }

                rpc.get_engine_client().start_workflow(
                    trigger.workflow.name,
                    trigger.workflow.namespace,
                    None,
                    trigger.workflow_input,
                    description=json.dumps(description),
                    **trigger.workflow_params
                )
        except Exception:
            # Log and continue to next cron trigger.
            LOG.exception(
                "Failed to process cron trigger %s",
                str(trigger)
            )
        finally:
            auth_ctx.set_ctx(None)
Exemplo n.º 10
0
    def process_cron_triggers_v2(self, ctx):
        LOG.debug("Processing cron triggers...")

        for trigger in triggers.get_next_cron_triggers():
            LOG.debug("Processing cron trigger: %s", trigger)

            try:
                # Setup admin context before schedule triggers.
                ctx = security.create_context(trigger.trust_id,
                                              trigger.project_id)

                auth_ctx.set_ctx(ctx)

                LOG.debug("Cron trigger security context: %s", ctx)

                # Try to advance the cron trigger next_execution_time and
                # remaining_executions if relevant.
                modified = advance_cron_trigger(trigger)

                # If cron trigger was not already modified by another engine.
                if modified:
                    LOG.debug("Starting workflow '%s' by cron trigger '%s'",
                              trigger.workflow.name, trigger.name)

                    description = {
                        "description": ("Workflow execution created by cron"
                                        " trigger '(%s)'." % trigger.id),
                        "triggered_by": {
                            "type": "cron_trigger",
                            "id": trigger.id,
                            "name": trigger.name,
                        }
                    }

                    rpc.get_engine_client().start_workflow(
                        trigger.workflow.name,
                        trigger.workflow.namespace,
                        trigger.workflow_input,
                        description=json.dumps(description),
                        **trigger.workflow_params)
            except Exception:
                # Log and continue to next cron trigger.
                LOG.exception("Failed to process cron trigger %s",
                              str(trigger))
            finally:
                auth_ctx.set_ctx(None)
Exemplo n.º 11
0
    def _start_workflow(self, triggers, event_params):
        """Start workflows defined in event triggers."""
        for t in triggers:
            LOG.info('Start to process event trigger: %s', t['id'])

            workflow_params = t.get('workflow_params', {})
            workflow_params.update({'event_params': event_params})

            # Setup context before schedule triggers.
            ctx = security.create_context(t['trust_id'], t['project_id'])
            auth_ctx.set_ctx(ctx)

            description = {
                "description": (
                    "Workflow execution created by event"
                    " trigger '(%s)'." % t['id']
                ),
                "triggered_by": {
                    "type": "event_trigger",
                    "id": t['id'],
                    "name": t['name']
                }
            }

            try:
                self.engine_client.start_workflow(
                    t['workflow_id'],
                    t['workflow_namespace'],
                    None,
                    t['workflow_input'],
                    description=json.dumps(description),
                    **workflow_params
                )
            except Exception as e:
                LOG.exception("Failed to process event trigger %s, "
                              "error: %s", t['id'], str(e))
            finally:
                auth_ctx.set_ctx(None)