Skip to content

Commit 1a92165

Browse files
authored
Remove unused graph code (#74)
1 parent 8ded724 commit 1a92165

File tree

4 files changed

+0
-166
lines changed

4 files changed

+0
-166
lines changed

src/main/java/io/jenkins/plugins/pipelinegraphview/multipipelinegraphview/MultiPipelineGraphViewAction.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import hudson.util.HttpResponses;
77
import hudson.util.RunList;
88
import io.jenkins.plugins.pipelinegraphview.utils.PipelineGraph;
9-
import io.jenkins.plugins.pipelinegraphview.utils.PipelineGraphApi;
109
import java.util.ArrayList;
1110
import java.util.List;
1211
import net.sf.json.JSONArray;
@@ -17,7 +16,6 @@
1716
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
1817
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
1918
import org.kohsuke.stapler.HttpResponse;
20-
import org.kohsuke.stapler.StaplerRequest;
2119
import org.kohsuke.stapler.WebMethod;
2220
import org.kohsuke.stapler.verb.GET;
2321

@@ -44,16 +42,6 @@ public MultiPipelineGraphViewAction(WorkflowJob target) {
4442
this.target = target;
4543
}
4644

47-
@GET
48-
@WebMethod(name = "graph")
49-
public HttpResponse getGraph(StaplerRequest req) throws JsonProcessingException {
50-
String runId = req.getParameter("runId");
51-
WorkflowRun run = target.getBuildByNumber(Integer.parseInt(runId));
52-
PipelineGraphApi api = new PipelineGraphApi(run);
53-
JSONObject graph = createGraphJson(api.createGraph());
54-
return HttpResponses.okJSON(graph);
55-
}
56-
5745
protected JSONObject createGraphJson(PipelineGraph pipelineGraph) throws JsonProcessingException {
5846
String graph = OBJECT_MAPPER.writeValueAsString(pipelineGraph);
5947
return JSONObject.fromObject(graph);

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/AbstractPipelineViewAction.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
1212
import org.kohsuke.stapler.HttpResponse;
1313
import org.kohsuke.stapler.WebMethod;
14-
import org.kohsuke.stapler.verb.GET;
1514

1615
public abstract class AbstractPipelineViewAction implements Action, IconSpec {
1716
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
@@ -40,16 +39,6 @@ protected JSONObject createJson(PipelineGraph pipelineGraph) throws JsonProcessi
4039
return JSONObject.fromObject(graph);
4140
}
4241

43-
@GET
44-
@WebMethod(name = "graph")
45-
public HttpResponse getGraph() throws JsonProcessingException {
46-
// TODO for automatic json serialisation look at:
47-
// https://github.com/jenkinsci/blueocean-plugin/blob/4f2aa260fca22604a087629dc0da5c80735e0548/blueocean-commons/src/main/java/io/jenkins/blueocean/commons/stapler/Export.java#L101
48-
// https://github.com/jenkinsci/blueocean-plugin/blob/4f2aa260fca22604a087629dc0da5c80735e0548/blueocean-commons/src/main/java/io/jenkins/blueocean/commons/stapler/TreeResponse.java#L48
49-
JSONObject graph = createJson(api.createGraph());
50-
return HttpResponses.okJSON(graph);
51-
}
52-
5342
@WebMethod(name = "tree")
5443
public HttpResponse getTree() throws JsonProcessingException {
5544
// TODO: This need to be updated to return a tree representation of the graph, not the graph.

src/main/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineGraphApi.java

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -52,83 +52,6 @@ private List<PipelineStageInternal> getPipelineNodes() {
5252
.collect(Collectors.toList());
5353
}
5454

55-
public PipelineGraph createGraph() {
56-
List<PipelineStageInternal> stages = getPipelineNodes();
57-
58-
// id => stage
59-
Map<String, PipelineStageInternal> stageMap =
60-
stages.stream()
61-
.collect(
62-
Collectors.toMap(
63-
PipelineStageInternal::getId, stage -> stage, (u, v) -> u, LinkedHashMap::new));
64-
65-
Map<String, List<String>> stageToChildrenMap = new HashMap<>();
66-
67-
List<String> stagesThatAreNested = new ArrayList<>();
68-
69-
Map<String, String> nextSiblingToOlderSibling = new HashMap<>();
70-
71-
List<String> stagesThatAreChildrenOrNestedStages = new ArrayList<>();
72-
stages.forEach(
73-
stage -> {
74-
if (stage.getParents().isEmpty()) {
75-
stageToChildrenMap.put(stage.getId(), new ArrayList<>());
76-
} else if (stage.getType().equals("PARALLEL")) {
77-
String parentId = stage.getParents().get(0); // assume one parent for now
78-
List<String> childrenOfParent =
79-
stageToChildrenMap.getOrDefault(parentId, new ArrayList<>());
80-
childrenOfParent.add(stage.getId());
81-
stageToChildrenMap.put(parentId, childrenOfParent);
82-
stagesThatAreChildrenOrNestedStages.add(stage.getId());
83-
} else if (stageMap.get(stage.getParents().get(0)).getType().equals("PARALLEL")) {
84-
String parentId = stage.getParents().get(0);
85-
PipelineStageInternal parent = stageMap.get(parentId);
86-
parent.setSeqContainerName(parent.getName());
87-
parent.setName(stage.getName());
88-
parent.setSequential(true);
89-
parent.setType(stage.getType());
90-
parent.setTitle(stage.getTitle());
91-
parent.setCompletePercent(stage.getCompletePercent());
92-
stage.setSequential(true);
93-
94-
nextSiblingToOlderSibling.put(stage.getId(), parentId);
95-
stagesThatAreNested.add(stage.getId());
96-
stagesThatAreChildrenOrNestedStages.add(stage.getId());
97-
// nested stage of nested stage
98-
} else if (stagesThatAreNested.contains(
99-
stageMap.get(stage.getParents().get(0)).getId())) {
100-
PipelineStageInternal parent =
101-
stageMap.get(nextSiblingToOlderSibling.get(stage.getParents().get(0)));
102-
// shouldn't happen but found it after restarting a matrix build
103-
// this breaks the layout badly but prevents a null pointer
104-
if (parent != null) {
105-
stage.setSequential(true);
106-
parent.setNextSibling(stage);
107-
stagesThatAreNested.add(stage.getId());
108-
stagesThatAreChildrenOrNestedStages.add(stage.getId());
109-
}
110-
}
111-
});
112-
113-
List<PipelineStage> stageResults =
114-
stageMap.values().stream()
115-
.map(
116-
pipelineStageInternal -> {
117-
List<PipelineStage> children =
118-
stageToChildrenMap.getOrDefault(pipelineStageInternal.getId(), emptyList())
119-
.stream()
120-
.map(mapper(stageMap, stageToChildrenMap))
121-
.collect(Collectors.toList());
122-
123-
return pipelineStageInternal.toPipelineStage(children);
124-
})
125-
.filter(stage -> !stagesThatAreChildrenOrNestedStages.contains(stage.getId()))
126-
.collect(Collectors.toList());
127-
128-
FlowExecution execution = run.getExecution();
129-
return new PipelineGraph(stageResults, execution != null && execution.isComplete());
130-
}
131-
13255
private Function<String, PipelineStage> mapper(
13356
Map<String, PipelineStageInternal> stageMap, Map<String, List<String>> stageToChildrenMap) {
13457

src/test/java/io/jenkins/plugins/pipelinegraphview/utils/PipelineGraphApiTest.java

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import hudson.model.Result;
77
import java.util.List;
8-
import java.util.Optional;
98
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
109
import org.junit.Rule;
1110
import org.junit.Test;
@@ -15,71 +14,6 @@ public class PipelineGraphApiTest {
1514

1615
@Rule public JenkinsRule j = new JenkinsRule();
1716

18-
@Test
19-
public void createGraph_unstableSmokes() throws Exception {
20-
WorkflowRun run =
21-
TestUtils.createAndRunJob(
22-
j, "unstableSmokes", "unstableSmokes.jenkinsfile", Result.FAILURE);
23-
PipelineGraphApi api = new PipelineGraphApi(run);
24-
PipelineGraph graph = api.createGraph();
25-
26-
List<PipelineStage> stages = graph.getStages();
27-
28-
String stagesString =
29-
TestUtils.collectStagesAsString(
30-
stages,
31-
(PipelineStage stage) ->
32-
String.format(
33-
"{%d,%s,%s,%s,%s}",
34-
stage.getCompletePercent(),
35-
stage.getName(),
36-
stage.getTitle(),
37-
stage.getType(),
38-
stage.getState()));
39-
assertThat(
40-
stagesString,
41-
is(
42-
String.join(
43-
"",
44-
"{50,unstable-one,unstable-one,STAGE,UNSTABLE},",
45-
"{50,success,success,STAGE,SUCCESS},",
46-
"{50,unstable-two,unstable-two,STAGE,UNSTABLE},",
47-
"{50,failure,failure,STAGE,FAILURE}")));
48-
}
49-
50-
@Test
51-
public void createGraph_complexSmokes() throws Exception {
52-
WorkflowRun run =
53-
TestUtils.createAndRunJob(j, "complexSmokes", "complexSmokes.jenkinsfile", Result.SUCCESS);
54-
PipelineGraphApi api = new PipelineGraphApi(run);
55-
PipelineGraph graph = api.createGraph();
56-
57-
List<PipelineStage> stages = graph.getStages();
58-
59-
String stagesString =
60-
TestUtils.collectStagesAsString(
61-
stages,
62-
(PipelineStage stage) ->
63-
String.format(
64-
"{%s,%s}",
65-
stage.getName(), Optional.ofNullable(stage.getSeqContainerName()).orElse("-")));
66-
67-
// As this is a graph view, and 'Branch C' doesn't have and steps, it doesn't get added as a
68-
// node.
69-
// Instead, its first child with steps 'Nested 1' gets added as a node, and all other children
70-
// get added as siblings. The 'getSeqContainerName' property of the 'Nested 1' now gets set to
71-
// its parent's display name ('Branch C') so the frontend can add a label.
72-
assertThat(
73-
stagesString,
74-
is(
75-
String.join(
76-
"",
77-
"{Non-Parallel Stage,-},",
78-
"{Parallel Stage,-}[{Branch A,-},{Branch B,-},{Nested 1,Branch C}],",
79-
"{Skipped stage,-},",
80-
"{Parallel Stage 2,-}[{Branch A,-},{Branch B,-},{Nested 1,Branch C}]")));
81-
}
82-
8317
@Test
8418
public void createTree_unstableSmokes() throws Exception {
8519
WorkflowRun run =

0 commit comments

Comments
 (0)