-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathOrkaAgent.java
More file actions
329 lines (269 loc) · 13.8 KB
/
OrkaAgent.java
File metadata and controls
329 lines (269 loc) · 13.8 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
package io.jenkins.plugins.orka;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.google.common.annotations.VisibleForTesting;
import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.TaskListener;
import hudson.slaves.AbstractCloudComputer;
import hudson.slaves.AbstractCloudSlave;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import io.jenkins.plugins.orka.helpers.CredentialsHelper;
import io.jenkins.plugins.orka.helpers.FormValidator;
import io.jenkins.plugins.orka.helpers.OrkaClientProxyFactory;
import io.jenkins.plugins.orka.helpers.OrkaInfoHelper;
import java.io.IOException;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.verb.POST;
public class OrkaAgent extends AbstractCloudSlave {
private static final long serialVersionUID = 6363583313270146174L;
public String orkaCredentialsId;
public String orkaEndpoint;
public String vmCredentialsId;
private boolean useJenkinsProxySettings;
private boolean ignoreSSLErrors;
private boolean createNewVMConfig;
private String vm;
private String node;
private String configName;
private String baseImage;
private int numCPUs;
private boolean useNetBoost;
private boolean useGpuPassthrough;
private String memory;
private boolean overwriteTag;
private String tag;
private Boolean tagRequired;
private String jvmOptions;
@Deprecated
public OrkaAgent(String name, String orkaCredentialsId, String orkaEndpoint, String vmCredentialsId, String vm,
String node, String redirectHost, boolean createNewVMConfig, String configName, String baseImage,
int numCPUs, int numExecutors, String host, int port, String remoteFS)
throws Descriptor.FormException, IOException {
this(name, orkaCredentialsId, orkaEndpoint, vmCredentialsId, vm, node, redirectHost, createNewVMConfig,
configName, baseImage, numCPUs, numExecutors, host, port, remoteFS, false, false, null);
}
@Deprecated
public OrkaAgent(String name, String orkaCredentialsId, String orkaEndpoint, String vmCredentialsId, String vm,
String node, String redirectHost, boolean createNewVMConfig, String configName, String baseImage,
int numCPUs, int numExecutors, String host, int port, String remoteFS,
boolean useJenkinsProxySettings, boolean ignoreSSLErrors)
throws Descriptor.FormException, IOException {
this(name, orkaCredentialsId, orkaEndpoint, vmCredentialsId, vm, node, redirectHost, createNewVMConfig,
configName, baseImage, numCPUs, numExecutors, host, port, remoteFS,
useJenkinsProxySettings, ignoreSSLErrors, null);
}
@Deprecated
public OrkaAgent(String name, String orkaCredentialsId, String orkaEndpoint, String vmCredentialsId, String vm,
String node, String redirectHost, boolean createNewVMConfig, String configName, String baseImage,
int numCPUs, int numExecutors, String host, int port, String remoteFS,
boolean useJenkinsProxySettings, boolean ignoreSSLErrors, String jvmOptions)
throws Descriptor.FormException, IOException {
this(name, orkaCredentialsId, orkaEndpoint, vmCredentialsId, vm, node, redirectHost, createNewVMConfig,
configName, baseImage, numCPUs, numExecutors, host, port, remoteFS,
useJenkinsProxySettings, ignoreSSLErrors, jvmOptions, "auto");
}
public OrkaAgent(String name, String orkaCredentialsId, String orkaEndpoint, String vmCredentialsId, String vm,
String node, String redirectHost, boolean createNewVMConfig, String configName, String baseImage,
int numCPUs, int numExecutors, String host, int port, String remoteFS,
boolean useJenkinsProxySettings, boolean ignoreSSLErrors, String jvmOptions, String memory)
throws Descriptor.FormException, IOException {
this(name, orkaCredentialsId, orkaEndpoint, vmCredentialsId, vm, node, redirectHost, createNewVMConfig,
configName, baseImage, numCPUs, false, false, numExecutors, host, port, remoteFS,
useJenkinsProxySettings, ignoreSSLErrors, jvmOptions, memory, false, null, null);
}
public OrkaAgent(String name, String orkaCredentialsId, String orkaEndpoint, String vmCredentialsId, String vm,
String node, String redirectHost, boolean createNewVMConfig, String configName, String baseImage,
int numCPUs, boolean useNetBoost, int numExecutors, String host,
int port, String remoteFS, boolean useJenkinsProxySettings, boolean ignoreSSLErrors, String jvmOptions,
String memory)
throws Descriptor.FormException, IOException {
this(name, orkaCredentialsId, orkaEndpoint, vmCredentialsId, vm, node, redirectHost, createNewVMConfig,
configName, baseImage, numCPUs, useNetBoost, false, numExecutors, host, port, remoteFS,
useJenkinsProxySettings, ignoreSSLErrors, jvmOptions, memory, false, null, null);
}
public OrkaAgent(String name, String orkaCredentialsId, String orkaEndpoint, String vmCredentialsId, String vm,
String node, String redirectHost, boolean createNewVMConfig, String configName, String baseImage,
int numCPUs, boolean useNetBoost, int numExecutors, String host,
int port, String remoteFS, boolean useJenkinsProxySettings, boolean ignoreSSLErrors, String jvmOptions,
String memory, boolean overwriteTag, String tag, Boolean tagRequired)
throws Descriptor.FormException, IOException {
this(name, orkaCredentialsId, orkaEndpoint, vmCredentialsId, vm, node, redirectHost, createNewVMConfig,
configName, baseImage, numCPUs, useNetBoost, false, numExecutors, host, port, remoteFS,
useJenkinsProxySettings, ignoreSSLErrors, jvmOptions, memory, overwriteTag, tag, tagRequired);
}
@DataBoundConstructor
public OrkaAgent(String name, String orkaCredentialsId, String orkaEndpoint, String vmCredentialsId, String vm,
String node, String redirectHost, boolean createNewVMConfig, String configName, String baseImage,
int numCPUs, boolean useNetBoost, boolean useGpuPassthrough, int numExecutors, String host,
int port, String remoteFS, boolean useJenkinsProxySettings, boolean ignoreSSLErrors, String jvmOptions,
String memory, boolean overwriteTag, String tag, Boolean tagRequired)
throws Descriptor.FormException, IOException {
super(name, remoteFS, new OrkaComputerLauncher(host, port, redirectHost, jvmOptions));
this.orkaCredentialsId = orkaCredentialsId;
this.orkaEndpoint = orkaEndpoint;
this.vmCredentialsId = vmCredentialsId;
this.vm = vm;
this.node = node;
this.createNewVMConfig = createNewVMConfig;
this.configName = configName;
this.baseImage = baseImage;
this.numCPUs = numCPUs;
this.useNetBoost = useNetBoost;
this.useGpuPassthrough = useGpuPassthrough;
this.useJenkinsProxySettings = useJenkinsProxySettings;
this.ignoreSSLErrors = ignoreSSLErrors;
this.jvmOptions = jvmOptions;
this.memory = memory;
this.overwriteTag = overwriteTag;
this.tag = this.overwriteTag ? tag : null;
this.tagRequired = this.overwriteTag ? tagRequired : null;
this.setNumExecutors(numExecutors);
}
public String getOrkaCredentialsId() {
return this.orkaCredentialsId;
}
public String getOrkaEndpoint() {
return this.orkaEndpoint;
}
public String getVmCredentialsId() {
return this.vmCredentialsId;
}
public boolean getUseJenkinsProxySettings() {
return this.useJenkinsProxySettings;
}
public boolean getIgnoreSSLErrors() {
return this.ignoreSSLErrors;
}
public boolean getCreateNewVMConfig() {
return this.createNewVMConfig;
}
public String getVm() {
return this.vm;
}
public String getNode() {
return this.node;
}
public String getConfigName() {
return this.configName;
}
public String getBaseImage() {
return this.baseImage;
}
public int getNumCPUs() {
return this.numCPUs;
}
public boolean getUseNetBoost() {
return this.useNetBoost;
}
public boolean getUseGpuPassthrough() {
return this.useGpuPassthrough;
}
public String getMemory() {
return this.memory;
}
public boolean getOverwriteTag() {
return this.overwriteTag;
}
public String getTag() {
return this.tag;
}
public Boolean getTagRequired() {
return this.tagRequired;
}
public String getJvmOptions() {
return this.jvmOptions;
}
@Override
public AbstractCloudComputer createComputer() {
return new OrkaComputer(this);
}
@Override
protected void _terminate(TaskListener listener) throws IOException, InterruptedException {
}
@Extension
public static final class DescriptorImpl extends SlaveDescriptor {
private OrkaClientProxyFactory clientProxyFactory = new OrkaClientProxyFactory();
private FormValidator formValidator = new FormValidator(clientProxyFactory);
private OrkaInfoHelper infoHelper = new OrkaInfoHelper(clientProxyFactory);
public DescriptorImpl() {
load();
}
@VisibleForTesting
void setClientProxyFactory(OrkaClientProxyFactory clientProxyFactory) {
this.clientProxyFactory = clientProxyFactory;
this.formValidator = new FormValidator(this.clientProxyFactory);
this.infoHelper = new OrkaInfoHelper(this.clientProxyFactory);
}
public String getDisplayName() {
return "Agent running under Orka by MacStadium";
}
@Override
public boolean isInstantiable() {
return true;
}
@POST
public FormValidation doCheckConfigName(@QueryParameter String configName, @QueryParameter String orkaEndpoint,
@QueryParameter String orkaCredentialsId, @QueryParameter boolean useJenkinsProxySettings,
@QueryParameter boolean ignoreSSLErrors, @QueryParameter boolean createNewVMConfig) {
return this.formValidator.doCheckConfigName(configName, orkaEndpoint, orkaCredentialsId,
useJenkinsProxySettings, ignoreSSLErrors, createNewVMConfig);
}
@POST
public FormValidation doCheckNode(@QueryParameter String value, @QueryParameter String orkaEndpoint,
@QueryParameter String orkaCredentialsId, @QueryParameter boolean useJenkinsProxySettings,
@QueryParameter boolean ignoreSSLErrors, @QueryParameter String vm,
@QueryParameter boolean createNewVMConfig, @QueryParameter int numCPUs) {
return this.formValidator.doCheckNode(value, orkaEndpoint, orkaCredentialsId,
useJenkinsProxySettings, ignoreSSLErrors, vm, createNewVMConfig, numCPUs);
}
@POST
public FormValidation doCheckMemory(@QueryParameter String memory) {
return this.formValidator.doCheckMemory(memory);
}
public ListBoxModel doFillOrkaCredentialsIdItems() {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
return CredentialsHelper.getCredentials(StandardCredentials.class);
}
public ListBoxModel doFillVmCredentialsIdItems() {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
return CredentialsHelper.getCredentials(StandardCredentials.class);
}
@POST
public ListBoxModel doFillNodeItems(@QueryParameter String orkaEndpoint,
@QueryParameter String orkaCredentialsId, @QueryParameter boolean useJenkinsProxySettings,
@QueryParameter boolean ignoreSSLErrors) {
return this.infoHelper.doFillNodeItems(orkaEndpoint, orkaCredentialsId, useJenkinsProxySettings,
ignoreSSLErrors);
}
public ListBoxModel doFillNumCPUsItems() {
return this.infoHelper.doFillNumCPUsItems();
}
@POST
public ListBoxModel doFillVmItems(@QueryParameter String orkaEndpoint, @QueryParameter String orkaCredentialsId,
@QueryParameter boolean useJenkinsProxySettings, @QueryParameter boolean ignoreSSLErrors,
@QueryParameter boolean createNewVMConfig) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
return this.infoHelper.doFillVmItems(orkaEndpoint, orkaCredentialsId, useJenkinsProxySettings,
ignoreSSLErrors, createNewVMConfig);
}
@POST
public ListBoxModel doFillBaseImageItems(@QueryParameter String orkaEndpoint,
@QueryParameter String orkaCredentialsId, @QueryParameter boolean useJenkinsProxySettings,
@QueryParameter boolean ignoreSSLErrors, @QueryParameter boolean createNewVMConfig) {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
return this.infoHelper.doFillBaseImageItems(orkaEndpoint, orkaCredentialsId, useJenkinsProxySettings,
ignoreSSLErrors, createNewVMConfig);
}
@POST
public FormValidation doTestConnection(@QueryParameter String orkaCredentialsId,
@QueryParameter String orkaEndpoint, @QueryParameter boolean useJenkinsProxySettings,
@QueryParameter boolean ignoreSSLErrors)
throws IOException {
return this.formValidator.doTestConnection(orkaCredentialsId, orkaEndpoint, useJenkinsProxySettings,
ignoreSSLErrors);
}
}
}