Beispiel #1
0
    def handle(self, *args, **options):
        runs = []
        pillows = import_pillows()
        aliased_pillows = filter(lambda x: isinstance(x, AliasedElasticPillow),
                                 pillows)

        mapped_masters, unmapped_masters, stale_indices = get_pillow_states(
            pillows)

        print "Master indices missing aliases:"

        unmapped_indices = [x[0] for x in unmapped_masters]

        reindex_pillows = filter(lambda x: x.es_index in unmapped_indices,
                                 aliased_pillows)

        print reindex_pillows

        if len(reindex_pillows) > 0:
            preindex_message = """
        Heads up!

        %sis going to start preindexing the following pillows:
        %s

        This may take a while, so don't deploy until all these have reported finishing.
            """ % (settings.EMAIL_SUBJECT_PREFIX, ', '.join(
                [x.__class__.__name__ for x in reindex_pillows]))

            mail_admins("Pillow preindexing starting", preindex_message)

        start = datetime.utcnow()
        for pillow in reindex_pillows:
            #loop through pillows once before running greenlets to fail hard on misconfigured pillows
            pillow_class_name = pillow.__class__.__name__
            reindex_command = get_reindex_command(pillow_class_name)
            if not reindex_command:
                raise Exception(
                    "Error, pillow [%s] is not configured with its own management command reindex command - it needs one"
                    % pillow_class_name)

        for pillow in reindex_pillows:
            print pillow.__class__.__name__
            g = gevent.spawn(do_reindex, pillow.__class__.__name__)
            runs.append(g)
        gevent.joinall(runs)
        if len(reindex_pillows) > 0:
            mail_admins(
                "Pillow preindexing completed",
                "Reindexing %s took %s seconds" %
                (', '.join([x.__class__.__name__ for x in reindex_pillows]),
                 (datetime.utcnow() - start).seconds))
        print "All pillowtop reindexing jobs completed"
    def handle(self, *args, **options):
        runs = []
        pillows = import_pillows()
        aliased_pillows = filter(lambda x: isinstance(x, AliasedElasticPillow), pillows)

        mapped_masters, unmapped_masters, stale_indices = get_pillow_states(pillows)

        print "Master indices missing aliases:"

        unmapped_indices = [x[0] for x in unmapped_masters]

        reindex_pillows = filter(lambda x: x.es_index in unmapped_indices, aliased_pillows)

        print reindex_pillows

        if len(reindex_pillows) > 0:
            preindex_message = """
        Heads up!

        %sis going to start preindexing the following pillows:
        %s

        This may take a while, so don't deploy until all these have reported finishing.
            """ % (settings.EMAIL_SUBJECT_PREFIX, ', '.join([x.__class__.__name__ for x in reindex_pillows]))

            mail_admins("Pillow preindexing starting", preindex_message)



        start = datetime.utcnow()
        for pillow in reindex_pillows:
            #loop through pillows once before running greenlets to fail hard on misconfigured pillows
            pillow_class_name = pillow.__class__.__name__
            reindex_command = get_reindex_command(pillow_class_name)
            if not reindex_command:
                raise Exception("Error, pillow [%s] is not configured with its own management command reindex command - it needs one" % pillow_class_name)

        for pillow in reindex_pillows:
            print pillow.__class__.__name__
            g = gevent.spawn(do_reindex, pillow.__class__.__name__)
            runs.append(g)
        gevent.joinall(runs)
        if len(reindex_pillows) > 0:
            mail_admins("Pillow preindexing completed", "Reindexing %s took %s seconds" % (
                ', '.join([x.__class__.__name__ for x in reindex_pillows]),
                (datetime.utcnow() - start).seconds
            ))
        print "All pillowtop reindexing jobs completed"
    def handle_noargs(self, **options):
        if options.get('interactive'):
            confirm = raw_input("""
            You have requested to reset the checkpoints for pillowtop. This is an irreversible
            operation, and may take a long time, and cause extraneous updates to the requisite
            consumers of the _changes feeds  Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: """)
        else:
            confirm = 'yes'

        if confirm != 'yes':
            print "Reset cancelled."
            return

        for pillow in import_pillows():
            print "Resetting checkpoint for %s" % pillow.get_checkpoint_doc_name()
            pillow.reset_checkpoint()
    def handle(self, *args, **options):
        if len(args) != 0: raise CommandError("This command doesn't expect arguments!")

        print ""
        show_info = options['show_info']
        list_pillows = options['list_pillows']
        do_flip = options['do_flip']
        es = get_es()

        pillows = import_pillows()
        aliased_pillows = filter(lambda x: isinstance(x, AliasedElasticPillow), pillows)

        #make tuples of (index, alias)
        #this maybe problematic if we have multiple pillows pointing to the same alias or indices
        master_aliases = dict((x.es_index, x.es_alias) for x in aliased_pillows)
        print master_aliases

        if show_info:
            system_status = es.get('_status')
            indices = system_status['indices'].keys()
            print ""
            print "\tActive indices"
            for index in indices:
                print "\t\t%s" % index
            print ""

            print "\n\tAlias Mapping Status"
            active_aliases = es.get('_aliases')
            for idx, alias_dict in active_aliases.items():
                line = ["\t\t", idx]
                is_master = False
                if idx in master_aliases:
                    is_master = True
                    line.append('*HEAD')

                if is_master:
                    if master_aliases[idx] in alias_dict['aliases']:
                        #is master, has alias, good
                        line.append('=> %s :)' % master_aliases[idx])
                    else:
                        #is not master, doesn't have alias, bad
                        line.append('=> Does not have alias yet :(')
                else:
                    #not a master index
                    line.append(
                        '=> [%s] Non HEAD has alias' % (' '.join(alias_dict['aliases'].keys())))
                print ' '.join(line)

            print ""
            sys.exit()
        if list_pillows:
            print aliased_pillows
            sys.exit()

        if do_flip:
            pillow_class_name = options['pillow_class']
            pillow_to_use = filter(lambda x: x.__class__.__name__ == pillow_class_name,
                                   aliased_pillows)
            if len(pillow_to_use) != 1:
                print "Unknown pillow (option --pillow <name>) class string, the options are: \n\t%s" % ', '.join(
                    [x.__class__.__name__ for x in aliased_pillows])
                sys.exit()

            #ok we got the pillow
            target_pillow = pillow_to_use[0]
            target_pillow.assume_alias()

            print es.get('_aliases')