def initializeHandler(cls, serviceInfoDict): cls.msgClient = MessageClient("WorkloadManagement/OptimizationMind") result = cls.msgClient.connect(JobManager=True) if not result['OK']: cls.log.error("Cannot connect to OptimizationMind!", result['Message']) return result
def connect(self): self.__msgClient = MessageClient(self.__mindName) self.__msgClient.subscribeToMessage("ProcessTask", self.__processTask) self.__msgClient.subscribeToDisconnect(self.__disconnected) result = self.__msgClient.connect( executorTypes=list(self.__modules), maxTasks=self.__maxTasks, extraArgs=self.__extraArgs ) if result["OK"]: self.__aliveLock.alive() gLogger.info("Connected to %s" % self.__mindName) return result
def initializeHandler(cls, serviceInfoDict): """Initialization of DB objects and OptimizationMind""" try: result = ObjectLoader().loadObject( "WorkloadManagementSystem.DB.JobDB", "JobDB") if not result["OK"]: return result cls.jobDB = result["Value"](parentLogger=cls.log) result = ObjectLoader().loadObject( "WorkloadManagementSystem.DB.JobLoggingDB", "JobLoggingDB") if not result["OK"]: return result cls.jobLoggingDB = result["Value"](parentLogger=cls.log) result = ObjectLoader().loadObject( "WorkloadManagementSystem.DB.TaskQueueDB", "TaskQueueDB") if not result["OK"]: return result cls.taskQueueDB = result["Value"](parentLogger=cls.log) result = ObjectLoader().loadObject( "WorkloadManagementSystem.DB.PilotAgentsDB", "PilotAgentsDB") if not result["OK"]: return result cls.pilotAgentsDB = result["Value"](parentLogger=cls.log) except RuntimeError as excp: return S_ERROR("Can't connect to DB: %s" % excp) cls.pilotsLoggingDB = None enablePilotsLogging = Operations().getValue( "/Services/JobMonitoring/usePilotsLoggingFlag", False) if enablePilotsLogging: try: result = ObjectLoader().loadObject( "WorkloadManagementSystem.DB.PilotsLoggingDB", "PilotsLoggingDB") if not result["OK"]: return result cls.pilotsLoggingDB = result["Value"](parentLogger=cls.log) except RuntimeError as excp: return S_ERROR("Can't connect to DB: %s" % excp) cls.msgClient = MessageClient("WorkloadManagement/OptimizationMind") result = cls.msgClient.connect(JobManager=True) if not result["OK"]: cls.log.warn("Cannot connect to OptimizationMind!", result["Message"]) return S_OK()
def initializeHandler(cls, serviceInfoDict): """ Initialization of DB objects and OptimizationMind """ cls.jobDB = JobDB() cls.jobLoggingDB = JobLoggingDB() cls.taskQueueDB = TaskQueueDB() cls.pilotAgentsDB = PilotAgentsDB() cls.pilotsLoggingDB = None enablePilotsLogging = Operations().getValue( '/Services/JobMonitoring/usePilotsLoggingFlag', False) if enablePilotsLogging: cls.pilotsLoggingDB = PilotsLoggingDB() cls.msgClient = MessageClient("WorkloadManagement/OptimizationMind") cls.__connectToOptMind() gThreadScheduler.addPeriodicTask(60, cls.__connectToOptMind) return S_OK()
def addClient(self, cliTrid, destination, clientInitParams, connectParams): if cliTrid in self.__byClient: gLogger.fatal("Trid is duplicated!! this shouldn't happen") return msgClient = MessageClient(destination, **clientInitParams) msgClient.subscribeToDisconnect(self.__srvDisconnect) msgClient.subscribeToAllMessages(self.msgFromSrv) msgClient.setUniqueName(connectParams[0]) result = msgClient.connect(**connectParams[1]) if not result["OK"]: return result self.__inOutLock.acquire() try: self.__byClient[cliTrid] = {"srvEnd": msgClient, "srvTrid": msgClient.getTrid(), "srvName": destination} self.__srvToCliTrid[msgClient.getTrid()] = cliTrid finally: self.__inOutLock.release() return result
def initializeHandler(cls, serviceInfoDict): cls.msgClient = MessageClient("WorkloadManagement/OptimizationMind") cls.__connectToOptMind() gThreadScheduler.addPeriodicTask(60, cls.__connectToOptMind) return S_OK()
return sendPingMsg( msgObj.msgClient, pongid + 1 ) def disconnectedCB( msgClient ): """ Reconnect :) """ retryCount = 0 while retryCount: result = msgClient.connect() if result[ 'OK' ]: return result time.sleep( 1 ) retryCount -= 1 return S_ERROR( "Could not reconnect... :P" ) if __name__ == "__main__": msgClient = MessageClient( "Framework/PingPong" ) msgClient.subscribeToMessage( 'Pong', pongCB ) msgClient.subscribeToDisconnect( disconnectedCB ) result = msgClient.connect() if not result[ 'OK' ]: print("CANNOT CONNECT: %s" % result['Message']) sys.exit(1) result = sendPingMsg( msgClient ) if not result[ 'OK' ]: print("CANNOT SEND PING: %s" % result['Message']) sys.exit(1) #Wait 10 secs of pingpongs :P time.sleep( 10 )