use of com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method getDataSourceKeyDefine.
@Override
public GeneralResponse<Map> getDataSourceKeyDefine(String clusterName, String authUser, Long keyId) throws UnExpectedRequestException, MetaDataAcquireFailedException {
// Check existence of cluster name
ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
// send request to get dbs
String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceKeyDefine()).path(keyId.toString()).toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token-User", authUser);
headers.add("Token-Code", clusterInfo.getLinkisToken());
HttpEntity<Object> entity = new HttpEntity<>(headers);
LOGGER.info("Start to get data source key define by user and cluster by linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.GET, entity);
Map<String, Object> response = restTemplate.exchange(url, HttpMethod.GET, entity, Map.class).getBody();
LOGGER.info("Finish to get data source key define by user and cluster by linkis. response: {}", response);
if (!checkResponse(response)) {
String message = (String) response.get("message");
LOGGER.error("Error! Can not get meta data from linkis, message: " + message);
throw new MetaDataAcquireFailedException("Error! Can not get meta data from linkis, exception: " + message);
}
Map data = (Map) response.get(LinkisResponseKeyEnum.DATA.getKey());
return new GeneralResponse<>("200", "Success to get datasource key define", data);
}
use of com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method getTableByCsId.
@Override
public DataInfo<CsTableInfoDetail> getTableByCsId(GetUserTableByCsIdRequest request) throws MetaDataAcquireFailedException, UnExpectedRequestException {
DataInfo<CsTableInfoDetail> result = new DataInfo<>();
List<CsTableInfoDetail> csTableInfoDetailList = new ArrayList<>();
try {
LOGGER.info("Start to get tables with context service ID and node name by restful API. csId: {}, nodeName: {}", request.getCsId(), request.getNodeName());
ClusterInfo clusterInfo = checkClusterNameExists(request.getClusterName());
String authUser = request.getLoginUser();
// send request
String url;
if (clusterInfo.getClusterType().endsWith(LINKIS_ONE_VERSION)) {
url = getPath(clusterInfo.getLinkisAddress()).path(QUERY_WORKFLOW_TABLE_PATH).toString();
} else {
url = getPath(clusterInfo.getLinkisAddress()).path(QUERY_CS_TABLE_PATH).toString();
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token-User", authUser);
headers.add("Token-Code", clusterInfo.getLinkisToken());
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("contextID", request.getCsId());
jsonObject.put("nodeName", request.getNodeName());
} catch (JSONException e) {
LOGGER.error(e.getMessage(), e);
throw new UnExpectedRequestException("Failed to construct http body json with context ID and node name", 500);
}
HttpEntity<Object> entity = new HttpEntity<>(jsonObject.toString(), headers);
LOGGER.info("Start to get table with context service ID and node name by restful API. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.POST, entity);
Map<String, Object> response = restTemplate.exchange(url, HttpMethod.POST, entity, Map.class).getBody();
if (!checkResponse(response)) {
String message = (String) response.get("message");
LOGGER.error("Error! Can not get meta data from linkis, message: " + message);
throw new MetaDataAcquireFailedException("Error! Can not get meta data from linkis, exception: " + message);
}
LOGGER.info("Finished to get table with context service ID and node name by restful API. response: {}", response);
Map<String, Object> data = (Map<String, Object>) response.get("data");
List<Map<String, Object>> tables = (List<Map<String, Object>>) data.get("tables");
if (tables == null || tables.size() == 0) {
return result;
}
LOGGER.info("Successfully to get tables with context service ID and node name by restful API. csId: {}, nodeName: {}, tables: {}", request.getCsId(), request.getNodeName(), tables);
for (Map<String, Object> table : tables) {
CsTableInfoDetail csTableInfoDetail = new CsTableInfoDetail();
csTableInfoDetail.setTableName(table.get("tableName").toString());
csTableInfoDetail.setContextKey(table.get("contextKey").toString());
csTableInfoDetailList.add(csTableInfoDetail);
}
result.setContent(csTableInfoDetailList);
result.setTotalCount(tables.size());
} catch (RestClientException e) {
LOGGER.error(e.getMessage(), e);
throw new MetaDataAcquireFailedException("Error! Can not get tables by context service ID and node name", 500);
}
return result;
}
use of com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method getAllDataSourceTypes.
@Override
public GeneralResponse<Map> getAllDataSourceTypes(String clusterName, String authUser) throws UnExpectedRequestException, MetaDataAcquireFailedException {
// Check existence of cluster name
ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
// send request to get dbs
String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceTypes()).toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token-User", authUser);
headers.add("Token-Code", clusterInfo.getLinkisToken());
HttpEntity<Object> entity = new HttpEntity<>(headers);
LOGGER.info("Start to get data source types by user and cluster by linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.GET, entity);
Map<String, Object> response = restTemplate.exchange(url, HttpMethod.GET, entity, Map.class).getBody();
LOGGER.info("Finish to get data source types by user and cluster by linkis. response: {}", response);
if (!checkResponse(response)) {
String message = (String) response.get("message");
LOGGER.error("Error! Can not get meta data from linkis, message: " + message);
throw new MetaDataAcquireFailedException("Error! Can not get meta data from linkis, exception: " + message);
}
Map data = (Map) response.get(LinkisResponseKeyEnum.DATA.getKey());
List<Map> types = (List<Map>) data.get("type_list");
return new GeneralResponse<>("200", "Success to get all datasource types", data);
}
use of com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method getDataSourceInfoDetail.
@Override
public GeneralResponse<Map> getDataSourceInfoDetail(String clusterName, String authUser, Long dataSourceId, Long versionId) throws UnExpectedRequestException, MetaDataAcquireFailedException {
// Check existence of cluster name
ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
// send request to get dbs
UriBuilder uriBuilder = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceInfo()).path(dataSourceId.toString());
if (versionId != null) {
uriBuilder.path(versionId.toString());
}
String url = uriBuilder.toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token-User", authUser);
headers.add("Token-Code", clusterInfo.getLinkisToken());
HttpEntity<Object> entity = new HttpEntity<>(headers);
LOGGER.info("Start to get data source info detail by user and cluster by linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.GET, entity);
Map<String, Object> response = restTemplate.exchange(url, HttpMethod.GET, entity, Map.class).getBody();
LOGGER.info("Finish to get data source info detail by user and cluster by linkis. response: {}", response);
if (!checkResponse(response)) {
String message = (String) response.get("message");
LOGGER.error("Error! Can not get meta data from linkis, message: " + message);
throw new MetaDataAcquireFailedException("Error! Can not get meta data from linkis, exception: " + message);
}
Map data = (Map) response.get(LinkisResponseKeyEnum.DATA.getKey());
Map types = (Map) data.get("info");
return new GeneralResponse<>("200", "Success to get datasource detail info", data);
}
use of com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method modifyDataSourceParam.
@Override
public GeneralResponse<Map> modifyDataSourceParam(String clusterName, String authUser, Long dataSourceId, String jsonRequest) throws UnExpectedRequestException, MetaDataAcquireFailedException {
// Check existence of cluster name
ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
// send request to get dbs
String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceInitVersion()).toString().replace("{DATA_SOURCE_ID}", dataSourceId.toString());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token-User", authUser);
headers.add("Token-Code", clusterInfo.getLinkisToken());
HttpEntity<Object> entity = new HttpEntity<>(jsonRequest, headers);
LOGGER.info("Start to modify data source param by user and cluster by linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.POST, entity);
Map<String, Object> response = restTemplate.exchange(url, HttpMethod.POST, entity, Map.class).getBody();
LOGGER.info("Finish to modify data source param by user and cluster by linkis. response: {}", response);
if (!checkResponse(response)) {
String message = (String) response.get("message");
LOGGER.error("Error! Can not get meta data from linkis, message: " + message);
throw new MetaDataAcquireFailedException("Error! Can not get meta data from linkis, exception: " + message);
}
Map data = (Map) response.get(LinkisResponseKeyEnum.DATA.getKey());
return new GeneralResponse<>("200", "Success to modify datasource connect params", data);
}
Aggregations