Java Code Examples for org.apache.flink.runtime.rest.handler.router.Router#addGet()

The following examples show how to use org.apache.flink.runtime.rest.handler.router.Router#addGet() . 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: HistoryServer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
void start() throws IOException, InterruptedException {
	synchronized (startupShutdownLock) {
		LOG.info("Starting history server.");

		Files.createDirectories(webDir.toPath());
		LOG.info("Using directory {} as local cache.", webDir);

		Router router = new Router();
		router.addGet("/:*", new HistoryServerStaticFileServerHandler(webDir));

		if (!webDir.exists() && !webDir.mkdirs()) {
			throw new IOException("Failed to create local directory " + webDir.getAbsoluteFile() + ".");
		}

		createDashboardConfigFile();

		archiveFetcher.start();

		netty = new WebFrontendBootstrap(router, LOG, webDir, serverSSLFactory, webAddress, webPort, config);
	}
}
 
Example 2
Source File: RestServerEndpoint.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static void registerHandler(Router router, String handlerURL, HttpMethodWrapper httpMethod, ChannelInboundHandler handler) {
	switch (httpMethod) {
		case GET:
			router.addGet(handlerURL, handler);
			break;
		case POST:
			router.addPost(handlerURL, handler);
			break;
		case DELETE:
			router.addDelete(handlerURL, handler);
			break;
		case PATCH:
			router.addPatch(handlerURL, handler);
			break;
		default:
			throw new RuntimeException("Unsupported http method: " + httpMethod + '.');
	}
}
 
Example 3
Source File: HistoryServer.java    From flink with Apache License 2.0 6 votes vote down vote up
void start() throws IOException, InterruptedException {
	synchronized (startupShutdownLock) {
		LOG.info("Starting history server.");

		Files.createDirectories(webDir.toPath());
		LOG.info("Using directory {} as local cache.", webDir);

		Router router = new Router();
		router.addGet("/:*", new HistoryServerStaticFileServerHandler(webDir));

		if (!webDir.exists() && !webDir.mkdirs()) {
			throw new IOException("Failed to create local directory " + webDir.getAbsoluteFile() + ".");
		}

		createDashboardConfigFile();

		archiveFetcher.start();

		netty = new WebFrontendBootstrap(router, LOG, webDir, serverSSLFactory, webAddress, webPort, config);
	}
}
 
Example 4
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void registerHandler(Router router, String handlerURL, HttpMethodWrapper httpMethod, ChannelInboundHandler handler) {
	switch (httpMethod) {
		case GET:
			router.addGet(handlerURL, handler);
			break;
		case POST:
			router.addPost(handlerURL, handler);
			break;
		case DELETE:
			router.addDelete(handlerURL, handler);
			break;
		case PATCH:
			router.addPatch(handlerURL, handler);
			break;
		default:
			throw new RuntimeException("Unsupported http method: " + httpMethod + '.');
	}
}
 
Example 5
Source File: HistoryServer.java    From flink with Apache License 2.0 6 votes vote down vote up
void start() throws IOException, InterruptedException {
	synchronized (startupShutdownLock) {
		LOG.info("Starting history server.");

		Files.createDirectories(webDir.toPath());
		LOG.info("Using directory {} as local cache.", webDir);

		Router router = new Router();
		router.addGet("/:*", new HistoryServerStaticFileServerHandler(webDir));

		if (!webDir.exists() && !webDir.mkdirs()) {
			throw new IOException("Failed to create local directory " + webDir.getAbsoluteFile() + ".");
		}

		createDashboardConfigFile();

		archiveFetcher.start();

		netty = new WebFrontendBootstrap(router, LOG, webDir, serverSSLFactory, webAddress, webPort, config);
	}
}
 
Example 6
Source File: RestServerEndpoint.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void registerHandler(Router router, String handlerURL, HttpMethodWrapper httpMethod, ChannelInboundHandler handler) {
	switch (httpMethod) {
		case GET:
			router.addGet(handlerURL, handler);
			break;
		case POST:
			router.addPost(handlerURL, handler);
			break;
		case DELETE:
			router.addDelete(handlerURL, handler);
			break;
		case PATCH:
			router.addPatch(handlerURL, handler);
			break;
		default:
			throw new RuntimeException("Unsupported http method: " + httpMethod + '.');
	}
}
 
Example 7
Source File: LeaderRetrievalHandlerTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the behaviour of the LeaderRetrievalHandler under the following conditions.
 *
 * <p>1. No gateway resolved --> service unavailable
 * 2. leader gateway
 * @throws Exception
 */
