Search in sources :

Example 36 with UnExpectedRequestException

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

the class OuterExecutionServiceImpl method killApplication.

@Override
public GeneralResponse<?> killApplication(String applicationId, String executionUser) throws JobKillException, UnExpectedRequestException, ClusterInfoNotConfigException, PermissionDeniedRequestException {
    LOGGER.info("Qualitis appjoint user: {}", executionUser);
    Application applicationInDb = applicationDao.findById(applicationId);
    if (applicationInDb == null) {
        throw new UnExpectedRequestException(String.format("Application ID: %s {&DOES_NOT_EXIST}", applicationId));
    }
    Integer status = applicationInDb.getStatus();
    if (status.equals(ApplicationStatusEnum.SUBMITTED.getCode()) || status.equals(ApplicationStatusEnum.RUNNING.getCode()) || status.equals(ApplicationStatusEnum.SUCCESSFUL_CREATE_APPLICATION.getCode())) {
        String realExecutionUser = applicationInDb.getExecuteUser();
        checkPermissionCreateUserProxyExecuteUser(executionUser, realExecutionUser);
        return executionManager.killApplication(applicationInDb, realExecutionUser);
    } else {
        return new GeneralResponse<>("400", "{&APPLICATION_IS_FINISHED}", null);
    }
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Application(com.webank.wedatasphere.qualitis.entity.Application)

Example 37 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException 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 38 with UnExpectedRequestException

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

the class OuterExecutionServiceImpl method getApplicationResult.

@Override
public GeneralResponse<?> getApplicationResult(String applicationId) throws UnExpectedRequestException {
    // Find application by applicationId
    Application applicationInDb = applicationDao.findById(applicationId);
    if (applicationInDb == null) {
        throw new UnExpectedRequestException(String.format("ApplicationId: %s {&DOES_NOT_EXIST}", applicationId));
    }
    Integer passNum = 0;
    Integer failedNum = 0;
    Integer notPassNum = 0;
    StringBuilder passMessage = new StringBuilder();
    StringBuilder failedMessage = new StringBuilder();
    StringBuilder notPassMessage = new StringBuilder();
    passMessage.append("The rules following below are pass(以下规则已通过校验): [");
    failedMessage.append("The rules following below are failed(以下规则已失败): [");
    notPassMessage.append("The rules following below are failed(以下规则未通过校验): [");
    // Find all tasks by application
    List<Task> tasks = taskDao.findByApplication(applicationInDb);
    // Find task rule simple in all tasks
    for (Task task : tasks) {
        // Add failed num, pass num if task status equals to Succeed, Failed
        if (task.getStatus().equals(TaskStatusEnum.FAILED.getCode())) {
            failedNum += task.getTaskRuleSimples().size();
            generateFailedMessage(task, failedMessage);
        } else if (task.getStatus().equals(TaskStatusEnum.PASS_CHECKOUT.getCode())) {
            passNum += task.getTaskRuleSimples().size();
            generatePassMessage(task, passMessage);
        } else if (task.getStatus().equals(TaskStatusEnum.FAIL_CHECKOUT.getCode())) {
            // Find not pass task if task status equals to failed_checkout
            for (TaskRuleSimple taskRuleSimple : task.getTaskRuleSimples()) {
                Boolean isPass = true;
                for (TaskRuleAlarmConfig taskRuleAlarmConfig : taskRuleSimple.getTaskRuleAlarmConfigList()) {
                    if (taskRuleAlarmConfig.getStatus().equals(AlarmConfigStatusEnum.NOT_PASS.getCode())) {
                        isPass = false;
                        break;
                    }
                }
                if (isPass) {
                    passNum++;
                    passMessage.append(taskRuleSimple.getRuleName()).append(", ");
                } else {
                    notPassNum++;
                    notPassMessage.append(taskRuleSimple.getRuleName()).append(", ");
                }
            }
        } else {
            throw new UnExpectedRequestException(String.format("ApplicationId: %s {&DOES_NOT_FINISHED_YET}", applicationId));
        }
    }
    passMessage.append("]").append(System.lineSeparator());
    failedMessage.append("]").append(System.lineSeparator());
    notPassMessage.append("]").append(System.lineSeparator());
    String resultMessage = passMessage.toString() + failedMessage.toString() + notPassMessage.toString();
    return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATION_RESULT}", new ApplicationResultResponse(passNum, failedNum, notPassNum, resultMessage));
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Task(com.webank.wedatasphere.qualitis.entity.Task) ApplicationResultResponse(com.webank.wedatasphere.qualitis.response.ApplicationResultResponse) TaskRuleAlarmConfig(com.webank.wedatasphere.qualitis.entity.TaskRuleAlarmConfig) Application(com.webank.wedatasphere.qualitis.entity.Application) TaskRuleSimple(com.webank.wedatasphere.qualitis.entity.TaskRuleSimple)

Example 39 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException 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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ClusterInfo(com.webank.wedatasphere.qualitis.entity.ClusterInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with UnExpectedRequestException

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

the class SystemConfigServiceImpl method findByKeyName.

@Override
public GeneralResponse<?> findByKeyName(String keyName) throws UnExpectedRequestException {
    SystemConfig systemConfigInDb = systemConfigDao.findByKeyName(keyName);
    if (null == systemConfigInDb) {
        throw new UnExpectedRequestException("key name {&DOES_NOT_EXIST}");
    }
    LOGGER.info("{&SUCCEED_TO_FIND_SYSTEM_CONFIG}. key:{}, value: {}", systemConfigInDb.getKeyName(), systemConfigInDb.getValue());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_FIND_SYSTEM_CONFIG}", systemConfigInDb);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) SystemConfig(com.webank.wedatasphere.qualitis.entity.SystemConfig)

Aggregations

UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)150 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)97 ArrayList (java.util.ArrayList)56 Transactional (org.springframework.transaction.annotation.Transactional)54 Project (com.webank.wedatasphere.qualitis.project.entity.Project)33 User (com.webank.wedatasphere.qualitis.entity.User)32 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)32 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)25 Map (java.util.Map)24 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)22 List (java.util.List)22 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)19 IOException (java.io.IOException)19 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)17 Date (java.util.Date)17 HashMap (java.util.HashMap)17 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)15 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)15 Collectors (java.util.stream.Collectors)15 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)14