当前位置: 首页>>代码示例>>Python>>正文


Python SystemManager.create_keyspace方法代码示例

本文整理汇总了Python中pycassa.system_manager.SystemManager.create_keyspace方法的典型用法代码示例。如果您正苦于以下问题:Python SystemManager.create_keyspace方法的具体用法?Python SystemManager.create_keyspace怎么用?Python SystemManager.create_keyspace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycassa.system_manager.SystemManager的用法示例。


在下文中一共展示了SystemManager.create_keyspace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_connection

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
def get_connection():
    """
    Creates a connection to Cassandra.

    Returs:
        pool
    """
    cassandra_host = os.environ.get('CASSANDRA_HOST', 'localhost')
    sys_mgr = SystemManager()
    try:
        sys_mgr.describe_ring(KEYSPACE)
    except:
        sys_mgr.create_keyspace(KEYSPACE, SIMPLE_STRATEGY, {'replication_factor': '1'})

    pool = ConnectionPool(KEYSPACE, server_list=[cassandra_host])
    for cf_name in [CF_LOGS, CF_LOGS_BY_APP, CF_LOGS_BY_HOST, CF_LOGS_BY_SEVERITY]:
        try:
            cf = ColumnFamily(pool, cf_name)
        except:
            sys_mgr.create_column_family(KEYSPACE, cf_name, comparator_type=TimeUUIDType())
            cf = ColumnFamily(pool, cf_name)
            cf.get_count(str(uuid.uuid4()))

    sys_mgr.close()

    return pool
开发者ID:hgdeoro,项目名称:daedalus,代码行数:28,代码来源:simple_client.py

示例2: CreateCF

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
def CreateCF(connStr, keySpace, cfs, columesTypeList = None):
    sysmgt = SystemManager(connStr)
    list = sysmgt.list_keyspaces()
    
    if keySpace in list:
        #print('pyagent is existed')
        pass
    else:
        sysmgt.create_keyspace(keySpace, SIMPLE_STRATEGY, {'replication_factor': '3'})
    cfDict = sysmgt.get_keyspace_column_families(keySpace)
    allCF = cfDict.keys()
    
    for i in range(len(cfs)):
        columnFamily = cfs[i]
        #print(columnFamily)
        if columesTypeList != None:
            columes = columesTypeList[i]
        else:
            columes = None
        if columnFamily in allCF:
            #print(columnFamily + ' is existed')
            pass
        else:
            #print(columnFamily + ' is creating')
            sysmgt.create_column_family(keySpace, columnFamily, super=False, 
                comparator_type=UTF8_TYPE,
                key_validation_class=ASCII_TYPE,
                default_validation_class=UTF8_TYPE,
                column_validation_classes=columes,
                gc_grace_seconds=1000)
    sysmgt.close()
开发者ID:wangbokun,项目名称:sms_send,代码行数:33,代码来源:cassandraoperator.py

示例3: initializeTableLayout

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
def initializeTableLayout(keyspace, server_list, replicationStrategy,
  strategyOptions, localDCName, credentials):

    sys_manager = SystemManager(server_list[0], credentials=credentials)

    # Make sure the the keyspace exists
    if keyspace not in sys_manager.list_keyspaces():
      sys_manager.create_keyspace(keyspace, replicationStrategy,
        strategyOptions)

    cf_defs = sys_manager.get_keyspace_column_families(keyspace)

    # Create UTF8 CF's
    for tablename in ["global_nodes", "metadata"]:
      if tablename not in cf_defs.keys():
        createUTF8ColumnFamily(sys_manager, keyspace, tablename)

    if localDCName:

        dcNodes = "dc_%s_nodes" % (localDCName,)
        if dcNodes not in cf_defs.keys():
          createUTF8ColumnFamily(sys_manager, keyspace, dcNodes)
    else:
      # TODO Log we do not have the DC name
      pass

    if "node_slices" not in cf_defs.keys():
      sys_manager.create_column_family(
        keyspace,
        "node_slices",
        super=False,
        comparator_type=pycassa_types.LongType(),
        key_validation_class=pycassa_types.UTF8Type(),
        default_validation_class=pycassa_types.LongType()
      )
