Search in sources :

Example 16 with VolumeTO

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

the class VmwareStorageMotionStrategy method migrateVmWithVolumesWithinCluster.

private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
    // Initiate migration of a virtual machine with it's volumes.
    try {
        List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
        for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
            VolumeInfo volume = entry.getKey();
            VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
            StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
            volumeToFilerto.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
        }
        MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid());
        MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), command);
        if (answer == null) {
            s_logger.error("Migration with storage of vm " + vm + " failed.");
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else if (!answer.getResult()) {
            s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails());
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails());
        } else {
            // Update the volume details after migration.
            updateVolumesAfterMigration(volumeToPool, answer.getVolumeTos());
        }
        return answer;
    } catch (OperationTimedoutException e) {
        s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e);
        throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId());
    }
}
Also used : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VolumeTO(com.cloud.agent.api.to.VolumeTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 17 with VolumeTO

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

the class VmwareResource method execute.

@Override
public Answer execute(DestroyCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource DestroyCommand to evict template from storage pool: " + _gson.toJson(cmd));
    }
    try {
        VmwareContext context = getServiceContext(null);
        VmwareHypervisorHost hyperHost = getHyperHost(context, null);
        VolumeTO vol = cmd.getVolume();
        VirtualMachineMO vmMo = findVmOnDatacenter(context, hyperHost, vol);
        if (vmMo != null && vmMo.isTemplate()) {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("Destroy template volume " + vol.getPath());
            }
            vmMo.destroy();
        } else {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("Template volume " + vol.getPath() + " is not found, no need to delete.");
            }
        }
        return new Answer(cmd, true, "Success");
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext(null);
        }
        String msg = "DestroyCommand failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        return new Answer(cmd, false, msg);
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) VirtualMachineMO(com.cloud.hypervisor.vmware.mo.VirtualMachineMO) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) RemoteException(java.rmi.RemoteException)

Example 18 with VolumeTO

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

the class CitrixDestroyCommandWrapper method execute.

@Override
public Answer execute(final DestroyCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final VolumeTO vol = command.getVolume();
    // Look up the VDI
    final String volumeUUID = vol.getPath();
    VDI vdi = null;
    try {
        vdi = citrixResourceBase.getVDIbyUuid(conn, volumeUUID);
    } catch (final Exception e) {
        return new Answer(command, true, "Success");
    }
    Set<VBD> vbds = null;
    try {
        vbds = vdi.getVBDs(conn);
    } catch (final Exception e) {
        final String msg = "VDI getVBDS for " + volumeUUID + " failed due to " + e.toString();
        s_logger.warn(msg, e);
        return new Answer(command, false, msg);
    }
    for (final VBD vbd : vbds) {
        try {
            vbd.unplug(conn);
            vbd.destroy(conn);
        } catch (final Exception e) {
            final String msg = "VM destroy for " + volumeUUID + "  failed due to " + e.toString();
            s_logger.warn(msg, e);
            return new Answer(command, false, msg);
        }
    }
    try {
        final Set<VDI> snapshots = vdi.getSnapshots(conn);
        for (final VDI snapshot : snapshots) {
            snapshot.destroy(conn);
        }
        vdi.destroy(conn);
    } catch (final Exception e) {
        final String msg = "VDI destroy for " + volumeUUID + " failed due to " + e.toString();
        s_logger.warn(msg, e);
        return new Answer(command, false, msg);
    }
    return new Answer(command, true, "Success");
}
Also used : Answer(com.cloud.agent.api.Answer) VolumeTO(com.cloud.agent.api.to.VolumeTO) Connection(com.xensource.xenapi.Connection) VBD(com.xensource.xenapi.VBD) VDI(com.xensource.xenapi.VDI)

Example 19 with VolumeTO

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

the class LibvirtDestroyCommandWrapper method execute.

@Override
public Answer execute(final DestroyCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final VolumeTO vol = command.getVolume();
    try {
        final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        final KVMStoragePool pool = storagePoolMgr.getStoragePool(vol.getPoolType(), vol.getPoolUuid());
        pool.deletePhysicalDisk(vol.getPath(), null);
        return new Answer(command, true, "Success");
    } catch (final CloudRuntimeException e) {
        s_logger.debug("Failed to delete volume: " + e.toString());
        return new Answer(command, false, e.toString());
    }
}
Also used : Answer(com.cloud.agent.api.Answer) VolumeTO(com.cloud.agent.api.to.VolumeTO) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 20 with VolumeTO

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

the class Ovm3StorageProcessor method execute.

/* Destroy a volume (image) */
public Answer execute(DestroyCommand cmd) {
    LOGGER.debug("execute: " + cmd.getClass());
    VolumeTO vol = cmd.getVolume();
    String vmName = cmd.getVmName();
    try {
        StoragePlugin store = new StoragePlugin(c);
        store.storagePluginDestroy(vol.getPoolUuid(), vol.getPath());
        return new Answer(cmd, true, "Success");
    } catch (Ovm3ResourceException e) {
        LOGGER.debug("Destroy volume " + vol.getName() + " failed for " + vmName + " ", e);
        return new Answer(cmd, false, e.getMessage());
    }
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin)

Aggregations

VolumeTO (com.cloud.agent.api.to.VolumeTO)31 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 Answer (com.cloud.agent.api.Answer)14 Pair (com.cloud.utils.Pair)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 NicTO (com.cloud.agent.api.to.NicTO)10 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)10 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)9 Connection (com.xensource.xenapi.Connection)8 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)7 DiskProfile (com.cloud.vm.DiskProfile)7 SR (com.xensource.xenapi.SR)6 VDI (com.xensource.xenapi.VDI)6 Test (org.junit.Test)6 MigrateWithStorageCommand (com.cloud.agent.api.MigrateWithStorageCommand)5 Network (com.xensource.xenapi.Network)5 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)4