Search in sources :

Example 21 with SnapshotDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.

the class SnapshotDataStoreDaoImpl method updateState.

@Override
public boolean updateState(State currentState, Event event, State nextState, DataObjectInStore vo, Object data) {
    SnapshotDataStoreVO dataObj = (SnapshotDataStoreVO) vo;
    Long oldUpdated = dataObj.getUpdatedCount();
    Date oldUpdatedTime = dataObj.getUpdated();
    SearchCriteria<SnapshotDataStoreVO> sc = updateStateSearch.create();
    sc.setParameters("id", dataObj.getId());
    sc.setParameters("state", currentState);
    sc.setParameters("updatedCount", dataObj.getUpdatedCount());
    dataObj.incrUpdatedCount();
    UpdateBuilder builder = getUpdateBuilder(dataObj);
    builder.set(dataObj, "state", nextState);
    builder.set(dataObj, "updated", new Date());
    int rows = update(dataObj, sc);
    if (rows == 0 && s_logger.isDebugEnabled()) {
        SnapshotDataStoreVO dbVol = findByIdIncludingRemoved(dataObj.getId());
        if (dbVol != null) {
            StringBuilder str = new StringBuilder("Unable to update ").append(dataObj.toString());
            str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=").append(dbVol.getUpdated());
            str.append(": New Data={id=").append(dataObj.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(dataObj.getUpdatedCount()).append("; updatedTime=").append(dataObj.getUpdated());
            str.append(": stale Data={id=").append(dataObj.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime);
        } else {
            s_logger.debug("Unable to update objectIndatastore: id=" + dataObj.getId() + ", as there is no such object exists in the database anymore");
        }
    }
    return rows > 0;
}
Also used : SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) UpdateBuilder(com.cloud.utils.db.UpdateBuilder) Date(java.util.Date)

Example 22 with SnapshotDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.

the class SnapshotDataStoreDaoImpl method deleteSnapshotRecordsOnPrimary.

@Override
public void deleteSnapshotRecordsOnPrimary() {
    SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
    sc.setParameters("store_role", DataStoreRole.Primary);
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    remove(sc);
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 23 with SnapshotDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.

the class VolumeServiceImpl method deleteVolumeCallback.

public Void deleteVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> callback, DeleteVolumeContext<VolumeApiResult> context) {
    CommandResult result = callback.getResult();
    VolumeObject vo = context.getVolume();
    VolumeApiResult apiResult = new VolumeApiResult(vo);
    try {
        if (result.isSuccess()) {
            vo.processEvent(Event.OperationSuccessed);
            if (canVolumeBeRemoved(vo.getId())) {
                s_logger.info("Volume " + vo.getId() + " is not referred anywhere, remove it from volumes table");
                volDao.remove(vo.getId());
            }
            SnapshotDataStoreVO snapStoreVo = _snapshotStoreDao.findByVolume(vo.getId(), DataStoreRole.Primary);
            if (snapStoreVo != null) {
                _snapshotStoreDao.remove(snapStoreVo.getId());
            }
        } else {
            vo.processEvent(Event.OperationFailed);
            apiResult.setResult(result.getResult());
        }
    } catch (Exception e) {
        s_logger.debug("ignore delete volume status update failure, it will be picked up by storage clean up thread later", e);
    }
    context.getFuture().complete(apiResult);
    return null;
}
Also used : SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 24 with SnapshotDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.

the class ObjectInDataStoreManagerImpl method create.

