Search in sources :

Example 1 with ConfigureSharedNetworkVlanIdAnswer

use of com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer in project cloudstack by apache.

the class NiciraNvpElementTest method implementSharedNetworkNumericalVlanIdTest.

@Test
public void implementSharedNetworkNumericalVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    // SHARED NETWORKS CASE 2: NUMERICAL VLAN ID
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getGuestType()).thenReturn(GuestType.Shared);
    when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
    when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
    HostVO niciraNvpHost = mock(HostVO.class);
    when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
    when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Shared);
    final DeployDestination dest = mock(DeployDestination.class);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    //SHARED NETWORKS CASE 2
    when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(false);
    VlanVO vlanVO = mock(VlanVO.class);
    when(vlanVO.getVlanTag()).thenReturn("111");
    when(vlanDao.listVlansByNetworkId(NETWORK_ID)).thenReturn(Arrays.asList(new VlanVO[] { vlanVO }));
    when(niciraNvpHost.getDetail("l2gatewayserviceuuid")).thenReturn("bbbb-bbbb-bbbb");
    final ConfigureSharedNetworkVlanIdAnswer answer = mock(ConfigureSharedNetworkVlanIdAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command) any())).thenReturn(answer);
    assertTrue(element.implement(network, offering, dest, context));
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) Domain(com.cloud.domain.Domain) VlanVO(com.cloud.dc.VlanVO) URI(java.net.URI) ConfigureSharedNetworkVlanIdAnswer(com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 2 with ConfigureSharedNetworkVlanIdAnswer

use of com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer in project cloudstack by apache.

the class NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper method execute.

@Override
public Answer execute(ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) {
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final String l2GatewayServiceUuid = command.getL2GatewayServiceUuid();
    long vlanId = command.getVlanId();
    final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
    tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
    final long networkId = command.getNetworkId();
    s_logger.debug("Connecting Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + " network " + networkId);
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid);
    LogicalSwitchPort lSwitchPort = null;
    try {
        lSwitchPort = new LogicalSwitchPort();
        lSwitchPort.setAdminStatusEnabled(true);
        lSwitchPort.setDisplayName(niciraNvpResource.truncate(networkId + "-l2Gateway-port", NAME_MAX_LEN));
        lSwitchPort.setTags(tags);
        lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort);
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " due to: " + e.getMessage() + ", retrying");
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid);
    s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
    try {
        final L2GatewayAttachment attachment = new L2GatewayAttachment(l2GatewayServiceUuid);
        if (command.getVlanId() != 0) {
            attachment.setVlanId(command.getVlanId());
        }
        niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(), attachment);
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", errorCode: " + e.getErrorCode());
        cleanup(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
    s_logger.debug("Successfully connected Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + ", network " + networkId + ", through Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ")");
    return new ConfigureSharedNetworkVlanIdAnswer(command, true, "OK");
}
Also used : NiciraNvpTag(com.cloud.network.nicira.NiciraNvpTag) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) ArrayList(java.util.ArrayList) L2GatewayAttachment(com.cloud.network.nicira.L2GatewayAttachment) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) ConfigureSharedNetworkVlanIdAnswer(com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort)

Example 3 with ConfigureSharedNetworkVlanIdAnswer

use of com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer in project cloudstack by apache.

the class NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper method handleException.

private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) {
    if (HttpStatusCodeHelper.isConflict(e.getErrorCode())) {
        s_logger.warn("There's been a conflict in NSX side, aborting implementation");
        return new ConfigureSharedNetworkVlanIdAnswer(command, false, "FAILED: There's been a conflict in NSX side");
    } else {
        s_logger.warn("Error code: " + e.getErrorCode() + ", retrying");
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, ConfigureSharedNetworkVlanIdAnswer.class, e);
    }
}
Also used : CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) ConfigureSharedNetworkVlanIdAnswer(com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer)

Example 4 with ConfigureSharedNetworkVlanIdAnswer

use of com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer in project cloudstack by apache.

the class NiciraNvpElement method sharedNetworkSupportNumericalVlanId.

private boolean sharedNetworkSupportNumericalVlanId(Network network, String lSwitchUuid, String ownerName, HostVO niciraNvpHost) {
    List<VlanVO> networkVlans = vlanDao.listVlansByNetworkId(network.getId());
    if (networkVlans.size() == 1) {
        for (VlanVO vlanVO : networkVlans) {
            long vlanId = Long.parseLong(vlanVO.getVlanTag());
            String l2GatewayServiceUuid = niciraNvpHost.getDetail("l2gatewayserviceuuid");
            if (l2GatewayServiceUuid == null) {
                throw new CloudRuntimeException("No L2 Gateway Service Uuid found on " + niciraNvpHost.getName());
            }
            ConfigureSharedNetworkVlanIdCommand cmd = new ConfigureSharedNetworkVlanIdCommand(lSwitchUuid, l2GatewayServiceUuid, vlanId, ownerName, network.getId());
            ConfigureSharedNetworkVlanIdAnswer answer = (ConfigureSharedNetworkVlanIdAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
            if (answer.getResult() == false) {
                s_logger.error("Failed to configure Shared network " + network.getDisplayText());
                return false;
            }
        }
    }
    return true;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigureSharedNetworkVlanIdCommand(com.cloud.agent.api.ConfigureSharedNetworkVlanIdCommand) VlanVO(com.cloud.dc.VlanVO) ConfigureSharedNetworkVlanIdAnswer(com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer)

Aggregations

ConfigureSharedNetworkVlanIdAnswer (com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer)4 VlanVO (com.cloud.dc.VlanVO)2 ConfigureSharedNetworkVlanIdCommand (com.cloud.agent.api.ConfigureSharedNetworkVlanIdCommand)1 DeployDestination (com.cloud.deploy.DeployDestination)1 Domain (com.cloud.domain.Domain)1 HostVO (com.cloud.host.HostVO)1 Network (com.cloud.network.Network)1 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)1 L2GatewayAttachment (com.cloud.network.nicira.L2GatewayAttachment)1 LogicalSwitchPort (com.cloud.network.nicira.LogicalSwitchPort)1 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)1 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)1 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)1 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)1 NetworkOffering (com.cloud.offering.NetworkOffering)1 Account (com.cloud.user.Account)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ReservationContext (com.cloud.vm.ReservationContext)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1