示例#1
0
    def handle(self, **options):
        flip_all = options['flip_all']
        code_red = options['code_red']

        es = get_es_new()
        es_indices = list(get_all_expected_es_indices())
        if code_red:
            if input('\n'.join([
                    'CODE RED!!!',
                    'Really delete ALL the elastic indices and pillow checkpoints?',
                    'The following indices will be affected:',
                    '\n'.join([
                        six.text_type(index_info) for index_info in es_indices
                    ]),
                    'This is a PERMANENT action. (Type "code red" to continue):',
                    '',
            ])).lower() == 'code red':
                for index_info in es_indices:
                    try:
                        es.indices.delete(index_info.index)
                    except NotFoundError:
                        print('elastic index not present: {}'.format(
                            index_info.index))
                    else:
                        print('deleted elastic index: {}'.format(
                            index_info.index))
            else:
                print('Safety first!')
            return

        if flip_all:
            for index_info in es_indices:
                assume_alias(es, index_info.index, index_info.alias)
            print(simplejson.dumps(es.indices.get_aliases(), indent=4))
示例#2
0
    def handle(self, *args, **options):
        if len(args) != 0: raise CommandError("This command doesn't expect arguments!")
        flip_all = options['flip_all']
        code_red = options['code_red']

        es = get_es_new()
        es_indices = list(get_all_expected_es_indices())
        if code_red:
            if raw_input('\n'.join([
                'CODE RED!!!',
                'Really delete ALL the elastic indices and pillow checkpoints?',
                'The following indices will be affected:',
                '\n'.join([unicode(index_info) for index_info in es_indices]),
                'This is a PERMANENT action. (Type "code red" to continue):',
                '',
            ])).lower() == 'code red':
                for index_info in es_indices:
                    es.indices.delete(index_info.index)
                    print 'deleted elastic index: {}'.format(index_info.index)
            else:
                print 'Safety first!'
            return

        if flip_all:
            for index_info in es_indices:
                assume_alias(es, index_info.index, index_info.alias)
            print simplejson.dumps(es.indices.get_aliases(), indent=4)
示例#3
0
    def handle(self, **options):
        flip_all = options['flip_all']
        code_red = options['code_red']

        es = get_es_new()
        es_indices = list(get_all_expected_es_indices())
        if code_red:
            if input('\n'.join([
                'CODE RED!!!',
                'Really delete ALL the elastic indices and pillow checkpoints?',
                'The following indices will be affected:',
                '\n'.join([six.text_type(index_info) for index_info in es_indices]),
                'This is a PERMANENT action. (Type "code red" to continue):',
                '',
            ])).lower() == 'code red':
                for index_info in es_indices:
                    try:
                        es.indices.delete(index_info.index)
                    except NotFoundError:
                        print('elastic index not present: {}'.format(index_info.index))
                    else:
                        print('deleted elastic index: {}'.format(index_info.index))
            else:
                print('Safety first!')
            return

        if flip_all:
            for index_info in es_indices:
                assume_alias(es, index_info.index, index_info.alias)
            print(simplejson.dumps(es.indices.get_aliases(), indent=4))
示例#4
0
    def handle(self, *args, **options):
        if len(args) != 0: raise CommandError("This command doesn't expect arguments!")
        flip_all = options['flip_all']
        code_red = options['code_red']

        es = get_es_new()
        es_indices = list(get_all_expected_es_indices())
        if code_red:
            if raw_input('\n'.join([
                'CODE RED!!!',
                'Really delete ALL the elastic indices and pillow checkpoints?',
                'The following indices will be affected:',
                '\n'.join([unicode(index_info) for index_info in es_indices]),
                'This is a PERMANENT action. (Type "code red" to continue):',
                '',
            ])).lower() == 'code red':
                for index_info in es_indices:
                    es.indices.delete(index_info.index)
                    print 'deleted elastic index: {}'.format(index_info.index)
            else:
                print 'Safety first!'
            return

        if flip_all:
            for index_info in es_indices:
                assume_alias(es, index_info.index, index_info.alias)
            print simplejson.dumps(es.indices.get_aliases(), indent=4)
