Esempio n. 1
0
def keepAliveMonitor(mid):
    """keepAliveMonitor(mid: str) -> void

    Prolongs the life of a monitor 'data_life_time'.

    """
    common.assertType(mid, str, "Expected monitor id to be a string value")

    mdata = _getMonitor(mid)

    mdata[K_RWLOCK].acquireWrite()
    mdata[K_TIMESTAMP] = time.time()
    mdata[K_RWLOCK].release()
Esempio n. 2
0
def existsMonitorData(mid):
    """existsMonitorData(mid: str) -> bool

    Returns true if the DB contains data of the specified monitor

    """
    common.assertType(mid, str, "Expected monitor id to be a string value")

    monitor_db_lock.acquireRead()
    ret = mid in monitor_db
    monitor_db_lock.release()

    return ret
Esempio n. 3
0
def existsMonitorData(mid):
    """existsMonitorData(mid: str) -> bool

    Returns true if the DB contains data of the specified monitor

    """
    common.assertType(mid, str, "Expected monitor id to be a string value")

    monitor_db_lock.acquireRead()
    ret = mid in monitor_db
    monitor_db_lock.release()

    return ret
Esempio n. 4
0
def keepAliveMonitor(mid):
    """keepAliveMonitor(mid: str) -> void

    Prolongs the life of a monitor 'data_life_time'.

    """
    common.assertType(mid, str, "Expected monitor id to be a string value")

    mdata = _getMonitor(mid)

    mdata[K_RWLOCK].acquireWrite()
    mdata[K_TIMESTAMP] = time.time()
    mdata[K_RWLOCK].release()
Esempio n. 5
0
def updateMonitorData(mid, sinfodao):
    """updateMonitorData(mid: str, sinfodao: SysInfoDAO) -> void

    Updates the information of the specified client.

    """
    common.assertType(mid, str, "Expeced monitor id to be a string value")
    common.assertType(sinfodao, common.SysInfoDAO, "Expected SysInfoDAO")

    mdata = _getMonitor(mid)

    mdata[K_RWLOCK].acquireWrite()
    mdata[K_SYSINFO] = sinfodao
    mdata[K_TIMESTAMP] = time.time()
    mdata[K_RWLOCK].release()
Esempio n. 6
0
def updateMonitorData(mid, sinfodao):
    """updateMonitorData(mid: str, sinfodao: SysInfoDAO) -> void

    Updates the information of the specified client.

    """
    common.assertType(mid, str, "Expeced monitor id to be a string value")
    common.assertType(sinfodao, common.SysInfoDAO, "Expected SysInfoDAO")

    mdata = _getMonitor(mid)

    mdata[K_RWLOCK].acquireWrite()
    mdata[K_SYSINFO] = sinfodao
    mdata[K_TIMESTAMP] = time.time()
    mdata[K_RWLOCK].release()
Esempio n. 7
0
def getMonitorData(mid):
    """getMonitorData(mid: str) -> SysInfoDAO, str, str

    Returns the stored data of a monitor or raises a KeyError exception if the
    monitor does not exist.

    Returns the tuple (SysInfoDAO, ip, port)

    """
    common.assertType(mid, str, "Expected monitor id to be a string value")

    mdata = _getMonitor(mid)

    mdata[K_RWLOCK].acquireRead()
    sinfodao = mdata[K_SYSINFO]
    port = mdata[K_PORT]
    ip = mdata[K_IP]
    mdata[K_RWLOCK].release()

    return sinfodao, ip, port
Esempio n. 8
0
def getMonitorData(mid):
    """getMonitorData(mid: str) -> SysInfoDAO, str, str

    Returns the stored data of a monitor or raises a KeyError exception if the
    monitor does not exist.

    Returns the tuple (SysInfoDAO, ip, port)

    """
    common.assertType(mid, str, "Expected monitor id to be a string value")

    mdata = _getMonitor(mid)

    mdata[K_RWLOCK].acquireRead()
    sinfodao = mdata[K_SYSINFO]
    port = mdata[K_PORT]
    ip = mdata[K_IP]
    mdata[K_RWLOCK].release()

    return sinfodao, ip, port
Esempio n. 9
0
def initializeNewMonitorData(ip, port):
    """initializeNewMonitorData(ip: str, port: str) -> str

    Generates a monitor id with the given ip and port and initializes an 
    entry in the internal db for this new monitor id.

    Returns the generated monitor id.

    """
    common.assertType(ip, str, "Expected ip to be a string value")
    common.assertType(port, str, "Expected port to be a string value")

    sha256 = hashlib.sha256()   
    sha256.update(ip)
    sha256.update(port)
    mid = sha256.hexdigest()

    monitor_db_lock.acquireWrite()
    monitor_db[mid] = [ip, port, None, time.time(), common.ReadWriteLock()]
    monitor_db_lock.release()

    return mid
Esempio n. 10
0
def initializeNewMonitorData(ip, port):
    """initializeNewMonitorData(ip: str, port: str) -> str

    Generates a monitor id with the given ip and port and initializes an 
    entry in the internal db for this new monitor id.

    Returns the generated monitor id.

    """
    common.assertType(ip, str, "Expected ip to be a string value")
    common.assertType(port, str, "Expected port to be a string value")

    sha256 = hashlib.sha256()
    sha256.update(ip)
    sha256.update(port)
    mid = sha256.hexdigest()

    monitor_db_lock.acquireWrite()
    monitor_db[mid] = [ip, port, None, time.time(), common.ReadWriteLock()]
    monitor_db_lock.release()

    return mid