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;
}
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);
}
}
}
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;
}
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());
}
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;
}
Aggregations