Search in sources :

Example 1 with PingCommand

use of com.cloud.legacymodel.communication.command.PingCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResource method getCurrentStatus.

@Override
public PingCommand getCurrentStatus(final long id) {
    try {
        final ControlClusterStatus ccs = getNiciraNvpApi().getControlClusterStatus();
        getApiProviderMajorityVersion(ccs);
        if (!"stable".equals(ccs.getClusterStatus())) {
            s_logger.error("ControlCluster state is not stable: " + ccs.getClusterStatus());
            rotateNiciraNvpApi();
            return null;
        }
    } catch (final NiciraNvpApiException e) {
        s_logger.error("getControlClusterStatus failed", e);
        rotateNiciraNvpApi();
        return null;
    }
    return new PingCommand(HostType.L2Networking, id);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) PingCommand(com.cloud.legacymodel.communication.command.PingCommand)

Example 2 with PingCommand

use of com.cloud.legacymodel.communication.command.PingCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testPingCommandStatusOk.

@Test
public void testPingCommandStatusOk() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final ControlClusterStatus ccs = mock(ControlClusterStatus.class);
    when(ccs.getClusterStatus()).thenReturn("stable");
    when(nvpApi.getControlClusterStatus()).thenReturn(ccs);
    final PingCommand ping = resource.getCurrentStatus(42);
    assertTrue(ping != null);
    assertTrue(ping.getHostId() == 42);
    assertTrue(ping.getHostType() == HostType.L2Networking);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) Test(org.junit.Test)

Example 3 with PingCommand

use of com.cloud.legacymodel.communication.command.PingCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testPingCommandStatusApiException.

@Test
public void testPingCommandStatusApiException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final ControlClusterStatus ccs = mock(ControlClusterStatus.class);
    when(ccs.getClusterStatus()).thenReturn("unstable");
    when(nvpApi.getControlClusterStatus()).thenThrow(new NiciraNvpApiException());
    final PingCommand ping = resource.getCurrentStatus(42);
    assertTrue(ping == null);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) Test(org.junit.Test)

Example 4 with PingCommand

use of com.cloud.legacymodel.communication.command.PingCommand 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)

Example 5 with PingCommand

use of com.cloud.legacymodel.communication.command.PingCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testPingCommandStatusFail.

@Test
public void testPingCommandStatusFail() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final ControlClusterStatus ccs = mock(ControlClusterStatus.class);
    when(ccs.getClusterStatus()).thenReturn("unstable");
    when(nvpApi.getControlClusterStatus()).thenReturn(ccs);
    final PingCommand ping = resource.getCurrentStatus(42);
    assertTrue(ping == null);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) PingCommand(com.cloud.legacymodel.communication.command.PingCommand) Test(org.junit.Test)

Aggregations

PingCommand (com.cloud.legacymodel.communication.command.PingCommand)5 ControlClusterStatus (com.cloud.network.nicira.ControlClusterStatus)4 Test (org.junit.Test)3 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)2 Request (com.cloud.common.transport.Request)1 Response (com.cloud.common.transport.Response)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 MaintainAnswer (com.cloud.legacymodel.communication.answer.MaintainAnswer)1 StartupAnswer (com.cloud.legacymodel.communication.answer.StartupAnswer)1 Command (com.cloud.legacymodel.communication.command.Command)1 CronCommand (com.cloud.legacymodel.communication.command.CronCommand)1 MaintainCommand (com.cloud.legacymodel.communication.command.MaintainCommand)1 ReadyCommand (com.cloud.legacymodel.communication.command.ReadyCommand)1 ShutdownCommand (com.cloud.legacymodel.communication.command.ShutdownCommand)1 AgentControlCommand (com.cloud.legacymodel.communication.command.agentcontrol.AgentControlCommand)1 StartupCommand (com.cloud.legacymodel.communication.command.startup.StartupCommand)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1