Search in sources :

Example 1 with CreateShard

use of org.opendaylight.controller.cluster.datastore.messages.CreateShard in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method testAddReplicasForAllShards.

@Test
public void testAddReplicasForAllShards() throws Exception {
    String name = "testAddReplicasForAllShards";
    String moduleShardsConfig = "module-shards-member1.conf";
    MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).waitForShardLeader("cars", "people").build();
    ModuleShardConfiguration petsModuleConfig = new ModuleShardConfiguration(URI.create("pets-ns"), "pets-module", "pets", null, Collections.singletonList(MEMBER_1));
    leaderNode1.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), leaderNode1.kit().getRef());
    leaderNode1.kit().expectMsgClass(Success.class);
    leaderNode1.kit().waitUntilLeader(leaderNode1.configDataStore().getActorContext(), "pets");
    MemberNode newReplicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    leaderNode1.waitForMembersUp("member-2");
    newReplicaNode2.waitForMembersUp("member-1");
    newReplicaNode2.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), newReplicaNode2.kit().getRef());
    newReplicaNode2.kit().expectMsgClass(Success.class);
    newReplicaNode2.operDataStore().getActorContext().getShardManager().tell(new CreateShard(new ModuleShardConfiguration(URI.create("no-leader-ns"), "no-leader-module", "no-leader", null, Collections.singletonList(MEMBER_1)), Shard.builder(), null), newReplicaNode2.kit().getRef());
    newReplicaNode2.kit().expectMsgClass(Success.class);
    ClusterAdminRpcService service = new ClusterAdminRpcService(newReplicaNode2.configDataStore(), newReplicaNode2.operDataStore(), null);
    RpcResult<AddReplicasForAllShardsOutput> rpcResult = service.addReplicasForAllShards().get(10, TimeUnit.SECONDS);
    AddReplicasForAllShardsOutput result = verifySuccessfulRpcResult(rpcResult);
    verifyShardResults(result.getShardResult(), successShardResult("cars", DataStoreType.Config), successShardResult("people", DataStoreType.Config), successShardResult("pets", DataStoreType.Config), successShardResult("cars", DataStoreType.Operational), successShardResult("people", DataStoreType.Operational), failedShardResult("no-leader", DataStoreType.Operational));
    verifyRaftPeersPresent(newReplicaNode2.configDataStore(), "cars", "member-1");
    verifyRaftPeersPresent(newReplicaNode2.configDataStore(), "people", "member-1");
    verifyRaftPeersPresent(newReplicaNode2.configDataStore(), "pets", "member-1");
    verifyRaftPeersPresent(newReplicaNode2.operDataStore(), "cars", "member-1");
    verifyRaftPeersPresent(newReplicaNode2.operDataStore(), "people", "member-1");
}
Also used : MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) AddReplicasForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutput) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test)

Example 2 with CreateShard

use of org.opendaylight.controller.cluster.datastore.messages.CreateShard in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method testRemoveAllShardReplicas.

@Test
public void testRemoveAllShardReplicas() throws Exception {
    String name = "testRemoveAllShardReplicas";
    String moduleShardsConfig = "module-shards-member1-and-2-and-3.conf";
    final MemberNode leaderNode1 = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).datastoreContextBuilder(DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(300).shardElectionTimeoutFactor(1)).build();
    final MemberNode replicaNode2 = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    final MemberNode replicaNode3 = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(moduleShardsConfig).build();
    leaderNode1.configDataStore().waitTillReady();
    verifyRaftPeersPresent(leaderNode1.configDataStore(), "cars", "member-2", "member-3");
    verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-1", "member-3");
    verifyRaftPeersPresent(replicaNode3.configDataStore(), "cars", "member-1", "member-2");
    ModuleShardConfiguration petsModuleConfig = new ModuleShardConfiguration(URI.create("pets-ns"), "pets-module", "pets", null, Arrays.asList(MEMBER_1, MEMBER_2, MEMBER_3));
    leaderNode1.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), leaderNode1.kit().getRef());
    leaderNode1.kit().expectMsgClass(Success.class);
    replicaNode2.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), replicaNode2.kit().getRef());
    replicaNode2.kit().expectMsgClass(Success.class);
    replicaNode3.configDataStore().getActorContext().getShardManager().tell(new CreateShard(petsModuleConfig, Shard.builder(), null), replicaNode3.kit().getRef());
    replicaNode3.kit().expectMsgClass(Success.class);
    verifyRaftPeersPresent(leaderNode1.configDataStore(), "pets", "member-2", "member-3");
    verifyRaftPeersPresent(replicaNode2.configDataStore(), "pets", "member-1", "member-3");
    verifyRaftPeersPresent(replicaNode3.configDataStore(), "pets", "member-1", "member-2");
    ClusterAdminRpcService service3 = new ClusterAdminRpcService(replicaNode3.configDataStore(), replicaNode3.operDataStore(), null);
    RpcResult<RemoveAllShardReplicasOutput> rpcResult = service3.removeAllShardReplicas(new RemoveAllShardReplicasInputBuilder().setMemberName("member-3").build()).get(10, TimeUnit.SECONDS);
    RemoveAllShardReplicasOutput result = verifySuccessfulRpcResult(rpcResult);
    verifyShardResults(result.getShardResult(), successShardResult("cars", DataStoreType.Config), successShardResult("people", DataStoreType.Config), successShardResult("pets", DataStoreType.Config), successShardResult("cars", DataStoreType.Operational), successShardResult("people", DataStoreType.Operational));
    verifyRaftPeersPresent(leaderNode1.configDataStore(), "cars", "member-2");
    verifyRaftPeersPresent(leaderNode1.configDataStore(), "people", "member-2");
    verifyRaftPeersPresent(leaderNode1.configDataStore(), "pets", "member-2");
    verifyRaftPeersPresent(replicaNode2.configDataStore(), "cars", "member-1");
    verifyRaftPeersPresent(replicaNode2.configDataStore(), "people", "member-1");
    verifyRaftPeersPresent(replicaNode2.configDataStore(), "pets", "member-1");
    verifyNoShardPresent(replicaNode3.configDataStore(), "cars");
    verifyNoShardPresent(replicaNode3.configDataStore(), "people");
    verifyNoShardPresent(replicaNode3.configDataStore(), "pets");
}
Also used : MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) RemoveAllShardReplicasOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasOutput) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RemoveAllShardReplicasInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemoveAllShardReplicasInputBuilder) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test)

