Search in sources :

Example 26 with BcfAnswer

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());
}
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 27 with BcfAnswer

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

Example 28 with BcfAnswer

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());
}
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 29 with BcfAnswer

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;
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) CacheBcfTopologyCommand(com.cloud.agent.api.CacheBcfTopologyCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO)

Example 30 with BcfAnswer

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);
            }
        }
    }
}
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)33 BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)29 Test (org.junit.Test)21 UpdateBcfRouterCommand (com.cloud.agent.api.UpdateBcfRouterCommand)5 AttachmentData (com.cloud.network.bigswitch.AttachmentData)5 RouterData (com.cloud.network.bigswitch.RouterData)5 SyncBcfTopologyCommand (com.cloud.agent.api.SyncBcfTopologyCommand)3 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 AclData (com.cloud.network.bigswitch.AclData)2 FloatingIpData (com.cloud.network.bigswitch.FloatingIpData)2 TopologyData (com.cloud.network.bigswitch.TopologyData)2 CacheBcfTopologyCommand (com.cloud.agent.api.CacheBcfTopologyCommand)1