def __call__(self, test, benckmark): try: self.cbb = Couchbase.connect(bucket='benchmarks', **SF_STORAGE) self.cbf = Couchbase.connect(bucket='feed', **SF_STORAGE) except Exception, e: logger.warn('Failed to connect to database, {}'.format(e)) return
def __call__(self, test, benckmark): try: self.cbb = Couchbase.connect(bucket='benchmarks', **SHOWFAST) self.cbf = Couchbase.connect(bucket='feed', **SHOWFAST) except Exception, e: logger.warn('Failed to connect to database, {}'.format(e)) return
def script_main(input, output, connection=None, ddoc_name=None): if os.path.isdir(input): # Read from the filesystem to a design doc, and try to put it into # Couchbase. Expects 'input' to be a directory readable by the script, # and 'output' to be a set of arguments with which to connect to the # Couchbase server. cb = connection or Couchbase.connect(**output) ddoc = fs_to_ddoc(input) # Now on with design documents url = ddoc.pop('_id') name = url.split('/', 1)[1] # URL should be "_design/{name}" try: response = cb._design(name, ddoc) except exceptions.HTTPError as e: raise e else: # Output to the filesystem from the given input Couchbase instance and # the design document name cb = connection or Couchbase.connect(**input) if not ddoc_name: raise AssertionError("No design document name supplied") try: response = cb._view(ddoc_name, method="GET") except exceptions.HTTPError as e: if e.status == 404: raise AssertionError("No such design document in %s" % input) else: raise ddoc = response ddoc_to_fs(ddoc, output)
def script_main(input, output, connection=None, ddoc_name=None): if os.path.isdir(input): # Read from the filesystem to a design doc, and try to put it into # Couchbase. Expects 'input' to be a directory readable by the script, # and 'output' to be a set of arguments with which to connect to the # Couchbase server. cb = connection or Couchbase.connect(**output) ddoc = fs_to_ddoc(input) # Now on with design documents url = ddoc.pop('_id') name = url.split('/', 1)[1] # URL should be "_design/{name}" print 'Creating design doc:', name, 'on bucket', output['bucket'] use_devmode = '_design/dev' in input response = cb.design_create(name, ddoc, use_devmode=use_devmode) print 'Design doc', name, 'creation result:', response.value else: # Output to the filesystem from the given input Couchbase instance and # the design document name cb = connection or Couchbase.connect(**input) if not ddoc_name: raise AssertionError('No design document name supplied') print 'Fetching design doc:', ddoc_name response = cb.design_get(ddoc_name, method='GET') print 'Design doc', ddoc_name, 'fetch result:', response.value ddoc = response ddoc_to_fs(ddoc, output)
class TempDatabaseMixin(object): temp_dbs = None _db = None def setUp(self): self.server = Couchbase("localhost", "Administrator", "password") def tearDown(self): if self.temp_dbs: for name in self.temp_dbs: self.server.delete(name) def temp_db(self): if self.temp_dbs is None: self.temp_dbs = {} # Find an unused database name while True: name = "couchbase-mapping-python_%d" % random.randint(0, sys.maxint) if name not in self.temp_dbs: break db = self.server.create(name) self.temp_dbs[name] = db return name, db def del_db(self, name): del self.temp_dbs[name] self.server.delete(name) @property def db(self): if self._db is None: name, self._db = self.temp_db() return self._db
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)
def __call__(self, test, benckmark): showfast = test.test_config.stats_settings.showfast cbmonitor = test.test_config.stats_settings.cbmonitor try: self.cbb = Couchbase.connect(bucket='benchmarks', **showfast) self.cbf = Couchbase.connect(bucket='feed', **showfast) except Exception, e: logger.warn('Failed to connect to database, {}'.format(e)) return
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')
class CouchbaseStorage(object): """ A storage backend using Couchbase You must supply a COUCHBASE_URL setting that is passed through urlparse. All parameters supplied get passed through to Couchbase Examples: * couchbase:///bucket * couchbase://hostname/bucket * couchbase://host1,host2/bucket * couchbase://hostname/bucket?password=123abc&timeout=5 """ def __init__(self, settings): url = urlparse.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) def save(self, key, value, expire=None): res = self.couchbase.set(key, value, ttl=expire) return res.success def clear(self, key): res = self.couchbase.delete(key) return res.success def clear_all_keys(self): """ Couchbase doesn't support clearing all keys (flushing) without the Admin username and password. It's not appropriate for Will to have this information so we don't support clear_all_keys for CB. """ return "Sorry, you must flush the Couchbase bucket from the Admin UI" def load(self, key): try: res = self.couchbase.get(key) return res.value except cb_exc.NotFoundError: pass def size(self): """ Couchbase doesn't support getting the size of the DB """ return "Unknown (See Couchbase Admin UI)"
def connectTOdb(): server = configurations.server_ip port = configurations.couchbase_port bucket = configurations.couchbase_rss_bucket password = configurations.couchbase_rss_password cbucket = Couchbase.connect(host=server, port=port, bucket=bucket, password=password) return cbucket
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]
def measure_latency(self): logger.info('Measuring replication latency') timings = [] found = lambda cb: [ v for v in cb.observe(item).value if v.flags != OBS_NOTFOUND ] password = self.test_config.bucket.password for master in self.cluster_spec.yield_masters(): for bucket in self.test_config.buckets: host, port = master.split(':') cb = Couchbase.connect(host=host, port=port, bucket=bucket, password=password) for _ in range(self.NUM_SAMPLES): item = uhex() cb.set(item, item) t0 = time() while len(found(cb)) != 2: sleep(0.001) latency = 1000 * (time() - t0) # s -> ms logger.info(latency) timings.append(latency) summary = { 'min': round(min(timings), 1), 'max': round(max(timings), 1), 'mean': round(np.mean(timings), 1), '80th': round(np.percentile(timings, 80), 1), '90th': round(np.percentile(timings, 90), 1), '95th': round(np.percentile(timings, 95), 1), '99th': round(np.percentile(timings, 99), 1), } logger.info(pretty_dict(summary)) if hasattr(self, 'experiment'): self.experiment.post_results(summary['95th'])
def connectTOdb(): server = configurations.server_ip port = configurations.couchbase_port bucket = configurations.couchbase_bucket password = configurations.couchbase_password cbucket = Couchbase.connect(host=server, port=port, bucket=bucket, password=password) return cbucket
def test_is_instance_of_connection(self): self.assertIsInstance( Couchbase.connect(host=self.cluster_info.host, port=self.cluster_info.port, password=self.cluster_info.bucket_password, bucket=self.cluster_info.bucket_prefix), Connection)
def connection(): if not hasattr(connection, 'singleton'): connection.singleton = Couchbase.connect(bucket=settings.COUCHBASE_BUCKET, host=settings.COUCHBASE_HOSTS, password=settings.COUCHBASE_PASSWORD, lockmode=LOCKMODE_WAIT) return connection.singleton
def __init__(self, url='localhost', port=8091, bucket='default', unique_key='_id', **kwargs): """Creates a connection to the specified Couchbase cluster and bucket. """ print kwargs parsed_url = urlparse(url) if parsed_url.hostname != None and parsed_url.port != None: url = parsed_url.hostname port = parsed_url.port if parsed_url.path != None: path = parsed_url.path.strip("/").strip(" ") if path != None and path != "": bucket = path self.couchbase = Couchbase.connect(bucket=bucket, host=url, port=port, quiet=True) self.unique_key = unique_key self.url = url self.bucket = bucket
def getbeer(self): cb = Couchbase.connect(bucket='beer-sample') new_beer = { "name": "Old Yankee Ale", "abv": 5.00, "ibu": 0, "srm": 0, "upc": 0, "type": "beer", "brewery_id": "cottrell_brewing_co", "updated": "2012-08-30 20:00:20", "description": ".A medium-bodied Amber Ale", "style": "American-Style Amber", "category": "North American Ale" } try: i = 0 match = randint(0, 100) ilimit = 100 rows = cb.query("beer", "by_name", limit=ilimit, skip=2, include_docs=True) for r in rows: if r.doc.value != None: i += 1 if i == match: # todo Key mit uebergeben new_beer = r.doc.value except CouchbaseError as e: print e finally: i = i return new_beer """
def get_mult_runs_data(design_doc, view_names, x_npy_file, y_npy_file): cb = Couchbase.connect(bucket=bucket_name, host=host_name) x = [[0, 0, 0, 0, 0, 0, 0, 0]] for view_name in view_names: rows = cb.query(design_doc, view_name) count = 0 for row in rows: x.append([row.value[1]['thread_alloc_count'], row.value[1]['proc_count'], row.value[1]['thread_alloc_size'], row.value[2]['mem_free'], row.value[2]['native_allocated_heap'], row.value[2]['native_free_heap'], row.value[2]['mem_total'], row.value[2]['native_heap'], row.value[3]['global_class_init'], row.value[3]['classes_loaded'], row.value[3]['total_methods_invoc'], row.value[4]['total_tx'], row.value[4]['total_rx']]) count = count + 1 print view_name + ' count: ' + `count` x.remove([0, 0, 0, 0, 0, 0, 0, 0]) joblib.dump(x, x_npy_file)
def update_defaults(self): cb = Couchbase.connect(bucket='exp_defaults', **CBMONITOR) cb.set(self.name, { 'id': self.name, 'name': self.experiment['name'], 'inputs': self.experiment['defaults'], })
def mngviewAdd(request): cb=Couchbase.connect(bucket='default', host='localhost') resultsess = cb.get("SessionDetails::{0}".format(request.POST.get('hiduname'))).value username = resultsess['username'] dep = resultsess['deploymentname'] result = cb.get("user::{0}".format(username)).value print result deploymentIndex = 0; temp ={} for res in result['deploy'] : if res['request']['depname'] == dep: temp = res['request'] break deploymentIndex = deploymentIndex + 1 temp['status'] = 'RDAD' temp['cpus'] = request.POST.get('number') temp['deploymentIndex'] = deploymentIndex depDoc = "DeploymentRequest::{0}::{1}".format(username,timestamp()) cb.set("{0}".format(depDoc),temp) resultsess['depDoc'] = depDoc cb.set ("SessionDetails::{0}".format(username), resultsess) cpu = request.POST.get('number') return render_to_response ("progress.html", {'cpu':cpu, 'uname':request.POST.get('hiduname')})
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)
def get_mult_runs_data(design_doc, view_names, x_npy_file, y_npy_file): cb = Couchbase.connect(bucket=bucket_name, host=host_name) x = [[0, 0, 0, 0, 0, 0, 0, 0]] for view_name in view_names: rows = cb.query(design_doc, view_name) count = 0 for row in rows: x.append([ row.value[1]['thread_alloc_count'], row.value[1]['proc_count'], row.value[1]['thread_alloc_size'], row.value[2]['mem_free'], row.value[2]['native_allocated_heap'], row.value[2]['native_free_heap'], row.value[2]['mem_total'], row.value[2]['native_heap'], row.value[3]['global_class_init'], row.value[3]['classes_loaded'], row.value[3]['total_methods_invoc'], row.value[4]['total_tx'], row.value[4]['total_rx'] ]) count = count + 1 print view_name + ' count: ' + ` count ` x.remove([0, 0, 0, 0, 0, 0, 0, 0]) joblib.dump(x, x_npy_file)
def get_run_data(design_doc, view_name, x_npy_file, y_npy_file, trn_run=False): cb = Couchbase.connect(bucket=bucket_name, host=host_name) rows = cb.query(design_doc, view_name) x = [[0, 0, 0, 0, 0, 0, 0, 0]] y = [15] count = 0 for row in rows: x.append([ row.value[1]['thread_alloc_count'], row.value[1]['proc_count'], row.value[1]['thread_alloc_size'], row.value[2]['mem_free'], row.value[2]['native_allocated_heap'], row.value[2]['native_free_heap'], row.value[2]['mem_total'], row.value[2]['native_heap'], row.value[3]['global_class_init'], row.value[3]['classes_loaded'], row.value[3]['total_methods_invoc'], row.value[4]['total_tx'], row.value[4]['total_rx'] ]) if trn_run == True: y.append(0) count = count + 1 x.remove([0, 0, 0, 0, 0, 0, 0, 0]) y.remove(15) joblib.dump(x, x_npy_file) joblib.dump(y, y_npy_file) return count
def update_defaults(self): cb = Couchbase.connect(bucket='exp_defaults', **SF_STORAGE) cb.set(self.name, { 'id': self.name, 'name': self.experiment['name'], 'inputs': self.experiment['defaults'], })
def test_is_instance_of_connection(self): self.assertIsInstance( Couchbase.connect(host=self.host, port=self.port, username=self.username, password=self.password, bucket=self.bucket_prefix), Connection)
def get_insight_data(request): insight = request.GET["insight"] abscissa = request.GET["abscissa"] vary_by = request.GET.get("vary_by") inputs = json.loads(request.GET["inputs"]) inputs.pop(abscissa) if vary_by: inputs.pop(vary_by) defaults = get_default_inputs(insight) cb = Couchbase.connect(bucket="experiments", **settings.COUCHBASE_SERVER) data = defaultdict(list) for row in cb.query("experiments", "experiments_by_name", key=insight, stale=False): value = row.value value_inputs = dict(defaults, **value["inputs"]) if dict(value_inputs, **inputs) == value_inputs: key = value["inputs"].get(vary_by, defaults.get(vary_by)) data[key].append((value_inputs[abscissa], value["value"])) for k, v in data.items(): v.sort(key=lambda xy: xy[0]) data = OrderedDict(sorted(data.items())) content = json.dumps(data) return HttpResponse(content)
def create_account(request): cb=Couchbase.connect(bucket='default', host='localhost') uname = request.POST.get('username') password = request.POST.get('password') accountname = request.POST.get('accountName') email = request.POST.get('email') session = {} sessionname = "SessionDetails::{0}".format(uname) session['username'] = uname cb.set(sessionname,session) value = {'username' : uname, 'password1':password, 'accountName':accountname, 'email' :email, 'deploy':None} print value['username'] cb.set("user::{0}".format(uname),json.dumps(value)) result = cb.get("user::{0}".format(uname)).value print result return render_to_response('deployments.html', {'result' :result, 'username':uname})
def login_user(request): state = "Please log in below..." cb=Couchbase.connect(bucket='default', host='localhost') username = password = '' if request.POST: username = request.POST.get('username') password = request.POST.get('password') try : result = cb.get("user::{0}".format(username)).value print result try : store = result result = json.loads(result) except: result = store session = {} if (result['password1'] == password) : session['username'] = username sessionname = "SessionDetails::{0}".format(username) cb.set(sessionname,session) return render_to_response("deployments.html",{'result':result, 'username' : username}) else : return render_to_response("auth.html",{'error':"IU", 'message':"Your username or password is invalid"}) except: return render_to_response("auth.html",{'error':"IU", 'message':"Your username or password is invalid"})
def test_is_instance_of_connection(self): self.assertIsInstance( Couchbase.connect(host=self.host, port=self.port, password=self.bucket_password, bucket=self.bucket_prefix), Connection)
def get_insight_defaults(request): cb = Couchbase.connect(bucket="exp_defaults", **settings.COUCHBASE_SERVER) defaults = [ row.value for row in cb.query("exp_defaults", "all", stale=False) ] content = json.dumps(defaults) return HttpResponse(content)
def __init__( self, priceType="e43", echost="api.eve-central.com", e43host="element-43.com", psqlhost="localhost", psqlname="element43", psqluser="******", psqlpass="******", psqlport="6432", cbserver="127.0.0.1", regionID=10000002, cbucket="prices", cbpass="******", ): self.priceType = priceType self.echost = echost self.e43host = e43host self.psqlhost = psqlhost self.psqlname = psqlname self.psqluser = psqluser self.psqlpass = psqlpass self.psqlport = psqlport self.cache = Couchbase.connect(cbucket, cbserver, password=cbpass) self.regionID = int(regionID) typeID = 0
def _add_cluster(self): cluster = self.test.cluster_spec.name params = self.test.cluster_spec.parameters try: cb = Couchbase.connect(bucket='clusters', **SF_STORAGE) cb.set(cluster, params) except Exception, e: logger.warn('Failed to add cluster, {}'.format(e))
def __init__(self, settings): super(Latency, self).__init__(settings) self.clients = [] for bucket in self.get_buckets(): self.clients.append(Couchbase.connect( bucket=bucket, host=settings.master_node, username=bucket, password=settings.bucket_password ))
def _add_cluster(self): cluster = self.test.cluster_spec.name params = self.test.cluster_spec.parameters try: cb = Couchbase.connect(bucket='clusters', **SHOWFAST) cb.set(cluster, params) except Exception, e: logger.warn('Failed to add cluster, {}'.format(e))
def connectToDb(): #Define Database connection creds server = script_settings.cb_server port = script_settings.couchbase_port admin_password = script_settings.cb_admin_password bucket = script_settings.cb_facebook_bucket cbucket = Couchbase.connect(host=server,port=port,bucket=bucket,password=admin_password) return cbucket
def connection(): if not hasattr(connection, 'singleton'): connection.singleton = Couchbase.connect( bucket=settings.COUCHBASE_BUCKET, host=settings.COUCHBASE_HOSTS, password=settings.COUCHBASE_PASSWORD, lockmode=LOCKMODE_WAIT) return connection.singleton
def connect_db(): """ connect to couchbase """ global db_client try: db_client = Couchbase.connect(host='127.0.0.1', port=8091, bucket='sample') except ConnectError as error: raise return db_client
def __init__(self, libvirt_url='qemu:///system', host='127.0.0.1:8091', bucket='default', password=''): self.cb = Couchbase.connect(host=host, bucket=bucket, password=password) self.vmUsageRecord = UsageRecord.UsageRecord(libvirt_url)
def test_transcoder_class(self): # Test whether we can pass a class for a transcoder key = self.gen_key("transcoder_class") c = Connection(**self.make_connargs(transcoder=TranscoderPP)) c.set(key, "value") c = Couchbase.connect(**self.make_connargs(transcoder=TranscoderPP)) c.set(key, "value")
def __init__(self): server = "83.212.114.237" port = 8091 # admin_username = "******" # admin_password = "******" bucket = "default" self.cbucket = Couchbase.connect(host=server, port=port, bucket=bucket)
def auth_user(request): state = "Please log in below..." cb= Couchbase.connect(bucket="default", host="localhost") diction = {"AWS":{'m3.large': '3584'}, "GCE":{"n1-highmem-4":'3584', "n1-highmem-8":'3584'}, "RackSpace":{"8GB Standard Instance":'3584'}, "Azure" :{"Large" : '3584'}} cb.set ("Machine", diction ) return render_to_response('auth.html',{'state':state})
def test_transcoder_class(self): # Test whether we can pass a class for a transcoder key = self.gen_key("transcoder_class") c = Connection(**self.make_connargs(transcoder=Transcoder)) c.set(key, "value") c = Couchbase.connect(**self.make_connargs(transcoder=Transcoder)) c.set(key, "value")
def get_Couchbase_bucket(): server = script_settings.cb_server port = script_settings.couchbase_port admin_username = script_settings.cb_admin_username admin_password = script_settings.cb_admin_password bucket = script_settings.cb_twitter_bucket cbucket = Couchbase.connect(host=server,port=port,bucket=bucket,password=admin_password) return cbucket
def save_deployment(request): cb=Couchbase.connect(bucket='default', host='localhost') result = cb.get("SessionDetails::{0}".format(request.POST.get('hiduname'))).value if (result != None): username = result['username'] result['deploymentname'] = request.POST.get('depname') cb.set("SessionDetails::{0}".format(username),result) provider = request.POST.get('provider') 'Use the parameters in the request for creating instances' if provider == "AWS": storeReq = copy.deepcopy(request.POST) key = request.FILES['keyfile'] fp = open("/tmp/piushs.pem", 'w') fp.write(key.read()) fp.close() if provider == "GCE": storeReq = copy.deepcopy(request.POST) save_dep_GCE(storeReq, request) if provider == "RackSpace": storeReq = copy.deepcopy(request.POST) key = request.FILES['prkeyfile'] fp = open("/tmp/rackspacepk", 'w') fp.write(key.read()) fp.close() if provider == "Azure": storeReq = copy.deepcopy(request.POST) key = request.FILES['certificate'] fp = open("/tmp/azurekey", 'w') fp.write(key.read()) fp.close() storeReq['status'] = "WA" storeReq['username'] = username depDoc = "DeploymentRequest::{0}::{1}".format(username, timestamp()) cb.set("{0}".format(depDoc),storeReq) result['depDoc'] = depDoc cb.set("SessionDetails::{0}".format(username),result) test = cb.set(depDoc, storeReq) return render_to_response("couchbaseconfiguration.html",{'provider':storeReq['provider'], 'machine':storeReq['machine'], 'cpus':storeReq['cpus'], 'username':username})
def _add_cluster(self): cluster = self.test.cluster_spec.name params = self.test.cluster_spec.parameters showfast = self.test.test_config.stats_settings.showfast try: cb = Couchbase.connect(bucket='clusters', **showfast) cb.set(cluster, params) except Exception, e: logger.warn('Failed to add cluster, {}'.format(e))
def _post_benckmark(self, metric, value): key, benckmark = self._prepare_data(metric, value) try: cb = Couchbase.connect(bucket='benchmarks', **SF_STORAGE) self._mark_previous_as_obsolete(cb, benckmark) cb.set(key, benckmark) Comparator()(test=self.test, benckmark=benckmark) except Exception, e: logger.warn('Failed to post results, {}'.format(e))
def __init__(self, settings): super(Latency, self).__init__(settings) self.clients = [] for bucket in self.get_buckets(): self.clients.append( Couchbase.connect(bucket=bucket, host=settings.master_node, username=bucket, password=settings.bucket_password))
def __init__(self, vip, port, bucket, username, password): try: self.cb = Couchbase.connect(bucket=bucket, host=vip, port=port, username=username, password=password) except Exception, e: raise ConnectionException(e)
def __init__(self, iterator, conn): self.size = 0 self.appends = 0 self.adds = 0 self.resets = 0 self.retries = 0 self.iterator = iterator # Define a thread-load RNG to ensure deterministic sequence. self.rng = random.Random(iterator.start) self.client = Couchbase.connect(**conn)
def _post_benckmark(self, metric, value): key, benckmark = self._prepare_data(metric, value) showfast = self.test.test_config.stats_settings.showfast try: cb = Couchbase.connect(bucket='benchmarks', **showfast) self._mark_previous_as_obsolete(cb, benckmark) cb.set(key, benckmark) Comparator()(test=self.test, benckmark=benckmark) except Exception, e: logger.warn('Failed to post results, {} : {}'.format(e, benckmark))
def post_results(self, value): self.update_defaults() key = uhex() self.experiment['value'] = value self.experiment['defaults'] = self.name logger.info('Adding new experiment {}: {}'.format( key, pretty_dict(self.experiment))) cb = Couchbase.connect(bucket='experiments', **SF_STORAGE) cb.set(key, self.experiment)
def L(a, b, c): cb = Couchbase.connect(bucket=b, host='getafix-macmini.ics.uci.edu', port=8091, password='', timeout=36000) filename = a + '.adm' file = open(filename, 'r') outfile = open(a + '.json', 'w') #outfile.write('[\n') line = file.readline() r = 0 while line: r += 1 if r % 100000 == 0: print(r) if (r > -1): timezone = -1 while line.find('datetime', timezone + 1, len(line)) >= 0: timezone = line.find('datetime', timezone + 1, len(line)) line = line[0:timezone + 29] + 'Z' + line[timezone + 29:] while line.find('int64') >= 0: i = line.find('int64') z = line.find('\")', i) line = line[0:z - 1].replace( 'int64(\"', '', 1) + line[z - 1:].replace('\")', '', 1) line = line.replace('{{', '[') line = line.replace('}}', ']') while line.find('(\"') >= 0 and line.find('\")') >= 0: i = line.find('(\"') z = line.rfind(':', 0, i) line = line.replace('(\"', '\":\"', 1) line = line.replace('\")', '\"}', 1) line = line[0:z + 1] + '{\"' + line[z + 1:] #outfile.write(line) data = json.loads(line) while 1 == 1: try: result = cb.set(str(data[c]), data) break except CouchbaseError as e: aa = 1 line = file.readline() #outfile.write(']') file.close() outfile.close() '''
def __init__(self, bucket, server, pwd): ''' Intentionally not handling connection errors here. We expect them to be handled by the calling code. ''' self.bucket = bucket, self.server = server, self.pwd = pwd, self.client = Couchbase.connect(bucket=self.bucket, host=self.server, password=self.pwd)
def connectToDb(): #Define Database connection creds server = script_settings.cb_server port = script_settings.couchbase_port admin_password = script_settings.cb_admin_password bucket = script_settings.cb_facebook_bucket cbucket = Couchbase.connect(host=server, port=port, bucket=bucket, password=admin_password) return cbucket