Search in sources :

Example 6 with GuestOSHypervisorVO

use of com.cloud.storage.GuestOSHypervisorVO 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 7 with GuestOSHypervisorVO

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

the class ManagementServerImpl method listGuestOSMappingByCriteria.

@Override
public Pair<List<? extends GuestOSHypervisor>, Integer> listGuestOSMappingByCriteria(final ListGuestOsMappingCmd cmd) {
    final Filter searchFilter = new Filter(GuestOSHypervisorVO.class, "hypervisorType", true, cmd.getStartIndex(), cmd.getPageSizeVal());
    final Long id = cmd.getId();
    final Long osTypeId = cmd.getOsTypeId();
    final String hypervisor = cmd.getHypervisor();
    final String hypervisorVersion = cmd.getHypervisorVersion();
    //throw exception if hypervisor name is not passed, but version is
    if (hypervisorVersion != null && (hypervisor == null || hypervisor.isEmpty())) {
        throw new InvalidParameterValueException("Hypervisor version parameter cannot be used without specifying a hypervisor : XenServer, KVM or VMware");
    }
    final SearchCriteria<GuestOSHypervisorVO> sc = _guestOSHypervisorDao.createSearchCriteria();
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (osTypeId != null) {
        sc.addAnd("guestOsId", SearchCriteria.Op.EQ, osTypeId);
    }
    if (hypervisor != null) {
        sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisor);
    }
    if (hypervisorVersion != null) {
        sc.addAnd("hypervisorVersion", SearchCriteria.Op.EQ, hypervisorVersion);
    }
    final Pair<List<GuestOSHypervisorVO>, Integer> result = _guestOSHypervisorDao.searchAndCount(sc, searchFilter);
    return new Pair<List<? extends GuestOSHypervisor>, Integer>(result.first(), result.second());
}
Also used : GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) Filter(com.cloud.utils.db.Filter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) Pair(com.cloud.utils.Pair) SSHKeyPair(com.cloud.user.SSHKeyPair)

Example 8 with GuestOSHypervisorVO

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

the class GuestOSHypervisorDaoImpl method removeGuestOsMapping.

@Override
public boolean removeGuestOsMapping(Long id) {
    GuestOSHypervisorVO guestOsHypervisor = findById(id);
    createForUpdate(id);
    guestOsHypervisor.setRemoved(new Date());
    update(id, guestOsHypervisor);
    return super.remove(id);
}
Also used : GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) Date(java.util.Date)

Example 9 with GuestOSHypervisorVO

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

the class DefaultVMSnapshotStrategy method takeVMSnapshot.

