Skip to content

Commit

Permalink
refactor JobInstance refesh (#2324)
Browse files Browse the repository at this point in the history
* refactor JobInstance refesh * fix job refesh npe * fix code style * Compatible with J Dk 8 * Modify the job refresh time to 5 秒之前 * fix alert npe * fix devops data * fix json parse error
  • Loading branch information
gaoyan1998 authored Sep 20, 2023
1 parent 8eec074 commit c2dc2b0
Show file tree
Hide file tree
Showing 41 changed files with 730 additions and 649 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

package org.dinky.controller;

import org.dinky.configure.schedule.Alert.JobAlerts;
import org.dinky.data.annotation.Log;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.enums.Status;
import org.dinky.data.model.AlertRule;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.job.handler.JobAlertHandler;
import org.dinky.service.AlertRuleService;

import java.util.List;
Expand Down Expand Up @@ -53,7 +53,6 @@
public class AlertRuleController {

private final AlertRuleService alertRuleService;
private final JobAlerts jobAlerts;

@PostMapping("/list")
@ApiOperation("Query alert rules list")
Expand Down Expand Up @@ -81,7 +80,7 @@ public ProTableResult<AlertRule> list(@RequestBody JsonNode para) {
public Result<Boolean> saveOrUpdateAlertRule(@RequestBody AlertRule alertRule) {
boolean saved = alertRuleService.saveOrUpdate(alertRule);
if (saved) {
jobAlerts.refreshRulesData();
JobAlertHandler.getInstance().refreshRulesData();
return Result.succeed(Status.MODIFY_SUCCESS);
}
return Result.failed(Status.MODIFY_FAILED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Result<JobInfoDetail> getJobInfoDetail(@RequestParam Integer id) {
paramType = "query",
required = true)
public Result<JobInfoDetail> refreshJobInfoDetail(@RequestParam Integer id) {
return Result.succeed(taskService.refreshJobInfoDetail(id), Status.RESTART_SUCCESS);
return Result.succeed(jobInstanceService.refreshJobInfoDetail(id), Status.RESTART_SUCCESS);
}

/** 获取单任务实例的血缘分析 */
Expand Down
134 changes: 134 additions & 0 deletions dinky-admin/src/main/java/org/dinky/data/dto/JobDataDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
*
* 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.dinky.data.dto;

import org.dinky.data.model.JobHistory;
import org.dinky.utils.JSONUtil;

import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.databind.JsonNode;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class JobDataDto {

@ApiModelProperty(
value = "ID",
dataType = "Integer",
example = "1",
notes = "Unique identifier for the job history")
private Integer id;

@ApiModelProperty(
value = "Tenant ID",
dataType = "Integer",
example = "1",
notes = "Tenant ID associated with the job history")
private Integer tenantId;

@TableField(exist = false)
@ApiModelProperty(value = "Job Object", notes = "Object representing job details")
private JsonNode job;

@TableField(exist = false)
@ApiModelProperty(value = "Exceptions Object", notes = "Object representing job exceptions")
private JsonNode exceptions;

@TableField(exist = false)
@ApiModelProperty(value = "Checkpoints Object", notes = "Object representing job checkpoints")
private JsonNode checkpoints;

@TableField(exist = false)
@ApiModelProperty(value = "Checkpoints Config Object", notes = "Object representing checkpoints configuration")
private JsonNode checkpointsConfig;

@TableField(exist = false)
@ApiModelProperty(value = "Config Object", notes = "Object representing job configuration")
private JsonNode config;

@TableField(exist = false)
@ApiModelProperty(value = "Jar Object", notes = "Object representing the JAR used in the job")
private JsonNode jar;

@TableField(exist = false)
@ApiModelProperty(value = "Cluster Object", notes = "Object representing the cluster")
private JsonNode cluster;

@TableField(exist = false)
@ApiModelProperty(value = "Cluster Configuration Object", notes = "Object representing cluster configuration")
private JsonNode clusterConfiguration;

@TableField(exist = false)
@ApiModelProperty(
value = "Error Flag",
dataType = "boolean",
example = "true",
notes = "Flag indicating if there was an error")
private boolean error;

@TableField(exist = false)
@ApiModelProperty(
value = "Error Message",
dataType = "boolean",
example = "true",
notes = "Flag indicating if there was an error")
private String errorMsg;

public JobHistory toJobHistory() {
return JobHistory.builder()
.id(this.id)
.tenantId(this.tenantId)
.jobJson(JSONUtil.toJsonString(getJob()))
.exceptionsJson(JSONUtil.toJsonString(getExceptions()))
.checkpointsJson(JSONUtil.toJsonString(getCheckpoints()))
.checkpointsConfigJson(JSONUtil.toJsonString(getCheckpointsConfig()))
.configJson(JSONUtil.toJsonString(getConfig()))
.jarJson(JSONUtil.toJsonString(getJar()))
.clusterJson(JSONUtil.toJsonString(getCluster()))
.clusterConfigurationJson(JSONUtil.toJsonString(getClusterConfiguration()))
.updateTime(LocalDateTime.now())
.build();
}

public static JobDataDto fromJobHistory(JobHistory jobHistory) {
return JobDataDto.builder()
.id(jobHistory.getId())
.tenantId(jobHistory.getTenantId())
.job(JSONUtil.parseToJsonNode(jobHistory.getJobJson()))
.exceptions(JSONUtil.parseToJsonNode(jobHistory.getExceptionsJson()))
.checkpoints(JSONUtil.parseToJsonNode(jobHistory.getCheckpointsJson()))
.checkpointsConfig(JSONUtil.parseToJsonNode(jobHistory.getCheckpointsConfigJson()))
.config(JSONUtil.parseToJsonNode(jobHistory.getConfigJson()))
.jar(JSONUtil.parseToJsonNode(jobHistory.getJarJson()))
.cluster(JSONUtil.parseToJsonNode(jobHistory.getClusterJson()))
.clusterConfiguration(JSONUtil.parseToJsonNode(jobHistory.getClusterConfigurationJson()))
.build();
}
}
43 changes: 2 additions & 41 deletions dinky-admin/src/main/java/org/dinky/data/model/JobHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.node.ObjectNode;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;

Expand All @@ -38,6 +38,7 @@
* @since 2022/3/2 19:48
*/
@Data
@Builder
@EqualsAndHashCode(callSuper = false)
@TableName("dinky_job_history")
@ApiModel(value = "JobHistory", description = "Job History Information")
Expand All @@ -59,87 +60,55 @@ public class JobHistory implements Serializable {
notes = "Tenant ID associated with the job history")
private Integer tenantId;

@TableField(exist = false)
@ApiModelProperty(value = "Job Object", notes = "Object representing job details")
private ObjectNode job;

@ApiModelProperty(
value = "Job JSON",
dataType = "String",
example = "{\"jobName\": \"Example Job\"}",
notes = "JSON representation of the job")
private String jobJson;

@TableField(exist = false)
@ApiModelProperty(value = "Exceptions Object", notes = "Object representing job exceptions")
private ObjectNode exceptions;

@ApiModelProperty(
value = "Exceptions JSON",
dataType = "String",
example = "{\"exceptionType\": \"RuntimeException\"}",
notes = "JSON representation of exceptions")
private String exceptionsJson;

@TableField(exist = false)
@ApiModelProperty(value = "Checkpoints Object", notes = "Object representing job checkpoints")
private ObjectNode checkpoints;

@ApiModelProperty(
value = "Checkpoints JSON",
dataType = "String",
example = "{\"checkpointId\": 123}",
notes = "JSON representation of checkpoints")
private String checkpointsJson;

@TableField(exist = false)
@ApiModelProperty(value = "Checkpoints Config Object", notes = "Object representing checkpoints configuration")
private ObjectNode checkpointsConfig;

@ApiModelProperty(
value = "Checkpoints Config JSON",
dataType = "String",
example = "{\"configParam\": \"value\"}",
notes = "JSON representation of checkpoints config")
private String checkpointsConfigJson;

@TableField(exist = false)
@ApiModelProperty(value = "Config Object", notes = "Object representing job configuration")
private ObjectNode config;

@ApiModelProperty(
value = "Config JSON",
dataType = "String",
example = "{\"configParam\": \"value\"}",
notes = "JSON representation of config")
private String configJson;

@TableField(exist = false)
@ApiModelProperty(value = "Jar Object", notes = "Object representing the JAR used in the job")
private ObjectNode jar;

@ApiModelProperty(
value = "Jar JSON",
dataType = "String",
example = "{\"jarName\": \"example.jar\"}",
notes = "JSON representation of the JAR")
private String jarJson;

@TableField(exist = false)
@ApiModelProperty(value = "Cluster Object", notes = "Object representing the cluster")
private ObjectNode cluster;

@ApiModelProperty(
value = "Cluster JSON",
dataType = "String",
example = "{\"clusterName\": \"exampleCluster\"}",
notes = "JSON representation of the cluster")
private String clusterJson;

@TableField(exist = false)
@ApiModelProperty(value = "Cluster Configuration Object", notes = "Object representing cluster configuration")
private ObjectNode clusterConfiguration;

@ApiModelProperty(
value = "Cluster Configuration JSON",
dataType = "String",
Expand All @@ -153,12 +122,4 @@ public class JobHistory implements Serializable {
dataType = "LocalDateTime",
notes = "Timestamp indicating the last update time")
private LocalDateTime updateTime;

@TableField(exist = false)
@ApiModelProperty(
value = "Error Flag",
dataType = "boolean",
example = "true",
notes = "Flag indicating if there was an error")
private boolean error;
}
Loading

0 comments on commit c2dc2b0

Please sign in to comment.