def setup_kv_obj(client, bucket_name, key, content_type, data): bucket = client.bucket(bucket_name) obj = riak.RiakObject(client, bucket, key) obj.content_type = content_type obj.data = data return obj
def make_kv_data_2i(N, test_bucket_name, riak_client): bucket = riak_client.bucket_type('default').bucket(test_bucket_name) test_data = [] string2i = [] integer2i = [] partitions = [] bad_partitions = [] for i in range(N): obj = riak.RiakObject(riak_client, bucket, str(u'key'+str(i))) obj.content_type = 'application/json' obj.data = {u'data' : i} obj.add_index('string_index_bin', 'string_val_'+str(i)) obj.add_index('integer_index_int', i) obj.store() test_data.append((str('key'+str(i)),{u'data' : i})) string2i.append('string_val_'+str(i)) integer2i.append(i) partitions.append((i,i)) bad_partitions.append((N+i,N+i)) return test_data, string2i, integer2i, partitions, bad_partitions
def remove_tiles_for_level(self, level, before_timestamp=None): bucket = self.bucket client = self.connection for key in self._key_iterator(level): if before_timestamp: obj = self.bucket.get(key, r=1) dummy_tile = Tile((0, 0, 0)) self._fill_metadata_from_obj(obj, dummy_tile) if dummy_tile.timestamp < before_timestamp: obj.delete() else: riak.RiakObject(client, bucket, key).delete()
def _store_data(client, bucket, id, data, indexed_columns): obj = riak.RiakObject(client, bucket, id) obj.set_data(data) obj.set_content_type('application/json') obj._encode_data = True # Set indexes for k in [k for k in data.items() if k in indexed_columns]: obj.add_index('%s_bin' % k, data[k]) # Try to optimize for write speed obj.store(w=1, dw=1, return_body=False)
def insert(self, hash_or_hashes): '''Insert one (or many) hashes into the database''' hashes = hash_or_hashes if not hasattr(hash_or_hashes, '__iter__'): hashes = [hash_or_hashes] for hsh in hashes: permutations = self.permute(hsh) obj = riak.RiakObject(self.client, self.bucket, str(hsh)) for i in range(self.num_tables): obj.add_index('%s_int' % str(i), permutations[i]) obj.set_content_type('application/simhash') obj.set_encoded_data('') obj.store()
def cmd_resource_add(domain, colluuid, mediatype, objname, blob): objkey = random_uuid() dn1 = 'resource=' + objkey + ',resins=' + colluuid + ',associatedDomain=' + domain + ',' + base at1 = [ ('objectClass', ['document', 'reservoirResource']), ('resource', objkey), ('documentIdentifier', objkey), ('mediaType', mediatype), ('cn', objname), ] bkt = rkv.bucket_type(domain).bucket(colluuid) obj = riak.RiakObject(rkv, bkt, objkey) obj.content_type = mediatype obj.data = blob print('Content-Type:', obj.content_type) print('Data:', obj.data) obj.store() #DEBUG# print ('adding', dn1) dap.add_s(dn1, at1) print('Resource:', objkey) return objkey
def teardown(self): import riak bucket = self.cache.bucket for k in bucket.get_keys(): riak.RiakObject(self.cache.connection, bucket, k).delete() TileCacheTestBase.teardown(self)