@Test
public void testLeaderRetrievalGateway() throws Exception {
	final String restPath = "/testing";

	final Configuration configuration = new Configuration();
	final Router router = new Router();
	final Time timeout = Time.seconds(10L);
	final CompletableFuture<RestfulGateway> gatewayFuture = new CompletableFuture<>();
	final GatewayRetriever<RestfulGateway> gatewayRetriever = () -> gatewayFuture;
	final RestfulGateway gateway = TestingRestfulGateway.newBuilder().build();

	final TestingHandler testingHandler = new TestingHandler(
		gatewayRetriever,
		timeout);

	router.addGet(restPath, testingHandler);
	WebFrontendBootstrap bootstrap = new WebFrontendBootstrap(
		router,
		log,
		null,
		null,
		"localhost",
		0,
		configuration);

	try (HttpTestClient httpClient = new HttpTestClient("localhost", bootstrap.getServerPort())) {
		// 1. no leader gateway available --> Service unavailable
		httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout));

		HttpTestClient.SimpleHttpResponse response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.SERVICE_UNAVAILABLE, response.getStatus());

		// 2. with leader
		gatewayFuture.complete(gateway);

		httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout));

		response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
		Assert.assertEquals(RESPONSE_MESSAGE, response.getContent());

	} finally {
		bootstrap.shutdown();
	}
}
 
Example 8
Source File: LeaderRetrievalHandlerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the behaviour of the LeaderRetrievalHandler under the following conditions.
 *
 * <p>1. No gateway resolved --> service unavailable
 * 2. leader gateway
 * @throws Exception
 */
@Test
public void testLeaderRetrievalGateway() throws Exception {
	final String restPath = "/testing";

	final Configuration configuration = new Configuration();
	final Router router = new Router();
	final Time timeout = Time.seconds(10L);
	final CompletableFuture<RestfulGateway> gatewayFuture = new CompletableFuture<>();
	final GatewayRetriever<RestfulGateway> gatewayRetriever = () -> gatewayFuture;
	final RestfulGateway gateway = TestingRestfulGateway.newBuilder().build();

	final TestingHandler testingHandler = new TestingHandler(
		gatewayRetriever,
		timeout);

	router.addGet(restPath, testingHandler);
	WebFrontendBootstrap bootstrap = new WebFrontendBootstrap(
		router,
		log,
		null,
		null,
		"localhost",
		0,
		configuration);

	try (HttpTestClient httpClient = new HttpTestClient("localhost", bootstrap.getServerPort())) {
		// 1. no leader gateway available --> Service unavailable
		httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout));

		HttpTestClient.SimpleHttpResponse response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.SERVICE_UNAVAILABLE, response.getStatus());

		// 2. with leader
		gatewayFuture.complete(gateway);

		httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout));

		response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
		Assert.assertEquals(RESPONSE_MESSAGE, response.getContent());

	} finally {
		bootstrap.shutdown();
	}
}
 
Example 9
Source File: LeaderRetrievalHandlerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the behaviour of the LeaderRetrievalHandler under the following conditions.
 *
 * <p>1. No gateway resolved --> service unavailable
 * 2. leader gateway
 * @throws Exception
 */
@Test
public void testLeaderRetrievalGateway() throws Exception {
	final String restPath = "/testing";

	final Configuration configuration = new Configuration();
	final Router router = new Router();
	final Time timeout = Time.seconds(10L);
	final CompletableFuture<RestfulGateway> gatewayFuture = new CompletableFuture<>();
	final GatewayRetriever<RestfulGateway> gatewayRetriever = () -> gatewayFuture;
	final RestfulGateway gateway = new TestingRestfulGateway.Builder().build();

	final TestingHandler testingHandler = new TestingHandler(
		gatewayRetriever,
		timeout);

	router.addGet(restPath, testingHandler);
	WebFrontendBootstrap bootstrap = new WebFrontendBootstrap(
		router,
		log,
		null,
		null,
		"localhost",
		0,
		configuration);

	try (HttpTestClient httpClient = new HttpTestClient("localhost", bootstrap.getServerPort())) {
		// 1. no leader gateway available --> Service unavailable
		httpClient.sendGetRequest(restPath, FutureUtils.toDuration(timeout));

		HttpTestClient.SimpleHttpResponse response = httpClient.getNextResponse(FutureUtils.toDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.SERVICE_UNAVAILABLE, response.getStatus());

		// 2. with leader
		gatewayFuture.complete(gateway);

		httpClient.sendGetRequest(restPath, FutureUtils.toDuration(timeout));

		response = httpClient.getNextResponse(FutureUtils.toDuration(timeout));

		Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
		Assert.assertEquals(RESPONSE_MESSAGE, response.getContent());

	} finally {
		bootstrap.shutdown();
	}
}