2 Created on Mar 25, 2014 6 @link: http://hierarchical-cluster-engine.com/ 7 @copyright: Copyright © 2013-2014 IOIX Ukraine 8 @license: http://hierarchical-cluster-engine.com/license/ 16 from cement.core
import foundation
20 from DTMAObjectsFiller
import DTMAObjectsFiller
24 import Constants
as CONSTANTS
30 logger = logging.getLogger(APP_CONSTS.LOGGER_NAME)
36 class DTMA(foundation.CementApp):
39 label = CONSTANTS.APP_NAME
45 foundation.CementApp.__init__(self)
46 self.
config = ConfigParser.ConfigParser()
68 host = str(self.
config.get(CONSTANTS.APP_NAME, CONSTANTS.DTM_HOST))
69 if len(host) > 1
and host[0] ==
"\"":
73 port = str(self.
config.get(CONSTANTS.APP_NAME, CONSTANTS.DTM_PORT))
74 addr = host +
":" + port
76 transport.Consts.TCP_TYPE)
86 elif task == CONSTANTS.TASKS[0]:
88 elif task == CONSTANTS.TASKS[1]:
90 elif task == CONSTANTS.TASKS[2]:
92 elif task == CONSTANTS.TASKS[3]:
94 elif task == CONSTANTS.TASKS[4]:
96 elif task == CONSTANTS.TASKS[5]:
98 elif task == CONSTANTS.TASKS[6]:
104 return json.dumps([ret], default=
lambda o: o.__dict__, sort_keys=
True, indent=4)
111 if self.pargs.config
is None:
112 configReadList = self.
config.read(CONSTANTS.DEFAULT_CONFIG_NAME1)
113 if len(configReadList) == 0:
114 configReadList = self.
config.read(CONSTANTS.DEFAULT_CONFIG_NAME2)
116 configReadList = self.
config.read(self.pargs.config)
117 return len(configReadList)
124 if cmd
in CONSTANTS.TASKS[1:3]:
125 if self.pargs.fields
is None or self.pargs.classes
is None:
126 self.
fillError(CONSTANTS.ERROR_STR2, CONSTANTS.ERROR_ARGS2)
128 elif cmd == CONSTANTS.TASKS[0]
or cmd == CONSTANTS.TASKS[3]:
129 if self.pargs.classes
is None:
130 optionName = [CONSTANTS.SERVER_CONFIG_OPTION_NAME, CONSTANTS.SERVER_CONFIG_OPTION_NAME2]\
131 [cmd == CONSTANTS.TASKS[3]]
133 self.pargs.classes = str(self.
config.get(CONSTANTS.SERVER_CONFIG_SECTION_NAME, optionName))
134 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
135 self.
fillError(CONSTANTS.ERROR_STR3.format(CONSTANTS.SERVER_CONFIG_SECTION_NAME, optionName),
136 CONSTANTS.ERROR_CONFIG_SECTION)
151 timeout = self.
config.get(CONSTANTS.APP_NAME, CONSTANTS.TCP_TIMEOUT_CONFIG_NAME)
152 except ConfigParser.NoSectionError:
153 timeout = CONSTANTS.TCP_TIMEOUT
154 except ConfigParser.NoOptionError:
155 timeout = CONSTANTS.TCP_TIMEOUT
157 for requestObject
in requestObjects:
158 if cmd == CONSTANTS.TASKS[0]:
159 eventType = EVENT_TYPES.ADMIN_FETCH_STAT_DATA
161 elif cmd == CONSTANTS.TASKS[1]:
162 eventType = EVENT_TYPES.ADMIN_SET_CONFIG_VARS
164 elif cmd == CONSTANTS.TASKS[2]:
165 eventType = EVENT_TYPES.ADMIN_GET_CONFIG_VARS
167 elif cmd == CONSTANTS.TASKS[3]:
168 eventType = EVENT_TYPES.ADMIN_STATE
170 elif cmd == CONSTANTS.TASKS[4]:
171 eventType = EVENT_TYPES.ADMIN_SUSPEND
173 elif cmd == CONSTANTS.TASKS[5]:
174 eventType = EVENT_TYPES.ADMIN_SYSTEM
176 elif cmd == CONSTANTS.TASKS[6]:
177 eventType = EVENT_TYPES.ADMIN_SQL_CUSTOM
180 event = self.
eventBuilder.build(eventType, requestObject)
183 responseTuple = [emptyResponse, CONSTANTS.ERROR_NETWORK]
186 responseTuple = [retEvent.eventObj, CONSTANTS.ERROR_NOERROR]
187 responses.append(responseTuple)
197 logIniFileName = self.
config.get(CONSTANTS.LOG_CONFIG_SECTION_NAME, CONSTANTS.LOG_CONFIG_OPTION_NAME)
198 if logIniFileName !=
None:
199 logging.config.fileConfig(logIniFileName, disable_existing_loggers=
False)
200 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
201 self.
errorStr = CONSTANTS.ERROR_STR8
202 self.
errorCode = CONSTANTS.ERROR_LOG_SECTION_ERROR
203 except Exception, err:
204 self.
errorStr = CONSTANTS.ERROR_STR10 +
': ' + str(err)
205 self.
errorCode = CONSTANTS.ERROR_LOG_INIT
213 foundation.CementApp.setup(self)
219 foundation.CementApp.run(self)
221 if '-h' in self.argv
or '--help' in self.argv:
223 requestObjects =
None 228 if self.
errorCode == CONSTANTS.ERROR_NOERROR:
231 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
232 self.
fillError(CONSTANTS.ERROR_STR3, CONSTANTS.ERROR_CONFIG_SECTION)
233 if not isHelpArg
and self.pargs.cmd
is None:
234 self.
fillError(CONSTANTS.ERROR_STR1, CONSTANTS.ERROR_ARGS1)
235 elif self.pargs.cmd
is not None and self.pargs.cmd
in CONSTANTS.TASKS
and \
238 requestObjects = self.
dTMAObjectsFiller.generateObjectsList(self.pargs.cmd, self.pargs.fields,
241 jsonBuf = json.dumps(responseObjects, default=
lambda o: o.__dict__, sort_keys=
True, indent=4)
243 self.
fillError(CONSTANTS.ERROR_STR4, CONSTANTS.ERROR_FIELDS_ARG)
245 self.
fillError(CONSTANTS.ERROR_STR5, CONSTANTS.ERROR_CLASSES_ARG)
247 self.
errorStr = CONSTANTS.ERROR_STR9
248 self.
errorCode = CONSTANTS.ERROR_NO_CONFIG
252 sys.stdout.write(jsonBuf)
254 logger.info(APP_CONSTS.LOGGER_DELIMITER_LINE)
260 foundation.CementApp.close(self)
def checkAdditionalArgs(self, cmd)
checkAdditionalArgs method Method checks additions mandatory argument's present
def transportCommunications(self, cmd, requestObjects)
taskProcessingDeserialize method Method serializes incoming task to the JSON string ...
def loadLogConfigFile(self)
load logging load logging configuration (log file, log level, filters)
DTMA Class contents main functional of DTMA application, class inherits from foundation.CementApp.
GeneralResponse event object, represents general state response for multipurpose usage.
def configReader(self)
configReader method Method try to read config file by prereared paths, return count of readed configs...
AdminConfigVars event object, for admin set or get config variables from any of threaded classes or a...
DTMCObjectsFiller Class contents serialize/deserialize methods for incoming "DTMA" commands...
def fillError(self, errorStr, errorCode)
fillError method calls from error-code point from main processing (...from event handlers) ...
Class hides routines of bulding connection objects.
def close(self)
close method Method calls after application run
AdminStatData event object, for admin fetch stat fields and possible data from any threaded classes i...
def setup(self)
setup method Method calls before run application
def __init__(self, connectionBuilder=None)
constructor initialise all class variable and recieve connectionBuilder as param(not mandatory) ...
DTMAExceptions module keepts DTMA module native exceptions.
def connectionInit(self)
connectionInit method initializes internal variables that containts network connections/communication...
def run(self)
run method Method contains main application functionality
def generateEmptyResponse(self, task)
generateEmptyResponse method If here was some critical error, we generate empty response here ...