Search in sources :

Example 71 with ActorSystem

use of akka.actor.ActorSystem in project webofneeds by researchstudio-sat.

the class AkkaRescalMain method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MatcherRescalAppConfiguration.class);
    ActorSystem system = ctx.getBean(ActorSystem.class);
    system.actorOf(SpringExtension.SpringExtProvider.get(system).props(RescalMatcherActor.class), "RescalMatcherActor");
}
Also used : ActorSystem(akka.actor.ActorSystem) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RescalMatcherActor(won.matcher.rescal.actor.RescalMatcherActor)

Example 72 with ActorSystem

use of akka.actor.ActorSystem in project webofneeds by researchstudio-sat.

the class MatcherRescalAppConfiguration method actorSystem.

/**
 * Actor system singleton for this application.
 */
@Bean
public ActorSystem actorSystem() {
    // load the Akka configuration
    String seedNodes = "[";
    for (String seed : clusterConfig.getSeedNodes()) {
        seedNodes += "\"akka.tcp://" + clusterConfig.getName() + "@" + seed.trim() + "\",";
    }
    seedNodes += "]";
    final Config applicationConf = ConfigFactory.load();
    final Config config = ConfigFactory.parseString("akka.cluster.seed-nodes=" + seedNodes).withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.bind-port=" + clusterConfig.getLocalPort())).withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + clusterConfig.getNodeHost())).withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.port=" + clusterConfig.getLocalPort())).withFallback(ConfigFactory.parseString("akka.cluster.roles=[matcher]")).withFallback(ConfigFactory.load(applicationConf));
    ActorSystem system = ActorSystem.create(clusterConfig.getName(), config);
    LoggingAdapter log = Logging.getLogger(system, this);
    log.info("Using Akka system settings: " + system.settings().toString());
    // initialize the application context in the Akka Spring Extension
    SpringExtension.SpringExtProvider.get(system).initialize(applicationContext);
    return system;
}
Also used : ActorSystem(akka.actor.ActorSystem) Config(com.typesafe.config.Config) ClusterConfig(won.matcher.service.common.config.ClusterConfig) LoggingAdapter(akka.event.LoggingAdapter) Bean(org.springframework.context.annotation.Bean)

Example 73 with ActorSystem

use of akka.actor.ActorSystem in project webofneeds by researchstudio-sat.

the class MatcherServiceAppConfiguration method actorSystem.

/**
 * Actor system singleton for this application.
 */
@Bean
public ActorSystem actorSystem() {
    // load the Akka configuration
    String seedNodes = "[";
    for (String seed : clusterConfig.getSeedNodes()) {
        seedNodes += "\"akka.tcp://" + clusterConfig.getName() + "@" + seed.trim() + "\",";
    }
    seedNodes += "]";
    final Config applicationConf = ConfigFactory.load();
    final Config config = ConfigFactory.parseString("akka.cluster.seed-nodes=" + seedNodes).withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.bind-port=" + clusterConfig.getLocalPort())).withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.hostname=" + clusterConfig.getNodeHost())).withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.port=" + clusterConfig.getLocalPort())).withFallback(ConfigFactory.parseString("akka.cluster.roles=[core]")).withFallback(ConfigFactory.load(applicationConf));
    ActorSystem system = ActorSystem.create(clusterConfig.getName(), config);
    LoggingAdapter log = Logging.getLogger(system, this);
    log.info("Using Akka system settings: " + system.settings().toString());
    // initialize the application context in the Akka Spring Extension
    SpringExtension.SpringExtProvider.get(system).initialize(applicationContext);
    return system;
}
Also used : ActorSystem(akka.actor.ActorSystem) Config(com.typesafe.config.Config) ClusterConfig(won.matcher.service.common.config.ClusterConfig) LoggingAdapter(akka.event.LoggingAdapter)

Example 74 with ActorSystem

use of akka.actor.ActorSystem in project controller by opendaylight.

the class ShardManagerTest method testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable.

