Search in sources :

Example 1 with RouterData

use of com.cloud.network.bigswitch.RouterData 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");
    }
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) AclData(com.cloud.network.bigswitch.AclData) ArrayList(java.util.ArrayList) RouterData(com.cloud.network.bigswitch.RouterData)

Example 2 with RouterData

use of com.cloud.network.bigswitch.RouterData in project cloudstack by apache.

the class BigSwitchBcfResourceTest method testCreateRouterRetryOnce.

@Test
public void testCreateRouterRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    when(_bigswitchBcfApi.createRouter((String) any(), (RouterData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
    CreateBcfRouterCommand cmd = new CreateBcfRouterCommand("tenantid");
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertTrue(ans.getResult());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) CreateBcfRouterCommand(com.cloud.agent.api.CreateBcfRouterCommand) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) RouterData(com.cloud.network.bigswitch.RouterData) Test(org.junit.Test)

Example 3 with RouterData

use of com.cloud.network.bigswitch.RouterData 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());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) RouterData(com.cloud.network.bigswitch.RouterData) UpdateBcfRouterCommand(com.cloud.agent.api.UpdateBcfRouterCommand) Test(org.junit.Test)

Example 4 with RouterData

use of com.cloud.network.bigswitch.RouterData 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());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) RouterData(com.cloud.network.bigswitch.RouterData) UpdateBcfRouterCommand(com.cloud.agent.api.UpdateBcfRouterCommand) Test(org.junit.Test)

Example 5 with RouterData

use of com.cloud.network.bigswitch.RouterData 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);
            }
        }
    }
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) RouterData(com.cloud.network.bigswitch.RouterData)

Aggregations

BcfAnswer (com.cloud.agent.api.BcfAnswer)5 BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)5 RouterData (com.cloud.network.bigswitch.RouterData)5 Test (org.junit.Test)3 UpdateBcfRouterCommand (com.cloud.agent.api.UpdateBcfRouterCommand)2 CreateBcfRouterCommand (com.cloud.agent.api.CreateBcfRouterCommand)1 AclData (com.cloud.network.bigswitch.AclData)1 ArrayList (java.util.ArrayList)1