def executePost(self): """ POST notification post notifation request handler create new notifcation, simple or complex """ servicedb = databaseManager.PgDB( self.serviceconf.connectionWns['user'], self.serviceconf.connectionWns['password'], self.serviceconf.connectionWns['dbname'], self.serviceconf.connectionWns['host'], self.serviceconf.connectionWns['port']) name = self.json["name"] description = self.json["description"] interval = self.json["interval"] not_id = None store = self.json.get("store", False) sql = """INSERT INTO wns.notification (name, description, interval, store) VALUES (%s,%s, %s, %s) RETURNING id;""" par = [name, description, interval, store] try: not_id = servicedb.executeInTransaction(sql, par)[0][0] except psycopg2.Error as e: self.setException(e.pgerror) servicedb.rollbackTransaction() return if not not_id: self.setException('Exception while creating a new notification') return try: from wnslib import notificationManager as notManager if "params" in self.json.keys(): params = self.json["params"] condition = self.json["condition"] service = self.json["service"] period = self.json.get("period", None) notManager.createSimpleNotification(name, service, params, condition, interval, period, store) else: print "Notification" funcFile = self.json["function"] msg = notManager.addNotification(name, funcFile, interval, store) if msg: self.setException(msg) servicedb.rollbackTransaction() return except Exception, e: msg = "The following error occoured: " + str(e) msg += "\n\nPlease try again" self.setException(msg) servicedb.rollbackTransaction() return
def executePut(self): #self.json = self.json['data'] description = self.json.get("description", None) from wnslib import notificationManager as notManager if description: servicedb = databaseManager.PgDB( self.serviceconf.connectionWns['user'], self.serviceconf.connectionWns['password'], self.serviceconf.connectionWns['dbname'], self.serviceconf.connectionWns['host'], self.serviceconf.connectionWns['port']) sql = "UPDATE wns.notification SET description = %s WHERE id=%s;" params = (description, self.not_id,) servicedb.executeInTransaction(sql, params) if not self.json.get("params") or not self.json.get("function"): self.setMessage("Updated notifcation description") servicedb.commitTransaction() return try: name = self.json["name"] interval = self.json["interval"] if "params" in self.json.keys(): print >> sys.stderr, "simpleNot" params = self.json["params"] condition = self.json["condition"] service = self.json["service"] period = self.json.get("period", None) notManager.createSimpleNotification(name, service, params, condition, interval, period) else: print >> sys.stderr, "Notification" funcFile = self.json["function"] msg = notManager.addNotification(name, funcFile, interval) if msg: self.setException(msg) if description: servicedb.rollbackTransaction() return if description: servicedb.commitTransaction() # Delete old notification function notManager.delNotification(name) except Exception, e: msg = "The following error occoured: " + str(e) msg += "\n\nPlease try again" if description: servicedb.rollbackTransaction() self.setException(msg) return
def executePost(self): servicedb = databaseManager.PgDB( self.serviceconf.connectionWns['user'], self.serviceconf.connectionWns['password'], self.serviceconf.connectionWns['dbname'], self.serviceconf.connectionWns['host'], self.serviceconf.connectionWns['port']) #self.json = self.json['data'] name = self.json["name"] description = self.json["description"] interval = self.json["interval"] not_id = None sql = """INSERT INTO wns.notification (name, description) VALUES (%s,%s) RETURNING id;""" par = [name, description] not_id = servicedb.executeInTransaction(sql, par)[0][0] if not not_id: self.setException('Exception while creating a new notification') return try: from wnslib import notificationManager as notManager if "params" in self.json.keys(): print "simpleNot" params = self.json["params"] condition = self.json["condition"] service = self.json["service"] period = self.json.get("period", None) notManager.createSimpleNotification(name, service, params, condition, interval, period) else: print "Notification" funcFile = self.json["function"] msg = notManager.addNotification(name, funcFile, interval) if msg: self.setException(msg) servicedb.rollbackTransaction() return except Exception, e: msg = "The following error occoured: " + str(e) msg += "\n\nPlease try again" self.setException(msg) servicedb.rollbackTransaction() return
def executePut(self): """ PUT notification Put notification request handler Update a existing notification """ description = self.json.get("description", None) interval = self.json.get("interval", None) from wnslib import notificationManager as notManager servicedb = databaseManager.PgDB( self.serviceconf.connectionWns['user'], self.serviceconf.connectionWns['password'], self.serviceconf.connectionWns['dbname'], self.serviceconf.connectionWns['host'], self.serviceconf.connectionWns['port']) if description: sql = "UPDATE wns.notification SET description = %s " params = (description, ) sql += " WHERE id=%s RETURNING *" params += (self.not_id, ) try: row = servicedb.executeInTransaction(sql, params) except psycopg2.Error as e: self.setException(e.pgerror) servicedb.rollbackTransaction() return else: sql = "SELECT * FROM wns.notification WHERE id=%s" params = (self.not_id, ) try: row = servicedb.executeInTransaction(sql, params) except psycopg2.Error as e: self.setException(e.pgerror) servicedb.rollbackTransaction() return if not self.json.get("params") and not self.json.get("function"): self.setMessage("Updated notifcation description") servicedb.commitTransaction() return if self.json.get('params') and self.json.get('function'): self.setException("What?!?!") servicedb.rollbackTransaction() return try: interval = self.json.get("interval", row[0][3]) name = row[0][1] store = self.json.get("store", row[0][4]) # Delete old notification function notManager.delNotification(name) if "params" in list(self.json.keys()): print("simpleNot", file=sys.stderr) params = self.json["params"] condition = self.json["condition"] service = self.json["service"] period = self.json.get("period", None) notManager.createSimpleNotification(name, service, params, condition, interval, period, store) else: print("Notification", file=sys.stderr) function_path = self.json["function"] msg = notManager.addNotification(name, function_path, interval, store) if msg: self.setException(msg) if description: servicedb.rollbackTransaction() return if description: servicedb.commitTransaction() else: sql = "UPDATE wns.notification SET interval = %s, store = %s" sql += " WHERE id=%s" params = (interval, store, self.not_id) try: servicedb.executeInTransaction(sql, params) except psycopg2.Error as e: self.setException(e.pgerror) servicedb.rollbackTransaction() servicedb.commitTransaction() except Exception as e: msg = "The following error occoured: " + str(e) msg += "\n\nPlease try again" if description: servicedb.rollbackTransaction() self.setException(msg) return self.setMessage("Notification " + name + " updated")