当前位置: 首页>>代码示例>>Python>>正文


Python RestConnection.query_tool方法代码示例

本文整理汇总了Python中membase.api.rest_client.RestConnection.query_tool方法的典型用法代码示例。如果您正苦于以下问题:Python RestConnection.query_tool方法的具体用法?Python RestConnection.query_tool怎么用?Python RestConnection.query_tool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在membase.api.rest_client.RestConnection的用法示例。


在下文中一共展示了RestConnection.query_tool方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_cbq_query

# 需要导入模块: from membase.api.rest_client import RestConnection [as 别名]
# 或者: from membase.api.rest_client.RestConnection import query_tool [as 别名]
    def run_cbq_query(self, query=None, min_output_size=10, server=None):
        if query is None:
            query = self.query
        if server is None:
           server = self.master
           if server.ip == "127.0.0.1":
            self.n1ql_port = server.n1ql_port
        else:
            if server.ip == "127.0.0.1":
                self.n1ql_port = server.n1ql_port
            if self.input.tuq_client and "client" in self.input.tuq_client:
                server = self.tuq_client
        query_params = {}
        cred_params = {'creds': []}
        rest = RestConnection(server)
        username = rest.username
        password = rest.password
        cred_params['creds'].append({'user': username, 'pass': password})
        for bucket in self.buckets:
            if bucket.saslPassword:
                cred_params['creds'].append({'user': 'local:%s' % bucket.name, 'pass': bucket.saslPassword})
        query_params.update(cred_params)
        if self.use_rest:
            query_params.update({'scan_consistency': self.scan_consistency})
            self.log.info('RUN QUERY %s' % query)

            if self.analytics:
                query = query + ";"
                for bucket in self.buckets:
                    query = query.replace(bucket.name,bucket.name+"_shadow")
                result = RestConnection(self.cbas_node).execute_statement_on_cbas(query, "immediate")
                result = json.loads(result)

            else :
                result = rest.query_tool(query, self.n1ql_port, query_params=query_params)


        else:
            if self.version == "git_repo":
                output = self.shell.execute_commands_inside("$GOPATH/src/github.com/couchbase/query/" +\
                                                            "shell/cbq/cbq ","","","","","","")
            else:
                os = self.shell.extract_remote_info().type.lower()
                if not(self.isprepared):
                    query = query.replace('"', '\\"')
                    query = query.replace('`', '\\`')

                cmd =  "%s/cbq  -engine=http://%s:%s/ -q -u %s -p %s" % (self.path, server.ip, server.port, username, password)

                output = self.shell.execute_commands_inside(cmd,query,"","","","","")
                if not(output[0] == '{'):
                    output1 = '{'+str(output)
                else:
                    output1 = output
                result = json.loads(output1)
        if isinstance(result, str) or 'errors' in result:
            raise CBQError(result, server.ip)
        self.log.info("TOTAL ELAPSED TIME: %s" % result["metrics"]["elapsedTime"])
        return result
开发者ID:arod1987,项目名称:testrunner,代码行数:61,代码来源:newtuq.py

示例2: QueryWorkbenchTests