Example 3 with CreateShard

use of org.opendaylight.controller.cluster.datastore.messages.CreateShard in project controller by opendaylight.

the class ShardManagerTest method testOnCreateShardWithLocalMemberNotInShardConfig.

@Test
public void testOnCreateShardWithLocalMemberNotInShardConfig() {
    LOG.info("testOnCreateShardWithLocalMemberNotInShardConfig starting");
    new TestKit(getSystem()) {

        {
            datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
            ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), ActorRef.noSender());
            Shard.Builder shardBuilder = Shard.builder();
            ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-5", "member-6"));
            shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
            expectMsgClass(duration("5 seconds"), Success.class);
            shardManager.tell(new FindLocalShard("foo", true), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            assertEquals("peerMembers size", 0, shardBuilder.getPeerAddresses().size());
            assertEquals("schemaContext", DisableElectionsRaftPolicy.class.getName(), shardBuilder.getDatastoreContext().getShardRaftConfig().getCustomRaftPolicyImplementationClass());
        }
    };
    LOG.info("testOnCreateShardWithLocalMemberNotInShardConfig ending");
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 4 with CreateShard

use of org.opendaylight.controller.cluster.datastore.messages.CreateShard in project controller by opendaylight.

the class ShardManagerTest method testOnCreateShardWithNoInitialSchemaContext.

@Test
public void testOnCreateShardWithNoInitialSchemaContext() {
    LOG.info("testOnCreateShardWithNoInitialSchemaContext starting");
    new TestKit(getSystem()) {

        {
            ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
            Shard.Builder shardBuilder = Shard.builder();
            ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-1"));
            shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
            expectMsgClass(duration("5 seconds"), Success.class);
            SchemaContext schemaContext = TestModel.createTestContext();
            shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
            shardManager.tell(new FindLocalShard("foo", true), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
            assertNotNull("schemaContext is null", shardBuilder.getDatastoreContext());
        }
    };
    LOG.info("testOnCreateShardWithNoInitialSchemaContext ending");
}
Also used : EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 5 with CreateShard

use of org.opendaylight.controller.cluster.datastore.messages.CreateShard in project controller by opendaylight.

the class ShardManagerTest method testOnCreateShard.

@Test
public void testOnCreateShard() {
    LOG.info("testOnCreateShard starting");
    new TestKit(getSystem()) {

        {
            datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
            ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
            SchemaContext schemaContext = TestModel.createTestContext();
            shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
            DatastoreContext datastoreContext = DatastoreContext.newBuilder().shardElectionTimeoutFactor(100).persistent(false).build();
            Shard.Builder shardBuilder = Shard.builder();
            ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-1", "member-5", "member-6"));
            shardManager.tell(new CreateShard(config, shardBuilder, datastoreContext), getRef());
            expectMsgClass(duration("5 seconds"), Success.class);
            shardManager.tell(new FindLocalShard("foo", true), getRef());
            expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            assertEquals("isRecoveryApplicable", false, shardBuilder.getDatastoreContext().isPersistent());
            assertTrue("Epxected ShardPeerAddressResolver", shardBuilder.getDatastoreContext().getShardRaftConfig().getPeerAddressResolver() instanceof ShardPeerAddressResolver);
            assertEquals("peerMembers", Sets.newHashSet(ShardIdentifier.create("foo", MemberName.forName("member-5"), shardMrgIDSuffix).toString(), ShardIdentifier.create("foo", MemberName.forName("member-6"), shardMrgIDSuffix).toString()), shardBuilder.getPeerAddresses().keySet());
            assertEquals("ShardIdentifier", ShardIdentifier.create("foo", MEMBER_1, shardMrgIDSuffix), shardBuilder.getId());
            assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
            // Send CreateShard with same name - should return Success with
            // a message.
            shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
            Success success = expectMsgClass(duration("5 seconds"), Success.class);
            assertNotNull("Success status is null", success.status());
        }
    };
    LOG.info("testOnCreateShard ending");
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) Success(akka.actor.Status.Success) EmptyModuleShardConfigProvider(org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider) DatastoreContext(org.opendaylight.controller.cluster.datastore.DatastoreContext) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) CreateShard(org.opendaylight.controller.cluster.datastore.messages.CreateShard) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Shard(org.opendaylight.controller.cluster.datastore.Shard) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl) ModuleShardConfiguration(org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)7 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)7 Test (org.junit.Test)5 ActorRef (akka.actor.ActorRef)4 TestActorRef (akka.testkit.TestActorRef)3 TestKit (akka.testkit.javadsl.TestKit)3 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)3 Shard (org.opendaylight.controller.cluster.datastore.Shard)3 ConfigurationImpl (org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)3 EmptyModuleShardConfigProvider (org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider)3 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)3 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)2 MemberNode (org.opendaylight.controller.cluster.datastore.MemberNode)2 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)2 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)2 Success (akka.actor.Status.Success)1 DatastoreContext (org.opendaylight.controller.cluster.datastore.DatastoreContext)1 DisableElectionsRaftPolicy (org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy)1