/
DistForkTask.java
151 lines (121 loc) · 3.4 KB
/
DistForkTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package hudson.plugins.distfork;
import hudson.model.Queue.Item;
import hudson.model.Queue.Task;
import hudson.model.Queue.Executable;
import hudson.model.Label;
import hudson.model.Node;
import hudson.model.ResourceList;
import hudson.model.Hudson;
import hudson.model.AbstractProject;
import hudson.model.queue.CauseOfBlockage;
import hudson.model.queue.SubTask;
import hudson.security.ACL;
import jenkins.model.Jenkins;
import org.acegisecurity.Authentication;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
/**
* {@link Task} that represents a distfork work.
*
* <p>
* TODO: once we authenticate the CLI client, allow that user to abort.
*
* @author Kohsuke Kawaguchi
*/
public class DistForkTask implements Task {
private final Label label;
private final String displayName;
private final long estimatedDuration;
private final Runnable runnable;
private final Authentication auth;
public DistForkTask(Label label, String displayName, long estimatedDuration, Runnable runnable) {
this.label = label;
this.displayName = displayName;
this.estimatedDuration = estimatedDuration;
this.runnable = runnable;
this.auth = Jenkins.getAuthentication();
}
public Label getAssignedLabel() {
return label;
}
public Node getLastBuiltOn() {
return null;
}
public boolean isBuildBlocked() {
return false;
}
public String getWhyBlocked() {
return null;
}
public String getName() {
return getDisplayName();
}
public String getFullDisplayName() {
return getDisplayName();
}
public long getEstimatedDuration() {
return estimatedDuration;
}
public Executable createExecutable() throws IOException {
return new Executable() {
public SubTask getParent() {
return DistForkTask.this;
}
public void run() {
runnable.run();
}
public long getEstimatedDuration() {
return estimatedDuration;
}
@Override
public String toString() {
return displayName;
}
};
}
public void checkAbortPermission() {
getACL().checkPermission(AbstractProject.ABORT);
}
public boolean hasAbortPermission() {
return getACL().hasPermission(AbstractProject.ABORT);
}
private ACL getACL() {
return Hudson.getInstance().getACL();
}
public String getUrl() {
return null;
}
public String getDisplayName() {
return displayName;
}
public ResourceList getResourceList() {
return new ResourceList();
}
public CauseOfBlockage getCauseOfBlockage() {
// not blocked at any time
return null;
}
public boolean isConcurrentBuild() {
// concurrently buildable
return true;
}
public Collection<? extends SubTask> getSubTasks() {
return Collections.singleton(this);
}
public Task getOwnerTask() {
return this;
}
public Object getSameNodeConstraint() {
return null;
}
@Nonnull
public Authentication getDefaultAuthentication() {
return auth;
}
@Override
public Authentication getDefaultAuthentication(Item item) {
return auth;
}
}