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());
}
}
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);
}
}
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());
}
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;
}
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);
}
Aggregations