Search in sources :

Example 6 with Link

use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.

the class OrganizationFolderTest method testOrganizationFolderFactoryNoPermissionsFolder.

@Test(expected = ServiceException.ForbiddenException.class)
public void testOrganizationFolderFactoryNoPermissionsFolder() throws Exception {
    List<OrganizationFolderPipelineImpl.OrganizationFolderFactory> organizationFolderFactoryList = ExtensionList.lookup(OrganizationFolderPipelineImpl.OrganizationFolderFactory.class);
    OrganizationFolderFactoryTestImpl organizationFolderFactoryTest = ((ExtensionList<OrganizationFolderPipelineImpl.OrganizationFolderFactory>) organizationFolderFactoryList).get(OrganizationFolderFactoryTestImpl.class);
    assertNotNull(organizationFolderFactoryTest);
    OrganizationFolderPipelineImpl folderPipeline = organizationFolderFactoryTest.getFolder(orgFolder, new Reachable() {

        @Override
        public Link getLink() {
            return organization.getLink().rel("/pipelines/");
        }
    }, mockOrganization());
    assertNotNull(folderPipeline);
    assertNotNull(folderPipeline.getQueue());
    assertNotNull(folderPipeline.getQueue().iterator());
    // Make sure the user does not have permissions to that folder
    PowerMockito.when(orgFolder.getACL()).thenReturn(new ACL() {

        @Override
        public boolean hasPermission(Authentication arg0, Permission arg1) {
            return false;
        }
    });
    ScmResourceImpl scmResource = new ScmResourceImpl(orgFolder, folderPipeline);
    StaplerRequest staplerRequest = PowerMockito.mock(StaplerRequest.class);
    assertEquals("hello", scmResource.getContent(staplerRequest));
}
Also used : StaplerRequest(org.kohsuke.stapler.StaplerRequest) ACL(hudson.security.ACL) Authentication(org.acegisecurity.Authentication) ExtensionList(hudson.ExtensionList) Reachable(io.jenkins.blueocean.rest.Reachable) Permission(hudson.security.Permission) Link(io.jenkins.blueocean.rest.hal.Link) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with Link

use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.

the class PipelinePluginAnalytics method onCompleted.

@Override
public void onCompleted(WorkflowRun workflowRun, @Nonnull TaskListener listener) {
    Analytics analytics = Analytics.get();
    if (analytics == null) {
        return;
    }
    // Tally up all the steps used in this run
    Tally tally = new Tally();
    NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(workflowRun);
    builder.getPipelineNodeSteps(new Link("steps/")).forEach(step -> tally.count(step.getStepType()));
    boolean isDeclarative = workflowRun.getParent().getAction(DeclarativeJobAction.class) != null;
    Result result = workflowRun.getResult();
    String resultAsString = result != null ? result.toString() : "UNKNOWN";
    // Send event for each step used in this run
    tally.get().forEach((key, value) -> {
        Map<String, Object> props = new HashMap<>();
        props.put("type", key);
        props.put("timesUsed", value);
        props.put("isDeclarative", isDeclarative);
        props.put("runResult", resultAsString);
        analytics.track(new TrackRequest("pipeline_step_used", props));
    });
}
Also used : Tally(io.jenkins.blueocean.service.embedded.analytics.Tally) HashMap(java.util.HashMap) TrackRequest(io.jenkins.blueocean.analytics.Analytics.TrackRequest) DeclarativeJobAction(org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction) Analytics(io.jenkins.blueocean.analytics.Analytics) Link(io.jenkins.blueocean.rest.hal.Link) NodeGraphBuilder(io.jenkins.blueocean.rest.impl.pipeline.NodeGraphBuilder) Result(hudson.model.Result)

Example 8 with Link

use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.

the class PipelineNodeGraphVisitor method getPipelineNodeSteps.

