cassandra cluster no load-balancing policy

monasca-api connect to cassandra cluster without
load-balancing policy parameter.
Task: 29958
Story: 2005196

Change-Id: Ia740f20f6b8d557a74a48cd0c78cd07c1500ca94
This commit is contained in:
zhangjianweibj 2019-03-15 09:47:11 +08:00
parent b1bd423822
commit 0b1bb93206
3 changed files with 17 additions and 1 deletions

View File

@ -23,6 +23,8 @@ import urllib
from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import Cluster
from cassandra.cluster import DCAwareRoundRobinPolicy
from cassandra.cluster import TokenAwarePolicy
from cassandra.query import FETCH_SIZE_UNSET
from cassandra.query import SimpleStatement
from monasca_common.rest import utils as rest_utils
@ -120,7 +122,12 @@ class MetricsRepository(metrics_repository.AbstractMetricsRepository):
auth_provider = None
self.cluster = Cluster(self.conf.cassandra.contact_points,
port=self.conf.cassandra.port, auth_provider=auth_provider)
port=self.conf.cassandra.port,
auth_provider=auth_provider,
load_balancing_policy=TokenAwarePolicy(
DCAwareRoundRobinPolicy(
local_dc=self.conf.cassandra.local_data_center))
)
self.session = self.cluster.connect(self.conf.cassandra.keyspace)
self.dim_val_by_metric_stmt = self.session.prepare(DIMENSION_VALUE_BY_METRIC_CQL)

View File

@ -40,6 +40,10 @@ Cassandra user for monasca-api service
cfg.StrOpt('password', default='', secret=True,
help='''
Cassandra user password for monasca-api service
'''),
cfg.StrOpt('local_data_center', default='',
help='''
Cassandra local data center name
''')
]

View File

@ -0,0 +1,5 @@
---
features:
- |
support cassandra cluster configuration with loadbalancing policy DCAwareRoundRobinPolicy.
'local_data_center' defalut value is ''.