-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix seatunnel-issue-6386 and windows specific starter cmd script bug #6735
Open
GangLiCN
wants to merge
1
commit into
apache:dev
Choose a base branch
from
GangLiCN:resync_from_base
base: dev
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...tunnel-core-starter/src/main/java/org/apache/seatunnel/core/starter/utils/SystemUtil.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 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.core.starter.utils; | ||
|
||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
public class SystemUtil { | ||
|
||
public static String GetOsType() { | ||
String os_type = ""; | ||
|
||
if (SystemUtils.IS_OS_WINDOWS) { | ||
os_type = "Windows"; | ||
} else if (SystemUtils.IS_OS_MAC) { | ||
os_type = "Mac"; | ||
} else if (SystemUtils.IS_OS_LINUX) { | ||
os_type = "Linux"; | ||
} else if (SystemUtils.IS_OS_SOLARIS) { | ||
os_type = "Solaris"; | ||
} else { | ||
os_type = "Unknown"; | ||
} | ||
|
||
return os_type; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import org.apache.seatunnel.core.starter.enums.EngineType; | ||
import org.apache.seatunnel.core.starter.flink.args.FlinkCommandArgs; | ||
import org.apache.seatunnel.core.starter.utils.CommandLineUtils; | ||
import org.apache.seatunnel.core.starter.utils.SystemUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
@@ -44,6 +45,7 @@ public class FlinkStarter implements Starter { | |
this.appJar = Common.appStarterDir().resolve(APP_JAR_NAME).toString(); | ||
} | ||
|
||
@SuppressWarnings("checkstyle:RegexpSingleline") | ||
public static void main(String[] args) { | ||
FlinkStarter flinkStarter = new FlinkStarter(args); | ||
System.out.println(String.join(" ", flinkStarter.buildCommands())); | ||
|
@@ -52,8 +54,46 @@ public static void main(String[] args) { | |
@Override | ||
public List<String> buildCommands() { | ||
List<String> command = new ArrayList<>(); | ||
String local_os_type = ""; | ||
|
||
SystemUtil my_system_util = new SystemUtil(); | ||
local_os_type = my_system_util.GetOsType(); | ||
// debug | ||
// System.out.println("OS type:"+local_os_type); | ||
|
||
String cmd_flink = ""; | ||
|
||
/* Nothe that "flink.cmd” or "flink.bat" can be retrieved from | ||
lower version of flink (e.g.1.0.9),We do not check if this | ||
file exists on the box, user needs to make sure this file | ||
exists or not. | ||
*/ | ||
switch (local_os_type.toLowerCase()) { | ||
case "windows": | ||
cmd_flink = "%FLINK_HOME%/bin/flink.bat"; | ||
break; | ||
case "linux": | ||
cmd_flink = "${FLINK_HOME}/bin/flink"; | ||
break; | ||
case "solaris": | ||
cmd_flink = "${FLINK_HOME}/bin/flink"; | ||
break; | ||
case "mac": | ||
cmd_flink = "${FLINK_HOME}/bin/flink"; | ||
break; | ||
case "unknown": | ||
cmd_flink = "error"; | ||
break; | ||
} | ||
|
||
// set start command | ||
command.add("${FLINK_HOME}/bin/flink"); | ||
if (!(cmd_flink.equals("error"))) { | ||
command.add(cmd_flink); | ||
} else { | ||
System.out.println("Error: Can not determine OS type, abort run !"); | ||
System.exit(-1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. System.exit(-1) is not recommended. The code causes some strange security problems; Throw an exception if there is a problem |
||
} | ||
|
||
// set deploy mode, run or run-application | ||
command.add(flinkCommandArgs.getDeployMode().getDeployMode()); | ||
// set submitted target master | ||
|
@@ -91,6 +131,8 @@ public List<String> buildCommands() { | |
.filter(Objects::nonNull) | ||
.map(String::trim) | ||
.forEach(variable -> command.add("-D" + variable)); | ||
// debug | ||
// System.out.println("Whole command string:" + command.toString()); | ||
Comment on lines
+134
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
return command; | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
...n/src/test/java/org/apache/seatunnel/core/starter/flink/TestFlinkJobCommandReturnV13.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,128 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.core.starter.flink; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.Properties; | ||
|
||
public class TestFlinkJobCommandReturnV13 { | ||
@Test | ||
public void testSparkJobCommandReturnV13() throws Exception { | ||
String flink_job_command = null; | ||
String flink_job_command_return = null; | ||
String flink_job_command_return_error = null; | ||
String flink_home_dir = null; | ||
String flink_submit_job_cmd = null; | ||
String seatunnel_home_dir = null; | ||
String seatunnel_submit_flink_job_jar_list = null; | ||
String seatunnel_submit_flink_job_cmd = null; | ||
String seatunnel_submit_flink_job_cmd_paras = null; | ||
String seatunnel_submit_flink_job_cmd_full_path = null; | ||
|
||
StringBuilder sb_cmd_final = new StringBuilder(); | ||
String seatunnel_submit_flink_job_cmd_final = null; | ||
|
||
final String separator = "/"; | ||
Properties prop = new Properties(); | ||
|
||
try { | ||
InputStream in = | ||
this.getClass() | ||
.getClassLoader() | ||
.getResourceAsStream("flink13-job-command.properties"); | ||
if (in == null) { | ||
throw new FileNotFoundException( | ||
"Resource file not found. Make sure the file exists in src/test/resources."); | ||
} | ||
prop.load(in); | ||
|
||
flink_home_dir = prop.getProperty("FLINK13_HOME"); | ||
flink_submit_job_cmd = prop.getProperty("FLINK13_SUBMIT_JOB_CMD"); | ||
seatunnel_home_dir = prop.getProperty("SEATUNNEL_HOME"); | ||
seatunnel_submit_flink_job_jar_list = | ||
prop.getProperty("SEATUNNEL_SUBMIT_FLINK13_JOB_JAR_LIST"); | ||
seatunnel_submit_flink_job_cmd = prop.getProperty("SEATUNNEL_SUBMIT_FLINK13_JOB_CMD"); | ||
|
||
sb_cmd_final.append(seatunnel_home_dir); | ||
sb_cmd_final.append(separator); | ||
sb_cmd_final.append("bin"); | ||
sb_cmd_final.append(separator); | ||
sb_cmd_final.append(seatunnel_submit_flink_job_cmd); | ||
sb_cmd_final.append(" --config "); | ||
sb_cmd_final.append(seatunnel_home_dir); | ||
sb_cmd_final.append(separator); | ||
sb_cmd_final.append("/config/v2.streaming.conf.template"); | ||
|
||
seatunnel_submit_flink_job_cmd_final = sb_cmd_final.toString(); | ||
// debug | ||
// System.out.println("Final command:" + seatunnel_submit_flink_job_cmd_final); | ||
|
||
Process process = Runtime.getRuntime().exec(seatunnel_submit_flink_job_cmd_final); | ||
process.waitFor(); // wait for the command to finish | ||
|
||
// Read the stdout of command | ||
flink_job_command_return = readStream(process.getInputStream()); | ||
|
||
// Read the stderror of command | ||
flink_job_command_return_error = readStream(process.getErrorStream()); | ||
Assertions.assertNotNull(flink_job_command_return); | ||
Assertions.assertNull(flink_job_command_return_error); | ||
|
||
/* if (flink_job_command_return_error == null) { | ||
System.out.println("Seatunnel flink job submutted successfully."); | ||
} else { | ||
System.out.println("Seatunnel flink job submutted failed, error messages is:"); | ||
System.out.println(flink_job_command_return_error); | ||
} | ||
*/ | ||
|
||
process.destroy(); | ||
// debug | ||
System.out.println( | ||
"Auto closed [start-seatunnel-flink-13-connector-v2.cmd] successfully."); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private static String readStream(InputStream inputStream) throws IOException { | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { | ||
String line; | ||
StringBuilder sb = new StringBuilder(); | ||
String str_final = ""; | ||
|
||
while ((line = reader.readLine()) != null) { | ||
System.out.println(line); | ||
sb.append(line); | ||
} | ||
str_final = sb.toString(); | ||
if (!(str_final.isEmpty())) { | ||
return str_final; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GangLiCN Please delete these useless codes