Search in sources :

Example 1 with InputStepExecution

use of org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution in project blueocean-plugin by jenkinsci.

the class PipelineStepVisitor method atomNode.

@Override
public void atomNode(@CheckForNull FlowNode before, @Nonnull FlowNode atomNode, @CheckForNull FlowNode after, @Nonnull ForkScanner scan) {
    if (stageStepsCollectionCompleted && !PipelineNodeUtil.isSyntheticStage(currentStage)) {
        return;
    }
    if (atomNode instanceof StepEndNode) {
        this.closestEndNode = (StepEndNode) atomNode;
    }
    if (atomNode instanceof StepAtomNode && !PipelineNodeUtil.isSkippedStage(currentStage)) {
        //if skipped stage, we don't collect its steps
        long pause = PauseAction.getPauseDuration(atomNode);
        chunk.setPauseTimeMillis(chunk.getPauseTimeMillis() + pause);
        TimingInfo times = StatusAndTiming.computeChunkTiming(run, pause, atomNode, atomNode, after);
        if (times == null) {
            times = new TimingInfo();
        }
        NodeRunStatus status;
        InputStep inputStep = null;
        if (PipelineNodeUtil.isPausedForInputStep((StepAtomNode) atomNode, inputAction)) {
            status = new NodeRunStatus(BlueRun.BlueRunResult.UNKNOWN, BlueRun.BlueRunState.PAUSED);
            try {
                for (InputStepExecution execution : inputAction.getExecutions()) {
                    FlowNode node = execution.getContext().get(FlowNode.class);
                    if (node != null && node.equals(atomNode)) {
                        inputStep = execution.getInput();
                        break;
                    }
                }
            } catch (IOException | InterruptedException | TimeoutException e) {
                logger.error("Error getting FlowNode from execution context: " + e.getMessage(), e);
            }
        } else {
            status = new NodeRunStatus(atomNode);
        }
        FlowNodeWrapper node = new FlowNodeWrapper(atomNode, status, times, inputStep, run);
        if (PipelineNodeUtil.isPreSyntheticStage(currentStage)) {
            preSteps.add(node);
        } else if (PipelineNodeUtil.isPostSyntheticStage(currentStage)) {
            postSteps.add(node);
        } else {
            if (!steps.contains(node)) {
                steps.push(node);
            }
        }
        stepMap.put(node.getId(), node);
        //If there is closest block boundary, we capture it's error to the last step encountered and prepare for next block.
        if (closestEndNode != null && closestEndNode.getError() != null) {
            node.setBlockErrorAction(closestEndNode.getError());
            //prepare for next block
            closestEndNode = null;
        }
    }
}
Also used : TimingInfo(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) IOException(java.io.IOException) StepAtomNode(org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode) InputStepExecution(org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution) InputStep(org.jenkinsci.plugins.workflow.support.steps.input.InputStep) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with InputStepExecution

use of org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution in project blueocean-plugin by jenkinsci.

the class PipelineStepImpl method submitInputStep.

@Override
public HttpResponse submitInputStep(StaplerRequest request) {
    JSONObject body;
    try {
        body = JSONObject.fromObject(IOUtils.toString(request.getReader()));
    } catch (IOException e) {
        throw new ServiceException.UnexpectedErrorException(e.getMessage());
    }
    String id = body.getString(ID_ELEMENT);
    if (id == null) {
        throw new ServiceException.BadRequestExpception("id is required");
    }
    if (body.get(PARAMETERS_ELEMENT) == null && body.get(ABORT_ELEMENT) == null) {
        throw new ServiceException.BadRequestExpception("parameters is required");
    }
    WorkflowRun run = node.getRun();
    InputAction inputAction = run.getAction(InputAction.class);
    if (inputAction == null) {
        throw new ServiceException.BadRequestExpception("Error processing Input Submit request. This Run instance does not" + " have an InputAction.");
    }
    try {
        InputStepExecution execution = inputAction.getExecution(id);
        if (execution == null) {
            throw new ServiceException.BadRequestExpception(String.format("Error processing Input Submit request. This Run instance does not" + " have an Input with an id of '%s'.", id));
        }
        //if abort, abort and return
        if (body.get(ABORT_ELEMENT) != null && body.getBoolean(ABORT_ELEMENT)) {
            return execution.doAbort();
        }
        //XXX: execution.doProceed(request) expects submitted form, otherwise we could have simply used it
        preSubmissionCheck(execution);
        Object o = parseValue(execution, JSONArray.fromObject(body.get(PARAMETERS_ELEMENT)), request);
        HttpResponse response = execution.proceed(o);
        for (PipelineInputStepListener listener : ExtensionList.lookup(PipelineInputStepListener.class)) {
            listener.onStepContinue(execution.getInput(), run);
        }
        return response;
    } catch (IOException | InterruptedException | TimeoutException e) {
        throw new ServiceException.UnexpectedErrorException("Error processing Input Submit request." + e.getMessage());
    }
}
Also used : InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) HttpResponse(org.kohsuke.stapler.HttpResponse) IOException(java.io.IOException) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) InputStepExecution(org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution) JSONObject(net.sf.json.JSONObject) ServiceException(io.jenkins.blueocean.commons.ServiceException) JSONObject(net.sf.json.JSONObject) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 InputStepExecution (org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution)2 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 JSONObject (net.sf.json.JSONObject)1 StepAtomNode (org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode)1 StepEndNode (org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode)1 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 TimingInfo (org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo)1 InputAction (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)1 InputStep (org.jenkinsci.plugins.workflow.support.steps.input.InputStep)1 HttpResponse (org.kohsuke.stapler.HttpResponse)1