generated from opensearch-project/opensearch-plugin-template-java
-
Notifications
You must be signed in to change notification settings - Fork 44
/
build.gradle
342 lines (298 loc) · 13.7 KB
/
build.gradle
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
337
338
339
340
341
342
import org.opensearch.gradle.test.RestIntegTestTask
import java.util.concurrent.Callable
import java.util.regex.Matcher
import java.util.regex.Pattern
buildscript {
ext {
// Four {digit(s)} concatenated with a "." followed by -rc{digit(s)}
// Examples: 1.0.0.1-rc2, 2.10.4.0-rc5
// Group (3) refers to the last .{digit{(s)} pattern (this is what we want to remove for OpS version)
final Pattern RC_pattern = Pattern.compile(/([0-9](\.[0-9]+){2})(\.[0-9]+)(-rc[0-9]+)$/)
// Four {digit(s)} concatenated with a "." followed by null or -SNAPSHOT
// Examples: 1.0.0.1, 2.10.4.0-SNAPSHOT
// Group (3) refers to the last .{digit{(s)} pattern (this is what we want to remove for OpS version)
final Pattern OTHER_pattern = Pattern.compile(/([0-9](\.[0-9]+){2})(\.[0-9]+)(|-SNAPSHOT)$/)
String opensearch_version
String plugin_version = version
Matcher rc_matcher = RC_pattern.matcher(plugin_version)
Matcher other_matcher = OTHER_pattern.matcher(plugin_version)
println("Identifing version of OpenSearch based on plugin version")
if (rc_matcher.find()) {
opensearch_version = rc_matcher.group(1) + rc_matcher.group(4)
} else if (other_matcher.find()) {
opensearch_version = other_matcher.group(1)
} else {
throw new InvalidUserDataException("Invalid plugin version [" + version + "] in gradle.properties file.")
}
println("- OpenSearch version: " + opensearch_version)
println("- Prometheus exporter plugin version: " + plugin_version)
versions = [
"opensearch": opensearch_version,
"prometheus": "0.16.0"
]
bwcPluginDownloadLink = 'https://github.com/Aiven-Open/prometheus-exporter-plugin-for-opensearch/releases/download/' +
project.BWCPluginVersion + '/prometheus-exporter-' + project.BWCPluginVersion + '.zip'
baseName = "bwcCluster"
bwcFilePath = "src/test/resources/org/opensearch/prometheus-exporter/bwc/"
bwcPrometheusExporterPath = bwcFilePath + "prometheus-exporter/"
}
repositories {
mavenLocal()
maven { url "https://aws.oss.sonatype.org/content/repositories/releases" }
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
configurations {
zipArchive
}
dependencies {
zipArchive group: 'org.opensearch.plugin.prometheus', name:'prometheus-exporter', version: "${versions.opensearch}"
classpath "org.opensearch.gradle:build-tools:${versions.opensearch}"
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.yaml-rest-test'
//apply plugin: 'checkstyle'
def pluginName = pluginName
def pluginDescription = pluginDescription
//def projectPath = 'org.opensearch'
//def pathToPlugin = 'path.to.plugin'
def pluginClassName = pluginClassname
opensearchplugin {
name pluginName
description pluginDescription
// classname "${projectPath}.${pathToPlugin}.${pluginClassName}"
classname pluginClassName
licenseFile rootProject.file('LICENSE.txt')
noticeFile rootProject.file('NOTICE.txt')
}
// thirdparty audit needs can be enabled
thirdPartyAudit.enabled = false
// This requires an additional Jar not published as part of build-tools
loggerUsageCheck.enabled = false
// No need to validate pom, as we do not upload to maven/sonatype
validateNebulaPom.enabled = false
repositories {
mavenLocal()
maven { url "https://aws.oss.sonatype.org/content/repositories/releases" }
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
jcenter()
}
dependencies {
// Deprecated in Gradle 6.8.1, use "implementation" instead
// See https://docs.gradle.org/6.8.1/userguide/java_plugin.html#sec:java_plugin_and_dependency_management
// compile "io.prometheus:simpleclient:${versions.prometheus}"
// compile "io.prometheus:simpleclient_common:${versions.prometheus}"
implementation group: 'io.prometheus', name: 'simpleclient', version: '0.16.0'
implementation group: 'io.prometheus', name: 'simpleclient_common', version: '0.16.0'
}
restResources {
restApi {
includeCore '_common', 'cat', 'cluster', 'nodes', 'indices', 'index'
}
}
test {
include '**/*Tests.class'
}
// Print more details if any deprecated APIs are used
tasks.withType(JavaCompile) {
options.compilerArgs += ['-Xlint:deprecation']
}
task integTest(type: RestIntegTestTask) {
description = "Run tests against a cluster"
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
filter {
excludeTestsMatching "org.opensearch.plugin.bwc.*IT"
}
}
tasks.named("check").configure { dependsOn(integTest) }
// Temporary disable task :testingConventions
testingConventions.enabled = false
testClusters.all {
numberOfNodes = 2
// It seems cluster name can not be customized here. It gives an error:
// Testclusters does not allow the following settings to be changed:[cluster.name] for node{::yamlRestTest-0}
// setting 'cluster.name', 'PrometheusExporterITCluster'
}
integTest {
// The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable
if (System.getProperty("test.debug") != null) {
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
}
}
testClusters.integTest {
testDistribution = "INTEG_TEST"
// This installs our plugin into the testClusters
plugin(project.tasks.bundlePlugin.archiveFile)
}
task copyZIPBundle {
dependsOn(bundlePlugin)
doLast {
// By using ant.copy we can "hack" around gradle check for other task's resources modification.
// It seems like a dirty hack but some official plugins seem to use this practice;
// for instance see https://github.com/opensearch-project/anomaly-detection/
ant.copy(todir: bwcPrometheusExporterPath + project.version) {
ant.fileset(dir: 'build/distributions/', includes: 'prometheus-exporter-' + project.version + '.zip')
}
}
}
// A hack. For some reason we can not reference 'ext' variables from testClusters, hence we define actual opensearch
// version the following way which seems to work fine for testClusters. See issue #324
project.opensearch_version = ext.versions.opensearch
// Clusters for BWC tests
2.times { i ->
testClusters {
"${baseName}$i" {
versions = [project.BWCversion, project.opensearch_version]
numberOfNodes = 3
plugin(provider(new Callable<RegularFile>() {
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
if (new File("$project.rootDir/$bwcFilePath/prometheus-exporter/$project.BWCPluginVersion").exists()) {
project.delete(files("$project.rootDir/$bwcFilePath/prometheus-exporter/$project.BWCPluginVersion"))
}
project.mkdir bwcPrometheusExporterPath + project.BWCPluginVersion
ant.get(src: bwcPluginDownloadLink,
dest: bwcPrometheusExporterPath + project.BWCPluginVersion,
httpusecaches: false)
return fileTree(bwcPrometheusExporterPath + project.BWCPluginVersion).getSingleFile()
}
}
}
}))
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'http.content_type.required', 'true'
}
}
}
List<Provider<RegularFile>> plugins = [
provider(new Callable<RegularFile>(){
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
return fileTree(bwcPrometheusExporterPath + project.version).getSingleFile()
}
}
}
})
]
// Creates 2 test clusters with 3 nodes of the old version.
2.times {i ->
task "${baseName}#oldVersionClusterTask$i"(type: RestIntegTestTask) {
useCluster testClusters."${baseName}$i"
filter {
includeTestsMatching "org.opensearch.plugin.bwc.*IT"
}
systemProperty 'tests.rest.bwcsuite', 'old_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'old'
systemProperty 'tests.plugin_bwc_version', project.BWCPluginVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}$i".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}$i".getName()}")
}
}
// Upgrades one node of the old cluster to new OpenSearch version with upgraded plugin version
// This results in a mixed cluster with 2 nodes on the old version and 1 upgraded node.
// This is also used as a one third upgraded cluster for a rolling upgrade.
task "${baseName}#mixedClusterTask"(type: RestIntegTestTask) {
dependsOn tasks.named("copyZIPBundle")
useCluster testClusters."${baseName}0"
dependsOn "${baseName}#oldVersionClusterTask0"
doFirst {
testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins)
}
filter {
includeTestsMatching "org.opensearch.plugin.bwc.*IT"
}
systemProperty 'tests.rest.bwcsuite', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'first'
systemProperty 'tests.plugin_bwc_version', project.BWCPluginVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}")
}
// Upgrades the second node to new OpenSearch version with upgraded plugin version after the first node is upgraded.
// This results in a mixed cluster with 1 node on the old version and 2 upgraded nodes.
// This is used for rolling upgrade.
task "${baseName}#twoThirdsUpgradedClusterTask"(type: RestIntegTestTask) {
dependsOn tasks.named("copyZIPBundle")
dependsOn "${baseName}#mixedClusterTask"
useCluster testClusters."${baseName}0"
doFirst {
testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins)
}
filter {
includeTestsMatching "org.opensearch.plugin.bwc.*IT"
}
systemProperty 'tests.rest.bwcsuite', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'second'
systemProperty 'tests.plugin_bwc_version', project.BWCPluginVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}")
}
// Upgrades the third node to new OpenSearch version with upgraded plugin version after the second node is upgraded.
// This results in a fully upgraded cluster.
// This is used for rolling upgrade.
task "${baseName}#rollingUpgradeClusterTask"(type: RestIntegTestTask) {
dependsOn tasks.named("copyZIPBundle")
dependsOn "${baseName}#twoThirdsUpgradedClusterTask"
useCluster testClusters."${baseName}0"
doFirst {
testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins)
}
filter {
includeTestsMatching "org.opensearch.plugin.bwc.*IT"
}
mustRunAfter "${baseName}#mixedClusterTask"
systemProperty 'tests.rest.bwcsuite', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'third'
systemProperty 'tests.plugin_bwc_version', project.BWCPluginVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}")
}
// Upgrades all the nodes of the old cluster to new OpenSearch version with upgraded plugin version
// at the same time resulting in a fully upgraded cluster.
task "${baseName}#fullRestartClusterTask"(type: RestIntegTestTask) {
dependsOn tasks.named("copyZIPBundle")
dependsOn "${baseName}#oldVersionClusterTask1"
useCluster testClusters."${baseName}1"
doFirst {
testClusters."${baseName}1".upgradeAllNodesAndPluginsToNextVersion(plugins)
}
filter {
includeTestsMatching "org.opensearch.plugin.bwc.*IT"
}
systemProperty 'tests.rest.bwcsuite', 'upgraded_cluster'
systemProperty 'tests.plugin_bwc_version', project.BWCPluginVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}1".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}1".getName()}")
}
// A BWC test suite which runs all the bwc tasks combined.
task bwcTestSuite(type: RestIntegTestTask) {
// Delete all downloaded and built plugin ZIP files.
// Again – we are using ant task to workaround gradle resources modification alert.
doFirst {
ant.delete(includeEmptyDirs: true, verbose: true, removeNotFollowedSymlinks: true) {
ant.fileset(
dir: 'src/test/resources/org/opensearch/prometheus-exporter/bwc/prometheus-exporter'
)
}
}
exclude '**/*Test*'
exclude '**/*IT*'
dependsOn tasks.named("${baseName}#mixedClusterTask")
dependsOn tasks.named("${baseName}#rollingUpgradeClusterTask")
dependsOn tasks.named("${baseName}#fullRestartClusterTask")
}
run {
useCluster testClusters.integTest
}