use of org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot in project controller by opendaylight.
the class ShardSnapshotActorTest method testSerializeSnapshot.
private static void testSerializeSnapshot(final String testName, final ShardDataTreeSnapshot snapshot, final boolean withInstallSnapshot) throws Exception {
new TestKit(getSystem()) {
{
final ActorRef snapshotActor = getSystem().actorOf(ShardSnapshotActor.props(), testName);
watch(snapshotActor);
final NormalizedNode<?, ?> expectedRoot = snapshot.getRootNode().get();
ByteArrayOutputStream installSnapshotStream = withInstallSnapshot ? new ByteArrayOutputStream() : null;
ShardSnapshotActor.requestSnapshot(snapshotActor, snapshot, Optional.ofNullable(installSnapshotStream), getRef());
final CaptureSnapshotReply reply = expectMsgClass(duration("3 seconds"), CaptureSnapshotReply.class);
assertNotNull("getSnapshotState is null", reply.getSnapshotState());
assertEquals("SnapshotState type", ShardSnapshotState.class, reply.getSnapshotState().getClass());
assertEquals("Snapshot", snapshot, ((ShardSnapshotState) reply.getSnapshotState()).getSnapshot());
if (installSnapshotStream != null) {
final ShardDataTreeSnapshot deserialized;
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(installSnapshotStream.toByteArray()))) {
deserialized = ShardDataTreeSnapshot.deserialize(in);
}
assertEquals("Deserialized snapshot type", snapshot.getClass(), deserialized.getClass());
final Optional<NormalizedNode<?, ?>> maybeNode = deserialized.getRootNode();
assertEquals("isPresent", true, maybeNode.isPresent());
assertEquals("Root node", expectedRoot, maybeNode.get());
}
}
};
}
use of org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot 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.ShardDataTreeSnapshot in project controller by opendaylight.
the class ShardSnapshotCohort method createSnapshot.
@Override
public void createSnapshot(final ActorRef actorRef, final Optional<OutputStream> installSnapshotStream) {
// Forward the request to the snapshot actor
final ShardDataTreeSnapshot snapshot = store.takeStateSnapshot();
log.debug("{}: requesting serialization of snapshot {}", logId, snapshot);
ShardSnapshotActor.requestSnapshot(snapshotActor, snapshot, installSnapshotStream, actorRef);
}
use of org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot 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);
}
Aggregations