use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testCreateNetworkApiException.
@Test
public void testCreateNetworkApiException() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
NetworkData networkdata = mock(NetworkData.class);
NetworkData.Network network = mock(NetworkData.Network.class);
when(networkdata.getNetwork()).thenReturn(network);
when(network.getId()).thenReturn("cccc");
doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).createNetwork((NetworkData) any());
CreateBcfSegmentCommand cmd = new CreateBcfSegmentCommand("tenantid", "tenantname", (String) _parameters.get("guid"), "networkName", 0);
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
assertFalse(ans.getResult());
verify(_bigswitchBcfApi, times(3)).createNetwork((NetworkData) any());
}
use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResource method executeRequest.
private Answer executeRequest(SyncBcfTopologyCommand cmd, int numRetries) {
try {
TopologyData topo = _latestTopology;
if (!cmd.isNetworkIncluded()) {
topo.clearNetworks();
}
if (!cmd.isRouterIncluded()) {
topo.clearRouters();
}
String hash = _bigswitchBcfApi.syncTopology(topo);
if (!initTopologySyncDone) {
initTopologySyncDone = true;
}
return new BcfAnswer(cmd, true, "BCF topology synced", hash);
} catch (BigSwitchBcfApiException e) {
if (numRetries > 0) {
return retry(cmd, --numRetries);
} else {
return new BcfAnswer(cmd, e);
}
} catch (IllegalArgumentException e1) {
return new BcfAnswer(cmd, false, "Illegal argument in BCF topology sync");
}
}
use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResource method executeRequest.
private Answer executeRequest(CreateBcfRouterInterfaceCommand cmd, int numRetries) {
RouterInterfaceData routerInterface = new RouterInterfaceData(cmd.getTenantId(), cmd.getGateway(), cmd.getCidr(), cmd.getNetworkId(), cmd.getNetworkName());
try {
String hash;
hash = _bigswitchBcfApi.createRouterInterface(cmd.getTenantId(), cmd.getTenantId(), routerInterface);
return new BcfAnswer(cmd, true, "router " + cmd.getTenantId() + " created.", hash);
} catch (BigSwitchBcfApiException e) {
if (e.is_topologySyncRequested()) {
cmd.setTopologySyncRequested(true);
return new BcfAnswer(cmd, true, " created; topology sync required.");
} else {
if (numRetries > 0) {
return retry(cmd, --numRetries);
} else {
return new BcfAnswer(cmd, e);
}
}
}
}
Aggregations