Esempio n. 1
0
 def setUp(self):
     super(SolrCoreAdminTestCase, self).setUp()
     self.solr_admin = SolrCoreAdmin(
         'http://localhost:8983/solr/admin/cores')
Esempio n. 2
0
def main():
    options, remainder = getopt.gnu_getopt(sys.argv[1:], 'hmdtra', [
        'help', 'migrate', 'dump', 'test', 'resume', 'async', 'solrhost=',
        'eshost=', 'redishost=', 'index=', 'core=', 'solrfq=', 'solrid=',
        'postgresqldsn=', 'translationmap=', 'esmapping=', 'essetting='
    ])
    if len(sys.argv) == 1:
        usage(sys.argv)
        sys.exit()

    aioloop = asyncio.get_event_loop()
    with_asyncio = False
    solrhost = 'solr'
    solrfq = '*'
    solrid = DEFAULT_ID_FIELD
    eshost = 'elasticsearch'
    redishost = 'redis'
    postgresqldsn = None
    core_name = 'solr2es'
    index_name = None
    action = 'migrate'
    translationmap = None
    esmapping = None
    essetting = None
    for opt, arg in options:
        if opt in ('-h', '--help'):
            usage(sys.argv)
            sys.exit()

        if opt in ('-a', '--async'):
            with_asyncio = True

        if opt == '--solrhost':
            solrhost = arg

        if opt == '--solrfq':
            solrfq = arg

        if opt == '--solrid':
            solrid = arg

        if opt == '--redishost':
            redishost = arg

        if opt == '--postgresqldsn':
            postgresqldsn = arg

        if opt == '--eshost':
            eshost = arg

        if opt == '--index':
            index_name = arg

        if opt == '--core':
            core_name = arg

        if opt == '--translationmap':
            translationmap = TranslationMap(_get_dict_from_string_or_file(arg))

        if opt == '--esmapping':
            esmapping = _get_dict_from_string_or_file(arg)

        if opt == '--essetting':
            essetting = _get_dict_from_string_or_file(arg)

        if opt in ('-d', '--dump'):
            action = 'dump' if postgresqldsn is None else 'dump_pgsql'
        elif opt in ('-r', '--resume'):
            action = 'resume' if postgresqldsn is None else 'resume_pgsql'
        elif opt in ('-m', '--migrate'):
            action = 'migrate'
        elif opt in ('-t', '--test'):
            action = 'test'

    if index_name is None:
        index_name = core_name

    solrurl = 'http://%s:8983/solr/%s' % (solrhost, core_name)
    es_index_body = _get_es_mappings_and_settings(essetting, esmapping)

    if action == 'migrate':
        aioloop.run_until_complete(aiomigrate(solrurl, eshost, index_name, solrfq, solrid)) if with_asyncio \
            else migrate(solrurl, eshost, index_name, solrfq, solrid)
    elif action == 'dump':
        aioloop.run_until_complete(aiodump_into_redis(solrurl, redishost, solrfq, solrid)) if with_asyncio \
            else dump_into_redis(solrurl, redishost, solrfq, solrid)
    elif action == 'resume':
        aioloop.run_until_complete(
            aioresume_from_redis(
                redishost, eshost,
                index_name)) if with_asyncio else resume_from_redis(
                    redishost, eshost, index_name)
    elif action == 'dump_pgsql':
        aioloop.run_until_complete(aiodump_into_pgsql(solrurl, postgresqldsn, solrfq, solrid)) if with_asyncio \
            else dump_into_pgsql(solrurl, postgresqldsn, solrfq, solrid)
    elif action == 'resume_pgsql':
        aioloop.run_until_complete(
            aioresume_from_pgsql(postgresqldsn, eshost, index_name, translationmap, es_index_body)) if with_asyncio \
            else resume_from_postgresql(postgresqldsn, eshost, index_name, translationmap, es_index_body)
    elif action == 'test':
        solr_status = loads(
            SolrCoreAdmin(
                'http://%s:8983/solr/admin/cores?action=STATUS&core=%s' %
                (solrhost, core_name)).status())
        LOGGER.info('Elasticsearch ping on %s is %s', eshost,
                    'OK' if Elasticsearch(host=eshost).ping() else 'KO')
        LOGGER.info('Solr status on %s is %s', solrurl,
                    'OK' if solr_status['status'][core_name] else 'KO')