use of org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState 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.ShardSnapshotState 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.ShardSnapshotState in project controller by opendaylight.
the class ShardRecoveryCoordinator method applyRecoverySnapshot.
/**
* Applies a recovered snapshot to the data store.
*
* @param snapshotState the serialized snapshot
*/
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void applyRecoverySnapshot(final Snapshot.State snapshotState) {
if (!(snapshotState instanceof ShardSnapshotState)) {
log.debug("{}: applyRecoverySnapshot ignoring snapshot: {}", snapshotState);
}
log.debug("{}: Applying recovered snapshot", shardName);
ShardDataTreeSnapshot shardSnapshot = ((ShardSnapshotState) snapshotState).getSnapshot();
try {
store.applyRecoverySnapshot(shardSnapshot);
} catch (Exception e) {
final File f = writeRoot("snapshot", shardSnapshot.getRootNode().orElse(null));
throw new IllegalStateException(String.format("%s: Failed to apply recovery snapshot %s. Node data was written to file %s", shardName, shardSnapshot, f), e);
}
}
use of org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState in project controller by opendaylight.
the class ShardSnapshotCohort method applySnapshot.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void applySnapshot(final Snapshot.State snapshotState) {
if (!(snapshotState instanceof ShardSnapshotState)) {
log.debug("{}: applySnapshot ignoring snapshot: {}", snapshotState);
}
final ShardDataTreeSnapshot snapshot = ((ShardSnapshotState) snapshotState).getSnapshot();
// Since this will be done only on Recovery or when this actor is a Follower
// we can safely commit everything in here. We not need to worry about event notifications
// as they would have already been disabled on the follower
log.info("{}: Applying snapshot", logId);
try {
store.applySnapshot(snapshot);
} catch (Exception e) {
log.error("{}: Failed to apply snapshot {}", logId, snapshot, e);
return;
}
log.info("{}: Done applying snapshot", logId);
}
use of org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState in project controller by opendaylight.
the class ShardSnapshotActor method onSerializeSnapshot.
private void onSerializeSnapshot(final SerializeSnapshot request) {
Optional<OutputStream> installSnapshotStream = request.getInstallSnapshotStream();
if (installSnapshotStream.isPresent()) {
try (ObjectOutputStream out = new ObjectOutputStream(installSnapshotStream.get())) {
request.getSnapshot().serialize(out);
} catch (IOException e) {
// TODO - we should communicate the failure in the CaptureSnapshotReply.
LOG.error("Error serializing snapshot", e);
}
}
request.getReplyTo().tell(new CaptureSnapshotReply(new ShardSnapshotState(request.getSnapshot()), installSnapshotStream), ActorRef.noSender());
}
Aggregations