You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ey...@apache.org on 2011/11/01 00:15:10 UTC

svn commit: r1195717 - in /incubator/ambari/trunk: CHANGES.txt agent/src/main/python/ambari_agent/ActionQueue.py agent/src/main/python/ambari_agent/FileUtil.py agent/src/main/python/ambari_agent/shell.py agent/src/test/python/TestFileUtil.py

Author: eyang
Date: Mon Oct 31 23:15:06 2011
New Revision: 1195717

URL: http://svn.apache.org/viewvc?rev=1195717&view=rev
Log:
AMBARI-119. Enhance agent to support workDirComponent. (Eric Yang)

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/agent/src/main/python/ambari_agent/ActionQueue.py
    incubator/ambari/trunk/agent/src/main/python/ambari_agent/FileUtil.py
    incubator/ambari/trunk/agent/src/main/python/ambari_agent/shell.py
    incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1195717&r1=1195716&r2=1195717&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Mon Oct 31 23:15:06 2011
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-119. Enhance agent to support workDirComponent. (Eric Yang)
+
   AMBARI-118. Added safe guard mechanism to prevent agent crash on 
   faulty action. (Eric Yang)
 

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=1195717&r1=1195716&r2=1195717&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 Mon Oct 31 23:15:06 2011
@@ -73,6 +73,7 @@ class ActionQueue(threading.Thread):
         try:
           result = switches.get(action['kind'], self.unknownAction)(action)
         except Exception, err:
+          logger.info(err)
           result = self.genResult(action)
           result['exitCode']=1
         # Update the result
@@ -103,7 +104,8 @@ class ActionQueue(threading.Thread):
   # track the liveness of the children process
   def startAction(self, action):
     result = self.genResult(action)
