use of org.opendaylight.mdsal.dom.api.DOMTransactionChainListener in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testChainedTransactionFailureWithMultipleShards.
@Test
public void testChainedTransactionFailureWithMultipleShards() throws Exception {
initDatastoresWithCarsAndPeople("testChainedTransactionFailureWithMultipleShards");
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, followerDistributedDataStore).build(), MoreExecutors.directExecutor());
final DOMTransactionChainListener listener = mock(DOMTransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataTreeWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
// Note that merge will validate the data and fail but put succeeds b/c deep validation is not
// done for put for performance reasons.
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
final var ex = assertThrows(ExecutionException.class, () -> writeTx.commit().get(5, TimeUnit.SECONDS)).getCause();
assertThat(ex, instanceOf(TransactionCommitFailedException.class));
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
txChain.close();
broker.close();
}
use of org.opendaylight.mdsal.dom.api.DOMTransactionChainListener in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testChainedTransactionFailureWithSingleShard.
@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception {
initDatastoresWithCars("testChainedTransactionFailureWithSingleShard");
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, followerDistributedDataStore).build(), MoreExecutors.directExecutor());
final DOMTransactionChainListener listener = mock(DOMTransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataTreeWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
final var ex = assertThrows(ExecutionException.class, () -> writeTx.commit().get(5, TimeUnit.SECONDS)).getCause();
assertThat(ex, instanceOf(TransactionCommitFailedException.class));
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
txChain.close();
broker.close();
}
use of org.opendaylight.mdsal.dom.api.DOMTransactionChainListener in project bgpcep by opendaylight.
the class BGPPeer method onSessionUp.
@Override
public synchronized void onSessionUp(final BGPSession session) {
this.currentSession = session;
this.sessionUp = true;
this.ribOutChain = this.rib.createPeerDOMChain(new DOMTransactionChainListener() {
@Override
public void onTransactionChainSuccessful(final DOMTransactionChain chain) {
LOG.debug("RibOut transaction chain {} successful.", chain);
}
@Override
public void onTransactionChainFailed(final DOMTransactionChain chain, final DOMDataTreeTransaction transaction, final Throwable cause) {
onRibOutChainFailed(cause);
}
});
if (this.currentSession instanceof BGPSessionStateProvider) {
((BGPSessionStateProvider) this.currentSession).registerMessagesCounter(this);
}
final GracefulRestartCapability advertisedGracefulRestartCapability = session.getAdvertisedGracefulRestartCapability();
final var advertisedTables = advertisedGracefulRestartCapability.getTables();
final var advertisedLLTables = session.getAdvertisedLlGracefulRestartCapability().getTables();
final List<AddressFamilies> addPathTablesType = session.getAdvertisedAddPathTableTypes();
final Set<BgpTableType> advertizedTableTypes = session.getAdvertisedTableTypes();
LOG.info("Session with peer {} went up with tables {} and Add Path tables {}", getName(), advertizedTableTypes, addPathTablesType);
final Set<TablesKey> setTables = advertizedTableTypes.stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toSet());
this.tables = ImmutableSet.copyOf(setTables);
this.addPathTableMaps = mapTableTypesFamilies(addPathTablesType);
final boolean restartingLocally = isLocalRestarting();
if (!restartingLocally) {
addBgp4Support();
}
if (!isRestartingGracefully()) {
this.peerId = RouterIds.createPeerId(session.getBgpId());
final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer, PeerKey> peerIId = getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer.class, new PeerKey(this.peerId));
this.peerPath = createPeerPath(this.peerId);
this.peerRibOutIId = peerPath.node(ADJRIBOUT_NID);
this.trackerRegistration = this.rib.getPeerTracker().registerPeer(this);
createEffRibInWriter();
registerPrefixesCounters(this.effRibInWriter, this.effRibInWriter);
this.effRibInWriter.init();
this.ribWriter = this.ribWriter.transform(this.peerId, this.peerPath, this.rib.getRibSupportContext(), this.tables, this.addPathTableMaps);
if (this.rpcRegistry != null) {
this.rpcRegistration = this.rpcRegistry.registerRpcImplementation(BgpPeerRpcService.class, new BgpPeerRpc(this, session, this.tables), ImmutableSet.of(this.rib.getInstanceIdentifier().child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.rib.Peer.class, new PeerKey(this.peerId))));
}
} else {
final Set<TablesKey> forwardingTables;
if (advertisedTables == null) {
forwardingTables = Collections.emptySet();
} else {
forwardingTables = advertisedTables.values().stream().filter(table -> table.getAfiFlags() != null).filter(table -> table.getAfiFlags().getForwardingState()).map(table -> new TablesKey(table.getAfi(), table.getSafi())).collect(Collectors.toSet());
}
this.ribWriter.clearTables(Sets.difference(this.tables, forwardingTables));
if (restartingLocally) {
this.effRibInWriter.close();
this.peerRestartStopwatch = Stopwatch.createStarted();
handleSelectionReferralTimer();
this.missingEOT.addAll(this.tables);
}
}
if (advertisedTables == null || advertisedTables.isEmpty()) {
setAdvertizedGracefulRestartTableTypes(Collections.emptyList());
} else {
setAdvertizedGracefulRestartTableTypes(advertisedTables.values().stream().map(t -> new TablesKey(t.getAfi(), t.getSafi())).collect(Collectors.toList()));
}
setAfiSafiGracefulRestartState(advertisedGracefulRestartCapability.getRestartTime().toJava(), false, restartingLocally);
final Map<TablesKey, Integer> llTablesReceived;
if (advertisedLLTables != null) {
llTablesReceived = new HashMap<>();
for (var table : advertisedLLTables.values()) {
llTablesReceived.put(new TablesKey(table.getAfi(), table.getSafi()), table.getLongLivedStaleTime().getValue().intValue());
}
} else {
llTablesReceived = Collections.emptyMap();
}
setAdvertizedLlGracefulRestartTableTypes(llTablesReceived);
if (!llTablesReceived.isEmpty()) {
llgrSupport = true;
// FIXME: propagate preserved tables
} else {
// FIXME: clear preserved tables
llgrSupport = false;
}
if (!restartingLocally) {
if (!setTables.contains(IPV4_UCAST_TABLE_KEY)) {
createAdjRibOutListener(IPV4_UCAST_TABLE_KEY, false);
}
for (final TablesKey key : getAfiSafisAdvertized()) {
createAdjRibOutListener(key, true);
}
}
// SpotBugs does not grok Optional.ifPresent() and thinks we are using unsynchronized access
final Optional<RevisedErrorHandlingSupport> errorHandling = this.bgpPeer.getErrorHandling();
if (errorHandling.isPresent()) {
this.currentSession.addDecoderConstraint(RevisedErrorHandlingSupport.class, errorHandling.get());
}
}
use of org.opendaylight.mdsal.dom.api.DOMTransactionChainListener in project controller by opendaylight.
the class AbstractDistributedDataStoreIntegrationTest method testChainedTransactionFailureWithSingleShard.
@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception {
final IntegrationTestKit testKit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
try (AbstractDataStore dataStore = testKit.setupAbstractDataStore(testParameter, "testChainedTransactionFailureWithSingleShard", "cars-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
final DOMTransactionChainListener listener = Mockito.mock(DOMTransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataTreeReadWriteTransaction writeTx = txChain.newReadWriteTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
try {
writeTx.commit().get(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (final ExecutionException e) {
// Expected
}
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
txChain.close();
broker.close();
}
}
use of org.opendaylight.mdsal.dom.api.DOMTransactionChainListener in project controller by opendaylight.
the class AbstractDistributedDataStoreIntegrationTest method testChainedTransactionFailureWithMultipleShards.
@Test
public void testChainedTransactionFailureWithMultipleShards() throws Exception {
final IntegrationTestKit testKit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
try (AbstractDataStore dataStore = testKit.setupAbstractDataStore(testParameter, "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
final DOMTransactionChainListener listener = Mockito.mock(DOMTransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataTreeWriteTransaction writeTx = txChain.newReadWriteTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
// done for put for performance reasons.
try {
writeTx.commit().get(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (final ExecutionException e) {
// Expected
}
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
txChain.close();
broker.close();
}
}
Aggregations