Search in sources :

Example 46 with Service

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);
}
Also used : RemovePrefixShardReplicaInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemovePrefixShardReplicaInputBuilder) RemovePrefixShardReplicaInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.RemovePrefixShardReplicaInput)

Example 47 with Service

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));
}
Also used : MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) ChangeMemberVotingStatesForAllShardsInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsInputBuilder) MemberVotingStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.member.voting.states.input.MemberVotingStateBuilder) ChangeMemberVotingStatesForAllShardsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ChangeMemberVotingStatesForAllShardsOutput) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 48 with Service

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());
}
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 49 with Service

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)));
}
Also used : MakeLeaderLocalInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.MakeLeaderLocalInputBuilder)

Example 50 with Service

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());
}
Also used : Logger(org.slf4j.Logger) NotificationService(org.opendaylight.controller.sal.binding.api.NotificationService) OutOfPixieDustNotificationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotificationBuilder) Assert.assertNotNull(org.junit.Assert.assertNotNull) LoggerFactory(org.slf4j.LoggerFactory) Test(org.junit.Test) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) NotificationProviderService(org.opendaylight.controller.sal.binding.api.NotificationProviderService) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) ArrayList(java.util.ArrayList) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) OpendaylightTestNotificationListener(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OpendaylightTestNotificationListener) List(java.util.List) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) OutOfPixieDustNotification(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotification) NotificationListener(org.opendaylight.yangtools.yang.binding.NotificationListener) Assert.assertEquals(org.junit.Assert.assertEquals) ProviderContext(org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext) BindingAwareProvider(org.opendaylight.controller.sal.binding.api.BindingAwareProvider) NotificationProviderService(org.opendaylight.controller.sal.binding.api.NotificationProviderService) NotificationService(org.opendaylight.controller.sal.binding.api.NotificationService) BindingAwareConsumer(org.opendaylight.controller.sal.binding.api.BindingAwareConsumer) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)36 BigInteger (java.math.BigInteger)33 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)22 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)22 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)21 ExecutionException (java.util.concurrent.ExecutionException)19 CoreException (org.eclipse.core.runtime.CoreException)18 List (java.util.List)15 Test (org.junit.Test)15 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)15 Logger (org.slf4j.Logger)14 LoggerFactory (org.slf4j.LoggerFactory)14 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)13 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)12 BoundServices (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices)12 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)10 ServerPort (org.eclipse.wst.server.core.ServerPort)9 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)9 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)9 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)9