Exemplo n.º 1
0
    def from_cloudevent(self, event):
        e_type = event["type"]
        e_source = event["source"]
        status = _FM_TYPE_EVENT_TO_STATUS.get(e_type)
        timestamp = event["time"]

        if e_type in ids.EVGROUP_FM_STAGE:
            self.update_stage(
                get_real_id(e_source),
                get_stage_id(e_source),
                status=status,
                start_time=timestamp
                if e_type == ids.EVTYPE_FM_STAGE_RUNNING else None,
                end_time=timestamp if e_type in {
                    ids.EVTYPE_FM_STAGE_FAILURE, ids.EVTYPE_FM_STAGE_SUCCESS
                } else None,
            )
        elif e_type in ids.EVGROUP_FM_STEP:
            self.update_step(
                get_real_id(e_source),
                get_stage_id(e_source),
                get_step_id(e_source),
                status=status,
                start_time=timestamp
                if e_type == ids.EVTYPE_FM_STEP_START else None,
                end_time=timestamp if e_type in {
                    ids.EVTYPE_FM_STEP_SUCCESS,
                    ids.EVTYPE_FM_STEP_FAILURE,
                } else None,
            )

        elif e_type in ids.EVGROUP_FM_JOB:
            self.update_job(
                get_real_id(e_source),
                get_stage_id(e_source),
                get_step_id(e_source),
                get_job_id(e_source),
                status=status,
                start_time=timestamp
                if e_type == ids.EVTYPE_FM_JOB_START else None,
                end_time=timestamp if e_type in {
                    ids.EVTYPE_FM_JOB_SUCCESS,
                    ids.EVTYPE_FM_JOB_FAILURE,
                } else None,
                data=event.data
                if e_type == ids.EVTYPE_FM_JOB_RUNNING else None,
                error=event.data.get("stderr")
                if e_type == ids.EVTYPE_FM_JOB_FAILURE else None,
            )
        elif e_type in ids.EVGROUP_ENSEMBLE:
            self.update_status(_ENSEMBLE_TYPE_EVENT_TO_STATUS[e_type])
        else:
            raise ValueError("Unknown type: {}".format(e_type))
        return self
Exemplo n.º 2
0
    def from_cloudevent(cls, event):
        snapshot = cls()
        e_type = event["type"]
        e_source = event["source"]
        timestamp = event["time"]

        if e_type in ids.EVGROUP_FM_STAGE:
            queue_state = event.data.get("queue_event_type")
            snapshot.update_stage(
                get_real_id(e_source),
                get_stage_id(e_source),
                status=_FM_TYPE_EVENT_TO_STATUS[e_type],
                start_time=timestamp
                if e_type == ids.EVTYPE_FM_STAGE_RUNNING else None,
                end_time=timestamp if e_type in {
                    ids.EVTYPE_FM_STAGE_FAILURE, ids.EVTYPE_FM_STAGE_SUCCESS
                } else None,
                queue_state=queue_state,
            )
        elif e_type in ids.EVGROUP_FM_STEP:
            snapshot.update_step(
                get_real_id(e_source),
                get_stage_id(e_source),
                get_step_id(e_source),
                status=_FM_TYPE_EVENT_TO_STATUS[e_type],
                start_time=timestamp
                if e_type == ids.EVTYPE_FM_STEP_START else None,
                end_time=timestamp if e_type in {
                    ids.EVTYPE_FM_STEP_SUCCESS,
                    ids.EVTYPE_FM_STEP_FAILURE,
                } else None,
            )
        elif e_type in ids.EVGROUP_FM_JOB:
            snapshot.update_job(
                get_real_id(e_source),
                get_stage_id(e_source),
                get_step_id(e_source),
                get_job_id(e_source),
                status=_FM_TYPE_EVENT_TO_STATUS[e_type],
                start_time=timestamp
                if e_type == ids.EVTYPE_FM_JOB_START else None,
                end_time=timestamp if e_type in {
                    ids.EVTYPE_FM_JOB_SUCCESS,
                    ids.EVTYPE_FM_JOB_FAILURE,
                } else None,
                data=event.data
                if e_type == ids.EVTYPE_FM_JOB_RUNNING else None,
            )
        elif e_type in ids.EVGROUP_ENSEMBLE:
            snapshot.update_status(_ENSEMBLE_TYPE_EVENT_TO_STATUS[e_type])
        else:
            raise ValueError("Unknown type: {}".format(e_type))
        return snapshot
