Search in sources :

Example 1 with AttachmentData

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

the class BigSwitchBcfResource method executeRequest.

private Answer executeRequest(UpdateBcfAttachmentCommand cmd, int numRetries) {
    AttachmentData attachment = new AttachmentData();
    attachment.getAttachment().setId(cmd.getAttachmentId());
    attachment.getAttachment().setTenantName(cmd.getTenantId());
    try {
        String hash = _bigswitchBcfApi.modifyAttachment(cmd.getTenantId(), cmd.getNetworkId(), attachment);
        return new BcfAnswer(cmd, true, "Network attachment  " + cmd.getAttachmentId() + " updated", hash);
    } catch (BigSwitchBcfApiException e) {
        if (e.is_topologySyncRequested()) {
            cmd.setTopologySyncRequested(true);
            return new BcfAnswer(cmd, true, "Network attachment  " + cmd.getAttachmentId() + " updated; 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) AttachmentData(com.cloud.network.bigswitch.AttachmentData)

Example 2 with AttachmentData

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

the class BigSwitchBcfResource method executeRequest.

private Answer executeRequest(CreateBcfAttachmentCommand cmd, int numRetries) {
    AttachmentData attachment = new AttachmentData();
    attachment.getAttachment().setId(cmd.getNicId());
    attachment.getAttachment().setHostId(cmd.getPortId());
    attachment.getAttachment().setTenantName(cmd.getTenantName());
    attachment.getAttachment().setVlan(cmd.getVlan());
    attachment.getAttachment().addIpv4(cmd.getIpv4());
    attachment.getAttachment().setMac(cmd.getMac());
    try {
        String hash = _bigswitchBcfApi.createAttachment(cmd.getTenantId(), cmd.getNetworkId(), attachment);
        return new BcfAnswer(cmd, true, "network attachment " + cmd.getPortId() + " created", hash);
    } catch (BigSwitchBcfApiException e) {
        if (e.is_topologySyncRequested()) {
            cmd.setTopologySyncRequested(true);
            return new BcfAnswer(cmd, true, "network attachment " + cmd.getPortId() + " 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) AttachmentData(com.cloud.network.bigswitch.AttachmentData)

Example 3 with AttachmentData

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

the class BigSwitchBcfResourceTest method testCreateAttachmentRetryOnce.

@Test
public void testCreateAttachmentRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    AttachmentData attachmentData = mock(AttachmentData.class);
    AttachmentData.Attachment attachment = mock(AttachmentData.Attachment.class);
    when(attachmentData.getAttachment()).thenReturn(attachment);
    when(attachment.getId()).thenReturn("eeee");
    when(_bigswitchBcfApi.createAttachment((String) any(), (String) any(), (AttachmentData) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
    CreateBcfAttachmentCommand cmd = new CreateBcfAttachmentCommand("tenantid", "tenantname", "networkid", "portid", "nicId", 100, "1.2.3.4", "aa:bb:cc:dd:ee:ff");
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertTrue(ans.getResult());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) CreateBcfAttachmentCommand(com.cloud.agent.api.CreateBcfAttachmentCommand) AttachmentData(com.cloud.network.bigswitch.AttachmentData) Test(org.junit.Test)

Example 4 with AttachmentData

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

the class BigSwitchBcfResourceTest method testCreateAttachmentApiException.

@Test
public void testCreateAttachmentApiException() throws ConfigurationException, BigSwitchBcfApiException {
    _resource.configure("BigSwitchBcfResource", _parameters);
    AttachmentData attachmentData = mock(AttachmentData.class);
    AttachmentData.Attachment attachment = mock(AttachmentData.Attachment.class);
    when(attachmentData.getAttachment()).thenReturn(attachment);
    when(attachment.getId()).thenReturn("eeee");
    doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).createAttachment((String) any(), (String) any(), (AttachmentData) any());
    CreateBcfAttachmentCommand cmd = new CreateBcfAttachmentCommand("tenantid", "tenantname", "networkid", "portid", "nicId", 100, "1.2.3.4", "aa:bb:cc:dd:ee:ff");
    BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
    assertFalse(ans.getResult());
    verify(_bigswitchBcfApi, times(3)).createAttachment((String) any(), (String) any(), (AttachmentData) any());
}
Also used : BcfAnswer(com.cloud.agent.api.BcfAnswer) BigSwitchBcfApiException(com.cloud.network.bigswitch.BigSwitchBcfApiException) CreateBcfAttachmentCommand(com.cloud.agent.api.CreateBcfAttachmentCommand) AttachmentData(com.cloud.network.bigswitch.AttachmentData) Test(org.junit.Test)

Example 5 with AttachmentData

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

Aggregations

BcfAnswer (com.cloud.agent.api.BcfAnswer)5 AttachmentData (com.cloud.network.bigswitch.AttachmentData)5 BigSwitchBcfApiException (com.cloud.network.bigswitch.BigSwitchBcfApiException)5 Test (org.junit.Test)3 CreateBcfAttachmentCommand (com.cloud.agent.api.CreateBcfAttachmentCommand)2 UpdateBcfAttachmentCommand (com.cloud.agent.api.UpdateBcfAttachmentCommand)1