use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfUtils method syncTopologyToBcfHost.
public String syncTopologyToBcfHost(HostVO bigswitchBcfHost, boolean natEnabled) {
SyncBcfTopologyCommand syncCmd;
if (natEnabled) {
syncCmd = new SyncBcfTopologyCommand(true, true);
} else {
syncCmd = new SyncBcfTopologyCommand(true, false);
}
BcfAnswer syncAnswer = (BcfAnswer) _agentMgr.easySend(bigswitchBcfHost.getId(), syncCmd);
if (syncAnswer == null || !syncAnswer.getResult()) {
s_logger.error("SyncBcfTopologyCommand failed");
return null;
}
return syncAnswer.getHash();
}
use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResource method executeRequest.
private Answer executeRequest(UpdateBcfRouterCommand cmd, int numRetries) {
RouterData routerData = new RouterData(cmd.getTenantId());
List<AclData> acls = new ArrayList<AclData>();
acls.addAll(cmd.getAcls());
routerData.getRouter().getAcls().addAll(acls);
routerData.getRouter().addExternalGateway(cmd.getPublicIp());
try {
String hash = _bigswitchBcfApi.modifyRouter(cmd.getTenantId(), routerData);
return new BcfAnswer(cmd, true, "tenant " + cmd.getTenantId() + " router updated", hash);
} catch (BigSwitchBcfApiException e) {
if (e.is_topologySyncRequested()) {
cmd.setTopologySyncRequested(true);
return new BcfAnswer(cmd, true, "tenant " + cmd.getTenantId() + " router updated but topology sync required.");
} else {
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 router update");
}
}
use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testDeleteSourceNatRetryOnce.
@Test
public void testDeleteSourceNatRetryOnce() 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 testDeleteAttachmentException.
@Test
public void testDeleteAttachmentException() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).deleteAttachment((String) any(), (String) any(), (String) any());
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(new DeleteBcfAttachmentCommand("networkId", "portid", "tenantid"));
assertFalse(ans.getResult());
verify(_bigswitchBcfApi, times(3)).deleteAttachment((String) any(), (String) any(), (String) any());
}
use of com.cloud.agent.api.BcfAnswer in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testDeleteNetworkApiException.
@Test
public void testDeleteNetworkApiException() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).deleteNetwork((String) any(), (String) any());
DeleteBcfSegmentCommand cmd = new DeleteBcfSegmentCommand("tenantid", "networkid");
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
assertFalse(ans.getResult());
verify(_bigswitchBcfApi, times(3)).deleteNetwork((String) any(), (String) any());
}
Aggregations