def test_create_drop_succeeeds(self):
        cluster = get_cluster()

        keyspace_ss = 'test_ks_ss'
        self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
        management.create_keyspace_simple(keyspace_ss, 2)
        self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_ss)

        self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
        with warnings.catch_warnings(record=True) as w:
            management.create_keyspace(keyspace_ss, strategy_class="SimpleStrategy", replication_factor=1)
            self.assertEqual(len(w), 1)
            self.assertEqual(w[-1].category, DeprecationWarning)
        self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_ss)
        self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)

        keyspace_nts = 'test_ks_nts'
        self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
        management.create_keyspace_simple(keyspace_nts, 2)
        self.assertTrue(keyspace_nts in cluster.metadata.keyspaces)

        with warnings.catch_warnings(record=True) as w:
            management.delete_keyspace(keyspace_nts)
            self.assertEqual(len(w), 1)
            self.assertEqual(w[-1].category, DeprecationWarning)

        self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
Beispiel #2
0
    def create_keyspace(
        self,
        keyspace,
        session=None
    ):
        settings = self.settings_dict

        keyspace_default_settings = {
            'durable_writes': True,
            'strategy_class': SimpleStrategy.name,
            'replication_factor': 3
        }

        keyspace_settings = settings.get(
            'KEYSPACES', {}
        ).get(
            keyspace, {}
        )

        keyspace_default_settings.update(keyspace_settings)
        keyspace_settings = keyspace_default_settings

        self.ensure_connection()
        create_keyspace(
            keyspace,
            **keyspace_settings
        )
def sync_cassandra():
    from cassandra.cqlengine.management import sync_table, create_keyspace
    from benchmark.feeds import UserFeed, TimelineFeed
    create_keyspace('stream_framework_bench', 'SimpleStrategy', 3)
    for feed_class in [UserFeed, TimelineFeed]:
        timeline = feed_class.get_timeline_storage()
        sync_table(timeline.model)
    def test_create_drop_succeeeds(self):
        cluster = get_cluster()

        keyspace_ss = 'test_ks_ss'
        self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
        management.create_keyspace_simple(keyspace_ss, 2)
        self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_ss)

        self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
        with warnings.catch_warnings(record=True) as w:
            management.create_keyspace(keyspace_ss,
                                       strategy_class="SimpleStrategy",
                                       replication_factor=1)
            self.assertEqual(len(w), 1)
            self.assertEqual(w[-1].category, DeprecationWarning)
        self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)

        management.drop_keyspace(keyspace_ss)
        self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)

        keyspace_nts = 'test_ks_nts'
        self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
        management.create_keyspace_simple(keyspace_nts, 2)
        self.assertTrue(keyspace_nts in cluster.metadata.keyspaces)

        with warnings.catch_warnings(record=True) as w:
            management.delete_keyspace(keyspace_nts)
            self.assertEqual(len(w), 1)
            self.assertEqual(w[-1].category, DeprecationWarning)

        self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
def sync_cassandra():
    from cassandra.cqlengine.management import sync_table, create_keyspace
    from benchmark.feeds import UserFeed, TimelineFeed
    create_keyspace('stream_framework_bench', 'SimpleStrategy', 3)
    for feed_class in [UserFeed, TimelineFeed]:
        timeline = feed_class.get_timeline_storage()
        sync_table(timeline.model)
def cassandra_setup():
    from cassandra.cqlengine.management import create_table, create_keyspace
    aggregated_timeline = AggregatedFeed.get_timeline_storage()
    timeline = FashiolistaFeed.get_timeline_storage()
    user_timeline = UserFeed.get_timeline_storage()
    create_keyspace('test')
    create_table(aggregated_timeline.model)
    create_table(timeline.model)
    create_table(user_timeline.model)
Beispiel #7
0
def cassandra_setup():
    from cassandra.cqlengine.management import create_table, create_keyspace
    aggregated_timeline = AggregatedFeed.get_timeline_storage()
    timeline = FashiolistaFeed.get_timeline_storage()
    user_timeline = UserFeed.get_timeline_storage()
    create_keyspace('test')
    create_table(aggregated_timeline.model)
    create_table(timeline.model)
    create_table(user_timeline.model)