开发者ID:acquia,项目名称:carbon-cassandra-plugin,代码行数:37,代码来源:carbon_cassandra_db.py

示例4: __init__

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
 def __init__(self, engine, **kw):
     super(CassandraStore, self).__init__(engine, **kw)
     spliturl = urlsplit(engine)
     _, keyspace, column_family = spliturl.path.split('/')
     try:
         self._store = pycassa.ColumnFamily(
             pycassa.ConnectionPool(keyspace, [spliturl.hostname]),
             column_family,
         )
     except pycassa.InvalidRequestException:
         from pycassa.system_manager import SystemManager  # @UnresolvedImport @IgnorePep8
         system_manager = SystemManager(spliturl[1])
         system_manager.create_keyspace(
             keyspace,
             pycassa.system_manager.SIMPLE_STRATEGY,
             dict(replication_factor=native(kw.get('replication', 1))),
         )
         system_manager.create_column_family(keyspace, column_family)
         self._store = pycassa.ColumnFamily(
             pycassa.ConnectionPool(keyspace, [spliturl.netloc]),
             column_family,
         )
     except pycassa.NotFoundException:
         from pycassa.system_manager import SystemManager  # @UnresolvedImport @IgnorePep8
         system_manager = SystemManager(spliturl[1])
         system_manager.create_column_family(keyspace, column_family)
         self._store = pycassa.ColumnFamily(
             pycassa.ConnectionPool(keyspace, [spliturl.netloc]),
             column_family,
         )
开发者ID:cnstudios,项目名称:Plex-Trakt-Scrobbler,代码行数:32,代码来源:cassandra.py

示例5: Cluster

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
class Cluster(object):
    def __init__(self, name):
        self.keyspaces = OrderedDict()
        self.name = name
        self._sm_client = None
        
        cmcache.append('clusters', self)
    
    def setclient(self, servers_list=[connection.DEFAULT_SERVER]):
        for server in servers_list:
            try:
                self._sm_client = SystemManager(server)
                return
            except:
                pass
        if self._sm_client is None:
            raise NoServerAvailable('Cannot create system_manager connections on server list %s' % str(servers_list))
    
    def registerKeyspace(self, name, keyspc):
        self.keyspaces[name] = keyspc
        if self._sm_client is None:
            self.setclient()
        # try to actually register this keyspace to the system via 
        if not name in self._sm_client.list_keyspaces():
            self._sm_client.create_keyspace(name, keyspec.strategy_class)
        
    def __str__(self):
        return self.name
开发者ID:hwang3419,项目名称:Comedy,代码行数:30,代码来源:hierachy.py

示例6: ensure_cassandra_cf

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
 def ensure_cassandra_cf(self):
     s = SystemManager()
     if self.keyspace not in s.list_keyspaces():
         s.create_keyspace(self.keyspace, SIMPLE_STRATEGY, {'replication_factor': '1'})
     if self.cassandra_columns_family not in s.get_keyspace_column_families(self.keyspace):
         s.create_column_family(self.keyspace, self.cassandra_columns_family)
     self.columnfamily = ColumnFamily(self.cassandra_session, self.cassandra_columns_family)
开发者ID:TPNguyen,项目名称:python-pds,代码行数:9,代码来源:temporal_daily_cython.py

