Skip to content

Commit

Permalink
[Fix JENKINS-33486] Replace FlowNodeNavigator with FlowGraphWalker
Browse files Browse the repository at this point in the history
  • Loading branch information
tfennelly committed Mar 11, 2016
1 parent 37e3c1c commit 59eed49
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 119 deletions.

This file was deleted.

Expand Up @@ -29,6 +29,7 @@
import org.jenkinsci.plugins.workflow.actions.TimingAction;
import org.jenkinsci.plugins.workflow.actions.WorkspaceAction;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.support.actions.PauseAction;

Expand Down Expand Up @@ -299,15 +300,12 @@ public static List<FlowNode> getStageNodes(FlowNode node) {
public static List<FlowNode> getChildNodes(final FlowNode parentNode) {
final List<FlowNode> nodes = new ArrayList<FlowNode>();

FlowNodeNavigator nodeNavigator = new FlowNodeNavigator(new FlowNodeNavigationListener() {
@Override
public void onNode(FlowNode navNode) {
if (navNode.getParents().contains(parentNode) && !nodes.contains(navNode)) {
nodes.add(navNode);
}
FlowGraphWalker walker = new FlowGraphWalker(parentNode.getExecution());
for (FlowNode node : walker) {
if (node.getParents().contains(parentNode) && !nodes.contains(node)) {
nodes.add(node);
}
});
nodeNavigator.navigate(parentNode.getExecution().getCurrentHeads());
}
sortNodesById(nodes);

return nodes;
Expand Down Expand Up @@ -347,16 +345,13 @@ static List<FlowNode> getUnsortedSortedExecutionNodeList(List<FlowNode> nodeList

// Gather all the nodes from the workflow
final List<FlowNode> unsortedNodes = new ArrayList<FlowNode>();
FlowNodeNavigator nodeNavigator = new FlowNodeNavigator(new FlowNodeNavigationListener() {
@Override
public void onNode(FlowNode node) {
if (!unsortedNodes.contains(node)) {
unsortedNodes.add(node);
}
FlowGraphWalker walker = new FlowGraphWalker(nodeList.get(0).getExecution());
for (FlowNode node : walker) {
if (!unsortedNodes.contains(node)) {
unsortedNodes.add(node);
}
});
}

nodeNavigator.navigate(nodeList);
cacheAction.unsortedNodeList = unsortedNodes;

return cacheAction.unsortedNodeList;
Expand Down
Expand Up @@ -23,15 +23,14 @@
*/
package com.cloudbees.workflow.rest.external;

import com.cloudbees.workflow.flownode.FlowNodeNavigationListener;
import com.cloudbees.workflow.flownode.FlowNodeNavigator;
import com.cloudbees.workflow.rest.endpoints.RunAPI;
import com.cloudbees.workflow.rest.hal.Link;
import com.cloudbees.workflow.rest.hal.Links;
import com.fasterxml.jackson.annotation.JsonInclude;
import hudson.model.Run;
import org.jenkinsci.plugins.workflow.actions.TimingAction;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.graph.FlowGraphWalker;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
Expand Down Expand Up @@ -211,25 +210,22 @@ public static RunExt create(WorkflowRun run) {
runExt.get_links().setArtifacts(Link.newLink(RunAPI.getArtifactsUrl(run)));
}

FlowNodeNavigator nodeNavigator = new FlowNodeNavigator(new FlowNodeNavigationListener() {
@Override
public void onNode(FlowNode node) {
long nodeTime = TimingAction.getStartTime(node);

if (nodeTime > runExt.getEndTimeMillis()) {
// Use the most resent FlowNode timestamp as being
// the end time for the run.
runExt.setEndTimeMillis(nodeTime);
}

if (StageNodeExt.isStageNode(node)) {
StageNodeExt stage = StageNodeExt.create(node);
runExt.addStage(stage);
runExt.setPauseDurationMillis(runExt.getPauseDurationMillis() + stage.getPauseDurationMillis());
}
FlowGraphWalker walker = new FlowGraphWalker(run.getExecution());
for (FlowNode node : walker) {
long nodeTime = TimingAction.getStartTime(node);

if (nodeTime > runExt.getEndTimeMillis()) {
// Use the most resent FlowNode timestamp as being
// the end time for the run.
runExt.setEndTimeMillis(nodeTime);
}

if (StageNodeExt.isStageNode(node)) {
StageNodeExt stage = StageNodeExt.create(node);
runExt.addStage(stage);
runExt.setPauseDurationMillis(runExt.getPauseDurationMillis() + stage.getPauseDurationMillis());
}
});
nodeNavigator.navigate(execution.getCurrentHeads());
}

if (!runExt.getStages().isEmpty()) {
runExt.sortStages();
Expand Down

0 comments on commit 59eed49

Please sign in to comment.