use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchTaskService method trace.
public JSONObject trace(final Long taskId) {
String sqlText = null;
final BatchTask batchTask = this.getBatchTaskById(taskId);
if (batchTask == null) {
throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_TASK);
} else {
sqlText = batchTask.getSqlText();
}
final String sql = Base64Util.baseDecode(sqlText);
if (StringUtils.isBlank(sql)) {
return null;
}
final JSONObject sqlJson = JSON.parseObject(sql);
JSONObject parserJson = sqlJson.getJSONObject("parser");
if (parserJson != null) {
parserJson = this.checkTrace(parserJson);
parserJson.put("sqlText", sqlJson.getString("job"));
parserJson.put("syncMode", sqlJson.get("syncMode"));
parserJson.put("taskId", taskId);
}
return parserJson;
}
use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchCatalogueService method getChildNode.
/**
* 获得当前节点的子节点信息,包括子孙文件夹和子孙文件
*
* @param tenantId 租户id
* @param isGetFile
* @param userId
* @return
* @author jiangbo、toutian
*/
private CatalogueVO getChildNode(CatalogueVO currentCatalogueVO, Boolean isGetFile, Long userId, Long tenantId) {
BatchCatalogue currentCatalogue = developCatalogueDao.getOne(currentCatalogueVO.getId());
if (currentCatalogue == null) {
throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_CATALOGUE);
}
currentCatalogueVO.setTenantId(currentCatalogue.getTenantId());
currentCatalogueVO.setName(currentCatalogue.getNodeName());
currentCatalogueVO.setLevel(currentCatalogue.getLevel());
currentCatalogueVO.setParentId(currentCatalogue.getNodePid());
currentCatalogueVO.setType(FILE_TYPE_FOLDER);
// 获取目录下的资源或任务列表
if (isGetFile) {
// 目录下的文件信息
List<CatalogueVO> catalogueChildFileList = Lists.newArrayList();
// 用户id 和 名称映射
Map<Long, String> userIdAndNameMap = Maps.newHashMap();
// 任务目录
if (CatalogueType.TASK_DEVELOP.getType().equals(currentCatalogueVO.getCatalogueType())) {
List<BatchTask> taskList = batchTaskService.catalogueListBatchTaskByNodePid(tenantId, currentCatalogueVO.getId());
taskList.sort(Comparator.comparing(BatchTask::getName));
if (CollectionUtils.isNotEmpty(taskList)) {
List<Long> taskIds = taskList.stream().map(BatchTask::getId).collect(Collectors.toList());
Map<Long, ReadWriteLockVO> readWriteLockIdAndVOMap = getReadWriteLockVOMap(tenantId, taskIds, userId, userIdAndNameMap);
// 遍历目录下的所有任务
for (BatchTask task : taskList) {
CatalogueVO childCatalogueTask = new CatalogueVO();
BeanUtils.copyProperties(task, childCatalogueTask);
childCatalogueTask.setType("file");
childCatalogueTask.setLevel(currentCatalogueVO.getLevel() + 1);
childCatalogueTask.setParentId(currentCatalogueVO.getId());
childCatalogueTask.setCreateUser(getUserNameInMemory(userIdAndNameMap, task.getCreateUserId()));
// 设置任务的读写锁信息
ReadWriteLockVO readWriteLockVO = readWriteLockIdAndVOMap.get(task.getId());
if (readWriteLockVO.getLastKeepLockUserName() == null) {
readWriteLockVO.setLastKeepLockUserName(getUserNameInMemory(userIdAndNameMap, task.getModifyUserId()));
readWriteLockVO.setGmtModified(task.getGmtModified());
}
childCatalogueTask.setReadWriteLockVO(readWriteLockVO);
catalogueChildFileList.add(childCatalogueTask);
}
}
} else if (FUNCTION_CATALOGUE_TYPE.contains(currentCatalogueVO.getCatalogueType())) {
// 处理函数目录
List<BatchFunction> functionList = batchFunctionService.listByNodePidAndTenantId(currentCatalogueVO.getTenantId(), currentCatalogueVO.getId());
if (CollectionUtils.isNotEmpty(functionList)) {
functionList.sort(Comparator.comparing(BatchFunction::getName));
for (BatchFunction function : functionList) {
CatalogueVO child = new CatalogueVO();
BeanUtils.copyProperties(function, child);
child.setLevel(currentCatalogueVO.getLevel() + 1);
child.setType("file");
child.setCreateUser(getUserNameInMemory(userIdAndNameMap, function.getCreateUserId()));
child.setParentId(function.getNodePid());
catalogueChildFileList.add(child);
}
}
} else if (CatalogueType.RESOURCE_MANAGER.getType().equals(currentCatalogueVO.getCatalogueType())) {
// 处理资源目录
List<BatchResource> resourceList = batchResourceService.listByPidAndTenantId(tenantId, currentCatalogueVO.getId());
resourceList.sort(Comparator.comparing(BatchResource::getResourceName));
if (CollectionUtils.isNotEmpty(resourceList)) {
for (BatchResource resource : resourceList) {
CatalogueVO childResource = new CatalogueVO();
BeanUtils.copyProperties(resource, childResource);
childResource.setName(resource.getResourceName());
childResource.setType("file");
childResource.setLevel(currentCatalogueVO.getLevel() + 1);
childResource.setParentId(currentCatalogueVO.getId());
childResource.setCreateUser(getUserNameInMemory(userIdAndNameMap, resource.getCreateUserId()));
catalogueChildFileList.add(childResource);
}
}
}
currentCatalogueVO.setChildren(catalogueChildFileList);
}
// 获取目录下的子目录
List<BatchCatalogue> childCatalogues = this.getChildCataloguesByType(currentCatalogueVO.getId(), currentCatalogueVO.getCatalogueType(), currentCatalogue.getTenantId());
childCatalogues = keepInitCatalogueBeTop(childCatalogues, currentCatalogue);
List<CatalogueVO> children = new ArrayList<>();
for (BatchCatalogue catalogue : childCatalogues) {
CatalogueVO cv = CatalogueVO.toVO(catalogue);
cv.setType(FILE_TYPE_FOLDER);
this.changeSQLFunctionCatalogueType(catalogue, cv, currentCatalogueVO);
children.add(cv);
}
if (currentCatalogueVO.getChildren() == null) {
currentCatalogueVO.setChildren(children);
} else {
currentCatalogueVO.getChildren().addAll(0, children);
}
return currentCatalogueVO;
}
use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchTaskService method updateTaskResource.
/**
* 更新任务主资源
*
* @param taskResourceMap
* @return
*/
@Transactional
public void updateTaskResource(final Map<String, Object> taskResourceMap) {
Preconditions.checkState(taskResourceMap.containsKey("id"), "need param of id");
Preconditions.checkState(taskResourceMap.containsKey("resources"), "need param of resources");
Preconditions.checkState(taskResourceMap.containsKey("tenantId"), "need param of tenantId");
Preconditions.checkState(taskResourceMap.containsKey("createUserId"), "need param of createUserId");
final Long id = MathUtil.getLongVal(taskResourceMap.get("id"));
final List<Object> oriResourceList = (List<Object>) taskResourceMap.get("resources");
final BatchTask task = this.developTaskDao.getOne(id);
Preconditions.checkNotNull(task, "can not find task by id " + id);
// 删除旧的资源
batchTaskResourceService.deleteByTaskId(task.getId(), ResourceRefType.MAIN_RES.getType());
// 添加新的资源
if (CollectionUtils.isNotEmpty(oriResourceList)) {
List<Long> resourceIdList = Lists.newArrayList();
oriResourceList.forEach(tmpId -> resourceIdList.add(MathUtil.getLongVal(tmpId)));
batchTaskResourceService.save(task, resourceIdList, ResourceRefType.MAIN_RES.getType());
}
}
use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchTaskService method initTaskInfo.
/**
*初始化 task的一些基本属性
*
* @param task
* @return
*/
private boolean initTaskInfo(BatchTaskBatchVO task) {
if (StringUtils.isBlank(task.getTaskDesc())) {
task.setTaskDesc("");
}
if (StringUtils.isBlank(task.getTaskParams())) {
task.setTaskParams("");
}
if (StringUtils.isBlank(task.getMainClass())) {
task.setMainClass("");
}
if (StringUtils.isBlank(task.getScheduleConf())) {
task.setScheduleConf(DEFAULT_SCHEDULE_CONF);
} else {
final JSONObject scheduleConf = JSON.parseObject(task.getScheduleConf());
final String beginDate = scheduleConf.getString("beginDate");
if (StringUtils.isBlank(beginDate) || "null".equalsIgnoreCase(beginDate)) {
throw new RdosDefineException("生效日期起至时间不能为空");
}
final String endDate = scheduleConf.getString("endDate");
if (StringUtils.isBlank(endDate) || "null".equalsIgnoreCase(endDate)) {
throw new RdosDefineException("生效日期结束时间不能为空");
}
}
if (task.getVersion() == null) {
task.setVersion(0);
}
if (task.getCreateUserId() == null) {
task.setCreateUserId(task.getUserId());
}
task.setGmtCreate(task.getGmtModified());
// 增加注释
task.setSqlText(this.createAnnotationText(task));
task.setSubmitStatus(ESubmitStatus.UNSUBMIT.getStatus());
task.setTaskParams(getDefaultTaskParam(task.getTenantId(), task.getTaskType()));
task.setScheduleStatus(EScheduleStatus.NORMAL.getVal());
task.setPeriodType(DEFAULT_SCHEDULE_PERIOD);
String scConf = DEFAULT_SCHEDULE_CONF;
int period = DEFAULT_SCHEDULE_PERIOD;
if (task.getFlowId() != null && task.getFlowId() > 0) {
final BatchTask flow = this.developTaskDao.getOne(task.getFlowId());
if (flow != null) {
scConf = flow.getScheduleConf();
final ScheduleCron scheduleCron;
try {
scheduleCron = ScheduleFactory.parseFromJson(scConf);
} catch (Exception e) {
throw new RdosDefineException(e.getMessage(), e);
}
period = scheduleCron.getPeriodType();
}
task.setScheduleConf(scConf);
}
task.setPeriodType(period);
if (Objects.isNull(task.getFlowId())) {
task.setFlowId(0L);
}
return true;
}
use of com.dtstack.taier.dao.domain.BatchTask in project Taier by DTStack.
the class BatchTaskService method checkFillPassword.
/**
* 密码回填检查方法
*/
private void checkFillPassword(final TaskResourceParam param) {
// 单独对同步任务中密码进行补全处理 将未变更的 ****** 填充为原密码信息 --2019/10/25 茂茂--
if (param.getId() > 0 && EScheduleJobType.SYNC.getVal().equals(param.getTaskType())) {
final String context = param.getSqlText();
if (null == context) {
return;
}
// 1、检查上送字段是否存在需要处理的密码,不存在直接跳过
final Pattern pattern = Pattern.compile(PatternConstant.PASSWORD_FIELD_REGEX, Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(context);
if (matcher.find()) {
LOGGER.info("当前上送信息存在隐藏密码字段,准备执行旧密码回填操作");
// 2、查询旧数据信息,保存成结构数据,待数据解析补充
final BatchTask task = this.developTaskDao.getOne(param.getId());
if (Objects.nonNull(task)) {
final String sqlText = task.getSqlText();
if (StringUtils.isNotEmpty(sqlText)) {
final JSONObject oldData = JSON.parseObject(Base64Util.baseDecode(sqlText));
// 3、处理新上送的数据,替换未变更的密码信息
final JSONObject newData = JSON.parseObject(context);
// 值并行处理 -- 固定接口直接写死job的值处理密码问题
this.fillPassword(newData, oldData.getJSONObject("job"));
param.setSqlText(newData.toJSONString());
}
}
}
}
}
Aggregations