@Override
public DataObject create(DataObject obj, DataStore dataStore) {
    if (dataStore.getRole() == DataStoreRole.Primary) {
        if (obj.getType() == DataObjectType.TEMPLATE) {
            VMTemplateStoragePoolVO vo = new VMTemplateStoragePoolVO(dataStore.getId(), obj.getId());
            vo = templatePoolDao.persist(vo);
        } else if (obj.getType() == DataObjectType.SNAPSHOT) {
            SnapshotInfo snapshotInfo = (SnapshotInfo) obj;
            SnapshotDataStoreVO ss = new SnapshotDataStoreVO();
            ss.setSnapshotId(obj.getId());
            ss.setDataStoreId(dataStore.getId());
            ss.setRole(dataStore.getRole());
            ss.setVolumeId(snapshotInfo.getVolumeId());
            // this is the virtual size of snapshot in primary storage.
            ss.setSize(snapshotInfo.getSize());
            // this physical size will get updated with actual size once the snapshot backup is done.
            ss.setPhysicalSize(snapshotInfo.getSize());
            SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshotInfo.getVolumeId());
            if (snapshotDataStoreVO != null) {
                //Double check the snapshot is removed or not
                SnapshotVO parentSnap = snapshotDao.findById(snapshotDataStoreVO.getSnapshotId());
                if (parentSnap != null) {
                    ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
                } else {
                    s_logger.debug("find inconsistent db for snapshot " + snapshotDataStoreVO.getSnapshotId());
                }
            }
            ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
            ss = snapshotDataStoreDao.persist(ss);
        }
    } else {
        // Image store
        switch(obj.getType()) {
            case TEMPLATE:
                TemplateDataStoreVO ts = new TemplateDataStoreVO();
                ts.setTemplateId(obj.getId());
                ts.setDataStoreId(dataStore.getId());
                ts.setDataStoreRole(dataStore.getRole());
                String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + templateDao.findById(obj.getId()).getAccountId() + "/" + obj.getId();
                if (dataStore.getTO() instanceof S3TO) {
                    TemplateInfo tmpl = (TemplateInfo) obj;
                    // for S3, we
                    installPath += "/" + tmpl.getUniqueName();
                // append
                // template name
                // in the path
                // for template
                // sync since we
                // don't have
                // template.properties
                // there
                }
                ts.setInstallPath(installPath);
                ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
                ts = templateDataStoreDao.persist(ts);
                break;
            case SNAPSHOT:
                SnapshotInfo snapshot = (SnapshotInfo) obj;
                SnapshotDataStoreVO ss = new SnapshotDataStoreVO();
                ss.setSnapshotId(obj.getId());
                ss.setDataStoreId(dataStore.getId());
                ss.setRole(dataStore.getRole());
                ss.setSize(snapshot.getSize());
                ss.setVolumeId(snapshot.getVolumeId());
                SnapshotDataStoreVO snapshotDataStoreVO = snapshotDataStoreDao.findParent(dataStore.getRole(), dataStore.getId(), snapshot.getVolumeId());
                if (snapshotDataStoreVO != null) {
                    ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId());
                }
                ss.setInstallPath(TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + snapshotDao.findById(obj.getId()).getAccountId() + "/" + snapshot.getVolumeId());
                ss.setState(ObjectInDataStoreStateMachine.State.Allocated);
                ss = snapshotDataStoreDao.persist(ss);
                break;
            case VOLUME:
                VolumeDataStoreVO vs = new VolumeDataStoreVO();
                vs.setVolumeId(obj.getId());
                vs.setDataStoreId(dataStore.getId());
                vs.setInstallPath(TemplateConstants.DEFAULT_VOLUME_ROOT_DIR + "/" + volumeDao.findById(obj.getId()).getAccountId() + "/" + obj.getId());
                vs.setState(ObjectInDataStoreStateMachine.State.Allocated);
                vs = volumeDataStoreDao.persist(vs);
                break;
        }
    }
    return this.get(obj, dataStore);
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) S3TO(com.cloud.agent.api.to.S3TO)

Example 25 with SnapshotDataStoreVO

use of org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO in project cloudstack by apache.

the class ObjectInDataStoreManagerImpl method delete.

@Override
public boolean delete(DataObject dataObj) {
    long objId = dataObj.getId();
    DataStore dataStore = dataObj.getDataStore();
    if (dataStore.getRole() == DataStoreRole.Primary) {
        if (dataObj.getType() == DataObjectType.TEMPLATE) {
            VMTemplateStoragePoolVO destTmpltPool = templatePoolDao.findByPoolTemplate(dataStore.getId(), objId);
            if (destTmpltPool != null) {
                return templatePoolDao.remove(destTmpltPool.getId());
            } else {
                s_logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete");
                return true;
            }
        }
    } else {
        // Image store
        switch(dataObj.getType()) {
            case TEMPLATE:
                TemplateDataStoreVO destTmpltStore = templateDataStoreDao.findByStoreTemplate(dataStore.getId(), objId);
                if (destTmpltStore != null) {
                    return templateDataStoreDao.remove(destTmpltStore.getId());
                } else {
                    s_logger.warn("Template " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
            case SNAPSHOT:
                SnapshotDataStoreVO destSnapshotStore = snapshotDataStoreDao.findByStoreSnapshot(dataStore.getRole(), dataStore.getId(), objId);
                if (destSnapshotStore != null) {
                    return snapshotDataStoreDao.remove(destSnapshotStore.getId());
                } else {
                    s_logger.warn("Snapshot " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
            case VOLUME:
                VolumeDataStoreVO destVolumeStore = volumeDataStoreDao.findByStoreVolume(dataStore.getId(), objId);
                if (destVolumeStore != null) {
                    return volumeDataStoreDao.remove(destVolumeStore.getId());
                } else {
                    s_logger.warn("Volume " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete");
                    return true;
                }
        }
    }
    s_logger.warn("Unsupported data object (" + dataObj.getType() + ", " + dataObj.getDataStore() + ")");
    return false;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)

Aggregations

SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)38 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 SnapshotVO (com.cloud.storage.SnapshotVO)10 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)10 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)9 VolumeDataStoreVO (org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)8 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)6 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 VolumeVO (com.cloud.storage.VolumeVO)5 Date (java.util.Date)5 ConfigurationException (javax.naming.ConfigurationException)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 DB (com.cloud.utils.db.DB)4 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)3 Account (com.cloud.user.Account)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)3 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)3 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)3