Search in sources :

Example 6 with PingCommand

use of com.cloud.agent.api.PingCommand in project cloudstack by apache.

the class CiscoVnmcResourceTest method testPingCommandStatusOk.

@Test
public void testPingCommandStatusOk() throws ConfigurationException, ExecutionException {
    _resource.setConnection(_connection);
    when(_connection.login()).thenReturn(true);
    PingCommand ping = _resource.getCurrentStatus(1);
    assertTrue(ping != null);
    assertTrue(ping.getHostId() == 1);
    assertTrue(ping.getHostType() == Host.Type.ExternalFirewall);
}
Also used : PingCommand(com.cloud.agent.api.PingCommand) Test(org.junit.Test)

Example 7 with PingCommand

use of com.cloud.agent.api.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() == Type.L2Networking);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) PingCommand(com.cloud.agent.api.PingCommand) Test(org.junit.Test)

Example 8 with PingCommand

use of com.cloud.agent.api.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.agent.api.PingCommand) Test(org.junit.Test)

Example 9 with PingCommand

use of com.cloud.agent.api.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(Host.Type.L2Networking, id);
}
Also used : ControlClusterStatus(com.cloud.network.nicira.ControlClusterStatus) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) PingCommand(com.cloud.agent.api.PingCommand)

Example 10 with PingCommand

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

Aggregations

PingCommand (com.cloud.agent.api.PingCommand)23 Test (org.junit.Test)15 ControlClusterStatus (com.cloud.network.nicira.ControlClusterStatus)8 Answer (com.cloud.agent.api.Answer)4 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)4 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)3 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)3 Command (com.cloud.agent.api.Command)3 CronCommand (com.cloud.agent.api.CronCommand)3 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)3 MaintainCommand (com.cloud.agent.api.MaintainCommand)3 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)3 StartupAnswer (com.cloud.agent.api.StartupAnswer)3 StartupCommand (com.cloud.agent.api.StartupCommand)3 Request (com.cloud.agent.transport.Request)3 Response (com.cloud.agent.transport.Response)3 Output (com.cloud.network.schema.showvcs.Output)3 VcsNodeInfo (com.cloud.network.schema.showvcs.VcsNodeInfo)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 ReadyCommand (com.cloud.agent.api.ReadyCommand)2