Cassandra.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 import roslib; roslib.load_manifest("cassandra_ros")
00004 import rospy
00005 import pycassa
00006 
00007 class Cassandra():
00008     def __init__(self, host="localhost", port=9160):
00009         self.host       = host
00010         self.port       = port
00011                 
00012         self.sysManager = pycassa.SystemManager(str(self.host)+":"+str(self.port), framed_transport=True, timeout=30)
00013         
00014     def createKeyspace(self, keyspace=False,
00015                                replication_strategy='SimpleStrategy',
00016                                strategy_options={'replication_factor': '1'}):
00017         try:
00018             if keyspace == False:
00019                 keyspace = self.keyspace
00020             self.sysManager.create_keyspace(keyspace, replication_strategy, strategy_options)
00021         except:
00022             return False
00023         return True
00024     
00025     def dropKeyspace(self, keyspace=False):
00026         try:
00027             if keyspace == False:
00028                 keyspace = self.keyspace
00029             self.sysManager.drop_keyspace(keyspace)
00030         except:
00031             return False
00032         return True
00033     
00034     def existKeyspace(self, keyspace=False):
00035         try:
00036             if keyspace == False:
00037                 keyspace = self.keyspace
00038             keyspaces = self.sysManager.list_keyspaces()
00039             return any(keyspace == item for item in keyspaces)
00040         except:
00041             pass
00042         return False
00043     
00044     def getColumnComment(self, col_name, keyspace=False):
00045         try:
00046             if keyspace == False:
00047                 keyspace = self.keyspace
00048             columns = self.sysManager.get_keyspace_column_families(keyspace)
00049             return columns[col_name].comment
00050         except:
00051             pass
00052         return False
00053     
00054     def getAllColumns(self, keyspace=False):
00055         try:
00056             if keyspace == False:
00057                 keyspace = self.keyspace
00058             columns = self.sysManager.get_keyspace_column_families(keyspace)
00059             return columns.keys()
00060         except:
00061             pass
00062         return False
00063     
00064     def setColumnComment(self, col_name, comment, keyspace=False):
00065         try:
00066             if keyspace == False:
00067                 keyspace = self.keyspace
00068             self.sysManager.alter_column_family(keyspace, col_name, comment=comment)
00069             return True
00070         except:
00071             pass
00072         return False
00073         
00074     def createColumn(self, col_name, super=False, column_validation_classes=None):#,compression_options={'sstable_compression':'SnappyCompressor','chunk_length_kb':'64'}):
00075         try:
00076             self.sysManager.create_column_family(self.keyspace,
00077                                                  col_name,
00078                                                  super=super,
00079                                                  #default_validation_class=pycassa.BYTES_TYPE,
00080                                                  comparator_type=pycassa.UTF8_TYPE,
00081                                                  column_validation_classes=column_validation_classes,
00082                                                  key_validation_class=pycassa.UTF8_TYPE)#,
00083                                                  #compression_options=compression_options)
00084         except:
00085             return False
00086         return True
00087     
00088     def dropColumn(self, col_name):
00089         try:
00090             self.sysManager.drop_column_family(self.keyspace, col_name)
00091         except:
00092             return False
00093         return True
00094     
00095     def existColumn(self, col_name, keyspace=False):
00096         try:
00097             if keyspace == False:
00098                 keyspace = self.keyspace
00099             colums = self.sysManager.get_keyspace_column_families(keyspace)
00100             if colums.has_key(col_name):
00101                 return True
00102         except:
00103             pass
00104         return False
00105     
00106     def typeOfColumn(self, col_name, keyspace=False):
00107         try:
00108             if keyspace == False:
00109                 keyspace = self.keyspace
00110             colums = self.sysManager.get_keyspace_column_families(keyspace)
00111             return colums[col_name].column_type
00112         except:
00113             pass
00114         return False
00115     
00116     def getColumn(self, col_name):
00117         try:
00118             return pycassa.ColumnFamily(self.pool, col_name)
00119         except:
00120             pass
00121         return False
00122     
00123     def connectToKeyspace(self, keyspace="ros"):
00124         self.keyspace   = keyspace
00125         try:
00126             self.pool = pycassa.ConnectionPool(self.keyspace, [self.host + ":" + str(self.port)])
00127         except:
00128             return False
00129         return True
00130         
00131     def disconnect(self):
00132         try:
00133             self.pool.dispose()
00134         except:
00135             return False
00136         return True
00137         


cassandra_ros
Author(s): André Dietrich, Sebastian Zug
autogenerated on Sun Jan 5 2014 11:10:29