Skip to content

Commit aee1d42

Browse files
author
yanxi0227
committed
find jar name
1 parent 6b0ee91 commit aee1d42

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

core/src/main/java/com/dtstack/flink/sql/util/PluginUtil.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
package com.dtstack.flink.sql.util;
2222

2323
import com.dtstack.flink.sql.classloader.DtClassLoader;
24+
import org.apache.commons.lang3.StringUtils;
2425
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerationException;
2526
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException;
2627
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException;
2728
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
2829

2930
import java.io.ByteArrayInputStream;
3031
import java.io.File;
32+
import java.io.FilenameFilter;
3133
import java.io.IOException;
3234
import java.net.MalformedURLException;
3335
import java.net.URL;
@@ -105,15 +107,19 @@ public static Properties stringToProperties(String str) throws IOException{
105107
return properties;
106108
}
107109

108-
public static URL getRemoteJarFilePath(String pluginType, String tableType, String remoteSqlRootDir) throws MalformedURLException {
110+
public static URL getRemoteJarFilePath(String pluginType, String tableType, String remoteSqlRootDir) throws Exception {
109111
String dirName = pluginType + tableType.toLowerCase();
110-
String jarName = String.format("%s-%s.jar", pluginType, tableType.toLowerCase());
112+
String prefix = String.format("%s-%s", pluginType, tableType.toLowerCase());
113+
String jarPath = remoteSqlRootDir + SP + dirName;
114+
String jarName = getCoreJarFileName(jarPath, prefix);
111115
return new URL("file:" + remoteSqlRootDir + SP + dirName + SP + jarName);
112116
}
113117

114-
public static URL getRemoteSideJarFilePath(String pluginType, String sideOperator, String tableType, String remoteSqlRootDir) throws MalformedURLException {
118+
public static URL getRemoteSideJarFilePath(String pluginType, String sideOperator, String tableType, String remoteSqlRootDir) throws Exception {
115119
String dirName = pluginType + sideOperator + tableType.toLowerCase();
116-
String jarName = String.format("%s-%s-%s.jar", pluginType, sideOperator, tableType.toLowerCase());
120+
String prefix = String.format("%s-%s-%s", pluginType, sideOperator, tableType.toLowerCase());
121+
String jarPath = remoteSqlRootDir + SP + dirName;
122+
String jarName = getCoreJarFileName(jarPath, prefix);
117123
return new URL("file:" + remoteSqlRootDir + SP + dirName + SP + jarName);
118124
}
119125

@@ -138,4 +144,27 @@ public static void addPluginJar(String pluginDir, DtClassLoader classLoader) thr
138144
}
139145
}
140146

147+
public static String getCoreJarFileName (String path, String prefix) throws Exception {
148+
String coreJarFileName = null;
149+
File pluginDir = new File(path);
150+
if (pluginDir.exists() && pluginDir.isDirectory()){
151+
File[] jarFiles = pluginDir.listFiles(new FilenameFilter() {
152+
@Override
153+
public boolean accept(File dir, String name) {
154+
return name.toLowerCase().startsWith(prefix) && name.toLowerCase().endsWith(".jar");
155+
}
156+
});
157+
158+
if (jarFiles != null && jarFiles.length > 0){
159+
coreJarFileName = jarFiles[0].getName();
160+
}
161+
}
162+
163+
if (StringUtils.isEmpty(coreJarFileName)){
164+
throw new Exception("Can not find core jar file in path:" + path);
165+
}
166+
167+
return coreJarFileName;
168+
}
169+
141170
}

launcher/src/main/java/com/dtstack/flink/sql/launcher/LauncherMain.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.dtstack.flink.sql.ClusterMode;
2727
import com.dtstack.flink.sql.Main;
2828
import com.dtstack.flink.sql.launcher.perjob.PerJobSubmitter;
29+
import com.dtstack.flink.sql.util.PluginUtil;
2930
import org.apache.flink.client.program.ClusterClient;
3031
import org.apache.flink.client.program.PackagedProgram;
3132
import org.apache.flink.client.program.PackagedProgramUtils;
@@ -52,13 +53,14 @@
5253
*/
5354

5455
public class LauncherMain {
55-
private static final String CORE_JAR = "core.jar";
56+
private static final String CORE_JAR = "core";
5657

5758
private static String SP = File.separator;
5859

5960

60-
private static String getLocalCoreJarPath(String localSqlRootJar){
61-
return localSqlRootJar + SP + CORE_JAR;
61+
private static String getLocalCoreJarPath(String localSqlRootJar) throws Exception {
62+
String jarPath = PluginUtil.getCoreJarFileName(localSqlRootJar, CORE_JAR);
63+
return jarPath;
6264
}
6365

6466
public static void main(String[] args) throws Exception {

0 commit comments

Comments
 (0)