Search in sources :

Example 1 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class VMSnapshotHelperImpl method getVolumeTOList.

@Override
public List<VolumeObjectTO> getVolumeTOList(final Long vmId) {
    final List<VolumeObjectTO> volumeTOs = new ArrayList<>();
    final List<VolumeVO> volumeVOs = volumeDao.findByInstance(vmId);
    for (final VolumeVO volume : volumeVOs) {
        final VolumeInfo volumeInfo = volumeDataFactory.getVolume(volume.getId());
        volumeTOs.add((VolumeObjectTO) volumeInfo.getTO());
    }
    return volumeTOs;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) ArrayList(java.util.ArrayList) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo)

Example 2 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class AbstractHyperVisorStorageMotionStrategy method updateVolumePathsAfterMigration.

protected void updateVolumePathsAfterMigration(final Map<VolumeInfo, DataStore> volumeToPool, final List<VolumeObjectTO> volumeTos) {
    for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        boolean updated = false;
        final VolumeInfo volume = entry.getKey();
        final StoragePool pool = (StoragePool) entry.getValue();
        for (final VolumeObjectTO volumeTo : volumeTos) {
            if (volume.getId() == volumeTo.getId()) {
                final VolumeVO volumeVO = volDao.findById(volume.getId());
                final Long oldPoolId = volumeVO.getPoolId();
                volumeVO.setPath(volumeTo.getPath());
                volumeVO.setFolder(pool.getPath());
                volumeVO.setPodId(pool.getPodId());
                volumeVO.setPoolId(pool.getId());
                volumeVO.setLastPoolId(oldPoolId);
                volDao.update(volume.getId(), volumeVO);
                updated = true;
                break;
            }
        }
        if (!updated) {
            s_logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated.");
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map)

Example 3 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO 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)

Example 4 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class DefaultVMSnapshotStrategy method updateVolumePath.

private void updateVolumePath(final List<VolumeObjectTO> volumeTOs) {
    for (final VolumeObjectTO volume : volumeTOs) {
        if (volume.getPath() != null) {
            final VolumeVO volumeVO = volumeDao.findById(volume.getId());
            volumeVO.setPath(volume.getPath());
            volumeVO.setVmSnapshotChainSize(volume.getSize());
            volumeDao.persist(volumeVO);
        }
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO)

Example 5 with VolumeObjectTO

use of com.cloud.storage.to.VolumeObjectTO in project cosmic by MissionCriticalCloud.

the class DefaultVMSnapshotStrategy method deleteVMSnapshot.

@Override
public boolean deleteVMSnapshot(final VMSnapshot vmSnapshot) {
    final UserVmVO userVm = userVmDao.findById(vmSnapshot.getVmId());
    final VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
    try {
        vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested);
    } catch (final NoTransitionException e) {
        s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested");
        throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage());
    }
    try {
        final Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
        final List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(vmSnapshot.getVmId());
        final String vmInstanceName = userVm.getInstanceName();
        final VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(vmSnapshotVO).getParent();
        final VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), vmSnapshot.getCreated().getTime(), vmSnapshot.getDescription(), vmSnapshot.getCurrent(), parent, true);
        final GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
        final DeleteVMSnapshotCommand deleteSnapshotCommand = new DeleteVMSnapshotCommand(vmInstanceName, vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
        final Answer answer = agentMgr.send(hostId, deleteSnapshotCommand);
        if (answer != null && answer.getResult()) {
            processAnswer(vmSnapshotVO, userVm, answer, hostId);
            return true;
        } else {
            final String errMsg = (answer == null) ? null : answer.getDetails();
            s_logger.error("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
            throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
        }
    } catch (final OperationTimedoutException | AgentUnavailableException e) {
        throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + e.getMessage());
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) GuestOSVO(com.cloud.storage.GuestOSVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) Answer(com.cloud.agent.api.Answer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) VMSnapshotTO(com.cloud.agent.api.VMSnapshotTO) DeleteVMSnapshotCommand(com.cloud.agent.api.DeleteVMSnapshotCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO)

Aggregations

VolumeObjectTO (com.cloud.storage.to.VolumeObjectTO)58 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)36 PrimaryDataStoreTO (com.cloud.storage.to.PrimaryDataStoreTO)22 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)21 Connection (com.xensource.xenapi.Connection)19 InternalErrorException (com.cloud.exception.InternalErrorException)18 VDI (com.xensource.xenapi.VDI)17 NfsTO (com.cloud.agent.api.to.NfsTO)16 DataTO (com.cloud.agent.api.to.DataTO)15 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)14 ArrayList (java.util.ArrayList)14 SR (com.xensource.xenapi.SR)13 XenAPIException (com.xensource.xenapi.Types.XenAPIException)13 XmlRpcException (org.apache.xmlrpc.XmlRpcException)13 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)10 IOException (java.io.IOException)10 LibvirtException (org.libvirt.LibvirtException)10 VolumeVO (com.cloud.storage.VolumeVO)9 URI (java.net.URI)9 HashMap (java.util.HashMap)8