1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */1819package org.apache.giraph.job;
2021import org.apache.giraph.conf.GiraphConfiguration;
22import org.apache.giraph.conf.GiraphConstants;
23import org.apache.giraph.utils.CounterUtils;
24import org.apache.hadoop.mapreduce.Job;
25import org.apache.log4j.Logger;
2627/**28 * Utility methods for halting application while running29 */30publicclassHaltApplicationUtils {
31/** Do not instantiate */32privateHaltApplicationUtils() { }
3334/**35 * Wait for halt info to become available and print instructions on how to36 * halt37 *38 * @param submittedJob Submitted job39 * @param conf Configuration40 */41publicstaticvoid printHaltInfo(Job submittedJob,
42GiraphConfiguration conf) {
43 String zkServer = CounterUtils.waitAndGetCounterNameFromGroup(
44 submittedJob, GiraphConstants.ZOOKEEPER_SERVER_PORT_COUNTER_GROUP);
45 String haltNode = CounterUtils.waitAndGetCounterNameFromGroup(
46 submittedJob, GiraphConstants.ZOOKEEPER_HALT_NODE_COUNTER_GROUP);
47if (zkServer != null && haltNode != null) {
48 GiraphConstants.HALT_INSTRUCTIONS_WRITER_CLASS.newInstance(
49 conf).writeHaltInstructions(zkServer, haltNode);
50 }
51 }
5253/**54 * Writer of instructions about how to halt55 */56publicinterfaceHaltInstructionsWriter {
57/**58 * Write instructions about how to halt59 *60 * @param zkServer ZooKeeper server61 * @param haltNode ZooKeeper node which should be created in order to halt62 */63void writeHaltInstructions(String zkServer, String haltNode);
64 }
6566/**67 * Default implementation of {@link HaltInstructionsWriter} - points to how68 * to use {@link org.apache.giraph.zk.ZooKeeperNodeCreator} to halt69 */70publicstaticclassDefaultHaltInstructionsWriterimplements71HaltInstructionsWriter {
72/** Class logger */73privatestaticfinal Logger LOG = Logger.getLogger(
74 DefaultHaltInstructionsWriter.class);
7576 @Override
77publicvoid writeHaltInstructions(String zkServer, String haltNode) {
78if (LOG.isInfoEnabled()) {
79 LOG.info("writeHaltInstructions: " +
80"To halt after next superstep execute: " +
81"'bin/halt-application --zkServer " + zkServer +
82" --zkNode " + haltNode + "'");
83 }
84 }
85 }
86 }