Package org.jenkinsci.plugins.workflow.graph

Examples of org.jenkinsci.plugins.workflow.graph.FlowNode


            throw new IOException("expected an STMExecution but got a " + exec);
        }
    }

    @Override protected FlowNode getNode() throws IOException {
        FlowNode node = getExecution().getNode(id);
        if (node == null) {
            throw new IOException("no such node " + id);
        }
        return node;
    }
View Full Code Here


    /*packgage*/ synchronized void onProgramEnd(Outcome outcome) {
        // end of the program
        // run till the end successfully FIXME: failure comes here, too
        // TODO: if program terminates with exception, we need to record it
        // TODO: in the error case, we have to close all the open nodes
        FlowNode head = new FlowEndNode(this, iotaStr(), (FlowStartNode)startNodes.pop(), result, getCurrentHeads().toArray(new FlowNode[0]));
        if (outcome.isFailure())
            head.addAction(new ErrorAction(outcome.getAbnormal()));

        // shrink everything into a single new head
        done = true;
        FlowHead first = getFirstHead();
        first.setNewHead(head);
View Full Code Here

            return;
        }
        LOGGER.log(Level.FINE, "next state is {0} on {1} with stack {2}", new Object[] {next, thread, stack});
        String priorID = heads.get(thread);
        assert priorID != null;
        FlowNode prior;
        try {
            prior = getNode(priorID);
        } catch (IOException x) {
            LOGGER.log(Level.WARNING, null, x);
            return;
        }
        if (next.equals(END)) {
            stack.pop();
            if (stack.isEmpty()) {
                LOGGER.log(Level.FINE, "finishing thread {0}", thread);
                pcs.remove(thread);
                heads.remove(thread);
                try {
                    addingHead(new BlockEndNode<BlockStartNode>(this, newID(), /*TODO*/null, prior) {
                        @Override protected String getTypeDisplayName() {
                            return "Thread end";
                        }
                    });
                    // TODO keep a list of all thread end nodes to collect into finals list in finish()
                    if (heads.isEmpty()) {
                        finish(Result.SUCCESS);
                    }
                } catch (Exception x) {
                    // What to do about it?
                    LOGGER.log(Level.WARNING, null, x);
                }
            } else {
                Frame caller = stack.peek();
                LOGGER.log(Level.FINE, "finishing subroutine from {0} on {1}", new Object[] {caller, thread});
                State s = getStateMap().get(caller.state);
                assert s instanceof BlockState : "found " + s + " rather than a BlockState on the stack for " + caller.state;
                FutureCallback callback = caller.callback;
                assert callback != null : "no callback defined for " + caller.state;
                caller.callback = null;
                callback.onSuccess(null); // TODO should there be a way of passing a return value from the block?
                heads.put(thread, caller.id);
                try {
                    addingHead(new BlockEndNode<BlockStartNode>(this, newID(), /*TODO*/null, /* TODO is this right? or should it be from caller.id? */prior) {
                        @Override protected String getTypeDisplayName() {
                            return "Block end";
                        }
                    });
                } catch (IOException x) {
                    LOGGER.log(Level.WARNING, null, x);
                }
            }
        } else {
            State s = getStateMap().get(next);
            if (s == null) {
                LOGGER.log(Level.WARNING, "no such state {0}", next);
                // How better to recover?
                next(thread, END);
                return;
            }
            String id = newID();
            FlowNode n = s.run(new STMContext(owner, id, next, thread), id, this, prior);
            stack.peek().state = next;
            stack.peek().id = id;
            heads.put(thread, id);
            try {
                addingHead(n);
View Full Code Here

    @Override public List<FlowNode> getCurrentHeads() {
        List<FlowNode> r = new ArrayList<FlowNode>();
        for (String head : heads.values()) {
            try {
                FlowNode node = getNode(head);
                if (node == null) {
                    LOGGER.log(Level.WARNING, "no such head node {0}", head);
                    continue;
                }
                r.add(node);
View Full Code Here

        List<FlowNode> finals = new ArrayList<FlowNode>();
        for (Map.Entry<String,String> entry : heads.entrySet()) {
            String thread = entry.getKey();
            String priorID = entry.getValue();
            assert priorID != null;
            FlowNode prior = getNode(priorID);
            BlockEndNode<BlockStartNode> blockEndNode = new BlockEndNode<BlockStartNode>(this, newID(), /*TODO*/ null, prior) {
                @Override protected String getTypeDisplayName() {
                    return "Thread end";
                }
            };
View Full Code Here

public class PauseActionTest {

    @Test
    public void test() throws Exception {
        FlowExecution flowExecution = Mockito.mock(FlowExecution.class);
        FlowNode flowNode = new FlowNode(flowExecution, "1") {
            @Override
            protected String getTypeDisplayName() {
                return "flownode";
            }
        };

        Assert.assertEquals(false, PauseAction.isPaused(flowNode));
        Assert.assertEquals(0L, PauseAction.getPauseDuration(flowNode));

        flowNode.addAction(new PauseAction("P1"));
        PauseAction firstPause = PauseAction.getCurrentPause(flowNode);
        Assert.assertEquals("P1", firstPause.getCause());
        Assert.assertEquals(true, PauseAction.isPaused(flowNode));
        Thread.sleep(200);
        Assert.assertTrue(PauseAction.getPauseDuration(flowNode) > 100L);

        PauseAction.endCurrentPause(flowNode);
        Assert.assertEquals(false, PauseAction.isPaused(flowNode));
        long firstPauseDuration = firstPause.getPauseDuration();

        Thread.sleep(200);
        Assert.assertEquals(firstPauseDuration, PauseAction.getPauseDuration(flowNode));

        flowNode.addAction(new PauseAction("P2"));
        PauseAction secondPause = PauseAction.getCurrentPause(flowNode);
        Assert.assertEquals("P2", secondPause.getCause());
        Assert.assertEquals(true, PauseAction.isPaused(flowNode));
        Thread.sleep(200);
        Assert.assertTrue(PauseAction.getPauseDuration(flowNode) > firstPauseDuration);
View Full Code Here

        walker.addHeads(heads);

        // nodes that we've visited
        Map<FlowNode,Row> rows = new LinkedHashMap<FlowNode, Row>();

        FlowNode n;
        while ((n=walker.next())!=null) {
            Row row = new Row(n);
            rows.put(n, row);
        }
        return rows;
View Full Code Here

     */
    private Row buildForwardReferences(Map<FlowNode, Row> rows) {
        // build up all the forward references
        Row firstRow = null;
        for (Row r : rows.values()) {
            FlowNode n = r.node;
            for (FlowNode p : n.getParents()) {
                rows.get(p).addGraphChild(r);
            }
            if (n.getParents().isEmpty()) {
                if (firstRow==null)
                    firstRow = r;
                else {
                    // in an unlikely case when we find multiple head nodes,
                    // treat them all as siblings
View Full Code Here

TOP

Related Classes of org.jenkinsci.plugins.workflow.graph.FlowNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.