def create_index(self,
                     name='',
                     description='',
                     content_type='',
                     options=None,
                     datastore_name='',
                     view_name=''):

        res, _ = self.clients.resource_registry.find_resources(name=name)
        if len(res) > 0:
            raise BadRequest('Resource with name %s already exists.' % name)

        if content_type == IndexManagementService.ELASTICSEARCH_INDEX:
            index = ElasticSearchIndex(name=name, description=description)
            index.content_type = IndexManagementService.ELASTICSEARCH_INDEX
            index.index_name = name
            if options:
                index.options = options
            index_id, _ = self.clients.resource_registry.create(index)
            return index_id

        elif content_type == IndexManagementService.COUCHDB_INDEX:
            index = CouchDBIndex(name=name, description=description)
            index.datastore_name = datastore_name
            index.view_name = view_name
            index.content_type = IndexManagementService.COUCHDB_INDEX
            if options:
                index.options = options
            index_id, _ = self.clients.resource_registry.create(index)
            return index_id

        else:
            raise BadRequest('Unknown content_type or not specified')
    def create_index(self, name='', description='', content_type='', options=None, datastore_name='', view_name=''):
        
        res, _ = self.clients.resource_registry.find_resources(name=name)
        if len(res)>0:
            raise BadRequest('Resource with name %s already exists.' % name)

        if content_type == IndexManagementService.ELASTICSEARCH_INDEX:
            index = ElasticSearchIndex(name=name, description=description)
            index.content_type=IndexManagementService.ELASTICSEARCH_INDEX
            index.index_name = name 
            if options:
                index.options = options
            index_id, _ = self.clients.resource_registry.create(index)
            return index_id


        elif content_type == IndexManagementService.COUCHDB_INDEX:
            index = CouchDBIndex(name=name, description=description)
            index.datastore_name = datastore_name
            index.view_name = view_name
            index.content_type=IndexManagementService.COUCHDB_INDEX
            if options:
                index.options = options
            index_id, _ = self.clients.resource_registry.create(index)
            return index_id

        else:
            raise BadRequest('Unknown content_type or not specified')
    def create_index(self, name="", description="", content_type="", options=None, datastore_name="", view_name=""):

        res, _ = self.clients.resource_registry.find_resources(name=name)
        if len(res) > 0:
            raise BadRequest("Resource with name %s already exists." % name)

        if content_type == IndexManagementService.DATASTORE_INDEX:
            index = ElasticSearchIndex(name=name, description=description)
            index.content_type = IndexManagementService.DATASTORE_INDEX
            index.index_name = name
            if options:
                index.options = options
            index_id, _ = self.clients.resource_registry.create(index)
            return index_id

        else:
            raise BadRequest("Unknown content_type or not specified")
Ejemplo n.º 4
0
    def test_query_index(self, es_mock):
        mock_index = ElasticSearchIndex(content_type=IndexManagementService.ELASTICSEARCH_INDEX)
        self.rr_read.return_value = mock_index
        self.discovery.elasticsearch_host = 'fakehost'
        self.discovery.elasticsearch_port = 'fakeport'
        es_mock().search_index_advanced.return_value = {'hits':{'hits':[{'_id':'success'}]}}

        retval = self.discovery.query_term('mock_index', 'field', 'value', order={'name':'asc'}, limit=20, offset=20)

        self.assertTrue(retval[0]['_id']=='success', '%s' % retval)
Ejemplo n.º 5
0
    def test_query_geo_bbox(self, mock_es):
        self.rr_read.return_value = ElasticSearchIndex(name='test')
        self.discovery.elasticsearch_host = ''
        self.discovery.elasticsearch_port = ''
        self.discovery._multi = Mock()
        self.discovery._multi.return_value = None
        response = {'ok':True, 'status':200, 'hits':{'hits':['hi']}}
        mock_es().search_index_advanced.return_value = response

        retval = self.discovery.query_geo_bbox('abc123', 'blah', [0,10], [10,0])

        self.assertTrue(retval == ['hi'])
Ejemplo n.º 6
0
    def test_query_range(self, mock_es):
        mock_index = ElasticSearchIndex(name='index', index_name='index')
        self.discovery.elasticsearch_host = 'fakehost'
        self.discovery.elasticsearch_port = 'fakeport'
        self.rr_read.return_value = mock_index
        hits = [{'_id':'a'},{'_id':'b'}]
        mock_es().search_index_advanced.return_value = {'hits':{'hits':hits}}

        retval = self.discovery.query_range('index_id','field',0,100,id_only=False)

        mock_es().search_index_advanced.assert_called_once_with('index',ep.ElasticQuery().range(field='field', from_value=0, to_value=100))
        retval.sort()
        self.assertTrue(retval==hits, '%s' % retval)
        
        retval = self.discovery.query_range('index_id','field',0,100,id_only=True)
        retval.sort()
        self.assertTrue(retval==['a','b'])