Search in sources :

Example 6 with Slave

use of hudson.model.Slave in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method parallelStagesNonNested.

@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());
}
Also used : Slave(hudson.model.Slave) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 7 with Slave

use of hudson.model.Slave in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method sequentialParallelStages.

@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());
    }
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Arrays(java.util.Arrays) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Issue(org.jvnet.hudson.test.Issue) QueueTaskFuture(hudson.model.queue.QueueTaskFuture) URL(java.net.URL) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) PARAMETERS_ELEMENT(io.jenkins.blueocean.rest.impl.pipeline.PipelineStepImpl.PARAMETERS_ELEMENT) StringUtils(org.apache.commons.lang3.StringUtils) RunList(hudson.util.RunList) MemoryFlowChunk(org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk) Map(java.util.Map) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) Jenkins(jenkins.model.Jenkins) MapsHelper(io.jenkins.blueocean.commons.MapsHelper) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Run(hudson.model.Run) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) NodeDownstreamBuildAction(io.jenkins.blueocean.listeners.NodeDownstreamBuildAction) FilePath(hudson.FilePath) Result(hudson.model.Result) JSONObject(net.sf.json.JSONObject) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) Optional(java.util.Optional) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) BeforeClass(org.junit.BeforeClass) SemaphoreStep(org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep) FreeStyleProject(hudson.model.FreeStyleProject) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) FlowGraphTable(org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable) UnstableStep(org.jenkinsci.plugins.workflow.steps.UnstableStep) GitSampleRepoRule(jenkins.plugins.git.GitSampleRepoRule) Unirest(com.mashape.unirest.http.Unirest) SCMSource(jenkins.scm.api.SCMSource) Util(hudson.Util) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Description(org.hamcrest.Description) Iterator(java.util.Iterator) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Test(org.junit.Test) BranchSource(jenkins.branch.BranchSource) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) Ignore(org.junit.Ignore) Matcher(org.hamcrest.Matcher) Assert(org.junit.Assert) Slave(hudson.model.Slave) ExtensionList(hudson.ExtensionList) GitSCMSource(jenkins.plugins.git.GitSCMSource) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Slave(hudson.model.Slave) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 8 with Slave

use of hudson.model.Slave in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method sequentialParallelStagesLongRun.

@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);
    }
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) Arrays(java.util.Arrays) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Issue(org.jvnet.hudson.test.Issue) QueueTaskFuture(hudson.model.queue.QueueTaskFuture) URL(java.net.URL) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) PARAMETERS_ELEMENT(io.jenkins.blueocean.rest.impl.pipeline.PipelineStepImpl.PARAMETERS_ELEMENT) StringUtils(org.apache.commons.lang3.StringUtils) RunList(hudson.util.RunList) MemoryFlowChunk(org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk) Map(java.util.Map) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) Jenkins(jenkins.model.Jenkins) MapsHelper(io.jenkins.blueocean.commons.MapsHelper) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Run(hudson.model.Run) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) NodeDownstreamBuildAction(io.jenkins.blueocean.listeners.NodeDownstreamBuildAction) FilePath(hudson.FilePath) Result(hudson.model.Result) JSONObject(net.sf.json.JSONObject) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) Optional(java.util.Optional) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) BeforeClass(org.junit.BeforeClass) SemaphoreStep(org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep) FreeStyleProject(hudson.model.FreeStyleProject) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) FlowGraphTable(org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable) UnstableStep(org.jenkinsci.plugins.workflow.steps.UnstableStep) GitSampleRepoRule(jenkins.plugins.git.GitSampleRepoRule) Unirest(com.mashape.unirest.http.Unirest) SCMSource(jenkins.scm.api.SCMSource) Util(hudson.Util) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Description(org.hamcrest.Description) Iterator(java.util.Iterator) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) Test(org.junit.Test) BranchSource(jenkins.branch.BranchSource) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) Ignore(org.junit.Ignore) Matcher(org.hamcrest.Matcher) Assert(org.junit.Assert) Slave(hudson.model.Slave) ExtensionList(hudson.ExtensionList) GitSCMSource(jenkins.plugins.git.GitSCMSource) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Slave(hudson.model.Slave) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) Link(io.jenkins.blueocean.rest.hal.Link) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Slave (hudson.model.Slave)8 Test (org.junit.Test)8 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)6 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)6 Map (java.util.Map)5 Issue (org.jvnet.hudson.test.Issue)5 File (java.io.File)4 Unirest (com.mashape.unirest.http.Unirest)3 ExtensionList (hudson.ExtensionList)3 FilePath (hudson.FilePath)3 Util (hudson.Util)3 FreeStyleProject (hudson.model.FreeStyleProject)3 Result (hudson.model.Result)3 Run (hudson.model.Run)3 QueueTaskFuture (hudson.model.queue.QueueTaskFuture)3 RunList (hudson.util.RunList)3 MapsHelper (io.jenkins.blueocean.commons.MapsHelper)3 NodeDownstreamBuildAction (io.jenkins.blueocean.listeners.NodeDownstreamBuildAction)3 Link (io.jenkins.blueocean.rest.hal.Link)3 PARAMETERS_ELEMENT (io.jenkins.blueocean.rest.impl.pipeline.PipelineStepImpl.PARAMETERS_ELEMENT)3