hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [02/30] hbase-site git commit: Published site at .
Date Fri, 18 Aug 2017 15:06:29 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/cef8af03/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.RoleCommand.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.RoleCommand.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.RoleCommand.html
index 0d46b6f..680bc31 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.RoleCommand.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.RoleCommand.html
@@ -26,185 +26,185 @@
 <span class="sourceLineNo">018</span><a name="line.18"></a>
 <span class="sourceLineNo">019</span>package org.apache.hadoop.hbase;<a name="line.19"></a>
 <span class="sourceLineNo">020</span><a name="line.20"></a>
-<span class="sourceLineNo">021</span>import com.sun.jersey.api.client.Client;<a name="line.21"></a>
-<span class="sourceLineNo">022</span>import com.sun.jersey.api.client.ClientResponse;<a name="line.22"></a>
-<span class="sourceLineNo">023</span>import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;<a name="line.23"></a>
-<span class="sourceLineNo">024</span><a name="line.24"></a>
-<span class="sourceLineNo">025</span>import org.apache.commons.logging.Log;<a name="line.25"></a>
-<span class="sourceLineNo">026</span>import org.apache.commons.logging.LogFactory;<a name="line.26"></a>
-<span class="sourceLineNo">027</span>import org.apache.hadoop.conf.Configuration;<a name="line.27"></a>
-<span class="sourceLineNo">028</span>import org.apache.hadoop.conf.Configured;<a name="line.28"></a>
-<span class="sourceLineNo">029</span>import org.apache.hadoop.util.ReflectionUtils;<a name="line.29"></a>
-<span class="sourceLineNo">030</span>import org.codehaus.jackson.JsonNode;<a name="line.30"></a>
-<span class="sourceLineNo">031</span>import org.codehaus.jackson.map.ObjectMapper;<a name="line.31"></a>
-<span class="sourceLineNo">032</span><a name="line.32"></a>
-<span class="sourceLineNo">033</span>import javax.ws.rs.core.MediaType;<a name="line.33"></a>
-<span class="sourceLineNo">034</span>import javax.ws.rs.core.Response;<a name="line.34"></a>
-<span class="sourceLineNo">035</span>import javax.ws.rs.core.UriBuilder;<a name="line.35"></a>
-<span class="sourceLineNo">036</span>import javax.xml.ws.http.HTTPException;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>import java.io.IOException;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import java.net.URI;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>import java.util.HashMap;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import java.util.Locale;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import java.util.Map;<a name="line.41"></a>
-<span class="sourceLineNo">042</span><a name="line.42"></a>
-<span class="sourceLineNo">043</span>/**<a name="line.43"></a>
-<span class="sourceLineNo">044</span> * A ClusterManager implementation designed to control Cloudera Manager (http://www.cloudera.com)<a name="line.44"></a>
-<span class="sourceLineNo">045</span> * clusters via REST API. This API uses HTTP GET requests against the cluster manager server to<a name="line.45"></a>
-<span class="sourceLineNo">046</span> * retrieve information and POST/PUT requests to perform actions. As a simple example, to retrieve a<a name="line.46"></a>
-<span class="sourceLineNo">047</span> * list of hosts from a CM server with login credentials admin:admin, a simple curl command would be<a name="line.47"></a>
-<span class="sourceLineNo">048</span> *     curl -X POST -H "Content-Type:application/json" -u admin:admin \<a name="line.48"></a>
-<span class="sourceLineNo">049</span> *         "http://this.is.my.server.com:7180/api/v8/hosts"<a name="line.49"></a>
-<span class="sourceLineNo">050</span> *<a name="line.50"></a>
-<span class="sourceLineNo">051</span> * This command would return a JSON result, which would need to be parsed to retrieve relevant<a name="line.51"></a>
-<span class="sourceLineNo">052</span> * information. This action and many others are covered by this class.<a name="line.52"></a>
-<span class="sourceLineNo">053</span> *<a name="line.53"></a>
-<span class="sourceLineNo">054</span> * A note on nomenclature: while the ClusterManager interface uses a ServiceType enum when<a name="line.54"></a>
-<span class="sourceLineNo">055</span> * referring to things like RegionServers and DataNodes, cluster managers often use different<a name="line.55"></a>
-<span class="sourceLineNo">056</span> * terminology. As an example, Cloudera Manager (http://www.cloudera.com) would refer to a<a name="line.56"></a>
-<span class="sourceLineNo">057</span> * RegionServer as a "role" of the HBase "service." It would further refer to "hbase" as the<a name="line.57"></a>
-<span class="sourceLineNo">058</span> * "serviceType." Apache Ambari (http://ambari.apache.org) would call the RegionServer a<a name="line.58"></a>
-<span class="sourceLineNo">059</span> * "component" of the HBase "service."<a name="line.59"></a>
-<span class="sourceLineNo">060</span> *<a name="line.60"></a>
-<span class="sourceLineNo">061</span> * This class will defer to the ClusterManager terminology in methods that it implements from<a name="line.61"></a>
-<span class="sourceLineNo">062</span> * that interface, but uses Cloudera Manager's terminology when dealing with its API directly.<a name="line.62"></a>
-<span class="sourceLineNo">063</span> */<a name="line.63"></a>
-<span class="sourceLineNo">064</span>public class RESTApiClusterManager extends Configured implements ClusterManager {<a name="line.64"></a>
-<span class="sourceLineNo">065</span>  // Properties that need to be in the Configuration object to interact with the REST API cluster<a name="line.65"></a>
-<span class="sourceLineNo">066</span>  // manager. Most easily defined in hbase-site.xml, but can also be passed on the command line.<a name="line.66"></a>
-<span class="sourceLineNo">067</span>  private static final String REST_API_CLUSTER_MANAGER_HOSTNAME =<a name="line.67"></a>
-<span class="sourceLineNo">068</span>      "hbase.it.clustermanager.restapi.hostname";<a name="line.68"></a>
-<span class="sourceLineNo">069</span>  private static final String REST_API_CLUSTER_MANAGER_USERNAME =<a name="line.69"></a>
-<span class="sourceLineNo">070</span>      "hbase.it.clustermanager.restapi.username";<a name="line.70"></a>
-<span class="sourceLineNo">071</span>  private static final String REST_API_CLUSTER_MANAGER_PASSWORD =<a name="line.71"></a>
-<span class="sourceLineNo">072</span>      "hbase.it.clustermanager.restapi.password";<a name="line.72"></a>
-<span class="sourceLineNo">073</span>  private static final String REST_API_CLUSTER_MANAGER_CLUSTER_NAME =<a name="line.73"></a>
-<span class="sourceLineNo">074</span>      "hbase.it.clustermanager.restapi.clustername";<a name="line.74"></a>
-<span class="sourceLineNo">075</span><a name="line.75"></a>
-<span class="sourceLineNo">076</span>  // Some default values for the above properties.<a name="line.76"></a>
-<span class="sourceLineNo">077</span>  private static final String DEFAULT_SERVER_HOSTNAME = "http://localhost:7180";<a name="line.77"></a>
-<span class="sourceLineNo">078</span>  private static final String DEFAULT_SERVER_USERNAME = "admin";<a name="line.78"></a>
-<span class="sourceLineNo">079</span>  private static final String DEFAULT_SERVER_PASSWORD = "admin";<a name="line.79"></a>
-<span class="sourceLineNo">080</span>  private static final String DEFAULT_CLUSTER_NAME = "Cluster 1";<a name="line.80"></a>
-<span class="sourceLineNo">081</span><a name="line.81"></a>
-<span class="sourceLineNo">082</span>  // Fields for the hostname, username, password, and cluster name of the cluster management server<a name="line.82"></a>
-<span class="sourceLineNo">083</span>  // to be used.<a name="line.83"></a>
-<span class="sourceLineNo">084</span>  private String serverHostname;<a name="line.84"></a>
-<span class="sourceLineNo">085</span>  private String serverUsername;<a name="line.85"></a>
-<span class="sourceLineNo">086</span>  private String serverPassword;<a name="line.86"></a>
-<span class="sourceLineNo">087</span>  private String clusterName;<a name="line.87"></a>
-<span class="sourceLineNo">088</span><a name="line.88"></a>
-<span class="sourceLineNo">089</span>  // Each version of Cloudera Manager supports a particular API versions. Version 6 of this API<a name="line.89"></a>
-<span class="sourceLineNo">090</span>  // provides all the features needed by this class.<a name="line.90"></a>
-<span class="sourceLineNo">091</span>  private static final String API_VERSION = "v6";<a name="line.91"></a>
-<span class="sourceLineNo">092</span><a name="line.92"></a>
-<span class="sourceLineNo">093</span>  // Client instances are expensive, so use the same one for all our REST queries.<a name="line.93"></a>
-<span class="sourceLineNo">094</span>  private Client client = Client.create();<a name="line.94"></a>
-<span class="sourceLineNo">095</span><a name="line.95"></a>
-<span class="sourceLineNo">096</span>  // An instance of HBaseClusterManager is used for methods like the kill, resume, and suspend<a name="line.96"></a>
-<span class="sourceLineNo">097</span>  // because cluster managers don't tend to implement these operations.<a name="line.97"></a>
-<span class="sourceLineNo">098</span>  private ClusterManager hBaseClusterManager;<a name="line.98"></a>
-<span class="sourceLineNo">099</span><a name="line.99"></a>
-<span class="sourceLineNo">100</span>  private static final Log LOG = LogFactory.getLog(RESTApiClusterManager.class);<a name="line.100"></a>
-<span class="sourceLineNo">101</span><a name="line.101"></a>
-<span class="sourceLineNo">102</span>  RESTApiClusterManager() {<a name="line.102"></a>
-<span class="sourceLineNo">103</span>    hBaseClusterManager = ReflectionUtils.newInstance(HBaseClusterManager.class,<a name="line.103"></a>
-<span class="sourceLineNo">104</span>        new IntegrationTestingUtility().getConfiguration());<a name="line.104"></a>
-<span class="sourceLineNo">105</span>  }<a name="line.105"></a>
-<span class="sourceLineNo">106</span><a name="line.106"></a>
-<span class="sourceLineNo">107</span>  @Override<a name="line.107"></a>
-<span class="sourceLineNo">108</span>  public void setConf(Configuration conf) {<a name="line.108"></a>
-<span class="sourceLineNo">109</span>    super.setConf(conf);<a name="line.109"></a>
-<span class="sourceLineNo">110</span>    if (conf == null) {<a name="line.110"></a>
-<span class="sourceLineNo">111</span>      // Configured gets passed null before real conf. Why? I don't know.<a name="line.111"></a>
-<span class="sourceLineNo">112</span>      return;<a name="line.112"></a>
-<span class="sourceLineNo">113</span>    }<a name="line.113"></a>
-<span class="sourceLineNo">114</span>    serverHostname = conf.get(REST_API_CLUSTER_MANAGER_HOSTNAME, DEFAULT_SERVER_HOSTNAME);<a name="line.114"></a>
-<span class="sourceLineNo">115</span>    serverUsername = conf.get(REST_API_CLUSTER_MANAGER_USERNAME, DEFAULT_SERVER_USERNAME);<a name="line.115"></a>
-<span class="sourceLineNo">116</span>    serverPassword = conf.get(REST_API_CLUSTER_MANAGER_PASSWORD, DEFAULT_SERVER_PASSWORD);<a name="line.116"></a>
-<span class="sourceLineNo">117</span>    clusterName = conf.get(REST_API_CLUSTER_MANAGER_CLUSTER_NAME, DEFAULT_CLUSTER_NAME);<a name="line.117"></a>
-<span class="sourceLineNo">118</span><a name="line.118"></a>
-<span class="sourceLineNo">119</span>    // Add filter to Client instance to enable server authentication.<a name="line.119"></a>
-<span class="sourceLineNo">120</span>    client.addFilter(new HTTPBasicAuthFilter(serverUsername, serverPassword));<a name="line.120"></a>
-<span class="sourceLineNo">121</span>  }<a name="line.121"></a>
-<span class="sourceLineNo">122</span><a name="line.122"></a>
-<span class="sourceLineNo">123</span>  @Override<a name="line.123"></a>
-<span class="sourceLineNo">124</span>  public void start(ServiceType service, String hostname, int port) throws IOException {<a name="line.124"></a>
-<span class="sourceLineNo">125</span>    performClusterManagerCommand(service, hostname, RoleCommand.START);<a name="line.125"></a>
-<span class="sourceLineNo">126</span>  }<a name="line.126"></a>
-<span class="sourceLineNo">127</span><a name="line.127"></a>
-<span class="sourceLineNo">128</span>  @Override<a name="line.128"></a>
-<span class="sourceLineNo">129</span>  public void stop(ServiceType service, String hostname, int port) throws IOException {<a name="line.129"></a>
-<span class="sourceLineNo">130</span>    performClusterManagerCommand(service, hostname, RoleCommand.STOP);<a name="line.130"></a>
-<span class="sourceLineNo">131</span>  }<a name="line.131"></a>
-<span class="sourceLineNo">132</span><a name="line.132"></a>
-<span class="sourceLineNo">133</span>  @Override<a name="line.133"></a>
-<span class="sourceLineNo">134</span>  public void restart(ServiceType service, String hostname, int port) throws IOException {<a name="line.134"></a>
-<span class="sourceLineNo">135</span>    performClusterManagerCommand(service, hostname, RoleCommand.RESTART);<a name="line.135"></a>
-<span class="sourceLineNo">136</span>  }<a name="line.136"></a>
-<span class="sourceLineNo">137</span><a name="line.137"></a>
-<span class="sourceLineNo">138</span>  @Override<a name="line.138"></a>
-<span class="sourceLineNo">139</span>  public boolean isRunning(ServiceType service, String hostname, int port) throws IOException {<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    String serviceName = getServiceName(roleServiceType.get(service));<a name="line.140"></a>
-<span class="sourceLineNo">141</span>    String hostId = getHostId(hostname);<a name="line.141"></a>
-<span class="sourceLineNo">142</span>    String roleState = getRoleState(serviceName, service.toString(), hostId);<a name="line.142"></a>
-<span class="sourceLineNo">143</span>    String healthSummary = getHealthSummary(serviceName, service.toString(), hostId);<a name="line.143"></a>
-<span class="sourceLineNo">144</span>    boolean isRunning = false;<a name="line.144"></a>
-<span class="sourceLineNo">145</span><a name="line.145"></a>
-<span class="sourceLineNo">146</span>    // Use Yoda condition to prevent NullPointerException. roleState will be null if the "service<a name="line.146"></a>
-<span class="sourceLineNo">147</span>    // type" does not exist on the specified hostname.<a name="line.147"></a>
-<span class="sourceLineNo">148</span>    if ("STARTED".equals(roleState) &amp;&amp; "GOOD".equals(healthSummary)) {<a name="line.148"></a>
-<span class="sourceLineNo">149</span>      isRunning = true;<a name="line.149"></a>
-<span class="sourceLineNo">150</span>    }<a name="line.150"></a>
-<span class="sourceLineNo">151</span><a name="line.151"></a>
-<span class="sourceLineNo">152</span>    return isRunning;<a name="line.152"></a>
-<span class="sourceLineNo">153</span>  }<a name="line.153"></a>
-<span class="sourceLineNo">154</span><a name="line.154"></a>
-<span class="sourceLineNo">155</span>  @Override<a name="line.155"></a>
-<span class="sourceLineNo">156</span>  public void kill(ServiceType service, String hostname, int port) throws IOException {<a name="line.156"></a>
-<span class="sourceLineNo">157</span>    hBaseClusterManager.kill(service, hostname, port);<a name="line.157"></a>
-<span class="sourceLineNo">158</span>  }<a name="line.158"></a>
-<span class="sourceLineNo">159</span><a name="line.159"></a>
-<span class="sourceLineNo">160</span>  @Override<a name="line.160"></a>
-<span class="sourceLineNo">161</span>  public void suspend(ServiceType service, String hostname, int port) throws IOException {<a name="line.161"></a>
-<span class="sourceLineNo">162</span>    hBaseClusterManager.suspend(service, hostname, port);<a name="line.162"></a>
-<span class="sourceLineNo">163</span>  }<a name="line.163"></a>
-<span class="sourceLineNo">164</span><a name="line.164"></a>
-<span class="sourceLineNo">165</span>  @Override<a name="line.165"></a>
-<span class="sourceLineNo">166</span>  public void resume(ServiceType service, String hostname, int port) throws IOException {<a name="line.166"></a>
-<span class="sourceLineNo">167</span>    hBaseClusterManager.resume(service, hostname, port);<a name="line.167"></a>
-<span class="sourceLineNo">168</span>  }<a name="line.168"></a>
-<span class="sourceLineNo">169</span><a name="line.169"></a>
+<span class="sourceLineNo">021</span>import org.apache.commons.logging.Log;<a name="line.21"></a>
+<span class="sourceLineNo">022</span>import org.apache.commons.logging.LogFactory;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import org.apache.hadoop.conf.Configuration;<a name="line.23"></a>
+<span class="sourceLineNo">024</span>import org.apache.hadoop.conf.Configured;<a name="line.24"></a>
+<span class="sourceLineNo">025</span>import org.apache.hadoop.util.ReflectionUtils;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import org.codehaus.jackson.JsonNode;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import org.codehaus.jackson.map.ObjectMapper;<a name="line.27"></a>
+<span class="sourceLineNo">028</span>import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;<a name="line.28"></a>
+<span class="sourceLineNo">029</span>import javax.ws.rs.client.Client;<a name="line.29"></a>
+<span class="sourceLineNo">030</span>import javax.ws.rs.client.ClientBuilder;<a name="line.30"></a>
+<span class="sourceLineNo">031</span>import javax.ws.rs.client.Entity;<a name="line.31"></a>
+<span class="sourceLineNo">032</span>import javax.ws.rs.client.Invocation;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import javax.ws.rs.client.WebTarget;<a name="line.33"></a>
+<span class="sourceLineNo">034</span>import javax.ws.rs.core.MediaType;<a name="line.34"></a>
+<span class="sourceLineNo">035</span>import javax.ws.rs.core.Response;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>import javax.ws.rs.core.UriBuilder;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import javax.xml.ws.http.HTTPException;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import java.io.IOException;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import java.net.URI;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import java.util.HashMap;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import java.util.Locale;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import java.util.Map;<a name="line.42"></a>
+<span class="sourceLineNo">043</span><a name="line.43"></a>
+<span class="sourceLineNo">044</span>/**<a name="line.44"></a>
+<span class="sourceLineNo">045</span> * A ClusterManager implementation designed to control Cloudera Manager (http://www.cloudera.com)<a name="line.45"></a>
+<span class="sourceLineNo">046</span> * clusters via REST API. This API uses HTTP GET requests against the cluster manager server to<a name="line.46"></a>
+<span class="sourceLineNo">047</span> * retrieve information and POST/PUT requests to perform actions. As a simple example, to retrieve a<a name="line.47"></a>
+<span class="sourceLineNo">048</span> * list of hosts from a CM server with login credentials admin:admin, a simple curl command would be<a name="line.48"></a>
+<span class="sourceLineNo">049</span> *     curl -X POST -H "Content-Type:application/json" -u admin:admin \<a name="line.49"></a>
+<span class="sourceLineNo">050</span> *         "http://this.is.my.server.com:7180/api/v8/hosts"<a name="line.50"></a>
+<span class="sourceLineNo">051</span> *<a name="line.51"></a>
+<span class="sourceLineNo">052</span> * This command would return a JSON result, which would need to be parsed to retrieve relevant<a name="line.52"></a>
+<span class="sourceLineNo">053</span> * information. This action and many others are covered by this class.<a name="line.53"></a>
+<span class="sourceLineNo">054</span> *<a name="line.54"></a>
+<span class="sourceLineNo">055</span> * A note on nomenclature: while the ClusterManager interface uses a ServiceType enum when<a name="line.55"></a>
+<span class="sourceLineNo">056</span> * referring to things like RegionServers and DataNodes, cluster managers often use different<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * terminology. As an example, Cloudera Manager (http://www.cloudera.com) would refer to a<a name="line.57"></a>
+<span class="sourceLineNo">058</span> * RegionServer as a "role" of the HBase "service." It would further refer to "hbase" as the<a name="line.58"></a>
+<span class="sourceLineNo">059</span> * "serviceType." Apache Ambari (http://ambari.apache.org) would call the RegionServer a<a name="line.59"></a>
+<span class="sourceLineNo">060</span> * "component" of the HBase "service."<a name="line.60"></a>
+<span class="sourceLineNo">061</span> *<a name="line.61"></a>
+<span class="sourceLineNo">062</span> * This class will defer to the ClusterManager terminology in methods that it implements from<a name="line.62"></a>
+<span class="sourceLineNo">063</span> * that interface, but uses Cloudera Manager's terminology when dealing with its API directly.<a name="line.63"></a>
+<span class="sourceLineNo">064</span> */<a name="line.64"></a>
+<span class="sourceLineNo">065</span>public class RESTApiClusterManager extends Configured implements ClusterManager {<a name="line.65"></a>
+<span class="sourceLineNo">066</span>  // Properties that need to be in the Configuration object to interact with the REST API cluster<a name="line.66"></a>
+<span class="sourceLineNo">067</span>  // manager. Most easily defined in hbase-site.xml, but can also be passed on the command line.<a name="line.67"></a>
+<span class="sourceLineNo">068</span>  private static final String REST_API_CLUSTER_MANAGER_HOSTNAME =<a name="line.68"></a>
+<span class="sourceLineNo">069</span>      "hbase.it.clustermanager.restapi.hostname";<a name="line.69"></a>
+<span class="sourceLineNo">070</span>  private static final String REST_API_CLUSTER_MANAGER_USERNAME =<a name="line.70"></a>
+<span class="sourceLineNo">071</span>      "hbase.it.clustermanager.restapi.username";<a name="line.71"></a>
+<span class="sourceLineNo">072</span>  private static final String REST_API_CLUSTER_MANAGER_PASSWORD =<a name="line.72"></a>
+<span class="sourceLineNo">073</span>      "hbase.it.clustermanager.restapi.password";<a name="line.73"></a>
+<span class="sourceLineNo">074</span>  private static final String REST_API_CLUSTER_MANAGER_CLUSTER_NAME =<a name="line.74"></a>
+<span class="sourceLineNo">075</span>      "hbase.it.clustermanager.restapi.clustername";<a name="line.75"></a>
+<span class="sourceLineNo">076</span><a name="line.76"></a>
+<span class="sourceLineNo">077</span>  // Some default values for the above properties.<a name="line.77"></a>
+<span class="sourceLineNo">078</span>  private static final String DEFAULT_SERVER_HOSTNAME = "http://localhost:7180";<a name="line.78"></a>
+<span class="sourceLineNo">079</span>  private static final String DEFAULT_SERVER_USERNAME = "admin";<a name="line.79"></a>
+<span class="sourceLineNo">080</span>  private static final String DEFAULT_SERVER_PASSWORD = "admin";<a name="line.80"></a>
+<span class="sourceLineNo">081</span>  private static final String DEFAULT_CLUSTER_NAME = "Cluster 1";<a name="line.81"></a>
+<span class="sourceLineNo">082</span><a name="line.82"></a>
+<span class="sourceLineNo">083</span>  // Fields for the hostname, username, password, and cluster name of the cluster management server<a name="line.83"></a>
+<span class="sourceLineNo">084</span>  // to be used.<a name="line.84"></a>
+<span class="sourceLineNo">085</span>  private String serverHostname;<a name="line.85"></a>
+<span class="sourceLineNo">086</span>  private String serverUsername;<a name="line.86"></a>
+<span class="sourceLineNo">087</span>  private String serverPassword;<a name="line.87"></a>
+<span class="sourceLineNo">088</span>  private String clusterName;<a name="line.88"></a>
+<span class="sourceLineNo">089</span><a name="line.89"></a>
+<span class="sourceLineNo">090</span>  // Each version of Cloudera Manager supports a particular API versions. Version 6 of this API<a name="line.90"></a>
+<span class="sourceLineNo">091</span>  // provides all the features needed by this class.<a name="line.91"></a>
+<span class="sourceLineNo">092</span>  private static final String API_VERSION = "v6";<a name="line.92"></a>
+<span class="sourceLineNo">093</span><a name="line.93"></a>
+<span class="sourceLineNo">094</span>  // Client instances are expensive, so use the same one for all our REST queries.<a name="line.94"></a>
+<span class="sourceLineNo">095</span>  private Client client = ClientBuilder.newClient();<a name="line.95"></a>
+<span class="sourceLineNo">096</span><a name="line.96"></a>
+<span class="sourceLineNo">097</span>  // An instance of HBaseClusterManager is used for methods like the kill, resume, and suspend<a name="line.97"></a>
+<span class="sourceLineNo">098</span>  // because cluster managers don't tend to implement these operations.<a name="line.98"></a>
+<span class="sourceLineNo">099</span>  private ClusterManager hBaseClusterManager;<a name="line.99"></a>
+<span class="sourceLineNo">100</span><a name="line.100"></a>
+<span class="sourceLineNo">101</span>  private static final Log LOG = LogFactory.getLog(RESTApiClusterManager.class);<a name="line.101"></a>
+<span class="sourceLineNo">102</span><a name="line.102"></a>
+<span class="sourceLineNo">103</span>  RESTApiClusterManager() {<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    hBaseClusterManager = ReflectionUtils.newInstance(HBaseClusterManager.class,<a name="line.104"></a>
+<span class="sourceLineNo">105</span>        new IntegrationTestingUtility().getConfiguration());<a name="line.105"></a>
+<span class="sourceLineNo">106</span>  }<a name="line.106"></a>
+<span class="sourceLineNo">107</span><a name="line.107"></a>
+<span class="sourceLineNo">108</span>  @Override<a name="line.108"></a>
+<span class="sourceLineNo">109</span>  public void setConf(Configuration conf) {<a name="line.109"></a>
+<span class="sourceLineNo">110</span>    super.setConf(conf);<a name="line.110"></a>
+<span class="sourceLineNo">111</span>    if (conf == null) {<a name="line.111"></a>
+<span class="sourceLineNo">112</span>      // Configured gets passed null before real conf. Why? I don't know.<a name="line.112"></a>
+<span class="sourceLineNo">113</span>      return;<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    }<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    serverHostname = conf.get(REST_API_CLUSTER_MANAGER_HOSTNAME, DEFAULT_SERVER_HOSTNAME);<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    serverUsername = conf.get(REST_API_CLUSTER_MANAGER_USERNAME, DEFAULT_SERVER_USERNAME);<a name="line.116"></a>
+<span class="sourceLineNo">117</span>    serverPassword = conf.get(REST_API_CLUSTER_MANAGER_PASSWORD, DEFAULT_SERVER_PASSWORD);<a name="line.117"></a>
+<span class="sourceLineNo">118</span>    clusterName = conf.get(REST_API_CLUSTER_MANAGER_CLUSTER_NAME, DEFAULT_CLUSTER_NAME);<a name="line.118"></a>
+<span class="sourceLineNo">119</span><a name="line.119"></a>
+<span class="sourceLineNo">120</span>    // Add filter to Client instance to enable server authentication.<a name="line.120"></a>
+<span class="sourceLineNo">121</span>    client.register(HttpAuthenticationFeature.basic(serverUsername, serverPassword));<a name="line.121"></a>
+<span class="sourceLineNo">122</span>  }<a name="line.122"></a>
+<span class="sourceLineNo">123</span><a name="line.123"></a>
+<span class="sourceLineNo">124</span>  @Override<a name="line.124"></a>
+<span class="sourceLineNo">125</span>  public void start(ServiceType service, String hostname, int port) throws IOException {<a name="line.125"></a>
+<span class="sourceLineNo">126</span>    performClusterManagerCommand(service, hostname, RoleCommand.START);<a name="line.126"></a>
+<span class="sourceLineNo">127</span>  }<a name="line.127"></a>
+<span class="sourceLineNo">128</span><a name="line.128"></a>
+<span class="sourceLineNo">129</span>  @Override<a name="line.129"></a>
+<span class="sourceLineNo">130</span>  public void stop(ServiceType service, String hostname, int port) throws IOException {<a name="line.130"></a>
+<span class="sourceLineNo">131</span>    performClusterManagerCommand(service, hostname, RoleCommand.STOP);<a name="line.131"></a>
+<span class="sourceLineNo">132</span>  }<a name="line.132"></a>
+<span class="sourceLineNo">133</span><a name="line.133"></a>
+<span class="sourceLineNo">134</span>  @Override<a name="line.134"></a>
+<span class="sourceLineNo">135</span>  public void restart(ServiceType service, String hostname, int port) throws IOException {<a name="line.135"></a>
+<span class="sourceLineNo">136</span>    performClusterManagerCommand(service, hostname, RoleCommand.RESTART);<a name="line.136"></a>
+<span class="sourceLineNo">137</span>  }<a name="line.137"></a>
+<span class="sourceLineNo">138</span><a name="line.138"></a>
+<span class="sourceLineNo">139</span>  @Override<a name="line.139"></a>
+<span class="sourceLineNo">140</span>  public boolean isRunning(ServiceType service, String hostname, int port) throws IOException {<a name="line.140"></a>
+<span class="sourceLineNo">141</span>    String serviceName = getServiceName(roleServiceType.get(service));<a name="line.141"></a>
+<span class="sourceLineNo">142</span>    String hostId = getHostId(hostname);<a name="line.142"></a>
+<span class="sourceLineNo">143</span>    String roleState = getRoleState(serviceName, service.toString(), hostId);<a name="line.143"></a>
+<span class="sourceLineNo">144</span>    String healthSummary = getHealthSummary(serviceName, service.toString(), hostId);<a name="line.144"></a>
+<span class="sourceLineNo">145</span>    boolean isRunning = false;<a name="line.145"></a>
+<span class="sourceLineNo">146</span><a name="line.146"></a>
+<span class="sourceLineNo">147</span>    // Use Yoda condition to prevent NullPointerException. roleState will be null if the "service<a name="line.147"></a>
+<span class="sourceLineNo">148</span>    // type" does not exist on the specified hostname.<a name="line.148"></a>
+<span class="sourceLineNo">149</span>    if ("STARTED".equals(roleState) &amp;&amp; "GOOD".equals(healthSummary)) {<a name="line.149"></a>
+<span class="sourceLineNo">150</span>      isRunning = true;<a name="line.150"></a>
+<span class="sourceLineNo">151</span>    }<a name="line.151"></a>
+<span class="sourceLineNo">152</span><a name="line.152"></a>
+<span class="sourceLineNo">153</span>    return isRunning;<a name="line.153"></a>
+<span class="sourceLineNo">154</span>  }<a name="line.154"></a>
+<span class="sourceLineNo">155</span><a name="line.155"></a>
+<span class="sourceLineNo">156</span>  @Override<a name="line.156"></a>
+<span class="sourceLineNo">157</span>  public void kill(ServiceType service, String hostname, int port) throws IOException {<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    hBaseClusterManager.kill(service, hostname, port);<a name="line.158"></a>
+<span class="sourceLineNo">159</span>  }<a name="line.159"></a>
+<span class="sourceLineNo">160</span><a name="line.160"></a>
+<span class="sourceLineNo">161</span>  @Override<a name="line.161"></a>
+<span class="sourceLineNo">162</span>  public void suspend(ServiceType service, String hostname, int port) throws IOException {<a name="line.162"></a>
+<span class="sourceLineNo">163</span>    hBaseClusterManager.suspend(service, hostname, port);<a name="line.163"></a>
+<span class="sourceLineNo">164</span>  }<a name="line.164"></a>
+<span class="sourceLineNo">165</span><a name="line.165"></a>
+<span class="sourceLineNo">166</span>  @Override<a name="line.166"></a>
+<span class="sourceLineNo">167</span>  public void resume(ServiceType service, String hostname, int port) throws IOException {<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    hBaseClusterManager.resume(service, hostname, port);<a name="line.168"></a>
+<span class="sourceLineNo">169</span>  }<a name="line.169"></a>
 <span class="sourceLineNo">170</span><a name="line.170"></a>
-<span class="sourceLineNo">171</span>  // Convenience method to execute command against role on hostname. Only graceful commands are<a name="line.171"></a>
-<span class="sourceLineNo">172</span>  // supported since cluster management APIs don't tend to let you SIGKILL things.<a name="line.172"></a>
-<span class="sourceLineNo">173</span>  private void performClusterManagerCommand(ServiceType role, String hostname, RoleCommand command)<a name="line.173"></a>
-<span class="sourceLineNo">174</span>      throws IOException {<a name="line.174"></a>
-<span class="sourceLineNo">175</span>    LOG.info("Performing " + command + " command against " + role + " on " + hostname + "...");<a name="line.175"></a>
-<span class="sourceLineNo">176</span>    String serviceName = getServiceName(roleServiceType.get(role));<a name="line.176"></a>
-<span class="sourceLineNo">177</span>    String hostId = getHostId(hostname);<a name="line.177"></a>
-<span class="sourceLineNo">178</span>    String roleName = getRoleName(serviceName, role.toString(), hostId);<a name="line.178"></a>
-<span class="sourceLineNo">179</span>    doRoleCommand(serviceName, roleName, command);<a name="line.179"></a>
-<span class="sourceLineNo">180</span>  }<a name="line.180"></a>
-<span class="sourceLineNo">181</span><a name="line.181"></a>
-<span class="sourceLineNo">182</span>  // Performing a command (e.g. starting or stopping a role) requires a POST instead of a GET.<a name="line.182"></a>
-<span class="sourceLineNo">183</span>  private void doRoleCommand(String serviceName, String roleName, RoleCommand roleCommand) {<a name="line.183"></a>
-<span class="sourceLineNo">184</span>    URI uri = UriBuilder.fromUri(serverHostname)<a name="line.184"></a>
-<span class="sourceLineNo">185</span>        .path("api")<a name="line.185"></a>
-<span class="sourceLineNo">186</span>        .path(API_VERSION)<a name="line.186"></a>
-<span class="sourceLineNo">187</span>        .path("clusters")<a name="line.187"></a>
-<span class="sourceLineNo">188</span>        .path(clusterName)<a name="line.188"></a>
-<span class="sourceLineNo">189</span>        .path("services")<a name="line.189"></a>
-<span class="sourceLineNo">190</span>        .path(serviceName)<a name="line.190"></a>
-<span class="sourceLineNo">191</span>        .path("roleCommands")<a name="line.191"></a>
-<span class="sourceLineNo">192</span>        .path(roleCommand.toString())<a name="line.192"></a>
-<span class="sourceLineNo">193</span>        .build();<a name="line.193"></a>
-<span class="sourceLineNo">194</span>    String body = "{ \"items\": [ \"" + roleName + "\" ] }";<a name="line.194"></a>
-<span class="sourceLineNo">195</span>    LOG.info("Executing POST against " + uri + " with body " + body + "...");<a name="line.195"></a>
-<span class="sourceLineNo">196</span>    ClientResponse response = client.resource(uri)<a name="line.196"></a>
-<span class="sourceLineNo">197</span>        .type(MediaType.APPLICATION_JSON)<a name="line.197"></a>
-<span class="sourceLineNo">198</span>        .post(ClientResponse.class, body);<a name="line.198"></a>
-<span class="sourceLineNo">199</span><a name="line.199"></a>
+<span class="sourceLineNo">171</span><a name="line.171"></a>
+<span class="sourceLineNo">172</span>  // Convenience method to execute command against role on hostname. Only graceful commands are<a name="line.172"></a>
+<span class="sourceLineNo">173</span>  // supported since cluster management APIs don't tend to let you SIGKILL things.<a name="line.173"></a>
+<span class="sourceLineNo">174</span>  private void performClusterManagerCommand(ServiceType role, String hostname, RoleCommand command)<a name="line.174"></a>
+<span class="sourceLineNo">175</span>      throws IOException {<a name="line.175"></a>
+<span class="sourceLineNo">176</span>    LOG.info("Performing " + command + " command against " + role + " on " + hostname + "...");<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    String serviceName = getServiceName(roleServiceType.get(role));<a name="line.177"></a>
+<span class="sourceLineNo">178</span>    String hostId = getHostId(hostname);<a name="line.178"></a>
+<span class="sourceLineNo">179</span>    String roleName = getRoleName(serviceName, role.toString(), hostId);<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    doRoleCommand(serviceName, roleName, command);<a name="line.180"></a>
+<span class="sourceLineNo">181</span>  }<a name="line.181"></a>
+<span class="sourceLineNo">182</span><a name="line.182"></a>
+<span class="sourceLineNo">183</span>  // Performing a command (e.g. starting or stopping a role) requires a POST instead of a GET.<a name="line.183"></a>
+<span class="sourceLineNo">184</span>  private void doRoleCommand(String serviceName, String roleName, RoleCommand roleCommand) {<a name="line.184"></a>
+<span class="sourceLineNo">185</span>    URI uri = UriBuilder.fromUri(serverHostname)<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        .path("api")<a name="line.186"></a>
+<span class="sourceLineNo">187</span>        .path(API_VERSION)<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        .path("clusters")<a name="line.188"></a>
+<span class="sourceLineNo">189</span>        .path(clusterName)<a name="line.189"></a>
+<span class="sourceLineNo">190</span>        .path("services")<a name="line.190"></a>
+<span class="sourceLineNo">191</span>        .path(serviceName)<a name="line.191"></a>
+<span class="sourceLineNo">192</span>        .path("roleCommands")<a name="line.192"></a>
+<span class="sourceLineNo">193</span>        .path(roleCommand.toString())<a name="line.193"></a>
+<span class="sourceLineNo">194</span>        .build();<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    String body = "{ \"items\": [ \"" + roleName + "\" ] }";<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    LOG.info("Executing POST against " + uri + " with body " + body + "...");<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    WebTarget webTarget = client.target(uri);<a name="line.197"></a>
+<span class="sourceLineNo">198</span>    Invocation.Builder invocationBuilder =  webTarget.request(MediaType.APPLICATION_JSON);<a name="line.198"></a>
+<span class="sourceLineNo">199</span>    Response response = invocationBuilder.post(Entity.json(body));<a name="line.199"></a>
 <span class="sourceLineNo">200</span>    int statusCode = response.getStatus();<a name="line.200"></a>
 <span class="sourceLineNo">201</span>    if (statusCode != Response.Status.OK.getStatusCode()) {<a name="line.201"></a>
 <span class="sourceLineNo">202</span>      throw new HTTPException(statusCode);<a name="line.202"></a>
@@ -245,16 +245,16 @@
 <span class="sourceLineNo">237</span>  // Execute GET against URI, returning a JsonNode object to be traversed.<a name="line.237"></a>
 <span class="sourceLineNo">238</span>  private JsonNode getJsonNodeFromURIGet(URI uri) throws IOException {<a name="line.238"></a>
 <span class="sourceLineNo">239</span>    LOG.info("Executing GET against " + uri + "...");<a name="line.239"></a>
-<span class="sourceLineNo">240</span>    ClientResponse response = client.resource(uri)<a name="line.240"></a>
-<span class="sourceLineNo">241</span>        .accept(MediaType.APPLICATION_JSON_TYPE)<a name="line.241"></a>
-<span class="sourceLineNo">242</span>        .get(ClientResponse.class);<a name="line.242"></a>
-<span class="sourceLineNo">243</span><a name="line.243"></a>
-<span class="sourceLineNo">244</span>    int statusCode = response.getStatus();<a name="line.244"></a>
-<span class="sourceLineNo">245</span>    if (statusCode != Response.Status.OK.getStatusCode()) {<a name="line.245"></a>
-<span class="sourceLineNo">246</span>      throw new HTTPException(statusCode);<a name="line.246"></a>
-<span class="sourceLineNo">247</span>    }<a name="line.247"></a>
-<span class="sourceLineNo">248</span>    // This API folds information as the value to an "items" attribute.<a name="line.248"></a>
-<span class="sourceLineNo">249</span>    return new ObjectMapper().readTree(response.getEntity(String.class)).get("items");<a name="line.249"></a>
+<span class="sourceLineNo">240</span>    WebTarget webTarget = client.target(uri);<a name="line.240"></a>
+<span class="sourceLineNo">241</span>    Invocation.Builder invocationBuilder =  webTarget.request(MediaType.APPLICATION_JSON);<a name="line.241"></a>
+<span class="sourceLineNo">242</span>    Response response = invocationBuilder.get();<a name="line.242"></a>
+<span class="sourceLineNo">243</span>    int statusCode = response.getStatus();<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    if (statusCode != Response.Status.OK.getStatusCode()) {<a name="line.244"></a>
+<span class="sourceLineNo">245</span>      throw new HTTPException(statusCode);<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    }<a name="line.246"></a>
+<span class="sourceLineNo">247</span>    // This API folds information as the value to an "items" attribute.<a name="line.247"></a>
+<span class="sourceLineNo">248</span>    return new ObjectMapper().readTree(response.readEntity(String.class)).get("items");<a name="line.248"></a>
+<span class="sourceLineNo">249</span><a name="line.249"></a>
 <span class="sourceLineNo">250</span>  }<a name="line.250"></a>
 <span class="sourceLineNo">251</span><a name="line.251"></a>
 <span class="sourceLineNo">252</span>  // This API assigns a unique role name to each host's instance of a role.<a name="line.252"></a>

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/cef8af03/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.Service.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.Service.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.Service.html
index 0d46b6f..680bc31 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.Service.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/RESTApiClusterManager.Service.html
@@ -26,185 +26,185 @@
 <span class="sourceLineNo">018</span><a name="line.18"></a>
 <span class="sourceLineNo">019</span>package org.apache.hadoop.hbase;<a name="line.19"></a>
 <span class="sourceLineNo">020</span><a name="line.20"></a>
-<span class="sourceLineNo">021</span>import com.sun.jersey.api.client.Client;<a name="line.21"></a>
-<span class="sourceLineNo">022</span>import com.sun.jersey.api.client.ClientResponse;<a name="line.22"></a>
-<span class="sourceLineNo">023</span>import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;<a name="line.23"></a>
-<span class="sourceLineNo">024</span><a name="line.24"></a>
-<span class="sourceLineNo">025</span>import org.apache.commons.logging.Log;<a name="line.25"></a>
-<span class="sourceLineNo">026</span>import org.apache.commons.logging.LogFactory;<a name="line.26"></a>
-<span class="sourceLineNo">027</span>import org.apache.hadoop.conf.Configuration;<a name="line.27"></a>
-<span class="sourceLineNo">028</span>import org.apache.hadoop.conf.Configured;<a name="line.28"></a>
-<span class="sourceLineNo">029</span>import org.apache.hadoop.util.ReflectionUtils;<a name="line.29"></a>
-<span class="sourceLineNo">030</span>import org.codehaus.jackson.JsonNode;<a name="line.30"></a>
-<span class="sourceLineNo">031</span>import org.codehaus.jackson.map.ObjectMapper;<a name="line.31"></a>
-<span class="sourceLineNo">032</span><a name="line.32"></a>
-<span class="sourceLineNo">033</span>import javax.ws.rs.core.MediaType;<a name="line.33"></a>
-<span class="sourceLineNo">034</span>import javax.ws.rs.core.Response;<a name="line.34"></a>
-<span class="sourceLineNo">035</span>import javax.ws.rs.core.UriBuilder;<a name="line.35"></a>
-<span class="sourceLineNo">036</span>import javax.xml.ws.http.HTTPException;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>import java.io.IOException;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>import java.net.URI;<a name="line.38"></a>
-<span class="sourceLineNo">039</span>import java.util.HashMap;<a name="line.39"></a>
-<span class="sourceLineNo">040</span>import java.util.Locale;<a name="line.40"></a>
-<span class="sourceLineNo">041</span>import java.util.Map;<a name="line.41"></a>
-<span class="sourceLineNo">042</span><a name="line.42"></a>
-<span class="sourceLineNo">043</span>/**<a name="line.43"></a>
-<span class="sourceLineNo">044</span> * A ClusterManager implementation designed to control Cloudera Manager (http://www.cloudera.com)<a name="line.44"></a>
-<span class="sourceLineNo">045</span> * clusters via REST API. This API uses HTTP GET requests against the cluster manager server to<a name="line.45"></a>
-<span class="sourceLineNo">046</span> * retrieve information and POST/PUT requests to perform actions. As a simple example, to retrieve a<a name="line.46"></a>
-<span class="sourceLineNo">047</span> * list of hosts from a CM server with login credentials admin:admin, a simple curl command would be<a name="line.47"></a>
-<span class="sourceLineNo">048</span> *     curl -X POST -H "Content-Type:application/json" -u admin:admin \<a name="line.48"></a>
-<span class="sourceLineNo">049</span> *         "http://this.is.my.server.com:7180/api/v8/hosts"<a name="line.49"></a>
-<span class="sourceLineNo">050</span> *<a name="line.50"></a>
-<span class="sourceLineNo">051</span> * This command would return a JSON result, which would need to be parsed to retrieve relevant<a name="line.51"></a>
-<span class="sourceLineNo">052</span> * information. This action and many others are covered by this class.<a name="line.52"></a>
-<span class="sourceLineNo">053</span> *<a name="line.53"></a>
-<span class="sourceLineNo">054</span> * A note on nomenclature: while the ClusterManager interface uses a ServiceType enum when<a name="line.54"></a>
-<span class="sourceLineNo">055</span> * referring to things like RegionServers and DataNodes, cluster managers often use different<a name="line.55"></a>
-<span class="sourceLineNo">056</span> * terminology. As an example, Cloudera Manager (http://www.cloudera.com) would refer to a<a name="line.56"></a>
-<span class="sourceLineNo">057</span> * RegionServer as a "role" of the HBase "service." It would further refer to "hbase" as the<a name="line.57"></a>
-<span class="sourceLineNo">058</span> * "serviceType." Apache Ambari (http://ambari.apache.org) would call the RegionServer a<a name="line.58"></a>
-<span class="sourceLineNo">059</span> * "component" of the HBase "service."<a name="line.59"></a>
-<span class="sourceLineNo">060</span> *<a name="line.60"></a>
-<span class="sourceLineNo">061</span> * This class will defer to the ClusterManager terminology in methods that it implements from<a name="line.61"></a>
-<span class="sourceLineNo">062</span> * that interface, but uses Cloudera Manager's terminology when dealing with its API directly.<a name="line.62"></a>
-<span class="sourceLineNo">063</span> */<a name="line.63"></a>
-<span class="sourceLineNo">064</span>public class RESTApiClusterManager extends Configured implements ClusterManager {<a name="line.64"></a>
-<span class="sourceLineNo">065</span>  // Properties that need to be in the Configuration object to interact with the REST API cluster<a name="line.65"></a>
-<span class="sourceLineNo">066</span>  // manager. Most easily defined in hbase-site.xml, but can also be passed on the command line.<a name="line.66"></a>
-<span class="sourceLineNo">067</span>  private static final String REST_API_CLUSTER_MANAGER_HOSTNAME =<a name="line.67"></a>
-<span class="sourceLineNo">068</span>      "hbase.it.clustermanager.restapi.hostname";<a name="line.68"></a>
-<span class="sourceLineNo">069</span>  private static final String REST_API_CLUSTER_MANAGER_USERNAME =<a name="line.69"></a>
-<span class="sourceLineNo">070</span>      "hbase.it.clustermanager.restapi.username";<a name="line.70"></a>
-<span class="sourceLineNo">071</span>  private static final String REST_API_CLUSTER_MANAGER_PASSWORD =<a name="line.71"></a>
-<span class="sourceLineNo">072</span>      "hbase.it.clustermanager.restapi.password";<a name="line.72"></a>
-<span class="sourceLineNo">073</span>  private static final String REST_API_CLUSTER_MANAGER_CLUSTER_NAME =<a name="line.73"></a>
-<span class="sourceLineNo">074</span>      "hbase.it.clustermanager.restapi.clustername";<a name="line.74"></a>
-<span class="sourceLineNo">075</span><a name="line.75"></a>
-<span class="sourceLineNo">076</span>  // Some default values for the above properties.<a name="line.76"></a>
-<span class="sourceLineNo">077</span>  private static final String DEFAULT_SERVER_HOSTNAME = "http://localhost:7180";<a name="line.77"></a>
-<span class="sourceLineNo">078</span>  private static final String DEFAULT_SERVER_USERNAME = "admin";<a name="line.78"></a>
-<span class="sourceLineNo">079</span>  private static final String DEFAULT_SERVER_PASSWORD = "admin";<a name="line.79"></a>
-<span class="sourceLineNo">080</span>  private static final String DEFAULT_CLUSTER_NAME = "Cluster 1";<a name="line.80"></a>
-<span class="sourceLineNo">081</span><a name="line.81"></a>
-<span class="sourceLineNo">082</span>  // Fields for the hostname, username, password, and cluster name of the cluster management server<a name="line.82"></a>
-<span class="sourceLineNo">083</span>  // to be used.<a name="line.83"></a>
-<span class="sourceLineNo">084</span>  private String serverHostname;<a name="line.84"></a>
-<span class="sourceLineNo">085</span>  private String serverUsername;<a name="line.85"></a>
-<span class="sourceLineNo">086</span>  private String serverPassword;<a name="line.86"></a>
-<span class="sourceLineNo">087</span>  private String clusterName;<a name="line.87"></a>
-<span class="sourceLineNo">088</span><a name="line.88"></a>
-<span class="sourceLineNo">089</span>  // Each version of Cloudera Manager supports a particular API versions. Version 6 of this API<a name="line.89"></a>
-<span class="sourceLineNo">090</span>  // provides all the features needed by this class.<a name="line.90"></a>
-<span class="sourceLineNo">091</span>  private static final String API_VERSION = "v6";<a name="line.91"></a>
-<span class="sourceLineNo">092</span><a name="line.92"></a>
-<span class="sourceLineNo">093</span>  // Client instances are expensive, so use the same one for all our REST queries.<a name="line.93"></a>
-<span class="sourceLineNo">094</span>  private Client client = Client.create();<a name="line.94"></a>
-<span class="sourceLineNo">095</span><a name="line.95"></a>
-<span class="sourceLineNo">096</span>  // An instance of HBaseClusterManager is used for methods like the kill, resume, and suspend<a name="line.96"></a>
-<span class="sourceLineNo">097</span>  // because cluster managers don't tend to implement these operations.<a name="line.97"></a>
-<span class="sourceLineNo">098</span>  private ClusterManager hBaseClusterManager;<a name="line.98"></a>
-<span class="sourceLineNo">099</span><a name="line.99"></a>
-<span class="sourceLineNo">100</span>  private static final Log LOG = LogFactory.getLog(RESTApiClusterManager.class);<a name="line.100"></a>
-<span class="sourceLineNo">101</span><a name="line.101"></a>
-<span class="sourceLineNo">102</span>  RESTApiClusterManager() {<a name="line.102"></a>
-<span class="sourceLineNo">103</span>    hBaseClusterManager = ReflectionUtils.newInstance(HBaseClusterManager.class,<a name="line.103"></a>
-<span class="sourceLineNo">104</span>        new IntegrationTestingUtility().getConfiguration());<a name="line.104"></a>
-<span class="sourceLineNo">105</span>  }<a name="line.105"></a>
-<span class="sourceLineNo">106</span><a name="line.106"></a>
-<span class="sourceLineNo">107</span>  @Override<a name="line.107"></a>
-<span class="sourceLineNo">108</span>  public void setConf(Configuration conf) {<a name="line.108"></a>
-<span class="sourceLineNo">109</span>    super.setConf(conf);<a name="line.109"></a>
-<span class="sourceLineNo">110</span>    if (conf == null) {<a name="line.110"></a>
-<span class="sourceLineNo">111</span>      // Configured gets passed null before real conf. Why? I don't know.<a name="line.111"></a>
-<span class="sourceLineNo">112</span>      return;<a name="line.112"></a>
-<span class="sourceLineNo">113</span>    }<a name="line.113"></a>
-<span class="sourceLineNo">114</span>    serverHostname = conf.get(REST_API_CLUSTER_MANAGER_HOSTNAME, DEFAULT_SERVER_HOSTNAME);<a name="line.114"></a>
-<span class="sourceLineNo">115</span>    serverUsername = conf.get(REST_API_CLUSTER_MANAGER_USERNAME, DEFAULT_SERVER_USERNAME);<a name="line.115"></a>
-<span class="sourceLineNo">116</span>    serverPassword = conf.get(REST_API_CLUSTER_MANAGER_PASSWORD, DEFAULT_SERVER_PASSWORD);<a name="line.116"></a>
-<span class="sourceLineNo">117</span>    clusterName = conf.get(REST_API_CLUSTER_MANAGER_CLUSTER_NAME, DEFAULT_CLUSTER_NAME);<a name="line.117"></a>
-<span class="sourceLineNo">118</span><a name="line.118"></a>
-<span class="sourceLineNo">119</span>    // Add filter to Client instance to enable server authentication.<a name="line.119"></a>
-<span class="sourceLineNo">120</span>    client.addFilter(new HTTPBasicAuthFilter(serverUsername, serverPassword));<a name="line.120"></a>
-<span class="sourceLineNo">121</span>  }<a name="line.121"></a>
-<span class="sourceLineNo">122</span><a name="line.122"></a>
-<span class="sourceLineNo">123</span>  @Override<a name="line.123"></a>
-<span class="sourceLineNo">124</span>  public void start(ServiceType service, String hostname, int port) throws IOException {<a name="line.124"></a>
-<span class="sourceLineNo">125</span>    performClusterManagerCommand(service, hostname, RoleCommand.START);<a name="line.125"></a>
-<span class="sourceLineNo">126</span>  }<a name="line.126"></a>
-<span class="sourceLineNo">127</span><a name="line.127"></a>
-<span class="sourceLineNo">128</span>  @Override<a name="line.128"></a>
-<span class="sourceLineNo">129</span>  public void stop(ServiceType service, String hostname, int port) throws IOException {<a name="line.129"></a>
-<span class="sourceLineNo">130</span>    performClusterManagerCommand(service, hostname, RoleCommand.STOP);<a name="line.130"></a>
-<span class="sourceLineNo">131</span>  }<a name="line.131"></a>
-<span class="sourceLineNo">132</span><a name="line.132"></a>
-<span class="sourceLineNo">133</span>  @Override<a name="line.133"></a>
-<span class="sourceLineNo">134</span>  public void restart(ServiceType service, String hostname, int port) throws IOException {<a name="line.134"></a>
-<span class="sourceLineNo">135</span>    performClusterManagerCommand(service, hostname, RoleCommand.RESTART);<a name="line.135"></a>
-<span class="sourceLineNo">136</span>  }<a name="line.136"></a>
-<span class="sourceLineNo">137</span><a name="line.137"></a>
-<span class="sourceLineNo">138</span>  @Override<a name="line.138"></a>
-<span class="sourceLineNo">139</span>  public boolean isRunning(ServiceType service, String hostname, int port) throws IOException {<a name="line.139"></a>
-<span class="sourceLineNo">140</span>    String serviceName = getServiceName(roleServiceType.get(service));<a name="line.140"></a>
-<span class="sourceLineNo">141</span>    String hostId = getHostId(hostname);<a name="line.141"></a>
-<span class="sourceLineNo">142</span>    String roleState = getRoleState(serviceName, service.toString(), hostId);<a name="line.142"></a>
-<span class="sourceLineNo">143</span>    String healthSummary = getHealthSummary(serviceName, service.toString(), hostId);<a name="line.143"></a>
-<span class="sourceLineNo">144</span>    boolean isRunning = false;<a name="line.144"></a>
-<span class="sourceLineNo">145</span><a name="line.145"></a>
-<span class="sourceLineNo">146</span>    // Use Yoda condition to prevent NullPointerException. roleState will be null if the "service<a name="line.146"></a>
-<span class="sourceLineNo">147</span>    // type" does not exist on the specified hostname.<a name="line.147"></a>
-<span class="sourceLineNo">148</span>    if ("STARTED".equals(roleState) &amp;&amp; "GOOD".equals(healthSummary)) {<a name="line.148"></a>
-<span class="sourceLineNo">149</span>      isRunning = true;<a name="line.149"></a>
-<span class="sourceLineNo">150</span>    }<a name="line.150"></a>
-<span class="sourceLineNo">151</span><a name="line.151"></a>
-<span class="sourceLineNo">152</span>    return isRunning;<a name="line.152"></a>
-<span class="sourceLineNo">153</span>  }<a name="line.153"></a>
-<span class="sourceLineNo">154</span><a name="line.154"></a>
-<span class="sourceLineNo">155</span>  @Override<a name="line.155"></a>
-<span class="sourceLineNo">156</span>  public void kill(ServiceType service, String hostname, int port) throws IOException {<a name="line.156"></a>
-<span class="sourceLineNo">157</span>    hBaseClusterManager.kill(service, hostname, port);<a name="line.157"></a>
-<span class="sourceLineNo">158</span>  }<a name="line.158"></a>
-<span class="sourceLineNo">159</span><a name="line.159"></a>
-<span class="sourceLineNo">160</span>  @Override<a name="line.160"></a>
-<span class="sourceLineNo">161</span>  public void suspend(ServiceType service, String hostname, int port) throws IOException {<a name="line.161"></a>
-<span class="sourceLineNo">162</span>    hBaseClusterManager.suspend(service, hostname, port);<a name="line.162"></a>
-<span class="sourceLineNo">163</span>  }<a name="line.163"></a>
-<span class="sourceLineNo">164</span><a name="line.164"></a>
-<span class="sourceLineNo">165</span>  @Override<a name="line.165"></a>
-<span class="sourceLineNo">166</span>  public void resume(ServiceType service, String hostname, int port) throws IOException {<a name="line.166"></a>
-<span class="sourceLineNo">167</span>    hBaseClusterManager.resume(service, hostname, port);<a name="line.167"></a>
-<span class="sourceLineNo">168</span>  }<a name="line.168"></a>
-<span class="sourceLineNo">169</span><a name="line.169"></a>
+<span class="sourceLineNo">021</span>import org.apache.commons.logging.Log;<a name="line.21"></a>
+<span class="sourceLineNo">022</span>import org.apache.commons.logging.LogFactory;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import org.apache.hadoop.conf.Configuration;<a name="line.23"></a>
+<span class="sourceLineNo">024</span>import org.apache.hadoop.conf.Configured;<a name="line.24"></a>
+<span class="sourceLineNo">025</span>import org.apache.hadoop.util.ReflectionUtils;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import org.codehaus.jackson.JsonNode;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import org.codehaus.jackson.map.ObjectMapper;<a name="line.27"></a>
+<span class="sourceLineNo">028</span>import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;<a name="line.28"></a>
+<span class="sourceLineNo">029</span>import javax.ws.rs.client.Client;<a name="line.29"></a>
+<span class="sourceLineNo">030</span>import javax.ws.rs.client.ClientBuilder;<a name="line.30"></a>
+<span class="sourceLineNo">031</span>import javax.ws.rs.client.Entity;<a name="line.31"></a>
+<span class="sourceLineNo">032</span>import javax.ws.rs.client.Invocation;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import javax.ws.rs.client.WebTarget;<a name="line.33"></a>
+<span class="sourceLineNo">034</span>import javax.ws.rs.core.MediaType;<a name="line.34"></a>
+<span class="sourceLineNo">035</span>import javax.ws.rs.core.Response;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>import javax.ws.rs.core.UriBuilder;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import javax.xml.ws.http.HTTPException;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import java.io.IOException;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import java.net.URI;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import java.util.HashMap;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>import java.util.Locale;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>import java.util.Map;<a name="line.42"></a>
+<span class="sourceLineNo">043</span><a name="line.43"></a>
+<span class="sourceLineNo">044</span>/**<a name="line.44"></a>
+<span class="sourceLineNo">045</span> * A ClusterManager implementation designed to control Cloudera Manager (http://www.cloudera.com)<a name="line.45"></a>
+<span class="sourceLineNo">046</span> * clusters via REST API. This API uses HTTP GET requests against the cluster manager server to<a name="line.46"></a>
+<span class="sourceLineNo">047</span> * retrieve information and POST/PUT requests to perform actions. As a simple example, to retrieve a<a name="line.47"></a>
+<span class="sourceLineNo">048</span> * list of hosts from a CM server with login credentials admin:admin, a simple curl command would be<a name="line.48"></a>
+<span class="sourceLineNo">049</span> *     curl -X POST -H "Content-Type:application/json" -u admin:admin \<a name="line.49"></a>
+<span class="sourceLineNo">050</span> *         "http://this.is.my.server.com:7180/api/v8/hosts"<a name="line.50"></a>
+<span class="sourceLineNo">051</span> *<a name="line.51"></a>
+<span class="sourceLineNo">052</span> * This command would return a JSON result, which would need to be parsed to retrieve relevant<a name="line.52"></a>
+<span class="sourceLineNo">053</span> * information. This action and many others are covered by this class.<a name="line.53"></a>
+<span class="sourceLineNo">054</span> *<a name="line.54"></a>
+<span class="sourceLineNo">055</span> * A note on nomenclature: while the ClusterManager interface uses a ServiceType enum when<a name="line.55"></a>
+<span class="sourceLineNo">056</span> * referring to things like RegionServers and DataNodes, cluster managers often use different<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * terminology. As an example, Cloudera Manager (http://www.cloudera.com) would refer to a<a name="line.57"></a>
+<span class="sourceLineNo">058</span> * RegionServer as a "role" of the HBase "service." It would further refer to "hbase" as the<a name="line.58"></a>
+<span class="sourceLineNo">059</span> * "serviceType." Apache Ambari (http://ambari.apache.org) would call the RegionServer a<a name="line.59"></a>
+<span class="sourceLineNo">060</span> * "component" of the HBase "service."<a name="line.60"></a>
+<span class="sourceLineNo">061</span> *<a name="line.61"></a>
+<span class="sourceLineNo">062</span> * This class will defer to the ClusterManager terminology in methods that it implements from<a name="line.62"></a>
+<span class="sourceLineNo">063</span> * that interface, but uses Cloudera Manager's terminology when dealing with its API directly.<a name="line.63"></a>
+<span class="sourceLineNo">064</span> */<a name="line.64"></a>
+<span class="sourceLineNo">065</span>public class RESTApiClusterManager extends Configured implements ClusterManager {<a name="line.65"></a>
+<span class="sourceLineNo">066</span>  // Properties that need to be in the Configuration object to interact with the REST API cluster<a name="line.66"></a>
+<span class="sourceLineNo">067</span>  // manager. Most easily defined in hbase-site.xml, but can also be passed on the command line.<a name="line.67"></a>
+<span class="sourceLineNo">068</span>  private static final String REST_API_CLUSTER_MANAGER_HOSTNAME =<a name="line.68"></a>
+<span class="sourceLineNo">069</span>      "hbase.it.clustermanager.restapi.hostname";<a name="line.69"></a>
+<span class="sourceLineNo">070</span>  private static final String REST_API_CLUSTER_MANAGER_USERNAME =<a name="line.70"></a>
+<span class="sourceLineNo">071</span>      "hbase.it.clustermanager.restapi.username";<a name="line.71"></a>
+<span class="sourceLineNo">072</span>  private static final String REST_API_CLUSTER_MANAGER_PASSWORD =<a name="line.72"></a>
+<span class="sourceLineNo">073</span>      "hbase.it.clustermanager.restapi.password";<a name="line.73"></a>
+<span class="sourceLineNo">074</span>  private static final String REST_API_CLUSTER_MANAGER_CLUSTER_NAME =<a name="line.74"></a>
+<span class="sourceLineNo">075</span>      "hbase.it.clustermanager.restapi.clustername";<a name="line.75"></a>
+<span class="sourceLineNo">076</span><a name="line.76"></a>
+<span class="sourceLineNo">077</span>  // Some default values for the above properties.<a name="line.77"></a>
+<span class="sourceLineNo">078</span>  private static final String DEFAULT_SERVER_HOSTNAME = "http://localhost:7180";<a name="line.78"></a>
+<span class="sourceLineNo">079</span>  private static final String DEFAULT_SERVER_USERNAME = "admin";<a name="line.79"></a>
+<span class="sourceLineNo">080</span>  private static final String DEFAULT_SERVER_PASSWORD = "admin";<a name="line.80"></a>
+<span class="sourceLineNo">081</span>  private static final String DEFAULT_CLUSTER_NAME = "Cluster 1";<a name="line.81"></a>
+<span class="sourceLineNo">082</span><a name="line.82"></a>
+<span class="sourceLineNo">083</span>  // Fields for the hostname, username, password, and cluster name of the cluster management server<a name="line.83"></a>
+<span class="sourceLineNo">084</span>  // to be used.<a name="line.84"></a>
+<span class="sourceLineNo">085</span>  private String serverHostname;<a name="line.85"></a>
+<span class="sourceLineNo">086</span>  private String serverUsername;<a name="line.86"></a>
+<span class="sourceLineNo">087</span>  private String serverPassword;<a name="line.87"></a>
+<span class="sourceLineNo">088</span>  private String clusterName;<a name="line.88"></a>
+<span class="sourceLineNo">089</span><a name="line.89"></a>
+<span class="sourceLineNo">090</span>  // Each version of Cloudera Manager supports a particular API versions. Version 6 of this API<a name="line.90"></a>
+<span class="sourceLineNo">091</span>  // provides all the features needed by this class.<a name="line.91"></a>
+<span class="sourceLineNo">092</span>  private static final String API_VERSION = "v6";<a name="line.92"></a>
+<span class="sourceLineNo">093</span><a name="line.93"></a>
+<span class="sourceLineNo">094</span>  // Client instances are expensive, so use the same one for all our REST queries.<a name="line.94"></a>
+<span class="sourceLineNo">095</span>  private Client client = ClientBuilder.newClient();<a name="line.95"></a>
+<span class="sourceLineNo">096</span><a name="line.96"></a>
+<span class="sourceLineNo">097</span>  // An instance of HBaseClusterManager is used for methods like the kill, resume, and suspend<a name="line.97"></a>
+<span class="sourceLineNo">098</span>  // because cluster managers don't tend to implement these operations.<a name="line.98"></a>
+<span class="sourceLineNo">099</span>  private ClusterManager hBaseClusterManager;<a name="line.99"></a>
+<span class="sourceLineNo">100</span><a name="line.100"></a>
+<span class="sourceLineNo">101</span>  private static final Log LOG = LogFactory.getLog(RESTApiClusterManager.class);<a name="line.101"></a>
+<span class="sourceLineNo">102</span><a name="line.102"></a>
+<span class="sourceLineNo">103</span>  RESTApiClusterManager() {<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    hBaseClusterManager = ReflectionUtils.newInstance(HBaseClusterManager.class,<a name="line.104"></a>
+<span class="sourceLineNo">105</span>        new IntegrationTestingUtility().getConfiguration());<a name="line.105"></a>
+<span class="sourceLineNo">106</span>  }<a name="line.106"></a>
+<span class="sourceLineNo">107</span><a name="line.107"></a>
+<span class="sourceLineNo">108</span>  @Override<a name="line.108"></a>
+<span class="sourceLineNo">109</span>  public void setConf(Configuration conf) {<a name="line.109"></a>
+<span class="sourceLineNo">110</span>    super.setConf(conf);<a name="line.110"></a>
+<span class="sourceLineNo">111</span>    if (conf == null) {<a name="line.111"></a>
+<span class="sourceLineNo">112</span>      // Configured gets passed null before real conf. Why? I don't know.<a name="line.112"></a>
+<span class="sourceLineNo">113</span>      return;<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    }<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    serverHostname = conf.get(REST_API_CLUSTER_MANAGER_HOSTNAME, DEFAULT_SERVER_HOSTNAME);<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    serverUsername = conf.get(REST_API_CLUSTER_MANAGER_USERNAME, DEFAULT_SERVER_USERNAME);<a name="line.116"></a>
+<span class="sourceLineNo">117</span>    serverPassword = conf.get(REST_API_CLUSTER_MANAGER_PASSWORD, DEFAULT_SERVER_PASSWORD);<a name="line.117"></a>
+<span class="sourceLineNo">118</span>    clusterName = conf.get(REST_API_CLUSTER_MANAGER_CLUSTER_NAME, DEFAULT_CLUSTER_NAME);<a name="line.118"></a>
+<span class="sourceLineNo">119</span><a name="line.119"></a>
+<span class="sourceLineNo">120</span>    // Add filter to Client instance to enable server authentication.<a name="line.120"></a>
+<span class="sourceLineNo">121</span>    client.register(HttpAuthenticationFeature.basic(serverUsername, serverPassword));<a name="line.121"></a>
+<span class="sourceLineNo">122</span>  }<a name="line.122"></a>
+<span class="sourceLineNo">123</span><a name="line.123"></a>
+<span class="sourceLineNo">124</span>  @Override<a name="line.124"></a>
+<span class="sourceLineNo">125</span>  public void start(ServiceType service, String hostname, int port) throws IOException {<a name="line.125"></a>
+<span class="sourceLineNo">126</span>    performClusterManagerCommand(service, hostname, RoleCommand.START);<a name="line.126"></a>
+<span class="sourceLineNo">127</span>  }<a name="line.127"></a>
+<span class="sourceLineNo">128</span><a name="line.128"></a>
+<span class="sourceLineNo">129</span>  @Override<a name="line.129"></a>
+<span class="sourceLineNo">130</span>  public void stop(ServiceType service, String hostname, int port) throws IOException {<a name="line.130"></a>
+<span class="sourceLineNo">131</span>    performClusterManagerCommand(service, hostname, RoleCommand.STOP);<a name="line.131"></a>
+<span class="sourceLineNo">132</span>  }<a name="line.132"></a>
+<span class="sourceLineNo">133</span><a name="line.133"></a>
+<span class="sourceLineNo">134</span>  @Override<a name="line.134"></a>
+<span class="sourceLineNo">135</span>  public void restart(ServiceType service, String hostname, int port) throws IOException {<a name="line.135"></a>
+<span class="sourceLineNo">136</span>    performClusterManagerCommand(service, hostname, RoleCommand.RESTART);<a name="line.136"></a>
+<span class="sourceLineNo">137</span>  }<a name="line.137"></a>
+<span class="sourceLineNo">138</span><a name="line.138"></a>
+<span class="sourceLineNo">139</span>  @Override<a name="line.139"></a>
+<span class="sourceLineNo">140</span>  public boolean isRunning(ServiceType service, String hostname, int port) throws IOException {<a name="line.140"></a>
+<span class="sourceLineNo">141</span>    String serviceName = getServiceName(roleServiceType.get(service));<a name="line.141"></a>
+<span class="sourceLineNo">142</span>    String hostId = getHostId(hostname);<a name="line.142"></a>
+<span class="sourceLineNo">143</span>    String roleState = getRoleState(serviceName, service.toString(), hostId);<a name="line.143"></a>
+<span class="sourceLineNo">144</span>    String healthSummary = getHealthSummary(serviceName, service.toString(), hostId);<a name="line.144"></a>
+<span class="sourceLineNo">145</span>    boolean isRunning = false;<a name="line.145"></a>
+<span class="sourceLineNo">146</span><a name="line.146"></a>
+<span class="sourceLineNo">147</span>    // Use Yoda condition to prevent NullPointerException. roleState will be null if the "service<a name="line.147"></a>
+<span class="sourceLineNo">148</span>    // type" does not exist on the specified hostname.<a name="line.148"></a>
+<span class="sourceLineNo">149</span>    if ("STARTED".equals(roleState) &amp;&amp; "GOOD".equals(healthSummary)) {<a name="line.149"></a>
+<span class="sourceLineNo">150</span>      isRunning = true;<a name="line.150"></a>
+<span class="sourceLineNo">151</span>    }<a name="line.151"></a>
+<span class="sourceLineNo">152</span><a name="line.152"></a>
+<span class="sourceLineNo">153</span>    return isRunning;<a name="line.153"></a>
+<span class="sourceLineNo">154</span>  }<a name="line.154"></a>
+<span class="sourceLineNo">155</span><a name="line.155"></a>
+<span class="sourceLineNo">156</span>  @Override<a name="line.156"></a>
+<span class="sourceLineNo">157</span>  public void kill(ServiceType service, String hostname, int port) throws IOException {<a name="line.157"></a>
+<span class="sourceLineNo">158</span>    hBaseClusterManager.kill(service, hostname, port);<a name="line.158"></a>
+<span class="sourceLineNo">159</span>  }<a name="line.159"></a>
+<span class="sourceLineNo">160</span><a name="line.160"></a>
+<span class="sourceLineNo">161</span>  @Override<a name="line.161"></a>
+<span class="sourceLineNo">162</span>  public void suspend(ServiceType service, String hostname, int port) throws IOException {<a name="line.162"></a>
+<span class="sourceLineNo">163</span>    hBaseClusterManager.suspend(service, hostname, port);<a name="line.163"></a>
+<span class="sourceLineNo">164</span>  }<a name="line.164"></a>
+<span class="sourceLineNo">165</span><a name="line.165"></a>
+<span class="sourceLineNo">166</span>  @Override<a name="line.166"></a>
+<span class="sourceLineNo">167</span>  public void resume(ServiceType service, String hostname, int port) throws IOException {<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    hBaseClusterManager.resume(service, hostname, port);<a name="line.168"></a>
+<span class="sourceLineNo">169</span>  }<a name="line.169"></a>
 <span class="sourceLineNo">170</span><a name="line.170"></a>
-<span class="sourceLineNo">171</span>  // Convenience method to execute command against role on hostname. Only graceful commands are<a name="line.171"></a>
-<span class="sourceLineNo">172</span>  // supported since cluster management APIs don't tend to let you SIGKILL things.<a name="line.172"></a>
-<span class="sourceLineNo">173</span>  private void performClusterManagerCommand(ServiceType role, String hostname, RoleCommand command)<a name="line.173"></a>
-<span class="sourceLineNo">174</span>      throws IOException {<a name="line.174"></a>
-<span class="sourceLineNo">175</span>    LOG.info("Performing " + command + " command against " + role + " on " + hostname + "...");<a name="line.175"></a>
-<span class="sourceLineNo">176</span>    String serviceName = getServiceName(roleServiceType.get(role));<a name="line.176"></a>
-<span class="sourceLineNo">177</span>    String hostId = getHostId(hostname);<a name="line.177"></a>
-<span class="sourceLineNo">178</span>    String roleName = getRoleName(serviceName, role.toString(), hostId);<a name="line.178"></a>
-<span class="sourceLineNo">179</span>    doRoleCommand(serviceName, roleName, command);<a name="line.179"></a>
-<span class="sourceLineNo">180</span>  }<a name="line.180"></a>
-<span class="sourceLineNo">181</span><a name="line.181"></a>
-<span class="sourceLineNo">182</span>  // Performing a command (e.g. starting or stopping a role) requires a POST instead of a GET.<a name="line.182"></a>
-<span class="sourceLineNo">183</span>  private void doRoleCommand(String serviceName, String roleName, RoleCommand roleCommand) {<a name="line.183"></a>
-<span class="sourceLineNo">184</span>    URI uri = UriBuilder.fromUri(serverHostname)<a name="line.184"></a>
-<span class="sourceLineNo">185</span>        .path("api")<a name="line.185"></a>
-<span class="sourceLineNo">186</span>        .path(API_VERSION)<a name="line.186"></a>
-<span class="sourceLineNo">187</span>        .path("clusters")<a name="line.187"></a>
-<span class="sourceLineNo">188</span>        .path(clusterName)<a name="line.188"></a>
-<span class="sourceLineNo">189</span>        .path("services")<a name="line.189"></a>
-<span class="sourceLineNo">190</span>        .path(serviceName)<a name="line.190"></a>
-<span class="sourceLineNo">191</span>        .path("roleCommands")<a name="line.191"></a>
-<span class="sourceLineNo">192</span>        .path(roleCommand.toString())<a name="line.192"></a>
-<span class="sourceLineNo">193</span>        .build();<a name="line.193"></a>
-<span class="sourceLineNo">194</span>    String body = "{ \"items\": [ \"" + roleName + "\" ] }";<a name="line.194"></a>
-<span class="sourceLineNo">195</span>    LOG.info("Executing POST against " + uri + " with body " + body + "...");<a name="line.195"></a>
-<span class="sourceLineNo">196</span>    ClientResponse response = client.resource(uri)<a name="line.196"></a>
-<span class="sourceLineNo">197</span>        .type(MediaType.APPLICATION_JSON)<a name="line.197"></a>
-<span class="sourceLineNo">198</span>        .post(ClientResponse.class, body);<a name="line.198"></a>
-<span class="sourceLineNo">199</span><a name="line.199"></a>
+<span class="sourceLineNo">171</span><a name="line.171"></a>
+<span class="sourceLineNo">172</span>  // Convenience method to execute command against role on hostname. Only graceful commands are<a name="line.172"></a>
+<span class="sourceLineNo">173</span>  // supported since cluster management APIs don't tend to let you SIGKILL things.<a name="line.173"></a>
+<span class="sourceLineNo">174</span>  private void performClusterManagerCommand(ServiceType role, String hostname, RoleCommand command)<a name="line.174"></a>
+<span class="sourceLineNo">175</span>      throws IOException {<a name="line.175"></a>
+<span class="sourceLineNo">176</span>    LOG.info("Performing " + command + " command against " + role + " on " + hostname + "...");<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    String serviceName = getServiceName(roleServiceType.get(role));<a name="line.177"></a>
+<span class="sourceLineNo">178</span>    String hostId = getHostId(hostname);<a name="line.178"></a>
+<span class="sourceLineNo">179</span>    String roleName = getRoleName(serviceName, role.toString(), hostId);<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    doRoleCommand(serviceName, roleName, command);<a name="line.180"></a>
+<span class="sourceLineNo">181</span>  }<a name="line.181"></a>
+<span class="sourceLineNo">182</span><a name="line.182"></a>
+<span class="sourceLineNo">183</span>  // Performing a command (e.g. starting or stopping a role) requires a POST instead of a GET.<a name="line.183"></a>
+<span class="sourceLineNo">184</span>  private void doRoleCommand(String serviceName, String roleName, RoleCommand roleCommand) {<a name="line.184"></a>
+<span class="sourceLineNo">185</span>    URI uri = UriBuilder.fromUri(serverHostname)<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        .path("api")<a name="line.186"></a>
+<span class="sourceLineNo">187</span>        .path(API_VERSION)<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        .path("clusters")<a name="line.188"></a>
+<span class="sourceLineNo">189</span>        .path(clusterName)<a name="line.189"></a>
+<span class="sourceLineNo">190</span>        .path("services")<a name="line.190"></a>
+<span class="sourceLineNo">191</span>        .path(serviceName)<a name="line.191"></a>
+<span class="sourceLineNo">192</span>        .path("roleCommands")<a name="line.192"></a>
+<span class="sourceLineNo">193</span>        .path(roleCommand.toString())<a name="line.193"></a>
+<span class="sourceLineNo">194</span>        .build();<a name="line.194"></a>
+<span class="sourceLineNo">195</span>    String body = "{ \"items\": [ \"" + roleName + "\" ] }";<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    LOG.info("Executing POST against " + uri + " with body " + body + "...");<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    WebTarget webTarget = client.target(uri);<a name="line.197"></a>
+<span class="sourceLineNo">198</span>    Invocation.Builder invocationBuilder =  webTarget.request(MediaType.APPLICATION_JSON);<a name="line.198"></a>
+<span class="sourceLineNo">199</span>    Response response = invocationBuilder.post(Entity.json(body));<a name="line.199"></a>
 <span class="sourceLineNo">200</span>    int statusCode = response.getStatus();<a name="line.200"></a>
 <span class="sourceLineNo">201</span>    if (statusCode != Response.Status.OK.getStatusCode()) {<a name="line.201"></a>
 <span class="sourceLineNo">202</span>      throw new HTTPException(statusCode);<a name="line.202"></a>
@@ -245,16 +245,16 @@
 <span class="sourceLineNo">237</span>  // Execute GET against URI, returning a JsonNode object to be traversed.<a name="line.237"></a>
 <span class="sourceLineNo">238</span>  private JsonNode getJsonNodeFromURIGet(URI uri) throws IOException {<a name="line.238"></a>
 <span class="sourceLineNo">239</span>    LOG.info("Executing GET against " + uri + "...");<a name="line.239"></a>
-<span class="sourceLineNo">240</span>    ClientResponse response = client.resource(uri)<a name="line.240"></a>
-<span class="sourceLineNo">241</span>        .accept(MediaType.APPLICATION_JSON_TYPE)<a name="line.241"></a>
-<span class="sourceLineNo">242</span>        .get(ClientResponse.class);<a name="line.242"></a>
-<span class="sourceLineNo">243</span><a name="line.243"></a>
-<span class="sourceLineNo">244</span>    int statusCode = response.getStatus();<a name="line.244"></a>
-<span class="sourceLineNo">245</span>    if (statusCode != Response.Status.OK.getStatusCode()) {<a name="line.245"></a>
-<span class="sourceLineNo">246</span>      throw new HTTPException(statusCode);<a name="line.246"></a>
-<span class="sourceLineNo">247</span>    }<a name="line.247"></a>
-<span class="sourceLineNo">248</span>    // This API folds information as the value to an "items" attribute.<a name="line.248"></a>
-<span class="sourceLineNo">249</span>    return new ObjectMapper().readTree(response.getEntity(String.class)).get("items");<a name="line.249"></a>
+<span class="sourceLineNo">240</span>    WebTarget webTarget = client.target(uri);<a name="line.240"></a>
+<span class="sourceLineNo">241</span>    Invocation.Builder invocationBuilder =  webTarget.request(MediaType.APPLICATION_JSON);<a name="line.241"></a>
+<span class="sourceLineNo">242</span>    Response response = invocationBuilder.get();<a name="line.242"></a>
+<span class="sourceLineNo">243</span>    int statusCode = response.getStatus();<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    if (statusCode != Response.Status.OK.getStatusCode()) {<a name="line.244"></a>
+<span class="sourceLineNo">245</span>      throw new HTTPException(statusCode);<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    }<a name="line.246"></a>
+<span class="sourceLineNo">247</span>    // This API folds information as the value to an "items" attribute.<a name="line.247"></a>
+<span class="sourceLineNo">248</span>    return new ObjectMapper().readTree(response.readEntity(String.class)).get("items");<a name="line.248"></a>
+<span class="sourceLineNo">249</span><a name="line.249"></a>
 <span class="sourceLineNo">250</span>  }<a name="line.250"></a>
 <span class="sourceLineNo">251</span><a name="line.251"></a>
 <span class="sourceLineNo">252</span>  // This API assigns a unique role name to each host's instance of a role.<a name="line.252"></a>


Mime
View raw message