Search in sources :

Example 1 with RestartDeclarativePipelineAction

use of org.jenkinsci.plugins.pipeline.modeldefinition.actions.RestartDeclarativePipelineAction in project blueocean-plugin by jenkinsci.

the class PipelineNodeImpl method restart.

public HttpResponse restart(StaplerRequest request) {
    try {
        JSONObject body = JSONObject.fromObject(IOUtils.toString(request.getReader()));
        boolean restart = body.getBoolean("restart");
        if (restart && isRestartable()) {
            LOGGER.debug("submitInputStep, restart: {}, step: {}", restart, this.getDisplayName());
            RestartDeclarativePipelineAction restartDeclarativePipelineAction = this.run.getAction(RestartDeclarativePipelineAction.class);
            Queue.Item item = restartDeclarativePipelineAction.run(this.getDisplayName());
            BluePipeline bluePipeline = BluePipelineFactory.getPipelineInstance(this.run.getParent(), this.parent);
            BlueQueueItem queueItem = QueueUtil.getQueuedItem(bluePipeline.getOrganization(), item, run.getParent());
            if (queueItem != null) {
                // If the item is still queued
                return (req, rsp, node1) -> {
                    rsp.setStatus(HttpServletResponse.SC_OK);
                    rsp.getOutputStream().print(Export.toJson(queueItem.toRun()));
                };
            }
            final WorkflowRun restartRun = getRun(run.getParent(), item.getId());
            if (restartRun != null) {
                return (req, rsp, node1) -> {
                    rsp.setStatus(HttpServletResponse.SC_OK);
                    rsp.getOutputStream().print(Export.toJson(new PipelineRunImpl(restartRun, parent, bluePipeline.getOrganization())));
                };
            } else {
                // For some reason could not be added to the queue
                throw new ServiceException.UnexpectedErrorException("Run was not added to queue.");
            }
        }
    // ISE cant happen if stage not restartable or anything else :)
    } catch (Exception e) {
        LOGGER.warn("error restarting stage: " + e.getMessage(), e);
        throw new ServiceException.UnexpectedErrorException(e.getMessage());
    }
    return null;
}
Also used : ActionProxiesImpl(io.jenkins.blueocean.service.embedded.rest.ActionProxiesImpl) Date(java.util.Date) RestartDeclarativePipelineAction(org.jenkinsci.plugins.pipeline.modeldefinition.actions.RestartDeclarativePipelineAction) StaplerRequest(org.kohsuke.stapler.StaplerRequest) LoggerFactory(org.slf4j.LoggerFactory) Exported(org.kohsuke.stapler.export.Exported) Export(io.jenkins.blueocean.commons.stapler.Export) HashSet(java.util.HashSet) Queue(hudson.model.Queue) BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) AbstractRunImpl(io.jenkins.blueocean.service.embedded.rest.AbstractRunImpl) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) LogAction(org.jenkinsci.plugins.workflow.actions.LogAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Action(hudson.model.Action) Logger(org.slf4j.Logger) HttpResponse(org.kohsuke.stapler.HttpResponse) Collection(java.util.Collection) Reachable(io.jenkins.blueocean.rest.Reachable) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) HttpServletResponse(javax.servlet.http.HttpServletResponse) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) ServiceException(io.jenkins.blueocean.commons.ServiceException) QueueUtil(io.jenkins.blueocean.service.embedded.rest.QueueUtil) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) NodeDownstreamBuildAction(io.jenkins.blueocean.listeners.NodeDownstreamBuildAction) JSONObject(net.sf.json.JSONObject) BlueActionProxy(io.jenkins.blueocean.rest.model.BlueActionProxy) BlueInputStep(io.jenkins.blueocean.rest.model.BlueInputStep) BluePipelineStepContainer(io.jenkins.blueocean.rest.model.BluePipelineStepContainer) BluePipelineFactory(io.jenkins.blueocean.rest.factory.BluePipelineFactory) CheckForNull(javax.annotation.CheckForNull) Collections(java.util.Collections) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) ServiceException(io.jenkins.blueocean.commons.ServiceException) RestartDeclarativePipelineAction(org.jenkinsci.plugins.pipeline.modeldefinition.actions.RestartDeclarativePipelineAction) JSONObject(net.sf.json.JSONObject) ServiceException(io.jenkins.blueocean.commons.ServiceException) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) Queue(hudson.model.Queue) BlueQueueItem(io.jenkins.blueocean.rest.model.BlueQueueItem)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Action (hudson.model.Action)1 Queue (hudson.model.Queue)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 Export (io.jenkins.blueocean.commons.stapler.Export)1 NodeDownstreamBuildAction (io.jenkins.blueocean.listeners.NodeDownstreamBuildAction)1 Reachable (io.jenkins.blueocean.rest.Reachable)1 BluePipelineFactory (io.jenkins.blueocean.rest.factory.BluePipelineFactory)1 Link (io.jenkins.blueocean.rest.hal.Link)1 BlueActionProxy (io.jenkins.blueocean.rest.model.BlueActionProxy)1 BlueInputStep (io.jenkins.blueocean.rest.model.BlueInputStep)1 BluePipeline (io.jenkins.blueocean.rest.model.BluePipeline)1 BluePipelineNode (io.jenkins.blueocean.rest.model.BluePipelineNode)1 BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)1 BluePipelineStepContainer (io.jenkins.blueocean.rest.model.BluePipelineStepContainer)1 BlueQueueItem (io.jenkins.blueocean.rest.model.BlueQueueItem)1 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)1 AbstractRunImpl (io.jenkins.blueocean.service.embedded.rest.AbstractRunImpl)1 ActionProxiesImpl (io.jenkins.blueocean.service.embedded.rest.ActionProxiesImpl)1 QueueUtil (io.jenkins.blueocean.service.embedded.rest.QueueUtil)1