@Test public void lifecycleTest() { AddressEndpointBuilder child = getAddressEndpointBuilder().setKey(MAC_KEY_23_45); setParentEndpoints(child, IP_KEY_1_22); AddressEndpointBuilder firstParent = getAddressEndpointBuilder().setKey(IP_KEY_1_22); setChildEndpoints(firstParent, MAC_KEY_23_45); submitEndpointsToDatastore(child.build(), firstParent.build()); assertEndpointsInDatastore(child.getKey(), firstParent.getKey()); locationProvider.createLocationForVppEndpoint(vppEndpointBuilder(MAC_KEY_23_45_VPP, NODE_1, INTF_NAME)); List<ProviderAddressEndpointLocation> locations = readLocations(); Assert.assertEquals(1, locations.size()); ProviderAddressEndpointLocation location = locations.get(0); Assert.assertTrue(location.getKey().equals(getLocationKey(IP_KEY_1_22))); assertNodeConnector(location.getAbsoluteLocation(), INTF_NAME); assertMountPoint(location.getAbsoluteLocation(), NODE_1); AddressEndpointBuilder secondParent = getAddressEndpointBuilder().setKey(IP_KEY_2_22); setChildEndpoints(secondParent, MAC_KEY_23_45); setParentEndpoints(child, IP_KEY_1_22, IP_KEY_2_22); submitEndpointsToDatastore(child.build(), secondParent.build()); assertEndpointsInDatastore(child.getKey(), secondParent.getKey()); locations = readLocations(); Assert.assertEquals(2, locations.size()); locations.forEach(loc -> { Assert.assertTrue(loc.getKey().equals(getLocationKey(IP_KEY_1_22)) || loc.getKey().equals(getLocationKey(IP_KEY_2_22))); assertNodeConnector(loc.getAbsoluteLocation(), INTF_NAME); assertMountPoint(loc.getAbsoluteLocation(), NODE_1); }); setParentEndpoints(child, IP_KEY_1_22); WriteTransaction wTx = dataBroker.newWriteOnlyTransaction(); putEndpoints(wTx, child.build()); deleteEndpoints(wTx, secondParent.getKey()); DataStoreHelper.submitToDs(wTx); locations = readLocations(); Assert.assertEquals(1, locations.size()); locations.forEach(loc -> { Assert.assertTrue(loc.getKey().equals(getLocationKey(IP_KEY_1_22))); assertNodeConnector(loc.getAbsoluteLocation(), INTF_NAME); assertMountPoint(loc.getAbsoluteLocation(), NODE_1); }); deleteEndpointsFromDatastore(child.getKey(), firstParent.getKey()); locations = readLocations(); Assert.assertTrue(locations == null || locations.isEmpty()); }
@Override public ListenableFuture<Void> createLocationForVppEndpoint(VppEndpoint vppEndpoint) { try { THREAD_LOCK.lock(); vppEndpoints.put(vppEndpoint.getKey(), vppEndpoint); Collection<AddressEndpoint> cachedAddrEp = pendingAddrEndpoints.row(vppEndpoint.getKey()).values(); if (cachedAddrEp == null || cachedAddrEp.isEmpty()) { return Futures.immediateFuture(null); } ReadWriteTransaction rwTx = syncedChain.newReadWriteTransaction(); List<AddressEndpoint> result = cachedAddrEp.stream().filter(ep -> canCreateLocation(ep)).collect(Collectors.toList()); result.forEach(ep -> syncEndpointLocation(rwTx, ep)); result.forEach(ep -> pendingAddrEndpoints.remove(vppEndpoint.getKey(), ep.getKey())); syncedChain.submitNow(rwTx); } catch (Exception e) { LOG.error("Failed to resolve location for vpp endpoint {}. {}", vppEndpoint.getKey(), e); } finally { THREAD_LOCK.unlock(); } return Futures.immediateFuture(null); }
VppEndpointLocationProvider implements ClusteredDataTreeChangeListener<AddressEndpoint>, VPPLocationProvider, AutoCloseable { @Override public ListenableFuture<Void> createLocationForVppEndpoint(VppEndpoint vppEndpoint) { try { THREAD_LOCK.lock(); vppEndpoints.put(vppEndpoint.getKey(), vppEndpoint); Collection<AddressEndpoint> cachedAddrEp = pendingAddrEndpoints.row(vppEndpoint.getKey()).values(); if (cachedAddrEp == null || cachedAddrEp.isEmpty()) { return Futures.immediateFuture(null); } ReadWriteTransaction rwTx = syncedChain.newReadWriteTransaction(); List<AddressEndpoint> result = cachedAddrEp.stream().filter(ep -> canCreateLocation(ep)).collect(Collectors.toList()); result.forEach(ep -> syncEndpointLocation(rwTx, ep)); result.forEach(ep -> pendingAddrEndpoints.remove(vppEndpoint.getKey(), ep.getKey())); syncedChain.submitNow(rwTx); } catch (Exception e) { LOG.error("Failed to resolve location for vpp endpoint {}. {}", vppEndpoint.getKey(), e); } finally { THREAD_LOCK.unlock(); } return Futures.immediateFuture(null); } }
VppEndpointLocationProvider implements ClusteredDataTreeChangeListener<AddressEndpoint>, VPPLocationProvider, AutoCloseable { @Override public ListenableFuture<Void> createLocationForVppEndpoint(VppEndpoint vppEndpoint) { try { THREAD_LOCK.lock(); vppEndpoints.put(vppEndpoint.getKey(), vppEndpoint); Collection<AddressEndpoint> cachedAddrEp = pendingAddrEndpoints.row(vppEndpoint.getKey()).values(); if (cachedAddrEp == null || cachedAddrEp.isEmpty()) { return Futures.immediateFuture(null); } ReadWriteTransaction rwTx = syncedChain.newReadWriteTransaction(); List<AddressEndpoint> result = cachedAddrEp.stream().filter(ep -> canCreateLocation(ep)).collect(Collectors.toList()); result.forEach(ep -> syncEndpointLocation(rwTx, ep)); result.forEach(ep -> pendingAddrEndpoints.remove(vppEndpoint.getKey(), ep.getKey())); syncedChain.submitNow(rwTx); } catch (Exception e) { LOG.error("Failed to resolve location for vpp endpoint {}. {}", vppEndpoint.getKey(), e); } finally { THREAD_LOCK.unlock(); } return Futures.immediateFuture(null); } VppEndpointLocationProvider(DataBroker dataProvider); }
VppEndpointLocationProvider implements ClusteredDataTreeChangeListener<AddressEndpoint>, VPPLocationProvider, AutoCloseable { @Override public ListenableFuture<Void> createLocationForVppEndpoint(VppEndpoint vppEndpoint) { try { THREAD_LOCK.lock(); vppEndpoints.put(vppEndpoint.getKey(), vppEndpoint); Collection<AddressEndpoint> cachedAddrEp = pendingAddrEndpoints.row(vppEndpoint.getKey()).values(); if (cachedAddrEp == null || cachedAddrEp.isEmpty()) { return Futures.immediateFuture(null); } ReadWriteTransaction rwTx = syncedChain.newReadWriteTransaction(); List<AddressEndpoint> result = cachedAddrEp.stream().filter(ep -> canCreateLocation(ep)).collect(Collectors.toList()); result.forEach(ep -> syncEndpointLocation(rwTx, ep)); result.forEach(ep -> pendingAddrEndpoints.remove(vppEndpoint.getKey(), ep.getKey())); syncedChain.submitNow(rwTx); } catch (Exception e) { LOG.error("Failed to resolve location for vpp endpoint {}. {}", vppEndpoint.getKey(), e); } finally { THREAD_LOCK.unlock(); } return Futures.immediateFuture(null); } VppEndpointLocationProvider(DataBroker dataProvider); @Override void onDataTreeChanged(Collection<DataTreeModification<AddressEndpoint>> change); @Override ListenableFuture<Void> createLocationForVppEndpoint(VppEndpoint vppEndpoint); @Override ListenableFuture<Void> deleteLocationForVppEndpoint(VppEndpoint vppEndpoint); @Override ListenableFuture<Void> replaceLocationForEndpoint(@Nonnull ExternalLocationCase location,
            @Nonnull AddressEndpointWithLocationKey addrEpWithLocKey); @Override void close(); }
