public static void main()

in streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/util/BashJavaUtils.java [44:131]


    public static void main(String[] args) throws IOException {
        String action = args[0].toLowerCase();
        String[] actionArgs = Arrays.copyOfRange(args, 1, args.length);

        switch (action) {
            case "--get_yaml":
                String key = actionArgs[0];
                String conf = actionArgs[1];
                Map<String, String> confMap = PropertiesUtils.fromYamlFileAsJava(conf);
                String value = confMap.get(key);
                System.out.println(value);
                break;
            case "--check_port":
                int port = Integer.parseInt(actionArgs[0]);
                try (Socket ignored = new Socket(localhost, port)) {
                    System.out.println("used");
                } catch (Exception e) {
                    System.out.println("free");
                }
                break;
            case "--free_port":
                int start = Integer.parseInt(actionArgs[0]);
                for (port = start; port < 65535; port++) {
                    try (Socket ignored = new Socket(localhost, port)) {
                    } catch (Exception e) {
                        System.out.println(port);
                        break;
                    }
                }
                break;
            case "--read_flink":
                String input = actionArgs[0];
                String[] inputs = input.split(":");
                String flinkDist = Arrays.stream(inputs).filter(c -> c.contains("flink-dist-")).findFirst().get();
                File flinkHome = new File(flinkDist.replaceAll("/lib/.*", ""));
                FlinkVersion flinkVersion = new FlinkVersion(flinkHome.getAbsolutePath());

                PrintStream originalOut = System.out;
                System.setOut(new PrintStream(new NullOutputStream()));

                String version = flinkVersion.majorVersion();
                float ver = Float.parseFloat(version);
                File yaml = new File(flinkHome, ver < 1.19f ? "/conf/flink-conf.yaml" : "/conf/config.yaml");

                Map<String, String> config = PropertiesUtils.fromYamlFileAsJava(yaml.getAbsolutePath());
                String flinkPort = config.getOrDefault("rest.port", "8081");
                System.setOut(originalOut);
                System.out.println(
                    flinkHome
                        .getAbsolutePath()
                        .concat(",")
                        .concat(flinkHome.getName())
                        .concat(",")
                        .concat(flinkPort));
                break;
            case "--replace":
                String filePath = actionArgs[0];
                String[] text = actionArgs[1].split("\\|\\|");
                String searchText = text[0];
                String replaceText = text[1];
                try {
                    File file = new File(filePath);
                    String content = FileUtils.readString(file);
                    content = content.replace(searchText, replaceText);
                    FileWriter writer = new FileWriter(filePath);
                    writer.write(content);
                    writer.flush();
                    writer.close();
                    System.exit(0);
                } catch (IOException e) {
                    System.exit(1);
                }
                break;
            case "--download":
                try {
                    URL url = new URL(actionArgs[0]);
                    Path path = Paths.get(actionArgs[1]).toAbsolutePath().normalize();
                    try (InputStream inStream = url.openStream()) {
                        Files.copy(inStream, path, StandardCopyOption.REPLACE_EXISTING);
                    }
                } catch (Exception e) {
                    System.exit(1);
                }
                break;
            default:
                break;
        }
    }