abstractdog commented on code in PR #427:
URL: https://github.com/apache/tez/pull/427#discussion_r2561667762


##########
tez-api/src/main/java/org/apache/tez/client/registry/zookeeper/ZkFrameworkClient.java:
##########
@@ -0,0 +1,164 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.tez.client.registry.zookeeper;
+
+import java.io.IOException;
+
+import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.hadoop.yarn.api.records.ApplicationReport;
+import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
+import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
+import org.apache.hadoop.yarn.api.records.YarnApplicationState;
+import org.apache.hadoop.yarn.client.api.YarnClientApplication;
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.util.Records;
+import org.apache.tez.client.FrameworkClient;
+import org.apache.tez.client.registry.AMRecord;
+import org.apache.tez.dag.api.TezConfiguration;
+
+public class ZkFrameworkClient extends FrameworkClient {
+
+  private AMRecord amRecord;
+  private ZkAMRegistryClient amRegistryClient = null;
+  private volatile boolean isRunning = false;
+  private String amHost;
+  private int amPort;
+
+  @Override
+  public synchronized void init(TezConfiguration tezConf) {
+    if (this.amRegistryClient == null) {
+      try {
+        this.amRegistryClient = ZkAMRegistryClient.getClient(tezConf);
+        this.isRunning = true;
+      } catch (Exception e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  @Override
+  public void start() {
+    try {
+      this.amRegistryClient.start();
+      isRunning = true;
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  @Override
+  public void stop() {
+    isRunning = false;
+    close();
+  }
+
+  @Override
+  public void close() {
+    if (amRegistryClient != null) {
+      amRegistryClient.close();
+    }
+  }
+
+  /**
+   * Creates a dummy {@link YarnClientApplication} using a pre-existing {@link 
ApplicationId}
+   * rather than requesting a new one from the ResourceManager.
+   *
+   * <p><strong>Note:</strong> This is a <em>dummy, backward-compatibility 
implementation</em>.
+   * Instead of allocating a fresh application ID from the ResourceManager, 
this method
+   * reuses the {@code applicationId} already obtained via {@code 
getApplicationReport()}.
+   * This allows legacy code paths to continue operating without requiring 
actual
+   * creation of a new application.</p>
+   *
+   * <p>Hidden assumption here: this method assumes that
+   * {@code getApplicationReport()} has already been called before
+   * {@code createApplication()}, ensuring that {@code 
amRecord.getApplicationId()}
+   * is always available. This assumption holds in all supported usage 
patterns:
+   * the only code path where {@code createApplication()} might be called 
first is
+   * {@code TezClient.submitDAGApplication()}, but that path is never 
exercised in
+   * Zookeeper standalone mode because that mode assumes applications are 
already
+   * running. Therefore, the ordering guarantee is valid in practice.</p>
+   *
+   * <p>
+   * The method constructs a minimal {@link ApplicationSubmissionContext} and a
+   * synthetic {@link GetNewApplicationResponse}, both populated with the 
already
+   * known application ID. These objects are then wrapped into a
+   * {@link YarnClientApplication} instance and returned.
+   * </p>
+   *
+   * @return a {@link YarnClientApplication} backed by a submission context and
+   *         a mocked {@link GetNewApplicationResponse}, both tied to the 
pre-existing
+   *         application ID.
+   */
+  @Override
+  public YarnClientApplication createApplication() {
+    ApplicationSubmissionContext context = 
Records.newRecord(ApplicationSubmissionContext.class);
+    ApplicationId appId = amRecord.getApplicationId();

Review Comment:
   I know it looks confusing, and already added a javadoc explain this:
   ```
      * <p><strong>Note:</strong> This is a <em>dummy, backward-compatibility 
implementation</em>.
      * Instead of allocating a fresh application ID from the ResourceManager, 
this method
      * reuses the {@code applicationId} already obtained via {@code 
getApplicationReport()}.
      * This allows legacy code paths to continue operating without requiring 
actual
      * creation of a new application.</p>
      *
      * <p>Hidden assumption here: this method assumes that
      * {@code getApplicationReport()} has already been called before
      * {@code createApplication()}, ensuring that {@code 
amRecord.getApplicationId()}
      * is always available. This assumption holds in all supported usage 
patterns:
      * the only code path where {@code createApplication()} might be called 
first is
      * {@code TezClient.submitDAGApplication()}, but that path is never 
exercised in
      * Zookeeper standalone mode because that mode assumes applications are 
already
      * running. Therefore, the ordering guarantee is valid in practice.</p>
   ```



-- 
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