Search in sources :

Example 1 with Output

use of com.cloud.network.schema.showvcs.Output 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 2 with Output

use of com.cloud.network.schema.showvcs.Output in project cloudstack by apache.

the class BrocadeVcsApi method convertToXML.

protected Output convertToXML(String object) throws BrocadeVcsApiException {
    Output output = null;
    try {
        final JAXBContext context = JAXBContext.newInstance(Output.class);
        final StringReader reader = new StringReader(object);
        final Unmarshaller unmarshaller = context.createUnmarshaller();
        final Object result = unmarshaller.unmarshal(reader);
        if (result instanceof Output) {
            output = (Output) result;
            s_logger.info(output);
        }
    } catch (final JAXBException e) {
        s_logger.error("Failed to convert string to object : " + e.getMessage());
        throw new BrocadeVcsApiException("Failed to convert string to object : " + e.getMessage());
    }
    return output;
}
Also used : Output(com.cloud.network.schema.showvcs.Output) JAXBException(javax.xml.bind.JAXBException) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 3 with Output

use of com.cloud.network.schema.showvcs.Output in project cloudstack by apache.

the class BrocadeVcsApiTest method testGetSwitchStatus.

@Test
public void testGetSwitchStatus() throws BrocadeVcsApiException, IOException {
    // Prepare
    method = mock(HttpPost.class);
    response = mock(HttpResponse.class);
    final StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK);
    when(response.getStatusLine()).thenReturn(statusLine);
    when(response.getEntity()).thenReturn(new StringEntity(OUTPUT_XML_RESPONSE));
    // Execute
    final Output result = api.getSwitchStatus();
    // Assert
    verify(method, times(1)).releaseConnection();
    assertEquals("Wrong URI for get SwitchStatus REST service", Constants.STATUS_URI, uri);
    assertEquals("Wrong HTTP method for get SwitchStatus REST service", "post", type);
    assertEquals("Wrong state for get SwitchStatus REST service", "Online", result.getVcsNodes().getVcsNodeInfo().get(0).getNodeState());
}
Also used : StatusLine(org.apache.http.StatusLine) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Output(com.cloud.network.schema.showvcs.Output) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 4 with Output

use of com.cloud.network.schema.showvcs.Output 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 5 with Output

use of com.cloud.network.schema.showvcs.Output 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

Output (com.cloud.network.schema.showvcs.Output)5 PingCommand (com.cloud.agent.api.PingCommand)3 VcsNodeInfo (com.cloud.network.schema.showvcs.VcsNodeInfo)3 Test (org.junit.Test)3 VcsNodes (com.cloud.network.schema.showvcs.VcsNodes)2 ArrayList (java.util.ArrayList)2 BrocadeVcsApiException (com.cloud.network.brocade.BrocadeVcsApiException)1 StringReader (java.io.StringReader)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1