# 需要导入模块: from membase.api.rest_client import RestConnection [as 别名]
# 或者: from membase.api.rest_client.RestConnection import query_tool [as 别名]
class QueryWorkbenchTests(BaseTestCase):
    n1ql_port =8093
    _input = TestInputSingleton.input
    num_items = _input.param("items", 100)
    _value_size = _input.param("value_size", 256)
    gen_create = BlobGenerator('loadOne', 'loadOne',_value_size, end=num_items)
    #bucket and ram quota
    buckets_ram = {
        "CUSTOMER": 100,
        "DISTRICT": 100,
        "HISTORY": 100,
        "ITEM": 100,
        "NEW_ORDER": 100,
        "ORDERS": 100,
        "ORDER_LINE": 100,
        #"default:": 100
        }

    def setUp(self):
        super(QueryWorkbenchTests, self).setUp()
        server = self.master
        if self.input.tuq_client and "client" in self.input.tuq_client:
            server = self.tuq_client
        self.rest = RestConnection(server)
        #self.rest.delete_bucket("default")
        time.sleep(20)
        # drop and recreate buckets
        for i, bucket_name in enumerate(self.buckets_ram.keys()):
            self.rest.create_bucket(bucket=bucket_name,
                                   ramQuotaMB=int(self.buckets_ram[bucket_name]),
                                   replicaNumber=0,
                                   proxyPort=11218+i)
            print self.servers[0]
            #bucket = self.src_cluster.get_bucket_by_name(bucket_name)
        time.sleep(20)
        #self.rest.create_bucket(bucket="default",
                                   #ramQuotaMB=int(self.buckets_ram["default"]),
                                   #replicaNumber=0,
                                   #proxyPort=11218)
        self._load_all_buckets(self,self.servers[0], self.gen_create, "create", 0)
        #time.sleep(20)





    def tearDown(self):
        super(QueryWorkbenchTests, self).tearDown()



    def test_describe(self):
        for bucket_name in self.rest.get_buckets():
            query = "infer %s" % bucket_name
            print query
            result = self.rest.query_tool(query, self.n1ql_port)
            print result
开发者ID:EricACooper,项目名称:testrunner,代码行数:59,代码来源:tuq_queryworkbench.py

示例3: QueryWorkbenchTests

# 需要导入模块: from membase.api.rest_client import RestConnection [as 别名]
# 或者: from membase.api.rest_client.RestConnection import query_tool [as 别名]
class QueryWorkbenchTests(BaseUITestCase):
    """
    For the first node the following services should be turn on: kv,n1ql,index
    """
    def setUp(self):
        super(QueryWorkbenchTests, self).setUp()
        self.bucketname = 'beer'
        self.baseHelper = BaseHelper(self)
        self.queryHelper = QueryWorkbenchHelper(self)
        self.baseHelper.login()
        self.baseHelper.loadSampleBucket(self.servers[0], self.bucketname)
        self.rest = RestConnection(self.servers[0])
        self.rest.set_indexer_storage_mode()
        self.rest.query_tool("DROP INDEX `beer`.`beer_index_sec` USING GSI;")

    def tearDown(self):
        super(QueryWorkbenchTests, self).tearDown()

    def test_create_indexes(self):
        expected_results = self.input.param('expected_result', None)
        if expected_results is not None:
            # 4.7 vs 4.6 versions
            expected_results = expected_results.replace('_STAR_', '*').replace('_SEM_', ';').decode('unicode_escape').split('|')
        summary_result = self.input.param('summary_result', '')
        summary_result = summary_result.replace('_STAR_', '*').replace('_SEM_', ';').decode('unicode_escape')
        result_mode = self.input.param('mode', 'JSON')
        if self.rest.get_nodes()[0].version <= '4.7' and result_mode in ['Plan Text', 'Plan']:
            self.log.info("skip 'Plan Text', 'Plan' modes in version < 4.7")
            return
        init_query = self.input.param('init_query', '').replace('_STAR_', '*').replace('_SEM_', ';').decode('unicode_escape')
        check_query = self.input.param('check_query', '').replace('_STAR_', '*').replace('_SEM_', ';').decode('unicode_escape')

        # go to query workbench page
        NavigationHelper(self).navigate('Query')

        if init_query:
            self.queryHelper.execute_query(init_query)
            self.queryHelper.controls.query_top_screen().view_next.click()
            next_text = '{"no_data_yet": "hit execute to run query"}'
            self.assertEqual(next_text, self.queryHelper.controls.query_results_box().result_json_mode.get_text())
        self.queryHelper.execute_query(check_query)

        if expected_results is not None:
            self.queryHelper.check_result(expected_results, mode=result_mode)
        if summary_result:
            self.queryHelper.check_summary_result(summary_result, mode=result_mode)
        if init_query:
            self.queryHelper.controls.query_top_screen().view_previous.click()
            self.assertEqual(init_query, self.queryHelper.controls.query_top_screen().query_editor_value.get_text())

    def test_bucket_analysis(self):
        init_analysis = self.input.param('init_analysis', None)
        expected_analysis = self.input.param('expected_analysis', None)
        init_analysis = init_analysis.replace('_STAR_', '*').replace('_SEM_', ';').decode(
            'unicode_escape').split('|')  # 4.7 vs 4.6
        expected_analysis = expected_analysis.replace('_STAR_', '*').replace('_SEM_', ';').decode(
            'unicode_escape')
        check_query = self.input.param('check_query', '').replace('_STAR_', '*').replace('_SEM_', ';').decode(
            'unicode_escape')

        NavigationHelper(self).navigate('Query')
        self.queryHelper.check_bucket_analysis_result(init_analysis)
        self.queryHelper.execute_query(check_query)
        self.queryHelper.controls.query_bucket_analysis().refresh_button.click(highlight=False)
        time.sleep(6)
        self.queryHelper.check_bucket_analysis_result(expected_analysis)

    def test_save_query(self):
        path = self.input.param('path', "n1ql_query.txt")
        check_query = self.input.param('check_query', '').replace('_STAR_', '*').replace('_SEM_', ';').decode(
            'unicode_escape')
        home = expanduser("~")
        home += "\Downloads"
        saved_file = "%s\%s" % (home, path)
        try:
            if path:
                os.remove(saved_file)
            else:
                os.remove("%s\download.txt" % home)
        except OSError:
            pass
        NavigationHelper(self).navigate('Query')
        self.queryHelper.execute_query(check_query)
        self.queryHelper.save_query(path)
        if not path:
            saved_file = "%s\download.txt" % home
        f = open(saved_file, 'r')
        content = f.read()
        self.assertEqual(content, check_query, msg='Incorrect saved query file: %s' % content)

    def test_save_result(self):
        path = self.input.param('path', "data.json")
        check_query = self.input.param('check_query', '').replace('_STAR_', '*').replace('_SEM_', ';').decode(
            'unicode_escape')
        expected_result = self.input.param('expected_result', '{"no_data_yet": "hit execute to run query"}')
        expected_result = expected_result.replace('_STAR_', '*').replace('_SEM_', ';').decode('unicode_escape')
        home = expanduser("~")
        home += "\Downloads"
        saved_file = "%s\%s" % (home, path)
        try:
