@GuardedBy("this") private DOMStoreWriteTransaction lookup(final LogicalDatastoreType store, final YangInstanceIdentifier path) { final DOMDataTreeIdentifier id = new DOMDataTreeIdentifier(store, path); for (Entry<DOMDataTreeIdentifier, DOMStoreWriteTransaction> e : idToTransaction.entrySet()) { if (e.getKey().contains(id)) { return e.getValue(); } } throw new IllegalArgumentException(String.format("Path %s is not acessible from transaction %s", id, this)); }
@GuardedBy("this") private ShardingTableEntry lookupShard(final DOMDataTreeIdentifier prefix) { final ShardingTableEntry t = shardingTables.get(prefix.getDatastoreType()); if (t == null) { return null; } return t.lookup(prefix.getRootIdentifier()); }
AdjInTracker(final DOMDataTreeChangeService service, final RIBSupportContextRegistry registry, final DOMTransactionChain chain, final YangInstanceIdentifier peerIId, @Nonnull final PerTableTypeRouteCounter effectiveRibInRouteCounters, @Nonnull final PerTableTypeRouteCounter adjRibInRouteCounters) { this.registry = Preconditions.checkNotNull(registry); this.chain = Preconditions.checkNotNull(chain); this.peerIId = Preconditions.checkNotNull(peerIId); this.effRibTables = this.peerIId.node(EffectiveRibIn.QNAME).node(Tables.QNAME); this.effectiveRibInRouteCounters = Preconditions.checkNotNull(effectiveRibInRouteCounters); this.adjRibInRouteCounters = Preconditions.checkNotNull(adjRibInRouteCounters); final DOMDataTreeIdentifier treeId = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, this.peerIId.node(AdjRibIn.QNAME).node(Tables.QNAME)); LOG.debug("Registered Effective RIB on {}", this.peerIId); this.reg = service.registerDataTreeChangeListener(treeId, this); }
@GuardedBy("this") private boolean haveSubtree(final DOMDataTreeIdentifier subtree) { for (final DOMDataTreeIdentifier i : idToShard.keySet()) { if (i.contains(subtree)) { return true; } } return false; }
@Override public <L extends org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener> ListenerRegistration<L> registerDataTreeChangeListener(final org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier treeId, final L listener) { final DOMDataTreeChangeListener delegateListener; if (listener instanceof org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener) { delegateListener = (ClusteredDOMDataTreeChangeListener) listener::onDataTreeChanged; } else { delegateListener = listener::onDataTreeChanged; } final ListenerRegistration<?> reg = delegate().registerDataTreeChangeListener( DOMDataTreeIdentifier.fromMdsal(treeId), delegateListener); return new AbstractListenerRegistration<L>(listener) { @Override protected void removeRegistration() { reg.close(); } }; }
@Override public <T extends DOMDataTreeShard> ListenerRegistration<T> registerDataTreeShard(final DOMDataTreeIdentifier prefix, final T shard) throws DOMDataTreeShardingConflictException { final ShardRegistration<T> reg; final ShardRegistration<?> parentReg; synchronized (this) { /* * Lookup the parent shard (e.g. the one which currently matches the prefix), * and if it exists, check if its registration prefix does not collide with * this registration. */ final ShardingTableEntry parent = lookupShard(prefix); parentReg = parent.getRegistration(); if (parentReg != null && prefix.equals(parentReg.getPrefix())) { throw new DOMDataTreeShardingConflictException(String.format("Prefix %s is already occupied by shard %s", prefix, parentReg.getInstance())); } // FIXME: wrap the shard in a proper adaptor based on implemented interface reg = new ShardRegistration<T>(this, prefix, shard); storeShard(prefix, reg); // FIXME: update any producers/registrations } // Notify the parent shard if (parentReg != null) { parentReg.getInstance().onChildAttached(prefix, shard); } return reg; }
/** * Return a counterpart to an MD-SAL data tree identifier. * * @return Controller data tree identifier. */ public static DOMDataTreeIdentifier fromMdsal(final org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier mdsal) { return new DOMDataTreeIdentifier(LogicalDatastoreType.fromMdsal(mdsal.getDatastoreType()), mdsal.getRootIdentifier()); }
@GuardedBy("this") private DOMDataTreeProducer lookupChild(final DOMDataTreeIdentifier s) { for (final Entry<DOMDataTreeIdentifier, DOMDataTreeProducer> e : children.entrySet()) { if (e.getKey().contains(s)) { return e.getValue(); } } return null; }
private DOMDataTreeIdentifier toDomTreeIdentifier(final DataTreeIdentifier<?> treeId) { final YangInstanceIdentifier domPath = codec.toYangInstanceIdentifierBlocking(treeId.getRootIdentifier()); return new DOMDataTreeIdentifier(treeId.getDatastoreType(), domPath); } }
@GuardedBy("this") private void storeShard(final DOMDataTreeIdentifier prefix, final ShardRegistration<?> reg) { ShardingTableEntry t = shardingTables.get(prefix.getDatastoreType()); if (t == null) { t = new ShardingTableEntry(); shardingTables.put(prefix.getDatastoreType(), t); } t.store(prefix.getRootIdentifier(), reg); }
@GuardedBy("this") private DOMDataTreeProducer findProducer(final DOMDataTreeIdentifier subtree) { for (final Entry<DOMDataTreeIdentifier, DOMDataTreeProducer> e : idToProducer.entrySet()) { if (e.getKey().contains(subtree)) { return e.getValue(); } } return null; }
private Messaging4TransportProviderImpl(final YangInstanceIdentifier id, final AmqpUserAgent userAgent, final DOMDataBroker dataBroker, final DOMNotificationService notificationService) { identifier = id; try { Session session = AmqpPublisher.getAmqpSession(userAgent.getHost(), userAgent.getPort(), userAgent.getUsername(), userAgent.getPassword()); MessageProducer producer = session.createProducer(AmqpConfig.getDestination(Messaging4TransportConstants. AMQP_TOPIC_EVENT_DESTINATION)); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } catch (final Exception e) { throw new IllegalStateException("Unable to connect to the AMQP server", e); } notificationReg = notificationService.registerNotificationListener(this, TOPIC_NOTIFICATION_PATH); final YangInstanceIdentifier receiverPath = identifier; final DOMDataTreeIdentifier receiverConfigPath = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, receiverPath); // configurationReg = dataBroker.registerDataChangeListener(); //receiverConfigPath, this); // todo: registerDataTreeChangeListener LOG.info("AMQP user agent initialized. id: {}", id); }
@Override public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerDataTreeChangeListener(final DOMDataTreeIdentifier treeId, final L listener) { DOMStore publisher = getTxFactories().get(treeId.getDatastoreType()); checkState(publisher != null, "Requested logical data store is not available."); return ((DOMStoreTreeChangePublisher)publisher).registerTreeChangeListener(treeId.getRootIdentifier(), listener); } });
@Override public synchronized DOMDataTreeProducer createProducer(final Collection<DOMDataTreeIdentifier> subtrees) { Preconditions.checkState(!closed, "Producer is already closed"); Preconditions.checkState(openTx == null, "Transaction %s is still open", openTx); for (final DOMDataTreeIdentifier s : subtrees) { // Check if the subtree was visible at any time if (!haveSubtree(s)) { throw new IllegalArgumentException(String.format("Subtree %s was never available in producer %s", s, this)); } // Check if the subtree has not been delegated to a child final DOMDataTreeProducer child = lookupChild(s); Preconditions.checkArgument(child == null, "Subtree %s is delegated to child producer %s", s, child); // Check if part of the requested subtree is not delegated to a child. for (final DOMDataTreeIdentifier c : children.keySet()) { if (s.contains(c)) { throw new IllegalArgumentException(String.format("Subtree %s cannot be delegated as it is superset of already-delegated %s", s, c)); } } } final DOMDataTreeProducer ret = dataTree.createProducer(this, subtrees); final ImmutableMap.Builder<DOMDataTreeIdentifier, DOMDataTreeProducer> cb = ImmutableMap.builder(); cb.putAll(children); for (final DOMDataTreeIdentifier s : subtrees) { cb.put(s, ret); } children = cb.build(); return ret; }
private AdjRibOutListener(final PeerId peerId, final TablesKey tablesKey, final YangInstanceIdentifier ribId, final CodecsRegistry registry, final RIBSupport support, final DOMDataTreeChangeService service, final ChannelOutputLimiter session, final boolean mpSupport, final UnsignedInt32Counter routeCounter) { this.session = Preconditions.checkNotNull(session); this.support = Preconditions.checkNotNull(support); this.codecs = registry.getCodecs(this.support); this.mpSupport = mpSupport; final YangInstanceIdentifier adjRibOutId = ribId.node(Peer.QNAME).node(IdentifierUtils.domPeerId(peerId)).node(AdjRibOut.QNAME).node(Tables.QNAME).node(RibSupportUtils.toYangTablesKey(tablesKey)); this.registerDataTreeChangeListener = service.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, adjRibOutId), this); this.routeCounter = routeCounter; }
@Override public <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerDataTreeChangeListener(final DOMDataTreeIdentifier treeId, final L listener) { DOMStore publisher = getTxFactories().get(treeId.getDatastoreType()); checkState(publisher != null, "Requested logical data store is not available."); return ((DOMStoreTreeChangePublisher) publisher).registerTreeChangeListener(treeId.getRootIdentifier(), listener); } });
@Override public void instantiateServiceInstance() { if(this.configurationWriter != null) { this.configurationWriter.apply(); } LOG.info("Application Peer Singleton Service {} instantiated", getIdentifier()); final YangInstanceIdentifier yangIId = YangInstanceIdentifier.builder().node(ApplicationRib.QNAME) .nodeWithKey(ApplicationRib.QNAME, APP_ID_QNAME, this.appRibId.getValue()).node(Tables.QNAME).node(Tables.QNAME).build(); this.applicationPeer.instantiateServiceInstance(); this.registration = this.dataTreeChangeService .registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yangIId), this.applicationPeer); }
void removeShard(final ShardRegistration<?> reg) { final DOMDataTreeIdentifier prefix = reg.getPrefix(); final ShardRegistration<?> parentReg; synchronized (this) { final ShardingTableEntry t = shardingTables.get(prefix.getDatastoreType()); if (t == null) { LOG.warn("Shard registration {} points to non-existent table", reg); return; } t.remove(prefix.getRootIdentifier()); parentReg = lookupShard(prefix).getRegistration(); /* * FIXME: adjust all producers. This is tricky, as we need different locking strategy, * simply because we risk AB/BA deadlock with a producer being split off from * a producer. * */ } if (parentReg != null) { parentReg.getInstance().onChildDetached(prefix, reg.getInstance()); } }
private LocRibWriter(final RIBSupportContextRegistry registry, final DOMTransactionChain chain, final YangInstanceIdentifier target, final Long ourAs, final DOMDataTreeChangeService service, final PolicyDatabase pd, final TablesKey tablesKey, final CacheDisconnectedPeers cacheDisconnectedPeers, @Nonnull final PathSelectionMode pathSelectionMode, final UnsignedInt32Counter routeCounter) { this.chain = Preconditions.checkNotNull(chain); this.tableKey = RibSupportUtils.toYangTablesKey(tablesKey); this.localTablesKey = tablesKey; this.locRibTarget = YangInstanceIdentifier.create(target.node(LocRib.QNAME).node(Tables.QNAME).node(this.tableKey).getPathArguments()); this.ourAs = Preconditions.checkNotNull(ourAs); this.ribSupport = registry.getRIBSupportContext(tablesKey).getRibSupport(); this.attributesIdentifier = this.ribSupport.routeAttributesIdentifier(); this.peerPolicyTracker = new ExportPolicyPeerTrackerImpl(pd, this.localTablesKey); this.cacheDisconnectedPeers = cacheDisconnectedPeers; this.pathSelectionMode = pathSelectionMode; this.routeCounter = routeCounter; final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction(); tx.merge(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(Routes.QNAME), this.ribSupport.emptyRoutes()); tx.merge(LogicalDatastoreType.OPERATIONAL, this.locRibTarget.node(Attributes.QNAME).node(ATTRIBUTES_UPTODATE_TRUE.getNodeType()), ATTRIBUTES_UPTODATE_TRUE); tx.submit(); final YangInstanceIdentifier tableId = target.node(Peer.QNAME).node(Peer.QNAME); this.reg = service.registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, tableId), this); }