abstractdog commented on code in PR #427: URL: https://github.com/apache/tez/pull/427#discussion_r2543404391
########## tez-api/src/main/java/org/apache/tez/client/registry/zookeeper/ZkFrameworkClient.java: ########## @@ -0,0 +1,132 @@ +/** + * 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(); + } catch (Exception e) { + throw new RuntimeException(e); + } + isRunning = true; + } + + @Override + public void stop() { + isRunning = false; + amRegistryClient.close(); + } + + @Override + public void close() throws IOException { + amRegistryClient.close(); + } + + @Override + public YarnClientApplication createApplication() throws YarnException, IOException { + ApplicationSubmissionContext context = Records.newRecord(ApplicationSubmissionContext.class); + ApplicationId appId = amRecord.getApplicationId(); Review Comment: right, confusing, added javadoc comment for clarity: ``` * <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]
