Java Code Examples for org.apache.flink.runtime.akka.AkkaUtils#createLocalActorSystem()

The following examples show how to use org.apache.flink.runtime.akka.AkkaUtils#createLocalActorSystem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AkkaActorSystemTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void shutsDownOnActorFailure() {
	final ActorSystem actorSystem = AkkaUtils.createLocalActorSystem(new Configuration());

	try {
		final CompletableFuture<Terminated> terminationFuture = actorSystem.getWhenTerminated().toCompletableFuture();
		final ActorRef actorRef = actorSystem.actorOf(Props.create(SimpleActor.class));

		final FlinkException cause = new FlinkException("Flink test exception");

		actorRef.tell(Fail.exceptionally(cause), ActorRef.noSender());

		// make sure that the ActorSystem shuts down
		terminationFuture.join();
	} finally {
		AkkaUtils.terminateActorSystem(actorSystem).join();
	}
}
 
Example 2
Source File: MesosServicesUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link MesosServices} instance depending on the high availability settings.
 *
 * @param configuration containing the high availability settings
 * @param hostname the hostname to advertise to remote clients
 * @return a mesos services instance
 * @throws Exception if the mesos services instance could not be created
 */
public static MesosServices createMesosServices(Configuration configuration, String hostname) throws Exception {

	ActorSystem localActorSystem = AkkaUtils.createLocalActorSystem(configuration);

	MesosArtifactServer artifactServer = createArtifactServer(configuration, hostname);

	HighAvailabilityMode highAvailabilityMode = HighAvailabilityMode.fromConfig(configuration);

	switch (highAvailabilityMode) {
		case NONE:
			return new StandaloneMesosServices(localActorSystem, artifactServer);

		case ZOOKEEPER:
			final String zkMesosRootPath = configuration.getString(
				HighAvailabilityOptions.HA_ZOOKEEPER_MESOS_WORKERS_PATH);

			ZooKeeperUtilityFactory zooKeeperUtilityFactory = new ZooKeeperUtilityFactory(
				configuration,
				zkMesosRootPath);

			return new ZooKeeperMesosServices(localActorSystem, artifactServer, zooKeeperUtilityFactory);

		default:
			throw new Exception("High availability mode " + highAvailabilityMode + " is not supported.");
	}
}
 
Example 3
Source File: TestingRpcService.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@code TestingRpcService}, using the given configuration.
 */
public TestingRpcService(Configuration configuration) {
	super(AkkaUtils.createLocalActorSystem(configuration),
		AkkaRpcServiceConfiguration.fromConfiguration(configuration));

	this.registeredConnections = new ConcurrentHashMap<>();
}
 
Example 4
Source File: MesosServicesUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link MesosServices} instance depending on the high availability settings.
 *
 * @param configuration containing the high availability settings
 * @param hostname the hostname to advertise to remote clients
 * @return a mesos services instance
 * @throws Exception if the mesos services instance could not be created
 */
public static MesosServices createMesosServices(Configuration configuration, String hostname) throws Exception {

	ActorSystem localActorSystem = AkkaUtils.createLocalActorSystem(configuration);

	MesosArtifactServer artifactServer = createArtifactServer(configuration, hostname);

	HighAvailabilityMode highAvailabilityMode = HighAvailabilityMode.fromConfig(configuration);

	switch (highAvailabilityMode) {
		case NONE:
			return new StandaloneMesosServices(localActorSystem, artifactServer);

		case ZOOKEEPER:
			final String zkMesosRootPath = configuration.getString(
				HighAvailabilityOptions.HA_ZOOKEEPER_MESOS_WORKERS_PATH);

			ZooKeeperUtilityFactory zooKeeperUtilityFactory = new ZooKeeperUtilityFactory(
				configuration,
				zkMesosRootPath);

			return new ZooKeeperMesosServices(localActorSystem, artifactServer, zooKeeperUtilityFactory);

		default:
			throw new Exception("High availability mode " + highAvailabilityMode + " is not supported.");
	}
}
 
Example 5
Source File: TestingRpcService.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@code TestingRpcService}, using the given configuration.
 */
