Impala Practice VI: Using the rest API

Source: Internet
Author: User

Objective

After the last Impala situation, and decided to do a set of Impala management system, then the first problem is to obtain the various state of Impala, such as task execution status. After more than a day of trying to summarize.

    • Hue: You can use Hue's script, Hue is written in Python, which has a beeswax module that is responsible for the execution of the task. The disadvantage is that Java APIs are not found.
    • Cloudera Manager Java Api:java can invoke the CM native API and need to import the jar package. Run is run through, but the data too say, at present only through this interface to get the basic situation of the cluster, do not want to toss impala that fast.
    • Cloudera Manager's API:CM provides rest API for others to call, after nearly a day of tossing and running through this piece.
Cloudera Manager Apiimpala Related

The following are some of the APIs associated with Impala, and the main ones that can be used are the following interfaces with queries:

  • /clusters/{clustername}/services/{servicename}/commands/huesyncdb
  • /clusters/{clustername}/services/{servicename}/commands/impalacreatecatalogdatabase
  • /clusters/{clustername}/services/{servicename}/commands/impalacreatecatalogdatabasetables
  • /clusters/{clustername}/services/{servicename}/commands/impalacreateuserdir
  • /clusters/{clustername}/services/{servicename}/commands/impaladisablellamaha
  • /clusters/{clustername}/services/{servicename}/commands/impaladisablellamarm
  • /clusters/{clustername}/services/{servicename}/commands/impalaenablellamaha
  • /clusters/{clustername}/services/{servicename}/commands/impalaenablellamarm
  • /clusters/{clustername}/services/{servicename}/impalaqueries
  • /clusters/{clustername}/services/{servicename}/impalaqueries/{queryid}
  • /clusters/{clustername}/services/{servicename}/impalaqueries/{queryid}/cancel
  • /clusters/{clustername}/services/{servicename}/impalaqueries/attributes
Invoke Example

Interface Description:

GET

Returns details about the query. Not all queries has details, check the Detailsavailable field from the getqueries response.

/api/v9/clusters/{clusterName}/services/{serviceName}/impalaQueries/{queryId}

Note:
1. Username:password: Refers to the login cm's account number and password
2. Cluster1: Is the name of your cluster
3. Impala: Is the name of your Impala service
4.364E76F05CDFFSDF802B0:3A499CC3FB86BF8AFSD: Is the ID of the query

Curl Example:

-u‘clouderamanager.zhdd.com/api/v9/clusters/Cluster1/services/impala/impalaQueries/364e76f05cdffsdf802b0:3a499cc3fb86bf8afsd‘

Results:

The result is a large JSON string

Java Example:

import org. Apache. HTTP. Auth. Authscope;import org. Apache. HTTP. Auth. Usernamepasswordcredentials;import org. Apache. HTTP. Client. Credentialsprovider;import org. Apache. HTTP. Client. Methods. Closeablehttpresponse;import org. Apache. HTTP. Client. Methods. HttpGet;import org. Apache. HTTP. Client. Methods. HttpPost;import org. Apache. HTTP. Impl. Client. Basiccredentialsprovider;import org. Apache. HTTP. Impl. Client. Closeablehttpclient;import org. Apache. HTTP. Impl. Client. Httpclients;import org. Apache. HTTP. Util. Entityutils;public class Clientauthentication {public static void main (string[] args) throws Exception {String username ="username";String Password ="Password";Credentialsprovider Credsprovider = new Basiccredentialsprovider ();Credsprovider. SetCredentials(New Authscope ("Clouderamanager.zhdd.com", Authscope. any_port), New usernamepasswordcredentials (username, password));Closeablehttpclient httpclient = httpclients. Custom(). Setdefaultcredentialsprovider(Credsprovider). Build();try {httpget httpget = new HttpGet ("http://clouderamanager.zhdd.com/api/v9/clusters/Cluster1/services/impala/impalaQueries/ 364E76F05CDFFSDF802B0:3A499CC3FB86BF8AFSD ");System. out. println("Executing request"+ HttpGet. Getrequestline());Closeablehttpresponse response = HttpClient. Execute(HttpGet);try {System. out. println("----------------------------------------");System. out. println(Response. Getstatusline());System. out. println(entityutils. toString(Response. GetEntity()));} finally {response. Close();}} finally {HttpClient. Close();}    }}
Summarize

In this case, my first reaction was to use hue, but the Python and Java interface felt too much trouble, so I found the rest API of CM.

Problem

CM API should have some small problems, I in curl and postman on the test is easier to pass, but the use of Java HttpClient calls always error, permissions authentication failed, always can not authenticate permissions, this problem toss a long time, find a few people help. At last I don't know how, I'll toss it all out.

2016-04-17 18:39:00 HZCT

Impala Practice VI: Using the rest API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.