第三方应用如何通过HTTP接入Linkis
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,第三方应用如何通过HTTP接入Linkis,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。DSS(DataSphereStudio)和Li
千家信息网最后更新 2025年12月02日第三方应用如何通过HTTP接入LinkisDSS(DataSphereStudio)和Linkis的介绍说明不在文中赘述,下面侧重将第三方应用通过http(rest)接入DSS。"
第三方应用如何通过HTTP接入Linkis,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
一、环境说明
环境说明:dss-0.7.0,linkis-0.9.3二、登录 login
发送请求采用过okhttp,RestTemplate,HTTPClient,json与java bean采用过fastjson,gson,Jackson;因为dss的登录状态保持在cookie中,在经过n次踩雷后最终采用RestTemplate(spring-web:5.0.7)+fastjson(1.2.58) 的方式进行请求,并将登录cookie传递给后续其他请求;
POST /api/rest_j/v1/user/login请求参数 { "userName": "hadoop", "password": "hadoop" }返回示例(返回json可能我略有修改,以官方为准) { "method": null, "status": 0, "message": "login successful(登录成功)!", "data": { "isFirstLogin": false, "isAdmin": true, "userName": "hadoop" }}import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClientBuilder;import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;import org.springframework.web.client.RestTemplate;/*** 简单工具类,可以根据自己需求扩展*/public class HttpUtil {public static RestTemplate getRestClient() {// 下面代码HttpClientBuilder会自动管理cookie。// 如果 HttpClientBuilder.create().disableCookieManagement,则禁用cookie的管理CloseableHttpClient build = HttpClientBuilder.create().useSystemProperties().build();return new RestTemplate(new HttpComponentsClientHttpRequestFactory(build));}}
import org.springframework.http.ResponseEntity; /** * 发送post请求进行登录 * @param restClient * @return ResponseEntity */private ResponseEntitylogin(RestTemplate restClient) { JSONObject postData = new JSONObject(); postData.put("userName", "hadoop"); postData.put("password", "hadoop"); String loginUrl = "http://ip:port/api/rest_j/v1/user/login"; return restClient.postForEntity(loginUrl, postData, JSONObject.class); }
三、执行任务 execute
源代码在linkis模块的EntranceRestfulApi
POST /api/rest_j/v1/entrance/execute请求参数{"method":"/api/rest_j/v1/entrance/execute","params": {"variable":{"k1":"v1"},"configuration":{"special":{"k2":"v2"},"runtime":{"k3":"v3"},"startup":{"k4":"v4"}}},"executeApplicationName":"spark","executionCode":"show tables","runType":"sql","source":{"scriptPath": "/home/Linkis/Linkis.sql"}}返回示例{"method": "/api/rest_j/v1/entrance/execute","status": 0,"message": "请求执行成功","data": {"execID": "030418IDEhivebdpdwc010004:10087IDE_johnnwang_21",//执行id,后面要根据它获取任务状态"taskID": "123" // 任务id,后面要根据它或者执行文件}}
/** * * @param restClient * @param sql 要执行的sql代码 * @return */ private ResponseEntityexecuteSql(RestTemplate restClient, String sql) { String url = "/api/rest_j/v1/entrance/execute"; JSONObject map = new JSONObject(); map.put("method", url); map.put("params", new HashMap<>()); //用户指定的运行服务程序的参数,必填,里面的值可以为空 map.put("executeApplicationName", "hive");//执行引擎,我用的hive map.put("executionCode", sql); map.put("runType", "sql");//当用户执行如spark服务时,可以选择python、R、SQL等,不能为空 //因为我没有执行文件脚本,所以没有scriptPath参数 String executeSql = "http://ip:port" + url; return restClient.postForEntity(executeSql, map, JSONObject.class); }
四、查看任务状态 status
源代码在linkis模块的EntranceRestfulApi
GET /api/rest_j/v1/entrance/${execID}/status返回示例{"method": "/api/rest_j/v1/entrance/{execID}/status","status": 0,"message": "获取状态成功","data": {"execID": "${execID}","status": "Running"}}
String statusUrl = "http://ip:port/api/rest_j/v1/entrance/" + execID + "/status";ResponseEntitystatusResp = restTemplate.getForEntity(statusUrl, JSONObject.class);if (statusResp != null && statusResp.getStatusCode().value() == HttpStatus.SC_OK) { String status; for (; ; ) { statusResp = restTemplate.getForEntity(statusUrl, JSONObject.class); status = statusResp.getBody().getJSONObject("data").getString("status"); //死循环查看任务状态,如果任务成功或者失败,则退出循环 if ("Succeed".equals(status) || "Failed".equals(status)) { break; } } if ("Succeed".equals(status)) { // do something }}
五、获取执行结果文件 get
源代码在linkis模块 QueryRestfulApi
GET /api/rest_j/v1/jobhistory/${taskId}/get返回示例{"method": "/api/jobhistory/{id}/get","status": 0,"message": "OK","data": {"task": {"taskID": 3111,"instance": "test-dn2:9108","execId": "IDE_hadoop_46","umUser": "hadoop","engineInstance": "test-dn2:37301","executionCode": "show databases", //执行的sql"progress": 1.0,"logPath": "file:///linkis/hadoop/log/IDE/2020-09-08/3111.log",// 日志路径"resultLocation": "hdfs:///linkis2/hadoop/dwc/20200908/IDE/3111",//sql执行结果所存储的文件路径"status": "Succeed","createdTime": 1599551337000,"updatedTime": 1599551339000,"engineType": null,"errCode": null,"errDesc": null,"executeApplicationName": "hive","requestApplicationName": "IDE","scriptPath": null,"runType": "sql","paramsJson": "{}","costTime": 2000,"strongerExecId": "030413IDEhivetest-dn2:9108IDE_hadoop_46","sourceJson": "{\"scriptPath\":null}"}}}
String historyUrl = "http://ip:port/api/rest_j/v1/jobhistory/" + taskID + "/get";ResponseEntityhisResp = restTemplate.getForEntity(historyUrl, JSONObject.class);if (hisResp != null && hisResp.getStatusCode().value() == HttpStatus.SC_OK) { String resultLocation = hisResp.getBody().getJSONObject("data").getJSONObject("task").getString("resultLocation");}
六、打开结果文件 openFile
源代码在linkis模块 FsRestfulApi
GET /api/rest_j/v1/filesystem/openFile?path=${resultLocation}/_0.dolphin返回示例{"method": "/api/filesystem/openFile","status": 0,"message": "OK","data": {"sql查询结果数据"}}
String resUrl = "http://ip:port/api/rest_j/v1/filesystem/openFile?path=" + resultLocation + "/_0.dolphin";ResponseEntityresResp = restTemplate.getForEntity(resUrl, JSONObject.class); if (resResp!= null && resResp.getStatusCode().value() == HttpStatus.SC_OK) { //do something}
看完上述内容,你们掌握第三方应用如何通过HTTP接入Linkis的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!
任务
文件
状态
示例
登录
成功
参数
模块
源代码
结果
第三方
应用
接入
代码
内容
方法
更多
环境
用户
路径
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
信息社会与网络安全
数据库数据的特征
西安东华软件开发
网络安全应用大赛
医药软件开发项风险预测
网络安全红海市场
智慧交通数据库设计及研究
生存服务器怎么下载
职工档案已进电脑数据库
计算机网络技术会秃头吗
js键值对初始化添加数据库
网络安全小报小图案
云服务器IP会被游戏
提取安卓设备应用数据库
网络安全法宣传短信
火影的排位是所有服务器吗
计算机网络技术发展前景如何
重返帝国换服务器
忘川风华录服务器可以换吗
龙岗区网络技术转移价格走势
饥荒创建服务器
2016校园网络安全事件
新媒体网络技术专业
华为服务器硬盘格式化怎么操作
黑蚁网络技术公司是什么
怀旧服部落战秒进服务器
软件开发什么技术
c 软件开发遇到的问题
莱州金苏网络技术
4u服务器能定制么