Search in sources :

Example 1 with AddReplicasForAllShardsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutput in project controller by opendaylight.

the class ClusterAdminRpcService method addReplicasForAllShards.

@Override
public Future<RpcResult<AddReplicasForAllShardsOutput>> addReplicasForAllShards() {
    LOG.info("Adding replicas for all shards");
    final List<Entry<ListenableFuture<Success>, ShardResultBuilder>> shardResultData = new ArrayList<>();
    Function<String, Object> messageSupplier = AddShardReplica::new;
    sendMessageToManagerForConfiguredShards(DataStoreType.Config, shardResultData, messageSupplier);
    sendMessageToManagerForConfiguredShards(DataStoreType.Operational, shardResultData, messageSupplier);
    return waitForShardResults(shardResultData, shardResults -> new AddReplicasForAllShardsOutputBuilder().setShardResult(shardResults).build(), "Failed to add replica");
}
Also used : Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) ArrayList(java.util.ArrayList) AddReplicasForAllShardsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutputBuilder) Success(akka.actor.Status.Success)

Example 2 with AddReplicasForAllShardsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutput 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)

Aggregations

Success (akka.actor.Status.Success)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 MemberNode (org.opendaylight.controller.cluster.datastore.MemberNode)1 ModuleShardConfiguration (org.opendaylight.controller.cluster.datastore.config.ModuleShardConfiguration)1 CreateShard (org.opendaylight.controller.cluster.datastore.messages.CreateShard)1 AddReplicasForAllShardsOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutput)1 AddReplicasForAllShardsOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.AddReplicasForAllShardsOutputBuilder)1