use of akka.actor.ActorSystem in project modules.playframework.org by playframework.
the class Global method scheduleJobs.
public void scheduleJobs() {
ActorSystem actorSystem = Akka.system();
ActorRef feedCreationActor = actorSystem.actorOf(new Props(FeedCreationActor.class));
actorSystem.scheduler().schedule(Duration.create(0, TimeUnit.MILLISECONDS), Duration.create(1, TimeUnit.HOURS), feedCreationActor, "generate");
}
use of akka.actor.ActorSystem in project modules.playframework.org by playframework.
the class AbstractController method createHistoricalEvent.
public static void createHistoricalEvent(String category, String message) {
HistoricalEvent historicalEvent = new HistoricalEvent();
historicalEvent.creationDate = new Date();
historicalEvent.category = category;
historicalEvent.message = message;
ActorSystem actorSystem = Akka.system();
ActorRef actor = actorSystem.actorOf(new Props(HistoricalEventActor.class));
actor.tell(historicalEvent);
}
use of akka.actor.ActorSystem in project SSM by Intel-bigdata.
the class TestSmartAgent method testAgent.
@Test
public void testAgent() throws InterruptedException {
ActorSystem system = getActorSystem();
final int num = 2;
JavaTestKit[] masters = new JavaTestKit[num];
String[] masterPaths = new String[num];
for (int i = 0; i < num; i++) {
masters[i] = new JavaTestKit(system);
masterPaths[i] = AgentUtils.getFullPath(system, masters[i].getRef().path());
}
SmartConf conf = new SmartConf();
AgentRunner runner = new AgentRunner(AgentUtils.overrideRemoteAddress(ConfigFactory.load(AgentConstants.AKKA_CONF_FILE), conf.get(SmartConfKeys.SMART_AGENT_ADDRESS_KEY)), masterPaths);
runner.start();
masters[0].expectMsgClass(RegisterNewAgent.class);
masters[0].reply(new MasterToAgent.AgentRegistered(new MasterToAgent.AgentId("test")));
system.stop(masters[0].getRef());
masters[1].expectMsgClass(RegisterNewAgent.class);
}
use of akka.actor.ActorSystem in project flink by apache.
the class MetricFetcherTest method testUpdate.
@Test
public void testUpdate() throws Exception {
// ========= setup TaskManager =================================================================================
JobID jobID = new JobID();
InstanceID tmID = new InstanceID();
ResourceID tmRID = new ResourceID(tmID.toString());
TaskManagerGateway taskManagerGateway = mock(TaskManagerGateway.class);
when(taskManagerGateway.getAddress()).thenReturn("/tm/address");
Instance taskManager = mock(Instance.class);
when(taskManager.getTaskManagerGateway()).thenReturn(taskManagerGateway);
when(taskManager.getId()).thenReturn(tmID);
when(taskManager.getTaskManagerID()).thenReturn(tmRID);
// ========= setup JobManager ==================================================================================
JobDetails details = mock(JobDetails.class);
when(details.getJobId()).thenReturn(jobID);
ActorGateway jobManagerGateway = mock(ActorGateway.class);
Object registeredTaskManagersAnswer = new JobManagerMessages.RegisteredTaskManagers(JavaConverters.collectionAsScalaIterableConverter(Collections.singletonList(taskManager)).asScala());
when(jobManagerGateway.ask(isA(RequestJobDetails.class), any(FiniteDuration.class))).thenReturn(Future$.MODULE$.successful((Object) new MultipleJobsDetails(new JobDetails[0], new JobDetails[0])));
when(jobManagerGateway.ask(isA(JobManagerMessages.RequestRegisteredTaskManagers$.class), any(FiniteDuration.class))).thenReturn(Future$.MODULE$.successful(registeredTaskManagersAnswer));
when(jobManagerGateway.path()).thenReturn("/jm/address");
JobManagerRetriever retriever = mock(JobManagerRetriever.class);
when(retriever.getJobManagerGatewayAndWebPort()).thenReturn(Option.apply(new scala.Tuple2<ActorGateway, Integer>(jobManagerGateway, 0)));
// ========= setup QueryServices ================================================================================
Object requestMetricsAnswer = createRequestDumpAnswer(tmID, jobID);
final ActorRef jmQueryService = mock(ActorRef.class);
final ActorRef tmQueryService = mock(ActorRef.class);
ActorSystem actorSystem = mock(ActorSystem.class);
when(actorSystem.actorFor(eq("/jm/" + METRIC_QUERY_SERVICE_NAME))).thenReturn(jmQueryService);
when(actorSystem.actorFor(eq("/tm/" + METRIC_QUERY_SERVICE_NAME + "_" + tmRID.getResourceIdString()))).thenReturn(tmQueryService);
MetricFetcher.BasicGateway jmQueryServiceGateway = mock(MetricFetcher.BasicGateway.class);
when(jmQueryServiceGateway.ask(any(MetricQueryService.getCreateDump().getClass()), any(FiniteDuration.class))).thenReturn(Future$.MODULE$.successful((Object) new MetricDumpSerialization.MetricSerializationResult(new byte[0], 0, 0, 0, 0)));
MetricFetcher.BasicGateway tmQueryServiceGateway = mock(MetricFetcher.BasicGateway.class);
when(tmQueryServiceGateway.ask(any(MetricQueryService.getCreateDump().getClass()), any(FiniteDuration.class))).thenReturn(Future$.MODULE$.successful(requestMetricsAnswer));
whenNew(MetricFetcher.BasicGateway.class).withArguments(eq(new Object() {
@Override
public boolean equals(Object o) {
return o == jmQueryService;
}
})).thenReturn(jmQueryServiceGateway);
whenNew(MetricFetcher.BasicGateway.class).withArguments(eq(new Object() {
@Override
public boolean equals(Object o) {
return o == tmQueryService;
}
})).thenReturn(tmQueryServiceGateway);
// ========= start MetricFetcher testing =======================================================================
ExecutionContextExecutor context = ExecutionContext$.MODULE$.fromExecutor(new CurrentThreadExecutor());
MetricFetcher fetcher = new MetricFetcher(actorSystem, retriever, context);
// verify that update fetches metrics and updates the store
fetcher.update();
MetricStore store = fetcher.getMetricStore();
synchronized (store) {
assertEquals("7", store.jobManager.metrics.get("abc.hist_min"));
assertEquals("6", store.jobManager.metrics.get("abc.hist_max"));
assertEquals("4.0", store.jobManager.metrics.get("abc.hist_mean"));
assertEquals("0.5", store.jobManager.metrics.get("abc.hist_median"));
assertEquals("5.0", store.jobManager.metrics.get("abc.hist_stddev"));
assertEquals("0.75", store.jobManager.metrics.get("abc.hist_p75"));
assertEquals("0.9", store.jobManager.metrics.get("abc.hist_p90"));
assertEquals("0.95", store.jobManager.metrics.get("abc.hist_p95"));
assertEquals("0.98", store.jobManager.metrics.get("abc.hist_p98"));
assertEquals("0.99", store.jobManager.metrics.get("abc.hist_p99"));
assertEquals("0.999", store.jobManager.metrics.get("abc.hist_p999"));
assertEquals("x", store.getTaskManagerMetricStore(tmID.toString()).metrics.get("abc.gauge"));
assertEquals("5.0", store.getJobMetricStore(jobID.toString()).metrics.get("abc.jc"));
assertEquals("2", store.getTaskMetricStore(jobID.toString(), "taskid").metrics.get("2.abc.tc"));
assertEquals("1", store.getTaskMetricStore(jobID.toString(), "taskid").metrics.get("2.opname.abc.oc"));
}
}
use of akka.actor.ActorSystem in project flink by apache.
the class WebRuntimeMonitorITCase method testRedirectToLeader.
/**
* Tests that the monitor associated with the following job manager redirects to the leader.
*/
@Test
public void testRedirectToLeader() throws Exception {
final Deadline deadline = TestTimeout.fromNow();
ActorSystem[] jobManagerSystem = new ActorSystem[2];
WebRuntimeMonitor[] webMonitor = new WebRuntimeMonitor[2];
List<LeaderRetrievalService> leaderRetrievalServices = new ArrayList<>();
try (TestingServer zooKeeper = new TestingServer()) {
final Configuration config = ZooKeeperTestUtils.createZooKeeperHAConfig(zooKeeper.getConnectString(), temporaryFolder.getRoot().getPath());
File logDir = temporaryFolder.newFolder();
Path logFile = Files.createFile(new File(logDir, "jobmanager.log").toPath());
Files.createFile(new File(logDir, "jobmanager.out").toPath());
config.setInteger(ConfigConstants.JOB_MANAGER_WEB_PORT_KEY, 0);
config.setString(ConfigConstants.JOB_MANAGER_WEB_LOG_PATH_KEY, logFile.toString());
for (int i = 0; i < jobManagerSystem.length; i++) {
jobManagerSystem[i] = AkkaUtils.createActorSystem(new Configuration(), new Some<>(new Tuple2<String, Object>("localhost", 0)));
}
for (int i = 0; i < webMonitor.length; i++) {
LeaderRetrievalService lrs = ZooKeeperUtils.createLeaderRetrievalService(config);
leaderRetrievalServices.add(lrs);
webMonitor[i] = new WebRuntimeMonitor(config, lrs, jobManagerSystem[i]);
}
ActorRef[] jobManager = new ActorRef[2];
String[] jobManagerAddress = new String[2];
for (int i = 0; i < jobManager.length; i++) {
Configuration jmConfig = config.clone();
jmConfig.setInteger(ConfigConstants.JOB_MANAGER_WEB_PORT_KEY, webMonitor[i].getServerPort());
jobManager[i] = JobManager.startJobManagerActors(jmConfig, jobManagerSystem[i], TestingUtils.defaultExecutor(), TestingUtils.defaultExecutor(), JobManager.class, MemoryArchivist.class)._1();
jobManagerAddress[i] = AkkaUtils.getAkkaURL(jobManagerSystem[i], jobManager[i]);
webMonitor[i].start(jobManagerAddress[i]);
}
LeaderRetrievalService lrs = ZooKeeperUtils.createLeaderRetrievalService(config);
leaderRetrievalServices.add(lrs);
TestingListener leaderListener = new TestingListener();
lrs.start(leaderListener);
leaderListener.waitForNewLeader(deadline.timeLeft().toMillis());
String leaderAddress = leaderListener.getAddress();
int leaderIndex = leaderAddress.equals(jobManagerAddress[0]) ? 0 : 1;
int followerIndex = (leaderIndex + 1) % 2;
ActorSystem leadingSystem = jobManagerSystem[leaderIndex];
ActorSystem followerSystem = jobManagerSystem[followerIndex];
WebMonitor leadingWebMonitor = webMonitor[leaderIndex];
WebMonitor followerWebMonitor = webMonitor[followerIndex];
// For test stability reason we have to wait until we are sure that both leader
// listeners have been notified.
JobManagerRetriever leadingRetriever = Whitebox.getInternalState(leadingWebMonitor, "retriever");
JobManagerRetriever followerRetriever = Whitebox.getInternalState(followerWebMonitor, "retriever");
// Wait for the initial notifications
waitForLeaderNotification(leadingSystem, jobManager[leaderIndex], leadingRetriever, deadline);
waitForLeaderNotification(leadingSystem, jobManager[leaderIndex], followerRetriever, deadline);
try (HttpTestClient leaderClient = new HttpTestClient("localhost", leadingWebMonitor.getServerPort());
HttpTestClient followingClient = new HttpTestClient("localhost", followerWebMonitor.getServerPort())) {
String expected = new Scanner(new File(MAIN_RESOURCES_PATH + "/index.html")).useDelimiter("\\A").next();
// Request the file from the leading web server
leaderClient.sendGetRequest("index.html", deadline.timeLeft());
HttpTestClient.SimpleHttpResponse response = leaderClient.getNextResponse(deadline.timeLeft());
assertEquals(HttpResponseStatus.OK, response.getStatus());
assertEquals(response.getType(), MimeTypes.getMimeTypeForExtension("html"));
assertEquals(expected, response.getContent());
// Request the file from the following web server
followingClient.sendGetRequest("index.html", deadline.timeLeft());
response = followingClient.getNextResponse(deadline.timeLeft());
assertEquals(HttpResponseStatus.TEMPORARY_REDIRECT, response.getStatus());
assertTrue(response.getLocation().contains(String.valueOf(leadingWebMonitor.getServerPort())));
// Kill the leader
leadingSystem.shutdown();
// Wait for the notification of the follower
waitForLeaderNotification(followerSystem, jobManager[followerIndex], followerRetriever, deadline);
// Same request to the new leader
followingClient.sendGetRequest("index.html", deadline.timeLeft());
response = followingClient.getNextResponse(deadline.timeLeft());
assertEquals(HttpResponseStatus.OK, response.getStatus());
assertEquals(response.getType(), MimeTypes.getMimeTypeForExtension("html"));
assertEquals(expected, response.getContent());
// Simple overview request
followingClient.sendGetRequest("/overview", deadline.timeLeft());
response = followingClient.getNextResponse(deadline.timeLeft());
assertEquals(HttpResponseStatus.OK, response.getStatus());
assertEquals(response.getType(), MimeTypes.getMimeTypeForExtension("json"));
assertTrue(response.getContent().contains("\"taskmanagers\":1") || response.getContent().contains("\"taskmanagers\":0"));
}
} finally {
for (ActorSystem system : jobManagerSystem) {
if (system != null) {
system.shutdown();
}
}
for (WebMonitor monitor : webMonitor) {
monitor.stop();
}
for (LeaderRetrievalService lrs : leaderRetrievalServices) {
lrs.stop();
}
}
}
Aggregations