def test_force_allocation_of_shards_with_failed_node(self):
     """Test that shard allocation command was called twice after it fails on the first node."""
     self.elasticsearch1.nodes.info = mock.Mock(
         return_value={
             "nodes": {
                 "ELASTIC1": {
                     "name": "el1-alpha"
                 },
                 "ELASTIC3": {
                     "name": "el2-alpha"
                 },
             }
         })
     self.elasticsearch2.nodes.info = mock.Mock(
         return_value={
             "nodes": {
                 "ELASTIC7": {
                     "name": "el1-beta"
                 },
                 "ELASTIC4": {
                     "name": "el2-beta"
                 },
             }
         })
     self.elasticsearch1.cat.shards = mock.Mock(return_value=[
         {
             "index": "index1",
             "shard": 2,
             "state": "UNASSIGNED"
         },
         {
             "index": "index2",
             "shard": 4,
             "state": "ASSIGNED"
         },
     ])
     self.elasticsearch2.cat.shards = mock.Mock(return_value=[
         {
             "index": "index3",
             "shard": 6,
             "state": "ASSIGNED"
         },
         {
             "index": "index4",
             "shard": 7,
             "state": "UNASSIGNED"
         },
     ])
     self.elasticsearch1.cluster.reroute = mock.Mock(
         side_effect=RequestError("test"))
     self.elasticsearch2.cluster.reroute = mock.Mock(
         side_effect=RequestError("test"))
     elasticsearch_clusters = self.default_elasticsearch_clusters()
     elasticsearch_clusters.force_allocation_of_all_unassigned_shards()
     assert self.elasticsearch1.cluster.reroute.call_count == 2
     assert self.elasticsearch2.cluster.reroute.call_count == 2
Ejemplo n.º 2
0
 def test_expect_500_if_bad_elastic_query(self):
     self.es_client.msearch = Mock(side_effect=RequestError('kaboom', 'error', {}))
     min_date = MOCK_FAKE_NOW - timedelta(days=1)
     response = self.client.get('/api/v1/histogram', {
         'min_date': min_date.isoformat()
     })
     self.assertEquals(response.status_code, 500)
Ejemplo n.º 3
0
 def update(self, document):
     """ Update by id
     :param document:
     """
     # Me lo pediste vos nacho, despues no me putees
     # te tengo que putear, seas quien seas
     #return True
     try:
         return self.es.update(index=settings.SEARCH_INDEX['index'], id=document['docid'], doc_type=document['type'], body=document)
     except RequestError,e:
         raise RequestError(e)
Ejemplo n.º 4
0
    def search(self, doc_type, query, fields="*" ):
        """Search by query
        :param doc_type:
        :param query:
        :param fields:
        """

        try:
            return self.es.search(index=settings.SEARCH_INDEX['index'], doc_type=doc_type, body=query, _source_include=fields)
        except RequestError,e:
            raise RequestError(e)
Ejemplo n.º 5
0
def acknowledge_result(results):
    """
    Interpret a result from an ElasticSearch API call and display it.
        result          Dictionary object from ElasticSearch API

    Returns
        error_status    Boolean value indicating if result was an error or not.
    """

    error_status = True

    if results and results.get('acknowledged'):
        print "acknowledged: %s" % results['acknowledged']
        error_status = False
    elif results and results.get('error'):
        print "error: %s" % results['error']
    elif not results:
        raise RequestError("An unknown error occurred in your request.")
    else:
        print json.dumps(results, sort_keys=True, indent=4, separators=(',',': '))

    return error_status
Ejemplo n.º 6
0
def es_invalid_search(*args, **kwargs):
    raise RequestError("invalid query")
Ejemplo n.º 7
0
 def __len__(self):
     raise RequestError(400, "dummy parsing failure", {})