use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testCreateSourceNatRetryOnce.
@Test
public void testCreateSourceNatRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
when(_bigswitchBcfApi.modifyRouter((String) any(), (RouterData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
UpdateBcfRouterCommand cmd = new UpdateBcfRouterCommand("tenantid");
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
assertTrue(ans.getResult());
}
use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testDeleteStaticNatApiException.
@Test
public void testDeleteStaticNatApiException() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).deleteFloatingIp((String) any(), (String) any());
DeleteBcfStaticNatCommand cmd = new DeleteBcfStaticNatCommand("tenantid", "10.4.4.100");
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
assertFalse(ans.getResult());
verify(_bigswitchBcfApi, times(3)).deleteFloatingIp((String) any(), (String) any());
}
use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testUpdateAttachmentRetryOnce.
@Test
public void testUpdateAttachmentRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
when(_bigswitchBcfApi.modifyAttachment((String) any(), (String) any(), (AttachmentData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(new UpdateBcfAttachmentCommand("networkId", "portId", "tenantId", "portname"));
assertTrue(ans.getResult());
}
use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfUtils method sendBcfCommandWithNetworkSyncCheck.
public BcfAnswer sendBcfCommandWithNetworkSyncCheck(BcfCommand cmd, Network network) throws IllegalArgumentException {
// get registered Big Switch controller
ControlClusterData cluster = getControlClusterData(network.getPhysicalNetworkId());
if (cluster.getMaster() == null) {
return new BcfAnswer(cmd, new CloudRuntimeException("Big Switch Network controller temporarily unavailable"));
}
TopologyData topo = getTopology(network.getPhysicalNetworkId());
cmd.setTopology(topo);
BcfAnswer answer = (BcfAnswer) _agentMgr.easySend(cluster.getMaster().getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("BCF API Command failed");
throw new IllegalArgumentException("Failed API call to Big Switch Network plugin");
}
String newHash = answer.getHash();
if (cmd.isTopologySyncRequested()) {
newHash = syncTopologyToBcfHost(cluster.getMaster());
}
if (newHash != null) {
commitTopologyHash(network.getPhysicalNetworkId(), newHash);
}
HostVO slave = cluster.getSlave();
if (slave != null) {
TopologyData newTopo = getTopology(network.getPhysicalNetworkId());
CacheBcfTopologyCommand cacheCmd = new CacheBcfTopologyCommand(newTopo);
_agentMgr.easySend(cluster.getSlave().getId(), cacheCmd);
}
return answer;
}
use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResource method executeRequest.
private Answer executeRequest(CreateBcfRouterCommand cmd, int numRetries) {
RouterData router = new RouterData(cmd.getTenantId());
try {
String hash;
hash = _bigswitchBcfApi.createRouter(cmd.getTenantId(), router);
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