You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2014/06/23 23:47:48 UTC

[12/13] git commit: SLIDER-153 building up exec

SLIDER-153 building up exec


Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/918e746d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/918e746d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/918e746d

Branch: refs/heads/feature/SLIDER-153_add_slider_py_command
Commit: 918e746d83c4ad0f4a25bba39050942f5689599a
Parents: d6131ca
Author: Steve Loughran <st...@apache.org>
Authored: Mon Jun 23 14:40:34 2014 -0700
Committer: Steve Loughran <st...@apache.org>
Committed: Mon Jun 23 14:40:34 2014 -0700

----------------------------------------------------------------------
 slider-assembly/src/main/scripts/slider    |   1 -
 slider-assembly/src/main/scripts/slider.py | 109 +++++++++++++++++++++++-
 2 files changed, 106 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/918e746d/slider-assembly/src/main/scripts/slider
----------------------------------------------------------------------
diff --git a/slider-assembly/src/main/scripts/slider b/slider-assembly/src/main/scripts/slider
index e9522cf..caf275b 100755
--- a/slider-assembly/src/main/scripts/slider
+++ b/slider-assembly/src/main/scripts/slider
@@ -32,7 +32,6 @@ function usage
 this="${BASH_SOURCE-$0}"
 bindir=$(cd -P -- "$(dirname -- "$this")" && pwd -P)
 script="$(basename -- "$this")"
-this="$bin/$script"
 
 # lib directory is one up; it is expected to contain 
 # slider.jar and any other dependencies that are not in the

http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/918e746d/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
index d5891ed..e846e64 100644
--- a/slider-assembly/src/main/scripts/slider.py
+++ b/slider-assembly/src/main/scripts/slider.py
@@ -16,13 +16,116 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 import sys
+import os
 import subprocess
 
-# Slider main method
+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
+
+
+"""
+
+
+
+print os.environ['HOME']
+
+
+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 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()
+  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)
+  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
   
   
+  commandline = ["java",]
+  # commandline.append(slider_jvm_opts)
+  commandline.append("-classpath")
+  commandline.append(slider_classpath)
+  commandline.append(SLIDER_CLASSNAME)
+  commandline.extend(args)
+  print "ready to exec : %s" % commandline
+  # docs warn of using PIPE on stderr 
+  return subprocess.call(commandline,
+                         stdin=None,
+                         stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE,
+                         shell=False)
+
+
+
+
+
 if __name__ == '__main__':
-    print "slider python script"
+  print "slider python script"
+  try:
     rv = main()
-    sys.exit(rv)
+    if rv != 0:
+      print "exit code = %d" % rv
+  except Exception as e:
+    print "Exception: %s " % e.message
+    rv = -1
+  
+  sys.exit(rv)