Search in sources :

Example 1 with ScaleVmAnswer

use of com.cloud.agent.api.ScaleVmAnswer in project cloudstack by apache.

the class MockVmManagerImpl method scaleVm.

@Override
public Answer scaleVm(final ScaleVmCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        final String vmName = cmd.getVmName();
        final MockVMVO vm = _mockVmDao.findByVmName(vmName);
        if (vm == null) {
            return new ScaleVmAnswer(cmd, false, "Can't find VM " + vmName);
        }
        vm.setCpu(cmd.getCpus() * cmd.getMaxSpeed());
        vm.setMemory(cmd.getMaxRam());
        _mockVmDao.update(vm.getId(), vm);
        s_logger.debug("Scaled up VM " + vmName);
        txn.commit();
        return new ScaleVmAnswer(cmd, true, null);
    } catch (final Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Unable to scale up VM", ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 2 with ScaleVmAnswer

use of com.cloud.agent.api.ScaleVmAnswer in project cloudstack by apache.

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);
    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);
    ScaleVmCommand reconfigureCmd = new ScaleVmCommand("myVmName", newServiceOffering.getCpu(), newServiceOffering.getSpeed(), newServiceOffering.getSpeed(), 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.agent.api.ScaleVmAnswer) DeployDestination(com.cloud.deploy.DeployDestination) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand) Test(org.junit.Test)

Example 3 with ScaleVmAnswer

use of com.cloud.agent.api.ScaleVmAnswer in project cloudstack by apache.

the class CitrixScaleVmCommandWrapper method execute.

@Override
public Answer execute(final ScaleVmCommand command, final CitrixResourceBase citrixResourceBase) {
    final VirtualMachineTO vmSpec = command.getVirtualMachine();
    final String vmName = vmSpec.getName();
    try {
        final Connection conn = citrixResourceBase.getConnection();
        final Set<VM> vms = VM.getByNameLabel(conn, vmName);
        final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
        // If DMC is not enable then don't execute this command.
        if (!citrixResourceBase.isDmcEnabled(conn, host)) {
            throw new CloudRuntimeException("Unable to scale the vm: " + vmName + " as DMC - Dynamic memory control is not enabled for the XenServer:" + citrixResourceBase.getHost().getUuid() + " ,check your license and hypervisor version.");
        }
        if (vms == null || vms.size() == 0) {
            s_logger.info("No running VM " + vmName + " exists on XenServer" + citrixResourceBase.getHost().getUuid());
            return new ScaleVmAnswer(command, false, "VM does not exist");
        }
        // stop vm which is running on this host or is in halted state
        final Iterator<VM> iter = vms.iterator();
        while (iter.hasNext()) {
            final VM vm = iter.next();
            final VM.Record vmr = vm.getRecord(conn);
            if (vmr.powerState == VmPowerState.HALTED || vmr.powerState == VmPowerState.RUNNING && !citrixResourceBase.isRefNull(vmr.residentOn) && !vmr.residentOn.getUuid(conn).equals(citrixResourceBase.getHost().getUuid())) {
                iter.remove();
            }
        }
        for (final VM vm : vms) {
            vm.getRecord(conn);
            try {
                citrixResourceBase.scaleVM(conn, vm, vmSpec, host);
            } catch (final Exception e) {
                final String msg = "Catch exception " + e.getClass().getName() + " when scaling VM:" + vmName + " due to " + e.toString();
                s_logger.debug(msg);
                return new ScaleVmAnswer(command, false, msg);
            }
        }
        final String msg = "scaling VM " + vmName + " is successful on host " + host;
        s_logger.debug(msg);
        return new ScaleVmAnswer(command, true, msg);
    } catch (final XenAPIException e) {
        final String msg = "Upgrade Vm " + vmName + " fail due to " + e.toString();
        s_logger.warn(msg, e);
        return new ScaleVmAnswer(command, false, msg);
    } catch (final XmlRpcException e) {
        final String msg = "Upgrade Vm " + vmName + " fail due to " + e.getMessage();
        s_logger.warn(msg, e);
        return new ScaleVmAnswer(command, false, msg);
    } catch (final Exception e) {
        final String msg = "Unable to upgrade " + vmName + " due to " + e.getMessage();
        s_logger.warn(msg, e);
        return new ScaleVmAnswer(command, false, msg);
    }
}
Also used : Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VM(com.xensource.xenapi.VM) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 4 with ScaleVmAnswer

use of com.cloud.agent.api.ScaleVmAnswer in project cloudstack by apache.

the class VmwareResource method execute.

protected ScaleVmAnswer execute(ScaleVmCommand cmd) {
    VmwareContext context = getServiceContext();
    VirtualMachineTO vmSpec = cmd.getVirtualMachine();
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(cmd.getVmName());
        VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
        int ramMb = getReservedMemoryMb(vmSpec);
        long hotaddIncrementSizeInMb;
        long hotaddMemoryLimitInMb;
        long requestedMaxMemoryInMb = vmSpec.getMaxRam() / (1024 * 1024);
        // Check if VM is really running on hypervisor host
        if (getVmPowerState(vmMo) != PowerState.PowerOn) {
            throw new CloudRuntimeException("Found that the VM " + vmMo.getVmName() + " is not running. Unable to scale-up this VM");
        }
        // Check max hot add limit
        hotaddIncrementSizeInMb = vmMo.getHotAddMemoryIncrementSizeInMb();
        hotaddMemoryLimitInMb = vmMo.getHotAddMemoryLimitInMb();
        if (requestedMaxMemoryInMb > hotaddMemoryLimitInMb) {
            throw new CloudRuntimeException("Memory of VM " + vmMo.getVmName() + " cannot be scaled to " + requestedMaxMemoryInMb + "MB." + " Requested memory limit is beyond the hotadd memory limit for this VM at the moment is " + hotaddMemoryLimitInMb + "MB.");
        }
        // Check increment is multiple of increment size
        long reminder = requestedMaxMemoryInMb % hotaddIncrementSizeInMb;
        if (reminder != 0) {
            requestedMaxMemoryInMb = requestedMaxMemoryInMb + hotaddIncrementSizeInMb - reminder;
        }
        // Check if license supports the feature
        VmwareHelper.isFeatureLicensed(hyperHost, FeatureKeyConstants.HOTPLUG);
        VmwareHelper.setVmScaleUpConfig(vmConfigSpec, vmSpec.getCpus(), vmSpec.getMaxSpeed(), vmSpec.getMinSpeed(), (int) requestedMaxMemoryInMb, ramMb, vmSpec.getLimitCpuUse());
        if (!vmMo.configureVm(vmConfigSpec)) {
            throw new Exception("Unable to execute ScaleVmCommand");
        }
    } catch (Exception e) {
        s_logger.error("Unexpected exception: ", e);
        return new ScaleVmAnswer(cmd, false, "Unable to execute ScaleVmCommand due to " + e.toString());
    }
    return new ScaleVmAnswer(cmd, true, null);
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Aggregations

ScaleVmAnswer (com.cloud.agent.api.ScaleVmAnswer)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)2 ConfigurationException (javax.naming.ConfigurationException)2 ScaleVmCommand (com.cloud.agent.api.ScaleVmCommand)1 DeployDestination (com.cloud.deploy.DeployDestination)1 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)1 MockVMVO (com.cloud.simulator.MockVMVO)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)1 Connection (com.xensource.xenapi.Connection)1 Host (com.xensource.xenapi.Host)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 VM (com.xensource.xenapi.VM)1 IOException (java.io.IOException)1