Search in sources :

Example 6 with StoragePoolVO

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

the class ZoneWideStoragePoolAllocator method select.

@Override
protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
    s_logger.debug("ZoneWideStoragePoolAllocator to find storage pool");
    if (dskCh.useLocalStorage()) {
        return null;
    }
    if (s_logger.isTraceEnabled()) {
        // Log the pools details that are ignored because they are in disabled state
        List<StoragePoolVO> disabledPools = _storagePoolDao.findDisabledPoolsByScope(plan.getDataCenterId(), null, null, ScopeType.ZONE);
        if (disabledPools != null && !disabledPools.isEmpty()) {
            for (StoragePoolVO pool : disabledPools) {
                s_logger.trace("Ignoring pool " + pool + " as it is in disabled state.");
            }
        }
    }
    List<StoragePool> suitablePools = new ArrayList<StoragePool>();
    List<StoragePoolVO> storagePools = _storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags());
    if (storagePools == null) {
        storagePools = new ArrayList<StoragePoolVO>();
    }
    List<StoragePoolVO> anyHypervisorStoragePools = new ArrayList<StoragePoolVO>();
    for (StoragePoolVO storagePool : storagePools) {
        if (HypervisorType.Any.equals(storagePool.getHypervisor())) {
            anyHypervisorStoragePools.add(storagePool);
        }
    }
    List<StoragePoolVO> storagePoolsByHypervisor = _storagePoolDao.findZoneWideStoragePoolsByHypervisor(plan.getDataCenterId(), dskCh.getHypervisorType());
    storagePools.retainAll(storagePoolsByHypervisor);
    storagePools.addAll(anyHypervisorStoragePools);
    // add remaining pools in zone, that did not match tags, to avoid set
    List<StoragePoolVO> allPools = _storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), null);
    allPools.removeAll(storagePools);
    for (StoragePoolVO pool : allPools) {
        avoid.addPool(pool.getId());
    }
    for (StoragePoolVO storage : storagePools) {
        if (suitablePools.size() == returnUpTo) {
            break;
        }
        StoragePool storagePool = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(storage.getId());
        if (filter(avoid, storagePool, dskCh, plan)) {
            suitablePools.add(storagePool);
        } else {
            avoid.addPool(storagePool.getId());
        }
    }
    return suitablePools;
}
Also used : StoragePool(com.cloud.storage.StoragePool) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList)

Example 7 with StoragePoolVO

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

the class VolumeApiServiceImpl method takeSnapshot.

@Override
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_CREATE, eventDescription = "taking snapshot", async = true)
public Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Account account, boolean quiescevm, Snapshot.LocationType locationType) throws ResourceAllocationException {
    VolumeInfo volume = volFactory.getVolume(volumeId);
    if (volume == null) {
        throw new InvalidParameterValueException("Creating snapshot failed due to volume:" + volumeId + " doesn't exist");
    }
    if (volume.getState() != Volume.State.Ready) {
        throw new InvalidParameterValueException("VolumeId: " + volumeId + " is not in " + Volume.State.Ready + " state but " + volume.getState() + ". Cannot take snapshot.");
    }
    StoragePoolVO storagePoolVO = _storagePoolDao.findById(volume.getPoolId());
    if (storagePoolVO.isManaged() && locationType == null) {
        locationType = Snapshot.LocationType.PRIMARY;
    }
    VMInstanceVO vm = null;
    if (volume.getInstanceId() != null)
        vm = _vmInstanceDao.findById(volume.getInstanceId());
    if (vm != null) {
        // serialize VM operation
        AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext();
        if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) {
            // avoid re-entrance
            VmWorkJobVO placeHolder = null;
            placeHolder = createPlaceHolderWork(vm.getId());
            try {
                return orchestrateTakeVolumeSnapshot(volumeId, policyId, snapshotId, account, quiescevm, locationType);
            } finally {
                _workJobDao.expunge(placeHolder.getId());
            }
        } else {
            Outcome<Snapshot> outcome = takeVolumeSnapshotThroughJobQueue(vm.getId(), volumeId, policyId, snapshotId, account.getId(), quiescevm, locationType);
            try {
                outcome.get();
            } catch (InterruptedException e) {
                throw new RuntimeException("Operation is interrupted", e);
            } catch (java.util.concurrent.ExecutionException e) {
                throw new RuntimeException("Execution excetion", e);
            }
            Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
            if (jobResult != null) {
                if (jobResult instanceof ConcurrentOperationException)
                    throw (ConcurrentOperationException) jobResult;
                else if (jobResult instanceof ResourceAllocationException)
                    throw (ResourceAllocationException) jobResult;
                else if (jobResult instanceof Throwable)
                    throw new RuntimeException("Unexpected exception", (Throwable) jobResult);
            }
            return _snapshotDao.findById(snapshotId);
        }
    } else {
        CreateSnapshotPayload payload = new CreateSnapshotPayload();
        payload.setSnapshotId(snapshotId);
        payload.setSnapshotPolicyId(policyId);
        payload.setAccount(account);
        payload.setQuiescevm(quiescevm);
        volume.addPayload(payload);
        return volService.takeSnapshot(volume);
    }
}
Also used : AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) VMInstanceVO(com.cloud.vm.VMInstanceVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO) ExecutionException(java.util.concurrent.ExecutionException) VmWorkTakeVolumeSnapshot(com.cloud.vm.VmWorkTakeVolumeSnapshot) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ActionEvent(com.cloud.event.ActionEvent)