示例#5
0
 def test_assume_alias(self):
     initialize_index_and_mapping(self.es, TEST_INDEX_INFO)
     doc_id = uuid.uuid4().hex
     doc = {'_id': doc_id, 'doc_type': 'CommCareCase', 'type': 'mother'}
     send_to_elasticsearch(self.index, TEST_INDEX_INFO.type, doc_id, get_es_new, 'test', doc)
     self.assertEqual(1, get_doc_count(self.es, self.index))
     assume_alias(self.es, self.index, TEST_INDEX_INFO.alias)
     es_doc = self.es.get_source(TEST_INDEX_INFO.alias, TEST_INDEX_INFO.type, doc_id)
     for prop in doc:
         self.assertEqual(doc[prop], es_doc[prop])
示例#6
0
 def test_assume_alias(self):
     initialize_index_and_mapping(self.es, TEST_INDEX_INFO)
     doc_id = uuid.uuid4().hex
     doc = {'_id': doc_id, 'doc_type': 'CommCareCase', 'type': 'mother'}
     send_to_elasticsearch(self.index, TEST_INDEX_INFO.type, doc_id,
                           get_es_new, 'test', doc)
     self.assertEqual(1, get_doc_count(self.es, self.index))
     assume_alias(self.es, self.index, TEST_INDEX_INFO.alias)
     es_doc = self.es_interface.get_doc(TEST_INDEX_INFO.alias,
                                        TEST_INDEX_INFO.type, doc_id)
     for prop in doc:
         self.assertEqual(doc[prop], es_doc[prop])
示例#7
0
    def test_assume_alias_deletes_old_aliases(self):
        # create a different index and set the alias for it
        initialize_index_and_mapping(self.es, TEST_INDEX_INFO)
        new_index = 'test_index-with-duplicate-alias'
        if not self.es.indices.exists(new_index):
            self.es.indices.create(index=new_index)
        self.es.indices.put_alias(new_index, TEST_INDEX_INFO.alias)
        self.addCleanup(functools.partial(ensure_index_deleted, new_index))

        # make sure it's there in the other index
        aliases = self.es.indices.get_aliases()
        self.assertEqual([TEST_INDEX_INFO.alias], list(aliases[new_index]['aliases']))

        # assume alias and make sure it's removed (and added to the right index)
        assume_alias(self.es, self.index, TEST_INDEX_INFO.alias)
        aliases = self.es.indices.get_aliases()
        self.assertEqual(0, len(aliases[new_index]['aliases']))
        self.assertEqual([TEST_INDEX_INFO.alias], list(aliases[self.index]['aliases']))
示例#8
0
    def test_assume_alias_deletes_old_aliases(self):
        # create a different index and set the alias for it
        initialize_index_and_mapping(self.es, TEST_INDEX_INFO)
        new_index = 'test_index-with-duplicate-alias'
        if not self.es.indices.exists(new_index):
            self.es.indices.create(index=new_index)
        self.es.indices.put_alias(new_index, TEST_INDEX_INFO.alias)
        self.addCleanup(functools.partial(ensure_index_deleted, new_index))

        # make sure it's there in the other index
        aliases = self.es_interface.get_aliases()
        self.assertEqual([TEST_INDEX_INFO.alias], list(aliases[new_index]['aliases']))

        # assume alias and make sure it's removed (and added to the right index)
        assume_alias(self.es, self.index, TEST_INDEX_INFO.alias)
        aliases = self.es_interface.get_aliases()

        self.assertEqual(0, len(aliases[new_index]['aliases']))
        self.assertEqual([TEST_INDEX_INFO.alias], list(aliases[self.index]['aliases']))
示例#9
0
    def test_assume_alias_deletes_old_aliases(self):
        # create a different index and set the alias for it
        initialize_index_and_mapping(self.es, TEST_INDEX_INFO)
        new_index = 'test_index-with-duplicate-alias'
        if not self.es.indices.exists(new_index):
            self.es.indices.create(index=new_index)
        self.es.indices.put_alias(new_index, TEST_INDEX_INFO.alias)
        self.addCleanup(functools.partial(ensure_index_deleted, new_index))

        # make sure it's there in the other index
        aliases = self.es_interface.get_aliases()
        # NOTE: alias is currently applied to *both* indices now because the
        # `initialize_index_and_mapping` helper function both creates the index
        # and applies an alias to the (new) index. The `assertIn()` test is used
        # here as to not make this test depend on that implied functionality of
        # the helper function.
        self.assertIn(new_index, aliases[TEST_INDEX_INFO.alias])

        # assume alias and make sure it's removed (and added to the right index)
        assume_alias(self.es, self.index, TEST_INDEX_INFO.alias)
        aliases = self.es_interface.get_aliases()

        self.assertEqual([self.index], aliases[TEST_INDEX_INFO.alias])