From b2e5cb975b3033dfdfdb2971a4adb2273c3e5b96 Mon Sep 17 00:00:00 2001 From: Adrian Schroeter Date: Thu, 19 May 2016 13:58:09 -0700 Subject: [PATCH] deployer: honor memory overrides for container resizing Change-Id: I4425cc08174038bf38622508e9135a1e37ce7258 --- .../task/AllocateHostResourceTaskService.java | 2 +- .../task/CreateManagementVmTaskService.java | 28 ++++++------------- .../deployer/dcp/util/MiscUtils.java | 16 +++++++++-- ruby/integration_tests/Rakefile | 6 ++++ ruby/integration_tests/ci/start_devbox.sh | 4 +++ 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/task/AllocateHostResourceTaskService.java b/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/task/AllocateHostResourceTaskService.java index 6bbcf21847..ee1e7c0847 100644 --- a/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/task/AllocateHostResourceTaskService.java +++ b/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/task/AllocateHostResourceTaskService.java @@ -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) { diff --git a/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/task/CreateManagementVmTaskService.java b/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/task/CreateManagementVmTaskService.java index 176762e878..ff246df100 100644 --- a/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/task/CreateManagementVmTaskService.java +++ b/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/task/CreateManagementVmTaskService.java @@ -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 vmCost = new ArrayList<>(); diff --git a/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/util/MiscUtils.java b/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/util/MiscUtils.java index 84c6604a07..fd3cdf3eed 100644 --- a/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/util/MiscUtils.java +++ b/java/deployer/src/main/java/com/vmware/photon/controller/deployer/dcp/util/MiscUtils.java @@ -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); diff --git a/ruby/integration_tests/Rakefile b/ruby/integration_tests/Rakefile index a665d89280..5f16e88c6a 100644 --- a/ruby/integration_tests/Rakefile +++ b/ruby/integration_tests/Rakefile @@ -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] diff --git a/ruby/integration_tests/ci/start_devbox.sh b/ruby/integration_tests/ci/start_devbox.sh index daa6d94ac5..35476451d4 100755 --- a/ruby/integration_tests/ci/start_devbox.sh +++ b/ruby/integration_tests/ci/start_devbox.sh @@ -44,6 +44,10 @@ fi if [ "$DEPLOYER_TEST" ] then + ( + cd $TESTS + bundle exec rake reboot_host + ) ./prepare-devbox-deployment.sh else vagrant up