HetuEngine運(yùn)維管理實(shí)踐-通過restAPI接口實(shí)現(xiàn)計(jì)算實(shí)例和數(shù)據(jù)源管理(一)

      網(wǎng)友投稿 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 獲取;

      HetuEngine運(yùn)維管理實(shí)踐-通過restAPI接口實(shí)現(xiàn)計(jì)算實(shí)例和數(shù)據(jù)源管理(一)

      登錄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)容。

      上一篇:Go 語言入門很簡單--技巧和竅門(Tips and Tricks)
      下一篇:Go 語言入門很簡單 -- 1. 第一個Go程序
      相關(guān)文章
      亚洲中文字幕无码一去台湾 | 亚洲精品tv久久久久久久久| 亚洲第一第二第三第四第五第六 | mm1313亚洲国产精品美女| 中文字幕无码亚洲欧洲日韩| 国产成+人+综合+亚洲专| 亚洲一级免费视频| 亚洲成a人不卡在线观看| 久久精品国产亚洲av高清漫画| 香蕉视频在线观看亚洲| 亚洲国产一区二区三区青草影视| 亚洲AV无码成人精品区蜜桃| 久久精品亚洲中文字幕无码网站 | 精品亚洲一区二区| 亚洲国产精品一区二区成人片国内| 亚洲色欲一区二区三区在线观看| 91麻豆精品国产自产在线观看亚洲 | 久久久久亚洲AV无码麻豆| 91亚洲va在线天线va天堂va国产| 中文字幕亚洲综合久久2| 亚洲成a人片在线观看中文!!!| 亚洲av乱码一区二区三区香蕉| 亚洲一区二区三区播放在线| 亚洲人成电影网站久久| 亚洲天然素人无码专区| 国产成人高清亚洲一区久久| 亚洲片国产一区一级在线观看 | 亚洲午夜电影在线观看高清 | 亚洲综合小说另类图片动图| 亚洲国产精品18久久久久久 | 亚洲综合色一区二区三区小说| 亚洲国产成人手机在线电影bd| 亚洲AV无码无限在线观看不卡 | 亚洲AV日韩AV永久无码久久| 亚洲色av性色在线观无码| 亚洲av永久综合在线观看尤物| 亚洲人成网站18禁止| 天堂亚洲免费视频| 中文字幕精品亚洲无线码一区| 久久青青成人亚洲精品| 亚洲精品不卡视频|