def __init__(self, inbox, outbox, hostID, queue, monitorInterval): # Save arguments tpSize = config.getfloat('irs', 'thread_pool_size') / 2 waitTimeout = 3 maxTasks = config.getfloat('irs', 'max_tasks') self.tp = ThreadPool(tpSize, waitTimeout, maxTasks) self._stop = False self._flush = False self._queue = queue self._activeMessages = {} self._monitorInterval = monitorInterval self._hostID = int(hostID) self._used_slots_array = [0] * MESSAGES_PER_MAILBOX self._outgoingMail = EMPTYMAILBOX self._incomingMail = EMPTYMAILBOX # TODO: add support for multiple paths (multiple mailboxes) self._spmStorageDir = config.get('irs', 'repository') self._inCmd = [ constants.EXT_DD, 'if=' + str(inbox), 'iflag=direct,fullblock', 'bs=' + str(BLOCK_SIZE), 'count=' + str(BLOCKS_PER_MAILBOX), 'skip=' + str(self._hostID * BLOCKS_PER_MAILBOX) ] self._outCmd = [ constants.EXT_DD, 'of=' + str(outbox), 'iflag=fullblock', 'oflag=direct', 'conv=notrunc', 'bs=' + str(BLOCK_SIZE), 'seek=' + str(self._hostID * BLOCKS_PER_MAILBOX) ] self._init = False self._initMailbox() # Read initial mailbox state self._msgCounter = 0 self._sendMail() # Clear outgoing mailbox threading.Thread.__init__(self) self.daemon = True self.start()
def __init__(self, tpSize=config.getfloat('irs', 'thread_pool_size'), waitTimeout=3, maxTasks=config.getfloat('irs', 'max_tasks')): self.storage_repository = config.get('irs', 'repository') self.tp = ThreadPool(tpSize, waitTimeout, maxTasks) self._tasks = {} self._unqueuedTasks = []
def __init__(self, pool, maxHostID, monitorInterval=2): self._messageTypes = {} # Save arguments self._stop = False self._stopped = False self._poolID = str(pool.spUUID) self._spmStorageDir = pool.storage_repository tpSize = config.getfloat('irs', 'thread_pool_size') / 2 waitTimeout = 3 maxTasks = config.getfloat('irs', 'max_tasks') self.tp = ThreadPool(tpSize, waitTimeout, maxTasks) # *** IMPORTANT NOTE: The SPM's inbox is the HSMs' outbox and vice # versa *** # self._inbox = os.path.join(self._spmStorageDir, self._poolID, "mastersd", sd.DOMAIN_META_DATA, "inbox") if not os.path.exists(self._inbox): self.log.error("SPM_MailMonitor create failed - inbox %s does not " "exist" % repr(self._inbox)) raise RuntimeError("SPM_MailMonitor create failed - inbox %s does " "not exist" % repr(self._inbox)) self._outbox = os.path.join(self._spmStorageDir, self._poolID, "mastersd", sd.DOMAIN_META_DATA, "outbox") if not os.path.exists(self._outbox): self.log.error("SPM_MailMonitor create failed - outbox %s does " "not exist" % repr(self._outbox)) raise RuntimeError("SPM_MailMonitor create failed - outbox %s " "does not exist" % repr(self._outbox)) self._numHosts = int(maxHostID) self._outMailLen = MAILBOX_SIZE * self._numHosts self._monitorInterval = monitorInterval # TODO: add support for multiple paths (multiple mailboxes) self._outgoingMail = self._outMailLen * "\0" self._incomingMail = self._outgoingMail self._inCmd = ['dd', 'if=' + str(self._inbox), 'iflag=direct,fullblock', 'count=1' ] self._outCmd = ['dd', 'of=' + str(self._outbox), 'oflag=direct', 'iflag=fullblock', 'conv=notrunc', 'count=1' ] self._outLock = thread.allocate_lock() self._inLock = thread.allocate_lock() # Clear outgoing mail self.log.debug("SPM_MailMonitor - clearing outgoing mail, command is: " "%s", self._outCmd) cmd = self._outCmd + ['bs=' + str(self._outMailLen)] (rc, out, err) = _mboxExecCmd(cmd, sudo=False, data=self._outgoingMail) if rc: self.log.warning("SPM_MailMonitor couldn't clear outgoing mail, " "dd failed") thread.start_new_thread(self.run, (self, )) self.log.debug('SPM_MailMonitor created for pool %s' % self._poolID)
def __init__(self, pool, maxHostID, monitorInterval=2): self._messageTypes = {} # Save arguments self._stop = False self._stopped = False self._poolID = str(pool.spUUID) self._spmStorageDir = pool.storage_repository tpSize = config.getfloat('irs', 'thread_pool_size') / 2 waitTimeout = 3 maxTasks = config.getfloat('irs', 'max_tasks') self.tp = ThreadPool(tpSize, waitTimeout, maxTasks) # *** IMPORTANT NOTE: The SPM's inbox is the HSMs' outbox and vice # versa *** # self._inbox = os.path.join(self._spmStorageDir, self._poolID, "mastersd", sd.DOMAIN_META_DATA, "inbox") if not os.path.exists(self._inbox): self.log.error("SPM_MailMonitor create failed - inbox %s does not " "exist" % repr(self._inbox)) raise RuntimeError("SPM_MailMonitor create failed - inbox %s does " "not exist" % repr(self._inbox)) self._outbox = os.path.join(self._spmStorageDir, self._poolID, "mastersd", sd.DOMAIN_META_DATA, "outbox") if not os.path.exists(self._outbox): self.log.error("SPM_MailMonitor create failed - outbox %s does " "not exist" % repr(self._outbox)) raise RuntimeError("SPM_MailMonitor create failed - outbox %s " "does not exist" % repr(self._outbox)) self._numHosts = int(maxHostID) self._outMailLen = MAILBOX_SIZE * self._numHosts self._monitorInterval = monitorInterval # TODO: add support for multiple paths (multiple mailboxes) self._outgoingMail = self._outMailLen * "\0" self._incomingMail = self._outgoingMail self._inCmd = [ 'dd', 'if=' + str(self._inbox), 'iflag=direct,fullblock', 'count=1' ] self._outCmd = [ 'dd', 'of=' + str(self._outbox), 'oflag=direct', 'iflag=fullblock', 'conv=notrunc', 'count=1' ] self._outLock = thread.allocate_lock() self._inLock = thread.allocate_lock() # Clear outgoing mail self.log.debug( "SPM_MailMonitor - clearing outgoing mail, command is: " "%s", self._outCmd) cmd = self._outCmd + ['bs=' + str(self._outMailLen)] (rc, out, err) = misc.execCmd(cmd, sudo=False, data=self._outgoingMail) if rc: self.log.warning("SPM_MailMonitor couldn't clear outgoing mail, " "dd failed") thread.start_new_thread(self.run, (self, )) self.log.debug('SPM_MailMonitor created for pool %s' % self._poolID)
def __init__(self, sdUUID, hostId, interval, changeEvent, checker): self.thread = concurrent.thread(self._run, logger=log.name) self.stopEvent = threading.Event() self.domain = None self.sdUUID = sdUUID self.hostId = hostId self.interval = interval self.changeEvent = changeEvent self.checker = checker self.lock = threading.Lock() self.monitoringPath = None # For backward compatibility, we must present a fake status before # collecting the first sample. The fake status is marked as # actual=False so engine can handle it correctly. self.status = Status(PathStatus(actual=False), DomainStatus(actual=False)) self.isIsoDomain = None self.isoPrefix = None self.lastRefresh = time.time() # Use float to allow short refresh internal during tests. self.refreshTime = \ config.getfloat("irs", "repo_stats_cache_refresh_timeout") self.wasShutdown = False # Used for synchronizing during the tests self.cycleCallback = None
def __init__(self, sdUUID, hostId, interval, changeEvent, checker): self.thread = concurrent.thread(self._run, logger=log.name, name="monitor/" + sdUUID[:7]) self.stopEvent = threading.Event() self.domain = None self.sdUUID = sdUUID self.hostId = hostId self.interval = interval self.changeEvent = changeEvent self.checker = checker self.lock = threading.Lock() self.monitoringPath = None # For backward compatibility, we must present a fake status before # collecting the first sample. The fake status is marked as # actual=False so engine can handle it correctly. self.status = Status(PathStatus(actual=False), DomainStatus(actual=False)) self.isIsoDomain = None self.isoPrefix = None self.lastRefresh = time.time() # Use float to allow short refresh internal during tests. self.refreshTime = \ config.getfloat("irs", "repo_stats_cache_refresh_timeout") self.wasShutdown = False # Used for synchronizing during the tests self.cycleCallback = None
def __init__(self, inbox, outbox, hostID, queue, monitorInterval): # Save arguments tpSize = config.getfloat('irs', 'thread_pool_size') / 2 waitTimeout = 3 maxTasks = config.getfloat('irs', 'max_tasks') self.tp = ThreadPool(tpSize, waitTimeout, maxTasks) self._stop = False self._flush = False self._queue = queue self._activeMessages = {} self._monitorInterval = monitorInterval self._hostID = int(hostID) self._used_slots_array = [0] * MESSAGES_PER_MAILBOX self._outgoingMail = EMPTYMAILBOX self._incomingMail = EMPTYMAILBOX # TODO: add support for multiple paths (multiple mailboxes) self._spmStorageDir = config.get('irs', 'repository') self._inCmd = [constants.EXT_DD, 'if=' + str(inbox), 'iflag=direct,fullblock', 'bs=' + str(BLOCK_SIZE), 'count=' + str(BLOCKS_PER_MAILBOX), 'skip=' + str(self._hostID * BLOCKS_PER_MAILBOX) ] self._outCmd = [constants.EXT_DD, 'of=' + str(outbox), 'iflag=fullblock', 'oflag=direct', 'conv=notrunc', 'bs=' + str(BLOCK_SIZE), 'seek=' + str(self._hostID * BLOCKS_PER_MAILBOX) ] self._init = False self._initMailbox() # Read initial mailbox state self._msgCounter = 0 self._sendMail() # Clear outgoing mailbox threading.Thread.__init__(self) self.daemon = True self.start()