Search in sources :

Example 6 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class ObjectInDataStoreManagerImpl method delete.

@Override
public boolean delete(final DataObject dataObj) {
    final long objId = dataObj.getId();
    final DataStore dataStore = dataObj.getDataStore();
    if (dataStore.getRole() == DataStoreRole.Primary) {
        if (dataObj.getType() == DataObjectType.TEMPLATE) {
            final 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:
                final 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:
                final 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:
                final 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(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO)

Example 7 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class ObjectInDataStoreManagerImpl method deleteIfNotReady.

@Override
public boolean deleteIfNotReady(final DataObject dataObj) {
    final long objId = dataObj.getId();
    final DataStore dataStore = dataObj.getDataStore();
    if (dataStore.getRole() == DataStoreRole.Primary) {
        if (dataObj.getType() == DataObjectType.TEMPLATE) {
            final VMTemplateStoragePoolVO destTmpltPool = templatePoolDao.findByPoolTemplate(dataStore.getId(), objId);
            if (destTmpltPool != null && destTmpltPool.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                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 if (dataObj.getType() == DataObjectType.SNAPSHOT) {
            final SnapshotDataStoreVO destSnapshotStore = snapshotDataStoreDao.findByStoreSnapshot(dataStore.getRole(), dataStore.getId(), objId);
            if (destSnapshotStore != null && destSnapshotStore.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                snapshotDataStoreDao.remove(destSnapshotStore.getId());
            }
            return true;
        }
    } else {
        // Image store
        switch(dataObj.getType()) {
            case TEMPLATE:
                return true;
            case SNAPSHOT:
                final SnapshotDataStoreVO destSnapshotStore = snapshotDataStoreDao.findByStoreSnapshot(dataStore.getRole(), dataStore.getId(), objId);
                if (destSnapshotStore != null && destSnapshotStore.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                    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:
                final VolumeDataStoreVO destVolumeStore = volumeDataStoreDao.findByStoreVolume(dataStore.getId(), objId);
                if (destVolumeStore != null && destVolumeStore.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                    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() + "), no need to delete from object in store ref table");
    return false;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Example 8 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class VolumeDataFactoryImpl method getVolume.

@Override
public VolumeInfo getVolume(final long volumeId, final boolean toBeLiveMigrated) {
    final VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId);
    if (volumeVO == null) {
        return null;
    }
    VolumeObject vol;
    if (volumeVO.getPoolId() == null) {
        DataStore store = null;
        final VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
        if (volumeStore != null) {
            store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
        }
        vol = VolumeObject.getVolumeObject(store, volumeVO, toBeLiveMigrated);
    } else {
        final DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
        vol = VolumeObject.getVolumeObject(store, volumeVO, toBeLiveMigrated);
    }
    return vol;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Example 9 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class VolumeDataFactoryImpl method getVolume.

@Override
public VolumeInfo getVolume(final long volumeId, final DataStoreRole storeRole) {
    final VolumeVO volumeVO = volumeDao.findById(volumeId);
    VolumeObject vol = null;
    if (storeRole == DataStoreRole.Image) {
        final VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
        if (volumeStore != null) {
            final DataStore store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
            vol = VolumeObject.getVolumeObject(store, volumeVO);
        }
    } else {
        // Primary data store
        if (volumeVO.getPoolId() != null) {
            final DataStore store = storeMgr.getDataStore(volumeVO.getPoolId(), DataStoreRole.Primary);
            vol = VolumeObject.getVolumeObject(store, volumeVO);
        }
    }
    return vol;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Example 10 with VolumeDataStoreVO

use of com.cloud.storage.datastore.db.VolumeDataStoreVO in project cosmic by MissionCriticalCloud.

the class VolumeObject method processEvent.

@Override
public void processEvent(final ObjectInDataStoreStateMachine.Event event, final Answer answer) {
    try {
        if (dataStore.getRole() == DataStoreRole.Primary) {
            if (answer instanceof CopyCmdAnswer) {
                final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                final VolumeVO vol = volumeDao.findById(getId());
                final VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
                vol.setPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    vol.setSize(newVol.getSize());
                }
                if (newVol.getFormat() != null) {
                    vol.setFormat(newVol.getFormat());
                }
                vol.setPoolId(getDataStore().getId());
                volumeDao.update(vol.getId(), vol);
            } else if (answer instanceof CreateObjectAnswer) {
                final CreateObjectAnswer createAnswer = (CreateObjectAnswer) answer;
                final VolumeObjectTO newVol = (VolumeObjectTO) createAnswer.getData();
                final VolumeVO vol = volumeDao.findById(getId());
                vol.setPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    vol.setSize(newVol.getSize());
                }
                vol.setPoolId(getDataStore().getId());
                if (newVol.getFormat() != null) {
                    vol.setFormat(newVol.getFormat());
                }
                volumeDao.update(vol.getId(), vol);
            }
        } else {
            // image store or imageCache store
            if (answer instanceof DownloadAnswer) {
                final DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
                final VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
                volStore.setInstallPath(dwdAnswer.getInstallPath());
                volStore.setChecksum(dwdAnswer.getCheckSum());
                volumeStoreDao.update(volStore.getId(), volStore);
            } else if (answer instanceof CopyCmdAnswer) {
                final CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                final VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
                final VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
                volStore.setInstallPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    volStore.setSize(newVol.getSize());
                }
                volumeStoreDao.update(volStore.getId(), volStore);
            }
        }
    } catch (final RuntimeException ex) {
        if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
            objectInStoreMgr.deleteIfNotReady(this);
        }
        throw ex;
    }
    this.processEvent(event);
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CreateObjectAnswer(com.cloud.storage.command.CreateObjectAnswer) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Aggregations

VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)32 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 VolumeVO (com.cloud.storage.VolumeVO)9 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)8 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)8 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)7 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)7 Date (java.util.Date)7 ExecutionException (java.util.concurrent.ExecutionException)6 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)5 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)4 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)4 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)3 VolumeApiResult (com.cloud.engine.subsystem.api.storage.VolumeService.VolumeApiResult)3 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)3 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)3 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)3 VolumeObjectTO (com.cloud.storage.to.VolumeObjectTO)3 DB (com.cloud.utils.db.DB)3