Java Code Examples for hudson.model.Slave#setNumExecutors()

The following examples show how to use hudson.model.Slave#setNumExecutors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PipelineNodeTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
@Issue("JENKINS-49779")
public void sequentialParallelStagesWithPost() throws Exception {
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "sequentialParallelWithPost.jenkinsfile");
    Slave s = j.createOnlineSlave();
    s.setNumExecutors(2);

    // Run until completed
    j.buildAndAssertSuccess(p);

    List<Map> nodes = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/", List.class);
    assertEquals(9, nodes.size());


    Optional<Map> thirdSeqStage = nodes.stream()
                                       .filter(map -> map.get("displayName")
                                                         .equals("third-sequential-stage")).findFirst();

    assertTrue(thirdSeqStage.isPresent());

    List<Map> steps = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/" + thirdSeqStage.get().get("id") + "/steps/", List.class);

    assertEquals(2, steps.size());
    assertEquals("echo 'dummy text third-sequential-stage'", steps.get(0).get("displayDescription"));
    assertEquals("echo 'dummy text post multiple-stages'", steps.get(1).get("displayDescription"));
}
 
Example 2
Source File: PipelineNodeTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void nestedStagesGroups() throws Exception {
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "nestedStagesGroups.jenkinsfile");
    Slave s = j.createOnlineSlave();
    s.setLabelString("foo");
    s.setNumExecutors(4);

    // Run until completed
    WorkflowRun run = p.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(run);

    PipelineNodeGraphVisitor pipelineNodeGraphVisitor = new PipelineNodeGraphVisitor(run);
    assertTrue(pipelineNodeGraphVisitor.isDeclarative());
    List<FlowNodeWrapper> wrappers = pipelineNodeGraphVisitor.getPipelineNodes();
    assertEquals(7, wrappers.size());
}
 
Example 3
Source File: PipelineNodeTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
@Issue("JENKINS-49050")
public void parallelStagesNonNested() throws Exception {
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "parallelStagesNonNested.jenkinsfile");
    Slave s = j.createOnlineSlave();
    s.setLabelString("foo");
    s.setNumExecutors(2);

    // Run until completed
    WorkflowRun run = p.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(run);

    PipelineNodeGraphVisitor pipelineNodeGraphVisitor = new PipelineNodeGraphVisitor(run);

    List<FlowNodeWrapper> wrappers = pipelineNodeGraphVisitor.getPipelineNodes();
    assertEquals(3, wrappers.size());

    List<Map> nodes = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/", List.class);
    assertEquals(3, nodes.size());
}
 
Example 4
Source File: PipelineNodeTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
@Issue("JENKINS-49050")
public void parallelStagesGroupsAndNestedStages() throws Exception {
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "parallelStagesGroupsAndStages.jenkinsfile");
    Slave s = j.createOnlineSlave();
    s.setLabelString("foo");
    s.setNumExecutors(2);

    // Run until completed
    WorkflowRun run = p.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(run);

    PipelineNodeGraphVisitor pipelineNodeGraphVisitor = new PipelineNodeGraphVisitor(run);
    assertTrue(pipelineNodeGraphVisitor.isDeclarative());

    List<FlowNodeWrapper> wrappers = pipelineNodeGraphVisitor.getPipelineNodes();

    FlowNodeWrapper flowNodeWrapper = wrappers.get(0);
    assertEquals("top", flowNodeWrapper.getDisplayName());
    assertEquals(2, flowNodeWrapper.edges.size());

    flowNodeWrapper = wrappers.get(1);
    assertEquals("first", flowNodeWrapper.getDisplayName());
    assertEquals(1, flowNodeWrapper.edges.size());
    assertEquals(1, flowNodeWrapper.getParents().size());

    assertEquals("first-inner-first", flowNodeWrapper.edges.get(0).getDisplayName());

    assertEquals(7, wrappers.size());

    List<Map> nodes = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/", List.class);
    assertEquals(7, nodes.size());
}
 
Example 5
Source File: PipelineNodeTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Ignore("Fails on ci.jenkins.io but not locally. Reasons unclear.  Likely a timing issue.")
@Test
public void sequentialParallelStagesLongRun() throws Exception {
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "sequential_parallel_stages_long_run_time.jenkinsfile");
    Slave s = j.createOnlineSlave();
    s.setNumExecutors(3);
    WorkflowRun run = p.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(run);

    List<String> watchedStages = Arrays.asList("first-sequential-stage", "second-sequential-stage", "third-sequential-stage");

    run = p.scheduleBuild2(0).waitForStart();

    Thread.sleep(1000);

    long loopCount = 0;
    while (run.isBuilding()) {
        PipelineNodeContainerImpl pipelineNodeContainer = new PipelineNodeContainerImpl(run, new Link("foo"));

        List<BluePipelineNode> nodes = pipelineNodeContainer.getNodes();
        for (BluePipelineNode node : nodes) {
            if (StringUtils.isEmpty(node.getFirstParent())
                && watchedStages.contains(node.getDisplayName())) {
                LOGGER.error("node {} has getFirstParent null", node);
                fail("node with getFirstParent null:" + node);
            }

            // we try to find edges with id for a non existing node in the list
            List<BluePipelineNode.Edge> emptyEdges =
                node.getEdges().stream().filter(edge ->
                                                    !nodes.stream()
                                                          .filter(bluePipelineNode -> bluePipelineNode.getId().equals(edge.getId()))
                                                          .findFirst().isPresent()

                ).collect(Collectors.toList());
            if (!emptyEdges.isEmpty()) {
                // TODO remove this weird if but it's only to have breakpoint in IDE
                assertTrue("edges with unknown nodes" + nodes, !emptyEdges.isEmpty());
            }
        }


        LOGGER.debug("nodes size {}", nodes.size());
        if (nodes.size() != 9) {
            LOGGER.info("loop: " + loopCount + ", nodes size {}", nodes.size());
            LOGGER.info("nodes != 9 {}", nodes);
            fail("nodes != 9:  " + nodes);
        }

        Thread.sleep(100);
    }

}
 
