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());
}
}
}
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();
}
}
}
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();
}
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);
}
}
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");
}
Aggregations