org.apache.flink.runtime.rest.handler.RestHandlerSpecification Java Examples

The following examples show how to use org.apache.flink.runtime.rest.handler.RestHandlerSpecification. 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: RestAPIDocGeneratorTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(CompletableFuture<String> localAddressFuture) {
	return Arrays.asList(
		Tuple2.of(
			new TestEmptyMessageHeaders(
				"/test/empty1",
				"This is a testing REST API."), null),
		Tuple2.of(
			new TestEmptyMessageHeaders(
				"/test/empty2",
				"This is another testing REST API."), null),
		Tuple2.of(
			new TestExcludeMessageHeaders(
				"/test/exclude1",
				"This REST API should not appear in the generated documentation."), null),
		Tuple2.of(
			new TestExcludeMessageHeaders(
				"/test/exclude2",
				"This REST API should also not appear in the generated documentation."), null));
}
 
Example #2
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testDuplicateHandlerRegistrationIsForbidden() throws Exception {
	final RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(new TestHeaders(), testHandler),
		Tuple2.of(TestUploadHeaders.INSTANCE, testHandler)
	);

	assertThrows("Duplicate REST handler",
		FlinkRuntimeException.class,
		() -> {
			try (TestRestServerEndpoint restServerEndpoint =  new TestRestServerEndpoint(serverConfig, handlers)) {
				restServerEndpoint.start();
				return null;
			}
		});
}
 
Example #3
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testEndpointsMustBeUnique() throws Exception {
	final RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(new TestHeaders(), testHandler),
		Tuple2.of(new TestHeaders(), testUploadHandler)
	);

	assertThrows("REST handler registration",
		FlinkRuntimeException.class,
		() -> {
			try (TestRestServerEndpoint restServerEndpoint =  new TestRestServerEndpoint(serverConfig, handlers)) {
				restServerEndpoint.start();
				return null;
			}
		});
}
 
Example #4
Source File: TestRestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = new ArrayList<>(abstractRestHandlers.length);
	for (final AbstractRestHandler abstractRestHandler : abstractRestHandlers) {
		handlers.add(Tuple2.of(
			abstractRestHandler.getMessageHeaders(),
			abstractRestHandler));
	}
	return handlers;
}
 
Example #5
Source File: TestRestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = new ArrayList<>(abstractRestHandlers.length);
	for (final AbstractRestHandler abstractRestHandler : abstractRestHandlers) {
		handlers.add(Tuple2.of(
			abstractRestHandler.getMessageHeaders(),
			abstractRestHandler));
	}
	return handlers;
}
 
Example #6
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void before() throws Exception {
	temporaryFolder.create();
	Configuration config = new Configuration();
	config.setString(RestOptions.BIND_PORT, "0");
	config.setString(RestOptions.ADDRESS, "localhost");
	// set this to a lower value on purpose to test that files larger than the content limit are still accepted
	config.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, 1024 * 1024);
	configuredUploadDir = temporaryFolder.newFolder().toPath();
	config.setString(WebOptions.UPLOAD_DIR, configuredUploadDir.toString());

	RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);

	final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () ->
		CompletableFuture.completedFuture(mockRestfulGateway);

	file1 = temporaryFolder.newFile();
	try (RandomAccessFile rw = new RandomAccessFile(file1, "rw")) {
		rw.setLength(1024 * 1024 * 64);
	}
	file2 = temporaryFolder.newFile();
	Files.write(file2.toPath(), "world".getBytes(ConfigConstants.DEFAULT_CHARSET));

	mixedHandler = new MultipartMixedHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));
	jsonHandler = new MultipartJsonHandler(mockGatewayRetriever);
	fileHandler = new MultipartFileHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(mixedHandler.getMessageHeaders(), mixedHandler),
		Tuple2.of(jsonHandler.getMessageHeaders(), jsonHandler),
		Tuple2.of(fileHandler.getMessageHeaders(), fileHandler));

	serverEndpoint = new TestRestServerEndpoint(serverConfig, handlers);

	serverEndpoint.start();
	serverAddress = serverEndpoint.getRestBaseUrl();
	serverSocketAddress = serverEndpoint.getServerAddress();
}
 
