@Override protected void channelRead0(ChannelHandlerContext ctx, Object message) { // we can't deal with this message. No one in the pipeline handled it. Log it. logger.debug("Unknown message received: {}", message); sendError(ctx, "Unknown message received."); }
File getBaseDir(Configuration configuration) { return new File(getBaseDirStr(configuration)); }
@After public void tearDown() { BlockingInvokable.reset(); }
final CompletableFuture<RestfulGateway> gatewayFuture = new CompletableFuture<>(); final GatewayRetriever<RestfulGateway> gatewayRetriever = () -> gatewayFuture; final RestfulGateway gateway = TestingRestfulGateway.newBuilder().build(); final TestingHandler testingHandler = new TestingHandler( gatewayRetriever, timeout); WebFrontendBootstrap bootstrap = new WebFrontendBootstrap( router, log, try (HttpTestClient httpClient = new HttpTestClient("localhost", bootstrap.getServerPort())) { httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout)); HttpTestClient.SimpleHttpResponse response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout)); Assert.assertEquals(HttpResponseStatus.SERVICE_UNAVAILABLE, response.getStatus()); httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout)); response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout)); Assert.assertEquals(HttpResponseStatus.OK, response.getStatus()); Assert.assertEquals(RESPONSE_MESSAGE, response.getContent()); bootstrap.shutdown();
assertTrue(getRunningJobs(CLUSTER.getClusterClient()).isEmpty()); while (getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) { Thread.sleep(10); try (HttpTestClient client = new HttpTestClient("localhost", getRestPort())) { client.sendPatchRequest("/jobs/" + jid + "/?mode=stop", deadline.timeLeft()); HttpTestClient.SimpleHttpResponse response = client.getNextResponse(deadline.timeLeft()); assertEquals(HttpResponseStatus.ACCEPTED, response.getStatus()); assertEquals("application/json; charset=UTF-8", response.getType()); assertEquals("{}", response.getContent()); while (!getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) { Thread.sleep(20); try (HttpTestClient client = new HttpTestClient("localhost", getRestPort())) { FiniteDuration timeout = new FiniteDuration(30, TimeUnit.SECONDS); client.sendGetRequest("/jobs/" + jid + "/config", timeout); HttpTestClient.SimpleHttpResponse response = client.getNextResponse(timeout); assertEquals(HttpResponseStatus.OK, response.getStatus()); assertEquals("application/json; charset=UTF-8", response.getType()); assertEquals("{\"jid\":\"" + jid + "\",\"name\":\"Stoppable streaming test job\"," + "\"execution-config\":{\"execution-mode\":\"PIPELINED\",\"restart-strategy\":\"Cluster level default restart strategy\"," + "\"job-parallelism\":-1,\"object-reuse-mode\":false,\"user-config\":{}}}", response.getContent()); BlockingInvokable.reset();
@Test public void getLogAndStdoutFiles() throws Exception { WebMonitorUtils.LogFileLocation logFiles = WebMonitorUtils.LogFileLocation.find(CLUSTER_CONFIGURATION); FileUtils.writeStringToFile(logFiles.logFile, "job manager log"); String logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/jobmanager/log"); assertTrue(logs.contains("job manager log")); FileUtils.writeStringToFile(logFiles.stdOutFile, "job manager out"); logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/jobmanager/stdout"); assertTrue(logs.contains("job manager out")); }
@Before public void setUp() throws Exception { jarDir = temporaryFolder.newFolder().toPath(); restfulGateway = TestingRestfulGateway.newBuilder().build(); jarDeleteHandler = new JarDeleteHandler( () -> CompletableFuture.completedFuture(restfulGateway), Time.seconds(10), Collections.emptyMap(), new JarDeleteHeaders(), jarDir, Executors.directExecutor() ); Files.createFile(jarDir.resolve(TEST_JAR_NAME)); }
@Test public void testGetArchivers() { JsonArchivist[] direct = WebRuntimeMonitor.getJsonArchivists(); JsonArchivist[] reflected = WebMonitorUtils.getJsonArchivists(); Assert.assertEquals(direct.length, reflected.length); for (int x = 0; x < direct.length; x++) { Assert.assertSame(direct[x].getClass(), reflected[x].getClass()); } }
@Override protected void initChannel(SocketChannel ch) { RouterHandler handler = new RouterHandler(WebFrontendBootstrap.this.router, new HashMap<>()); // SSL should be the first handler in the pipeline if (serverSSLFactory != null) { ch.pipeline().addLast("ssl", serverSSLFactory.createNettySSLHandler()); } ch.pipeline() .addLast(new HttpServerCodec()) .addLast(new ChunkedWriteHandler()) .addLast(new HttpRequestHandler(uploadDir)) .addLast(handler.getName(), handler) .addLast(new PipelineErrorHandler(WebFrontendBootstrap.this.log)); } };
/** * Tests dynamically loading of handlers such as {@link JarUploadHandler}. */ @Test public void testLoadWebSubmissionExtension() throws Exception { final Configuration configuration = new Configuration(); configuration.setString(JobManagerOptions.ADDRESS, "localhost"); final WebMonitorExtension webMonitorExtension = WebMonitorUtils.loadWebSubmissionExtension( CompletableFuture::new, Time.seconds(10), Collections.emptyMap(), CompletableFuture.completedFuture("localhost:12345"), Paths.get("/tmp"), Executors.directExecutor(), configuration); assertThat(webMonitorExtension, is(not(nullValue()))); } }
@Test public void getConfiguration() { try { String config = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/jobmanager/config"); Map<String, String> conf = WebMonitorUtils.fromKeyValueJsonArray(config); assertEquals( CLUSTER_CONFIGURATION.getString(ConfigConstants.LOCAL_START_WEBSERVER, null), conf.get(ConfigConstants.LOCAL_START_WEBSERVER)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void getFrontPage() { try { String fromHTTP = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/index.html"); String text = "Apache Flink Dashboard"; assertTrue("Startpage should contain " + text, fromHTTP.contains(text)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void testStopYarn() throws Exception { assertTrue(getRunningJobs(CLUSTER.getClusterClient()).isEmpty()); while (getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) { Thread.sleep(10); final Deadline deadline = testTimeout.fromNow(); try (HttpTestClient client = new HttpTestClient("localhost", getRestPort())) { client.sendGetRequest("/jobs/" + jid + "/yarn-stop", deadline.timeLeft()); .getNextResponse(deadline.timeLeft()); assertEquals(HttpResponseStatus.ACCEPTED, response.getStatus()); assertEquals("application/json; charset=UTF-8", response.getType()); assertEquals("{}", response.getContent()); while (!getRunningJobs(CLUSTER.getClusterClient()).isEmpty()) { Thread.sleep(20); BlockingInvokable.reset();
@Test public void getTaskManagerLogAndStdoutFiles() { try { String json = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/"); ObjectMapper mapper = new ObjectMapper(); JsonNode parsed = mapper.readTree(json); ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers"); JsonNode taskManager = taskManagers.get(0); String id = taskManager.get("id").asText(); WebMonitorUtils.LogFileLocation logFiles = WebMonitorUtils.LogFileLocation.find(CLUSTER_CONFIGURATION); //we check for job manager log files, since no separate taskmanager logs exist FileUtils.writeStringToFile(logFiles.logFile, "job manager log"); String logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/" + id + "/log"); assertTrue(logs.contains("job manager log")); FileUtils.writeStringToFile(logFiles.stdOutFile, "job manager out"); logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/" + id + "/stdout"); assertTrue(logs.contains("job manager out")); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { logger.debug("Unhandled exception: {}", cause); sendError(ctx, ExceptionUtils.stringifyException(cause)); }
private File getUploadDir(Configuration configuration) { File baseDir = new File(configuration.getString(WebOptions.UPLOAD_DIR, getBaseDirStr(configuration))); boolean uploadDirSpecified = configuration.contains(WebOptions.UPLOAD_DIR); return uploadDirSpecified ? baseDir : new File(baseDir, "flink-web-" + UUID.randomUUID()); }
@Test public void testResponseHeaders() throws Exception { // check headers for successful json response URL taskManagersUrl = new URL("http://localhost:" + getRestPort() + "/taskmanagers"); HttpURLConnection taskManagerConnection = (HttpURLConnection) taskManagersUrl.openConnection(); taskManagerConnection.setConnectTimeout(100000); taskManagerConnection.connect(); if (taskManagerConnection.getResponseCode() >= 400) { // error! InputStream is = taskManagerConnection.getErrorStream(); String errorMessage = IOUtils.toString(is, ConfigConstants.DEFAULT_CHARSET); throw new RuntimeException(errorMessage); } // we don't set the content-encoding header Assert.assertNull(taskManagerConnection.getContentEncoding()); Assert.assertEquals("application/json; charset=UTF-8", taskManagerConnection.getContentType()); // check headers in case of an error URL notFoundJobUrl = new URL("http://localhost:" + getRestPort() + "/jobs/dontexist"); HttpURLConnection notFoundJobConnection = (HttpURLConnection) notFoundJobUrl.openConnection(); notFoundJobConnection.setConnectTimeout(100000); notFoundJobConnection.connect(); if (notFoundJobConnection.getResponseCode() >= 400) { // we don't set the content-encoding header Assert.assertNull(notFoundJobConnection.getContentEncoding()); Assert.assertEquals("application/json; charset=UTF-8", notFoundJobConnection.getContentType()); } else { throw new RuntimeException("Request for non-existing job did not return an error."); } }
@Test public void getNumberOfTaskManagers() { try { String json = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/"); ObjectMapper mapper = new ObjectMapper(); JsonNode response = mapper.readTree(json); ArrayNode taskManagers = (ArrayNode) response.get("taskmanagers"); assertNotNull(taskManagers); assertEquals(NUM_TASK_MANAGERS, taskManagers.size()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@Test public void getTaskmanagers() throws Exception { String json = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/"); ObjectMapper mapper = new ObjectMapper(); JsonNode parsed = mapper.readTree(json); ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers"); assertNotNull(taskManagers); assertEquals(NUM_TASK_MANAGERS, taskManagers.size()); JsonNode taskManager = taskManagers.get(0); assertNotNull(taskManager); assertEquals(NUM_SLOTS, taskManager.get("slotsNumber").asInt()); assertTrue(taskManager.get("freeSlots").asInt() <= NUM_SLOTS); }