Search in sources :

Example 1 with ScaleVmCommand

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;
}
Also used : OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) ServiceOffering(com.cloud.offering.ServiceOffering) HostVO(com.cloud.host.HostVO) UnPlugNicAnswer(com.cloud.legacymodel.communication.answer.UnPlugNicAnswer) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.legacymodel.communication.answer.ClusterVMMetaDataSyncAnswer) RestoreVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer) RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) StartAnswer(com.cloud.legacymodel.communication.answer.StartAnswer) PlugNicAnswer(com.cloud.legacymodel.communication.answer.PlugNicAnswer) CheckVirtualMachineAnswer(com.cloud.legacymodel.communication.answer.CheckVirtualMachineAnswer) StopAnswer(com.cloud.legacymodel.communication.answer.StopAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) ScaleVmCommand(com.cloud.legacymodel.communication.command.ScaleVmCommand)

Example 2 with ScaleVmCommand

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);
}
Also used : ScaleVmAnswer(com.cloud.legacymodel.communication.answer.ScaleVmAnswer) DeployDestination(com.cloud.deploy.DeployDestination) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ScaleVmCommand(com.cloud.legacymodel.communication.command.ScaleVmCommand) Test(org.junit.Test)

Example 3 with ScaleVmCommand

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());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Host(com.xensource.xenapi.Host) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) ScaleVmCommand(com.cloud.legacymodel.communication.command.ScaleVmCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ScaleVmCommand (com.cloud.legacymodel.communication.command.ScaleVmCommand)3 Answer (com.cloud.legacymodel.communication.answer.Answer)2 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)2 Test (org.junit.Test)2 DeployDestination (com.cloud.deploy.DeployDestination)1 HostVO (com.cloud.host.HostVO)1 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)1 CheckVirtualMachineAnswer (com.cloud.legacymodel.communication.answer.CheckVirtualMachineAnswer)1 ClusterVMMetaDataSyncAnswer (com.cloud.legacymodel.communication.answer.ClusterVMMetaDataSyncAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 PlugNicAnswer (com.cloud.legacymodel.communication.answer.PlugNicAnswer)1 RestoreVMSnapshotAnswer (com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer)1 ScaleVmAnswer (com.cloud.legacymodel.communication.answer.ScaleVmAnswer)1 StartAnswer (com.cloud.legacymodel.communication.answer.StartAnswer)1 StopAnswer (com.cloud.legacymodel.communication.answer.StopAnswer)1 UnPlugNicAnswer (com.cloud.legacymodel.communication.answer.UnPlugNicAnswer)1 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1