mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 21:22:21 +03:00
ahenk service init methots
This commit is contained in:
parent
44891af172
commit
85a9bcd5a1
1 changed files with 102 additions and 48 deletions
|
@ -24,6 +24,7 @@ from base.messaging.Messaging import Messaging
|
||||||
from base.plugin.PluginManager import PluginManager
|
from base.plugin.PluginManager import PluginManager
|
||||||
from base.registration.Registration import Registration
|
from base.registration.Registration import Registration
|
||||||
from base.task.TaskManager import TaskManager
|
from base.task.TaskManager import TaskManager
|
||||||
|
from base.scheduler.scheduler_factory import SchedulerFactory
|
||||||
|
|
||||||
pidfilePath = '/var/run/ahenk.pid'
|
pidfilePath = '/var/run/ahenk.pid'
|
||||||
|
|
||||||
|
@ -31,10 +32,95 @@ pidfilePath = '/var/run/ahenk.pid'
|
||||||
class AhenkDeamon(BaseDaemon):
|
class AhenkDeamon(BaseDaemon):
|
||||||
"""docstring for AhenkDeamon"""
|
"""docstring for AhenkDeamon"""
|
||||||
|
|
||||||
def reload(self, msg):
|
def reload(self):
|
||||||
# reload service here
|
# reload service here
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def init_logger(self):
|
||||||
|
logger = Logger()
|
||||||
|
logger.info('[AhenkDeamon] Log was set')
|
||||||
|
Scope.getInstance().setLogger(logger)
|
||||||
|
return logger
|
||||||
|
|
||||||
|
def init_config_manager(self, configFilePath, configfileFolderPath):
|
||||||
|
configManager = ConfigManager(configFilePath, configfileFolderPath)
|
||||||
|
config = configManager.read()
|
||||||
|
Scope.getInstance().setConfigurationManager(config)
|
||||||
|
return config
|
||||||
|
|
||||||
|
def init_scheduler(self):
|
||||||
|
scheduler_ins = SchedulerFactory.get_intstance()
|
||||||
|
scheduler_ins.initialize()
|
||||||
|
Scope.getInstance().set_scheduler(scheduler_ins)
|
||||||
|
sc_thread = threading.Thread(target=scheduler_ins.run)
|
||||||
|
sc_thread.setDaemon(True)
|
||||||
|
sc_thread.start()
|
||||||
|
|
||||||
|
def init_event_manager(self):
|
||||||
|
eventManager = EventManager()
|
||||||
|
Scope.getInstance().setEventManager(eventManager)
|
||||||
|
return eventManager
|
||||||
|
|
||||||
|
def init_ahenk_db(self):
|
||||||
|
db_service = AhenkDbService()
|
||||||
|
db_service.connect()
|
||||||
|
db_service.initialize_table()
|
||||||
|
Scope.getInstance().setDbService(db_service)
|
||||||
|
return db_service
|
||||||
|
|
||||||
|
def init_messaging(self):
|
||||||
|
messageManager = Messaging()
|
||||||
|
Scope.getInstance().setMessageManager(messageManager)
|
||||||
|
return messageManager
|
||||||
|
|
||||||
|
def init_plugin_manager(self):
|
||||||
|
pluginManager = PluginManager()
|
||||||
|
pluginManager.loadPlugins()
|
||||||
|
Scope.getInstance().setPluginManager(pluginManager)
|
||||||
|
return pluginManager
|
||||||
|
|
||||||
|
def init_task_manager(self):
|
||||||
|
taskManager = TaskManager()
|
||||||
|
Scope.getInstance().setTaskManager(taskManager)
|
||||||
|
return taskManager
|
||||||
|
|
||||||
|
def init_registration(self):
|
||||||
|
registration = Registration()
|
||||||
|
Scope.getInstance().setRegistration(registration)
|
||||||
|
return registration
|
||||||
|
|
||||||
|
def init_execution_manager(self):
|
||||||
|
execution_manager = ExecutionManager()
|
||||||
|
Scope.getInstance().setExecutionManager(execution_manager)
|
||||||
|
return execution_manager
|
||||||
|
|
||||||
|
def init_messager(self):
|
||||||
|
messager = Messager()
|
||||||
|
messanger_thread = threading.Thread(target=messager.connect_to_server)
|
||||||
|
messanger_thread.start()
|
||||||
|
|
||||||
|
while messager.is_connected() is False:
|
||||||
|
time.sleep(1)
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
Scope.getInstance().setMessager(messager)
|
||||||
|
return messager
|
||||||
|
|
||||||
|
def init_message_response_queue(self):
|
||||||
|
responseQueue = queue.Queue()
|
||||||
|
messageResponseQueue = MessageResponseQueue(responseQueue)
|
||||||
|
messageResponseQueue.setDaemon(True)
|
||||||
|
messageResponseQueue.start()
|
||||||
|
Scope.getInstance().setResponseQueue(responseQueue)
|
||||||
|
return responseQueue
|
||||||
|
|
||||||
|
def check_registration(self):
|
||||||
|
# TODO restrict number of attemption
|
||||||
|
while Scope.getInstance().getRegistration().is_registered() is False:
|
||||||
|
print('registration need')
|
||||||
|
Scope.getInstance().getLogger().debug('[AhenkDeamon] Attempting to register')
|
||||||
|
Scope.getInstance().getRegistration().registration_request()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print('Ahenk running...')
|
print('Ahenk running...')
|
||||||
|
|
||||||
|
@ -45,65 +131,41 @@ class AhenkDeamon(BaseDaemon):
|
||||||
configfileFolderPath = '/etc/ahenk/config.d/'
|
configfileFolderPath = '/etc/ahenk/config.d/'
|
||||||
|
|
||||||
# configuration manager must be first load
|
# configuration manager must be first load
|
||||||
configManager = ConfigManager(configFilePath, configfileFolderPath)
|
self.init_config_manager(configFilePath, configfileFolderPath)
|
||||||
config = configManager.read()
|
|
||||||
globalscope.setConfigurationManager(config)
|
|
||||||
|
|
||||||
# Logger must be second
|
# Logger must be second
|
||||||
logger = Logger()
|
logger = self.init_logger()
|
||||||
logger.info('[AhenkDeamon] Log was set')
|
|
||||||
globalscope.setLogger(logger)
|
|
||||||
|
|
||||||
eventManager = EventManager()
|
self.init_event_manager()
|
||||||
globalscope.setEventManager(eventManager)
|
|
||||||
logger.info('[AhenkDeamon] Event Manager was set')
|
logger.info('[AhenkDeamon] Event Manager was set')
|
||||||
|
|
||||||
db_service = AhenkDbService()
|
self.init_ahenk_db()
|
||||||
db_service.connect()
|
|
||||||
db_service.initialize_table()
|
|
||||||
globalscope.setDbService(db_service)
|
|
||||||
logger.info('[AhenkDeamon] DataBase Service was set')
|
logger.info('[AhenkDeamon] DataBase Service was set')
|
||||||
|
|
||||||
messageManager = Messaging()
|
self.init_messaging()
|
||||||
globalscope.setMessageManager(messageManager)
|
|
||||||
logger.info('[AhenkDeamon] Message Manager was set')
|
logger.info('[AhenkDeamon] Message Manager was set')
|
||||||
|
|
||||||
pluginManager = PluginManager()
|
self.init_plugin_manager()
|
||||||
pluginManager.loadPlugins()
|
|
||||||
globalscope.setPluginManager(pluginManager)
|
|
||||||
logger.info('[AhenkDeamon] Plugin Manager was set')
|
logger.info('[AhenkDeamon] Plugin Manager was set')
|
||||||
|
|
||||||
taskManager = TaskManager()
|
self.init_task_manager()
|
||||||
globalscope.setTaskManager(taskManager)
|
|
||||||
logger.info('[AhenkDeamon] Task Manager was set')
|
logger.info('[AhenkDeamon] Task Manager was set')
|
||||||
|
|
||||||
registration = Registration()
|
#self.init_registration()
|
||||||
globalscope.setRegistration(registration)
|
|
||||||
logger.info('[AhenkDeamon] Registration was set')
|
logger.info('[AhenkDeamon] Registration was set')
|
||||||
|
|
||||||
execution_manager = ExecutionManager()
|
self.init_execution_manager()
|
||||||
globalscope.setExecutionManager(execution_manager)
|
|
||||||
logger.info('[AhenkDeamon] Execution Manager was set')
|
logger.info('[AhenkDeamon] Execution Manager was set')
|
||||||
|
|
||||||
# TODO restrict number of attemption
|
#self.check_registration()
|
||||||
while registration.is_registered() is False:
|
|
||||||
print('registration need')
|
|
||||||
logger.debug('[AhenkDeamon] Attempting to register')
|
|
||||||
registration.registration_request()
|
|
||||||
|
|
||||||
logger.info('[AhenkDeamon] Ahenk is registered')
|
logger.info('[AhenkDeamon] Ahenk is registered')
|
||||||
|
|
||||||
messager = Messager()
|
messager = self.init_messager()
|
||||||
messanger_thread = threading.Thread(target=messager.connect_to_server)
|
|
||||||
messanger_thread.start()
|
|
||||||
|
|
||||||
while messager.is_connected() is False:
|
|
||||||
time.sleep(1)
|
|
||||||
time.sleep(5)
|
|
||||||
|
|
||||||
globalscope.setMessager(messager)
|
|
||||||
logger.info('[AhenkDeamon] Messager was set')
|
logger.info('[AhenkDeamon] Messager was set')
|
||||||
|
|
||||||
|
self.init_message_response_queue()
|
||||||
|
|
||||||
|
|
||||||
# if registration.is_ldap_registered() is False:
|
# if registration.is_ldap_registered() is False:
|
||||||
# logger.debug('[AhenkDeamon] Attempting to registering ldap')
|
# logger.debug('[AhenkDeamon] Attempting to registering ldap')
|
||||||
# registration.ldap_registration_request() #TODO work on message
|
# registration.ldap_registration_request() #TODO work on message
|
||||||
|
@ -127,14 +189,6 @@ class AhenkDeamon(BaseDaemon):
|
||||||
|
|
||||||
messager.send_direct_message('test')
|
messager.send_direct_message('test')
|
||||||
|
|
||||||
|
|
||||||
responseQueue = queue.Queue()
|
|
||||||
messageResponseQueue = MessageResponseQueue(responseQueue)
|
|
||||||
messageResponseQueue.setDaemon(True)
|
|
||||||
messageResponseQueue.start()
|
|
||||||
globalscope.setResponseQueue(responseQueue)
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue