diff options
-rwxr-xr-x | DominoClient.py | 2 | ||||
-rwxr-xr-x | DominoServer.py | 38 | ||||
-rw-r--r-- | domino_conf.py | 1 | ||||
-rw-r--r-- | lib/util/miscutil.py | 5 |
4 files changed, 33 insertions, 13 deletions
diff --git a/DominoClient.py b/DominoClient.py index 8ce8ae7..067b090 100755 --- a/DominoClient.py +++ b/DominoClient.py @@ -316,7 +316,7 @@ class DominoClient: return try: pub_msg_r = self.sender().d_publish(pub_msg) - logging.info('Publish Response is received from: %d ,sequence number: %d', pub_msg_r.domino_udid, pub_msg_r.seq_no) + logging.info('Publish Response is received from: %d ,sequence number: %d Op. Status: %d', pub_msg_r.domino_udid, pub_msg_r.seq_no, pub_msg_r.responseCode) except (Thrift.TException, TSocket.TTransportException) as tx: print '%s' % (tx.message) except (socket.timeout) as tx: diff --git a/DominoServer.py b/DominoServer.py index c9a64b1..cebdc78 100755 --- a/DominoServer.py +++ b/DominoServer.py @@ -49,7 +49,7 @@ class CommunicationHandler: def __init__(self, dominoserver): self.log = {} self.dominoServer = dominoserver - self.seqno = 0; + self.seqno = SERVER_SEQNO; def openconnection(self, ipaddr, tcpport): try: @@ -97,7 +97,6 @@ class CommunicationHandler: # - Respond Back with a heartbeat def d_heartbeat(self, hb_msg): - global SERVER_UDID logging.info('heartbeat received from %d' , hb_msg.domino_udid) hb_r = HeartBeatMessage() @@ -113,7 +112,6 @@ class CommunicationHandler: # # - Respond Back with Registration Response def d_register(self, reg_msg): - global SERVER_UDID #Prepare and send Registration Response reg_r = RegisterResponseMessage() @@ -132,7 +130,9 @@ class CommunicationHandler: #Logic for a new UDID assignment self.seqno = self.seqno + 1 - + + self.dominoServer.registration_record[reg_r.domino_udid_assigned] = reg_msg + #commit to the database dbconn = sqlite3.connect(SERVER_DBFILE) c = dbconn.cursor() @@ -156,7 +156,6 @@ class CommunicationHandler: # - Save the templates & labels # - Respond Back with Subscription Response def d_subscribe(self, sub_msg): - global SERVER_UDID, SERVER_SEQNO logging.info('Subscribe Request received from %d' , sub_msg.domino_udid) if sub_msg.template_op == APPEND: @@ -228,7 +227,6 @@ class CommunicationHandler: # - Launch Push service # - Respond Back with Publication Response def d_publish(self, pub_msg): - global SERVER_UDID, SERVER_SEQNO, TOSCADIR, TOSCA_DEFAULT_FNAME logging.info('Publish Request received from %d' , pub_msg.domino_udid) logging.debug(pub_msg.template) @@ -242,10 +240,21 @@ class CommunicationHandler: logging.error('Error occurred in creating %s. Err no: %d', exception.errno) #Risking a race condition if another process is attempting to write to same file - f = open(TOSCADIR+TOSCA_DEFAULT_FNAME, 'w') - for item in pub_msg.template: - print>>f, item - f.close() +# f = open(TOSCADIR+TOSCA_DEFAULT_FNAME, 'w') +# for item in pub_msg.template: +# print>>f, item +# f.close() + try: + miscutil.write_templatefile(TOSCADIR+TOSCA_DEFAULT_FNAME , pub_msg.template) + except: + #Some sort of race condition should have occured that prevented the write operation + #treat as failure + pub_r = PublishResponseMessage() + pub_r.domino_udid = SERVER_UDID + pub_r.seq_no = self.seqno + pub_r.responseCode = FAILURE + self.seqno = self.seqno + 1 + return pub_r # Load tosca object from file into memory tosca = ToscaTemplate( TOSCADIR+TOSCA_DEFAULT_FNAME ) @@ -264,7 +273,8 @@ class CommunicationHandler: # Create per-domain Tosca files file_paths = partitioner.partition_tosca('./toscafiles/template1.yaml',node_site,tosca.tpl) - + logging.debug('Per domain file paths: %s', file_paths) + # Create list of translated template files # Create work-flow @@ -275,7 +285,11 @@ class CommunicationHandler: for site in file_paths: domino_client_ip = self.dominoServer.registration_record[site].ipaddr domino_client_port = self.dominoServer.registration_record[site].tcpport - self.push_template(miscutil.read_templatefile(file_paths[site]), domino_client_ip, domino_client_port) + try: + template_lines = miscutil.read_templatefile(file_paths[site]) + self.push_template(template_lines, domino_client_ip, domino_client_port) + except IOError as e: + logging.error('I/O error(%d): %s' , e.errno, e.strerror) #Fill in the details pub_r = PublishResponseMessage() diff --git a/domino_conf.py b/domino_conf.py index 293adeb..4f03212 100644 --- a/domino_conf.py +++ b/domino_conf.py @@ -20,3 +20,4 @@ SERVER_UDID = 0 TOSCADIR = './toscafiles/' TOSCA_DEFAULT_FNAME = 'template1.yaml' SERVER_DBFILE = 'dominoserver.db' +SERVER_SEQNO = 0 diff --git a/lib/util/miscutil.py b/lib/util/miscutil.py index ea284af..3fc95a6 100644 --- a/lib/util/miscutil.py +++ b/lib/util/miscutil.py @@ -10,3 +10,8 @@ def read_templatefile(temp_filename): f.close() return lines +def write_templatefile(temp_filename, template_lines): + f = open(temp_filename, 'w') + for item in template_lines: + print>>f, item + f.close() |