001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019package org.apache.hadoop.hbase.chaos.actions; 020 021import java.io.IOException; 022 023import org.apache.hadoop.hbase.ServerName; 024import org.apache.hadoop.hbase.util.Threads; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027 028/** 029* Base class for restarting HBaseServer's 030*/ 031public class RestartActionBaseAction extends Action { 032 private static final Logger LOG = 033 LoggerFactory.getLogger(RestartActionBaseAction.class); 034 long sleepTime; // how long should we sleep 035 036 public RestartActionBaseAction(long sleepTime) { 037 this.sleepTime = sleepTime; 038 } 039 040 void sleep(long sleepTime) { 041 LOG.info("Sleeping for:" + sleepTime); 042 Threads.sleep(sleepTime); 043 } 044 045 void restartMaster(ServerName server, long sleepTime) throws IOException { 046 sleepTime = Math.max(sleepTime, 1000); 047 // Don't try the kill if we're stopping 048 if (context.isStopping()) { 049 return; 050 } 051 052 killMaster(server); 053 sleep(sleepTime); 054 startMaster(server); 055 } 056 057 void restartRs(ServerName server, long sleepTime) throws IOException { 058 sleepTime = Math.max(sleepTime, 1000); 059 // Don't try the kill if we're stopping 060 if (context.isStopping()) { 061 return; 062 } 063 killRs(server); 064 sleep(sleepTime); 065 startRs(server); 066 } 067 068 void restartZKNode(ServerName server, long sleepTime) throws IOException { 069 sleepTime = Math.max(sleepTime, 1000); 070 // Don't try the kill if we're stopping 071 if (context.isStopping()) { 072 return; 073 } 074 killZKNode(server); 075 sleep(sleepTime); 076 startZKNode(server); 077 } 078 079 void restartDataNode(ServerName server, long sleepTime) throws IOException { 080 sleepTime = Math.max(sleepTime, 1000); 081 // Don't try the kill if we're stopping 082 if (context.isStopping()) { 083 return; 084 } 085 killDataNode(server); 086 sleep(sleepTime); 087 startDataNode(server); 088 } 089}