@Override
public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) {
    Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
    UserVm userVm = userVmDao.findById(vmSnapshot.getVmId());
    VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
    try {
        vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.CreateRequested);
    } catch (NoTransitionException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    CreateVMSnapshotAnswer answer = null;
    boolean result = false;
    try {
        GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
        List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
        VMSnapshotTO current = null;
        VMSnapshotVO currentSnapshot = vmSnapshotDao.findCurrentSnapshotByVmId(userVm.getId());
        if (currentSnapshot != null)
            current = vmSnapshotHelper.getSnapshotWithParents(currentSnapshot);
        VMSnapshotOptions options = ((VMSnapshotVO) vmSnapshot).getOptions();
        boolean quiescevm = true;
        if (options != null)
            quiescevm = options.needQuiesceVM();
        VMSnapshotTO target = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), null, vmSnapshot.getDescription(), false, current, quiescevm);
        if (current == null)
            vmSnapshotVO.setParent(null);
        else
            vmSnapshotVO.setParent(current.getId());
        HostVO host = hostDao.findById(hostId);
        GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
        CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(userVm.getInstanceName(), userVm.getUuid(), target, volumeTOs, guestOS.getDisplayName());
        if (guestOsMapping == null) {
            ccmd.setPlatformEmulator(null);
        } else {
            ccmd.setPlatformEmulator(guestOsMapping.getGuestOsName());
        }
        ccmd.setWait(_wait);
        answer = (CreateVMSnapshotAnswer) agentMgr.send(hostId, ccmd);
        if (answer != null && answer.getResult()) {
            processAnswer(vmSnapshotVO, userVm, answer, hostId);
            s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName());
            result = true;
            for (VolumeObjectTO volumeTo : answer.getVolumeTOs()) {
                publishUsageEvent(EventTypes.EVENT_VM_SNAPSHOT_CREATE, vmSnapshot, userVm, volumeTo);
            }
            return vmSnapshot;
        } else {
            String errMsg = "Creating VM snapshot: " + vmSnapshot.getName() + " failed";
            if (answer != null && answer.getDetails() != null)
                errMsg = errMsg + " due to " + answer.getDetails();
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
    } catch (OperationTimedoutException e) {
        s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
        throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
    } catch (AgentUnavailableException e) {
        s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e);
        throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
    } finally {
        if (!result) {
            try {
                vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
            } catch (NoTransitionException e1) {
                s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage());
            }
        }
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) VMSnapshotOptions(org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotOptions) GuestOSVO(com.cloud.storage.GuestOSVO) CreateVMSnapshotCommand(com.cloud.agent.api.CreateVMSnapshotCommand) HostVO(com.cloud.host.HostVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) UserVm(com.cloud.uservm.UserVm) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) VMSnapshotTO(com.cloud.agent.api.VMSnapshotTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 10 with GuestOSHypervisorVO

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

the class DefaultVMSnapshotStrategy method revertVMSnapshot.

@Override
public boolean revertVMSnapshot(VMSnapshot vmSnapshot) {
    VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
    UserVmVO userVm = userVmDao.findById(vmSnapshot.getVmId());
    try {
        vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.RevertRequested);
    } catch (NoTransitionException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    boolean result = false;
    try {
        VMSnapshotVO snapshot = vmSnapshotDao.findById(vmSnapshotVO.getId());
        List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
        String vmInstanceName = userVm.getInstanceName();
        VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(snapshot).getParent();
        VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(snapshot.getId(), snapshot.getName(), snapshot.getType(), snapshot.getCreated().getTime(), snapshot.getDescription(), snapshot.getCurrent(), parent, true);
        Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
        GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
        RevertToVMSnapshotCommand revertToSnapshotCommand = new RevertToVMSnapshotCommand(vmInstanceName, userVm.getUuid(), vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
        HostVO host = hostDao.findById(hostId);
        GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
        if (guestOsMapping == null) {
            revertToSnapshotCommand.setPlatformEmulator(null);
        } else {
            revertToSnapshotCommand.setPlatformEmulator(guestOsMapping.getGuestOsName());
        }
        RevertToVMSnapshotAnswer answer = (RevertToVMSnapshotAnswer) agentMgr.send(hostId, revertToSnapshotCommand);
        if (answer != null && answer.getResult()) {
            processAnswer(vmSnapshotVO, userVm, answer, hostId);
            result = true;
        } else {
            String errMsg = "Revert VM: " + userVm.getInstanceName() + " to snapshot: " + vmSnapshotVO.getName() + " failed";
            if (answer != null && answer.getDetails() != null)
                errMsg = errMsg + " due to " + answer.getDetails();
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
    } catch (OperationTimedoutException e) {
        s_logger.debug("Failed to revert vm snapshot", e);
        throw new CloudRuntimeException(e.getMessage());
    } catch (AgentUnavailableException e) {
        s_logger.debug("Failed to revert vm snapshot", e);
        throw new CloudRuntimeException(e.getMessage());
    } finally {
        if (!result) {
            try {
                vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
            } catch (NoTransitionException e1) {
                s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage());
            }
        }
    }
    return result;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) RevertToVMSnapshotCommand(com.cloud.agent.api.RevertToVMSnapshotCommand) GuestOSVO(com.cloud.storage.GuestOSVO) HostVO(com.cloud.host.HostVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) VMSnapshotTO(com.cloud.agent.api.VMSnapshotTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Aggregations

GuestOSHypervisorVO (com.cloud.storage.GuestOSHypervisorVO)15 HostVO (com.cloud.host.HostVO)10 GuestOSVO (com.cloud.storage.GuestOSVO)10 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)6 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)6 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)6 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)5 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)5 UserVmVO (com.cloud.vm.UserVmVO)5 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)5 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4 ArrayList (java.util.ArrayList)4 Command (com.cloud.agent.api.Command)3 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 IOException (java.io.IOException)3 Date (java.util.Date)3 Test (org.junit.Test)3 CreateVMSnapshotCommand (com.cloud.agent.api.CreateVMSnapshotCommand)2