use of org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO in project cloudstack by apache.
the class VolumeDataStoreDaoImpl method updateVolumeId.
@Override
public boolean updateVolumeId(long srcVolId, long destVolId) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
VolumeDataStoreVO volumeDataStoreVO = findByVolume(srcVolId);
if (volumeDataStoreVO != null) {
txn.start();
volumeDataStoreVO.setVolumeId(destVolId);
update(volumeDataStoreVO.getId(), volumeDataStoreVO);
txn.commit();
}
} catch (Exception e) {
throw new CloudRuntimeException("Unable to update the volume id for volume store ref", e);
}
return true;
}
use of org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO in project cloudstack by apache.
the class VolumeDataFactoryImpl method getVolume.
@Override
public VolumeInfo getVolume(long volumeId, DataStoreRole storeRole) {
VolumeVO volumeVO = volumeDao.findById(volumeId);
VolumeObject vol = null;
if (storeRole == DataStoreRole.Image) {
VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
if (volumeStore != null) {
DataStore store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
vol = VolumeObject.getVolumeObject(store, volumeVO);
}
} else {
// Primary data store
if (volumeVO.getPoolId() != null) {
DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
vol = VolumeObject.getVolumeObject(store, volumeVO);
}
}
return vol;
}
use of org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO in project cloudstack by apache.
the class StorageCacheReplacementAlgorithmLRU method chooseOneToBeReplaced.
@Override
public DataObject chooseOneToBeReplaced(DataStore store) {
if (unusedTimeInterval == null) {
unusedTimeInterval = NumbersUtil.parseInt(configDao.getValue(Config.StorageCacheReplacementLRUTimeInterval.key()), 30);
}
Calendar cal = Calendar.getInstance();
cal.setTime(DateUtil.now());
cal.add(Calendar.DAY_OF_MONTH, -unusedTimeInterval.intValue());
Date bef = cal.getTime();
QueryBuilder<TemplateDataStoreVO> sc = QueryBuilder.create(TemplateDataStoreVO.class);
sc.and(sc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
sc.and(sc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
sc.and(sc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
sc.and(sc.entity().getDataStoreRole(), SearchCriteria.Op.EQ, store.getRole());
sc.and(sc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
TemplateDataStoreVO template = sc.find();
if (template != null) {
return templateFactory.getTemplate(template.getTemplateId(), store);
}
QueryBuilder<VolumeDataStoreVO> volSc = QueryBuilder.create(VolumeDataStoreVO.class);
volSc.and(volSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
volSc.and(volSc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
volSc.and(volSc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
volSc.and(volSc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
VolumeDataStoreVO volume = volSc.find();
if (volume != null) {
return volumeFactory.getVolume(volume.getVolumeId(), store);
}
QueryBuilder<SnapshotDataStoreVO> snapshotSc = QueryBuilder.create(SnapshotDataStoreVO.class);
snapshotSc.and(snapshotSc.entity().getLastUpdated(), SearchCriteria.Op.LT, bef);
snapshotSc.and(snapshotSc.entity().getState(), SearchCriteria.Op.EQ, ObjectInDataStoreStateMachine.State.Ready);
snapshotSc.and(snapshotSc.entity().getDataStoreId(), SearchCriteria.Op.EQ, store.getId());
snapshotSc.and(snapshotSc.entity().getRole(), SearchCriteria.Op.EQ, store.getRole());
snapshotSc.and(snapshotSc.entity().getRefCnt(), SearchCriteria.Op.EQ, 0);
SnapshotDataStoreVO snapshot = snapshotSc.find();
if (snapshot != null) {
return snapshotFactory.getSnapshot(snapshot.getSnapshotId(), store);
}
return null;
}
use of org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO in project cloudstack by apache.
the class VolumeApiServiceImpl method uploadVolume.
@Override
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPLOAD, eventDescription = "uploading volume for post upload", async = true)
public GetUploadParamsResponse uploadVolume(final GetUploadParamsForVolumeCmd cmd) throws ResourceAllocationException, MalformedURLException {
Account caller = CallContext.current().getCallingAccount();
long ownerId = cmd.getEntityOwnerId();
final Account owner = _entityMgr.findById(Account.class, ownerId);
final Long zoneId = cmd.getZoneId();
final String volumeName = cmd.getName();
String format = cmd.getFormat();
final Long diskOfferingId = cmd.getDiskOfferingId();
String imageStoreUuid = cmd.getImageStoreUuid();
final DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId);
validateVolume(caller, ownerId, zoneId, volumeName, null, format, diskOfferingId);
return Transaction.execute(new TransactionCallbackWithException<GetUploadParamsResponse, MalformedURLException>() {
@Override
public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws MalformedURLException {
VolumeVO volume = persistVolume(owner, zoneId, volumeName, null, cmd.getFormat(), diskOfferingId, Volume.State.NotUploaded);
VolumeInfo vol = volFactory.getVolume(volume.getId());
RegisterVolumePayload payload = new RegisterVolumePayload(null, cmd.getChecksum(), cmd.getFormat());
vol.addPayload(payload);
Pair<EndPoint, DataObject> pair = volService.registerVolumeForPostUpload(vol, store);
EndPoint ep = pair.first();
DataObject dataObject = pair.second();
GetUploadParamsResponse response = new GetUploadParamsResponse();
String ssvmUrlDomain = _configDao.getValue(Config.SecStorageSecureCopyCert.key());
String url = ImageStoreUtil.generatePostUploadUrl(ssvmUrlDomain, ep.getPublicAddr(), vol.getUuid());
response.setPostURL(new URL(url));
// set the post url, this is used in the monitoring thread to determine the SSVM
VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(vol.getId());
assert (volumeStore != null) : "sincle volume is registered, volumestore cannot be null at this stage";
volumeStore.setExtractUrl(url);
_volumeStoreDao.persist(volumeStore);
response.setId(UUID.fromString(vol.getUuid()));
int timeout = ImageStoreUploadMonitorImpl.getUploadOperationTimeout();
DateTime currentDateTime = new DateTime(DateTimeZone.UTC);
String expires = currentDateTime.plusMinutes(timeout).toString();
response.setTimeout(expires);
String key = _configDao.getValue(Config.SSVMPSK.key());
/*
* encoded metadata using the post upload config key
*/
TemplateOrVolumePostUploadCommand command = new TemplateOrVolumePostUploadCommand(vol.getId(), vol.getUuid(), volumeStore.getInstallPath(), cmd.getChecksum(), vol.getType().toString(), vol.getName(), vol.getFormat().toString(), dataObject.getDataStore().getUri(), dataObject.getDataStore().getRole().toString());
command.setLocalPath(volumeStore.getLocalDownloadPath());
//using the existing max upload size configuration
command.setMaxUploadSize(_configDao.getValue(Config.MaxUploadVolumeSize.key()));
command.setDefaultMaxAccountSecondaryStorage(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key()));
command.setAccountId(vol.getAccountId());
Gson gson = new GsonBuilder().create();
String metadata = EncryptionUtil.encodeData(gson.toJson(command), key);
response.setMetadata(metadata);
/*
* signature calculated on the url, expiry, metadata.
*/
response.setSignature(EncryptionUtil.generateSignature(metadata + url + expires, key));
return response;
}
});
}
use of org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO in project cloudstack by apache.
the class StorageManagerImpl method deleteImageStore.
@Override
public boolean deleteImageStore(DeleteImageStoreCmd cmd) {
final long storeId = cmd.getId();
// Verify that image store exists
ImageStoreVO store = _imageStoreDao.findById(storeId);
if (store == null) {
throw new InvalidParameterValueException("Image store with id " + storeId + " doesn't exist");
}
_accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), store.getDataCenterId());
// Verify that there are no live snapshot, template, volume on the image
// store to be deleted
List<SnapshotDataStoreVO> snapshots = _snapshotStoreDao.listByStoreId(storeId, DataStoreRole.Image);
if (snapshots != null && snapshots.size() > 0) {
throw new InvalidParameterValueException("Cannot delete image store with active snapshots backup!");
}
List<VolumeDataStoreVO> volumes = _volumeStoreDao.listByStoreId(storeId);
if (volumes != null && volumes.size() > 0) {
throw new InvalidParameterValueException("Cannot delete image store with active volumes backup!");
}
// search if there are user templates stored on this image store, excluding system, builtin templates
List<TemplateJoinVO> templates = _templateViewDao.listActiveTemplates(storeId);
if (templates != null && templates.size() > 0) {
throw new InvalidParameterValueException("Cannot delete image store with active templates backup!");
}
// ready to delete
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
// first delete from image_store_details table, we need to do that since
// we are not actually deleting record from main
// image_data_store table, so delete cascade will not work
_imageStoreDetailsDao.deleteDetails(storeId);
_snapshotStoreDao.deletePrimaryRecordsForStore(storeId, DataStoreRole.Image);
_volumeStoreDao.deletePrimaryRecordsForStore(storeId);
_templateStoreDao.deletePrimaryRecordsForStore(storeId);
_imageStoreDao.remove(storeId);
}
});
return true;
}
Aggregations