Search in sources :

Example 56 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class VirtualMachineManagerImpl method orchestrateMigrateAway.

private void orchestrateMigrateAway(final String vmUuid, final long srcHostId, final DeploymentPlanner planner) throws InsufficientServerCapacityException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (vm == null) {
        String message = String.format("Unable to find VM with uuid [%s].", vmUuid);
        s_logger.warn(message);
        throw new CloudRuntimeException(message);
    }
    ServiceOfferingVO offeringVO = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
    final Long hostId = vm.getHostId();
    if (hostId == null) {
        String message = String.format("Unable to migrate %s due to it does not have a host id.", vm.toString());
        s_logger.warn(message);
        throw new CloudRuntimeException(message);
    }
    final Host host = _hostDao.findById(hostId);
    Long poolId = null;
    final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    for (final VolumeVO rootVolumeOfVm : vols) {
        final StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
        if (rootDiskPool != null) {
            poolId = rootDiskPool.getId();
        }
    }
    final ExcludeList excludes = new ExcludeList();
    excludes.addHost(hostId);
    DataCenterDeployment plan = getMigrationDeployment(vm, host, poolId, excludes);
    DeployDestination dest = null;
    while (true) {
        try {
            plan.setMigrationPlan(true);
            dest = _dpMgr.planDeployment(profile, plan, excludes, planner);
        } catch (final AffinityConflictException e2) {
            String message = String.format("Unable to create deployment, affinity rules associted to the %s conflict.", vm.toString());
            s_logger.warn(message, e2);
            throw new CloudRuntimeException(message, e2);
        }
        if (dest == null) {
            s_logger.warn("Unable to find destination for migrating the vm " + profile);
            throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", DataCenter.class, host.getDataCenterId());
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Found destination " + dest + " for migrating to.");
        }
        excludes.addHost(dest.getHost().getId());
        try {
            migrate(vm, srcHostId, dest);
            return;
        } catch (ResourceUnavailableException | ConcurrentOperationException e) {
            s_logger.warn(String.format("Unable to migrate %s to %s due to [%s]", vm.toString(), dest.getHost().toString(), e.getMessage()), e);
        }
        try {
            advanceStop(vmUuid, true);
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final ResourceUnavailableException | ConcurrentOperationException | OperationTimedoutException e) {
            s_logger.error(String.format("Unable to stop %s due to [%s].", vm.toString(), e.getMessage()), e);
            throw new CloudRuntimeException("Unable to migrate " + vm);
        }
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) Host(com.cloud.host.Host) AffinityConflictException(com.cloud.exception.AffinityConflictException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 57 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class VirtualMachineManagerImpl method buildMapUsingUserInformation.

/**
 *  Builds the map of storage pools and volumes with the information entered by the user. Before creating the an entry we validate if the migration is feasible checking if the migration is allowed and if the target host can access the defined target storage pool.
 */
protected Map<Volume, StoragePool> buildMapUsingUserInformation(VirtualMachineProfile profile, Host targetHost, Map<Long, Long> userDefinedVolumeToStoragePoolMap) {
    Map<Volume, StoragePool> volumeToPoolObjectMap = new HashMap<>();
    if (MapUtils.isEmpty(userDefinedVolumeToStoragePoolMap)) {
        return volumeToPoolObjectMap;
    }
    for (Long volumeId : userDefinedVolumeToStoragePoolMap.keySet()) {
        VolumeVO volume = _volsDao.findById(volumeId);
        Long poolId = userDefinedVolumeToStoragePoolMap.get(volumeId);
        StoragePoolVO targetPool = _storagePoolDao.findById(poolId);
        StoragePoolVO currentPool = _storagePoolDao.findById(volume.getPoolId());
        executeManagedStorageChecksWhenTargetStoragePoolProvided(currentPool, volume, targetPool);
        if (targetHost != null && _poolHostDao.findByPoolHost(targetPool.getId(), targetHost.getId()) == null) {
            throw new CloudRuntimeException(String.format("Cannot migrate the volume [%s] to the storage pool [%s] while migrating VM [%s] to target host [%s]. The host does not have access to the storage pool entered.", volume.getUuid(), targetPool.getUuid(), profile.getUuid(), targetHost.getUuid()));
        }
        if (currentPool.getId() == targetPool.getId()) {
            s_logger.info(String.format("The volume [%s] is already allocated in storage pool [%s].", volume.getUuid(), targetPool.getUuid()));
        }
        volumeToPoolObjectMap.put(volume, targetPool);
    }
    return volumeToPoolObjectMap;
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) Volume(com.cloud.storage.Volume) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 58 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class VirtualMachineManagerImpl method getCandidateStoragePoolsToMigrateLocalVolume.

/**
 * We use {@link StoragePoolAllocator} objects to find storage pools for given DataCenterDeployment where we would be able to allocate the given volume.
 */
protected List<StoragePool> getCandidateStoragePoolsToMigrateLocalVolume(VirtualMachineProfile profile, DataCenterDeployment plan, Volume volume) {
    List<StoragePool> poolList = new ArrayList<>();
    DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
    DiskProfile diskProfile = new DiskProfile(volume, diskOffering, profile.getHypervisorType());
    ExcludeList avoid = new ExcludeList();
    StoragePoolVO volumeStoragePool = _storagePoolDao.findById(volume.getPoolId());
    if (volumeStoragePool.isLocal()) {
        diskProfile.setUseLocalStorage(true);
    }
    for (StoragePoolAllocator allocator : _storagePoolAllocators) {
        List<StoragePool> poolListFromAllocator = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL);
        if (CollectionUtils.isEmpty(poolListFromAllocator)) {
            continue;
        }
        for (StoragePool pool : poolListFromAllocator) {
            if (pool.isLocal() || isStorageCrossClusterMigration(plan.getClusterId(), volumeStoragePool)) {
                poolList.add(pool);
            }
        }
    }
    return poolList;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ArrayList(java.util.ArrayList) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)

