use of com.webank.wedatasphere.qualitis.entity.ClusterInfo in project Qualitis by WeBankFinTech.
the class OuterExecutionServiceImpl method getTaskLog.
@Override
public GeneralResponse<?> getTaskLog(GetTaskLogRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Check Arguments
GetTaskLogRequest.checkRequest(request);
Task task = taskDao.findByRemoteTaskIdAndClusterName(request.getTaskId(), request.getClusterId());
if (task == null) {
throw new UnExpectedRequestException("Task_id {&DOES_NOT_EXIST}");
}
ClusterInfo clusterInfo = clusterInfoDao.findByClusterName(request.getClusterId());
if (clusterInfo == null) {
throw new UnExpectedRequestException("cluster : [" + request.getClusterId() + "] {&DOES_NOT_EXIST}");
}
String executeUser = task.getApplication().getExecuteUser();
// Check if user has permissions proxying execution user
checkPermissionCreateUserProxyExecuteUser(request.getCreateUser(), executeUser);
// Check if user has permissions to view this task
if (!request.getCreateUser().equals(task.getApplication().getCreateUser())) {
throw new UnExpectedRequestException(String.format("User: %s {&HAS_NO_PERMISSION_TO_ACCESS} task: %s", request.getCreateUser(), request.getTaskId()), 403);
}
LogResult logResult;
try {
logResult = monitorManager.getTaskPartialLog(request.getTaskId(), 0, executeUser, clusterInfo.getLinkisAddress(), clusterInfo.getClusterName());
} catch (LogPartialException | ClusterInfoNotConfigException e) {
throw new UnExpectedRequestException(e.getMessage());
}
LOGGER.info("Succeed to get log of the task. task_id: {}, cluster_id: {}", request.getTaskId(), request.getClusterId());
return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_TASK_LOG}", logResult.getLog());
}
use of com.webank.wedatasphere.qualitis.entity.ClusterInfo in project Qualitis by WeBankFinTech.
the class ClusterInfoServiceImpl method addClusterInfo.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<ClusterInfo> addClusterInfo(AddClusterInfoRequest request) throws UnExpectedRequestException {
// 检查参数
checkRequest(request);
// 查看clusterName是否已存在
String clusterName = request.getClusterName();
String clusterType = request.getClusterType();
String linkisAddress = request.getLinkisAddress();
String linkisToken = request.getLinkisToken();
ClusterInfo clusterInfoInDb = clusterInfoDao.findByClusterName(clusterName);
if (clusterInfoInDb != null) {
throw new UnExpectedRequestException("cluster name {&ALREADY_EXIST}");
}
// 创建新ClusterInfo并保存
ClusterInfo newClusterInfo = new ClusterInfo();
newClusterInfo.setClusterName(clusterName);
newClusterInfo.setClusterType(clusterType);
newClusterInfo.setLinkisAddress(linkisAddress);
newClusterInfo.setLinkisToken(linkisToken);
ClusterInfo savedClusterInfo = clusterInfoDao.saveClusterInfo(newClusterInfo);
LOGGER.info("Succeed to add cluster_info, response: {}", savedClusterInfo);
return new GeneralResponse<>("200", "{&ADD_CLUSTER_INFO_SUCCESSFULLY}", savedClusterInfo);
}
use of com.webank.wedatasphere.qualitis.entity.ClusterInfo in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method getColumnInfo.
@Override
public List<ColumnInfoDetail> getColumnInfo(String clusterName, String dbName, String tableName, String userName) throws MetaDataAcquireFailedException, UnExpectedRequestException {
ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
// send request to get table comment.
String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getColumnInfo()).queryParam("database", dbName).queryParam("tableName", tableName).toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token-User", userName);
headers.add("Token-Code", clusterInfo.getLinkisToken());
HttpEntity<Object> entity = new HttpEntity<>(headers);
LOGGER.info("Start to get column info by user and cluster and db and table 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("Finished to get column info by user and cluster and db and table 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);
}
List<Map<String, Object>> tableFieldInfo = (List<Map<String, Object>>) ((Map<String, Object>) response.get("data")).get("tableFieldsInfo");
List<ColumnInfoDetail> result = new ArrayList<>();
for (Map<String, Object> map : tableFieldInfo) {
ColumnInfoDetail columnInfoDetail = new ColumnInfoDetail();
columnInfoDetail.setFieldName(map.get("name").toString());
columnInfoDetail.setDataType(map.get("type").toString());
if (map.get("length") != null && !"".equals(map.get("length").toString())) {
columnInfoDetail.setColumnLen(Integer.parseInt(map.get("length").toString()));
}
columnInfoDetail.setColumnAlias(map.get("alias") == null ? "" : map.get("alias").toString());
columnInfoDetail.setColumnComment(map.get("comment") == null ? "" : map.get("comment").toString());
columnInfoDetail.setPrimary((Boolean) map.get("primary"));
columnInfoDetail.setPartitionField((Boolean) map.get("partitionField"));
result.add(columnInfoDetail);
}
return result;
}
use of com.webank.wedatasphere.qualitis.entity.ClusterInfo in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method getDataSourceVersions.
@Override
public GeneralResponse<Map> getDataSourceVersions(String clusterName, String authUser, Long dataSourceId) throws UnExpectedRequestException, MetaDataAcquireFailedException {
// Check existence of cluster name
ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
// send request to get dbs
String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceVersions()).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<>(headers);
LOGGER.info("Start to get data source versions 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 versions 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("versions");
return new GeneralResponse<>("200", "Success to get datasource version", data);
}
use of com.webank.wedatasphere.qualitis.entity.ClusterInfo in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method getTablesByDataSource.
@Override
public Map getTablesByDataSource(String clusterName, String authUser, Long dataSourceId, String dbName) throws UnExpectedRequestException, MetaDataAcquireFailedException {
// Check existence of cluster name
ClusterInfo clusterInfo = checkClusterNameExists(clusterName);
// send request to get dbs
String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getDatasourceTable()).queryParam("system", "Qualitis").toString().replace("{DATA_SOURCE_ID}", dataSourceId.toString()).replace("{DATA_SOURCE_DB}", dbName);
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 tables by data source. 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 tables by data source. 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> tables = (List<Map>) data.get("tables");
if (CollectionUtils.isEmpty(tables)) {
LOGGER.info("No tables with data source to be choosed.");
}
return data;
}
Aggregations