Search in sources :

Example 1 with NetworkData

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

the class BigSwitchBcfResource method executeRequest.

private Answer executeRequest(CreateBcfSegmentCommand cmd, int numRetries) {
    NetworkData network = new NetworkData();
    network.getNetwork().setTenantId(cmd.getTenantId());
    network.getNetwork().setTenantName(cmd.getTenantName());
    network.getNetwork().setId(cmd.getNetworkId());
    network.getNetwork().setName(truncate("segment-cloudstack-" + cmd.getNetworkName(), 64));
    network.getNetwork().setVlan(cmd.getVlan());
    try {
        String hash = _bigswitchBcfApi.createNetwork(network);
        return new BcfAnswer(cmd, true, "Segment " + network.getNetwork().getId() + " created", hash);
    } catch (BigSwitchBcfApiException e) {
        if (e.is_topologySyncRequested()) {
            cmd.setTopologySyncRequested(true);
            return new BcfAnswer(cmd, true, "Segment " + network.getNetwork().getId() + " 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) NetworkData(com.cloud.network.bigswitch.NetworkData)

Example 2 with NetworkData

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

the class BigSwitchBcfResourceTest method testCreateNetworkRetryOnce.

@Test
public void testCreateNetworkRetryOnce() 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");
    when(_bigswitchBcfApi.createNetwork((NetworkData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
    CreateBcfSegmentCommand cmd = new CreateBcfSegmentCommand("tenantid", "tenantname", (String) _parameters.get("guid"), "networkName", 0);
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertTrue(ans.getResult());
}
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 3 with NetworkData

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

Aggregations

BcfAnswer (com.cloud.agent.api.BcfAnswer)3 BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)3 NetworkData (com.cloud.network.bigswitch.NetworkData)3 CreateBcfSegmentCommand (com.cloud.agent.api.CreateBcfSegmentCommand)2 Test (org.junit.Test)2