本文整理汇总了Python中pycassa.system_manager.SystemManager.describe_ring方法的典型用法代码示例。如果您正苦于以下问题:Python SystemManager.describe_ring方法的具体用法?Python SystemManager.describe_ring怎么用?Python SystemManager.describe_ring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycassa.system_manager.SystemManager
的用法示例。
在下文中一共展示了SystemManager.describe_ring方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_connection
# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import describe_ring [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
示例2: create_keyspace
# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import describe_ring [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()
示例3: detect_nodes
# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import describe_ring [as 别名]
def detect_nodes(seeds, keyspace):
from feedly import settings
if not settings.FEEDLY_DISCOVER_CASSANDRA_NODES:
logger.warning('cassandra nodes discovery is off')
return seeds
nodes = frozenset(seeds)
logging.info('retrieve nodes from seeds %r' % seeds)
for seed in seeds:
try:
sys_manager = SystemManager(seed)
except TTransportException:
logging.warning('%s is not a seed or is not reachable' % seed)
continue
ring_description = sys_manager.describe_ring(keyspace)
for ring_range in ring_description:
endpoint_details = ring_range.endpoint_details[0]
hostname = endpoint_details.host
port = getattr(endpoint_details, 'port', 9160)
nodes = nodes.union({'%s:%s' % (hostname, port), }, nodes)
break
return nodes
示例4: get_status
# 需要导入模块: from pycassa.system_manager import SystemManager [as 别名]
# 或者: from pycassa.system_manager.SystemManager import describe_ring [as 别名]
def get_status(self):
status = {}
_logger = logging.getLogger(__name__ + '.get_status')
try:
pool = _get_connection()
pool.dispose()
status['get_connection'] = "ok"
except:
status['get_connection'] = "error"
_logger.exception("_get_connection() failed")
try:
status['get_error_count'] = self.get_error_count()
except:
status['get_error_count'] = "error"
_logger.exception("get_error_count() failed")
try:
status['get_warn_count'] = self.get_warn_count()
except:
status['get_warn_count'] = "error"
_logger.exception("get_warn_count() failed")
try:
status['get_info_count'] = self.get_info_count()
except:
status['get_info_count'] = "error"
_logger.exception("get_info_count() failed")
try:
status['get_debug_count'] = self.get_debug_count()
except:
status['get_debug_count'] = "error"
_logger.exception("get_debug_count() failed")
try:
self.query()
status['query'] = "ok"
except:
status['query'] = "error"
_logger.exception("query() failed")
try:
apps = self.list_applications()
status['list_applications'] = ", ".join(apps)
for app in apps:
try:
status['query_by_application_' + app] = len(self.query_by_application(app))
except:
status['query_by_application_' + app] = "error"
_logger.exception("query_by_application() failed for app {0}".format(app))
except:
status['list_applications'] = "error"
_logger.exception("list_applications() failed")
try:
hosts = self.list_hosts()
status['list_hosts'] = ", ".join(hosts)
for a_host in hosts:
try:
status['query_by_host_' + a_host] = len(self.query_by_host(a_host))
except:
status['query_by_host_' + a_host] = "error"
_logger.exception("query_by_host() failed for host {0}".format(a_host))
except:
status['list_hosts'] = "error"
_logger.exception("list_hosts() failed")
try:
sys_mgr = SystemManager()
sys_mgr.describe_ring(settings.KEYSPACE)
status['SystemManager.describe_ring(%s)' % settings.KEYSPACE] = 'ok'
except:
status['SystemManager.describe_ring(%s)' % settings.KEYSPACE] = 'error'
_logger.exception("SystemManager.describe_ring() failed")
finally:
sys_mgr.close()
return status