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



##########
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;
+
+/** Then implementation of ApplicationReportProvider. */
+@Internal
+public class ApplicationReportProviderImpl implements 
ApplicationReportProvider {
+    private YarnClient yarnClient;
+    private ApplicationId appId;

Review comment:
       Could be `final`.

##########
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:
       JavaDoc is missing.

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterDescriptor.java
##########
@@ -1195,53 +1189,72 @@ private ApplicationReport startAppMaster(
         yarnClient.submitApplication(appContext);
 
         LOG.info("Waiting for the cluster to be allocated");
+
+        try {
+            waitTillTargetState(
+                    yarnClient, appId, YarnApplicationState.ACCEPTED, 
YarnApplicationState.RUNNING);
+        } catch (IOException e) {
+            throw new YarnDeploymentException("Failed to deploy the cluster.", 
e);
+        }
+
+        // since deployment was successful, remove the hook
+        ShutdownHookUtil.removeShutdownHook(deploymentFailureHook, 
getClass().getSimpleName(), LOG);
+
+        return ApplicationReportProviderImpl.of(yarnClient, applicationId);

Review comment:
       Aren't we leaking the `yarnClient` here? How will the lifecycle of the 
`yarnClient` be managed?

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterClientProvider.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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 ClusterClientProvider. */
+@Internal
+public class YarnClusterClientProvider implements ClusterClientProvider {
+    private static final Logger LOG = 
LoggerFactory.getLogger(YarnClusterClientProvider.class);
+
+    private final Object lock = new Object();
+
+    private volatile ApplicationId applicationId;

Review comment:
       I wouldn't encode whether the application report has been retrieved or 
not via the `ApplicationId` field. This works but an explicit state or the 
final `ApplicationReport` would be better. We could also think about letting 
the `ApplicationReportProvider` cache the `ApplicationReport`.

##########
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;
+
+/** Then implementation of ApplicationReportProvider. */

Review comment:
       ```suggestion
   /** The implementation of ApplicationReportProvider. */
   ```

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterClientProvider.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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 ClusterClientProvider. */
+@Internal
+public class YarnClusterClientProvider implements ClusterClientProvider {
+    private static final Logger LOG = 
LoggerFactory.getLogger(YarnClusterClientProvider.class);
+
+    private final Object lock = new Object();
+
+    private volatile ApplicationId applicationId;
+    private ApplicationReportProvider appReportProvider;
+    private Configuration flinkConf;
+
+    private YarnClusterClientProvider(
+            ApplicationReportProvider applicationReportProvider, Configuration 
flinkConfiguration) {
+        this.appReportProvider = applicationReportProvider;
+        this.flinkConf = flinkConfiguration;
+    }
+
+    @Override
+    public ClusterClient getClusterClient() {
+        try {
+            if (applicationId != null) {
+                synchronized (lock) {
+                    if (applicationId != null) {
+                        ApplicationReport report = 
appReportProvider.waitTillSubmissionFinish();
+                        this.applicationId = report.getApplicationId();
+                        setClusterEntrypointInfoToConfig(flinkConf, report);

Review comment:
       Is this method used somewhere else in the `YarnClusterDescriptor`?

##########
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;
+
+/** Then implementation of ApplicationReportProvider. */
+@Internal
+public class ApplicationReportProviderImpl implements 
ApplicationReportProvider {
+    private YarnClient yarnClient;

Review comment:
       What is the lifecycle of the `yarnClient`? When will it be freed/closed?

##########
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;
+
+/** Then implementation of ApplicationReportProvider. */
+@Internal
+public class ApplicationReportProviderImpl implements 
ApplicationReportProvider {
+    private YarnClient yarnClient;
+    private ApplicationId appId;
+
+    private ApplicationReportProviderImpl(YarnClient yarnClient, ApplicationId 
applicationId) {
+        this.yarnClient = yarnClient;
+        this.appId = applicationId;
+    }
+
+    @Override
+    public ApplicationReport waitTillSubmissionFinish() throws Exception {
+        try {
+            return YarnClusterDescriptor.waitTillTargetState(
+                    yarnClient, appId, YarnApplicationState.RUNNING);
+        } catch (IOException e) {
+            throw new RuntimeException(
+                    "Errors on getting YARN application report. Maybe 
application has finished.",
+                    e);

Review comment:
       Why throwing an unchecked exception when the signature states a checked 
exception?

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterClientProvider.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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 ClusterClientProvider. */
+@Internal
+public class YarnClusterClientProvider implements ClusterClientProvider {
+    private static final Logger LOG = 
LoggerFactory.getLogger(YarnClusterClientProvider.class);
+
+    private final Object lock = new Object();

Review comment:
       Where is concurrency coming from so that we have to introduce locks?

##########
File path: 
flink-yarn/src/main/java/org/apache/flink/yarn/YarnClusterClientProvider.java
##########
@@ -0,0 +1,74 @@
+/*
+ * 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 ClusterClientProvider. */
+@Internal
+public class YarnClusterClientProvider implements ClusterClientProvider {
+    private static final Logger LOG = 
LoggerFactory.getLogger(YarnClusterClientProvider.class);
+
+    private final Object lock = new Object();
+
+    private volatile ApplicationId applicationId;
+    private ApplicationReportProvider appReportProvider;
+    private Configuration flinkConf;

Review comment:
       Can this be final?




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to