Unverified Commit 7ea8cab6 authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Feature-2622][core] Local task supports cancel (#2623)

parent 963cb1d2
...@@ -129,7 +129,7 @@ public class Job2MysqlHandler implements JobHandler { ...@@ -129,7 +129,7 @@ public class Job2MysqlHandler implements JobHandler {
history.setStatus(job.getStatus().getCode()); history.setStatus(job.getStatus().getCode());
history.setJobId(job.getJobId()); history.setJobId(job.getJobId());
history.setEndTime(job.getEndTime()); history.setEndTime(job.getEndTime());
history.setJobManagerAddress(job.isUseGateway() ? job.getJobManagerAddress() : null); history.setJobManagerAddress(job.getJobManagerAddress());
Integer clusterId = job.getJobConfig().getClusterId(); Integer clusterId = job.getJobConfig().getClusterId();
ClusterInstance clusterInstance; ClusterInstance clusterInstance;
......
...@@ -100,6 +100,9 @@ public class ClusterInstanceServiceImpl extends SuperServiceImpl<ClusterInstance ...@@ -100,6 +100,9 @@ public class ClusterInstanceServiceImpl extends SuperServiceImpl<ClusterInstance
port = Integer.valueOf(flinkConfig.get("rest.port")); port = Integer.valueOf(flinkConfig.get("rest.port"));
} else { } else {
port = URLUtils.getRandomPort(); port = URLUtils.getRandomPort();
while (!IpUtils.isPortAvailable(port)) {
port = URLUtils.getRandomPort();
}
} }
return buildLocalEnvironmentAddress(port); return buildLocalEnvironmentAddress(port);
} }
......
...@@ -225,7 +225,13 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen ...@@ -225,7 +225,13 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
config.setClusterId(jobInstance.getClusterId()); config.setClusterId(jobInstance.getClusterId());
} }
} else if (GatewayType.LOCAL.equalsValue(task.getType())) { } else if (GatewayType.LOCAL.equalsValue(task.getType())) {
if (task.getJobInstanceId() == null) {
config.setClusterId(null); config.setClusterId(null);
} else {
JobInstance jobInstance = jobInstanceService.getById(task.getJobInstanceId());
config.setClusterId(jobInstance.getClusterId());
config.setUseRemote(true);
}
config.setClusterConfigurationId(null); config.setClusterConfigurationId(null);
} else { } else {
Optional.ofNullable(task.getClusterId()).ifPresent(config::setClusterId); Optional.ofNullable(task.getClusterId()).ifPresent(config::setClusterId);
......
...@@ -22,6 +22,7 @@ package org.dinky.utils; ...@@ -22,6 +22,7 @@ package org.dinky.utils;
import org.dinky.assertion.Asserts; import org.dinky.assertion.Asserts;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -171,6 +172,16 @@ public class IpUtils { ...@@ -171,6 +172,16 @@ public class IpUtils {
return "127.0.0.1"; return "127.0.0.1";
} }
public static boolean isPortAvailable(int port) {
try (ServerSocket serverSocket = new ServerSocket(port)) {
// If the code reaches this point, the port is available
return true;
} catch (Exception e) {
// Port is not available
return false;
}
}
public static String getHostName() { public static String getHostName() {
try { try {
return InetAddress.getLocalHost().getHostName(); return InetAddress.getLocalHost().getHostName();
......
...@@ -107,6 +107,6 @@ public class URLUtils { ...@@ -107,6 +107,6 @@ public class URLUtils {
public static int getRandomPort() { public static int getRandomPort() {
Random random = new Random(); Random random = new Random();
return random.nextInt(65536); return 30000 + random.nextInt(35536);
} }
} }
...@@ -237,7 +237,7 @@ public class JobConfig { ...@@ -237,7 +237,7 @@ public class JobConfig {
} }
public boolean isUseRemote() { public boolean isUseRemote() {
return !GatewayType.LOCAL.equalsValue(type); return useRemote || !GatewayType.LOCAL.equalsValue(type);
} }
public void buildLocal() { public void buildLocal() {
......
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