org.apache.flink.runtime.rest.handler.legacy.files.StaticFileServerHandler Java Examples

The following examples show how to use org.apache.flink.runtime.rest.handler.legacy.files.StaticFileServerHandler. 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: WebMonitorEndpoint.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
private ChannelInboundHandler createStaticFileHandler(
		Time timeout,
		File fileToServe) {

	if (fileToServe == null) {
		return new ConstantTextHandler("(file unavailable)");
	} else {
		try {
			return new StaticFileServerHandler<>(
				leaderRetriever,
				timeout,
				fileToServe);
		} catch (IOException e) {
			log.info("Cannot load log file handler.", e);
			return new ConstantTextHandler("(log file unavailable)");
		}
	}
}
 
Example #2
Source File: WebMonitorEndpoint.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
private ChannelInboundHandler createStaticFileHandler(
		Time timeout,
		File fileToServe) {

	if (fileToServe == null) {
		return new ConstantTextHandler("(file unavailable)");
	} else {
		try {
			return new StaticFileServerHandler<>(
				leaderRetriever,
				timeout,
				fileToServe);
		} catch (IOException e) {
			log.info("Cannot load log file handler.", e);
			return new ConstantTextHandler("(log file unavailable)");
		}
	}
}
 
Example #3
Source File: WebMonitorUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the flink-runtime-web dependency is available and if so returns a
 * StaticFileServerHandler which can serve the static file contents.
 *
 * @param leaderRetriever to be used by the StaticFileServerHandler
 * @param timeout for lookup requests
 * @param tmpDir to be used by the StaticFileServerHandler to store temporary files
 * @param <T> type of the gateway to retrieve
 * @return StaticFileServerHandler if flink-runtime-web is in the classpath; Otherwise Optional.empty
 * @throws IOException if we cannot create the StaticFileServerHandler
 */
public static <T extends RestfulGateway> Optional<StaticFileServerHandler<T>> tryLoadWebContent(
		GatewayRetriever<? extends T> leaderRetriever,
		Time timeout,
		File tmpDir) throws IOException {

	if (isFlinkRuntimeWebInClassPath()) {
		return Optional.of(new StaticFileServerHandler<>(
			leaderRetriever,
			timeout,
			tmpDir));
	} else {
		return Optional.empty();
	}
}
 
Example #4
Source File: WebMonitorUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the flink-runtime-web dependency is available and if so returns a
 * StaticFileServerHandler which can serve the static file contents.
 *
 * @param leaderRetriever to be used by the StaticFileServerHandler
 * @param timeout for lookup requests
 * @param tmpDir to be used by the StaticFileServerHandler to store temporary files
 * @param <T> type of the gateway to retrieve
 * @return StaticFileServerHandler if flink-runtime-web is in the classpath; Otherwise Optional.empty
 * @throws IOException if we cannot create the StaticFileServerHandler
 */
public static <T extends RestfulGateway> Optional<StaticFileServerHandler<T>> tryLoadWebContent(
		GatewayRetriever<? extends T> leaderRetriever,
		Time timeout,
		File tmpDir) throws IOException {

	if (isFlinkRuntimeWebInClassPath()) {
		return Optional.of(new StaticFileServerHandler<>(
			leaderRetriever,
			timeout,
			tmpDir));
	} else {
		return Optional.empty();
	}
}
 
Example #5
Source File: WebMonitorUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the flink-runtime-web dependency is available and if so returns a
 * StaticFileServerHandler which can serve the static file contents.
 *
 * @param leaderRetriever to be used by the StaticFileServerHandler
 * @param timeout for lookup requests
 * @param tmpDir to be used by the StaticFileServerHandler to store temporary files
 * @param <T> type of the gateway to retrieve
 * @return StaticFileServerHandler if flink-runtime-web is in the classpath; Otherwise Optional.empty
 * @throws IOException if we cannot create the StaticFileServerHandler
 */
public static <T extends RestfulGateway> Optional<StaticFileServerHandler<T>> tryLoadWebContent(
		GatewayRetriever<? extends T> leaderRetriever,
		Time timeout,
		File tmpDir) throws IOException {

	if (isFlinkRuntimeWebInClassPath()) {
		return Optional.of(new StaticFileServerHandler<>(
			leaderRetriever,
			timeout,
			tmpDir));
	} else {
		return Optional.empty();
	}
}
 
Example #6
Source File: RestServerEndpointITCase.java    From Flink-CEPplus 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.createRestClientSSLContext(config);
	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 #7
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 #8
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();
}