@Test public final void testCreateOrUpdateLink() { ConnectPoint src = new ConnectPoint(DID1, P1); ConnectPoint dst = new ConnectPoint(DID2, P2); final DefaultLinkDescription linkDescription = new DefaultLinkDescription(src, dst, INDIRECT); LinkEvent event = linkStore.createOrUpdateLink(PID, linkDescription); assertLink(DID1, P1, DID2, P2, INDIRECT, event.subject()); assertEquals(LINK_ADDED, event.type()); LinkEvent event2 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT)); assertLink(DID1, P1, DID2, P2, DIRECT, event2.subject()); assertEquals(LINK_UPDATED, event2.type()); LinkEvent event3 = linkStore.createOrUpdateLink(PID, new DefaultLinkDescription(src, dst, DIRECT)); assertNull("No change event expected", event3); }
@Override public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) { final DeviceId dstDeviceId = linkDescription.dst().deviceId(); final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId); if (clusterService.getLocalNode().id().equals(dstNodeId)) { LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst()); Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId); if (internalLinkKey == null) { return null; } linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v, linkDescription)); return refreshLinkCache(linkKey); } else { if (!providerId.scheme().equals("cfg")) { return null; } if (dstNodeId == null) { return null; } return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), LINK_INJECT_MESSAGE, SERIALIZER::encode, SERIALIZER::decode, dstNodeId)); } }
ECLinkStore extends AbstractStore<LinkEvent, LinkStoreDelegate> implements LinkStore { @Override public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) { final DeviceId dstDeviceId = linkDescription.dst().deviceId(); final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId); if (clusterService.getLocalNode().id().equals(dstNodeId)) { LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst()); Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId); if (internalLinkKey == null) { return null; } linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v, linkDescription)); return refreshLinkCache(linkKey); } else { if (!providerId.scheme().equals("cfg")) { return null; } if (dstNodeId == null) { return null; } return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), LINK_INJECT_MESSAGE, SERIALIZER::encode, SERIALIZER::decode, dstNodeId)); } } }
ECLinkStore extends AbstractStore<LinkEvent, LinkStoreDelegate> implements LinkStore { @Override public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) { final DeviceId dstDeviceId = linkDescription.dst().deviceId(); final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId); if (clusterService.getLocalNode().id().equals(dstNodeId)) { LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst()); Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId); if (internalLinkKey == null) { return null; } linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v, linkDescription)); return refreshLinkCache(linkKey); } else { if (!providerId.scheme().equals("cfg")) { return null; } if (dstNodeId == null) { return null; } return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), LINK_INJECT_MESSAGE, SERIALIZER::encode, SERIALIZER::decode, dstNodeId)); } }  }
ECLinkStore extends AbstractStore<LinkEvent, LinkStoreDelegate> implements LinkStore { @Override public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) { final DeviceId dstDeviceId = linkDescription.dst().deviceId(); final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId); if (clusterService.getLocalNode().id().equals(dstNodeId)) { LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst()); Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId); if (internalLinkKey == null) { return null; } linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v, linkDescription)); return refreshLinkCache(linkKey); } else { if (!providerId.scheme().equals("cfg")) { return null; } if (dstNodeId == null) { return null; } return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), LINK_INJECT_MESSAGE, SERIALIZER::encode, SERIALIZER::decode, dstNodeId)); } }  @Activate void activate(); @Deactivate void deactivate(); @Override int getLinkCount(); @Override Iterable<Link> getLinks(); @Override Set<Link> getDeviceEgressLinks(DeviceId deviceId); @Override Set<Link> getDeviceIngressLinks(DeviceId deviceId); @Override Link getLink(ConnectPoint src, ConnectPoint dst); @Override Set<Link> getEgressLinks(ConnectPoint src); @Override Set<Link> getIngressLinks(ConnectPoint dst); @Override LinkEvent createOrUpdateLink(ProviderId providerId,
                                        LinkDescription linkDescription); @Override LinkEvent removeOrDownLink(ConnectPoint src, ConnectPoint dst); @Override LinkEvent removeLink(ConnectPoint src, ConnectPoint dst); }
ECLinkStore extends AbstractStore<LinkEvent, LinkStoreDelegate> implements LinkStore { @Override public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) { final DeviceId dstDeviceId = linkDescription.dst().deviceId(); final NodeId dstNodeId = mastershipService.getMasterFor(dstDeviceId); if (clusterService.getLocalNode().id().equals(dstNodeId)) { LinkKey linkKey = linkKey(linkDescription.src(), linkDescription.dst()); Provided<LinkKey> internalLinkKey = getProvided(linkKey, providerId); if (internalLinkKey == null) { return null; } linkDescriptions.compute(internalLinkKey, (k, v) -> createOrUpdateLinkInternal(v, linkDescription)); return refreshLinkCache(linkKey); } else { if (!providerId.scheme().equals("cfg")) { return null; } if (dstNodeId == null) { return null; } return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new Provided<>(linkDescription, providerId), LINK_INJECT_MESSAGE, SERIALIZER::encode, SERIALIZER::decode, dstNodeId)); } }  @Activate void activate(); @Deactivate void deactivate(); @Override int getLinkCount(); @Override Iterable<Link> getLinks(); @Override Set<Link> getDeviceEgressLinks(DeviceId deviceId); @Override Set<Link> getDeviceIngressLinks(DeviceId deviceId); @Override Link getLink(ConnectPoint src, ConnectPoint dst); @Override Set<Link> getEgressLinks(ConnectPoint src); @Override Set<Link> getIngressLinks(ConnectPoint dst); @Override LinkEvent createOrUpdateLink(ProviderId providerId,
                                        LinkDescription linkDescription); @Override LinkEvent removeOrDownLink(ConnectPoint src, ConnectPoint dst); @Override LinkEvent removeLink(ConnectPoint src, ConnectPoint dst);  }