171171import com .cloud .host .dao .HostDao ;
172172import com .cloud .hypervisor .Hypervisor .HypervisorType ;
173173import com .cloud .hypervisor .HypervisorGuru ;
174+ import com .cloud .hypervisor .HypervisorGuruBase ;
174175import com .cloud .hypervisor .HypervisorGuruManager ;
175176import com .cloud .network .Network ;
176177import com .cloud .network .NetworkModel ;
@@ -4659,34 +4660,43 @@ public VMInstanceVO reConfigureVm(final String vmUuid, final ServiceOffering old
46594660 }
46604661 }
46614662
4662- private VMInstanceVO orchestrateReConfigureVm (final String vmUuid , final ServiceOffering oldServiceOffering , final ServiceOffering newServiceOffering ,
4663- final boolean reconfiguringOnExistingHost ) throws ResourceUnavailableException , ConcurrentOperationException {
4664- final VMInstanceVO vm = _vmDao .findByUuid (vmUuid );
4663+ private VMInstanceVO orchestrateReConfigureVm (String vmUuid , ServiceOffering oldServiceOffering , ServiceOffering newServiceOffering ,
4664+ boolean reconfiguringOnExistingHost ) throws ResourceUnavailableException , ConcurrentOperationException {
4665+ VMInstanceVO vm = _vmDao .findByUuid (vmUuid );
46654666 upgradeVmDb (vm .getId (), newServiceOffering , oldServiceOffering );
46664667
4667- final HostVO hostVo = _hostDao .findById (vm .getHostId ());
4668- final Float memoryOvercommitRatio = CapacityManager .MemOverprovisioningFactor .valueIn (hostVo .getClusterId ());
4669- final Float cpuOvercommitRatio = CapacityManager .CpuOverprovisioningFactor .valueIn (hostVo .getClusterId ());
4670- final long minMemory = (long )(newServiceOffering .getRamSize () / memoryOvercommitRatio );
4671- final ScaleVmCommand reconfigureCmd =
4672- new ScaleVmCommand (vm .getInstanceName (), newServiceOffering .getCpu (), (int )(newServiceOffering .getSpeed () / cpuOvercommitRatio ),
4668+ HostVO hostVo = _hostDao .findById (vm .getHostId ());
4669+
4670+ Long clustedId = hostVo .getClusterId ();
4671+ Float memoryOvercommitRatio = CapacityManager .MemOverprovisioningFactor .valueIn (clustedId );
4672+ Float cpuOvercommitRatio = CapacityManager .CpuOverprovisioningFactor .valueIn (clustedId );
4673+ boolean divideMemoryByOverprovisioning = HypervisorGuruBase .VmMinMemoryEqualsMemoryDividedByMemOverprovisioningFactor .valueIn (clustedId );
4674+ boolean divideCpuByOverprovisioning = HypervisorGuruBase .VmMinCpuSpeedEqualsCpuSpeedDividedByCpuOverprovisioningFactor .valueIn (clustedId );
4675+
4676+ int minMemory = (int )(newServiceOffering .getRamSize () / (divideMemoryByOverprovisioning ? memoryOvercommitRatio : 1 ));
4677+ int minSpeed = (int )(newServiceOffering .getSpeed () / (divideCpuByOverprovisioning ? cpuOvercommitRatio : 1 ));
4678+
4679+ ScaleVmCommand scaleVmCommand =
4680+ new ScaleVmCommand (vm .getInstanceName (), newServiceOffering .getCpu (), minSpeed ,
46734681 newServiceOffering .getSpeed (), minMemory * 1024L * 1024L , newServiceOffering .getRamSize () * 1024L * 1024L , newServiceOffering .getLimitCpuUse ());
46744682
4675- final Long dstHostId = vm .getHostId ();
4676- if ( vm . getHypervisorType (). equals ( HypervisorType . VMware )) {
4677- final HypervisorGuru hvGuru = _hvGuruMgr . getGuru (vm .getHypervisorType ());
4678- Map < String , String > details = null ;
4679- details = hvGuru .getClusterSettings (vm .getId ());
4680- reconfigureCmd .getVirtualMachine ().setDetails (details );
4683+ Long dstHostId = vm .getHostId ();
4684+
4685+ if (vm .getHypervisorType (). equals ( HypervisorType . VMware )) {
4686+ HypervisorGuru hvGuru = _hvGuruMgr . getGuru ( vm . getHypervisorType ()) ;
4687+ Map < String , String > details = hvGuru .getClusterSettings (vm .getId ());
4688+ scaleVmCommand .getVirtualMachine ().setDetails (details );
46814689 }
46824690
4683- final ItWorkVO work = new ItWorkVO (UUID .randomUUID ().toString (), _nodeId , State .Running , vm .getType (), vm .getId ());
4691+ ItWorkVO work = new ItWorkVO (UUID .randomUUID ().toString (), _nodeId , State .Running , vm .getType (), vm .getId ());
46844692
46854693 work .setStep (Step .Prepare );
46864694 work .setResourceType (ItWorkVO .ResourceType .Host );
46874695 work .setResourceId (vm .getHostId ());
46884696 _workDao .persist (work );
4697+
46894698 boolean success = false ;
4699+
46904700 try {
46914701 if (reconfiguringOnExistingHost ) {
46924702 vm .setServiceOfferingId (oldServiceOffering .getId ());
@@ -4695,17 +4705,18 @@ private VMInstanceVO orchestrateReConfigureVm(final String vmUuid, final Service
46954705 _capacityMgr .allocateVmCapacity (vm , false ); // lock the new capacity
46964706 }
46974707
4698- final Answer reconfigureAnswer = _agentMgr .send (vm .getHostId (), reconfigureCmd );
4699- if (reconfigureAnswer == null || !reconfigureAnswer .getResult ()) {
4700- s_logger .error ("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer .getDetails ()));
4701- throw new CloudRuntimeException ("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer .getDetails ()));
4708+ Answer scaleVmAnswer = _agentMgr .send (vm .getHostId (), scaleVmCommand );
4709+ if (scaleVmAnswer == null || !scaleVmAnswer .getResult ()) {
4710+ String msg = String .format ("Unable to scale %s due to [%s]." , vm .toString (), (scaleVmAnswer == null ? "" : scaleVmAnswer .getDetails ()));
4711+ s_logger .error (msg );
4712+ throw new CloudRuntimeException (msg );
47024713 }
47034714 if (vm .getType ().equals (VirtualMachine .Type .User )) {
47044715 _userVmMgr .generateUsageEvent (vm , vm .isDisplayVm (), EventTypes .EVENT_VM_DYNAMIC_SCALE );
47054716 }
47064717 success = true ;
4707- } catch (final OperationTimedoutException e ) {
4708- throw new AgentUnavailableException ("Operation timed out on reconfiguring " + vm , dstHostId );
4718+ } catch (OperationTimedoutException e ) {
4719+ throw new AgentUnavailableException (String . format ( "Unable to scale %s due to [%s]." , vm . toString (), e . getMessage ()), dstHostId , e );
47094720 } catch (final AgentUnavailableException e ) {
47104721 throw e ;
47114722 } finally {
0 commit comments