def update_alarm(self, alarm): """Update an alarm. :param alarm: the new Alarm to update """ session = self._engine_facade.get_session() with session.begin(): count = session.query(models.Alarm).filter( models.Alarm.alarm_id == alarm.alarm_id).update( alarm.as_dict()) if not count: raise storage.AlarmNotFound(alarm.alarm_id) return alarm
def update_alarm(self, alarm, upsert=False): """Create an alarm. :param alarm: The alarm to create. It is Alarm object, so we need to call as_dict() """ _id = alarm.alarm_id alarm_to_store = hbase_utils.serialize_entry(alarm.as_dict()) with self.conn_pool.connection() as conn: alarm_table = conn.table(self.ALARM_TABLE) if not upsert: q = hbase_utils.make_query(alarm_id=alarm.alarm_id) query_alarm = alarm_table.scan(filter=q) if len(list(query_alarm)) == 0: raise storage.AlarmNotFound(alarm.alarm_id) alarm_table.put(_id, alarm_to_store) stored_alarm = hbase_utils.deserialize_entry(alarm_table.row(_id)) return models.Alarm(**stored_alarm)