Search in sources :

Example 76 with ActorRef

use of akka.actor.ActorRef in project flink by apache.

the class ChaosMonkeyITCase method requestJobStatus.

private JobStatus requestJobStatus(JobID jobId, JobManagerProcess jobManager, ActorSystem actorSystem, FiniteDuration timeout) throws Exception {
    ActorRef jobManagerRef = jobManager.getActorRef(actorSystem, timeout);
    AkkaActorGateway jobManagerGateway = new AkkaActorGateway(jobManagerRef, null);
    JobManagerMessages.JobStatusResponse resp = JobManagerActorTestUtils.requestJobStatus(jobId, jobManagerGateway, timeout);
    if (resp instanceof JobManagerMessages.CurrentJobStatus) {
        JobManagerMessages.CurrentJobStatus jobStatusResponse = (JobManagerMessages.CurrentJobStatus) resp;
        return jobStatusResponse.status();
    } else if (resp instanceof JobManagerMessages.JobNotFound) {
        return JobStatus.RESTARTING;
    }
    throw new IllegalStateException("Unexpected response from JobManager");
}
Also used : AkkaActorGateway(org.apache.flink.runtime.instance.AkkaActorGateway) ActorRef(akka.actor.ActorRef) JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages)

Example 77 with ActorRef

use of akka.actor.ActorRef in project flink by apache.

the class TaskManagerFailureRecoveryITCase method testRestartWithFailingTaskManager.

