Search in sources :

Example 6 with RpcService

use of org.apache.flink.runtime.rpc.RpcService in project flink by apache.

the class TaskManagerRunner method startTaskManagerRunnerServices.

private void startTaskManagerRunnerServices() throws Exception {
    synchronized (lock) {
        rpcSystem = RpcSystem.load(configuration);
        this.executor = Executors.newScheduledThreadPool(Hardware.getNumberCPUCores(), new ExecutorThreadFactory("taskmanager-future"));
        highAvailabilityServices = HighAvailabilityServicesUtils.createHighAvailabilityServices(configuration, executor, AddressResolution.NO_ADDRESS_RESOLUTION, rpcSystem, this);
        JMXService.startInstance(configuration.getString(JMXServerOptions.JMX_SERVER_PORT));
        rpcService = createRpcService(configuration, highAvailabilityServices, rpcSystem);
        this.resourceId = getTaskManagerResourceID(configuration, rpcService.getAddress(), rpcService.getPort());
        this.workingDirectory = ClusterEntrypointUtils.createTaskManagerWorkingDirectory(configuration, resourceId);
        LOG.info("Using working directory: {}", workingDirectory);
        HeartbeatServices heartbeatServices = HeartbeatServices.fromConfiguration(configuration);
        metricRegistry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(configuration, rpcSystem.getMaximumMessageSizeInBytes(configuration)), ReporterSetup.fromConfiguration(configuration, pluginManager));
        final RpcService metricQueryServiceRpcService = MetricUtils.startRemoteMetricsRpcService(configuration, rpcService.getAddress(), configuration.getString(TaskManagerOptions.BIND_HOST), rpcSystem);
        metricRegistry.startQueryService(metricQueryServiceRpcService, resourceId.unwrap());
        blobCacheService = BlobUtils.createBlobCacheService(configuration, Reference.borrowed(workingDirectory.unwrap().getBlobStorageDirectory()), highAvailabilityServices.createBlobStore(), null);
        final ExternalResourceInfoProvider externalResourceInfoProvider = ExternalResourceUtils.createStaticExternalResourceInfoProviderFromConfig(configuration, pluginManager);
        taskExecutorService = taskExecutorServiceFactory.createTaskExecutor(this.configuration, this.resourceId.unwrap(), rpcService, highAvailabilityServices, heartbeatServices, metricRegistry, blobCacheService, false, externalResourceInfoProvider, workingDirectory.unwrap(), this);
        handleUnexpectedTaskExecutorServiceTermination();
        MemoryLogger.startIfConfigured(LOG, configuration, terminationFuture.thenAccept(ignored -> {
        }));
    }
}
Also used : ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) TaskExecutorBlobService(org.apache.flink.runtime.blob.TaskExecutorBlobService) Tuple2(org.apache.flink.api.java.tuple.Tuple2) Hardware(org.apache.flink.runtime.util.Hardware) RpcSystemUtils(org.apache.flink.runtime.rpc.RpcSystemUtils) LoggerFactory(org.slf4j.LoggerFactory) ExternalResourceUtils(org.apache.flink.runtime.externalresource.ExternalResourceUtils) LeaderRetrievalException(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) LeaderRetrievalUtils(org.apache.flink.runtime.util.LeaderRetrievalUtils) ReporterSetup(org.apache.flink.runtime.metrics.ReporterSetup) InetAddress(java.net.InetAddress) MemoryLogger(org.apache.flink.runtime.taskmanager.MemoryLogger) StateChangelogStorageLoader(org.apache.flink.runtime.state.changelog.StateChangelogStorageLoader) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) FunctionUtils(org.apache.flink.util.function.FunctionUtils) Duration(java.time.Duration) SecurityUtils(org.apache.flink.runtime.security.SecurityUtils) TaskManagerOptionsInternal(org.apache.flink.configuration.TaskManagerOptionsInternal) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) AkkaOptions(org.apache.flink.configuration.AkkaOptions) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) AbstractID(org.apache.flink.util.AbstractID) Collection(java.util.Collection) JvmShutdownSafeguard(org.apache.flink.runtime.util.JvmShutdownSafeguard) HighAvailabilityServicesUtils(org.apache.flink.runtime.highavailability.HighAvailabilityServicesUtils) MetricUtils(org.apache.flink.runtime.metrics.util.MetricUtils) GuardedBy(javax.annotation.concurrent.GuardedBy) SecurityConfiguration(org.apache.flink.runtime.security.SecurityConfiguration) EnvironmentInformation(org.apache.flink.runtime.util.EnvironmentInformation) StringUtils(org.apache.flink.util.StringUtils) Executors(java.util.concurrent.Executors) HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) ExecutorUtils(org.apache.flink.util.ExecutorUtils) JMXService(org.apache.flink.management.jmx.JMXService) MetricGroup(org.apache.flink.metrics.MetricGroup) FileSystem(org.apache.flink.core.fs.FileSystem) PluginManager(org.apache.flink.core.plugin.PluginManager) ConfigurationParserUtils(org.apache.flink.runtime.util.ConfigurationParserUtils) ClusterEntrypointUtils(org.apache.flink.runtime.entrypoint.ClusterEntrypointUtils) Time(org.apache.flink.api.common.time.Time) TaskExecutorPartitionTrackerImpl(org.apache.flink.runtime.io.network.partition.TaskExecutorPartitionTrackerImpl) FlinkException(org.apache.flink.util.FlinkException) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) CompletableFuture(java.util.concurrent.CompletableFuture) ShutdownHookUtil(org.apache.flink.util.ShutdownHookUtil) ArrayList(java.util.ArrayList) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) RpcService(org.apache.flink.runtime.rpc.RpcService) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ExternalResourceInfoProvider(org.apache.flink.runtime.externalresource.ExternalResourceInfoProvider) FatalErrorHandler(org.apache.flink.runtime.rpc.FatalErrorHandler) FlinkSecurityManager(org.apache.flink.core.security.FlinkSecurityManager) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ExecutorService(java.util.concurrent.ExecutorService) TaskManagerExceptionUtils(org.apache.flink.util.TaskManagerExceptionUtils) Logger(org.slf4j.Logger) AutoCloseableAsync(org.apache.flink.util.AutoCloseableAsync) Configuration(org.apache.flink.configuration.Configuration) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) IOException(java.io.IOException) Reference(org.apache.flink.util.Reference) RpcUtils(org.apache.flink.runtime.rpc.RpcUtils) SignalHandler(org.apache.flink.runtime.util.SignalHandler) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) VisibleForTesting(org.apache.flink.annotation.VisibleForTesting) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) DeterminismEnvelope(org.apache.flink.runtime.entrypoint.DeterminismEnvelope) RpcSystem(org.apache.flink.runtime.rpc.RpcSystem) PluginUtils(org.apache.flink.core.plugin.PluginUtils) WorkingDirectory(org.apache.flink.runtime.entrypoint.WorkingDirectory) JMXServerOptions(org.apache.flink.configuration.JMXServerOptions) BlobCacheService(org.apache.flink.runtime.blob.BlobCacheService) AddressResolution(org.apache.flink.runtime.rpc.AddressResolution) BlobUtils(org.apache.flink.runtime.blob.BlobUtils) FlinkParseException(org.apache.flink.runtime.entrypoint.FlinkParseException) RpcService(org.apache.flink.runtime.rpc.RpcService) MetricRegistryImpl(org.apache.flink.runtime.metrics.MetricRegistryImpl) ExternalResourceInfoProvider(org.apache.flink.runtime.externalresource.ExternalResourceInfoProvider)