Example #7
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o1,
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o2) {
	final int urlComparisonResult = CASE_INSENSITIVE_ORDER.compare(o1.f0.getTargetRestEndpointURL(), o2.f0.getTargetRestEndpointURL());
	if (urlComparisonResult != 0) {
		return urlComparisonResult;
	} else {
		return API_VERSION_ORDER.compare(
			Collections.min(o1.f0.getSupportedAPIVersions()),
			Collections.min(o2.f0.getSupportedAPIVersions()));
	}
}
 
Example #8
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void registerHandler(Router router, Tuple2<RestHandlerSpecification, ChannelInboundHandler> specificationHandler, Logger log) {
	final String handlerURL = specificationHandler.f0.getTargetRestEndpointURL();
	// setup versioned urls
	for (final RestAPIVersion supportedVersion : specificationHandler.f0.getSupportedAPIVersions()) {
		final String versionedHandlerURL = '/' + supportedVersion.getURLVersionPrefix() + handlerURL;
		log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), versionedHandlerURL);
		registerHandler(router, versionedHandlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		if (supportedVersion.isDefaultVersion()) {
			// setup unversioned url for convenience and backwards compatibility
			log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), handlerURL);
			registerHandler(router, handlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		}
	}
}
 
Example #9
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void registerHandler(Router router, Tuple2<RestHandlerSpecification, ChannelInboundHandler> specificationHandler, Logger log) {
	final String handlerURL = specificationHandler.f0.getTargetRestEndpointURL();
	// setup versioned urls
	for (final RestAPIVersion supportedVersion : specificationHandler.f0.getSupportedAPIVersions()) {
		final String versionedHandlerURL = '/' + supportedVersion.getURLVersionPrefix() + handlerURL;
		log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), versionedHandlerURL);
		registerHandler(router, versionedHandlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		if (supportedVersion.isDefaultVersion()) {
			// setup unversioned url for convenience and backwards compatibility
			log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), handlerURL);
			registerHandler(router, handlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		}
	}
}
 
Example #10
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
private static void checkAllEndpointsAndHandlersAreUnique(final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers) {
	// check for all handlers that
	// 1) the instance is only registered once
	// 2) only 1 handler is registered for each endpoint (defined by (version, method, url))
	// technically the first check is redundant since a duplicate instance also returns the same headers which
	// should fail the second check, but we get a better error message
	final Set<String> uniqueEndpoints = new HashSet<>();
	final Set<ChannelInboundHandler> distinctHandlers = Collections.newSetFromMap(new IdentityHashMap<>());
	for (Tuple2<RestHandlerSpecification, ChannelInboundHandler> handler : handlers) {
		boolean isNewHandler = distinctHandlers.add(handler.f1);
		if (!isNewHandler) {
			throw new FlinkRuntimeException("Duplicate REST handler instance found."
				+ " Please ensure each instance is registered only once.");
		}

		final RestHandlerSpecification headers = handler.f0;
		for (RestAPIVersion supportedAPIVersion : headers.getSupportedAPIVersions()) {
			final String parameterizedEndpoint = supportedAPIVersion.toString() + headers.getHttpMethod() + headers.getTargetRestEndpointURL();
			// normalize path parameters; distinct path parameters still clash at runtime
			final String normalizedEndpoint = parameterizedEndpoint.replaceAll(":[\\w-]+", ":param");
			boolean isNewEndpoint = uniqueEndpoints.add(normalizedEndpoint);
			if (!isNewEndpoint) {
				throw new FlinkRuntimeException(
					String.format(
						"REST handler registration overlaps with another registration for: version=%s, method=%s, url=%s.",
						supportedAPIVersion, headers.getHttpMethod(), headers.getTargetRestEndpointURL()));
			}
		}
	}
}
 
