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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations