use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class StorageCacheReplacementAlgorithmLRUTest method testSelectObjectFailed.
@Test
public void testSelectObjectFailed() {
cacheReplacementAlgorithm.setUnusedTimeInterval(1);
try {
VMTemplateVO template = new VMTemplateVO();
template.setTemplateType(Storage.TemplateType.USER);
template.setUrl(UUID.randomUUID().toString());
template.setUniqueName(UUID.randomUUID().toString());
template.setName(UUID.randomUUID().toString());
template.setPublicTemplate(true);
template.setFeatured(true);
template.setRequiresHvm(true);
template.setBits(64);
template.setFormat(Storage.ImageFormat.VHD);
template.setEnablePassword(true);
template.setEnableSshKey(true);
template.setGuestOSId(1);
template.setBootable(true);
template.setPrepopulate(true);
template.setCrossZones(true);
template.setExtractable(true);
template = templateDao.persist(template);
VMTemplateVO template2 = new VMTemplateVO();
template2.setTemplateType(Storage.TemplateType.USER);
template2.setUrl(UUID.randomUUID().toString());
template2.setUniqueName(UUID.randomUUID().toString());
template2.setName(UUID.randomUUID().toString());
template2.setPublicTemplate(true);
template2.setFeatured(true);
template2.setRequiresHvm(true);
template2.setBits(64);
template2.setFormat(Storage.ImageFormat.VHD);
template2.setEnablePassword(true);
template2.setEnableSshKey(true);
template2.setGuestOSId(1);
template2.setBootable(true);
template2.setPrepopulate(true);
template2.setCrossZones(true);
template2.setExtractable(true);
template2 = templateDao.persist(template2);
ImageStoreVO imageStoreVO = new ImageStoreVO();
imageStoreVO.setRole(DataStoreRole.ImageCache);
imageStoreVO.setName(UUID.randomUUID().toString());
imageStoreVO.setProviderName(DataStoreProvider.NFS_IMAGE);
imageStoreVO.setProtocol("nfs");
imageStoreVO.setUrl(UUID.randomUUID().toString());
imageStoreVO = imageStoreDao.persist(imageStoreVO);
Date date = DateUtil.now();
TemplateDataStoreVO templateStoreVO1 = new TemplateDataStoreVO();
templateStoreVO1.setLastUpdated(date);
templateStoreVO1.setDataStoreRole(DataStoreRole.ImageCache);
templateStoreVO1.setDataStoreId(imageStoreVO.getId());
templateStoreVO1.setState(ObjectInDataStoreStateMachine.State.Ready);
templateStoreVO1.setCopy(true);
templateStoreVO1.setTemplateId(template.getId());
templateDataStoreDao.persist(templateStoreVO1);
TemplateDataStoreVO templateStoreVO2 = new TemplateDataStoreVO();
templateStoreVO2.setLastUpdated(date);
templateStoreVO2.setDataStoreRole(DataStoreRole.ImageCache);
templateStoreVO2.setDataStoreId(imageStoreVO.getId());
templateStoreVO2.setState(ObjectInDataStoreStateMachine.State.Ready);
templateStoreVO2.setCopy(true);
templateStoreVO2.setTemplateId(template2.getId());
templateDataStoreDao.persist(templateStoreVO2);
DataStore store = dataStoreManager.getDataStore(imageStoreVO.getId(), DataStoreRole.ImageCache);
Assert.assertNull(cacheReplacementAlgorithm.chooseOneToBeReplaced(store));
} catch (Exception e) {
Assert.fail();
}
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method cacheSnapshotChain.
private DataObject cacheSnapshotChain(SnapshotInfo snapshot, Scope scope) {
DataObject leafData = null;
DataStore store = cacheMgr.getCacheStorage(snapshot, scope);
while (snapshot != null) {
DataObject cacheData = cacheMgr.createCacheObject(snapshot, store);
if (leafData == null) {
leafData = cacheData;
}
snapshot = snapshot.getParent();
}
return leafData;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method internalCanHandle.
/**
* Handles migrating volumes on managed Storage.
*/
protected StrategyPriority internalCanHandle(Map<VolumeInfo, DataStore> volumeMap, Host srcHost, Host destHost) {
Set<VolumeInfo> volumeInfoSet = volumeMap.keySet();
for (VolumeInfo volumeInfo : volumeInfoSet) {
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volumeInfo.getPoolId());
if (storagePoolVO.isManaged()) {
return StrategyPriority.HIGHEST;
}
}
Collection<DataStore> dataStores = volumeMap.values();
for (DataStore dataStore : dataStores) {
StoragePoolVO storagePoolVO = _storagePoolDao.findById(dataStore.getId());
if (storagePoolVO.isManaged()) {
return StrategyPriority.HIGHEST;
}
}
return StrategyPriority.CANT_HANDLE;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method isSourceAndDestinationPoolTypeOfNfs.
/**
* Returns true if at least one of the entries on the map 'volumeDataStoreMap' has both source and destination storage pools of Network Filesystem (NFS).
*/
protected boolean isSourceAndDestinationPoolTypeOfNfs(Map<VolumeInfo, DataStore> volumeDataStoreMap) {
for (Map.Entry<VolumeInfo, DataStore> entry : volumeDataStoreMap.entrySet()) {
VolumeInfo srcVolumeInfo = entry.getKey();
DataStore destDataStore = entry.getValue();
StoragePoolVO destStoragePool = _storagePoolDao.findById(destDataStore.getId());
StoragePoolVO sourceStoragePool = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
if (sourceStoragePool.getPoolType() == StoragePoolType.NetworkFilesystem && destStoragePool.getPoolType() == StoragePoolType.NetworkFilesystem) {
return true;
}
}
return false;
}
use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleCreateNonManagedVolumeFromManagedSnapshot.
private void handleCreateNonManagedVolumeFromManagedSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
if (!HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType())) {
String errMsg = "Creating a volume on non-managed storage from a snapshot on managed storage is currently only supported with XenServer.";
handleError(errMsg, callback);
}
long volumeStoragePoolId = volumeInfo.getDataStore().getId();
StoragePoolVO volumeStoragePoolVO = _storagePoolDao.findById(volumeStoragePoolId);
if (volumeStoragePoolVO.getClusterId() == null) {
String errMsg = "To create a non-managed volume from a managed snapshot, the destination storage pool must be cluster scoped.";
handleError(errMsg, callback);
}
String errMsg = null;
CopyCmdAnswer copyCmdAnswer = null;
boolean usingBackendSnapshot = false;
try {
snapshotInfo.processEvent(Event.CopyingRequested);
usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
if (usingBackendSnapshot) {
boolean computeClusterSupportsVolumeClone = clusterDao.getSupportsResigning(volumeStoragePoolVO.getClusterId());
if (!computeClusterSupportsVolumeClone) {
String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + volumeStoragePoolVO.getClusterId();
LOGGER.warn(noSupportForResignErrMsg);
throw new CloudRuntimeException(noSupportForResignErrMsg);
}
createVolumeFromSnapshot(snapshotInfo);
HostVO hostVO = getHost(snapshotInfo.getDataCenterId(), HypervisorType.XenServer, true);
copyCmdAnswer = performResignature(snapshotInfo, hostVO, null, true);
verifyCopyCmdAnswer(copyCmdAnswer, snapshotInfo);
}
int primaryStorageDownloadWait = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value();
CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
HostVO hostVO = getHostInCluster(volumeStoragePoolVO.getClusterId());
if (!usingBackendSnapshot) {
long snapshotStoragePoolId = snapshotInfo.getDataStore().getId();
DataStore snapshotDataStore = dataStoreMgr.getDataStore(snapshotStoragePoolId, DataStoreRole.Primary);
_volumeService.grantAccess(snapshotInfo, hostVO, snapshotDataStore);
}
Map<String, String> srcDetails = getSnapshotDetails(snapshotInfo);
copyCommand.setOptions(srcDetails);
copyCmdAnswer = (CopyCmdAnswer) agentManager.send(hostVO.getId(), copyCommand);
if (!copyCmdAnswer.getResult()) {
errMsg = copyCmdAnswer.getDetails();
LOGGER.warn(errMsg);
throw new CloudRuntimeException(errMsg);
}
} catch (Exception ex) {
errMsg = "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateNonManagedVolumeFromManagedSnapshot': " + ex.getMessage();
throw new CloudRuntimeException(errMsg);
} finally {
try {
HostVO hostVO = getHostInCluster(volumeStoragePoolVO.getClusterId());
long snapshotStoragePoolId = snapshotInfo.getDataStore().getId();
DataStore snapshotDataStore = dataStoreMgr.getDataStore(snapshotStoragePoolId, DataStoreRole.Primary);
_volumeService.revokeAccess(snapshotInfo, hostVO, snapshotDataStore);
} catch (Exception e) {
LOGGER.debug("Failed to revoke access from dest volume", e);
}
if (usingBackendSnapshot) {
deleteVolumeFromSnapshot(snapshotInfo);
}
try {
if (StringUtils.isEmpty(errMsg)) {
snapshotInfo.processEvent(Event.OperationSuccessed);
} else {
snapshotInfo.processEvent(Event.OperationFailed);
}
} catch (Exception ex) {
LOGGER.warn("Error processing snapshot event: " + ex.getMessage(), ex);
}
if (copyCmdAnswer == null) {
copyCmdAnswer = new CopyCmdAnswer(errMsg);
}
CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
result.setResult(errMsg);
callback.complete(result);
}
}
Aggregations