Search in sources :

Example 1 with Request

use of com.cloud.common.transport.Request in project cosmic by MissionCriticalCloud.

the class Agent method stop.

public void stop(final String reason) {
    logger.info("Stopping the agent due to: {}", reason);
    if (this._connection != null) {
        final ShutdownCommand cmd = new ShutdownCommand(reason);
        try {
            if (this._link != null) {
                final Request req = new Request(this._id != null ? this._id : -1, -1, cmd, false);
                this._link.send(req.toBytes());
            }
        } catch (final ClosedChannelException e) {
            logger.warn("Unable to send: " + cmd.toString());
        } catch (final Exception e) {
            logger.warn("Unable to send: " + cmd.toString() + " due to exception: ", e);
        }
        logger.debug("Sending shutdown to management server");
        try {
            Thread.sleep(1000);
        } catch (final InterruptedException e) {
            logger.debug("Who the heck interrupted me here?");
        }
        this._connection.stop();
        this._connection = null;
    }
    if (this.resource != null) {
        this.resource.stop();
    }
    this._urgentTaskPool.shutdownNow();
    synchronized (this) {
        this.notifyAll();
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) Request(com.cloud.common.transport.Request) ShutdownCommand(com.cloud.legacymodel.communication.command.ShutdownCommand) AgentControlChannelException(com.cloud.legacymodel.exceptions.AgentControlChannelException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NioConnectionException(com.cloud.legacymodel.exceptions.NioConnectionException)

Example 2 with Request

use of com.cloud.common.transport.Request in project cosmic by MissionCriticalCloud.

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.common.transport.Request)

Example 3 with Request

use of com.cloud.common.transport.Request in project cosmic by MissionCriticalCloud.

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 (this.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(), this._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 : AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) PingAnswer(com.cloud.legacymodel.communication.answer.PingAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) UnsupportedAnswer(com.cloud.legacymodel.communication.answer.UnsupportedAnswer) ReadyCommand(com.cloud.legacymodel.communication.command.ReadyCommand) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) Command(com.cloud.legacymodel.communication.command.Command) AgentControlCommand(com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand) StartupStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupStorageCommand) StartupSecondaryStorageCommand(com.cloud.legacymodel.communication.command.startup.StartupSecondaryStorageCommand) StartupRoutingCommand(com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand) CheckHealthCommand(com.cloud.legacymodel.communication.command.CheckHealthCommand) PingRoutingCommand(com.cloud.legacymodel.communication.command.PingRoutingCommand) ShutdownCommand(com.cloud.legacymodel.communication.command.ShutdownCommand) StartupProxyCommand(com.cloud.legacymodel.communication.command.startup.StartupProxyCommand) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Request(com.cloud.common.transport.Request)

Example 4 with Request

use of com.cloud.common.transport.Request in project cosmic by MissionCriticalCloud.

the class ClusteredAgentManagerImpl method finishRebalance.

protected void finishRebalance(final long hostId, final long futureOwnerId, final Event event) {
    final boolean success = event == Event.RebalanceCompleted ? true : false;
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Finishing rebalancing for the agent " + hostId + " with event " + event);
    }
    final AgentAttache attache = findAttache(hostId);
    if (attache == null || !(attache instanceof ClusteredAgentAttache)) {
        s_logger.debug("Unable to find forward attache for the host id=" + hostId + ", assuming that the agent disconnected already");
        this._hostTransferDao.completeAgentTransfer(hostId);
        return;
    }
    final ClusteredAgentAttache forwardAttache = (ClusteredAgentAttache) attache;
    if (success) {
        // 1) Set transfer mode to false - so the agent can start processing requests normally
        forwardAttache.setTransferMode(false);
        // 2) Get all transfer requests and route them to peer
        Request requestToTransfer = forwardAttache.getRequestToTransfer();
        while (requestToTransfer != null) {
            s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " + this._nodeId + " to " + futureOwnerId);
            final boolean routeResult = routeToPeer(Long.toString(futureOwnerId), requestToTransfer.getBytes());
            if (!routeResult) {
                logD(requestToTransfer.getBytes(), "Failed to route request to peer");
            }
            requestToTransfer = forwardAttache.getRequestToTransfer();
        }
        s_logger.debug("Management server " + this._nodeId + " completed agent " + hostId + " rebalance to " + futureOwnerId);
    } else {
        failRebalance(hostId);
    }
    s_logger.debug("Management server " + this._nodeId + " completed agent " + hostId + " rebalance");
    this._hostTransferDao.completeAgentTransfer(hostId);
}
Also used : Request(com.cloud.common.transport.Request)

Example 5 with Request

use of com.cloud.common.transport.Request in project cosmic by MissionCriticalCloud.

the class AgentAttache method sendNext.

protected synchronized void sendNext(final long seq) {
    _currentSequence = null;
    if (_requests.isEmpty()) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(log(seq, "No more commands found"));
        }
        return;
    }
    final Request req = _requests.pop();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(log(req.getSequence(), "Sending now.  is current sequence."));
    }
    try {
        send(req);
    } catch (final AgentUnavailableException e) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(log(req.getSequence(), "Unable to send the next sequence"));
        }
        cancel(req.getSequence());
    }
    _currentSequence = req.getSequence();
}
Also used : AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) Request(com.cloud.common.transport.Request)

Aggregations

Request (com.cloud.common.transport.Request)13 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)6 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)6 ReadyCommand (com.cloud.legacymodel.communication.command.ReadyCommand)5 ShutdownCommand (com.cloud.legacymodel.communication.command.ShutdownCommand)5 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)5 Command (com.cloud.legacymodel.communication.command.Command)4 PingCommand (com.cloud.legacymodel.communication.command.PingCommand)4 AgentControlCommand (com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand)4 ClosedChannelException (java.nio.channels.ClosedChannelException)4 HostVO (com.cloud.host.HostVO)3 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)3 ConfigurationException (javax.naming.ConfigurationException)3 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)2 Answer (com.cloud.legacymodel.communication.answer.Answer)2 StartupAnswer (com.cloud.legacymodel.communication.answer.StartupAnswer)2 CheckHealthCommand (com.cloud.legacymodel.communication.command.CheckHealthCommand)2 CronCommand (com.cloud.legacymodel.communication.command.CronCommand)2 MaintainCommand (com.cloud.legacymodel.communication.command.MaintainCommand)2 PingRoutingCommand (com.cloud.legacymodel.communication.command.PingRoutingCommand)2