Search in sources :

Example 26 with VolumeDataStoreVO

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;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 27 with VolumeDataStoreVO

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;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)

Example 28 with VolumeDataStoreVO

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;
}
Also used : Calendar(java.util.Calendar) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) Date(java.util.Date)

Example 29 with VolumeDataStoreVO

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;
        }
    });
}
Also used : Account(com.cloud.user.Account) MalformedURLException(java.net.MalformedURLException) GsonBuilder(com.google.gson.GsonBuilder) TransactionStatus(com.cloud.utils.db.TransactionStatus) Gson(com.google.gson.Gson) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) GetUploadParamsResponse(org.apache.cloudstack.api.response.GetUploadParamsResponse) URL(java.net.URL) DateTime(org.joda.time.DateTime) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) TemplateOrVolumePostUploadCommand(org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) Pair(com.cloud.utils.Pair) ActionEvent(com.cloud.event.ActionEvent)

Example 30 with VolumeDataStoreVO

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;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) TemplateJoinVO(com.cloud.api.query.vo.TemplateJoinVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ImageStoreVO(org.apache.cloudstack.storage.datastore.db.ImageStoreVO)

Aggregations

VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)33 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 VolumeVO (com.cloud.storage.VolumeVO)9 Date (java.util.Date)8 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)8 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)7 ExecutionException (java.util.concurrent.ExecutionException)5 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)5 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)4 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)3 ActionEvent (com.cloud.event.ActionEvent)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)3 DB (com.cloud.utils.db.DB)3 ArrayList (java.util.ArrayList)3 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)3 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)3