Commit d804ae96 authored by mcb's avatar mcb

commit 数据运维

parent 4726f8d6
package com.jz.common.enums;
/**
* 业务流程实例状态
*
* @author Bellamy
* @since 2020-11-30 14:30:23
*/
public enum FlowInstanceEnum {
/**
* 运行
*/
running("running", "30"),
/**
* 成功
*/
success("success", "50"),
kill("kill", "60"),
failed("failed", "70"),
;
private String code;
private String value;
private FlowInstanceEnum(String code, String value) {
this.code = code;
this.value = value;
}
public static FlowInstanceEnum get(String code) {
if (code == null) {
return null;
}
for (FlowInstanceEnum status : values()) {
if (status.getCode().equalsIgnoreCase(code)) {
return status;
}
}
return null;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
...@@ -7,6 +7,8 @@ import java.util.HashMap; ...@@ -7,6 +7,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.jz.dmp.modules.controller.dataOperation.bean.SetSlaReq;
import com.jz.dmp.modules.controller.dataOperation.bean.SetSlaRulesReq;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
...@@ -725,5 +727,54 @@ public class AzkabanApiUtils2 { ...@@ -725,5 +727,54 @@ public class AzkabanApiUtils2 {
return list; return list;
} }
/**
* Set SLA
* @author Bellamy
* @return 调用成功后,返回execid
*/
@SuppressWarnings("unchecked")
public String saveSla(SetSlaReq req) {
String sessionId = login();
String executeFlowUrl = azkabanServerUrl + "/schedule?token=" + sessionId;
LinkedMultiValueMap<String, Object> linkedMultiValueMap = new LinkedMultiValueMap<String, Object>();
linkedMultiValueMap.add("session.id", sessionId);
linkedMultiValueMap.add("ajax", "setSla");
linkedMultiValueMap.add("scheduleId", req.getScheduleId());
linkedMultiValueMap.add("slaEmails",req.getSlaEmails());
List<SetSlaRulesReq> slaRule = req.getSlaRule();
for (int i = 0; i < slaRule.size(); i++) {
SetSlaRulesReq sla = slaRule.get(i);
linkedMultiValueMap.add("settings[" + i +"]", sla.getFlow() +"," + sla.getSlaRule() +"," + sla.getDuration()+"," +sla.getEmailNotification()+"," +sla.getKill());
}
Map<String, Object> postForObject = null;
try {
postForObject = bulidRestTemplate().postForObject(executeFlowUrl, linkedMultiValueMap, Map.class);
} catch (Exception e) {
LOGGER.error(executeFlowUrl + "----" + linkedMultiValueMap + "----设置SLA接口异常");
e.printStackTrace();
throw new RuntimeException("设置SLA接口异常");
}
if (postForObject.containsKey("error")){
throw new RuntimeException(postForObject.get("error").toString());
}
String status = (String) postForObject.get("status");
if ("error".equals(status)) {
String message = (String) postForObject.get("message");
throw new RuntimeException(message);
}
/*Integer[] execIds = new Integer[] {};
if (postForObject.get("execIds")!=null) {
execIds = (Integer[])postForObject.get("execIds");
}
LOGGER.info("获取所有任务("+projectName+")正在调度execids"+execIds.toString());*/
return null;
}
} }
...@@ -40,5 +40,5 @@ public interface ExecutionFlowsMapper { ...@@ -40,5 +40,5 @@ public interface ExecutionFlowsMapper {
Map<String, Object> queryTaskInstanceStatus() throws Exception; Map<String, Object> queryTaskInstanceStatus() throws Exception;
List<Map> queryLastStatus(@Param("taskName") String[] taskName) throws Exception; List<Map> queryLastStatus(@Param("taskName") String[] taskName, @Param("status") String status) throws Exception;
} }
...@@ -3,10 +3,7 @@ package com.jz.dmp.modules.controller.dataOperation; ...@@ -3,10 +3,7 @@ package com.jz.dmp.modules.controller.dataOperation;
import com.jz.common.constant.JsonResult; import com.jz.common.constant.JsonResult;
import com.jz.common.constant.ResultCode; import com.jz.common.constant.ResultCode;
import com.jz.common.page.PageInfoResponse; import com.jz.common.page.PageInfoResponse;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevExamplesListDto; import com.jz.dmp.modules.controller.dataOperation.bean.*;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevExamplesListReq;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevTaskListDto;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevTaskListReq;
import com.jz.dmp.modules.service.DmpDevelopTaskService; import com.jz.dmp.modules.service.DmpDevelopTaskService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
...@@ -83,4 +80,25 @@ public class DmpDevExamplesController { ...@@ -83,4 +80,25 @@ public class DmpDevExamplesController {
return result; return result;
} }
/**
* 设置SLA
*
* @return
* @author Bellamy
* @since 2021-02-03
*/
@ApiOperation(value = "设置SLA", notes = "设置SLA")
@PostMapping(value = "/setSla")
public JsonResult setSla(@RequestBody SetSlaReq req) {
JsonResult result = new JsonResult();
try {
result = dmpDevelopTaskService.setSla(req);
} catch (Exception e) {
result.setCode(ResultCode.INTERNAL_SERVER_ERROR);
result.setMessage("failed!");
e.printStackTrace();
}
return result;
}
} }
...@@ -84,7 +84,7 @@ public class DmpDevTaskController { ...@@ -84,7 +84,7 @@ public class DmpDevTaskController {
* @since 2021-02-22 * @since 2021-02-22
*/ */
@ApiOperation(value = "运维大屏--重点关注任务状态", notes = "重点关注") @ApiOperation(value = "运维大屏--重点关注任务状态", notes = "重点关注")
@PostMapping(value = "/getTaskStatus") @GetMapping(value = "/getTaskStatus")
public JsonResult getTaskStatus(@RequestParam String projectId) throws Exception { public JsonResult getTaskStatus(@RequestParam String projectId) throws Exception {
if (StringUtils.isEmpty(projectId)) { if (StringUtils.isEmpty(projectId)) {
return new JsonResult(ResultCode.PARAMS_ERROR, "projectId不能为空!"); return new JsonResult(ResultCode.PARAMS_ERROR, "projectId不能为空!");
......
package com.jz.dmp.modules.controller.dataOperation.bean;
import com.jz.common.page.BasePageBean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* @ClassName: SetSlaReq
* @Description: set sla请求参数
* @Author:Bellamy
* @Date 2021/01/13
* @Version 1.0
*/
@Data
@ApiModel(value = "set sla请求参数", description = "et sla请求参数")
public class SetSlaReq implements Serializable {
private static final long serialVersionUID = 4274039208139198292L;
@ApiModelProperty(value = "scheduleId")
private String scheduleId;
@ApiModelProperty(value = "邮件")
private String slaEmails;
@ApiModelProperty(value = "sla规则")
private List<SetSlaRulesReq> slaRule;
@ApiModelProperty(value = "projectId")
@NotEmpty(message = "projectId不能为空!")
@NotNull(message = "projectId不能为空!")
private String projectId;
}
package com.jz.dmp.modules.controller.dataOperation.bean;
import com.jz.common.page.BasePageBean;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* @ClassName: SetSlaRulesReq
* @Description: 数据运维-SLA请求参数
* @Author:Bellamy
* @Date 2021/01/13
* @Version 1.0
*/
@Data
@ApiModel(value = "SLA请求参数", description = "SLA请求参数")
public class SetSlaRulesReq implements Serializable {
private static final long serialVersionUID = 7548870996371216281L;
@ApiModelProperty(value = "flow/job")
@NotNull(message = "flow/job不能为空")
@NotEmpty(message = "flow/job不能为空")
private String flow;
@ApiModelProperty(value = "sla 规则")
private String slaRule;
@ApiModelProperty(value = "duration")
private String duration;
@ApiModelProperty(value = "邮件通知")
private Boolean emailNotification;
@ApiModelProperty(value = "kill")
private Boolean kill;
}
...@@ -9,10 +9,7 @@ import com.jz.common.page.PageInfoResponse; ...@@ -9,10 +9,7 @@ import com.jz.common.page.PageInfoResponse;
import com.jz.dmp.modules.controller.DataIntegration.bean.flow.FlowPro; import com.jz.dmp.modules.controller.DataIntegration.bean.flow.FlowPro;
import com.jz.dmp.modules.controller.bean.DmpDevelopTaskDto; import com.jz.dmp.modules.controller.bean.DmpDevelopTaskDto;
import com.jz.dmp.modules.controller.bean.DmpDevelopTaskRequest; import com.jz.dmp.modules.controller.bean.DmpDevelopTaskRequest;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevExamplesListDto; import com.jz.dmp.modules.controller.dataOperation.bean.*;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevExamplesListReq;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevTaskListDto;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevTaskListReq;
import com.jz.dmp.modules.model.DmpDevelopTask; import com.jz.dmp.modules.model.DmpDevelopTask;
/** /**
...@@ -183,4 +180,12 @@ public interface DmpDevelopTaskService { ...@@ -183,4 +180,12 @@ public interface DmpDevelopTaskService {
* @since 2021-02-22 * @since 2021-02-22
*/ */
JsonResult getTaskStatus(String projectId) throws Exception; JsonResult getTaskStatus(String projectId) throws Exception;
/**
* 设置SLA
*
* @return
* @author Bellamy
* @since 2021-02-03
*/
JsonResult setSla(SetSlaReq req) throws Exception;
} }
\ No newline at end of file
...@@ -12,6 +12,7 @@ import com.jz.common.constant.CommConstant; ...@@ -12,6 +12,7 @@ import com.jz.common.constant.CommConstant;
import com.jz.common.constant.JsonResult; import com.jz.common.constant.JsonResult;
import com.jz.common.constant.ResultCode; import com.jz.common.constant.ResultCode;
import com.jz.common.constant.StatuConstant; import com.jz.common.constant.StatuConstant;
import com.jz.common.enums.FlowInstanceEnum;
import com.jz.common.enums.ModuleLogEnum; import com.jz.common.enums.ModuleLogEnum;
import com.jz.common.page.PageInfoResponse; import com.jz.common.page.PageInfoResponse;
import com.jz.common.persistence.BaseService; import com.jz.common.persistence.BaseService;
...@@ -24,10 +25,7 @@ import com.jz.dmp.modules.controller.bean.DmpDevelopTaskDto; ...@@ -24,10 +25,7 @@ import com.jz.dmp.modules.controller.bean.DmpDevelopTaskDto;
import com.jz.dmp.modules.controller.bean.DmpDevelopTaskRequest; import com.jz.dmp.modules.controller.bean.DmpDevelopTaskRequest;
import com.jz.dmp.modules.controller.bean.MyDmpDevelopTaskConverter; import com.jz.dmp.modules.controller.bean.MyDmpDevelopTaskConverter;
import com.jz.dmp.modules.controller.bean.MyDmpDevelopTaskHistoryConverter; import com.jz.dmp.modules.controller.bean.MyDmpDevelopTaskHistoryConverter;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevExamplesListDto; import com.jz.dmp.modules.controller.dataOperation.bean.*;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevExamplesListReq;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevTaskListDto;
import com.jz.dmp.modules.controller.dataOperation.bean.DataDevTaskListReq;
import com.jz.dmp.modules.controller.projconfig.bean.DmpProjectConfigInfoDto; import com.jz.dmp.modules.controller.projconfig.bean.DmpProjectConfigInfoDto;
import com.jz.dmp.modules.dao.*; import com.jz.dmp.modules.dao.*;
import com.jz.dmp.modules.dao.projconfig.DmpProjectConfigInfoMapper; import com.jz.dmp.modules.dao.projconfig.DmpProjectConfigInfoMapper;
...@@ -789,6 +787,16 @@ public class DmpDevelopTaskServiceImpl extends BaseService implements DmpDevelop ...@@ -789,6 +787,16 @@ public class DmpDevelopTaskServiceImpl extends BaseService implements DmpDevelop
req.setTreeIdOrName(req.getTreeIdOrName().trim());//节点名称 req.setTreeIdOrName(req.getTreeIdOrName().trim());//节点名称
} }
} }
if (StringUtils.isNotBlank(req.getStatus())) {
if (FlowInstanceEnum.running.getCode().equals(req.getStatus())) {
req.setStatus(FlowInstanceEnum.running.getValue());
} else if (FlowInstanceEnum.failed.getCode().equals(req.getStatus())) {
req.setStatus(FlowInstanceEnum.failed.getValue());
} else {
//全部
req.setStatus("");
}
}
PageHelper.startPage(req.getPageNum(), req.getPageSize()); PageHelper.startPage(req.getPageNum(), req.getPageSize());
List<DataDevTaskListDto> list = dmpDevelopTaskDao.queryDevTaskListPage(req); List<DataDevTaskListDto> list = dmpDevelopTaskDao.queryDevTaskListPage(req);
...@@ -798,11 +806,21 @@ public class DmpDevelopTaskServiceImpl extends BaseService implements DmpDevelop ...@@ -798,11 +806,21 @@ public class DmpDevelopTaskServiceImpl extends BaseService implements DmpDevelop
pageInfoResponse.setMessage("查询成功"); pageInfoResponse.setMessage("查询成功");
pageInfoResponse.setData(pageInfo); pageInfoResponse.setData(pageInfo);
String taskName = ""; String taskName = "";
List<DataDevTaskListDto> listObj = (List<DataDevTaskListDto>) pageInfo; List<DataDevTaskListDto> listObj = pageInfoResponse.getData().getList();
for (DataDevTaskListDto str : listObj) { for (DataDevTaskListDto str : listObj) {
taskName += "," + str.getTaskName(); taskName += "," + str.getTaskName();
} }
List<Map> flowList = executionFlowsMapper.queryLastStatus(taskName.substring(1).split(",")); //查询实例最后执行状态
List<Map> flowList = executionFlowsMapper.queryLastStatus(taskName.substring(1).split(","), req.getStatus());
if (flowList.size() > 0 && flowList != null) {
for (DataDevTaskListDto str : listObj) {
for (Map strFlow : flowList) {
if (str.getTaskName().equals(strFlow.get("taskName"))) {
str.setStatus(String.valueOf(strFlow.get("status")));
}
}
}
}
return pageInfoResponse; return pageInfoResponse;
} }
...@@ -1611,4 +1629,24 @@ public class DmpDevelopTaskServiceImpl extends BaseService implements DmpDevelop ...@@ -1611,4 +1629,24 @@ public class DmpDevelopTaskServiceImpl extends BaseService implements DmpDevelop
return JsonResult.ok(taskStatus); return JsonResult.ok(taskStatus);
} }
/**
* 设置SLA
*
* @return
* @author Bellamy
* @since 2021-02-03
*/
@Override
public JsonResult setSla(SetSlaReq req) throws Exception {
Map<String, Object> params = new HashMap<>();
Long projectId = Long.valueOf(req.getProjectId()); //项目id
DmpProjectSystemInfo publishToProjectSystemInfo = dmpProjectDao.queryProjectSystemInfo(projectId);
//调用azkaban服务
String azkabanApiUrl = publishToProjectSystemInfo.getAzkabanMonitorUrl();
AzkabanApiUtils2 azkabanApiUtils = new AzkabanApiUtils2(azkabanApiUrl, redisTemplate);
azkabanApiUtils.saveSla(req);
return null;
}
} }
\ No newline at end of file
...@@ -222,7 +222,20 @@ ...@@ -222,7 +222,20 @@
)t )t
</select> </select>
<select id="queryLastStatus" resultType="java.util.Map"> <select id="queryLastStatus" resultType="java.util.Map">
SELECT
exec_id AS execId,
flow_id AS taskName,
max(from_unixtime( submit_time / 1000, '%Y-%m-%d %H:%i:%s' )) AS startTime,
(case when status='30' then '运行中' when status='50' then '成功' when status='70' then '失败' end) status
FROM
execution_flows
WHERE 1 = 1
<if test="status != null and status !='' ">and status=#{status}</if>
and flow_id in
<foreach collection="taskName" item="item" open="(" separator="," close=")">
#{item}
</foreach>
group by flow_id
</select> </select>
</mapper> </mapper>
\ No newline at end of file
...@@ -177,7 +177,7 @@ ...@@ -177,7 +177,7 @@
dmp_navigation_tree t1 dmp_navigation_tree t1
inner join dmp_develop_task t2 on t2.TREE_ID=t1.ID and t2.data_status ='1' inner join dmp_develop_task t2 on t2.TREE_ID=t1.ID and t2.data_status ='1'
left join dmp_member t3 on t1.create_user_id=t3.user_id left join dmp_member t3 on t1.create_user_id=t3.user_id
where 1=1 and IS_LEVEL ='1' where 1=1 and IS_LEVEL ='1' and t1.data_status ='1'
and t1.project_id = #{projectId} and t1.project_id = #{projectId}
<if test="taskId != null and taskId != ''"> and t2.id =#{taskId} </if> <if test="taskId != null and taskId != ''"> and t2.id =#{taskId} </if>
<if test="treeIdOrName != null and treeIdOrName != ''"> and t1.name like concat('%',#{treeIdOrName},'%') </if> <if test="treeIdOrName != null and treeIdOrName != ''"> and t1.name like concat('%',#{treeIdOrName},'%') </if>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment