1.官方文檔
http://kylin.apache.org/docs15/howto/howto_build_cube_with_restapi.html
http://kylin.apache.org/docs15/howto/howto_use_restapi.html
常用的接口有:
1)獲取segment列表
GET http://host:port/kylin/api/cubes?cubeName=youcubename&limit=15&offset=0
2)獲取構建任務詳情
GET http://host:port/kylin/api/jobs/{job_uuid}
此處的job_uuid可以從上邊的接口segment列表中獲取last_build_job_id即可
3)獲取構建步驟的輸出
GET http://host:port/kylin/api/jobs/{job_uuid}/steps/{step_id}/output
此處的step_id可以從構建任務詳情的接口中找到steps數據然後得到其中每個的id即可5)獲
4)構建kylin的接口
PUT http://host:port/kylin/api/cubes/{cube_name}/rebuild
需要參數
String params="{\"startTime\": "+startTime+",\"endTime\": "+endTime+",\"buildType\":\"BUILD\"}";
5)合併segments
PUT http://host:port/kylin/api/cubes/{cube_name}/rebuild
需要參數
String params="{\"startTime\": "+startTime+",\"endTime\": "+endTime+",\"buildType\":\"MERGE\"}";
2.java調用api接口的公用方法
public static String buildCube(String addr,String params,String method){
String message="";
try {
URL url = new URL(addr);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod(method);
connection.setDoOutput(true);
String auth = ACCOUNT + ":" + PWD;
String code = new String(new Base64().encode(auth.getBytes()));
connection.setRequestProperty("Authorization", "Basic " + code);
connection.setRequestProperty("Content-Type","application/json;charset=UTF-8");
if(params!=null && !"".equals(params)){
PrintWriter out = new PrintWriter(connection.getOutputStream());
out.write(params);
out.close();
}
BufferedReader in;
try {
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
} catch (FileNotFoundException exception) {
java.io.InputStream err = ((HttpURLConnection) connection)
.getErrorStream();
if (err == null)
throw exception;
in = new BufferedReader(new InputStreamReader(err));
}
StringBuffer response = new StringBuffer();
String line;
while ((line = in.readLine()) != null)
response.append(line + "\n");
in.close();
message = response.toString();
}catch (Exception e){
message=e.getMessage();
}
return message;
}
其中參數addr爲地址,例如:
http://host:port/kylin/api/cubes?cubeName=cubename&limit=15&offset=0
param爲參數,有的地址需要參數。例如構建接口
String params="{\"startTime\": "+startTime+",\"endTime\": "+endTime+",\"buildType\":\"BUILD\"}";
method爲調用的方法。有三種:PUT、GET、POST
3.具體接口的地址使用參見kylin的官方api的接口地址。例如
public String testKylin(){
String result="";
try {
String params="";
System.out.println("params=========="+params);
String addr="http://172.16.37.107:7070/kylin/api/cubes?cubeName=cube_for_dicts&limit=15&offset=0";
System.out.println("addr========"+addr);
result = UtilHttp.buildCube(addr,params,"GET");
} catch (Exception e) {
result=e.getMessage();
}
return result;
}