Search in sources :

Example 1 with QueueTaskMessage

use of org.jenkinsci.plugins.pubsub.QueueTaskMessage in project blueocean-plugin by jenkinsci.

the class JobIndexingMessageEnricher method enrich.

@Override
public void enrich(@Nonnull Message message) {
    if (message instanceof JobChannelMessage) {
        JobChannelMessage jobChannelMessage = (JobChannelMessage) message;
        Item jobChannelItem = jobChannelMessage.getJobChannelItem();
        Enum indexingStatus;
        Enum indexingResult;
        if (jobChannelItem instanceof OrganizationFolder) {
            indexingStatus = JobIndexing.EventProps.job_orgfolder_indexing_status;
            indexingResult = JobIndexing.EventProps.job_orgfolder_indexing_result;
        } else if (jobChannelItem instanceof MultiBranchProject) {
            jobChannelMessage.set(EventProps.Job.job_ismultibranch, "true");
            indexingStatus = EventProps.Job.job_multibranch_indexing_status;
            indexingResult = EventProps.Job.job_multibranch_indexing_result;
        } else {
            // don't enrich if not org folder or multibranch
            return;
        }
        if (message instanceof QueueTaskMessage) {
            QueueTaskMessage queueTaskMessage = (QueueTaskMessage) message;
            Queue.Item queueItem = queueTaskMessage.getQueueItem();
            if (queueItem instanceof Queue.LeftItem) {
                Queue.LeftItem leftItem = (Queue.LeftItem) queueItem;
                if (leftItem.isCancelled()) {
                    jobChannelMessage.set(indexingStatus, "COMPLETE");
                    jobChannelMessage.set(indexingResult, "CANCELLED");
                } else {
                    if (message.getEventName().equals(Events.JobChannel.job_run_queue_task_complete.name())) {
                        jobChannelMessage.set(indexingStatus, "COMPLETE");
                        Queue.Executable executable = ((Queue.LeftItem) queueItem).getExecutable();
                        if (executable instanceof BranchIndexing) {
                            BranchIndexing branchIndexing = (BranchIndexing) executable;
                            Result result = branchIndexing.getResult();
                            if (result != null) {
                                jobChannelMessage.set(indexingResult, result.toString());
                            }
                        } else if (executable instanceof OrganizationFolder.OrganizationScan) {
                            OrganizationFolder.OrganizationScan orgScan = (OrganizationFolder.OrganizationScan) executable;
                            Result result = orgScan.getResult();
                            if (result != null) {
                                jobChannelMessage.set(indexingResult, result.toString());
                            }
                        }
                    } else {
                        jobChannelMessage.set(indexingStatus, "INDEXING");
                    }
                }
            } else {
                jobChannelMessage.set(indexingStatus, "INDEXING");
            }
        }
    }
}
Also used : JobChannelMessage(org.jenkinsci.plugins.pubsub.JobChannelMessage) OrganizationFolder(jenkins.branch.OrganizationFolder) BranchIndexing(jenkins.branch.MultiBranchProject.BranchIndexing) Result(hudson.model.Result) Item(hudson.model.Item) QueueTaskMessage(org.jenkinsci.plugins.pubsub.QueueTaskMessage) MultiBranchProject(jenkins.branch.MultiBranchProject) Queue(hudson.model.Queue)

Aggregations

Item (hudson.model.Item)1 Queue (hudson.model.Queue)1 Result (hudson.model.Result)1 MultiBranchProject (jenkins.branch.MultiBranchProject)1 BranchIndexing (jenkins.branch.MultiBranchProject.BranchIndexing)1 OrganizationFolder (jenkins.branch.OrganizationFolder)1 JobChannelMessage (org.jenkinsci.plugins.pubsub.JobChannelMessage)1 QueueTaskMessage (org.jenkinsci.plugins.pubsub.QueueTaskMessage)1