5-Kylin Java Restful API

2024-09-06 06:38
文章标签 java api restful kylin

本文主要是介绍5-Kylin Java Restful API,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 最近在做大数据方面的开发, 学习研究了一段时间的kylin系统, 对于前端开发需要使用 RESTful API ,但是官网并没有提供详细的Java  API. 经过几天的看文档,最终写出了 Java 的API,不敢私藏,特分享与大家.

复制代码
  1 import java.io.BufferedReader;2 import java.io.InputStream;3 import java.io.InputStreamReader;4 import java.io.OutputStream;5 import java.net.HttpURLConnection;6 import java.net.URL;7 8 import org.apache.commons.codec.binary.Base64;  9 10 11 12 /**13  * 14  * @author HennSun  15  * www.shareideas.net16  * @Reference17  * http://kylin.apache.org/docs15/howto/howto_use_restapi.html#authentication18  *19  */20 public class KylinHttpBasic {21     22     private static String encoding;23     private static final String baseURL = "http://10.1.50.123:7070/kylin/api";24     public static String login(String user,String passwd){25         String method = "POST";26         String para = "/user/authentication";27         byte[] key = (user+":"+passwd).getBytes();28         encoding = Base64.encodeBase64String(key);29         return  excute(para,method,null);30     }31 32     33     public static String listQueryableTables(String projectName){34          35         String method = "GET";36         String para = "/tables_and_columns?project="+projectName;37         38         return  excute(para,method,null);39         40     }41     42     43     /**44      * 45      * @param offset required int Offset used by pagination46      * @param limit required int Cubes per page.47      * @param cubeName optional string Keyword for cube names. To find cubes whose name contains this keyword.48      * @param projectName optional string Project name.49      * @return50      */51     public static String listCubes(int offset,52                                    int limit,53                                    String cubeName,54                                    String projectName ){55         String method = "GET";56         String para = "/cubes?offset="+offset57                             +"&limit="+limit58                             +"&cubeName="+cubeName59                             +"&projectName="+projectName;60         return excute(para,method,null); 61     }62     63     /**64      * 65      * @param cubeName  Cube name.66      * @return67      */68     public static String getCubeDes(String cubeName){69         String method = "GET";70         String para = "/cube_desc/"+cubeName;71         return excute(para,method,null); 72         73     }74     75     76     /**77      * 78      * @param cubeName79      * @return80      */81     public static String getCube(String cubeName){82         String method = "GET";83         String para = "/cubes/"+cubeName;84         return excute(para,method,null); 85         86     }87     88     89     90     /**91      * 92      * @param modelName Data model name, by default it should be the same with cube name.93      * @return94      */95     public static String getDataModel(String modelName){96         String method = "GET";97         String para = "/model/"+modelName;98         return excute(para,method,null);  99         
100     }
101 
102     /**
103      *  
104      * @param cubeName cubeName Cube name.
105      * @return
106      */
107     public static String enableCube(String cubeName){
108         
109         String method = "PUT";
110         String para = "/cubes/"+cubeName+"/enable";
111         return excute(para,method,null); 
112         
113     }
114     
115     /**
116      * 
117      * @param cubeName Cube name.
118      * @return
119      */
120     public static String disableCube(String cubeName){
121         
122         String method = "PUT";
123         String para = "/cubes/"+cubeName+"/disable";
124         return excute(para,method,null); 
125         
126     }
127     
128     /**
129      *  
130      * @param cubeName Cube name.
131      * @return
132      */
133     public static String purgeCube(String cubeName){
134 
135         String method = "PUT";
136         String para = "/cubes/"+cubeName+"/purge";
137         return excute(para,method,null); 
138         
139     }
140     
141     
142     /**
143      *  
144      * @param jobId Job id
145      * @return
146      */
147     public static String resumeJob(String jobId){
148 
149         String method = "PUT";
150         String para = "/jobs/"+jobId+"/resume";
151         return excute(para,method,null); 
152         
153     }
154     
155     
156     /**
157      * startTime - required long Start timestamp of data to build, e.g. 1388563200000 for 2014-1-1
158      * endTime - required long End timestamp of data to build
159      * buildType - required string Supported build type: ‘BUILD’, ‘MERGE’, ‘REFRESH’
160      * @param cubeName  Cube name.
161      * @return
162      */
163     public static String buildCube(String cubeName,String body){
164         String method = "PUT";
165         String para = "/cubes/"+cubeName+"/rebuild";
166         
167         return excute(para,method,body); 
168     }
169     
170     
171     /**
172      * 
173      * @param jobId  Job id.
174      * @return
175      */
176     public static String discardJob(String jobId){
177 
178         String method = "PUT";
179         String para = "/jobs/"+jobId+"/cancel";
180         return excute(para,method,null); 
181         
182     }
183     
184     /**
185      * 
186      * @param jobId  Job id.
187      * @return
188      */
189     public static String getJobStatus(String jobId){
190 
191         String method = "GET";
192         String para = "/jobs/"+jobId;
193         return excute(para,method,null); 
194         
195     }
196     
197     /**
198      * 
199      * @param jobId Job id.
200      * @param stepId  Step id; the step id is composed by jobId with step sequence id; 
201      * for example, the jobId is “fb479e54-837f-49a2-b457-651fc50be110”, its 3rd step id 
202      * is “fb479e54-837f-49a2-b457-651fc50be110-3”,
203      * @return
204      */
205     public static String getJobStepOutput(String jobId,String stepId){
206         String method = "GET";
207         String para = "/"+jobId+"/steps/"+stepId+"/output";
208         return excute(para,method,null); 
209     }
210     
211     /**
212      * 
213      * @param tableName table name to find.
214      * @return
215      */
216     public static String getHiveTable(String tableName){
217         String method = "GET";
218         String para = "/tables/"+tableName;
219         return excute(para,method,null); 
220     }
221     
222     /**
223      * 
224      * @param tableName  table name to find.
225      * @return
226      */
227     public static String getHiveTableInfo(String tableName){
228         String method = "GET";
229         String para = "/tables/"+tableName+"/exd-map";
230         return excute(para,method,null); 
231     }
232     
233 
234     /**
235      * 
236      * @param projectName will list all tables in the project.
237      * @param extOptional boolean set true to get extend info of table.
238      * @return
239      */
240     public static String getHiveTables(String projectName,boolean extOptional){
241         String method = "GET";
242         String para = "/tables?project="+projectName+"&ext="+extOptional;
243         return excute(para,method,null); 
244     }
245     
246     
247     /**
248      * 
249      * @param tables  table names you want to load from hive, separated with comma.
250      * @param project the project which the tables will be loaded into.
251      * @return
252      */
253     public static String loadHiveTables(String tables,String project){
254         String method = "POST";
255         String para = "/tables/"+tables+"/"+project;
256         return excute(para,method,null); 
257     }
258     
259     /**
260      * 
261      * @param type ‘METADATA’ or ‘CUBE’
262      * @param name  Cache key, e.g the cube name.
263      * @param action ‘create’, ‘update’ or ‘drop’
264      * @return
265      */
266     public static String wipeCache(String type,String name,String action){
267         String method = "POST";
268         String para = "/cache/"+type+"/"+name+"/"+action;
269         return excute(para,method,null); 
270     }
271     
272     
273     public static String query(String body){
274         String  method = "POST";
275         String para = "/query";
276         
277         return excute(para,method,body);
278     }
279     
280     
281     
282     private  static String excute(String para,String method,String body){
283     
284         StringBuilder out = new StringBuilder();
285         try {
286             URL url = new URL(baseURL+para);        
287             HttpURLConnection connection = (HttpURLConnection) url.openConnection();
288             connection.setRequestMethod(method);   
289             connection.setDoOutput(true);
290             connection.setRequestProperty  ("Authorization", "Basic " + encoding);
291             connection.setRequestProperty("Content-Type","application/json");         
292             if(body !=null){
293                 byte[] outputInBytes = body.getBytes("UTF-8");
294                 OutputStream os = connection.getOutputStream();
295                 os.write(outputInBytes);    
296                 os.close();
297             }
298             InputStream content = (InputStream)connection.getInputStream();  
299             BufferedReader in  = new BufferedReader (new InputStreamReader (content)); 
300             String line;
301             while ((line = in.readLine()) != null) {
302                 out.append(line);
303             }
304             in.close();
305             connection.disconnect();
306             
307         } catch(Exception e) {
308             e.printStackTrace();
309         }
310         return out.toString();
311     }
312 }
复制代码

