ailiujiarui commented on issue #15819: URL: https://github.com/apache/dolphinscheduler/issues/15819#issuecomment-2219884955
I am a student selected in this OSPP, and here is part of my implementation plan. # 1. Delete the Java type If you want to add a new task type, you need to first delete the related code of the Java type from the previous task types.  For example, this piece of code first determines whether it is a Java type. You can use this as a starting point to delete the JAVA type and leave a mark. Later, you can add the Normal Jar type. By the same token, in all related places, first delete the code of the Java type task, including calls, uses, etc. By the way, record the position. After deletion is complete and other functions are normal, add the Normal jar type at these recorded places. # 2. Partial implementation of the Normal Jar type First, we need to add a new constant in the JavaConstants class to represent the NORMAL JAR task type: ```java // Original code public class JavaConstants { public static final String RUN_TYPE_JAVA = "JAVA"; public static final String RUN_TYPE_JAR = "JAR"; } // New code public class JavaConstants { public static final String RUN_TYPE_JAVA = "JAVA"; public static final String RUN_TYPE_JAR = "JAR"; public static final String RUN_TYPE_NORMAL_JAR = "NORMAL_JAR"; // New constant } ``` Then, update the checkParameters method in the JavaParameters class to accept the new run type: ```java // Original code public class JavaParameters extends AbstractParameters { // ... public boolean checkParameters() { return runType != null && (runType.equals(JavaConstants.RUN_TYPE_JAVA) || runType.equals(JavaConstants.RUN_TYPE_JAR)); } } // New code public class JavaParameters extends AbstractParameters { // ... public boolean checkParameters() { return runType != null && (runType.equals(JavaConstants.RUN_TYPE_JAVA) || runType.equals(JavaConstants.RUN_TYPE_JAR) || runType.equals(JavaConstants.RUN_TYPE_NORMAL_JAR)); // Updated condition } } ``` Update the handle method in the JavaTask class to handle the new run type. This may involve adding a new method, such as buildNormalJarCommand, to build the command to execute the NORMAL JAR task: ```java // Original code public class JavaTask extends AbstractTask { // Other code @Override public void handle(TaskCallBack taskCallBack) throws TaskException { // Other code switch (javaParameters.getRunType()) { case JavaConstants.RUN_TYPE_JAVA: command = buildJavaCommand(); break; case JavaConstants.RUN_TYPE_JAR: command = buildJarCommand(); break; default: throw new RunTypeNotFoundException("run type is required, but it is null now."); } // Other code } } // New code public class JavaTask extends AbstractTask { // Other code @Override public void handle(TaskCallBack taskCallBack) throws TaskException { // ... switch (javaParameters.getRunType()) { case JavaConstants.RUN_TYPE_JAVA: command = buildJavaCommand(); break; case JavaConstants.RUN_TYPE_JAR: command = buildJarCommand(); break; case JavaConstants.RUN_TYPE_NORMAL_JAR: // New case command = buildNormalJarCommand(); // New method break; default: throw new RunTypeNotFoundException("run type is required, but it is null now."); } // ... } // New method protected String buildNormalJarCommand() { // Get the absolute path of the JAR file ResourceContext resourceContext = taskRequest.getResourceContext(); String mainJarAbsolutePathInLocal = resourceContext .getResourceItem(javaParameters.getMainJar().getResourceName()) .getResourceAbsolutePathInLocal(); // Build the command StringBuilder builder = new StringBuilder(); builder.append(getJavaCommandPath()) .append("java").append(" ") .append(buildResourcePath()).append(" ") .append("-cp").append(" ") .append(taskRequest.getExecutePath()).append(FOLDER_SEPARATOR) .append(mainJarAbsolutePathInLocal).append(" ") .append(javaParameters.getMainClass()).append(" ") // Main class name .append(javaParameters.getMainArgs().trim()).append(" ") // Main class parameters .append(javaParameters.getJvmArgs().trim()); // JVM parameters return builder.toString(); } } ``` This method first gets the absolute path of the JAR file, then builds a command to execute the NORMAL JAR task. This command includes the path of the Java command, the class path, the path of the JAR file, the main class name, the main class parameters, and the JVM parameters. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
