Search in sources :

Example 1 with RpcService

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

the class JobManagerRunnerMockTest method setUp.

@Before
public void setUp() throws Exception {
    RpcService mockRpc = mock(RpcService.class);
    when(mockRpc.getAddress()).thenReturn("localhost");
    jobManager = mock(JobMaster.class);
    jobManagerGateway = mock(JobMasterGateway.class);
    when(jobManager.getSelf()).thenReturn(jobManagerGateway);
    when(jobManager.getRpcService()).thenReturn(mockRpc);
    PowerMockito.whenNew(JobMaster.class).withAnyArguments().thenReturn(jobManager);
    jobCompletion = new TestingOnCompletionActions();
    leaderElectionService = mock(LeaderElectionService.class);
    when(leaderElectionService.hasLeadership()).thenReturn(true);
    SubmittedJobGraphStore submittedJobGraphStore = mock(SubmittedJobGraphStore.class);
    blobStore = mock(BlobStore.class);
    HighAvailabilityServices haServices = mock(HighAvailabilityServices.class);
    when(haServices.getJobManagerLeaderElectionService(any(JobID.class))).thenReturn(leaderElectionService);
    when(haServices.getSubmittedJobGraphStore()).thenReturn(submittedJobGraphStore);
    when(haServices.createBlobStore()).thenReturn(blobStore);
    when(haServices.getRunningJobsRegistry()).thenReturn(runningJobsRegistry);
    HeartbeatServices heartbeatServices = mock(HeartbeatServices.class);
    runner = PowerMockito.spy(new JobManagerRunner(ResourceID.generate(), new JobGraph("test", new JobVertex("vertex")), mock(Configuration.class), mockRpc, haServices, heartbeatServices, JobManagerServices.fromConfiguration(new Configuration(), haServices), new MetricRegistry(MetricRegistryConfiguration.defaultMetricRegistryConfiguration()), jobCompletion, jobCompletion));
}
Also used : HeartbeatServices(org.apache.flink.runtime.heartbeat.HeartbeatServices) SubmittedJobGraphStore(org.apache.flink.runtime.jobmanager.SubmittedJobGraphStore) MetricRegistryConfiguration(org.apache.flink.runtime.metrics.MetricRegistryConfiguration) Configuration(org.apache.flink.configuration.Configuration) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) RpcService(org.apache.flink.runtime.rpc.RpcService) LeaderElectionService(org.apache.flink.runtime.leaderelection.LeaderElectionService) BlobStore(org.apache.flink.runtime.blob.BlobStore) JobID(org.apache.flink.api.common.JobID) Before(org.junit.Before)

Example 2 with RpcService

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

the class ClusterEntrypoint method initializeServices.

protected void initializeServices(Configuration configuration, PluginManager pluginManager) throws Exception {
    LOG.info("Initializing cluster services.");
    synchronized (lock) {
        resourceId = configuration.getOptional(JobManagerOptions.JOB_MANAGER_RESOURCE_ID).map(value -> DeterminismEnvelope.deterministicValue(new ResourceID(value))).orElseGet(() -> DeterminismEnvelope.nondeterministicValue(ResourceID.generate()));
        LOG.debug("Initialize cluster entrypoint {} with resource id {}.", getClass().getSimpleName(), resourceId);
        workingDirectory = ClusterEntrypointUtils.createJobManagerWorkingDirectory(configuration, resourceId);
        LOG.info("Using working directory: {}.", workingDirectory);
        rpcSystem = RpcSystem.load(configuration);
        commonRpcService = RpcUtils.createRemoteRpcService(rpcSystem, configuration, configuration.getString(JobManagerOptions.ADDRESS), getRPCPortRange(configuration), configuration.getString(JobManagerOptions.BIND_HOST), configuration.getOptional(JobManagerOptions.RPC_BIND_PORT));
        JMXService.startInstance(configuration.getString(JMXServerOptions.JMX_SERVER_PORT));
        // update the configuration used to create the high availability services
        configuration.setString(JobManagerOptions.ADDRESS, commonRpcService.getAddress());
        configuration.setInteger(JobManagerOptions.PORT, commonRpcService.getPort());
        ioExecutor = Executors.newFixedThreadPool(ClusterEntrypointUtils.getPoolSize(configuration), new ExecutorThreadFactory("cluster-io"));
        haServices = createHaServices(configuration, ioExecutor, rpcSystem);
        blobServer = BlobUtils.createBlobServer(configuration, Reference.borrowed(workingDirectory.unwrap().getBlobStorageDirectory()), haServices.createBlobStore());
        blobServer.start();
        configuration.setString(BlobServerOptions.PORT, String.valueOf(blobServer.getPort()));
        heartbeatServices = createHeartbeatServices(configuration);
        metricRegistry = createMetricRegistry(configuration, pluginManager, rpcSystem);
        final RpcService metricQueryServiceRpcService = MetricUtils.startRemoteMetricsRpcService(configuration, commonRpcService.getAddress(), configuration.getString(JobManagerOptions.BIND_HOST), rpcSystem);
        metricRegistry.startQueryService(metricQueryServiceRpcService, null);
        final String hostname = RpcUtils.getHostname(commonRpcService);
        processMetricGroup = MetricUtils.instantiateProcessMetricGroup(metricRegistry, hostname, ConfigurationUtils.getSystemResourceMetricsProbingInterval(configuration));
        executionGraphInfoStore = createSerializableExecutionGraphStore(configuration, commonRpcService.getScheduledExecutor());
    }
}
Also used : ExecutorThreadFactory(org.apache.flink.util.concurrent.ExecutorThreadFactory) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) RpcService(org.apache.flink.runtime.rpc.RpcService)

