From f15f1fb5dcd6d912509766e7f38884e77c70673d Mon Sep 17 00:00:00 2001 From: Naveen Akkapeddi Date: Fri, 8 Mar 2019 20:38:17 -0800 Subject: [PATCH] Add param to enable CPU reservation --- .../plugins/vsphere/builders/ReconfigureCpu.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/vsphere/builders/ReconfigureCpu.java b/src/main/java/org/jenkinsci/plugins/vsphere/builders/ReconfigureCpu.java index ca7993a7..e1474f2f 100644 --- a/src/main/java/org/jenkinsci/plugins/vsphere/builders/ReconfigureCpu.java +++ b/src/main/java/org/jenkinsci/plugins/vsphere/builders/ReconfigureCpu.java @@ -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 { 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; + 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); VSphereLogger.vsLogger(jLogger, "Finished!"); return true;