use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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);
}
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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.response.GeneralResponse 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));
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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.response.GeneralResponse 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);
}
Aggregations