Example 3 with RpcService

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

the class MiniCluster method terminateRpcServices.

@Nonnull
private CompletableFuture<Void> terminateRpcServices() {
    synchronized (lock) {
        final int numRpcServices = 1 + rpcServices.size();
        final Collection<CompletableFuture<?>> rpcTerminationFutures = new ArrayList<>(numRpcServices);
        rpcTerminationFutures.add(commonRpcService.stopService());
        for (RpcService rpcService : rpcServices) {
            rpcTerminationFutures.add(rpcService.stopService());
        }
        commonRpcService = null;
        rpcServices.clear();
        return FutureUtils.completeAll(rpcTerminationFutures);
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RpcService(org.apache.flink.runtime.rpc.RpcService) ArrayList(java.util.ArrayList) Nonnull(javax.annotation.Nonnull)

Example 4 with RpcService

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

the class AkkaRpcActorTest method testActorTerminationWhenServiceShutdown.

/**
 * Tests that actors are properly terminated when the AkkaRpcService is shut down.
 */
@Test
public void testActorTerminationWhenServiceShutdown() throws Exception {
    final ActorSystem rpcActorSystem = AkkaUtils.createDefaultActorSystem();
    final RpcService rpcService = new AkkaRpcService(rpcActorSystem, AkkaRpcServiceConfiguration.defaultConfiguration());
    try {
        SimpleRpcEndpoint rpcEndpoint = new SimpleRpcEndpoint(rpcService, SimpleRpcEndpoint.class.getSimpleName());
        rpcEndpoint.start();
        CompletableFuture<Void> terminationFuture = rpcEndpoint.getTerminationFuture();
        rpcService.stopService();
        terminationFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
    } finally {
        rpcActorSystem.terminate();
        AkkaFutureUtils.toJava(rpcActorSystem.whenTerminated()).get(timeout.getSize(), timeout.getUnit());
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) RpcService(org.apache.flink.runtime.rpc.RpcService) Test(org.junit.Test)

Example 5 with RpcService

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

the class ApplicationDispatcherGatewayServiceFactory method create.

@Override
public AbstractDispatcherLeaderProcess.DispatcherGatewayService create(DispatcherId fencingToken, Collection<JobGraph> recoveredJobs, Collection<JobResult> recoveredDirtyJobResults, JobGraphWriter jobGraphWriter, JobResultStore jobResultStore) {
    final List<JobID> recoveredJobIds = getRecoveredJobIds(recoveredJobs);
    final Dispatcher dispatcher;
    try {
        dispatcher = dispatcherFactory.createDispatcher(rpcService, fencingToken, recoveredJobs, recoveredDirtyJobResults, (dispatcherGateway, scheduledExecutor, errorHandler) -> new ApplicationDispatcherBootstrap(application, recoveredJobIds, configuration, dispatcherGateway, scheduledExecutor, errorHandler), PartialDispatcherServicesWithJobPersistenceComponents.from(partialDispatcherServices, jobGraphWriter, jobResultStore));
    } catch (Exception e) {
        throw new FlinkRuntimeException("Could not create the Dispatcher rpc endpoint.", e);
    }
    dispatcher.start();
    return DefaultDispatcherGatewayService.from(dispatcher);
}
Also used : DispatcherId(org.apache.flink.runtime.dispatcher.DispatcherId) Dispatcher(org.apache.flink.runtime.dispatcher.Dispatcher) PartialDispatcherServices(org.apache.flink.runtime.dispatcher.PartialDispatcherServices) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) PartialDispatcherServicesWithJobPersistenceComponents(org.apache.flink.runtime.dispatcher.PartialDispatcherServicesWithJobPersistenceComponents) Collection(java.util.Collection) Configuration(org.apache.flink.configuration.Configuration) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) AbstractDispatcherLeaderProcess(org.apache.flink.runtime.dispatcher.runner.AbstractDispatcherLeaderProcess) Collectors(java.util.stream.Collectors) JobResult(org.apache.flink.runtime.jobmaster.JobResult) List(java.util.List) JobID(org.apache.flink.api.common.JobID) RpcService(org.apache.flink.runtime.rpc.RpcService) Internal(org.apache.flink.annotation.Internal) PackagedProgram(org.apache.flink.client.program.PackagedProgram) DispatcherFactory(org.apache.flink.runtime.dispatcher.DispatcherFactory) JobResultStore(org.apache.flink.runtime.highavailability.JobResultStore) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) JobGraphWriter(org.apache.flink.runtime.jobmanager.JobGraphWriter) DefaultDispatcherGatewayService(org.apache.flink.runtime.dispatcher.runner.DefaultDispatcherGatewayService) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Dispatcher(org.apache.flink.runtime.dispatcher.Dispatcher) JobID(org.apache.flink.api.common.JobID) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

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