org.apache.flink.runtime.dispatcher.DispatcherGateway Java Examples

The following examples show how to use org.apache.flink.runtime.dispatcher.DispatcherGateway. 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: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	if (jobExecutionResults.hasNext()) {
		lastJobExecutionResult = jobExecutionResults.next();
	}
	checkState(lastJobExecutionResult != null);
	if (lastJobExecutionResult instanceof JobExecutionResultResponseBody) {
		return CompletableFuture.completedFuture((JobExecutionResultResponseBody) lastJobExecutionResult);
	} else if (lastJobExecutionResult instanceof RestHandlerException) {
		return FutureUtils.completedExceptionally((RestHandlerException) lastJobExecutionResult);
	} else {
		throw new AssertionError();
	}
}
 
Example #2
Source File: JobSubmitHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccessfulJobSubmission() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
		objectOut.writeObject(new JobGraph("testjob"));
	}

	TestingDispatcherGateway.Builder builder = new TestingDispatcherGateway.Builder();
	builder
		.setBlobServerPort(blobServer.getPort())
		.setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get()))
		.setHostname("localhost");
	DispatcherGateway mockGateway = builder.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());

	handler.handleRequest(new HandlerRequest<>(request, EmptyMessageParameters.getInstance(), Collections.emptyMap(), Collections.emptyMap(), Collections.singleton(jobGraphFile.toFile())), mockGateway)
		.get();
}
 
Example #3
Source File: JobSubmitHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccessfulJobSubmission() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
		objectOut.writeObject(new JobGraph("testjob"));
	}

	TestingDispatcherGateway.Builder builder = new TestingDispatcherGateway.Builder();
	builder
		.setBlobServerPort(blobServer.getPort())
		.setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get()))
		.setHostname("localhost");
	DispatcherGateway mockGateway = builder.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());

	handler.handleRequest(new HandlerRequest<>(request, EmptyMessageParameters.getInstance(), Collections.emptyMap(), Collections.emptyMap(), Collections.singleton(jobGraphFile.toFile())), mockGateway)
		.get();
}
 
Example #4
Source File: JobSubmitHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializationFailureHandling() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	DispatcherGateway mockGateway = new TestingDispatcherGateway.Builder()
		.setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get()))
		.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.toString(), Collections.emptyList(), Collections.emptyList());

	try {
		handler.handleRequest(new HandlerRequest<>(request, EmptyMessageParameters.getInstance()), mockGateway);
		Assert.fail();
	} catch (RestHandlerException rhe) {
		Assert.assertEquals(HttpResponseStatus.BAD_REQUEST, rhe.getHttpResponseStatus());
	}
}
 
Example #5
Source File: MetricsHandlerTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);

	this.leaderRetriever = new GatewayRetriever<DispatcherGateway>() {
		@Override
		public CompletableFuture<DispatcherGateway> getFuture() {
			return CompletableFuture.completedFuture(mockDispatcherGateway);
		}
	};
	this.pathParameters = getPathParameters();
	this.metricsHandler = getMetricsHandler();

	final MetricStore metricStore = new MetricStore();
	metricStore.add(new MetricDump.CounterDump(getQueryScopeInfo(), TEST_METRIC_NAME,
		TEST_METRIC_VALUE));
	when(mockMetricFetcher.getMetricStore()).thenReturn(metricStore);
}
 
Example #6
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JobExecutionResultResponseBody> handleRequest(
		@Nonnull HandlerRequest<EmptyRequestBody, JobMessageParameters> request,
		@Nonnull DispatcherGateway gateway) throws RestHandlerException {
	if (jobExecutionResults.hasNext()) {
		lastJobExecutionResult = jobExecutionResults.next();
	}
	checkState(lastJobExecutionResult != null);
	if (lastJobExecutionResult instanceof JobExecutionResultResponseBody) {
		return CompletableFuture.completedFuture((JobExecutionResultResponseBody) lastJobExecutionResult);
	} else if (lastJobExecutionResult instanceof RestHandlerException) {
		return FutureUtils.completedExceptionally((RestHandlerException) lastJobExecutionResult);
	} else {
		throw new AssertionError();
	}
}
 
Example #7
Source File: AbstractMetricsHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);

	final MetricStore metricStore = new MetricStore();
	metricStore.add(new MetricDump.CounterDump(
		new QueryScopeInfo.JobManagerQueryScopeInfo(),
		TEST_METRIC_NAME,
		TEST_METRIC_VALUE));

	when(mockMetricFetcher.getMetricStore()).thenReturn(metricStore);

	testMetricsHandler = new TestMetricsHandler(
		new GatewayRetriever<DispatcherGateway>() {
			@Override
			public CompletableFuture<DispatcherGateway> getFuture() {
				return CompletableFuture.completedFuture(mockDispatcherGateway);
			}
		},
		Time.milliseconds(50),
		Collections.emptyMap(),
		new TestMetricsHeaders(),
		mockMetricFetcher);
}
 
