Skip to content

Commit

Permalink
[Improvement] Merge redundant codes (apache#7550)
Browse files Browse the repository at this point in the history
  • Loading branch information
JinsYin authored and Lucaszlei committed Dec 26, 2021
1 parent 4e7b0ef commit e424338
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.dolphinscheduler.plugin.task.api;

import org.apache.dolphinscheduler.spi.task.ResourceInfo;
import org.apache.dolphinscheduler.spi.task.request.TaskRequest;

/**
Expand Down Expand Up @@ -80,4 +81,21 @@ public void cancelApplication(boolean status) throws Exception {
* set main jar name
*/
protected abstract void setMainJarName();

/**
* Get name of jar resource.
*
* @param mainJar
* @return
*/
protected String getResourceNameOfMainJar(ResourceInfo mainJar) {
if (null == mainJar) {
throw new RuntimeException("The jar for the task is required.");
}

return mainJar.getId() == 0
? mainJar.getRes()
// when update resource maybe has error
: mainJar.getResourceName().replaceFirst("/", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,9 @@ protected String buildCommand() {
protected void setMainJarName() {
// main jar
ResourceInfo mainJar = flinkParameters.getMainJar();
if (mainJar != null) {
int resourceId = mainJar.getId();
String resourceName;
if (resourceId == 0) {
resourceName = mainJar.getRes();
} else {
resourceName = mainJar.getResourceName().replaceFirst("/", "");
}
mainJar.setRes(resourceName);
flinkParameters.setMainJar(mainJar);
}
String resourceName = getResourceNameOfMainJar(mainJar);
mainJar.setRes(resourceName);
flinkParameters.setMainJar(mainJar);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,9 @@ protected String buildCommand() {
protected void setMainJarName() {
// main jar
ResourceInfo mainJar = mapreduceParameters.getMainJar();
if (mainJar != null) {
int resourceId = mainJar.getId();
String resourceName;
if (resourceId == 0) {
resourceName = mainJar.getRes();
} else {
resourceName = mainJar.getResourceName().replaceFirst("/", "");
}
mainJar.setRes(resourceName);
mapreduceParameters.setMainJar(mainJar);
}
String resourceName = getResourceNameOfMainJar(mainJar);
mainJar.setRes(resourceName);
mapreduceParameters.setMainJar(mainJar);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,9 @@ protected String buildCommand() {
protected void setMainJarName() {
// main jar
ResourceInfo mainJar = sparkParameters.getMainJar();

if (null == mainJar) {
throw new RuntimeException("Spark task jar params is null");
}

int resourceId = mainJar.getId();
String resourceName;
if (resourceId == 0) {
resourceName = mainJar.getRes();
} else {
//when update resource maybe has error
resourceName = mainJar.getResourceName().replaceFirst("/", "");
}
String resourceName = getResourceNameOfMainJar(mainJar);
mainJar.setRes(resourceName);
sparkParameters.setMainJar(mainJar);

}

@Override
Expand Down

0 comments on commit e424338

Please sign in to comment.