<commit_before>#!/usr/bin/env bash
################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

if [[ -z $TEST_DATA_DIR ]]; then
  echo "Must run common.sh before elasticsearch-common.sh."
  exit 1
fi

function setup_elasticsearch {
    mkdir -p $TEST_DATA_DIR

    local downloadUrl=$1
    local elasticsearch_version=$2

    if [ -z $elasticsearch_version ]; then
      echo "Elasticsearch version not declared."
      exit 1
    fi

    # start downloading Elasticsearch
    echo "Downloading Elasticsearch from $downloadUrl ..."
    curl "$downloadUrl" > $TEST_DATA_DIR/elasticsearch.tar.gz

    local elasticsearchDir=$TEST_DATA_DIR/elasticsearch
    mkdir -p $elasticsearchDir
    tar xzf $TEST_DATA_DIR/elasticsearch.tar.gz -C $elasticsearchDir --strip-components=1

    if [ `uname -i` == 'aarch64' ] && [ $elasticsearch_version -ge 6 ]; then
      echo xpack.ml.enabled: false >> $elasticsearchDir/config/elasticsearch.yml
    fi

    # start Elasticsearch cluster
    $elasticsearchDir/bin/elasticsearch &
}

function wait_elasticsearch_working {
    echo "Waiting for Elasticsearch node to work..."

    for ((i=1;i<=60;i++)); do
        output=$(curl -XGET 'http://localhost:9200' | grep "cluster_name" || true)

        # make sure the elasticsearch node is actually working
        if [ "${output}" = "" ]; then
            sleep 1
        else
            echo "Elasticsearch node is working."
            return
        fi
    done<commit_msg>[FLINK-17424][e2e] Adopt download strategy of Kafka tests in Elasticsearch tests<commit_after>#!/usr/bin/env bash
################################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

if [[ -z $TEST_DATA_DIR ]]; then
  echo "Must run common.sh before elasticsearch-common.sh."
  exit 1
fi

function setup_elasticsearch {
    mkdir -p $TEST_DATA_DIR

    local downloadUrl=$1
    local elasticsearch_version=$2

    if [ -z $elasticsearch_version ]; then
      echo "Elasticsearch version not declared."
      exit 1
    fi

    # start downloading Elasticsearch
    echo "Downloading Elasticsearch from $downloadUrl ..."
    curl "$downloadUrl" --retry 10 --retry-max-time 120 --output $TEST_DATA_DIR/elasticsearch.tar.gz

    local elasticsearchDir=$TEST_DATA_DIR/elasticsearch
    mkdir -p $elasticsearchDir
    tar xzf $TEST_DATA_DIR/elasticsearch.tar.gz -C $elasticsearchDir --strip-components=1

    if [ `uname -i` == 'aarch64' ] && [ $elasticsearch_version -ge 6 ]; then
      echo xpack.ml.enabled: false >> $elasticsearchDir/config/elasticsearch.yml
    fi

    # start Elasticsearch cluster
    $elasticsearchDir/bin/elasticsearch &
}

function wait_elasticsearch_working {
    echo "Waiting for Elasticsearch node to work..."

    for ((i=1;i<=60;i++)); do
        output=$(curl -XGET 'http://localhost:9200' | grep "cluster_name" || true)

        # make sure the elasticsearch node is actually working
        if [ "${output}" = "" ]; then
            sleep 1
        else
            echo "Elasticsearch node is working."
            return
        fi
    done
{'fraction_non_alphanumeric': 0.14804003336113428, 'fraction_numerical': 0.010633861551292744, 'mean_word_length': 3.5729265967588177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '675654', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1233, 'n_words': 467}