예제 #1
0
class CouchBaseBolt(storm.BasicBolt):
    global couchbase
    couchbase = Couchbase('172.26.6.9:8091',
                          username='******',
                          password='******')
    global bucket
    bucket = couchbase['default']

    def process(self, tup):
        handler = logging.FileHandler("/Users/apolion/logfile.txt",
                                      "w",
                                      encoding="UTF-8")

        formatter = logging.Formatter("%(message)s")
        handler.setFormatter(formatter)
        root_logger = logging.getLogger()
        root_logger.addHandler(handler)
        root_logger.setLevel(logging.INFO)

        try:
            key = str(uuid.uuid4())
            myjson = json.loads(tup.values[0])
            bucket["TEST_SPOUT_%s" % (key)] = json.dumps(myjson,
                                                         sort_keys=True)
            root_logger.info(myjson)

        except Exception as inst:
            root_logger.info("EXCEPTION!")
            root_logger.info(myjson)
            root_logger.info(inst)
            root_logger.info(inst.args)
예제 #2
0
 def __init__(self):
     # connect to a couchbase server and select bucket where docs are stored
     self.conn = S3Connection(ACCESS_KEY_ID, SECRET_ACCESS_KEY)
     self.couchbase = Couchbase("%s:%s" % (SERVER_NAME, SERVER_PORT),
                                username=USERNAME,
                                password=PASSWORD)
     self.cb_bucket = self.couchbase[CB_BUCKET_NAME]
예제 #3
0
 def __init__(self, settings):
     self.verify_settings(quiet=True)
     url = parse.urlparse(settings.COUCHBASE_URL)
     params = dict([param.split('=') for param in url.query.split('&')])
     self.couchbase = Couchbase(host=url.hostname.split(','),
                                bucket=url.path.strip('/'),
                                port=url.port or 8091,
                                **params)
예제 #4
0
    def test_old_unified_client_example(self):
        from couchbase import Couchbase

        # connect to a couchbase server
        cb = Couchbase(self.host + ':' + self.port,
                       username=self.username,
                       password=self.password)
        if not cb.couch_api_base:
            raise SkipTest

        default_bucket = cb[self.bucket_name]
        default_bucket['key1'] = 'value1'

        default_bucket2 = cb.bucket(self.bucket_name)
        default_bucket2['key2'] = {'value': 'value2', 'expiration': 0}

        default_bucket.set('key3', 0, 0, 'value3')

        self.assertEqual(str(default_bucket.get('key1')[2]), 'value1')
        self.assertEqual(str(default_bucket2.get('key2')[2]), 'value2')
        self.assertEqual(str(default_bucket2['key3'][2]), 'value3')

        # create a new bucket
        try:
            newbucket = cb.create('newbucket', ram_quota_mb=100, replica=1)
        except:
            newbucket = cb['newbucket']

        # set a JSON document using the more "pythonic" interface
        newbucket['json_test'] = {'type': 'item', 'value': 'json test'}
        print 'json_test ' + str(newbucket['json_test'])
        # use the more verbose API which allows for setting expiration & flags
        newbucket.set('key4', 0, 0, {'type': 'item', 'value': 'json test'})
        print 'key4 ' + str(newbucket['key4'])

        design_doc = {
            "views": {
                "all_by_types": {
                    "map":
                    '''function (doc, meta) {
                             emit([meta.type, doc.type, meta.id], doc.value);
                             // row output: ['json', 'item', 'key4'], 'json test'
                           }'''
                },
            },
        }
        # save a design document
        newbucket['_design/testing'] = design_doc

        all_by_types_view = newbucket['_design/testing']['all_by_types']
        rows = all_by_types_view.results({'stale': False})
        for row in rows:
            self.assertTrue(row is not None)

        cb.delete('newbucket')
예제 #5
0
    def bucket(cls, bucket):
        """Gives the bucket from couchbase server.

        :param bucket: Bucket name to fetch.
        :type bucket: str
        :returns: couchbase driver's Bucket object.
        :rtype: :class:`couchbase.client.Bucket`
        :raises: :exc:`couchbasekit.errors.CredentialsNotSetError` If the
            credentials wasn't set.
        """
        if cls.connection is None:
            if cls.username is None or cls.password is None:
                raise CredentialsNotSetError()
            cls.connection = Couchbase(cls.server, cls.username, cls.password)
        return cls.connection.bucket(bucket)
예제 #6
0
    def bucket(cls, bucket_name):
        """Gives the bucket from couchbase server.

        :param bucket_name: Bucket name to fetch.
        :type bucket_name: str
        :returns: couchbase driver's Bucket object.
        :rtype: :class:`couchbase.client.Bucket`
        :raises: :exc:`RuntimeError` If the credentials wasn't set.
        """
        if cls.connection is None:
            if cls.username is None or cls.password is None:
                raise RuntimeError(
                    "CouchBase credentials are not set to connect.")
            cls.connection = Couchbase(cls.server, cls.username, cls.password)
        if bucket_name not in cls._buckets:
            cls._buckets[bucket_name] = cls.connection.bucket(bucket_name)
        return cls._buckets[bucket_name]
예제 #7
0
 def __init__(self):
     from couchbase import Couchbase
     self.client = Couchbase(HOST, 'Administrator', 'asdasd')['default']