Search in sources :

Example 36 with StoragePool

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

the class VolumeOrchestrator method cleanupVolumeDuringMigrationFailure.

private void cleanupVolumeDuringMigrationFailure(Long volumeId, Long destPoolId) {
    StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destPoolId, DataStoreRole.Primary);
    if (destPool == null) {
        return;
    }
    VolumeVO volume = _volsDao.findById(volumeId);
    if (volume.getState() == Volume.State.Migrating) {
        VolumeVO duplicateVol = _volsDao.findByPoolIdName(destPoolId, volume.getName());
        if (duplicateVol != null) {
            s_logger.debug("Remove volume " + duplicateVol.getId() + " on storage pool " + destPoolId);
            _volsDao.remove(duplicateVol.getId());
        }
        s_logger.debug("change volume state to ready from migrating in case migration failure for vol: " + volumeId);
        volume.setState(Volume.State.Ready);
        _volsDao.update(volumeId, volume);
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO)

Example 37 with StoragePool

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

the class StoragePoolJoinDaoImpl method newStoragePoolResponse.

@Override
public StoragePoolResponse newStoragePoolResponse(StoragePoolJoinVO pool) {
    StoragePool storagePool = storagePoolDao.findById(pool.getId());
    StoragePoolResponse poolResponse = new StoragePoolResponse();
    poolResponse.setId(pool.getUuid());
    poolResponse.setName(pool.getName());
    poolResponse.setState(pool.getStatus());
    String path = pool.getPath();
    // cifs store may contain password entry, remove the password
    path = StringUtils.cleanString(path);
    poolResponse.setPath(path);
    poolResponse.setIpAddress(pool.getHostAddress());
    poolResponse.setZoneId(pool.getZoneUuid());
    poolResponse.setZoneName(pool.getZoneName());
    poolResponse.setType(pool.getPoolType().toString());
    poolResponse.setPodId(pool.getPodUuid());
    poolResponse.setPodName(pool.getPodName());
    poolResponse.setCreated(pool.getCreated());
    if (pool.getScope() != null) {
        poolResponse.setScope(pool.getScope().toString());
    }
    if (pool.getHypervisor() != null) {
        poolResponse.setHypervisor(pool.getHypervisor().toString());
    }
    StoragePoolDetailVO poolType = storagePoolDetailsDao.findDetail(pool.getId(), "pool_type");
    if (poolType != null) {
        poolResponse.setType(poolType.getValue());
    }
    long allocatedSize = pool.getUsedCapacity() + pool.getReservedCapacity();
    if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
        List<StoragePoolVO> childDatastores = storagePoolDao.listChildStoragePoolsInDatastoreCluster(pool.getId());
        if (childDatastores != null) {
            for (StoragePoolVO childDatastore : childDatastores) {
                StoragePoolJoinVO childDSJoinVO = findById(childDatastore.getId());
                allocatedSize += (childDSJoinVO.getUsedCapacity() + childDSJoinVO.getReservedCapacity());
            }
        }
    }
    poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
    poolResponse.setDiskSizeAllocated(allocatedSize);
    poolResponse.setCapacityIops(pool.getCapacityIops());
    if (storagePool.isManaged()) {
        DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
        PrimaryDataStoreDriver driver = (PrimaryDataStoreDriver) store.getDriver();
        long usedIops = driver.getUsedIops(storagePool);
        poolResponse.setAllocatedIops(usedIops);
    }
    // TODO: StatsCollector does not persist data
    StorageStats stats = ApiDBUtils.getStoragePoolStatistics(pool.getId());
    if (stats != null) {
        Long used = stats.getByteUsed();
        poolResponse.setDiskSizeUsed(used);
    }
    poolResponse.setClusterId(pool.getClusterUuid());
    poolResponse.setClusterName(pool.getClusterName());
    poolResponse.setProvider(pool.getStorageProviderName());
    poolResponse.setTags(pool.getTag());
    poolResponse.setOverProvisionFactor(Double.toString(CapacityManager.StorageOverprovisioningFactor.valueIn(pool.getId())));
    // set async job
    if (pool.getJobId() != null) {
        poolResponse.setJobId(pool.getJobUuid());
        poolResponse.setJobStatus(pool.getJobStatus());
    }
    poolResponse.setHasAnnotation(annotationDao.hasAnnotations(pool.getUuid(), AnnotationService.EntityType.PRIMARY_STORAGE.name(), accountManager.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    poolResponse.setObjectName("storagepool");
    return poolResponse;
}
Also used : StoragePoolResponse(org.apache.cloudstack.api.response.StoragePoolResponse) StoragePool(com.cloud.storage.StoragePool) StorageStats(com.cloud.storage.StorageStats) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StoragePoolDetailVO(org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO) StoragePoolJoinVO(com.cloud.api.query.vo.StoragePoolJoinVO)

Example 38 with StoragePool

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

the class AbstractStoragePoolAllocator method reorderPoolsByCapacity.

protected List<StoragePool> reorderPoolsByCapacity(DeploymentPlan plan, List<StoragePool> pools) {
    Long zoneId = plan.getDataCenterId();
    Long clusterId = plan.getClusterId();
    short capacityType;
    if (pools != null && pools.size() != 0) {
        capacityType = pools.get(0).getPoolType().isShared() ? Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED : Capacity.CAPACITY_TYPE_LOCAL_STORAGE;
    } else {
        return null;
    }
    List<Long> poolIdsByCapacity = capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("List of pools in descending order of free capacity: " + poolIdsByCapacity);
    }
    // now filter the given list of Pools by this ordered list
    Map<Long, StoragePool> poolMap = new HashMap<>();
    for (StoragePool pool : pools) {
        poolMap.put(pool.getId(), pool);
    }
    List<Long> matchingPoolIds = new ArrayList<>(poolMap.keySet());
    poolIdsByCapacity.retainAll(matchingPoolIds);
    List<StoragePool> reorderedPools = new ArrayList<>();
    for (Long id : poolIdsByCapacity) {
        reorderedPools.add(poolMap.get(id));
    }
    return reorderedPools;
}
Also used : StoragePool(com.cloud.storage.StoragePool) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 39 with StoragePool

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

the class DefaultHostListener method hostConnect.

@Override
public boolean hostConnect(long hostId, long poolId) throws StorageConflictException {
    StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
    final Answer answer = agentMgr.easySend(hostId, cmd);
    if (answer == null) {
        throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
    }
    if (!answer.getResult()) {
        String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
        alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
        throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
    }
    assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
    ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
    if (mspAnswer.getLocalDatastoreName() != null && pool.isShared()) {
        String datastoreName = mspAnswer.getLocalDatastoreName();
        List<StoragePoolVO> localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName);
        for (StoragePoolVO localStoragePool : localStoragePools) {
            if (datastoreName.equals(localStoragePool.getPath())) {
                s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName());
                throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName());
            }
        }
    }
    StoragePoolVO poolVO = this.primaryStoreDao.findById(poolId);
    updateStoragePoolHostVOAndDetails(poolVO, hostId, mspAnswer);
    if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
        storageManager.syncDatastoreClusterStoragePool(poolId, ((ModifyStoragePoolAnswer) answer).getDatastoreClusterChildren(), hostId);
    }
    storageService.updateStorageCapabilities(poolId, false);
    s_logger.info("Connection established between storage pool " + pool + " and host " + hostId);
    return true;
}
Also used : ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StorageConflictException(com.cloud.exception.StorageConflictException) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Example 40 with StoragePool

use of com.cloud.storage.StoragePool 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)

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