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);
}
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;
}
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());
}
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);
}
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);
}
Aggregations