use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.
the class HypervStorageMotionStrategy method migrateVmWithVolumes.
private Answer migrateVmWithVolumes(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.getPrivateIpAddress());
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.
updateVolumePathsAfterMigration(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());
}
}
use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.
the class LibvirtComputingResourceTest method testResizeVolumeCommandException2.
@SuppressWarnings("unchecked")
@Test
public void testResizeVolumeCommandException2() {
final String path = "nfs:/127.0.0.1/storage/secondary";
final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
final Long currentSize = 100l;
final Long newSize = 200l;
final boolean shrinkOk = false;
final String vmInstance = "Test";
final ResizeVolumeCommand command = new ResizeVolumeCommand(path, pool, currentSize, newSize, shrinkOk, vmInstance);
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final KVMStoragePool storagePool = Mockito.mock(KVMStoragePool.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
when(storagePool.getPhysicalDisk(path)).thenThrow(CloudRuntimeException.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.
the class XenServer610MigrateVolumeCommandWrapper method execute.
@Override
public Answer execute(final MigrateVolumeCommand command, final XenServer610Resource xenServer610Resource) {
final Connection connection = xenServer610Resource.getConnection();
final String volumeUUID = command.getVolumePath();
final StorageFilerTO poolTO = command.getPool();
try {
final String uuid = poolTO.getUuid();
final SR destinationPool = xenServer610Resource.getStorageRepository(connection, uuid);
final VDI srcVolume = xenServer610Resource.getVDIbyUuid(connection, volumeUUID);
final Map<String, String> other = new HashMap<String, String>();
other.put("live", "true");
// Live migrate the vdi across pool.
final Task task = srcVolume.poolMigrateAsync(connection, destinationPool, other);
final long timeout = xenServer610Resource.getMigrateWait() * 1000L;
xenServer610Resource.waitForTask(connection, task, 1000, timeout);
xenServer610Resource.checkForSuccess(connection, task);
final VDI dvdi = Types.toVDI(task, connection);
return new MigrateVolumeAnswer(command, true, null, dvdi.getUuid(connection));
} catch (final Exception e) {
final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
s_logger.error(msg, e);
return new MigrateVolumeAnswer(command, false, msg, null);
}
}
use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.
the class CitrixModifyStoragePoolCommandWrapper method execute.
@Override
public Answer execute(final ModifyStoragePoolCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
final StorageFilerTO pool = command.getPool();
final boolean add = command.getAdd();
if (add) {
try {
final String srName = command.getStoragePath() != null ? command.getStoragePath() : pool.getUuid();
final SR sr = citrixResourceBase.getStorageRepository(conn, srName);
citrixResourceBase.setupHeartbeatSr(conn, sr, false);
final long capacity = sr.getPhysicalSize(conn);
final long available = capacity - sr.getPhysicalUtilisation(conn);
if (capacity == -1) {
final String msg = "Pool capacity is -1! pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg);
return new Answer(command, false, msg);
}
final Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
final ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(command, capacity, available, tInfo);
return answer;
} catch (final XenAPIException e) {
final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
} catch (final Exception e) {
final String msg = "ModifyStoragePoolCommand add XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
}
} else {
try {
final SR sr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
final String srUuid = sr.getUuid(conn);
final String result = citrixResourceBase.callHostPluginPremium(conn, "setup_heartbeat_file", "host", citrixResourceBase.getHost().getUuid(), "sr", srUuid, "add", "false");
if (result == null || !result.split("#")[1].equals("0")) {
throw new CloudRuntimeException("Unable to remove heartbeat file entry for SR " + srUuid + " due to " + result);
}
return new Answer(command, true, "success");
} catch (final XenAPIException e) {
final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.toString() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
} catch (final Exception e) {
final String msg = "ModifyStoragePoolCommand remove XenAPIException:" + e.getMessage() + " host:" + citrixResourceBase.getHost().getUuid() + " pool: " + pool.getHost() + pool.getPath();
s_logger.warn(msg, e);
return new Answer(command, false, msg);
}
}
}
use of com.cloud.agent.api.to.StorageFilerTO in project cloudstack by apache.
the class CitrixCreateCommandWrapper method execute.
@Override
public Answer execute(final CreateCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
final StorageFilerTO pool = command.getPool();
final DiskProfile dskch = command.getDiskCharacteristics();
VDI vdi = null;
try {
final SR poolSr = citrixResourceBase.getStorageRepository(conn, pool.getUuid());
if (command.getTemplateUrl() != null) {
VDI tmpltvdi = null;
tmpltvdi = citrixResourceBase.getVDIbyUuid(conn, command.getTemplateUrl());
vdi = tmpltvdi.createClone(conn, new HashMap<String, String>());
vdi.setNameLabel(conn, dskch.getName());
} else {
final VDI.Record vdir = new VDI.Record();
vdir.nameLabel = dskch.getName();
vdir.SR = poolSr;
vdir.type = Types.VdiType.USER;
vdir.virtualSize = dskch.getSize();
vdi = VDI.create(conn, vdir);
}
VDI.Record vdir;
vdir = vdi.getRecord(conn);
s_logger.debug("Succesfully created VDI for " + command + ". Uuid = " + vdir.uuid);
final VolumeTO vol = new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), vdir.nameLabel, pool.getPath(), vdir.uuid, vdir.virtualSize, null);
return new CreateAnswer(command, vol);
} catch (final Exception e) {
s_logger.warn("Unable to create volume; Pool=" + pool + "; Disk: " + dskch, e);
return new CreateAnswer(command, e);
}
}
Aggregations