SLIDER-153 bin/slider is now python
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/6f05995e Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/6f05995e Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/6f05995e Branch: refs/heads/feature/SLIDER-151_Implement_full_slider_API_in_REST_and_switch_client_to_it Commit: 6f05995e42c767062500da68759f75e7f66fd05c Parents: 8a8ffd9 Author: Steve Loughran <ste...@apache.org> Authored: Tue Jun 24 16:08:58 2014 -0700 Committer: Steve Loughran <ste...@apache.org> Committed: Tue Jun 24 16:08:58 2014 -0700 ---------------------------------------------------------------------- slider-assembly/src/main/scripts/slider | 217 +++++++++++++++++------- slider-assembly/src/main/scripts/slider.py | 169 ------------------ slider-assembly/src/main/scripts/slider.sh | 74 ++++++++ 3 files changed, 230 insertions(+), 230 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/6f05995e/slider-assembly/src/main/scripts/slider ---------------------------------------------------------------------- diff --git a/slider-assembly/src/main/scripts/slider b/slider-assembly/src/main/scripts/slider old mode 100755 new mode 100644 index caf275b..d48eca6 --- a/slider-assembly/src/main/scripts/slider +++ b/slider-assembly/src/main/scripts/slider @@ -1,5 +1,6 @@ -#!/usr/bin/env bash - +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# # 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. @@ -7,68 +8,162 @@ # (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 +# 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. - - -# this is the shell script to start Slider deploying an application -# Usage: slider <action> <commands> - -# The env variable SLIDER_JVM_OPTS can be used to override -# the default JVM opts - -function usage -{ - echo "Usage: slider <action> <arguments>" - echo "" -} - -# Slider works out its own location -this="${BASH_SOURCE-$0}" -bindir=$(cd -P -- "$(dirname -- "$this")" && pwd -P) -script="$(basename -- "$this")" - -# lib directory is one up; it is expected to contain -# slider.jar and any other dependencies that are not in the -# standard Hadoop classpath - -slider_home="${bindir}/.." -slider_home=`cd -P "${slider_home}" && pwd -P` - -libdir="${slider_home}/lib" -libdir=`cd -P "${libdir}" && pwd -P` - - -confdir="${slider_home}/conf" - -# normalize the conf dir so it can be passed down -confdir=`cd -P "${confdir}" && pwd -P` -confdir=${SLIDER_CONF_DIR:-$confdir} - - -slider_jvm_opts="-Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Xmx256m -Djava.confdir=${confdir}" -slider_jvm_opts=${SLIDER_JVM_OPTS:-$slider_jvm_opts} - -# allow for an extra classpath -slider_classpath_extra=${SLIDER_CLASSPATH_EXTRA:-""} - -slider_classpath="${libdir}/*:${confdir}:${slider_classpath_extra}" - -launcher=org.apache.slider.Slider - - -echo "slider_home = \"${slider_home}\"" -echo "slider_jvm_opts = \"${slider_jvm_opts}\"" -echo "classpath = \"${slider_classpath}\"" -export CLASSPATH="${slider_classpath}" -echo "" - -echo "command is java ${slider_jvm_opts} --classpath \"${slider_classpath}\" ${launcher} $@" -echo "" -echo "" -exec java ${slider_jvm_opts} ${launcher} $@ +import sys +import os +import subprocess + +CONF = "conf" + +LIB = "lib" + +SLIDER_CONF_DIR = "SLIDER_CONF_DIR" +SLIDER_JVM_OPTS = "SLIDER_JVM_OPTS" +SLIDER_CLASSPATH_EXTRA = "SLIDER_CLASSPATH_EXTRA" + +SLIDER_CLASSNAME = "org.apache.slider.Slider" +DEFAULT_JVM__OPTS = "-Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Xmx256m -Djava.confdir=%s" + +""" +Launches slider + + +""" + + + +def scriptDir(): + """ + get the script path + """ + return os.path.dirname(os.path.realpath(__file__)) + +def sliderDir(): + return os.path.dirname(scriptDir()) + +def libDir(sliderdir) : + return os.path.join(sliderdir, LIB) + +def confDir(sliderdir): + """ + determine the active configuration directory + :param sliderdir: slider directory + :return: the configuration directory -any env var will + override the relative path + """ + localconf = os.path.join(sliderdir, CONF) + return os.environ.get(SLIDER_CONF_DIR,localconf) + +def dirMustExist(dir): + if not os.path.exists(dir): + raise Exception("Directory does not exist: %s " % dir) + return dir + +def read(pipe, line): + """ + read a char, append to the listing if there is a char that is not \n + :param pipe: pipe to read from + :param line: line being built up + :return: (the potentially updated line, flag indicating newline reached) + """ + + c = pipe.read(1) + if c != "": + o = c.decode('utf-8') + if o != '\n': + line += o + return line, False + else: + return line, True + else: + return line, False + + + +def usage(): + print "Usage: slider <action> <arguments>" + return 1 + + +def main(): + """ + Slider main method + :return: exit code of the process + """ + if len(sys.argv)==1 : + return usage() + print "stdout encoding: "+ sys.stdout.encoding + args = sys.argv[1:] + slider_home = sliderDir() + libdir = dirMustExist(libDir(slider_home)) + confdir = dirMustExist(confDir(slider_home)) + default_jvm_opts = DEFAULT_JVM__OPTS % confdir + slider_jvm_opts = os.environ.get(SLIDER_JVM_OPTS, default_jvm_opts) + # split the JVM opts by space + jvm_opts_split = slider_jvm_opts.split() + slider_classpath_extra = os.environ.get(SLIDER_CLASSPATH_EXTRA, "") + p = os.pathsep # path separator + d = os.sep # dir separator + slider_classpath = libdir + d + "*" + p \ + + confdir + p \ + + slider_classpath_extra + + + print "slider_home = \"%s\"" % slider_home + print "slider_jvm_opts = \"%s\"" % slider_jvm_opts + print "slider_classpath = \"%s\"" % slider_classpath + + #java = "/usr/bin/java" + commandline = ["java", ] + commandline.append("-classpath") + commandline.append(slider_classpath) + commandline.extend(jvm_opts_split) + commandline.append(SLIDER_CLASSNAME) + commandline.extend(args) + print "ready to exec : %s" % commandline + # docs warn of using PIPE on stderr + exe = subprocess.Popen(commandline, + stdin=None, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=False) + stdout = exe.stdout + stderr = exe.stderr + outline = "" + errline = "" + while exe.poll() is None: + # process is running; grab output and echo every line + outline, done = read(stdout, outline) + if done: + print outline + outline = "" + errline, done = read(stderr, errline) + if done: + print errline + errline = "" + + # get tail + out, err = exe.communicate() + print outline + out.decode() + print errline + err.decode() + return exe.returncode + + + +if __name__ == '__main__': + """ + Entry point + """ + try: + returncode = main() + except Exception as e: + print "Exception: %s " % e.message + returncode = -1 + + sys.exit(returncode) http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/6f05995e/slider-assembly/src/main/scripts/slider.py ---------------------------------------------------------------------- diff --git a/slider-assembly/src/main/scripts/slider.py b/slider-assembly/src/main/scripts/slider.py deleted file mode 100644 index d48eca6..0000000 --- a/slider-assembly/src/main/scripts/slider.py +++ /dev/null @@ -1,169 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# 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 sys -import os -import subprocess - -CONF = "conf" - -LIB = "lib" - -SLIDER_CONF_DIR = "SLIDER_CONF_DIR" -SLIDER_JVM_OPTS = "SLIDER_JVM_OPTS" -SLIDER_CLASSPATH_EXTRA = "SLIDER_CLASSPATH_EXTRA" - -SLIDER_CLASSNAME = "org.apache.slider.Slider" -DEFAULT_JVM__OPTS = "-Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Xmx256m -Djava.confdir=%s" - -""" -Launches slider - - -""" - - - -def scriptDir(): - """ - get the script path - """ - return os.path.dirname(os.path.realpath(__file__)) - -def sliderDir(): - return os.path.dirname(scriptDir()) - -def libDir(sliderdir) : - return os.path.join(sliderdir, LIB) - -def confDir(sliderdir): - """ - determine the active configuration directory - :param sliderdir: slider directory - :return: the configuration directory -any env var will - override the relative path - """ - localconf = os.path.join(sliderdir, CONF) - return os.environ.get(SLIDER_CONF_DIR,localconf) - -def dirMustExist(dir): - if not os.path.exists(dir): - raise Exception("Directory does not exist: %s " % dir) - return dir - -def read(pipe, line): - """ - read a char, append to the listing if there is a char that is not \n - :param pipe: pipe to read from - :param line: line being built up - :return: (the potentially updated line, flag indicating newline reached) - """ - - c = pipe.read(1) - if c != "": - o = c.decode('utf-8') - if o != '\n': - line += o - return line, False - else: - return line, True - else: - return line, False - - - -def usage(): - print "Usage: slider <action> <arguments>" - return 1 - - -def main(): - """ - Slider main method - :return: exit code of the process - """ - if len(sys.argv)==1 : - return usage() - print "stdout encoding: "+ sys.stdout.encoding - args = sys.argv[1:] - slider_home = sliderDir() - libdir = dirMustExist(libDir(slider_home)) - confdir = dirMustExist(confDir(slider_home)) - default_jvm_opts = DEFAULT_JVM__OPTS % confdir - slider_jvm_opts = os.environ.get(SLIDER_JVM_OPTS, default_jvm_opts) - # split the JVM opts by space - jvm_opts_split = slider_jvm_opts.split() - slider_classpath_extra = os.environ.get(SLIDER_CLASSPATH_EXTRA, "") - p = os.pathsep # path separator - d = os.sep # dir separator - slider_classpath = libdir + d + "*" + p \ - + confdir + p \ - + slider_classpath_extra - - - print "slider_home = \"%s\"" % slider_home - print "slider_jvm_opts = \"%s\"" % slider_jvm_opts - print "slider_classpath = \"%s\"" % slider_classpath - - #java = "/usr/bin/java" - commandline = ["java", ] - commandline.append("-classpath") - commandline.append(slider_classpath) - commandline.extend(jvm_opts_split) - commandline.append(SLIDER_CLASSNAME) - commandline.extend(args) - print "ready to exec : %s" % commandline - # docs warn of using PIPE on stderr - exe = subprocess.Popen(commandline, - stdin=None, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - shell=False) - stdout = exe.stdout - stderr = exe.stderr - outline = "" - errline = "" - while exe.poll() is None: - # process is running; grab output and echo every line - outline, done = read(stdout, outline) - if done: - print outline - outline = "" - errline, done = read(stderr, errline) - if done: - print errline - errline = "" - - # get tail - out, err = exe.communicate() - print outline + out.decode() - print errline + err.decode() - return exe.returncode - - - -if __name__ == '__main__': - """ - Entry point - """ - try: - returncode = main() - except Exception as e: - print "Exception: %s " % e.message - returncode = -1 - - sys.exit(returncode) http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/6f05995e/slider-assembly/src/main/scripts/slider.sh ---------------------------------------------------------------------- diff --git a/slider-assembly/src/main/scripts/slider.sh b/slider-assembly/src/main/scripts/slider.sh new file mode 100755 index 0000000..caf275b --- /dev/null +++ b/slider-assembly/src/main/scripts/slider.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +# 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. + + +# this is the shell script to start Slider deploying an application +# Usage: slider <action> <commands> + +# The env variable SLIDER_JVM_OPTS can be used to override +# the default JVM opts + +function usage +{ + echo "Usage: slider <action> <arguments>" + echo "" +} + +# Slider works out its own location +this="${BASH_SOURCE-$0}" +bindir=$(cd -P -- "$(dirname -- "$this")" && pwd -P) +script="$(basename -- "$this")" + +# lib directory is one up; it is expected to contain +# slider.jar and any other dependencies that are not in the +# standard Hadoop classpath + +slider_home="${bindir}/.." +slider_home=`cd -P "${slider_home}" && pwd -P` + +libdir="${slider_home}/lib" +libdir=`cd -P "${libdir}" && pwd -P` + + +confdir="${slider_home}/conf" + +# normalize the conf dir so it can be passed down +confdir=`cd -P "${confdir}" && pwd -P` +confdir=${SLIDER_CONF_DIR:-$confdir} + + +slider_jvm_opts="-Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Xmx256m -Djava.confdir=${confdir}" +slider_jvm_opts=${SLIDER_JVM_OPTS:-$slider_jvm_opts} + +# allow for an extra classpath +slider_classpath_extra=${SLIDER_CLASSPATH_EXTRA:-""} + +slider_classpath="${libdir}/*:${confdir}:${slider_classpath_extra}" + +launcher=org.apache.slider.Slider + + +echo "slider_home = \"${slider_home}\"" +echo "slider_jvm_opts = \"${slider_jvm_opts}\"" +echo "classpath = \"${slider_classpath}\"" +export CLASSPATH="${slider_classpath}" +echo "" + +echo "command is java ${slider_jvm_opts} --classpath \"${slider_classpath}\" ${launcher} $@" +echo "" +echo "" +exec java ${slider_jvm_opts} ${launcher} $@