Example #8
Source File: JarRunHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
public JarRunHandler(
		final GatewayRetriever<? extends DispatcherGateway> leaderRetriever,
		final Time timeout,
		final Map<String, String> responseHeaders,
		final MessageHeaders<JarRunRequestBody, JarRunResponseBody, JarRunMessageParameters> messageHeaders,
		final Path jarDir,
		final Configuration configuration,
		final Executor executor,
		final Supplier<ApplicationRunner> applicationRunnerSupplier) {
	super(leaderRetriever, timeout, responseHeaders, messageHeaders);

	this.jarDir = requireNonNull(jarDir);
	this.configuration = requireNonNull(configuration);
	this.executor = requireNonNull(executor);

	this.applicationRunner = applicationRunnerSupplier.get();
}
 
Example #9
Source File: JarRunHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<JarRunResponseBody> handleRequest(
		@Nonnull final HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request,
		@Nonnull final DispatcherGateway gateway) throws RestHandlerException {

	final Configuration effectiveConfiguration = new Configuration(configuration);
	effectiveConfiguration.set(DeploymentOptions.ATTACHED, false);
	effectiveConfiguration.set(DeploymentOptions.TARGET, EmbeddedExecutor.NAME);

	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);
	context.applyToConfiguration(effectiveConfiguration);
	SavepointRestoreSettings.toConfiguration(getSavepointRestoreSettings(request), effectiveConfiguration);

	final PackagedProgram program = context.toPackagedProgram(effectiveConfiguration);

	return CompletableFuture
			.supplyAsync(() -> applicationRunner.run(gateway, program, effectiveConfiguration), executor)
			.thenApply(jobIds -> {
				if (jobIds.isEmpty()) {
					throw new CompletionException(new ProgramInvocationException("No jobs submitted."));
				}
				return new JarRunResponseBody(jobIds.get(0));
			});
}
 
Example #10
Source File: JobSubmitHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<JobGraph> uploadJobGraphFiles(
		DispatcherGateway gateway,
		CompletableFuture<JobGraph> jobGraphFuture,
		Collection<Path> jarFiles,
		Collection<Tuple2<String, Path>> artifacts,
		Configuration configuration) {
	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	return jobGraphFuture.thenCombine(blobServerPortFuture, (JobGraph jobGraph, Integer blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.uploadJobGraphFiles(jobGraph, jarFiles, artifacts, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(new RestHandlerException(
				"Could not upload job files.",
				HttpResponseStatus.INTERNAL_SERVER_ERROR,
				e));
		}
		return jobGraph;
	});
}
 
Example #11
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected CompletableFuture<ClientCoordinationResponseBody> handleRequest(@Nonnull HandlerRequest<ClientCoordinationRequestBody, ClientCoordinationMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	try {
		TestCoordinationRequest req =
			(TestCoordinationRequest) request
				.getRequestBody()
				.getSerializedCoordinationRequest()
				.deserializeValue(getClass().getClassLoader());
		TestCoordinationResponse resp = new TestCoordinationResponse(req.payload);
		return CompletableFuture.completedFuture(
			new ClientCoordinationResponseBody(
				new SerializedValue<>(resp)));
	} catch (Exception e) {
		return FutureUtils.completedExceptionally(e);
	}
}
 
Example #12
Source File: JobSubmitHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<JobGraph> uploadJobGraphFiles(
		DispatcherGateway gateway,
		CompletableFuture<JobGraph> jobGraphFuture,
		Collection<Path> jarFiles,
		Collection<Tuple2<String, Path>> artifacts,
		Configuration configuration) {
	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	return jobGraphFuture.thenCombine(blobServerPortFuture, (JobGraph jobGraph, Integer blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.uploadJobGraphFiles(jobGraph, jarFiles, artifacts, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(new RestHandlerException(
				"Could not upload job files.",
				HttpResponseStatus.INTERNAL_SERVER_ERROR,
				e));
		}
		return jobGraph;
	});
}
 
