| 74 | |
| 75 | |
| 76 | def parse_java_app(java_app_class: str, java_jar_full_path: str): |
| 77 | _java_app_type = "" |
| 78 | _frag_param_str = "" |
| 79 | _java_inner_context_type = "" |
| 80 | _java_executable = "java" |
| 81 | if shutil.which("java") is None: |
| 82 | if os.environ.get("JAVA_HOME", None) is not None: |
| 83 | _java_executable = os.path.join(os.environ.get("JAVA_HOME"), "bin", "java") |
| 84 | if not os.path.isfile(_java_executable) or not os.access( |
| 85 | _java_executable, os.X_OK |
| 86 | ): |
| 87 | raise RuntimeError( |
| 88 | "Java executable not found, you shall install a java runtime." |
| 89 | ) |
| 90 | parse_user_app_cmd = [ |
| 91 | _java_executable, |
| 92 | "-cp", |
| 93 | "{}".format(java_jar_full_path), |
| 94 | "com.alibaba.graphscope.utils.AppBaseParser", |
| 95 | java_app_class, |
| 96 | ] |
| 97 | logger.info(" ".join(parse_user_app_cmd)) |
| 98 | parse_user_app_process = subprocess.Popen( |
| 99 | parse_user_app_cmd, |
| 100 | env=os.environ.copy(), |
| 101 | encoding="utf-8", |
| 102 | errors="replace", |
| 103 | stdout=subprocess.PIPE, |
| 104 | stderr=subprocess.PIPE, |
| 105 | universal_newlines=True, |
| 106 | bufsize=1, |
| 107 | ) |
| 108 | out, err = parse_user_app_process.communicate() |
| 109 | logger.info(err) |
| 110 | for line in out.split("\n"): |
| 111 | logger.info(line) |
| 112 | if len(line) == 0: |
| 113 | continue |
| 114 | if line.find("DefaultPropertyApp") != -1: |
| 115 | _java_app_type = "default_property" |
| 116 | elif line.find("ParallelPropertyApp") != -1: |
| 117 | _java_app_type = "parallel_property" |
| 118 | elif line.find("DefaultAppBase") != -1: |
| 119 | _java_app_type = "default_simple" |
| 120 | elif line.find("ParallelAppBase") != -1: |
| 121 | _java_app_type = "parallel_simple" |
| 122 | elif line.find("Error") != -1: |
| 123 | raise Exception("Error occurred in verifying user app") |
| 124 | elif line.find("TypeParams") != -1: |
| 125 | _frag_param_str = line.split(":")[-1].strip() |
| 126 | elif line.find("ContextType") != -1: |
| 127 | _java_inner_context_type = line.split(":")[-1].strip() |
| 128 | logger.info( |
| 129 | "Java app type: {}, frag type str: {}, ctx type: {}".format( |
| 130 | _java_app_type, _frag_param_str, _java_inner_context_type |
| 131 | ) |
| 132 | ) |
| 133 | |