这篇关于5-Kylin Java Restful API的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1141284

相关文章

Java实现在Word文档中添加文本水印和图片水印的操作指南

《Java实现在Word文档中添加文本水印和图片水印的操作指南》在当今数字时代,文档的自动化处理与安全防护变得尤为重要,无论是为了保护版权、推广品牌,还是为了在文档中加入特定的标识,为Word文档添加... 目录引言Spire.Doc for Java:高效Word文档处理的利器代码实战:使用Java为Wo

SpringBoot日志级别与日志分组详解

《SpringBoot日志级别与日志分组详解》文章介绍了日志级别(ALL至OFF)及其作用,说明SpringBoot默认日志级别为INFO,可通过application.properties调整全局或... 目录日志级别1、级别内容2、调整日志级别调整默认日志级别调整指定类的日志级别项目开发过程中,利用日志

Java中的抽象类与abstract 关键字使用详解

《Java中的抽象类与abstract关键字使用详解》:本文主要介绍Java中的抽象类与abstract关键字使用详解,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、抽象类的概念二、使用 abstract2.1 修饰类 => 抽象类2.2 修饰方法 => 抽象方法,没有

SpringBoot 多环境开发实战(从配置、管理与控制)

《SpringBoot多环境开发实战(从配置、管理与控制)》本文详解SpringBoot多环境配置,涵盖单文件YAML、多文件模式、MavenProfile分组及激活策略,通过优先级控制灵活切换环境... 目录一、多环境开发基础(单文件 YAML 版)(一)配置原理与优势(二)实操示例二、多环境开发多文件版

