Search in sources :

Example 61 with OperationTimedoutException

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

the class SecurityGroupManagerImpl method securityGroupRulesForVmSecIp.

@Override
public boolean securityGroupRulesForVmSecIp(long nicId, String secondaryIp, boolean ruleAction) {
    Account caller = CallContext.current().getCallingAccount();
    if (secondaryIp == null) {
        throw new InvalidParameterValueException("Vm secondaryIp can't be null");
    }
    NicVO nic = _nicDao.findById(nicId);
    long vmId = nic.getInstanceId();
    UserVm vm = _userVMDao.findById(vmId);
    if (vm == null || vm.getType() != VirtualMachine.Type.User) {
        throw new InvalidParameterValueException("Can't configure the SG ipset, arprules rules for the non existing or non user vm");
    }
    // Verify permissions
    _accountMgr.checkAccess(caller, null, false, vm);
    // Validate parameters
    List<SecurityGroupVO> vmSgGrps = getSecurityGroupsForVm(vmId);
    if (vmSgGrps.isEmpty()) {
        s_logger.debug("Vm is not in any Security group ");
        return true;
    }
    //If network does not support SG service, no need add SG rules for secondary ip
    Network network = _networkModel.getNetwork(nic.getNetworkId());
    if (!_networkModel.isSecurityGroupSupportedInNetwork(network)) {
        s_logger.debug("Network " + network + " is not enabled with security group service, " + "so not applying SG rules for secondary ip");
        return true;
    }
    String vmMac = vm.getPrivateMacAddress();
    String vmName = vm.getInstanceName();
    if (vmMac == null || vmName == null) {
        throw new InvalidParameterValueException("vm name or vm mac can't be null");
    }
    //create command for the to add ip in ipset and arptables rules
    NetworkRulesVmSecondaryIpCommand cmd = new NetworkRulesVmSecondaryIpCommand(vmName, vmMac, secondaryIp, ruleAction);
    s_logger.debug("Asking agent to configure rules for vm secondary ip");
    Commands cmds = null;
    cmds = new Commands(cmd);
    try {
        _agentMgr.send(vm.getHostId(), cmds);
    } catch (AgentUnavailableException e) {
        s_logger.debug(e.toString());
    } catch (OperationTimedoutException e) {
        s_logger.debug(e.toString());
    }
    return true;
}
Also used : Account(com.cloud.user.Account) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) NetworkRulesVmSecondaryIpCommand(com.cloud.agent.api.NetworkRulesVmSecondaryIpCommand) UserVm(com.cloud.uservm.UserVm) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) NicVO(com.cloud.vm.NicVO)

Example 62 with OperationTimedoutException

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

the class KVMFencerTest method testWithTimeoutingFence.

@Test
public void testWithTimeoutingFence() throws AgentUnavailableException, OperationTimedoutException {
    HostVO host = Mockito.mock(HostVO.class);
    Mockito.when(host.getClusterId()).thenReturn(1l);
    Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
    Mockito.when(host.getStatus()).thenReturn(Status.Up);
    Mockito.when(host.getDataCenterId()).thenReturn(1l);
    Mockito.when(host.getPodId()).thenReturn(1l);
    Mockito.when(host.getId()).thenReturn(1l);
    HostVO secondHost = Mockito.mock(HostVO.class);
    Mockito.when(secondHost.getClusterId()).thenReturn(1l);
    Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
    Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
    Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
    Mockito.when(secondHost.getPodId()).thenReturn(1l);
    Mockito.when(host.getId()).thenReturn(2l);
    VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
    Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Arrays.asList(host, secondHost));
    Mockito.when(agentManager.send(Matchers.anyLong(), Matchers.any(FenceCommand.class))).thenThrow(new OperationTimedoutException(null, 2l, 0l, 0, false));
    Assert.assertFalse(fencer.fenceOff(virtualMachine, host));
}
Also used : FenceCommand(com.cloud.agent.api.FenceCommand) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) HostVO(com.cloud.host.HostVO) VirtualMachine(com.cloud.vm.VirtualMachine) Test(org.junit.Test)

Example 63 with OperationTimedoutException

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

the class InternalLoadBalancerVMManagerImpl method sendCommandsToInternalLbVm.