Example #13
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	MockitoAnnotations.initMocks(this);

	final MetricStore metricStore = new MetricStore();
	metricStore.add(new MetricDump.CounterDump(
		new QueryScopeInfo.JobManagerQueryScopeInfo(),
		TEST_METRIC_NAME,
		TEST_METRIC_VALUE));

	when(mockMetricFetcher.getMetricStore()).thenReturn(metricStore);

	testMetricsHandler = new TestMetricsHandler(
		new GatewayRetriever<DispatcherGateway>() {
			@Override
			public CompletableFuture<DispatcherGateway> getFuture() {
				return CompletableFuture.completedFuture(mockDispatcherGateway);
			}
		},
		Time.milliseconds(50),
		Collections.emptyMap(),
		new TestMetricsHeaders(),
		mockMetricFetcher);
}
 
Example #14
Source File: ApplicationDispatcherBootstrap.java    From flink with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
CompletableFuture<Void> fixJobIdAndRunApplicationAsync(
		final DispatcherGateway dispatcher,
		final ScheduledExecutor scheduledExecutor) {

	final Optional<String> configuredJobId =
			configuration.getOptional(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID);

	if (!HighAvailabilityMode.isHighAvailabilityModeActivated(configuration) && !configuredJobId.isPresent()) {
		return runApplicationAsync(dispatcher, scheduledExecutor, false);
	}

	if (!configuredJobId.isPresent()) {
		configuration.set(PipelineOptionsInternal.PIPELINE_FIXED_JOB_ID, ZERO_JOB_ID.toHexString());
	}
	return runApplicationAsync(dispatcher, scheduledExecutor, true);
}
 
Example #15
Source File: MiniCluster.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public CompletableFuture<JobSubmissionResult> submitJob(JobGraph jobGraph) {
	final CompletableFuture<DispatcherGateway> dispatcherGatewayFuture = getDispatcherGatewayFuture();

	// we have to allow queued scheduling in Flip-6 mode because we need to request slots
	// from the ResourceManager
	jobGraph.setAllowQueuedScheduling(true);

	final CompletableFuture<InetSocketAddress> blobServerAddressFuture = createBlobServerAddress(dispatcherGatewayFuture);

	final CompletableFuture<Void> jarUploadFuture = uploadAndSetJobFiles(blobServerAddressFuture, jobGraph);

	final CompletableFuture<Acknowledge> acknowledgeCompletableFuture = jarUploadFuture
		.thenCombine(
			dispatcherGatewayFuture,
			(Void ack, DispatcherGateway dispatcherGateway) -> dispatcherGateway.submitJob(jobGraph, rpcTimeout))
		.thenCompose(Function.identity());

	return acknowledgeCompletableFuture.thenApply(
		(Acknowledge ignored) -> new JobSubmissionResult(jobGraph.getJobID()));
}
 
Example #16
Source File: EmbeddedExecutor.java    From flink with Apache License 2.0 6 votes vote down vote up
private static CompletableFuture<JobID> submitJob(
		final Configuration configuration,
		final DispatcherGateway dispatcherGateway,
		final JobGraph jobGraph,
		final Time rpcTimeout) {
	checkNotNull(jobGraph);

	LOG.info("Submitting Job with JobId={}.", jobGraph.getJobID());

	return dispatcherGateway
			.getBlobServerPort(rpcTimeout)
			.thenApply(blobServerPort -> new InetSocketAddress(dispatcherGateway.getHostname(), blobServerPort))
			.thenCompose(blobServerAddress -> {

				try {
					ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(blobServerAddress, configuration));
				} catch (FlinkException e) {
					throw new CompletionException(e);
				}

				return dispatcherGateway.submitJob(jobGraph, rpcTimeout);
			}).thenApply(ack -> jobGraph.getJobID());
}
 
Example #17
Source File: JobSubmitHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializationFailureHandling() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	DispatcherGateway mockGateway = new TestingDispatcherGateway.Builder()
		.setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get()))
		.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.toString(), Collections.emptyList(), Collections.emptyList());

	try {
		handler.handleRequest(new HandlerRequest<>(request, EmptyMessageParameters.getInstance()), mockGateway);
		Assert.fail();
	} catch (RestHandlerException rhe) {
		Assert.assertEquals(HttpResponseStatus.BAD_REQUEST, rhe.getHttpResponseStatus());
	}
}
 
Example #18
Source File: JobSubmitHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccessfulJobSubmission() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
		objectOut.writeObject(new JobGraph("testjob"));
	}

	TestingDispatcherGateway.Builder builder = new TestingDispatcherGateway.Builder();
	builder
		.setBlobServerPort(blobServer.getPort())
		.setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get()))
		.setHostname("localhost");
	DispatcherGateway mockGateway = builder.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());

	handler.handleRequest(new HandlerRequest<>(request, EmptyMessageParameters.getInstance(), Collections.emptyMap(), Collections.emptyMap(), Collections.singleton(jobGraphFile.toFile())), mockGateway)
		.get();
}
 
