-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the code to address comments
* Use native logic that takes into account state of the nodes
- Loading branch information
nkorabli
committed
May 28, 2021
1 parent
1cbedb6
commit 3fe45d5
Showing
7 changed files
with
114 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 0 additions & 91 deletions
91
src/main/java/org/jenkinsci/plugins/vsphere/VSphereNodeReconcileWork.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
src/main/java/org/jenkinsci/plugins/vsphere/VSpherePreProvisonWork.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.jenkinsci.plugins.vsphere; | ||
|
||
import hudson.Extension; | ||
import hudson.Functions; | ||
import hudson.model.TaskListener; | ||
import hudson.model.AsyncPeriodicWork; | ||
import hudson.slaves.Cloud; | ||
import jenkins.model.Jenkins; | ||
import org.jenkinsci.plugins.vSphereCloud; | ||
import org.jenkinsci.plugins.vSphereCloudSlaveTemplate; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
/** | ||
* A {@link AsyncPeriodicWork} that pre-provisions nodes to meet insntanceMin template value. | ||
* <p> | ||
* The async work will check the number of active nodes | ||
* and provision additional ones to meet template values. | ||
* | ||
* The check is happening every 2 minutes. | ||
*/ | ||
@Extension | ||
@Restricted(NoExternalUse.class) | ||
public final class VSpherePreProvisonWork extends AsyncPeriodicWork { | ||
private static final Logger LOGGER = Logger.getLogger(VSpherePreProvisonWork.class.getName()); | ||
|
||
public VSpherePreProvisonWork() { | ||
super("Vsphere pre-provision check"); | ||
} | ||
|
||
@Override | ||
public long getRecurrencePeriod() { | ||
return Functions.getIsUnitTest() ? Long.MAX_VALUE : MIN * 2; | ||
} | ||
|
||
@Override | ||
public void execute(TaskListener listener) { | ||
for (Cloud cloud : Jenkins.getActiveInstance().clouds) { | ||
if (!(cloud instanceof vSphereCloud)) continue; | ||
for (vSphereCloudSlaveTemplate template : ((vSphereCloud) cloud).getTemplates()) { | ||
if (template.getInstancesMin() > 0) { | ||
LOGGER.log(Level.INFO, "Check if template (label=" + template.getLabelString() + ") has enough active nodes to meet instances Min value"); | ||
((vSphereCloud) cloud).preProvisionNodes(template); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters