xintongsong commented on code in PR #708:
URL: https://github.com/apache/flink-agents/pull/708#discussion_r3329897267


##########
e2e-test/test-scripts/test_submit_examples_to_flink.sh:
##########
@@ -0,0 +1,339 @@
+#!/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.
+#
+#
+# Submits the Java/Python examples to a local Flink standalone cluster and
+# checks that the JobManager accepts each one. The examples talk to remote
+# LLM APIs, so we only verify submission, then cancel the jobs.
+#
+# Env: FLINK_VERSION (default 2.2.0), FLINK_HOME (reuse existing install),
+#      VERBOSE=1 (set -x).
+
+set -euo pipefail
+
+if [[ "${VERBOSE:-0}" == "1" ]]; then
+    set -x
+fi
+
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[0;33m'
+BLUE='\033[0;34m'
+NC='\033[0m'
+
+log_info()    { printf "${BLUE}[INFO]${NC}  %s\n"  "$*"; }
+log_ok()      { printf "${GREEN}[OK]${NC}    %s\n" "$*"; }
+log_warn()    { printf "${YELLOW}[WARN]${NC}  %s\n" "$*"; }
+log_error()   { printf "${RED}[ERROR]${NC} %s\n"   "$*" >&2; }
+log_section() {
+    printf 
"\n${BLUE}==============================================================${NC}\n"
+    printf "${BLUE}>>> %s${NC}\n" "$*"
+    printf   
"${BLUE}==============================================================${NC}\n"
+}
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT_DIR="$(cd "$SCRIPT_DIR/../.."; pwd)"
+log_info "Project root: $ROOT_DIR"
+
+FLINK_VERSION="${FLINK_VERSION:-2.2.0}"
+FLINK_MAJOR_MINOR="${FLINK_VERSION%.*}"
+SUBMIT_TIMEOUT="${SUBMIT_TIMEOUT:-180}"
+
+# Bash 3 (default on macOS) lacks associative arrays.
+RESULT_NAMES=()
+RESULT_STATES=()
+SUBMITTED_JOB_IDS=()
+
+cleanup() {
+    local exit_code=$?
+    log_section "Cleanup"
+
+    if [[ -n "${FLINK_HOME:-}" && -x "$FLINK_HOME/bin/flink" ]]; then
+        for jid in "${SUBMITTED_JOB_IDS[@]:-}"; do
+            [[ -n "$jid" ]] || continue
+            log_info "Cancelling job $jid"
+            "$FLINK_HOME/bin/flink" cancel "$jid" >/dev/null 2>&1 || true
+        done
+
+        if [[ -x "$FLINK_HOME/bin/stop-cluster.sh" ]]; then
+            log_info "Stopping Flink cluster"
+            "$FLINK_HOME/bin/stop-cluster.sh" >/dev/null 2>&1 || true
+        fi
+
+        if [[ -d "$FLINK_HOME/log" ]]; then
+            local log_archive="$ROOT_DIR/flink-logs-$(date 
+%Y%m%d-%H%M%S).tar.gz"
+            tar -czf "$log_archive" -C "$FLINK_HOME" log >/dev/null 2>&1 \
+                && log_info "Flink logs archived to: $log_archive" \
+                || log_warn "Failed to archive Flink logs"
+        fi
+    fi
+
+    print_summary
+    exit "$exit_code"
+}
+trap cleanup EXIT
+
+print_summary() {
+    log_section "Test summary"
+    local total=${#RESULT_NAMES[@]}
+    local passed=0
+    local failed=0
+    local i
+    for (( i = 0; i < total; i++ )); do
+        local name="${RESULT_NAMES[$i]}"
+        local state="${RESULT_STATES[$i]}"
+        if [[ "$state" == "PASS" ]]; then
+            printf "  ${GREEN}PASS${NC}  %s\n" "$name"
+            passed=$((passed + 1))
+        else
+            printf "  ${RED}FAIL${NC}  %s\n" "$name"
+            failed=$((failed + 1))
+        fi
+    done
+    printf "\nTotal: %d   Passed: %d   Failed: %d\n" "$total" "$passed" 
"$failed"
+
+    if (( failed > 0 )); then
+        log_error "$failed example(s) failed to submit"
+        exit 1
+    fi
+}
+
+record_result() {
+    RESULT_NAMES+=("$1")
+    RESULT_STATES+=("$2")
+}
+
+install_flink() {
+    log_section "Step 1: install Flink standalone (version $FLINK_VERSION)"
+
+    if [[ -n "${FLINK_HOME:-}" && -x "$FLINK_HOME/bin/flink" ]]; then
+        log_info "Reusing existing FLINK_HOME: $FLINK_HOME"
+        export FLINK_HOME
+        return 0
+    fi
+
+    # Anchor VENV_DIR to the repo so we can find it after install.sh exits.
+    export VENV_DIR="${VENV_DIR:-$ROOT_DIR/.flink-agents-env}"
+
+    log_info "Running tools/install.sh --non-interactive --install-flink 
--enable-pyflink"
+    FLINK_VERSION="$FLINK_VERSION" bash "$ROOT_DIR/tools/install.sh" \
+        --non-interactive --install-flink --enable-pyflink
+
+    local install_dir="${INSTALL_DIR:-$HOME/.local/flink}"
+    export FLINK_HOME="${install_dir}/flink-${FLINK_VERSION}"
+
+    if [[ ! -x "$FLINK_HOME/bin/flink" ]]; then
+        log_error "Flink installation not found at expected path: $FLINK_HOME"
+        exit 1
+    fi
+    log_ok "Flink installed at: $FLINK_HOME"
+
+    # `flink run -py` shells out to a Python interpreter that must have
+    # pyflink importable. Activate the venv install.sh provisioned and
+    # point PYFLINK_CLIENT_EXECUTABLE at it.
+    if [[ ! -x "$VENV_DIR/bin/python" ]]; then
+        log_error "Expected Python venv not found at: $VENV_DIR"
+        exit 1
+    fi
+    # shellcheck disable=SC1091
+    source "$VENV_DIR/bin/activate"
+    export PYFLINK_CLIENT_EXECUTABLE="$VENV_DIR/bin/python"
+    log_ok "Activated PyFlink venv: $VENV_DIR"
+}
+
+build_project() {
+    log_section "Step 2: build flink-agents (Java + Python)"
+    (
+        cd "$ROOT_DIR"
+        SKIP_SPOTLESS_CHECK=true bash tools/build.sh
+    )
+    log_ok "Build completed"
+}
+
+stage_dist_jars() {
+    log_section "Step 3: stage dist uber jar into \$FLINK_HOME/lib"
+
+    local project_version
+    project_version=$(sed -n 's/.*<version>\(.*\)<\/version>.*/\1/p' \
+        "$ROOT_DIR/pom.xml" | head -n 2 | tail -n 1)
+    log_info "Detected project version: $project_version"
+
+    # The flink-version uber jar already bundles the common deps.
+    local 
flink_jar="$ROOT_DIR/dist/flink-${FLINK_MAJOR_MINOR}/target/flink-agents-dist-flink-${FLINK_MAJOR_MINOR}-${project_version}.jar"
+
+    if [[ ! -f "$flink_jar" ]]; then
+        log_error "Flink dist jar not found: $flink_jar"
+        exit 1
+    fi
+
+    cp "$flink_jar"  "$FLINK_HOME/lib/"
+    log_ok "Staged: $(basename "$flink_jar")"
+}
+
+package_examples() {

Review Comment:
   I think `build_project` should have already built the examples. We should 
not need to re-build them.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to