Search in sources :

Example 16 with PingCommand

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

the class BrocadeVcsResource method getCurrentStatus.

@Override
public PingCommand getCurrentStatus(long id) {
    Output output;
    try {
        output = _brocadeVcsApi.getSwitchStatus();
    } catch (BrocadeVcsApiException e) {
        s_logger.error("getSwitchStatus failed", e);
        return null;
    }
    List<VcsNodeInfo> vcsNodes = output.getVcsNodes().getVcsNodeInfo();
    if (vcsNodes != null && !vcsNodes.isEmpty()) {
        for (VcsNodeInfo vcsNodeInfo : vcsNodes) {
            if (!"Online".equals(vcsNodeInfo.getNodeState())) {
                s_logger.error("Brocade Switch is not ready: " + id);
                return null;
            }
        }
    }
    return new PingCommand(Host.Type.L2Networking, id);
}
Also used : Output(com.cloud.network.schema.showvcs.Output) VcsNodeInfo(com.cloud.network.schema.showvcs.VcsNodeInfo) BrocadeVcsApiException(com.cloud.network.brocade.BrocadeVcsApiException) PingCommand(com.cloud.agent.api.PingCommand)

Example 17 with PingCommand

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

the class BigSwitchBcfResourceTest method testPingCommandStatusFail.

@Test
public void testPingCommandStatusFail() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    ControlClusterStatus ccs = mock(ControlClusterStatus.class);
    when(ccs.getStatus()).thenReturn(false);
    when(_bigswitchBcfApi.getControlClusterStatus()).thenReturn(ccs);
    PingCommand ping = _resource.getCurrentStatus(42);
    assertTrue(ping == null);
}
Also used : ControlClusterStatus(com.cloud.network.bigswitch.ControlClusterStatus) PingCommand(com.cloud.agent.api.PingCommand) Test(org.junit.Test)

Example 18 with PingCommand

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

the class BrocadeVcsResourceTest method testPingCommandStatusOk.

@Test
public void testPingCommandStatusOk() throws ConfigurationException, BrocadeVcsApiException {
    resource.configure("BrocadeVcsResource", parameters);
    final VcsNodeInfo nodeInfo = mock(VcsNodeInfo.class);
    when(nodeInfo.getNodeState()).thenReturn("Online");
    List<VcsNodeInfo> nodes = new ArrayList<VcsNodeInfo>();
    nodes.add(nodeInfo);
    final VcsNodes vcsNodes = mock(VcsNodes.class);
    final Output output = mock(Output.class);
    when(output.getVcsNodes()).thenReturn(vcsNodes);
    when(vcsNodes.getVcsNodeInfo()).thenReturn(nodes);
    when(api.getSwitchStatus()).thenReturn(output);
    final PingCommand ping = resource.getCurrentStatus(42);
    assertTrue(ping != null);
    assertTrue(ping.getHostId() == 42);
    assertTrue(ping.getHostType() == Host.Type.L2Networking);
}
Also used : VcsNodes(com.cloud.network.schema.showvcs.VcsNodes) Output(com.cloud.network.schema.showvcs.Output) VcsNodeInfo(com.cloud.network.schema.showvcs.VcsNodeInfo) ArrayList(java.util.ArrayList) PingCommand(com.cloud.agent.api.PingCommand) Test(org.junit.Test)

Example 19 with PingCommand

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

the class BrocadeVcsResourceTest method testPingCommandStatusApiException.

@Test
public void testPingCommandStatusApiException() throws ConfigurationException, BrocadeVcsApiException {
    resource.configure("BrocadeVcsResource", parameters);
    when(api.getSwitchStatus()).thenThrow(new BrocadeVcsApiException());
    final PingCommand ping = resource.getCurrentStatus(42);
    assertTrue(ping == null);
}
Also used : BrocadeVcsApiException(com.cloud.network.brocade.BrocadeVcsApiException) PingCommand(com.cloud.agent.api.PingCommand) Test(org.junit.Test)

Example 20 with PingCommand

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

the class BrocadeVcsResourceTest method testPingCommandStatusFail.

@Test
public void testPingCommandStatusFail() throws ConfigurationException, BrocadeVcsApiException {
    resource.configure("BrocadeVcsResource", parameters);
    final VcsNodeInfo nodeInfo = mock(VcsNodeInfo.class);
    when(nodeInfo.getNodeState()).thenReturn("Offline");
    List<VcsNodeInfo> nodes = new ArrayList<VcsNodeInfo>();
    nodes.add(nodeInfo);
    final VcsNodes vcsNodes = mock(VcsNodes.class);
    final Output output = mock(Output.class);
    when(output.getVcsNodes()).thenReturn(vcsNodes);
    when(vcsNodes.getVcsNodeInfo()).thenReturn(nodes);
    when(api.getSwitchStatus()).thenReturn(output);
    final PingCommand ping = resource.getCurrentStatus(42);
    assertTrue(ping == null);
}
Also used : VcsNodes(com.cloud.network.schema.showvcs.VcsNodes) Output(com.cloud.network.schema.showvcs.Output) VcsNodeInfo(com.cloud.network.schema.showvcs.VcsNodeInfo) ArrayList(java.util.ArrayList) PingCommand(com.cloud.agent.api.PingCommand) Test(org.junit.Test)

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