Search in sources :

Example 61 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class VmwareManagerImpl method listVsphereStoragePolicyCompatibleStoragePools.

@Override
public List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsphereStoragePolicyCompatiblePoolsCmd cmd) {
    Long policyId = cmd.getPolicyId();
    VsphereStoragePolicyVO storagePolicy = vsphereStoragePolicyDao.findById(policyId);
    if (storagePolicy == null) {
        throw new CloudRuntimeException("Storage policy with ID = " + policyId + " was not found");
    }
    long zoneId = storagePolicy.getZoneId();
    List<StoragePoolVO> poolsInZone = primaryStorageDao.listByStatusInZone(zoneId, StoragePoolStatus.Up);
    List<StoragePool> compatiblePools = new ArrayList<>();
    for (StoragePoolVO pool : poolsInZone) {
        StorageFilerTO storageFilerTO = new StorageFilerTO(pool);
        List<Long> hostIds = storageManager.getUpHostsInPool(pool.getId());
        if (CollectionUtils.isNullOrEmpty(hostIds)) {
            s_logger.debug("Did not find a suitable host to verify compatibility of the pool " + pool.getName());
            continue;
        }
        Collections.shuffle(hostIds);
        CheckDataStoreStoragePolicyComplainceCommand command = new CheckDataStoreStoragePolicyComplainceCommand(storagePolicy.getPolicyId(), storageFilerTO);
        long targetHostId = hypervisorGuruManager.getGuruProcessedCommandTargetHost(hostIds.get(0), command);
        try {
            Answer answer = _agentMgr.send(targetHostId, command);
            boolean result = answer != null && answer.getResult();
            if (result) {
                compatiblePools.add(pool);
            }
        } catch (AgentUnavailableException | OperationTimedoutException e) {
            s_logger.error("Could not verify if storage policy " + storagePolicy.getName() + " is compatible with storage pool " + pool.getName());
        }
    }
    return compatiblePools;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) StoragePool(com.cloud.storage.StoragePool) CheckDataStoreStoragePolicyComplainceCommand(org.apache.cloudstack.storage.command.CheckDataStoreStoragePolicyComplainceCommand) ArrayList(java.util.ArrayList) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VsphereStoragePolicyVO(com.cloud.dc.VsphereStoragePolicyVO)

Example 62 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class VMwareGuru method finalizeMigrate.

@Override
public List<Command> finalizeMigrate(VirtualMachine vm, Map<Volume, StoragePool> volumeToPool) {
    List<Command> commands = new ArrayList<Command>();
    // OfflineVmwareMigration: specialised migration command
    List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerTo = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
    Long poolClusterId = null;
    for (Map.Entry<Volume, StoragePool> entry : volumeToPool.entrySet()) {
        Volume volume = entry.getKey();
        StoragePool pool = entry.getValue();
        VolumeTO volumeTo = new VolumeTO(volume, _storagePoolDao.findById(pool.getId()));
        StorageFilerTO filerTo = new StorageFilerTO(pool);
        if (pool.getClusterId() != null) {
            poolClusterId = pool.getClusterId();
        }
        volumeToFilerTo.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
    }
    final Long destClusterId = poolClusterId;
    final Long srcClusterId = vmManager.findClusterAndHostIdForVm(vm.getId()).first();
    final boolean isInterClusterMigration = isInterClusterMigration(destClusterId, srcClusterId);
    MigrateVmToPoolCommand migrateVmToPoolCommand = new MigrateVmToPoolCommand(vm.getInstanceName(), volumeToFilerTo, getHostGuidInTargetCluster(isInterClusterMigration, destClusterId), true);
    commands.add(migrateVmToPoolCommand);
    // OfflineVmwareMigration: cleanup if needed
    if (isInterClusterMigration) {
        final String srcDcName = _clusterDetailsDao.getVmwareDcName(srcClusterId);
        final String destDcName = _clusterDetailsDao.getVmwareDcName(destClusterId);
        if (srcDcName != null && destDcName != null && !srcDcName.equals(destDcName)) {
            final UnregisterVMCommand unregisterVMCommand = new UnregisterVMCommand(vm.getInstanceName(), true);
            unregisterVMCommand.setCleanupVmFiles(true);
            commands.add(unregisterVMCommand);
        }
    }
    return commands;
}
Also used : StoragePool(com.cloud.storage.StoragePool) ArrayList(java.util.ArrayList) UnregisterVMCommand(com.cloud.agent.api.UnregisterVMCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VolumeTO(com.cloud.agent.api.to.VolumeTO) MigrateVmToPoolCommand(com.cloud.agent.api.MigrateVmToPoolCommand) CreateVolumeOVACommand(com.cloud.agent.api.storage.CreateVolumeOVACommand) PrepareOVAPackingCommand(com.cloud.agent.api.storage.PrepareOVAPackingCommand) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) UnregisterNicCommand(com.cloud.agent.api.UnregisterNicCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) MigrateVmToPoolCommand(com.cloud.agent.api.MigrateVmToPoolCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) Command(com.cloud.agent.api.Command) UnregisterVMCommand(com.cloud.agent.api.UnregisterVMCommand) DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) Volume(com.cloud.storage.Volume) Map(java.util.Map) HashMap(java.util.HashMap) Pair(com.cloud.utils.Pair)

