/
vSphereCloud.java
660 lines (582 loc) · 26.2 KB
/
vSphereCloud.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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.jenkinsci.plugins;
import com.cloudbees.hudson.plugins.folder.AbstractFolderProperty;
import com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor;
import com.cloudbees.hudson.plugins.folder.Folder;
import hudson.Extension;
import hudson.model.*;
import hudson.model.Descriptor.FormException;
import hudson.slaves.Cloud;
import hudson.slaves.NodeProvisioner.PlannedNode;
import hudson.slaves.SlaveComputer;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import hudson.util.StreamTaskListener;
import jenkins.model.Jenkins;
import jenkins.slaves.iterators.api.NodeIterator;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.jenkinsci.plugins.folder.FolderVSphereCloudProperty;
import org.jenkinsci.plugins.vsphere.VSphereConnectionConfig;
import org.jenkinsci.plugins.vsphere.tools.*;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import javax.annotation.CheckForNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Future;
import java.util.logging.Level;
/**
* @author Admin
*/
public class vSphereCloud extends Cloud {
@Deprecated
private transient String vsHost;
private final String vsDescription;
@Deprecated
private transient String username;
@Deprecated
private transient String password;
private final int maxOnlineSlaves;
private
@CheckForNull
VSphereConnectionConfig vsConnectionConfig;
private final int instanceCap;
private final List<? extends vSphereCloudSlaveTemplate> templates;
private transient int currentOnlineSlaveCount = 0;
private transient ConcurrentHashMap<String, String> currentOnline;
private transient CloudProvisioningState templateState;
private static java.util.logging.Logger VSLOG = java.util.logging.Logger.getLogger("vsphere-cloud");
private static void InternalLog(Slave slave, SlaveComputer slaveComputer, TaskListener listener, Throwable ex, String format, Object... args) {
final Level logLevel = Level.INFO;
if (!VSLOG.isLoggable(logLevel) && listener == null)
return;
String s = "";
if (slave != null)
s = String.format("[%s] ", slave.getNodeName());
if (slaveComputer != null)
s = String.format("[%s] ", slaveComputer.getName());
s = s + String.format(format, args);
if (listener != null) {
listener.getLogger().print(s + "\n");
if (ex != null) {
listener.getLogger().print(ex.toString() + "\n");
ex.printStackTrace(listener.getLogger());
}
}
if (ex != null) {
VSLOG.log(logLevel, s, ex);
} else {
VSLOG.log(logLevel, s);
}
}
public static void Log(String format, Object... args) {
InternalLog(null, null, null, null, format, args);
}
public static void Log(Throwable ex, String format, Object... args) {
InternalLog(null, null, null, ex, format, args);
}
public static void Log(TaskListener listener, String format, Object... args) {
InternalLog(null, null, listener, null, format, args);
}
public static void Log(TaskListener listener, Throwable ex, String format, Object... args) {
InternalLog(null, null, listener, ex, format, args);
}
public static void Log(Slave slave, String format, Object... args) {
InternalLog(slave, null, null, null, format, args);
}
public static void Log(Slave slave, Throwable ex, String format, Object... args) {
InternalLog(slave, null, null, ex, format, args);
}
public static void Log(Slave slave, TaskListener listener, String format, Object... args) {
InternalLog(slave, null, listener, null, format, args);
}
public static void Log(Slave slave, TaskListener listener, Throwable ex, String format, Object... args) {
InternalLog(slave, null, listener, ex, format, args);
}
public static void Log(SlaveComputer slave, TaskListener listener, String format, Object... args) {
InternalLog(null, slave, listener, null, format, args);
}
public static void Log(SlaveComputer slave, TaskListener listener, Throwable ex, String format, Object... args) {
InternalLog(null, slave, listener, ex, format, args);
}
@Deprecated
public vSphereCloud(String vsHost, String vsDescription,
String username, String password, int maxOnlineSlaves) {
this(null, vsDescription, maxOnlineSlaves, 0, null);
}
@DataBoundConstructor
public vSphereCloud(VSphereConnectionConfig vsConnectionConfig, String vsDescription, int maxOnlineSlaves, int instanceCap, List<? extends vSphereCloudSlaveTemplate> templates) {
super("vSphereCloud");
this.vsDescription = vsDescription;
this.maxOnlineSlaves = maxOnlineSlaves;
this.vsConnectionConfig = vsConnectionConfig;
if (templates == null) {
this.templates = Collections.emptyList();
} else {
this.templates = templates;
}
if (instanceCap == 0) {
this.instanceCap = Integer.MAX_VALUE;
} else {
this.instanceCap = instanceCap;
}
try {
readResolve();
} catch (IOException ioex) {
//do nothing;
}
Log("STARTING VSPHERE CLOUD");
}
public Object readResolve() throws IOException {
if (vsConnectionConfig == null) {
vsConnectionConfig = new VSphereConnectionConfig(vsHost, null);
}
if (this.templates != null) {
for (vSphereCloudSlaveTemplate template : templates) {
template.parent = this;
}
}
return this;
}
private void ensureLists() {
if (currentOnline == null)
currentOnline = new ConcurrentHashMap<String, String>();
if (templateState == null) {
/*
* If Jenkins has just restarted, we may have existing slaves that
* exist but aren't currently recorded in our non-persisted state,
* so we need to discover them.
*/
templateState = new CloudProvisioningState(this);
for (final vSphereCloudProvisionedSlave n : NodeIterator.nodes(vSphereCloudProvisionedSlave.class)) {
final String nodeName = n.getNodeName();
final vSphereCloudSlaveTemplate template = getTemplateForVM(nodeName);
if (template != null) {
final CloudProvisioningRecord provisionable = templateState.getOrCreateRecord(template);
templateState.provisioningStarted(provisionable, nodeName);
templateState.provisionedSlaveNowActive(provisionable, nodeName);
}
}
}
}
public int getMaxOnlineSlaves() {
return maxOnlineSlaves;
}
public int getInstanceCap() {
return this.instanceCap;
}
public List<? extends vSphereCloudSlaveTemplate> getTemplates() {
return this.templates;
}
private vSphereCloudSlaveTemplate getTemplateForVM(final String vmName) {
if (this.templates == null || vmName == null)
return null;
for (final vSphereCloudSlaveTemplate t : this.templates) {
final String cloneNamePrefix = t.getCloneNamePrefix();
if (cloneNamePrefix != null && vmName.startsWith(cloneNamePrefix)) {
return t;
}
}
return null;
}
private List<vSphereCloudSlaveTemplate> getTemplates(final Label label) {
if (this.templates == null)
return Collections.emptyList();
List<vSphereCloudSlaveTemplate> matchingTemplates = new ArrayList<vSphereCloudSlaveTemplate>();
for (vSphereCloudSlaveTemplate t : this.templates) {
if (t.getMode() == Node.Mode.NORMAL) {
if (label == null || label.matches(t.getLabelSet())) {
matchingTemplates.add(t);
}
} else if (t.getMode() == Node.Mode.EXCLUSIVE) {
if (label != null && label.matches(t.getLabelSet())) {
matchingTemplates.add(t);
}
}
}
return matchingTemplates;
}
public
@CheckForNull
String getPassword() {
return vsConnectionConfig != null ? vsConnectionConfig.getPassword() : null;
}
public
@CheckForNull
String getUsername() {
return vsConnectionConfig != null ? vsConnectionConfig.getUsername() : null;
}
public String getVsDescription() {
return vsDescription;
}
public
@CheckForNull
String getVsHost() {
return vsConnectionConfig != null ? vsConnectionConfig.getVsHost() : null;
}
public
@CheckForNull
VSphereConnectionConfig getVsConnectionConfig() {
return vsConnectionConfig;
}
public final int getHash() {
return new HashCodeBuilder(67, 89).
append(getVsDescription()).
append(getVsHost()).
toHashCode();
}
public VSphere vSphereInstance() throws VSphereException {
// TODO: validate configs
final String effectiveVsHost = getVsHost();
if (effectiveVsHost == null) {
throw new VSphereException("vSphere host is not specified");
}
final String effectiveUserName = getUsername();
if (effectiveUserName == null) {
throw new VSphereException("vSphere username is not specified");
}
return VSphere.connect(effectiveVsHost + "/sdk", effectiveUserName, getPassword());
}
@Override
public boolean canProvision(Label label) {
return !getTemplates(label).isEmpty();
}
private Integer calculateMaxAdditionalSlavesPermitted() {
if (this.instanceCap == 0 || this.instanceCap == Integer.MAX_VALUE) {
return null;
}
final int totalVms = templateState.countNodes();
final int maxSlavesToProvision = this.instanceCap - totalVms;
final boolean thereIsNoRoom = maxSlavesToProvision <= 0;
VSLOG.info("There are " + totalVms + " VMs in this cloud. The instance cap for the cloud is "
+ this.instanceCap + ", so we " + (thereIsNoRoom ? "are full" : "have room for more"));
return Integer.valueOf(maxSlavesToProvision);
}
@Override
public Collection<PlannedNode> provision(final Label label, int excessWorkload) {
final String methodCallDescription = "provision(" + label + "," + excessWorkload + ")";
try {
int excessWorkloadSoFar = excessWorkload;
// First we see what our static slaves can do for us.
int numberOfvSphereCloudSlaves = 0;
int numberOfvSphereCloudSlaveExecutors = 0;
for (vSphereCloudSlave n : NodeIterator.nodes(vSphereCloudSlave.class)) {
if (n instanceof vSphereCloudProvisionedSlave) {
continue; // ignore cloud slaves
}
if (n.getComputer().isOffline() && label.matches(n.getAssignedLabels())) {
n.getComputer().tryReconnect();
numberOfvSphereCloudSlaves++;
numberOfvSphereCloudSlaveExecutors += n.getNumExecutors();
}
}
excessWorkloadSoFar -= numberOfvSphereCloudSlaveExecutors;
if (excessWorkloadSoFar <= 0) {
VSLOG.log(Level.INFO, methodCallDescription + ": " + numberOfvSphereCloudSlaves + " existing slaves (="
+ numberOfvSphereCloudSlaveExecutors + " executors): Workload is satisifed by bringing those online.");
return Collections.emptySet();
}
// If we've got this far then our static slaves are insufficient to meet
// demand and we should consider creating new slaves.
synchronized (this) {
ensureLists();
}
final List<PlannedNode> plannedNodes = new ArrayList<PlannedNode>();
synchronized (templateState) {
templateState.pruneUnwantedRecords();
Integer maxSlavesToProvisionBeforeCloudCapHit = calculateMaxAdditionalSlavesPermitted();
if (maxSlavesToProvisionBeforeCloudCapHit != null && maxSlavesToProvisionBeforeCloudCapHit <= 0) {
return Collections.emptySet(); // no capacity due to cloud instance cap
}
final List<vSphereCloudSlaveTemplate> templates = getTemplates(label);
final List<CloudProvisioningRecord> whatWeCouldUse = templateState.calculateProvisionableTemplates(templates);
VSLOG.log(Level.INFO, methodCallDescription + ": " + numberOfvSphereCloudSlaves + " existing slaves (="
+ numberOfvSphereCloudSlaveExecutors + " executors), templates available are " + whatWeCouldUse);
while (excessWorkloadSoFar > 0) {
if (maxSlavesToProvisionBeforeCloudCapHit != null) {
final int intValue = maxSlavesToProvisionBeforeCloudCapHit.intValue();
if (intValue <= 0) {
break; // out of capacity due to cloud instance cap
}
maxSlavesToProvisionBeforeCloudCapHit = Integer.valueOf(intValue - 1);
}
final CloudProvisioningRecord whatWeShouldSpinUp = CloudProvisioningAlgorithm.findTemplateWithMostFreeCapacity(whatWeCouldUse);
if (whatWeShouldSpinUp == null) {
break; // out of capacity due to template instance cap
}
final String nodeName = CloudProvisioningAlgorithm.findUnusedName(whatWeShouldSpinUp);
final PlannedNode plannedNode = VSpherePlannedNode.createInstance(templateState, nodeName, whatWeShouldSpinUp);
plannedNodes.add(plannedNode);
excessWorkloadSoFar -= plannedNode.numExecutors;
}
}
VSLOG.log(Level.INFO, methodCallDescription + ": Provisioning " + plannedNodes.size()
+ " new =" + plannedNodes);
return plannedNodes;
} catch (Exception ex) {
VSLOG.log(Level.WARNING, methodCallDescription + ": Failed.", ex);
return Collections.emptySet();
}
}
/**
* This is called by {@link vSphereCloudProvisionedSlave} instances once
* they terminate, so we can take note of their passing and then destroy the
* VM itself.
*
* @param cloneName The name of the VM that's just terminated.
*/
void provisionedSlaveHasTerminated(final String cloneName) {
synchronized (this) {
ensureLists();
}
VSLOG.log(Level.FINER, "provisionedSlaveHasTerminated({0}): recording in our runtime state...", cloneName);
// once we're done, remove our cached record.
synchronized (templateState) {
templateState.provisionedSlaveNowTerminated(cloneName);
}
VSLOG.log(Level.FINER, "provisionedSlaveHasTerminated({0}): destroying VM...", cloneName);
VSphere vSphere = null;
try {
vSphere = vSphereInstance();
vSphere.destroyVm(cloneName, false);
VSLOG.log(Level.FINER, "provisionedSlaveHasTerminated({0}): VM destroyed.", cloneName);
} catch (VSphereException ex) {
VSLOG.log(Level.SEVERE, "provisionedSlaveHasTerminated(" + cloneName + "): Exception while trying to destroy VM", ex);
} finally {
if (vSphere != null) {
vSphere.disconnect();
}
}
}
static class VSpherePlannedNode extends PlannedNode {
private VSpherePlannedNode(String displayName, Future<Node> future, int numExecutors) {
super(displayName, future, numExecutors);
}
public static VSpherePlannedNode createInstance(final CloudProvisioningState templateState,
final String nodeName,
final CloudProvisioningRecord whatWeShouldSpinUp) {
final vSphereCloudSlaveTemplate template = whatWeShouldSpinUp.getTemplate();
final int numberOfExecutors = template.getNumberOfExecutors();
final Callable<Node> provisionNodeCallable = new Callable<Node>() {
public Node call() throws Exception {
try {
final Node newNode = provisionNewNode(whatWeShouldSpinUp, nodeName);
VSLOG.log(Level.INFO, "Provisioned new slave " + nodeName);
synchronized (templateState) {
templateState.provisionedSlaveNowActive(whatWeShouldSpinUp, nodeName);
}
return newNode;
} catch (Exception ex) {
VSLOG.log(Level.WARNING, "Failed to provision new slave " + nodeName, ex);
synchronized (templateState) {
templateState.provisioningEndedInError(whatWeShouldSpinUp, nodeName);
}
throw ex;
}
}
};
templateState.provisioningStarted(whatWeShouldSpinUp, nodeName);
final Future<Node> provisionNodeTask = Computer.threadPoolForRemoting.submit(provisionNodeCallable);
final VSpherePlannedNode result = new VSpherePlannedNode(nodeName, provisionNodeTask, numberOfExecutors);
return result;
}
private static Node provisionNewNode(final CloudProvisioningRecord whatWeShouldSpinUp, final String cloneName)
throws VSphereException, FormException, IOException, InterruptedException {
final vSphereCloudSlaveTemplate template = whatWeShouldSpinUp.getTemplate();
final vSphereCloudProvisionedSlave slave = template.provision(cloneName, StreamTaskListener.fromStdout());
// ensure Jenkins knows about us before we forget what we're doing,
// otherwise it'll just ask for more.
Jenkins.getInstance().addNode(slave);
return slave;
}
@Override
public String toString() {
return displayName;
}
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("vSphereCloud");
sb.append("{Host='").append(getVsHost()).append('\'');
sb.append(", Description='").append(vsDescription).append('\'');
sb.append('}');
return sb.toString();
}
public synchronized Boolean canMarkVMOnline(String slaveName, String vmName) {
ensureLists();
// Don't allow more than max.
if ((maxOnlineSlaves > 0) && (currentOnline.size() == maxOnlineSlaves))
return Boolean.FALSE;
// Don't allow two slaves to the same VM to fire up.
// With templates the vmName will be the same. So first verify if the slave is from a template
if (currentOnline.containsValue(vmName))
return Boolean.FALSE;
// TODO: what we want here is to validate the instance cap of both the cloud and the template (if the slave is created from a template);
// Don't allow two instances of the same slave, although Jenkins will
// probably not encounter this.
if (currentOnline.containsKey(slaveName))
return Boolean.FALSE;
return Boolean.TRUE;
}
public synchronized Boolean markVMOnline(String slaveName, String vmName) {
ensureLists();
// If the combination is already in the list, it's good.
if (currentOnline.containsKey(slaveName) && currentOnline.get(slaveName).equals(vmName))
return Boolean.TRUE;
if (!canMarkVMOnline(slaveName, vmName))
return Boolean.FALSE;
currentOnline.put(slaveName, vmName);
currentOnlineSlaveCount++;
return Boolean.TRUE;
}
public synchronized void markVMOffline(String slaveName, String vmName) {
ensureLists();
if (currentOnline.remove(slaveName) != null)
currentOnlineSlaveCount--;
}
public static List<vSphereCloud> findAllVsphereClouds(String jobName) {
List<vSphereCloud> vSphereClouds = new ArrayList<vSphereCloud>();
String[] path = new String[0];
Folder prevFolder = null;
if (Stapler.getCurrentRequest() != null){
path = Stapler.getCurrentRequest().getRequestURI().split("/");
} else if (jobName != null) {
path = jobName.split("/");
}
for (String item : path) {
if (item.equals("job") || item.equals("jenkins"))
continue;
TopLevelItem topLevelItem = null;
if (prevFolder == null) {
topLevelItem = Jenkins.getActiveInstance().getItem(item);
} else {
Collection<TopLevelItem> items = prevFolder.getItems();
for (TopLevelItem levelItem : items) {
if (levelItem.getName().endsWith(item)){
topLevelItem = levelItem;
}
}
}
if (topLevelItem != null && topLevelItem instanceof Folder) {
extractClouds(vSphereClouds, (Folder) topLevelItem);
}
}
for (Cloud cloud : Jenkins.getInstance().clouds) {
if (cloud instanceof vSphereCloud) {
vSphereClouds.add((vSphereCloud) cloud);
}
}
return vSphereClouds;
}
private static void extractClouds(List<vSphereCloud> vSphereClouds, Folder folder) {
DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties = folder.getProperties();
for (AbstractFolderProperty<?> property : properties) {
if (property instanceof FolderVSphereCloudProperty) {
vSphereClouds.addAll(((FolderVSphereCloudProperty) property).getVsphereClouds());
}
}
}
public static List<String> findAllVsphereCloudNames() {
List<String> cloudNames = new ArrayList<String>();
for (org.jenkinsci.plugins.vSphereCloud vSphereCloud : findAllVsphereClouds(null)) {
cloudNames.add(vSphereCloud.getVsDescription());
}
return cloudNames;
}
@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}
@Extension
public static final class DescriptorImpl extends Descriptor<Cloud> {
public final
@Deprecated
ConcurrentMap<String, vSphereCloud> hypervisors = new ConcurrentHashMap<String, vSphereCloud>();
private
@Deprecated
String vsHost;
private
@Deprecated
String username;
private
@Deprecated
String password;
private
@Deprecated
int maxOnlineSlaves;
@Override
public String getDisplayName() {
return "vSphere Cloud";
}
@Override
public boolean configure(StaplerRequest req, JSONObject o)
throws FormException {
vsHost = o.getString("vsHost");
username = o.getString("username");
password = o.getString("password");
maxOnlineSlaves = o.getInt("maxOnlineSlaves");
save();
return super.configure(req, o);
}
/**
* For UI.
*
* @param vsHost From UI.
* @param vsDescription From UI.
* @param credentialsId From UI.
* @return Result of the validation.
*/
public FormValidation doTestConnection(@QueryParameter String vsHost,
@QueryParameter String vsDescription,
@QueryParameter String credentialsId) {
try {
/* We know that these objects are not null */
if (vsHost.length() == 0) {
return FormValidation.error("vSphere Host is not specified");
} else {
/* Perform other sanity checks. */
if (!vsHost.startsWith("https://")) {
return FormValidation.error("vSphere host must start with https://");
} else if (vsHost.endsWith("/")) {
return FormValidation.error("vSphere host name must NOT end with a trailing slash");
}
}
final VSphereConnectionConfig config = new VSphereConnectionConfig(vsHost, credentialsId);
final String effectiveUsername = config.getUsername();
final String effectivePassword = config.getPassword();
if (StringUtils.isEmpty(effectiveUsername)) {
return FormValidation.error("Username is not specified");
}
if (StringUtils.isEmpty(effectivePassword)) {
return FormValidation.error("Password is not specified");
}
VSphere.connect(vsHost + "/sdk", effectiveUsername, effectivePassword).disconnect();
return FormValidation.ok("Connected successfully");
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public FormValidation doCheckMaxOnlineSlaves(@QueryParameter String maxOnlineSlaves) {
return FormValidation.validateNonNegativeInteger(maxOnlineSlaves);
}
public FormValidation doCheckInstanceCap(@QueryParameter String instanceCap) {
return FormValidation.validateNonNegativeInteger(instanceCap);
}
}
}