def delete(self, username=None): """Delete a collection and the associated row in the tree entry table""" from indigo.models import Notification if self.is_root: return cfg = get_config(None) session = connection.get_session() keyspace = cfg.get('KEYSPACE', 'indigo') session.set_keyspace(keyspace) query = SimpleStatement( """DELETE FROM tree_entry WHERE container=%s""") session.execute(query, (self.path, )) # Get the row that describe the collection as a child of its parent child = TreeEntry.objects.filter(container=self.container, name=u"{}/".format( self.name)).first() if child: child.delete() session = get_graph_session() session.execute_graph("""v_coll = {}.drop(); """.format(gq_get_vertex_collection(self))) state = self.mqtt_get_state() payload = self.mqtt_payload(state, {}) Notification.delete_collection(username, self.path, payload) self.reset()
def delete_id(cls, uuid): """Delete all blobs for the specified uuid""" cfg = get_config(None) session = connection.get_session() keyspace = cfg.get('KEYSPACE', 'indigo') session.set_keyspace(keyspace) query = SimpleStatement("""DELETE FROM data_object WHERE uuid=%s""") session.execute(query, (uuid,))
def create_acl(self, acl_cql): """Replace the static acl with the given cql string""" cfg = get_config(None) session = connection.get_session() keyspace = cfg.get('KEYSPACE', 'indigo') session.set_keyspace(keyspace) query = SimpleStatement(u"""UPDATE data_object SET acl = {} WHERE uuid=%s""".format(acl_cql)) session.execute(query, (self.uuid,))
def update_container_acl(self, acl_cql): """Update the static acl with the given cql string""" cfg = get_config(None) session = connection.get_session() keyspace = cfg.get('KEYSPACE', 'indigo') session.set_keyspace(keyspace) query = SimpleStatement( u"""UPDATE tree_entry SET container_acl=container_acl+{} WHERE container=%s""".format(acl_cql)) session.execute(query, (self.container, ))
def create_entry_acl(self, acl_cql): """Replace the acl with the given cql string """ cfg = get_config(None) session = connection.get_session() keyspace = cfg.get('KEYSPACE', 'indigo') session.set_keyspace(keyspace) query = SimpleStatement(u"""UPDATE tree_entry SET acl={} WHERE container=%s and name=%s""".format(acl_cql)) session.execute(query, ( self.container, self.name, ))
def update(self, **kwargs): """Update a collection""" cfg = get_config(None) session = connection.get_session() keyspace = cfg.get('KEYSPACE', 'indigo') session.set_keyspace(keyspace) for arg in kwargs: # For static fields we can't use the name in the where condition if arg in static_fields: query = SimpleStatement(u"""UPDATE tree_entry SET {}=%s WHERE container=%s""".format(arg)) session.execute(query, (kwargs[arg], self.container)) else: query = SimpleStatement(u"""UPDATE tree_entry SET {}=%s WHERE container=%s and name=%s""".format(arg)) session.execute(query, (kwargs[arg], self.container, self.name)) return self
def recent(cls, script_name, count=20): """Return the last logs""" cfg = get_config(None) session = connection.get_session() keyspace = cfg.get('KEYSPACE', 'indigo') session.set_keyspace(keyspace) # I couldn't find how to disable paging in cqlengine in the "model" view # so I create the cal query directly query = SimpleStatement(u"""SELECT * from listener_log WHERE script_name = '{}' ORDER BY when DESC limit {}""".format(script_name, count)) # Disable paging for this query (we use IN and ORDER BY in the same # query query.fetch_size = None res = [] for row in session.execute(query): res.append(ListenerLog(**row).to_dict()) return res
def ready(self): from indigo.models import initialise, Collection, User, Group logging.basicConfig(level=logging.WARNING) logging.getLogger("models").setLevel(logging.WARNING) logging.getLogger("dse.policies").setLevel(logging.WARNING) logging.getLogger("dse.cluster").setLevel(logging.WARNING) logging.getLogger("dse.cqlengine.management").setLevel(logging.WARNING) cfg = get_config(None) initialise(keyspace=cfg.get('KEYSPACE', 'indigo'), hosts=cfg.get('CASSANDRA_HOSTS', ('127.0.0.1', ))) # Try to get the root. It will create it if it doesn't exist root = Collection.get_root() # TODO: Review that at some point # Check that the graph vertices for users are still there User.check_graph_users()
def update(self, **kwargs): """Update a data object""" cfg = get_config(None) session = connection.get_session() keyspace = cfg.get('KEYSPACE', 'indigo') session.set_keyspace(keyspace) for arg in kwargs: # For static fields we can't use the name in the where condition if arg in static_fields: query = SimpleStatement("""UPDATE data_object SET {}=%s WHERE uuid=%s""".format(arg)) session.execute(query, (kwargs[arg], self.uuid)) else: print """UPDATE data_object SET {}=%s WHERE uuid=%s and sequence_number=%s""".format(arg) query = SimpleStatement("""UPDATE data_object SET {}=%s WHERE uuid=%s and sequence_number=%s""".format(arg)) session.execute(query, (kwargs[arg], self.uuid, self.sequence_number)) return self
def recent(cls, count=20): """Return the last activities""" # return Notification.objects.filter(date__in=last_x_days())\ # .order_by("-when").all().limit(count) cfg = get_config(None) session = connection.get_session() keyspace = cfg.get('KEYSPACE', 'indigo') session.set_keyspace(keyspace) # I couldn't find how to disable paging in cqlengine in the "model" view # so I create the cal query directly query = SimpleStatement(u"""SELECT * from Notification WHERE date IN ({}) ORDER BY when DESC limit {}""".format( ",".join(["'%s'" % el for el in last_x_days()]), count) ) # Disable paging for this query (we use IN and ORDER BY in the same # query query.fetch_size = None res = [] for row in session.execute(query): res.append(Notification(**row).to_dict()) return res
logger.info('Stopping MQTT...') mqtt_client.disconnect() logger.info('Dereticulating splines... Done!') sys.exit(0) if __name__ == '__main__': arguments = docopt(__doc__, version='Listener v1.0') logger = log.init_log('listener') signal.signal(signal.SIGTERM, shutdown) cfg = get_config(None) initialise(keyspace=cfg.get('KEYSPACE', 'indigo'), hosts=cfg.get('CASSANDRA_HOSTS', ('127.0.0.1', )), repl_factor=cfg.get('REPLICATION_FACTOR', 1)) if arguments['--verbose']: logger.setLevel(logging.DEBUG) elif arguments['--quiet']: logger.setLevel(logging.WARNING) else: logger.setLevel(logging.INFO) script_directory_topic = '+/resource/{0}/#'.format( arguments['<script_collection>']) script_directory_topic = '/'.join( filter(None, script_directory_topic.split('/')))