Beispiel #8
0
def get_column_family(
    connection,
    model
):
    connection_settings = connection.settings_dict

    if hasattr(model, 'Cassandra'):
        cassandra_settings = model.Cassandra.__dict__

    else:
        cassandra_settings = default_cassandra_model_settings

    if hasattr(cassandra_settings, 'keyspace'):
        keyspace = cassandra_settings.keyspace

    else:
        keyspace = connection_settings.get('DEFAULT_KEYSPACE')

    keyspace_settings = connection_settings.get('KEYSPACES', {}).get(keyspace)
    if None is keyspace_settings:
        keyspace_settings = {}  # Replace with default keyspace settings.

    replication_factor = keyspace_settings.get(
        'replication_factor',

    )

    replication_strategy_class = keyspace_settings['strategy_class']

    create_keyspace(
        keyspace,
        replication_strategy_class,
        replication_factor
    )

    table_options = default_table_options

    if hasattr(cassandra_settings, 'table_options'):
        if not isinstance(cassandra_settings.table_optoins, dict):
            raise DatabaseError(
                'The value of table_optoins in the Cassandra class '
                'must be a dict containing overrides for the default'
                'column family options.'
            )
        table_options.update(cassandra_settings.table_metadata)

    return type(
        str(model._meta.db_table),
        (CqlColumnFamily,), {
            '__model__': model,
            'table_options': table_options
        }
    )
Beispiel #9
0
    def setup(self, collection):
        """

        :param collection:
        :return:
        """

        connection.setup([CASSANDRA_1], collection)

        management.create_keyspace(
            collection,
            replication_factor=1,
            strategy_class='SimpleStrategy',
        )

        TestModel.__keyspace__ = collection
        management.sync_table(TestModel)
Beispiel #10
0
    def setup(self, collection):
        """

        :param collection:
        :return:
        """

        connection.setup([CASSANDRA_1], collection)

        management.create_keyspace(
            collection,
            replication_factor=1,
            strategy_class='SimpleStrategy',
        )

        TestModel.__keyspace__ = collection
        management.sync_table(TestModel)
Beispiel #11
0
    def setup(self, force=False, throw=False):
        if self._setup and not force:
            return True

        try:
            connection.setup(self.uri, self.keyspace)
            management.create_keyspace(self.keyspace, replication_factor=1, strategy_class='SimpleStrategy')
            for model in self._models:
                model.__keyspace__ = self.keyspace
                management.sync_table(model)
        except NoHostAvailable:
            logger.error('Could not connect to Cassandra, expect errors.')
            return False

        # Note: return values are for test skipping
        self._setup = True
        return True
Beispiel #12
0
    def setUp(self):
        class MyModel(Model):
            id = columns.Text(max_length=63,
                              primary_key=True,
                              default=lambda: str(uuid.uuid4()))
            value = columns.Text(max_length=63)

        self.model = MyModel
        connection.setup(['127.0.0.1'], self.keyspace)
        create_keyspace(self.keyspace,
                        strategy_class='SimpleStrategy',
                        replication_factor=1)
        sync_table(MyModel)

        class MyManager(CQLManager):
            model = self.model
            fields = (
                'id',
                'value',
            )
            create_fields = ('value', )
            update_fields = ('value', )

        self.manager_class = MyManager
Beispiel #13
0
def connect(): 
    setup(["127.0.0.1"], "videos")
    management.create_keyspace('videos', 'SimpleStrategy',replication_factor=1)
from sys import path
path.append(".")

from cassandra.cqlengine.management import sync_table, create_keyspace

from killranalytics.models import connect_cassandra, PageViews, RealTimeData

connect_cassandra()

ks = 'killranalytics'
create_keyspace(ks, "SimpleStrategy", 1)

sync_table(PageViews)
sync_table(RealTimeData)


print "done"
Beispiel #15
0
import uuid
from cassandra.cqlengine import columns
from cassandra.cqlengine import connection
from datetime import datetime
from cassandra.cqlengine.management import sync_table, create_keyspace
from cassandra.cqlengine.models import Model

##Configuration--------

keyspace="octalspace"
connection.default()
create_keyspace(keyspace, replication_factor=1, strategy_class="SimpleStrategy")
connection.setup(['127.0.0.1'], keyspace, protocol_version=3)

##/Configuration-------

class Account(Model):
    pk = columns.UUID(primary_key=True)
    created_at = columns.DateTime()
    username = columns.Text()

'''
So, how do you do tree data models in cassandra? It is a mystery

My initial thought is that the top level post object, (a self post or a link)
has a list of *all* it's children. That way we can do a batch read and get an entire page. 
Well mostly, one for the object, and once for all of it's descendents

That use case is going to be the vast majority of our data stuff, getting a top level post and *all* descendents.

For displaying it as a tree, we'd need to have each comment contain a list (well, unordered set) of it's immediate children.
Beispiel #16
0
def connect():
    setup(["127.0.0.1"], "videos")
    management.create_keyspace('videos',
                               'SimpleStrategy',
                               replication_factor=1)