← Back to team overview

bigdata-dev team mailing list archive

[Merge] lp:~bigdata-dev/charms/trusty/hdp-storm/cs-jps-quickfix into lp:charms/trusty/hdp-storm

 

Cory Johns has proposed merging lp:~bigdata-dev/charms/trusty/hdp-storm/cs-jps-quickfix into lp:charms/trusty/hdp-storm.

Requested reviews:
  Big Data Charmers (bigdata-charmers)

For more details, see:
https://code.launchpad.net/~bigdata-dev/charms/trusty/hdp-storm/cs-jps-quickfix/+merge/250934

Work around the JPS upstream issue (https://bugs.launchpad.net/ubuntu/+source/openjdk-6/+bug/1417962)
-- 
Your team Juju Big Data Development is subscribed to branch lp:~bigdata-dev/charms/trusty/hdp-storm/cs-jps-quickfix.
=== modified file 'hooks/bdutils.py'
--- hooks/bdutils.py	2014-09-03 04:10:49 +0000
+++ hooks/bdutils.py	2015-02-25 14:49:18 +0000
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+import re
 import os
 import pwd
 import grp
@@ -133,28 +134,30 @@
                 m = ll[0]+" = "+ll[1].strip().strip(';').strip("\"").strip()
                 #log ("==> {} ".format("\""+m+"\""))
                 os.environ[ll[0]] = ll[1].strip().strip(';').strip("\"").strip()
-                
+
+
+def jps(name):
+    """
+    Get PIDs for named Java processes, for any user.
+    """
+    pat = re.sub(r'^(.)', r'^[^ ]*java .*[\1]', name)
+    try:
+        output = subprocess.check_output(['sudo', 'pgrep', '-f', pat])
+    except subprocess.CalledProcessError:
+        return []
+    return map(int, filter(None, map(str.strip, output.split('\n'))))
+
+
 def is_jvm_service_active(processname):
-    cmd=["jps"]
-    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
-    out, err = p.communicate()
-    if err == None and str(out).find(processname) != -1:
-        return True
-    else:
-        return False
+    return jps(processname) != []
+
 
 def kill_java_process(process):
-    cmd=["jps"]
-    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
-    out, err = p.communicate()
-    cmd = out.split()
-    for i in range(0, len(cmd)):
-        if cmd[i] == process:
-            pid = int(cmd[i-1])
-            os.kill(pid, signal.SIGTERM)
+    for pid in jps(process):
+        os.kill(pid, signal.SIGTERM)
     return 0
 
 def mergeFiles(file1, file2):
     with open(file1, 'a') as f1:
         with open(file2) as f2:
-            f1.write(f2.read())
\ No newline at end of file
+            f1.write(f2.read())

=== modified file 'tests/10-deploy'
--- tests/10-deploy	2014-09-19 22:54:54 +0000
+++ tests/10-deploy	2015-02-25 14:49:18 +0000
@@ -28,7 +28,7 @@
                 getattr(self, test)()
 
     def test_zookeeper_service_status(self):
-        o,c= self.zk_unit.run("jps | awk '{print $2}'")
+        o,c= self.zk_unit.run("pgrep -a java")
         if o.find('QuorumPeerMain') == -1:
             amulet.raise_status(amulet.FAIL, msg="Zookeeper QuorumPeerMain not started")
     
@@ -51,13 +51,13 @@
             if (time.time() - ticks) > 300:
                 amulet.raise_status(amulet.FAIL, msg="nimbus-server is not started")
                 break
-            o,c= self.st_unit.run("jps | awk '{print $2}'")
+            o,c= self.st_unit.run("pgrep -a java")
             if o.find('nimbus') != -1:
                 break
             time.sleep(2)
                      
     def test_storm_slave_service_status(self):
-        o,c= self.st_slave_unit.run("jps | awk '{print $2}'")
+        o,c= self.st_slave_unit.run("pgrep -a java")
         if o.find('supervisor') == -1:
             amulet.raise_status(amulet.FAIL, msg="supervisor is not started")
                     


Follow ups