Search in sources :

Example 21 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class PrimaryDataStoreHelper method enable.

public boolean enable(final DataStore store) {
    final StoragePoolVO pool = this.dataStoreDao.findById(store.getId());
    pool.setStatus(StoragePoolStatus.Up);
    dataStoreDao.update(pool.getId(), pool);
    return true;
}
Also used : StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 22 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class PrimaryDataStoreHelper method createPrimaryDataStore.

public DataStore createPrimaryDataStore(final PrimaryDataStoreParameters params) {
    if (params == null) {
        throw new InvalidParameterValueException("createPrimaryDataStore: Input params is null, please check");
    }
    StoragePoolVO dataStoreVO = dataStoreDao.findPoolByUUID(params.getUuid());
    if (dataStoreVO != null) {
        throw new CloudRuntimeException("duplicate uuid: " + params.getUuid());
    }
    dataStoreVO = new StoragePoolVO();
    dataStoreVO.setStorageProviderName(params.getProviderName());
    dataStoreVO.setHostAddress(params.getHost());
    dataStoreVO.setPoolType(params.getType());
    dataStoreVO.setPath(params.getPath());
    dataStoreVO.setPort(params.getPort());
    dataStoreVO.setName(params.getName());
    dataStoreVO.setUuid(params.getUuid());
    dataStoreVO.setDataCenterId(params.getZoneId());
    dataStoreVO.setPodId(params.getPodId());
    dataStoreVO.setClusterId(params.getClusterId());
    dataStoreVO.setStatus(StoragePoolStatus.Initialized);
    dataStoreVO.setUserInfo(params.getUserInfo());
    dataStoreVO.setManaged(params.isManaged());
    dataStoreVO.setCapacityIops(params.getCapacityIops());
    dataStoreVO.setCapacityBytes(params.getCapacityBytes());
    dataStoreVO.setUsedBytes(params.getUsedBytes());
    dataStoreVO.setHypervisor(params.getHypervisorType());
    final Map<String, String> details = params.getDetails();
    if (params.getType() == StoragePoolType.SMB && details != null) {
        final String user = details.get("user");
        String password = details.get("password");
        final String domain = details.get("domain");
        String updatedPath = params.getPath();
        if (user == null || password == null) {
            final String errMsg = "Missing cifs user and password details. Add them as details parameter.";
            s_logger.warn(errMsg);
            throw new InvalidParameterValueException(errMsg);
        } else {
            try {
                password = DBEncryptionUtil.encrypt(URLEncoder.encode(password, "UTF-8"));
                details.put("password", password);
                updatedPath += "?user=" + user + "&password=" + password + "&domain=" + domain;
            } catch (final UnsupportedEncodingException e) {
                throw new CloudRuntimeException("Error while generating the cifs url. " + e.getMessage());
            }
        }
        dataStoreVO.setPath(updatedPath);
    }
    final String tags = params.getTags();
    if (tags != null) {
        final String[] tokens = tags.split(",");
        for (String tag : tokens) {
            tag = tag.trim();
            if (tag.length() == 0) {
                continue;
            }
            details.put(tag, "true");
        }
    }
    dataStoreVO = dataStoreDao.persist(dataStoreVO, details);
    return dataStoreMgr.getDataStore(dataStoreVO.getId(), DataStoreRole.Primary);
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 23 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class PrimaryDataStoreHelper method attachCluster.

public DataStore attachCluster(final DataStore store) {
    final StoragePoolVO pool = this.dataStoreDao.findById(store.getId());
    storageMgr.createCapacityEntry(pool.getId());
    pool.setScope(ScopeType.CLUSTER);
    pool.setStatus(StoragePoolStatus.Up);
    this.dataStoreDao.update(pool.getId(), pool);
    return dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
Also used : StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Example 24 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class StorageSystemSnapshotStrategy method performSnapshotAndCopyOnHostSide.

private void performSnapshotAndCopyOnHostSide(final VolumeInfo volumeInfo, final SnapshotInfo snapshotInfo) {
    Map<String, String> sourceDetails = null;
    final VolumeVO volumeVO = _volumeDao.findById(volumeInfo.getId());
    final Long vmInstanceId = volumeVO.getInstanceId();
    final VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(vmInstanceId);
    Long hostId = null;
    // if the volume to snapshot is associated with a VM
    if (vmInstanceVO != null) {
        hostId = vmInstanceVO.getHostId();
        // if the VM is not associated with a host
        if (hostId == null) {
            hostId = vmInstanceVO.getLastHostId();
            if (hostId == null) {
                sourceDetails = getSourceDetails(volumeInfo);
            }
        }
    } else // volume to snapshot is not associated with a VM (could be a data disk in the detached state)
    {
        sourceDetails = getSourceDetails(volumeInfo);
    }
    final HostVO hostVO = getHost(hostId, volumeVO);
    final long storagePoolId = volumeVO.getPoolId();
    final StoragePoolVO storagePoolVO = _storagePoolDao.findById(storagePoolId);
    final DataStore dataStore = _dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    final Map<String, String> destDetails = getDestDetails(storagePoolVO, snapshotInfo);
    final SnapshotAndCopyCommand snapshotAndCopyCommand = new SnapshotAndCopyCommand(volumeInfo.getPath(), sourceDetails, destDetails);
    SnapshotAndCopyAnswer snapshotAndCopyAnswer = null;
    try {
        // if sourceDetails != null, we need to connect the host(s) to the volume
        if (sourceDetails != null) {
            _volService.grantAccess(volumeInfo, hostVO, dataStore);
        }
        _volService.grantAccess(snapshotInfo, hostVO, dataStore);
        snapshotAndCopyAnswer = (SnapshotAndCopyAnswer) _agentMgr.send(hostVO.getId(), snapshotAndCopyCommand);
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    } finally {
        try {
            _volService.revokeAccess(snapshotInfo, hostVO, dataStore);
            // if sourceDetails != null, we need to disconnect the host(s) from the volume
            if (sourceDetails != null) {
                _volService.revokeAccess(volumeInfo, hostVO, dataStore);
            }
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
    }
    if (snapshotAndCopyAnswer == null || !snapshotAndCopyAnswer.getResult()) {
        final String errMsg;
        if (snapshotAndCopyAnswer != null && snapshotAndCopyAnswer.getDetails() != null && !snapshotAndCopyAnswer.getDetails().isEmpty()) {
            errMsg = snapshotAndCopyAnswer.getDetails();
        } else {
            errMsg = "Unable to perform host-side operation";
        }
        throw new CloudRuntimeException(errMsg);
    }
    // for XenServer, this is the VDI's UUID
    final String path = snapshotAndCopyAnswer.getPath();
    final SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(snapshotInfo.getId(), DiskTO.PATH, path, false);
    _snapshotDetailsDao.persist(snapshotDetail);
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) HostVO(com.cloud.host.HostVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) SnapshotAndCopyAnswer(com.cloud.storage.command.SnapshotAndCopyAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) SnapshotAndCopyCommand(com.cloud.storage.command.SnapshotAndCopyCommand)

Example 25 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class PrimaryDataStoreProviderManagerImpl method getPrimaryDataStore.

@Override
public PrimaryDataStore getPrimaryDataStore(final long dataStoreId) {
    final StoragePoolVO dataStoreVO = dataStoreDao.findById(dataStoreId);
    if (dataStoreVO == null) {
        throw new CloudRuntimeException("Unable to locate datastore with id " + dataStoreId);
    }
    final String providerName = dataStoreVO.getStorageProviderName();
    final DataStoreProvider provider = providerManager.getDataStoreProvider(providerName);
    final PrimaryDataStoreImpl dataStore = PrimaryDataStoreImpl.createDataStore(dataStoreVO, driverMaps.get(provider.getName()), provider);
    return dataStore;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStoreImpl(com.cloud.storage.datastore.PrimaryDataStoreImpl) DataStoreProvider(com.cloud.engine.subsystem.api.storage.DataStoreProvider) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Aggregations

StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)86 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22 Test (org.junit.Test)18 HostVO (com.cloud.host.HostVO)15 VolumeVO (com.cloud.storage.VolumeVO)15 ArrayList (java.util.ArrayList)15 Answer (com.cloud.agent.api.Answer)14 Account (com.cloud.user.Account)13 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)11 StoragePool (com.cloud.storage.StoragePool)10 AttachAnswer (com.cloud.storage.command.AttachAnswer)10 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 RebootAnswer (com.cloud.agent.api.RebootAnswer)8 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)8