Search in sources :

Example 36 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException 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 37 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException 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)

Example 38 with AgentUnavailableException

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

the class ManagementServerMock method deleteVM.

public void deleteVM(UserVm vm, Network network) {
    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;
            }
            UnPlugNicAnswer reply = new UnPlugNicAnswer(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) {
        e.printStackTrace();
    } catch (OperationTimedoutException e) {
        e.printStackTrace();
    }
    _userVmDao.remove(vm.getId());
}
Also used : UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) Answer(org.mockito.stubbing.Answer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands)

Example 39 with AgentUnavailableException

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

the class CheckOnAgentInvestigator method isVmAlive.

@Override
public boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM {
    CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(vm.getInstanceName());
    try {
        CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer) _agentMgr.send(vm.getHostId(), cmd);
        if (!answer.getResult()) {
            s_logger.debug("Unable to get vm state on " + vm.toString());
            throw new UnknownVM();
        }
        s_logger.debug("Agent responded with state " + answer.getState().toString());
        return answer.getState() == PowerState.PowerOn;
    } catch (AgentUnavailableException e) {
        s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage());
        throw new UnknownVM();
    } catch (OperationTimedoutException e) {
        s_logger.debug("Operation timed out for " + vm.toString() + ": " + e.getMessage());
        throw new UnknownVM();
    }
}
Also used : CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CheckVirtualMachineCommand(com.cloud.agent.api.CheckVirtualMachineCommand)

Example 40 with AgentUnavailableException

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

the class HighAvailabilityManagerImpl method destroyVM.

protected Long destroyVM(final HaWorkVO work) {
    final VirtualMachine vm = _itMgr.findById(work.getInstanceId());
    s_logger.info("Destroying " + vm.toString());
    try {
        if (vm.getState() != State.Destroyed) {
            s_logger.info("VM is no longer in Destroyed state " + vm.toString());
            return null;
        }
        if (vm.getHostId() != null) {
            _itMgr.destroy(vm.getUuid(), false);
            s_logger.info("Successfully destroy " + vm);
            return null;
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(vm + " has already been stopped");
            }
            return null;
        }
    } catch (final AgentUnavailableException e) {
        s_logger.debug("Agnet is not available" + e.getMessage());
    } catch (OperationTimedoutException e) {
        s_logger.debug("operation timed out: " + e.getMessage());
    } catch (ConcurrentOperationException e) {
        s_logger.debug("concurrent operation: " + e.getMessage());
    }
    return (System.currentTimeMillis() >> 10) + _stopRetryInterval;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

AgentUnavailableException (com.cloud.exception.AgentUnavailableException)74 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)56 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)30 Answer (com.cloud.agent.api.Answer)27 HostVO (com.cloud.host.HostVO)25 Commands (com.cloud.agent.manager.Commands)21 ArrayList (java.util.ArrayList)15 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)11 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 Command (com.cloud.agent.api.Command)9 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)9 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)9 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)8 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)8 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 GuestOSVO (com.cloud.storage.GuestOSVO)8 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)7 FenceCommand (com.cloud.agent.api.FenceCommand)6 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6