use of com.cloud.legacymodel.communication.command.ScaleVmCommand in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImpl method orchestrateReConfigureVm.
private VMInstanceVO orchestrateReConfigureVm(final String vmUuid, final ServiceOffering oldServiceOffering, final boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
final long newServiceofferingId = vm.getServiceOfferingId();
final ServiceOffering newServiceOffering = _offeringDao.findById(vm.getId(), newServiceofferingId);
final HostVO hostVo = _hostDao.findById(vm.getHostId());
final Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(hostVo.getClusterId());
final Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(hostVo.getClusterId());
final long minMemory = (long) (newServiceOffering.getRamSize() / memoryOvercommitRatio);
final ScaleVmCommand reconfigureCmd = new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), minMemory * 1024L * 1024L, newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse());
final Long dstHostId = vm.getHostId();
final ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Running, vm.getType(), vm.getId());
work.setStep(Step.Prepare);
work.setResourceType(ItWorkVO.ResourceType.Host);
work.setResourceId(vm.getHostId());
_workDao.persist(work);
boolean success = false;
try {
if (reconfiguringOnExistingHost) {
vm.setServiceOfferingId(oldServiceOffering.getId());
// release the old capacity
_capacityMgr.releaseVmCapacity(vm, false, false, vm.getHostId());
vm.setServiceOfferingId(newServiceofferingId);
// lock the new capacity
_capacityMgr.allocateVmCapacity(vm, false);
}
final Answer reconfigureAnswer = _agentMgr.send(vm.getHostId(), reconfigureCmd);
if (reconfigureAnswer == null || !reconfigureAnswer.getResult()) {
s_logger.error("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
throw new CloudRuntimeException("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
}
success = true;
} catch (final OperationTimedoutException e) {
throw new AgentUnavailableException("Operation timed out on reconfiguring " + vm, dstHostId);
} catch (final AgentUnavailableException e) {
throw e;
} finally {
if (!success) {
// release the new capacity
_capacityMgr.releaseVmCapacity(vm, false, false, vm.getHostId());
vm.setServiceOfferingId(oldServiceOffering.getId());
// allocate the old capacity
_capacityMgr.allocateVmCapacity(vm, false);
}
}
return vm;
}
use of com.cloud.legacymodel.communication.command.ScaleVmCommand in project cosmic by MissionCriticalCloud.
the class VirtualMachineManagerImplTest method testScaleVM2.
@Test(expected = CloudRuntimeException.class)
public void testScaleVM2() throws Exception {
new DeployDestination(null, null, null, _host);
doReturn(3L).when(_vmInstance).getId();
when(_vmInstanceDao.findById(anyLong())).thenReturn(_vmInstance);
final ServiceOfferingVO newServiceOffering = getSvcoffering(512);
doReturn(1L).when(_vmInstance).getHostId();
doReturn(hostVO).when(_hostDao).findById(1L);
doReturn(1L).when(_vmInstance).getDataCenterId();
doReturn(1L).when(hostVO).getClusterId();
when(CapacityManager.CpuOverprovisioningFactor.valueIn(1L)).thenReturn(1.0f);
final ScaleVmCommand reconfigureCmd = new ScaleVmCommand("myVmName", newServiceOffering.getCpu(), newServiceOffering.getRamSize(), newServiceOffering.getRamSize(), newServiceOffering.getLimitCpuUse());
new ScaleVmAnswer(reconfigureCmd, true, "details");
when(_agentMgr.send(2l, reconfigureCmd)).thenReturn(null);
_vmMgr.reConfigureVm(_vmInstance.getUuid(), getSvcoffering(256), false);
}
use of com.cloud.legacymodel.communication.command.ScaleVmCommand in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testScaleVmCommand.
@Test
public void testScaleVmCommand() {
final String uuid = "6172d8b7-ba10-4a70-93f9-ecaf41f51d53";
final VirtualMachineTO machineTO = Mockito.mock(VirtualMachineTO.class);
final Connection conn = Mockito.mock(Connection.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final Host host = Mockito.mock(Host.class);
final ScaleVmCommand scaleVm = new ScaleVmCommand(machineTO);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(this.citrixResourceBase.getConnection()).thenReturn(conn);
when(this.citrixResourceBase.getHost()).thenReturn(xsHost);
when(this.citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
try {
when(this.citrixResourceBase.isDmcEnabled(conn, host)).thenReturn(true);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(scaleVm, this.citrixResourceBase);
verify(this.citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
Aggregations