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()));
}
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());
}
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;
}
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);
}
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);
}
Aggregations