示例7: _cassandra_ensure_keyspace

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
    def _cassandra_ensure_keyspace(self, server_list,
                                   keyspace_name, cf_info_list):
        # Retry till cassandra is up
        server_idx = 0
        num_dbnodes = len(self._server_list)
        connected = False
        while not connected:
            try:
                cass_server = self._server_list[server_idx]
                sys_mgr = SystemManager(cass_server)
                connected = True
            except Exception as e:
                # TODO do only for
                # thrift.transport.TTransport.TTransportException
                server_idx = (server_idx + 1) % num_dbnodes
                time.sleep(3)

        if self._reset_config:
            try:
                sys_mgr.drop_keyspace(keyspace_name)
            except pycassa.cassandra.ttypes.InvalidRequestException as e:
                # TODO verify only EEXISTS
                self._logger("Warning! " + str(e), level=SandeshLevel.SYS_WARN)

        try:
            sys_mgr.create_keyspace(keyspace_name, SIMPLE_STRATEGY,
                                    {'replication_factor': str(num_dbnodes)})
        except pycassa.cassandra.ttypes.InvalidRequestException as e:
            # TODO verify only EEXISTS
            self._logger("Warning! " + str(e), level=SandeshLevel.SYS_WARN)

        gc_grace_sec = 0
        if num_dbnodes > 1:
            gc_grace_sec = 60

        for cf_info in cf_info_list:
            try:
                (cf_name, comparator_type) = cf_info
                if comparator_type:
                    sys_mgr.create_column_family(
                        keyspace_name, cf_name,
                        comparator_type=comparator_type,
                        gc_grace_seconds=gc_grace_sec,
                        default_validation_class='UTF8Type')
                else:
                    sys_mgr.create_column_family(keyspace_name, cf_name,
                        gc_grace_seconds=gc_grace_sec,
                        default_validation_class='UTF8Type')
            except pycassa.cassandra.ttypes.InvalidRequestException as e:
                # TODO verify only EEXISTS
                self._logger("Warning! " + str(e), level=SandeshLevel.SYS_WARN)
                sys_mgr.alter_column_family(keyspace_name, cf_name,
                    gc_grace_seconds=gc_grace_sec,
                    default_validation_class='UTF8Type')
开发者ID:GIC-de,项目名称:contrail-controller,代码行数:56,代码来源:vnc_cassandra.py

示例8: test_big_batched_writes

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
def test_big_batched_writes():
    ## this is an m1.xlarge doing nothing but supporting this test
    server = 'localhost:9160'
    keyspace = 'testkeyspace_' + getpass.getuser().replace('-', '_')
    family = 'testcf'
    sm = SystemManager(server)
    try:
        sm.drop_keyspace(keyspace)
    except pycassa.InvalidRequestException:
        pass
    sm.create_keyspace(keyspace, SIMPLE_STRATEGY, {'replication_factor': '1'})
    sm.create_column_family(keyspace, family, super=False,
                            key_validation_class = LEXICAL_UUID_TYPE,
                            default_validation_class  = LEXICAL_UUID_TYPE,
                            column_name_class = ASCII_TYPE)
    sm.alter_column(keyspace, family, 'test', ASCII_TYPE)
    sm.close()

    pool = ConnectionPool(keyspace, [server], max_retries=10, pool_timeout=0, pool_size=10, timeout=120)
    pool.fill()
    pool.add_listener( Listener() )

    ## assert that we are using framed transport
    conn = pool._q.get()
    assert isinstance(conn.transport, thrift.transport.TTransport.TFramedTransport)
    pool._q.put(conn)

    try:
        for num_rows in range(14, 20):
            ## write some data to cassandra using increasing data sizes
            one_mb = ' ' * 2**20
            rows = []
            for i in xrange(num_rows):
                key = uuid.uuid4()
                rows.append((key, dict(test=one_mb)))

            testcf = pycassa.ColumnFamily(pool, family)
            with testcf.batch() as batch:
                for (key, data_dict) in rows:
                    data_size = len(data_dict.values()[0])
                    logger.critical('adding %r with %.6f MB' % (key, float(data_size)/2**20))
                    batch.insert(key, data_dict)

            logger.critical('%d rows written' % num_rows)

    finally:
        sm = SystemManager(server)
        try:
            sm.drop_keyspace(keyspace)
        except pycassa.InvalidRequestException:
            pass
        sm.close()
        logger.critical('clearing test keyspace: %r' % keyspace)
开发者ID:johnrfrank,项目名称:pycassa,代码行数:55,代码来源:test_big_batch_writes.py

