Commit 2767b4b5 authored by wenmo's avatar wenmo

gateway format

parent 7698c3e4
...@@ -20,14 +20,14 @@ import java.util.ServiceLoader; ...@@ -20,14 +20,14 @@ import java.util.ServiceLoader;
**/ **/
public interface Gateway { public interface Gateway {
static Optional<Gateway> get(GatewayConfig config){ static Optional<Gateway> get(GatewayConfig config) {
Asserts.checkNotNull(config,"配置不能为空"); Asserts.checkNotNull(config, "配置不能为空");
Asserts.checkNotNull(config.getType(),"配置类型不能为空"); Asserts.checkNotNull(config.getType(), "配置类型不能为空");
ServiceLoader<Gateway> loader = ServiceLoader.load(Gateway.class); ServiceLoader<Gateway> loader = ServiceLoader.load(Gateway.class);
Iterator<Gateway> iterator = loader.iterator(); Iterator<Gateway> iterator = loader.iterator();
while(iterator.hasNext()) { while (iterator.hasNext()) {
Gateway gateway = iterator.next(); Gateway gateway = iterator.next();
if(gateway.canHandle(config.getType())){ if (gateway.canHandle(config.getType())) {
gateway.setGatewayConfig(config); gateway.setGatewayConfig(config);
return Optional.of(gateway); return Optional.of(gateway);
} }
...@@ -35,10 +35,10 @@ public interface Gateway { ...@@ -35,10 +35,10 @@ public interface Gateway {
return Optional.empty(); return Optional.empty();
} }
static Gateway build(GatewayConfig config){ static Gateway build(GatewayConfig config) {
Optional<Gateway> optionalGateway = Gateway.get(config); Optional<Gateway> optionalGateway = Gateway.get(config);
if(!optionalGateway.isPresent()){ if (!optionalGateway.isPresent()) {
throw new GatewayException("不支持 Flink Gateway 类型【"+config.getType().getLongValue()+"】,请添加扩展包"); throw new GatewayException("不支持 Flink Gateway 类型【" + config.getType().getLongValue() + "】,请添加扩展包");
} }
return optionalGateway.get(); return optionalGateway.get();
} }
......
...@@ -8,12 +8,12 @@ import com.dlink.assertion.Asserts; ...@@ -8,12 +8,12 @@ import com.dlink.assertion.Asserts;
* @author wenmo * @author wenmo
* @since 2021/11/3 21:58 * @since 2021/11/3 21:58
*/ */
public enum ActionType{ public enum ActionType {
SAVEPOINT("savepoint"),CANCEL("cancel"); SAVEPOINT("savepoint"), CANCEL("cancel");
private String value; private String value;
ActionType(String value){ ActionType(String value) {
this.value = value; this.value = value;
} }
...@@ -21,9 +21,9 @@ public enum ActionType{ ...@@ -21,9 +21,9 @@ public enum ActionType{
return value; return value;
} }
public static ActionType get(String value){ public static ActionType get(String value) {
for (ActionType type : ActionType.values()) { for (ActionType type : ActionType.values()) {
if(Asserts.isEquals(type.getValue(),value)){ if (Asserts.isEquals(type.getValue(), value)) {
return type; return type;
} }
} }
......
...@@ -26,11 +26,11 @@ public class AppConfig { ...@@ -26,11 +26,11 @@ public class AppConfig {
this.userJarMainAppClass = userJarMainAppClass; this.userJarMainAppClass = userJarMainAppClass;
} }
public static AppConfig build(String userJarPath, String userJarParasStr, String userJarMainAppClass){ public static AppConfig build(String userJarPath, String userJarParasStr, String userJarMainAppClass) {
if(Asserts.isNotNullString(userJarParasStr)){ if (Asserts.isNotNullString(userJarParasStr)) {
return new AppConfig(userJarPath,userJarParasStr.split(" "),userJarMainAppClass); return new AppConfig(userJarPath, userJarParasStr.split(" "), userJarMainAppClass);
}else{ } else {
return new AppConfig(userJarPath,new String[]{},userJarMainAppClass); return new AppConfig(userJarPath, new String[]{}, userJarMainAppClass);
} }
} }
......
...@@ -7,9 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -7,9 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -36,42 +34,42 @@ public class GatewayConfig { ...@@ -36,42 +34,42 @@ public class GatewayConfig {
appConfig = new AppConfig(); appConfig = new AppConfig();
} }
public static GatewayConfig build(JsonNode para){ public static GatewayConfig build(JsonNode para) {
GatewayConfig config = new GatewayConfig(); GatewayConfig config = new GatewayConfig();
if(para.has("taskId")) { if (para.has("taskId")) {
config.setTaskId(para.get("taskId").asInt()); config.setTaskId(para.get("taskId").asInt());
} }
config.setType(GatewayType.get(para.get("type").asText())); config.setType(GatewayType.get(para.get("type").asText()));
if(para.has("flinkConfigPath")) { if (para.has("flinkConfigPath")) {
config.getClusterConfig().setFlinkConfigPath(para.get("flinkConfigPath").asText()); config.getClusterConfig().setFlinkConfigPath(para.get("flinkConfigPath").asText());
} }
if(para.has("flinkLibPath")) { if (para.has("flinkLibPath")) {
config.getClusterConfig().setFlinkLibPath(para.get("flinkLibPath").asText()); config.getClusterConfig().setFlinkLibPath(para.get("flinkLibPath").asText());
} }
if(para.has("yarnConfigPath")) { if (para.has("yarnConfigPath")) {
config.getClusterConfig().setYarnConfigPath(para.get("yarnConfigPath").asText()); config.getClusterConfig().setYarnConfigPath(para.get("yarnConfigPath").asText());
} }
if(para.has("jobName")) { if (para.has("jobName")) {
config.getFlinkConfig().setJobName(para.get("jobName").asText()); config.getFlinkConfig().setJobName(para.get("jobName").asText());
} }
if(para.has("userJarPath")) { if (para.has("userJarPath")) {
config.getAppConfig().setUserJarPath(para.get("userJarPath").asText()); config.getAppConfig().setUserJarPath(para.get("userJarPath").asText());
} }
if(para.has("userJarParas")) { if (para.has("userJarParas")) {
config.getAppConfig().setUserJarParas(para.get("userJarParas").asText().split("\\s+")); config.getAppConfig().setUserJarParas(para.get("userJarParas").asText().split("\\s+"));
} }
if(para.has("userJarMainAppClass")) { if (para.has("userJarMainAppClass")) {
config.getAppConfig().setUserJarMainAppClass(para.get("userJarMainAppClass").asText()); config.getAppConfig().setUserJarMainAppClass(para.get("userJarMainAppClass").asText());
} }
if(para.has("savePoint")) { if (para.has("savePoint")) {
config.getFlinkConfig().setSavePoint(para.get("savePoint").asText()); config.getFlinkConfig().setSavePoint(para.get("savePoint").asText());
} }
if(para.has("configParas")) { if (para.has("configParas")) {
try { try {
Map<String, String> configMap = new HashMap<>(); Map<String, String> configMap = new HashMap<>();
JsonNode paras = mapper.readTree(para.get("configParas").asText()); JsonNode paras = mapper.readTree(para.get("configParas").asText());
paras.forEach((JsonNode node)-> { paras.forEach((JsonNode node) -> {
configMap.put(node.get("key").asText(),node.get("value").asText()); configMap.put(node.get("key").asText(), node.get("value").asText());
} }
); );
config.getFlinkConfig().setConfiguration(configMap); config.getFlinkConfig().setConfiguration(configMap);
......
...@@ -8,12 +8,12 @@ import com.dlink.assertion.Asserts; ...@@ -8,12 +8,12 @@ import com.dlink.assertion.Asserts;
* @author wenmo * @author wenmo
* @since 2021/11/3 21:58 * @since 2021/11/3 21:58
*/ */
public enum SavePointType{ public enum SavePointType {
TRIGGER("trigger"),DISPOSE("dispose"),STOP("stop"),CANCEL("cancel"); TRIGGER("trigger"), DISPOSE("dispose"), STOP("stop"), CANCEL("cancel");
private String value; private String value;
SavePointType(String value){ SavePointType(String value) {
this.value = value; this.value = value;
} }
...@@ -21,9 +21,9 @@ public enum SavePointType{ ...@@ -21,9 +21,9 @@ public enum SavePointType{
return value; return value;
} }
public static SavePointType get(String value){ public static SavePointType get(String value) {
for (SavePointType type : SavePointType.values()) { for (SavePointType type : SavePointType.values()) {
if(Asserts.isEqualsIgnoreCase(type.getValue(),value)){ if (Asserts.isEqualsIgnoreCase(type.getValue(), value)) {
return type; return type;
} }
} }
......
...@@ -25,12 +25,12 @@ public class JobInfo { ...@@ -25,12 +25,12 @@ public class JobInfo {
this.status = status; this.status = status;
} }
public enum JobStatus{ public enum JobStatus {
RUN("run"),STOP("stop"),CANCEL("cancel"),FAIL("fail"); RUN("run"), STOP("stop"), CANCEL("cancel"), FAIL("fail");
private String value; private String value;
JobStatus(String value){ JobStatus(String value) {
this.value = value; this.value = value;
} }
} }
......
...@@ -34,12 +34,12 @@ public abstract class AbstractGatewayResult implements GatewayResult { ...@@ -34,12 +34,12 @@ public abstract class AbstractGatewayResult implements GatewayResult {
this.exceptionMsg = exceptionMsg; this.exceptionMsg = exceptionMsg;
} }
public void success(){ public void success() {
this.isSuccess = true; this.isSuccess = true;
this.endTime = LocalDateTime.now(); this.endTime = LocalDateTime.now();
} }
public void fail(String error){ public void fail(String error) {
this.isSuccess = false; this.isSuccess = false;
this.endTime = LocalDateTime.now(); this.endTime = LocalDateTime.now();
this.exceptionMsg = error; this.exceptionMsg = error;
......
...@@ -55,7 +55,7 @@ public class KubernetesResult extends AbstractGatewayResult { ...@@ -55,7 +55,7 @@ public class KubernetesResult extends AbstractGatewayResult {
this.jids = jids; this.jids = jids;
} }
public static KubernetesResult build(GatewayType type){ public static KubernetesResult build(GatewayType type) {
return new KubernetesResult(type,LocalDateTime.now()); return new KubernetesResult(type, LocalDateTime.now());
} }
} }
...@@ -43,8 +43,8 @@ public class SavePointResult extends AbstractGatewayResult { ...@@ -43,8 +43,8 @@ public class SavePointResult extends AbstractGatewayResult {
return null; return null;
} }
public static SavePointResult build(GatewayType type){ public static SavePointResult build(GatewayType type) {
return new SavePointResult(type,LocalDateTime.now()); return new SavePointResult(type, LocalDateTime.now());
} }
} }
...@@ -23,11 +23,11 @@ public class TestResult { ...@@ -23,11 +23,11 @@ public class TestResult {
this.error = error; this.error = error;
} }
public static TestResult success(){ public static TestResult success() {
return new TestResult(true,null); return new TestResult(true, null);
} }
public static TestResult fail(String error){ public static TestResult fail(String error) {
return new TestResult(false,error); return new TestResult(false, error);
} }
} }
package com.dlink.gateway.result; package com.dlink.gateway.result;
import com.dlink.gateway.GatewayType; import com.dlink.gateway.GatewayType;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
...@@ -52,8 +50,8 @@ public class YarnResult extends AbstractGatewayResult { ...@@ -52,8 +50,8 @@ public class YarnResult extends AbstractGatewayResult {
this.jids = jids; this.jids = jids;
} }
public static YarnResult build(GatewayType type){ public static YarnResult build(GatewayType type) {
return new YarnResult(type,LocalDateTime.now()); return new YarnResult(type, LocalDateTime.now());
} }
} }
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