Example 8 with StoragePoolVO

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

the class StoragePoolDetailsDaoImpl method addDetail.

@Override
public void addDetail(long resourceId, String key, String value, boolean display) {
    List<StoragePoolVO> ChildPools = _storagePoolDao.listChildStoragePoolsInDatastoreCluster(resourceId);
    for (StoragePoolVO childPool : ChildPools) {
        super.addDetail(new StoragePoolDetailVO(childPool.getId(), key, value, display));
    }
    super.addDetail(new StoragePoolDetailVO(resourceId, key, value, display));
}
Also used : StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StoragePoolDetailVO(org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO)

Example 9 with StoragePoolVO

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

the class StorageSystemDataMotionStrategy method copyManagedVolumeToSecondaryStorage.

private String copyManagedVolumeToSecondaryStorage(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, HostVO hostVO, String errMsg) {
    boolean srcVolumeDetached = srcVolumeInfo.getAttachedVM() == null;
    try {
        StoragePoolVO storagePoolVO = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
        Map<String, String> srcDetails = getVolumeDetails(srcVolumeInfo);
        CopyVolumeCommand copyVolumeCommand = new CopyVolumeCommand(srcVolumeInfo.getId(), destVolumeInfo.getPath(), storagePoolVO, destVolumeInfo.getDataStore().getUri(), true, StorageManager.KvmStorageOfflineMigrationWait.value(), true);
        copyVolumeCommand.setSrcData(srcVolumeInfo.getTO());
        copyVolumeCommand.setSrcDetails(srcDetails);
        handleQualityOfServiceForVolumeMigration(srcVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
        if (srcVolumeDetached) {
            _volumeService.grantAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
        }
        CopyVolumeAnswer copyVolumeAnswer = (CopyVolumeAnswer) agentManager.send(hostVO.getId(), copyVolumeCommand);
        if (copyVolumeAnswer == null || !copyVolumeAnswer.getResult()) {
            if (copyVolumeAnswer != null && StringUtils.isNotEmpty(copyVolumeAnswer.getDetails())) {
                throw new CloudRuntimeException(copyVolumeAnswer.getDetails());
            } else {
                throw new CloudRuntimeException(errMsg);
            }
        }
        return copyVolumeAnswer.getVolumePath();
    } catch (Exception ex) {
        String msg = "Failed to perform volume copy to secondary storage : ";
        LOGGER.warn(msg, ex);
        throw new CloudRuntimeException(msg + ex.getMessage());
    } finally {
        if (srcVolumeDetached) {
            _volumeService.revokeAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
        }
        handleQualityOfServiceForVolumeMigration(srcVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 10 with StoragePoolVO

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

the class SnapshotTestWithFakeData method createDataStore.

private DataStore createDataStore() throws URISyntaxException {
    StoragePoolVO pool = new StoragePoolVO();
    pool.setClusterId(clusterId);
    pool.setDataCenterId(dcId);
    URI uri = new URI("nfs://jfkdkf/fjdkfj");
    pool.setHostAddress(uri.getHost());
    pool.setPath(uri.getPath());
    pool.setPort(0);
    pool.setName(UUID.randomUUID().toString());
    pool.setUuid(UUID.randomUUID().toString());
    pool.setStatus(StoragePoolStatus.Up);
    pool.setPoolType(Storage.StoragePoolType.NetworkFilesystem);
    pool.setPodId(podId);
    pool.setScope(ScopeType.CLUSTER);
    pool.setStorageProviderName(DataStoreProvider.DEFAULT_PRIMARY);
    pool = primaryDataStoreDao.persist(pool);
    DataStore store = dataStoreManager.getPrimaryDataStore(pool.getId());
    return store;
}
Also used : DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) URI(java.net.URI)

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