#.........这里部分代码省略.........
开发者ID:arod1987,项目名称:testrunner,代码行数:103,代码来源:uiqueryworkbench.py

示例4: WAREHOUSE

# 需要导入模块: from membase.api.rest_client import RestConnection [as 别名]
# 或者: from membase.api.rest_client.RestConnection import query_tool [as 别名]
                  "create index WH_ID on WAREHOUSE(W_ID) using gsi WITH {\"defer_build\":true}",
                  "build index on WAREHOUSE(WH_ID) using gsi",
                  "select keyspace_id, state from system:indexes",
                  "select keyspace_id, state from system:indexes where state != 'online'"
                 ]

    server_info = {
        "ip": cfg.CLUSTER_IPS[0],
        "port" : 8091,
        "username" : cfg.COUCHBASE_USER,
        "password" : cfg.COUCHBASE_PWD
    }
    #node = type('OBJ', (object,), server_info)
    #print node
    cluster_rest = RestConnection(server_info)

    # drop and recreate buckets
    for i, bucket_name in enumerate(buckets_ram.keys()):
        print "Creating bucket {0}".format(bucket_name)
        cluster_rest.delete_bucket(bucket_name)
        cluster_rest.create_bucket(bucket=bucket_name,
                                   ramQuotaMB=int(buckets_ram[bucket_name]),
                                   proxyPort=port+i)
    time.sleep(60)

    # index drop/create
    for query in index_n1ql:
        print query
        result = cluster_rest.query_tool(query)
        print result
开发者ID:EricACooper,项目名称:testrunner,代码行数:32,代码来源:create_buckets_indexes.py


注:本文中的membase.api.rest_client.RestConnection.query_tool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。