Example 7 with RpcService

use of org.apache.flink.runtime.rpc.RpcService in project flink by apache.

the class RetryingRegistrationTest method testCancellation.

@Test
public void testCancellation() throws Exception {
    final String testEndpointAddress = "my-test-address";
    final UUID leaderId = UUID.randomUUID();
    CompletableFuture<RegistrationResponse> result = new CompletableFuture<>();
    AtomicInteger registrationCallCounter = new AtomicInteger(0);
    TestRegistrationGateway testGateway = DefaultTestRegistrationGateway.newBuilder().setRegistrationFunction((uuid, aLong) -> {
        registrationCallCounter.incrementAndGet();
        return result;
    }).build();
    rpcService.registerGateway(testEndpointAddress, testGateway);
    TestRetryingRegistration registration = new TestRetryingRegistration(rpcService, testEndpointAddress, leaderId);
    registration.startRegistration();
    // cancel and fail the current registration attempt
    registration.cancel();
    result.completeExceptionally(new TimeoutException());
    // there should not be a second registration attempt
    assertThat(registrationCallCounter.get(), is(lessThanOrEqualTo(1)));
}
Also used : FlinkException(org.apache.flink.util.FlinkException) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) LoggerFactory(org.slf4j.LoggerFactory) ScheduledExecutorServiceAdapter(org.apache.flink.util.concurrent.ScheduledExecutorServiceAdapter) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) Assert.assertThat(org.junit.Assert.assertThat) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RpcService(org.apache.flink.runtime.rpc.RpcService) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Assert.fail(org.junit.Assert.fail) Mockito.anyLong(org.mockito.Mockito.anyLong) Mockito.anyString(org.mockito.Mockito.anyString) Before(org.junit.Before) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) TestingUtils(org.apache.flink.testutils.TestingUtils) Matchers.is(org.hamcrest.Matchers.is) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) Mockito.any(org.mockito.Mockito.any) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Mockito.anyString(org.mockito.Mockito.anyString) UUID(java.util.UUID) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 8 with RpcService

