Author: eyang
Date: Tue Oct 11 17:09:15 2011
New Revision: 1181893
URL: http://svn.apache.org/viewvc?rev=1181893&view=rev
Log:
AMBARI-51. Refactor transport data model for commands to become action. (Eric Yang)
Modified:
incubator/ambari/trunk/agent/pom.xml
incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionResults.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/DaemonHandler.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/FileUtil.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/Hardware.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/PackageHandler.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/Runner.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/ServerStatus.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/ShellHandler.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/Zeroconf.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/ZooKeeperCommunicator.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/createDaemon.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/daemon.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/main.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/package.py
incubator/ambari/trunk/agent/src/main/python/ambari_agent/shell.py
incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ActionResult.java
incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java
Modified: incubator/ambari/trunk/agent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/pom.xml?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/pom.xml (original)
+++ incubator/ambari/trunk/agent/pom.xml Tue Oct 11 17:09:15 2011
@@ -62,7 +62,7 @@
<executions>
<execution>
<configuration>
- <executable>python</executable>
+ <executable>python2.6</executable>
<workingDirectory>target/ambari-agent-${project.version}</workingDirectory>
<arguments>
<argument>${project.basedir}/src/main/python/setup.py</argument>
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
@@ -57,108 +57,90 @@ class ActionQueue(threading.Thread):
for action in actions:
q.put(action)
- # dispatch action types
def run(self):
global clusterId, bluePrintName, bluePrintRevision
while True:
while not q.empty():
action = q.get()
switches = {
- 'START_ACTION': self.startAction,
- 'STOP_ACTION': self.stopAction,
- 'RUN_ACTION': self.runAction
+ 'START_ACTION' : self.startAction,
+ 'STOP_ACTION' : self.stopAction,
+ 'RUN_ACTION' : self.runAction,
+ 'CREATE_STRUCTURE_ACTION' : self.createStructureAction,
+ 'DELETE_STRUCTURE_ACTION' : self.deleteStructureAction,
+ 'WRITE_FILE_ACTION' : self.writeFileAction,
}
result = switches.get(action['kind'], self.unknownAction)(action)
- # Store the blue print check point file
- if clusterId!=action['clusterId'] or bluePrintName!=action['bluePrintName'] or bluePrintRevision!=action['bluePrintRevision']:
- clusterId = action['clusterId']
- bluePrintName = action['bluePrintName']
- bluePrintRevision = action['bluePrintRevision']
- output = {
- 'clusterId' : clusterId,
- 'bluePrintName' : bluePrintName,
- 'bluePrintRevision' : bluePrintRevision
- }
- data = json.dumps(output)
- info = ['ambari-write-file',os.getuid(),os.getgid(),'0700','/tmp/blueprint',data]
- writeFile(info)
# Update the result
r.put(result)
+ # Store action result to agent response queue
def result(self):
result = []
while not r.empty():
result.append(r.get())
return result
- # Run start action, start a server process and
- # track the liveness of the children process
- def startAction(self, action):
+ # Generate default action response
+ def genResult(self, action):
result = {
- 'id' : action['id'],
+ 'id' : action['id'],
'clusterId' : action['clusterId'],
- 'kind' : action['kind'],
- 'component' : action['component'],
- 'role' : action['role'],
+ 'kind' : action['kind'],
'bluePrintName' : action['bluePrintName'],
- 'bluePrintRevision' : action['bluePrintRevision']
+ 'bluePrintRevision' : action['bluePrintRevision'],
+ 'component' : action['component'],
+ 'role' : action['role']
}
- self.sh.startProcess(action['component'], action['role'], action['commands'][0]['cmd'],
action['user'])
return result
+ # Run start action, start a server process and
+ # track the liveness of the children process
+ def startAction(self, action):
+ result = self.genResult(action)
+ return self.sh.startProcess(action['clusterId'],
+ action['bluePrintName'],
+ action['bluePrintRevision'],
+ action['component'],
+ action['role'],
+ action['command'],
+ action['user'], result)
+
# Run stop action, stop a server process.
def stopAction(self, action):
- result = {
- 'id' : action['id'],
- 'kind' : action['kind'],
- 'clusterId' : action['clusterId'],
- 'component' : action['component'],
- 'role' : action['role'],
- 'bluePrintName' : action['bluePrintName'],
- 'bluePrintRevision' : action['bluePrintRevision']
- }
- self.sh.stopProcess(action['component'], action['role'], action['signal'])
- return result
+ result = self.genResult(action)
+ return self.sh.stopProcess(action['clusterId'],
+ action['bluePrintName'],
+ action['bluePrintRevision'],
+ action['component'],
+ action['role'],
+ action['signal'], result)
+
+ # Write file action
+ def writeFileAction(self, action):
+ result = self.genResult(action)
+ return self.sh.writeFile(action, result)
- # Run commands action
+ # Run command action
def runAction(self, action):
- result = {
- 'id' : action['id'],
- 'clusterId' : action['clusterId'],
- 'kind' : action['kind'],
- 'bluePrintName' : action['bluePrintName'],
- 'bluePrintRevision' : action['bluePrintRevision']
- }
- return self.runCommands(action['commands'], action['cleanUpCommands'], result)
+ result = self.genResult(action)
+ return self.sh.runAction(action['clusterId'],
+ action['component'],
+ action['role'],
+ action['user'],
+ action['command'],
+ action['cleanUpCommand'], result)
+
+ # Create directory structure for cluster
+ def createStructureAction(self, action):
+ result = self.genResult(action)
+ result['exitCode'] = 0
+ return result
- # run commands
- def runCommands(self, commands, cleanUps, result):
- failure = False
- cmdResult = []
- for cmd in commands:
- script = cmd['cmd']
- if script[0]=="ambari-write-file":
- response = writeFile(script)
- else:
- response = self.sh.run(script, cmd['user'])
- exitCode = response['exit_code']
- if exitCode==0:
- cmdResult.append({'exitCode':exitCode})
- else:
- failure=True
- cmdResult.append({'exitCode':exitCode, 'stdout':response['stdout'], 'stderr':response['stderr']})
- result['commandResults'] = cmdResult
- if(failure):
- cleanUpResult = []
- for cmd in cleanUps:
- script = cmd['cmd']
- response = self.sh.run(script, cmd['user'])
- exitCode = response['exit_code']
- if exitCode==0:
- cleanUpResult.append({'exitCode':exitCode})
- else:
- cleanUpResult.append({'exitCode':exitCode,'stdout':response['stdout'],'stderr':response['stderr']})
- result['cleanUpCommandResults'] = cleanUpResult
+ # Delete directory structure for cluster
+ def deleteStructureAction(self, action):
+ result = self.genResult(action)
+ result['exitCode'] = 0
return result
# Handle unknown action
@@ -171,14 +153,3 @@ class ActionQueue(threading.Thread):
def isIdle(self):
return q.empty()
- # Report current clusterId
- def getClusterId(self):
- return clusterId
-
- # Report blue print name
- def getBluePrintName(self):
- return bluePrintName
-
- # Report blue print revision
- def getBluePrintRevision(self):
- return bluePrintRevision
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionResults.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionResults.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionResults.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionResults.py Tue Oct 11
17:09:15 2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/Controller.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/DaemonHandler.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/DaemonHandler.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/DaemonHandler.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/DaemonHandler.py Tue Oct 11
17:09:15 2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/FileUtil.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/FileUtil.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/FileUtil.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/FileUtil.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/Hardware.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/Hardware.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/Hardware.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/Hardware.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
@@ -18,6 +18,7 @@ See the License for the specific languag
limitations under the License.
'''
+from shell import shellRunner
import multiprocessing
import platform
@@ -47,35 +48,39 @@ class Hardware:
def scanCpu(self):
self.cpuCount = multiprocessing.cpu_count()
- self.cpuSpeed = 1
+ self.cpuSpeed = 0
self.cpuFlag = ""
def scanNet(self):
switches = {
- 'Linux': self.ethtools,
+ 'Linux': self.ethtool,
'Darwin': self.ifconfig
}
- switches.get(self.os, self.ethtools)()
+ switches.get(self.os, self.ethtool)()
- def ethtools(self):
- self.netSpeed = 10
+ def ethtool(self):
+ sh = shellRunner()
+ script = [ 'ethtool', 'eth0', '|', 'grep', 'Speed:', '|', 'sed', "'s/\s*Speed:\s*//'",
'|', 'sed', "'s/Mb\/s//'" ]
+ result = sh.run(script)
+ self.netSpeed = int(result['output'].rstrip())
def ifconfig(self):
- self.netSpeed = 100
+ sh = shellRunner()
+ script = [ 'ifconfig', 'en0', '|', 'grep', 'media:', '|', 'sed', "'s/.*(//'", '|', 'sed',
"'s/ .*//'", '|', 'sed', "'s/baseT//'" ]
+ result = sh.run(script)
+ if "none" in result['output']:
+ # No ethernet detected, detect airport
+ script = [ '/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport',
'-I', '|', 'grep', 'lastTxRate:', '|', 'sed', "'s/.*: //'", '|', 'sed', "'s/$//'"]
+ result = sh.run(script)
+ self.netSpeed = int(result['output'].rstrip())
def scanOS(self):
self.arch = platform.processor()
self.os = platform.system()
-'''
-SPEED="$(ifconfig en0 | grep media: | sed 's/.*(//' | sed 's/ .*//' | sed 's/baseT/ MBit\/s/')";
-
-SPEED="$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport
-I | grep lastTxRate: | sed 's/.*: //' | sed 's/$/ MBit\/s/')";
-'''
-
def main(argv=None):
hardware = Hardware()
- print hardware.build()
+ print hardware.get()
if __name__ == '__main__':
main()
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/Heartbeat.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
@@ -35,16 +35,13 @@ class Heartbeat:
global clusterId, bluePrintName, bluePrintRevision
serverStatus = ServerStatus()
timestamp = int(time.time()*1000)
- heartbeat = { 'responseId' : id,
- 'timestamp' : timestamp,
- 'clusterId' : self.actionQueue.getClusterId(),
- 'bluePrintName' : self.actionQueue.getBluePrintName(),
- 'bluePrintRevision' : self.actionQueue.getBluePrintRevision(),
- 'hostname' : socket.gethostname(),
- 'hardwareProfile' : self.hardware.get(),
- 'actionResults' : self.actionQueue.result(),
- 'serversStatus' : serverStatus.build(),
- 'idle' : self.actionQueue.isIdle()
+ heartbeat = { 'responseId' : id,
+ 'timestamp' : timestamp,
+ 'hostname' : socket.gethostname(),
+ 'hardwareProfile' : self.hardware.get(),
+ 'actionResults' : self.actionQueue.result(),
+ 'installedRoleStates' : serverStatus.build(),
+ 'idle' : self.actionQueue.isIdle()
}
return heartbeat
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/PackageHandler.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/PackageHandler.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/PackageHandler.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/PackageHandler.py Tue Oct 11
17:09:15 2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/Runner.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/Runner.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/Runner.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/Runner.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/ServerStatus.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/ServerStatus.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/ServerStatus.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/ServerStatus.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
@@ -31,11 +31,14 @@ class ServerStatus:
list = []
servers = sh.getServerTracker()
for server in servers:
- (component, role) = server.split(".")
+ (clusterId, bluePrintName, bluePrintRevision, component, role) = server.split("/")
result = {
- 'component' : component,
- 'role' : role,
- 'state' : 'STARTED'
+ 'clusterId' : clusterId,
+ 'bluePrintName' : bluePrintName,
+ 'bluePrintRevision' : bluePrintRevision,
+ 'component' : component,
+ 'roleName' : role,
+ 'serverStatus' : 'STARTED'
}
list.append(result)
return list
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/ShellHandler.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/ShellHandler.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/ShellHandler.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/ShellHandler.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/Zeroconf.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/Zeroconf.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/Zeroconf.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/Zeroconf.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/ZooKeeperCommunicator.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/ZooKeeperCommunicator.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/ZooKeeperCommunicator.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/ZooKeeperCommunicator.py Tue
Oct 11 17:09:15 2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/__init__.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
"""
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/createDaemon.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/createDaemon.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/createDaemon.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/createDaemon.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/daemon.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/daemon.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/daemon.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/daemon.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/main.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/main.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/main.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/main.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/package.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/package.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/package.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/package.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
Modified: incubator/ambari/trunk/agent/src/main/python/ambari_agent/shell.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/main/python/ambari_agent/shell.py?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/main/python/ambari_agent/shell.py (original)
+++ incubator/ambari/trunk/agent/src/main/python/ambari_agent/shell.py Tue Oct 11 17:09:15
2011
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python2.6
'''
Licensed to the Apache Software Foundation (ASF) under one
@@ -22,7 +22,9 @@ import logging
import logging.handlers
import subprocess
import os
+import tempfile
import signal
+import sys
global serverTracker
serverTracker = {}
@@ -30,35 +32,85 @@ logger = logging.getLogger()
class shellRunner:
# Run any command
- def run(self, script, user):
+ def run(self, script, user=None):
code = 0
cmd = " "
cmd = cmd.join(script)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True,
close_fds=True)
out, err = p.communicate()
- if p.wait() != 0:
- code = 1
- return {'exit_code': code, 'output': out, 'error': err}
+ code = p.wait()
+ return {'exitCode': code, 'output': out, 'error': err}
+
+ # dispatch action types
+ def runAction(self, clusterId, component, role, user, command, cleanUpCommand, result):
+ code = 0
+ cmd = sys.executable
+ tempfilename = tempfile.mktemp()
+ tmp = open(tempfilename, 'w')
+ tmp.write(command['script'])
+ tmp.close()
+ cmd = "%s %s %s" % (cmd, tempfilename, " ".join(command['param']))
+ commandResult = {}
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True,
close_fds=True)
+ out, err = p.communicate()
+ code = p.wait()
+ if code != 0:
+ commandResult['output'] = out
+ commandResult['error'] = err
+ commandResult['exitCode'] = code
+ result['commandResult'] = commandResult
+ os.unlink(tempfilename)
+ if code != 0:
+ tempfilename = tempfile.mktemp()
+ tmp = open(tempfilename, 'w')
+ tmp.write(command['script'])
+ tmp.close()
+ cmd = sys.executable
+ cmd = "%s %s %s" % (cmd, tempfilename, " ".join(cleanUpCommand['param']))
+ cleanUpCode = 0
+ cleanUpResult = {}
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True,
close_fds=True)
+ out, err = p.communicate()
+ cleanUpCode = p.wait()
+ if cleanUpCode != 0:
+ cleanUpResult['output'] = out
+ cleanUpResult['error'] = err
+ cleanUpResult['exitCode'] = cleanUpCode
+ result['cleanUpResult'] = cleanUpResult
+ os.unlink(tempfilename)
+ return result
# Start a process and presist its state
- def startProcess(self, component, role, script, user):
+ def startProcess(self, clusterId, bluePrintName, bluePrintRevision, component, role, script,
user, result):
global serverTracker
- process = component+"."+role
+ code = 0
+ commandResult = {}
+ process = clusterId+"/"+bluePrintName+"/"+bluePrintRevision+"/"+component+"/"+role
if not process in serverTracker:
- cmd = " "
- cmd = cmd.join(script)
+ cmd = sys.executable
+ tempfilename = tempfile.mktemp()
+ tmp = open(tempfilename, 'w')
+ tmp.write(script['script'])
+ tmp.close()
+ cmd = "%s %s %s" % (cmd, tempfilename, " ".join(script['param']))
child_pid = os.fork()
if child_pid == 0:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True,
close_fds=True)
- p.wait()
+ out, err = p.communicate()
+ code = p.wait()
+ os.unlink(tempfilename)
serverTracker[process] = None
else:
serverTracker[process] = child_pid
+ commandResult['exitCode'] = 0
+ result['commandResult'] = commandResult
+ return result
# Stop a process and remove presisted state
- def stopProcess(self, component, role, sig):
+ def stopProcess(self, clusterId, bluePrintName, bluePrintRevision, component, role, sig,
result):
global serverTracker
- process = component+"."+role
+ process = clusterId+"/"+bluePrintName+"/"+bluePrintRevision+"/"+component+"/"+role
+ commandResult = {'exitCode': 0}
if process in serverTracker:
if sig=='TERM':
os.kill(serverTracker[process], signal.SIGTERM)
@@ -68,6 +120,8 @@ class shellRunner:
else:
os.kill(serverTracker[process], signal.SIGKILL)
del serverTracker[process]
+ result['commandResult'] = commandResult
+ return result
def getServerTracker(self):
return serverTracker
Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ActionResult.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ActionResult.java?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ActionResult.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/ActionResult.java
Tue Oct 11 17:09:15 2011
@@ -18,8 +18,6 @@
package org.apache.ambari.common.rest.entities.agent;
-import java.util.List;
-
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
@@ -44,9 +42,9 @@ public class ActionResult {
@XmlElement
private Kind kind;
@XmlElement
- private List<CommandResult> commandResults;
+ private CommandResult commandResult;
@XmlElement
- private List<CommandResult> cleanUpCommandResults;
+ private CommandResult cleanUpCommandResult;
@XmlElement
private String component;
@XmlElement
@@ -80,20 +78,20 @@ public class ActionResult {
this.kind = kind;
}
- public List<CommandResult> getCommandResults() {
- return commandResults;
+ public CommandResult getCommandResult() {
+ return commandResult;
}
- public void setCommandResults(List<CommandResult> commandResults) {
- this.commandResults = commandResults;
+ public void setCommandResult(CommandResult commandResult) {
+ this.commandResult = commandResult;
}
- public List<CommandResult> getCleanUpCommandResults() {
- return cleanUpCommandResults;
+ public CommandResult getCleanUpCommandResult() {
+ return cleanUpCommandResult;
}
- public void setCleanUpResults(List<CommandResult> cleanUpResults) {
- this.cleanUpCommandResults = cleanUpResults;
+ public void setCleanUpResult(CommandResult cleanUpResult) {
+ this.cleanUpCommandResult = cleanUpResult;
}
Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java?rev=1181893&r1=1181892&r2=1181893&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java
(original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/agent/Command.java
Tue Oct 11 17:09:15 2011
@@ -36,33 +36,31 @@ public class Command {
public Command() {
}
- public Command(String user, String cmd, String[] param) {
- this.cmd = cmd;
+ public Command(String user, String script, String[] param) {
+ this.script = script;
this.user = user;
this.param = param;
}
@XmlElement
- private String cmd;
-
+ private String script;
@XmlElement
private String[] param;
-
@XmlElement
private String user;
- public String getCmd() {
- return cmd;
+ public String getScript() {
+ return script;
}
+ public void setScript(String script) {
+ this.script = script;
+ }
+
public String getUser() {
return user;
}
- public void setCmd(String cmd) {
- this.cmd = cmd;
- }
-
public void setUser(String user) {
this.user = user;
}
|