Skip to content

Commit

Permalink
add debug console log
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyan1998 committed Nov 23, 2023
1 parent 3dfba3d commit 6823bef
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
28 changes: 25 additions & 3 deletions dinky-admin/src/main/java/org/dinky/aop/ProcessAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@

package org.dinky.aop;

import cn.hutool.core.util.ObjectUtil;
import org.dinky.context.ConsoleContextHolder;
import org.dinky.data.annotations.ExecuteProcess;
import org.dinky.data.annotations.ProcessId;
import org.dinky.data.annotations.ProcessStep;
import org.dinky.data.enums.ProcessStatus;
import org.dinky.data.enums.ProcessStepType;
import org.dinky.data.enums.ProcessType;
import org.dinky.data.exception.DinkyException;
import org.dinky.data.model.ProcessStepEntity;

import org.apache.http.util.TextUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.aspectj.lang.ProceedingJoinPoint;
Expand Down Expand Up @@ -116,26 +119,45 @@ public Object processStepAround(ProceedingJoinPoint joinPoint, ProcessStep proce
return result;
}

private Object getProcessId(ProceedingJoinPoint joinPoint) {
private Object getProcessId(ProceedingJoinPoint joinPoint) throws IllegalAccessException {
Object[] params = joinPoint.getArgs();
if (params.length == 0) {
throw new IllegalArgumentException("Must have ProcessId params");
}

Object processIdObj = null;
// Get the method, here you can convert the signature strong to MethodSignature
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();

Annotation[][] annotations = method.getParameterAnnotations();
for (int i = 0; i < annotations.length; i++) {
Object param = params[i];
if (param == null)continue;
//Check whether the parameters on the method have the Process Id annotation
Annotation[] paramAnn = annotations[i];
for (Annotation annotation : paramAnn) {
if (annotation instanceof ProcessId) {
return String.valueOf(param.hashCode());
processIdObj = param;
break;
}
}
//If there is no Process Id annotation on the parameter,
// continue to find out whether there is a variable in the object with the Process Id annotation
if (processIdObj == null){
Field[] fields = param.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.isAnnotationPresent(ProcessId.class)) {
field.setAccessible(true);
processIdObj = field.get(param);
}
}
}
}
if (ObjectUtil.isBasicType(processIdObj)){
return processIdObj;
}else {
throw new DinkyException("The type of the parameter annotated with @ProcessId must be a basic type and not null");
}
throw new IllegalArgumentException("Must have ProcessId annoation params");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public Result<JobResult> submitTask(@ProcessId @RequestParam Integer id) throws
required = true,
dataType = "DebugDTO",
paramType = "body")
@ExecuteProcess(type = ProcessType.FLINK_SUBMIT)
public Result<JobResult> debugTask(@RequestBody DebugDTO debugDTO) throws Exception {
JobResult result = taskService.debugTask(debugDTO);
if (result.isSuccess()) {
Expand Down Expand Up @@ -159,7 +160,7 @@ public Result<List<SqlExplainResult>> explainSql(@RequestBody TaskDTO taskDTO) t
@PostMapping("/getJobPlan")
@ApiOperation("Get Job Plan")
@ExecuteProcess(type = ProcessType.FLINK_JOB_PLAN)
public Result<ObjectNode> getJobPlan(@ProcessId @RequestBody TaskDTO taskDTO) {
public Result<ObjectNode> getJobPlan(@RequestBody TaskDTO taskDTO) {
ObjectNode jobPlan = null;
try {
jobPlan = taskService.getJobPlan(taskDTO);
Expand Down
2 changes: 2 additions & 0 deletions dinky-admin/src/main/java/org/dinky/data/dto/DebugDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.dinky.data.annotations.ProcessId;

/**
* Param for debug flink sql and common sql
Expand All @@ -37,6 +38,7 @@ public class DebugDTO {
dataType = "Integer",
example = "1",
notes = "The ID of Task which is debugged")
@ProcessId
private Integer id;

@ApiModelProperty(
Expand Down
8 changes: 5 additions & 3 deletions dinky-admin/src/main/java/org/dinky/data/dto/TaskDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.dinky.data.dto;

import org.dinky.data.annotations.ProcessId;
import org.dinky.data.model.Task;
import org.dinky.data.model.ext.TaskExtConfig;
import org.dinky.job.JobConfig;
Expand All @@ -43,6 +44,10 @@
@ApiModel(value = "StudioExecuteDTO", description = "DTO for executing SQL queries")
public class TaskDTO extends AbstractStatementDTO {

@ApiModelProperty(value = "ID", dataType = "Integer", example = "6", notes = "The identifier of the execution")
@ProcessId
private Integer id;

@ApiModelProperty(value = "Name", required = true, dataType = "String", example = "Name")
private String name;

Expand Down Expand Up @@ -209,9 +214,6 @@ public class TaskDTO extends AbstractStatementDTO {
@ApiModelProperty(value = "Job Name", dataType = "String", example = "MyJob", notes = "The name of the job")
private String jobName;

@ApiModelProperty(value = "ID", dataType = "Integer", example = "6", notes = "The identifier of the execution")
private Integer id;

@ApiModelProperty(
value = "Max Row Number",
dataType = "Integer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.PARAMETER)
@Target({ElementType.PARAMETER,ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ProcessId {}

0 comments on commit 6823bef

Please sign in to comment.