FusionInsight Manager集成對接之通過Basic認證實現(xiàn)用戶操作
場景說明
用戶在某些業(yè)務場景下需要以非界面方式實現(xiàn)操作FusionInsight Manager系統(tǒng),要求開發(fā)基于HTTP Basic認證的應用程序實現(xiàn)如下功能:
登錄FusionInsight Manager系統(tǒng)。
訪問FusionInsight Manager系統(tǒng),進行查詢、添加、刪除等操作。
開發(fā)思路
功能分解
根據(jù)上述的業(yè)務場景進行功能分解,需要開發(fā)的功能點如表11-198所示。
表11-198?在Manager中開發(fā)的功能
序號
步驟
代碼實現(xiàn)
1
添加用戶
請參見“添加用戶”。
2
查找用戶
請參見“查找用戶”。
3
修改用戶
請參見“修改用戶”。
4
刪除用戶
請參見“刪除用戶”。
5
導出用戶列表
請參見“導出用戶列表”。
數(shù)據(jù)準備
從FusionInsight Manager的Rest API接口文檔中獲取webUrl以及用戶想要實現(xiàn)的操作對應的Url。
從FusionInsight Manager的Rest API接口文檔中獲取想要實現(xiàn)的操作對應需要的json請求體參數(shù)和格式,并創(chuàng)建和保存相應的json文件。
樣例代碼說明
登錄認證
實現(xiàn)Basic認證登錄,并返回登錄后的httpClient。
配置用戶的集群信息和登錄帳號信息:
配置文件:“樣例工程文件夾\conf\UserInfo.properties”。
參數(shù)說明:
userName:登錄Manager系統(tǒng)的用戶名。
password:userName對應的用戶密碼。
webUrl:Manager首頁地址。
填寫“UserInfo.properties”文件中的參數(shù),注意填寫的準確性,可以仿照以下參數(shù)示例進行填寫,其中,“IP_Address”填寫FusionInsight Manager對應的浮動IP地址。
如果需要使用其他用戶進行操作,請先登錄FusionInsight Manager創(chuàng)建用戶。
userName= admin password= adminPassWord webUrl= https://IP_Address:28443/web/
以下代碼片段是調(diào)用firstAccess接口完成登錄認證的示例,在“rest”包的“UserManager”類的main方法中。
BasicAuthAccess authAccess = new BasicAuthAccess(); HttpClient httpClient = authAccess.loginAndAccess(webUrl, userName, password, userTLSVersion); LOG.info("Start to access REST API."); HttpManager httpManager = new HttpManager(); String operationName = ""; String operationUrl = ""; String jsonFilePath = "";
添加用戶
通過訪問Manager接口完成添加用戶。
以下代碼片段是添加用戶的示例,在“rest”包的“UserManager”類的main方法中。
//訪問Manager接口完成添加用戶 operationName = "AddUser"; operationUrl = webUrl + ADD_USER_URL; jsonFilePath = "./conf/addUser.json"; httpManager.sendHttpPostRequest(httpClient, operationUrl, jsonFilePath, operationName)
查找用戶
通過訪問Manager接口完成查找用戶。
以下代碼片段是查找用戶的示例,在“rest”包的“UserManager”類的main方法中。
//訪問Manager接口完成查找用戶列表 operationName = "QueryUserList"; operationUrl = webUrl + QUERY_USER_LIST_URL; String responseLineContent = httpManager.sendHttpGetRequest(httpClient, operationUrl, operationName); LOG.info("The {} response is {}.", operationName, responseLineContent);
修改用戶
通過訪問Manager接口完成修改用戶。
以下代碼片段是修改用戶的示例,在“rest”包的“UserManager”類的main方法中。
//訪問Manager接口完成修改用戶 operationName = "ModifyUser"; String modifyUserName = "user888"; operationUrl = webUrl + MODIFY_USER_URL + modifyUserName; jsonFilePath = "./conf/modifyUser.json"; httpManager.sendHttpPutRequest(httpClient, operationUrl, jsonFilePath, operationName);
刪除用戶
通過訪問Manager接口完成刪除用戶。
以下代碼片段是刪除用戶的示例,在“rest”包的“UserManager”類的main方法中。
//訪問Manager接口完成刪除用戶 operationName = "DeleteUser"; String deleteJsonStr = "{\"userNames\":[\"user888\"]}"; operationUrl = webUrl + DELETE_USER_URL; httpManager.sendHttpDeleteRequest(httpClient, operationUrl, deleteJsonStr, operationName); LOG.info("Exit main.");
導出用戶列表
通過訪問Manager接口完成導出用戶列表,導出用戶列表需要依次調(diào)用導出和下載接口完成用戶列表的導出。導出接口的輸出為下載接口的輸入。
以下代碼片段是導出用戶列表的示例,在“rest”包的“ExportUsers”類的main方法中。
String operationName = "ExportUsers"; String exportOperationUrl = webUrl + EXPORT_URL; HttpManager httpManager = new HttpManager(); //調(diào)用導出接口 String responseLineContent = httpManager .sendHttpPostRequestWithString(httpClient, exportOperationUrl, StringUtils.EMPTY, operationName); //調(diào)用下載接口 operationName = "DownloadUsers"; JSONObject jsonObj = JSON.parseObject(responseLineContent); String downloadOperationUrl = webUrl + DOWNLOAD_URL + jsonObj.getString("fileName"); httpManager.sendHttpGetRequest(httpClient, downloadOperationUrl, operationName);
FusionInsight
版權聲明:本文內(nèi)容由網(wǎng)絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權內(nèi)容。