Search in sources :

Example 6 with Request

use of com.cloud.agent.transport.Request in project cloudstack by apache.

the class AgentManagerImpl method send.

@Override
public Answer[] send(final Long hostId, final Commands commands, int timeout) throws AgentUnavailableException, OperationTimedoutException {
    assert hostId != null : "Who's not checking the agent id before sending?  ... (finger wagging)";
    if (hostId == null) {
        throw new AgentUnavailableException(-1);
    }
    if (timeout <= 0) {
        timeout = Wait.value();
    }
    if (CheckTxnBeforeSending.value()) {
        if (!noDbTxn()) {
            throw new CloudRuntimeException("We do not allow transactions to be wrapped around commands sent to be executed on remote agents.  " + "We cannot predict how long it takes a command to complete.  " + "The transaction may be rolled back because the connection took too long.");
        }
    } else {
        assert noDbTxn() : "I know, I know.  Why are we so strict as to not allow txn across an agent call?  ...  Why are we so cruel ... Why are we such a dictator .... Too bad... Sorry...but NO AGENT COMMANDS WRAPPED WITHIN DB TRANSACTIONS!";
    }
    final Command[] cmds = checkForCommandsAndTag(commands);
    final AgentAttache agent = getAttache(hostId);
    if (agent == null || agent.isClosed()) {
        throw new AgentUnavailableException("agent not logged into this management server", hostId);
    }
    final Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
    req.setSequence(agent.getNextSequence());
    final Answer[] answers = agent.send(req, timeout);
    notifyAnswersToMonitors(hostId, req.getSequence(), answers);
    commands.setAnswers(answers);
    return answers;
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) PingAnswer(com.cloud.agent.api.PingAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) PingCommand(com.cloud.agent.api.PingCommand) PingRoutingCommand(com.cloud.agent.api.PingRoutingCommand) SetHostParamsCommand(com.cloud.agent.api.SetHostParamsCommand) StartupSecondaryStorageCommand(com.cloud.agent.api.StartupSecondaryStorageCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) StartupProxyCommand(com.cloud.agent.api.StartupProxyCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) Command(com.cloud.agent.api.Command) ReadyCommand(com.cloud.agent.api.ReadyCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Request(com.cloud.agent.transport.Request)

Example 7 with Request

use of com.cloud.agent.transport.Request in project CloudStack-archive by CloudStack-extras.

the class Agent method sendStartup.

public void sendStartup(Link link) {
    final StartupCommand[] startup = _resource.initialize();
    final Command[] commands = new Command[startup.length];
    for (int i = 0; i < startup.length; i++) {
        setupStartupCommand(startup[i]);
        commands[i] = startup[i];
    }
    final Request request = new Request(_id != null ? _id : -1, -1, commands, false, false);
    request.setSequence(getNextSequence());
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Sending Startup: " + request.toString());
    }
    synchronized (this) {
        _startup = new StartupTask(link);
        _timer.schedule(_startup, _startupWait);
    }
    try {
        link.send(request.toBytes());
    } catch (final ClosedChannelException e) {
        s_logger.warn("Unable to send reques: " + request.toString());
    }
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) ClosedChannelException(java.nio.channels.ClosedChannelException) MaintainCommand(com.cloud.agent.api.MaintainCommand) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) Command(com.cloud.agent.api.Command) PingCommand(com.cloud.agent.api.PingCommand) ModifySshKeysCommand(com.cloud.agent.api.ModifySshKeysCommand) UpgradeCommand(com.cloud.agent.api.UpgradeCommand) CronCommand(com.cloud.agent.api.CronCommand) Request(com.cloud.agent.transport.Request)

Example 8 with Request

use of com.cloud.agent.transport.Request in project CloudStack-archive by CloudStack-extras.

the class Agent method processOtherTask.

