Search in sources :

Example 6 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode 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 TransactionChainListener listener = Mockito.mock(TransactionChainListener.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);
    try {
        writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
        fail("Expected TransactionCommitFailedException");
    } catch (final TransactionCommitFailedException e) {
    // Expected
    }
    verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
    txChain.close();
    broker.close();
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ConcurrentDOMDataBroker(org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker) TransactionChainListener(org.opendaylight.mdsal.common.api.TransactionChainListener) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 7 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode 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 TransactionChainListener listener = Mockito.mock(TransactionChainListener.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);
    try {
        writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
        fail("Expected TransactionCommitFailedException");
    } catch (final TransactionCommitFailedException e) {
    // Expected
    }
    verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
    txChain.close();
    broker.close();
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ConcurrentDOMDataBroker(org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker) TransactionChainListener(org.opendaylight.mdsal.common.api.TransactionChainListener) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 8 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class TransactionProxyTest method testReadRoot.

@Test
public void testReadRoot() throws ReadFailedException, InterruptedException, ExecutionException, java.util.concurrent.TimeoutException {
    SchemaContext schemaContext = SchemaContextHelper.full();
    Configuration configuration = mock(Configuration.class);
    doReturn(configuration).when(mockActorContext).getConfiguration();
    doReturn(schemaContext).when(mockActorContext).getSchemaContext();
    doReturn(Sets.newHashSet("test", "cars")).when(configuration).getAllShardNames();
    NormalizedNode<?, ?> expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    NormalizedNode<?, ?> expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
    setUpReadData("test", NormalizedNodeAggregatorTest.getRootNode(expectedNode1, schemaContext));
    setUpReadData("cars", NormalizedNodeAggregatorTest.getRootNode(expectedNode2, schemaContext));
    doReturn(MemberName.forName(memberName)).when(mockActorContext).getCurrentMemberName();
    doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(mockActorContext).getClientDispatcher();
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
    Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(YangInstanceIdentifier.EMPTY).get(5, TimeUnit.SECONDS);
    assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
    NormalizedNode<?, ?> normalizedNode = readOptional.get();
    assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection);
    @SuppressWarnings("unchecked") Collection<NormalizedNode<?, ?>> collection = (Collection<NormalizedNode<?, ?>>) normalizedNode.getValue();
    for (NormalizedNode<?, ?> node : collection) {
        assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode);
    }
    assertTrue("Child with QName = " + TestModel.TEST_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME) != null);
    assertEquals(expectedNode1, NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME));
    assertTrue("Child with QName = " + CarsModel.BASE_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME) != null);
    assertEquals(expectedNode2, NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME));
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) Collection(java.util.Collection) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 9 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class AbstractEntityOwnershipTest method verifyEntityCandidate.

protected void verifyEntityCandidate(final NormalizedNode<?, ?> node, final String entityType, final YangInstanceIdentifier entityId, final String candidateName, final boolean expectPresent) {
    try {
        assertNotNull("Missing " + EntityOwners.QNAME.toString(), node);
        assertTrue(node instanceof ContainerNode);
        ContainerNode entityOwnersNode = (ContainerNode) node;
        MapEntryNode entityTypeEntry = getMapEntryNodeChild(entityOwnersNode, EntityType.QNAME, ENTITY_TYPE_QNAME, entityType, true);
        MapEntryNode entityEntry = getMapEntryNodeChild(entityTypeEntry, ENTITY_QNAME, ENTITY_ID_QNAME, entityId, true);
        getMapEntryNodeChild(entityEntry, Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName, expectPresent);
    } catch (AssertionError e) {
        throw new AssertionError("Verification of entity candidate failed - returned data was: " + node, e);
    }
}
Also used : ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DataContainerNode(org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 10 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class TestModel method createAugmentedListEntry.

public static MapEntryNode createAugmentedListEntry(final int id, final String name) {
    Set<QName> childAugmentations = new HashSet<>();
    childAugmentations.add(AUG_CONT_QNAME);
    ContainerNode augCont = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(AUG_CONT_QNAME)).withChild(ImmutableNodes.leafNode(AUG_NAME_QNAME, name)).build();
    final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(childAugmentations);
    final AugmentationNode augmentationNode = Builders.augmentationBuilder().withNodeIdentifier(augmentationIdentifier).withChild(augCont).build();
    return ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(AUGMENTED_LIST_QNAME, ID_QNAME, id)).withChild(ImmutableNodes.leafNode(ID_QNAME, id)).withChild(augmentationNode).build();
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) QName(org.opendaylight.yangtools.yang.common.QName) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) HashSet(java.util.HashSet)

Aggregations

ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)81 Test (org.junit.Test)46 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)32 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)28 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)18 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)12 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)9 DefaultDOMRpcResult (org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult)8 ByteBuf (io.netty.buffer.ByteBuf)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 Map (java.util.Map)6 DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)6 Collection (java.util.Collection)4 ExecutionException (java.util.concurrent.ExecutionException)4 ConcurrentDOMDataBroker (org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker)4 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)4 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)4 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)4 DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)4