From d82782603eb7e6631150d32eb4439139de93abf3 Mon Sep 17 00:00:00 2001 From: Sylvain Gaudan Date: Wed, 7 Feb 2024 10:51:13 +0100 Subject: [PATCH] configuration mgnt --- README.md | 125 ++++++++++++++++++++++++++++++------ arlas/cli/cli.py | 37 ++++++----- arlas/cli/collections.py | 46 +++++++++---- arlas/cli/configurations.py | 83 ++++++++++++++++++++++++ arlas/cli/index.py | 60 +++++++++++------ arlas/cli/model_infering.py | 2 +- arlas/cli/service.py | 2 +- arlas/cli/variables.py | 5 +- scripts/tests.sh | 66 +++++++++++++++---- 9 files changed, 338 insertions(+), 88 deletions(-) create mode 100644 arlas/cli/configurations.py diff --git a/README.md b/README.md index 1025add..af29829 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,13 @@ arlas_cli --help ### Initial configuration The confiuration file `~/.arlas/cli/configuration.yaml` must contain the different ARLAS/elasticsearch endpoints you want to interact with. [One is automatically created for your convinience at the first launch](configuration.yaml). It contains the demo endpoint and the localhost endpoint. -The configuration must contain references to collection models for creating collections. A default one is provided for ARLAS EO. A reference can be an http url or a path to a local file. -It must also contain references to index mappings for creating indices. A default one is provided for ARLAS EO. A reference can be an http url or a path to a local file. +The configuration can contain references to collection models for creating collections. A default one is provided for ARLAS EO. A reference can be an http url or a path to a local file. +It can also contain references to index mappings for creating indices. A default one is provided for ARLAS EO. A reference can be an http url or a path to a local file. ## Running ```shell -arlas_cli --help +arlas_cli --version ``` ## Examples @@ -43,6 +43,7 @@ In the following examples, you will see how to: - get the structure of a arlas collection - delete a collection from arlas - delete a mapping from elasticsearch +- list, create, describe and delete a configuration for `arlas_cli` ... with the `arlas_cli` command line only! @@ -59,31 +60,46 @@ curl -X GET https://raw.githubusercontent.com/gisaia/arlas-cli/master/tests/samp Now we can generate the mapping file based on that sample: ```shell -arlas_cli --config local indices \ +arlas_cli indices \ + --config local \ mapping sample.json \ --field-mapping track.timestamps.center:date-epoch_second \ --field-mapping track.timestamps.start:date-epoch_second \ --field-mapping track.timestamps.end:date-epoch_second \ - --push-on courses + --push-on courses ``` The `--push-on` option registers the mapping in the specified index. Note that the three timestamps are not identified as datetimes by `arlas_cli`. The `--field-mapping` allows to overwrite the detected type. +#### Type identification + +A geometry is identified as such if +- it is a geojson +- it is a WKT string +- the fielf name contains `geohash` +- it is a string containing two float seperated by a comma + +A date is identified as such if +- its name is one of `timestamp`, `date`, `start` or `end` and that it can be parsed as a date +- its name contains `timestamp`, `date`, `start` or `end` and its values are number within [631152000, 4102444800] or [631152000000, 4102444800000] (year 1950 to 2100) + + ### Generate the elasticsearch mapping To add a specific mapping, it is possible to use the `create`` command: ```shell -arlas_cli --config local indices \ +arlas_cli indices \ + --config local \ create courses \ - --mapping mapping.json + --mapping mapping.json ``` ### List indices ```shell -arlas_cli --config local indices list +arlas_cli indices --config local list --config local ``` returns: @@ -99,14 +115,13 @@ returns: ### Add data ```shell -arlas_cli --config local indices \ - data courses sample.json +arlas_cli indices --config local data courses sample.json --config local ``` ### Describe an index ```shell -arlas_cli --config local indices describe courses +arlas_cli indices --config local describe courses --config local ``` returns: @@ -128,19 +143,20 @@ returns: ### Add a collection ```shell -arlas_cli --config local collections \ +arlas_cli collections \ + --config local \ create courses \ --index courses --display-name courses \ --id-path track.id \ --centroid-path track.location \ --geometry-path track.trail \ - --date-path track.timestamps.center + --date-path track.timestamps.center ``` ### List collections ```shell -arlas_cli --config local collections list +arlas_cli collections --config local list ``` returns: @@ -156,7 +172,7 @@ returns: ### Describe a collection ```shell -arlas_cli --config local collections describe courses +arlas_cli collections --config local describe courses ``` returns: @@ -179,17 +195,19 @@ returns: ### Delete a collection ```shell -arlas_cli --config local collections delete courses +arlas_cli collections --config local delete courses ``` ### Delete an index ```shell -arlas_cli --config local indices delete courses +arlas_cli indices --config local delete courses ``` Note: by default, it is not allowed to delete an index for a given configuration. To allow deleting, edit the configuration file and set `allow_delete` to `True`. -## Configuration + + +## Configurations The command line uses the `${HOME}/.arlas/cli/configuration.yaml` configuration file: @@ -217,4 +235,73 @@ models: The `arlas` section contains the different deployment configurations. The mapping section lists the mapping template that you can use. Finaly, the models are the templates for the collections. A [detaild description](docs/model/README.md) of the configuration structure is provided. - \ No newline at end of file + + ### Create, describe and delete a configuration for `arlas_cli` + +You can edit directly the `${HOME}/.arlas/cli/configuration.yaml` configuration file to update your configurations. You can also use the command line itself. + +To list the configurations: +```shell +arlas_cli confs list +``` + +returns: + +```shell ++-----------+-----------------------------+ +| name | url | ++-----------+-----------------------------+ +| local | http://localhost:9999/arlas | +| test_conf | http://localhost:9999 | ++-----------+-----------------------------+ +``` + +To describe a configuration: + +```shell +arlas_cli confs describe local +``` + +returns: + +```yaml +allow_delete: true +authorization: null +elastic: + headers: + Content-Type: application/json + location: http://localhost:9200 +server: + headers: + Content-Type: application/json + location: http://localhost:9999/arlas +``` + +To create a configuration: + +```shell +arlas_cli confs create dev_conf \ + --server http://localhost:9999 \ + --headers "Content-Type:application/json" \ + --elastic http://localhost:9200 \ + --elastic-headers "Content-Type:application/json" \ + --no-allow-delete +``` + +To delete the configuration: + +```shell +arlas_cli confs delete dev_conf +``` + +Also, it is possible to use a different configuration file than the one placed in your home directory (`$HOME/.arlas/cli/configuration.yaml`): + +```shell +arlas_cli --config-file /tmp/config.yaml +``` + +returns + +```shell +Warning : no configuration file found, we created an empty one for you (/tmp/config.yaml). +``` diff --git a/arlas/cli/cli.py b/arlas/cli/cli.py index d0736f6..7ed2be3 100644 --- a/arlas/cli/cli.py +++ b/arlas/cli/cli.py @@ -3,34 +3,35 @@ import sys from arlas.cli.collections import collections +from arlas.cli.configurations import configurations from arlas.cli.index import indices -from arlas.cli.variables import variables, configuration_file +from arlas.cli.variables import variables from arlas.cli.settings import ARLAS, Configuration, Resource, Settings -app = typer.Typer(add_completion=False) +app = typer.Typer(add_completion=False, no_args_is_help=True) arlas_cli_version = "arlas_cli_versions" -@app.callback() -def collections_callback( - config: str = typer.Option(help="Name of the ARLAS configuration to use from your configuration file ({}).".format(configuration_file)) +@app.callback(invoke_without_command=True) +def init( + config_file: str = typer.Option(None, help="Path to the configuration file if you do not want to use the default one: .arlas/cli/configuration.yaml."), + version: bool = typer.Option(False, "--version", help="Print command line version") ): - variables["arlas"] = config - - -def main(): - if os.path.exists(configuration_file): - Configuration.init(configuration_file=configuration_file) + if config_file: + variables["configuration_file"] = config_file + if version: + print(arlas_cli_version) + if os.path.exists(variables["configuration_file"]): + Configuration.init(configuration_file=variables["configuration_file"]) if Configuration.settings.arlas and len(Configuration.settings.arlas) > 0: # Configuration is ok. ... else: - print("Error : no arlas endpoint found in {}.".format(configuration_file), file=sys.stderr) + print("Error : no arlas endpoint found in {}.".format(variables["configuration_file"]), file=sys.stderr) sys.exit(1) else: # we create a template to facilitate the creation of the configuration file - print(os.path.dirname(configuration_file)) - os.makedirs(os.path.dirname(configuration_file), exist_ok=True) + os.makedirs(os.path.dirname(variables["configuration_file"]), exist_ok=True) Configuration.settings = Settings( arlas={ "demo": ARLAS(server=Resource(location="https://demo.cloud.arlas.io/arlas/server", headers={"Content-Type": "application/json"})), @@ -47,11 +48,15 @@ def main(): "arlas_eo": Resource(location="https://raw.githubusercontent.com/gisaia/ARLAS-EO/master/collection.json") } ) - Configuration.save(configuration_file) - print("Warning : no configuration file found, we created an empty one for you ({}).".format(configuration_file), file=sys.stderr) + Configuration.save(variables["configuration_file"]) + print("Warning : no configuration file found, we created an empty one for you ({}).".format(variables["configuration_file"]), file=sys.stderr) sys.exit(0) + + +def main(): app.add_typer(collections, name="collections") app.add_typer(indices, name="indices") + app.add_typer(configurations, name="confs") app() diff --git a/arlas/cli/collections.py b/arlas/cli/collections.py index 8e9f197..55cec4f 100644 --- a/arlas/cli/collections.py +++ b/arlas/cli/collections.py @@ -11,33 +11,50 @@ collections = typer.Typer() +@collections.callback() +def configuration(config: str = typer.Option(help="Name of the ARLAS configuration to use from your configuration file ({}).".format(variables["configuration_file"]))): + variables["arlas"] = config + + @collections.command(help="List collections", name="list") def list_collections(): - collections = Service.list_collections(variables["arlas"]) + config = variables["arlas"] + collections = Service.list_collections(config) tab = PrettyTable(collections[0], sortby="name", align="l") tab.add_rows(collections[1:]) print(tab) @collections.command(help="Count the number of hits within a collection (or all collection if not provided)") -def count(collection: str = typer.Argument(default=None, help="Collection's name")): - count = Service.count_collection(variables["arlas"], collection) +def count( + collection: str = typer.Argument(default=None, help="Collection's name") +): + config = variables["arlas"] + count = Service.count_collection(config, collection) tab = PrettyTable(count[0], sortby="collection name", align="l") tab.add_rows(count[1:]) print(tab) @collections.command(help="Describe a collection") -def describe(collection: str = typer.Argument(help="Collection's name")): - collections = Service.describe_collection(variables["arlas"], collection) +def describe( + collection: str = typer.Argument(help="Collection's name") +): + config = variables["arlas"] + collections = Service.describe_collection(config, collection) tab = PrettyTable(collections[0], sortby="field name", align="l") tab.add_rows(collections[1:]) print(tab) @collections.command(help="Display a sample of a collection") -def sample(collection: str = typer.Argument(help="Collection's name"), pretty: bool = typer.Option(default=True), size: int = typer.Option(default=10)): - sample = Service.sample_collection(variables["arlas"], collection, pretty=pretty, size=size) +def sample( + collection: str = typer.Argument(help="Collection's name"), + pretty: bool = typer.Option(default=True), + size: int = typer.Option(default=10) +): + config = variables["arlas"] + sample = Service.sample_collection(config, collection, pretty=pretty, size=size) print(json.dumps(sample.get("hits", []), indent=2 if pretty else None)) @@ -45,13 +62,14 @@ def sample(collection: str = typer.Argument(help="Collection's name"), pretty: b def delete( collection: str = typer.Argument(help="collection's name") ): - if typer.confirm("You are about to delete the collection '{}' on the '{}' configuration.\n".format(collection, variables["arlas"]), - prompt_suffix="Do you want to continue (del {} on {})?".format(collection, variables["arlas"]), + config = variables["arlas"] + if typer.confirm("You are about to delete the collection '{}' on the '{}' configuration.\n".format(collection, config), + prompt_suffix="Do you want to continue (del {} on {})?".format(collection, config), default=False, ): Service.delete_collection( - variables["arlas"], + config, collection=collection) - print("{} has been deleted on {}.".format(collection, variables["arlas"])) + print("{} has been deleted on {}.".format(collection, config)) @collections.command(help="Create a collection") @@ -68,6 +86,7 @@ def create( geometry_path: str = typer.Option(default=None, help="Overide the JSON path to the geometry field."), date_path: str = typer.Option(default=None, help="Overide the JSON path to the date field.") ): + config = variables["arlas"] if not owner and (orgs or public): print("Error: an owner must be provided for sharing the collection.", file=sys.stderr) exit(1) @@ -81,7 +100,7 @@ def create( print("Error: model {} not found".format(model), file=sys.stderr) exit(1) Service.create_collection( - variables["arlas"], + config, collection, model_resource=model_resource, index=index, @@ -93,5 +112,4 @@ def create( centroid_path=centroid_path, geometry_path=geometry_path, date_path=date_path) - print("Collection {} created on {}".format(collection, variables["arlas"])) - + print("Collection {} created on {}".format(collection, config)) diff --git a/arlas/cli/configurations.py b/arlas/cli/configurations.py new file mode 100644 index 0000000..3f65361 --- /dev/null +++ b/arlas/cli/configurations.py @@ -0,0 +1,83 @@ +import sys +import typer +import yaml +from prettytable import PrettyTable +from arlas.cli.settings import ARLAS, AuthorizationService, Configuration, Resource +from arlas.cli.variables import variables + +configurations = typer.Typer() + + +@configurations.command(help="List configurations", name="list") +def list_configurations(): + confs = [] + for (name, conf) in Configuration.settings.arlas.items(): + confs.append([name, conf.server.location]) + tab = PrettyTable(["name", "url"], sortby="name", align="l") + tab.add_rows(confs[1:]) + print(tab) + + +@configurations.command(help="Add a configuration", name="create") +def create_configuration( + name: str = typer.Argument(help="Name of the configuration"), + server: str = typer.Option(help="ARLAS Server url"), + headers: list[str] = typer.Option([], help="header (name:value)"), + elastic: str = typer.Option(default=None, help="dictionary of name/es resources"), + elastic_headers: list[str] = typer.Option([], help="header (name:value)"), + allow_delete: bool = typer.Option(default=False, help="Is delete command allowed for this configuration?"), + auth_token_url: str = typer.Option(default=None, help="Token URL of the authentication service"), + auth_headers: list[str] = typer.Option([], help="header (name:value)"), + auth_login: str = typer.Option(default=None, help="login"), + auth_password: str = typer.Option(default=None, help="password"), + auth_client_id: str = typer.Option(default=None, help="Client ID"), + auth_client_secret: str = typer.Option(default=None, help="Client secret"), + auth_grant_type: str = typer.Option(default=None, help="Grant type (e.g. password)"), + auth_arlas_iam: bool = typer.Option(default=True, help="Is it an ARLAS IAM service?") +): + if Configuration.settings.arlas.get(name): + print("Error: a configuration with that name already exists, please remove it first.", file=sys.stderr) + exit(1) + + conf = ARLAS( + server=Resource(location=server, headers=dict(map(lambda h: (h.split(":")[0], h.split(":")[1]), headers))), + allow_delete=allow_delete) + if auth_token_url: + conf.authorization = AuthorizationService( + token_url=Resource(location=auth_token_url, headers=dict(map(lambda h: (h.split(":")[0], h.split(":")[1]), auth_headers))), + login=auth_login, + password=auth_password, + client_id=auth_client_id, + client_secret=auth_client_secret, + grant_type=auth_grant_type, + arlas_iam=auth_arlas_iam + ) + if elastic: + conf.elastic = Resource(location=elastic, headers=dict(map(lambda h: (h.split(":")[0], h.split(":")[1]), elastic_headers))) + Configuration.settings.arlas[name] = conf + Configuration.save(variables["configuration_file"]) + Configuration.init(variables["configuration_file"]) + print("Configuration {} created.".format(name)) + + +@configurations.command(help="Delete a configuration", name="delete") +def delete_configuration( + name: str = typer.Argument(help="Name of the configuration"), +): + if Configuration.settings.arlas.get(name) is None: + print("Error: no configuration found for {}.".format(name), file=sys.stderr) + exit(1) + Configuration.settings.arlas.pop(name) + Configuration.save(variables["configuration_file"]) + Configuration.init(variables["configuration_file"]) + print("Configuration {} deleted.".format(name)) + + +@configurations.command(help="Describe a configuration", name="describe") +def describe_configuration( + name: str = typer.Argument(help="Name of the configuration"), +): + if Configuration.settings.arlas.get(name) is None: + print("Error: no configuration found for {}.".format(name), file=sys.stderr) + exit(1) + print(yaml.dump(Configuration.settings.arlas[name].model_dump())) \ No newline at end of file diff --git a/arlas/cli/index.py b/arlas/cli/index.py index df3effc..e1e1f2a 100644 --- a/arlas/cli/index.py +++ b/arlas/cli/index.py @@ -6,31 +6,45 @@ from arlas.cli.settings import Configuration, Resource from arlas.cli.service import Service -from arlas.cli.variables import variables, configuration_file from arlas.cli.model_infering import make_mapping +from arlas.cli.variables import variables indices = typer.Typer() +@indices.callback() +def configuration(config: str = typer.Option(help="Name of the ARLAS configuration to use from your configuration file ({}).".format(variables["configuration_file"]))): + variables["arlas"] = config + + @indices.command(help="List indices", name="list") def list_indices(): - indices = Service.list_indices(variables["arlas"]) + config = variables["arlas"] + indices = Service.list_indices(config) tab = PrettyTable(indices[0], sortby="name", align="l") tab.add_rows(indices[1:]) print(tab) @indices.command(help="Describe an index") -def describe(index: str = typer.Argument(help="index's name")): - indices = Service.describe_index(variables["arlas"], index) +def describe( + index: str = typer.Argument(help="index's name") +): + config = variables["arlas"] + indices = Service.describe_index(config, index) tab = PrettyTable(indices[0], sortby="field name", align="l") tab.add_rows(indices[1:]) print(tab) @indices.command(help="Display a sample of an index") -def sample(index: str = typer.Argument(help="index's name"), pretty: bool = typer.Option(default=True), size: int = typer.Option(default=10)): - sample = Service.sample_index(variables["arlas"], index, pretty=pretty, size=size) +def sample( + index: str = typer.Argument(help="index's name"), + pretty: bool = typer.Option(default=True), + size: int = typer.Option(default=10) +): + config = variables["arlas"] + sample = Service.sample_index(config, index, pretty=pretty, size=size) print(json.dumps(sample["hits"].get("hits", []), indent=2 if pretty else None)) @@ -40,6 +54,7 @@ def create( mapping: str = typer.Option(help="Name of the mapping within your configuration, or URL or file path"), shards: int = typer.Option(default=1, help="Number of shards for the index") ): + config = variables["arlas"] mapping_resource = Configuration.settings.mappings.get(mapping, None) if not mapping_resource: if os.path.exists(mapping): @@ -48,11 +63,11 @@ def create( print("Error: model {} not found".format(mapping), file=sys.stderr) exit(1) Service.create_index_from_resource( - variables["arlas"], + config, index=index, mapping_resource=mapping_resource, number_of_shards=shards) - print("Index {} created on {}".format(index, variables["arlas"])) + print("Index {} created on {}".format(index, config)) @indices.command(help="Index data") @@ -61,12 +76,13 @@ def data( files: list[str] = typer.Argument(help="List of pathes to the file conaining the data. Format: NDJSON"), bulk: int = typer.Option(default=100, help="Bulk size for indexing data") ): + config = variables["arlas"] for file in files: if not os.path.exists(file): print("Error: file \"{}\" not found.".format(file), file=sys.stderr) exit(1) count = Service.count_hits(file_path=file) - Service.index_hits(variables["arlas"], index=index, file_path=file, bulk_size=bulk, count=count) + Service.index_hits(config, index=index, file_path=file, bulk_size=bulk, count=count) @indices.command(help="Generate the mapping based on the data") @@ -76,6 +92,7 @@ def mapping( field_mapping: list[str] = typer.Option(default=[], help="Overide the mapping with the provided field/type. Example: fragment.location:geo_point"), push_on: str = typer.Option(default=None, help="Push the generated mapping for the provided index name"), ): + config = variables["arlas"] if not os.path.exists(file): print("Error: file \"{}\" not found.".format(file), file=sys.stderr) exit(1) @@ -88,12 +105,12 @@ def mapping( print("Error: invalid field_mapping \"{}\". The format is \"field:type\" like \"fragment.location:geo_point\"".format(fm), file=sys.stderr) exit(1) mapping = make_mapping(file=file, nb_lines=nb_lines, types=types) - if push_on: + if push_on and config: Service.create_index( - variables["arlas"], + config, index=push_on, mapping=mapping) - print("Index {} created on {}".format(push_on, variables["arlas"])) + print("Index {} created on {}".format(push_on, config)) else: print(json.dumps(mapping, indent=2)) @@ -102,19 +119,20 @@ def mapping( def delete( index: str = typer.Argument(help="index's name") ): - if not Configuration.settings.arlas.get(variables["arlas"]).allow_delete: - print("Error: delete on \"{}\" is not allowed. To allow delete, change your configuration file ({}).".format(variables["arlas"], configuration_file), file=sys.stderr) + config = variables["arlas"] + if not Configuration.settings.arlas.get(config).allow_delete: + print("Error: delete on \"{}\" is not allowed. To allow delete, change your configuration file ({}).".format(config, configuration_file), file=sys.stderr) exit(1) - if typer.confirm("You are about to delete the index '{}' on the '{}' configuration.\n".format(index, variables["arlas"]), - prompt_suffix="Do you want to continue (del {} on {})?".format(index, variables["arlas"]), + if typer.confirm("You are about to delete the index '{}' on the '{}' configuration.\n".format(index, config), + prompt_suffix="Do you want to continue (del {} on {})?".format(index, config), default=False, ): - if variables["arlas"] != "local" and variables["arlas"].find("test") < 0: - if typer.prompt("WARNING: You are not on a test environment. To delete {} on {}, type the name of the configuration ({})".format(index, variables["arlas"], variables["arlas"])) != variables["arlas"]: - print("Error: delete on \"{}\" cancelled.".format(variables["arlas"]), file=sys.stderr) + if config != "local" and config.find("test") < 0: + if typer.prompt("WARNING: You are not on a test environment. To delete {} on {}, type the name of the configuration ({})".format(index, config, config)) != config: + print("Error: delete on \"{}\" cancelled.".format(config), file=sys.stderr) exit(1) Service.delete_index( - variables["arlas"], + config, index=index) - print("{} has been deleted on {}.".format(index, variables["arlas"])) + print("{} has been deleted on {}.".format(index, config)) diff --git a/arlas/cli/model_infering.py b/arlas/cli/model_infering.py index 3feffe3..dd2803c 100644 --- a/arlas/cli/model_infering.py +++ b/arlas/cli/model_infering.py @@ -106,7 +106,7 @@ def __type_node__(n, name: str = None) -> str: if all(isinstance(x, (int)) for x in n): if name and (name.find("timestamp") >= 0 or name.find("_date") >= 0 or name.find("date_") >= 0 or name.find("start_") >= 0 or name.find("_start") >= 0 or name.find("_end") >= 0 or name.find("end_") >= 0): # all between year 1950 and 2100, in second or milli second - if all((x > 631152000 and x < 4102444800) for x in n) or all((x > 631152000000 and x < 4102444800000) for x in n): + if all((x > 631152000 and x < 4102444800) for x in n): return "date-epoch_second" if all((x > 631152000000 and x < 4102444800000) for x in n): return "date-epoch_millis" diff --git a/arlas/cli/service.py b/arlas/cli/service.py index 99892a7..3b8ef82 100644 --- a/arlas/cli/service.py +++ b/arlas/cli/service.py @@ -1,7 +1,7 @@ import json import os import sys -from alive_progress import alive_bar, alive_it +from alive_progress import alive_bar import requests from arlas.cli.settings import Configuration, Resource diff --git a/arlas/cli/variables.py b/arlas/cli/variables.py index eefc76d..29af626 100644 --- a/arlas/cli/variables.py +++ b/arlas/cli/variables.py @@ -1,5 +1,6 @@ import os -variables = {} -configuration_file = os.path.join(os.path.expanduser('~'), ".arlas", "cli", "configuration.yaml") +variables = { + "configuration_file": os.path.join(os.path.expanduser('~'), ".arlas", "cli", "configuration.yaml") +} diff --git a/scripts/tests.sh b/scripts/tests.sh index f7ea92e..d1b2e70 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -6,7 +6,7 @@ set -e # ---------------------------------------------------------- echo "TEST default configuration placed in $HOME/.arlas/cli" rm -f $HOME/.arlas/cli/configuration.yaml -python3 -m arlas.cli.cli --help +python3 -m arlas.cli.cli --version FILE=$HOME/.arlas/cli/configuration.yaml if test -f "$FILE"; then echo "OK: $FILE exists." @@ -17,7 +17,7 @@ fi # ---------------------------------------------------------- echo "TEST infer mapping and add mapping on ES" -python3 -m arlas.cli.cli --config local indices mapping tests/sample.json --field-mapping track.timestamps.center:date-epoch_second --field-mapping track.timestamps.start:date-epoch_second --field-mapping track.timestamps.end:date-epoch_second --push-on courses +python3 -m arlas.cli.cli indices --config local mapping tests/sample.json --field-mapping track.timestamps.center:date-epoch_second --field-mapping track.timestamps.start:date-epoch_second --field-mapping track.timestamps.end:date-epoch_second --push-on courses if [ "$? -eq 0" ] ; then echo "OK: Mapping infered and added" else @@ -27,7 +27,7 @@ fi # ---------------------------------------------------------- echo "TEST retrieve mapping from ES" -if python3 -m arlas.cli.cli --config local indices list | grep courses ; then +if python3 -m arlas.cli.cli indices --config local list | grep courses ; then echo "OK: mapping found" else echo "ERROR: mapping not found" @@ -36,7 +36,7 @@ fi # ---------------------------------------------------------- echo "TEST describe mapping from ES" -if python3 -m arlas.cli.cli --config local indices describe courses | grep "track.timestamps.center" | grep "date "; then +if python3 -m arlas.cli.cli indices --config local describe courses | grep "track.timestamps.center" | grep "date "; then echo "OK: describe mapping ok" else echo "ERROR: describe mapping failled" @@ -45,7 +45,7 @@ fi # ---------------------------------------------------------- echo "TEST add data to ES" -python3 -m arlas.cli.cli --config local indices data courses tests/sample.json +python3 -m arlas.cli.cli indices --config local data courses tests/sample.json if [ "$? -eq 0" ] ; then echo "OK: data added" else @@ -56,7 +56,7 @@ sleep 2 # ---------------------------------------------------------- echo "TEST retrieve hits from ES" -if python3 -m arlas.cli.cli --config local indices list | grep courses | grep " 2 "; then +if python3 -m arlas.cli.cli indices --config local list | grep courses | grep " 2 "; then echo "OK: two hits found" else echo "ERROR: hits not found" @@ -66,7 +66,7 @@ fi # ---------------------------------------------------------- echo "TEST add collection" -python3 -m arlas.cli.cli --config local collections create courses --index courses --display-name courses --id-path track.id --centroid-path track.location --geometry-path track.trail --date-path track.timestamps.center +python3 -m arlas.cli.cli collections --config local create courses --index courses --display-name courses --id-path track.id --centroid-path track.location --geometry-path track.trail --date-path track.timestamps.center if [ "$? -eq 0" ] ; then echo "OK: data added" else @@ -77,7 +77,7 @@ sleep 2 # ---------------------------------------------------------- echo "TEST retrieve collection" -if python3 -m arlas.cli.cli --config local collections list | grep courses ; then +if python3 -m arlas.cli.cli collections --config local list | grep courses ; then echo "OK: collection found" else echo "ERROR: collection not found" @@ -86,7 +86,7 @@ fi # ---------------------------------------------------------- echo "TEST describe collection" -python3 -m arlas.cli.cli --config local collections describe courses +python3 -m arlas.cli.cli collections --config local describe courses if [ "$? -eq 0" ] ; then echo "OK: Describe collection ok" else @@ -96,7 +96,7 @@ fi # ---------------------------------------------------------- echo "TEST count collection" -python3 -m arlas.cli.cli --config local collections count courses +python3 -m arlas.cli.cli collections --config local count courses if [ "$? -eq 0" ] ; then echo "OK: Count collection ok" else @@ -107,7 +107,7 @@ fi # ---------------------------------------------------------- echo "TEST delete collection" -yes | python3 -m arlas.cli.cli --config local collections delete courses +yes | python3 -m arlas.cli.cli collections --config local delete courses if [ "$? -eq 0" ] ; then echo "OK: delete collection ok" else @@ -118,7 +118,7 @@ fi sleep 2 # ---------------------------------------------------------- echo "TEST collection deleted" -if python3 -m arlas.cli.cli --config local collections list | grep courses ; then +if python3 -m arlas.cli.cli collections --config local list| grep courses ; then echo "ERROR: collection found, not deleted" exit 1 else @@ -127,7 +127,7 @@ fi # ---------------------------------------------------------- echo "TEST delete index" -yes | python3 -m arlas.cli.cli --config local indices delete courses +yes | python3 -m arlas.cli.cli indices --config local delete courses if [ "$? -eq 0" ] ; then echo "OK: delete index ok" else @@ -140,12 +140,50 @@ sleep 2 # ---------------------------------------------------------- echo "TEST index deleted" -if python3 -m arlas.cli.cli --config local indices list | grep courses ; then +if python3 -m arlas.cli.cli indices --config local list| grep courses ; then echo "ERROR: index found, not deleted" exit 1 else echo "OK: index deleted" fi +# ---------------------------------------------------------- +echo "TEST list configurations" +if python3 -m arlas.cli.cli confs list | grep local ; then + echo "OK: configuration found" +else + echo "ERROR: configuration not found" + exit 1 +fi + +# ---------------------------------------------------------- +echo "TEST create configuration" +python3 -m arlas.cli.cli confs create toto --server http://localhost:9999 +if [ "$? -eq 0" ] ; then + echo "OK: configuration found" +else + echo "ERROR: configuration not found" + exit 1 +fi + +# ---------------------------------------------------------- +echo "TEST configuration added" +if python3 -m arlas.cli.cli confs list | grep toto ; then + echo "OK: configuration found" +else + echo "ERROR: configuration not found" + exit 1 +fi + +# ---------------------------------------------------------- +echo "TEST delete configuration" +python3 -m arlas.cli.cli confs delete toto +if [ "$? -eq 0" ] ; then + echo "OK: configuration deleted" +else + echo "ERROR: configuration not deleted" + exit 1 +fi + ./scripts/stop_stack.sh \ No newline at end of file