|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | +# contributor license agreements. See the NOTICE file distributed with |
| 5 | +# this work for additional information regarding copyright ownership. |
| 6 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | +# (the "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +set -e |
| 19 | + |
| 20 | +# Configuration |
| 21 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 22 | +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" |
| 23 | + |
| 24 | +# Logging functions |
| 25 | +log_info() { |
| 26 | + echo "ℹ️ $1" |
| 27 | +} |
| 28 | + |
| 29 | +log_success() { |
| 30 | + echo "✅ $1" |
| 31 | +} |
| 32 | + |
| 33 | +log_error() { |
| 34 | + echo "❌ $1" >&2 |
| 35 | +} |
| 36 | + |
| 37 | +# Utility function to copy JAR files with version numbers |
| 38 | +copy_jar() { |
| 39 | + local src_pattern="$1" |
| 40 | + local dest_dir="$2" |
| 41 | + local description="$3" |
| 42 | + |
| 43 | + log_info "Copying $description..." |
| 44 | + |
| 45 | + # Find matching files |
| 46 | + local matches=($src_pattern) |
| 47 | + local count=${#matches[@]} |
| 48 | + |
| 49 | + # No files matched |
| 50 | + if (( count == 0 )); then |
| 51 | + log_error "No matching JAR files found: $src_pattern" |
| 52 | + log_error "Please build the Fluss project first: mvn clean package" |
| 53 | + return 1 |
| 54 | + fi |
| 55 | + |
| 56 | + # Multiple files matched |
| 57 | + if (( count > 1 )); then |
| 58 | + log_error "Multiple matching JAR files found:" |
| 59 | + printf " %s\n" "${matches[@]}" |
| 60 | + return 1 |
| 61 | + fi |
| 62 | + |
| 63 | + # Exactly one file matched → copy it with original file name |
| 64 | + mkdir -p "$dest_dir" |
| 65 | + cp "${matches[0]}" "$dest_dir/" |
| 66 | + log_success "Copied: $(basename "${matches[0]}")" |
| 67 | +} |
| 68 | + |
| 69 | +# Utility function to download and verify JAR |
| 70 | +download_jar() { |
| 71 | + local url="$1" |
| 72 | + local dest_file="$2" |
| 73 | + local expected_hash="$3" |
| 74 | + local description="$4" |
| 75 | + |
| 76 | + log_info "Downloading $description..." |
| 77 | + |
| 78 | + # Download the file |
| 79 | + if ! wget -O "$dest_file" "$url"; then |
| 80 | + log_error "Failed to download $description from $url" |
| 81 | + return 1 |
| 82 | + fi |
| 83 | + |
| 84 | + # Verify file size |
| 85 | + if [ ! -s "$dest_file" ]; then |
| 86 | + log_error "Downloaded file is empty: $dest_file" |
| 87 | + return 1 |
| 88 | + fi |
| 89 | + |
| 90 | + # Verify checksum if provided |
| 91 | + if [ -n "$expected_hash" ]; then |
| 92 | + local actual_hash=$(shasum "$dest_file" | awk '{print $1}') |
| 93 | + if [ "$expected_hash" != "$actual_hash" ]; then |
| 94 | + log_error "Checksum mismatch for $description" |
| 95 | + log_error "Expected: $expected_hash" |
| 96 | + log_error "Actual: $actual_hash" |
| 97 | + return 1 |
| 98 | + fi |
| 99 | + log_success "Checksum verified for $description" |
| 100 | + else |
| 101 | + log_success "Downloaded $description" |
| 102 | + fi |
| 103 | +} |
| 104 | + |
| 105 | +# Check if required directories exist |
| 106 | +check_prerequisites() { |
| 107 | + log_info "Checking prerequisites..." |
| 108 | + |
| 109 | + local required_dirs=( |
| 110 | + "$PROJECT_ROOT/fluss-flink/fluss-flink-1.20/target" |
| 111 | + "$PROJECT_ROOT/fluss-lake/fluss-lake-paimon/target" |
| 112 | + "$PROJECT_ROOT/fluss-flink/fluss-flink-tiering/target" |
| 113 | + ) |
| 114 | + |
| 115 | + for dir in "${required_dirs[@]}"; do |
| 116 | + if [ ! -d "$dir" ]; then |
| 117 | + log_error "Required directory not found: $dir" |
| 118 | + log_error "Please build the Fluss project first: mvn clean package" |
| 119 | + exit 1 |
| 120 | + fi |
| 121 | + done |
| 122 | + |
| 123 | + log_success "All prerequisites met" |
| 124 | +} |
| 125 | + |
| 126 | +# Main execution |
| 127 | +main() { |
| 128 | + log_info "Preparing JAR files for Fluss Quickstart Flink Docker..." |
| 129 | + log_info "Project root: $PROJECT_ROOT" |
| 130 | + |
| 131 | + # Check prerequisites |
| 132 | + check_prerequisites |
| 133 | + |
| 134 | + # Clean and create directories |
| 135 | + log_info "Setting up directories..." |
| 136 | + rm -rf lib opt |
| 137 | + mkdir -p lib opt |
| 138 | + |
| 139 | + # Copy Fluss connector JARs |
| 140 | + log_info "Copying Fluss connector JARs..." |
| 141 | + copy_jar "$PROJECT_ROOT/fluss-flink/fluss-flink-1.20/target/fluss-flink-1.20-*.jar" "./lib" "fluss-flink-1.20 connector" |
| 142 | + copy_jar "$PROJECT_ROOT/fluss-lake/fluss-lake-paimon/target/fluss-lake-paimon-*.jar" "./lib" "fluss-lake-paimon connector" |
| 143 | + |
| 144 | + # Download external dependencies |
| 145 | + log_info "Downloading external dependencies..." |
| 146 | + |
| 147 | + # Download flink-faker for data generation |
| 148 | + download_jar \ |
| 149 | + "https://github.com/knaufk/flink-faker/releases/download/v0.5.3/flink-faker-0.5.3.jar" \ |
| 150 | + "./lib/flink-faker-0.5.3.jar" \ |
| 151 | + "" \ |
| 152 | + "flink-faker-0.5.3" |
| 153 | + |
| 154 | + # Download flink-shaded-hadoop-2-uber for Hadoop integration |
| 155 | + download_jar \ |
| 156 | + "https://repo1.maven.org/maven2/io/trino/hadoop/hadoop-apache/3.3.5-2/hadoop-apache-3.3.5-2.jar" \ |
| 157 | + "./lib/hadoop-apache-3.3.5-2.jar" \ |
| 158 | + "508255883b984483a45ca48d5af6365d4f013bb8" \ |
| 159 | + "hadoop-apache-3.3.5-2.jar" |
| 160 | + |
| 161 | + # Download paimon-flink connector |
| 162 | + download_jar \ |
| 163 | + "https://repo1.maven.org/maven2/org/apache/paimon/paimon-flink-1.20/1.2.0/paimon-flink-1.20-1.2.0.jar" \ |
| 164 | + "./lib/paimon-flink-1.20-1.2.0.jar" \ |
| 165 | + "b9f8762c6e575f6786f1d156a18d51682ffc975c" \ |
| 166 | + "paimon-flink-1.20-1.2.0" |
| 167 | + |
| 168 | + # Prepare lake tiering JAR |
| 169 | + log_info "Preparing lake tiering JAR..." |
| 170 | + copy_jar "$PROJECT_ROOT/fluss-flink/fluss-flink-tiering/target/fluss-flink-tiering-*.jar" "./opt" "fluss-flink-tiering" |
| 171 | + |
| 172 | + # Final verification |
| 173 | + verify_jars |
| 174 | + |
| 175 | + # Show summary |
| 176 | + show_summary |
| 177 | +} |
| 178 | + |
| 179 | +# Verify that all required JAR files are present |
| 180 | +verify_jars() { |
| 181 | + log_info "Verifying all required JAR files are present..." |
| 182 | + |
| 183 | + local missing_jars=() |
| 184 | + local lib_jars=( |
| 185 | + "fluss-flink-1.20-*.jar" |
| 186 | + "fluss-lake-paimon-*.jar" |
| 187 | + "flink-faker-0.5.3.jar" |
| 188 | + "hadoop-apache-3.3.5-2.jar" |
| 189 | + "paimon-flink-1.20-1.2.0.jar" |
| 190 | + ) |
| 191 | + |
| 192 | + local opt_jars=( |
| 193 | + "fluss-flink-tiering-*.jar" |
| 194 | + ) |
| 195 | + |
| 196 | + # Check lib directory |
| 197 | + for jar_pattern in "${lib_jars[@]}"; do |
| 198 | + if ! ls ./lib/$jar_pattern >/dev/null 2>&1; then |
| 199 | + missing_jars+=("lib/$jar_pattern") |
| 200 | + fi |
| 201 | + done |
| 202 | + |
| 203 | + # Check opt directory |
| 204 | + for jar_pattern in "${opt_jars[@]}"; do |
| 205 | + if ! ls ./opt/$jar_pattern >/dev/null 2>&1; then |
| 206 | + missing_jars+=("opt/$jar_pattern") |
| 207 | + fi |
| 208 | + done |
| 209 | + |
| 210 | + # Report results |
| 211 | + if [ ${#missing_jars[@]} -eq 0 ]; then |
| 212 | + log_success "All required JAR files are present!" |
| 213 | + else |
| 214 | + log_error "Missing required JAR files:" |
| 215 | + for jar in "${missing_jars[@]}"; do |
| 216 | + log_error " - $jar" |
| 217 | + done |
| 218 | + exit 1 |
| 219 | + fi |
| 220 | +} |
| 221 | + |
| 222 | +# Summary function |
| 223 | +show_summary() { |
| 224 | + log_success "JAR files preparation completed!" |
| 225 | + echo "" |
| 226 | + log_info "📦 Generated JAR files:" |
| 227 | + echo "Lib directory:" |
| 228 | + ls -la ./lib/ 2>/dev/null || echo " (empty)" |
| 229 | + echo "Opt directory:" |
| 230 | + ls -la ./opt/ 2>/dev/null || echo " (empty)" |
| 231 | +} |
| 232 | + |
| 233 | +# Run main function |
| 234 | +main "$@" |
0 commit comments