Example #19
Source File: AbstractMetricsHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private TestMetricsHandler(
	GatewayRetriever<DispatcherGateway> leaderRetriever,
	Time timeout,
	Map<String, String> headers,
	MessageHeaders<EmptyRequestBody,
		MetricCollectionResponseBody,
		TestMessageParameters> messageHeaders,
	MetricFetcher metricFetcher) {

	super(leaderRetriever, timeout, headers, messageHeaders, metricFetcher);
}
 
Example #20
Source File: JobStatusPollingUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Polls the {@link JobStatus} of a job periodically and when the job has reached
 * a terminal state, it requests its {@link JobResult}.
 *
 * @param dispatcherGateway the {@link DispatcherGateway} to be used for requesting the details of the job.
 * @param jobId the id of the job
 * @param scheduledExecutor the executor to be used to periodically request the status of the job
 * @param rpcTimeout the timeout of the rpc
 * @param retryPeriod the interval between two consecutive job status requests
 * @return a future that will contain the job's {@link JobResult}.
 */
static CompletableFuture<JobResult> getJobResult(
		final DispatcherGateway dispatcherGateway,
		final JobID jobId,
		final ScheduledExecutor scheduledExecutor,
		final Time rpcTimeout,
		final Time retryPeriod) {

	return pollJobResultAsync(
			() -> dispatcherGateway.requestJobStatus(jobId, rpcTimeout),
			() -> dispatcherGateway.requestJobResult(jobId, rpcTimeout),
			scheduledExecutor,
			retryPeriod.toMilliseconds()
	);
}
 
Example #21
Source File: RestClusterClientSavepointTriggerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<TriggerResponse> handleRequest(
	@Nonnull HandlerRequest<SavepointTriggerRequestBody, SavepointTriggerMessageParameters> request,
	@Nonnull DispatcherGateway gateway) throws RestHandlerException {

	return CompletableFuture.completedFuture(new TriggerResponse(triggerHandlerLogic.apply(request.getRequestBody())));
}
 
Example #22
Source File: JobSubmitHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectionOnCountMismatch() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
		objectOut.writeObject(new JobGraph("testjob"));
	}
	final Path countExceedingFile = TEMPORARY_FOLDER.newFile().toPath();

	TestingDispatcherGateway.Builder builder = new TestingDispatcherGateway.Builder();
	builder
		.setBlobServerPort(blobServer.getPort())
		.setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get()))
		.setHostname("localhost");
	DispatcherGateway mockGateway = builder.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());

	try {
		handler.handleRequest(new HandlerRequest<>(request, EmptyMessageParameters.getInstance(), Collections.emptyMap(), Collections.emptyMap(), Arrays.asList(jobGraphFile.toFile(), countExceedingFile.toFile())), mockGateway)
			.get();
	} catch (Exception e) {
		ExceptionUtils.findThrowable(e, candidate -> candidate instanceof RestHandlerException && candidate.getMessage().contains("count"));
	}
}
 
Example #23
Source File: JobSubmitHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailedJobSubmission() throws Exception {
	final String errorMessage = "test";
	DispatcherGateway mockGateway = new TestingDispatcherGateway.Builder()
		.setSubmitFunction(jobgraph -> FutureUtils.completedExceptionally(new Exception(errorMessage)))
		.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();

	JobGraph jobGraph = new JobGraph("testjob");
	try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
		objectOut.writeObject(jobGraph);
	}
	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());

	try {
		handler.handleRequest(new HandlerRequest<>(
				request,
				EmptyMessageParameters.getInstance(),
				Collections.emptyMap(),
				Collections.emptyMap(),
				Collections.singletonList(jobGraphFile.toFile())), mockGateway)
			.get();
	} catch (Exception e) {
		Throwable t = ExceptionUtils.stripExecutionException(e);
		Assert.assertEquals(errorMessage, t.getMessage());
	}
}
 
Example #24
Source File: ZooKeeperDefaultDispatcherRunnerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private DispatcherGateway grantLeadership(TestingLeaderElectionService dispatcherLeaderElectionService) throws InterruptedException, java.util.concurrent.ExecutionException {
	final UUID leaderSessionId = UUID.randomUUID();
	dispatcherLeaderElectionService.isLeader(leaderSessionId);
	final LeaderConnectionInfo leaderConnectionInfo = dispatcherLeaderElectionService.getConfirmationFuture().get();

	return testingRpcServiceResource.getTestingRpcService().connect(
		leaderConnectionInfo.getAddress(),
		DispatcherId.fromUuid(leaderSessionId),
		DispatcherGateway.class).get();
}
 
