Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/292#discussion_r23175364
  
    --- Diff: 
flink-yarn/src/main/java/org/apache/flink/yarn/FlinkYarnCluster.java ---
    @@ -0,0 +1,363 @@
    +/*
    + * 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 akka.actor.ActorRef;
    +import akka.actor.ActorSystem;
    +
    +import static akka.pattern.Patterns.ask;
    +
    +import akka.actor.Props;
    +import akka.util.Timeout;
    +import org.apache.flink.configuration.GlobalConfiguration;
    +import org.apache.flink.runtime.net.NetUtils;
    +import org.apache.flink.runtime.yarn.AbstractFlinkYarnCluster;
    +import org.apache.flink.runtime.yarn.FlinkYarnClusterStatus;
    +import org.apache.hadoop.conf.Configuration;
    +import org.apache.hadoop.fs.FileSystem;
    +import org.apache.hadoop.fs.Path;
    +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.exceptions.YarnException;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import scala.None$;
    +import scala.Some;
    +import scala.concurrent.Await;
    +import scala.concurrent.Awaitable;
    +import scala.concurrent.Future;
    +import scala.concurrent.duration.Duration;
    +import scala.concurrent.duration.FiniteDuration;
    +
    +import java.io.IOException;
    +import java.net.InetAddress;
    +import java.net.InetSocketAddress;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.concurrent.TimeUnit;
    +import java.util.concurrent.atomic.AtomicBoolean;
    +
    +
    +public class FlinkYarnCluster extends AbstractFlinkYarnCluster {
    +   private static final Logger LOG = 
LoggerFactory.getLogger(FlinkYarnCluster.class);
    +
    +   private static final int POLLING_THREAD_INTERVAL_MS = 1000;
    +
    +   private YarnClient yarnClient;
    +   private Thread actorRunner;
    +   private Thread clientShutdownHook = new ClientShutdownHook();
    +   private PollingThread pollingRunner;
    +   private Configuration hadoopConfig;
    +   // (HDFS) location of the files required to run on YARN. Needed here to 
delete them on shutdown.
    +   private Path sessionFilesDir;
    +   private InetSocketAddress jobManagerAddress;
    +
    +   //---------- Class internal fields -------------------
    +
    +   private ActorSystem actorSystem;
    +   private ActorRef applicationClient;
    +   private ApplicationReport intialAppReport;
    +   private static FiniteDuration akkaDuration = Duration.apply(5, 
TimeUnit.SECONDS);
    +   private static Timeout akkaTimeout = 
Timeout.durationToTimeout(akkaDuration);
    +
    +   public FlinkYarnCluster(final YarnClient yarnClient, final 
ApplicationId appId,
    +                                                   Configuration 
hadoopConfig, Path sessionFilesDir) throws IOException, YarnException {
    +           this.yarnClient = yarnClient;
    +           this.hadoopConfig = hadoopConfig;
    +           this.sessionFilesDir = sessionFilesDir;
    +
    +           // get one application report manually
    +           intialAppReport = yarnClient.getApplicationReport(appId);
    +           String jobManagerHost = intialAppReport.getHost();
    +           int jobManagerPort = intialAppReport.getRpcPort();
    +           this.jobManagerAddress = new InetSocketAddress(jobManagerHost, 
jobManagerPort);
    +
    +           // start actor system
    +           LOG.info("Start actor system.");
    +           InetAddress ownHostname = 
NetUtils.resolveAddress(jobManagerAddress); // find name of own public 
interface, able to connect to the JM
    +           actorSystem = 
YarnUtils.createActorSystem(ownHostname.getCanonicalHostName(), 0, 
GlobalConfiguration.getConfiguration()); // set port automatically.
    +
    +           // start application client
    +           LOG.info("Start application client.");
    +
    +           applicationClient = 
actorSystem.actorOf(Props.create(ApplicationClient.class));
    +
    +           // instruct ApplicationClient to start a periodical status 
polling
    +           applicationClient.tell(new 
Messages.LocalRegisterClient(jobManagerHost + ":" + jobManagerPort), 
applicationClient);
    +
    +
    +           // add hook to ensure proper shutdown
    +           Runtime.getRuntime().addShutdownHook(clientShutdownHook);
    +
    +           actorRunner = new Thread(new Runnable() {
    +                   @Override
    +                   public void run() {
    +                           // blocks until ApplicationMaster has been 
stopped
    +                           actorSystem.awaitTermination();
    +
    +                           // get final application report
    +                           try {
    +                                   ApplicationReport appReport = 
yarnClient.getApplicationReport(appId);
    +
    +                                   LOG.info("Application " + appId + " 
finished with state " + appReport
    --- End diff --
    
    {}-placeholder


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to