public TestingRpcService(Configuration configuration) {
	super(AkkaUtils.createLocalActorSystem(configuration),
		AkkaRpcServiceConfiguration.fromConfiguration(configuration));

	this.registeredConnections = new ConcurrentHashMap<>();
}
 
Example 6
Source File: MesosServicesUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link MesosServices} instance depending on the high availability settings.
 *
 * @param configuration containing the high availability settings
 * @param hostname the hostname to advertise to remote clients
 * @return a mesos services instance
 * @throws Exception if the mesos services instance could not be created
 */
public static MesosServices createMesosServices(Configuration configuration, String hostname) throws Exception {

	ActorSystem localActorSystem = AkkaUtils.createLocalActorSystem(configuration);

	MesosArtifactServer artifactServer = createArtifactServer(configuration, hostname);

	HighAvailabilityMode highAvailabilityMode = HighAvailabilityMode.fromConfig(configuration);

	switch (highAvailabilityMode) {
		case NONE:
			return new StandaloneMesosServices(localActorSystem, artifactServer);

		case ZOOKEEPER:
			final String zkMesosRootPath = configuration.getString(
				HighAvailabilityOptions.HA_ZOOKEEPER_MESOS_WORKERS_PATH);

			ZooKeeperUtilityFactory zooKeeperUtilityFactory = new ZooKeeperUtilityFactory(
				configuration,
				zkMesosRootPath);

			return new ZooKeeperMesosServices(localActorSystem, artifactServer, zooKeeperUtilityFactory);

		default:
			throw new Exception("High availability mode " + highAvailabilityMode + " is not supported.");
	}
}
 
Example 7
Source File: TestingRpcService.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@code TestingRpcService}, using the given configuration.
 */
public TestingRpcService(Configuration configuration) {
	super(AkkaUtils.createLocalActorSystem(configuration),
		AkkaRpcServiceConfiguration.fromConfiguration(configuration));

	this.registeredConnections = new ConcurrentHashMap<>();
}
 
Example 8
Source File: MesosResourceManagerTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	system = AkkaUtils.createLocalActorSystem(flinkConfig);
}
 
Example 9
Source File: TaskManagerTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() {
	system = AkkaUtils.createLocalActorSystem(new Configuration());
}
 
Example 10
Source File: MetricQueryServiceTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreateDump() throws Exception {
	ActorSystem s = AkkaUtils.createLocalActorSystem(new Configuration());
	try {
		ActorRef serviceActor = MetricQueryService.startMetricQueryService(s, null, Long.MAX_VALUE);
		TestActorRef testActorRef = TestActorRef.create(s, Props.create(TestActor.class));
		TestActor testActor = (TestActor) testActorRef.underlyingActor();

		final Counter c = new SimpleCounter();
		final Gauge<String> g = () -> "Hello";
		final Histogram h = new TestHistogram();
		final Meter m = new TestMeter();

		final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();

		MetricQueryService.notifyOfAddedMetric(serviceActor, c, "counter", tm);
		MetricQueryService.notifyOfAddedMetric(serviceActor, g, "gauge", tm);
		MetricQueryService.notifyOfAddedMetric(serviceActor, h, "histogram", tm);
		MetricQueryService.notifyOfAddedMetric(serviceActor, m, "meter", tm);
		serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef);

		testActor.waitForResult();

		MetricDumpSerialization.MetricSerializationResult dump = testActor.getSerializationResult();

		assertTrue(dump.serializedCounters.length > 0);
		assertTrue(dump.serializedGauges.length > 0);
		assertTrue(dump.serializedHistograms.length > 0);
		assertTrue(dump.serializedMeters.length > 0);

		MetricQueryService.notifyOfRemovedMetric(serviceActor, c);
		MetricQueryService.notifyOfRemovedMetric(serviceActor, g);
		MetricQueryService.notifyOfRemovedMetric(serviceActor, h);
		MetricQueryService.notifyOfRemovedMetric(serviceActor, m);

		serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef);

		testActor.waitForResult();

		MetricDumpSerialization.MetricSerializationResult emptyDump = testActor.getSerializationResult();

		assertEquals(0, emptyDump.serializedCounters.length);
		assertEquals(0, emptyDump.serializedGauges.length);
		assertEquals(0, emptyDump.serializedHistograms.length);
		assertEquals(0, emptyDump.serializedMeters.length);
	} finally {
		s.terminate();
	}
}
 
