Search in sources :

Example 46 with AgentUnavailableException

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

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

the class SecurityGroupListener method processConnect.

@Override
public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) {
    if (s_logger.isInfoEnabled())
        s_logger.info("Received a host startup notification");
    if (cmd instanceof StartupRoutingCommand) {
        //if (Boolean.toString(true).equals(host.getDetail("can_bridge_firewall"))) {
        try {
            int interval = MIN_TIME_BETWEEN_CLEANUPS + _cleanupRandom.nextInt(MIN_TIME_BETWEEN_CLEANUPS / 2);
            CleanupNetworkRulesCmd cleanupCmd = new CleanupNetworkRulesCmd(interval);
            Commands c = new Commands(cleanupCmd);
            _agentMgr.send(host.getId(), c, this);
            if (s_logger.isInfoEnabled())
                s_logger.info("Scheduled network rules cleanup, interval=" + cleanupCmd.getInterval());
        } catch (AgentUnavailableException e) {
            //usually hypervisors that do not understand sec group rules.
            s_logger.debug("Unable to schedule network rules cleanup for host " + host.getId(), e);
        }
        if (_workTracker != null) {
            _workTracker.processConnect(host.getId());
        }
    }
}
Also used : AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) CleanupNetworkRulesCmd(com.cloud.agent.api.CleanupNetworkRulesCmd)

Example 48 with AgentUnavailableException

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

the class SecurityGroupManagerImpl method work.

@DB
public void work() {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Checking the database");
    }
    final SecurityGroupWorkVO work = _workDao.take(_serverId);
    if (work == null) {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Security Group work: no work found");
        }
        return;
    }
    final Long userVmId = work.getInstanceId();
    if (work.getStep() == Step.Done) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Security Group work: found a job in done state, rescheduling for vm: " + userVmId);
        }
        ArrayList<Long> affectedVms = new ArrayList<Long>();
        affectedVms.add(userVmId);
        scheduleRulesetUpdateToHosts(affectedVms, false, _timeBetweenCleanups * 1000l);
        return;
    }
    s_logger.debug("Working on " + work);
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            UserVm vm = null;
            Long seqnum = null;
            boolean locked = false;
            try {
                vm = _userVMDao.acquireInLockTable(work.getInstanceId());
                if (vm == null) {
                    vm = _userVMDao.findById(work.getInstanceId());
                    if (vm == null) {
                        s_logger.info("VM " + work.getInstanceId() + " is removed");
                        locked = true;
                        return;
                    }
                    s_logger.warn("Unable to acquire lock on vm id=" + userVmId);
                    return;
                }
                locked = true;
                Long agentId = null;
                VmRulesetLogVO log = _rulesetLogDao.findByVmId(userVmId);
                if (log == null) {
                    s_logger.warn("Cannot find log record for vm id=" + userVmId);
                    return;
                }
                seqnum = log.getLogsequence();
                if (vm != null && vm.getState() == State.Running) {
                    Map<PortAndProto, Set<String>> ingressRules = generateRulesForVM(userVmId, SecurityRuleType.IngressRule);
                    Map<PortAndProto, Set<String>> egressRules = generateRulesForVM(userVmId, SecurityRuleType.EgressRule);
                    agentId = vm.getHostId();
                    if (agentId != null) {
                        // get nic secondary ip address
                        String privateIp = vm.getPrivateIpAddress();
                        NicVO nic = _nicDao.findByIp4AddressAndVmId(privateIp, vm.getId());
                        List<String> nicSecIps = null;
                        if (nic != null) {
                            if (nic.getSecondaryIp()) {
                                //get secondary ips of the vm
                                long networkId = nic.getNetworkId();
                                nicSecIps = _nicSecIpDao.getSecondaryIpAddressesForNic(nic.getId());
                            }
                        }
                        SecurityGroupRulesCmd cmd = generateRulesetCmd(vm.getInstanceName(), nic.getIPv6Address(), vm.getPrivateIpAddress(), vm.getPrivateMacAddress(), vm.getId(), generateRulesetSignature(ingressRules, egressRules), seqnum, ingressRules, egressRules, nicSecIps);
                        Commands cmds = new Commands(cmd);
                        try {
                            _agentMgr.send(agentId, cmds, _answerListener);
                        } catch (AgentUnavailableException e) {
                            s_logger.debug("Unable to send ingress rules updates for vm: " + userVmId + "(agentid=" + agentId + ")");
                            _workDao.updateStep(work.getInstanceId(), seqnum, Step.Done);
                        }
                    }
                }
            } finally {
                if (locked) {
                    _userVMDao.releaseFromLockTable(userVmId);
                    _workDao.updateStep(work.getId(), Step.Done);
                }
            }
        }
    });
}
Also used : SecurityGroupRulesCmd(com.cloud.agent.api.SecurityGroupRulesCmd) ArrayList(java.util.ArrayList) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) UserVm(com.cloud.uservm.UserVm) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) NicVO(com.cloud.vm.NicVO) DB(com.cloud.utils.db.DB)

Example 49 with AgentUnavailableException

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

Example 50 with AgentUnavailableException

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

the class ResourceManagerImpl method updateClusterPassword.

@Override
public boolean updateClusterPassword(final UpdateHostPasswordCmd command) {
    final boolean shouldUpdateHostPasswd = command.getUpdatePasswdOnHost();
    // get agents for the cluster
    final List<HostVO> hosts = listAllHostsInCluster(command.getClusterId());
    for (final HostVO host : hosts) {
        try {
            /*
                 * FIXME: this is a buggy logic, check with alex. Shouldn't
                 * return if propagation return non null
                 */
            final Boolean result = propagateResourceEvent(host.getId(), ResourceState.Event.UpdatePassword);
            if (result != null) {
                return result;
            }
        } catch (final AgentUnavailableException e) {
            s_logger.error("Agent is not availbale!", e);
        }
        if (shouldUpdateHostPasswd) {
            final boolean isUpdated = doUpdateHostPassword(host.getId());
            if (!isUpdated) {
                throw new CloudRuntimeException("CloudStack failed to update the password of the Host with UUID / ID ==> " + host.getUuid() + " / " + host.getId() + ". Please make sure you are still able to connect to your hosts.");
            }
        }
    }
    return true;
}
Also used : AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO)

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