Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
deployer: honor memory overrides for container resizing
Browse files Browse the repository at this point in the history
Change-Id: I4425cc08174038bf38622508e9135a1e37ce7258
  • Loading branch information
schadr committed May 23, 2016
1 parent 2eb85b6 commit b2e5cb9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private Operation createContainerPatch(HostService.State hostState,
int maxCpuCount) {

ContainerService.State patchState = new ContainerService.State();
patchState.memoryMb = templateState.memoryMb * MiscUtils.getAdjustedManagementHostMemory(hostState) / totalMemory;
patchState.memoryMb = templateState.memoryMb * MiscUtils.getAdjustedManagementVmMemory(hostState) / totalMemory;
patchState.cpuShares = templateState.cpuCount * ContainerService.State.DOCKER_CPU_SHARES_MAX / maxCpuCount;
patchState.dynamicParameters = new HashMap<>();
if (null != containerState.dynamicParameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,32 +533,20 @@ private void computeVmFlavorRequirements(State currentState,
// if this fails, then fall back to using the resource requirements specified by the service
// containers placed on the VM.
//
if (hostState.cpuCount == null || hostState.memoryMb == null) {
throw new IllegalStateException("Failed to calculate host resources for host " + hostState.hostAddress);
}

int cpuCount;
long memoryMb;

if (hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_CPU_COUNT_OVERWRITE) &&
hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_MEMORY_MB_OVERWRITE) &&
hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_DISK_GB_OVERWRITE)) {

cpuCount = Integer.parseInt(
hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_CPU_COUNT_OVERWRITE));
memoryMb = Long.parseLong(
hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_MEMORY_MB_OVERWRITE));
int cpuCount = MiscUtils.getAdjustedManagementVmCpu(hostState);
long memoryMb = MiscUtils.getAdjustedManagementVmMemory(hostState);

if (hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_CPU_COUNT_OVERWRITE) ||
hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_MEMORY_MB_OVERWRITE)) {
ServiceUtils.logInfo(this, "Found flavor override values for VM %s: %d vCPUs, %d MB memory",
vmState.name, cpuCount, memoryMb);

} else if (hostState.cpuCount != null && hostState.memoryMb != null) {

cpuCount = MiscUtils.getAdjustedManagementHostCpu(hostState);
memoryMb = MiscUtils.getAdjustedManagementHostMemory(hostState);

} else {
ServiceUtils.logInfo(this, "Computed flavor values for VM %s from host size: %d vCPUs, %d MB memory",
vmState.name, cpuCount, memoryMb);

} else {
throw new IllegalStateException("Failed to calculate host resources for host " + hostState.hostAddress);
}

List<QuotaLineItem> vmCost = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,24 @@ private static float getManagementVmHostRatio(HostService.State hostState) {
DeployerDefaults.MANAGEMENT_VM_TO_MANAGEMENT_ONLY_HOST_RESOURCE_RATIO;
}

public static int getAdjustedManagementHostCpu(HostService.State hostState) {
public static int getAdjustedManagementVmCpu(HostService.State hostState) {
if (hostState.metadata != null
&& hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_CPU_COUNT_OVERWRITE)) {
return Integer.parseInt(
hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_CPU_COUNT_OVERWRITE));
}

float managementVmHostRatio = getManagementVmHostRatio(hostState);
return Math.max((int) (hostState.cpuCount * managementVmHostRatio), 1);
}

public static long getAdjustedManagementHostMemory(HostService.State hostState) {
public static long getAdjustedManagementVmMemory(HostService.State hostState) {
if (hostState.metadata != null
&& hostState.metadata.containsKey(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_MEMORY_MB_OVERWRITE)) {
return Long.parseLong(
hostState.metadata.get(HostService.State.METADATA_KEY_NAME_MANAGEMENT_VM_MEMORY_MB_OVERWRITE));
}

float managementVmHostRatio = getManagementVmHostRatio(hostState);
long afterRationMemeory = (long) (hostState.memoryMb * managementVmHostRatio);
return floorToNearestNumberDivisibleByFour(afterRationMemeory);
Expand Down
6 changes: 6 additions & 0 deletions ruby/integration_tests/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ task :reboot_hosts, [:dc_yml] do |t, args|
sleep(5 * 60)
end

desc 'Reboot host'
task :reboot_host do |t|
EsxCloud::HostCleaner.reboot_host EsxCloud::TestHelpers.get_esx_ip, EsxCloud::TestHelpers.get_esx_username, EsxCloud::TestHelpers.get_esx_password
sleep(5 * 60)
end

desc 'Power off management vms'
task :power_off_management_vms, [:count] do |t, args|
EsxCloud::UptimeHelper.power_off_management_vms args[:count]
Expand Down
4 changes: 4 additions & 0 deletions ruby/integration_tests/ci/start_devbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ fi

if [ "$DEPLOYER_TEST" ]
then
(
cd $TESTS
bundle exec rake reboot_host
)
./prepare-devbox-deployment.sh
else
vagrant up
Expand Down

0 comments on commit b2e5cb9

Please sign in to comment.