Search in sources :

Example 1 with LogPartialException

use of com.webank.wedatasphere.qualitis.exception.LogPartialException in project Qualitis by WeBankFinTech.

the class LinkisJobSubmitter method getJobPartialLog.

@Override
public LogResult getJobPartialLog(Long taskId, Integer begin, String user, String remoteAddress, String clusterName) throws LogPartialException, ClusterInfoNotConfigException {
    Integer begin1 = 0;
    String jobStatus = null;
    String logPath = null;
    String execId = null;
    try {
        Map response = getTaskDetail(taskId, user, remoteAddress, clusterName);
        jobStatus = (String) ((Map) ((Map) response.get("data")).get("task")).get("status");
        logPath = (String) ((Map) ((Map) response.get("data")).get("task")).get("logPath");
        execId = (String) ((Map) ((Map) response.get("data")).get("task")).get("strongerExecId");
    } catch (TaskNotExistException e) {
        throw new LogPartialException(e);
    }
    String log = "";
    if (isTaskRunning(jobStatus)) {
        String url = getPath(remoteAddress).path(linkisConfig.getRunningLog()).toString();
        url = url.replace("{id}", execId);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add("Token-User", user);
        headers.add("Token-Code", getToken(clusterName));
        HttpEntity entity = new HttpEntity<>(headers);
        LOGGER.info("Start to get job log from linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.GET, entity);
        Map response = restTemplate.exchange(url, HttpMethod.GET, entity, Map.class).getBody();
        LOGGER.info("Succeed to get job log from linkis. repsonse: {}", response);
        if (!checkResponse(response)) {
            throw new LogPartialException("Failed to get partial logs, task ID: " + taskId);
        }
        log = (String) ((List) ((Map) response.get("data")).get("log")).get(3);
    } else {
        String url = getPath(remoteAddress).path(linkisConfig.getFinishLog()).toString() + "?path=" + logPath;
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add("Token-User", user);
        headers.add("Token-Code", getToken(clusterName));
        HttpEntity entity = new HttpEntity<>(headers);
        LOGGER.info("Start to get job log from linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.GET, entity);
        Map response = restTemplate.exchange(url, HttpMethod.GET, entity, Map.class).getBody();
        LOGGER.info("Succeed to get job log from linkis. repsonse: {}", response);
        if (!checkResponse(response)) {
            throw new LogPartialException("Failed to get partial logs, task ID: " + taskId);
        }
        log = (String) ((List) ((Map) response.get("data")).get("log")).get(3);
    }
    // 将账号敏感信息脱敏替换成 ******
    log = maskAccountInfo(log);
    Integer end = getEnd(log) + begin1;
    return new LogResult(log, begin1, end, getLast(log));
}
Also used : TaskNotExistException(com.webank.wedatasphere.qualitis.exception.TaskNotExistException) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) LogResult(com.webank.wedatasphere.qualitis.bean.LogResult) LogPartialException(com.webank.wedatasphere.qualitis.exception.LogPartialException) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with LogPartialException

use of com.webank.wedatasphere.qualitis.exception.LogPartialException 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());
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Task(com.webank.wedatasphere.qualitis.entity.Task) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) LogResult(com.webank.wedatasphere.qualitis.bean.LogResult) LogPartialException(com.webank.wedatasphere.qualitis.exception.LogPartialException) ClusterInfoNotConfigException(com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)

Example 3 with LogPartialException

use of com.webank.wedatasphere.qualitis.exception.LogPartialException in project Qualitis by WeBankFinTech.

the class JobServiceImpl method getTaskLog.

@Override
public GeneralResponse<?> getTaskLog(Long taskId, String clusterName) throws UnExpectedRequestException {
    Task task = taskDao.findById(taskId);
    if (task == null) {
        throw new UnExpectedRequestException("{&JOB_ID_DOES_NOT_EXIST}");
    }
    ClusterInfo clusterInfo = clusterInfoDao.findByClusterName(clusterName);
    if (clusterInfo == null) {
        throw new UnExpectedRequestException("Cluster info {&DOES_NOT_EXIST}");
    }
    LogResult logResult;
    String proxyUser = task.getTaskProxyUser();
    try {
        logResult = monitorManager.getTaskPartialLog(task.getTaskRemoteId(), 0, StringUtils.isNotBlank(proxyUser) ? proxyUser : task.getApplication().getExecuteUser(), clusterInfo.getLinkisAddress(), clusterName);
    } catch (LogPartialException | ClusterInfoNotConfigException e) {
        throw new UnExpectedRequestException(e.getMessage());
    }
    LOGGER.info("Succeed to get task log, task_id: {}, cluster_id: {}", taskId, clusterName);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_TASK_LOG}", logResult.getLog());
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Task(com.webank.wedatasphere.qualitis.entity.Task) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) LogResult(com.webank.wedatasphere.qualitis.bean.LogResult) LogPartialException(com.webank.wedatasphere.qualitis.exception.LogPartialException) ClusterInfoNotConfigException(com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)

Aggregations

LogResult (com.webank.wedatasphere.qualitis.bean.LogResult)3 LogPartialException (com.webank.wedatasphere.qualitis.exception.LogPartialException)3 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)2 Task (com.webank.wedatasphere.qualitis.entity.Task)2 ClusterInfoNotConfigException (com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)2 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)2 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 TaskNotExistException (com.webank.wedatasphere.qualitis.exception.TaskNotExistException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1