protected boolean sendCommandsToInternalLbVm(final VirtualRouter internalLbVm, final Commands cmds) throws AgentUnavailableException {
    Answer[] answers = null;
    try {
        answers = _agentMgr.send(internalLbVm.getHostId(), cmds);
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Timed Out", e);
        throw new AgentUnavailableException("Unable to send commands to virtual router ", internalLbVm.getHostId(), e);
    }
    if (answers == null) {
        return false;
    }
    if (answers.length != cmds.size()) {
        return false;
    }
    boolean result = true;
    if (answers.length > 0) {
        for (final Answer answer : answers) {
            if (!answer.getResult()) {
                result = false;
                break;
            }
        }
    }
    return result;
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) Answer(com.cloud.agent.api.Answer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException)

Example 64 with OperationTimedoutException

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

the class AgentHookBase method startAgentHttpHandlerInVM.

@Override
public void startAgentHttpHandlerInVM(StartupProxyCommand startupCmd) {
    StartConsoleProxyAgentHttpHandlerCommand cmd = null;
    try {
        SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
        byte[] randomBytes = new byte[16];
        random.nextBytes(randomBytes);
        String storePassword = Base64.encodeBase64String(randomBytes);
        byte[] ksBits = null;
        String consoleProxyUrlDomain = _configDao.getValue(Config.ConsoleProxyUrlDomain.key());
        if (consoleProxyUrlDomain == null || consoleProxyUrlDomain.isEmpty()) {
            s_logger.debug("SSL is disabled for console proxy based on global config, skip loading certificates");
        } else {
            ksBits = _ksMgr.getKeystoreBits(ConsoleProxyManager.CERTIFICATE_NAME, ConsoleProxyManager.CERTIFICATE_NAME, storePassword);
        //ks manager raises exception if ksBits are null, hence no need to explicltly handle the condition
        }
        cmd = new StartConsoleProxyAgentHttpHandlerCommand(ksBits, storePassword);
        cmd.setEncryptorPassword(getEncryptorPassword());
        HostVO consoleProxyHost = findConsoleProxyHost(startupCmd);
        assert (consoleProxyHost != null);
        if (consoleProxyHost != null) {
            Answer answer = _agentMgr.send(consoleProxyHost.getId(), cmd);
            if (answer == null || !answer.getResult()) {
                s_logger.error("Console proxy agent reported that it failed to execute http handling startup command");
            } else {
                s_logger.info("Successfully sent out command to start HTTP handling in console proxy agent");
            }
        }
    } catch (NoSuchAlgorithmException e) {
        s_logger.error("Unexpected exception in SecureRandom Algorithm selection ", e);
    } catch (AgentUnavailableException e) {
        s_logger.error("Unable to send http handling startup command to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e);
    } catch (OperationTimedoutException e) {
        s_logger.error("Unable to send http handling startup command(time out) to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e);
    } catch (OutOfMemoryError e) {
        s_logger.error("Unrecoverable OutOfMemory Error, exit and let it be re-launched");
        System.exit(1);
    } catch (Exception e) {
        s_logger.error("Unexpected exception when sending http handling startup command(time out) to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e);
    }
}
Also used : ConsoleAccessAuthenticationAnswer(com.cloud.agent.api.ConsoleAccessAuthenticationAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StartConsoleProxyAgentHttpHandlerCommand(com.cloud.agent.api.proxy.StartConsoleProxyAgentHttpHandlerCommand) SecureRandom(java.security.SecureRandom) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 65 with OperationTimedoutException

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

the class AccountManagerImpl method doDisableAccount.

private boolean doDisableAccount(long accountId) throws ConcurrentOperationException, ResourceUnavailableException {
    List<VMInstanceVO> vms = _vmDao.listByAccountId(accountId);
    boolean success = true;
    for (VMInstanceVO vm : vms) {
        try {
            try {
                _itMgr.advanceStop(vm.getUuid(), false);
            } catch (OperationTimedoutException ote) {
                s_logger.warn("Operation for stopping vm timed out, unable to stop vm " + vm.getHostName(), ote);
                success = false;
            }
        } catch (AgentUnavailableException aue) {
            s_logger.warn("Agent running on host " + vm.getHostId() + " is unavailable, unable to stop vm " + vm.getHostName(), aue);
            success = false;
        }
    }
    return success;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) VMInstanceVO(com.cloud.vm.VMInstanceVO)

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