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;
20  
21  import java.io.IOException;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.hadoop.classification.InterfaceAudience;
26  import org.apache.hadoop.conf.Configured;
27  
28  
29  /**
30   * ClusterManager is an api to manage servers in a distributed environment. It provides services
31   * for starting / stopping / killing Hadoop/HBase daemons. Concrete implementations provide actual
32   * functionality for carrying out deployment-specific tasks.
33   */
34  @InterfaceAudience.Private
35  public abstract class ClusterManager extends Configured {
36    protected static final Log LOG = LogFactory.getLog(ClusterManager.class);
37  
38    private static final String SIGKILL = "SIGKILL";
39    private static final String SIGSTOP = "SIGSTOP";
40    private static final String SIGCONT = "SIGCONT";
41  
42    public ClusterManager() {
43    }
44  
45    /**
46     * Type of the service daemon
47     */
48    public static enum ServiceType {
49      HADOOP_NAMENODE("namenode"),
50      HADOOP_DATANODE("datanode"),
51      HADOOP_JOBTRACKER("jobtracker"),
52      HADOOP_TASKTRACKER("tasktracker"),
53      HBASE_MASTER("master"),
54      HBASE_REGIONSERVER("regionserver");
55  
56      private String name;
57  
58      ServiceType(String name) {
59        this.name = name;
60      }
61  
62      public String getName() {
63        return name;
64      }
65  
66      @Override
67      public String toString() {
68        return getName();
69      }
70    }
71  
72    /**
73     * Start the service on the given host
74     */
75    public abstract void start(ServiceType service, String hostname) throws IOException;
76  
77    /**
78     * Stop the service on the given host
79     */
80    public abstract void stop(ServiceType service, String hostname) throws IOException;
81  
82    /**
83     * Restart the service on the given host
84     */
85    public abstract void restart(ServiceType service, String hostname) throws IOException;
86  
87    /**
88     * Send the given posix signal to the service
89     */
90    public abstract void signal(ServiceType service, String signal,
91        String hostname) throws IOException;
92  
93    /**
94     * Kill the service running on given host
95     */
96    public void kill(ServiceType service, String hostname) throws IOException {
97      signal(service, SIGKILL, hostname);
98    }
99  
100   /**
101    * Suspend the service running on given host
102    */
103   public void suspend(ServiceType service, String hostname) throws IOException {
104     signal(service, SIGSTOP, hostname);
105   }
106 
107   /**
108    * Resume the services running on given hosts
109    */
110   public void resume(ServiceType service, String hostname) throws IOException {
111     signal(service, SIGCONT, hostname);
112   }
113 
114   /**
115    * Returns whether the service is running on the remote host. This only checks whether the
116    * service still has a pid.
117    */
118   public abstract boolean isRunning(ServiceType service, String hostname) throws IOException;
119 
120   /* TODO: further API ideas:
121    *
122    * //return services running on host:
123    * ServiceType[] getRunningServicesOnHost(String hostname);
124    *
125    * //return which services can be run on host (for example, to query whether hmaster can run on this host)
126    * ServiceType[] getRunnableServicesOnHost(String hostname);
127    *
128    * //return which hosts can run this service
129    * String[] getRunnableHostsForService(ServiceType service);
130    */
131 
132 }