Unverified Commit 3c0dae5e authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Feature-1364][admin,flink] Add local environment with web UI (#1365)

parent 635e4fae
......@@ -142,6 +142,18 @@ public class Job2MysqlHandler implements JobHandler {
if (Asserts.isNotNull(cluster)) {
clusterId = cluster.getId();
}
} else if (GatewayType.LOCAL.equalsValue(job.getJobConfig().getType())
&& Asserts.isNotNullString(job.getJobManagerAddress())) {
cluster = clusterService.registersCluster(Cluster.autoRegistersCluster(
job.getJobManagerAddress(),
job.getJobId(),
job.getJobConfig().getJobName() + LocalDateTime.now(),
job.getType().getLongValue(),
null,
taskId));
if (Asserts.isNotNull(cluster)) {
clusterId = cluster.getId();
}
} else {
cluster = clusterService.getById(clusterId);
}
......@@ -149,7 +161,8 @@ public class Job2MysqlHandler implements JobHandler {
history.setClusterId(clusterId);
historyService.updateById(history);
if (Asserts.isNullCollection(job.getJids()) || GatewayType.LOCAL.equalsValue(job.getJobConfig().getType())) {
if (Asserts.isNullCollection(job.getJids()) || (GatewayType.LOCAL.equalsValue(job.getJobConfig().getType())
&& Asserts.isNullString(job.getJobManagerAddress()))) {
return true;
}
......
......@@ -23,7 +23,6 @@ import com.dlink.assertion.Assert;
import com.dlink.cluster.FlinkCluster;
import com.dlink.cluster.FlinkClusterInfo;
import com.dlink.constant.FlinkConstant;
import com.dlink.constant.NetConstant;
import com.dlink.db.service.impl.SuperServiceImpl;
import com.dlink.mapper.ClusterMapper;
import com.dlink.model.Cluster;
......@@ -86,7 +85,7 @@ public class ClusterServiceImpl extends SuperServiceImpl<ClusterMapper, Cluster>
try {
InetAddress inetAddress = InetAddress.getLocalHost();
if (inetAddress != null) {
return inetAddress.getHostAddress() + NetConstant.COLON + FlinkConstant.FLINK_REST_DEFAULT_PORT;
return inetAddress.getHostAddress();
}
} catch (UnknownHostException e) {
e.printStackTrace();
......
......@@ -102,7 +102,7 @@ public class JobHistoryServiceImpl extends SuperServiceImpl<JobHistoryMapper, Jo
jobHistory.setId(id);
try {
JsonNode jobInfo = FlinkAPI.build(jobManagerHost).getJobInfo(jobId);
if (jobInfo.has(FlinkRestResultConstant.ERRORS)) {
if (Asserts.isNull(jobInfo) || jobInfo.has(FlinkRestResultConstant.ERRORS)) {
final JobHistory dbHistory = getById(id);
if (Objects.nonNull(dbHistory)) {
jobHistory = dbHistory;
......
......@@ -229,7 +229,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
// init UDF
udfService.init(task.getStatement(), config);
loadDocker(id, config.getClusterConfigurationId(), config.getGatewayConfig());
if (GatewayType.KUBERNETES_APPLICATION.equalsValue(config.getType())) {
loadDocker(id, config.getClusterConfigurationId(), config.getGatewayConfig());
}
JobManager jobManager = JobManager.build(config);
process.start();
......@@ -247,6 +249,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
private void loadDocker(Integer taskId, Integer clusterConfigurationId, GatewayConfig gatewayConfig) {
Map dockerConfig = (Map) clusterConfigurationService.getClusterConfigById(clusterConfigurationId).getConfig()
.get("dockerConfig");
if (dockerConfig == null) {
return;
}
String params = SystemConfiguration.getInstances().getSqlSubmitJarParas()
+ buildParas(taskId, dockerConfig.getOrDefault("dinky.remote.addr", "").toString());
......@@ -535,6 +540,9 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
@Override
public JobStatus checkJobStatus(JobInfoDetail jobInfoDetail) {
JobConfig jobConfig = new JobConfig();
if (Asserts.isNull(jobInfoDetail.getClusterConfiguration())) {
return JobStatus.UNKNOWN;
}
Map<String, Object> gatewayConfigMap = clusterConfigurationService
.getGatewayConfig(jobInfoDetail.getClusterConfiguration().getId());
jobConfig.buildGatewayConfig(gatewayConfigMap);
......@@ -792,7 +800,6 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
String jobId = jobInstance.getJid();
boolean useGateway = false;
JobConfig jobConfig = new JobConfig();
jobConfig.setAddress(cluster.getJobManagerHost());
jobConfig.setType(cluster.getType());
Task task = this.getTaskInfoById(cluster.getTaskId());
......@@ -811,6 +818,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
useGateway = true;
}
jobConfig.setTaskId(jobInstance.getTaskId());
jobConfig.setAddress(cluster.getJobManagerHost());
JobManager jobManager = JobManager.build(jobConfig);
jobManager.setUseGateway(useGateway);
if ("canceljob".equals(savePointType)) {
......@@ -1287,7 +1295,8 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
String exceptionUrl = "http://" + jobManagerHost + "/#/job/" + jobInstance.getJid() + "/exceptions";
for (AlertInstance alertInstance : alertGroup.getInstances()) {
if (alertInstance == null || (Asserts.isNotNull(alertInstance.getEnabled()) && !alertInstance.getEnabled())) {
if (alertInstance == null
|| (Asserts.isNotNull(alertInstance.getEnabled()) && !alertInstance.getEnabled())) {
continue;
}
Map<String, String> map = JSONUtil.toMap(alertInstance.getParams());
......
......@@ -78,6 +78,11 @@ public class MysqlCDCBuilder extends AbstractCDCBuilder implements CDCBuilder {
String connectMaxRetries = config.getSource().get("connect.max-retries");
String connectionPoolSize = config.getSource().get("connection.pool.size");
String heartbeatInterval = config.getSource().get("heartbeat.interval");
String chunkSize = config.getSource().get("scan.incremental.snapshot.chunk.size");
String distributionFactorLower = config.getSource().get("chunk-key.even-distribution.factor.upper-bound");
String distributionFactorUpper = config.getSource().get("chunk-key.even-distribution.factor.lower-bound");
String scanNewlyAddedTableEnabled = config.getSource().get("scan.newly-added-table.enabled");
String schemaChanges = config.getSource().get("schema.changes");
Properties debeziumProperties = new Properties();
// 为部分转换添加默认值
......@@ -164,6 +169,26 @@ public class MysqlCDCBuilder extends AbstractCDCBuilder implements CDCBuilder {
sourceBuilder.heartbeatInterval(Duration.ofMillis(Long.valueOf(heartbeatInterval)));
}
if (Asserts.isAllNotNullString(chunkSize)) {
sourceBuilder.splitSize(Integer.parseInt(chunkSize));
}
if (Asserts.isNotNullString(distributionFactorLower)) {
sourceBuilder.distributionFactorLower(Double.valueOf(distributionFactorLower));
}
if (Asserts.isNotNullString(distributionFactorUpper)) {
sourceBuilder.distributionFactorUpper(Double.valueOf(distributionFactorUpper));
}
if (Asserts.isEqualsIgnoreCase(scanNewlyAddedTableEnabled, "true")) {
sourceBuilder.scanNewlyAddedTableEnabled(true);
}
if (Asserts.isEqualsIgnoreCase(schemaChanges, "true")) {
sourceBuilder.includeSchemaChanges(true);
}
return env.fromSource(sourceBuilder.build(), WatermarkStrategy.noWatermarks(), "MySQL CDC Source");
}
......
......@@ -45,6 +45,10 @@ public class Asserts {
return object == null;
}
public static boolean isAllNotNull(Object... object) {
return Arrays.stream(object).allMatch(Asserts::isNotNull);
}
public static boolean isNullString(String str) {
return isNull(str) || str.isEmpty();
}
......
......@@ -20,6 +20,7 @@
package com.dlink.job;
import com.dlink.assertion.Asserts;
import com.dlink.constant.NetConstant;
import com.dlink.executor.ExecutorSetting;
import com.dlink.function.data.model.UDF;
import com.dlink.gateway.GatewayType;
......@@ -31,6 +32,7 @@ import com.dlink.gateway.config.SavePointStrategy;
import com.dlink.session.SessionConfig;
import org.apache.flink.configuration.CoreOptions;
import org.apache.flink.configuration.RestOptions;
import org.apache.http.util.TextUtils;
import java.util.ArrayList;
......@@ -85,8 +87,17 @@ public class JobConfig {
public JobConfig() {
}
public void setAddress(String address) {
if (GatewayType.LOCAL.equalsValue(type) && Asserts.isNotNull(config)
&& config.containsKey(RestOptions.PORT.key())) {
this.address = address + NetConstant.COLON + config.get(RestOptions.PORT.key());
} else {
this.address = address;
}
}
public JobConfig(String type, boolean useSession, boolean useRemote, boolean useSqlFragment,
boolean useStatementSet, Integer parallelism, Map<String, String> config) {
boolean useStatementSet, Integer parallelism, Map<String, String> config) {
this.type = type;
this.useSession = useSession;
this.useRemote = useRemote;
......@@ -97,13 +108,13 @@ public class JobConfig {
}
public JobConfig(String type, boolean useResult, boolean useChangeLog, boolean useAutoCancel, boolean useSession,
String session, Integer clusterId,
Integer clusterConfigurationId, Integer jarId, Integer taskId, String jobName,
boolean useSqlFragment,
boolean useStatementSet, boolean useBatchModel, Integer maxRowNum, Integer checkpoint,
Integer parallelism,
Integer savePointStrategyValue, String savePointPath, Map<String, String> variables,
Map<String, String> config) {
String session, Integer clusterId,
Integer clusterConfigurationId, Integer jarId, Integer taskId, String jobName,
boolean useSqlFragment,
boolean useStatementSet, boolean useBatchModel, Integer maxRowNum, Integer checkpoint,
Integer parallelism,
Integer savePointStrategyValue, String savePointPath, Map<String, String> variables,
Map<String, String> config) {
this.type = type;
this.useResult = useResult;
this.useChangeLog = useChangeLog;
......@@ -129,11 +140,11 @@ public class JobConfig {
}
public JobConfig(String type, boolean useResult, boolean useChangeLog, boolean useAutoCancel, boolean useSession,
String session, boolean useRemote, String address,
String jobName, boolean useSqlFragment,
boolean useStatementSet, Integer maxRowNum, Integer checkpoint, Integer parallelism,
Integer savePointStrategyValue, String savePointPath, Map<String, String> config,
GatewayConfig gatewayConfig) {
String session, boolean useRemote, String address,
String jobName, boolean useSqlFragment,
boolean useStatementSet, Integer maxRowNum, Integer checkpoint, Integer parallelism,
Integer savePointStrategyValue, String savePointPath, Map<String, String> config,
GatewayConfig gatewayConfig) {
this.type = type;
this.useResult = useResult;
this.useChangeLog = useChangeLog;
......@@ -141,7 +152,6 @@ public class JobConfig {
this.useSession = useSession;
this.session = session;
this.useRemote = useRemote;
this.address = address;
this.jobName = jobName;
this.useSqlFragment = useSqlFragment;
this.useStatementSet = useStatementSet;
......@@ -152,10 +162,11 @@ public class JobConfig {
this.savePointPath = savePointPath;
this.config = config;
this.gatewayConfig = gatewayConfig;
setAddress(address);
}
public JobConfig(String type, boolean useResult, boolean useSession, String session, boolean useRemote,
Integer clusterId, Integer maxRowNum) {
Integer clusterId, Integer maxRowNum) {
this.type = type;
this.useResult = useResult;
this.useSession = useSession;
......@@ -166,12 +177,12 @@ public class JobConfig {
}
public JobConfig(String type, Integer step, boolean useResult, boolean useSession, boolean useRemote,
Integer clusterId,
Integer clusterConfigurationId, Integer jarId, Integer taskId, String jobName,
boolean useSqlFragment,
boolean useStatementSet, boolean useBatchModel, Integer checkpoint, Integer parallelism,
Integer savePointStrategyValue,
String savePointPath, Map<String, String> config) {
Integer clusterId,
Integer clusterConfigurationId, Integer jarId, Integer taskId, String jobName,
boolean useSqlFragment,
boolean useStatementSet, boolean useBatchModel, Integer checkpoint, Integer parallelism,
Integer savePointStrategyValue,
String savePointPath, Map<String, String> config) {
this.type = type;
this.step = step;
this.useResult = useResult;
......@@ -238,7 +249,8 @@ public class JobConfig {
if (config.containsKey("flinkConfig")
&& Asserts.isNotNullMap((Map<String, String>) config.get("flinkConfig"))) {
gatewayConfig.setFlinkConfig(FlinkConfig.build((Map<String, String>) config.get("flinkConfig")));
gatewayConfig.getFlinkConfig().getConfiguration().put(CoreOptions.DEFAULT_PARALLELISM.key(),String.valueOf(parallelism));
gatewayConfig.getFlinkConfig().getConfiguration().put(CoreOptions.DEFAULT_PARALLELISM.key(),
String.valueOf(parallelism));
}
if (config.containsKey("kubernetesConfig")) {
Map<String, String> kubernetesConfig = (Map<String, String>) config.get("kubernetesConfig");
......@@ -246,7 +258,8 @@ public class JobConfig {
}
// at present only k8s task have this
if (config.containsKey("taskCustomConfig")) {
Map<String, Map<String, String>> taskCustomConfig = (Map<String, Map<String, String>>) config.get("taskCustomConfig");
Map<String, Map<String, String>> taskCustomConfig = (Map<String, Map<String, String>>) config
.get("taskCustomConfig");
if (taskCustomConfig.containsKey("kubernetesConfig")) {
gatewayConfig.getFlinkConfig().getConfiguration().putAll(taskCustomConfig.get("kubernetesConfig"));
}
......
......@@ -20,7 +20,6 @@
package com.dlink.executor;
import com.dlink.assertion.Asserts;
import com.dlink.constant.FlinkConstant;
import com.dlink.constant.NetConstant;
import lombok.Getter;
......@@ -35,8 +34,9 @@ import lombok.Setter;
@Getter
@Setter
public class EnvironmentSetting {
private String host;
private int port;
private Integer port;
private String[] jarFiles;
private boolean useRemote;
......@@ -47,25 +47,34 @@ public class EnvironmentSetting {
this.useRemote = useRemote;
}
public EnvironmentSetting(String host, int port, String... jarFiles) {
public EnvironmentSetting(String... jarFiles) {
this.useRemote = false;
this.jarFiles = jarFiles;
}
public EnvironmentSetting(String host, Integer port, String... jarFiles) {
this.host = host;
this.port = port;
this.useRemote = true;
this.jarFiles = jarFiles;
}
public static EnvironmentSetting build(String address,String... jarFiles) {
public static EnvironmentSetting build(String address, String... jarFiles) {
Asserts.checkNull(address, "Flink 地址不能为空");
String[] strs = address.split(NetConstant.COLON);
if (strs.length >= 2) {
return new EnvironmentSetting(strs[0], Integer.parseInt(strs[1]),jarFiles);
return new EnvironmentSetting(strs[0], Integer.parseInt(strs[1]), jarFiles);
} else {
return new EnvironmentSetting(strs[0], FlinkConstant.FLINK_REST_DEFAULT_PORT,jarFiles);
return new EnvironmentSetting(jarFiles);
}
}
public String getAddress() {
return host + NetConstant.COLON + port;
if (Asserts.isAllNotNull(host, port)) {
return host + NetConstant.COLON + port;
} else {
return "";
}
}
}
......@@ -22,6 +22,7 @@ package com.dlink.executor;
import com.dlink.assertion.Asserts;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.RestOptions;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
/**
......@@ -36,8 +37,11 @@ public class LocalBatchExecutor extends Executor {
this.executorSetting = executorSetting;
if (Asserts.isNotNull(executorSetting.getConfig())) {
Configuration configuration = Configuration.fromMap(executorSetting.getConfig());
this.environment = StreamExecutionEnvironment.createLocalEnvironment(configuration);
} else {
if (configuration.contains(RestOptions.PORT)) {
this.environment = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration);
} else {
this.environment = StreamExecutionEnvironment.createLocalEnvironment(configuration);
} } else {
this.environment = StreamExecutionEnvironment.createLocalEnvironment();
}
init();
......
......@@ -22,6 +22,7 @@ package com.dlink.executor;
import com.dlink.assertion.Asserts;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.RestOptions;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
/**
......@@ -36,7 +37,11 @@ public class LocalStreamExecutor extends Executor {
this.executorSetting = executorSetting;
if (Asserts.isNotNull(executorSetting.getConfig())) {
Configuration configuration = Configuration.fromMap(executorSetting.getConfig());
this.environment = StreamExecutionEnvironment.createLocalEnvironment(configuration);
if (configuration.contains(RestOptions.PORT)) {
this.environment = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration);
} else {
this.environment = StreamExecutionEnvironment.createLocalEnvironment(configuration);
}
} else {
this.environment = StreamExecutionEnvironment.createLocalEnvironment();
}
......
......@@ -126,6 +126,11 @@
<artifactId>flink-connector-jdbc_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime-web_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
......
......@@ -126,6 +126,11 @@
<artifactId>flink-connector-jdbc_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime-web_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -154,5 +154,10 @@
<artifactId>flink-shaded-guava</artifactId>
<version>18.0-13.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime-web_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
</dependencies>
</project>
......@@ -188,5 +188,10 @@
<artifactId>flink-json</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime-web_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
</dependency>
</dependencies>
</project>
......@@ -163,6 +163,11 @@
<artifactId>flink-doris-connector-1.14_2.12</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime-web</artifactId>
<version>${flink.version}</version>
</dependency>
</dependencies>
</project>
......@@ -144,6 +144,10 @@
<artifactId>commons-cli</artifactId>
<version>${commons.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-runtime-web</artifactId>
<version>${flink.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
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