tillrohrmann commented on a change in pull request #18220:
URL: https://github.com/apache/flink/pull/18220#discussion_r779362854



##########
File path: 
flink-yarn/src/test/java/org/apache/flink/yarn/ApplicationReportProviderImplTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.yarn;
+
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.junit.Test;

Review comment:
       New tests should use Junit5.

##########
File path: 
flink-yarn/src/test/java/org/apache/flink/yarn/ApplicationReportProviderImplTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.yarn;
+
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/** Tests for the {@link ApplicationReportProviderImpl}. */
+public class ApplicationReportProviderImplTest extends AbstractYarnClusterTest 
{
+
+    /**
+     * When yarnClient has been stopped and then retrieving app report from 
Yarn, it should fail
+     * fast and throw exception.
+     */
+    @Test
+    public void testWhenYarnClientStoppedShouldThrowException() {
+        final YarnClient yarnClient = YarnClient.createYarnClient();
+        initilizeYarnClient(yarnClient);
+        yarnClient.stop();
+        assertTrue(yarnClient.isInState(Service.STATE.STOPPED));
+
+        try {
+            ApplicationReportProviderImpl.of(yarnClient, 
null).waitTillSubmissionFinish();
+            fail();
+        } catch (Exception e) {
+            assertEquals(
+                    "Errors on using YarnClient to retrieve application 
report. Maybe it has been closed by YarnClusterDescriptor.",
+                    e.getMessage());
+        }

Review comment:
       You could use `assertThatThrownBy`

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterClientProvider.java
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.client.program.ClusterClient;
+import org.apache.flink.client.program.ClusterClientProvider;
+import org.apache.flink.client.program.rest.RestClusterClient;
+import org.apache.flink.configuration.Configuration;
+
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.flink.yarn.YarnClusterDescriptor.setClusterEntrypointInfoToConfig;
+
+/**
+ * The implementation of {@link ClusterClientProvider}, waiting for the job to 
be running and then
+ * creating a {@link RestClusterClient} with the respective connection 
information.
+ */
+@Internal
+public class YarnClusterClientProvider implements ClusterClientProvider {
+    private static final Logger LOG = 
LoggerFactory.getLogger(YarnClusterClientProvider.class);
+
+    private final ApplicationId applicationId;
+    private final ApplicationReportProvider appReportProvider;
+    private final Configuration flinkConf;
+
+    private volatile boolean submissionFinished = false;
+
+    private YarnClusterClientProvider(
+            ApplicationReportProvider applicationReportProvider,
+            Configuration flinkConfiguration,
+            ApplicationId applicationId) {
+        this.appReportProvider = applicationReportProvider;
+        this.flinkConf = flinkConfiguration;

Review comment:
       I think it is better to copy the configuration. That way the caller of 
the constructor cannot change the config afterwards.

##########
File path: 
flink-yarn/src/test/java/org/apache/flink/yarn/YarnClusterClientProviderTest.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.yarn.configuration.YarnConfigOptions;
+
+import org.apache.commons.beanutils.ConvertUtils;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.util.Records;
+import org.junit.Test;
+
+import static 
org.apache.hadoop.yarn.api.records.FinalApplicationStatus.UNDEFINED;
+import static org.junit.Assert.assertEquals;
+
+/** Test for {@link YarnClusterClientProvider}. */
+public class YarnClusterClientProviderTest {
+
+    /** Once Yarn app master has been running, it should not retrieve app 
report again. */
+    @Test
+    public void testNoLongerRetrieveAppReportOnceAppRunning() {
+        final Configuration flinkConf = new Configuration();
+        final ApplicationId applicationId =
+                ApplicationId.newInstance(System.currentTimeMillis(), 1);
+
+        final ApplicationReportProvider mockAppReportProvider =
+                MockApplicationReportProvider.of(applicationId, "localhost", 
10);
+        assertEquals(0, ((MockApplicationReportProvider) 
mockAppReportProvider).getInvokeNumber());
+
+        YarnClusterClientProvider provider =
+                YarnClusterClientProvider.of(mockAppReportProvider, flinkConf, 
applicationId);
+
+        provider.getClusterClient();
+        assertEquals(1, ((MockApplicationReportProvider) 
mockAppReportProvider).getInvokeNumber());
+
+        provider.getClusterClient();
+        assertEquals(1, ((MockApplicationReportProvider) 
mockAppReportProvider).getInvokeNumber());
+    }
+
+    @Test
+    public void testJMHostShouldSetIntoConfig() {
+        final Configuration flinkConf = new Configuration();
+        final ApplicationId applicationId =
+                ApplicationId.newInstance(System.currentTimeMillis(), 1);
+        final String host = "localhost";
+        final int rpcPort = 10000;
+        final ApplicationReportProvider mockAppReportProvider =
+                MockApplicationReportProvider.of(applicationId, host, rpcPort);
+
+        YarnClusterClientProvider.of(mockAppReportProvider, flinkConf, 
applicationId)
+                .getClusterClient();
+
+        assertEquals(flinkConf.get(JobManagerOptions.ADDRESS), host);
+        assertEquals(flinkConf.getInteger(JobManagerOptions.PORT), rpcPort);
+        assertEquals(flinkConf.get(RestOptions.ADDRESS), host);
+        assertEquals(flinkConf.getInteger(RestOptions.PORT), rpcPort);
+        assertEquals(
+                flinkConf.get(YarnConfigOptions.APPLICATION_ID),
+                ConvertUtils.convert(applicationId));
+    }
+
+    private static class MockApplicationReportProvider implements 
ApplicationReportProvider {
+        int invokeNumber = 0;
+        ApplicationId applicationId;
+        String host;
+        int rpcHost;

Review comment:
       access modifies are missing

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/ApplicationReportProviderImpl.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.annotation.Internal;
+
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+
+import java.io.IOException;
+
+/** The implementation of ApplicationReportProvider. */
+@Internal
+public class ApplicationReportProviderImpl implements 
ApplicationReportProvider {
+    private final YarnClient yarnClient;
+    private final ApplicationId appId;
+
+    private ApplicationReportProviderImpl(YarnClient yarnClient, ApplicationId 
applicationId) {
+        this.yarnClient = yarnClient;
+        this.appId = applicationId;
+    }
+
+    @Override
+    public ApplicationReport waitTillSubmissionFinish() throws Exception {

Review comment:
       If possible maybe narrow down the thrown exception type.

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/ApplicationReportProviderImpl.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.annotation.Internal;
+
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+
+import java.io.IOException;
+
+/** The implementation of ApplicationReportProvider. */
+@Internal
+public class ApplicationReportProviderImpl implements 
ApplicationReportProvider {
+    private final YarnClient yarnClient;
+    private final ApplicationId appId;
+
+    private ApplicationReportProviderImpl(YarnClient yarnClient, ApplicationId 
applicationId) {
+        this.yarnClient = yarnClient;
+        this.appId = applicationId;
+    }
+
+    @Override
+    public ApplicationReport waitTillSubmissionFinish() throws Exception {
+        // Make access to the YarnClient fail fast if the client has been 
closed by the
+        // YarnClusterDescriptor
+        if (yarnClient.isInState(Service.STATE.STOPPED)) {
+            throw new Exception(

Review comment:
       `FlinkException`

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/ApplicationReportProviderImpl.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.annotation.Internal;
+
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+
+import java.io.IOException;
+
+/** The implementation of ApplicationReportProvider. */
+@Internal
+public class ApplicationReportProviderImpl implements 
ApplicationReportProvider {
+    private final YarnClient yarnClient;
+    private final ApplicationId appId;
+
+    private ApplicationReportProviderImpl(YarnClient yarnClient, ApplicationId 
applicationId) {
+        this.yarnClient = yarnClient;
+        this.appId = applicationId;
+    }
+
+    @Override
+    public ApplicationReport waitTillSubmissionFinish() throws Exception {
+        // Make access to the YarnClient fail fast if the client has been 
closed by the
+        // YarnClusterDescriptor
+        if (yarnClient.isInState(Service.STATE.STOPPED)) {
+            throw new Exception(
+                    "Errors on using YarnClient to retrieve application 
report. Maybe it has been closed by YarnClusterDescriptor.");
+        }
+
+        try {
+            return YarnClusterDescriptor.waitTillTargetState(
+                    yarnClient, appId, YarnApplicationState.RUNNING);
+        } catch (IOException e) {

Review comment:
       What about the other exceptions that `waitTillTargetState` throws?

##########
File path: 
flink-yarn/src/test/java/org/apache/flink/yarn/ApplicationReportProviderImplTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.yarn;
+
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/** Tests for the {@link ApplicationReportProviderImpl}. */
+public class ApplicationReportProviderImplTest extends AbstractYarnClusterTest 
{

Review comment:
       ```suggestion
   @ExtendWith(TestLoggerExtension.class)
   public class ApplicationReportProviderImplTest extends 
AbstractYarnClusterTest {
   ```

##########
File path: 
flink-yarn/src/test/java/org/apache/flink/yarn/YarnClusterClientProviderTest.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.yarn.configuration.YarnConfigOptions;
+
+import org.apache.commons.beanutils.ConvertUtils;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.util.Records;
+import org.junit.Test;
+
+import static 
org.apache.hadoop.yarn.api.records.FinalApplicationStatus.UNDEFINED;
+import static org.junit.Assert.assertEquals;
+
+/** Test for {@link YarnClusterClientProvider}. */
+public class YarnClusterClientProviderTest {
+
+    /** Once Yarn app master has been running, it should not retrieve app 
report again. */
+    @Test
+    public void testNoLongerRetrieveAppReportOnceAppRunning() {
+        final Configuration flinkConf = new Configuration();
+        final ApplicationId applicationId =
+                ApplicationId.newInstance(System.currentTimeMillis(), 1);
+
+        final ApplicationReportProvider mockAppReportProvider =
+                MockApplicationReportProvider.of(applicationId, "localhost", 
10);
+        assertEquals(0, ((MockApplicationReportProvider) 
mockAppReportProvider).getInvokeNumber());
+
+        YarnClusterClientProvider provider =
+                YarnClusterClientProvider.of(mockAppReportProvider, flinkConf, 
applicationId);
+
+        provider.getClusterClient();
+        assertEquals(1, ((MockApplicationReportProvider) 
mockAppReportProvider).getInvokeNumber());
+
+        provider.getClusterClient();
+        assertEquals(1, ((MockApplicationReportProvider) 
mockAppReportProvider).getInvokeNumber());
+    }
+
+    @Test
+    public void testJMHostShouldSetIntoConfig() {
+        final Configuration flinkConf = new Configuration();
+        final ApplicationId applicationId =
+                ApplicationId.newInstance(System.currentTimeMillis(), 1);
+        final String host = "localhost";
+        final int rpcPort = 10000;
+        final ApplicationReportProvider mockAppReportProvider =
+                MockApplicationReportProvider.of(applicationId, host, rpcPort);
+
+        YarnClusterClientProvider.of(mockAppReportProvider, flinkConf, 
applicationId)
+                .getClusterClient();
+
+        assertEquals(flinkConf.get(JobManagerOptions.ADDRESS), host);
+        assertEquals(flinkConf.getInteger(JobManagerOptions.PORT), rpcPort);
+        assertEquals(flinkConf.get(RestOptions.ADDRESS), host);
+        assertEquals(flinkConf.getInteger(RestOptions.PORT), rpcPort);
+        assertEquals(
+                flinkConf.get(YarnConfigOptions.APPLICATION_ID),
+                ConvertUtils.convert(applicationId));

Review comment:
       I think this test relies on the fact that `YarnClusterClientProvider` 
modifies the given `flinkConf`. This is an implementation detail. I think it is 
better to use the public API for assertions. If this is not possible then we 
could think about adding a package private 
`getRestClusterClientConfiguration()` or so that can be retrieved from the 
provider. But also this method leaks implementation details.

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/ApplicationReportProvider.java
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.annotation.Internal;
+
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+
+/** ApplicationReportProvider. */
+@Internal
+public interface ApplicationReportProvider {
+    ApplicationReport waitTillSubmissionFinish() throws Exception;

Review comment:
       Maybe also say when to expect that an `Exception` is thrown.

##########
File path: 
flink-yarn/src/test/java/org/apache/flink/yarn/YarnClusterClientProviderTest.java
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.yarn.configuration.YarnConfigOptions;
+
+import org.apache.commons.beanutils.ConvertUtils;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.util.Records;
+import org.junit.Test;
+
+import static 
org.apache.hadoop.yarn.api.records.FinalApplicationStatus.UNDEFINED;
+import static org.junit.Assert.assertEquals;
+
+/** Test for {@link YarnClusterClientProvider}. */
+public class YarnClusterClientProviderTest {

Review comment:
       Same here with Junit5.

##########
File path: 
flink-yarn/src/test/java/org/apache/flink/yarn/ApplicationReportProviderImplTest.java
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.yarn;
+
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/** Tests for the {@link ApplicationReportProviderImpl}. */
+public class ApplicationReportProviderImplTest extends AbstractYarnClusterTest 
{

Review comment:
       Why do we have to extend the `AbstractYarnClusterTest`? Can't we make 
`TestingYarnClient` a top level class?

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/ApplicationReportProviderImpl.java
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.annotation.Internal;
+
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+
+import java.io.IOException;
+
+/** The implementation of ApplicationReportProvider. */
+@Internal
+public class ApplicationReportProviderImpl implements 
ApplicationReportProvider {
+    private final YarnClient yarnClient;

Review comment:
       I think we shouldn't let this class depend on `YarnClusterDescriptor` 
but maybe having something like a `BorrowedYarnClient` that needs to be 
unwrapped in order to obtain a `YarnClient`. This unwrapping will make sure 
that the `YarnClient` has not been closed (e.g. by doing what you've proposed) 
or by some other mean (e.g. `YarnClusterDescriptor` remembering the borrowed 
yarn clients and closing them explicitly when closing the `yarnClient`).

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/ApplicationReportProviderImpl.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.yarn;
+
+import org.apache.flink.annotation.Internal;
+
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+
+import java.io.IOException;
+
+/** The implementation of ApplicationReportProvider. */
+@Internal
+public class ApplicationReportProviderImpl implements 
ApplicationReportProvider {
+    private final YarnClient yarnClient;
+    private final ApplicationId appId;
+
+    private ApplicationReportProviderImpl(YarnClient yarnClient, ApplicationId 
applicationId) {
+        this.yarnClient = yarnClient;
+        this.appId = applicationId;
+    }
+
+    @Override
+    public ApplicationReport waitTillSubmissionFinish() throws Exception {
+        // Make access to the YarnClient fail fast if the client has been 
closed by the
+        // YarnClusterDescriptor
+        if (yarnClient.isInState(Service.STATE.STOPPED)) {
+            throw new Exception(
+                    "Errors on using YarnClient to retrieve application 
report. Maybe it has been closed by YarnClusterDescriptor.");
+        }
+
+        try {
+            return YarnClusterDescriptor.waitTillTargetState(
+                    yarnClient, appId, YarnApplicationState.RUNNING);
+        } catch (IOException e) {
+            throw new Exception(

Review comment:
       `FlinkException` would be better




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to