use of akka.actor.ActorSystem in project flink by apache.
the class WebRuntimeMonitorITCase method testLeaderNotAvailable.
@Test
public void testLeaderNotAvailable() throws Exception {
final Deadline deadline = TestTimeout.fromNow();
ActorSystem actorSystem = null;
WebRuntimeMonitor webRuntimeMonitor = null;
try (TestingServer zooKeeper = new TestingServer()) {
File logDir = temporaryFolder.newFolder();
Path logFile = Files.createFile(new File(logDir, "jobmanager.log").toPath());
Files.createFile(new File(logDir, "jobmanager.out").toPath());
final Configuration config = new Configuration();
config.setInteger(ConfigConstants.JOB_MANAGER_WEB_PORT_KEY, 0);
config.setString(ConfigConstants.JOB_MANAGER_WEB_LOG_PATH_KEY, logFile.toString());
config.setString(HighAvailabilityOptions.HA_MODE, "ZOOKEEPER");
config.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, zooKeeper.getConnectString());
actorSystem = AkkaUtils.createDefaultActorSystem();
LeaderRetrievalService leaderRetrievalService = mock(LeaderRetrievalService.class);
webRuntimeMonitor = new WebRuntimeMonitor(config, leaderRetrievalService, actorSystem);
webRuntimeMonitor.start("akka://schmakka");
try (HttpTestClient client = new HttpTestClient("localhost", webRuntimeMonitor.getServerPort())) {
client.sendGetRequest("index.html", deadline.timeLeft());
HttpTestClient.SimpleHttpResponse response = client.getNextResponse();
assertEquals(HttpResponseStatus.SERVICE_UNAVAILABLE, response.getStatus());
assertEquals(MimeTypes.getMimeTypeForExtension("txt"), response.getType());
assertTrue(response.getContent().contains("refresh"));
}
} finally {
if (actorSystem != null) {
actorSystem.shutdown();
}
if (webRuntimeMonitor != null) {
webRuntimeMonitor.stop();
}
}
}
use of akka.actor.ActorSystem in project flink by apache.
the class BootstrapTools method startActorSystem.
/**
* Starts an Actor System at a specific port.
* @param configuration The Flink configuration.
* @param listeningAddress The address to listen at.
* @param listeningPort The port to listen at.
* @param logger the logger to output log information.
* @return The ActorSystem which has been started.
* @throws Exception
*/
public static ActorSystem startActorSystem(Configuration configuration, String listeningAddress, int listeningPort, Logger logger) throws Exception {
String hostPortUrl = listeningAddress + ':' + listeningPort;
logger.info("Trying to start actor system at {}", hostPortUrl);
try {
Config akkaConfig = AkkaUtils.getAkkaConfig(configuration, new scala.Some<>(new scala.Tuple2<String, Object>(listeningAddress, listeningPort)));
logger.debug("Using akka configuration\n {}", akkaConfig);
ActorSystem actorSystem = AkkaUtils.createActorSystem(akkaConfig);
logger.info("Actor system started at {}", AkkaUtils.getAddress(actorSystem));
return actorSystem;
} catch (Throwable t) {
if (t instanceof org.jboss.netty.channel.ChannelException) {
Throwable cause = t.getCause();
if (cause != null && t.getCause() instanceof java.net.BindException) {
throw new IOException("Unable to create ActorSystem at address " + hostPortUrl + " : " + cause.getMessage(), t);
}
}
throw new Exception("Could not create actor system", t);
}
}
use of akka.actor.ActorSystem in project flink by apache.
the class FlinkClient method getJobManager.
private ActorRef getJobManager() throws IOException {
final Configuration configuration = GlobalConfiguration.loadConfiguration();
ActorSystem actorSystem;
try {
final scala.Tuple2<String, Object> systemEndpoint = new scala.Tuple2<String, Object>("", 0);
actorSystem = AkkaUtils.createActorSystem(configuration, new Some<scala.Tuple2<String, Object>>(systemEndpoint));
} catch (final Exception e) {
throw new RuntimeException("Could not start actor system to communicate with JobManager", e);
}
return JobManager.getJobManagerActorRef(AkkaUtils.getAkkaProtocol(configuration), NetUtils.unresolvedHostAndPortToNormalizedString(this.jobManagerHost, this.jobManagerPort), actorSystem, AkkaUtils.getLookupTimeout(configuration));
}
use of akka.actor.ActorSystem in project torodb by torodb.
the class DefaultOplogApplier method apply.
@Override
public ApplyingJob apply(OplogFetcher fetcher, ApplierContext applierContext) {
Materializer materializer = ActorMaterializer.create(actorSystem);
RunnableGraph<Pair<UniqueKillSwitch, CompletionStage<Done>>> graph = createOplogSource(fetcher).async().via(createBatcherFlow(applierContext)).viaMat(KillSwitches.single(), Keep.right()).async().map(analyzedElem -> {
for (AnalyzedOplogBatch analyzedOplogBatch : analyzedElem.analyzedBatch) {
batchExecutor.apply(analyzedOplogBatch, applierContext);
}
return analyzedElem;
}).map(this::metricExecution).toMat(Sink.foreach(this::storeLastAppliedOp), (killSwitch, completionStage) -> new Pair<>(killSwitch, completionStage));
Pair<UniqueKillSwitch, CompletionStage<Done>> pair = graph.run(materializer);
UniqueKillSwitch killSwitch = pair.first();
CompletableFuture<Empty> whenComplete = pair.second().toCompletableFuture().thenApply(done -> Empty.getInstance()).whenComplete((done, t) -> {
fetcher.close();
if (done != null) {
LOGGER.trace("Oplog replication stream finished normally");
} else {
Throwable cause;
if (t instanceof CompletionException) {
cause = t.getCause();
} else {
cause = t;
}
//the completable future has been cancelled
if (cause instanceof CancellationException) {
LOGGER.debug("Oplog replication stream has been cancelled");
killSwitch.shutdown();
} else {
//in this case the exception should came from the stream
cause = Throwables.getRootCause(cause);
LOGGER.error("Oplog replication stream finished exceptionally: " + cause.getLocalizedMessage(), cause);
//the stream should be finished exceptionally, but just in case we
//notify the kill switch to stop the stream.
killSwitch.shutdown();
}
}
});
return new DefaultApplyingJob(killSwitch, whenComplete);
}
use of akka.actor.ActorSystem in project flink by apache.
the class SlotPoolRpcTest method setup.
// ------------------------------------------------------------------------
// setup
// ------------------------------------------------------------------------
@BeforeClass
public static void setup() {
ActorSystem actorSystem = AkkaUtils.createLocalActorSystem(new Configuration());
rpcService = new AkkaRpcService(actorSystem, Time.seconds(10));
}
Aggregations