Search in sources :

Example 1 with ConfigureSharedNetworkUuidAnswer

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

the class NiciraNvpElementTest method implementSharedNetworkUuidVlanIdTest.

@Test
public void implementSharedNetworkUuidVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    // SHARED NETWORKS CASE 1: LOGICAL ROUTER'S UUID AS 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 1
    when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(true);
    when(network.getCidr()).thenReturn(NETWORK_CIDR);
    when(network.getGateway()).thenReturn(NETWORK_GATEWAY);
    NiciraNvpRouterMappingVO mapping = mock(NiciraNvpRouterMappingVO.class);
    when(mapping.getLogicalRouterUuid()).thenReturn("xxxx-xxxx-xxxx");
    when(niciraNvpRouterMappingDao.findByNetworkId(NETWORK_ID)).thenReturn(mapping);
    final ConfigureSharedNetworkUuidAnswer answer = mock(ConfigureSharedNetworkUuidAnswer.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) ConfigureSharedNetworkUuidAnswer(com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) Domain(com.cloud.domain.Domain) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Example 2 with ConfigureSharedNetworkUuidAnswer

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

the class NiciraNvpConfigureSharedNetworkUuidCommandWrapper method execute.

@Override
public Answer execute(ConfigureSharedNetworkUuidCommand command, NiciraNvpResource niciraNvpResource) {
    final String logicalRouterUuid = command.getLogicalRouterUuid();
    final String logicalSwitchUuid = command.getLogicalSwitchUuid();
    final String portIpAddress = command.getPortIpAddress();
    final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
    tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
    final long networkId = command.getNetworkId();
    final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
    s_logger.debug("Attaching Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId);
    // Step 1: Get lSwitch displayName
    s_logger.info("Looking for Logical Switch " + logicalSwitchUuid + " display name");
    String logicalSwitchDisplayName;
    try {
        List<LogicalSwitch> lSwitchList = niciraNvpApi.findLogicalSwitch(logicalSwitchUuid);
        if (lSwitchList != null) {
            if (lSwitchList.size() == 1) {
                logicalSwitchDisplayName = lSwitchList.get(0).getDisplayName();
            } else {
                s_logger.error("More than one Logical Switch found with uuid " + logicalSwitchUuid);
                throw new CloudRuntimeException("More than one Logical Switch found with uuid=" + logicalSwitchUuid);
            }
        } else {
            s_logger.error("Logical Switch " + logicalSwitchUuid + " not found");
            throw new CloudRuntimeException("Logical Switch " + logicalSwitchUuid + " not found");
        }
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Logical Switch " + logicalSwitchUuid + " not found, retrying");
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, ConfigureSharedNetworkUuidAnswer.class, e);
    } catch (CloudRuntimeException e) {
        s_logger.info("Shared network UUID vlan id failed due to : " + e.getMessage());
        return new ConfigureSharedNetworkUuidAnswer(command, false, e.getMessage());
    }
    s_logger.info("Found display name " + logicalSwitchDisplayName + " for Logical Switch " + logicalSwitchUuid);
    // Step 2: Create lRouterPort
    s_logger.debug("Creating Logical Router Port in Logical Router " + logicalRouterUuid);
    LogicalRouterPort lRouterPort = null;
    try {
        lRouterPort = new LogicalRouterPort();
        lRouterPort.setAdminStatusEnabled(true);
        lRouterPort.setDisplayName(niciraNvpResource.truncate(logicalSwitchDisplayName + "-uplink", NAME_MAX_LEN));
        lRouterPort.setTags(tags);
        final List<String> ipAddresses = new ArrayList<String>();
        ipAddresses.add(portIpAddress);
        lRouterPort.setIpAddresses(ipAddresses);
        lRouterPort = niciraNvpApi.createLogicalRouterPort(logicalRouterUuid, lRouterPort);
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not create Logical Router Port on Logical Router " + logicalRouterUuid + " due to: " + e.getMessage() + ", retrying");
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully created in Logical Router " + logicalRouterUuid);
    // Step 3: Create lSwitchPort
    s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")");
    LogicalSwitchPort lSwitchPort = null;
    try {
        lSwitchPort = new LogicalSwitchPort(niciraNvpResource.truncate("lrouter-uplink", NAME_MAX_LEN), tags, true);
        lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort);
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")  due to: " + e.getMessage());
        cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")");
    // Step 4: Attach lRouterPort to lSwitchPort with a PatchAttachment
    s_logger.debug("Attaching Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment");
    try {
        niciraNvpApi.updateLogicalRouterPortAttachment(logicalRouterUuid, lRouterPort.getUuid(), new PatchAttachment(lSwitchPort.getUuid()));
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not attach Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying");
        cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
        cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully attached to to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment");
    // Step 5: Attach lSwitchPort to lRouterPort with a PatchAttachment
    s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment");
    try {
        niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(), new PatchAttachment(lRouterPort.getUuid()));
    } catch (NiciraNvpApiException e) {
        s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying");
        cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
        cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
        return handleException(e, command, niciraNvpResource);
    }
    s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached to to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment");
    s_logger.info("Successfully attached Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId);
    return new ConfigureSharedNetworkUuidAnswer(command, true, "OK");
}
Also used : ConfigureSharedNetworkUuidAnswer(com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer) LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) ArrayList(java.util.ArrayList) PatchAttachment(com.cloud.network.nicira.PatchAttachment) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpTag(com.cloud.network.nicira.NiciraNvpTag) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) LogicalSwitchPort(com.cloud.network.nicira.LogicalSwitchPort)

