Search in sources :

Example 21 with VolumeDataStoreVO

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

the class VolumeObject method processEvent.

@Override
public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
    try {
        if (dataStore.getRole() == DataStoreRole.Primary) {
            if (answer instanceof CopyCmdAnswer) {
                CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                VolumeVO vol = volumeDao.findById(getId());
                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) {
                CreateObjectAnswer createAnswer = (CreateObjectAnswer) answer;
                VolumeObjectTO newVol = (VolumeObjectTO) createAnswer.getData();
                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) {
                DownloadAnswer dwdAnswer = (DownloadAnswer) answer;
                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) {
                CopyCmdAnswer cpyAnswer = (CopyCmdAnswer) answer;
                VolumeDataStoreVO volStore = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
                VolumeObjectTO newVol = (VolumeObjectTO) cpyAnswer.getNewData();
                volStore.setInstallPath(newVol.getPath());
                if (newVol.getSize() != null) {
                    volStore.setSize(newVol.getSize());
                }
                volumeStoreDao.update(volStore.getId(), volStore);
            }
        }
    } catch (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(org.apache.cloudstack.storage.command.CreateObjectAnswer) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Example 22 with VolumeDataStoreVO

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

the class VolumeServiceImpl method expungeVolumeAsync.

@DB
@Override
public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(VolumeInfo volume) {
    AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();
    VolumeApiResult result = new VolumeApiResult(volume);
    if (volume.getDataStore() == null) {
        s_logger.info("Expunge volume with no data store specified");
        if (canVolumeBeRemoved(volume.getId())) {
            s_logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table");
            volDao.remove(volume.getId());
        }
        future.complete(result);
        return future;
    }
    // Find out if the volume is at state of download_in_progress on secondary storage
    VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
    if (volumeStore != null) {
        if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
            s_logger.debug("Volume: " + volume.getName() + " is currently being uploaded; cant' delete it.");
            future.complete(result);
            return future;
        }
    }
    VolumeVO vol = volDao.findById(volume.getId());
    if (vol == null) {
        s_logger.debug("Volume " + volume.getId() + " is not found");
        future.complete(result);
        return future;
    }
    if (!volumeExistsOnPrimary(vol)) {
        // not created on primary store
        if (volumeStore == null) {
            // also not created on secondary store
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Marking volume that was never created as destroyed: " + vol);
            }
            volDao.remove(vol.getId());
            future.complete(result);
            return future;
        }
    }
    VolumeObject vo = (VolumeObject) volume;
    if (volume.getDataStore().getRole() == DataStoreRole.Image) {
        // no need to change state in volumes table
        volume.processEventOnly(Event.DestroyRequested);
    } else if (volume.getDataStore().getRole() == DataStoreRole.Primary) {
        volume.processEvent(Event.ExpungeRequested);
    }
    DeleteVolumeContext<VolumeApiResult> context = new DeleteVolumeContext<VolumeApiResult>(null, vo, future);
    AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteVolumeCallback(null, null)).setContext(context);
    volume.getDataStore().getDriver().deleteAsync(volume.getDataStore(), volume, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) VolumeVO(com.cloud.storage.VolumeVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DB(com.cloud.utils.db.DB)

Example 23 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) {
    VolumeVO volumeVO = volumeDao.findByIdIncludingRemoved(volumeId);
    if (volumeVO == null) {
        return null;
    }
    VolumeObject vol = null;
    if (volumeVO.getPoolId() == null) {
        DataStore store = null;
        VolumeDataStoreVO volumeStore = volumeStoreDao.findByVolume(volumeId);
        if (volumeStore != null) {
            store = storeMgr.getDataStore(volumeStore.getDataStoreId(), DataStoreRole.Image);
        }
        vol = VolumeObject.getVolumeObject(store, volumeVO);
    } else {
        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 24 with VolumeDataStoreVO

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

the class VolumeObject method incRefCount.

@Override
public void incRefCount() {
    if (dataStore == null) {
        return;
    }
    if (dataStore.getRole() == DataStoreRole.Image || dataStore.getRole() == DataStoreRole.ImageCache) {
        VolumeDataStoreVO store = volumeStoreDao.findByStoreVolume(dataStore.getId(), getId());
        store.incrRefCnt();
        store.setLastUpdated(new Date());
        volumeStoreDao.update(store.getId(), store);
    }
}
Also used : VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) Date(java.util.Date)

Example 25 with VolumeDataStoreVO

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

the class VolumeDataStoreDaoImpl method findByStoreVolume.

@Override
public VolumeDataStoreVO findByStoreVolume(long storeId, long volumeId) {
    SearchCriteria<VolumeDataStoreVO> sc = storeVolumeSearch.create();
    sc.setParameters("store_id", storeId);
    sc.setParameters("volume_id", volumeId);
    sc.setParameters("destroyed", false);
    /*
        When we download volume then we create entry in volume_store_ref table.
        We mark the volume entry to ready state once download_url gets generated.
        When we migrate that volume, then again one more entry is created with same volume id.
        Its state is marked as allocated. Later we try to list only one dataobject in datastore
        for state transition during volume migration. If the listed volume's state is allocated
        then migration passes otherwise it fails.

         Below fix will remove the randomness and give priority to volume entry which is made for
         migration (download_url/extracturl will be null in case of migration). Giving priority to
         download volume case is not needed as there will be only one entry in that case so no randomness.
        */
    List<VolumeDataStoreVO> vos = listBy(sc);
    if (vos.size() > 1) {
        for (VolumeDataStoreVO vo : vos) {
            if (vo.getExtractUrl() == null) {
                return vo;
            }
        }
    }
    return vos.size() == 1 ? vos.get(0) : null;
}
Also used : VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)

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