Skip to content

Commit

Permalink
Add job overview (#2573)
Browse files Browse the repository at this point in the history
* Optimize the process

* add job overview
  • Loading branch information
gaoyan1998 authored Nov 25, 2023
1 parent d326ecb commit c56784b
Show file tree
Hide file tree
Showing 19 changed files with 689 additions and 219 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import org.dinky.data.model.ID;
import org.dinky.data.model.devops.TaskManagerConfiguration;
import org.dinky.data.model.ext.JobInfoDetail;
import org.dinky.data.model.job.JobInstance;
import org.dinky.data.model.home.JobInstanceStatus;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.data.vo.task.JobInstanceVo;
import org.dinky.explainer.lineage.LineageResult;
import org.dinky.service.JobInstanceService;
import org.dinky.utils.BuildConfiguration;
Expand Down Expand Up @@ -78,7 +79,7 @@ public class JobInstanceController {
paramType = "body",
required = true,
dataTypeClass = JsonNode.class)
public ProTableResult<JobInstance> listJobInstances(@RequestBody JsonNode para) {
public ProTableResult<JobInstanceVo> listJobInstances(@RequestBody JsonNode para) {
return jobInstanceService.listJobInstances(para);
}

Expand All @@ -87,11 +88,8 @@ public ProTableResult<JobInstance> listJobInstances(@RequestBody JsonNode para)
*/
@GetMapping("/getStatusCount")
@ApiOperation("Get status count")
public Result<Dict> getStatusCount() {
Dict result = Dict.create()
.set("history", jobInstanceService.getStatusCount(true))
.set("instance", jobInstanceService.getStatusCount(false));
return Result.succeed(result);
public Result<JobInstanceStatus> getStatusCount() {
return Result.succeed(jobInstanceService.getStatusCount());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import org.dinky.data.enums.MetricsType;
import org.dinky.data.metrics.Jvm;
import org.dinky.data.model.Metrics;
import org.dinky.data.model.job.JobInstance;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.result.Result;
import org.dinky.data.vo.MetricsVO;
import org.dinky.data.vo.task.JobInstanceVo;
import org.dinky.service.JobInstanceService;
import org.dinky.service.MonitorService;

Expand Down Expand Up @@ -93,9 +93,9 @@ public Result<List<MetricsVO>> getFlinkData(@RequestParam Long startTime, Long e
ObjectNode para = nodeFactory.objectNode();
para.put("isHistory", false);
para.put("taskId", taskIds);
ProTableResult<JobInstance> jobInstanceProTableResult = jobInstanceService.listJobInstances(para);
ProTableResult<JobInstanceVo> jobInstanceProTableResult = jobInstanceService.listJobInstances(para);
List<String> jids = jobInstanceProTableResult.getData().stream()
.map(JobInstance::getJid)
.map(JobInstanceVo::getJid)
.collect(Collectors.toList());
return Result.succeed(monitorService.getData(
DateUtil.date(startTime),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@

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

/**
* JobInstanceStatus
*
* @since 2022/2/28 22:25
*/
@ApiModel(value = "JobInstanceStatus", description = "Job Instance Status Information")
@Data
public class JobInstanceStatus {

@ApiModelProperty(value = "All", dataType = "Integer", example = "10", notes = "Total count of job instances")
Expand Down Expand Up @@ -117,109 +119,6 @@ public class JobInstanceStatus {
notes = "Count of job instances in the Unknown state")
private Integer unknown = 0;

public JobInstanceStatus() {}

public Integer getAll() {
return all;
}

public void setAll(Integer all) {
this.all = all;
}

public Integer getInitializing() {
return initializing;
}

public void setInitializing(Integer initializing) {
this.initializing = initializing;
}

public Integer getRunning() {
return running;
}

public void setRunning(Integer running) {
this.running = running;
}

public Integer getFinished() {
return finished;
}

public void setFinished(Integer finished) {
this.finished = finished;
}

public Integer getFailed() {
return failed;
}

public void setFailed(Integer failed) {
this.failed = failed;
}

public Integer getCanceled() {
return canceled;
}

public void setCanceled(Integer canceled) {
this.canceled = canceled;
}

public Integer getRestarting() {
return restarting;
}

public void setRestarting(Integer restarting) {
this.restarting = restarting;
}

public Integer getCreated() {
return created;
}

public void setCreated(Integer created) {
this.created = created;
}

public Integer getFailing() {
return failing;
}

public void setFailing(Integer failing) {
this.failing = failing;
}

public Integer getCancelling() {
return cancelling;
}

public void setCancelling(Integer cancelling) {
this.cancelling = cancelling;
}

public Integer getSuspended() {
return suspended;
}

public void setSuspended(Integer suspended) {
this.suspended = suspended;
}

public Integer getReconciling() {
return reconciling;
}

public void setReconciling(Integer reconciling) {
this.reconciling = reconciling;
}

public Integer getUnknown() {
return unknown;
}

public void setUnknown(Integer unknown) {
this.unknown = unknown;
}
@ApiModelProperty(value = "modelOverview", dataType = "JobModelOverview", notes = "batch and steamng count")
private JobModelOverview modelOverview;
}
102 changes: 102 additions & 0 deletions dinky-admin/src/main/java/org/dinky/data/vo/task/JobInstanceVo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
*
* 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.vo.task;

import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class JobInstanceVo {

@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(
value = "ID",
dataType = "Integer",
example = "1",
notes = "Unique identifier for the job instance")
private Integer id;

@ApiModelProperty(value = "Name", dataType = "String", notes = "Name of the job instance")
private String name;

@ApiModelProperty(
value = "Task ID",
dataType = "Integer",
example = "1",
notes = "Task ID associated with the job instance")
private Integer taskId;

@ApiModelProperty(value = "Step", dataType = "Integer", example = "1", notes = "Step number of the job instance")
private Integer step;

@ApiModelProperty(value = "JID", dataType = "String", notes = "JID of the job instance")
private String jid;

@ApiModelProperty(value = "Status", dataType = "String", notes = "Status of the job instance")
private String status;

@ApiModelProperty(value = "type", dataType = "String", notes = "run mode type", example = "kubernets-application")
private String type;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.INSERT)
@ApiModelProperty(
value = "Create Time",
dataType = "String",
notes = "Timestamp indicating the creation time of the job instance")
private LocalDateTime createTime;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@TableField(fill = FieldFill.INSERT_UPDATE)
@ApiModelProperty(
value = "Update Time",
dataType = "String",
notes = "Timestamp indicating the last update time of the job instance")
private LocalDateTime updateTime;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(
value = "Finish Time",
dataType = "String",
notes = "Timestamp indicating the finish time of the job instance")
private LocalDateTime finishTime;

@ApiModelProperty(
value = "Duration",
dataType = "Long",
example = "3600",
notes = "Duration of the job instance in seconds")
private Long duration;

@ApiModelProperty(
value = "Failed Restart Count",
dataType = "Integer",
example = "2",
notes = "Count of failed restarts")
private Integer failedRestartCount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.dinky.mapper;

import org.dinky.data.model.home.JobInstanceCount;
import org.dinky.data.model.home.JobModelOverview;
import org.dinky.data.model.job.JobInstance;
import org.dinky.mybatis.mapper.SuperMapper;

Expand All @@ -43,7 +44,7 @@ public interface JobInstanceMapper extends SuperMapper<JobInstance> {

List<JobInstanceCount> countStatus();

List<JobInstanceCount> countHistoryStatus();
JobModelOverview getJobStreamingOrBatchModelOverview();

@InterceptorIgnore(tenantLine = "true")
List<JobInstance> listJobInstanceActive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
*/
public interface SuperMapper<T> extends BaseMapper<T> {

List<T> selectForProTable(
Page<T> page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper, @Param("param") Map<String, Object> param);
<K> List<K> selectForProTable(
Page<K> page, @Param(Constants.WRAPPER) Wrapper<K> queryWrapper, @Param("param") Map<String, Object> param);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.dinky.data.model.home.JobInstanceStatus;
import org.dinky.data.model.job.JobInstance;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.vo.task.JobInstanceVo;
import org.dinky.explainer.lineage.LineageResult;
import org.dinky.mybatis.service.ISuperService;

Expand All @@ -49,10 +50,9 @@ public interface JobInstanceService extends ISuperService<JobInstance> {
/**
* Get the count of job instance statuses.
*
* @param isHistory A boolean indicating whether to get the history status count or not.
* @return An integer representing the count of job instance statuses.
*/
JobInstanceStatus getStatusCount(boolean isHistory);
JobInstanceStatus getStatusCount();

/**
* Get a list of active job instances.
Expand Down Expand Up @@ -123,7 +123,7 @@ public interface JobInstanceService extends ISuperService<JobInstance> {
* @param para A {@link JsonNode} object representing the filter conditions for listing job instances.
* @return A {@link ProTableResult<JobInstance>} object representing the list of job instances.
*/
ProTableResult<JobInstance> listJobInstances(JsonNode para);
ProTableResult<JobInstanceVo> listJobInstances(JsonNode para);

/**
* Initialize the tenant by the given job instance ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
import org.dinky.data.model.ext.JobInfoDetail;
import org.dinky.data.model.home.JobInstanceCount;
import org.dinky.data.model.home.JobInstanceStatus;
import org.dinky.data.model.home.JobModelOverview;
import org.dinky.data.model.job.History;
import org.dinky.data.model.job.JobInstance;
import org.dinky.data.result.ProTableResult;
import org.dinky.data.vo.task.JobInstanceVo;
import org.dinky.explainer.lineage.LineageBuilder;
import org.dinky.explainer.lineage.LineageResult;
import org.dinky.job.FlinkJobTask;
Expand Down Expand Up @@ -89,14 +91,12 @@ public JobInstance getByIdWithoutTenant(Integer id) {
}

@Override
public JobInstanceStatus getStatusCount(boolean isHistory) {
public JobInstanceStatus getStatusCount() {
List<JobInstanceCount> jobInstanceCounts;
if (isHistory) {
jobInstanceCounts = baseMapper.countHistoryStatus();
} else {
jobInstanceCounts = baseMapper.countStatus();
}
jobInstanceCounts = baseMapper.countStatus();
JobModelOverview modelOverview = baseMapper.getJobStreamingOrBatchModelOverview();
JobInstanceStatus jobInstanceStatus = new JobInstanceStatus();
jobInstanceStatus.setModelOverview(modelOverview);
int total = 0;
for (JobInstanceCount item : jobInstanceCounts) {
Integer counts = Asserts.isNull(item.getCounts()) ? 0 : item.getCounts();
Expand Down Expand Up @@ -252,16 +252,16 @@ public JobInstance getJobInstanceByTaskId(Integer id) {
}

@Override
public ProTableResult<JobInstance> listJobInstances(JsonNode para) {
public ProTableResult<JobInstanceVo> listJobInstances(JsonNode para) {
int current = para.has("current") ? para.get("current").asInt() : 1;
int pageSize = para.has("pageSize") ? para.get("pageSize").asInt() : 10;
QueryWrapper<JobInstance> queryWrapper = new QueryWrapper<>();
QueryWrapper<JobInstanceVo> queryWrapper = new QueryWrapper<>();
ProTableUtil.autoQueryDefalut(para, queryWrapper);
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> param = mapper.convertValue(para, Map.class);
Page<JobInstance> page = new Page<>(current, pageSize);
List<JobInstance> list = baseMapper.selectForProTable(page, queryWrapper, param);
return ProTableResult.<JobInstance>builder()
Page<JobInstanceVo> page = new Page<>(current, pageSize);
List<JobInstanceVo> list = baseMapper.selectForProTable(page, queryWrapper, param);
return ProTableResult.<JobInstanceVo>builder()
.success(true)
.data(list)
.total(page.getTotal())
Expand Down
Loading

0 comments on commit c56784b

Please sign in to comment.