use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class ImageStoreProviderManagerImpl method listImageStoresByScope.
@Override
public List<DataStore> listImageStoresByScope(final ZoneScope scope) {
final List<ImageStoreVO> stores = dataStoreDao.findByScope(scope);
final List<DataStore> imageStores = new ArrayList<>();
for (final ImageStoreVO store : stores) {
imageStores.add(getImageStore(store.getId()));
}
return imageStores;
}
use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class SnapshotDataFactoryImpl method getSnapshot.
@Override
public SnapshotInfo getSnapshot(final long snapshotId, final DataStoreRole role) {
final SnapshotVO snapshot = snapshotDao.findById(snapshotId);
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshotId, role);
if (snapshotStore == null) {
snapshotStore = snapshotStoreDao.findByVolume(snapshot.getVolumeId(), role);
if (snapshotStore == null) {
return null;
}
}
final DataStore store = storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
final SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
return so;
}
use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class StorageSystemDataMotionStrategy method handleCreateTemplateFromSnapshot.
private Void handleCreateTemplateFromSnapshot(final SnapshotInfo snapshotInfo, final TemplateInfo templateInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
try {
snapshotInfo.processEvent(Event.CopyingRequested);
} catch (final Exception ex) {
throw new CloudRuntimeException("This snapshot is not currently in a state where it can be used to create a template.");
}
final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
final DataStore srcDataStore = snapshotInfo.getDataStore();
final String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
final int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
final CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), templateInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
String errMsg = null;
CopyCmdAnswer copyCmdAnswer = null;
try {
_volumeService.grantAccess(snapshotInfo, hostVO, srcDataStore);
final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(srcDataStore.getId()), snapshotInfo);
copyCommand.setOptions(srcDetails);
copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
} catch (final Exception ex) {
throw new CloudRuntimeException(ex.getMessage());
} finally {
try {
_volumeService.revokeAccess(snapshotInfo, hostVO, srcDataStore);
} catch (final Exception ex) {
s_logger.debug(ex.getMessage(), ex);
}
if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) {
errMsg = copyCmdAnswer.getDetails();
} else {
errMsg = "Unable to perform host-side operation";
}
}
try {
if (errMsg == null) {
snapshotInfo.processEvent(Event.OperationSuccessed);
} else {
snapshotInfo.processEvent(Event.OperationFailed);
}
} catch (final Exception ex) {
s_logger.debug(ex.getMessage(), ex);
}
}
final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
result.setResult(errMsg);
callback.complete(result);
return null;
}
use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class TemplateDataStoreDaoImpl method findByTemplateZoneReady.
@Override
public TemplateDataStoreVO findByTemplateZoneReady(final long templateId, final Long zoneId) {
List<DataStore> imgStores = null;
imgStores = _storeMgr.getImageStoresByScope(new ZoneScope(zoneId));
if (imgStores != null) {
Collections.shuffle(imgStores);
for (final DataStore store : imgStores) {
final List<TemplateDataStoreVO> sRes = listByTemplateStoreStatus(templateId, store.getId(), State.Ready);
if (sRes != null && sRes.size() > 0) {
return sRes.get(0);
}
}
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.DataStore in project cosmic by MissionCriticalCloud.
the class VolumeDataStoreDaoImpl method duplicateCacheRecordsOnRegionStore.
@Override
public void duplicateCacheRecordsOnRegionStore(final long storeId) {
// find all records on image cache
final List<DataStore> cacheStores = storeMgr.listImageCacheStores();
if (cacheStores == null || cacheStores.size() == 0) {
return;
}
final List<VolumeDataStoreVO> vols = new ArrayList<>();
for (final DataStore store : cacheStores) {
// check if the volume is stored there
vols.addAll(listByStoreId(store.getId()));
}
// create an entry for each record, but with empty install path since the content is not yet on region-wide store yet
if (vols != null) {
s_logger.info("Duplicate " + vols.size() + " volume cache store records to region store");
for (final VolumeDataStoreVO vol : vols) {
final VolumeDataStoreVO volStore = findByStoreVolume(storeId, vol.getVolumeId());
if (volStore != null) {
s_logger.info("There is already entry for volume " + vol.getVolumeId() + " on region store " + storeId);
continue;
}
s_logger.info("Persisting an entry for volume " + vol.getVolumeId() + " on region store " + storeId);
final VolumeDataStoreVO vs = new VolumeDataStoreVO();
vs.setVolumeId(vol.getVolumeId());
vs.setDataStoreId(storeId);
vs.setState(vol.getState());
vs.setDownloadPercent(vol.getDownloadPercent());
vs.setDownloadState(vol.getDownloadState());
vs.setSize(vol.getSize());
vs.setPhysicalSize(vol.getPhysicalSize());
vs.setErrorString(vol.getErrorString());
vs.setRefCnt(vol.getRefCnt());
persist(vs);
// increase ref_cnt so that this will not be recycled before the content is pushed to region-wide store
vol.incrRefCnt();
this.update(vol.getId(), vol);
}
}
}
Aggregations