コード例 #1
0
class ResourceProvider(WorkerResource):
    def __init__(self, resourceQ):
        self._logger = Logger(PROCESS_NAME).getLogger()
        self._logger.info('# process start : %s' % PROCESS_NAME)
        self._reqQ = resourceQ['reqQ']
        self._routerQ = resourceQ['routerQ']
        self._resourceQ = multiprocessing.Queue()
        self._networkObj = None

        WorkerResource.__init__(self, self._logger)

    def __del__(self):
        self._logger.warn('@ terminate process : %s' % PROCESS_NAME)
        self.clearResource()

    def doProcess(self):
        try:
            while True:
                reqMsg = self._reqQ.get()
                print "[Q] ResourceProvider :", reqMsg
                protocol, statCode = parseProtocol(reqMsg)
                if protocol == 'SYS_REQ_RESOURCE':
                    self._routerQ.put_nowait(
                        genResWorkerResource(reqMsg['workerId'],
                                             self.getCurrentResource()))

        except KeyboardInterrupt, e:
            pass
コード例 #2
0
class ClientListener:
    def __init__(self, clientQ):
        self._logger = Logger(PROCESS_NAME).getLogger()
        self._logger.info('# process start : %s' % PROCESS_NAME)
        self._clientQ = clientQ
        self._reqQ = clientQ['reqQ']
        self._routerQ = clientQ['routerQ']

    def __del__(self):
        self._logger.warn('@ terminate process : %s' % PROCESS_NAME)

    def runServer(self):
        try:
            hostIp, hostPort = getHostInfo(PROCESS_NAME)
            svrsock = socket(AF_INET, SOCK_STREAM)
            svrsock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
            svrsock.bind((hostIp, hostPort))
            svrsock.listen(5)

            while True:
                socketObj, addr = svrsock.accept()
                clientListener = Thread(target=self._bindClientListener,
                                        args=(socketObj, addr))
                clientListener.setDaemon(1)
                clientListener.start()

                self._logger.info("# connected client")
                self._logger.info("- client addr : %s, port : %d" %
                                  (addr[0], addr[1]))
        except KeyboardInterrupt, ki:
            pass
コード例 #3
0
class MasterNetworkManager:
    def __init__(self, resourceQ):
        self._logger = Logger(PROCESS_NAME).getLogger()
        self._logger.info('# process start : %s' % PROCESS_NAME)
        self._reqQ = resourceQ['reqQ']
        self._routerQ = resourceQ['routerQ']
        self._networkQ = multiprocessing.Queue()
        self._tempProviders = {}
        self._providers = {}

    def __del__(self):
        self._logger.warn('@ terminate process : %s' % PROCESS_NAME)
        for tempId in self._tempProviders.keys():
            self._tempProviders[tempId].close()
        for workerId in self._providers.keys():
            self._providers[workerId].close()

    def _sendMsg(self, **args):
        networkObj = None
        try:
            if args.has_key('tempId'):
                networkObj = self._tempProviders[args['tempId']]
            elif args.has_key('workerId'):
                networkObj = self._providers[args['workerId']]
        except KeyError, e:
            self._logger.warn('# key error : %s' % (str(args)))

        if not networkObj:
            self._logger.warn('# network object not exist.')
            return False
        return networkObj.sendMsg(args)
コード例 #4
0
class ResourceMaster(Resources):
    def __init__(self, resourceQ):
        self._logger = Logger(PROCESS_NAME).getLogger()
        self._logger.info('# process start : %s' % PROCESS_NAME)
        self._reqQ = resourceQ['reqQ']
        self._routerQ = resourceQ['routerQ']
        Resources.__init__(self, self._logger)

    def __del__(self):
        self._logger.warn('@ terminate process : %s' % PROCESS_NAME)

    def doProcess(self):
        try:
            while True:
                reqMsg = self._routerQ.get()
                print "[Q] ResourceMaster :", reqMsg
                protocol, statCode = parseProtocol(reqMsg)

                if protocol == 'SYS_SET_RESOURCE':
                    self.initResource(reqMsg['workerId'], reqMsg['resource'])
                elif protocol == 'SYS_DEL_RESOURCE':
                    self.delResource(reqMsg['workerId'])
                print '[RESOURCE] resource size : %d' % (len(self._resources))
        except KeyboardInterrupt, e:
            pass
