-
Notifications
You must be signed in to change notification settings - Fork 105
Add additional parameters to reconfiguring VMs #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import org.jenkinsci.plugins.vsphere.tools.VSphereLogger; | ||
| import org.kohsuke.stapler.DataBoundConstructor; | ||
| import org.kohsuke.stapler.QueryParameter; | ||
| import com.vmware.vim25.ResourceAllocationInfo; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import javax.servlet.ServletException; | ||
|
|
@@ -34,11 +35,16 @@ public class ReconfigureCpu extends ReconfigureStep { | |
|
|
||
| private final String cpuCores; | ||
| private final String coresPerSocket; | ||
| private final String cpuLimitMHz; | ||
| private final ResourceAllocationInfo cpuReservation; | ||
|
|
||
| @DataBoundConstructor | ||
| public ReconfigureCpu(String cpuCores, String coresPerSocket) throws VSphereException { | ||
| public ReconfigureCpu(String cpuCores, String coresPerSocket, String cpuLimitMHz) throws VSphereException { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't change the constructor - that can break things for existing users, especially folks who're using pipeline builds. FYI while this plugin pre-dates such a practice being widely known, these days it's considered Jenkins "best practice" to have a constructor that only take mandatory arguments (and to have as few of those as possible) with everything else being set by data bound set methods. This makes it much easier for code that doesn't know or care about newly introduced optional fields to continue to work. |
||
| this.cpuCores = cpuCores; | ||
| this.coresPerSocket = coresPerSocket; | ||
| this.cpuLimitMHz = cpuLimitMHz; | ||
| this.cpuReservation = new ResourceAllocationInfo(); | ||
| this.cpuReservation.setReservation((long)Integer.valueOf(this.cpuLimitMHz)); | ||
| } | ||
|
|
||
| public String getCpuCores() { | ||
|
|
@@ -75,6 +81,8 @@ public boolean reconfigureCPU (final Run<?, ?> run, final Launcher launcher, fin | |
| PrintStream jLogger = listener.getLogger(); | ||
| String expandedCPUCores = cpuCores; | ||
| String expandedCoresPerSocket = coresPerSocket; | ||
| ResourceAllocationInfo resAllInfo = cpuReservation; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace with something like ...except that you'll also need to make sure that, if |
||
|
|
||
| EnvVars env; | ||
| try { | ||
| env = run.getEnvironment(listener); | ||
|
|
@@ -91,6 +99,7 @@ public boolean reconfigureCPU (final Run<?, ?> run, final Launcher launcher, fin | |
| VSphereLogger.vsLogger(jLogger, "Preparing reconfigure: CPU"); | ||
| spec.setNumCPUs(Integer.valueOf(expandedCPUCores)); | ||
| spec.setNumCoresPerSocket(Integer.valueOf(expandedCoresPerSocket)); | ||
| spec.setCpuAllocation(resAllInfo); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the user hasn't set |
||
|
|
||
| VSphereLogger.vsLogger(jLogger, "Finished!"); | ||
| return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've introduced data duplication here.
EITHER store the
cpuLimitMHzonly OR store thecpuReservationonly ... but do not store acpuReservationthat (always) contains a limit ofcpuLimitMHz.Personally, I'd recommend having only a field of
cpuLimitMHzand pushing the code that creates aResourceAllocationInfodown toreconfigureCPUwhere it's used.