Search in sources :

Example 21 with Ovm3ResourceException

use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.

the class Ovm3VmSupport method execute.

/* do migrations of VMs in a simple way just inside a cluster for now */
public MigrateAnswer execute(final MigrateCommand cmd) {
    final String vmName = cmd.getVmName();
    String destUuid = cmd.getHostGuid();
    String destIp = cmd.getDestinationIp();
    State state = State.Error;
    /*
         * TODO: figure out non pooled migration, works from CLI but not from
         * the agent... perhaps pause the VM and then migrate it ? for now just
         * stop the VM.
         */
    String msg = "Migrating " + vmName + " to " + destIp;
    LOGGER.info(msg);
    if (!config.getAgentInOvm3Cluster() && !config.getAgentInOvm3Pool()) {
        try {
            Xen xen = new Xen(c);
            Xen.Vm vm = xen.getRunningVmConfig(vmName);
            HostVO destHost = resourceMgr.findHostByGuid(destUuid);
            if (destHost == null) {
                msg = "Unable to find migration target host in DB " + destUuid + " with ip " + destIp;
                LOGGER.info(msg);
                return new MigrateAnswer(cmd, false, msg, null);
            }
            xen.stopVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid());
            msg = destHost.toString();
            state = State.Stopping;
            return new MigrateAnswer(cmd, false, msg, null);
        } catch (Ovm3ResourceException e) {
            msg = "Unpooled VM Migrate of " + vmName + " to " + destUuid + " failed due to: " + e.getMessage();
            LOGGER.debug(msg, e);
            return new MigrateAnswer(cmd, false, msg, null);
        } finally {
            /* shouldn't we just reinitialize completely as a last resort ? */
            hypervisor.setVmState(vmName, state);
        }
    } else {
        try {
            Xen xen = new Xen(c);
            Xen.Vm vm = xen.getRunningVmConfig(vmName);
            if (vm == null) {
                state = State.Stopped;
                msg = vmName + " is no running on " + config.getAgentHostname();
                return new MigrateAnswer(cmd, false, msg, null);
            }
            /* not a storage migration!!! */
            xen.migrateVm(ovmObject.deDash(vm.getVmRootDiskPoolId()), vm.getVmUuid(), destIp);
            state = State.Stopping;
            msg = "Migration of " + vmName + " successfull";
            return new MigrateAnswer(cmd, true, msg, null);
        } catch (Ovm3ResourceException e) {
            msg = "Pooled VM Migrate" + ": Migration of " + vmName + " to " + destIp + " failed due to " + e.getMessage();
            LOGGER.debug(msg, e);
            return new MigrateAnswer(cmd, false, msg, null);
        } finally {
            hypervisor.setVmState(vmName, state);
        }
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) State(com.cloud.vm.VirtualMachine.State) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) HostVO(com.cloud.host.HostVO)

Example 22 with Ovm3ResourceException

use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.

the class Ovm3VmSupport method getVmStat.

private VmStatsEntry getVmStat(String vmName) {
    CloudstackPlugin cSp = new CloudstackPlugin(c);
    Map<String, String> oldVmStats = null;
    Map<String, String> newVmStats = null;
    VmStatsEntry stats = new VmStatsEntry();
    try {
        if (vmStats.containsKey(vmName)) {
            oldVmStats = new HashMap<String, String>();
            oldVmStats.putAll(vmStats.get(vmName));
        }
        newVmStats = cSp.ovsDomUStats(vmName);
    } catch (Ovm3ResourceException e) {
        LOGGER.info("Unable to retrieve stats from " + vmName, e);
        return stats;
    }
    if (oldVmStats == null) {
        LOGGER.debug("No old stats retrieved stats from " + vmName);
        stats.setNumCPUs(1);
        stats.setNetworkReadKBs(0);
        stats.setNetworkWriteKBs(0);
        stats.setDiskReadKBs(0);
        stats.setDiskWriteKBs(0);
        stats.setDiskReadIOs(0);
        stats.setDiskWriteIOs(0);
        stats.setCPUUtilization(0);
        stats.setEntityType("vm");
    } else {
        LOGGER.debug("Retrieved new stats from " + vmName);
        int cpus = Integer.parseInt(newVmStats.get("vcpus"));
        stats.setNumCPUs(cpus);
        stats.setNetworkReadKBs(doubleMin(newVmStats.get("rx_bytes"), oldVmStats.get("rx_bytes")));
        stats.setNetworkWriteKBs(doubleMin(newVmStats.get("tx_bytes"), oldVmStats.get("tx_bytes")));
        stats.setDiskReadKBs(doubleMin(newVmStats.get("rd_bytes"), oldVmStats.get("rd_bytes")));
        stats.setDiskWriteKBs(doubleMin(newVmStats.get("rw_bytes"), oldVmStats.get("rw_bytes")));
        stats.setDiskReadIOs(doubleMin(newVmStats.get("rd_ops"), oldVmStats.get("rd_ops")));
        stats.setDiskWriteIOs(doubleMin(newVmStats.get("rw_ops"), oldVmStats.get("rw_ops")));
        Double dCpu = doubleMin(newVmStats.get("cputime"), oldVmStats.get("cputime"));
        Double dTime = doubleMin(newVmStats.get("uptime"), oldVmStats.get("uptime"));
        Double cpupct = dCpu / dTime * 100 * cpus;
        stats.setCPUUtilization(cpupct);
        stats.setEntityType("vm");
    }
    ((ConcurrentHashMap<String, Map<String, String>>) vmStats).put(vmName, newVmStats);
    return stats;
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) VmStatsEntry(com.cloud.agent.api.VmStatsEntry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)