コード例 #5
0
ファイル: MainProcess.py プロジェクト: kasugare/test
class MainProcess:
	def __init__(self):
		self._logger = Logger(PROCESS_NAME).getLogger()

	def doProcess(self):
		self._logger.info("Show logger info format")
		self._logger.debug("Show logger debug format")
		self._logger.warn("Show logger warn format")
		self._logger.critical("Show logger critical format")
		self._logger.exception("Show logger except format")
コード例 #6
0
ファイル: DeployManager.py プロジェクト: riahtu/openDPU
class DeployManager:
	def __init__(self, deployQ):
		self._logger = Logger(PROCESS_NAME).getLogger()
		self._logger.info('# process start : %s' %PROCESS_NAME)
		self._reqQ = deployQ['reqQ']
		self._routerQ = deployQ['routerQ']

	def __del__(self):
		self._logger.warn('@ terminate process : %s' %PROCESS_NAME)

	def doProcess(self):
		try:
			while True:
				reqMsg = self._routerQ.get()
				print "[Q] DeployManager :", reqMsg
				print reqMsg
		except KeyboardInterrupt, e:
			pass
コード例 #7
0
ファイル: JobWorkerManager.py プロジェクト: riahtu/openDPU
class JobWorkerManager:
	def __init__(self, jobQ):
		self._logger = Logger(PROCESS_NAME).getLogger()
		self._logger.info('# process start : %s' %PROCESS_NAME)
		self._reqQ = jobQ['reqQ']
		self._routerQ = jobQ['routerQ']

	def __del__(self):
		self._logger.warn('@ terminate process : %s' %PROCESS_NAME)

	def doProcess(self):
		try:
			self._reqQ.put_nowait("[%s] : message test" %PROCESS_NAME)

			while True:
				reqMsg = self._routerQ.get()
				print "[Q] JobWorkerManager :", reqMsg
		except KeyboardInterrupt, e:
			pass
コード例 #8
0
class JobManager:
    def __init__(self, jobQ):
        self._logger = Logger(PROCESS_NAME).getLogger()
        self._logger.info('# process start : %s' % PROCESS_NAME)
        self._reqQ = jobQ['reqQ']
        self._routerQ = jobQ['routerQ']

    def __del__(self):
        self._logger.warn('@ terminate process : %s' % PROCESS_NAME)

    def doProcess(self):
        try:
            self._loadJobs()

            while True:
                reqMsg = self._routerQ.get()
                print "[Q] JobManager(SYS) :", reqMsg
                protocol, statCode = parseProtocol(reqMsg)

        except KeyboardInterrupt, e:
            pass
コード例 #9
0
class WorkerNetworkManager:
    def __init__(self, workerId, networkQ):
        self._logger = Logger(PROCESS_NAME).getLogger()
        self._logger.info('# process start : %s' % PROCESS_NAME)
        self._reqQ = networkQ['reqQ']
        self._routerQ = networkQ['routerQ']
        self._networkQ = multiprocessing.Queue()
        self._workerId = workerId
        self._networkObj = None

    def __del__(self):
        self._logger.warn('@ terminate process : %s' % PROCESS_NAME)

    def doProcess(self):
        try:
            connGatewayQHandler = Thread(target=self._runConnectionGateway,
                                         args=())
            connGatewayQHandler.setDaemon(1)
            connGatewayQHandler.start()

            self._connectMasterServer()

            while True:
                reqMsg = self._reqQ.get()
                print "[Q] WorkerNetworkManager(SYS) :", reqMsg
                protocol, statCode = parseProtocol(reqMsg)

                if protocol == 'SYS_GET_WID':
                    tempId = reqMsg['tempId']
                    self._workerId = reqMsg['workerId']
                    self._networkQ.put_nowait(
                        genSetWid(reqMsg['tempId'], reqMsg['workerId']))
                elif protocol == 'SYS_RES_RESOURCE':
                    self._networkQ.put_nowait(
                        genSetWorkerResource(reqMsg['workerId'],
                                             reqMsg['result']))
        except KeyboardInterrupt, e:
            pass