Coverage Report - org.apache.giraph.job.HaltApplicationUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
HaltApplicationUtils
0%
0/7
0%
0/4
1.75
HaltApplicationUtils$DefaultHaltInstructionsWriter
0%
0/5
0%
0/2
1.75
HaltApplicationUtils$HaltInstructionsWriter
N/A
N/A
1.75
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.giraph.job;
 20  
 
 21  
 import org.apache.giraph.conf.GiraphConfiguration;
 22  
 import org.apache.giraph.conf.GiraphConstants;
 23  
 import org.apache.giraph.utils.CounterUtils;
 24  
 import org.apache.hadoop.mapreduce.Job;
 25  
 import org.apache.log4j.Logger;
 26  
 
 27  
 /**
 28  
  * Utility methods for halting application while running
 29  
  */
 30  
 public class HaltApplicationUtils {
 31  
   /** Do not instantiate */
 32  0
   private HaltApplicationUtils() { }
 33  
 
 34  
   /**
 35  
    * Wait for halt info to become available and print instructions on how to
 36  
    * halt
 37  
    *
 38  
    * @param submittedJob Submitted job
 39  
    * @param conf         Configuration
 40  
    */
 41  
   public static void printHaltInfo(Job submittedJob,
 42  
       GiraphConfiguration conf) {
 43  0
     String zkServer = CounterUtils.waitAndGetCounterNameFromGroup(
 44  
         submittedJob, GiraphConstants.ZOOKEEPER_SERVER_PORT_COUNTER_GROUP);
 45  0
     String haltNode = CounterUtils.waitAndGetCounterNameFromGroup(
 46  
         submittedJob, GiraphConstants.ZOOKEEPER_HALT_NODE_COUNTER_GROUP);
 47  0
     if (zkServer != null && haltNode != null) {
 48  0
       GiraphConstants.HALT_INSTRUCTIONS_WRITER_CLASS.newInstance(
 49  0
           conf).writeHaltInstructions(zkServer, haltNode);
 50  
     }
 51  0
   }
 52  
 
 53  
   /**
 54  
    * Writer of instructions about how to halt
 55  
    */
 56  
   public interface HaltInstructionsWriter {
 57  
     /**
 58  
      * Write instructions about how to halt
 59  
      *
 60  
      * @param zkServer ZooKeeper server
 61  
      * @param haltNode ZooKeeper node which should be created in order to halt
 62  
      */
 63  
     void writeHaltInstructions(String zkServer, String haltNode);
 64  
   }
 65  
 
 66  
   /**
 67  
    * Default implementation of {@link HaltInstructionsWriter} - points to how
 68  
    * to use {@link org.apache.giraph.zk.ZooKeeperNodeCreator} to halt
 69  
    */
 70  0
   public static class DefaultHaltInstructionsWriter implements
 71  
       HaltInstructionsWriter {
 72  
     /** Class logger */
 73  0
     private static final Logger LOG = Logger.getLogger(
 74  
         DefaultHaltInstructionsWriter.class);
 75  
 
 76  
     @Override
 77  
     public void writeHaltInstructions(String zkServer, String haltNode) {
 78  0
       if (LOG.isInfoEnabled()) {
 79  0
         LOG.info("writeHaltInstructions: " +
 80  
             "To halt after next superstep execute: " +
 81  
             "'bin/halt-application --zkServer " + zkServer +
 82  
             " --zkNode " + haltNode + "'");
 83  
       }
 84  0
     }
 85  
   }
 86  
 }