|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership.
|
|
|
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
* (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package org.apache.dolphinscheduler.api.service;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status;
|
|
|
|
import org.apache.dolphinscheduler.api.utils.Constants;
|
|
|
|
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
|
|
|
|
import org.apache.dolphinscheduler.common.utils.CollectionUtils;
|
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
|
|
|
import org.apache.dolphinscheduler.dao.ProcessDao;
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project;
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.User;
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.text.MessageFormat;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* task instance service
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
public class TaskInstanceService extends BaseService {
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(TaskInstanceService.class);
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
ProjectMapper projectMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
ProjectService projectService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
ProcessDao processDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
TaskInstanceMapper taskInstanceMapper;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* query task list by project, process instance, task name, task start time, task end time, task status, keyword paging
|
|
|
|
*
|
|
|
|
* @param loginUser
|
|
|
|
* @param projectName
|
|
|
|
* @param processInstanceId
|
|
|
|
* @param taskName
|
|
|
|
* @param startDate
|
|
|
|
* @param endDate
|
|
|
|
* @param searchVal
|
|
|
|
* @param stateType
|
|
|
|
* @param pageNo
|
|
|
|
* @param pageSize
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Map<String,Object> queryTaskListPaging(User loginUser, String projectName,
|
|
|
|
Integer processInstanceId, String taskName, String startDate, String endDate,
|
|
|
|
String searchVal, ExecutionStatus stateType,String host,
|
|
|
|
Integer pageNo, Integer pageSize) {
|
|
|
|
Map<String, Object> result = new HashMap<>(5);
|
|
|
|
Project project = projectMapper.queryByName(projectName);
|
|
|
|
|
|
|
|
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
|
|
|
|
Status status = (Status) checkResult.get(Constants.STATUS);
|
|
|
|
if (status != Status.SUCCESS) {
|
|
|
|
return checkResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
int[] statusArray = null;
|
|
|
|
if(stateType != null){
|
|
|
|
statusArray = new int[]{stateType.ordinal()};
|
|
|
|
}
|
|
|
|
|
|
|
|
Date start = null;
|
|
|
|
Date end = null;
|
|
|
|
try {
|
|
|
|
if(StringUtils.isNotEmpty(startDate)){
|
|
|
|
start = DateUtils.getScheduleDate(startDate);
|
|
|
|
}
|
|
|
|
if(StringUtils.isNotEmpty( endDate)){
|
|
|
|
end = DateUtils.getScheduleDate(endDate);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
result.put(Constants.STATUS, Status.REQUEST_PARAMS_NOT_VALID_ERROR);
|
|
|
|
result.put(Constants.MSG, MessageFormat.format(Status.REQUEST_PARAMS_NOT_VALID_ERROR.getMsg(), "startDate,endDate"));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Page<TaskInstance> page = new Page(pageNo, pageSize);
|
|
|
|
IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(
|
|
|
|
page, project.getId(), processInstanceId, searchVal, taskName, statusArray, host, start, end
|
|
|
|
);
|
|
|
|
PageInfo pageInfo = new PageInfo<ProcessInstance>(pageNo, pageSize);
|
|
|
|
Set<String> exclusionSet = new HashSet<String>(){{
|
|
|
|
add(Constants.CLASS);
|
|
|
|
add("taskJson");
|
|
|
|
}};
|
|
|
|
pageInfo.setTotalCount((int)taskInstanceIPage.getTotal());
|
|
|
|
pageInfo.setLists(CollectionUtils.getListByExclusion(taskInstanceIPage.getRecords(),exclusionSet));
|
|
|
|
result.put(Constants.DATA_LIST, pageInfo);
|
|
|
|
putMsg(result, Status.SUCCESS);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|