Exemplo n.º 3
0
    def from_cloudevent(self, event):
        e_type = event["type"]
        e_source = event["source"]
        status = _FM_TYPE_EVENT_TO_STATUS.get(e_type)
        timestamp = event["time"]

        if e_type in ids.EVGROUP_FM_STEP:
            start_time = None
            end_time = None
            if e_type == ids.EVTYPE_FM_STEP_RUNNING:
                start_time = convert_iso8601_to_datetime(timestamp)
            elif e_type in {ids.EVTYPE_FM_STEP_SUCCESS, ids.EVTYPE_FM_STEP_FAILURE}:
                end_time = convert_iso8601_to_datetime(timestamp)

            self.update_step(
                get_real_id(e_source),
                get_step_id(e_source),
                step=Step(
                    status=status,
                    start_time=start_time,
                    end_time=end_time,
                ),
            )
            if e_type == ids.EVTYPE_FM_STEP_RUNNING and event.data:
                for job_id, job in event.data.get(ids.JOBS, {}).items():
                    self.update_job(
                        get_real_id(e_source),
                        get_step_id(e_source),
                        job_id,
                        # XXX: can we remove this?
                        job=Job(
                            stdout=job[ids.STDOUT],
                            stderr=job[ids.STDERR],
                        ),
                    )

        elif e_type in ids.EVGROUP_FM_JOB:
            start_time = None
            end_time = None
            if e_type == ids.EVTYPE_FM_JOB_START:
                start_time = convert_iso8601_to_datetime(timestamp)
            elif e_type in {ids.EVTYPE_FM_JOB_SUCCESS, ids.EVTYPE_FM_JOB_FAILURE}:
                end_time = convert_iso8601_to_datetime(timestamp)

            self.update_job(
                get_real_id(e_source),
                get_step_id(e_source),
                get_job_id(e_source),
                job=Job(
                    status=status,
                    start_time=start_time,
                    end_time=end_time,
                    data=event.data if e_type == ids.EVTYPE_FM_JOB_RUNNING else None,
                    error=event.data.get(ids.ERROR_MSG)
                    if e_type == ids.EVTYPE_FM_JOB_FAILURE
                    else None,
                ),
            )
        elif e_type in ids.EVGROUP_ENSEMBLE:
            self.update_status(_ENSEMBLE_TYPE_EVENT_TO_STATUS[e_type])
        elif e_type == ids.EVTYPE_EE_SNAPSHOT_UPDATE:
            self._data = recursive_update(self._data, event.data, check_key=False)
        else:
            raise ValueError("Unknown type: {}".format(e_type))
        return self
Exemplo n.º 4
0
def test_source_get_ids(source_string, expected_ids):

    assert tool.get_real_id(source_string) == expected_ids["real"]
    assert tool.get_step_id(source_string) == expected_ids["step"]
    assert tool.get_job_id(source_string) == expected_ids["job"]
Exemplo n.º 5
0
    def from_cloudevent(self, event):
        e_type = event["type"]
        e_source = event["source"]
        status = _FM_TYPE_EVENT_TO_STATUS.get(e_type)
        timestamp = event["time"]

        if e_type in ids.EVGROUP_FM_STEP:
            start_time = None
            end_time = None
            if e_type == ids.EVTYPE_FM_STEP_RUNNING:
                start_time = convert_iso8601_to_datetime(timestamp)
            elif e_type in {
                    ids.EVTYPE_FM_STEP_SUCCESS,
                    ids.EVTYPE_FM_STEP_FAILURE,
                    ids.EVTYPE_FM_STEP_TIMEOUT,
            }:
                end_time = convert_iso8601_to_datetime(timestamp)

            self.update_step(
                get_real_id(e_source),
                get_step_id(e_source),
                step=Step(
                    status=status,
                    start_time=start_time,
                    end_time=end_time,
                ),
            )

            if e_type == ids.EVTYPE_FM_STEP_TIMEOUT:
                step = self._snapshot.get_step(get_real_id(e_source),
                                               get_step_id(e_source))
                for job_id, job in step.jobs.items():
                    if job.status != state.JOB_STATE_FINISHED:
                        job_error = "The run is cancelled due to reaching MAX_RUNTIME"
                        self.update_job(
                            get_real_id(e_source),
                            get_step_id(e_source),
                            job_id,
                            job=Job(status=state.JOB_STATE_FAILURE,
                                    error=job_error),
                        )

        elif e_type in ids.EVGROUP_FM_JOB:
            start_time = None
            end_time = None
            if e_type == ids.EVTYPE_FM_JOB_START:
                start_time = convert_iso8601_to_datetime(timestamp)
            elif e_type in {
                    ids.EVTYPE_FM_JOB_SUCCESS, ids.EVTYPE_FM_JOB_FAILURE
            }:
                end_time = convert_iso8601_to_datetime(timestamp)

            self.update_job(
                get_real_id(e_source),
                get_step_id(e_source),
                get_job_id(e_source),
                job=Job(
                    status=status,
                    start_time=start_time,
                    end_time=end_time,
                    data=event.data
                    if e_type == ids.EVTYPE_FM_JOB_RUNNING else None,
                    stdout=event.data.get(ids.STDOUT)
                    if e_type == ids.EVTYPE_FM_JOB_START else None,
                    stderr=event.data.get(ids.STDERR)
                    if e_type == ids.EVTYPE_FM_JOB_START else None,
                    error=event.data.get(ids.ERROR_MSG)
                    if e_type == ids.EVTYPE_FM_JOB_FAILURE else None,
                ),
            )
        elif e_type in ids.EVGROUP_ENSEMBLE:
            self.update_status(_ENSEMBLE_TYPE_EVENT_TO_STATUS[e_type])
        elif e_type == ids.EVTYPE_EE_SNAPSHOT_UPDATE:
            self._data = recursive_update(self._data,
                                          event.data,
                                          check_key=False)
        else:
            raise ValueError("Unknown type: {}".format(e_type))
        return self