Example 23 with Ovm3ResourceException

use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.

the class StoragePluginTest method testStorageFileCreation.

@Test
public void testStorageFileCreation() throws Ovm3ResourceException {
    con.setResult(results.simpleResponseWrapWrapper(FILECREATEXML));
    FileProperties file = sPt.storagePluginCreate(FSMNTUUID, NFSHOST, FILE, SIZE, false);
    file.getOnDiskSize();
}
Also used : FileProperties(com.cloud.hypervisor.ovm3.objects.StoragePlugin.FileProperties) Test(org.junit.Test)

Example 24 with Ovm3ResourceException

use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.

the class Ovm3VmSupport method deleteVif.

private Boolean deleteVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException {
    /* here we should use the housekeeping of VLANs/Networks etc..
         * so we can clean after the last VM is gone
         */
    try {
        String net = network.getNetwork(nic);
        if (net != null) {
            LOGGER.debug("Removing vif " + nic.getDeviceId() + " " + " " + nic.getMac() + " " + net + " from " + vm.getVmName());
            vm.removeVif(net, nic.getMac());
        } else {
            LOGGER.debug("Unable to remove vif " + nic.getDeviceId() + " no network for " + vm.getVmName());
            return false;
        }
    } catch (Exception e) {
        String msg = "Unable to remove vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage();
        LOGGER.debug(msg);
        throw new Ovm3ResourceException(msg);
    }
    return true;
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 25 with Ovm3ResourceException

use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException in project cloudstack by apache.

the class Ovm3VmSupport method execute.

/* Migration should make sure both HVs are the same ? */
public PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) {
    VirtualMachineTO vm = cmd.getVirtualMachine();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Preparing host for migrating " + vm.getName());
    }
    NicTO[] nics = vm.getNics();
    try {
        for (NicTO nic : nics) {
            network.getNetwork(nic);
        }
        hypervisor.setVmState(vm.getName(), State.Migrating);
        LOGGER.debug("VM " + vm.getName() + " is in Migrating state");
        return new PrepareForMigrationAnswer(cmd);
    } catch (Ovm3ResourceException e) {
        LOGGER.error("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to: " + e.getMessage());
        return new PrepareForMigrationAnswer(cmd, e);
    }
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) NicTO(com.cloud.agent.api.to.NicTO) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer)

Aggregations

Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)41 Linux (com.cloud.hypervisor.ovm3.objects.Linux)13 Test (org.junit.Test)10 Answer (com.cloud.agent.api.Answer)9 DataTO (com.cloud.agent.api.to.DataTO)9 CloudstackPlugin (com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)9 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)8 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)7 Xen (com.cloud.hypervisor.ovm3.objects.Xen)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 ConfigurationException (javax.naming.ConfigurationException)6 ConnectionTest (com.cloud.hypervisor.ovm3.objects.ConnectionTest)5 Pool (com.cloud.hypervisor.ovm3.objects.Pool)5 XenTest (com.cloud.hypervisor.ovm3.objects.XenTest)5 XmlTestResultTest (com.cloud.hypervisor.ovm3.objects.XmlTestResultTest)5 Ovm3SupportTest (com.cloud.hypervisor.ovm3.support.Ovm3SupportTest)5 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)5 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)5 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)4 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4