incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r1182606 - 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/main.py
Date Wed, 12 Oct 2011 22:45:51 GMT
Author: eyang
Date: Wed Oct 12 22:45:50 2011
New Revision: 1182606

URL: http://svn.apache.org/viewvc?rev=1182606&view=rev
Log:
AMBARI-65. Added directory structure actions. (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/main.py

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1182606&r1=1182605&r2=1182606&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Oct 12 22:45:50 2011
@@ -2,6 +2,10 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-65. Added directory structure actions. (Eric Yang)
+
+  AMBARI-60. Added permission check for RUN_ACTION, and WRITE_FILE_ACTION. (Eric Yang)
+
   AMBARI-64. Define components in terms of XML. (omalley)
 
   AMBARI-63. Implement cluster update, rename and delete CLI commands (vgogte)

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=1182606&r1=1182605&r2=1182606&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 Wed Oct 12 22:45:50
2011
@@ -22,7 +22,7 @@ import logging
 import logging.handlers
 import Queue
 import threading
-from FileUtil import writeFile
+from FileUtil import writeFile, createStructure, deleteStructure
 from shell import shellRunner
 import json
 import os
@@ -121,13 +121,13 @@ class ActionQueue(threading.Thread):
   def createStructureAction(self, action):
     result = self.genResult(action)
     result['exitCode'] = 0
-    return result
+    return createStructure(action, result)
 
   # Delete directory structure for cluster
   def deleteStructureAction(self, action):
     result = self.genResult(action)
     result['exitCode'] = 0
-    return result
+    return deleteStructure(action, result)
 
   # Handle unknown action
   def unknownAction(self, action):

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=1182606&r1=1182605&r2=1182606&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 Wed Oct 12 22:45:50
2011
@@ -25,12 +25,19 @@ import logging.handlers
 import getpass
 import os, errno
 import sys, traceback
+import ConfigParser
+import shutil
+import StringIO
 
 logger = logging.getLogger()
 
 def writeFile(action, result):
+  global config
+  oldCwd = os.getcwd()
   fileInfo = action['file']
   try:
+    path = config.get('agent','prefix')+"/clusters/"+action['clusterId']+"-"+action['role']
+    os.chdir(path)
     user=fileInfo['owner']
     group=fileInfo['group']
     filename=fileInfo['path']
@@ -62,14 +69,41 @@ def writeFile(action, result):
       os.chown(filename, user, group)
     os.umask(oldMask)
     result['exitCode'] = 0
-    return result
   except Exception, err:
     result['exitCode'] = 1
     result['stderr'] = traceback.format_exc()
-    return result
+  os.chdir(oldCwd)
+  return result
+
+def createStructure(action, result):
+  global config
+  try:
+    path = config.get('agent','prefix')+"/clusters/"+action['clusterId']+"-"+action['role']
+    os.makedirs(path+"/stack")
+    os.makedirs(path+"/logs")
+    os.makedirs(path+"/data")
+    os.makedirs(path+"/pkgs")
+    os.makedirs(path+"/config")
+    result['exitCode'] = 0
+  except Exception, err:
+    result['exitCode'] = 1
+    result['stderr'] = traceback.format_exc()
+  return result
+
+def deleteStructure(action, result):
+  global config
+  try:
+    path = config.get('agent','prefix')+"/clusters/"+action['clusterId']+"-"+action['role']
+    if os.path.exists(path):
+      shutil.rmtree(path)
+    result['exitCode'] = 0
+  except Exception, err:
+    result['exitCode'] = 1
+    result['stderr'] = traceback.format_exc()
+  return result
 
 def main():
-  config = {
+  configFile = {
     "data"       : "test", 
     "owner"      : os.getuid(), 
     "group"      : os.getgid() , 
@@ -77,10 +111,10 @@ def main():
     "path"       : "/tmp/ambari_file_test/_file_write_test", 
     "umask"      : 022 
   }
-  action = { 'file' : config }
+  action = { 'file' : configFile }
   result = { }
   print writeFile(action, result)
-  config = { 
+  configFile = { 
     "data"       : "test", 
     "owner"      : "eyang", 
     "group"      : "staff", 
@@ -89,8 +123,21 @@ def main():
     "umask"      : "022" 
   }
   result = { }
-  action = { 'file' : config }
+  action = { 'file' : configFile }
   print writeFile(action, result)
 
+  global config
+  config = ConfigParser.RawConfigParser()
+  content = """
+[agent]
+prefix=/tmp/ambari
+  """
+  s = StringIO.StringIO(content)
+  config.readfp(s);
+  action = { 'clusterId' : 'abc', 'role' : 'hdfs' }
+  result = {}
+  print createStructure(action, result)
+  print deleteStructure(action, result)
+
 if __name__ == "__main__":
   main()

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=1182606&r1=1182605&r2=1182606&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 Wed Oct 12 22:45:50
2011
@@ -58,6 +58,9 @@ def debug(sig, frame):
     logger.info(message)
       
 def main():
+  global config
+  default_cfg = { 'agent' : { 'prefix' : '/home/ambari' } }
+  config = ConfigParser.RawConfigParser(default_cfg)
   signal.signal(signal.SIGINT, signal_handler)
   signal.signal(signal.SIGTERM, signal_handler)
   signal.signal(signal.SIGUSR1, debug)
@@ -96,7 +99,6 @@ def main():
 
   # Check for ambari configuration file.
   if(os.path.exists('/etc/ambari/ambari.ini')):
-    config = ConfigParser.RawConfigParser()
     config.read('/etc/ambari/ambari.ini')
     try:
       credential = {}
@@ -109,9 +111,11 @@ def main():
   else:
     credential = None
     controllerUrl = "http://localhost:4080"
-  logger.info("Connecting to controller at:"+controllerUrl)
+  logger.info("Connecting to controller at: "+controllerUrl)
 
   # Launch Controller communication
+  print controllerUrl
+  print credential
   controller = Controller(controllerUrl, credential) 
   controller.start()
   controller.run()



Mime
View raw message