@Override
public List<BluePipelineStep> getPipelineNodeSteps(final String nodeId, Link parent) {
    FlowExecution execution = run.getExecution();
    if (execution == null) {
        logger.debug(String.format("Pipeline %s, runid %s  has null execution", run.getParent().getName(), run.getId()));
        return Collections.emptyList();
    }
    DepthFirstScanner depthFirstScanner = new DepthFirstScanner();
    // If blocked scope, get the end node
    FlowNode n = depthFirstScanner.findFirstMatch(execution.getCurrentHeads(), input -> (input != null && input.getId().equals(nodeId) && (PipelineNodeUtil.isStage(input) || PipelineNodeUtil.isParallelBranch(input))));
    if (n == null) {
        // if no node found or the node is not stage or parallel we return empty steps
        return Collections.emptyList();
    }
    PipelineStepVisitor visitor = new PipelineStepVisitor(run, n);
    ForkScanner.visitSimpleChunks(execution.getCurrentHeads(), visitor, new StageChunkFinder());
    return visitor.getSteps().stream().map(node -> new PipelineStepImpl(node, parent)).collect(Collectors.toList());
}
Also used : DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) Arrays(java.util.Arrays) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) LoggerFactory(org.slf4j.LoggerFactory) LabelAction(org.jenkinsci.plugins.workflow.actions.LabelAction) StringUtils(org.apache.commons.lang3.StringUtils) GenericStatus(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.GenericStatus) MemoryFlowChunk(org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk) Map(java.util.Map) ExecutionModelAction(org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) Action(hudson.model.Action) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) StepStartNode(org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode) List(java.util.List) PauseAction(org.jenkinsci.plugins.workflow.support.actions.PauseAction) Optional(java.util.Optional) FlowStartNode(org.jenkinsci.plugins.workflow.graph.FlowStartNode) 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) TimingAction(org.jenkinsci.plugins.workflow.actions.TimingAction) HashMap(java.util.HashMap) Stack(java.util.Stack) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) TimingInfo(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo) BlockEndNode(org.jenkinsci.plugins.workflow.graph.BlockEndNode) StandardChunkVisitor(org.jenkinsci.plugins.workflow.graphanalysis.StandardChunkVisitor) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) StageChunkFinder(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StageChunkFinder) StatusAndTiming(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StatusAndTiming) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) NotExecutedNodeAction(org.jenkinsci.plugins.workflow.actions.NotExecutedNodeAction) IOException(java.io.IOException) ForkScanner(org.jenkinsci.plugins.workflow.graphanalysis.ForkScanner) StepAtomNode(org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) CheckForNull(javax.annotation.CheckForNull) Collections(java.util.Collections) StageChunkFinder(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StageChunkFinder) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 9 with Link

use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.

the class BranchContainerImpl method iterator.

@Override
@SuppressWarnings("unchecked")
public Iterator<BluePipeline> iterator(int start, int limit) {
    final BlueOrganization organization = OrganizationFactory.getInstance().getContainingOrg(pipeline.mbp.getItemGroup());
    if (organization == null) {
        throw new ServiceException.UnexpectedErrorException("Could not find organization for " + pipeline.mbp.getFullName());
    }
    final Link link = getLink();
    // Filter will decide if the requester wants branches or pull requests
    Collection<Job> allJobsMatchinFilter = ContainerFilter.filter(pipeline.mbp.getAllJobs());
    return allJobsMatchinFilter.stream().map(job -> (BluePipeline) new BranchImpl(organization, job, link)).sorted(BRANCH_COMPARATOR).skip(start).limit(limit).iterator();
}
Also used : BlueOrganization(io.jenkins.blueocean.rest.model.BlueOrganization) Job(hudson.model.Job) Link(io.jenkins.blueocean.rest.hal.Link)

Example 10 with Link

use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.

the class ArtifactImplTest method findUniqueArtifactsWithSameName.

@Test
public void findUniqueArtifactsWithSameName() throws IllegalAccessException {
    // mock artifacts
    Run.Artifact artifact1 = mock(Run.Artifact.class);
    Run.Artifact artifact2 = mock(Run.Artifact.class);
    // artifact1 mocks
    when(artifact1.getFileName()).thenReturn("test-suite.log");
    MemberModifier.field(Run.Artifact.class, "relativePath").set(artifact1, "path1/test-suite.log");
    when(artifact1.getHref()).thenReturn("path1/test-suite.log");
    // artifact2 mocks
    when(artifact2.getFileName()).thenReturn("test-suite.log");
    MemberModifier.field(Run.Artifact.class, "relativePath").set(artifact2, "path2/test-suite.log");
    when(artifact2.getHref()).thenReturn("path2/test-suite.log");
    // list of artifacts
    ArrayList artifactList = new ArrayList();
    artifactList.add(artifact1);
    artifactList.add(artifact2);
    // mock run
    Run run = mock(Run.class);
    when(run.getUrl()).thenReturn("job/myfolder/job/myjob/1/");
    when(run.getArtifacts()).thenReturn(artifactList);
    Link parentLink = mock(Link.class);
    ArtifactImpl a1 = new ArtifactImpl(run, artifact1, parentLink);
    ArtifactImpl a2 = new ArtifactImpl(run, artifact2, parentLink);
    assertThat(a1.getId(), is(not(a2.getId())));
}
Also used : ArrayList(java.util.ArrayList) Run(hudson.model.Run) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Link (io.jenkins.blueocean.rest.hal.Link)30 Test (org.junit.Test)12 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)8 Run (hudson.model.Run)7 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)7 Reachable (io.jenkins.blueocean.rest.Reachable)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 BlueOrganization (io.jenkins.blueocean.rest.model.BlueOrganization)5 BluePipelineNode (io.jenkins.blueocean.rest.model.BluePipelineNode)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)4 Job (hudson.model.Job)3 ServiceException (io.jenkins.blueocean.commons.ServiceException)3 BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)3 BlueQueueItem (io.jenkins.blueocean.rest.model.BlueQueueItem)3