Spring 中的切面与事务结合使用完整示例

《Spring中的切面与事务结合使用完整示例》本文给大家介绍Spring中的切面与事务结合使用完整示例,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录 一、前置知识:Spring AOP 与 事务的关系 事务本质上就是一个“切面”二、核心组件三、完

Java实现远程执行Shell指令

《Java实现远程执行Shell指令》文章介绍使用JSch在SpringBoot项目中实现远程Shell操作,涵盖环境配置、依赖引入及工具类编写,详解分号和双与号执行多指令的区别... 目录软硬件环境说明编写执行Shell指令的工具类总结jsch(Java Secure Channel)是SSH2的一个纯J

JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法

《JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法》:本文主要介绍JavaScript中比较两个数组是否有相同元素(交集)的三种常用方法,每种方法结合实例代码给大家介绍的非常... 目录引言:为什么"相等"判断如此重要?方法1:使用some()+includes()(适合小数组)方法2

SpringBoot 获取请求参数的常用注解及用法

《SpringBoot获取请求参数的常用注解及用法》SpringBoot通过@RequestParam、@PathVariable等注解支持从HTTP请求中获取参数,涵盖查询、路径、请求体、头、C... 目录SpringBoot 提供了多种注解来方便地从 HTTP 请求中获取参数以下是主要的注解及其用法:1

HTTP 与 SpringBoot 参数提交与接收协议方式

《HTTP与SpringBoot参数提交与接收协议方式》HTTP参数提交方式包括URL查询、表单、JSON/XML、路径变量、头部、Cookie、GraphQL、WebSocket和SSE,依据... 目录HTTP 协议支持多种参数提交方式,主要取决于请求方法(Method)和内容类型(Content-Ty

深度解析Java @Serial 注解及常见错误案例

《深度解析Java@Serial注解及常见错误案例》Java14引入@Serial注解,用于编译时校验序列化成员,替代传统方式解决运行时错误,适用于Serializable类的方法/字段,需注意签... 目录Java @Serial 注解深度解析1. 注解本质2. 核心作用(1) 主要用途(2) 适用位置3