Example #25
Source File: ApplicationDispatcherBootstrap.java    From flink with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Void> getApplicationResult(
		final DispatcherGateway dispatcherGateway,
		final Collection<JobID> applicationJobIds,
		final ScheduledExecutor executor) {
	final List<CompletableFuture<?>> jobResultFutures = applicationJobIds
			.stream()
			.map(jobId -> unwrapJobResultException(getJobResult(dispatcherGateway, jobId, executor)))
			.collect(Collectors.toList());
	return FutureUtils.waitForAll(jobResultFutures);
}
 
Example #26
Source File: JarSubmissionITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private static JarRunResponseBody runJar(JarRunHandler handler, String jarName, DispatcherGateway restfulGateway) throws Exception {
	final JarRunMessageParameters runParameters = JarRunHeaders.getInstance().getUnresolvedMessageParameters();
	HandlerRequest<JarRunRequestBody, JarRunMessageParameters> runRequest = new HandlerRequest<>(
		new JarRunRequestBody(),
		runParameters,
		Collections.singletonMap(runParameters.jarIdPathParameter.getKey(), jarName),
		Collections.emptyMap(),
		Collections.emptyList());
	return handler.handleRequest(runRequest, restfulGateway)
		.get();
}
 
Example #27
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<EmptyResponseBody> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, EmptyMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final CompletableFuture<EmptyResponseBody> result = responseQueue.poll();

	if (result != null) {
		return result;
	} else {
		return CompletableFuture.completedFuture(EmptyResponseBody.getInstance());
	}
}
 
Example #28
Source File: JarRunHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<JarRunResponseBody> handleRequest(
		@Nonnull final HandlerRequest<JarRunRequestBody, JarRunMessageParameters> request,
		@Nonnull final DispatcherGateway gateway) throws RestHandlerException {
	final JarHandlerContext context = JarHandlerContext.fromRequest(request, jarDir, log);

	final SavepointRestoreSettings savepointRestoreSettings = getSavepointRestoreSettings(request);

	final CompletableFuture<JobGraph> jobGraphFuture = getJobGraphAsync(context, savepointRestoreSettings);

	CompletableFuture<Integer> blobServerPortFuture = gateway.getBlobServerPort(timeout);

	CompletableFuture<JobGraph> jarUploadFuture = jobGraphFuture.thenCombine(blobServerPortFuture, (jobGraph, blobServerPort) -> {
		final InetSocketAddress address = new InetSocketAddress(gateway.getHostname(), blobServerPort);
		try {
			ClientUtils.extractAndUploadJobGraphFiles(jobGraph, () -> new BlobClient(address, configuration));
		} catch (FlinkException e) {
			throw new CompletionException(e);
		}

		return jobGraph;
	});

	CompletableFuture<Acknowledge> jobSubmissionFuture = jarUploadFuture.thenCompose(jobGraph -> {
		// we have to enable queued scheduling because slots will be allocated lazily
		jobGraph.setAllowQueuedScheduling(true);
		return gateway.submitJob(jobGraph, timeout);
	});

	return jobSubmissionFuture
		.thenCombine(jarUploadFuture, (ack, jobGraph) -> new JarRunResponseBody(jobGraph.getJobID()));
}
 
Example #29
Source File: JarRunHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
public JarRunHandler(
		final GatewayRetriever<? extends DispatcherGateway> leaderRetriever,
		final Time timeout,
		final Map<String, String> responseHeaders,
		final MessageHeaders<JarRunRequestBody, JarRunResponseBody, JarRunMessageParameters> messageHeaders,
		final Path jarDir,
		final Configuration configuration,
		final Executor executor) {
	super(leaderRetriever, timeout, responseHeaders, messageHeaders);

	this.jarDir = requireNonNull(jarDir);
	this.configuration = requireNonNull(configuration);
	this.executor = requireNonNull(executor);
}
 
Example #30
Source File: ApplicationDispatcherBootstrap.java    From flink with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<JobResult> getJobResult(
		final DispatcherGateway dispatcherGateway,
		final JobID jobId,
		final ScheduledExecutor scheduledExecutor) {

	final Time timeout = Time.milliseconds(configuration.get(ClientOptions.CLIENT_TIMEOUT).toMillis());
	final Time retryPeriod = Time.milliseconds(configuration.get(ClientOptions.CLIENT_RETRY_PERIOD).toMillis());

	return JobStatusPollingUtils.getJobResult(
					dispatcherGateway, jobId, scheduledExecutor, timeout, retryPeriod);
}