Example 11
Source File: MetricQueryServiceTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testHandleOversizedMetricMessage() throws Exception {
	ActorSystem s = AkkaUtils.createLocalActorSystem(new Configuration());
	try {
		final long sizeLimit = 200L;
		ActorRef serviceActor = MetricQueryService.startMetricQueryService(s, null, sizeLimit);
		TestActorRef testActorRef = TestActorRef.create(s, Props.create(TestActor.class));
		TestActor testActor = (TestActor) testActorRef.underlyingActor();

		final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();

		final String gaugeValue = "Hello";
		final long requiredGaugesToExceedLimit = sizeLimit / gaugeValue.length() + 1;
		List<Tuple2<String, Gauge<String>>> gauges = LongStream.range(0, requiredGaugesToExceedLimit)
			.mapToObj(x -> Tuple2.of("gauge" + x, (Gauge<String>) () -> "Hello" + x))
			.collect(Collectors.toList());
		gauges.forEach(gauge -> MetricQueryService.notifyOfAddedMetric(serviceActor, gauge.f1, gauge.f0, tm));

		MetricQueryService.notifyOfAddedMetric(serviceActor, new SimpleCounter(), "counter", tm);
		MetricQueryService.notifyOfAddedMetric(serviceActor, new TestHistogram(), "histogram", tm);
		MetricQueryService.notifyOfAddedMetric(serviceActor, new TestMeter(), "meter", tm);

		serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef);
		testActor.waitForResult();

		MetricDumpSerialization.MetricSerializationResult dump = testActor.getSerializationResult();

		assertTrue(dump.serializedCounters.length > 0);
		assertEquals(1, dump.numCounters);
		assertTrue(dump.serializedMeters.length > 0);
		assertEquals(1, dump.numMeters);

		// gauges exceeded the size limit and will be excluded
		assertEquals(0, dump.serializedGauges.length);
		assertEquals(0, dump.numGauges);

		assertTrue(dump.serializedHistograms.length > 0);
		assertEquals(1, dump.numHistograms);

		// unregister all but one gauge to ensure gauges are reported again if the remaining fit
		for (int x = 1; x < gauges.size(); x++) {
			MetricQueryService.notifyOfRemovedMetric(serviceActor, gauges.get(x).f1);
		}

		serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef);
		testActor.waitForResult();

		MetricDumpSerialization.MetricSerializationResult recoveredDump = testActor.getSerializationResult();

		assertTrue(recoveredDump.serializedCounters.length > 0);
		assertEquals(1, recoveredDump.numCounters);
		assertTrue(recoveredDump.serializedMeters.length > 0);
		assertEquals(1, recoveredDump.numMeters);
		assertTrue(recoveredDump.serializedGauges.length > 0);
		assertEquals(1, recoveredDump.numGauges);
		assertTrue(recoveredDump.serializedHistograms.length > 0);
		assertEquals(1, recoveredDump.numHistograms);
	} finally {
		s.terminate();
	}
}
 
Example 12
Source File: StackTraceSampleCoordinatorTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
	system = AkkaUtils.createLocalActorSystem(new Configuration());
}
 
Example 13
Source File: MesosResourceManagerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	system = AkkaUtils.createLocalActorSystem(flinkConfig);
}
 
Example 14
Source File: StackTraceSampleCoordinatorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
	system = AkkaUtils.createLocalActorSystem(new Configuration());
}
 
Example 15
Source File: MesosResourceManagerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	system = AkkaUtils.createLocalActorSystem(flinkConfig);
}
 
Example 16
Source File: ActorSystemResource.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected void before() throws Throwable {
	Preconditions.checkState(actorSystem == null, "ActorSystem must not be initialized when calling before.");
	actorSystem = AkkaUtils.createLocalActorSystem(configuration);
}