summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlas Kozat <ulas.kozat@gmail.com>2016-06-03 22:48:03 -0700
committerUlas Kozat <ulas.kozat@gmail.com>2016-06-03 22:48:03 -0700
commit28f34e2ae729c0e40874ebfc2e60f3854d95f724 (patch)
tree632090b0a05454edcd4b08e7c5706d9ddeeae551
parenta292aa32eebe17196eff1862cff9e6e6e84414e4 (diff)
added sqlite3 support at Domino Server for label subscriptions and client registrations
Change-Id: Ia3d741adadb20eb92525a4640ad70fa3fdc435a2 Signed-off-by: Ulas Kozat <ulas.kozat@gmail.com>
-rwxr-xr-xDominoServer.py58
-rw-r--r--domino_conf.py2
-rw-r--r--lib/thrift/protocol/TBinaryProtocol.pycbin10720 -> 0 bytes
-rw-r--r--lib/thrift/protocol/TProtocol.pycbin14621 -> 0 bytes
-rw-r--r--lib/thrift/protocol/__init__.pycbin254 -> 0 bytes
-rw-r--r--lib/thrift/server/TServer.pycbin8801 -> 0 bytes
-rw-r--r--lib/thrift/server/__init__.pycbin177 -> 0 bytes
-rw-r--r--lib/thrift/transport/TSocket.pycbin5822 -> 0 bytes
-rw-r--r--lib/thrift/transport/TTransport.pycbin17217 -> 0 bytes
-rw-r--r--lib/thrift/transport/__init__.pycbin213 -> 0 bytes
10 files changed, 50 insertions, 10 deletions
diff --git a/DominoServer.py b/DominoServer.py
index 39c4632..f2a22e2 100755
--- a/DominoServer.py
+++ b/DominoServer.py
@@ -14,6 +14,7 @@
import sys, os, glob, random, errno
import getopt, socket
import logging, json
+import sqlite3
#sys.path.append('gen-py')
#sys.path.insert(0, glob.glob('./lib/py/build/lib.*')[0])
sys.path.insert(0, glob.glob('./lib')[0])
@@ -131,15 +132,21 @@ class CommunicationHandler:
#Logic for a new UDID assignment
self.seqno = self.seqno + 1
-
- # Store the Domino Client info
- # TBD: check the sequence number to ensure the most recent record is saved
- self.dominoServer.registration_record[reg_r.domino_udid_assigned] = reg_msg
- data = {}
- data[reg_r.domino_udid_assigned] = [reg_msg.ipaddr, reg_msg.tcpport, reg_msg.supported_templates, reg_msg.seq_no]
- with open(SERVER_DBFILE, 'a') as f:
- json.dump(data, f)
- f.close()
+
+ #commit to the database
+ dbconn = sqlite3.connect(SERVER_DBFILE)
+ c = dbconn.cursor()
+ try:
+ newrow = [(reg_r.domino_udid_assigned, reg_msg.ipaddr, reg_msg.tcpport, ','.join(reg_msg.supported_templates), reg_msg.seq_no),]
+ c.executemany('INSERT INTO clients VALUES (?,?,?,?,?)',newrow)
+ except sqlite3.OperationalError as ex:
+ logging.error('Could not add the new registration record into %s for Domino Client %d : %s', SERVER_DBFILE, reg_r.domino_udid_assigned, ex.message)
+ except:
+ logging.error('Could not add the new registration record into %s for Domino Client %d', SERVER_DBFILE, reg_r.domino_udid_assigned)
+ logging.error('Unexpected error: %s', sys.exc_info()[0])
+
+ dbconn.commit()
+ dbconn.close()
return reg_r
@@ -177,6 +184,23 @@ class CommunicationHandler:
self.dominoServer.subscribed_labels[sub_msg.domino_udid].difference_update(set(sub_msg.labels))
logging.debug('Supported Template: %s Supported Labels: %s' , self.dominoServer.subscribed_templateformats[sub_msg.domino_udid] , self.dominoServer.subscribed_labels[sub_msg.domino_udid])
+
+ #commit to the database
+ dbconn = sqlite3.connect(SERVER_DBFILE)
+ c = dbconn.cursor()
+ newlabelset = self.dominoServer.subscribed_labels[sub_msg.domino_udid]
+ try:
+ c.execute("REPLACE INTO labels (udid, label_list) VALUES ({udid}, '{newvalue}')".\
+ format(udid=sub_msg.domino_udid, newvalue=','.join(list(newlabelset)) ))
+ except sqlite3.OperationalError as ex1:
+ logging.error('Could not add the new labels to %s for Domino Client %d : %s', SERVER_DBFILE, sub_msg.domino_udid, ex1.message)
+ except:
+ logging.error('Could not add the new labels to %s for Domino Client %d', SERVER_DBFILE, sub_msg.domino_udid)
+ logging.error('Unexpected error: %s', sys.exc_info()[0])
+
+ dbconn.commit()
+ dbconn.close()
+
#Fill in the details
sub_r = SubscribeResponseMessage()
@@ -329,6 +353,22 @@ def main(argv):
print ex.message
sys.exit(2)
+ #start the database with schemas
+ dbconn = sqlite3.connect(SERVER_DBFILE)
+ c = dbconn.cursor()
+ try:
+ c.execute('''CREATE TABLE labels (udid INTEGER PRIMARY KEY, label_list TEXT)''')
+ except sqlite3.OperationalError as ex:
+ logging.debug('In database file %s, no table is created as %s', SERVER_DBFILE, ex.message)
+
+ try:
+ c.execute('''CREATE TABLE clients (udid INTEGER PRIMARY KEY, ipaddr TEXT, tcpport INTEGER, templatetypes TEXT, seqno INTEGER)''')
+ except sqlite3.OperationalError as ex:
+ logging.debug('In database file %s, no table is created as %s', SERVER_DBFILE, ex.message)
+
+ dbconn.commit()
+ dbconn.close()
+
logging.debug('Domino Server Starting...')
server.start_communicationService()
print 'done.'
diff --git a/domino_conf.py b/domino_conf.py
index f311d43..55f8367 100644
--- a/domino_conf.py
+++ b/domino_conf.py
@@ -16,4 +16,4 @@ DEFAULT_TOSCA_PUBFILE = './tosca-templates/tosca_helloworld_nfv.yaml'
SERVER_UDID = 0
TOSCADIR = './toscafiles/'
TOSCA_DEFAULT_FNAME = 'template1.yaml'
-SERVER_DBFILE = 'dominoserver.json'
+SERVER_DBFILE = 'dominoserver.db'
diff --git a/lib/thrift/protocol/TBinaryProtocol.pyc b/lib/thrift/protocol/TBinaryProtocol.pyc
deleted file mode 100644
index 8c89556..0000000
--- a/lib/thrift/protocol/TBinaryProtocol.pyc
+++ /dev/null
Binary files differ
diff --git a/lib/thrift/protocol/TProtocol.pyc b/lib/thrift/protocol/TProtocol.pyc
deleted file mode 100644
index 8ec8411..0000000
--- a/lib/thrift/protocol/TProtocol.pyc
+++ /dev/null
Binary files differ
diff --git a/lib/thrift/protocol/__init__.pyc b/lib/thrift/protocol/__init__.pyc
deleted file mode 100644
index a259bbd..0000000
--- a/lib/thrift/protocol/__init__.pyc
+++ /dev/null
Binary files differ
diff --git a/lib/thrift/server/TServer.pyc b/lib/thrift/server/TServer.pyc
deleted file mode 100644
index 5a9174d..0000000
--- a/lib/thrift/server/TServer.pyc
+++ /dev/null
Binary files differ
diff --git a/lib/thrift/server/__init__.pyc b/lib/thrift/server/__init__.pyc
deleted file mode 100644
index 7a11045..0000000
--- a/lib/thrift/server/__init__.pyc
+++ /dev/null
Binary files differ
diff --git a/lib/thrift/transport/TSocket.pyc b/lib/thrift/transport/TSocket.pyc
deleted file mode 100644
index ff141f3..0000000
--- a/lib/thrift/transport/TSocket.pyc
+++ /dev/null
Binary files differ
diff --git a/lib/thrift/transport/TTransport.pyc b/lib/thrift/transport/TTransport.pyc
deleted file mode 100644
index c7cf4cb..0000000
--- a/lib/thrift/transport/TTransport.pyc
+++ /dev/null
Binary files differ
diff --git a/lib/thrift/transport/__init__.pyc b/lib/thrift/transport/__init__.pyc
deleted file mode 100644
index dcbb012..0000000
--- a/lib/thrift/transport/__init__.pyc
+++ /dev/null
Binary files differ