1
1
import org.opensearch.gradle.test.RestIntegTestTask
2
2
3
+ import java.util.concurrent.Callable
3
4
import java.util.regex.Matcher
4
5
import java.util.regex.Pattern
5
6
@@ -36,6 +37,12 @@ buildscript {
36
37
" opensearch" : opensearch_version,
37
38
" prometheus" : " 0.16.0"
38
39
]
40
+
41
+ bwcPluginDownloadLink = ' https://github.com/Aiven-Open/prometheus-exporter-plugin-for-opensearch/releases/download/' +
42
+ project.BWCPluginVersion + ' /prometheus-exporter-' + project.BWCPluginVersion + ' .zip'
43
+ baseName = " bwcCluster"
44
+ bwcFilePath = " src/test/resources/org/opensearch/prometheus-exporter/bwc/"
45
+ bwcPrometheusExporterPath = bwcFilePath + " prometheus-exporter/"
39
46
}
40
47
41
48
repositories {
@@ -46,7 +53,12 @@ buildscript {
46
53
maven { url " https://plugins.gradle.org/m2/" }
47
54
}
48
55
56
+ configurations {
57
+ zipArchive
58
+ }
59
+
49
60
dependencies {
61
+ zipArchive group : ' org.opensearch.plugin.prometheus' , name :' prometheus-exporter' , version : " ${ versions.opensearch} "
50
62
classpath " org.opensearch.gradle:build-tools:${ versions.opensearch} "
51
63
}
52
64
}
@@ -118,6 +130,9 @@ task integTest(type: RestIntegTestTask) {
118
130
description = " Run tests against a cluster"
119
131
testClassesDirs = sourceSets. test. output. classesDirs
120
132
classpath = sourceSets. test. runtimeClasspath
133
+ filter {
134
+ excludeTestsMatching " org.opensearch.plugin.bwc.*IT"
135
+ }
121
136
}
122
137
tasks. named(" check" ). configure { dependsOn(integTest) }
123
138
@@ -146,6 +161,178 @@ testClusters.integTest {
146
161
plugin(project. tasks. bundlePlugin. archiveFile)
147
162
}
148
163
164
+ task copyZIPBundle {
165
+ dependsOn(bundlePlugin)
166
+
167
+ doLast {
168
+ // By using ant.copy we can "hack" around gradle check for other task's resources modification.
169
+ // It seems like a dirty hack but some official plugins seem to use this practice;
170
+ // for instance see https://github.com/opensearch-project/anomaly-detection/
171
+ ant. copy(todir : bwcPrometheusExporterPath + project. version) {
172
+ ant. fileset(dir : ' build/distributions/' , includes : ' prometheus-exporter-' + project. version + ' .zip' )
173
+ }
174
+ }
175
+ }
176
+
177
+ // Clusters for BWC tests
178
+ 2. times { i ->
179
+ testClusters {
180
+ " ${ baseName} $i " {
181
+ versions = [project.BWCversion , " 2.17.1" ]
182
+ numberOfNodes = 3
183
+ plugin(provider(new Callable<RegularFile > () {
184
+ @Override
185
+ RegularFile call () throws Exception {
186
+ return new RegularFile () {
187
+ @Override
188
+ File getAsFile () {
189
+ if (new File (" $project . rootDir /$bwcFilePath /prometheus-exporter/$project . BWCPluginVersion " ). exists()) {
190
+ project. delete(files(" $project . rootDir /$bwcFilePath /prometheus-exporter/$project . BWCPluginVersion " ))
191
+ }
192
+ project. mkdir bwcPrometheusExporterPath + project.BWCPluginVersion
193
+ ant. get(src : bwcPluginDownloadLink,
194
+ dest : bwcPrometheusExporterPath + project.BWCPluginVersion ,
195
+ httpusecaches : false )
196
+ return fileTree(bwcPrometheusExporterPath + project.BWCPluginVersion ). getSingleFile()
197
+ }
198
+ }
199
+ }
200
+ }))
201
+ setting ' path.repo' , " ${ buildDir} /cluster/shared/repo/${ baseName} "
202
+ setting ' http.content_type.required' , ' true'
203
+ }
204
+ }
205
+ }
206
+
207
+ List<Provider<RegularFile > > plugins = [
208
+ provider(new Callable<RegularFile > (){
209
+ @Override
210
+ RegularFile call () throws Exception {
211
+ return new RegularFile () {
212
+ @Override
213
+ File getAsFile () {
214
+ return fileTree(bwcPrometheusExporterPath + project. version). getSingleFile()
215
+ }
216
+ }
217
+ }
218
+ })
219
+ ]
220
+
221
+ // Creates 2 test clusters with 3 nodes of the old version.
222
+ 2. times {i ->
223
+ task " ${ baseName} #oldVersionClusterTask$i " (type : RestIntegTestTask ) {
224
+ useCluster testClusters. " ${ baseName} $i "
225
+ filter {
226
+ includeTestsMatching " org.opensearch.plugin.bwc.*IT"
227
+ }
228
+ systemProperty ' tests.rest.bwcsuite' , ' old_cluster'
229
+ systemProperty ' tests.rest.bwcsuite_round' , ' old'
230
+ systemProperty ' tests.plugin_bwc_version' , project.BWCPluginVersion
231
+ nonInputProperties. systemProperty(' tests.rest.cluster' , " ${ -> testClusters."${baseName}$i".allHttpSocketURI.join(",")} " )
232
+ nonInputProperties. systemProperty(' tests.clustername' , " ${ -> testClusters."${baseName}$i".getName()} " )
233
+ }
234
+ }
235
+
236
+ // Upgrades one node of the old cluster to new OpenSearch version with upgraded plugin version
237
+ // This results in a mixed cluster with 2 nodes on the old version and 1 upgraded node.
238
+ // This is also used as a one third upgraded cluster for a rolling upgrade.
239
+ task " ${ baseName} #mixedClusterTask" (type : RestIntegTestTask ) {
240
+ dependsOn tasks. named(" copyZIPBundle" )
241
+ useCluster testClusters. " ${ baseName} 0"
242
+ dependsOn " ${ baseName} #oldVersionClusterTask0"
243
+ doFirst {
244
+ testClusters. " ${ baseName} 0" . upgradeNodeAndPluginToNextVersion(plugins)
245
+ }
246
+ filter {
247
+ includeTestsMatching " org.opensearch.plugin.bwc.*IT"
248
+ }
249
+ systemProperty ' tests.rest.bwcsuite' , ' mixed_cluster'
250
+ systemProperty ' tests.rest.bwcsuite_round' , ' first'
251
+ systemProperty ' tests.plugin_bwc_version' , project.BWCPluginVersion
252
+ nonInputProperties. systemProperty(' tests.rest.cluster' , " ${ -> testClusters."${baseName}0".allHttpSocketURI.join(",")} " )
253
+ nonInputProperties. systemProperty(' tests.clustername' , " ${ -> testClusters."${baseName}0".getName()} " )
254
+ }
255
+
256
+ // Upgrades the second node to new OpenSearch version with upgraded plugin version after the first node is upgraded.
257
+ // This results in a mixed cluster with 1 node on the old version and 2 upgraded nodes.
258
+ // This is used for rolling upgrade.
259
+ task " ${ baseName} #twoThirdsUpgradedClusterTask" (type : RestIntegTestTask ) {
260
+ dependsOn tasks. named(" copyZIPBundle" )
261
+ dependsOn " ${ baseName} #mixedClusterTask"
262
+ useCluster testClusters. " ${ baseName} 0"
263
+ doFirst {
264
+ testClusters. " ${ baseName} 0" . upgradeNodeAndPluginToNextVersion(plugins)
265
+ }
266
+ filter {
267
+ includeTestsMatching " org.opensearch.plugin.bwc.*IT"
268
+ }
269
+ systemProperty ' tests.rest.bwcsuite' , ' mixed_cluster'
270
+ systemProperty ' tests.rest.bwcsuite_round' , ' second'
271
+ systemProperty ' tests.plugin_bwc_version' , project.BWCPluginVersion
272
+ nonInputProperties. systemProperty(' tests.rest.cluster' , " ${ -> testClusters."${baseName}0".allHttpSocketURI.join(",")} " )
273
+ nonInputProperties. systemProperty(' tests.clustername' , " ${ -> testClusters."${baseName}0".getName()} " )
274
+ }
275
+
276
+ // Upgrades the third node to new OpenSearch version with upgraded plugin version after the second node is upgraded.
277
+ // This results in a fully upgraded cluster.
278
+ // This is used for rolling upgrade.
279
+ task " ${ baseName} #rollingUpgradeClusterTask" (type : RestIntegTestTask ) {
280
+ dependsOn tasks. named(" copyZIPBundle" )
281
+ dependsOn " ${ baseName} #twoThirdsUpgradedClusterTask"
282
+ useCluster testClusters. " ${ baseName} 0"
283
+ doFirst {
284
+ testClusters. " ${ baseName} 0" . upgradeNodeAndPluginToNextVersion(plugins)
285
+ }
286
+ filter {
287
+ includeTestsMatching " org.opensearch.plugin.bwc.*IT"
288
+ }
289
+ mustRunAfter " ${ baseName} #mixedClusterTask"
290
+ systemProperty ' tests.rest.bwcsuite' , ' mixed_cluster'
291
+ systemProperty ' tests.rest.bwcsuite_round' , ' third'
292
+ systemProperty ' tests.plugin_bwc_version' , project.BWCPluginVersion
293
+ nonInputProperties. systemProperty(' tests.rest.cluster' , " ${ -> testClusters."${baseName}0".allHttpSocketURI.join(",")} " )
294
+ nonInputProperties. systemProperty(' tests.clustername' , " ${ -> testClusters."${baseName}0".getName()} " )
295
+ }
296
+
297
+ // Upgrades all the nodes of the old cluster to new OpenSearch version with upgraded plugin version
298
+ // at the same time resulting in a fully upgraded cluster.
299
+ task " ${ baseName} #fullRestartClusterTask" (type : RestIntegTestTask ) {
300
+ dependsOn tasks. named(" copyZIPBundle" )
301
+ dependsOn " ${ baseName} #oldVersionClusterTask1"
302
+ useCluster testClusters. " ${ baseName} 1"
303
+ doFirst {
304
+ testClusters. " ${ baseName} 1" . upgradeAllNodesAndPluginsToNextVersion(plugins)
305
+ }
306
+ filter {
307
+ includeTestsMatching " org.opensearch.plugin.bwc.*IT"
308
+ }
309
+ systemProperty ' tests.rest.bwcsuite' , ' upgraded_cluster'
310
+ systemProperty ' tests.plugin_bwc_version' , project.BWCPluginVersion
311
+ nonInputProperties. systemProperty(' tests.rest.cluster' , " ${ -> testClusters."${baseName}1".allHttpSocketURI.join(",")} " )
312
+ nonInputProperties. systemProperty(' tests.clustername' , " ${ -> testClusters."${baseName}1".getName()} " )
313
+ }
314
+
315
+ // A BWC test suite which runs all the bwc tasks combined.
316
+ task bwcTestSuite (type : RestIntegTestTask ) {
317
+
318
+ // Delete all downloaded and built plugin ZIP files.
319
+ // Again – we are using ant task to workaround gradle resources modification alert.
320
+ doFirst {
321
+ ant. delete(includeEmptyDirs : true , verbose : true , removeNotFollowedSymlinks : true ) {
322
+ ant. fileset(
323
+ dir : ' src/test/resources/org/opensearch/prometheus-exporter/bwc/prometheus-exporter'
324
+ )
325
+ }
326
+ }
327
+
328
+ exclude ' **/*Test*'
329
+ exclude ' **/*IT*'
330
+
331
+ dependsOn tasks. named(" ${ baseName} #mixedClusterTask" )
332
+ dependsOn tasks. named(" ${ baseName} #rollingUpgradeClusterTask" )
333
+ dependsOn tasks. named(" ${ baseName} #fullRestartClusterTask" )
334
+ }
335
+
149
336
run {
150
337
useCluster testClusters. integTest
151
338
}
0 commit comments