|
53 | 53 | public enum PackagedProgramUtils {
|
54 | 54 | ;
|
55 | 55 |
|
| 56 | + private static final String SQL_DRIVER_CLASS_NAME = |
| 57 | + "org.apache.flink.table.runtime.application.SqlDriver"; |
| 58 | + |
56 | 59 | private static final String PYTHON_GATEWAY_CLASS_NAME =
|
57 | 60 | "org.apache.flink.client.python.PythonGatewayServer";
|
58 | 61 |
|
@@ -193,43 +196,21 @@ public static boolean isPython(String[] programArguments) {
|
193 | 196 | }
|
194 | 197 |
|
195 | 198 | public static URL getPythonJar() {
|
196 |
| - String flinkOptPath = System.getenv(ConfigConstants.ENV_FLINK_OPT_DIR); |
197 |
| - final List<Path> pythonJarPath = new ArrayList<>(); |
198 |
| - try { |
199 |
| - Files.walkFileTree( |
200 |
| - FileSystems.getDefault().getPath(flinkOptPath), |
201 |
| - new SimpleFileVisitor<Path>() { |
202 |
| - @Override |
203 |
| - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) |
204 |
| - throws IOException { |
205 |
| - FileVisitResult result = super.visitFile(file, attrs); |
206 |
| - if (file.getFileName().toString().startsWith("flink-python")) { |
207 |
| - pythonJarPath.add(file); |
208 |
| - } |
209 |
| - return result; |
210 |
| - } |
211 |
| - }); |
212 |
| - } catch (IOException e) { |
213 |
| - throw new RuntimeException( |
214 |
| - "Exception encountered during finding the flink-python jar. This should not happen.", |
215 |
| - e); |
216 |
| - } |
217 |
| - |
218 |
| - if (pythonJarPath.size() != 1) { |
219 |
| - throw new RuntimeException("Found " + pythonJarPath.size() + " flink-python jar."); |
220 |
| - } |
221 |
| - |
222 |
| - try { |
223 |
| - return pythonJarPath.get(0).toUri().toURL(); |
224 |
| - } catch (MalformedURLException e) { |
225 |
| - throw new RuntimeException("URL is invalid. This should not happen.", e); |
226 |
| - } |
| 199 | + return getOptJar("flink-python"); |
227 | 200 | }
|
228 | 201 |
|
229 | 202 | public static String getPythonDriverClassName() {
|
230 | 203 | return PYTHON_DRIVER_CLASS_NAME;
|
231 | 204 | }
|
232 | 205 |
|
| 206 | + public static boolean isSqlApplication(String entryPointClassName) { |
| 207 | + return (entryPointClassName != null) && (entryPointClassName.equals(SQL_DRIVER_CLASS_NAME)); |
| 208 | + } |
| 209 | + |
| 210 | + public static URL getSqlGatewayJar() { |
| 211 | + return getOptJar("flink-sql-gateway"); |
| 212 | + } |
| 213 | + |
233 | 214 | public static URI resolveURI(String path) throws URISyntaxException {
|
234 | 215 | final URI uri = new URI(path);
|
235 | 216 | if (uri.getScheme() != null) {
|
@@ -260,4 +241,39 @@ private static ProgramInvocationException generateException(
|
260 | 241 | stderr.length() == 0 ? "(none)" : stderr),
|
261 | 242 | cause);
|
262 | 243 | }
|
| 244 | + |
| 245 | + private static URL getOptJar(String jarName) { |
| 246 | + String flinkOptPath = System.getenv(ConfigConstants.ENV_FLINK_OPT_DIR); |
| 247 | + final List<Path> optJarPath = new ArrayList<>(); |
| 248 | + try { |
| 249 | + Files.walkFileTree( |
| 250 | + FileSystems.getDefault().getPath(flinkOptPath), |
| 251 | + new SimpleFileVisitor<Path>() { |
| 252 | + @Override |
| 253 | + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) |
| 254 | + throws IOException { |
| 255 | + FileVisitResult result = super.visitFile(file, attrs); |
| 256 | + if (file.getFileName().toString().startsWith(jarName)) { |
| 257 | + optJarPath.add(file); |
| 258 | + } |
| 259 | + return result; |
| 260 | + } |
| 261 | + }); |
| 262 | + } catch (IOException e) { |
| 263 | + throw new RuntimeException( |
| 264 | + "Exception encountered during finding the flink-python jar. This should not happen.", |
| 265 | + e); |
| 266 | + } |
| 267 | + |
| 268 | + if (optJarPath.size() != 1) { |
| 269 | + throw new RuntimeException( |
| 270 | + String.format("Found " + optJarPath.size() + " %s jar.", jarName)); |
| 271 | + } |
| 272 | + |
| 273 | + try { |
| 274 | + return optJarPath.get(0).toUri().toURL(); |
| 275 | + } catch (MalformedURLException e) { |
| 276 | + throw new RuntimeException("URL is invalid. This should not happen.", e); |
| 277 | + } |
| 278 | + } |
263 | 279 | }
|
0 commit comments