def build(self): """Returns a reindexer that will return either all domains with case search enabled, or a single domain if passed in """ limit_to_db = self.options.pop('limit_to_db', None) domain = self.options.pop('domain', None) limit_db_aliases = [limit_to_db] if limit_to_db else None initialize_index_and_mapping(get_es_new(), CASE_SEARCH_INDEX_INFO) try: if domain is not None: if not domain_needs_search_index(domain): raise CaseSearchNotEnabledException( "{} does not have case search enabled".format(domain)) domains = [domain] else: # return changes for all enabled domains domains = domains_needing_search_index() change_provider = get_domain_case_change_provider( domains=domains, limit_db_aliases=limit_db_aliases) except ProgrammingError: # The db hasn't been intialized yet, so skip this reindex and complain. return _fail_gracefully_and_tell_admins() else: return PillowChangeProviderReindexer( get_case_search_processor(), change_provider=change_provider, )
def build(self): return PillowChangeProviderReindexer( pillow_or_processor=get_group_to_user_pillow(), change_provider=CouchViewChangeProvider( couch_db=Group.get_db(), view_name='all_docs/by_doc_type', view_kwargs={ 'startkey': ['Group'], 'endkey': ['Group', {}], 'include_docs': True, }), )
def handle(self, *args, **options): if len(args) < 1: raise CommandError('Usage is ptop_reindexer_fluff %s' % self.args) fluff_configs = { config.name: config for config in get_fluff_pillow_configs() } pillow_name = args[0] if pillow_name not in fluff_configs: raise CommandError( 'Unrecognised fluff pillow: "{}". Options are:\n\t{}'.format( pillow_name, '\n\t'.join(fluff_configs))) pillow_getter = get_pillow_by_name(pillow_name, instantiate=False) pillow = pillow_getter(delete_filtered=True) if len(args) == 1: domains = pillow.domains else: domains = args[1:] domains_not_in_pillow = set(domains) - set(pillow.domains) if domains_not_in_pillow: bad_domains = ', '.join(domains_not_in_pillow) available_domains = ', '.join(pillow.domains) raise CommandError( "The following domains aren't for this pillow: {}.\nAvailable domains are: {}" .format(bad_domains, available_domains)) if pillow.kafka_topic in (topics.CASE, topics.FORM): couch_db = couch_config.get_db(None) elif pillow.kafka_topic == topics.COMMCARE_USER: couch_db = couch_config.get_db(settings.NEW_USERS_GROUPS_DB) else: raise CommandError('Reindexer not configured for topic: {}'.format( pillow.kafka_topic)) change_provider = CouchDomainDocTypeChangeProvider( couch_db=couch_db, domains=domains, doc_types=[pillow.doc_type], event_handler=ReindexEventHandler(pillow_name), ) PillowChangeProviderReindexer(pillow, change_provider).reindex()
def get_case_search_reindexer(domain=None): """Returns a reindexer that will return either all domains with case search enabled, or a single domain if passed in """ initialize_index_and_mapping(get_es_new(), CASE_SEARCH_INDEX_INFO) try: if domain is not None: if not case_search_enabled_for_domain(domain): raise CaseSearchNotEnabledException( "{} does not have case search enabled".format(domain)) domains = [domain] else: # return changes for all enabled domains domains = case_search_enabled_domains() change_provider = get_domain_case_change_provider(domains=domains) except ProgrammingError: # The db hasn't been intialized yet, so skip this reindex and complain. return _fail_gracefully_and_tell_admins() else: return PillowChangeProviderReindexer( get_case_search_to_elasticsearch_pillow(), change_provider=change_provider)