Search in sources :

Example 26 with BigSwitchBcfApiException

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

Example 27 with BigSwitchBcfApiException

use of com.cloud.network.bigswitch.BigSwitchBcfApiException 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)

Example 28 with BigSwitchBcfApiException

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

Example 29 with BigSwitchBcfApiException

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

Example 30 with BigSwitchBcfApiException

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

Aggregations

BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)30 BcfAnswer (com.cloud.agent.api.BcfAnswer)29 Test (org.junit.Test)22 AttachmentData (com.cloud.network.bigswitch.AttachmentData)5 RouterData (com.cloud.network.bigswitch.RouterData)5 UpdateBcfRouterCommand (com.cloud.agent.api.UpdateBcfRouterCommand)4 NetworkData (com.cloud.network.bigswitch.NetworkData)3 CreateBcfAttachmentCommand (com.cloud.agent.api.CreateBcfAttachmentCommand)2 CreateBcfRouterCommand (com.cloud.agent.api.CreateBcfRouterCommand)2 CreateBcfSegmentCommand (com.cloud.agent.api.CreateBcfSegmentCommand)2 CreateBcfStaticNatCommand (com.cloud.agent.api.CreateBcfStaticNatCommand)2 DeleteBcfAttachmentCommand (com.cloud.agent.api.DeleteBcfAttachmentCommand)2 DeleteBcfSegmentCommand (com.cloud.agent.api.DeleteBcfSegmentCommand)2 DeleteBcfStaticNatCommand (com.cloud.agent.api.DeleteBcfStaticNatCommand)2 UpdateBcfAttachmentCommand (com.cloud.agent.api.UpdateBcfAttachmentCommand)2 FloatingIpData (com.cloud.network.bigswitch.FloatingIpData)2 TopologyData (com.cloud.network.bigswitch.TopologyData)2 PingCommand (com.cloud.agent.api.PingCommand)1 SyncBcfTopologyCommand (com.cloud.agent.api.SyncBcfTopologyCommand)1 AclData (com.cloud.network.bigswitch.AclData)1