use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method removePrefixShardReplica.
private void removePrefixShardReplica(final MemberNode memberNode, final InstanceIdentifier<?> identifier, final String removeFromMember, final BindingNormalizedNodeSerializer serializer, final String shardName, final String... peerMemberNames) throws Exception {
final RemovePrefixShardReplicaInput input = new RemovePrefixShardReplicaInputBuilder().setDataStoreType(DataStoreType.Config).setShardPrefix(identifier).setMemberName(removeFromMember).build();
final ClusterAdminRpcService service = new ClusterAdminRpcService(memberNode.configDataStore(), memberNode.operDataStore(), serializer);
final RpcResult<Void> rpcResult = service.removePrefixShardReplica(input).get(10, TimeUnit.SECONDS);
verifySuccessfulRpcResult(rpcResult);
verifyRaftPeersPresent(memberNode.configDataStore(), shardName, peerMemberNames);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method testChangeMemberVotingStatesForAllShards.
@Test
public void testChangeMemberVotingStatesForAllShards() throws Exception {
String name = "testChangeMemberVotingStatesForAllShards";
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();
leaderNode1.operDataStore().waitTillReady();
replicaNode3.configDataStore().waitTillReady();
replicaNode3.operDataStore().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");
// Invoke RPC service on member-3 to change voting status
ClusterAdminRpcService service3 = new ClusterAdminRpcService(replicaNode3.configDataStore(), replicaNode3.operDataStore(), null);
RpcResult<ChangeMemberVotingStatesForAllShardsOutput> rpcResult = service3.changeMemberVotingStatesForAllShards(new ChangeMemberVotingStatesForAllShardsInputBuilder().setMemberVotingState(ImmutableList.of(new MemberVotingStateBuilder().setMemberName("member-2").setVoting(FALSE).build(), new MemberVotingStateBuilder().setMemberName("member-3").setVoting(FALSE).build())).build()).get(10, TimeUnit.SECONDS);
ChangeMemberVotingStatesForAllShardsOutput result = verifySuccessfulRpcResult(rpcResult);
verifyShardResults(result.getShardResult(), successShardResult("cars", DataStoreType.Config), successShardResult("people", DataStoreType.Config), successShardResult("cars", DataStoreType.Operational), successShardResult("people", DataStoreType.Operational));
verifyVotingStates(new AbstractDataStore[] { leaderNode1.configDataStore(), leaderNode1.operDataStore(), replicaNode2.configDataStore(), replicaNode2.operDataStore(), replicaNode3.configDataStore(), replicaNode3.operDataStore() }, new String[] { "cars", "people" }, new SimpleEntry<>("member-1", TRUE), new SimpleEntry<>("member-2", FALSE), new SimpleEntry<>("member-3", FALSE));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service 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.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method doMakeShardLeaderLocal.
private static void doMakeShardLeaderLocal(final MemberNode memberNode, String shardName, String newLeader) throws Exception {
ClusterAdminRpcService service = new ClusterAdminRpcService(memberNode.configDataStore(), memberNode.operDataStore(), null);
final RpcResult<Void> rpcResult = service.makeLeaderLocal(new MakeLeaderLocalInputBuilder().setDataStoreType(DataStoreType.Config).setShardName(shardName).build()).get(10, TimeUnit.SECONDS);
verifySuccessfulRpcResult(rpcResult);
verifyRaftState(memberNode.configDataStore(), shardName, raftState -> assertThat(raftState.getLeader(), containsString(newLeader)));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.policy.rev170207.Service in project controller by opendaylight.
the class NotificationIT method notificationTest.
/**
* test of delivering of notification
* @throws Exception
*/
@Test
public void notificationTest() throws Exception {
LOG.info("The registration of the Provider 1.");
AbstractTestProvider provider1 = new AbstractTestProvider() {
@Override
public void onSessionInitiated(ProviderContext session) {
notifyProviderService = session.getSALService(NotificationProviderService.class);
}
};
// registerProvider method calls onSessionInitiated method above
broker.registerProvider(provider1);
assertNotNull(notifyProviderService);
LOG.info("The registration of the Consumer 1. It retrieves Notification Service " + "from MD-SAL and registers OpendaylightTestNotificationListener as notification listener");
BindingAwareConsumer consumer1 = session -> {
NotificationService notificationService = session.getSALService(NotificationService.class);
assertNotNull(notificationService);
listener1Reg = notificationService.registerNotificationListener(listener1);
};
// registerConsumer method calls onSessionInitialized method above
broker.registerConsumer(consumer1);
assertNotNull(listener1Reg);
LOG.info("The notification of type FlowAdded with cookie ID 0 is created. The " + "delay 100ms to make sure that the notification was delivered to " + "listener.");
notifyProviderService.publish(noDustNotification("rainy day", 42));
Thread.sleep(100);
/**
* Check that one notification was delivered and has correct cookie.
*/
assertEquals(1, listener1.notificationBag.size());
assertEquals("rainy day", listener1.notificationBag.get(0).getReason());
assertEquals(42, listener1.notificationBag.get(0).getDaysTillNewDust().intValue());
LOG.info("The registration of the Consumer 2. SalFlowListener is registered " + "registered as notification listener.");
BindingAwareProvider provider = session -> listener2Reg = session.getSALService(NotificationProviderService.class).registerNotificationListener(listener2);
// registerConsumer method calls onSessionInitialized method above
broker.registerProvider(provider);
LOG.info("3 notifications are published");
notifyProviderService.publish(noDustNotification("rainy day", 5));
notifyProviderService.publish(noDustNotification("rainy day", 10));
notifyProviderService.publish(noDustNotification("tax collector", 2));
/**
* The delay 100ms to make sure that the notifications were delivered to
* listeners.
*/
Thread.sleep(100);
/**
* Check that 3 notification was delivered to both listeners (first one
* received 4 in total, second 3 in total).
*/
assertEquals(4, listener1.notificationBag.size());
assertEquals(3, listener2.notificationBag.size());
/**
* The second listener is closed (unregistered)
*/
listener2Reg.close();
LOG.info("The notification 5 is published");
notifyProviderService.publish(noDustNotification("entomologist hunt", 10));
/**
* The delay 100ms to make sure that the notification was delivered to
* listener.
*/
Thread.sleep(100);
/**
* Check that first consumer received 5 notifications in total, second
* consumer received only three. Last notification was never received by
* second consumer because its listener was unregistered.
*/
assertEquals(5, listener1.notificationBag.size());
assertEquals(3, listener2.notificationBag.size());
}
Aggregations