Ejemplo n.º 1
0
    def transition(self, state, state_reason):
        """
        Sets the state and state_reason of this ArtifactBuild.

        :param state: ArtifactBuildState value
        :param state_reason: Reason why this state has been set.
        :return: True/False, whether state was changed
        """
        # Convert state from its possible representation to number.
        state = self.validate_state("state", state)

        # Log the state and state_reason
        if state == ArtifactBuildState.FAILED.value:
            log_fnc = log.error
        else:
            log_fnc = log.info
        log_fnc("Artifact build %r moved to state %s, %r" %
                (self, ArtifactBuildState(state).name, state_reason))

        if self.state == state:
            return False

        self.state = state
        if ArtifactBuildState(state).counter:
            ArtifactBuildState(state).counter.inc()

        self.state_reason = state_reason
        if self.state in [
                ArtifactBuildState.DONE.value, ArtifactBuildState.FAILED.value,
                ArtifactBuildState.CANCELED.value
        ]:
            self.time_completed = datetime.utcnow()

        # For FAILED/CANCELED states, move also all the artifacts depending
        # on this one to FAILED/CANCELED state, because there is no way we
        # can rebuild them.
        if self.state in [
                ArtifactBuildState.FAILED.value,
                ArtifactBuildState.CANCELED.value
        ]:
            for build in self.depending_artifact_builds():
                build.transition(
                    self.state, "Cannot build artifact, because its "
                    "dependency cannot be built.")

        messaging.publish('build.state.changed', self.json())

        return True
Ejemplo n.º 2
0
    def json(self):
        build_args = {}
        if self.build_args:
            build_args = json.loads(self.build_args)

        build_url = get_url_for('build', id=self.id)
        db.session.add(self)
        return {
            "id": self.id,
            "name": self.name,
            "original_nvr": self.original_nvr,
            "rebuilt_nvr": self.rebuilt_nvr,
            "type": self.type,
            "type_name": ArtifactType(self.type).name,
            "state": self.state,
            "state_name": ArtifactBuildState(self.state).name,
            "state_reason": self.state_reason,
            "dep_on": self.dep_on.name if self.dep_on else None,
            "dep_on_id": self.dep_on.id if self.dep_on else None,
            "time_submitted": _utc_datetime_to_iso(self.time_submitted),
            "time_completed": _utc_datetime_to_iso(self.time_completed),
            "event_id": self.event_id,
            "build_id": self.build_id,
            "url": build_url,
            "build_args": build_args,
            "odcs_composes":
            [rel.compose.odcs_compose_id for rel in self.composes],
            "rebuild_reason": RebuildReason(self.rebuild_reason
                                            or 0).name.lower()
        }
Ejemplo n.º 3
0
    def json_min(self):
        builds_summary = defaultdict(int)
        builds_summary['total'] = len(self.builds.all())
        for build in self.builds:
            state_name = ArtifactBuildState(build.state).name
            builds_summary[state_name] += 1

        data = self._common_json()
        data['builds_summary'] = dict(builds_summary)
        return data
Ejemplo n.º 4
0
 def __repr__(self):
     return "<ArtifactBuild %s, type %s, state %s, event %s>" % (
         self.name, ArtifactType(self.type).name,
         ArtifactBuildState(self.state).name, self.event.message_id)