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

    https://github.com/apache/flink/pull/5215#discussion_r159225871
  
    --- Diff: 
flink-yarn/src/main/java/org/apache/flink/yarn/cli/YarnApplicationStatusMonitor.java
 ---
    @@ -0,0 +1,101 @@
    +/*
    + * 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.cli;
    +
    +import org.apache.flink.runtime.clusterframework.ApplicationStatus;
    +import org.apache.flink.runtime.concurrent.ScheduledExecutor;
    +import org.apache.flink.util.Preconditions;
    +
    +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 org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.concurrent.ScheduledFuture;
    +import java.util.concurrent.TimeUnit;
    +
    +/**
    + * Utility class which monitors the specified yarn application status 
periodically.
    + */
    +public class YarnApplicationStatusMonitor implements AutoCloseable {
    +
    +   private static final Logger LOG = 
LoggerFactory.getLogger(YarnApplicationStatusMonitor.class);
    +
    +   private static final long UPDATE_INTERVAL = 1000L;
    +
    +   private final YarnClient yarnClient;
    +
    +   private final ApplicationId yarnApplicationId;
    +
    +   private final ScheduledFuture<?> applicationStatusUpdateFuture;
    +
    +   private volatile ApplicationStatus applicationStatus;
    +
    +   public YarnApplicationStatusMonitor(
    +                   YarnClient yarnClient,
    +                   ApplicationId yarnApplicationId,
    +                   ScheduledExecutor scheduledExecutor) {
    +           this.yarnClient = Preconditions.checkNotNull(yarnClient);
    +           this.yarnApplicationId = 
Preconditions.checkNotNull(yarnApplicationId);
    +
    +           applicationStatusUpdateFuture = 
scheduledExecutor.scheduleWithFixedDelay(
    +                   this::updateApplicationStatus,
    +                   UPDATE_INTERVAL,
    +                   UPDATE_INTERVAL,
    +                   TimeUnit.MILLISECONDS);
    +
    +           applicationStatus = ApplicationStatus.UNKNOWN;
    +   }
    +
    +   public ApplicationStatus getApplicationStatusNow() {
    +           return applicationStatus;
    +   }
    +
    +   @Override
    +   public void close() throws Exception {
    +           applicationStatusUpdateFuture.cancel(false);
    --- End diff --
    
    There is no need to declare `throws Exception` here because `cancel()` does 
not throw any checked exceptions.


---

Reply via email to