Search in sources :

Example 1 with MetadataShardDataTreeSnapshot

use of org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot in project controller by opendaylight.

the class ShardRecoveryCoordinatorTest method createSnapshot.

private static ShardSnapshotState createSnapshot() {
    final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, SchemaContextHelper.PEOPLE_YANG));
    DataTreeSnapshot snapshot = dataTree.takeSnapshot();
    DataTreeModification modification = snapshot.newModification();
    modification.merge(CarsModel.BASE_PATH, CarsModel.create());
    modification.merge(PeopleModel.BASE_PATH, PeopleModel.create());
    modification.ready();
    dataTree.commit(dataTree.prepare(modification));
    return new ShardSnapshotState(new MetadataShardDataTreeSnapshot(dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get()));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Example 2 with MetadataShardDataTreeSnapshot

use of org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot in project controller by opendaylight.

the class DistributedDataStoreRemotingIntegrationTest method verifySnapshot.

private static void verifySnapshot(final Snapshot actual, final Snapshot expected, final NormalizedNode<?, ?> expRoot) {
    assertEquals("Snapshot getLastAppliedTerm", expected.getLastAppliedTerm(), actual.getLastAppliedTerm());
    assertEquals("Snapshot getLastAppliedIndex", expected.getLastAppliedIndex(), actual.getLastAppliedIndex());
    assertEquals("Snapshot getLastTerm", expected.getLastTerm(), actual.getLastTerm());
    assertEquals("Snapshot getLastIndex", expected.getLastIndex(), actual.getLastIndex());
    assertEquals("Snapshot state type", ShardSnapshotState.class, actual.getState().getClass());
    MetadataShardDataTreeSnapshot shardSnapshot = (MetadataShardDataTreeSnapshot) ((ShardSnapshotState) actual.getState()).getSnapshot();
    assertEquals("Snapshot root node", expRoot, shardSnapshot.getRootNode().get());
}
Also used : MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)

Example 3 with MetadataShardDataTreeSnapshot

use of org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot in project controller by opendaylight.

the class AbstractShardTest method setupInMemorySnapshotStore.

DataTree setupInMemorySnapshotStore() throws DataValidationFailedException {
    final DataTree testStore = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
    writeToStore(testStore, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    final NormalizedNode<?, ?> root = readStore(testStore, YangInstanceIdentifier.EMPTY);
    InMemorySnapshotStore.addSnapshot(shardID.toString(), Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)), Collections.<ReplicatedLogEntry>emptyList(), 0, 1, -1, -1, 1, null, null));
    return testStore;
}
Also used : ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Example 4 with MetadataShardDataTreeSnapshot

use of org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot in project controller by opendaylight.

the class ShardSnapshotActorTest method testSerializeBoronSnapshot.

@Test
public void testSerializeBoronSnapshot() throws Exception {
    testSerializeSnapshot("testSerializeBoronSnapshotWithInstallSnapshot", new MetadataShardDataTreeSnapshot(DATA), true);
    testSerializeSnapshot("testSerializeBoronSnapshotWithoutInstallSnapshot", new MetadataShardDataTreeSnapshot(DATA), false);
}
Also used : MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 5 with MetadataShardDataTreeSnapshot

use of org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot in project controller by opendaylight.

the class ShardDataTree method applySnapshot.

private void applySnapshot(@Nonnull final ShardDataTreeSnapshot snapshot, final UnaryOperator<DataTreeModification> wrapper) throws DataValidationFailedException {
    final Stopwatch elapsed = Stopwatch.createStarted();
    if (anyPendingTransactions()) {
        LOG.warn("{}: applying state snapshot with pending transactions", logContext);
    }
    final Map<Class<? extends ShardDataTreeSnapshotMetadata<?>>, ShardDataTreeSnapshotMetadata<?>> snapshotMeta;
    if (snapshot instanceof MetadataShardDataTreeSnapshot) {
        snapshotMeta = ((MetadataShardDataTreeSnapshot) snapshot).getMetadata();
    } else {
        snapshotMeta = ImmutableMap.of();
    }
    for (ShardDataTreeMetadata<?> m : metadata) {
        final ShardDataTreeSnapshotMetadata<?> s = snapshotMeta.get(m.getSupportedType());
        if (s != null) {
            m.applySnapshot(s);
        } else {
            m.reset();
        }
    }
    final DataTreeModification mod = wrapper.apply(dataTree.takeSnapshot().newModification());
    // delete everything first
    mod.delete(YangInstanceIdentifier.EMPTY);
    final java.util.Optional<NormalizedNode<?, ?>> maybeNode = snapshot.getRootNode();
    if (maybeNode.isPresent()) {
        // Add everything from the remote node back
        mod.write(YangInstanceIdentifier.EMPTY, maybeNode.get());
    }
    mod.ready();
    final DataTreeModification unwrapped = unwrap(mod);
    dataTree.validate(unwrapped);
    DataTreeCandidateTip candidate = dataTree.prepare(unwrapped);
    dataTree.commit(candidate);
    notifyListeners(candidate);
    LOG.debug("{}: state snapshot applied in {}", logContext, elapsed);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) PruningDataTreeModification(org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) Stopwatch(com.google.common.base.Stopwatch) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ShardDataTreeSnapshotMetadata(org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshotMetadata)

Aggregations

MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)9 ShardSnapshotState (org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState)6 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)6 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)6 Test (org.junit.Test)4 Snapshot (org.opendaylight.controller.cluster.raft.persisted.Snapshot)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 AddressFromURIString (akka.actor.AddressFromURIString)2 Stopwatch (com.google.common.base.Stopwatch)2 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)2 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)1 GetShardDataTree (org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree)1 DatastoreSnapshot (org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot)1 ShardDataTreeSnapshotMetadata (org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshotMetadata)1 PruningDataTreeModification (org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification)1 ReplicatedLogEntry (org.opendaylight.controller.cluster.raft.ReplicatedLogEntry)1 ApplySnapshot (org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot)1 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1