Search in sources :

Example 61 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project netvirt by opendaylight.

the class DhcpExternalTunnelManager method chooseDpn.

/**
 * Choose a dpn among the list of elanDpns such that it has lowest count of being the designated dpn.
 * @param tunnelIp The tunnel Ip address
 * @param elanInstanceName The elan instance name
 * @param dpns The data path nodes
 * @return The designated dpn
 */
private BigInteger chooseDpn(IpAddress tunnelIp, String elanInstanceName, List<BigInteger> dpns) {
    BigInteger designatedDpnId = DhcpMConstants.INVALID_DPID;
    if (dpns != null && dpns.size() != 0) {
        List<BigInteger> candidateDpns = DhcpServiceUtils.getDpnsForElan(elanInstanceName, broker);
        candidateDpns.retainAll(dpns);
        LOG.trace("Choosing new dpn for tunnelIp {}, elanInstanceName {}, among elanDpns {}", tunnelIp, elanInstanceName, candidateDpns);
        boolean elanDpnAvailableFlag = true;
        if (candidateDpns.isEmpty()) {
            candidateDpns = dpns;
            elanDpnAvailableFlag = false;
        }
        int size = 0;
        L2GatewayDevice device = getDeviceFromTunnelIp(tunnelIp);
        if (device == null) {
            LOG.trace("Could not find any device for elanInstanceName {} and tunnelIp {}", elanInstanceName, tunnelIp);
            handleUnableToDesignateDpn(tunnelIp, elanInstanceName);
            return designatedDpnId;
        }
        for (BigInteger dpn : candidateDpns) {
            String hwvtepNodeId = device.getHwvtepNodeId();
            if (!elanDpnAvailableFlag) {
                if (!isTunnelConfigured(dpn, hwvtepNodeId)) {
                    LOG.trace("Tunnel is not configured on dpn {} to TOR {}", dpn, hwvtepNodeId);
                    continue;
                }
            } else if (!isTunnelUp(hwvtepNodeId, dpn)) {
                LOG.trace("Tunnel is not up between dpn {} and TOR {}", dpn, hwvtepNodeId);
                continue;
            }
            Set<Pair<IpAddress, String>> tunnelIpElanNameSet = designatedDpnsToTunnelIpElanNameCache.get(dpn);
            if (tunnelIpElanNameSet == null) {
                designatedDpnId = dpn;
                break;
            }
            if (size == 0 || tunnelIpElanNameSet.size() < size) {
                size = tunnelIpElanNameSet.size();
                designatedDpnId = dpn;
            }
        }
        writeDesignatedSwitchForExternalTunnel(designatedDpnId, tunnelIp, elanInstanceName);
        return designatedDpnId;
    }
    handleUnableToDesignateDpn(tunnelIp, elanInstanceName);
    return designatedDpnId;
}
Also used : BigInteger(java.math.BigInteger) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) TerminationPoint(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 62 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project netvirt by opendaylight.

the class DhcpExternalTunnelManager method initilizeCaches.

private void initilizeCaches() {
    LOG.trace("Loading designatedDpnsToTunnelIpElanNameCache");
    InstanceIdentifier<DesignatedSwitchesForExternalTunnels> instanceIdentifier = InstanceIdentifier.builder(DesignatedSwitchesForExternalTunnels.class).build();
    Optional<DesignatedSwitchesForExternalTunnels> designatedSwitchForTunnelOptional = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, instanceIdentifier);
    if (designatedSwitchForTunnelOptional.isPresent()) {
        List<DesignatedSwitchForTunnel> list = designatedSwitchForTunnelOptional.get().getDesignatedSwitchForTunnel();
        for (DesignatedSwitchForTunnel designatedSwitchForTunnel : list) {
            Set<Pair<IpAddress, String>> setOfTunnelIpElanNamePair = designatedDpnsToTunnelIpElanNameCache.get(BigInteger.valueOf(designatedSwitchForTunnel.getDpId()));
            if (setOfTunnelIpElanNamePair == null) {
                setOfTunnelIpElanNamePair = new CopyOnWriteArraySet<>();
            }
            Pair<IpAddress, String> tunnelIpElanNamePair = new ImmutablePair<>(designatedSwitchForTunnel.getTunnelRemoteIpAddress(), designatedSwitchForTunnel.getElanInstanceName());
            setOfTunnelIpElanNamePair.add(tunnelIpElanNamePair);
            designatedDpnsToTunnelIpElanNameCache.put(BigInteger.valueOf(designatedSwitchForTunnel.getDpId()), setOfTunnelIpElanNamePair);
        }
    }
    LOG.trace("Loading vniMacAddressToPortCache");
    InstanceIdentifier<Ports> inst = InstanceIdentifier.builder(Neutron.class).child(Ports.class).build();
    Optional<Ports> optionalPorts = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, inst);
    if (optionalPorts.isPresent()) {
        List<Port> list = optionalPorts.get().getPort();
        for (Port port : list) {
            if (NeutronUtils.isPortVnicTypeNormal(port)) {
                continue;
            }
            String macAddress = port.getMacAddress().getValue();
            Uuid networkId = port.getNetworkId();
            String segmentationId = DhcpServiceUtils.getSegmentationId(networkId, broker);
            if (segmentationId == null) {
                return;
            }
            updateVniMacToPortCache(new BigInteger(segmentationId), macAddress, port);
        }
    }
}
Also used : DesignatedSwitchForTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp.rev160428.designated.switches._for.external.tunnels.DesignatedSwitchForTunnel) SubnetToDhcpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710.subnet.dhcp.port.data.SubnetToDhcpPort) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DesignatedSwitchesForExternalTunnels(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.dhcp.rev160428.DesignatedSwitchesForExternalTunnels) BigInteger(java.math.BigInteger) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 63 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project netvirt by opendaylight.

