def handle(self, *labels, **options): """ More targeted pillow checkpoint reset system - must specify the pillow class_name to reset the checkpoint """ if not labels: pillow_class_names = [cls.__name__ for cls in get_all_pillow_classes()] print "\nNo pillow class specified, options are:\n\t%s\n" % ("\n\t".join(pillow_class_names)) sys.exit() pillow_class_name = labels[0] pillow_to_use = get_pillow_by_name(pillow_class_name) if not pillow_to_use: print "" print "\n\tPillow class [%s] not in configuration, what are you trying to do?\n" % pillow_class_name sys.exit() if not options.get("interactive"): confirm = raw_input( """ You have requested to reset the checkpoints for the pillow [%s]. 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: """ % pillow_class_name ) else: confirm = "yes" if confirm != "yes": print "Reset cancelled." return print "Resetting checkpoint for %s" % pillow_to_use.checkpoint.checkpoint_id print "\tOld checkpoint: %s" % pillow_to_use.get_checkpoint()["seq"] pillow_to_use.checkpoint.reset() print "\n\tNew checkpoint reset to zero"
def test_get_pillow_classes(self): pillows = get_all_pillow_classes() self.assertEquals(len(pillows), 1) pillow_class = pillows[0] self.assertTrue(isclass(pillow_class)) self.assertEqual(FakeConstructedPillow, pillow_class)
def test_get_all_pillow_classes(self): pillows = get_all_pillow_classes() self.assertEquals(len(pillows), 1) self.assertTrue(isclass(pillows[0]))
def get_all_elasticsearch_pillow_classes(): from pillowtop.listener import AliasedElasticPillow return filter(lambda x: issubclass(x, AliasedElasticPillow), get_all_pillow_classes())
def handle(self, *args, **options): runs = [] pillow_classes = get_all_pillow_classes() aliased_classes = filter(lambda x: issubclass(x, AliasedElasticPillow), pillow_classes) aliasable_pillows = [p(create_index=False) for p in aliased_classes] reindex_all = options['replace'] pillow_state_results = get_pillow_states(aliasable_pillows) print "Master indices missing aliases:" unmapped_indices = [x[0] for x in pillow_state_results.unmapped_masters] print unmapped_indices if reindex_all: print "Reindexing ALL master pillows that are not aliased" preindexable_pillows = aliasable_pillows else: print ("Reindexing master pillows that do not exist yet " "(ones with aliases skipped)") preindexable_pillows = filter(lambda x: not x.index_exists(), aliasable_pillows) reindex_pillows = filter(lambda x: x.es_index in unmapped_indices, preindexable_pillows) print "Reindexing:\n\t", print '\n\t'.join(x.es_index for x in reindex_pillows) if len(reindex_pillows) > 0: preindex_message = """ Heads up! %s is 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_commands(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) if len(reindex_pillows) > 0: gevent.joinall(runs) try: for job in runs: job.get() except Exception: f = StringIO() traceback.print_exc(file=f) mail_admins("Pillow preindexing failed", f.getvalue()) raise else: 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"