|
@@ -1,10 +1,37 @@
|
|
|
|
+#!/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 this work for additional information
|
|
|
|
+regarding copyright ownership. The ASF licenses this file
|
|
|
|
+to you under the Apache License, Version 2.0 (the
|
|
|
|
+"License"); you may not use this file except in compliance
|
|
|
|
+with the License. You may obtain a copy of the License at
|
|
|
|
+
|
|
|
|
+ http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
+
|
|
|
|
+Unless required by applicable law or agreed to in writing, software
|
|
|
|
+distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
+See the License for the specific language governing permissions and
|
|
|
|
+limitations under the License.
|
|
|
|
+'''
|
|
|
|
+
|
|
import json
|
|
import json
|
|
|
|
+import os.path
|
|
|
|
+import logging
|
|
|
|
+
|
|
|
|
+logger = logging.getLogger()
|
|
|
|
|
|
#read static imports from file and write them to manifest
|
|
#read static imports from file and write them to manifest
|
|
def writeImports(outputFile, inputFileName='imports.txt'):
|
|
def writeImports(outputFile, inputFileName='imports.txt'):
|
|
inputFile = open(inputFileName, 'r')
|
|
inputFile = open(inputFileName, 'r')
|
|
-
|
|
|
|
|
|
+ modulesdir = os.path.abspath(os.getcwd() + "../../../puppet/modules/")
|
|
|
|
+ logger.info("Modules dir is " + modulesdir)
|
|
for line in inputFile:
|
|
for line in inputFile:
|
|
|
|
+ modulename = line.rstrip('\n')
|
|
|
|
+ line = "import " + "\"" + modulesdir + "/" + modulename + "\"\n"
|
|
outputFile.write(line)
|
|
outputFile.write(line)
|
|
|
|
|
|
inputFile.close()
|
|
inputFile.close()
|
|
@@ -17,7 +44,7 @@ def generateManifest(inputJsonStr):
|
|
params = parsedJson['params']
|
|
params = parsedJson['params']
|
|
configurations = parsedJson['configurations']
|
|
configurations = parsedJson['configurations']
|
|
#hostAttributes = parsedJson['hostAttributes']
|
|
#hostAttributes = parsedJson['hostAttributes']
|
|
- roles = parsedJson['roles']
|
|
|
|
|
|
+ roles = parsedJson['roleCommands']
|
|
|
|
|
|
#writing manifest
|
|
#writing manifest
|
|
manifest = open('site.pp', 'w')
|
|
manifest = open('site.pp', 'w')
|
|
@@ -60,8 +87,8 @@ def writeNodes(outputFile, clusterHostInfo):
|
|
outputFile.write('$' + node + '= [')
|
|
outputFile.write('$' + node + '= [')
|
|
coma = ''
|
|
coma = ''
|
|
|
|
|
|
- for host in node:
|
|
|
|
- outputFile.write(coma + '\'' + host + '\'')
|
|
|
|
|
|
+ for value in clusterHostInfo[node]:
|
|
|
|
+ outputFile.write(coma + '\'' + value + '\'')
|
|
coma = ', '
|
|
coma = ', '
|
|
|
|
|
|
outputFile.write(']\n')
|
|
outputFile.write(']\n')
|
|
@@ -87,7 +114,7 @@ def writeConfigurations(outputFile, configs):
|
|
outputFile.write('$configuration = {\n')
|
|
outputFile.write('$configuration = {\n')
|
|
|
|
|
|
for configName in configs.iterkeys():
|
|
for configName in configs.iterkeys():
|
|
- outputFile.write('$' + configName + '=> {\n')
|
|
|
|
|
|
+ outputFile.write(configName + '=> {\n')
|
|
config = configs[configName]
|
|
config = configs[configName]
|
|
|
|
|
|
coma = ''
|
|
coma = ''
|
|
@@ -95,7 +122,7 @@ def writeConfigurations(outputFile, configs):
|
|
outputFile.write(coma + '"' + configParam + '" => "' + config[configParam] + '"')
|
|
outputFile.write(coma + '"' + configParam + '" => "' + config[configParam] + '"')
|
|
coma = ',\n'
|
|
coma = ',\n'
|
|
|
|
|
|
- outputFile.write('\n}\n')
|
|
|
|
|
|
+ outputFile.write('\n},\n')
|
|
|
|
|
|
outputFile.write('\n}\n')
|
|
outputFile.write('\n}\n')
|
|
|
|
|
|
@@ -110,14 +137,14 @@ def writeTasks(outputFile, roles):
|
|
serviceStates = readDict(serviceStatesFile)
|
|
serviceStates = readDict(serviceStatesFile)
|
|
serviceStatesFile.close()
|
|
serviceStatesFile.close()
|
|
|
|
|
|
- outputFile.write('node /<toBeDefined>/ {\n ')
|
|
|
|
|
|
+ outputFile.write('node /default/ {\n ')
|
|
writeStages(outputFile, len(roles))
|
|
writeStages(outputFile, len(roles))
|
|
stageNum = 1
|
|
stageNum = 1
|
|
|
|
|
|
for role in roles :
|
|
for role in roles :
|
|
rolename = role['role']
|
|
rolename = role['role']
|
|
- command = role['roleCommand']
|
|
|
|
- taskParams = role['params']
|
|
|
|
|
|
+ command = role['cmd']
|
|
|
|
+ taskParams = role['roleParams']
|
|
taskParamsNormalized = normalizeTaskParams(taskParams)
|
|
taskParamsNormalized = normalizeTaskParams(taskParams)
|
|
taskParamsPostfix = ''
|
|
taskParamsPostfix = ''
|
|
|
|
|
|
@@ -127,9 +154,10 @@ def writeTasks(outputFile, roles):
|
|
className = rolesToClass[rolename]
|
|
className = rolesToClass[rolename]
|
|
serviceState = serviceStates[command]
|
|
serviceState = serviceStates[command]
|
|
|
|
|
|
- outputFile.write('class {\'' + className + '\':' + ' stage => ' + str(stageNum) + ', service_state => ' + serviceState + taskParamsPostfix + '}\n')
|
|
|
|
|
|
+ outputFile.write('class {\'' + className + '\':' + ' stage => ' + str(stageNum) +
|
|
|
|
+ ', service_state => ' + serviceState + taskParamsPostfix + '}\n')
|
|
stageNum = stageNum + 1
|
|
stageNum = stageNum + 1
|
|
-
|
|
|
|
|
|
+ outputFile.write('}\n')
|
|
def normalizeTaskParams(taskParams):
|
|
def normalizeTaskParams(taskParams):
|
|
result = ''
|
|
result = ''
|
|
coma = ''
|
|
coma = ''
|
|
@@ -149,9 +177,8 @@ def writeStages(outputFile, numStages):
|
|
|
|
|
|
outputFile.write('\n')
|
|
outputFile.write('\n')
|
|
|
|
|
|
-
|
|
|
|
|
|
+logging.basicConfig(level=logging.DEBUG)
|
|
#test code
|
|
#test code
|
|
jsonFile = open('test.json', 'r')
|
|
jsonFile = open('test.json', 'r')
|
|
jsonStr = jsonFile.read()
|
|
jsonStr = jsonFile.read()
|
|
-print '>>>JSON STRING: ' + jsonStr
|
|
|
|
generateManifest(jsonStr)
|
|
generateManifest(jsonStr)
|