the class DhcpExternalTunnelManager method getTunnelIpBasedOnElan.

public IpAddress getTunnelIpBasedOnElan(String elanInstanceName, String vmMacAddress) {
    LOG.trace("DhcpExternalTunnelManager getTunnelIpBasedOnElan elanInstanceName {}", elanInstanceName);
    IpAddress tunnelIp = null;
    for (Entry<Pair<IpAddress, String>, Set<String>> entry : availableVMCache.entrySet()) {
        Pair<IpAddress, String> pair = entry.getKey();
        LOG.trace("DhcpExternalTunnelManager getTunnelIpBasedOnElan left {} right {}", pair.getLeft(), pair.getRight());
        if (pair.getRight().trim().equalsIgnoreCase(elanInstanceName.trim())) {
            Set<String> listExistingVmMacAddress = entry.getValue();
            if (listExistingVmMacAddress != null && !listExistingVmMacAddress.isEmpty() && listExistingVmMacAddress.contains(vmMacAddress)) {
                tunnelIp = pair.getLeft();
                break;
            }
        }
    }
    LOG.trace("DhcpExternalTunnelManager getTunnelIpBasedOnElan returned tunnelIP {}", tunnelIp);
    return tunnelIp;
}
Also used : Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) LocatorSet(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.locator.set.attributes.LocatorSet) HashSet(java.util.HashSet) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 64 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project xwiki-platform by xwiki.

the class MailStorageScriptServiceTest method resendAsynchronouslySeveralMessages.

@Test
public void resendAsynchronouslySeveralMessages() throws Exception {
    Map filterMap = Collections.singletonMap("state", "prepare_%");
    MailStatus status1 = new MailStatus();
    status1.setBatchId("batch1");
    status1.setMessageId("message1");
    MailStatus status2 = new MailStatus();
    status2.setBatchId("batch2");
    status2.setMessageId("message2");
    MailStatusResult statusResult1 = mock(MailStatusResult.class, "status1");
    when(statusResult1.getTotalMailCount()).thenReturn(1L);
    MailStatusResult statusResult2 = mock(MailStatusResult.class, "status2");
    when(statusResult2.getTotalMailCount()).thenReturn(2L);
    List<Pair<MailStatus, MailStatusResult>> results = new ArrayList<>();
    results.add(new ImmutablePair<>(status1, statusResult1));
    results.add(new ImmutablePair<>(status2, statusResult2));
    MailResender resender = this.mocker.getInstance(MailResender.class, "database");
    when(resender.resendAsynchronously(filterMap, 5, 10)).thenReturn(results);
    List<ScriptMailResult> scriptResults = this.mocker.getComponentUnderTest().resendAsynchronously(filterMap, 5, 10);
    assertEquals(2, scriptResults.size());
    assertEquals("batch1", scriptResults.get(0).getBatchId());
    assertEquals(1L, scriptResults.get(0).getStatusResult().getTotalMailCount());
    assertEquals("batch2", scriptResults.get(1).getBatchId());
    assertEquals(2L, scriptResults.get(1).getStatusResult().getTotalMailCount());
}
Also used : ArrayList(java.util.ArrayList) ScriptMailResult(org.xwiki.mail.script.ScriptMailResult) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Test(org.junit.Test)

Example 65 with Pair

use of org.apache.beam.repackaged.core.org.apache.commons.lang3.tuple.Pair in project xwiki-platform by xwiki.

the class DatabaseMailResender method resendAsynchronously.

@Override
public List<Pair<MailStatus, MailStatusResult>> resendAsynchronously(Map<String, Object> filterMap, int offset, int count) throws MailStoreException {
    List<Pair<MailStatus, MailStatusResult>> results = new ArrayList<>();
    List<MailStatus> statuses = this.store.load(filterMap, offset, count, null, true);
    for (MailStatus status : statuses) {
        try {
            results.add(new ImmutablePair<>(status, resendAsynchronously(status.getBatchId(), status.getMessageId())));
        } catch (MailStoreException e) {
            // Failed to load the message from the content store and thus the mail couldn't be resent
            // Log a warning but continue to try to send the other mails...
            this.logger.warn("Failed to load mail content for batchId [{}], messageId [{}]", status.getBatchId(), status.getMessageId());
        }
    }
    return results;
}
Also used : MailStoreException(org.xwiki.mail.MailStoreException) ArrayList(java.util.ArrayList) MailStatus(org.xwiki.mail.MailStatus) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

Pair (org.apache.commons.lang3.tuple.Pair)685 ArrayList (java.util.ArrayList)209 List (java.util.List)154 Test (org.junit.Test)150 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)142 HashMap (java.util.HashMap)123 Collectors (java.util.stream.Collectors)123 Map (java.util.Map)112 Message (com.microsoft.azure.sdk.iot.device.Message)71 IOException (java.io.IOException)70 MutablePair (org.apache.commons.lang3.tuple.MutablePair)64 java.util (java.util)55 IotHubTransportMessage (com.microsoft.azure.sdk.iot.device.transport.IotHubTransportMessage)52 Set (java.util.Set)49 StringUtils (org.apache.commons.lang3.StringUtils)48 File (java.io.File)46 Optional (java.util.Optional)45 Arrays (java.util.Arrays)44 HashSet (java.util.HashSet)40 Test (org.junit.jupiter.api.Test)39