use of org.apache.flink.runtime.rpc.RpcService in project flink by apache.

the class RetryingRegistrationTest method testPropagateFailures.

@Test
public void testPropagateFailures() throws Exception {
    final String testExceptionMessage = "testExceptionMessage";
    // RPC service that fails with exception upon the connection
    RpcService rpc = mock(RpcService.class);
    when(rpc.connect(anyString(), any(Class.class))).thenThrow(new RuntimeException(testExceptionMessage));
    TestRetryingRegistration registration = new TestRetryingRegistration(rpc, "testaddress", UUID.randomUUID());
    registration.startRegistration();
    CompletableFuture<?> future = registration.getFuture();
    assertTrue(future.isDone());
    try {
        future.get();
        fail("We expected an ExecutionException.");
    } catch (ExecutionException e) {
        assertEquals(testExceptionMessage, e.getCause().getMessage());
    }
}
Also used : TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) RpcService(org.apache.flink.runtime.rpc.RpcService) Mockito.anyString(org.mockito.Mockito.anyString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 9 with RpcService

use of org.apache.flink.runtime.rpc.RpcService in project flink by apache.

the class TaskManagerRunnerStartupTest method testMetricInitialization.

/**
 * Checks that all expected metrics are initialized.
 */
@Test
public void testMetricInitialization() throws Exception {
    Configuration cfg = createFlinkConfiguration();
    List<String> registeredMetrics = new ArrayList<>();
    startTaskManager(cfg, rpcService, highAvailabilityServices, WORKING_DIRECTORY_RESOURCE.createNewWorkingDirectory(), TestingMetricRegistry.builder().setRegisterConsumer((metric, metricName, group) -> registeredMetrics.add(group.getMetricIdentifier(metricName))).setScopeFormats(ScopeFormats.fromConfig(cfg)).build());
    // GC-related metrics are not checked since their existence depends on the JVM used
    Set<String> expectedTaskManagerMetricsWithoutTaskManagerId = Sets.newHashSet(".taskmanager..Status.JVM.ClassLoader.ClassesLoaded", ".taskmanager..Status.JVM.ClassLoader.ClassesUnloaded", ".taskmanager..Status.JVM.Memory.Heap.Used", ".taskmanager..Status.JVM.Memory.Heap.Committed", ".taskmanager..Status.JVM.Memory.Heap.Max", ".taskmanager..Status.JVM.Memory.NonHeap.Used", ".taskmanager..Status.JVM.Memory.NonHeap.Committed", ".taskmanager..Status.JVM.Memory.NonHeap.Max", ".taskmanager..Status.JVM.Memory.Direct.Count", ".taskmanager..Status.JVM.Memory.Direct.MemoryUsed", ".taskmanager..Status.JVM.Memory.Direct.TotalCapacity", ".taskmanager..Status.JVM.Memory.Mapped.Count", ".taskmanager..Status.JVM.Memory.Mapped.MemoryUsed", ".taskmanager..Status.JVM.Memory.Mapped.TotalCapacity", ".taskmanager..Status.Flink.Memory.Managed.Used", ".taskmanager..Status.Flink.Memory.Managed.Total", ".taskmanager..Status.JVM.Threads.Count", ".taskmanager..Status.JVM.CPU.Load", ".taskmanager..Status.JVM.CPU.Time", ".taskmanager..Status.Network.TotalMemorySegments", ".taskmanager..Status.Network.AvailableMemorySegments", ".taskmanager..Status.Shuffle.Netty.TotalMemorySegments", ".taskmanager..Status.Shuffle.Netty.TotalMemory", ".taskmanager..Status.Shuffle.Netty.AvailableMemorySegments", ".taskmanager..Status.Shuffle.Netty.AvailableMemory", ".taskmanager..Status.Shuffle.Netty.UsedMemorySegments", ".taskmanager..Status.Shuffle.Netty.UsedMemory");
    Pattern pattern = Pattern.compile("\\.taskmanager\\.([^.]+)\\..*");
    Set<String> registeredMetricsWithoutTaskManagerId = registeredMetrics.stream().map(pattern::matcher).flatMap(matcher -> matcher.find() ? Stream.of(matcher.group(0).replaceAll(matcher.group(1), "")) : Stream.empty()).collect(Collectors.toSet());
    assertThat(expectedTaskManagerMetricsWithoutTaskManagerId, everyItem(isIn(registeredMetricsWithoutTaskManagerId)));
}
Also used : IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) IsIn.isIn(org.hamcrest.collection.IsIn.isIn) MemorySize(org.apache.flink.configuration.MemorySize) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) Assert.assertThat(org.junit.Assert.assertThat) NettyShuffleEnvironmentOptions(org.apache.flink.configuration.NettyShuffleEnvironmentOptions) Every.everyItem(org.hamcrest.core.Every.everyItem) TaskManagerOptions(org.apache.flink.configuration.TaskManagerOptions) SettableLeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService) TestingMetricRegistry(org.apache.flink.runtime.metrics.util.TestingMetricRegistry) RpcService(org.apache.flink.runtime.rpc.RpcService) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) ExternalResourceInfoProvider(org.apache.flink.runtime.externalresource.ExternalResourceInfoProvider) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) Assume(org.junit.Assume) Assert.fail(org.junit.Assert.fail) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ClassRule(org.junit.ClassRule) Before(org.junit.Before) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) IOUtils(org.apache.flink.util.IOUtils) Sets(org.apache.flink.shaded.guava30.com.google.common.collect.Sets) Configuration(org.apache.flink.configuration.Configuration) TestingHeartbeatServices(org.apache.flink.runtime.heartbeat.TestingHeartbeatServices) NoOpTaskExecutorBlobService(org.apache.flink.runtime.blob.NoOpTaskExecutorBlobService) NoOpMetricRegistry(org.apache.flink.runtime.metrics.NoOpMetricRegistry) Set(java.util.Set) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) Stream(java.util.stream.Stream) CoreOptions(org.apache.flink.configuration.CoreOptions) WorkingDirectory(org.apache.flink.runtime.entrypoint.WorkingDirectory) WorkingDirectoryResource(org.apache.flink.runtime.testutils.WorkingDirectoryResource) TestingRpcServiceResource(org.apache.flink.runtime.rpc.TestingRpcServiceResource) Pattern(java.util.regex.Pattern) TestingHighAvailabilityServices(org.apache.flink.runtime.highavailability.TestingHighAvailabilityServices) ScopeFormats(org.apache.flink.runtime.metrics.scope.ScopeFormats) TemporaryFolder(org.junit.rules.TemporaryFolder) Pattern(java.util.regex.Pattern) Configuration(org.apache.flink.configuration.Configuration) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with RpcService

