Search in sources :

Example 36 with StoragePoolVO

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

the class PrimaryDataStoreHelper method attachCluster.

public DataStore attachCluster(DataStore store) {
    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);
    if (pool.getPoolType() == StoragePoolType.DatastoreCluster && pool.getParent() == 0) {
        List<StoragePoolVO> childDatastores = dataStoreDao.listChildStoragePoolsInDatastoreCluster(pool.getId());
        for (StoragePoolVO child : childDatastores) {
            child.setScope(ScopeType.CLUSTER);
            this.dataStoreDao.update(child.getId(), child);
        }
    }
    return dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
}
Also used : StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 37 with StoragePoolVO

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

the class PrimaryDataStoreHelper method maintain.

public boolean maintain(DataStore store) {
    StoragePoolVO pool = this.dataStoreDao.findById(store.getId());
    pool.setStatus(StoragePoolStatus.Maintenance);
    this.dataStoreDao.update(pool.getId(), pool);
    return true;
}
Also used : StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 38 with StoragePoolVO

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

the class PrimaryDataStoreHelper method attachHost.

public DataStore attachHost(DataStore store, HostScope scope, StoragePoolInfo existingInfo) {
    StoragePoolHostVO poolHost = storagePoolHostDao.findByPoolHost(store.getId(), scope.getScopeId());
    if (poolHost == null) {
        poolHost = new StoragePoolHostVO(store.getId(), scope.getScopeId(), existingInfo.getLocalPath());
        storagePoolHostDao.persist(poolHost);
    }
    StoragePoolVO pool = this.dataStoreDao.findById(store.getId());
    pool.setScope(scope.getScopeType());
    pool.setUsedBytes(existingInfo.getCapacityBytes() - existingInfo.getAvailableBytes());
    pool.setCapacityBytes(existingInfo.getCapacityBytes());
    pool.setStatus(StoragePoolStatus.Up);
    this.dataStoreDao.update(pool.getId(), pool);
    this.storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, pool.getUsedBytes());
    return dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
}
Also used : StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO)

Example 39 with StoragePoolVO

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

the class PrimaryDataStoreHelper method createPrimaryDataStore.

public DataStore createPrimaryDataStore(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());
    Map<String, String> details = params.getDetails();
    if (params.getType() == StoragePoolType.SMB && details != null) {
        String user = details.get("user");
        String password = details.get("password");
        String domain = details.get("domain");
        String updatedPath = params.getPath();
        if (user == null || password == null) {
            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 (UnsupportedEncodingException e) {
                throw new CloudRuntimeException("Error while generating the cifs url. " + e.getMessage());
            }
        }
        dataStoreVO.setPath(updatedPath);
    }
    String tags = params.getTags();
    List<String> storageTags = new ArrayList<String>();
    if (tags != null) {
        String[] tokens = tags.split(",");
        for (String tag : tokens) {
            tag = tag.trim();
            if (tag.length() == 0) {
                continue;
            }
            storageTags.add(tag);
        }
    }
    dataStoreVO = dataStoreDao.persist(dataStoreVO, details, storageTags);
    return dataStoreMgr.getDataStore(dataStoreVO.getId(), DataStoreRole.Primary);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 40 with StoragePoolVO

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

the class PrimaryDataStoreHelper method enable.

public boolean enable(DataStore store) {
    StoragePoolVO pool = this.dataStoreDao.findById(store.getId());
    pool.setStatus(StoragePoolStatus.Up);
    dataStoreDao.update(pool.getId(), pool);
    return true;
}
Also used : 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