forked from DataLinkDC/dinky
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
302 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
dlink-admin/src/main/java/com/dlink/controller/APIController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.dlink.controller; | ||
|
||
import com.dlink.common.result.Result; | ||
import com.dlink.dto.APIExecuteSqlDTO; | ||
import com.dlink.job.JobResult; | ||
import com.dlink.service.APIService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* APIController | ||
* | ||
* @author wenmo | ||
* @since 2021/12/11 21:44 | ||
*/ | ||
@Slf4j | ||
@RestController | ||
@RequestMapping("/openapi") | ||
public class APIController { | ||
|
||
@Autowired | ||
private APIService apiService; | ||
@PostMapping("/executeSql") | ||
|
||
public Result executeSql(@RequestBody APIExecuteSqlDTO apiExecuteSqlDTO) { | ||
return Result.succeed(apiService.executeSql(apiExecuteSqlDTO),"执行成功"); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
dlink-admin/src/main/java/com/dlink/dto/APIExecuteSqlDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.dlink.dto; | ||
|
||
import com.dlink.assertion.Asserts; | ||
import com.dlink.gateway.config.GatewayConfig; | ||
import com.dlink.job.JobConfig; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* APIExecuteSqlDTO | ||
* | ||
* @author wenmo | ||
* @since 2021/12/11 21:50 | ||
*/ | ||
@Getter | ||
@Setter | ||
public class APIExecuteSqlDTO { | ||
// RUN_MODE | ||
private String type; | ||
private boolean useResult = false; | ||
private boolean useStatementSet = false; | ||
private String address; | ||
private boolean fragment = false; | ||
private String statement; | ||
private String jobName; | ||
private Integer maxRowNum = 100; | ||
private Integer checkPoint = 0; | ||
private Integer parallelism; | ||
private String savePointPath; | ||
private Map<String, String> configuration; | ||
private GatewayConfig gatewayConfig; | ||
|
||
private static final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
public JobConfig getJobConfig() { | ||
Integer savePointStrategy = 0; | ||
if (Asserts.isNotNullString(savePointPath)) { | ||
savePointStrategy = 3; | ||
} | ||
return new JobConfig( | ||
type, useResult, false, null, true, address, jobName, | ||
fragment, useStatementSet, maxRowNum, checkPoint, parallelism, savePointStrategy, | ||
savePointPath, configuration, gatewayConfig); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
dlink-admin/src/main/java/com/dlink/result/APIJobResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.dlink.result; | ||
|
||
import com.dlink.job.Job; | ||
import com.dlink.job.JobResult; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* APIJobResult | ||
* | ||
* @author wenmo | ||
* @since 2021/12/11 22:49 | ||
*/ | ||
@Getter | ||
@Setter | ||
public class APIJobResult { | ||
private String jobManagerAddress; | ||
private Job.JobStatus status; | ||
private boolean success; | ||
private String jobId; | ||
private String error; | ||
private LocalDateTime startTime; | ||
private LocalDateTime endTime; | ||
|
||
public APIJobResult(String jobManagerAddress, Job.JobStatus status, boolean success, String jobId, String error, LocalDateTime startTime, LocalDateTime endTime) { | ||
this.jobManagerAddress = jobManagerAddress; | ||
this.status = status; | ||
this.success = success; | ||
this.jobId = jobId; | ||
this.error = error; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
} | ||
|
||
public static APIJobResult build(JobResult jobResult){ | ||
return new APIJobResult(jobResult.getJobManagerAddress(),jobResult.getStatus(),jobResult.isSuccess(), | ||
jobResult.getJobId(),jobResult.getError(),jobResult.getStartTime(),jobResult.getEndTime()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
dlink-admin/src/main/java/com/dlink/service/APIService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.dlink.service; | ||
|
||
import com.dlink.dto.APIExecuteSqlDTO; | ||
import com.dlink.result.APIJobResult; | ||
|
||
/** | ||
* APIService | ||
* | ||
* @author wenmo | ||
* @since 2021/12/11 21:45 | ||
*/ | ||
public interface APIService { | ||
|
||
APIJobResult executeSql(APIExecuteSqlDTO apiExecuteSqlDTO); | ||
} |
30 changes: 30 additions & 0 deletions
30
dlink-admin/src/main/java/com/dlink/service/impl/APIServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.dlink.service.impl; | ||
|
||
import com.dlink.dto.APIExecuteSqlDTO; | ||
import com.dlink.job.JobConfig; | ||
import com.dlink.job.JobManager; | ||
import com.dlink.job.JobResult; | ||
import com.dlink.result.APIJobResult; | ||
import com.dlink.service.APIService; | ||
import com.dlink.utils.RunTimeUtil; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* APIServiceImpl | ||
* | ||
* @author wenmo | ||
* @since 2021/12/11 21:46 | ||
*/ | ||
@Service | ||
public class APIServiceImpl implements APIService { | ||
|
||
@Override | ||
public APIJobResult executeSql(APIExecuteSqlDTO apiExecuteSqlDTO) { | ||
JobConfig config = apiExecuteSqlDTO.getJobConfig(); | ||
JobManager jobManager = JobManager.build(config); | ||
JobResult jobResult = jobManager.executeSql(apiExecuteSqlDTO.getStatement()); | ||
APIJobResult apiJobResult = APIJobResult.build(jobResult); | ||
RunTimeUtil.recovery(jobManager); | ||
return apiJobResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
dlink-admin/src/main/resources/json/openapi_executesql_perjob.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* http://127.0.0.1:8888/openapi/executeSql */ | ||
{ | ||
/* required-start */ | ||
"type":"yarn-per-job", | ||
"statement":"CREATE TABLE Orders (\r\n order_number INT,\r\n price DECIMAL(32,2),\r\n order_time TIMESTAMP(3)\r\n) WITH (\r\n 'connector' = 'datagen',\r\n 'rows-per-second' = '1',\r\n 'fields.order_number.kind' = 'sequence',\r\n 'fields.order_number.start' = '1',\r\n 'fields.order_number.end' = '1000'\r\n);\r\nCREATE TABLE pt (\r\nordertotal INT,\r\nnumtotal INT\r\n) WITH (\r\n 'connector' = 'print'\r\n);\r\ninsert into pt select 1 as ordertotal ,sum(order_number)*2 as numtotal from Orders", | ||
"gatewayConfig":{ | ||
"clusterConfig":{ | ||
"flinkConfigPath":"/opt/src/flink-1.13.3_conf/conf", | ||
"flinkLibPath":"hdfs:///flink13/lib/flinklib", | ||
"yarnConfigPath":"/usr/local/hadoop/hadoop-2.7.7/etc/hadoop" | ||
}, | ||
"flinkConfig": { | ||
"configuration":{ | ||
"parallelism.default": 1 | ||
} | ||
} | ||
}, | ||
/* required-end */ | ||
/* default-start */ | ||
"useResult":false, | ||
"useStatementSet":false, | ||
"fragment":false, | ||
"maxRowNum":100, | ||
"checkPoint":0, | ||
"parallelism":1, | ||
/* default-start */ | ||
/* custom-start */ | ||
"jobName":"openapitest", | ||
"savePointPath":"hdfs://ns/flink/savepoints/savepoint-5f4b8c-4326844a6843", | ||
"configuration":{ | ||
"table.exec.resource.default-parallelism":2 | ||
} | ||
/* custom-end */ | ||
} |
23 changes: 23 additions & 0 deletions
23
dlink-admin/src/main/resources/json/openapi_executesql_yarnsession.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* http://127.0.0.1:8888/openapi/executeSql */ | ||
{ | ||
/* required-start */ | ||
"type":"yarn-session", | ||
"address":"10.1.51.24:8081", | ||
"statement":"CREATE TABLE Orders (\r\n order_number INT,\r\n price DECIMAL(32,2),\r\n order_time TIMESTAMP(3)\r\n) WITH (\r\n 'connector' = 'datagen',\r\n 'rows-per-second' = '1',\r\n 'fields.order_number.kind' = 'sequence',\r\n 'fields.order_number.start' = '1',\r\n 'fields.order_number.end' = '1000'\r\n);\r\nCREATE TABLE pt (\r\nordertotal INT,\r\nnumtotal INT\r\n) WITH (\r\n 'connector' = 'print'\r\n);\r\ninsert into pt select 1 as ordertotal ,sum(order_number)*2 as numtotal from Orders", | ||
/* required-end */ | ||
/* default-start */ | ||
"useResult":false, | ||
"useStatementSet":false, | ||
"fragment":false, | ||
"maxRowNum":100, | ||
"checkPoint":0, | ||
"parallelism":1, | ||
/* default-start */ | ||
/* custom-start */ | ||
"jobName":"openapitest", | ||
"savePointPath":"hdfs://ns/flink/savepoints/savepoint-5f4b8c-4326844a6843", | ||
"configuration":{ | ||
"table.exec.resource.default-parallelism":2 | ||
} | ||
/* custom-end */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
dlink-core/src/main/java/com/dlink/utils/DateFormatUtil.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.