Example 3 with ConfigureSharedNetworkUuidAnswer

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

the class NiciraNvpConfigureSharedNetworkUuidCommandWrapper method handleException.

private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkUuidCommand command, NiciraNvpResource niciraNvpResource) {
    if (HttpStatusCodeHelper.isConflict(e.getErrorCode())) {
        s_logger.warn("There's been a conflict in NSX side, aborting implementation");
        return new ConfigureSharedNetworkUuidAnswer(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, ConfigureSharedNetworkUuidAnswer.class, e);
    }
}
Also used : ConfigureSharedNetworkUuidAnswer(com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility)

Example 4 with ConfigureSharedNetworkUuidAnswer

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

the class NiciraNvpElement method sharedNetworkSupportUUIDVlanId.

private boolean sharedNetworkSupportUUIDVlanId(Network network, String lSwitchUuid, String ownerName, HostVO niciraNvpHost) {
    String networkCidr = network.getCidr();
    String vlanGateway = network.getGateway();
    String portIpAddress = createLogicalRouterPortIpAddress(networkCidr, vlanGateway);
    NiciraNvpRouterMappingVO mapRouterNetwork = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
    String lRouterUuid = mapRouterNetwork.getLogicalRouterUuid();
    ConfigureSharedNetworkUuidCommand cmd = new ConfigureSharedNetworkUuidCommand(lRouterUuid, lSwitchUuid, portIpAddress, ownerName, network.getId());
    ConfigureSharedNetworkUuidAnswer answer = (ConfigureSharedNetworkUuidAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    if (answer.getResult() == false) {
        s_logger.error("Failed to configure Logical Router for Shared network " + network.getDisplayText());
        return false;
    }
    return true;
}
Also used : ConfigureSharedNetworkUuidAnswer(com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) ConfigureSharedNetworkUuidCommand(com.cloud.agent.api.ConfigureSharedNetworkUuidCommand)

Aggregations

ConfigureSharedNetworkUuidAnswer (com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer)4 NiciraNvpRouterMappingVO (com.cloud.network.NiciraNvpRouterMappingVO)2 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)2 ConfigureSharedNetworkUuidCommand (com.cloud.agent.api.ConfigureSharedNetworkUuidCommand)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 LogicalRouterPort (com.cloud.network.nicira.LogicalRouterPort)1 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)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 PatchAttachment (com.cloud.network.nicira.PatchAttachment)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