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;
025
026/**
027* Base class for restarting HBaseServer's
028*/
029public class RestartActionBaseAction extends Action {
030  long sleepTime; // how long should we sleep
031
032  public RestartActionBaseAction(long sleepTime) {
033    this.sleepTime = sleepTime;
034  }
035
036  void sleep(long sleepTime) {
037    LOG.info("Sleeping for:" + sleepTime);
038    Threads.sleep(sleepTime);
039  }
040
041  void restartMaster(ServerName server, long sleepTime) throws IOException {
042    sleepTime = Math.max(sleepTime, 1000);
043    // Don't try the kill if we're stopping
044    if (context.isStopping()) {
045      return;
046    }
047
048    killMaster(server);
049    sleep(sleepTime);
050    startMaster(server);
051  }
052
053  void restartRs(ServerName server, long sleepTime) throws IOException {
054    sleepTime = Math.max(sleepTime, 1000);
055    // Don't try the kill if we're stopping
056    if (context.isStopping()) {
057      return;
058    }
059    killRs(server);
060    sleep(sleepTime);
061    startRs(server);
062  }
063
064  void restartZKNode(ServerName server, long sleepTime) throws IOException {
065    sleepTime = Math.max(sleepTime, 1000);
066    // Don't try the kill if we're stopping
067    if (context.isStopping()) {
068      return;
069    }
070    killZKNode(server);
071    sleep(sleepTime);
072    startZKNode(server);
073  }
074
075  void restartDataNode(ServerName server, long sleepTime) throws IOException {
076    sleepTime = Math.max(sleepTime, 1000);
077    // Don't try the kill if we're stopping
078    if (context.isStopping()) {
079      return;
080    }
081    killDataNode(server);
082    sleep(sleepTime);
083    startDataNode(server);
084  }
085}