Search in sources :

Example 6 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 7 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)

Example 8 with Request

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

the class Agent method sendRequest.

@Override
public AgentControlAnswer sendRequest(final AgentControlCommand cmd, final int timeoutInMilliseconds) throws AgentControlChannelException {
    final Request request = new Request(getId(), -1, new Command[] { cmd }, true, false);
    request.setSequence(getNextSequence());
    final AgentControlListener listener = new AgentControlListener(request);
    registerControlListener(listener);
    try {
        logger.debug("Sending request to management server: " + request.toString());
        postRequest(request);
        synchronized (listener) {
            try {
                listener.wait(timeoutInMilliseconds);
            } catch (final InterruptedException e) {
                logger.warn("sendRequest is interrupted, exit waiting");
            }
        }
        return listener.getAnswer();
    } finally {
        unregisterControlListener(listener);
    }
}
Also used : Request(com.cloud.common.transport.Request) IAgentControlListener(com.cloud.common.agent.IAgentControlListener)

Example 9 with Request

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

the class Agent method sendStartup.

public void sendStartup(final Link link) {
    final StartupCommand[] startup = this.resource.initialize();
    if (startup != null) {
        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(this._id != null ? this._id : -1, -1, commands, false, false);
        request.setSequence(getNextSequence());
        if (logger.isDebugEnabled()) {
            logger.debug("Sending Startup: " + request.toString());
        }
        lockStartupTask(link);
        try {
            link.send(request.toBytes());
        } catch (final ClosedChannelException e) {
            logger.warn("Unable to send request: " + request.toString());
        }
    }
}
Also used : StartupCommand(com.cloud.legacymodel.communication.command.startup.StartupCommand) ClosedChannelException(java.nio.channels.ClosedChannelException) MaintainCommand(com.cloud.legacymodel.communication.command.MaintainCommand) ReadyCommand(com.cloud.legacymodel.communication.command.ReadyCommand) CronCommand(com.cloud.legacymodel.communication.command.CronCommand) 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) ShutdownCommand(com.cloud.legacymodel.communication.command.ShutdownCommand) Request(com.cloud.common.transport.Request)

Example 10 with Request

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

the class Agent method processOtherTask.

public void processOtherTask(final Task task) {
    final Object obj = task.get();
    if (obj instanceof Response) {
        if (System.currentTimeMillis() - this._lastPingResponseTime > this._pingInterval * this.agentConfiguration.getPingRetries()) {
            logger.error("Ping Interval has gone past " + this._pingInterval * this.agentConfiguration.getPingRetries() + ". Won't reconnect to mgt server, as connection is still alive");
            return;
        }
        final PingCommand ping = this.resource.getCurrentStatus(getId());
        final Request request = new Request(this._id, -1, ping, false);
        request.setSequence(getNextSequence());
        if (logger.isDebugEnabled()) {
            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) {
            logger.warn("Unable to send request: " + request.toString());
        }
    } else if (obj instanceof Request) {
        final Request req = (Request) obj;
        final Command command = req.getCommand();
        if (command.getContextParam("logid") != null) {
            MDC.put("logcontextid", command.getContextParam("logid"));
        }
        Answer answer = null;
        this._inProgress.incrementAndGet();
        try {
            answer = this.resource.executeRequest(command);
        } finally {
            this._inProgress.decrementAndGet();
        }
        if (answer != null) {
            final Response response = new Response(req, answer);
            if (logger.isDebugEnabled()) {
                logger.debug("Watch Sent: " + response.toString());
            }
            try {
                task.getLink().send(response.toBytes());
            } catch (final ClosedChannelException e) {
                logger.warn("Unable to send response: " + response.toString());
            }
        }
    } else {
        logger.warn("Ignoring an unknown task");
    }
}
Also used : Response(com.cloud.common.transport.Response) ClosedChannelException(java.nio.channels.ClosedChannelException) MaintainAnswer(com.cloud.legacymodel.communication.answer.MaintainAnswer) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) StartupAnswer(com.cloud.legacymodel.communication.answer.StartupAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) MaintainCommand(com.cloud.legacymodel.communication.command.MaintainCommand) ReadyCommand(com.cloud.legacymodel.communication.command.ReadyCommand) CronCommand(com.cloud.legacymodel.communication.command.CronCommand) 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) ShutdownCommand(com.cloud.legacymodel.communication.command.ShutdownCommand) Request(com.cloud.common.transport.Request) PingCommand(com.cloud.legacymodel.communication.command.PingCommand)

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