Example 63 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class RandomStoragePoolAllocator method select.

@Override
public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
    List<StoragePool> suitablePools = new ArrayList<StoragePool>();
    long dcId = plan.getDataCenterId();
    Long podId = plan.getPodId();
    Long clusterId = plan.getClusterId();
    if (podId == null) {
        return null;
    }
    s_logger.debug("Looking for pools in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId);
    List<StoragePoolVO> pools = storagePoolDao.listBy(dcId, podId, clusterId, ScopeType.CLUSTER);
    if (pools.size() == 0) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("No storage pools available for allocation, returning");
        }
        return suitablePools;
    }
    Collections.shuffle(pools);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("RandomStoragePoolAllocator has " + pools.size() + " pools to check for allocation");
    }
    for (StoragePoolVO pool : pools) {
        if (suitablePools.size() == returnUpTo) {
            break;
        }
        StoragePool pol = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(pool.getId());
        if (filter(avoid, pol, dskCh, plan)) {
            suitablePools.add(pol);
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("RandomStoragePoolAllocator returning " + suitablePools.size() + " suitable storage pools");
    }
    return suitablePools;
}
Also used : StoragePool(com.cloud.storage.StoragePool) ArrayList(java.util.ArrayList) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 64 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class AncientDataMotionStrategy method addFullCloneAndDiskprovisiongStrictnessFlagOnVMwareDest.

/**
 * Adds {@code 'vmware.create.full.clone'} value for a given primary storage, whose HV is VMware, on datastore's {@code fullCloneFlag} field
 * @param dataTO Dest data store TO
 * @return dataTO including fullCloneFlag, if provided
 */
protected DataTO addFullCloneAndDiskprovisiongStrictnessFlagOnVMwareDest(DataTO dataTO) {
    if (dataTO != null && dataTO.getHypervisorType().equals(Hypervisor.HypervisorType.VMware)) {
        DataStoreTO dataStoreTO = dataTO.getDataStore();
        if (dataStoreTO != null && dataStoreTO instanceof PrimaryDataStoreTO) {
            PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO;
            primaryDataStoreTO.setFullCloneFlag(CapacityManager.VmwareCreateCloneFull.valueIn(primaryDataStoreTO.getId()));
            StoragePool pool = storageManager.getStoragePool(primaryDataStoreTO.getId());
            primaryDataStoreTO.setDiskProvisioningStrictnessFlag(storageManager.DiskProvisioningStrictness.valueIn(pool.getDataCenterId()));
        }
    }
    return dataTO;
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) StoragePool(com.cloud.storage.StoragePool) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO)

Example 65 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class AncientDataMotionStrategy method copyVolumeFromSnapshot.

protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) {
    SnapshotInfo snapshot = (SnapshotInfo) snapObj;
    StoragePool pool = (StoragePool) volObj.getDataStore();
    String basicErrMsg = "Failed to create volume from " + snapshot.getName() + " on pool " + pool;
    DataStore store = snapObj.getDataStore();
    DataStoreTO storTO = store.getTO();
    DataObject srcData = snapObj;
    try {
        if (!(storTO instanceof NfsTO)) {
            // cache snapshot to zone-wide staging store for the volume to be created
            srcData = cacheSnapshotChain(snapshot, new ZoneScope(pool.getDataCenterId()));
        }
        String value = configDao.getValue(Config.CreateVolumeFromSnapshotWait.toString());
        int _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.CreateVolumeFromSnapshotWait.getDefaultValue()));
        EndPoint ep = null;
        if (srcData.getDataStore().getRole() == DataStoreRole.Primary) {
            ep = selector.select(volObj);
        } else {
            ep = selector.select(srcData, volObj);
        }
        CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneAndDiskprovisiongStrictnessFlagOnVMwareDest(volObj.getTO()), _createVolumeFromSnapshotWait, VirtualMachineManager.ExecuteInSequence.value());
        Answer answer = null;
        if (ep == null) {
            String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        return answer;
    } catch (Exception e) {
        s_logger.error(basicErrMsg, e);
        throw new CloudRuntimeException(basicErrMsg);
    } finally {
        if (!(storTO instanceof NfsTO)) {
            // still keep snapshot on cache which may be migrated from previous secondary storage
            releaseSnapshotCacheChain((SnapshotInfo) srcData);
        }
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) StoragePool(com.cloud.storage.StoragePool) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) NfsTO(com.cloud.agent.api.to.NfsTO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore)

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