VppEndpointLocationProvider implements ClusteredDataTreeChangeListener<AddressEndpoint>, VPPLocationProvider, AutoCloseable { @Override public ListenableFuture<Void> createLocationForVppEndpoint(VppEndpoint vppEndpoint) { try { THREAD_LOCK.lock(); vppEndpoints.put(vppEndpoint.getKey(), vppEndpoint); Collection<AddressEndpoint> cachedAddrEp = pendingAddrEndpoints.row(vppEndpoint.getKey()).values(); if (cachedAddrEp == null || cachedAddrEp.isEmpty()) { return Futures.immediateFuture(null); } ReadWriteTransaction rwTx = syncedChain.newReadWriteTransaction(); List<AddressEndpoint> result = cachedAddrEp.stream().filter(ep -> canCreateLocation(ep)).collect(Collectors.toList()); result.forEach(ep -> syncEndpointLocation(rwTx, ep)); result.forEach(ep -> pendingAddrEndpoints.remove(vppEndpoint.getKey(), ep.getKey())); syncedChain.submitNow(rwTx); } catch (Exception e) { LOG.error("Failed to resolve location for vpp endpoint {}. {}", vppEndpoint.getKey(), e); } finally { THREAD_LOCK.unlock(); } return Futures.immediateFuture(null); } VppEndpointLocationProvider(DataBroker dataProvider); @Override void onDataTreeChanged(Collection<DataTreeModification<AddressEndpoint>> change); @Override ListenableFuture<Void> createLocationForVppEndpoint(VppEndpoint vppEndpoint); @Override ListenableFuture<Void> deleteLocationForVppEndpoint(VppEndpoint vppEndpoint); @Override ListenableFuture<Void> replaceLocationForEndpoint(@Nonnull ExternalLocationCase location,
            @Nonnull AddressEndpointWithLocationKey addrEpWithLocKey); @Override void close(); static final ProviderName VPP_ENDPOINT_LOCATION_PROVIDER; static final long PROVIDER_PRIORITY; }