Search in sources :

Example 46 with StoragePool

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;
}
Also used : StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Cluster(com.cloud.org.Cluster) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 47 with StoragePool

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());
}
Also used : StoragePool(com.cloud.storage.StoragePool) Volume(com.cloud.storage.Volume) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 48 with StoragePool

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);
}
Also used : StoragePool(com.cloud.storage.StoragePool) Volume(com.cloud.storage.Volume) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 49 with StoragePool

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);
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 50 with StoragePool

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;
}
Also used : StoragePool(com.cloud.storage.StoragePool) Pod(com.cloud.dc.Pod) Cluster(com.cloud.org.Cluster) Host(com.cloud.host.Host) DataCenter(com.cloud.dc.DataCenter) Volume(com.cloud.storage.Volume) DeployDestination(com.cloud.deploy.DeployDestination) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

StoragePool (com.cloud.storage.StoragePool)234 Answer (com.cloud.agent.api.Answer)81 Test (org.junit.Test)70 ArrayList (java.util.ArrayList)69 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)63 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)56 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)56 Volume (com.cloud.storage.Volume)55 HashMap (java.util.HashMap)47 VolumeVO (com.cloud.storage.VolumeVO)37 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)36 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)35 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)29 DiskProfile (com.cloud.vm.DiskProfile)29 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KvmHaBase.NfsStoragePool)28 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)28 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)28 AttachAnswer (com.cloud.storage.command.AttachAnswer)28