@Test
public void testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable() throws Exception {
    LOG.info("testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable starting");
    String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
    MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-256", "member-2")).build());
    // Create an ActorSystem, ShardManager and actor for member-256.
    final ActorSystem system256 = newActorSystem("Member256");
    // 2562 is the tcp port of Member256 in src/test/resources/application.conf.
    Cluster.get(system256).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2562"));
    final ActorRef mockShardActor256 = newMockShardActor(system256, Shard.DEFAULT_NAME, "member-256");
    final PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
    // ShardManager must be created with shard configuration to let its localShards has shards.
    final TestActorRef<TestShardManager> shardManager256 = TestActorRef.create(system256, newTestShardMgrBuilder(mockConfig).shardActor(mockShardActor256).cluster(new ClusterWrapperImpl(system256)).primaryShardInfoCache(primaryShardInfoCache).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    // Create an ActorSystem, ShardManager and actor for member-2 whose name is contained in member-256.
    final ActorSystem system2 = newActorSystem("Member2");
    // Join member-2 into the cluster of member-256.
    Cluster.get(system2).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2562"));
    final ActorRef mockShardActor2 = newMockShardActor(system2, Shard.DEFAULT_NAME, "member-2");
    final TestActorRef<TestShardManager> shardManager2 = TestActorRef.create(system2, newTestShardMgrBuilder(mockConfig).shardActor(mockShardActor2).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    new TestKit(system256) {

        {
            shardManager256.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager2.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager256.tell(new ActorInitialized(), mockShardActor256);
            shardManager2.tell(new ActorInitialized(), mockShardActor2);
            String memberId256 = "member-256-shard-default-" + shardMrgIDSuffix;
            String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
            shardManager256.tell(new ShardLeaderStateChanged(memberId256, memberId256, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor256);
            shardManager256.tell(new RoleChangeNotification(memberId256, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor256);
            shardManager2.tell(new ShardLeaderStateChanged(memberId2, memberId256, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor2);
            shardManager2.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor2);
            shardManager256.underlyingActor().waitForMemberUp();
            shardManager256.tell(new FindPrimary("default", true), getRef());
            LocalPrimaryShardFound found = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
            String path = found.getPrimaryPath();
            assertTrue("Unexpected primary path " + path + " which must on member-256", path.contains("member-256-shard-default-config"));
            PrimaryShardInfo primaryShardInfo = new PrimaryShardInfo(system256.actorSelection(mockShardActor256.path()), DataStoreVersions.CURRENT_VERSION);
            primaryShardInfoCache.putSuccessful("default", primaryShardInfo);
            // Simulate member-2 become unreachable.
            shardManager256.tell(MockClusterWrapper.createUnreachableMember("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
            shardManager256.underlyingActor().waitForUnreachableMember();
            // Make sure leader shard on member-256 is still leader and still in the cache.
            shardManager256.tell(new FindPrimary("default", true), getRef());
            found = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
            path = found.getPrimaryPath();
            assertTrue("Unexpected primary path " + path + " which must still not on member-256", path.contains("member-256-shard-default-config"));
            Future<PrimaryShardInfo> futurePrimaryShard = primaryShardInfoCache.getIfPresent("default");
            futurePrimaryShard.onComplete(new OnComplete<PrimaryShardInfo>() {

                @Override
                public void onComplete(final Throwable failure, final PrimaryShardInfo futurePrimaryShardInfo) {
                    if (failure != null) {
                        assertTrue("Primary shard info is unexpectedly removed from primaryShardInfoCache", false);
                    } else {
                        assertEquals("Expected primaryShardInfoCache entry", primaryShardInfo, futurePrimaryShardInfo);
                    }
                }
            }, system256.dispatchers().defaultGlobalDispatcher());
        }
    };
    LOG.info("testShardAvailabilityChangeOnMemberWithNameContainedInLeaderIdUnreachable ending");
}
Also used : ActorSystem(akka.actor.ActorSystem) ClusterWrapperImpl(org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) AddressFromURIString(akka.actor.AddressFromURIString) TestKit(akka.testkit.javadsl.TestKit) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) LocalPrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) PrimaryShardInfoFutureCache(org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 75 with ActorSystem

use of akka.actor.ActorSystem in project controller by opendaylight.

the class ShardManagerTest method testShardAvailabilityOnChangeOfMemberReachability.

@Test
public void testShardAvailabilityOnChangeOfMemberReachability() throws Exception {
    LOG.info("testShardAvailabilityOnChangeOfMemberReachability starting");
    String shardManagerID = ShardManagerIdentifier.builder().type(shardMrgIDSuffix).build().toString();
    // Create an ActorSystem ShardManager actor for member-1.
    final ActorSystem system1 = newActorSystem("Member1");
    Cluster.get(system1).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
    final ActorRef mockShardActor1 = newMockShardActor(system1, Shard.DEFAULT_NAME, "member-1");
    final TestActorRef<TestShardManager> shardManager1 = TestActorRef.create(system1, newTestShardMgrBuilder().shardActor(mockShardActor1).cluster(new ClusterWrapperImpl(system1)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    // Create an ActorSystem ShardManager actor for member-2.
    final ActorSystem system2 = newActorSystem("Member2");
    Cluster.get(system2).join(AddressFromURIString.parse("akka://cluster-test@127.0.0.1:2558"));
    final ActorRef mockShardActor2 = newMockShardActor(system2, Shard.DEFAULT_NAME, "member-2");
    MockConfiguration mockConfig2 = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).build());
    final TestActorRef<TestShardManager> shardManager2 = TestActorRef.create(system2, newTestShardMgrBuilder(mockConfig2).shardActor(mockShardActor2).cluster(new ClusterWrapperImpl(system2)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardManagerID);
    new TestKit(system1) {

        {
            shardManager1.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager2.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager1.tell(new ActorInitialized(), mockShardActor1);
            shardManager2.tell(new ActorInitialized(), mockShardActor2);
            String memberId2 = "member-2-shard-default-" + shardMrgIDSuffix;
            String memberId1 = "member-1-shard-default-" + shardMrgIDSuffix;
            shardManager1.tell(new ShardLeaderStateChanged(memberId1, memberId2, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor1);
            shardManager1.tell(new RoleChangeNotification(memberId1, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor1);
            shardManager2.tell(new ShardLeaderStateChanged(memberId2, memberId2, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), mockShardActor2);
            shardManager2.tell(new RoleChangeNotification(memberId2, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor2);
            shardManager1.underlyingActor().waitForMemberUp();
            shardManager1.tell(new FindPrimary("default", true), getRef());
            RemotePrimaryShardFound found = expectMsgClass(duration("5 seconds"), RemotePrimaryShardFound.class);
            String path = found.getPrimaryPath();
            assertTrue("Unexpected primary path " + path, path.contains("member-2-shard-default-config"));
            shardManager1.tell(MockClusterWrapper.createUnreachableMember("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
            shardManager1.underlyingActor().waitForUnreachableMember();
            PeerDown peerDown = MessageCollectorActor.expectFirstMatching(mockShardActor1, PeerDown.class);
            assertEquals("getMemberName", MEMBER_2, peerDown.getMemberName());
            MessageCollectorActor.clearMessages(mockShardActor1);
            shardManager1.tell(MockClusterWrapper.createMemberRemoved("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
            MessageCollectorActor.expectFirstMatching(mockShardActor1, PeerDown.class);
            shardManager1.tell(new FindPrimary("default", true), getRef());
            expectMsgClass(duration("5 seconds"), NoShardLeaderException.class);
            shardManager1.tell(MockClusterWrapper.createReachableMember("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
            shardManager1.underlyingActor().waitForReachableMember();
            PeerUp peerUp = MessageCollectorActor.expectFirstMatching(mockShardActor1, PeerUp.class);
            assertEquals("getMemberName", MEMBER_2, peerUp.getMemberName());
            MessageCollectorActor.clearMessages(mockShardActor1);
            shardManager1.tell(new FindPrimary("default", true), getRef());
            RemotePrimaryShardFound found1 = expectMsgClass(duration("5 seconds"), RemotePrimaryShardFound.class);
            String path1 = found1.getPrimaryPath();
            assertTrue("Unexpected primary path " + path1, path1.contains("member-2-shard-default-config"));
            shardManager1.tell(MockClusterWrapper.createMemberUp("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
            MessageCollectorActor.expectFirstMatching(mockShardActor1, PeerUp.class);
            // Test FindPrimary wait succeeds after reachable member event.
            shardManager1.tell(MockClusterWrapper.createUnreachableMember("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
            shardManager1.underlyingActor().waitForUnreachableMember();
            shardManager1.tell(new FindPrimary("default", true), getRef());
            shardManager1.tell(MockClusterWrapper.createReachableMember("member-2", "akka://cluster-test@127.0.0.1:2558"), getRef());
            RemotePrimaryShardFound found2 = expectMsgClass(duration("5 seconds"), RemotePrimaryShardFound.class);
            String path2 = found2.getPrimaryPath();
            assertTrue("Unexpected primary path " + path2, path2.contains("member-2-shard-default-config"));
        }
    };
    LOG.info("testShardAvailabilityOnChangeOfMemberReachability ending");
}
Also used : ActorSystem(akka.actor.ActorSystem) ClusterWrapperImpl(org.opendaylight.controller.cluster.datastore.ClusterWrapperImpl) UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) AddressFromURIString(akka.actor.AddressFromURIString) TestKit(akka.testkit.javadsl.TestKit) RemotePrimaryShardFound(org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound) FindPrimary(org.opendaylight.controller.cluster.datastore.messages.FindPrimary) PeerDown(org.opendaylight.controller.cluster.datastore.messages.PeerDown) MockConfiguration(org.opendaylight.controller.cluster.datastore.utils.MockConfiguration) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) PeerUp(org.opendaylight.controller.cluster.datastore.messages.PeerUp) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Aggregations

ActorSystem (akka.actor.ActorSystem)91 ActorRef (akka.actor.ActorRef)54 Test (org.junit.Test)51 Configuration (org.apache.flink.configuration.Configuration)27 FiniteDuration (scala.concurrent.duration.FiniteDuration)12 File (java.io.File)11 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)11 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)11 Props (akka.actor.Props)10 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)10 TestActorRef (akka.testkit.TestActorRef)8 IOException (java.io.IOException)8 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)8 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)8 Deadline (scala.concurrent.duration.Deadline)8 AddressFromURIString (akka.actor.AddressFromURIString)7 ActorMaterializer (akka.stream.ActorMaterializer)7 Materializer (akka.stream.Materializer)7 Sink (akka.stream.javadsl.Sink)7 Source (akka.stream.javadsl.Source)7