Ejemplo n.º 1
0
 def add(cls, endpoints, counters):
     es = endpoints and ENDPOINT_DELIMITER.join(sorted(endpoints)) or ""
     cs = counters and COUNTER_DELIMITER.join(sorted(counters)) or ""
     ck = hashlib.md5("%s:%s" %(es.encode("utf8"), cs.encode("utf8"))).hexdigest()
     cursor = db_conn.execute('''insert ignore into tmp_graph (endpoints, counters, ck) values(%s, %s, %s) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id),time_=%s''',
             (es, cs, ck, datetime.datetime.now()))
     id_ = cursor.lastrowid
     db_conn.commit()
     cursor and cursor.close()
     return id_
Ejemplo n.º 2
0
 def add(cls, endpoints, counters):
     es = endpoints and ENDPOINT_DELIMITER.join(sorted(endpoints)) or ""
     cs = counters and COUNTER_DELIMITER.join(sorted(counters)) or ""
     ck = hashlib.md5("%s:%s" %
                      (es.encode("utf8"), cs.encode("utf8"))).hexdigest()
     cursor = db_conn.execute(
         '''insert ignore into tmp_graph (endpoints, counters, ck) values(%s, %s, %s) ON DUPLICATE KEY UPDATE time_=%s''',
         (es, cs, ck, datetime.datetime.now()))
     id_ = cursor.lastrowid
     db_conn.commit()
     cursor and cursor.close()
     return id_
Ejemplo n.º 3
0
 def add(cls, endpoints, counters):
     es = endpoints and ENDPOINT_DELIMITER.join(sorted(endpoints)) or ""
     cs = counters and COUNTER_DELIMITER.join(sorted(counters)) or ""
     ck = hashlib.md5("%s:%s" %(es.encode("utf8"), cs.encode("utf8"))).hexdigest()
     cursor = db_conn.execute('''insert ignore into tmp_graph (endpoints, counters, ck) values(%s, %s, %s) ON DUPLICATE KEY UPDATE time_=%s''',
             (es, cs, ck, datetime.datetime.now()))
     id_ = cursor.lastrowid
     if not id_:
         cursor = db_conn.execute("select id from tmp_graph where ck='" + ck + "'")
         id_ = cursor.fetchone()[0]
     db_conn.commit()
     cursor and cursor.close()
     return id_
Ejemplo n.º 4
0
 def add(cls, endpoints, counters):
     es = endpoints and ENDPOINT_DELIMITER.join(sorted(endpoints)) or ""
     cs = counters and COUNTER_DELIMITER.join(sorted(counters)) or ""
     ck = hashlib.md5("%s:%s" %
                      (es.encode("utf8"), cs.encode("utf8"))).hexdigest()
     cursor = db_conn.execute(
         '''insert ignore into tmp_graph (endpoints, counters, ck) values(%s, %s, %s) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id),time_=%s''',
         (es, cs, ck, datetime.datetime.now()))
     id_ = cursor.lastrowid
     if not id_:
         cursor = db_conn.execute("select id from tmp_graph where ck='" +
                                  ck + "'")
         id_ = cursor.fetchone()[0]
     db_conn.commit()
     cursor and cursor.close()
     return id_