use of com.dtstack.taier.dao.domain.BatchTaskResource in project Taier by DTStack.
the class BatchTaskResourceService method save.
public List<BatchTaskResource> save(BatchTask batchTask, List<Long> resourceIds, Integer refType) {
List<BatchTaskResource> taskResources = new ArrayList<>(resourceIds.size());
for (Long resourceId : resourceIds) {
// 检查资源是否存在
if (batchResourceService.getResource(resourceId) == null) {
logger.warn("can't find resource from BatchResource table by id:{}", resourceId);
throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_RESOURCE);
}
// 存储
BatchTaskResource resource = developTaskResourceDao.getByTaskIdAndResourceId(batchTask.getId(), resourceId, refType);
if (resource == null) {
resource = new BatchTaskResource();
}
resource.setTaskId(batchTask.getId());
resource.setTenantId(batchTask.getTenantId());
resource.setGmtCreate(Timestamp.valueOf(LocalDateTime.now()));
resource.setGmtModified(Timestamp.valueOf(LocalDateTime.now()));
resource.setResourceId(resourceId);
resource.setResourceType(refType);
taskResources.add(addOrUpdate(resource));
}
return taskResources;
}
use of com.dtstack.taier.dao.domain.BatchTaskResource in project Taier by DTStack.
the class BatchTaskResourceShadeService method saveTaskResource.
public void saveTaskResource(List<BatchTaskResource> taskResourceList) {
for (BatchTaskResource resource : taskResourceList) {
BatchTaskResourceShade shade = new BatchTaskResourceShade();
BeanUtils.copyProperties(resource, shade);
// 把taskResourceShade的id置为null 防止误更新
shade.setId(null);
addOrUpdate(shade);
}
}
use of com.dtstack.taier.dao.domain.BatchTaskResource in project Taier by DTStack.
the class BatchTaskService method buildScheduleTaskShadeDTO.
/**
* 构建一个要发布到engine的任务DTO {@link ScheduleTaskShadeDTO}
* @param batchTask 要发布的任务集合
* @param parentTaskIds 父任务的id
* @return 调度任务DTO
*/
private ScheduleTaskShadeDTO buildScheduleTaskShadeDTO(final BatchTask batchTask, List<Long> parentTaskIds) {
if (batchTask.getId() <= 0) {
// 只有异常情况才会走到该逻辑
throw new RdosDefineException("batchTask id can't be 0", ErrorCode.SERVER_EXCEPTION);
}
final long taskId = batchTask.getId();
// 清空任务关联的batch_task_param, task_resource, task_task 表信息
this.batchTaskParamShadeService.clearDataByTaskId(taskId);
this.batchTaskResourceShadeService.clearDataByTaskId(taskId);
final List<BatchTaskParam> batchTaskParamList = this.batchTaskParamService.getTaskParam(batchTask.getId());
// 查询出任务所有的关联的资源(运行主体资源和依赖引用资源)
final List<BatchTaskResource> batchTaskResourceList = this.batchTaskResourceService.getTaskResources(batchTask.getId(), null);
List<Long> parentTaskList = this.batchTaskTaskService.getAllParentTaskId(batchTask.getId());
parentTaskIds.addAll(parentTaskList);
if (!CollectionUtils.isEmpty(batchTaskResourceList)) {
this.batchTaskResourceShadeService.saveTaskResource(batchTaskResourceList);
}
// 保存batch_task_shade
final ScheduleTaskShadeDTO scheduleTaskShadeDTO = new ScheduleTaskShadeDTO();
BeanUtils.copyProperties(batchTask, scheduleTaskShadeDTO);
scheduleTaskShadeDTO.setTaskId(batchTask.getId());
scheduleTaskShadeDTO.setScheduleStatus(EScheduleStatus.NORMAL.getVal());
if (!CollectionUtils.isEmpty(batchTaskParamList)) {
this.batchTaskParamShadeService.saveTaskParam(batchTaskParamList);
} else {
scheduleTaskShadeDTO.setTaskParams("");
}
return scheduleTaskShadeDTO;
}
use of com.dtstack.taier.dao.domain.BatchTaskResource in project Taier by DTStack.
the class BatchResourceService method deleteResource.
/**
* 删除资源
*/
public Long deleteResource(Long tenantId, Long resourceId) {
List<BatchTaskResource> taskResources = this.batchTaskResourceService.getUseableResources(resourceId);
if (!CollectionUtils.isEmpty(taskResources)) {
throw new RdosDefineException(ErrorCode.CAN_NOT_DELETE_RESOURCE);
}
List<BatchFunctionResource> functionResources = batchFunctionResourceService.listByResourceId(resourceId);
if (!CollectionUtils.isEmpty(functionResources)) {
throw new RdosDefineException(ErrorCode.CAN_NOT_DELETE_RESOURCE);
}
// 删除资源在hdfs的实际存储文件
BatchResource resource = getResource(resourceId);
try {
HdfsOperator.checkAndDele(HadoopConf.getConfiguration(tenantId), HadoopConf.getHadoopKerberosConf(tenantId), resource.getUrl());
} catch (Exception e) {
LOGGER.error("tenantId:{} resourceId:{} fail delete resource from HDFS", tenantId, resourceId, e);
}
// 删除资源记录
developResourceDao.deleteById(resourceId);
return resourceId;
}
Aggregations