incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1395833 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-agent/src/main/python/manifestGenerator/
Date Tue, 09 Oct 2012 01:13:07 GMT
Author: mahadev
Date: Tue Oct  9 01:13:06 2012
New Revision: 1395833

URL: http://svn.apache.org/viewvc?rev=1395833&view=rev
Log:
AMBARI-828. Manifest generation for various actions from the server. (mahadev)

Added:
    incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/rolesToClass.dict
    incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/serviceStates.dict
    incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/test.json
Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/manifestGenerator.py

Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1395833&r1=1395832&r2=1395833&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Tue Oct  9 01:13:06 2012
@@ -12,6 +12,9 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-828. Manifest generation for various actions from the server.
+  (mahadev)
+
   AMBARI-827. Add clusterName to the status of the commands run by the agent.
   (mahadev)
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/manifestGenerator.py
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/manifestGenerator.py?rev=1395833&r1=1395832&r2=1395833&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/manifestGenerator.py
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/manifestGenerator.py
Tue Oct  9 01:13:06 2012
@@ -1,98 +1,157 @@
-import json
-
-def generateManifest(inputJsonStr):
-#reading json
-  parsedJson = json.loads(inputJsonStr)
-  hostname = parsedJson['hostname']
-  clusterHostInfo = parsedJson['clusterHostInfo']
-  params = parsedJson['params']
-  configurations = parsedJson['configurations']
-  hostAttributes = parsedJson['hostAttributes']
-  roles = parsedJson['roles']
-  
-#writing manifest
-  manifest = open('site.pp', 'w')
-
-  #writing imports from external static file
-  writeImports(manifest)
-  
-  #writing nodes
-  writeNodes(manifest, clusterHostInfo)
-  
-  #writing params from map
-  writeParams(manifest, params)
-  
-  #writing config maps
-  writeConfigurations(manifest, configurations)
-
-  #cycle here - writing host attributes
-  writeHostAttributes(manifest, hostAttributes)
-
-  #writing task definitions 
-  writeTasks(manifest, roles)
-     
-  manifest.close()
-    
-  
-  #read static imports from file and write them to manifest
-  def writeImports(outputFile, inputFileName='imports.txt'):
-    inputFile = open(inputFileName, 'r')
-    
-    for line in inputFile:
-      outputFile.write(line)
-      
-    inputFile.close()
-
-  #write nodes
-  def writeNodes(outputFile, clusterHostInfo):
-    for node in clusterHostInfo.iterkeys():
-      outputFile.write('$' + node + '= ['
-    
-      coma = ''
-      for host in node:
-        outputFile.write(coma + '\'' + host + '\'')
-        coma = ', '
-
-      outputFile.write(']\n'
-
-  #write params
-  def writeParams(outputFile, params):
-    for param in params.iterkeys():
-      outputFile.write('$' +  param + '="' + params[param] + '"\n')
-
-  #write host attributes
-  def writeHostAttributes(outputFile, hostAttributes):
-    outputFile.write('$hostAttributes={\n')
-  
-    coma = ''
-    for attribute in hostAttributes.iterkeys():
-      outputFile.write(coma + '"' +  attribute + '" => "{' + hostAttributes[attribute]
+ '"}')
-      coma = ',\n'
-
-    outputFile.write('}\n')
-
-  #write configurations
-  def writeConfigurations(outputFile, configs):
-    outputFile.write('$configuration =  {\n'
-  
-    for configName in configs.iterkeys():
-      outputFile.write('$' + configName + '=> {\n')
-      config = configs[configName]
-      
-      coma = ''
-      for configParam in config.iterkeys():
-        outputFile.write(coma + '"' + configParam + '" => "' + config[configParam] + '"')
-        coma = ',\n'
-
-      outputFile.write('\n}\n')
-      
-    outputFile.write('\n}\n'
-
-  #write node tasks
-  def writeTasks(outputFile, tasks):
-    for task in tasks :
-      nodename = task['role']
-      command = task['roleCommand']
-      taskParams = task['params']
-    #TODO: write node task to file
-      
\ No newline at end of file
+import json
+
+  #read static imports from file and write them to manifest
+def writeImports(outputFile, inputFileName='imports.txt'):
+  inputFile = open(inputFileName, 'r')
+  
+  for line in inputFile:
+    outputFile.write(line)
+    
+  inputFile.close()
+
+def generateManifest(inputJsonStr):
+#reading json
+  parsedJson = json.loads(inputJsonStr)
+  hostname = parsedJson['hostname']
+  clusterHostInfo = parsedJson['clusterHostInfo']
+  params = parsedJson['params']
+  configurations = parsedJson['configurations']
+  #hostAttributes = parsedJson['hostAttributes']
+  roles = parsedJson['roles']
+  
+#writing manifest
+  manifest = open('site.pp', 'w')
+
+  #writing imports from external static file
+  writeImports(manifest)
+  
+  #writing nodes
+  writeNodes(manifest, clusterHostInfo)
+  
+  #writing params from map
+  writeParams(manifest, params)
+  
+  #writing config maps
+  writeConfigurations(manifest, configurations)
+
+  #writing host attributes
+  #writeHostAttributes(manifest, hostAttributes)
+
+  #writing task definitions 
+  writeTasks(manifest, roles)
+     
+  manifest.close()
+    
+  
+  #read dictionary
+def readDict(file, separator='='):
+  result = dict()
+  
+  for line in file :
+    dictTuple = line.partition(separator)
+    result[dictTuple[0].strip()] = dictTuple[2].strip()
+  
+  return result
+  
+
+  #write nodes
+def writeNodes(outputFile, clusterHostInfo):
+  for node in clusterHostInfo.iterkeys():
+    outputFile.write('$' + node + '= [')
+    coma = ''
+    
+    for host in node:
+      outputFile.write(coma + '\'' + host + '\'')
+      coma = ', '
+
+    outputFile.write(']\n')
+
+#write params
+def writeParams(outputFile, params):
+  for param in params.iterkeys():
+    outputFile.write('$' +  param + '="' + params[param] + '"\n')
+
+#write host attributes
+def writeHostAttributes(outputFile, hostAttributes):
+  outputFile.write('$hostAttributes={\n')
+
+  coma = ''
+  for attribute in hostAttributes.iterkeys():
+    outputFile.write(coma + '"' +  attribute + '" => "{' + hostAttributes[attribute] +
'"}')
+    coma = ',\n'
+
+  outputFile.write('}\n')
+
+#write configurations
+def writeConfigurations(outputFile, configs):
+  outputFile.write('$configuration =  {\n')
+
+  for configName in configs.iterkeys():
+    outputFile.write('$' + configName + '=> {\n')
+    config = configs[configName]
+    
+    coma = ''
+    for configParam in config.iterkeys():
+      outputFile.write(coma + '"' + configParam + '" => "' + config[configParam] + '"')
+      coma = ',\n'
+
+    outputFile.write('\n}\n')
+    
+  outputFile.write('\n}\n')
+
+#write node tasks
+def writeTasks(outputFile, roles):
+  #reading dictionaries
+  rolesToClassFile = open('rolesToClass.dict', 'r')
+  rolesToClass = readDict(rolesToClassFile)
+  rolesToClassFile.close()
+
+  serviceStatesFile =  open('serviceStates.dict', 'r')
+  serviceStates = readDict(serviceStatesFile)
+  serviceStatesFile.close()
+
+  outputFile.write('node /<toBeDefined>/ {\n ')
+  writeStages(outputFile, len(roles))
+  stageNum = 1
+
+  for role in roles :
+    rolename = role['role']
+    command = role['roleCommand']
+    taskParams = role['params']
+    taskParamsNormalized = normalizeTaskParams(taskParams)
+    taskParamsPostfix = ''
+    
+    if len(taskParamsNormalized) > 0 :
+      taskParamsPostfix = ', ' + taskParamsNormalized
+    
+    className = rolesToClass[rolename]
+    serviceState = serviceStates[command]
+    
+    outputFile.write('class {\'' + className + '\':' + ' stage => ' + str(stageNum) +
', service_state => ' + serviceState + taskParamsPostfix + '}\n')
+    stageNum = stageNum + 1
+    
+def normalizeTaskParams(taskParams):
+  result = ''
+  coma = ''
+  
+  for paramName in taskParams.iterkeys():
+    result = coma + result + paramName + ' => ' + taskParams[paramName]
+    coma = ','
+    
+  return result
+  
+def writeStages(outputFile, numStages):
+  arrow = ''
+  
+  for i in range(numStages):
+    outputFile.write(arrow + 'stage{' + str(i) + ' :}')
+    arrow = ' -> '
+  
+  outputFile.write('\n')
+    
+    
+#test code
+jsonFile = open('test.json', 'r')
+jsonStr = jsonFile.read() 
+print '>>>JSON STRING: ' + jsonStr
+generateManifest(jsonStr)

Added: incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/rolesToClass.dict
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/rolesToClass.dict?rev=1395833&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/rolesToClass.dict
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/rolesToClass.dict
Tue Oct  9 01:13:06 2012
@@ -0,0 +1,28 @@
+NAMENODE = hdp-hadoop::namenode
+DATANODE = hdp-hadoop::datanode
+SNAMENODE = hdp-hadoop::snamenode
+JOBTRACKER = hdp-hadoop::jobtracker
+TASKTRACKER = hdp-hadoop::tasktracker
+HDFS_CLIENT = hdp-hadoop::client
+MAPREDUCE_CLIENT = hdp-hadoop::client
+ZOOKEEPER_SERVER = hdp-zookeeper
+ZOOKEEPER_CLIENT = hdp-zookeeper::client
+HBASE_MASTER = hdp-hbase::master
+HBASE_REGIONSERVER = hdp-hbase::regionserver
+HBASE_CLIENT = hdp-hbase::client
+PIG_CLIENT = hdp-pig
+SQOOP_CLIENT = hdp-sqoop
+OOZIE_SERVER = hdp-oozie::server
+OOZIE_CLIENT = hdp-oozie::client
+HIVE_CLIENT = hdp-hive::client
+HCATALOG_CLIENT = hdp-hcat
+HCATALOG_SERVER = hdp-hcat::server
+HIVE_SERVER = hdp-hive::server
+HIVE_MYSQL = hdp-mysql::server
+TEMPLETON_SERVER = hdp-templeton::server
+TEMPLETON_CLIENT = hdp-templeton::client
+DASHBOARD = hdp-dashboard
+NAGIOS_SERVER = hdp-nagios::server
+GANGLIA_MONITOR_SERVER = hdp-ganglia::server
+GANGLIA_MONITOR = hdp-ganglia::monitor
+HTTPD = hdp-monitor-webserver
\ No newline at end of file

Added: incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/serviceStates.dict
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/serviceStates.dict?rev=1395833&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/serviceStates.dict
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/serviceStates.dict
Tue Oct  9 01:13:06 2012
@@ -0,0 +1,2 @@
+START = running
+INSTALL = installed_and_configured
\ No newline at end of file

Added: incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/test.json
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/test.json?rev=1395833&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/test.json
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-agent/src/main/python/manifestGenerator/test.json
Tue Oct  9 01:13:06 2012
@@ -0,0 +1,33 @@
+{
+"commandId": "234",
+"hostname":  "h1.hortonworks.com",
+
+"clusterHostInfo" : 
+{
+"NAMENODE": ["h2.hortonworks.com"],
+"DATANODE": ["h1.hortonworks.com", "h2.hortonworks.com"]
+},
+"params": 
+{
+"hdfs_user" : "hdfs",
+"jdk_location": "lah/blah"
+},
+"configurations" : {
+"hdfs_site" : { "dfs.block.size" : "256000000", "dfs.replication" : "1" } ,
+"core_site" :  { "fs.default.name" : "hrt8n36.cc1.ygridcore.net" }
+},
+"roles": [
+{
+"role" : "DATANODE", 
+"roleCommand": "START",
+"params" : {
+"myid" : "23"
+}
+},
+{
+"role": "NAMENODE",
+"roleCommand": "INSTALL",
+"params" : {}
+}
+]
+}



Mime
View raw message