Search in sources :

Example 26 with VolumeObjectTO

use of com.cloud.legacymodel.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class CitrixDeleteVMSnapshotCommandWrapper method execute.

@Override
public Answer execute(final DeleteVMSnapshotCommand command, final CitrixResourceBase citrixResourceBase) {
    final String snapshotName = command.getTarget().getSnapshotName();
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final List<VDI> vdiList = new ArrayList<>();
        final Set<VM> snapshots = VM.getByNameLabel(conn, snapshotName);
        if (snapshots == null || snapshots.size() == 0) {
            s_logger.warn("VM snapshot with name " + snapshotName + " does not exist, assume it is already deleted");
            return new DeleteVMSnapshotAnswer(command, command.getVolumeTOs());
        }
        final VM snapshot = snapshots.iterator().next();
        final Set<VBD> vbds = snapshot.getVBDs(conn);
        for (final VBD vbd : vbds) {
            if (vbd.getType(conn) == Types.VbdType.DISK) {
                final VDI vdi = vbd.getVDI(conn);
                vdiList.add(vdi);
            }
        }
        if (command.getTarget().getType() == VMSnapshot.Type.DiskAndMemory) {
            vdiList.add(snapshot.getSuspendVDI(conn));
        }
        snapshot.destroy(conn);
        for (final VDI vdi : vdiList) {
            vdi.destroy(conn);
        }
        try {
            Thread.sleep(5000);
        } catch (final InterruptedException ex) {
        }
        // re-calculate used capacify for this VM snapshot
        for (final VolumeObjectTO volumeTo : command.getVolumeTOs()) {
            final long size = citrixResourceBase.getVMSnapshotChainSize(conn, volumeTo, command.getVmName());
            volumeTo.setSize(size);
        }
        return new DeleteVMSnapshotAnswer(command, command.getVolumeTOs());
    } catch (final Exception e) {
        s_logger.warn("Catch Exception: " + e.getClass().toString() + " due to " + e.toString(), e);
        return new DeleteVMSnapshotAnswer(command, false, e.getMessage());
    }
}
Also used : Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) VM(com.xensource.xenapi.VM) VBD(com.xensource.xenapi.VBD) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VDI(com.xensource.xenapi.VDI) DeleteVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.DeleteVMSnapshotAnswer)

Example 27 with VolumeObjectTO

use of com.cloud.legacymodel.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class XenServer610MigrateWithStorageCompleteCommandWrapper method execute.

@Override
public Answer execute(final MigrateWithStorageCompleteCommand command, final XenServer610Resource xenServer610Resource) {
    final Connection connection = xenServer610Resource.getConnection();
    final VirtualMachineTO vmSpec = command.getVirtualMachine();
    final String name = vmSpec.getName();
    try {
        final XsHost xsHost = xenServer610Resource.getHost();
        final String uuid = xsHost.getUuid();
        final Set<VM> vms = VM.getByNameLabel(connection, name);
        // Check if VMs can be found by label.
        if (vms == null) {
            throw new CloudRuntimeException("Couldn't find VMs by label " + name + " on the destination host.");
        }
        final VM migratedVm = vms.iterator().next();
        // Check the vm is present on the new host.
        if (migratedVm == null) {
            throw new CloudRuntimeException("Couldn't find the migrated vm " + name + " on the destination host.");
        }
        final Host host = Host.getByUuid(connection, uuid);
        migratedVm.setAffinity(connection, host);
        // Volume paths would have changed. Return that information.
        final List<VolumeObjectTO> volumeToSet = xenServer610Resource.getUpdatedVolumePathsOfMigratedVm(connection, migratedVm, vmSpec.getDisks());
        return new MigrateWithStorageCompleteAnswer(command, volumeToSet);
    } catch (final CloudRuntimeException e) {
        s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageCompleteAnswer(command, e);
    } catch (final Exception e) {
        s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e);
        return new MigrateWithStorageCompleteAnswer(command, e);
    }
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) Host(com.xensource.xenapi.Host) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) MigrateWithStorageCompleteAnswer(com.cloud.legacymodel.communication.answer.MigrateWithStorageCompleteAnswer) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 28 with VolumeObjectTO

