View Javadoc

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.hadoop.hbase.chaos.actions;
20  
21  import java.io.IOException;
22  
23  import org.apache.hadoop.hbase.ServerName;
24  import org.apache.hadoop.hbase.util.Threads;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  /**
29  * Base class for restarting HBaseServer's
30  */
31  public class RestartActionBaseAction extends Action {
32    private static final Logger LOG =
33        LoggerFactory.getLogger(RestartActionBaseAction.class);
34    long sleepTime; // how long should we sleep
35  
36    public RestartActionBaseAction(long sleepTime) {
37      this.sleepTime = sleepTime;
38    }
39  
40    void sleep(long sleepTime) {
41      LOG.info("Sleeping for:" + sleepTime);
42      Threads.sleep(sleepTime);
43    }
44  
45    void restartMaster(ServerName server, long sleepTime) throws IOException {
46      sleepTime = Math.max(sleepTime, 1000);
47      // Don't try the kill if we're stopping
48      if (context.isStopping()) {
49        return;
50      }
51  
52      killMaster(server);
53      sleep(sleepTime);
54      startMaster(server);
55    }
56  
57    void restartRs(ServerName server, long sleepTime) throws IOException {
58      sleepTime = Math.max(sleepTime, 1000);
59      // Don't try the kill if we're stopping
60      if (context.isStopping()) {
61        return;
62      }
63      killRs(server);
64      sleep(sleepTime);
65      startRs(server);
66    }
67  
68    void restartZKNode(ServerName server, long sleepTime) throws IOException {
69      sleepTime = Math.max(sleepTime, 1000);
70      // Don't try the kill if we're stopping
71      if (context.isStopping()) {
72        return;
73      }
74      killZKNode(server);
75      sleep(sleepTime);
76      startZKNode(server);
77    }
78  
79    void restartDataNode(ServerName server, long sleepTime) throws IOException {
80      sleepTime = Math.max(sleepTime, 1000);
81      // Don't try the kill if we're stopping
82      if (context.isStopping()) {
83        return;
84      }
85      killDataNode(server);
86      sleep(sleepTime);
87      startDataNode(server);
88    }
89  }