use of org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testBackupDatastore.
@Test
public void testBackupDatastore() throws Exception {
MemberNode node = MemberNode.builder(memberNodes).akkaConfig("Member1").moduleShardsConfig("module-shards-member1.conf").waitForShardLeader("cars", "people").testName("testBackupDatastore").build();
String fileName = "target/testBackupDatastore";
new File(fileName).delete();
ClusterAdminRpcService service = new ClusterAdminRpcService(node.configDataStore(), node.operDataStore(), null);
RpcResult<Void> rpcResult = service.backupDatastore(new BackupDatastoreInputBuilder().setFilePath(fileName).build()).get(5, TimeUnit.SECONDS);
verifySuccessfulRpcResult(rpcResult);
try (FileInputStream fis = new FileInputStream(fileName)) {
List<DatastoreSnapshot> snapshots = SerializationUtils.deserialize(fis);
assertEquals("DatastoreSnapshot size", 2, snapshots.size());
ImmutableMap<String, DatastoreSnapshot> map = ImmutableMap.of(snapshots.get(0).getType(), snapshots.get(0), snapshots.get(1).getType(), snapshots.get(1));
verifyDatastoreSnapshot(node.configDataStore().getActorContext().getDataStoreName(), map.get(node.configDataStore().getActorContext().getDataStoreName()), "cars", "people");
} finally {
new File(fileName).delete();
}
// Test failure by killing a shard.
node.configDataStore().getActorContext().getShardManager().tell(node.datastoreContextBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), ActorRef.noSender());
ActorRef carsShardActor = node.configDataStore().getActorContext().findLocalShard("cars").get();
node.kit().watch(carsShardActor);
carsShardActor.tell(PoisonPill.getInstance(), ActorRef.noSender());
node.kit().expectTerminated(carsShardActor);
rpcResult = service.backupDatastore(new BackupDatastoreInputBuilder().setFilePath(fileName).build()).get(5, TimeUnit.SECONDS);
assertFalse("isSuccessful", rpcResult.isSuccessful());
assertEquals("getErrors", 1, rpcResult.getErrors().size());
}
use of org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot in project controller by opendaylight.
the class ShardManagerGetSnapshotReplyActorTest method testSuccess.
@Test
public void testSuccess() {
TestKit kit = new TestKit(getSystem());
List<String> shardList = Arrays.asList("shard1", "shard2", "shard3");
ShardManagerSnapshot shardManagerSnapshot = new ShardManagerSnapshot(shardList, Collections.emptyMap());
ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props(shardList, "config", shardManagerSnapshot, kit.getRef(), "shard-manager", Duration.create(100, TimeUnit.SECONDS)), "testSuccess");
kit.watch(replyActor);
ByteState shard1SnapshotState = ByteState.of(new byte[] { 1, 2, 3 });
replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard1", MEMBER_1, "config").toString(), Snapshot.create(shard1SnapshotState, Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());
ByteState shard2SnapshotState = ByteState.of(new byte[] { 4, 5, 6 });
replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard2", MEMBER_1, "config").toString(), Snapshot.create(shard2SnapshotState, Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());
kit.expectNoMsg(FiniteDuration.create(500, TimeUnit.MILLISECONDS));
ByteState shard3SnapshotState = ByteState.of(new byte[] { 7, 8, 9 });
replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard3", MEMBER_1, "config").toString(), Snapshot.create(shard3SnapshotState, Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());
DatastoreSnapshot datastoreSnapshot = kit.expectMsgClass(DatastoreSnapshot.class);
assertEquals("getType", "config", datastoreSnapshot.getType());
assertEquals("getShardManagerSnapshot", shardManagerSnapshot.getShardList(), datastoreSnapshot.getShardManagerSnapshot().getShardList());
List<ShardSnapshot> shardSnapshots = datastoreSnapshot.getShardSnapshots();
assertEquals("ShardSnapshot size", 3, shardSnapshots.size());
assertEquals("ShardSnapshot 1 getName", "shard1", shardSnapshots.get(0).getName());
assertEquals("ShardSnapshot 1 getSnapshot", shard1SnapshotState, shardSnapshots.get(0).getSnapshot().getState());
assertEquals("ShardSnapshot 2 getName", "shard2", shardSnapshots.get(1).getName());
assertEquals("ShardSnapshot 2 getSnapshot", shard2SnapshotState, shardSnapshots.get(1).getSnapshot().getState());
assertEquals("ShardSnapshot 3 getName", "shard3", shardSnapshots.get(2).getName());
assertEquals("ShardSnapshot 3 getSnapshot", shard3SnapshotState, shardSnapshots.get(2).getSnapshot().getState());
kit.expectMsgClass(Terminated.class);
}
use of org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot in project controller by opendaylight.
the class DatastoreSnapshotRestoreTest method test.
@Test
public void test() throws Exception {
assertTrue("Failed to mkdir " + restoreDirectoryPath, restoreDirectoryFile.mkdirs());
final DatastoreSnapshot configSnapshot = new DatastoreSnapshot("config", newShardManagerSnapshot("config-one", "config-two"), Arrays.asList(new DatastoreSnapshot.ShardSnapshot("config-one", newSnapshot(CarsModel.BASE_PATH, CarsModel.newCarsNode(CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)), CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L)))))), new DatastoreSnapshot.ShardSnapshot("config-two", newSnapshot(PeopleModel.BASE_PATH, PeopleModel.emptyContainer()))));
DatastoreSnapshot operSnapshot = new DatastoreSnapshot("oper", null, Arrays.asList(new DatastoreSnapshot.ShardSnapshot("oper-one", newSnapshot(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)))));
DatastoreSnapshotList snapshotList = new DatastoreSnapshotList(Arrays.asList(configSnapshot, operSnapshot));
try (FileOutputStream fos = new FileOutputStream(backupFile)) {
SerializationUtils.serialize(snapshotList, fos);
}
DatastoreSnapshotRestore instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath);
assertDatastoreSnapshotEquals(configSnapshot, instance.getAndRemove("config"));
assertDatastoreSnapshotEquals(operSnapshot, instance.getAndRemove("oper"));
assertNull("DatastoreSnapshot was not removed", instance.getAndRemove("config"));
assertFalse(backupFile + " was not deleted", backupFile.exists());
instance = DatastoreSnapshotRestore.instance(restoreDirectoryPath);
assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("config"));
assertNull("Expected null DatastoreSnapshot", instance.getAndRemove("oper"));
}
use of org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testRestoreFromDatastoreSnapshot.
@Test
public void testRestoreFromDatastoreSnapshot() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
final String name = "transactionIntegrationTest";
final ContainerNode carsNode = CarsModel.newCarsNode(CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)), CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L))));
DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.full());
AbstractShardTest.writeToStore(dataTree, CarsModel.BASE_PATH, carsNode);
NormalizedNode<?, ?> root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
final Snapshot carsSnapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)), Collections.emptyList(), 2, 1, 2, 1, 1, "member-1", null);
dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.full());
final NormalizedNode<?, ?> peopleNode = PeopleModel.create();
AbstractShardTest.writeToStore(dataTree, PeopleModel.BASE_PATH, peopleNode);
root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
final Snapshot peopleSnapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)), Collections.emptyList(), 2, 1, 2, 1, 1, "member-1", null);
restoreFromSnapshot = new DatastoreSnapshot(name, null, Arrays.asList(new DatastoreSnapshot.ShardSnapshot("cars", carsSnapshot), new DatastoreSnapshot.ShardSnapshot("people", peopleSnapshot)));
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, name, "module-shards-member1.conf", true, "cars", "people")) {
final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
// two reads
Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.BASE_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", carsNode, optional.get());
optional = readTx.read(PeopleModel.BASE_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", peopleNode, optional.get());
}
}
};
}
Aggregations