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

Proposed by Cory Johns
Status: Merged
Merged at revision: 18
Proposed branch: lp:~bigdata-dev/charms/trusty/hdp-storm/cs-jps-quickfix
Merge into: lp:charms/trusty/hdp-storm
Diff against target: 86 lines (+23/-20)
2 files modified
hooks/bdutils.py (+20/-17)
tests/10-deploy (+3/-3)
To merge this branch: bzr merge lp:~bigdata-dev/charms/trusty/hdp-storm/cs-jps-quickfix
Reviewer Review Type Date Requested Status
Matt Bruzek (community) Approve
amir sanjar (community) Approve
Review via email: mp+250934@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
amir sanjar (asanjar) :
review: Approve
Revision history for this message
Matt Bruzek (mbruzek) wrote :

I was not able to get the charm tests running on my machine but I looked over the code and it looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/bdutils.py'
2--- hooks/bdutils.py 2014-09-03 04:10:49 +0000
3+++ hooks/bdutils.py 2015-02-25 14:49:18 +0000
4@@ -1,4 +1,5 @@
5 #!/usr/bin/python
6+import re
7 import os
8 import pwd
9 import grp
10@@ -133,28 +134,30 @@
11 m = ll[0]+" = "+ll[1].strip().strip(';').strip("\"").strip()
12 #log ("==> {} ".format("\""+m+"\""))
13 os.environ[ll[0]] = ll[1].strip().strip(';').strip("\"").strip()
14-
15+
16+
17+def jps(name):
18+ """
19+ Get PIDs for named Java processes, for any user.
20+ """
21+ pat = re.sub(r'^(.)', r'^[^ ]*java .*[\1]', name)
22+ try:
23+ output = subprocess.check_output(['sudo', 'pgrep', '-f', pat])
24+ except subprocess.CalledProcessError:
25+ return []
26+ return map(int, filter(None, map(str.strip, output.split('\n'))))
27+
28+
29 def is_jvm_service_active(processname):
30- cmd=["jps"]
31- p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
32- out, err = p.communicate()
33- if err == None and str(out).find(processname) != -1:
34- return True
35- else:
36- return False
37+ return jps(processname) != []
38+
39
40 def kill_java_process(process):
41- cmd=["jps"]
42- p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
43- out, err = p.communicate()
44- cmd = out.split()
45- for i in range(0, len(cmd)):
46- if cmd[i] == process:
47- pid = int(cmd[i-1])
48- os.kill(pid, signal.SIGTERM)
49+ for pid in jps(process):
50+ os.kill(pid, signal.SIGTERM)
51 return 0
52
53 def mergeFiles(file1, file2):
54 with open(file1, 'a') as f1:
55 with open(file2) as f2:
56- f1.write(f2.read())
57\ No newline at end of file
58+ f1.write(f2.read())
59
60=== modified file 'tests/10-deploy'
61--- tests/10-deploy 2014-09-19 22:54:54 +0000
62+++ tests/10-deploy 2015-02-25 14:49:18 +0000
63@@ -28,7 +28,7 @@
64 getattr(self, test)()
65
66 def test_zookeeper_service_status(self):
67- o,c= self.zk_unit.run("jps | awk '{print $2}'")
68+ o,c= self.zk_unit.run("pgrep -a java")
69 if o.find('QuorumPeerMain') == -1:
70 amulet.raise_status(amulet.FAIL, msg="Zookeeper QuorumPeerMain not started")
71
72@@ -51,13 +51,13 @@
73 if (time.time() - ticks) > 300:
74 amulet.raise_status(amulet.FAIL, msg="nimbus-server is not started")
75 break
76- o,c= self.st_unit.run("jps | awk '{print $2}'")
77+ o,c= self.st_unit.run("pgrep -a java")
78 if o.find('nimbus') != -1:
79 break
80 time.sleep(2)
81
82 def test_storm_slave_service_status(self):
83- o,c= self.st_slave_unit.run("jps | awk '{print $2}'")
84+ o,c= self.st_slave_unit.run("pgrep -a java")
85 if o.find('supervisor') == -1:
86 amulet.raise_status(amulet.FAIL, msg="supervisor is not started")
87

Subscribers

People subscribed via source and target branches