Example #11
Source File: TestRestServerEndpoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = new ArrayList<>(abstractRestHandlers.length);
	for (final AbstractRestHandler abstractRestHandler : abstractRestHandlers) {
		handlers.add(Tuple2.of(
			abstractRestHandler.getMessageHeaders(),
			abstractRestHandler));
	}
	return handlers;
}
 
Example #12
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o1,
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o2) {
	final int urlComparisonResult = CASE_INSENSITIVE_ORDER.compare(o1.f0.getTargetRestEndpointURL(), o2.f0.getTargetRestEndpointURL());
	if (urlComparisonResult != 0) {
		return urlComparisonResult;
	} else {
		return API_VERSION_ORDER.compare(
			Collections.min(o1.f0.getSupportedAPIVersions()),
			Collections.min(o2.f0.getSupportedAPIVersions()));
	}
}
 
Example #13
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void before() throws Exception {
	temporaryFolder.create();
	Configuration config = new Configuration();
	config.setString(RestOptions.BIND_PORT, "0");
	config.setString(RestOptions.ADDRESS, "localhost");
	// set this to a lower value on purpose to test that files larger than the content limit are still accepted
	config.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, 1024 * 1024);
	configuredUploadDir = temporaryFolder.newFolder().toPath();
	config.setString(WebOptions.UPLOAD_DIR, configuredUploadDir.toString());

	RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);

	final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () ->
		CompletableFuture.completedFuture(mockRestfulGateway);

	file1 = temporaryFolder.newFile();
	try (RandomAccessFile rw = new RandomAccessFile(file1, "rw")) {
		rw.setLength(1024 * 1024 * 64);
	}
	file2 = temporaryFolder.newFile();
	Files.write(file2.toPath(), "world".getBytes(ConfigConstants.DEFAULT_CHARSET));

	mixedHandler = new MultipartMixedHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));
	jsonHandler = new MultipartJsonHandler(mockGatewayRetriever);
	fileHandler = new MultipartFileHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(mixedHandler.getMessageHeaders(), mixedHandler),
		Tuple2.of(jsonHandler.getMessageHeaders(), jsonHandler),
		Tuple2.of(fileHandler.getMessageHeaders(), fileHandler));

	serverEndpoint = new TestRestServerEndpoint(serverConfig, handlers);

	serverEndpoint.start();
	serverAddress = serverEndpoint.getRestBaseUrl();
	serverSocketAddress = serverEndpoint.getServerAddress();
}
 
Example #14
Source File: MultipartUploadResource.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void before() throws Exception {
	temporaryFolder.create();
	Configuration config = new Configuration();
	config.setString(RestOptions.BIND_PORT, "0");
	config.setString(RestOptions.ADDRESS, "localhost");
	// set this to a lower value on purpose to test that files larger than the content limit are still accepted
	config.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, 1024 * 1024);
	configuredUploadDir = temporaryFolder.newFolder().toPath();
	config.setString(WebOptions.UPLOAD_DIR, configuredUploadDir.toString());

	RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);

	final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () ->
		CompletableFuture.completedFuture(mockRestfulGateway);

	file1 = temporaryFolder.newFile();
	try (RandomAccessFile rw = new RandomAccessFile(file1, "rw")) {
		rw.setLength(1024 * 1024 * 64);
	}
	file2 = temporaryFolder.newFile();
	Files.write(file2.toPath(), "world".getBytes(ConfigConstants.DEFAULT_CHARSET));

	mixedHandler = new MultipartMixedHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));
	jsonHandler = new MultipartJsonHandler(mockGatewayRetriever);
	fileHandler = new MultipartFileHandler(mockGatewayRetriever, Arrays.asList(file1.toPath(), file2.toPath()));

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(mixedHandler.getMessageHeaders(), mixedHandler),
		Tuple2.of(jsonHandler.getMessageHeaders(), jsonHandler),
		Tuple2.of(fileHandler.getMessageHeaders(), fileHandler));

	serverEndpoint = new TestRestServerEndpoint(serverConfig, handlers);

	serverEndpoint.start();
	serverAddress = serverEndpoint.getRestBaseUrl();
	serverSocketAddress = serverEndpoint.getServerAddress();
}
 
