Search in sources :

Example 1 with StartConsoleProxyAgentHttpHandlerCommand

use of com.cloud.agent.api.proxy.StartConsoleProxyAgentHttpHandlerCommand 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)

Aggregations

AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 Answer (com.cloud.agent.api.Answer)1 ConsoleAccessAuthenticationAnswer (com.cloud.agent.api.ConsoleAccessAuthenticationAnswer)1 GetVncPortAnswer (com.cloud.agent.api.GetVncPortAnswer)1 StartConsoleProxyAgentHttpHandlerCommand (com.cloud.agent.api.proxy.StartConsoleProxyAgentHttpHandlerCommand)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 HostVO (com.cloud.host.HostVO)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SecureRandom (java.security.SecureRandom)1