Skip to content

Commit

Permalink
next round of push
Browse files Browse the repository at this point in the history
  • Loading branch information
bcui6611 committed Apr 21, 2012
1 parent 26eff7f commit a83a553
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions dbaccessor.py
Expand Up @@ -33,10 +33,13 @@ def create_databases(self):
status TEXT, status TEXT,
portDirect INTEGER, portDirect INTEGER,
portProxy INTEGER, portProxy INTEGER,
clusterMembership INTEGER, clusterMembership TEXT,
os TEXT, os TEXT,
uptime INTEGER, uptime INTEGER,
version TEXT)""") version TEXT,
master TEXT)""")
self.cursor.execute(""" CREATE UNIQUE INDEX IF NOT EXISTS server_idx on
ServerNode(host, port, master) """)


self.cursor.execute(""" CREATE TABLE IF NOT EXISTS DiskInfo ( self.cursor.execute(""" CREATE TABLE IF NOT EXISTS DiskInfo (
diskInfoId INTEGER PRIMARY KEY, diskInfoId INTEGER PRIMARY KEY,
Expand Down Expand Up @@ -85,8 +88,11 @@ def create_databases(self):
authType TEXT, authType TEXT,
saslPassword TEXT, saslPassword TEXT,
numReplica INTEGER, numReplica INTEGER,
ramQuota REAL)""") ramQuota REAL,

master TEXT)""")
self.cursor.execute(""" CREATE UNIQUE INDEX IF NOT EXISTS bucket_idx on
Bucket(name, master) """)

self.cursor.execute(""" CREATE TABLE IF NOT EXISTS BucketStats ( self.cursor.execute(""" CREATE TABLE IF NOT EXISTS BucketStats (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
diskUsed REAL, diskUsed REAL,
Expand All @@ -109,10 +115,10 @@ def create_databases(self):
timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY(bucketId) REFERENCES Bucket(bucketId))""") FOREIGN KEY(bucketId) REFERENCES Bucket(bucketId))""")


def create_or_update_node(self, host, port, status): def create_or_update_node(self, host, port, status, master):
sqlstmt = """INSERT OR REPLACE INTO ServerNode (host,port,status) sqlstmt = """INSERT OR REPLACE INTO ServerNode (host,port,status, master)
VALUES( '{0}', {1}, '{2}' )""" VALUES( '{0}', {1}, '{2}', '{3}' )"""
self.cursor.execute(sqlstmt.format(host, port, status)) self.cursor.execute(sqlstmt.format(host, port, status, master))
return self.cursor.lastrowid return self.cursor.lastrowid


def process_node_stats(self, nodeId, nodeInfo): def process_node_stats(self, nodeId, nodeInfo):
Expand Down Expand Up @@ -146,6 +152,7 @@ def process_node_stats(self, nodeId, nodeInfo):
VALUES('{0}', {1}, {2}, {3}, {4}, {5}, {6})""" VALUES('{0}', {1}, {2}, {3}, {4}, {5}, {6})"""


if nodeInfo['storageTotals'] is not None: if nodeInfo['storageTotals'] is not None:
print nodeInfo
hdd = nodeInfo['storageTotals']['hdd'] hdd = nodeInfo['storageTotals']['hdd']
if hdd is not None: if hdd is not None:
self.cursor.execute(sqlstmt.format('hdd', self.cursor.execute(sqlstmt.format('hdd',
Expand Down Expand Up @@ -196,16 +203,17 @@ def process_node_stats(self, nodeId, nodeInfo):


return True return True


def process_bucket(self, bucket): def process_bucket(self, bucket, master):
sqlstmt = """INSERT OR REPLACE INTO Bucket sqlstmt = """INSERT OR REPLACE INTO Bucket
(name, type, authType, saslPassword, numReplica, ramQuota) (name, type, authType, saslPassword, numReplica, ramQuota, master)
VALUES('{0}', '{1}', '{2}', '{3}', {4}, {5})""" VALUES('{0}', '{1}', '{2}', '{3}', {4}, {5}, '{6}')"""
self.cursor.execute(sqlstmt.format(bucket['name'], self.cursor.execute(sqlstmt.format(bucket['name'],
bucket['bucketType'], bucket['bucketType'],
bucket['authType'], bucket['authType'],
bucket['saslPassword'], bucket['saslPassword'],
bucket['replicaNumber'], bucket['replicaNumber'],
bucket['quota']['ram'])) bucket['quota']['ram'],
master))
bucketId = self.cursor.lastrowid bucketId = self.cursor.lastrowid


sqlstmt = """INSERT INTO BucketStats sqlstmt = """INSERT INTO BucketStats
Expand Down Expand Up @@ -256,18 +264,22 @@ def process_bucket_node_stats(self, bucket_id, node_name, stat, jason):
#print get_avg, set_avg, del_avg, disk_write_queue_avg #print get_avg, set_avg, del_avg, disk_write_queue_avg
#self.cursor.execute(sqlstmt.format(get_avg, set_avg, del_avg, disk_write_queue_avg, bucket_id)) #self.cursor.execute(sqlstmt.format(get_avg, set_avg, del_avg, disk_write_queue_avg, bucket_id))


def extract_result(self, rows): def extract_result(self, rows, multi_row):
if rows is not None: if rows is not None:
for row in rows: if multi_row:
return row return rows
else:
for row in rows:
return row
else: else:
return [0] return [0]


def execute(self, stmt): def execute(self, stmt, multi_row=False):
self.cursor.execute(stmt) self.cursor.execute(stmt)
return self.extract_result(self.cursor.fetchall()) return self.extract_result(self.cursor.fetchall(), multi_row)


def browse_table(self, table): def browse_table(self, table):
print "TABLE:", table
stmt = "SELECT * from {0}" stmt = "SELECT * from {0}"
self.cursor.execute(stmt.format(table)) self.cursor.execute(stmt.format(table))
rows = self.cursor.fetchall() rows = self.cursor.fetchall()
Expand All @@ -281,4 +293,4 @@ def browse_db(self):
self.browse_table("SystemStats") self.browse_table("SystemStats")
self.browse_table("Bucket") self.browse_table("Bucket")
self.browse_table("BucketStats") self.browse_table("BucketStats")
self.browse_table("BucketOps") #self.browse_table("BucketOps")

0 comments on commit a83a553

Please sign in to comment.