@Test
public void testRestartWithFailingTaskManager() {
    final int PARALLELISM = 4;
    LocalFlinkMiniCluster cluster = null;
    ActorSystem additionalSystem = null;
    try {
        Configuration config = new Configuration();
        config.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, 2);
        config.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, PARALLELISM);
        config.setInteger(ConfigConstants.TASK_MANAGER_MEMORY_SIZE_KEY, 16);
        config.setString(ConfigConstants.AKKA_WATCH_HEARTBEAT_INTERVAL, "500 ms");
        config.setString(ConfigConstants.AKKA_WATCH_HEARTBEAT_PAUSE, "20 s");
        config.setInteger(ConfigConstants.AKKA_WATCH_THRESHOLD, 20);
        cluster = new LocalFlinkMiniCluster(config, false);
        cluster.start();
        // for the result
        List<Long> resultCollection = new ArrayList<Long>();
        final ExecutionEnvironment env = ExecutionEnvironment.createRemoteEnvironment("localhost", cluster.getLeaderRPCPort());
        env.setParallelism(PARALLELISM);
        env.setRestartStrategy(RestartStrategies.fixedDelayRestart(1, 1000));
        env.getConfig().disableSysoutLogging();
        env.generateSequence(1, 10).map(new FailingMapper<Long>()).reduce(new ReduceFunction<Long>() {

            @Override
            public Long reduce(Long value1, Long value2) {
                return value1 + value2;
            }
        }).output(new LocalCollectionOutputFormat<Long>(resultCollection));
        // simple reference (atomic does not matter) to pass back an exception from the trigger thread
        final AtomicReference<Throwable> ref = new AtomicReference<Throwable>();
        // trigger the execution from a separate thread, so we are available to temper with the
        // cluster during the execution
        Thread trigger = new Thread("program trigger") {

            @Override
            public void run() {
                try {
                    env.execute();
                } catch (Throwable t) {
                    ref.set(t);
                }
            }
        };
        trigger.setDaemon(true);
        trigger.start();
        // the mappers in turn are waiting
        for (int i = 0; i < PARALLELISM; i++) {
            FailingMapper.TASK_TO_COORD_QUEUE.take();
        }
        // bring up one more task manager and wait for it to appear
        {
            additionalSystem = cluster.startTaskManagerActorSystem(2);
            ActorRef additionalTaskManager = cluster.startTaskManager(2, additionalSystem);
            Object message = TaskManagerMessages.getNotifyWhenRegisteredAtJobManagerMessage();
            Future<Object> future = Patterns.ask(additionalTaskManager, message, 30000);
            try {
                Await.result(future, new FiniteDuration(30000, TimeUnit.MILLISECONDS));
            } catch (TimeoutException e) {
                fail("The additional TaskManager did not come up within 30 seconds");
            }
        }
        // kill the two other TaskManagers
        for (ActorRef tm : cluster.getTaskManagersAsJava()) {
            tm.tell(PoisonPill.getInstance(), null);
        }
        // wait for the next set of mappers (the recovery ones) to come online
        for (int i = 0; i < PARALLELISM; i++) {
            FailingMapper.TASK_TO_COORD_QUEUE.take();
        }
        // tell the mappers that they may continue this time
        for (int i = 0; i < PARALLELISM; i++) {
            FailingMapper.COORD_TO_TASK_QUEUE.add(new Object());
        }
        // wait for the program to finish
        trigger.join();
        if (ref.get() != null) {
            Throwable t = ref.get();
            t.printStackTrace();
            fail("Program execution caused an exception: " + t.getMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        if (additionalSystem != null) {
            additionalSystem.shutdown();
        }
        if (cluster != null) {
            cluster.stop();
        }
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) Configuration(org.apache.flink.configuration.Configuration) ActorRef(akka.actor.ActorRef) ArrayList(java.util.ArrayList) ReduceFunction(org.apache.flink.api.common.functions.ReduceFunction) FiniteDuration(scala.concurrent.duration.FiniteDuration) AtomicReference(java.util.concurrent.atomic.AtomicReference) TimeoutException(java.util.concurrent.TimeoutException) LocalFlinkMiniCluster(org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster) Future(scala.concurrent.Future) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 78 with ActorRef

use of akka.actor.ActorRef in project chuidiang-ejemplos by chuidiang.

the class HelloActorMain method main.

public static void main(String[] args) {
    // an actor needs an ActorSystem
    ActorSystem system = ActorSystem.create("HelloWorldSystem");
    // create and start the actor
    Props actor = Props.create(HelloActor.class);
    ActorRef helloActor = system.actorOf(actor, "HelloActor");
    // send the actor two messages
    helloActor.tell("hello 1", helloActor);
    helloActor.tell("hello 2", helloActor);
    helloActor.tell("hello 3", helloActor);
    // shut down the system
    system.terminate();
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) Props(akka.actor.Props)

Example 79 with ActorRef

use of akka.actor.ActorRef in project chuidiang-ejemplos by chuidiang.

the class Server2Main method main.

public static void main(String[] args) throws InterruptedException {
    // Override the configuration of the port
    // when specified as program argument
    System.setProperty("akka.remote.netty.tcp.port", "5558");
    // Create an Akka system
    ActorSystem system = ActorSystem.create("ClusterSystem", ConfigFactory.defaultApplication());
    // Create an actor that handles cluster domain events
    ActorRef publisher = system.actorOf(Props.create(Publisher.class), "publisher");
    while (true) {
        publisher.tell("Hello", publisher);
        Thread.sleep(1000);
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef)

Aggregations

ActorRef (akka.actor.ActorRef)79 Test (org.junit.Test)53 Configuration (org.apache.flink.configuration.Configuration)43 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)33 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)30 ActorSystem (akka.actor.ActorSystem)28 FiniteDuration (scala.concurrent.duration.FiniteDuration)26 JobID (org.apache.flink.api.common.JobID)22 Props (akka.actor.Props)20 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)18 UUID (java.util.UUID)17 JavaTestKit (akka.testkit.JavaTestKit)16 IOException (java.io.IOException)15 TaskManagerServicesConfiguration (org.apache.flink.runtime.taskexecutor.TaskManagerServicesConfiguration)15 TaskDeploymentDescriptor (org.apache.flink.runtime.deployment.TaskDeploymentDescriptor)13 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)13 TestingLeaderRetrievalService (org.apache.flink.runtime.leaderelection.TestingLeaderRetrievalService)13 File (java.io.File)12 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)12 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)12