Search in sources :

Example 66 with ActorSystem

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

the class JobManagerTest method testCancelWithSavepointNoDirectoriesConfigured.

/**
	 * Tests that a meaningful exception is returned if no savepoint directory is
	 * configured.
	 */
@Test
public void testCancelWithSavepointNoDirectoriesConfigured() throws Exception {
    FiniteDuration timeout = new FiniteDuration(30, TimeUnit.SECONDS);
    Configuration config = new Configuration();
    ActorSystem actorSystem = null;
    ActorGateway jobManager = null;
    ActorGateway archiver = null;
    ActorGateway taskManager = null;
    try {
        actorSystem = AkkaUtils.createLocalActorSystem(new Configuration());
        Tuple2<ActorRef, ActorRef> master = JobManager.startJobManagerActors(config, actorSystem, TestingUtils.defaultExecutor(), TestingUtils.defaultExecutor(), Option.apply("jm"), Option.apply("arch"), TestingJobManager.class, TestingMemoryArchivist.class);
        jobManager = new AkkaActorGateway(master._1(), null);
        archiver = new AkkaActorGateway(master._2(), null);
        ActorRef taskManagerRef = TaskManager.startTaskManagerComponentsAndActor(config, ResourceID.generate(), actorSystem, "localhost", Option.apply("tm"), Option.<LeaderRetrievalService>apply(new StandaloneLeaderRetrievalService(jobManager.path())), true, TestingTaskManager.class);
        taskManager = new AkkaActorGateway(taskManagerRef, null);
        // Wait until connected
        Object msg = new TestingTaskManagerMessages.NotifyWhenRegisteredAtJobManager(jobManager.actor());
        Await.ready(taskManager.ask(msg, timeout), timeout);
        // Create job graph
        JobVertex sourceVertex = new JobVertex("Source");
        sourceVertex.setInvokableClass(BlockingStatefulInvokable.class);
        sourceVertex.setParallelism(1);
        JobGraph jobGraph = new JobGraph("TestingJob", sourceVertex);
        JobSnapshottingSettings snapshottingSettings = new JobSnapshottingSettings(Collections.singletonList(sourceVertex.getID()), Collections.singletonList(sourceVertex.getID()), Collections.singletonList(sourceVertex.getID()), 3600000, 3600000, 0, Integer.MAX_VALUE, ExternalizedCheckpointSettings.none(), null, true);
        jobGraph.setSnapshotSettings(snapshottingSettings);
        // Submit job graph
        msg = new JobManagerMessages.SubmitJob(jobGraph, ListeningBehaviour.DETACHED);
        Await.result(jobManager.ask(msg, timeout), timeout);
        // Wait for all tasks to be running
        msg = new TestingJobManagerMessages.WaitForAllVerticesToBeRunning(jobGraph.getJobID());
        Await.result(jobManager.ask(msg, timeout), timeout);
        // Cancel with savepoint
        msg = new JobManagerMessages.CancelJobWithSavepoint(jobGraph.getJobID(), null);
        CancellationResponse cancelResp = (CancellationResponse) Await.result(jobManager.ask(msg, timeout), timeout);
        if (cancelResp instanceof CancellationFailure) {
            CancellationFailure failure = (CancellationFailure) cancelResp;
            assertTrue(failure.cause() instanceof IllegalStateException);
            assertTrue(failure.cause().getMessage().contains("savepoint directory"));
        } else {
            fail("Unexpected cancellation response from JobManager: " + cancelResp);
        }
    } finally {
        if (actorSystem != null) {
            actorSystem.shutdown();
        }
        if (archiver != null) {
            archiver.actor().tell(PoisonPill.getInstance(), ActorRef.noSender());
        }
        if (jobManager != null) {
            jobManager.actor().tell(PoisonPill.getInstance(), ActorRef.noSender());
        }
        if (taskManager != null) {
            taskManager.actor().tell(PoisonPill.getInstance(), ActorRef.noSender());
        }
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) AkkaActorGateway(org.apache.flink.runtime.instance.AkkaActorGateway) Configuration(org.apache.flink.configuration.Configuration) ActorRef(akka.actor.ActorRef) JobSnapshottingSettings(org.apache.flink.runtime.jobgraph.tasks.JobSnapshottingSettings) JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) TestingJobManagerMessages(org.apache.flink.runtime.testingUtils.TestingJobManagerMessages) FiniteDuration(scala.concurrent.duration.FiniteDuration) SubmitJob(org.apache.flink.runtime.messages.JobManagerMessages.SubmitJob) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) TestingJobManagerMessages(org.apache.flink.runtime.testingUtils.TestingJobManagerMessages) StandaloneLeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.StandaloneLeaderRetrievalService) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) AkkaActorGateway(org.apache.flink.runtime.instance.AkkaActorGateway) CancellationFailure(org.apache.flink.runtime.messages.JobManagerMessages.CancellationFailure) WaitForAllVerticesToBeRunning(org.apache.flink.runtime.testingUtils.TestingJobManagerMessages.WaitForAllVerticesToBeRunning) CancellationResponse(org.apache.flink.runtime.messages.JobManagerMessages.CancellationResponse) Test(org.junit.Test)