示例9: create_keyspace

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
 def create_keyspace(self):
     """
     Creates the Cassandra Keyspace (if not exist)
     """
     sys_mgr = None
     try:
         sys_mgr = SystemManager()
         try:
             sys_mgr.describe_ring(settings.KEYSPACE)
         except:
             logger.info("create_keyspace(): Creating keyspace %s", settings.KEYSPACE)
             sys_mgr.create_keyspace(settings.KEYSPACE, SIMPLE_STRATEGY, {'replication_factor': '1'})
     finally:
         if sys_mgr:
             sys_mgr.close()
开发者ID:hgdeoro,项目名称:daedalus,代码行数:17,代码来源:storage.py

示例10: cassandra_reset

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
def cassandra_reset():
    from feedly import settings

    hostname = settings.FEEDLY_CASSANDRA_HOSTS[0]
    keyspace = "test_feedly"

    sys = SystemManager(hostname)

    # sys.drop_keyspace(keyspace)

    if keyspace not in sys.list_keyspaces():
        sys.create_keyspace(keyspace, SIMPLE_STRATEGY, {"replication_factor": "1"})

        sys.create_column_family(keyspace, "activity", comparator_type=UTF8_TYPE)

        sys.create_column_family(keyspace, "timeline", comparator_type=IntegerType(reversed=True))
开发者ID:jblomo,项目名称:Feedly,代码行数:18,代码来源:conftest.py

示例11: __init__

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
 def __init__(self, engine, **kw):
     super(CassandraStore, self).__init__(engine, **kw)
     spliturl = urlparse.urlsplit(engine)
     _, keyspace, column_family = spliturl[2].split('/')
     try:
         self._pool = pycassa.connect(keyspace, [spliturl[1]])
         self._store = pycassa.ColumnFamily(self._pool, column_family)
     except pycassa.InvalidRequestException:
         from pycassa.system_manager import SystemManager
         system_manager = SystemManager(spliturl[1])
         system_manager.create_keyspace(
             keyspace, kw.get('replication', 1)
         )
         system_manager.create_column_family(keyspace, column_family)
         self._pool = pycassa.connect(keyspace, [spliturl[1]])
         self._store = pycassa.ColumnFamily(self._pool, column_family)
开发者ID:othrayte,项目名称:xbmc-module-shove,代码行数:18,代码来源:cassandra.py

示例12: __init__

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
class CassandraDbSysManager:
    def __init__(self):
        try:
            logger.info("Connection to " + DB_IP + ":" + DB_PORT + " ...")
            self.sysDB = SystemManager(DB_IP + ":" + DB_PORT)
            logger.info("Connection to the systemManager established.")
        except Exception as exep:
            logger.warning("Could not connect to the DB '" + DB_IP + ":" + DB_PORT + "'. | " + str(exep))


    def create_keyspace(self, KeyspaceName, replica_factor):
        try:
            logger.info(
                "Creating the Keyspace '" + KeyspaceName + "' with replica_factor '" + str(replica_factor) + "'")
            self.sysDB.create_keyspace(KeyspaceName, replica_factor)
            logger.info("Keyspace created.")
        except Exception as exep:
            logger.warning("Could not create the keyspace '" + KeyspaceName + "'. | " + str(exep))

    def drop_keyspace(self, KeyspaceName):
        try:
            logger.info("Dropping the Keyspace '" + KeyspaceName + "'")
            self.sysDB.drop_keyspace(KeyspaceName)
            logger.info("Keyspace dropped.")
        except Exception as exep:
            logger.warning("Could not drop the keyspace '" + KeyspaceName + "'. | " + str(exep))

    def create_column_family(self, KeyspaceName, columnFamily):
        try:
            logger.info("Creating the Column family '" + columnFamily + "' into the keyspace '" + KeyspaceName + "'")
            self.sysDB.create_column_family(KeyspaceName, columnFamily, super=False,
                                            comparator_type=pycassa.system_manager.ASCII_TYPE)
            logger.info("Column Family created.")
        except Exception as exep:
            logger.warning(
                "Could not create the Column Family '" + columnFamily + "' into the keyspace '" + KeyspaceName + "'. | " + str(
                    exep))

    def drop_column_family(self, KeyspaceName, columnFamily):
        try:
            logger.info("Dropping the Column Family '" + columnFamily + "' from the Keyspace '" + KeyspaceName + "'")
            self.sysDB.drop_column_family(KeyspaceName, columnFamily)
            logger.info("Column Family dropped.")
        except Exception as exep:
            logger.warning("Could not drop the column family '" + columnFamily + "'. | " + str(exep))
