[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-26 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/flink/pull/5309


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-25 Thread tillrohrmann
Github user tillrohrmann commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r163905384
  
--- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/ExecutionGraphCacheTest.java
 ---
@@ -228,10 +246,10 @@ public void testConcurrentAccess() throws Exception {
Collection allExecutionGraphs = 
allExecutionGraphFutures.get();
--- End diff --

True, thanks for the info. Didn't know `ExecutorCompletionService` before.


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-25 Thread tillrohrmann
Github user tillrohrmann commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r163904466
  
--- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/ExecutionGraphCacheTest.java
 ---
@@ -199,12 +212,17 @@ public void testCacheEntryCleanup() throws Exception {
public void testConcurrentAccess() throws Exception {
final Time timeout = Time.milliseconds(100L);
final Time timeToLive = Time.hours(1L);
-   final JobID jobId = new JobID();
-
-   final AccessExecutionGraph accessExecutionGraph = 
mock(AccessExecutionGraph.class);
 
-   final JobManagerGateway jobManagerGateway = 
mock(JobManagerGateway.class);
-   when(jobManagerGateway.requestJob(eq(jobId), 
any(Time.class))).thenReturn(CompletableFuture.completedFuture(accessExecutionGraph));
+   final AtomicInteger requestJobCalls = new AtomicInteger(0);
--- End diff --

True, will change it.


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-25 Thread tillrohrmann
Github user tillrohrmann commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r163902431
  
--- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/ExecutionGraphCacheTest.java
 ---
@@ -30,62 +30,69 @@
 import org.apache.flink.runtime.executiongraph.ExecutionGraph;
 import org.apache.flink.runtime.jobgraph.JobStatus;
 import org.apache.flink.runtime.jobmanager.JobManager;
-import org.apache.flink.runtime.jobmaster.JobManagerGateway;
 import org.apache.flink.runtime.messages.FlinkJobNotFoundException;
+import 
org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.TestingRestfulGateway;
 import org.apache.flink.util.ExecutorUtils;
 import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.Preconditions;
 import org.apache.flink.util.TestLogger;
 
+import org.hamcrest.Matchers;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
 /**
  * Tests for the {@link ExecutionGraphCache}.
  */
 public class ExecutionGraphCacheTest extends TestLogger {
 
+   private static ArchivedExecutionGraph expectedExecutionGraph;
+   private static final JobID expectedJobId = new JobID();
+
+   @BeforeClass
+   public static void setup() {
+   expectedExecutionGraph = new 
ArchivedExecutionGraphBuilder().build();
+   }
+
/**
 * Tests that we can cache AccessExecutionGraphs over multiple accesses.
 */
@Test
public void testExecutionGraphCaching() throws Exception {
final Time timeout = Time.milliseconds(100L);
final Time timeToLive = Time.hours(1L);
-   final JobID jobId = new JobID();
-   final AccessExecutionGraph accessExecutionGraph = 
mock(AccessExecutionGraph.class);
 
-   final JobManagerGateway jobManagerGateway = 
mock(JobManagerGateway.class);
-   when(jobManagerGateway.requestJob(eq(jobId), 
any(Time.class))).thenReturn(CompletableFuture.completedFuture(accessExecutionGraph));
+   final CountingRestfulGateway restfulGateway = 
createCountingRestfulGateway(expectedJobId, 
CompletableFuture.completedFuture(expectedExecutionGraph));
 
try (ExecutionGraphCache executionGraphCache = new 
ExecutionGraphCache(timeout, timeToLive)) {
-   CompletableFuture 
accessExecutionGraphFuture = executionGraphCache.getExecutionGraph(jobId, 
jobManagerGateway);
+   CompletableFuture 
accessExecutionGraphFuture = 
executionGraphCache.getExecutionGraph(expectedJobId, restfulGateway);
 
-   assertEquals(accessExecutionGraph, 
accessExecutionGraphFuture.get());
+   assertEquals(expectedExecutionGraph, 
accessExecutionGraphFuture.get());
 
-   CompletableFuture 
accessExecutionGraphFuture2 = executionGraphCache.getExecutionGraph(jobId, 
jobManagerGateway);
+   CompletableFuture 
accessExecutionGraphFuture2 = 
executionGraphCache.getExecutionGraph(expectedJobId, restfulGateway);
 
-   assertEquals(accessExecutionGraph, 
accessExecutionGraphFuture2.get());
+   assertEquals(expectedExecutionGraph, 
accessExecutionGraphFuture2.get());
--- End diff --

True, will remove it.


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-25 Thread tillrohrmann
Github user tillrohrmann commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r163899592
  
--- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java 
---
@@ -331,13 +331,13 @@ public void start() throws Exception {
}
 
@Override
-   public CompletableFuture requestJob(JobID jobId, 
Time timeout) {
+   public CompletableFuture requestJob(JobID 
jobId, Time timeout) {
--- End diff --

True will change it.


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-24 Thread GJL
Github user GJL commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r163571196
  
--- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/ExecutionGraphCacheTest.java
 ---
@@ -228,10 +246,10 @@ public void testConcurrentAccess() throws Exception {
Collection allExecutionGraphs = 
allExecutionGraphFutures.get();
--- End diff --

Doesn't need to be changed but `ExecutorCompletionService` does something 
similar.


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-24 Thread GJL
Github user GJL commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r163570275
  
--- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/ExecutionGraphCacheTest.java
 ---
@@ -199,12 +212,17 @@ public void testCacheEntryCleanup() throws Exception {
public void testConcurrentAccess() throws Exception {
final Time timeout = Time.milliseconds(100L);
final Time timeToLive = Time.hours(1L);
-   final JobID jobId = new JobID();
-
-   final AccessExecutionGraph accessExecutionGraph = 
mock(AccessExecutionGraph.class);
 
-   final JobManagerGateway jobManagerGateway = 
mock(JobManagerGateway.class);
-   when(jobManagerGateway.requestJob(eq(jobId), 
any(Time.class))).thenReturn(CompletableFuture.completedFuture(accessExecutionGraph));
+   final AtomicInteger requestJobCalls = new AtomicInteger(0);
--- End diff --

Wouldn't it be easier to make `CountingRestfulGateway` thread safe, and 
reuse it here?


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-24 Thread GJL
Github user GJL commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r163546199
  
--- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/ExecutionGraphCacheTest.java
 ---
@@ -30,62 +30,69 @@
 import org.apache.flink.runtime.executiongraph.ExecutionGraph;
 import org.apache.flink.runtime.jobgraph.JobStatus;
 import org.apache.flink.runtime.jobmanager.JobManager;
-import org.apache.flink.runtime.jobmaster.JobManagerGateway;
 import org.apache.flink.runtime.messages.FlinkJobNotFoundException;
+import 
org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.TestingRestfulGateway;
 import org.apache.flink.util.ExecutorUtils;
 import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.Preconditions;
 import org.apache.flink.util.TestLogger;
 
+import org.hamcrest.Matchers;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
 /**
  * Tests for the {@link ExecutionGraphCache}.
  */
 public class ExecutionGraphCacheTest extends TestLogger {
 
+   private static ArchivedExecutionGraph expectedExecutionGraph;
+   private static final JobID expectedJobId = new JobID();
+
+   @BeforeClass
+   public static void setup() {
+   expectedExecutionGraph = new 
ArchivedExecutionGraphBuilder().build();
+   }
+
/**
 * Tests that we can cache AccessExecutionGraphs over multiple accesses.
 */
@Test
public void testExecutionGraphCaching() throws Exception {
final Time timeout = Time.milliseconds(100L);
final Time timeToLive = Time.hours(1L);
-   final JobID jobId = new JobID();
-   final AccessExecutionGraph accessExecutionGraph = 
mock(AccessExecutionGraph.class);
 
-   final JobManagerGateway jobManagerGateway = 
mock(JobManagerGateway.class);
-   when(jobManagerGateway.requestJob(eq(jobId), 
any(Time.class))).thenReturn(CompletableFuture.completedFuture(accessExecutionGraph));
+   final CountingRestfulGateway restfulGateway = 
createCountingRestfulGateway(expectedJobId, 
CompletableFuture.completedFuture(expectedExecutionGraph));
 
try (ExecutionGraphCache executionGraphCache = new 
ExecutionGraphCache(timeout, timeToLive)) {
-   CompletableFuture 
accessExecutionGraphFuture = executionGraphCache.getExecutionGraph(jobId, 
jobManagerGateway);
+   CompletableFuture 
accessExecutionGraphFuture = 
executionGraphCache.getExecutionGraph(expectedJobId, restfulGateway);
 
-   assertEquals(accessExecutionGraph, 
accessExecutionGraphFuture.get());
+   assertEquals(expectedExecutionGraph, 
accessExecutionGraphFuture.get());
 
-   CompletableFuture 
accessExecutionGraphFuture2 = executionGraphCache.getExecutionGraph(jobId, 
jobManagerGateway);
+   CompletableFuture 
accessExecutionGraphFuture2 = 
executionGraphCache.getExecutionGraph(expectedJobId, restfulGateway);
 
-   assertEquals(accessExecutionGraph, 
accessExecutionGraphFuture2.get());
+   assertEquals(expectedExecutionGraph, 
accessExecutionGraphFuture2.get());
--- End diff --

You can reassign `accessExecutionGraphFuture` to avoid `2`. I don't think 
`2` is adding anything to the readability.


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-24 Thread GJL
Github user GJL commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r163549462
  
--- Diff: 
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java 
---
@@ -331,13 +331,13 @@ public void start() throws Exception {
}
 
@Override
-   public CompletableFuture requestJob(JobID jobId, 
Time timeout) {
+   public CompletableFuture requestJob(JobID 
jobId, Time timeout) {
--- End diff --

nit: The git commit message is wrong: 

*Let JobMasterGateway#requestJob and DispatcherGateway#requestJob return a 
CompletableFuture\*


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-19 Thread tillrohrmann
Github user tillrohrmann commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r162560220
  
--- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/DummyExecutionGraph.java
 ---
@@ -0,0 +1,295 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.executiongraph;
+
+import org.apache.flink.api.common.ArchivedExecutionConfig;
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.accumulators.Accumulator;
+import org.apache.flink.api.common.accumulators.AccumulatorHelper;
+import org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult;
+import org.apache.flink.runtime.checkpoint.CheckpointStatsSnapshot;
+import org.apache.flink.runtime.jobgraph.JobStatus;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+import 
org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration;
+import org.apache.flink.util.Preconditions;
+import org.apache.flink.util.SerializedValue;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+/**
+ * {@link SerializableExecutionGraph} implementation for testing purposes.
+ */
+public class DummyExecutionGraph implements SerializableExecutionGraph {
--- End diff --

Yes you're right @zentol. Thanks for the pointer. Will remove 
`DummyExecutionGraph` and its builder and replace it with 
`ArchivedExecutionGraphBuilder`.


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-18 Thread zentol
Github user zentol commented on a diff in the pull request:

https://github.com/apache/flink/pull/5309#discussion_r162373027
  
--- Diff: 
flink-runtime/src/test/java/org/apache/flink/runtime/executiongraph/DummyExecutionGraph.java
 ---
@@ -0,0 +1,295 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.executiongraph;
+
+import org.apache.flink.api.common.ArchivedExecutionConfig;
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.accumulators.Accumulator;
+import org.apache.flink.api.common.accumulators.AccumulatorHelper;
+import org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult;
+import org.apache.flink.runtime.checkpoint.CheckpointStatsSnapshot;
+import org.apache.flink.runtime.jobgraph.JobStatus;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+import 
org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration;
+import org.apache.flink.util.Preconditions;
+import org.apache.flink.util.SerializedValue;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+/**
+ * {@link SerializableExecutionGraph} implementation for testing purposes.
+ */
+public class DummyExecutionGraph implements SerializableExecutionGraph {
--- End diff --

Looks a bit like a duplicate of 
https://github.com/apache/flink/blob/25e9f83c4ba522b111e2d661ae7715ad9a46f38b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/legacy/utils/ArchivedExecutionGraphBuilder.java
 .

(This is _not_ a review)


---


[GitHub] flink pull request #5309: [FLINK-8450] [flip6] Make JobMaster/DispatcherGate...

2018-01-18 Thread tillrohrmann
GitHub user tillrohrmann opened a pull request:

https://github.com/apache/flink/pull/5309

[FLINK-8450] [flip6] Make JobMaster/DispatcherGateway#requestJob type safe

## What is the purpose of the change

Let JobMasterGateway#requestJob and DispatcherGateway#requestJob return a
CompletableFuture instead of a
CompletableFuture. In order to support the old code
and the JobManagerGateway implementation we have to keep the return type
in RestfulGateway. Once the old code has been removed, we should change
this as well.

## Brief change log

- Change return type of `RestfulGateway#requestJob` to `CompletableFuture`
- Change return type of `JobMasterGateway#requestJob` and 
`DispatcherGateway#requestJob` to 
`CompletableFuture`
- Introduce `TestingRestfulGateway` as a testing utility
- Adapt `ExecutionGraphCacheTest` to use `TestingRestfulGateway` instead of 
Mockito mocks

## Verifying this change

This change is already covered by existing tests.

## Does this pull request potentially affect one of the following parts:

  - Dependencies (does it add or upgrade a dependency): (no)
  - The public API, i.e., is any changed class annotated with 
`@Public(Evolving)`: (no)
  - The serializers: (no)
  - The runtime per-record code paths (performance sensitive): (no)
  - Anything that affects deployment or recovery: JobManager (and its 
components), Checkpointing, Yarn/Mesos, ZooKeeper: (no)
  - The S3 file system connector: (no)

## Documentation

  - Does this pull request introduce a new feature? (no)
  - If yes, how is the feature documented? (not applicable)


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/tillrohrmann/flink makeRequestJobTypeSafe

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/flink/pull/5309.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #5309


commit 9883bed1cca16a419a46fe09ad1498ada42d67e2
Author: Till Rohrmann 
Date:   2018-01-16T17:45:53Z

[FLINK-8449] [flip6] Extend OnCompletionActions to accept an 
SerializableExecutionGraph

This commit introduces the SerializableExecutionGraph which extends the
AccessExecutionGraph and adds serializability to it. Moreover, this commit
changes the OnCompletionActions interface such that it accepts a
SerializableExecutionGraph instead of a plain JobResult. This allows to
archive the completed ExecutionGraph for further usage in the container
component of the JobMasterRunner.

commit 7ac8280eddad550f18bfecccb8f2959a422acf1f
Author: Till Rohrmann 
Date:   2018-01-17T14:01:57Z

[FLINK-8450] [flip6] Make JobMaster/DispatcherGateway#requestJob type safe

Let JobMasterGateway#requestJob and DispatcherGateway#requestJob return a
CompletableFuture instead of a
CompletableFuture. In order to support the old code
and the JobManagerGateway implementation we have to keep the return type
in RestfulGateway. Once the old code has been removed, we should change
this as well.




---