Example 59 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class VirtualMachineManagerImpl method migrateVmStorageThroughJobQueue.

public Outcome<VirtualMachine> migrateVmStorageThroughJobQueue(final String vmUuid, final Map<Long, Long> volumeToPool) {
    Collection<Long> poolIds = volumeToPool.values();
    Set<Long> uniquePoolIds = new HashSet<>(poolIds);
    for (Long poolId : uniquePoolIds) {
        StoragePoolVO pool = _storagePoolDao.findById(poolId);
        checkConcurrentJobsPerDatastoreThreshhold(pool);
    }
    String commandName = VmWorkStorageMigration.class.getName();
    Pair<VmWorkJobVO, Long> pendingWorkJob = retrievePendingWorkJob(vmUuid, commandName);
    VmWorkJobVO workJob = pendingWorkJob.first();
    Long vmId = pendingWorkJob.second();
    if (workJob == null) {
        Pair<VmWorkJobVO, VmWork> newVmWorkJobAndInfo = createWorkJobAndWorkInfo(commandName, vmId);
        workJob = newVmWorkJobAndInfo.first();
        VmWorkStorageMigration workInfo = new VmWorkStorageMigration(newVmWorkJobAndInfo.second(), volumeToPool);
        setCmdInfoAndSubmitAsyncJob(workJob, workInfo, vmId);
    }
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmJobVirtualMachineOutcome(workJob, vmId);
}
Also used : StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) HashSet(java.util.HashSet) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Example 60 with StoragePoolVO

use of org.apache.cloudstack.storage.datastore.db.StoragePoolVO in project cloudstack by apache.

the class SolidFireUtil method hostAddedToCluster.

public static void hostAddedToCluster(long hostId, long clusterId, String storageProvider, ClusterDao clusterDao, HostDao hostDao, PrimaryDataStoreDao storagePoolDao, StoragePoolDetailsDao storagePoolDetailsDao) {
    HostVO hostVO = hostDao.findById(hostId);
    Preconditions.checkArgument(hostVO != null, "Could not locate host for ID: " + hostId);
    ClusterVO cluster = clusterDao.findById(clusterId);
    GlobalLock lock = GlobalLock.getInternLock(cluster.getUuid());
    if (!lock.lock(LOCK_TIME_IN_SECONDS)) {
        String errMsg = "Couldn't lock the DB on the following string: " + cluster.getUuid();
        LOGGER.warn(errMsg);
        throw new CloudRuntimeException(errMsg);
    }
    try {
        List<StoragePoolVO> storagePools = storagePoolDao.findPoolsByProvider(storageProvider);
        if (storagePools != null && storagePools.size() > 0) {
            List<SolidFireUtil.SolidFireConnection> sfConnections = new ArrayList<>();
            for (StoragePoolVO storagePool : storagePools) {
                if (!isStorageApplicableToZoneOrCluster(storagePool, clusterId, clusterDao)) {
                    continue;
                }
                SolidFireUtil.SolidFireConnection sfConnection = SolidFireUtil.getSolidFireConnection(storagePool.getId(), storagePoolDetailsDao);
                if (!sfConnections.contains(sfConnection)) {
                    sfConnections.add(sfConnection);
                    List<SolidFireUtil.SolidFireVag> sfVags = SolidFireUtil.getAllVags(sfConnection);
                    SolidFireVag sfVag = getVolumeAccessGroup(hostVO.getStorageUrl(), sfVags);
                    if (sfVag != null) {
                        placeVolumeIdsInVag(sfConnection, sfVags, sfVag, hostVO, hostDao);
                    } else {
                        handleVagForHost(sfConnection, sfVags, hostVO, hostDao, clusterDao);
                    }
                }
            }
        }
    } finally {
        lock.unlock();
        lock.releaseRef();
    }
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) GlobalLock(com.cloud.utils.db.GlobalLock) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Aggregations

StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)276 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)106 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)75 ArrayList (java.util.ArrayList)54 VolumeVO (com.cloud.storage.VolumeVO)53 HostVO (com.cloud.host.HostVO)46 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)45 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)45 HashMap (java.util.HashMap)44 Answer (com.cloud.agent.api.Answer)38 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)35 StoragePool (com.cloud.storage.StoragePool)33 Test (org.junit.Test)33 VMInstanceVO (com.cloud.vm.VMInstanceVO)25 Map (java.util.Map)25 Account (com.cloud.user.Account)24 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)20 ExecutionException (java.util.concurrent.ExecutionException)20 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 ClusterVO (com.cloud.dc.ClusterVO)18