[dev] support instanceInfo's complex query

This commit is contained in:
tjq 2020-06-06 07:58:42 +08:00
parent 0e32fbeeef
commit f54ba4a078
7 changed files with 19 additions and 22 deletions

View File

@ -43,7 +43,7 @@ public class InstanceInfoDO {
/**
* 任务状态 {@link InstanceStatus}
*/
private int status;
private Integer status;
// 执行结果允许存储稍大的结果
@Lob
@Column(columnDefinition="TEXT")

View File

@ -2,8 +2,6 @@ package com.github.kfcfans.oms.server.persistence.core.repository;
import com.github.kfcfans.oms.server.persistence.core.model.InstanceInfoDO;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@ -62,12 +60,6 @@ public interface InstanceInfoRepository extends JpaRepository<InstanceInfoDO, Lo
InstanceInfoDO findByInstanceId(long instanceId);
// list 三兄弟
Page<InstanceInfoDO> findByAppIdAndType(long appId, int type, Pageable pageable);
Page<InstanceInfoDO> findByJobIdAndType(long jobId, int type, Pageable pageable);
// 只会有一条数据只是为了统一
Page<InstanceInfoDO> findByInstanceIdAndType(long instanceId, int type, Pageable pageable);
// 数据统计
long countByAppIdAndStatus(long appId, int status);
long countByAppIdAndStatusAndGmtCreateAfter(long appId, int status, Date time);

View File

@ -5,10 +5,10 @@ import com.github.kfcfans.oms.common.OmsException;
import com.github.kfcfans.oms.common.TimeExpressionType;
import com.github.kfcfans.oms.common.request.http.SaveWorkflowRequest;
import com.github.kfcfans.oms.common.response.WorkflowInfoDTO;
import com.github.kfcfans.oms.server.common.utils.WorkflowDAGUtils;
import com.github.kfcfans.oms.server.common.SJ;
import com.github.kfcfans.oms.server.common.constans.SwitchableStatus;
import com.github.kfcfans.oms.server.common.utils.CronExpression;
import com.github.kfcfans.oms.server.common.utils.WorkflowDAGUtils;
import com.github.kfcfans.oms.server.persistence.core.model.WorkflowInfoDO;
import com.github.kfcfans.oms.server.persistence.core.repository.WorkflowInfoRepository;
import org.springframework.beans.BeanUtils;
@ -58,7 +58,9 @@ public class WorkflowService {
wf.setStatus(req.isEnable() ? SwitchableStatus.ENABLE.getV() : SwitchableStatus.DISABLE.getV());
wf.setTimeExpressionType(req.getTimeExpressionType().getV());
wf.setNotifyUserIds(SJ.commaJoiner.join(req.getNotifyUserIds()));
if (req.getNotifyUserIds() != null) {
wf.setNotifyUserIds(SJ.commaJoiner.join(req.getNotifyUserIds()));
}
// 计算 NextTriggerTime
if (req.getTimeExpressionType() == TimeExpressionType.CRON) {

View File

@ -20,6 +20,7 @@ import com.github.kfcfans.oms.server.web.response.InstanceInfoVO;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
@ -110,18 +111,12 @@ public class InstanceController {
Sort sort = Sort.by(Sort.Direction.DESC, "gmtModified");
PageRequest pageable = PageRequest.of(request.getIndex(), request.getPageSize(), sort);
// 查询全部数据
if (request.getJobId() == null && request.getInstanceId() == null) {
return ResultDTO.success(convertPage(instanceInfoRepository.findByAppIdAndType(request.getAppId(), request.getType().getV(), pageable)));
}
InstanceInfoDO queryEntity = new InstanceInfoDO();
BeanUtils.copyProperties(request, queryEntity);
queryEntity.setType(request.getType().getV());
// 根据JobId查询
if (request.getJobId() != null) {
return ResultDTO.success(convertPage(instanceInfoRepository.findByJobIdAndType(request.getJobId(), request.getType().getV(), pageable)));
}
// 根据InstanceId查询
return ResultDTO.success(convertPage(instanceInfoRepository.findByInstanceIdAndType(request.getInstanceId(), request.getType().getV(), pageable)));
Page<InstanceInfoDO> pageResult = instanceInfoRepository.findAll(Example.of(queryEntity), pageable);
return ResultDTO.success(convertPage(pageResult));
}
private PageResult<InstanceInfoVO> convertPage(Page<InstanceInfoDO> page) {

View File

@ -44,6 +44,12 @@ public class WorkflowController {
return ResultDTO.success(null);
}
@GetMapping("/enable")
public ResultDTO<Void> enableWorkflow(Long workflowId, Long appId) {
workflowService.enableWorkflow(workflowId, appId);
return ResultDTO.success(null);
}
@GetMapping("/delete")
public ResultDTO<Void> deleteWorkflow(Long workflowId, Long appId) {
workflowService.deleteWorkflow(workflowId, appId);

View File

@ -23,4 +23,5 @@ public class QueryInstanceRequest {
private InstanceType type;
private Long instanceId;
private Long jobId;
private Long wfInstanceId;
}

View File

@ -153,6 +153,7 @@ public class OhMyWorker implements ApplicationContextAware, InitializingBean, Di
}catch (OmsException oe) {
throw oe;
}catch (Exception ignore) {
log.warn("[OhMyWorker] assert appName by url({}) failed, please check the server address.", realUrl);
}
}
log.error("[OhMyWorker] no available server in {}.", config.getServerAddress());