use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class VirtualMachineManagerImpl method prepareVmStorageMigration.
private Map<Volume, StoragePool> prepareVmStorageMigration(VMInstanceVO vm, Map<Long, Long> volumeToPool) {
Map<Volume, StoragePool> volumeToPoolMap = new HashMap<>();
if (MapUtils.isEmpty(volumeToPool)) {
throw new CloudRuntimeException(String.format("Unable to migrate %s: missing volume to pool mapping.", vm.toString()));
}
Cluster cluster = null;
Long dataCenterId = null;
for (Map.Entry<Long, Long> entry : volumeToPool.entrySet()) {
StoragePool pool = _storagePoolDao.findById(entry.getValue());
if (pool.getClusterId() != null) {
cluster = _clusterDao.findById(pool.getClusterId());
break;
}
dataCenterId = pool.getDataCenterId();
}
Long podId = null;
Long clusterId = null;
if (cluster != null) {
dataCenterId = cluster.getDataCenterId();
podId = cluster.getPodId();
clusterId = cluster.getId();
}
if (dataCenterId == null) {
String msg = "Unable to migrate vm: failed to create deployment destination with given volume to pool map";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
final DataCenterDeployment destination = new DataCenterDeployment(dataCenterId, podId, clusterId, null, null, null);
// Create a map of which volume should go in which storage pool.
final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
volumeToPoolMap = createMappingVolumeAndStoragePool(profile, destination, volumeToPool);
try {
stateTransitTo(vm, Event.StorageMigrationRequested, null);
} catch (final NoTransitionException e) {
String msg = String.format("Unable to migrate vm: %s", vm.getUuid());
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
}
return volumeToPoolMap;
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class VirtualMachineManagerImpl method migrateVmThroughJobQueue.
public Outcome<VirtualMachine> migrateVmThroughJobQueue(final String vmUuid, final long srcHostId, final DeployDestination dest) {
Map<Volume, StoragePool> volumeStorageMap = dest.getStorageForDisks();
if (volumeStorageMap != null) {
for (Volume vol : volumeStorageMap.keySet()) {
checkConcurrentJobsPerDatastoreThreshhold(volumeStorageMap.get(vol));
}
}
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
Long vmId = vm.getId();
String commandName = VmWorkMigrate.class.getName();
Pair<VmWorkJobVO, Long> pendingWorkJob = retrievePendingWorkJob(vmId, vmUuid, VirtualMachine.Type.Instance, commandName);
VmWorkJobVO workJob = pendingWorkJob.first();
if (workJob == null) {
Pair<VmWorkJobVO, VmWork> newVmWorkJobAndInfo = createWorkJobAndWorkInfo(commandName, vmId);
workJob = newVmWorkJobAndInfo.first();
VmWorkMigrate workInfo = new VmWorkMigrate(newVmWorkJobAndInfo.second(), srcHostId, dest);
setCmdInfoAndSubmitAsyncJob(workJob, workInfo, vmId);
}
AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
return new VmStateSyncOutcome(workJob, VirtualMachine.PowerState.PowerOn, vmId, vm.getPowerHostId());
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class VirtualMachineManagerImpl method afterHypervisorMigrationCleanup.
private void afterHypervisorMigrationCleanup(VMInstanceVO vm, Map<Volume, StoragePool> volumeToPool, Long sourceClusterId, Answer[] hypervisorMigrationResults) throws InsufficientCapacityException {
boolean isDebugEnabled = s_logger.isDebugEnabled();
if (isDebugEnabled) {
String msg = String.format("Cleaning up after hypervisor pool migration volumes for VM %s(%s)", vm.getInstanceName(), vm.getUuid());
s_logger.debug(msg);
}
StoragePool rootVolumePool = null;
if (MapUtils.isNotEmpty(volumeToPool)) {
for (Map.Entry<Volume, StoragePool> entry : volumeToPool.entrySet()) {
if (Type.ROOT.equals(entry.getKey().getVolumeType())) {
rootVolumePool = entry.getValue();
break;
}
}
}
setDestinationPoolAndReallocateNetwork(rootVolumePool, vm);
Long destClusterId = rootVolumePool != null ? rootVolumePool.getClusterId() : null;
if (destClusterId != null && !destClusterId.equals(sourceClusterId)) {
if (isDebugEnabled) {
String msg = String.format("Resetting lastHost for VM %s(%s)", vm.getInstanceName(), vm.getUuid());
s_logger.debug(msg);
}
vm.setLastHostId(null);
vm.setPodIdToDeployIn(rootVolumePool.getPodId());
}
markVolumesInPool(vm, hypervisorMigrationResults);
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class VirtualMachineManagerImpl method orchestrateStorageMigration.
private void orchestrateStorageMigration(final String vmUuid, final Map<Long, Long> volumeToPool) {
final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
Map<Volume, StoragePool> volumeToPoolMap = prepareVmStorageMigration(vm, volumeToPool);
try {
if (s_logger.isDebugEnabled()) {
s_logger.debug(String.format("Offline migration of %s vm %s with volumes", vm.getHypervisorType().toString(), vm.getInstanceName()));
}
migrateThroughHypervisorOrStorage(vm, volumeToPoolMap);
} catch (ConcurrentOperationException | InsufficientCapacityException | StorageUnavailableException e) {
String msg = String.format("Failed to migrate VM: %s", vmUuid);
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
} finally {
try {
stateTransitTo(vm, Event.AgentReportStopped, null);
} catch (final NoTransitionException e) {
String anotherMEssage = String.format("failed to change vm state of VM: %s", vmUuid);
s_logger.warn(anotherMEssage, e);
throw new CloudRuntimeException(anotherMEssage, e);
}
}
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class VmWorkMigrate method getDeployDestination.
public DeployDestination getDeployDestination() {
DataCenter zone = zoneId != null ? s_entityMgr.findById(DataCenter.class, zoneId) : null;
Pod pod = podId != null ? s_entityMgr.findById(Pod.class, podId) : null;
Cluster cluster = clusterId != null ? s_entityMgr.findById(Cluster.class, clusterId) : null;
Host host = hostId != null ? s_entityMgr.findById(Host.class, hostId) : null;
Map<Volume, StoragePool> vols = null;
boolean displayStorage = true;
if (storage != null) {
vols = new HashMap<Volume, StoragePool>(storage.size());
for (Map.Entry<String, String> entry : storage.entrySet()) {
Volume volume = s_entityMgr.findByUuid(Volume.class, entry.getKey());
if (displayStorage && volume.isDeployAsIs()) {
displayStorage = false;
}
vols.put(volume, s_entityMgr.findByUuid(StoragePool.class, entry.getValue()));
}
}
DeployDestination dest = new DeployDestination(zone, pod, cluster, host, vols, displayStorage);
return dest;
}
Aggregations