Search in sources :

Example 61 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class VolumeObject method processEventOnly.

@Override
public void processEventOnly(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());
                }
                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());
                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.processEventOnly(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 62 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class PrimaryDataStoreImpl method getVolumes.

@Override
public List<VolumeInfo> getVolumes() {
    List<VolumeVO> volumes = volumeDao.findByPoolId(getId());
    List<VolumeInfo> volumeInfos = new ArrayList<VolumeInfo>();
    for (VolumeVO volume : volumes) {
        volumeInfos.add(VolumeObject.getVolumeObject(this, volume));
    }
    return volumeInfos;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 63 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class PrimaryDataStoreImpl method getVolume.

@Override
public VolumeInfo getVolume(long id) {
    VolumeVO volumeVO = volumeDao.findById(id);
    VolumeObject vol = VolumeObject.getVolumeObject(this, volumeVO);
    return vol;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VolumeObject(org.apache.cloudstack.storage.volume.VolumeObject)

Example 64 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class VolumeServiceImpl method canVolumeBeRemoved.

// check if a volume is expunged on both primary and secondary
private boolean canVolumeBeRemoved(long volumeId) {
    VolumeVO vol = volDao.findById(volumeId);
    if (vol == null) {
        // already removed from volumes table
        return false;
    }
    VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volumeId);
    if ((vol.getState() == State.Expunged || (vol.getPodId() == null && vol.getState() == State.Destroy)) && volumeStore == null) {
        // volume is expunged from primary, as well as on secondary
        return true;
    } else {
        return false;
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO)

Example 65 with VolumeVO

use of com.cloud.storage.VolumeVO in project cloudstack by apache.

the class SolidFireHostListener method getTargets.

private List<Map<String, String>> getTargets(long clusterId, long storagePoolId) {
    List<Map<String, String>> targets = new ArrayList<>();
    StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
    // If you do not pass in null for the second parameter, you only get back applicable ROOT disks.
    List<VolumeVO> volumes = _volumeDao.findByPoolId(storagePoolId, null);
    if (volumes != null) {
        for (VolumeVO volume : volumes) {
            Long instanceId = volume.getInstanceId();
            if (instanceId != null) {
                VMInstanceVO vmInstance = _vmDao.findById(instanceId);
                Long hostIdForVm = vmInstance.getHostId() != null ? vmInstance.getHostId() : vmInstance.getLastHostId();
                if (hostIdForVm != null) {
                    HostVO hostForVm = _hostDao.findById(hostIdForVm);
                    if (hostForVm.getClusterId().equals(clusterId)) {
                        Map<String, String> details = new HashMap<>();
                        details.put(ModifyTargetsCommand.IQN, volume.get_iScsiName());
                        details.put(ModifyTargetsCommand.STORAGE_HOST, storagePool.getHostAddress());
                        details.put(ModifyTargetsCommand.STORAGE_PORT, String.valueOf(storagePool.getPort()));
                        targets.add(details);
                    }
                }
            }
        }
    }
    return targets;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) HashMap(java.util.HashMap) Map(java.util.Map) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Aggregations

VolumeVO (com.cloud.storage.VolumeVO)156 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)44 ArrayList (java.util.ArrayList)39 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)36 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 HostVO (com.cloud.host.HostVO)24 VMInstanceVO (com.cloud.vm.VMInstanceVO)24 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)22 Account (com.cloud.user.Account)19 HashMap (java.util.HashMap)17 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)16 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)16 StoragePool (com.cloud.storage.StoragePool)15 HostPodVO (com.cloud.dc.HostPodVO)14 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)13 Pair (com.cloud.utils.Pair)13 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)11 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)11 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)11