def __init__(self):
     self.KEYSPACE = "ccproj_db"
     self.cluster = Cluster(contact_points=['10.176.67.91'],
                            load_balancing_policy=DCAwareRoundRobinPolicy(
                                local_dc='datacenter1'),
                            port=9042,
                            protocol_version=3)
     self.session = self.cluster.connect()
     self.session.set_keyspace(self.KEYSPACE)
 def __init__(self):
     self.le_dict = {}
     self.cluster = Cluster(contact_points=['10.176.67.91'],
                            load_balancing_policy=DCAwareRoundRobinPolicy(
                                local_dc='datacenter1'),
                            port=9042,
                            protocol_version=3)
     self.session = self.cluster.connect('ccproj_db',
                                         wait_for_all_pools=True)
     self.session.execute('USE ccproj_db')
Exemple #3
0
    def __init__(self):

        try:
            self.conf = cfg.CONF

            if self.conf.cassandra.user:
                auth_provider = PlainTextAuthProvider(
                    username=self.conf.cassandra.user,
                    password=self.conf.cassandra.password)
            else:
                auth_provider = None

            self.cluster = Cluster(
                self.conf.cassandra.contact_points,
                port=self.conf.cassandra.port,
                auth_provider=auth_provider,
                connect_timeout=self.conf.cassandra.connection_timeout,
                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)

            self.dim_val_stmt = self.session.prepare(DIMENSION_VALUE_CQL)

            self.dim_name_by_metric_stmt = self.session.prepare(
                DIMENSION_NAME_BY_METRIC_CQL)

            self.dim_name_stmt = self.session.prepare(DIMENSION_NAME_CQL)

            self.metric_name_by_dimension_stmt = self.session.prepare(
                METRIC_NAME_BY_DIMENSION_CQL)

            self.metric_name_by_dimension_offset_stmt = self.session.prepare(
                METRIC_NAME_BY_DIMENSION_OFFSET_CQL)

            self.metric_name_stmt = self.session.prepare(METRIC_NAME_CQL)

            self.metric_name_offset_stmt = self.session.prepare(
                METRIC_NAME_OFFSET_CQL)

            self.metric_by_id_stmt = self.session.prepare(METRIC_BY_ID_CQL)

        except Exception as ex:
            LOG.exception(ex)
            raise exceptions.RepositoryException(ex)

        self.epoch = datetime.utcfromtimestamp(0)
Exemple #4
0
    def connect(self):
        """ DB connection."""
        auth_provider = PlainTextAuthProvider(username=os.getenv('CASSANDRA_USERNAME'),
                                              password=os.getenv('CASSANDRA_PASSWORD'))

        self.cluster = Cluster(
            [os.getenv('CASSANDRA_HOST')],
            load_balancing_policy=TokenAwarePolicy(DCAwareRoundRobinPolicy()),
            port=os.getenv('CASSANDRA_PORT'),
            auth_provider=auth_provider,
            executor_threads=2,
            protocol_version=4,
        )

        self.session = self.cluster.connect()
        register_connection(str(self.session), session=self.session)
        set_default_connection(str(self.session))
def create_cluster():
    user = conf.cassandra.user
    if user:
        auth_provider = PlainTextAuthProvider(username=user,
                                              password=conf.cassandra.password)
    else:
        auth_provider = None

    cluster = Cluster(
        conf.cassandra.contact_points,
        port=conf.cassandra.port,
        auth_provider=auth_provider,
        connect_timeout=conf.cassandra.connection_timeout,
        load_balancing_policy=TokenAwarePolicy(
            DCAwareRoundRobinPolicy(
                local_dc=conf.cassandra.local_data_center)),
    )
    cluster.default_retry_policy = MonascaRetryPolicy(
        1, conf.cassandra.max_write_retries, conf.cassandra.max_write_retries)
    return cluster