Unverified Commit 3f9bf1c7 authored by gaoyan's avatar gaoyan Committed by GitHub

Add console log when run debug (#2566)

* Optimize the process * add debug console log * formate code
parent ad3f0df7
...@@ -26,11 +26,13 @@ import org.dinky.data.annotations.ProcessStep; ...@@ -26,11 +26,13 @@ import org.dinky.data.annotations.ProcessStep;
import org.dinky.data.enums.ProcessStatus; import org.dinky.data.enums.ProcessStatus;
import org.dinky.data.enums.ProcessStepType; import org.dinky.data.enums.ProcessStepType;
import org.dinky.data.enums.ProcessType; import org.dinky.data.enums.ProcessType;
import org.dinky.data.exception.DinkyException;
import org.dinky.data.model.ProcessStepEntity; import org.dinky.data.model.ProcessStepEntity;
import org.apache.http.util.TextUtils; import org.apache.http.util.TextUtils;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
...@@ -41,6 +43,7 @@ import org.slf4j.MDC; ...@@ -41,6 +43,7 @@ import org.slf4j.MDC;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import cn.hutool.core.text.StrFormatter; import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Aspect @Aspect
...@@ -116,12 +119,13 @@ public class ProcessAspect { ...@@ -116,12 +119,13 @@ public class ProcessAspect {
return result; return result;
} }
private Object getProcessId(ProceedingJoinPoint joinPoint) { private Object getProcessId(ProceedingJoinPoint joinPoint) throws IllegalAccessException {
Object[] params = joinPoint.getArgs(); Object[] params = joinPoint.getArgs();
if (params.length == 0) { if (params.length == 0) {
throw new IllegalArgumentException("Must have ProcessId params"); throw new IllegalArgumentException("Must have ProcessId params");
} }
Object processIdObj = null;
// Get the method, here you can convert the signature strong to MethodSignature // Get the method, here you can convert the signature strong to MethodSignature
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod(); Method method = signature.getMethod();
...@@ -129,13 +133,32 @@ public class ProcessAspect { ...@@ -129,13 +133,32 @@ public class ProcessAspect {
Annotation[][] annotations = method.getParameterAnnotations(); Annotation[][] annotations = method.getParameterAnnotations();
for (int i = 0; i < annotations.length; i++) { for (int i = 0; i < annotations.length; i++) {
Object param = params[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]; Annotation[] paramAnn = annotations[i];
for (Annotation annotation : paramAnn) { for (Annotation annotation : paramAnn) {
if (annotation instanceof ProcessId) { 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");
} }
} }
...@@ -95,6 +95,7 @@ public class TaskController { ...@@ -95,6 +95,7 @@ public class TaskController {
required = true, required = true,
dataType = "DebugDTO", dataType = "DebugDTO",
paramType = "body") paramType = "body")
@ExecuteProcess(type = ProcessType.FLINK_SUBMIT)
public Result<JobResult> debugTask(@RequestBody DebugDTO debugDTO) throws Exception { public Result<JobResult> debugTask(@RequestBody DebugDTO debugDTO) throws Exception {
JobResult result = taskService.debugTask(debugDTO); JobResult result = taskService.debugTask(debugDTO);
if (result.isSuccess()) { if (result.isSuccess()) {
...@@ -159,7 +160,7 @@ public class TaskController { ...@@ -159,7 +160,7 @@ public class TaskController {
@PostMapping("/getJobPlan") @PostMapping("/getJobPlan")
@ApiOperation("Get Job Plan") @ApiOperation("Get Job Plan")
@ExecuteProcess(type = ProcessType.FLINK_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; ObjectNode jobPlan = null;
jobPlan = taskService.getJobPlan(taskDTO); jobPlan = taskService.getJobPlan(taskDTO);
return Result.succeed(jobPlan, Status.EXECUTE_SUCCESS); return Result.succeed(jobPlan, Status.EXECUTE_SUCCESS);
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
package org.dinky.data.dto; package org.dinky.data.dto;
import org.dinky.data.annotations.ProcessId;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Getter; import lombok.Getter;
...@@ -37,6 +39,7 @@ public class DebugDTO { ...@@ -37,6 +39,7 @@ public class DebugDTO {
dataType = "Integer", dataType = "Integer",
example = "1", example = "1",
notes = "The ID of Task which is debugged") notes = "The ID of Task which is debugged")
@ProcessId
private Integer id; private Integer id;
@ApiModelProperty( @ApiModelProperty(
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.dinky.data.dto; package org.dinky.data.dto;
import org.dinky.data.annotations.ProcessId;
import org.dinky.data.model.Task; import org.dinky.data.model.Task;
import org.dinky.data.model.ext.TaskExtConfig; import org.dinky.data.model.ext.TaskExtConfig;
import org.dinky.job.JobConfig; import org.dinky.job.JobConfig;
...@@ -43,6 +44,10 @@ import lombok.extern.slf4j.Slf4j; ...@@ -43,6 +44,10 @@ import lombok.extern.slf4j.Slf4j;
@ApiModel(value = "StudioExecuteDTO", description = "DTO for executing SQL queries") @ApiModel(value = "StudioExecuteDTO", description = "DTO for executing SQL queries")
public class TaskDTO extends AbstractStatementDTO { 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") @ApiModelProperty(value = "Name", required = true, dataType = "String", example = "Name")
private String name; private String name;
...@@ -209,9 +214,6 @@ public class TaskDTO extends AbstractStatementDTO { ...@@ -209,9 +214,6 @@ public class TaskDTO extends AbstractStatementDTO {
@ApiModelProperty(value = "Job Name", dataType = "String", example = "MyJob", notes = "The name of the job") @ApiModelProperty(value = "Job Name", dataType = "String", example = "MyJob", notes = "The name of the job")
private String jobName; private String jobName;
@ApiModelProperty(value = "ID", dataType = "Integer", example = "6", notes = "The identifier of the execution")
private Integer id;
@ApiModelProperty( @ApiModelProperty(
value = "Max Row Number", value = "Max Row Number",
dataType = "Integer", dataType = "Integer",
......
...@@ -25,7 +25,7 @@ import java.lang.annotation.Retention; ...@@ -25,7 +25,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
@Target(ElementType.PARAMETER) @Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Inherited @Inherited
public @interface ProcessId {} public @interface ProcessId {}
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