public void processOtherTask(Task task) {
    final Object obj = task.get();
    if (obj instanceof Response) {
        if ((System.currentTimeMillis() - _lastPingResponseTime) > _pingInterval * _shell.getPingRetries()) {
            s_logger.error("Ping Interval has gone past " + _pingInterval * _shell.getPingRetries() + ".  Attempting to reconnect.");
            final Link link = task.getLink();
            reconnect(link);
            return;
        }
        final PingCommand ping = _resource.getCurrentStatus(getId());
        final Request request = new Request(_id, -1, ping, false);
        request.setSequence(getNextSequence());
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Sending ping: " + request.toString());
        }
        try {
            task.getLink().send(request.toBytes());
            //if i can send pingcommand out, means the link is ok
            setLastPingResponseTime();
        } catch (final ClosedChannelException e) {
            s_logger.warn("Unable to send request: " + request.toString());
        }
    } else if (obj instanceof Request) {
        final Request req = (Request) obj;
        final Command command = req.getCommand();
        Answer answer = null;
        _inProgress.incrementAndGet();
        try {
            answer = _resource.executeRequest(command);
        } finally {
            _inProgress.decrementAndGet();
        }
        if (answer != null) {
            final Response response = new Response(req, answer);
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Watch Sent: " + response.toString());
            }
            try {
                task.getLink().send(response.toBytes());
            } catch (final ClosedChannelException e) {
                s_logger.warn("Unable to send response: " + response.toString());
            }
        }
    } else {
        s_logger.warn("Ignoring an unknown task");
    }
}
Also used : Response(com.cloud.agent.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) UpgradeAnswer(com.cloud.agent.api.UpgradeAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) MaintainCommand(com.cloud.agent.api.MaintainCommand) StartupCommand(com.cloud.agent.api.StartupCommand) AgentControlCommand(com.cloud.agent.api.AgentControlCommand) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) Command(com.cloud.agent.api.Command) PingCommand(com.cloud.agent.api.PingCommand) ModifySshKeysCommand(com.cloud.agent.api.ModifySshKeysCommand) UpgradeCommand(com.cloud.agent.api.UpgradeCommand) CronCommand(com.cloud.agent.api.CronCommand) Request(com.cloud.agent.transport.Request) Link(com.cloud.utils.nio.Link) PingCommand(com.cloud.agent.api.PingCommand)

Example 9 with Request

use of com.cloud.agent.transport.Request in project CloudStack-archive by CloudStack-extras.

the class Agent method stop.

public void stop(final String reason, final String detail) {
    s_logger.info("Stopping the agent: Reason = " + reason + (detail != null ? ": Detail = " + detail : ""));
    if (_connection != null) {
        final ShutdownCommand cmd = new ShutdownCommand(reason, detail);
        try {
            if (_link != null) {
                Request req = new Request((_id != null ? _id : -1), -1, cmd, false);
                _link.send(req.toBytes());
            }
        } catch (final ClosedChannelException e) {
            s_logger.warn("Unable to send: " + cmd.toString());
        } catch (Exception e) {
            s_logger.warn("Unable to send: " + cmd.toString() + " due to exception: ", e);
        }
        s_logger.debug("Sending shutdown to management server");
        try {
            Thread.sleep(1000);
        } catch (final InterruptedException e) {
            s_logger.debug("Who the heck interrupted me here?");
        }
        _connection.stop();
        _connection = null;
    }
    if (_resource != null) {
        _resource.stop();
        _resource = null;
    }
    _ugentTaskPool.shutdownNow();
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) Request(com.cloud.agent.transport.Request) ShutdownCommand(com.cloud.agent.api.ShutdownCommand) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AgentControlChannelException(com.cloud.exception.AgentControlChannelException)

Example 10 with Request

use of com.cloud.agent.transport.Request in project cloudstack by apache.

the class Agent method postRequest.

@Override
public void postRequest(final AgentControlCommand cmd) throws AgentControlChannelException {
    final Request request = new Request(getId(), -1, new Command[] { cmd }, true, false);
    request.setSequence(getNextSequence());
    postRequest(request);
}
Also used : Request(com.cloud.agent.transport.Request)

Aggregations

Request (com.cloud.agent.transport.Request)18 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)8 StartupCommand (com.cloud.agent.api.StartupCommand)8 ClosedChannelException (java.nio.channels.ClosedChannelException)7 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)6 Command (com.cloud.agent.api.Command)6 PingCommand (com.cloud.agent.api.PingCommand)6 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 ReadyCommand (com.cloud.agent.api.ReadyCommand)5 ConfigurationException (javax.naming.ConfigurationException)5 CronCommand (com.cloud.agent.api.CronCommand)4 MaintainCommand (com.cloud.agent.api.MaintainCommand)4 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)3 Answer (com.cloud.agent.api.Answer)3 StartupAnswer (com.cloud.agent.api.StartupAnswer)3 HostVO (com.cloud.host.HostVO)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)3 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)2 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)2