Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core][Starter] When use cluster mode, but starter app root dir also should same as client mode. #2141

Merged
merged 2 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.seatunnel.flink.util;

import org.apache.seatunnel.common.utils.JsonUtils;
import org.apache.seatunnel.flink.enums.FormatType;

import org.apache.seatunnel.shade.com.typesafe.config.Config;
Expand Down Expand Up @@ -200,7 +199,6 @@ public static RowTypeInfo getTypeInformation(ObjectNode json) {
int size = json.size();
String[] fields = new String[size];
TypeInformation<?>[] informations = new TypeInformation[size];
Map<String, Object> jsonMap = JsonUtils.toMap(json);
int i = 0;
Iterator<Map.Entry<String, JsonNode>> nodeIterator = json.fields();
while (nodeIterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ private Common() {

private static DeployMode MODE;

private static boolean STARTER = false;

/**
* Set mode. return false in case of failure
*/
public static void setDeployMode(DeployMode mode) {
MODE = mode;
}

public static void setStarter(boolean inStarter) {
STARTER = inStarter;
}

public static DeployMode getDeployMode() {
return MODE;
}
Expand All @@ -54,7 +60,7 @@ public static DeployMode getDeployMode() {
* When running seatunnel in --master yarn or --master mesos, you can put plugins related files in plugins dir.
*/
public static Path appRootDir() {
if (DeployMode.CLIENT == MODE) {
if (DeployMode.CLIENT == MODE || STARTER) {
try {
String path = Common.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
path = new File(path).getPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class FlinkSqlStarter implements Starter {
FlinkSqlStarter(String[] args) {
this.flinkCommandArgs = CommandLineUtils.parseCommandArgs(args, FlinkJobType.SQL);
// set the deployment mode, used to get the job jar path.
Common.setStarter(true);
Common.setDeployMode(flinkCommandArgs.getDeployMode());
this.appJar = Common.appLibDir().resolve(APP_JAR_NAME).toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class FlinkStarter implements Starter {
this.flinkCommandArgs = CommandLineUtils.parseCommandArgs(args, FlinkJobType.JAR);
// set the deployment mode, used to get the job jar path.
Common.setDeployMode(flinkCommandArgs.getDeployMode());
Common.setStarter(true);
this.appJar = Common.appLibDir().resolve(APP_JAR_NAME).toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ private static SparkCommandArgs parseCommandArgs(String[] args) {
public List<String> buildCommands() throws IOException {
setSparkConf();
Common.setDeployMode(commandArgs.getDeployMode());
Common.setStarter(true);
this.jars.addAll(getPluginsJarDependencies());
this.jars.addAll(listJars(Common.appLibDir()));
this.jars.addAll(getConnectorJarDependencies());
this.appName = this.sparkConf.getOrDefault("spark.app.name", Constants.LOGO);
return buildFinal();
Expand Down Expand Up @@ -221,18 +221,6 @@ private List<Path> getConnectorJarDependencies() {
return pluginJars.stream().map(url -> new File(url.getPath()).toPath()).collect(Collectors.toList());
}

/**
* list jars in given directory
*/
private List<Path> listJars(Path dir) throws IOException {
try (Stream<Path> stream = Files.list(dir)) {
return stream
.filter(it -> !Files.isDirectory(it))
.filter(it -> it.getFileName().endsWith("jar"))
.collect(Collectors.toList());
}
}

/**
* build final spark-submit commands
*/
Expand Down Expand Up @@ -405,10 +393,9 @@ private ClusterModeSparkStarter(String[] args, SparkCommandArgs commandArgs) {
@Override
public List<String> buildCommands() throws IOException {
Common.setDeployMode(commandArgs.getDeployMode());
Common.setStarter(true);
Path pluginTarball = Common.pluginTarball();
if (Files.notExists(pluginTarball)) {
CompressionUtils.tarGzip(Common.pluginRootDir(), pluginTarball);
}
CompressionUtils.tarGzip(Common.pluginRootDir(), pluginTarball);
this.files.add(pluginTarball);
this.files.add(Paths.get(commandArgs.getConfigFile()));
return super.buildCommands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class FlinkStarter implements Starter {
this.flinkCommandArgs = CommandLineUtils.parseCommandArgs(args, FlinkJobType.JAR);
// set the deployment mode, used to get the job jar path.
Common.setDeployMode(flinkCommandArgs.getDeployMode());
Common.setStarter(true);
this.appJar = Common.appLibDir().resolve(APP_JAR_NAME).toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ private static SparkCommandArgs parseCommandArgs(String[] args) {
public List<String> buildCommands() throws IOException {
setSparkConf();
Common.setDeployMode(commandArgs.getDeployMode());
Common.setStarter(true);
this.jars.addAll(getPluginsJarDependencies());
this.jars.addAll(listJars(Common.appLibDir()));
this.jars.addAll(getConnectorJarDependencies());
this.appName = this.sparkConf.getOrDefault("spark.app.name", Constants.LOGO);
return buildFinal();
Expand Down Expand Up @@ -233,18 +233,6 @@ private List<Path> getConnectorJarDependencies() {
return pluginJars.stream().map(url -> new File(url.getPath()).toPath()).collect(Collectors.toList());
}

/**
* list jars in given directory
*/
private List<Path> listJars(Path dir) throws IOException {
try (Stream<Path> stream = Files.list(dir)) {
return stream
.filter(it -> !Files.isDirectory(it))
.filter(it -> it.getFileName().endsWith("jar"))
.collect(Collectors.toList());
}
}

/**
* build final spark-submit commands
*/
Expand Down Expand Up @@ -417,10 +405,9 @@ private ClusterModeSparkStarter(String[] args, SparkCommandArgs commandArgs) {
@Override
public List<String> buildCommands() throws IOException {
Common.setDeployMode(commandArgs.getDeployMode());
Common.setStarter(true);
Path pluginTarball = Common.pluginTarball();
if (Files.notExists(pluginTarball)) {
CompressionUtils.tarGzip(Common.pluginRootDir(), pluginTarball);
}
CompressionUtils.tarGzip(Common.pluginRootDir(), pluginTarball);
this.files.add(pluginTarball);
this.files.add(Paths.get(commandArgs.getConfigFile()));
return super.buildCommands();
Expand Down