forked from apache/phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phoenix_utils.py
executable file
·231 lines (197 loc) · 10.1 KB
/
phoenix_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/env python
############################################################################
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################################
import os
import fnmatch
import subprocess
def find(pattern, classPaths):
paths = classPaths.split(os.pathsep)
# for each class path
for path in paths:
# remove * if it's at the end of path
if ((path is not None) and (len(path) > 0) and (path[-1] == '*')) :
path = path[:-1]
for root, dirs, files in os.walk(path):
# sort the file names so *-client always precedes *-thin-client
files.sort()
for name in files:
if fnmatch.fnmatch(name, pattern):
return os.path.join(root, name)
return ""
def findFileInPathWithoutRecursion(pattern, path):
if not os.path.exists(path):
return ""
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path,f))]
# sort the file names so *-client always precedes *-thin-client
files.sort()
for name in files:
if fnmatch.fnmatch(name, pattern):
return os.path.join(path, name)
return ""
def which(command):
for path in os.environ["PATH"].split(os.pathsep):
if os.path.exists(os.path.join(path, command)):
return os.path.join(path, command)
return None
def findClasspath(command_name):
command_path = which(command_name)
if command_path is None:
# We don't have this command, so we can't get its classpath
return ''
command = "%s%s" %(command_path, ' classpath')
return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).stdout.read()
def setPath():
PHOENIX_CLIENT_JAR_PATTERN = "phoenix-*-client.jar"
PHOENIX_THIN_CLIENT_JAR_PATTERN = "phoenix-*-thin-client.jar"
PHOENIX_QUERYSERVER_JAR_PATTERN = "phoenix-*-queryserver.jar"
PHOENIX_LOADBALANCER_JAR_PATTERN = "phoenix-load-balancer-*[!t][!e][!s][!t][!s].jar"
PHOENIX_TRACESERVER_JAR_PATTERN = "phoenix-tracing-webapp-*-runnable.jar"
PHOENIX_TESTS_JAR_PATTERN = "phoenix-core-*-tests*.jar"
PHOENIX_PHERF_JAR_PATTERN = "phoenix-pherf-*-minimal*.jar"
# Backward support old env variable PHOENIX_LIB_DIR replaced by PHOENIX_CLASS_PATH
global phoenix_class_path
phoenix_class_path = os.getenv('PHOENIX_LIB_DIR','')
if phoenix_class_path == "":
phoenix_class_path = os.getenv('PHOENIX_CLASS_PATH','')
global hbase_conf_dir
# if HBASE_CONF_DIR set explicitly, use that
hbase_conf_dir = os.getenv('HBASE_CONF_DIR', os.getenv('HBASE_CONF_PATH'))
if not hbase_conf_dir:
# else fall back to HBASE_HOME
if os.getenv('HBASE_HOME'):
hbase_conf_dir = os.path.join(os.getenv('HBASE_HOME'), "conf")
elif os.name == 'posix':
# default to the bigtop configuration dir
hbase_conf_dir = '/etc/hbase/conf'
else:
# Try to provide something valid
hbase_conf_dir = '.'
global hbase_conf_path # keep conf_path around for backward compatibility
hbase_conf_path = hbase_conf_dir
global current_dir
current_dir = os.path.dirname(os.path.abspath(__file__))
global pherf_conf_path
pherf_conf_path = os.path.join(current_dir, "config")
pherf_properties_file = find("pherf.properties", pherf_conf_path)
if pherf_properties_file == "":
pherf_conf_path = os.path.join(current_dir, "..", "phoenix-pherf", "config")
global phoenix_jar_path
phoenix_jar_path = os.path.join(current_dir, "..", "phoenix-client", "target","*")
global phoenix_client_jar
phoenix_client_jar = find("phoenix-*-client.jar", phoenix_jar_path)
if phoenix_client_jar == "":
phoenix_client_jar = findFileInPathWithoutRecursion(PHOENIX_CLIENT_JAR_PATTERN, os.path.join(current_dir, ".."))
if phoenix_client_jar == "":
phoenix_client_jar = find(PHOENIX_CLIENT_JAR_PATTERN, phoenix_class_path)
global phoenix_test_jar_path
phoenix_test_jar_path = os.path.join(current_dir, "..", "phoenix-core", "target","*")
global hadoop_conf
hadoop_conf = os.getenv('HADOOP_CONF_DIR', None)
if not hadoop_conf:
if os.name == 'posix':
# Try to provide a sane configuration directory for Hadoop if not otherwise provided.
# If there's no jaas file specified by the caller, this is necessary when Kerberos is enabled.
hadoop_conf = '/etc/hadoop/conf'
else:
# Try to provide something valid..
hadoop_conf = '.'
global hadoop_classpath
if (os.name != 'nt'):
hadoop_classpath = findClasspath('hadoop')
else:
hadoop_classpath = os.getenv('HADOOP_CLASSPATH', '')
global hadoop_common_jar_path
hadoop_common_jar_path = os.path.join(current_dir, "..", "phoenix-client", "target","*")
global hadoop_common_jar
hadoop_common_jar = find("hadoop-common*.jar", hadoop_common_jar_path)
global hadoop_hdfs_jar_path
hadoop_hdfs_jar_path = os.path.join(current_dir, "..", "phoenix-client", "target","*")
global hadoop_hdfs_jar
hadoop_hdfs_jar = find("hadoop-hdfs*.jar", hadoop_hdfs_jar_path)
global testjar
testjar = find(PHOENIX_TESTS_JAR_PATTERN, phoenix_test_jar_path)
if testjar == "":
testjar = findFileInPathWithoutRecursion(PHOENIX_TESTS_JAR_PATTERN, os.path.join(current_dir, "..", 'lib'))
if testjar == "":
testjar = find(PHOENIX_TESTS_JAR_PATTERN, phoenix_class_path)
global phoenix_queryserver_jar
phoenix_queryserver_jar = find(PHOENIX_QUERYSERVER_JAR_PATTERN, os.path.join(current_dir, "..", "phoenix-queryserver", "target", "*"))
if phoenix_queryserver_jar == "":
phoenix_queryserver_jar = findFileInPathWithoutRecursion(PHOENIX_QUERYSERVER_JAR_PATTERN, os.path.join(current_dir, "..", "lib"))
if phoenix_queryserver_jar == "":
phoenix_queryserver_jar = findFileInPathWithoutRecursion(PHOENIX_QUERYSERVER_JAR_PATTERN, os.path.join(current_dir, ".."))
global phoenix_loadbalancer_jar
phoenix_loadbalancer_jar = find(PHOENIX_LOADBALANCER_JAR_PATTERN, os.path.join(current_dir, "..", "phoenix-loadbalancer", "target", "*"))
if phoenix_loadbalancer_jar == "":
phoenix_loadbalancer_jar = findFileInPathWithoutRecursion(PHOENIX_LOADBALANCER_JAR_PATTERN, os.path.join(current_dir, "..", "lib"))
if phoenix_loadbalancer_jar == "":
phoenix_loadbalancer_jar = findFileInPathWithoutRecursion(PHOENIX_LOADBALANCER_JAR_PATTERN, os.path.join(current_dir, ".."))
global phoenix_traceserver_jar
phoenix_traceserver_jar = find(PHOENIX_TRACESERVER_JAR_PATTERN, os.path.join(current_dir, "..", "phoenix-tracing-webapp", "target", "*"))
if phoenix_traceserver_jar == "":
phoenix_traceserver_jar = findFileInPathWithoutRecursion(PHOENIX_TRACESERVER_JAR_PATTERN, os.path.join(current_dir, "..", "lib"))
if phoenix_traceserver_jar == "":
phoenix_traceserver_jar = findFileInPathWithoutRecursion(PHOENIX_TRACESERVER_JAR_PATTERN, os.path.join(current_dir, ".."))
global phoenix_pherf_jar
phoenix_pherf_jar = find(PHOENIX_PHERF_JAR_PATTERN, os.path.join(current_dir, "..", "phoenix-pherf", "target", "*"))
if phoenix_pherf_jar == "":
phoenix_pherf_jar = findFileInPathWithoutRecursion(PHOENIX_PHERF_JAR_PATTERN, os.path.join(current_dir, "..", "lib"))
if phoenix_pherf_jar == "":
phoenix_pherf_jar = findFileInPathWithoutRecursion(PHOENIX_PHERF_JAR_PATTERN, os.path.join(current_dir, ".."))
global phoenix_thin_client_jar
phoenix_thin_client_jar = find(PHOENIX_THIN_CLIENT_JAR_PATTERN, os.path.join(current_dir, "..", "phoenix-queryserver-client", "target", "*"))
if phoenix_thin_client_jar == "":
phoenix_thin_client_jar = findFileInPathWithoutRecursion(PHOENIX_THIN_CLIENT_JAR_PATTERN, os.path.join(current_dir, ".."))
return ""
def shell_quote(args):
"""
Return the platform specific shell quoted string. Handles Windows and *nix platforms.
:param args: array of shell arguments
:return: shell quoted string
"""
if os.name == 'nt':
import subprocess
return subprocess.list2cmdline(args)
else:
# pipes module isn't available on Windows
import pipes
return " ".join([pipes.quote(v) for v in args])
def common_sqlline_args(parser):
parser.add_argument('-v', '--verbose', help='Verbosity on sqlline.', default='true')
parser.add_argument('-c', '--color', help='Color setting for sqlline.', default='true')
parser.add_argument('-fc', '--fastconnect', help='Fetch all schemas on initial connection', default='false')
if __name__ == "__main__":
setPath()
print "phoenix_class_path:", phoenix_class_path
print "hbase_conf_dir:", hbase_conf_dir
print "hbase_conf_path:", hbase_conf_path
print "current_dir:", current_dir
print "phoenix_jar_path:", phoenix_jar_path
print "phoenix_client_jar:", phoenix_client_jar
print "phoenix_test_jar_path:", phoenix_test_jar_path
print "hadoop_common_jar_path:", hadoop_common_jar_path
print "hadoop_common_jar:", hadoop_common_jar
print "hadoop_hdfs_jar_path:", hadoop_hdfs_jar_path
print "hadoop_hdfs_jar:", hadoop_hdfs_jar
print "testjar:", testjar
print "phoenix_queryserver_jar:", phoenix_queryserver_jar
print "phoenix_loadbalancer_jar:", phoenix_loadbalancer_jar
print "phoenix_thin_client_jar:", phoenix_thin_client_jar
print "hadoop_classpath:", hadoop_classpath