Search in sources :

Example 76 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class ObjectInDataStoreManagerImpl method deleteIfNotReady.

@Override
public boolean deleteIfNotReady(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 && 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) {
            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:
                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:
                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(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)

Example 77 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class BaseImageStoreDriverImpl method createVolumeAsyncCallback.

protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback, CreateContext<CreateCmdResult> context) {
    DownloadAnswer answer = callback.getResult();
    DataObject obj = context.data;
    DataStore store = obj.getDataStore();
    VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
    if (volStoreVO != null) {
        if (volStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Volume is already in DOWNLOADED state, ignore further incoming DownloadAnswer");
            }
            return null;
        }
        VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
        updateBuilder.setDownloadPercent(answer.getDownloadPct());
        updateBuilder.setDownloadState(answer.getDownloadStatus());
        updateBuilder.setLastUpdated(new Date());
        updateBuilder.setErrorString(answer.getErrorString());
        updateBuilder.setJobId(answer.getJobId());
        updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
        updateBuilder.setInstallPath(answer.getInstallPath());
        updateBuilder.setSize(answer.getTemplateSize());
        updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
        _volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
        // update size in volume table
        VolumeVO volUpdater = volumeDao.createForUpdate();
        volUpdater.setSize(answer.getTemplateSize());
        volumeDao.update(obj.getId(), volUpdater);
    }
    AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
    if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN) {
        CreateCmdResult result = new CreateCmdResult(null, null);
        result.setSuccess(false);
        result.setResult(answer.getErrorString());
        caller.complete(result);
        String msg = "Failed to upload volume: " + obj.getUuid() + " with error: " + answer.getErrorString();
        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, (volStoreVO == null ? -1L : volStoreVO.getZoneId()), null, msg, msg);
        s_logger.error(msg);
    } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
        CreateCmdResult result = new CreateCmdResult(null, null);
        caller.complete(result);
    }
    return null;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) Date(java.util.Date)

Example 78 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class StorageManagerImpl method cancelPrimaryStorageForMaintenance.

@Override
@DB
public PrimaryDataStoreInfo cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) throws ResourceUnavailableException {
    Long primaryStorageId = cmd.getId();
    StoragePoolVO primaryStorage = null;
    primaryStorage = _storagePoolDao.findById(primaryStorageId);
    if (primaryStorage == null) {
        String msg = "Unable to obtain lock on the storage pool in cancelPrimaryStorageForMaintenance()";
        s_logger.error(msg);
        throw new InvalidParameterValueException(msg);
    }
    if (primaryStorage.getStatus().equals(StoragePoolStatus.Up) || primaryStorage.getStatus().equals(StoragePoolStatus.PrepareForMaintenance)) {
        throw new StorageUnavailableException("Primary storage with id " + primaryStorageId + " is not ready to complete migration, as the status is:" + primaryStorage.getStatus().toString(), primaryStorageId);
    }
    DataStoreProvider provider = _dataStoreProviderMgr.getDataStoreProvider(primaryStorage.getStorageProviderName());
    DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
    DataStore store = _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
    lifeCycle.cancelMaintain(store);
    return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(primaryStorage.getId(), DataStoreRole.Primary);
}
Also used : PrimaryDataStoreInfo(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo) DataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle) PrimaryDataStoreLifeCycle(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DB(com.cloud.utils.db.DB)

Example 79 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class StorageManagerImpl method getSecondaryStorageUsedStats.

@Override
public CapacityVO getSecondaryStorageUsedStats(Long hostId, Long zoneId) {
    SearchCriteria<HostVO> sc = _hostDao.createSearchCriteria();
    if (zoneId != null) {
        sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
    }
    List<Long> hosts = new ArrayList<Long>();
    if (hostId != null) {
        hosts.add(hostId);
    } else {
        List<DataStore> stores = _dataStoreMgr.getImageStoresByScope(new ZoneScope(zoneId));
        if (stores != null) {
            for (DataStore store : stores) {
                hosts.add(store.getId());
            }
        }
    }
    CapacityVO capacity = new CapacityVO(hostId, zoneId, null, null, 0, 0, Capacity.CAPACITY_TYPE_SECONDARY_STORAGE);
    for (Long id : hosts) {
        StorageStats stats = ApiDBUtils.getSecondaryStorageStatistics(id);
        if (stats == null) {
            continue;
        }
        capacity.setUsedCapacity(stats.getByteUsed() + capacity.getUsedCapacity());
        capacity.setTotalCapacity(stats.getCapacityBytes() + capacity.getTotalCapacity());
    }
    return capacity;
}
Also used : ZoneScope(org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) CapacityVO(com.cloud.capacity.CapacityVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO)

Example 80 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore in project cloudstack by apache.

the class QueryManagerImpl method searchForVolumes.

@Override
public ListResponse<VolumeResponse> searchForVolumes(ListVolumesCmd cmd) {
    Pair<List<VolumeJoinVO>, Integer> result = searchForVolumesInternal(cmd);
    ListResponse<VolumeResponse> response = new ListResponse<VolumeResponse>();
    ResponseView respView = ResponseView.Restricted;
    if (cmd instanceof ListVolumesCmdByAdmin) {
        respView = ResponseView.Full;
    }
    List<VolumeResponse> volumeResponses = ViewResponseHelper.createVolumeResponse(respView, result.first().toArray(new VolumeJoinVO[result.first().size()]));
    for (VolumeResponse vr : volumeResponses) {
        String poolId = vr.getStoragePoolId();
        if (poolId == null) {
            continue;
        }
        DataStore store = dataStoreManager.getPrimaryDataStore(poolId);
        if (store == null) {
            continue;
        }
        DataStoreDriver driver = store.getDriver();
        if (driver == null) {
            continue;
        }
        Map<String, String> caps = driver.getCapabilities();
        if (caps != null) {
            boolean quiescevm = Boolean.parseBoolean(caps.get(DataStoreCapabilities.VOLUME_SNAPSHOT_QUIESCEVM.toString()));
            vr.setNeedQuiescevm(quiescevm);
        }
    }
    response.setResponses(volumeResponses, result.second());
    return response;
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) DataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver) ListVolumesCmdByAdmin(org.apache.cloudstack.api.command.admin.volume.ListVolumesCmdByAdmin) ResponseView(org.apache.cloudstack.api.ResponseObject.ResponseView) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ArrayList(java.util.ArrayList) List(java.util.List) VolumeJoinVO(com.cloud.api.query.vo.VolumeJoinVO)

Aggregations

DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)158 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)52 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)49 ExecutionException (java.util.concurrent.ExecutionException)37 VolumeVO (com.cloud.storage.VolumeVO)30 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)25 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)24 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)24 VMTemplateVO (com.cloud.storage.VMTemplateVO)22 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)22 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)22 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)18 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)17 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)17 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)16 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)13 Pair (com.cloud.utils.Pair)13