def hello(): try: if aerospike.client(config).is_connected()==False: client = aerospike.client(config).connect() foo = str(uuid.uuid1()); #key = ("test", "hits", foo) # Insert the 'hit' record # ts = datetime.datetime.utcnow() ts = int(round(time.time() * 1000)) client.put(("test", "hits", foo), {"server": host, "ts": ts} ) # Maintain our summaries for the grand total and for each server #key = ("test", "summary", "total_hits") client.increment(("test", "summary", "total_hits"), "total", 1) #key = ("test", "summary", host) client.increment(("test", "summary", host), "total", 1) (key, meta, bins) = client.get(("test","summary","total_hits")) # Return the updated web page return "Hello World! I have been seen by %s." % bins["total"] except Exception as e: return "Hummm - %s looks like we have an issue, let me try again" % "err: {0}".format(e)
def test_change_password_with_proper_parameters(self): user = "******" config = {"hosts": TestChangePassword.hostlist} self.clientreaduser = aerospike.client(config).connect(user, "aerospike") password = "******" status = self.clientreaduser.admin_change_password(user, password) assert status == 0 config = { "hosts": TestChangePassword.hostlist } try: self.clientreaduserwrong = aerospike.client( config).connect(user, "aerospike") except aerospike.exception.InvalidPassword as exception: assert exception.code == 62 assert exception.msg is None except aerospike.exception.ClientError as exception: assert exception.code == -1 assert exception.msg == "Failed to seed cluster" self.clientreaduserright = aerospike.client(config).connect( user, "newpassword") assert self.clientreaduserright is not None self.clientreaduserright.close() self.clientreaduser.close()
def setup_class(cls): """ Setup method. """ hostlist, user, password = TestBaseClass.get_hosts() config = {'hosts': hostlist} if user is None and password is None: TestOperate.client = aerospike.client(config).connect() else: TestOperate.client = aerospike.client(config).connect(user, password) config_no_typechecks = {'hosts': hostlist, 'strict_types': False} if user is None and password is None: TestOperate.client_no_typechecks = aerospike.client( config_no_typechecks).connect() else: TestOperate.client_no_typechecks = aerospike.client( config_no_typechecks).connect(user, password) TestOperate.skip_old_server = True versioninfo = TestOperate.client.info('version') for keys in versioninfo: for value in versioninfo[keys]: if value is not None: versionlist = value[ value.find("build") + 6:value.find("\n")].split(".") if int(versionlist[0]) >= 3 and int(versionlist[1]) >= 6: TestOperate.skip_old_server = False
def test_instance_serializer_and_no_class_serializer(self): """ Invoke put() for record with no class serializer. There is an instance serializer """ hostlist, user, password = TestBaseClass.get_hosts() method_config = {"hosts": hostlist, "serialization": ((lambda v: json.dumps(v)), (lambda v: json.loads(v)))} if user is None and password is None: client = aerospike.client(method_config).connect() else: client = aerospike.client(method_config).connect(user, password) key = ("test", "demo", 11) try: client.remove(key) except: pass rec = {"normal": 1234, "tuple": (1, 2, 3)} res = client.put(key, rec, serializer=aerospike.SERIALIZER_USER) assert res == 0 _, _, bins = client.get(key) # tuples JSON-encode to a list, and we use this fact to check which # serializer ran: assert bins == {"normal": 1234, "tuple": [1, 2, 3]} client.remove(key) client.close()
def test_with_unset_serializer_python_serializer(self): """ Invoke put() for mixed data record with python serializer and calling unset_serializers """ aerospike.set_serializer((lambda v: json.dumps(v))) aerospike.set_deserializer((lambda v: json.loads(v))) hostlist, user, password = TestBaseClass.get_hosts() method_config = {"hosts": hostlist} if user is None and password is None: client = aerospike.client(method_config).connect() else: client = aerospike.client(method_config).connect(user, password) key = ("test", "demo", 16) try: client.remove(key) except: pass rec = {"normal": 1234, "tuple": (1, 2, 3)} aerospike.unset_serializers() res = client.put(key, rec, serializer=aerospike.SERIALIZER_PYTHON) assert res == 0 _, _, bins = client.get(key) # tuples JSON-encode to a list, and we use this fact to check which # serializer ran: assert bins == {"normal": 1234, "tuple": (1, 2, 3)} client.remove(key)
def test_builtin_with_instance_serializer_and_no_class_serializer(self): """ Invoke put() for data record with builtin serializer and an instance serializer set """ hostlist, user, password = TestBaseClass.get_hosts() method_config = {"hosts": hostlist, "serialization": ((lambda v: json.dumps(v)), (lambda v: json.loads(v)))} if user is None and password is None: client = aerospike.client(method_config).connect() else: client = aerospike.client(method_config).connect(user, password) key = ("test", "demo", 12) try: client.remove(key) except: pass rec = {"normal": 1234, "tuple": (1, 2, 3)} res = client.put(key, rec, serializer=aerospike.SERIALIZER_PYTHON) assert res == 0 _, _, bins = client.get(key) assert bins == {"normal": 1234, "tuple": (1, 2, 3)} client.remove(key) client.close()
def test_with_class_serializer_and_instance_serializer_with_unset_serializer(self): """ Invoke put() for mixed data record with python serializer. """ aerospike.set_serializer((lambda v: json.dumps(v))) aerospike.set_deserializer((lambda v: json.loads(v))) hostlist, user, password = TestBaseClass.get_hosts() method_config = {"hosts": hostlist} if user is None and password is None: client = aerospike.client(method_config).connect() else: client = aerospike.client(method_config).connect(user, password) key = ("test", "demo", 16) try: TestPythonSerializer.client.remove(key) except: pass rec = {"normal": 1234, "tuple": (1, 2, 3)} aerospike.unset_serializers() try: client.put(key, rec, serializer=aerospike.SERIALIZER_USER) except e.ClientError as exception: assert exception.code == -1 assert exception.msg == "No serializer callback registered"
def setup_class(cls): print "setup class invoked..." hostlist, user, password = TestBaseClass.get_hosts() config = { 'hosts': hostlist } if user == None and password == None: TestLList.client = aerospike.client(config).connect() else: TestLList.client = aerospike.client(config).connect(user, password) TestLList.key1 = ('test', 'demo', 'integer_llist_ky') TestLList.llist_integer = TestLList.client.llist(TestLList.key1, 'integer_bin') TestLList.key2 = ('test', 'demo', 'string_llist_ky') TestLList.llist_string = TestLList.client.llist(TestLList.key2, 'string_bin') TestLList.key3 = ('test', 'demo', 'float_llist_ky') TestLList.llist_float = TestLList.client.llist(TestLList.key3, 'float_bin')
def setup_method(self, method): """ Setup method. """ hostlist, user, password = TestBaseClass.get_hosts() config = {'hosts': hostlist} if user is None and password is None: self.client = aerospike.client(config).connect() else: self.client = aerospike.client(config).connect(user, password) for i in range(19): key = ('test', u'demo', i) rec = {'name': 'name%s' % (str(i)), 'age': i} self.client.put(key, rec) key = ('test', u'demo', 122) llist = [{"op": aerospike.OPERATOR_APPEND, "bin": bytearray("asd;adk\0kj", "utf-8"), "val": u"john"}] self.client.operate(key, llist) key = ('test', u'demo', 'ldt_key') self.llist_bin = self.client.llist(key, 'llist_key') self.llist_bin.add(10)
def setUp(self): config = {"hosts": KVTestCase.hostlist} if KVTestCase.user is None and KVTestCase.password is None: self.client = aerospike.client(config).connect() else: self.client = aerospike.client(config).connect(KVTestCase.user, KVTestCase.password)
def test_put_with_mixeddata_client_serializer_deserializer_with_spec_in_put(self): pytest.xfail(reason="Need Python 2/3 compatible bytearray for strings") # Invoke put() for mixed data with class and instance serialziers # with a specification in put. Client one is called hostlist, user, password = TestBaseClass.get_hosts() method_config = {'hosts': hostlist, 'serialization': (client_serialize_function, client_deserialize_function)} if user is None and password is None: client = aerospike.client(method_config).connect() else: client = aerospike.client(method_config).connect(user, password) aerospike.set_serializer(serialize_function) aerospike.set_deserializer(deserialize_function) key = ('test', 'demo', 1) rec = { 'map': {"key": "asd';q;'1';", "pi": 3}, 'normal': 1234, 'special': '!@#@#$QSDAsd;as', 'list': ["nanslkdl", 1, bytearray("asd;as[d'as;d")], 'bytes': bytearray("asd;as[d'as;d"), 'nestedlist': ["nanslkdl", 1, bytearray("asd;as[d'as;d"), [1, bytearray("asd;as[d'as;d")]], 'nestedmap': { "key": "asd';q;'1';", "pi": 314, "nest": {"pi1": 312, "t": 1} }, } res = client.put(key, rec, {}, {}, aerospike.SERIALIZER_USER) assert res == 0 _, _, bins = client.get(key) assert bins == { 'map': {"key": "asd';q;'1';", "pi": 3}, 'normal': 1234, 'special': '!@#@#$QSDAsd;as', 'list': ["nanslkdl", 1, bytearray("asd;as[d'as;d", "utf-8")], 'bytes': bytearray("asd;as[d'as;d", "utf-8"), 'nestedlist': ["nanslkdl", 1, bytearray("asd;as[d'as;d", "utf-8"), [1, bytearray("asd;as[d'as;d", "utf-8")]], 'nestedmap': { "key": "asd';q;'1';", "pi": 314, "nest": {"pi1": 312, "t": 1} }, } client.close() self.delete_keys.append(key)
def test_with_class_serializer_and_instance_serializer(self): pytest.xfail(reason="Serialization of Bytes not functional") """ Invoke put() for mixed data record with class and instance serializer. """ aerospike.set_serializer((lambda v: json.dumps(v))) aerospike.set_deserializer((lambda v: json.loads(v))) hostlist, user, password = TestBaseClass.get_hosts() method_config = { "hosts": hostlist, "serialization": ((lambda v: marshal.dumps(v)), (lambda v: marshal.loads(v))), } if user is None and password is None: client = aerospike.client(method_config).connect() else: client = aerospike.client(method_config).connect(user, password) key = ("test", "demo", 16) try: TestPythonSerializer.client.remove(key) except: pass rec = {"normal": 1234, "tuple": (1, 2, 3)} res = client.put(key, rec, serializer=aerospike.SERIALIZER_USER) assert res == 0 _, _, bins = client.get(key) # tuples JSON-encode to a list, and we use this fact to check which # serializer ran: assert bins == {"normal": 1234, "tuple": (1, 2, 3)} client.remove(key)
def setup_class(cls): """ Setup method. """ hostlist, user, password = TestBaseClass.get_hosts() config = {'hosts': hostlist} if user is None and password is None: TestGeospatial.client = aerospike.client(config).connect() else: TestGeospatial.client = aerospike.client( config).connect(user, password) TestGeospatial.client.index_geo2dsphere_create( "test", "demo", "loc", "loc_index") TestGeospatial.client.index_geo2dsphere_create( "test", "demo", "loc_polygon", "loc_polygon_index") TestGeospatial.client.index_geo2dsphere_create( "test", "demo", "loc_circle", "loc_circle_index") TestGeospatial.skip_old_server = True versioninfo = TestGeospatial.client.info('version') for keys in versioninfo: for value in versioninfo[keys]: if value is not None: versionlist = value[ value.find("build") + 6:value.find("\n")].split(".") if int(versionlist[0]) >= 3 and int(versionlist[1]) >= 7: TestGeospatial.skip_old_server = False
def setup_method(self, method): """ Setup method. """ hostlist, _, _ = TestBaseClass.get_hosts() config = { 'hosts': hostlist, 'lua': {'user_path': '/tmp/', 'system_path': '../aerospike-client-c/lua/'}} if TestBaseClass.user is None and TestBaseClass.password is None: self.client = aerospike.client(config).connect() else: self.client = aerospike.client(config).connect( TestBaseClass.user, TestBaseClass.password) for i in range(5): key = ('test', 'demo', i) rec = { 'name': 'name%s' % (str(i)), 'addr': 'name%s' % (str(i)), 'test_age': i, 'no': i } self.client.put(key, rec)
def setup_class(cls): hostlist, user, password = TestBaseClass.get_hosts() config = { 'hosts': hostlist, 'lua': {'user_path': '/tmp/', 'system_path': '../aerospike-client-c/lua/'}} if user is None and password is None: client = aerospike.client(config).connect() else: client = aerospike.client(config).connect(user, password) TestAggregate.skip_old_server = True versioninfo = client.info('version') for keys in versioninfo: for value in versioninfo[keys]: if value is not None: versionlist = value[ value.find("build") + 6:value.find("\n")].split(".") if int(versionlist[0]) >= 3 and int(versionlist[1]) >= 6: TestAggregate.skip_old_server = False client.index_integer_create('test', 'demo', 'test_age', 'test_demo_test_age_idx') client.index_integer_create( 'test', 'demo', 'age1', 'test_demo_age1_idx') time.sleep(2) filename = "stream_example.lua" udf_type = aerospike.UDF_TYPE_LUA client.udf_put(filename, udf_type) shutil.copyfile(filename, config['lua']['user_path'] + 'stream_example.lua') client.close()
def setup_class(cls): hostlist, user, password = TestBaseClass.get_hosts() config = {'hosts': hostlist} if user is None and password is None: TestApply.client = aerospike.client(config).connect() else: TestApply.client = aerospike.client(config).connect(user, password) TestApply.skip_old_server = True versioninfo = TestApply.client.info('version') for keys in versioninfo: for value in versioninfo[keys]: if value is not None: versionlist = value[ value.find("build") + 6:value.find("\n")].split(".") if int(versionlist[0]) >= 3 and int(versionlist[1]) >= 6: TestApply.skip_old_server = False policy = {} TestApply.client.index_integer_create('test', 'demo', 'age', 'age_index', policy) policy = {} TestApply.client.index_integer_create('test', 'demo', 'age1', 'age_index1', policy) policy = {} filename = "sample.lua" udf_type = 0 TestApply.client.udf_put(filename, udf_type, policy) filename = "test_record_udf.lua" TestApply.client.udf_put(filename, udf_type, policy) filename = "udf_basic_ops.lua" TestApply.client.udf_put(filename, udf_type, policy)
def test_change_password_with_proper_timeout_policy_value(self): user = "******" config = self.connection_config self.clientreaduser = aerospike.client(config).connect(user, "aerospike") policy = {'timeout': 1000} password = "******" status = self.clientreaduser.admin_change_password( user, password, policy) assert status == 0 time.sleep(2) config = self.connection_config with pytest.raises( (aerospike.exception.InvalidPassword, aerospike.exception.InvalidCredential)): self.clientreaduserwrong = aerospike.client( config).connect(user, "aerospike") self.clientreaduserright = aerospike.client(config).connect( user, "newpassword") assert self.clientreaduserright is not None self.clientreaduserright.close() self.clientreaduser.close()
def test_change_password_with_proper_parameters(self): user = "******" config = self.connection_config self.clientreaduser = aerospike.client(config).connect(user, "aerospike") password = "******" status = self.clientreaduser.admin_change_password(user, password) assert status == 0 time.sleep(2) config = self.connection_config # Assert that connecting to the server with the old password fails with pytest.raises( (aerospike.exception.InvalidPassword, aerospike.exception.InvalidCredential)): self.clientreaduserwrong = aerospike.client( config).connect(user, "aerospike") self.clientreaduserright = aerospike.client(config).connect( user, "newpassword") assert self.clientreaduserright is not None self.clientreaduserright.close() self.clientreaduser.close()
def index(): if aerospike.client(config).is_connected()==False: client = aerospike.client(config).connect() voter_id = request.cookies.get('voter_id') if not voter_id: voter_id = hex(random.getrandbits(64))[2:-1] vote = "a" if request.method == 'POST': vote = request.form['vote'] time_ms = long(time.time()*1000) key = ("test", "votes", voter_id) operations = [ { "op" : aerospike.OPERATOR_WRITE, "bin" : "vote", "val" : vote }, { "op" : aerospike.OPERATOR_WRITE, "bin" : "ts", "val" : time_ms }, { "op" : aerospike.OPERATOR_WRITE, "bin" : "voter_id", "val" : voter_id }, { "op" : aerospike.OP_LIST_APPEND, "bin" : "history", "val" : {'vote': vote, 'ts': time_ms} } ] client.operate(key, operations) client.increment(("test", "summary", "total_votes"), "total", 1) client.increment(("test", "summary", host), "total", 1) resp = make_response(render_template( 'index.html', option_a=option_a, option_b=option_b, option_c=option_c, hostname=hostname, node=host, vote=vote, )) resp.set_cookie('voter_id', voter_id) return resp
def setup_class(cls): """ Setup method. """ hostlist, user, password = TestBaseClass.get_hosts() config = {'hosts': hostlist} if user == None and password == None: TestTouch.client = aerospike.client(config).connect() else: TestTouch.client = aerospike.client(config).connect(user, password)
def setup_class(cls): """ Setup class """ hostlist, user, password = TestBaseClass.get_hosts() config = {"hosts": hostlist} if user == None and password == None: TestPut.client = aerospike.client(config).connect() else: TestPut.client = aerospike.client(config).connect(user, password)
def setup_class(cls): """ Setup method. """ hostlist, user, password = TestBaseClass.get_hosts() config = {"hosts": hostlist} if user is None and password is None: TestSelectMany.client = aerospike.client(config).connect() else: TestSelectMany.client = aerospike.client(config).connect(user, password)
def setup_class(cls): """ Setup class. """ TestInfo.hostlist, user, password = TestBaseClass.get_hosts() config = {"hosts": TestInfo.hostlist} TestInfo.config = config if user is None and password is None: TestInfo.client = aerospike.client(config).connect() else: TestInfo.client = aerospike.client(config).connect(user, password)
def setup_class(cls): """ Setup class. """ hostlist, user, password = TestBaseClass.get_hosts() config = {'hosts': hostlist} if user is None and password is None: TestGetNodes.client = aerospike.client(config).connect() else: TestGetNodes.client = aerospike.client(config).connect(user, password)
def test_isconnected_positive(self): """ Invoke is_connected() positive. """ hostlist, user, password = TestBaseClass.get_hosts() config = {"hosts": hostlist} if user is None and password is None: self.client = aerospike.client(config).connect() else: self.client = aerospike.client(config).connect(user, password) assert self.client.is_connected() == True self.client.close()
def setup_class(cls): """ Setup method. """ TestGetMany.hostlist, TestGetMany.user, TestGetMany.password = TestBaseClass.get_hosts() config = {'hosts': TestGetMany.hostlist} if TestGetMany.user is None and TestGetMany.password is None: TestGetMany.client = aerospike.client(config).connect() else: TestGetMany.client = aerospike.client(config).connect( TestGetMany.user, TestGetMany.password)
def test_pos_close(self): """ Invoke close() after positive connect """ config = {'hosts': TestBaseClass.hostlist} if TestClose.user is None and TestClose.password is None: self.client = aerospike.client(config).connect() else: self.client = aerospike.client(config).connect(TestClose.user, TestClose.password) self.closeobject = self.client.close() assert self.closeobject is None
def has_geo_support(): if TestBaseClass.has_geo is not None: return TestBaseClass.has_geo import aerospike hostlist, user, password = TestBaseClass.get_hosts() config = {'hosts': hostlist} if user is None and password is None: client = aerospike.client(config).connect() else: client = aerospike.client(config).connect(user, password) TestBaseClass.has_geo = client.has_geo() client.close() return TestBaseClass.has_geo
def test_connect_positive_with_multiple_hosts(self): """ Invoke connect() with multiple hosts. """ config = {'hosts': TestConnect.hostlist} if TestConnect.user is None and TestConnect.password is None: self.client = aerospike.client(config).connect() else: self.client = aerospike.client(config).connect( TestConnect.user, TestConnect.password) assert self.client is not None self.client.close()
def setup_class(cls): """ Setup class. """ hostlist, user, password = TestBaseClass.get_hosts() config_no_typechecks = {'hosts': hostlist, 'strict_types': False} if user is None and password is None: TestOperateOrdered.client_no_typechecks = aerospike.client( config_no_typechecks).connect() else: TestOperateOrdered.client_no_typechecks = aerospike.client( config_no_typechecks).connect(user, password)
def connect(self): try: self.client = aerospike.client(self.config).connect() except Exception as e: import sys self.logger.error('Failed to connect to the cluster with ' + str(self.config['hosts']) + 'Exception message: ' + str(e))
def test_list_append_with_no_connection(self): client = aerospike.client({'hosts': [('localhost', 3000)]}) k = ('test', 'demo', 'no_con') with pytest.raises(e.ClusterError): client.list_append(k, 'bob', 'item')
def __init__(self, name): config = {'hosts': [('127.0.0.1', 3000)]} client = aerospike.client(config).connect() self.name = name self.client = client self.namespace = 'hdd'
def open_connection(self): if self.client == None: self.client = aerospike.client(self.config).connect()
from flask import Flask, request import os NUM_RECORDS = 10 # Configure the client config = { 'hosts': [('aerocluster', 3000)] # 'hosts': [ ('aerocluster-0-0.aerocluster.aerospike.svc.cluster.local', 3000) ] # 'hosts': [ ('54.144.78.251', 3000) ] } app = Flask(__name__) # Create a client and connect it to the cluster try: client = aerospike.client(config).connect('training', 'aerospike') except: import sys print("failed to connect to the cluster with", config['hosts']) sys.exit(1) @app.route('/', methods=['GET', 'POST']) def hello(): if request.method == 'POST': # Records are addressable via a tuple of (namespace, set, key) try: for i in range(NUM_RECORDS): key = ('test', 'testset', 'key' + str(i)) val = {'name': 'John Doe' + str(i), 'age': 32} client.put(key, val)
config = {'hosts': [(options.host, options.port)]} ################################################################################ # Application ################################################################################ exitCode = 0 try: # ---------------------------------------------------------------------------- # Connect to Cluster # ---------------------------------------------------------------------------- client = aerospike.client(config).connect(options.username, options.password) # ---------------------------------------------------------------------------- # Perform Operation # ---------------------------------------------------------------------------- try: policy = {} user = "******" password = "******" try: client_new = aerospike.client(config).connect(user, "bar") except ClientError: print( "User might not be created or node may be down. In case of non-existent user run create_user.py first"
except exception.IndexNotFound: logging.error("There is no secondary index defined for 'phone_number'") return None if results: return results[0][2].get("ltv") logging.error( "Record with phone_number → {} was not found!".format(phone_number)) logging.info("Testing local Aerospike connectivity") # Configure the client config = {"hosts": [("db", 3000)], "policies": {"timeout": 1000}} # Create a client and connect it to the cluster try: client = client(config).connect() except: logging.error("failed to connect to the cluster with", config["hosts"]) sys.exit(1) logging.info("Local Aerospike works fine") # Configure secondary index for phone_number try: client.index_integer_create("test", "customers", "phone_number", "index_phone") except exception.IndexFoundError: pass logging.info("Starting some local tests")
def test_setting_gen(): gen_val = aerospike.POLICY_GEN_IGNORE write_policy = {'commit_level': gen_val} policies = {'write': write_policy} config = {'hosts': host, 'policies': policies} client = aerospike.client(config)
def test_empty_host_in_config(self): with pytest.raises(e.ParamError) as err: client = aerospike.client({'hosts': []}) assert "Hosts must not be empty" in err.value.msg
def test_setting_conmmit_level(): commit_val = aerospike.POLICY_COMMIT_LEVEL_ALL write_policy = {'commit_level': commit_val} policies = {'write': write_policy} config = {'hosts': host, 'policies': policies} client = aerospike.client(config)
def test_setting_exists(): exists_val = aerospike.POLICY_EXISTS_CREATE write_policy = {'commit_level': exists_val} policies = {'write': write_policy} config = {'hosts': host, 'policies': policies} client = aerospike.client(config)
def test_setting_consistency(): replica_val = aerospike.POLICY_REPLICA_MASTER read_policy = {'replica': replica_val} policies = {'read': read_policy} config = {'hosts': host, 'policies': policies} client = aerospike.client(config)
def test_setting_consistency(): cons_val = aerospike.POLICY_CONSISTENCY_ONE read_policy = {'consistency_level': cons_val} policies = {'read': read_policy} config = {'hosts': host, 'policies': policies} client = aerospike.client(config)
def test_setting_key(): key_val = aerospike.POLICY_KEY_SEND read_policy = {'key': key_val} policies = {'read': read_policy} config = {'hosts': host, 'policies': policies} client = aerospike.client(config)
def start(keep_work_dir=False): """ Starts an asd process with the local aerospike.conf and connects the client to it. """ print "Starting asd" if not keep_work_dir: init_work_dir() init_state_dirs() interceptor = init_interceptor() search_path = [os.sep + os.path.join("usr", "bin")] if "ASREPO" in os.environ: repo = absolute_path(os.environ["ASREPO"]) uname = os.uname() search_path = [ os.path.join(repo, "target", uname[0] + "-" + uname[4], "bin") ] + search_path print "asd search path is", search_path for path in search_path: asd_path = os.path.join(path, "asd") if os.path.exists(asd_path): break else: raise Exception("No asd executable found") if not SHOW_ASD_OUTPUT: dev_null = open(os.devnull, "w") redirect = {"stdout": dev_null, "stderr": subprocess.STDOUT} else: redirect = {} temp_file = absolute_path("aerospike.conf") conf_file = [] conf_file.append(create_conf_file(temp_file, 3000, None, 1)) conf_file.append(create_conf_file(temp_file, 4000, 3000, 2)) os.environ["LD_PRELOAD"] = interceptor for index in xrange(1, 3): command = [asd_path, "--config-file", conf_file[index - 1]] print "Executing", command GLOBALS["asd-" + str(index)] = subprocess.Popen(command, cwd=absolute_path("."), **redirect) del os.environ["LD_PRELOAD"] print "Connecting client" config = {"hosts": [("127.0.0.1", PORT)]} for attempt in xrange(CLIENT_ATTEMPTS): try: GLOBALS["client"] = aerospike.client(config).connect() break except Exception: if attempt < CLIENT_ATTEMPTS - 1: time.sleep(1) else: raise print "Client connected" time.sleep(5) # let the cluster fully form and the client learn about it
def test_wrong_host_type(self): with pytest.raises(e.ParamError) as err: client = aerospike.client({'hosts': (())}) assert "Hosts must be a list" in err.value.msg
def test_invalid_host_in_list(self): with pytest.raises(e.ParamError) as err: client = aerospike.client( {'hosts': [("localhost", 3000), ()]}) assert "Invalid host" in err.value.msg
#!/usr/bin/env python import aerospike as aero config = {'hosts': [('localhost', 3000)]} NUM_ENTRIES = 1000000 MAX_VAL = 12000000 try: client = aero.client(config).connect() except: print "exception connecting to aerospike" import sys sys.exit(1) key = ('test', 'demo', 'foo') try: for i in range(0, NUM_ENTRIES): value = random.randint(0, MAX_VAL) client.put(str(i), {'value': str(value)}) except Exception as e: import sys client.close()
def test_config_not_dict(self): with pytest.raises(e.ParamError) as err: client = aerospike.client([]) assert "Config must be a dict" in err.value.msg
def test_is_connected_before_connect(self): """ Test that is_connected returns false before a connection is established """ client = aerospike.client(self.config) assert client.is_connected() is False
def test_setting_wrong_type(): write_policy = {'commit_level': [1, 2, 3]} policies = {'write': write_policy} config = {'hosts': host, 'policies': policies} with pytest.raises(e.ParamError): client = aerospike.client(config)
def get_aerospike_data(): # Connect to aerospike try: client = aerospike.client(config).connect() print("Connected to aerospike host:", config['hosts']) except: print("Failed to connect to the cluster with", config['hosts']) sys.exit(1) now = datetime.now() time = {} time[0] = now.replace(hour=20, minute=0, second=0, microsecond=0) - timedelta(days=1) time[1] = now.replace(hour=8, minute=0, second=0, microsecond=0) time[2] = now.replace(hour=13, minute=0, second=0, microsecond=0) time[3] = now.replace(hour=20, minute=0, second=0, microsecond=0) time[4] = now.replace(hour=8, minute=0, second=0, microsecond=0) + timedelta(days=1) conn = PostgresHook(postgres_conn_id='pgConn_pg').get_conn() cur = conn.cursor() cur.execute("delete from dar_group.darbazar_m_store;") client = aerospike.client(config).connect() query = client.query('merchants', 'store') records = query.results() client.close() b = len(records) for x in range(0, b): if 'schedule' in records[x][2]: ida1 = records[x][2]['merchant_id'] if 'merchant_id' in records[x][ 2] else None ida6 = records[x][2]['brand_name'] if 'brand_name' in records[x][ 2] else None if 'address' in records[x][2]: ida7 = records[x][2]['address'][ 'street_num'] if 'street_num' in records[x][2][ 'address'] else None ida8 = records[x][2]['address'][ 'street'] if 'street' in records[x][2]['address'] else None ida9 = records[x][2]['address'][ 'region_id'] if 'region_id' in records[x][2][ 'address'] else None ida10 = records[x][2]['address'][ 'apt_num'] if 'apt_num' in records[x][2][ 'address'] else None else: None d = json.dumps(records[x][2]['schedule']) o = json.loads(d) if d != '""': y = json.loads(o) for t in range(0, 7): ida2 = y[t]['day'] if 'day' in y[t] else None ida3 = y[t]['isOpen'] if 'isOpen' in y[t] else None ida4 = y[t]['openTime'] if 'openTime' in y[t] else None ida5 = y[t]['closeTime'] if 'closeTime' in y[t] else None cur.execute( "INSERT INTO dar_group.darbazar_m_store(merchant_id,day,isopen,opentime,closetime,brand_name,street_num, \ street,region_id,apt_num) \ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", (ida1, ida2, ida3, ida4, ida5, ida6, ida7, ida8, ida9, ida10)) else: continue else: continue cur.close() conn.close()
def test_no_host_in_config(self): with pytest.raises(e.ParamError) as err: client = aerospike.client({}) assert "Hosts must be a list" in err.value.msg
def read_aerospike(): try: client = aerospike.client(config).connect() print("Connected to aerospike host:", config['hosts']) except: print("Failed to connect to the cluster with", config['hosts']) sys.exit(1) now = datetime.now() time = {} time[0] = now.replace(hour=20, minute=0, second=0, microsecond=0) - timedelta(days=1) time[1] = now.replace(hour=8, minute=0, second=0, microsecond=0) time[2] = now.replace(hour=13, minute=0, second=0, microsecond=0) time[3] = now.replace(hour=20, minute=0, second=0, microsecond=0) time[4] = now.replace(hour=8, minute=0, second=0, microsecond=0) + timedelta(days=1) conn = PostgresHook(postgres_conn_id='pgConn_pg').get_conn() cur = conn.cursor() client = aerospike.client(config).connect() query = client.query('merchants', 'merchant') query.select('id', 'telephone', 'email', 'brand', 'old_id_code', 'merchant_id', 'state', 'merchant_type', 'code', 'description', 'legal_name', 'logal_token', 'surl', 'smap', 'avatar_token', 'banner_token', 'contacts', 'created_date', 'updated_date', 'biz_categories', 'address', 'kassa_types', 'website') records = query.results() client.close() b = len(records) cur.execute("delete from dar_group.darbazar_merchants") conn.commit() for x in range(0, b): id = records[x][2]['id'] id1 = records[x][2]['telephone'] if 'telephone' in records[x][ 2] else None id2 = records[x][2]['email'] if 'email' in records[x][2] else None id3 = records[x][2]['brand'] if 'brand' in records[x][2] else None id4 = records[x][2]['old_id_code'] if 'old_id_code' in records[x][ 2] else None id5 = records[x][2]['merchant_id'] if 'merchant_id' in records[x][ 2] else None id6 = records[x][2]['state'] if 'state' in records[x][2] else None ida7 = records[x][2]['merchant_type'] if 'merchant_type' in records[x][ 2] else None id7 = records[x][2]['code'] if 'code' in records[x][2] else None id8 = records[x][2]['description'] if 'description' in records[x][ 2] else None id9 = records[x][2]['legal_name'] if 'legal_name' in records[x][ 2] else None id10 = records[x][2]['logo_token'] if 'logo_token' in records[x][ 2] else None id11 = records[x][2]['surl'] if 'surl' in records[x][2] else None id12 = records[x][2]['smap'] if 'smap' in records[x][2] else None id13 = records[x][2]['avatar_token'] if 'avatar_token' in records[x][ 2] else None id14 = records[x][2]['banner_token'] if 'banner_token' in records[x][ 2] else None id15 = records[x][2]['contacts'] if 'contacts' in records[x][ 2] else None ids1 = records[x][2]['created_date'] if 'created_date' in records[x][ 2] else 0 id16 = datetime.fromtimestamp(int(ids1) / 1000).strftime('%Y-%m-%d %H:%M:%S') ids2 = records[x][2]['updated_date'] if 'updated_date' in records[x][ 2] else 0 id17 = datetime.fromtimestamp(int(ids2) / 1000).strftime('%Y-%m-%d %H:%M:%S') id18 = records[x][2]['biz_categories'] if 'biz_categories' in records[ x][2] else None id19 = records[x][2]['address'] if 'address' in records[x][2] else None id20 = records[x][2]['kassa_types'] if 'kassa_types' in records[x][ 2] else None id21 = records[x][2]['website'] if 'website' in records[x][2] else None cur.execute ("INSERT INTO dar_group.darbazar_merchants(id,telephone,email,brand,old_id_code,merchant_id,state, merchant_type, \ code,description,legal_name,logo_token,surl,smap,avatar_token,banner_token,contacts,created_date, \ updated_date,biz_categories,address,kassa_types,website) \ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" , \ (id,id1,id2,id3,id4,id5,id6,ida7,id7,id8,id9,id10,id11,id12,id13,id14,id15,id16,id17,id18,id19,id20,id21)) conn.commit() cur.close() conn.close()
def test_no_config(self): with pytest.raises(e.ParamError) as err: client = aerospike.client() assert "No config argument" in err.value.msg
password = a if user != None: if password == None: password = getpass.getpass("Enter Password:"******"failed to connect to the cluster with", config['hosts']) sys.exit(STATE_UNKNOWN) r = client.info_node(arg_value,(arg_host,arg_port)) client.close() #pprint.pprint(r) if arg_stat != None and arg_stat not in r: print "%s is not a known statistic." %arg_stat sys.exit(STATE_UNKNOWN) if r == -1: print "request to ",arg_host,":",arg_port," returned error." sys.exit(STATE_CRITICAL)
config = {'hosts': [(options.host, options.port)]} ########################################################################## # Application ########################################################################## exitCode = 0 try: # ---------------------------------------------------------------------------- # Connect to Cluster # ---------------------------------------------------------------------------- client = aerospike.client(config).connect(options.username, options.password) # ---------------------------------------------------------------------------- # Perform Operation # ---------------------------------------------------------------------------- try: policy = {} namespace = options.namespace index_name = args.pop() client.index_remove(namespace, index_name, policy) print("OK, 1 Integer Secondary Index Removed ") except Exception as e:
def __init__(self): self.config = {'hosts': [('127.0.0.1', 3000)]} self.client = aerospike.client(self.config).connect()
return Table.SetDebugMode(False) Table.GetDebugMode() # ***Open communication with the database*** if _DB_mode == "AS": # Specify the IP addresses and ports for the Aerospike cluster config = {'hosts': [('18.222.211.167', 3000), ('3.16.180.184', 3000)]} # Create a client and connect it to the cluster print("RunActualDB is", RunActualDB) print("Benchmarking with AeroSpike, Schema 3") database = "test_DB_SEF" try: client = aerospike.client(config).connect() #Be sure to tell the Table class the name of the client it's talking to Table.SetTableClient(client) except: print("failed to connect to the cluster with", config['hosts']) sys.exit(1) if _DB_mode == "SQL": client = mysql.connector.connect(host="3.16.81.134", user="******", passwd="DrBajaj2*", database="test_DB_SQL") database = "test_DB_SQL" '''-Args for local SQL database host="127.0.0.1", user="******", database="test_DB_SQL"
for w in words: (key, meta) = client.exists(('test', cls, w)) if meta != 'None': client.increment(('test', cls, w), 'qty', 1) else: client.put(('test', cls, w), {'qty': 1}) # Open dataset table df = pd.read_excel(open('ks.xlsx', 'rb')) classes = df.columns mystem = Mystem() # Connect to aerospike db config = {'hosts': [('127.0.0.1', 3000)], 'policies': {'timeout': 1000}} client = aerospike.client(config) client.connect() # Start learning for cls in classes: for row in df.index: cell = df.at[row, cls] if not isinstance(cell, int) and not isinstance( cell, np.int64) and not isinstance(cell, float) and not isinstance( cell, Timestamp) and not isinstance( cell, datetime.time) and not isinstance(cell, long): cell = cell.encode('utf-8') words = word_process(cell) count_freq(words, cls) elif isinstance(cell, Timestamp) or isinstance(cell, datetime.time):