-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbuild.gradle
More file actions
336 lines (288 loc) · 10.5 KB
/
build.gradle
File metadata and controls
336 lines (288 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
plugins {
id 'java'
id 'application'
id 'base'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.diffplug.spotless' version '7.1.0'
}
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
application {
mainClass = 'Gateway'
}
repositories {
mavenCentral()
maven {
url "https://ci.opensearch.org/ci/dbc/snapshots/maven/"
}
maven {
url "https://jitpack.io"
}
}
ext {
// ALSO CHANGE sql_version.py's version
// TODO: single source of truth
sqlPluginVersion = "3.4.0"
opensearchClientVersion = '3.2.0'
}
dependencies {
// SQL deps
implementation files('submodule/datasources-3.1.0.0-SNAPSHOT.jar')
implementation "org.opensearch.query:unified-query-common:${project.ext.sqlPluginVersion}.0-SNAPSHOT"
implementation "org.opensearch.query:unified-query-core:${project.ext.sqlPluginVersion}.0-SNAPSHOT"
implementation "org.opensearch.query:unified-query-opensearch:${project.ext.sqlPluginVersion}.0-SNAPSHOT"
implementation "org.opensearch.query:unified-query-ppl:${project.ext.sqlPluginVersion}.0-SNAPSHOT"
implementation "org.opensearch.query:unified-query-sql:${project.ext.sqlPluginVersion}.0-SNAPSHOT"
implementation "org.opensearch.query:unified-query-protocol:${project.ext.sqlPluginVersion}.0-SNAPSHOT"
// Clients
implementation "org.opensearch.client:opensearch-rest-high-level-client:${opensearchClientVersion}"
implementation "org.opensearch.client:opensearch-rest-client:${opensearchClientVersion}"
implementation "org.opensearch.client:opensearch-java:${opensearchClientVersion}"
// AWS SDK v2
implementation 'software.amazon.awssdk:sdk-core:2.31.63'
implementation 'software.amazon.awssdk:auth:2.31.63'
implementation 'software.amazon.awssdk:regions:2.31.63'
implementation 'software.amazon.awssdk:apache-client:2.31.63'
implementation 'software.amazon.awssdk:sts:2.31.63'
implementation 'software.amazon.awssdk:aws-core:2.31.63'
// Logging
implementation 'org.apache.logging.log4j:log4j-core:2.25.0'
implementation 'org.apache.logging.log4j:log4j-api:2.25.0'
// Logback
implementation 'ch.qos.logback:logback-classic:1.5.18'
// Apache Commons Configuration for YAML file parsing
implementation 'org.apache.commons:commons-configuration2:2.12.0'
implementation 'commons-beanutils:commons-beanutils:1.11.0'
implementation 'org.yaml:snakeyaml:2.2'
// JSON
implementation 'org.json:json:20250517'
implementation 'com.google.code.gson:gson:2.13.1'
// Guice, dependency injection
implementation 'com.google.inject:guice:7.0.0'
// Py4J
implementation 'net.sf.py4j:py4j:0.10.9.9'
// HTTP5
implementation 'org.apache.httpcomponents.core5:httpcore5:5.2'
implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.1'
// Testing
testImplementation "org.junit.jupiter:junit-jupiter-api:5.14.0"
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.14.0"
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
}
configurations {
sharedDependency
implementation {
extendsFrom sharedDependency
}
}
// Define source sets
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
}
}
jar {
archiveBaseName.set("opensearchsql")
}
test {
useJUnitPlatform()
}
// Python venv and pytest tasks
task setupVenv(type: Exec) {
description = 'Create Python virtual environment if it does not exist'
group = 'verification'
commandLine 'bash', '-c', '''
if [ ! -d "venv" ]; then
python3 -m venv venv
fi
'''
}
task installPythonDeps(type: Exec) {
description = 'Install Python dependencies in venv'
group = 'verification'
dependsOn setupVenv
commandLine 'bash', '-c', 'source venv/bin/activate && pip install -r requirements-dev.txt'
}
// Test cluster management tasks
task cloneOrPullSqlRepo(type: Exec) {
description = 'Clone or pull the SQL repository for testing'
group = 'verification'
def skipPull = project.findProperty('skipSqlRepoPull') ?: 'false'
commandLine 'bash', '-c', """
if [ -d "remote/sql/.git" ]; then
if [ "${skipPull}" = "true" ]; then
echo "Skipping git pull for remote/sql (skipSqlRepoPull=true)"
else
echo "Pulling latest changes in remote/sql..."
cd remote/sql && git pull
fi
else
echo "Cloning SQL repository..."
mkdir -p remote
git clone https://github.com/opensearch-project/sql.git remote/sql
fi
"""
}
task startTestCluster(type: Exec) {
description = 'Start OpenSearch test cluster in background (or detect existing)'
group = 'verification'
dependsOn cloneOrPullSqlRepo
commandLine 'bash', '-c', '''
set -e
mkdir -p build
# Check if cluster is already running
if curl -s http://localhost:9200 > /dev/null 2>&1; then
echo "Cluster already running at localhost:9200"
echo "Using existing cluster (will not stop it later)"
touch build/cluster.external
rm -f build/cluster.pid
exit 0
fi
# No cluster running, start our own
echo "No cluster detected, starting test cluster..."
rm -f build/cluster.external
cd remote/sql
# Stop any existing cluster we started previously
if [ -f "../../build/cluster.pid" ]; then
OLD_PID=$(cat ../../build/cluster.pid)
if ps -p $OLD_PID > /dev/null 2>&1; then
echo "Stopping previous cluster (PID: $OLD_PID)..."
kill $OLD_PID || true
sleep 5
fi
rm -f ../../build/cluster.pid
fi
# Start the cluster in background
nohup ./gradlew run > ../../build/cluster.log 2>&1 &
echo $! > ../../build/cluster.pid
echo "Cluster started with PID: $(cat ../../build/cluster.pid)"
'''
}
task waitForCluster(type: Exec) {
description = 'Wait for OpenSearch cluster to be ready'
group = 'verification'
dependsOn startTestCluster
commandLine 'bash', '-c', '''
# Quick check if cluster is already ready
if curl -s http://localhost:9200 > /dev/null 2>&1; then
echo "Cluster is ready!"
exit 0
fi
echo "Waiting for cluster to be ready..."
for i in {1..300}; do
if curl -s http://localhost:9200 > /dev/null 2>&1; then
echo "Cluster is ready!"
exit 0
fi
echo "Attempt $i/300: Cluster not ready yet, waiting..."
sleep 2
done
echo "Cluster failed to start within timeout"
exit 1
'''
}
task loadTestData(type: Exec) {
description = 'Load test data into OpenSearch cluster (idempotent)'
group = 'verification'
dependsOn waitForCluster
commandLine 'bash', '-c', '''
# Check if accounts index already exists with data
COUNT=$(curl -s "localhost:9200/accounts/_count" 2>/dev/null | grep -o '"count":[0-9]*' | grep -o '[0-9]*' || echo "0")
if [ "$COUNT" -gt "0" ]; then
echo "Test data already loaded (found $COUNT documents in accounts index)"
echo "Skipping data load"
exit 0
fi
echo "Loading test data..."
# Delete index if it exists but is empty
curl -s -X DELETE "localhost:9200/accounts" > /dev/null 2>&1 || true
# Load the data
curl -X POST "localhost:9200/accounts/_bulk" \
-H "Content-Type: application/x-ndjson" \
--data-binary @test_data/accounts.json
echo ""
echo "Test data loaded successfully"
'''
}
task pytest(type: Exec) {
description = 'Run pytest tests'
group = 'verification'
dependsOn installPythonDeps, loadTestData
workingDir = file('.')
commandLine 'bash', '-c', 'source venv/bin/activate && pytest src/main/python/opensearchsql_cli/tests/ -v'
// Fail the build if pytest fails
ignoreExitValue = false
}
task stopTestCluster(type: Exec) {
description = 'Stop the OpenSearch test cluster (only if we started it)'
group = 'verification'
commandLine 'bash', '-c', '''
# Don't stop external clusters
if [ -f "build/cluster.external" ]; then
echo "Cluster is external (not started by us), leaving it running"
rm -f build/cluster.external
exit 0
fi
# Stop cluster we started
if [ -f "build/cluster.pid" ]; then
PID=$(cat build/cluster.pid)
if ps -p $PID > /dev/null 2>&1; then
echo "Stopping cluster (PID: $PID)..."
kill $PID || true
sleep 2
# Force kill if still running
if ps -p $PID > /dev/null 2>&1; then
kill -9 $PID || true
fi
fi
rm -f build/cluster.pid
echo "Cluster stopped"
else
echo "No cluster to stop"
fi
'''
}
// Make test task depend on pytest (Python tests must pass for build to succeed)
test.dependsOn pytest
// Stop cluster after all tests complete (not just pytest)
test.finalizedBy stopTestCluster
spotless {
java {
target fileTree('.') {
include '**/*.java'
exclude '**/build/**', '**/build-*/**', 'src/main/gen/**'
}
importOrder()
licenseHeader("/*\n" +
" * Copyright OpenSearch Contributors\n" +
" * SPDX-License-Identifier: Apache-2.0\n" +
" */\n\n")
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format')
}
}
shadowJar {
archiveBaseName.set('opensearchsqlcli')
duplicatesStrategy = DuplicatesStrategy.FAIL
zip64 = true
manifest {
attributes 'Main-Class': 'Gateway'
attributes 'Multi-Release': 'true'
}
from(sourceSets.main.output)
configurations = [project.configurations.runtimeClasspath]
transform(Log4j2PluginsCacheFileTransformer)
transform(ServiceFileTransformer)
mergeServiceFiles()
mergeServiceFiles('META-INF/services/')
mergeServiceFiles('META-INF/spring/')
}