Example #15
Source File: RestServerEndpoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o1,
		Tuple2<RestHandlerSpecification, ChannelInboundHandler> o2) {
	final int urlComparisonResult = CASE_INSENSITIVE_ORDER.compare(o1.f0.getTargetRestEndpointURL(), o2.f0.getTargetRestEndpointURL());
	if (urlComparisonResult != 0) {
		return urlComparisonResult;
	} else {
		return API_VERSION_ORDER.compare(
			Collections.min(o1.f0.getSupportedAPIVersions()),
			Collections.min(o2.f0.getSupportedAPIVersions()));
	}
}
 
Example #16
Source File: RestServerEndpoint.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static void registerHandler(Router router, Tuple2<RestHandlerSpecification, ChannelInboundHandler> specificationHandler, Logger log) {
	final String handlerURL = specificationHandler.f0.getTargetRestEndpointURL();
	// setup versioned urls
	for (final RestAPIVersion supportedVersion : specificationHandler.f0.getSupportedAPIVersions()) {
		final String versionedHandlerURL = '/' + supportedVersion.getURLVersionPrefix() + handlerURL;
		log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), versionedHandlerURL);
		registerHandler(router, versionedHandlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		if (supportedVersion.isDefaultVersion()) {
			// setup unversioned url for convenience and backwards compatibility
			log.debug("Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), handlerURL);
			registerHandler(router, handlerURL, specificationHandler.f0.getHttpMethod(), specificationHandler.f1);
		}
	}
}
 
Example #17
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 4 votes vote down vote up
TestRestServerEndpoint(
	RestServerEndpointConfiguration configuration,
	List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers) throws IOException {
	super(configuration);
	this.handlers = requireNonNull(handlers);
}
 
Example #18
Source File: MultipartUploadResource.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	return handlers;
}
 
Example #19
Source File: DocumentingDispatcherRestEndpoint.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	return super.initializeHandlers(localAddressFuture);
}
 
Example #20
Source File: WebMonitorExtension.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> getHandlers() {
	return Collections.emptyList();
}
 
Example #21
Source File: DispatcherRestEndpoint.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = super.initializeHandlers(localAddressFuture);

	// Add the Dispatcher specific handlers

	final Time timeout = restConfiguration.getTimeout();

	JobSubmitHandler jobSubmitHandler = new JobSubmitHandler(
		leaderRetriever,
		timeout,
		responseHeaders,
		executor,
		clusterConfiguration);

	if (restConfiguration.isWebSubmitEnabled()) {
		try {
			webSubmissionExtension = WebMonitorUtils.loadWebSubmissionExtension(
				leaderRetriever,
				timeout,
				responseHeaders,
				localAddressFuture,
				uploadDir,
				executor,
				clusterConfiguration);

			// register extension handlers
			handlers.addAll(webSubmissionExtension.getHandlers());
		} catch (FlinkException e) {
			if (log.isDebugEnabled()) {
				log.debug("Failed to load web based job submission extension.", e);
			} else {
				log.info("Failed to load web based job submission extension. " +
					"Probable reason: flink-runtime-web is not in the classpath.");
			}
		}
	} else {
		log.info("Web-based job submission is not enabled.");
	}

	handlers.add(Tuple2.of(jobSubmitHandler.getMessageHeaders(), jobSubmitHandler));

	return handlers;
}
 
Example #22
Source File: WebSubmissionExtension.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> getHandlers() {
	return webSubmissionHandlers;
}
 