Example 6
Source File: PipelineNodeTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
@Issue("JENKINS-49050")
public void sequentialParallelStages() throws Exception {
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "sequentialParallel.jenkinsfile");
    Slave s = j.createOnlineSlave();
    s.setNumExecutors(2);

    // Run until completed
    WorkflowRun run = p.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(run);

    PipelineNodeGraphVisitor pipelineNodeGraphVisitor = new PipelineNodeGraphVisitor(run);
    assertTrue(pipelineNodeGraphVisitor.isDeclarative());

    List<FlowNodeWrapper> wrappers = pipelineNodeGraphVisitor.getPipelineNodes();

    assertEquals(9, wrappers.size());

    Optional<FlowNodeWrapper> optionalFlowNodeWrapper =
        wrappers.stream().filter(nodeWrapper -> nodeWrapper.getDisplayName().equals("first-sequential-stage"))
                .findFirst();

    // we ensure "multiple-stages" is parent of "first-sequential-stage"
    assertTrue(optionalFlowNodeWrapper.isPresent());
    assertEquals(1, optionalFlowNodeWrapper.get().edges.size());
    assertEquals("second-sequential-stage", optionalFlowNodeWrapper.get().edges.get(0).getDisplayName());

    final String parentId = optionalFlowNodeWrapper.get().getFirstParent().getId();

    optionalFlowNodeWrapper =
        wrappers.stream().filter(nodeWrapper -> nodeWrapper.getId().equals(parentId))
                .findFirst();

    assertTrue(optionalFlowNodeWrapper.isPresent());
    assertEquals("multiple-stages", optionalFlowNodeWrapper.get().getDisplayName());
    assertEquals(1, optionalFlowNodeWrapper.get().edges.size());

    optionalFlowNodeWrapper.get().edges.stream()
                                       .filter(nodeWrapper -> nodeWrapper.getDisplayName().equals("first-sequential-stage"))
                                       .findFirst();
    assertTrue(optionalFlowNodeWrapper.isPresent());


    optionalFlowNodeWrapper =
        wrappers.stream().filter(nodeWrapper -> nodeWrapper.getDisplayName().equals("other-single-stage"))
                .findFirst();
    assertTrue(optionalFlowNodeWrapper.isPresent());

    final String otherParentId = optionalFlowNodeWrapper.get().getFirstParent().getId();

    optionalFlowNodeWrapper =
        wrappers.stream().filter(nodeWrapper -> nodeWrapper.getId().equals(otherParentId))
                .findFirst();

    assertTrue(optionalFlowNodeWrapper.isPresent());
    assertEquals("parent", optionalFlowNodeWrapper.get().getDisplayName());
    assertEquals(3, optionalFlowNodeWrapper.get().edges.size());

    optionalFlowNodeWrapper =
        wrappers.stream().filter(nodeWrapper -> nodeWrapper.getDisplayName().equals("second-sequential-stage"))
                .findFirst();
    assertTrue(optionalFlowNodeWrapper.isPresent());

    assertEquals(1, optionalFlowNodeWrapper.get().edges.size());
    assertEquals("third-sequential-stage", optionalFlowNodeWrapper.get().edges.get(0).getDisplayName());

    optionalFlowNodeWrapper =
        wrappers.stream().filter(nodeWrapper -> nodeWrapper.getDisplayName().equals("third-sequential-stage"))
                .findFirst();
    assertTrue(optionalFlowNodeWrapper.isPresent());

    assertEquals(1, optionalFlowNodeWrapper.get().edges.size());
    assertEquals("second-solo", optionalFlowNodeWrapper.get().edges.get(0).getDisplayName());

    List<Map> nodes = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/", List.class);
    assertEquals(9, nodes.size());


    Optional<Map> firstSeqStage = nodes.stream()
                                       .filter(map -> map.get("displayName")
                                                         .equals("first-sequential-stage")).findFirst();

    assertTrue(firstSeqStage.isPresent());
    String firstParentId = (String) firstSeqStage.get().get("firstParent");

    Optional<Map> parentStage = nodes.stream()
                                     .filter(map -> map.get("id")
                                                       .equals(firstParentId)).findFirst();
    assertTrue(parentStage.isPresent());
    assertEquals("multiple-stages", parentStage.get().get("displayName"));

    // ensure no issue getting steps for each node
    for (Map<String, String> node : nodes) {
        String id = node.get("id");
        List<Map> steps =
            get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/1/nodes/" + id + "/steps/", List.class);
        assertFalse(steps.get(0).isEmpty());
    }
}