forked from taraslayshchuk/es2csv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7187ac
commit fc5d922
Showing
7 changed files
with
331 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
STACK_VERSION=8.9.0 | ||
NODES=1 | ||
PORT=9200 | ||
SECURITY_ENABLED=true | ||
ELASTICSEARCH_PASSWORD=verysecure | ||
PLUGINS="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Elasticsearch test cases.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Client Test cases.""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from typing_extensions import Self | ||
|
||
from esxport.elastic import ElasticsearchClient | ||
|
||
|
||
class TestElasticsearchClient: | ||
"""Elastic Client Test cases.""" | ||
|
||
def test_index_exists(self: Self, es_index: str, elastic_client: ElasticsearchClient) -> None: | ||
"""Test client return true when index exists.""" | ||
assert elastic_client.indices_exists(index=es_index) is True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
#!/bin/bash | ||
|
||
set -o allexport | ||
source test/.env | ||
set +o allexport | ||
set -euxo pipefail | ||
|
||
if [[ -z $STACK_VERSION ]]; then | ||
echo -e "\033[31;1mERROR:\033[0m Required environment variable [STACK_VERSION] not set\033[0m" | ||
exit 1 | ||
fi | ||
|
||
MAJOR_VERSION="$(echo "${STACK_VERSION}" | cut -c 1)" | ||
network_name=elastic | ||
if ! docker network inspect "$network_name" &>/dev/null; then | ||
docker network create "$network_name" | ||
echo "Created network: $network_name" | ||
else | ||
echo "Network $network_name already exists." | ||
fi | ||
|
||
mkdir -p "$(pwd)"/es/plugins | ||
|
||
if [[ ! -z $PLUGINS ]]; then | ||
docker run --rm \ | ||
--network=elastic \ | ||
-v "$(pwd)"/es/plugins/:/usr/share/elasticsearch/plugins/ \ | ||
--entrypoint=/usr/share/elasticsearch/bin/elasticsearch-plugin \ | ||
docker.elastic.co/elasticsearch/elasticsearch:"${STACK_VERSION}" \ | ||
install "${PLUGINS/\\n/ }" --batch | ||
fi | ||
|
||
for (( node=1; node<=${NODES-1}; node++ )) | ||
do | ||
port_com=$((9300 + node - 1)) | ||
UNICAST_HOSTS+="es$node:${port_com}," | ||
done | ||
|
||
for (( node=1; node<=${NODES-1}; node++ )) | ||
do | ||
port=$((${PORT:-9200} + node - 1)) | ||
port_com=$((9300 + node - 1)) | ||
if [ "x${MAJOR_VERSION}" == 'x6' ]; then | ||
docker run \ | ||
--rm \ | ||
--env "node.name=es${node}" \ | ||
--env "cluster.name=docker-elasticsearch" \ | ||
--env "cluster.routing.allocation.disk.threshold_enabled=false" \ | ||
--env "bootstrap.memory_lock=true" \ | ||
--env "ES_JAVA_OPTS=-Xms1g -Xmx1g" \ | ||
--env "xpack.security.enabled=false" \ | ||
--env "xpack.license.self_generated.type=basic" \ | ||
--env "discovery.zen.ping.unicast.hosts=${UNICAST_HOSTS}" \ | ||
--env "discovery.zen.minimum_master_nodes=${NODES}" \ | ||
--env "http.port=${port}" \ | ||
--ulimit nofile=65536:65536 \ | ||
--ulimit memlock=-1:-1 \ | ||
--publish "${port}:${port}" \ | ||
--publish "${port_com}:${port_com}" \ | ||
--detach \ | ||
--network=elastic \ | ||
--name="es${node}" \ | ||
-v "$(pwd)"/es/plugins/:/usr/share/elasticsearch/plugins/ \ | ||
docker.elastic.co/elasticsearch/elasticsearch:"${STACK_VERSION}" | ||
elif [ "x${MAJOR_VERSION}" == 'x7' ]; then | ||
docker run \ | ||
--rm \ | ||
--env "node.name=es${node}" \ | ||
--env "cluster.name=docker-elasticsearch" \ | ||
--env "cluster.initial_master_nodes=es1" \ | ||
--env "discovery.seed_hosts=es1" \ | ||
--env "cluster.routing.allocation.disk.threshold_enabled=false" \ | ||
--env "bootstrap.memory_lock=true" \ | ||
--env "ES_JAVA_OPTS=-Xms1g -Xmx1g" \ | ||
--env "xpack.security.enabled=false" \ | ||
--env "xpack.license.self_generated.type=basic" \ | ||
--env "http.port=${port}" \ | ||
--env "action.destructive_requires_name=false" \ | ||
--ulimit nofile=65536:65536 \ | ||
--ulimit memlock=-1:-1 \ | ||
--publish "${port}:${port}" \ | ||
--detach \ | ||
--network=elastic \ | ||
--name="es${node}" \ | ||
-v "$(pwd)"/es/plugins/:/usr/share/elasticsearch/plugins/ \ | ||
docker.elastic.co/elasticsearch/elasticsearch:"${STACK_VERSION}" | ||
elif [ "x${MAJOR_VERSION}" == 'x8' ]; then | ||
if [ "${SECURITY_ENABLED}" == 'true' ]; then | ||
elasticsearch_password=${ELASTICSEARCH_PASSWORD-'changeme'} | ||
docker run \ | ||
--rm \ | ||
--env "ELASTIC_PASSWORD=${elasticsearch_password}" \ | ||
--env "xpack.license.self_generated.type=basic" \ | ||
--env "node.name=es${node}" \ | ||
--env "cluster.name=docker-elasticsearch" \ | ||
--env "cluster.initial_master_nodes=es1" \ | ||
--env "discovery.seed_hosts=es1" \ | ||
--env "cluster.routing.allocation.disk.threshold_enabled=false" \ | ||
--env "bootstrap.memory_lock=true" \ | ||
--env "ES_JAVA_OPTS=-Xms1g -Xmx1g" \ | ||
--env "http.port=${port}" \ | ||
--env "action.destructive_requires_name=false" \ | ||
--ulimit nofile=65536:65536 \ | ||
--ulimit memlock=-1:-1 \ | ||
--publish "${port}:${port}" \ | ||
--network=elastic \ | ||
--name="es${node}" \ | ||
--detach \ | ||
-v "$(pwd)"/es/plugins/:/usr/share/elasticsearch/plugins/ \ | ||
docker.elastic.co/elasticsearch/elasticsearch:"${STACK_VERSION}" | ||
else | ||
docker run \ | ||
--rm \ | ||
--env "xpack.security.enabled=false" \ | ||
--env "node.name=es${node}" \ | ||
--env "cluster.name=docker-elasticsearch" \ | ||
--env "cluster.initial_master_nodes=es1" \ | ||
--env "discovery.seed_hosts=es1" \ | ||
--env "cluster.routing.allocation.disk.threshold_enabled=false" \ | ||
--env "bootstrap.memory_lock=true" \ | ||
--env "ES_JAVA_OPTS=-Xms1g -Xmx1g" \ | ||
--env "xpack.license.self_generated.type=basic" \ | ||
--env "http.port=${port}" \ | ||
--env "action.destructive_requires_name=false" \ | ||
--ulimit nofile=65536:65536 \ | ||
--ulimit memlock=-1:-1 \ | ||
--publish "${port}:${port}" \ | ||
--network=elastic \ | ||
--name="es${node}" \ | ||
--detach \ | ||
-v "$(pwd)"/es/plugins/:/usr/share/elasticsearch/plugins/ \ | ||
docker.elastic.co/elasticsearch/elasticsearch:"${STACK_VERSION}" | ||
fi | ||
fi | ||
done | ||
|
||
if [ "x${MAJOR_VERSION}" == 'x8' ] && [ "${SECURITY_ENABLED}" == 'true' ]; then | ||
docker run \ | ||
--network elastic \ | ||
--rm \ | ||
alpine/curl \ | ||
--max-time 120 \ | ||
--retry 120 \ | ||
--retry-delay 1 \ | ||
--retry-connrefused \ | ||
--show-error \ | ||
--silent \ | ||
-k \ | ||
-u elastic:"${ELASTICSEARCH_PASSWORD-'changeme'}" \ | ||
https://es1:"$PORT" | ||
else | ||
docker run \ | ||
--network elastic \ | ||
--rm \ | ||
alpine/curl \ | ||
--max-time 120 \ | ||
--retry 120 \ | ||
--retry-delay 1 \ | ||
--retry-connrefused \ | ||
--show-error \ | ||
--silent \ | ||
http://es1:"$PORT" | ||
fi | ||
|
||
|
||
echo "Elasticsearch up and running" |