You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ch...@apache.org on 2013/07/08 21:29:39 UTC
svn commit: r1500897 - in /uima/sandbox/uima-ducc/trunk/src/main/admin:
check_ducc ducc.py ducc_post_install ducc_props_diff ducc_statedump
ducc_util.py read_nodes.py sign_jconsole_jar start_ducc stop_ducc
Author: challngr
Date: Mon Jul 8 19:29:38 2013
New Revision: 1500897
URL: http://svn.apache.org/r1500897
Log:
UIMA-3055 Update admin-level scripting for refactor of ducc_util.
Modified:
uima/sandbox/uima-ducc/trunk/src/main/admin/check_ducc
uima/sandbox/uima-ducc/trunk/src/main/admin/ducc.py
uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_post_install
uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_props_diff
uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_statedump
uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_util.py
uima/sandbox/uima-ducc/trunk/src/main/admin/read_nodes.py
uima/sandbox/uima-ducc/trunk/src/main/admin/sign_jconsole_jar
uima/sandbox/uima-ducc/trunk/src/main/admin/start_ducc
uima/sandbox/uima-ducc/trunk/src/main/admin/stop_ducc
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/check_ducc
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/check_ducc?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/check_ducc (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/check_ducc Mon Jul 8 19:29:38 2013
@@ -22,16 +22,10 @@
import os
import sys
from time import time
-
-from ducc_boot import *
-set_ducc_home()
-
-
import getopt
-import subprocess
from ducc_util import DuccUtil
-from ducc_util import DuccProperties
+from ducc_base import DuccProperties
from local_hooks import verify_slave_node
from local_hooks import verify_master_node
@@ -133,6 +127,8 @@ class CheckDucc(DuccUtil):
print 'badarg', a
usage('bad arg: ' + a)
+ self.get_duccling_version();
+
if ( do_validate ):
# if validating, ONLY validate, called via ssh usually
self.validate(checkdate)
@@ -177,13 +173,17 @@ class CheckDucc(DuccUtil):
nodes['local'] = localnodes
# checking starts here
+ checked = {}
for (nodefile, nodelist) in nodes.items():
if ( nodelist == None ):
# loading the nodes prints the necessary message
continue
spacer = ' '
for node in nodelist:
+ if ( checked.has_key(node) ):
+ continue
+ checked[node] = node
print 'Checking', node, '...',
response = self.find_ducc_process(node) # a tuple, (True|False, proclist)
if ( not response[0] ):
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/ducc.py
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/ducc.py?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/ducc.py (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/ducc.py Mon Jul 8 19:29:38 2013
@@ -26,7 +26,7 @@ import getopt
import time
from ducc_util import DuccUtil
-from ducc_util import DuccProperties
+from ducc_base import DuccProperties
from local_hooks import verify_slave_node
class Ducc(DuccUtil):
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_post_install
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_post_install?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_post_install (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_post_install Mon Jul 8 19:29:38 2013
@@ -24,11 +24,8 @@ import sys
import shutil
import subprocess
-from ducc_boot import *
-set_ducc_home()
-
from ducc_util import DuccUtil
-from ducc_util import DuccProperties
+from ducc_base import DuccProperties
from ducc import Ducc
class PostInstall(DuccUtil):
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_props_diff
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_props_diff?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_props_diff (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_props_diff Mon Jul 8 19:29:38 2013
@@ -24,7 +24,7 @@ import sys
import getopt
from ducc_util import DuccUtil
-from ducc_util import DuccProperties
+from ducc_base import DuccProperties
from ducc import Ducc
class PropsDiff(DuccUtil):
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_statedump
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_statedump?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_statedump (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_statedump Mon Jul 8 19:29:38 2013
@@ -18,16 +18,11 @@
# under the License.
# -----------------------------------------------------------------------
-
-from ducc_boot import *
-set_ducc_home()
-
import getopt
import json
from ducc_util import DuccUtil
-from ducc_util import DuccProperties
-from ducc import Ducc
+from ducc_base import DuccProperties
class DuccStateListener(DuccUtil):
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_util.py
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_util.py?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_util.py (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/ducc_util.py Mon Jul 8 19:29:38 2013
@@ -25,168 +25,35 @@ import string
import subprocess
import re
import grp
-import zipfile
import resource
import time
-import platform
from stat import *
from local_hooks import find_other_processes
-class DuccPropertiesException(Exception):
- def __init__(self, msg):
- self.msg = msg
- def __str__(self):
- return repr(self.msg)
+# simple bootstratp to establish DUCC_HOME and to set the python path so it can
+# find the common code in DUCC_HOME/admin
+if ( os.environ.has_key('DUCC_HOME') ):
+ DUCC_HOME = os.environ['DUCC_HOME']
+else:
+ me = os.path.abspath(sys.argv[0])
+ ndx = me.rindex('/')
+ ndx = me.rindex('/', 0, ndx)
+ DUCC_HOME = me[:ndx] # split from 0 to ndx
+ os.environ['DUCC_HOME'] = DUCC_HOME
+
+sys.path.append(DUCC_HOME + '/bin')
+from ducc_base import DuccBase
+from ducc_base import DuccProperties
-class DuccProperties:
- def __init__(self):
- self.props = {}
-
- #
- # Expand all ${} values from env or from this properties file itself
- # The search order is:
- # 1 look in this properties file
- # 2 look in the environment
- #
- def do_subst(self, str):
- key = None
- p = re.compile("\\$\\{[a-zA-Z0-9_\\.\\-]+\\}")
- ndx = 0
-
- response = str
- m = p.search(response, ndx)
- while ( m != None ):
- key = m.group()[2:-1]
-
- val = None
- if ( self.has_key(key) ):
- val = self.get(key)
- elif ( os.environ.has_key(key) ):
- val = os.environ[key]
-
- if ( val != None ):
- response = string.replace(response, m.group() , val)
- ndx = m.start()+1
- m = p.search(response, ndx)
-
- return response
-
- def mkitem(self, line):
- ndx = line.find('#') # remove comments - like the java DuccProperties
- if ( ndx >= 0 ):
- line = line[0:ndx] # strip the comment
- ndx = line.find('//') # remove comments - like the java DuccProperties
- if ( ndx >= 0 ):
- line = line[0:ndx] # strip the comment
- line = line.strip() # clear leading and trailing whitespace
- if ( line == '' ): # empty line?
- return
-
- mobj = re.search('[ =:]+', line)
- if ( mobj ):
- key = line[:mobj.start()].strip()
- val = line[mobj.end():].strip()
- #print 'NEXT', mobj.start(), 'END', mobj.end(), 'KEY', key, 'VAL', val
- # val = self.do_subst(val) # we'll do lazy subst on get instead
- self.props[key] = val
- else:
- self.props[line] = None
-
- #
- # Load reads a properties file and adds it contents to the
- # hash. It may be called several times; each call updates
- # the internal has, thus building it up. The input file is
- # in the form of a java-like properties file.
- #
- def load(self, propsfile):
- if ( not os.path.exists(propsfile) ):
- raise DuccPropertiesException(propsfile + ' does not exist and cannot be loaded.')
-
- f = open(propsfile);
- for line in f:
- self.mkitem(line.strip())
- f.close()
-
- def load_from_manifest(self, jarfile):
- z = zipfile.ZipFile(jarfile)
- items = z.read('META-INF/MANIFEST.MF').split('\n')
- for item in items:
- self.mkitem(item)
-
- #
- # Try to load a properties file. Just be silent if it doesn't exist.
- #
- def load_if_exists(self, propsfile):
- if ( os.path.exists(propsfile) ):
- return self.load(propsfile)
-
- #
- # Put something into the hash.
- #
- def put(self, key, value):
- self.props[key] = value
-
- #
- # Get something from the hash.
- #
- def get(self, key):
- if ( self.props.has_key(key) ):
- return self.do_subst(self.props[key]) # we'll do lazy subst on get instead
- return None
-
- #
- # Remove an item if it exists
- #
- def delete(self, key):
- if ( self.props.has_key(key) ):
- del self.props[key]
- #
- # Write the has as a Java-like properties file
- #
- def write(self, propsfile):
- f = open(propsfile, 'w')
- items = self.props.items()
- for (k, v) in items:
- #print 'WRITING', k, '=', v
- f.write(k + ' = ' + str(v) + '\n')
- f.close()
-
- #
- # return a shallow copy of the dictionary
- #
- def copy_dictionary(self):
- return self.props.copy()
-
- #
- # return the entries in the dictionary
- #
- def items(self):
- return self.props.items()
-
- #
- # check to see if the key exists in the dictionary
- #
- def has_key(self, key):
- return self.props.has_key(key)
-
- #
- # Return the length of the dictionary
- #
- def __len__(self):
- return len(self.props)
-
-class DuccUtil:
+class DuccUtil(DuccBase):
def read_properties(self):
- self.ducc_properties = DuccProperties()
- self.ducc_properties.load(self.propsfile)
+ DuccBase.read_properties(self)
self.duccling = self.ducc_properties.get('ducc.agent.launcher.ducc_spawn_path')
- self.webserver_node = self.ducc_properties.get('ducc.ws.node')
- self.jvm = self.ducc_properties.get('ducc.jvm')
# self.broker_url = self.ducc_properties.get('ducc.broker.url')
self.broker_protocol = self.ducc_properties.get('ducc.broker.protocol')
@@ -211,22 +78,6 @@ class DuccUtil:
if ( self.webserver_node == None ):
self.webserver_node = self.localhost
-
- def java(self):
- return self.jvm
-
- def java_home(self):
- if ( os.environ.has_key('DUCC_POST_INSTALL') ):
- return 'JAVA_HOME' # avoid npe during first-time setup
-
- if ( self.system == 'Darwin' ):
- self.jvm_home = "/Library/Java/Home"
- else:
- ndx = self.jvm.rindex('/')
- ndx = self.jvm.rindex('/', 0, ndx)
- self.jvm_home = self.jvm[:ndx]
-
- return self.jvm_home
def find_netstat(self):
# don't you wish people would get together on where stuff lives?
@@ -268,60 +119,10 @@ class DuccUtil:
CMD = broker_home + '/bin/activemq'
CMD = CMD + ' stop'
CMD = 'JAVA_HOME=' + self.java_home() + ' ' + CMD
- print CMD
+ print '--------------------', CMD
self.ssh(broker_host, False, CMD)
pass
- def version(self):
- lines = self.popen(self.jvm, ' org.apache.uima.ducc.utils.Version')
- line = lines.readline().strip()
- return "DUCC Version", line
-
- def nohup_new(self, cmd, showpid=True):
- nfds = resource.getrlimit(resource.RLIMIT_NOFILE)[1] # returns softlimit, hardlimit
-
- # print 'NOHUP', cmd
- print 'NOHUP', ' '.join(cmd)
- print 'NOHUP', os.environ['IP']
- print 'NOHUP', os.environ['NodeName']
- #print 'NOHUP', os.environ['CLASSPATH']
- try:
- pid = os.fork()
- except OSError, e:
- raise Exception, "%s [%d]" % (e.strerror, e.errno)
-
- if ( pid != 0 ):
- return # the parent
- else:
- os.setsid()
-
- try:
- pid = os.fork()
- except OSError, e:
- raise Exception, "%s [%d]" % (e.strerror, e.errno)
-
- if ( pid != 0 ):
- if ( showpid ):
- os.write(1, 'PID ' + str(pid) + '\n')
- return
-
- print 'NOHUP flushing'
- sys.stdout.flush()
- nfds = resource.getrlimit(resource.RLIMIT_NOFILE)[1] # returns softlimit, hardlimit
- for i in range(3, nfds):
- try:
- #os.close(i);
- pass
- except:
- pass # wasn't open
-
- #devnull = os.devnull
- #open(devnull, 'r') # fd 0 stdin
- #open(devnull, 'w') # 1 stdout
- #open(devnull, 'w') # 2 stderr
- os.execvp(cmd[0], cmd)
-
-
def nohup(self, cmd, showpid=True):
cmd = ' '.join(cmd)
# print '**** nohup', cmd, '****'
@@ -333,21 +134,6 @@ class DuccUtil:
if ( showpid ) :
print 'PID', ducc.pid
- # simply spawn-and-forget using Python preferred mechanism
- def spawn(self, *CMD):
- cmd = ' '.join(CMD)
- # print '**** spawn', cmd, '****'
- ducc = subprocess.Popen(cmd, shell=True)
- pid = ducc.pid
- status = os.waitpid(pid, 0)
- return pid
-
- def popen(self, *CMD):
- cmd = ' '.join(CMD)
- #print 'POPEN:', cmd
- proc = subprocess.Popen(cmd, bufsize=0, stdout=subprocess.PIPE, shell=True, stderr=subprocess.STDOUT)
- return proc.stdout
-
# like popen, only it spawns via ssh
def ssh(self, host, do_wait, *CMD):
@@ -409,55 +195,11 @@ class DuccUtil:
os.environ['CLASSPATH'] = CLASSPATH
-
- def set_classpath_for_cli(self):
- # This is only needed if you use the API, not the executable jars. The executable
- # jars pull in everything needed.
- ducc_home = self.DUCC_HOME
- LIB = ducc_home + '/lib'
- RESOURCES = ducc_home + '/resources'
-
- local_jars = self.ducc_properties.get('ducc.local.jars') #local mods
-
- CLASSPATH = ''
-
- if ( local_jars != None ):
- extra_jars = local_jars.split()
- for j in extra_jars:
- CLASSPATH = CLASSPATH + ':' + LIB + '/' + j
-
- CLASSPATH = CLASSPATH + ":" + LIB + '/slf4j/*'
- CLASSPATH = CLASSPATH + ":" + LIB + '/apache-commons-cli/*'
- CLASSPATH = CLASSPATH + ":" + LIB + '/google-gson/*'
- CLASSPATH = CLASSPATH + ":" + LIB + '/apache-log4j/*'
- CLASSPATH = CLASSPATH + ":" + LIB + '/xstream/*'
- CLASSPATH = CLASSPATH + ":" + LIB + '/uima/*'
-
- # orchestrator http needs codecs
- CLASSPATH = CLASSPATH + ":" + LIB + '/http-client/*'
-
- # explicitly NOT ducc_test.jar
- CLASSPATH = CLASSPATH + ':' + LIB + '/uima-ducc-cli.jar'
- CLASSPATH = CLASSPATH + ':' + LIB + '/uima-ducc-common.jar'
- CLASSPATH = CLASSPATH + ':' + LIB + '/uima-ducc-transport.jar'
-
- CLASSPATH = CLASSPATH + ':' + RESOURCES
-
- os.environ['CLASSPATH'] = CLASSPATH
-
-
def format_classpath(self, cp):
strings = cp.split(':')
for s in strings:
print s
- def set_classpath_for_submit(self):
- ducc_home = self.DUCC_HOME
- LIB = ducc_home + '/lib'
-
- CLASSPATH = LIB + '/ducc-submit.jar'
- os.environ['CLASSPATH'] = CLASSPATH
-
def check_clock_skew(self, localdate):
user = os.environ['LOGNAME']
bypass = (user != 'ducc')
@@ -493,7 +235,7 @@ class DuccUtil:
def verify_jvm(self):
jvm = self.java()
- CMD = jvm + ' -fullversion > /dev/null'
+ CMD = jvm + ' -fullversion > /dev/null 2>&1'
rc = os.system(CMD)
if ( rc != 0 ):
print 'NOTOK', CMD, 'returns', rc, '. Must return rc 0. Startup cannot continue.'
@@ -567,8 +309,8 @@ class DuccUtil:
line = ' '.join(toks[0:4])
if ( line != version_from_head ):
print "Mismatched ducc_ling versions:"
- print "ALERT: Master version:", version_from_head
- print "ALERT: Local version:", line
+ print "ALERT: Version on Ducc Head:", version_from_head
+ print "ALERT: Version on Agent node:", line
return False
verfile.close()
else:
@@ -818,23 +560,6 @@ class DuccUtil:
path = head + '/' + path
return path
- def which(self, file):
- for p in os.environ["PATH"].split(":"):
- if os.path.exists(p + "/" + file):
- return p + "/" + file
- return None
-
- def mkargs(self, args):
- '''
- The cli needs to insure all args are fully quoted so the shell doesn't
- lose the proper tokenization. This quotes everything.
- '''
- answer = []
- for a in args:
- arg = '"' + a + '"'
- answer.append(arg)
- return answer
-
#
# Read the nodefile, recursing into 'imports' if needed, returning a
# map. The map is keyed on filename, with each entry a list of the nodes.
@@ -866,19 +591,7 @@ class DuccUtil:
return ret
def __init__(self):
-
- if ( os.environ.has_key('DUCC_HOME') ):
- self.DUCC_HOME = os.environ['DUCC_HOME']
- else:
- me = os.path.abspath(sys.argv[0])
- ndx = me.rindex('/')
- ndx = me.rindex('/', 0, ndx)
- self.DUCC_HOME = me[:ndx] # split from 0 to ndx
- os.environ['DUCC_HOME'] = self.DUCC_HOME
-
- self.system = platform.system()
- self.jvm = None
- self.webserver_node = 'localhost'
+ DuccBase.__init__(self)
self.duccling = None
self.broker_url = 'tcp://localhost:61616'
self.broker_protocol = 'tcp'
@@ -886,16 +599,13 @@ class DuccUtil:
self.broker_port = '61616'
self.default_components = ['rm', 'pm', 'sm', 'or', 'ws', 'broker']
self.default_nodefiles = [self.DUCC_HOME + '/resources/ducc.nodes']
- self.propsfile = self.DUCC_HOME + '/resources/ducc.properties'
- self.localhost = os.uname()[1]
- self.read_properties()
- os.environ['JAVA_HOME'] = self.java_home()
os.environ['NodeName'] = self.localhost # to match java code's implicit propery so script and java match
self.pid_file = self.DUCC_HOME + '/state/ducc.pids'
self.set_classpath()
self.os_pagesize = self.get_os_pagesize()
+ self.read_properties()
manage_broker = self.ducc_properties.get('ducc.broker.automanage')
self.automanage = False
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/read_nodes.py
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/read_nodes.py?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/read_nodes.py (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/read_nodes.py Mon Jul 8 19:29:38 2013
@@ -22,12 +22,8 @@
import os
import sys
-from ducc_boot import *
-set_ducc_home()
-
from ducc_util import DuccUtil
-from ducc_util import DuccProperties
-from ducc import Ducc
+from ducc_base import DuccProperties
#
# Read the ducc node list and spew to stdout - handles comments, imports, etc.
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/sign_jconsole_jar
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/sign_jconsole_jar?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/sign_jconsole_jar (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/sign_jconsole_jar Mon Jul 8 19:29:38 2013
@@ -30,9 +30,6 @@ import sys
import shutil
import subprocess
-from ducc_boot import *
-set_ducc_home()
-
from ducc_util import DuccUtil
class SignJconsole(DuccUtil):
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/start_ducc
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/start_ducc?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/start_ducc (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/start_ducc Mon Jul 8 19:29:38 2013
@@ -22,16 +22,14 @@
import os
import sys
import time
-
-from ducc_boot import *
-set_ducc_home()
-
import getopt
-from ducc_util import DuccUtil
-from ducc_util import DuccProperties
-from ducc import Ducc
+from ducc_util import DuccUtil
+from ducc_base import DuccProperties
+from local_hooks import verify_slave_node
from local_hooks import verify_master_node
+from local_hooks import verify_master_node
+from ducc import Ducc
class StartDucc(DuccUtil):
Modified: uima/sandbox/uima-ducc/trunk/src/main/admin/stop_ducc
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/src/main/admin/stop_ducc?rev=1500897&r1=1500896&r2=1500897&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/src/main/admin/stop_ducc (original)
+++ uima/sandbox/uima-ducc/trunk/src/main/admin/stop_ducc Mon Jul 8 19:29:38 2013
@@ -22,16 +22,12 @@
import os
import sys
import time
-
-from ducc_boot import *
-set_ducc_home()
-
-
import getopt
import glob
+
from ducc_util import DuccUtil
-from ducc_util import DuccProperties
-from ducc_util import DuccPropertiesException
+from ducc_base import DuccProperties
+from ducc_base import DuccPropertiesException
from ducc import Ducc
class StopDucc(DuccUtil):
@@ -237,7 +233,7 @@ class StopDucc(DuccUtil):
if ( not force ) :
self.clean_shutdown()
- sleeptime = 5
+ sleeptime = 30
print "Waiting " + str(sleeptime) + " seconds to broadcast agent shutdown."
time.sleep(sleeptime)