Search in sources :

Example 6 with DatastoreSnapshot

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());
}
Also used : MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) ActorRef(akka.actor.ActorRef) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) File(java.io.File) BackupDatastoreInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.BackupDatastoreInputBuilder) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 7 with DatastoreSnapshot

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);
}
Also used : ShardSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot) ShardManagerSnapshot(org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot) ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) ByteState(org.opendaylight.controller.cluster.raft.persisted.ByteState) GetSnapshotReply(org.opendaylight.controller.cluster.raft.client.messages.GetSnapshotReply) AbstractActorTest(org.opendaylight.controller.cluster.datastore.AbstractActorTest) Test(org.junit.Test)

Example 8 with DatastoreSnapshot

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"));
}
Also used : DatastoreSnapshotList(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList) FileOutputStream(java.io.FileOutputStream) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) Test(org.junit.Test)

Example 9 with DatastoreSnapshot

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());
            }
        }
    };
}
Also used : ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) AddressFromURIString(akka.actor.AddressFromURIString) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

DatastoreSnapshot (org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot)9 Test (org.junit.Test)6 AddressFromURIString (akka.actor.AddressFromURIString)3 TestKit (akka.testkit.javadsl.TestKit)3 ShardSnapshot (org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot)3 ShardManagerSnapshot (org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot)3 ActorRef (akka.actor.ActorRef)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)2 DatastoreSnapshotList (org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshotList)2 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)2 ActorSystem (akka.actor.ActorSystem)1 Status (akka.actor.Status)1 Failure (akka.actor.Status.Failure)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ClientBackedDataStore (org.opendaylight.controller.cluster.databroker.ClientBackedDataStore)1