Example 67 with ActorSystem

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

the class JobManagerProcessReapingTest method testReapProcessOnFailure.

@Test
public void testReapProcessOnFailure() {
    Process jmProcess = null;
    ActorSystem localSystem = null;
    final StringWriter processOutput = new StringWriter();
    try {
        String javaCommand = getJavaCommandPath();
        // is available on this machine
        if (javaCommand == null) {
            System.out.println("---- Skipping JobManagerProcessReapingTest : Could not find java executable ----");
            return;
        }
        // create a logging file for the process
        File tempLogFile = File.createTempFile("testlogconfig", "properties");
        tempLogFile.deleteOnExit();
        CommonTestUtils.printLog4jDebugConfig(tempLogFile);
        // start a JobManger process
        // the log level must be at least INFO, otherwise the bound port cannot be retrieved
        String[] command = new String[] { javaCommand, "-Dlog.level=DEBUG", "-Dlog4j.configuration=file:" + tempLogFile.getAbsolutePath(), "-Xms256m", "-Xmx256m", "-classpath", getCurrentClasspath(), JobManagerTestEntryPoint.class.getName() };
        // spawn the process and collect its output
        ProcessBuilder bld = new ProcessBuilder(command);
        jmProcess = bld.start();
        new PipeForwarder(jmProcess.getErrorStream(), processOutput);
        // start another actor system so we can send something to the JobManager
        Tuple2<String, Object> localAddress = new Tuple2<String, Object>("localhost", 0);
        localSystem = AkkaUtils.createActorSystem(new Configuration(), new Some<Tuple2<String, Object>>(localAddress));
        // grab the reference to the JobManager. try multiple times, until the process
        // is started and the JobManager is up
        ActorRef jobManagerRef = null;
        Throwable lastError = null;
        // Log message on JobManager must be: Starting JobManager at ...://flink@...:port/..."
        // otherwise, the pattern does not match and, thus, cannot retrieve the bound port
        String pattern = "Starting JobManager at [^:]*://flink@[^:]*:(\\d*)/";
        Pattern r = Pattern.compile(pattern);
        int jobManagerPort = -1;
        for (int i = 0; i < 40; i++) {
            Matcher m = r.matcher(processOutput.toString());
            if (m.find()) {
                jobManagerPort = Integer.parseInt(m.group(1));
                break;
            }
            Thread.sleep(500);
        }
        if (jobManagerPort != -1) {
            try {
                jobManagerRef = JobManager.getJobManagerActorRef("akka.tcp", NetUtils.unresolvedHostAndPortToNormalizedString("localhost", jobManagerPort), localSystem, new FiniteDuration(25, TimeUnit.SECONDS));
            } catch (Throwable t) {
                // job manager probably not ready yet
                lastError = t;
            }
        } else {
            fail("Could not determine port of started JobManager.");
        }
        assertTrue("JobManager process died", isProcessAlive(jmProcess));
        if (jobManagerRef == null) {
            if (lastError != null) {
                lastError.printStackTrace();
            }
            fail("JobManager process did not launch the JobManager properly. Failed to look up JobManager actor at" + " localhost:" + jobManagerPort);
        }
        // kill the JobManager actor
        jobManagerRef.tell(PoisonPill.getInstance(), ActorRef.noSender());
        // wait for max 5 seconds for the process to terminate
        {
            long now = System.currentTimeMillis();
            long deadline = now + 5000;
            while (now < deadline && isProcessAlive(jmProcess)) {
                Thread.sleep(100);
                now = System.currentTimeMillis();
            }
        }
        assertFalse("JobManager process did not terminate upon actor death", isProcessAlive(jmProcess));
        int returnCode = jmProcess.exitValue();
        assertEquals("JobManager died, but not because of the process reaper", JobManager.RUNTIME_FAILURE_RETURN_CODE(), returnCode);
    } catch (Exception e) {
        e.printStackTrace();
        printProcessLog(processOutput.toString());
        fail(e.getMessage());
    } catch (Error e) {
        e.printStackTrace();
        printProcessLog(processOutput.toString());
        throw e;
    } finally {
        if (jmProcess != null) {
            jmProcess.destroy();
        }
        if (localSystem != null) {
            localSystem.shutdown();
        }
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) Pattern(java.util.regex.Pattern) Configuration(org.apache.flink.configuration.Configuration) Matcher(java.util.regex.Matcher) ActorRef(akka.actor.ActorRef) FiniteDuration(scala.concurrent.duration.FiniteDuration) IOException(java.io.IOException) Some(scala.Some) StringWriter(java.io.StringWriter) Tuple2(scala.Tuple2) File(java.io.File) Test(org.junit.Test)

Example 68 with ActorSystem

use of akka.actor.ActorSystem 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 69 with ActorSystem

use of akka.actor.ActorSystem 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)

Example 70 with ActorSystem

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

the class AkkaSolrMain method main.

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

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