From 240ab3529251b0d61b195d585d09bc78cd66c0a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Ba=C5=9Faran?= Date: Mon, 14 Mar 2016 10:55:28 +0200 Subject: [PATCH] created message type --- README.md | 1 + opt/ahenk/base/Scope.py | 7 +++++++ opt/ahenk/base/logging/AhenkLogger.py | 1 - opt/ahenk/base/model/MessageFactory.py | 16 ++++++++++++++++ opt/ahenk/base/model/MessageType.py | 13 +++++++++++++ opt/ahenk/base/model/Task.py | 10 +++++++--- opt/ahenk/base/task/TaskManager.py | 15 +++++++++++++-- 7 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 opt/ahenk/base/model/MessageFactory.py create mode 100644 opt/ahenk/base/model/MessageType.py diff --git a/README.md b/README.md index 0643774..3e80d72 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This README would normally document whatever steps are necessary to get your app ### How can I build and create deb file ? ### Clone project and go to ahenk project folder, run command below + $ dpkg-buildpackage ### How do I get set up? ### diff --git a/opt/ahenk/base/Scope.py b/opt/ahenk/base/Scope.py index fcb5cf4..e3cb428 100644 --- a/opt/ahenk/base/Scope.py +++ b/opt/ahenk/base/Scope.py @@ -19,6 +19,7 @@ class Scope(object): self.responseQueue=None self.registration=None self.eventManager=None + self.dbService=None @staticmethod @@ -86,3 +87,9 @@ class Scope(object): def setEventManager(self,eventManager): self.eventManager=eventManager + + def getDbService(self): + return self.dbService + + def serDbService(self,dbService): + self.dbService = dbService diff --git a/opt/ahenk/base/logging/AhenkLogger.py b/opt/ahenk/base/logging/AhenkLogger.py index 66e08ee..aa850d4 100644 --- a/opt/ahenk/base/logging/AhenkLogger.py +++ b/opt/ahenk/base/logging/AhenkLogger.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # Author: İsmail BAŞARAN import sys -sys.path.append('../..') import logging import logging.config from base.Scope import Scope diff --git a/opt/ahenk/base/model/MessageFactory.py b/opt/ahenk/base/model/MessageFactory.py new file mode 100644 index 0000000..edb511b --- /dev/null +++ b/opt/ahenk/base/model/MessageFactory.py @@ -0,0 +1,16 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN +from base.model.MessageType import MessageType + +class MessageFactory(object): + + def createMessage(self,type,message): + + if type == MessageType.TASK_RECEIVED: + return "Message receivden response" + elif type == MessageType.TASK_PROCESSING: + return "Message processing response" + else + return None + createMessage = staticmethod(createMessage) diff --git a/opt/ahenk/base/model/MessageType.py b/opt/ahenk/base/model/MessageType.py new file mode 100644 index 0000000..5713e04 --- /dev/null +++ b/opt/ahenk/base/model/MessageType.py @@ -0,0 +1,13 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN +from enum import Enum + +class MessageType(Enum): + TASK_RECEIVED="TASK_RECEIVED" + TASK_PROCESSING="TASK_PROCESSING" + TASK_PROCESSED="TASK_PROCESSED" + TASK_ERROR="TASK_ERROR" + TASK_WARNING="TASK_WARNING" + POLICY_RECEIVED="POLICY_RECEIVED" + POLICY_PROCESSED="POLICY_PROCESSED" diff --git a/opt/ahenk/base/model/Task.py b/opt/ahenk/base/model/Task.py index 3c1846e..4b099ff 100644 --- a/opt/ahenk/base/model/Task.py +++ b/opt/ahenk/base/model/Task.py @@ -10,11 +10,15 @@ class Task(object): self.request = self.payload[u'request'] @property - def getPluginName(self): + def task_id(self): + self.request[u'id'] + + @property + def plugin_name(self): self.request[u'pluginName'] @property - def getCommandId(self): + def command_id(self): self.request[u'commandId'] @property @@ -22,5 +26,5 @@ class Task(object): self.request[u'parameterMap'] @property - def pluginVersion(self): + def plugin_version(self): self.request[u'pluginVersion'] diff --git a/opt/ahenk/base/task/TaskManager.py b/opt/ahenk/base/task/TaskManager.py index 82ab0bd..5612147 100644 --- a/opt/ahenk/base/task/TaskManager.py +++ b/opt/ahenk/base/task/TaskManager.py @@ -2,6 +2,8 @@ # -*- coding: utf-8 -*- # Author: İsmail BAŞARAN from base.Scope import Scope +from base.model.MessageFactory import MessageFactory +from base.model.MessageType import MessageType class TaskManager(object): """docstring for TaskManager""" @@ -10,11 +12,12 @@ class TaskManager(object): scope = Scope.getInstance() self.pluginManager = scope.getPluginManager() self.logger= scope.getLogger() + self.dbService = scope.getDbService() def addTask(self,task): try: - # TODO add log - # TODO save task to database + self.logger.debug('Adding task ... ' + str(task.plugin_ame) + ' - ' + str(task.command_id)) + self.saveTask(task) # TODO send task received message self.pluginManager.processTask(task) except Exception as e: @@ -36,3 +39,11 @@ class TaskManager(object): # TODO not implemented yet # remove task if it is processed pass + + def sendMessage(self,type,message): + # TODO not implemented yet + pass + + +if __name__ == '__main__': + print(MessageFactory.createMessage(MessageType.TASK_PROCESSING,"my message"))