Skip to content

Commit

Permalink
[Fix-1556] [core] Fix job submission succeeded but failed (#1557)
Browse files Browse the repository at this point in the history
Co-authored-by: wenmo <[email protected]>
  • Loading branch information
aiwenmo and aiwenmo authored Jan 14, 2023
1 parent 1d0212c commit 8ab0e6d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 68 deletions.
18 changes: 10 additions & 8 deletions dlink-common/src/main/java/com/dlink/model/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@

import com.dlink.assertion.Asserts;
import com.dlink.utils.SqlUtil;
import lombok.Getter;
import lombok.Setter;

import java.beans.Transient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


import lombok.Getter;
import lombok.Setter;

/**
* Table
Expand Down Expand Up @@ -63,7 +62,6 @@ public class Table implements Serializable, Comparable<Table>, Cloneable {
*/
private List<String> schemaTableNameList;


private List<Column> columns;

public Table() {
Expand All @@ -77,12 +75,16 @@ public Table(String name, String schema, List<Column> columns) {

@Transient
public String getSchemaTableName() {
return Asserts.isNullString(replaceSchemaMiddleLine(schema)) ? name : replaceSchemaMiddleLine(schema) + "." + name;
return Asserts.isNullString(replaceSchemaMiddleLine(schema))
? name
: replaceSchemaMiddleLine(schema) + "." + name;
}

@Transient
public String getSchemaTableNameWithUnderline() {
return Asserts.isNullString(replaceSchemaMiddleLine(schema)) ? name : replaceSchemaMiddleLine(schema) + "_" + name;
return Asserts.isNullString(replaceSchemaMiddleLine(schema))
? name
: replaceSchemaMiddleLine(schema) + "_" + name;
}

@Override
Expand Down Expand Up @@ -274,8 +276,8 @@ public Object clone() {
}

private String replaceSchemaMiddleLine(String schema) {
if (schema.contains("-")){
return schema.replaceAll("-","_");
if (schema.contains("-")) {
return schema.replaceAll("-", "_");
}
return schema;
}
Expand Down
20 changes: 12 additions & 8 deletions dlink-core/src/main/java/com/dlink/job/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@Getter
@Setter
public class Job {

private Integer id;
private Integer jobInstanceId;
private JobConfig jobConfig;
Expand All @@ -57,14 +58,11 @@ public class Job {
private List<String> jids;

public enum JobStatus {
INITIALIZE,
RUNNING,
SUCCESS,
FAILED,
CANCEL
INITIALIZE, RUNNING, SUCCESS, FAILED, CANCEL
}

public Job(JobConfig jobConfig, GatewayType type, JobStatus status, String statement, ExecutorSetting executorSetting, Executor executor, boolean useGateway) {
public Job(JobConfig jobConfig, GatewayType type, JobStatus status, String statement,
ExecutorSetting executorSetting, Executor executor, boolean useGateway) {
this.jobConfig = jobConfig;
this.type = type;
this.status = status;
Expand All @@ -75,11 +73,17 @@ public Job(JobConfig jobConfig, GatewayType type, JobStatus status, String state
this.useGateway = useGateway;
}

public static Job init(GatewayType type, JobConfig jobConfig, ExecutorSetting executorSetting, Executor executor, String statement, boolean useGateway) {
public static Job init(GatewayType type, JobConfig jobConfig, ExecutorSetting executorSetting, Executor executor,
String statement, boolean useGateway) {
return new Job(jobConfig, type, JobStatus.INITIALIZE, statement, executorSetting, executor, useGateway);
}

public JobResult getJobResult() {
return new JobResult(id, jobInstanceId, jobConfig, jobManagerAddress, status, statement, jobId, error, result, startTime, endTime);
return new JobResult(id, jobInstanceId, jobConfig, jobManagerAddress, status, statement, jobId, error, result,
startTime, endTime);
}

public boolean isFailed() {
return status.equals(JobStatus.FAILED);
}
}
27 changes: 19 additions & 8 deletions dlink-core/src/main/java/com/dlink/job/JobManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ public JobResult executeSql(String statement) {
job.setJobId(gatewayResult.getAppId());
job.setJids(gatewayResult.getJids());
job.setJobManagerAddress(formatAddress(gatewayResult.getWebURL()));
if (gatewayResult.isSucess()) {
job.setStatus(Job.JobStatus.SUCCESS);
} else {
job.setStatus(Job.JobStatus.FAILED);
job.setError(gatewayResult.getError());
}
} else if (useStatementSet && !useGateway) {
List<String> inserts = new ArrayList<>();
for (StatementParam item : jobParam.getTrans()) {
Expand Down Expand Up @@ -478,6 +484,12 @@ public JobResult executeSql(String statement) {
job.setJobId(gatewayResult.getAppId());
job.setJids(gatewayResult.getJids());
job.setJobManagerAddress(formatAddress(gatewayResult.getWebURL()));
if (gatewayResult.isSucess()) {
job.setStatus(Job.JobStatus.SUCCESS);
} else {
job.setStatus(Job.JobStatus.FAILED);
job.setError(gatewayResult.getError());
}
} else {
for (StatementParam item : jobParam.getTrans()) {
currentSql = item.getValue();
Expand Down Expand Up @@ -542,10 +554,9 @@ public JobResult executeSql(String statement) {
job.setJobId(gatewayResult.getAppId());
job.setJids(gatewayResult.getJids());
job.setJobManagerAddress(formatAddress(gatewayResult.getWebURL()));

if (gatewayResult.isSucess()){
if (gatewayResult.isSucess()) {
job.setStatus(Job.JobStatus.SUCCESS);
}else {
} else {
job.setStatus(Job.JobStatus.FAILED);
job.setError(gatewayResult.getError());
}
Expand Down Expand Up @@ -573,13 +584,13 @@ public JobResult executeSql(String statement) {
.getResult(null);
job.setResult(result);
}
job.setStatus(Job.JobStatus.SUCCESS);
}
}
job.setEndTime(LocalDateTime.now());
if (job.getStatus().name().equals(Job.JobStatus.FAILED.name())){
if (job.isFailed()) {
failed();
}else {
} else {
job.setStatus(Job.JobStatus.SUCCESS);
success();
}
} catch (Exception e) {
Expand Down Expand Up @@ -740,10 +751,10 @@ public JobResult executeJar() {
job.setJobManagerAddress(formatAddress(gatewayResult.getWebURL()));
job.setEndTime(LocalDateTime.now());

if (gatewayResult.isSucess()){
if (gatewayResult.isSucess()) {
job.setStatus(Job.JobStatus.SUCCESS);
success();
}else {
} else {
job.setError(gatewayResult.getError());
job.setStatus(Job.JobStatus.FAILED);
failed();
Expand Down
44 changes: 0 additions & 44 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
<scala.binary.version>2.12</scala.binary.version>
<scala.version>2.12.10</scala.version>
<!-- `provided` for product environment ,`compile` for dev environment -->
Expand Down Expand Up @@ -583,38 +582,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
<consoleOutput>true</consoleOutput>
<encoding>UTF-8</encoding>
<configLocation>style/checkstyle.xml</configLocation>
<failOnViolation>true</failOnViolation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<sourceDirectories>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
</sourceDirectories>
<excludes>**\/generated-sources\/</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.45</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>

Expand Down Expand Up @@ -649,10 +616,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
Expand Down Expand Up @@ -996,13 +959,6 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
Expand Down

0 comments on commit 8ab0e6d

Please sign in to comment.