def add(self, identifier, data):
        """
        Add an item to the tileindex

        :param identifier: tileindex item id
        :param data: GeoJSON dict

        :returns: `int` of status (as per HTTP status codes)
        """

        status_code = None

        LOGGER.info('Indexing {}'.format(identifier))
        LOGGER.debug('Data: {}'.format(json_pretty_print(data)))
        try:
            # FIXME: refresh='wait_for' essentially blocks further processing
            # until the document is fully available in ES.  This is done in
            # order to make updates to the layer registration datetime
            # immediately after in support of tracking performance (kind of
            # ironic eh?).
            # TODO: update using asyncio or multiprocessing
            r = self.es.index(index=self.name,
                              id=identifier,
                              body=data,
                              pipeline='gdr_register_datetime')
            if r['result'] == 'created':
                status_code = 201
            elif r['result'] == 'updated':
                status_code = 200
        except Exception as err:
            LOGGER.exception('Error indexing {}: {}'.format(identifier, err))
            return 500

        return status_code
Exemple #2
0
def get_key(ctx, key, raw):
    """get key from store"""

    if all([key is None]):
        raise click.ClickException('Missing --key/-k')

    provider_def = {'type': STORE_TYPE, 'url': STORE_URL}

    st = load_plugin('store', provider_def)

    try:
        if raw:
            click.echo('Getting {} key from store ({}).'.format(key, st.url))
            retrieved_key = st.get_key(key, raw=True)
        else:
            click.echo(
                'Getting geomet-data-registry_{} key from store ({}).'.format(
                    key, st.url))
            retrieved_key = st.get_key(key)
        if retrieved_key:
            try:
                click.echo('{}'.format(
                    json_pretty_print(json.loads(retrieved_key))))
            except ValueError:
                click.echo(retrieved_key)

    except StoreError as err:
        raise click.ClickException(err)
    click.echo('Done')
def list_keys(ctx, pattern=None):
    """list all keys in store"""

    provider_def = {'type': STORE_TYPE, 'url': STORE_URL}

    st = load_plugin('store', provider_def)

    try:
        click.echo(json_pretty_print(st.list_keys(pattern)))
    except StoreError as err:
        raise click.ClickException(err)
    click.echo('Done')
def get_key(ctx, key):
    """get key from store"""

    if all([key is None]):
        raise click.ClickException('Missing --key/-k')

    provider_def = {'type': STORE_TYPE, 'url': STORE_URL}

    st = load_plugin('store', provider_def)

    try:
        click.echo('Getting {} key from store ({}).'.format(key, st.url))
        retrived_key = json.loads(st.get_key(key))
        if retrived_key:
            click.echo('{}'.format(json_pretty_print(retrived_key)))

    except StoreError as err:
        raise click.ClickException(err)
    click.echo('Done')
Exemple #5
0
def list_keys(ctx, raw, pattern=None):
    """list all keys in store"""

    provider_def = {'type': STORE_TYPE, 'url': STORE_URL}

    st = load_plugin('store', provider_def)

    try:
        pattern = 'geomet-data-registry*{}'.format(pattern if pattern else '')
        if raw:
            keys = st.list_keys(pattern)
        else:
            keys = [
                remove_prefix(key, 'geomet-data-registry_')
                for key in st.list_keys(pattern)
            ]
        click.echo(json_pretty_print(keys))
    except StoreError as err:
        raise click.ClickException(err)
    click.echo('Done')
Exemple #6
0
def add_data(ctx, file_, directory, verify=False):
    """add data to system"""

    if all([file_ is None, directory is None]):
        raise click.ClickException('Missing --file/-f or --dir/-d option')

    files_to_process = []

    if file_ is not None:
        files_to_process = [file_]
    elif directory is not None:
        for root, dirs, files in os.walk(directory):
            for f in files:
                files_to_process.append(os.path.join(root, f))

    for file_to_process in files_to_process:
        handler = CoreHandler(file_to_process)
        result = handler.handle()
        if result:
            click.echo('File properties: {}'.format(
                json_pretty_print(handler.layer_plugin.items)))