-
Notifications
You must be signed in to change notification settings - Fork 67
/
build.gradle
921 lines (822 loc) · 32.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT")
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
default_bwc_version = System.getProperty("bwc.version", "2.18.0.0")
pa_bwc_version = System.getProperty("tests.bwc.version", default_bwc_version)
baseName = "paBwcCluster"
// The PA Commons (https://github.com/opensearch-project/performance-analyzer-commons)
// is a library dependency with hardcoded versioning in PA and RCA repos.
paCommonsVersion = "1.6.0"
// 3.0.0-SNAPSHOT -> 3.0.0.0-SNAPSHOT
version_tokens = opensearch_version.tokenize('-')
opensearch_build = version_tokens[0] + '.0'
if (buildVersionQualifier) {
opensearch_build += "-${buildVersionQualifier}"
}
if (isSnapshot) {
opensearch_build += "-SNAPSHOT"
paCommonsVersion += "-SNAPSHOT"
}
}
// Used to resolve build file dependencies
repositories {
mavenLocal()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.opensearch.gradle:build-tools:${opensearch_version}"
classpath 'org.ajoberstar:gradle-git:0.2.3'
}
}
plugins {
id 'java'
id 'com.netflix.nebula.ospackage' version "11.6.0"
id 'com.github.spotbugs' version '6.0.7'
id 'jacoco'
id 'com.diffplug.spotless' version '6.25.0'
id 'checkstyle'
id 'org.ajoberstar.grgit' version '5.0.0'
id 'org.gradle.test-retry' version '1.5.2'
}
checkstyle {
toolVersion = '10.12.1'
configFile file("checkstyle/checkstyle.xml")
}
spotbugsMain {
excludeFilter = file("checkstyle/findbugs-exclude.xml")
effort = com.github.spotbugs.snom.Effort.MAX
ignoreFailures = true
reports {
xml.enabled = false
html.enabled = true
}
}
spotbugsTest {
ignoreFailures = true
}
ext {
// The RCA branch that will be built. Default branch is main.
rcaProjectRepo = System.getProperty("performance-analyzer-rca.repo", "https://github.com/opensearch-project/performance-analyzer-rca.git")
rcaProjectFetch = System.getProperty("performance-analyzer-rca.fetch", "origin")
rcaProjectBranch = System.getProperty("performance-analyzer-rca.branch", "${rcaProjectFetch}/main")
// If true, then the build will clone the RCA Project into $rcaProjectDir
cloneRcaProject = "true" == System.getProperty("performance-analyzer-rca.build", "true")
// By default we will look for RCA in a peer directory
rcaProjectDir = System.getProperty("performance-analyzer-rca.path", "../performance-analyzer-rca")
}
allprojects {
group = "org.opensearch"
version = opensearch_build
}
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.pluginzip'
licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')
spotless {
java {
licenseHeaderFile(file('license-header'))
googleJavaFormat('1.17.0').aosp()
importOrder()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
// add support for spotless:off and spotless:on tags to exclude sections of code
toggleOffOn()
}
}
test {
enabled = true
systemProperty 'tests.security.manager', 'false'
retry {
failOnPassedAfterRetry = false
maxRetries = 3
maxFailures = 10
}
}
licenseHeaders.enabled = true
validateNebulaPom.enabled = false
loggerUsageCheck.enabled = false
def _numNodes = findProperty('numNodes') as Integer ?: 1
opensearchplugin {
name 'opensearch-performance-analyzer'
description 'OpenSearch Performance Analyzer Plugin'
classname 'org.opensearch.performanceanalyzer.PerformanceAnalyzerPlugin'
}
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
compileJava {
dependsOn spotlessApply
}
javadoc {
}
project.afterEvaluate {
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility)
// cannot contain the first version
// should be '8' or '11' etc.
String version = targetVersion.toString()
if (version.length() > 2) {
version = targetVersion.toString().substring(2)
}
compileJava.options.compilerArgs.removeAll(['--release', version])
}
publishing {
repositories {
maven {
name = "Snapshots"
url = "https://aws.oss.sonatype.org/content/repositories/snapshots"
credentials {
username "$System.env.SONATYPE_USERNAME"
password "$System.env.SONATYPE_PASSWORD"
}
}
}
publications {
pluginZip(MavenPublication) { publication ->
pom {
name = "performance-analyzer"
description = "OpenSearch performance-analyzer plugin"
groupId = "org.opensearch.plugin"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
name = "OpenSearch"
url = "https://github.com/opensearch-project/performance-analyzer"
}
}
}
}
}
}
repositories {
mavenLocal()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
configurations {
includeJars
zipArchive
}
tasks.withType(JavaCompile) {
options.warnings = false
}
jacoco {
toolVersion = "0.8.11"
}
jacocoTestReport {
reports {
xml.required = true
html.required = true
csv.required = false
}
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it,
include: [
'**/org/opensearch/performanceanalyzer/**',
],
exclude: [
'**/FaultDetectionMetricsCollector.class',
'**/ClusterSettingsManager.class',
])
})
}
}
jacocoTestCoverageVerification {
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it,
include: [
'**/org/opensearch/performanceanalyzer/**',
],
exclude: [
])
})
}
violationRules {
rule {
limit {
minimum = 0.5
}
}
}
}
// to run coverage verification during the build (and fail when appropriate)
check.dependsOn jacocoTestCoverageVerification
checkstyleMain.enabled = false
checkstyleTest.enabled = false
dependencies {
def junitVersion = "${versions.junit}"
def jacksonVersion = "${versions.jackson}"
def jacksonDataBindVersion = "${versions.jackson_databind}"
def guavaVersion = "${versions.guava}"
def log4jVersion = "${versions.log4j}"
def protobufVersion = "${versions.protobuf}"
def nettyVersion = "${versions.netty}"
configurations {
// jarHell reports class name conflicts between securemock and mockito-core
// has to disable one of them.
// Need to continue exclude this group until we figure out how to get rid of
// this exclusion with opensearch
all*.exclude group: "org.elasticsearch", module: "securemock"
all*.exclude group: "org.jboss.spec.javax.annotation", module: "jboss-annotations-api_1.2_spec"
}
configurations.all {
resolutionStrategy {
force "junit:junit:${junitVersion}"
force "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
force "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
force "com.fasterxml.jackson.core:jackson-databind:${jacksonDataBindVersion}"
force "com.fasterxml.jackson.module:jackson-module-paranamer:${jacksonVersion}"
force "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:${jacksonVersion}"
force "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
force "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:${jacksonVersion}"
force "org.apache.commons:commons-lang3:${versions.commonslang}"
force "org.slf4j:slf4j-api:2.0.0"
force "org.apache.bcel:bcel:6.6.0" // This line should be removed once Spotbugs is upgraded to 4.7.4
force "com.google.guava:guava:${guavaVersion}"
}
}
implementation 'org.jooq:jooq:3.10.8'
implementation 'org.apache.commons:commons-lang3:3.9'
implementation 'org.bouncycastle:bcprov-jdk15to18:1.78.1'
implementation 'org.bouncycastle:bcpkix-jdk18on:1.78.1'
implementation "org.opensearch:performance-analyzer-commons:${paCommonsVersion}"
implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonDataBindVersion}"
implementation "com.fasterxml.jackson.module:jackson-module-paranamer:${jacksonVersion}"
implementation(group: 'org.apache.logging.log4j', name: 'log4j-api', version: "${log4jVersion}")
implementation(group: 'org.apache.logging.log4j', name: 'log4j-core', version: "${log4jVersion}")
implementation("com.google.guava:guava:${guavaVersion}") {
version {
strictly "${guavaVersion}"
}
}
implementation(group: 'com.google.errorprone', name: 'error_prone_annotations') {
version {
strictly "2.9.0"
}
}
implementation(group: 'com.google.protobuf', name:'protobuf-java') {
version {
strictly "${protobufVersion}"
}
}
implementation("io.netty:netty-buffer") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-codec:") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-codec-http") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-common") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-handler") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-resolver") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-transport") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-codec-http2") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-codec-socks") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-handler-proxy") {
version {
strictly "${nettyVersion}"
}
}
implementation("io.netty:netty-transport-native-unix-common") {
version {
strictly "${nettyVersion}"
}
}
implementation("org.checkerframework:checker-qual") {
version {
strictly "3.29.0"
}
}
// JDK9+ has to run powermock 2+. https://github.com/powermock/powermock/issues/888
testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'
testImplementation(group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0') {
exclude(group: 'org.hamcrest', module: 'hamcrest-core')
}
implementation("org.mockito:mockito-core") {
version {
strictly "2.23.0"
}
}
// Dependency to mock final classes.
testImplementation group: 'org.mockito', name: 'mockito-inline', version: '2.13.0'
testImplementation group: 'org.powermock', name: 'powermock-core', version: '2.0.0'
testImplementation group: 'org.powermock', name: 'powermock-api-support', version: '2.0.0'
testImplementation(group: 'org.powermock', name: 'powermock-module-junit4-common', version: '2.0.0') {
exclude(group: 'org.hamcrest', module: 'hamcrest-core')
}
testImplementation group: 'org.javassist', name: 'javassist', version: '3.24.0-GA'
testImplementation group: 'org.powermock', name: 'powermock-reflect', version: '2.0.0'
//minimum byte-buddy version to be compatible with mockito-core 2.23.0 is 1.9.7+. https://github.com/mockito/mockito/issues/1606
implementation("net.bytebuddy:byte-buddy") {
version {
strictly "1.9.7"
}
}
implementation("net.bytebuddy:byte-buddy-agent") {
version {
strictly "1.9.7"
}
}
implementation("org.objenesis:objenesis") {
version {
strictly "3.0.1"
}
}
implementation("com.google.code.gson:gson") {
version {
strictly "2.9.0"
}
}
// Needed for BWC tests
zipArchive group: 'org.opensearch.plugin', name:'performance-analyzer', version: "${pa_bwc_version}-SNAPSHOT"
}
dependencyLicenses {
mapping from: /jackson-.*/, to: 'jackson'
}
dependencyLicenses.doFirst {
def licenseDir = "$projectDir/licenses"
exec {
workingDir("$licenseDir")
commandLine 'rm', "-f", "performance-analyzer-commons-${paCommonsVersion}.jar.sha1"
}
updateShas.updateShas()
}
gradle.startParameter.excludedTaskNames += [ "forbiddenApisMain",
"forbiddenApisTest",
"thirdPartyAudit",
"testingConventions"]
import java.util.concurrent.Callable
import org.ajoberstar.grgit.Grgit
import org.opensearch.gradle.test.RestIntegTestTask
import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask
static def propEnabled(property) {
return System.getProperty(property) != null && System.getProperty(property).toLowerCase().equals("true")
}
// The following Gradle tasks are used to create a PA/RCA enabled OpenSearch cluster
// Pass the -Dtests.enableIT property to Gradle to run ITs
/**
* cloneRcaGitRepo clones the performance-analyzer-rca repo if the -Dtests.enableIT=true flag is passed
* to the Gradle JVM
*/
task cloneRcaGitRepo() {
def destination = file(rcaProjectDir)
def uri = rcaProjectRepo
def fetch = rcaProjectFetch
def branch = rcaProjectBranch
if (!branch.startsWith(fetch)) { // to avoid checking out origin/origin/branch
branch = rcaProjectFetch + "/" + rcaProjectBranch
}
doFirst {
println "Cloning performance-analyzer-rca into ${rcaProjectDir} from ${rcaProjectRepo}#${rcaProjectBranch}"
}
doLast {
if (destination.exists() && destination.isDirectory()) { // If directory exists, use this instead.
def grgit = Grgit.open(dir: destination.toString())
} else { // Otherwise pull it from git.
def grgit = Grgit.clone(dir: destination.toString(), uri: uri)
grgit.fetch(remote: fetch)
grgit.checkout(branch: branch)
}
}
}
task buildRca() {
dependsOn(cloneRcaGitRepo)
doFirst {
logger.info("Building performance-analyzer-rca project in ${rcaProjectDir} with -Dopensearch.version=${opensearch_version}")
}
doLast {
exec {
workingDir("$rcaProjectDir")
if (buildVersionQualifier == null || buildVersionQualifier == '' || buildVersionQualifier == 'null') {
commandLine './gradlew', 'build', '-x', 'test', '-x', 'jacocoTestCoverageVerification', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}"
}
else {
commandLine './gradlew', 'build', '-x', 'test', '-x', 'jacocoTestCoverageVerification', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}", "-Dbuild.version_qualifier=${buildVersionQualifier}"
}
}
exec {
workingDir("$rcaProjectDir")
if (buildVersionQualifier == null || buildVersionQualifier == '' || buildVersionQualifier == 'null') {
commandLine './gradlew', 'publishToMavenLocal', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}"
}
else {
commandLine './gradlew', 'publishToMavenLocal', "-Dopensearch.version=${opensearch_version}", "-Dbuild.snapshot=${isSnapshot}", "-Dbuild.version_qualifier=${buildVersionQualifier}"
}
}
exec {
def licenseDir = "$projectDir/licenses"
workingDir("$licenseDir")
commandLine 'rm', "-f", "performanceanalyzer-rca-${version}.jar.sha1"
}
}
}
buildRca.finalizedBy updateShas
// This value is set by the unpackRca task
def rcaArtifactsDir
task unpackRca(type: Copy) {
dependsOn(buildRca)
from(zipTree("$rcaProjectDir/build/distributions/performance-analyzer-rca-${version}.zip")) {
}
into "$rcaProjectDir/build/distributions"
rcaArtifactsDir = "$rcaProjectDir/build/distributions/performance-analyzer-rca/"
doLast {
logger.info("Unpacked performance-analyzer-rca artifacts into ${rcaProjectDir}")
}
}
tasks.withType(Test) {
jvmArgs('--add-opens=java.base/sun.security.jca=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.util.concurrent=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.io=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.nio.file=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.lang=ALL-UNNAMED')
jvmArgs('--add-opens=java.base/java.util=ALL-UNNAMED')
}
bundlePlugin {
dependsOn 'unpackRca'
from("$rcaArtifactsDir/config") {
into "config"
}
from("$rcaArtifactsDir/bin") {
into "bin"
include "performance-analyzer-agent"
}
from("$rcaArtifactsDir") {
into "performance-analyzer-rca"
}
from("packaging") {
include "performance-analyzer-agent-cli"
into "bin"
}
from('build/resources/main/') {
include "plugin-security.policy"
}
from("config/opensearch-performance-analyzer") {
into "config"
}
}
/**
* setupOpenSearchCluster spins up a local 2 node OpenSearch cluster using the enableRca task in the performance-analyzer-rca
* repo. The performance-analyzer-rca repo is cloned as part of the cloneRcaGitRepo task.
*/
task setupOpenSearchCluster() {
dependsOn(cloneRcaGitRepo)
onlyIf = {
propEnabled("tests.enableIT")
}
doLast {
exec {
workingDir(rcaProjectDir)
commandLine './gradlew', 'enableRca'
}
sleep(30000)
}
}
/**
* integTest is a task provided by the OpenSearch test framework, which allows us to spin up clients
* and test API calls against a local or remote OpenSearch cluster.
*
* The simplest way to run this task in a way that "just works" is to invoke
* ./gradlew integTest -Dtests.enableIT=true -Dtests.useDockerCluster=true
* which will spin up a local 2 node OpenSearch cluster on your machine, then execute the test suite against it
*
* A full list of options is provided below. Check our gradle.properties file for the defaults for
* each of these properties.
*
* -Dtests.rest.cluster the OpenSearch REST endpoint that test clients should hit
* -Dtests.cluster the OpenSearch <a href="https://discuss.elastic.co/t/transport-client-vs-rest-client/13936">transport</a>
* endpoint that test clients should hit
* -Dtests.enableIT a flag to enable integration testing, by default this is false
* -Dtests.useDockerCluster if true, spin up a local 2 node cluster before executing tests
* NOTE: if you specify this, don't specify -Dtests.rest.cluster or -Dtests.cluster
* -Dtests.pa.port the port number of the PerformanceAnalyzer REST endpoint
* -Dtests.https either true or false, if true, then instantiate REST and transport clients using
* the https:// protocol and basic authentication via the -Dtests.user and -Dtests.password properties
* -Dtests.user the username of the admin user, this is used in conjunction with -Dtests.https and
* -Dtests.password to authenticate requests in the opensearch-security context
* -Dtests.password the password of the admin user specified by -Dtests.user
*/
task integTest(type: RestIntegTestTask) {
onlyIf = {
propEnabled("tests.enableIT")
}
if (propEnabled("tests.useDockerCluster")) {
dependsOn(setupOpenSearchCluster)
}
systemProperty 'tests.security.manager', 'false'
description = "Run integration tests against integTest cluster"
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
if (System.getProperty("tests.rest.bwcsuite") == null) {
filter {
excludeTestsMatching "org.opensearch.performanceanalyzer.bwc.*IT"
}
}
}
tasks.named("check").configure { dependsOn(integTest) }
Zip bundle = (Zip) project.getTasks().getByName("bundlePlugin");
integTest.dependsOn(bundle)
integTest.getClusters().forEach{c -> c.plugin(project.getObjects().fileProperty().value(bundle.getArchiveFile()))}
def opensearch_tmp_dir = rootProject.file('build/private/opensearch_tmp').absoluteFile
opensearch_tmp_dir.mkdirs()
task integTestRemote(type: RestIntegTestTask) {
onlyIf = {
propEnabled("tests.enableIT")
}
if (System.getProperty("tests.rest.bwcsuite") == null) {
filter {
excludeTestsMatching "org.opensearch.performanceanalyzer.bwc.*IT"
}
}
if (propEnabled("tests.useDockerCluster")) {
dependsOn(setupOpenSearchCluster)
}
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
systemProperty 'tests.security.manager', 'false'
systemProperty 'java.io.tmpdir', opensearch_tmp_dir.absolutePath
systemProperty "https", System.getProperty("https")
systemProperty "user", System.getProperty("user")
systemProperty "password", System.getProperty("password")
}
// Creates two test clusters of previous version and loads opensearch plugin of pa_bwc_version
2.times {i ->
testClusters {
"${baseName}$i" {
testDistribution = "ARCHIVE"
versions = ["2.18.0-SNAPSHOT", opensearch_version]
numberOfNodes = 3
plugin(provider(new Callable<RegularFile>() {
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
return configurations.zipArchive.asFileTree.matching {
include '**/performance-analyzer*'
}.singleFile
}
}
}
}))
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'http.content_type.required', 'true'
}
}
}
List<Provider<RegularFile>> plugins = []
// Ensure the artifact for the current project version is available to be used for the bwc tests
task prepareBwcTests {
dependsOn bundle
doLast {
plugins = [ project.getObjects().fileProperty().value(bundle.getArchiveFile()) ]
}
}
// Creates 2 test clusters with 3 nodes of the old version.
2.times {i ->
task "${baseName}#oldVersionClusterTask$i"(type: StandaloneRestIntegTestTask) {
dependsOn 'prepareBwcTests'
useCluster testClusters."${baseName}$i"
filter {
includeTestsMatching "org.opensearch.performanceanalyzer.bwc.*IT"
}
systemProperty 'tests.rest.bwcsuite', 'old_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'old'
systemProperty 'tests.plugin_bwc_version', pa_bwc_version
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: StandaloneRestIntegTestTask) {
useCluster testClusters."${baseName}0"
dependsOn "${baseName}#oldVersionClusterTask0"
doFirst {
testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins)
testClusters."${baseName}0".waitForAllConditions()
}
filter {
includeTestsMatching "org.opensearch.performanceanalyzer.bwc.*IT"
}
systemProperty 'tests.rest.bwcsuite', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'first'
systemProperty 'tests.plugin_bwc_version', pa_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}")
systemProperty 'tests.security.manager', 'false'
}
// 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: StandaloneRestIntegTestTask) {
dependsOn "${baseName}#mixedClusterTask"
useCluster testClusters."${baseName}0"
doFirst {
testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins)
testClusters."${baseName}0".waitForAllConditions()
}
filter {
includeTestsMatching "org.opensearch.performanceanalyzer.bwc.*IT"
}
systemProperty 'tests.rest.bwcsuite', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'second'
systemProperty 'tests.plugin_bwc_version', pa_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}")
systemProperty 'tests.security.manager', 'false'
}
// 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: StandaloneRestIntegTestTask) {
dependsOn "${baseName}#twoThirdsUpgradedClusterTask"
useCluster testClusters."${baseName}0"
doFirst {
testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins)
testClusters."${baseName}0".waitForAllConditions()
}
filter {
includeTestsMatching "org.opensearch.performanceanalyzer.bwc.*IT"
}
mustRunAfter "${baseName}#mixedClusterTask"
systemProperty 'tests.rest.bwcsuite', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'third'
systemProperty 'tests.plugin_bwc_version', pa_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}")
systemProperty 'tests.security.manager', 'false'
}
// 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: StandaloneRestIntegTestTask) {
dependsOn "${baseName}#oldVersionClusterTask1"
useCluster testClusters."${baseName}1"
doFirst {
testClusters."${baseName}1".upgradeAllNodesAndPluginsToNextVersion(plugins)
testClusters."${baseName}1".waitForAllConditions()
}
filter {
includeTestsMatching "org.opensearch.performanceanalyzer.bwc.*IT"
}
systemProperty 'tests.rest.bwcsuite', 'upgraded_cluster'
systemProperty 'tests.plugin_bwc_version', pa_bwc_version
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}1".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}1".getName()}")
systemProperty 'tests.security.manager', 'false'
}
// A bwc test suite which runs all the bwc tasks combined.
task bwcTestSuite(type: StandaloneRestIntegTestTask) {
exclude '**/*Test*'
exclude '**/*IT*'
dependsOn tasks.named("${baseName}#mixedClusterTask")
dependsOn tasks.named("${baseName}#rollingUpgradeClusterTask")
dependsOn tasks.named("${baseName}#fullRestartClusterTask")
}
run {
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 ->
cluster.waitForAllConditions()
}
}
useCluster testClusters.integTest
}
// This is afterEvaluate because the bundlePlugin ZIP task is updated afterEvaluate and changes the ZIP name to match the plugin name
afterEvaluate {
ospackage {
packageName = "opensearch-performance-analyzer"
release = isSnapshot ? "0.1" : '1'
version = "${project.version}"
into '/usr/share/opensearch/plugins'
from(zipTree(bundlePlugin.archivePath)) {
into opensearchplugin.name
}
configurationFile '/usr/lib/systemd/system/opensearch.service'
into('/usr/lib/systemd/system') {
fileType CONFIG | NOREPLACE
from "packaging/opensearch-performance-analyzer.service"
fileMode 0644
}
into('/usr/share/opensearch/bin') {
from ('packaging/performance-analyzer-agent-cli') {
fileMode 0755
}
}
user 'root'
permissionGroup 'root'
fileMode 0644
dirMode 0755
requires('opensearch-oss', versions.opensearch, EQUAL)
packager = 'Amazon'
vendor = 'Amazon'
os = 'LINUX'
prefix '/usr'
license 'ASL-2.0'
maintainer 'OpenSearch <[email protected]>'
url 'https://opensearch.org/downloads.html'
summary '''
Performance Analyzer plugin for OpenSearch.
Reference documentation can be found at https://opensearch.org/docs/.
'''.stripIndent().replace('\n', ' ').trim()
}
buildRpm {
arch = 'NOARCH'
postInstall file('packaging/rpm/postinst')
postUninstall file('packaging/rpm/postrm')
dependsOn 'assemble'
finalizedBy 'renameRpm'
task renameRpm(type: Copy) {
from("$buildDir/distributions")
into("$buildDir/distributions")
rename "$archiveFileName", "${packageName}-${version}.rpm"
doLast {
delete file("$buildDir/distributions/$archiveFileName")
}
}
}
buildDeb {
arch = 'all'
postInstall file('packaging/deb/postinst')
postUninstall file('packaging/deb/postrm')
dependsOn 'assemble'
finalizedBy 'renameDeb'
task renameDeb(type: Copy) {
from("$buildDir/distributions")
into("$buildDir/distributions")
rename "$archiveFileName", "${packageName}-${version}.deb"
doLast {
delete file("$buildDir/distributions/$archiveFileName")
}
}
}
task buildPackages(type: GradleBuild) {
tasks = ['build', 'buildRpm', 'buildDeb']
}
}
bundlePlugin.mustRunAfter unpackRca
// updateVersion: Task to auto increment to the next development iteration
task updateVersion {
onlyIf { System.getProperty('newVersion') }
doLast {
ext.newVersion = System.getProperty('newVersion')
println "Setting version to ${newVersion}."
// String tokenization to support -SNAPSHOT
ant.replaceregexp(match: opensearch_version.tokenize('-')[0], replace: newVersion.tokenize('-')[0], flags:'g', byline:true) {
fileset(dir: projectDir) {
// Include the required files that needs to be updated with new Version
include(name: "src/main/resources/plugin-descriptor.properties")
}
}
ant.replaceregexp(file:'build.gradle', match: '"opensearch.version", "\\d.*"', replace: '"opensearch.version", "' + newVersion.tokenize('-')[0] + '-SNAPSHOT"', flags:'g', byline:true)
}
}