| 123 | |
| 124 | |
| 125 | def init_storm_env(within_unittest=False): |
| 126 | |
| 127 | global NORMAL_CLASS_PATH, STORM_DIR, USER_CONF_DIR, STORM_CONF_DIR, STORM_WORKER_LIB_DIR, STORM_LIB_DIR,\ |
| 128 | STORM_TOOLS_LIB_DIR, STORM_WEBAPP_LIB_DIR, STORM_BIN_DIR, STORM_LOG4J2_CONF_DIR, STORM_SUPERVISOR_LOG_FILE,\ |
| 129 | CLUSTER_CONF_DIR, JAR_JVM_OPTS, JAVA_HOME, JAVA_CMD, CONF_FILE, STORM_EXT_CLASSPATH, \ |
| 130 | STORM_EXT_CLASSPATH_DAEMON, LOCAL_TTL_DEFAULT |
| 131 | |
| 132 | NORMAL_CLASS_PATH = cygpath if sys.platform == 'cygwin' else identity |
| 133 | STORM_DIR = os.sep.join(os.path.realpath( __file__ ).split(os.sep)[:-2]) |
| 134 | USER_CONF_DIR = os.path.expanduser("~" + os.sep + ".storm") |
| 135 | STORM_CONF_DIR = os.getenv('STORM_CONF_DIR', None) |
| 136 | |
| 137 | CLUSTER_CONF_DIR = STORM_CONF_DIR if STORM_CONF_DIR else os.path.join(STORM_DIR, "conf") |
| 138 | |
| 139 | if not os.path.isfile(os.path.join(USER_CONF_DIR, "storm.yaml")): |
| 140 | USER_CONF_DIR = CLUSTER_CONF_DIR |
| 141 | |
| 142 | STORM_WORKER_LIB_DIR = os.path.join(STORM_DIR, "lib-worker") |
| 143 | STORM_LIB_DIR = os.path.join(STORM_DIR, "lib") |
| 144 | |
| 145 | STORM_TOOLS_LIB_DIR = os.path.join(STORM_DIR, "lib-tools") |
| 146 | STORM_WEBAPP_LIB_DIR = os.path.join(STORM_DIR, "lib-webapp") |
| 147 | STORM_BIN_DIR = os.path.join(STORM_DIR, "bin") |
| 148 | STORM_LOG4J2_CONF_DIR = os.path.join(STORM_DIR, "log4j2") |
| 149 | STORM_SUPERVISOR_LOG_FILE = os.getenv('STORM_SUPERVISOR_LOG_FILE', "supervisor.log") |
| 150 | |
| 151 | CONF_FILE = "" |
| 152 | JAR_JVM_OPTS = shlex.split(os.getenv('STORM_JAR_JVM_OPTS', '')) |
| 153 | JAVA_HOME = os.getenv('JAVA_HOME', None) |
| 154 | JAVA_CMD = get_java_cmd() |
| 155 | |
| 156 | if JAVA_HOME and not os.path.exists(JAVA_CMD): |
| 157 | print(f"ERROR: JAVA_HOME is invalid. Could not find bin/java at {JAVA_HOME}.") |
| 158 | sys.exit(1) |
| 159 | |
| 160 | if not (within_unittest or os.path.exists(STORM_LIB_DIR)): |
| 161 | print("*" * 20) |
| 162 | print('''The storm client can only be run from within a release. |
| 163 | You appear to be trying to run the client from a checkout of Storm's source code. |
| 164 | You can download a Storm release at https://storm.apache.org/downloads.html")''') |
| 165 | print("*" * 20) |
| 166 | sys.exit(1) |
| 167 | |
| 168 | STORM_EXT_CLASSPATH = os.getenv('STORM_EXT_CLASSPATH', None) |
| 169 | STORM_EXT_CLASSPATH_DAEMON = os.getenv('STORM_EXT_CLASSPATH_DAEMON', None) |
| 170 | LOCAL_TTL_DEFAULT = "20" |
| 171 | |
| 172 | ini_file = os.path.join(CLUSTER_CONF_DIR, 'storm_env.ini') |
| 173 | if not os.path.isfile(ini_file): |
| 174 | return |
| 175 | config = configparser.ConfigParser() |
| 176 | config.optionxform = str |
| 177 | config.read(ini_file) |
| 178 | options = config.options('environment') |
| 179 | for option in options: |
| 180 | value = config.get('environment', option) |
| 181 | os.environ[option] = value |
| 182 | |