-    return self.sh.startProcess(action['clusterId'],
+    return self.sh.startProcess(action['workDirComponent'],
+      action['clusterId'],
       action['clusterDefinitionRevision'],
       action['component'], 
       action['role'], 
@@ -113,7 +115,8 @@ class ActionQueue(threading.Thread):
   # Run stop action, stop a server process.
   def stopAction(self, action):
     result = self.genResult(action)
-    return self.sh.stopProcess(action['clusterId'], 
+    return self.sh.stopProcess(action['workDirComponent'],
+      action['clusterId'], 
       action['clusterDefinitionRevision'],
       action['component'],
       action['role'], 
@@ -127,7 +130,8 @@ class ActionQueue(threading.Thread):
   # Run command action
   def runAction(self, action):
     result = self.genResult(action)
-    return self.sh.runAction(action['clusterId'], 
+    return self.sh.runAction(action['workDirComponent'],
+      action['clusterId'], 
       action['component'],
       action['role'],
       action['user'], 

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=1195717&r1=1195716&r2=1195717&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 Mon Oct 31 23:15:06 2011
@@ -78,7 +78,8 @@ def writeFile(action, result):
 
 def createStructure(action, result):
   try:
-    path = AmbariConfig.config.get('agent','prefix')+"/clusters/"+action['clusterId']+"-"+action['role']
+    workdir = action['workDirComponent']
+    path = AmbariConfig.config.get('agent','prefix')+"/clusters/"+workdir
     os.makedirs(path+"/stack")
     os.makedirs(path+"/logs")
     os.makedirs(path+"/data")
@@ -92,7 +93,8 @@ def createStructure(action, result):
 
 def deleteStructure(action, result):
   try:
-    path = AmbariConfig.config.get('agent','prefix')+"/clusters/"+action['clusterId']+"-"+action['role']
+    workdir = action['workDirComponent']
+    path = AmbariConfig.config.get('agent','prefix')+"/clusters/"+workdir
     if os.path.exists(path):
       shutil.rmtree(path)
     result['exitCode'] = 0

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=1195717&r1=1195716&r2=1195717&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 Mon Oct 31 23:15:06 2011
@@ -56,7 +56,9 @@ class shellRunner:
     return {'exitCode': code, 'output': out, 'error': err}
 
   # dispatch action types
-  def runAction(self, clusterId, component, role, user, command, cleanUpCommand, result):
+  def runAction(self, workdir, clusterId, component, role, user, command, cleanUpCommand, result):
+    oldDir = os.getcwd()
+    os.chdir(workdir)
     oldUid = os.getuid()
     try:
       user=getpwnam(user)[2]
@@ -99,14 +101,17 @@ class shellRunner:
       result['cleanUpResult'] = cleanUpResult
       os.unlink(tempfilename)
     try:
+      os.chdir(oldDir)
       os.setuid(oldUid)
     except Exception:
-      logger.warn("%s %s %s can not restore user for RUN_ACTION." % (clusterId, component, role))
+      logger.warn("%s %s %s can not restore environment for RUN_ACTION." % (clusterId, component, role))
     return result
 
   # Start a process and presist its state
-  def startProcess(self, clusterId, clusterDefinitionRevision, component, role, script, user, result):
+  def startProcess(self, workdir, clusterId, clusterDefinitionRevision, component, role, script, user, result):
     global serverTracker
+    oldDir = os.getcwd()
+    os.chdir(workdir)
     oldUid = os.getuid()
     try:
       user=getpwnam(user)[2]
@@ -135,14 +140,17 @@ class shellRunner:
         commandResult['exitCode'] = 0
       result['commandResult'] = commandResult
     try:
+      os.chdir(oldDir)
       os.setuid(oldUid)
     except Exception:
-      logger.warn("%s %s %s can not restore user for START_ACTION." % (clusterId, component, role))
+      logger.warn("%s %s %s can not restore environment for START_ACTION." % (clusterId, component, role))
     return result
 
   # Stop a process and remove presisted state
-  def stopProcess(self, clusterId, clusterDefinitionRevision, component, role, sig, result):
+  def stopProcess(self, workdir, clusterId, clusterDefinitionRevision, component, role, sig, result):
     global serverTracker
+    oldDir = os.getcwd()
+    os.chdir(workdir)
     process = clusterId+"/"+clusterDefinitionRevision+"/"+component+"/"+role
     commandResult = {'exitCode': 0}
     if process in serverTracker:
@@ -155,6 +163,10 @@ class shellRunner:
         os.kill(serverTracker[process], signal.SIGKILL)
         del serverTracker[process]
     result['commandResult'] = commandResult
+    try:
+      os.chdir(oldDir)
+    except Exception:
+      logger.warn("%s %s %s can not restore environment for STOP_ACTION." % (clusterId, component, role))
     return result
 
   def getServerTracker(self):

Modified: incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py?rev=1195717&r1=1195716&r2=1195717&view=diff
==============================================================================
--- incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py (original)
+++ incubator/ambari/trunk/agent/src/test/python/TestFileUtil.py Mon Oct 31 23:15:06 2011
@@ -24,7 +24,7 @@ import os, errno
 
 class TestFileUtil(TestCase):
   def test_createStructure(self):
-    action = { 'clusterId' : 'abc', 'role' : 'hdfs' }
+    action = { 'clusterId' : 'abc', 'role' : 'hdfs', 'workDirComponent' : 'abc-hdfs' }
     result = {}
     result = createStructure(action, result)
     self.assertEqual(result['exitCode'], 0, 'Create cluster structure failed.')
@@ -38,14 +38,19 @@ class TestFileUtil(TestCase):
       "path"       : "/tmp/ambari_file_test/_file_write_test",
       "umask"      : 022
     }
-    action = { 'clusterId' : 'abc', 'role' : 'hdfs', 'file' : configFile }
+    action = { 
+      'clusterId' : 'abc', 
+      'role' : 'hdfs', 
+      'workDirComponent' : 'abc-hdfs',
+      'file' : configFile 
+    }
     result = { }
     result = writeFile(action, result)
     self.assertEqual(result['exitCode'], 0, 'WriteFile test with uid/gid failed.')
 
 #  def test_deleteStructure(self):
     result = { }
-    action = { 'clusterId' : 'abc', 'role' : 'hdfs' }
+    action = { 'clusterId' : 'abc', 'role' : 'hdfs', 'workDirComponent' : 'abc-hdfs' }
     result = deleteStructure(action, result)
     self.assertEqual(result['exitCode'], 0, 'Delete cluster structure failed.')