Elasticsearch indices • For some actions, it takes at least 9 API calls to complete • These API calls share a lot of redundant configuration • Reduce redundant API calls and code • Simplify/Abstract the way they're called so it's easier
value1 = my_object.method(*args) my_object.method2(value1) value2 = function1(my_object.accessor) for value in function2(value2): my_list.append(value) other_obj = unwrapped2(my_object,my_list) ... ... Lots of code goes here ... including all necessary functions ... and it gets hard to read now ... end_goal = functionN(*args, **kwargs)
= client self.indices = [] self.__get_indices() def __get_indices(self): # code here to populate self.indices def __internal_method(self, *args, **kwargs): # code here to process whatever is needed def class_method(self, *args, **kwargs): # code here to process whatever is needed def filter_methodN(self, *args, **kwargs): # code here to filter self.indices
*args, **kwargs): # code here def filter_by_age(self, *args, **kwargs): # code here ilo = IndexList(client) ilo.filter_by_regex(*args, **kwargs) ilo.filter_by_age(*args, **kwargs) # Add as many more filters as there are (loop them, even) ilo.indices = the list of indices left after filtering.
def __init__(self, ilo): # setup instance vars here # code here def do_dry_run(self): # code here def do_action(self): # code here ilo = IndexList(client) ilo.filter_by_regex(*args, **kwargs) ilo.filter_by_age(*args, **kwargs) # Add as many more filters as there are (loop them, even) action = Action(ilo) action.do_dry_run() action.do_action()
import string, random, tempfile import click from click import testing as clicktest from mock import patch, Mock from . import CuratorTestCase from . import testvars as testvars host, port = os.environ.get('TEST_ES_SERVER', 'localhost:9200').split(':') port = int(port) if port else 9200
dummy is not actionable, removing from list. curator.indexlist: DEBUG: Removed from actionable list: dummy is not associated with aliases: ['testalias', 'foo'] curator.indexlist: DEBUG: Index my_index is not actionable, removing from list. curator.indexlist: DEBUG: Removed from actionable list: my_index is not associated with aliases: ['testalias', 'foo']
to send to :class:`elasticsearch.Indices.Reindex`, which must be complete and usable, as Curator will do no vetting of the request_body. If it fails to function, Curator will return an exception. :arg refresh: Whether to refresh the entire target index after the operation is complete. (default: `True`) :type refresh: bool :arg requests_per_second: The throttle to set on this request in sub-requests per second. ``-1`` means set no throttle as does ``unlimited`` which is the only non-float this accepts. (default: ``-1``) :arg wait_for_active_shards: Sets the number of shard copies that must be active before proceeding with the reindex operation. (default: ``1``) means the primary shard only. Set to ``all`` for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1) :arg wait_for_completion: Wait (or not) for the operation to complete before returning. (default: `True`) :type wait_for_completion: bool :arg wait_interval: How long in seconds to wait between checks for completion. :arg max_wait: Maximum number of seconds to `wait_for_completion` :arg remote_url_prefix: `Optional` url prefix, if needed to reach the Elasticsearch API (i.e., it's not at the root level) :type remote_url_prefix: str
get_version(): VERSIONFILE="../curator/_version.py" verstrline = fread(VERSIONFILE).strip() vsre = r"^__version__ = ['\"]([^'\"]*)['\"]" mo = re.search(vsre, verstrline, re.M) if mo: VERSION = mo.group(1) else: raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,)) build_number = os.environ.get('CURATOR_BUILD_NUMBER', None) if build_number: return VERSION + "b{}".format(build_number) return VERSION sys.path.insert(0, os.path.abspath('../')) extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx'] # continued on next slide...
to the Sphinx 1.6.3 quickstart utility. Please enter values for the following settings (just press Enter to accept a default value, if one is given in brackets). Enter the root path for documentation. > Root path for the documentation [.]:
built documentation. > Project name: Curator > Author name(s): Aaron Mildenstein Sphinx has the notion of a "version" and a "release" for the software. Each version can have multiple releases. For example, for Python the version is something like 2.5 or 3.0, while the release is something like 2.5.1 or 3.0a1. If you don't need this dual structure, just set both to the same value. > Project version []: 5.1 > Project release [5.1]: 5.1.1 Please indicate if you want to use one of the following Sphinx extensions: > autodoc: automatically insert docstrings from modules (y/n) [n]: y ... > intersphinx: link between Sphinx documentation of different projects (y/n) [n]: y > todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: n A Makefile and a Windows command file can be generated for you so that you only have to run e.g. `make html' instead of invoking sphinx-build directly. > Create Makefile? (y/n) [y]: > Create Windows command file? (y/n) [y]: n
An initial directory structure has been created. You should now populate your master file ./index.rst and create other documentation source files. Use the Makefile to build the docs, like so: make builder where "builder" is one of the supported builders, e.g. html, latex or linkcheck. $ ls -l total 32 -rw-r--r--@ 1 buh staff 607 Jul 7 18:19 Makefile drwxr-xr-x@ 2 buh staff 68 Jul 7 18:19 _build drwxr-xr-x@ 2 buh staff 68 Jul 7 18:19 _static drwxr-xr-x@ 2 buh staff 68 Jul 7 18:19 _templates -rw-r--r--@ 1 buh staff 5340 Jul 7 18:19 conf.py -rw-r--r--@ 1 buh staff 437 Jul 7 18:19 index.rst
autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # import os import sys # sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('../'))
environment... not yet created loading intersphinx inventory from https://docs.python.org/objects.inv... intersphinx inventory has moved: https://docs.python.org/objects.inv -> https:// docs.python.org/2/objects.inv loading intersphinx inventory from https://elasticsearch-py.readthedocs.io/en/ 5.4.0/objects.inv... ... SEVERAL MORE LINES HERE build succeeded. Build finished. The HTML pages are in _build/html. $
might get it wrong? Don't be! • Tests and test-driven development help a lot. • Coding skills improve over time. • Fix things and improve as you learn. • It's okay to iterate.