Example #23
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
	config.setString(WebOptions.UPLOAD_DIR, temporaryFolder.newFolder().getCanonicalPath());

	defaultSSLContext = SSLContext.getDefault();
	defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
	final SSLContext sslClientContext = SSLUtils.createRestSSLContext(config, true);
	if (sslClientContext != null) {
		SSLContext.setDefault(sslClientContext);
		HttpsURLConnection.setDefaultSSLSocketFactory(sslClientContext.getSocketFactory());
	}

	RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);
	RestClientConfiguration clientConfig = RestClientConfiguration.fromConfiguration(config);

	RestfulGateway mockRestfulGateway = mock(RestfulGateway.class);

	final GatewayRetriever<RestfulGateway> mockGatewayRetriever = () ->
		CompletableFuture.completedFuture(mockRestfulGateway);

	testHandler = new TestHandler(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	TestVersionHandler testVersionHandler = new TestVersionHandler(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	TestVersionSelectionHandler1 testVersionSelectionHandler1 = new TestVersionSelectionHandler1(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	TestVersionSelectionHandler2 testVersionSelectionHandler2 = new TestVersionSelectionHandler2(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	testUploadHandler = new TestUploadHandler(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT);

	final StaticFileServerHandler<RestfulGateway> staticFileServerHandler = new StaticFileServerHandler<>(
		mockGatewayRetriever,
		RpcUtils.INF_TIMEOUT,
		temporaryFolder.getRoot());

	final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = Arrays.asList(
		Tuple2.of(new TestHeaders(), testHandler),
		Tuple2.of(TestUploadHeaders.INSTANCE, testUploadHandler),
		Tuple2.of(testVersionHandler.getMessageHeaders(), testVersionHandler),
		Tuple2.of(testVersionSelectionHandler1.getMessageHeaders(), testVersionSelectionHandler1),
		Tuple2.of(testVersionSelectionHandler2.getMessageHeaders(), testVersionSelectionHandler2),
		Tuple2.of(WebContentHandlerSpecification.getInstance(), staticFileServerHandler));

	serverEndpoint = new TestRestServerEndpoint(serverConfig, handlers);
	restClient = new TestRestClient(clientConfig);

	serverEndpoint.start();
	serverAddress = serverEndpoint.getServerAddress();
}
 
Example #24
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
TestRestServerEndpoint(
		RestServerEndpointConfiguration configuration,
		List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers) throws IOException {
	super(configuration);
	this.handlers = requireNonNull(handlers);
}
 
Example #25
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	return handlers;
}
 
Example #26
Source File: DocumentingDispatcherRestEndpoint.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	return super.initializeHandlers(localAddressFuture);
}
 
Example #27
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	return handlers;
}
 
Example #28
Source File: RestServerEndpointITCase.java    From flink with Apache License 2.0 4 votes vote down vote up
TestRestServerEndpoint(
		RestServerEndpointConfiguration configuration,
		List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers) throws IOException {
	super(configuration);
	this.handlers = requireNonNull(handlers);
}
 
Example #29
Source File: WebSubmissionExtension.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> getHandlers() {
	return webSubmissionHandlers;
}
 
Example #30
Source File: DispatcherRestEndpoint.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> initializeHandlers(final CompletableFuture<String> localAddressFuture) {
	List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers = super.initializeHandlers(localAddressFuture);

	// Add the Dispatcher specific handlers

	final Time timeout = restConfiguration.getTimeout();

	JobSubmitHandler jobSubmitHandler = new JobSubmitHandler(
		leaderRetriever,
		timeout,
		responseHeaders,
		executor,
		clusterConfiguration);

	if (clusterConfiguration.getBoolean(WebOptions.SUBMIT_ENABLE)) {
		try {
			webSubmissionExtension = WebMonitorUtils.loadWebSubmissionExtension(
				leaderRetriever,
				timeout,
				responseHeaders,
				localAddressFuture,
				uploadDir,
				executor,
				clusterConfiguration);

			// register extension handlers
			handlers.addAll(webSubmissionExtension.getHandlers());
		} catch (FlinkException e) {
			if (log.isDebugEnabled()) {
				log.debug("Failed to load web based job submission extension.", e);
			} else {
				log.info("Failed to load web based job submission extension. " +
					"Probable reason: flink-runtime-web is not in the classpath.");
			}
		}
	} else {
		log.info("Web-based job submission is not enabled.");
	}

	handlers.add(Tuple2.of(jobSubmitHandler.getMessageHeaders(), jobSubmitHandler));

	return handlers;
}