use of com.cloud.legacymodel.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testDeleteVMSnapshotCommand.

@Test
public void testDeleteVMSnapshotCommand() {
    final Connection conn = Mockito.mock(Connection.class);
    final VMSnapshotTO snapshotTO = Mockito.mock(VMSnapshotTO.class);
    final List<VolumeObjectTO> volumeTOs = new ArrayList<>();
    final DeleteVMSnapshotCommand vmSnapshot = new DeleteVMSnapshotCommand("Test", snapshotTO, volumeTOs, "Debian");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(this.citrixResourceBase.getConnection()).thenReturn(conn);
    final Answer answer = wrapper.execute(vmSnapshot, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertTrue(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) VMSnapshotTO(com.cloud.legacymodel.to.VMSnapshotTO) DeleteVMSnapshotCommand(com.cloud.legacymodel.communication.command.DeleteVMSnapshotCommand) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 with VolumeObjectTO

use of com.cloud.legacymodel.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class VMSnapshotManagerImpl method getVolumeTOList.

private List<VolumeObjectTO> getVolumeTOList(final Long vmId) {
    final List<VolumeObjectTO> volumeTOs = new ArrayList<>();
    final List<VolumeVO> volumeVOs = _volumeDao.findByInstance(vmId);
    for (final VolumeVO volume : volumeVOs) {
        final VolumeInfo volumeInfo = volumeDataFactory.getVolume(volume.getId());
        volumeTOs.add((VolumeObjectTO) volumeInfo.getTO());
    }
    return volumeTOs;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo)

Example 30 with VolumeObjectTO

use of com.cloud.legacymodel.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class VolumeObject method processEventOnly.

@Override
public void processEventOnly(final ObjectInDataStoreStateMachine.Event event, final Answer answer) {
    try {
        if (dataStore.getRole() == DataStoreRole.Primary) {
            if (answer instanceof CopyCmdAnswer) {
                final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                final VolumeVO vol = volumeDao.findById(getId());
                final VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
                vol.setPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    vol.setSize(newVol.getSize());
                }
                vol.setPoolId(getDataStore().getId());
                volumeDao.update(vol.getId(), vol);
            } else if (answer instanceof CreateObjectAnswer) {
                final CreateObjectAnswer createAnswer = (CreateObjectAnswer) answer;
                final VolumeObjectTO newVol = (VolumeObjectTO) createAnswer.getData();
                final VolumeVO vol = volumeDao.findById(getId());
                vol.setPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    vol.setSize(newVol.getSize());
                }
                vol.setPoolId(getDataStore().getId());
                volumeDao.update(vol.getId(), vol);
            }
        } else {
            processDownloadAnswer(answer);
        }
    } catch (final RuntimeException ex) {
        if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
            objectInStoreMgr.deleteIfNotReady(this);
        }
        throw ex;
    }
    this.processEventOnly(event);
}
Also used : CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CreateObjectAnswer(com.cloud.legacymodel.communication.answer.CreateObjectAnswer) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer)

Aggregations

VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)61 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)38 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)23 PrimaryDataStoreTO (com.cloud.legacymodel.to.PrimaryDataStoreTO)23 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)19 Connection (com.xensource.xenapi.Connection)19 DataTO (com.cloud.legacymodel.to.DataTO)17 NfsTO (com.cloud.legacymodel.to.NfsTO)17 VDI (com.xensource.xenapi.VDI)17 DataStoreTO (com.cloud.legacymodel.to.DataStoreTO)16 ArrayList (java.util.ArrayList)14 SR (com.xensource.xenapi.SR)13 XenAPIException (com.xensource.xenapi.Types.XenAPIException)13 XmlRpcException (org.apache.xmlrpc.XmlRpcException)13 LibvirtException (org.libvirt.LibvirtException)12 IOException (java.io.IOException)11 VMSnapshotTO (com.cloud.legacymodel.to.VMSnapshotTO)10 DiskTO (com.cloud.legacymodel.to.DiskTO)9 VolumeVO (com.cloud.storage.VolumeVO)9 URI (java.net.URI)9