开发者ID:occi,项目名称:TSP-CloudStack,代码行数:47,代码来源:connection.py

示例13: setup_package

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
def setup_package():
    sys = SystemManager()
    if TEST_KS in sys.list_keyspaces():
        sys.drop_keyspace(TEST_KS)
    try:
        sys.create_keyspace(TEST_KS, 'SimpleStrategy', {'replication_factor': '1'})
        sys.create_column_family(TEST_KS, 'Standard1')
        sys.create_column_family(TEST_KS, 'Super1', super=True)
        sys.create_column_family(TEST_KS, 'Indexed1')
        sys.create_index(TEST_KS, 'Indexed1', 'birthdate', 'LongType')
        sys.create_column_family(TEST_KS, 'Counter1',
                                 default_validation_class='CounterColumnType')
        sys.create_column_family(TEST_KS, 'SuperCounter1', super=True,
                                 default_validation_class='CounterColumnType')
    except Exception, e:
        print e
        try:
            sys.drop_keyspace(TEST_KS)
        except:
            pass
        raise e
开发者ID:EmergingThreats,项目名称:pycassa,代码行数:23,代码来源:__init__.py

示例14: setup_namespace

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
    def setup_namespace(self, table_names):
        if self.pool:
            self.pool.dispose()
            del self.pool
            self.pool = None
        start_connect_time = time.time()

        super(CStorage, self).setup_namespace(table_names)

        sm = SystemManager(self._chosen_server)
        try:
            sm.create_keyspace(
                self._app_namespace, SIMPLE_STRATEGY,
                {
                    'replication_factor': str(self._config.get('replication_factor', '1'))
                },
                )
        except pycassa.InvalidRequestException, exc:
            if exc.why.startswith('Keyspace names must be case-insensitively unique'):
                pass
            else:
                raise exc
开发者ID:diffeo,项目名称:kvlayer,代码行数:24,代码来源:_cassandra.py

示例15: ComedySysManagerConnection

# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import create_keyspace [as 别名]
class ComedySysManagerConnection(object):
    """
    This is a also a client connection of Cassandra, difference is it is only for System-Manager level
    """
    def __init__(self, server='localhost:9160', credentials=None, framed_transport=True,
                                                                    timeout=_DEFAULT_TIMEOUT):
        self.conn = SystemManager(server,credentials,framed_transport,timeout)
        
    def create_keyspace(self, name, replication_strategy='SimpleStrategy', strategy_options=None, durable_writes=True, **ks_kwargs):
        """Create a database"""
        self.conn.create_keyspace(name, replication_strategy, strategy_options, durable_writes)
    
    create_database = create_keyspace
    
    def drop_keyspace(self, keyspace):
        """Drop a database"""
        self.conn.drop_keyspace(keyspace)
    
    drop_database = drop_keyspace
    
    
    def create_column_family(self, keyspace, name, column_validation_classes=None, **cf_kwargs):
        """Create a table"""
        self.conn.create_column_family(keyspace, name, column_validation_classes=None, **cf_kwargs) 
    
    create_table = create_column_family
    
    def drop_column_family(self, keyspace, column_family):
        """Drop a table"""
        self.conn.drop_column_family(keyspace, column_family)
        
    drop_table = drop_column_family
    

    def close(self):
        pass
开发者ID:tonytan4ever,项目名称:Comedy,代码行数:38,代码来源:connection.py


注:本文中的pycassa.system_manager.SystemManager.create_keyspace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。