use of org.apache.flink.runtime.rpc.RpcService in project flink by apache.

the class IPv6HostnamesITCase method getLocalIPv6Address.

private Inet6Address getLocalIPv6Address() {
    try {
        Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
        while (e.hasMoreElements()) {
            NetworkInterface netInterface = e.nextElement();
            // for each address of the network interface
            Enumeration<InetAddress> ee = netInterface.getInetAddresses();
            while (ee.hasMoreElements()) {
                InetAddress addr = ee.nextElement();
                if (addr instanceof Inet6Address && (!addr.isLoopbackAddress()) && (!addr.isAnyLocalAddress())) {
                    // see if it is possible to bind to the address
                    InetSocketAddress socketAddress = new InetSocketAddress(addr, 0);
                    try {
                        log.info("Considering address " + addr);
                        // test whether we can bind a socket to that address
                        log.info("Testing whether sockets can bind to " + addr);
                        ServerSocket sock = new ServerSocket();
                        sock.bind(socketAddress);
                        sock.close();
                        // test whether Akka's netty can bind to the address
                        log.info("Testing whether Akka can use " + addr);
                        try (NetUtils.Port port = NetUtils.getAvailablePort()) {
                            final RpcService rpcService = RpcSystem.load().localServiceBuilder(new Configuration()).withBindAddress(addr.getHostAddress()).withBindPort(port.getPort()).createAndStart();
                            rpcService.stopService().get();
                        }
                        log.info("Using address " + addr);
                        return (Inet6Address) addr;
                    } catch (IOException ignored) {
                    // fall through the loop
                    }
                }
            }
        }
        return null;
    } catch (Exception e) {
        return null;
    }
}
Also used : MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) InetSocketAddress(java.net.InetSocketAddress) NetworkInterface(java.net.NetworkInterface) Inet6Address(java.net.Inet6Address) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) AssumptionViolatedException(org.junit.AssumptionViolatedException) IOException(java.io.IOException) NetUtils(org.apache.flink.util.NetUtils) RpcService(org.apache.flink.runtime.rpc.RpcService) InetAddress(java.net.InetAddress)

Aggregations

RpcService (org.apache.flink.runtime.rpc.RpcService)25 Test (org.junit.Test)15 Configuration (org.apache.flink.configuration.Configuration)13 HighAvailabilityServices (org.apache.flink.runtime.highavailability.HighAvailabilityServices)9 ExecutionException (java.util.concurrent.ExecutionException)8 TestingRpcService (org.apache.flink.runtime.rpc.TestingRpcService)7 UUID (java.util.UUID)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Before (org.junit.Before)6 FlinkException (org.apache.flink.util.FlinkException)5 TestLogger (org.apache.flink.util.TestLogger)5 After (org.junit.After)5 Assert.assertThat (org.junit.Assert.assertThat)5 Assert.fail (org.junit.Assert.fail)5 LoggerFactory (org.slf4j.LoggerFactory)5 IOException (java.io.IOException)4 TimeUnit (java.util.concurrent.TimeUnit)4 HeartbeatServices (org.apache.flink.runtime.heartbeat.HeartbeatServices)4 Mockito.anyString (org.mockito.Mockito.anyString)4 InetAddress (java.net.InetAddress)3