Ejemplo n.º 1
0
    def test_engine(self):
        context = init_context(APP, servers=SERVERS)
        engine = ElasticsearchEngine.init_by_context(context)
        assert engine
        assert engine.hosts

        r = engine.put_template('mcluster_satus', TEMPLATE)
        assert r.get('acknowledged')
        r = engine.exists_template('mcluster_satus')
        assert r

        doc = {
            'author': 'kimchy',
            'text': 'Elasticsearch: cool. bonsai cool.',
            'timestamp': datetime.now()
        }

        result = engine.add("test", "tweet", doc)
        self.assertEqual(True, result.get('created'))

        result = engine.add("test", "facebook", doc)
        self.assertEqual(True, result.get('created'))

        result = engine.add("tessss", "tweet", doc)
        self.assertEqual(True, result.get('created'))
Ejemplo n.º 2
0
def _get_es():
    if not getattr(_get_es, '_es', None):
        from mimas.es.context import init_context
        from mimas.es import ElasticsearchEngine
        context = init_context('mcluster', ES_MONITOR_HOSTS)
        es = ElasticsearchEngine.init_by_context(context)
        _get_es._es = es
    return _get_es._es
Ejemplo n.º 3
0
 def test_stats(self):
     context = init_context(APP, servers=SERVERS)
     engine = ElasticsearchEngine.init_by_context(context)
     result = engine.get_stats()
     HEALTH_KEYS = [
         u'cluster_name', u'timestamp', u'nodes', u'status', u'indices'
     ]
     self.assertEqual(HEALTH_KEYS, result.keys())
Ejemplo n.º 4
0
def _get_es():
    if not getattr(_get_es, '_es', None):
        from mimas.es.context import init_context
        from mimas.es import ElasticsearchEngine
        context = init_context(APP, SERVERS)
        es = ElasticsearchEngine.init_by_context(context)
        _get_es._es = es
    return _get_es._es
Ejemplo n.º 5
0
def _get_local_es():
    es_opers = ElasticsearchOpers()
    node_info = es_opers.config_op.getValue(options.data_node_property,
                                            ['dataNodeIp', 'dataNodeName'])
    node_ip = node_info.get('dataNodeIp')
    es_localhost = "{node_ip}:{es_port}".format(node_ip=node_ip,
                                                es_port=ES_PORT)
    if not getattr(_get_local_es, '_es', None):
        from mimas.es.context import init_context
        from mimas.es import ElasticsearchEngine
        context = init_context('logs', es_localhost)
        es = ElasticsearchEngine.init_by_context(context)
        _get_local_es._es = es
    return _get_local_es._es
Ejemplo n.º 6
0
 def test_health(self):
     context = init_context(APP, servers=SERVERS)
     engine = ElasticsearchEngine.init_by_context(context)
     result = engine.get_health()
     HEALTH_KEYS = [
         u'status', u'number_of_nodes', u'unassigned_shards',
         u'number_of_pending_tasks', u'number_of_in_flight_fetch',
         u'timed_out', u'active_primary_shards',
         u'task_max_waiting_in_queue_millis', u'cluster_name',
         u'relocating_shards', u'active_shards_percent_as_number',
         u'active_shards', u'initializing_shards', u'number_of_data_nodes',
         u'delayed_unassigned_shards'
     ]
     self.assertEqual(HEALTH_KEYS, result.keys())
Ejemplo n.º 7
0
 def test_context(self):
     context = init_context(APP, servers=SERVERS)
     assert context
     assert context.config.get("APP")
     assert context.config.get("ELASTICSEARCH_SERVERS")
Ejemplo n.º 8
0
def put_template(template_name, template):
    context = init_context('mcluster', servers=options.es_hosts)
    es = ElasticsearchEngine.init_by_context(context)
    r = es.put_template(template_name, template)
    return r.get('acknowledged')