Search in sources :

Example 31 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.

the class HypervisorHelperImpl method quiesceVm.

@Override
public VMSnapshotTO quiesceVm(VirtualMachine virtualMachine) {
    String value = configurationDao.getValue("vmsnapshot.create.wait");
    int wait = NumbersUtil.parseInt(value, 1800);
    Long hostId = vmSnapshotHelper.pickRunningHost(virtualMachine.getId());
    VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(1L, UUID.randomUUID().toString(), VMSnapshot.Type.Disk, null, null, false, null, true);
    GuestOSVO guestOS = guestOSDao.findById(virtualMachine.getGuestOSId());
    List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(virtualMachine.getId());
    CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(virtualMachine.getInstanceName(), virtualMachine.getUuid(), vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
    HostVO host = hostDao.findById(hostId);
    GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
    ccmd.setPlatformEmulator(guestOsMapping.getGuestOsName());
    ccmd.setWait(wait);
    try {
        Answer answer = agentMgr.send(hostId, ccmd);
        if (answer != null && answer.getResult()) {
            CreateVMSnapshotAnswer snapshotAnswer = (CreateVMSnapshotAnswer) answer;
            vmSnapshotTO.setVolumes(snapshotAnswer.getVolumeTOs());
        } else {
            String errMsg = (answer != null) ? answer.getDetails() : null;
            throw new CloudRuntimeException("Failed to quiesce vm, due to " + errMsg);
        }
    } catch (AgentUnavailableException e) {
        throw new CloudRuntimeException("Failed to quiesce vm", e);
    } catch (OperationTimedoutException e) {
        throw new CloudRuntimeException("Failed to quiesce vm", e);
    }
    return vmSnapshotTO;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) GuestOSVO(com.cloud.storage.GuestOSVO) CreateVMSnapshotCommand(com.cloud.agent.api.CreateVMSnapshotCommand) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) Answer(com.cloud.agent.api.Answer) IntroduceObjectAnswer(org.apache.cloudstack.storage.command.IntroduceObjectAnswer) VMSnapshotTO(com.cloud.agent.api.VMSnapshotTO) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 32 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.

the class HypervisorHelperImpl method unquiesceVM.

@Override
public boolean unquiesceVM(VirtualMachine virtualMachine, VMSnapshotTO vmSnapshotTO) {
    Long hostId = vmSnapshotHelper.pickRunningHost(virtualMachine.getId());
    List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(virtualMachine.getId());
    GuestOSVO guestOS = guestOSDao.findById(virtualMachine.getGuestOSId());
    DeleteVMSnapshotCommand deleteSnapshotCommand = new DeleteVMSnapshotCommand(virtualMachine.getInstanceName(), vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
    try {
        Answer answer = agentMgr.send(hostId, deleteSnapshotCommand);
        if (answer != null && answer.getResult()) {
            return true;
        } else {
            String errMsg = (answer != null) ? answer.getDetails() : null;
            throw new CloudRuntimeException("Failed to unquiesce vm, due to " + errMsg);
        }
    } catch (AgentUnavailableException e) {
        throw new CloudRuntimeException("Failed to unquiesce vm", e);
    } catch (OperationTimedoutException e) {
        throw new CloudRuntimeException("Failed to unquiesce vm", e);
    }
}
Also used : CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) Answer(com.cloud.agent.api.Answer) IntroduceObjectAnswer(org.apache.cloudstack.storage.command.IntroduceObjectAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DeleteVMSnapshotCommand(com.cloud.agent.api.DeleteVMSnapshotCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) GuestOSVO(com.cloud.storage.GuestOSVO)

Example 33 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.

the class VMSnapshotHelperImpl method getVolumeTOList.

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

Example 34 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.

the class DefaultVMSnapshotStrategy method updateVolumePath.

private void updateVolumePath(List<VolumeObjectTO> volumeTOs) {
    for (VolumeObjectTO volume : volumeTOs) {
        if (volume.getPath() != null) {
            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(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 35 with VolumeObjectTO

use of org.apache.cloudstack.storage.to.VolumeObjectTO in project cloudstack by apache.

the class KVMStorageProcessor method cloneVolumeFromBaseTemplate.

@Override
public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
    final DataTO srcData = cmd.getSrcTO();
    final DataTO destData = cmd.getDestTO();
    final TemplateObjectTO template = (TemplateObjectTO) srcData;
    final DataStoreTO imageStore = template.getDataStore();
    final VolumeObjectTO volume = (VolumeObjectTO) destData;
    final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
    KVMPhysicalDisk BaseVol = null;
    KVMStoragePool primaryPool = null;
    KVMPhysicalDisk vol = null;
    try {
        primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
        String templatePath = template.getPath();
        if (primaryPool.getType() == StoragePoolType.CLVM) {
            templatePath = ((NfsTO) imageStore).getUrl() + File.separator + templatePath;
            vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds());
        } else {
            if (templatePath.contains("/mnt")) {
                //upgrade issue, if the path contains path, need to extract the volume uuid from path
                templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1);
            }
            BaseVol = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath);
            vol = storagePoolMgr.createDiskFromTemplate(BaseVol, volume.getUuid(), volume.getProvisioningType(), BaseVol.getPool(), volume.getSize(), cmd.getWaitInMillSeconds());
        }
        if (vol == null) {
            return new CopyCmdAnswer(" Can't create storage volume on storage pool");
        }
        final VolumeObjectTO newVol = new VolumeObjectTO();
        newVol.setPath(vol.getName());
        newVol.setSize(volume.getSize());
        if (vol.getFormat() == PhysicalDiskFormat.RAW) {
            newVol.setFormat(ImageFormat.RAW);
        } else if (vol.getFormat() == PhysicalDiskFormat.QCOW2) {
            newVol.setFormat(ImageFormat.QCOW2);
        } else if (vol.getFormat() == PhysicalDiskFormat.DIR) {
            newVol.setFormat(ImageFormat.DIR);
        }
        return new CopyCmdAnswer(newVol);
    } catch (final CloudRuntimeException e) {
        s_logger.debug("Failed to create volume: ", e);
        return new CopyCmdAnswer(e.toString());
    }
}
Also used : PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) DataTO(com.cloud.agent.api.to.DataTO) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

Aggregations

VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)108 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)59 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)45 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)36 PrimaryDataStoreTO (org.apache.cloudstack.storage.to.PrimaryDataStoreTO)36 DataTO (com.cloud.agent.api.to.DataTO)31 NfsTO (com.cloud.agent.api.to.NfsTO)31 InternalErrorException (com.cloud.exception.InternalErrorException)27 TemplateObjectTO (org.apache.cloudstack.storage.to.TemplateObjectTO)20 Connection (com.xensource.xenapi.Connection)19 VDI (com.xensource.xenapi.VDI)17 IOException (java.io.IOException)17 Answer (com.cloud.agent.api.Answer)16 DiskTO (com.cloud.agent.api.to.DiskTO)16 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)16 RemoteException (java.rmi.RemoteException)16 ArrayList (java.util.ArrayList)16 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)16 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14