This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
build.gradle
365 lines (322 loc) Β· 14.5 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file 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.
*/
import org.elasticsearch.gradle.testclusters.TestClusterConfiguration
import java.util.concurrent.TimeUnit
import java.util.function.Predicate
buildscript {
ext {
es_version = System.getProperty("es.version", "7.10.2")
kotlin_version = System.getProperty("kotlin.version", "1.3.72")
}
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
// For local publish dependency
mavenLocal()
}
dependencies {
classpath "org.elasticsearch.gradle:build-tools:${es_version}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}"
classpath "org.jetbrains.kotlin:kotlin-allopen:${kotlin_version}"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0-RC15"
classpath "org.jacoco:org.jacoco.agent:0.8.5"
}
}
plugins {
id 'nebula.ospackage' version "8.3.0"
id "com.dorongold.task-tree" version "1.5"
}
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'idea'
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'elasticsearch.testclusters'
apply plugin: 'elasticsearch.rest-test'
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'org.jetbrains.kotlin.plugin.allopen'
configurations.all {
if (it.state != Configuration.State.UNRESOLVED) return
resolutionStrategy {
force "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
force "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
force 'junit:junit:4.13.1'
force 'commons-beanutils:commons-beanutils:1.9.4'
force 'com.google.guava:guava:30.0-jre'
force 'com.puppycrawl.tools:checkstyle:8.29'
force 'commons-codec:commons-codec:1.13'
// force 'org.apache.logging.log4j:log4j-core:2.13.2'
force 'org.apache.httpcomponents:httpclient:4.5.13'
force 'org.apache.httpcomponents:httpclient-osgi:4.5.13'
force 'org.apache.httpcomponents.client5:httpclient5:5.0.3'
force 'org.apache.httpcomponents.client5:httpclient5-osgi:5.0.3'
force 'com.fasterxml.jackson.core:jackson-databind:2.13.2.2'
force 'com.fasterxml.jackson.core:jackson-core:2.13.2'
force 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.13.2'
force 'com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.13.2'
force 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.2'
force 'org.yaml:snakeyaml:1.26'
force 'org.codehaus.plexus:plexus-utils:3.0.24'
}
}
def usingRemoteCluster = System.properties.containsKey('tests.rest.cluster') || System.properties.containsKey('tests.cluster')
def usingMultiNode = project.properties.containsKey('numNodes')
// Only apply jacoco test coverage if we are running a local single node cluster
if (!usingRemoteCluster && !usingMultiNode) {
apply from: 'build-tools/esplugin-coverage.gradle'
}
check.dependsOn jacocoTestReport
esplugin {
name 'opendistro-index-management'
description 'Open Distro Index Management Plugin'
classname 'com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin'
extendedPlugins = ['opendistro-job-scheduler']
}
tasks.named("integTest").configure {
it.dependsOn(project.tasks.named("bundlePlugin"))
}
allOpen {
annotation("com.amazon.opendistroforelasticsearch.indexmanagement.util.OpenForTesting")
}
configurations {
ktlint
}
detekt {
config = files("detekt.yml")
buildUponDefaultConfig = true
}
configurations.testCompile {
exclude module: "securemock"
}
ext {
projectSubstitutions = [:]
opendistroVersion = "${version}"
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
licenseFile = rootProject.file('LICENSE')
noticeFile = rootProject.file('NOTICE')
}
group = "com.amazon.opendistroforelasticsearch"
version = "${opendistroVersion}.1"
dependencies {
compileOnly "org.elasticsearch:elasticsearch:${es_version}"
compileOnly "com.amazon.opendistroforelasticsearch:opendistro-job-scheduler-spi:1.13.0.0"
compile "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
compile "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
compile "org.jetbrains:annotations:13.0"
compile "com.amazon.opendistroforelasticsearch:notification:1.13.1.0"
compile "com.amazon.opendistroforelasticsearch:common-utils:1.13.0.0"
compile "com.github.seancfoley:ipaddress:5.3.3"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.13.2"
testCompile "org.elasticsearch.test:framework:${es_version}"
testCompile "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testCompile "org.mockito:mockito-core:2.23.0"
ktlint "com.pinterest:ktlint:0.33.0"
}
repositories {
// TODO: remove mavenLocal once notification is published to maven
mavenLocal()
}
if (isSnapshot) {
version += "-SNAPSHOT"
}
plugins.withId('java') {
sourceCompatibility = targetCompatibility = "1.8"
}
plugins.withId('org.jetbrains.kotlin.jvm') {
compileKotlin.kotlinOptions.jvmTarget = compileTestKotlin.kotlinOptions.jvmTarget = "1.8"
}
javadoc.enabled = false // turn off javadoc as it barfs on Kotlin code
licenseHeaders.enabled = true
dependencyLicenses.enabled = false
thirdPartyAudit.enabled = false
loggerUsageCheck.enabled = false
validateNebulaPom.enabled = false
def es_tmp_dir = rootProject.file('build/private/es_tmp').absoluteFile
es_tmp_dir.mkdirs()
def securityEnabled = System.getProperty("security", "false") == "true"
afterEvaluate {
testClusters.integTest.nodes.each { node ->
def plugins = node.plugins
def firstPlugin = plugins.get(0)
plugins.remove(0)
plugins.add(firstPlugin)
if (securityEnabled) {
node.extraConfigFile("kirk.pem", file("src/test/resources/security/kirk.pem"))
node.extraConfigFile("kirk-key.pem", file("src/test/resources/security/kirk-key.pem"))
node.extraConfigFile("esnode.pem", file("src/test/resources/security/esnode.pem"))
node.extraConfigFile("esnode-key.pem", file("src/test/resources/security/esnode-key.pem"))
node.extraConfigFile("root-ca.pem", file("src/test/resources/security/root-ca.pem"))
node.setting("opendistro_security.ssl.transport.pemcert_filepath", "esnode.pem")
node.setting("opendistro_security.ssl.transport.pemkey_filepath", "esnode-key.pem")
node.setting("opendistro_security.ssl.transport.pemtrustedcas_filepath", "root-ca.pem")
node.setting("opendistro_security.ssl.transport.enforce_hostname_verification", "false")
node.setting("opendistro_security.ssl.http.enabled", "true")
node.setting("opendistro_security.ssl.http.pemcert_filepath", "esnode.pem")
node.setting("opendistro_security.ssl.http.pemkey_filepath", "esnode-key.pem")
node.setting("opendistro_security.ssl.http.pemtrustedcas_filepath", "root-ca.pem")
node.setting("opendistro_security.allow_unsafe_democertificates", "true")
node.setting("opendistro_security.allow_default_init_securityindex", "true")
node.setting("opendistro_security.authcz.admin_dn", "CN=kirk,OU=client,O=client,L=test,C=de")
node.setting("opendistro_security.audit.type", "internal_elasticsearch")
node.setting("opendistro_security.enable_snapshot_restore_privilege", "true")
node.setting("opendistro_security.check_snapshot_restore_write_privileges", "true")
node.setting("opendistro_security.restapi.roles_enabled", "[\"all_access\", \"security_rest_api_access\"]")
node.setting("opendistro_security.system_indices.enabled", "true")
node.setting("opendistro_security.system_indices.indices", "[\".opendistro-ism-config\"]")
}
}
}
test {
systemProperty 'tests.security.manager', 'false'
}
File repo = file("$buildDir/testclusters/repo")
def _numNodes = findProperty('numNodes') as Integer ?: 1
testClusters.integTest {
plugin(project.tasks.bundlePlugin.archiveFile)
testDistribution = "OSS"
// Cluster shrink exception thrown if we try to set numberOfNodes to 1, so only apply if > 1
if (_numNodes > 1) numberOfNodes = _numNodes
// When running integration tests it doesn't forward the --debug-jvm to the cluster anymore
// i.e. we have to use a custom property to flag when we want to debug elasticsearch JVM
// since we also support multi node integration tests we increase debugPort per node
if (System.getProperty("cluster.debug") != null) {
def debugPort = 5005
nodes.forEach { node ->
node.jvmArgs("-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=*:${debugPort}")
debugPort += 1
}
}
plugin(provider({
new RegularFile() {
@Override
File getAsFile() { fileTree("src/test/resources/job-scheduler").getSingleFile() }
}
}))
if (securityEnabled) {
// TODO: Update the actual zip to 1.12
plugin(provider({
new RegularFile() {
@Override
File getAsFile() { fileTree("src/test/resources/security") { include "opendistro-security*" }.getSingleFile() }
}
}))
}
setting 'path.repo', repo.absolutePath
}
integTest {
systemProperty 'tests.security.manager', 'false'
systemProperty 'java.io.tmpdir', es_tmp_dir.absolutePath
systemProperty 'buildDir', buildDir.path
systemProperty "https", System.getProperty("https")
systemProperty "security", System.getProperty("security")
systemProperty "user", System.getProperty("user", "admin")
systemProperty "password", System.getProperty("password", "admin")
// Tell the test JVM if the cluster JVM is running under a debugger so that tests can use longer timeouts for
// requests. The 'doFirst' delays reading the debug setting on the cluster till execution time.
doFirst {
systemProperty 'cluster.debug', getDebug()
// Set number of nodes system property to be used in tests
systemProperty 'cluster.number_of_nodes', "${_numNodes}"
// There seems to be an issue when running multi node run or integ tasks with unicast_hosts
// not being written, the waitForAllConditions ensures it's written
getClusters().forEach { cluster ->
cluster.waitForAllConditions()
}
}
// The -Dcluster.debug option makes the cluster debuggable; this makes the tests debuggable
if (System.getProperty("test.debug") != null) {
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=8000'
}
// TODO: Fix running notification test against remote cluster with security plugin installed
if (System.getProperty("https") != null) {
filter {
excludeTestsMatching "com.amazon.opendistroforelasticsearch.indexmanagement.indexstatemanagement.action.NotificationActionIT"
}
}
}
run {
useCluster project.testClusters.integTest
doFirst {
// There seems to be an issue when running multi node run or integ tasks with unicast_hosts
// not being written, the waitForAllConditions ensures it's written
getClusters().forEach { cluster ->
if (securityEnabled) {
// TODO: This is a bit of a hack
LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions = new LinkedHashMap<>()
cluster.waitForConditions(waitConditions, System.currentTimeMillis(), 40, TimeUnit.SECONDS, cluster)
} else {
cluster.waitForAllConditions()
}
}
}
}
task ktlint(type: JavaExec, group: "verification") {
description = "Check Kotlin code style."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "src/**/*.kt"
// to generate report in checkstyle format prepend following args:
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
// see https://github.com/pinterest/ktlint#usage for more
}
check.dependsOn ktlint
task ktlintFormat(type: JavaExec, group: "formatting") {
description = "Fix Kotlin code style deviations."
main = "com.pinterest.ktlint.Main"
classpath = configurations.ktlint
args "-F", "src/**/*.kt"
}
compileKotlin { kotlinOptions.freeCompilerArgs = ['-Xjsr305=strict'] }
apply from: 'build-tools/pkgbuild.gradle'
// This IT is to simulate the situation
// when there are old version (without metadata change)
// and new version mixed in one cluster
import org.elasticsearch.gradle.test.RestIntegTestTask
def mixedClusterTest = project.tasks.create('mixedCluster', RestIntegTestTask.class)
def mixedClusterFlag = findProperty('mixed') as Boolean ?: false
println("mixed cluster flag: $mixedClusterFlag")
mixedClusterTest.dependsOn(bundlePlugin)
testClusters.mixedCluster {
testDistribution = "OSS"
if (_numNodes > 1) numberOfNodes = _numNodes
getNodes().each { node ->
node.plugin(provider({
new RegularFile() {
@Override
File getAsFile() { fileTree("src/test/resources/job-scheduler").getSingleFile() }
}
}))
if (mixedClusterFlag && node.name == "mixedCluster-1") {
node.plugin(provider({
new RegularFile() {
@Override
File getAsFile() { fileTree("src/test/resources/index-management").getSingleFile() }
}
}))
} else {
node.plugin(project.tasks.bundlePlugin.archiveFile)
}
node.plugins.each { println("plugin in the node: ${it.get()}") }
}
setting 'path.repo', repo.absolutePath
}
mixedCluster {
systemProperty 'tests.security.manager', 'false'
systemProperty 'tests.path.repo', repo.absolutePath
systemProperty 'cluster.mixed', "$mixedClusterFlag"
systemProperty 'cluster.number_of_nodes', "${_numNodes}"
}