亞寵展、全球?qū)櫸锂a(chǎn)業(yè)風(fēng)向標(biāo)——亞洲寵物展覽會深度解析
935
2022-05-29
HetuEngine依托Hadoop集群中的Yarn-Service進(jìn)行資源管理,實(shí)現(xiàn)計(jì)算實(shí)例的租戶級資源隔離。用戶在某些業(yè)務(wù)場景下需要經(jīng)常對計(jì)算實(shí)例或者數(shù)據(jù)源進(jìn)行增刪改查和批量更新,此類頻繁操作需要以非界面方式實(shí)現(xiàn),HetuEngine開放了相關(guān)REST API,便于對計(jì)算實(shí)例和數(shù)據(jù)源管理。具體接口內(nèi)容請參考《華為云Stack 8.0.3 MapReduce服務(wù)(3.1.1-LTS)HetuEngine Rest API接口文檔 01》。
開發(fā)思路
實(shí)現(xiàn)對FusionInsight Manager的cas認(rèn)證;
創(chuàng)建 HSConsole的httpclient;
調(diào)用hsconsole接口實(shí)現(xiàn)功能。
數(shù)據(jù)準(zhǔn)備
HetuEngine服務(wù)HSConsole頁面的鏈接地址,可以打開manager頁面進(jìn)入HetuEngine服務(wù)獲取,也可以通過調(diào)用Manager提供的接口獲取;
從HetuEngine的Rest API接口文檔中獲取用戶想要實(shí)現(xiàn)的操作對應(yīng)的Url;
hsconsole.jks文件,從hsconsole節(jié)點(diǎn)的安裝目錄/opt/huawei/Bigdata/FusionInsight_Hetu_8.1.1/1_xx_HSConsole/etc 獲取;
登錄FusionInsight Manager的用戶名密碼,需要具有hetuadmin用戶組權(quán)限;
樣例代碼
登錄認(rèn)證
功能介紹
實(shí)現(xiàn)Basic認(rèn)證登錄,并返回登錄后的httpClient。
前提條件
將獲取到的hsconsole.jks文件放在本地目錄下,例如
D:\\temp\\restapidemo\\hsconsole.jks
System.setProperty("javax.net.ssl.trustStore", "D:\\temp\\restapidemo\\hsconsole.jks"); String casUrl = "https://manager_float_ip:20009/cas/login?service=https%3A%2F%2Fmanager_float_ip%3A20026%2FHetuEngine%2FHSConsole%2F15%2F"; String hsconsoleUrl = "https://manager_float_ip:20026/HetuEngine/HSConsole/15/#/hsconsole/cluster"; String user = "youruser"; String password = "yourpassword"; CloseableHttpClient httpClient = null; HSConsoleHttpClient hsConsoleHttpClient = new HSConsoleHttpClient(); httpClient = hsConsoleHttpClient.getHttpClient(casUrl, hsconsoleUrl, user, password);`
其中,getHttpClient方法實(shí)現(xiàn)如下,在HSConsoleHttpClient類中:
public CloseableHttpClient getHttpClient(String casUrl, String hsconsoleUrl, String user, String password) throws Exception { CookieStore cookieStore = new BasicCookieStore(); HttpClientContext context = HttpClientContext.create(); context.setCookieStore(cookieStore); CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build(); CloseableHttpResponse response = (CloseableHttpResponse)HttpUtils.httpGet(httpClient, hsconsoleUrl, null, null, context); String pageIt = getPageIt(response.getEntity()); if (pageIt.isEmpty()) { LOG.error("cannot get page it from {}, respone code is {}, response entity is {}.", hsconsoleUrl, response.getStatusLine().getStatusCode(), EntityUtils.toString(response.getEntity())); closeResponse(response); closeClient(httpClient); throw new Exception(hsconsoleUrl + " cas authentication failed."); } if (loginCas(httpClient, pageIt, casUrl, hsconsoleUrl, context, user, password)) { return httpClient; } else { closeClient(httpClient); throw new Exception("cas authentication failed."); } }`
查詢計(jì)算實(shí)例狀態(tài)
功能介紹
通過訪問HetuEngine接口查詢計(jì)算實(shí)例狀態(tài),只能查詢出當(dāng)前用戶有權(quán)限看到的計(jì)算實(shí)例,返回值包含計(jì)算實(shí)例ID,集群名稱等信息,具體信息可以在REST API接口文檔中查詢。
代碼樣例
以下代碼片段是查詢計(jì)算實(shí)例狀態(tài)的示例,在main方法中。
public String getClusterInfo(CloseableHttpClient httpClient, String hsconsoleUrl) { String url = hsconsoleUrl.substring(0, hsconsoleUrl.indexOf("#")) + "v1/hsconsole/clusters?status=&sort=&size=10&page=0&filterType=&filterContent=&condition="; HttpManager httpManager = new HttpManager(httpClient); String response = httpManager.sendHttpGetRequest(url, "GET CLUSTER STATUE"); return response; }
創(chuàng)建計(jì)算實(shí)例配置
功能介紹
通過訪問HetuEngine接口創(chuàng)建計(jì)算實(shí)例配置。
代碼樣例
以下代碼片段是創(chuàng)建計(jì)算實(shí)例配置的示例,在main方法中,其中json是創(chuàng)建配置接口的入?yún)ⅲ唧w可以在REST API接口文檔中獲取。
public String createClusterConfig(CloseableHttpClient httpClient, String hsconsoleUrl, String json) { String url = hsconsoleUrl.substring(0, hsconsoleUrl.indexOf("#")) + "/v1/hsconsole/clusters/config"; HttpManager httpManager = new HttpManager(httpClient); String response = httpManager.sendHttpPostRequestWithString(url, json, "CREATE CLUSTER"); return response; }
啟動計(jì)算實(shí)例
功能介紹
通過訪問HetuEngine接口啟動計(jì)算實(shí)例。
代碼樣例
以下代碼片段是啟動計(jì)算實(shí)例的示例,在main方法中。
public String startCluster(CloseableHttpClient httpClient, String hsconsoleUrl, String clusterId) { String url = hsconsoleUrl.substring(0, hsconsoleUrl.indexOf("#")) + String.format("/v1/hsconsole/clusters/%s/start", clusterId); HttpManager httpManager = new HttpManager(httpClient); String response = httpManager.sendHttpPostRequestWithString(url, null, "START CLUSTER"); return response; }
停止計(jì)算實(shí)例
功能介紹
通過訪問HetuEngine接口停止計(jì)算實(shí)例。
代碼樣例
以下代碼片段是停止計(jì)算實(shí)例的示例,在main方法中。
public String stopCluster(CloseableHttpClient httpClient, String hsconsoleUrl, String clusterId) { String url = hsconsoleUrl.substring(0, hsconsoleUrl.indexOf("#")) + String.format("/v1/hsconsole/clusters/%s/stop", clusterId); HttpManager httpManager = new HttpManager(httpClient); String response = httpManager.sendHttpPostRequestWithString(url, null, "STOP CLUSTER"); return response; }
刪除計(jì)算實(shí)例
功能介紹
通過訪問HetuEngine接口刪除計(jì)算實(shí)例。
代碼樣例
以下代碼片段是刪除計(jì)算實(shí)例的示例,在main方法中,入?yún)lusterId可以使用查詢接口獲取,對應(yīng)HSConsole頁面上計(jì)算實(shí)例ID。
public void deleteCluster(CloseableHttpClient httpClient, String hsconsoleUrl, String clusterId) { String url = hsconsoleUrl.substring(0, hsconsoleUrl.indexOf("#")) + String.format("/v1/hsconsole/clusters/%s/delete", clusterId); HttpManager httpManager = new HttpManager(httpClient); httpManager.sendHttpDeleteRequest(url, null, "DELETE Computer Cluster"); }
EI企業(yè)智能 FusionInsight
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。