Search in sources :

Example 31 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException in project cloudstack by apache.

the class VMSnapshotStrategyTest method testDeleteVMSnapshot.

@Test
public void testDeleteVMSnapshot() throws AgentUnavailableException, OperationTimedoutException {
    Long hostId = 1L;
    Long vmId = 1L;
    Long guestOsId = 1L;
    HypervisorType hypervisorType = HypervisorType.Any;
    String hypervisorVersion = "default";
    String guestOsName = "Other";
    List<VolumeObjectTO> volumeObjectTOs = new ArrayList<VolumeObjectTO>();
    VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
    UserVmVO userVmVO = Mockito.mock(UserVmVO.class);
    Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId);
    Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId);
    Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId);
    Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs);
    Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO);
    GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
    Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
    GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class);
    Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName);
    Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO);
    Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO);
    VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class);
    Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO);
    Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot);
    Mockito.when(vmSnapshot.getId()).thenReturn(1L);
    Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date());
    Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null);
    HostVO hostVO = Mockito.mock(HostVO.class);
    Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO);
    Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType);
    Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion);
    Exception e = null;
    try {
        vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot);
    } catch (CloudRuntimeException e1) {
        e = e1;
    }
    assertNotNull(e);
    DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class);
    Mockito.when(answer.getResult()).thenReturn(true);
    Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer);
    boolean result = vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot);
    assertTrue(result);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) ArrayList(java.util.ArrayList) GuestOSVO(com.cloud.storage.GuestOSVO) Date(java.util.Date) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) VMSnapshotTO(com.cloud.agent.api.VMSnapshotTO) Command(com.cloud.agent.api.Command) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) Test(org.junit.Test)

Example 32 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException 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 33 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException 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 34 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException in project cloudstack by apache.

the class NetworkHelperImpl method start.

protected DomainRouterVO start(DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params, final DeploymentPlan planToDeploy) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    s_logger.debug("Starting router " + router);
    try {
        _itMgr.advanceStart(router.getUuid(), params, planToDeploy, null);
    } catch (final OperationTimedoutException e) {
        throw new ResourceUnavailableException("Starting router " + router + " failed! " + e.toString(), DataCenter.class, router.getDataCenterId());
    }
    if (router.isStopPending()) {
        s_logger.info("Clear the stop pending flag of router " + router.getHostName() + " after start router successfully!");
        router.setStopPending(false);
        router = _routerDao.persist(router);
    }
    // We don't want the failure of VPN Connection affect the status of
    // router, so we try to make connection
    // only after router start successfully
    final Long vpcId = router.getVpcId();
    if (vpcId != null) {
        _s2sVpnMgr.reconnectDisconnectedVpnByVpc(vpcId);
    }
    return _routerDao.findById(router.getId());
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DataCenter(com.cloud.dc.DataCenter) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 35 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException in project cloudstack by apache.

the class ManagementServerMock method createVM.

public UserVm createVM(String name, Network network) {
    VMTemplateVO tmpl = getVMTemplate();
    assertNotNull(tmpl);
    ServiceOffering small = getServiceByName("Small Instance");
    assertNotNull(small);
    Answer<?> callback = new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            Commands cmds = (Commands) args[1];
            if (cmds == null) {
                return null;
            }
            PlugNicAnswer reply = new PlugNicAnswer(null, true, "PlugNic");
            com.cloud.agent.api.Answer[] answers = { reply };
            cmds.setAnswers(answers);
            return null;
        }
    };
    try {
        Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenAnswer(callback);
    } catch (AgentUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OperationTimedoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    long id = _userVmDao.getNextInSequence(Long.class, "id");
    UserVmVO vm = new UserVmVO(id, name, name, tmpl.getId(), HypervisorType.XenServer, tmpl.getGuestOSId(), false, false, _zone.getDomainId(), Account.ACCOUNT_ID_SYSTEM, 1, small.getId(), null, name, null);
    vm.setState(com.cloud.vm.VirtualMachine.State.Running);
    vm.setHostId(_hostId);
    vm.setDataCenterId(network.getDataCenterId());
    _userVmDao.persist(vm);
    NicProfile profile = new NicProfile();
    try {
        _vmMgr.addVmToNetwork(vm, network, profile);
    } catch (Exception ex) {
    // TODO Auto-generated catch block
    //ex.printStackTrace();
    }
    return vm;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) UserVmVO(com.cloud.vm.UserVmVO) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) NicProfile(com.cloud.vm.NicProfile) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) Answer(org.mockito.stubbing.Answer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer)

Aggregations

OperationTimedoutException (com.cloud.exception.OperationTimedoutException)65 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)55 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 Answer (com.cloud.agent.api.Answer)25 HostVO (com.cloud.host.HostVO)23 Commands (com.cloud.agent.manager.Commands)16 ArrayList (java.util.ArrayList)13 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)11 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)10 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)10 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)9 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)9 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)8 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)8 GuestOSVO (com.cloud.storage.GuestOSVO)8 UserVmVO (com.cloud.vm.UserVmVO)7 ClusterVMMetaDataSyncAnswer (com.cloud.agent.api.ClusterVMMetaDataSyncAnswer)6 RebootAnswer (com.cloud.agent.api.RebootAnswer)6