forked from opendistro-for-elasticsearch/anomaly-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
418 lines (358 loc) · 16.8 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
/*
* 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.
*/
buildscript {
ext {
es_group = "org.elasticsearch"
es_version = '7.4.2'
es_distribution = 'oss-zip'
}
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
jcenter()
}
dependencies {
classpath "${es_group}.gradle:build-tools:${es_version}"
}
}
plugins {
id 'nebula.ospackage' version "5.3.0"
id "com.diffplug.gradle.spotless" version "3.26.1"
}
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
jcenter()
}
ext {
opendistroVersion = '1.4.0'
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
if (System.properties['os.name'].toLowerCase().contains('windows')) {
job_scheduler_plugin_zip = "file:///${fileTree("src/test/resources/job-scheduler").getSingleFile().absolutePath}"
} else {
job_scheduler_plugin_zip = "file://${fileTree("src/test/resources/job-scheduler").getSingleFile().absolutePath}"
}
}
version = "${opendistroVersion}.0"
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'base'
apply plugin: 'jacoco'
allprojects {
group = 'com.amazon.opendistroforelasticsearch'
plugins.withId('java') {
sourceCompatibility = targetCompatibility = "1.8"
}
}
ext {
projectSubstitutions = [:]
licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')
}
esplugin {
name 'opendistro-anomaly-detection'
description 'Amazon opendistro elasticsearch anomaly detector plugin'
classname 'com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin'
extendedPlugins = ['lang-painless', 'opendistro-job-scheduler']
}
// Handle case where older versions of esplugin doesn't expose the joda time version it uses
configurations.all {
if (it.state != Configuration.State.UNRESOLVED) return
resolutionStrategy {
force "joda-time:joda-time:${versions.joda}"
force "com.fasterxml.jackson.core:jackson-core:${versions.jackson}"
force "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:${versions.jackson}"
force "commons-logging:commons-logging:${versions.commonslogging}"
force "org.apache.httpcomponents:httpcore:${versions.httpcore}"
force "commons-codec:commons-codec:${versions.commonscodec}"
force "org.mockito:mockito-core:3.0.0"
force "org.objenesis:objenesis:3.0.1"
force "net.bytebuddy:byte-buddy:1.9.15"
force "net.bytebuddy:byte-buddy-agent:1.9.15"
}
}
configurations {
testCompile {
exclude group: 'org.elasticsearch', module: 'securemock'
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
}
// Allow @Test to be used in test classes not inherited from LuceneTestCase.
// see https://github.com/elastic/elasticsearch/blob/master/buildSrc/src/main/resources/forbidden/es-test-signatures.txt
forbiddenApis.ignoreFailures = true
// Allow test cases to be named Tests without having to be inherited from LuceneTestCase.
// see https://github.com/elastic/elasticsearch/blob/323f312bbc829a63056a79ebe45adced5099f6e6/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/TestingConventionsTasks.java
testingConventions.enabled = false
licenseHeaders.enabled = true
dependencyLicenses.enabled = false
thirdPartyAudit.enabled = false
// See package README.md for details on using these tasks.
def _numNodes = findProperty('numNodes') as Integer ?: 1
def getSeedHosts = { int num ->
def _localhost = "127.0.0.1:"
def _startPort = 9300
def _seed_hosts = new StringBuilder()
_seed_hosts.append("[")
(0..< num).each { i ->
if (i>0) {
_seed_hosts.append(", ")
}
def _host = "\"" + _localhost + (_startPort + i) + "\""
_seed_hosts.append(_host)
}
_seed_hosts.append("]")
_seed_hosts
}
tasks.create(name : "runMultiNode", type: org.elasticsearch.gradle.test.RunTask) {
daemonize = true
numNodes = _numNodes
// this has to be false otherwise ClusterFormationTasks.groovy will set discovery.seed_providers to file
autoSetHostsProvider = false
setting 'http.port', '9200-9300'
setting 'transport.port', '9300-9400'
setting 'discovery.seed_hosts', getSeedHosts(numNodes)
clusterName = 'multi-node-run'
plugin project.path
distribution = es_distribution
// Temporary until job-scheduler is published to Maven
setupCommand('installPlugin', 'bin/elasticsearch-plugin', 'install', job_scheduler_plugin_zip)
}
tasks.create(name: "startMultiNode") {
if (_numNodes == 1) {
dependsOn "runMultiNode#start"
} else {
(0..<_numNodes).each { n -> dependsOn "runMultiNode#node${n}.start" }
}
}
tasks.create(name : "runSingleNode", type: org.elasticsearch.gradle.test.RunTask) {
daemonize = true
numNodes = 3
// this has to be false otherwise ClusterFormationTasks.groovy will set discovery.seed_providers to file
autoSetHostsProvider = false
// this has to be false otherwise ClusterFormationTasks.groovy will set cluster.initial_master_nodes to all 3 nodes
autoSetInitialMasterNodes = false
setting 'http.port', '9200-9300'
setting 'transport.port', '9300-9400'
setting 'discovery.seed_hosts', getSeedHosts(numNodes)
setting 'node.master', true
setting 'node.data', true
setting 'node.ingest', true
// since we want to start one node at a time, we have to provide the node we are going to start first
setting 'cluster.initial_master_nodes', "[\"node-0\"]"
clusterName = 'multi-node-run'
plugin project.path
distribution = es_distribution
}
(0..2).each { i ->
tasks.create(name: "startSingleNode$i") {
dependsOn "runSingleNode#node${i}.start"
}
}
task stopMultiNode(type: Exec) {
commandLine "bash", "-c", "kill -9 \$(ps aux | grep lastic | grep -v grep | grep -v stopMultiNode | awk '{print \$2}')"
sleep(1000)
dependsOn "clean"
}
def es_tmp_dir = rootProject.file('build/private/es_tmp').absoluteFile
es_tmp_dir.mkdirs()
test {
include '**/*Tests.class'
systemProperty 'tests.security.manager', 'false'
}
integTestRunner {
systemProperty 'tests.security.manager', 'false'
systemProperty 'java.io.tmpdir', es_tmp_dir.absolutePath
systemProperty 'tests.locale', 'en'
// 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', integTestCluster.debug }
// 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'
}
}
integTestCluster {
distribution = es_distribution
// Temporary until job-scheduler is published to Maven
setupCommand('installPlugin', 'bin/elasticsearch-plugin', 'install', job_scheduler_plugin_zip)
}
run {
distribution = es_distribution
// Temporary until job-scheduler is published to Maven
setupCommand('installPlugin', 'bin/elasticsearch-plugin', 'install', job_scheduler_plugin_zip)
}
evaluationDependsOnChildren()
task release(type: Copy, group: 'build') {
dependsOn allprojects*.tasks.build
from(zipTree(project.tasks.bundlePlugin.outputs.files.getSingleFile()))
into "build/plugins/opendistro-anomaly-detection"
includeEmptyDirs = false
// ES versions < 6.3 have a top-level elasticsearch directory inside the plugin zip which we need to remove
eachFile { it.path = it.path - "elasticsearch/" }
}
List<String> jacocoExclusions = [
// code for configuration, settings, etc is excluded from coverage
'com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorPlugin',
'com.amazon.opendistroforelasticsearch.ad.settings.AnomalyDetectorSettings',
//TODO: add more test cases later for these package
'com.amazon.opendistroforelasticsearch.ad.model.*',
'com.amazon.opendistroforelasticsearch.ad.rest.*',
// Class containing just constants. Don't need to test
'com.amazon.opendistroforelasticsearch.ad.constant.*',
'com.amazon.opendistroforelasticsearch.ad.common.exception.FeatureNotAvailableException',
'com.amazon.opendistroforelasticsearch.ad.common.exception.AnomalyDetectionException',
'com.amazon.opendistroforelasticsearch.ad.util.ClientUtil',
'com.amazon.opendistroforelasticsearch.ad.ml.*',
'com.amazon.opendistroforelasticsearch.ad.feature.*',
'com.amazon.opendistroforelasticsearch.ad.dataprocessor.*',
'com.amazon.opendistroforelasticsearch.ad.AnomalyDetectorRunner',
'com.amazon.opendistroforelasticsearch.ad.resthandler.RestGetAnomalyResultAction',
'com.amazon.opendistroforelasticsearch.ad.metrics.MetricFactory',
'com.amazon.opendistroforelasticsearch.ad.indices.AnomalyDetectionIndices',
'com.amazon.opendistroforelasticsearch.ad.transport.ForwardAction',
'com.amazon.opendistroforelasticsearch.ad.transport.ForwardTransportAction',
'com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorAction',
'com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorRequest',
'com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorResponse',
'com.amazon.opendistroforelasticsearch.ad.transport.StopDetectorTransportAction',
'com.amazon.opendistroforelasticsearch.ad.transport.ADStatsAction',
'com.amazon.opendistroforelasticsearch.ad.transport.CronRequest',
'com.amazon.opendistroforelasticsearch.ad.transport.DeleteDetectorAction',
'com.amazon.opendistroforelasticsearch.ad.util.ParseUtils'
]
jacocoTestCoverageVerification {
violationRules {
rule {
element = 'CLASS'
excludes = jacocoExclusions
limit {
counter = 'BRANCH'
minimum = 0.60
}
}
rule {
element = 'CLASS'
excludes = jacocoExclusions
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.75
}
}
}
}
check.dependsOn jacocoTestCoverageVerification
jacocoTestCoverageVerification.dependsOn jacocoTestReport
dependencies {
compileOnly "org.elasticsearch.plugin:elasticsearch-scripting-painless-spi:${versions.elasticsearch}"
compileOnly "com.amazon.opendistroforelasticsearch:opendistro-job-scheduler-spi:1.4.0.0"
compile group: 'com.google.guava', name: 'guava', version:'15.0'
compile group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile files('lib/random-cut-forest-1.0.jar')
compile group: 'com.yahoo.datasketches', name: 'sketches-core', version: '0.13.4'
compile group: 'com.yahoo.datasketches', name: 'memory', version: '0.12.2'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile "org.jacoco:org.jacoco.agent:0.8.3"
compile "org.jacoco:org.jacoco.ant:0.8.3"
compile "org.jacoco:org.jacoco.core:0.8.3"
compile "org.jacoco:org.jacoco.report:0.8.3"
testCompile group: 'pl.pragmatists', name: 'JUnitParams', version: '1.1.1'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.0.0'
testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.2'
testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.2'
testCompile group: 'net.bytebuddy', name: 'byte-buddy', version: '1.9.15'
testCompile group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.9.15'
checkstyle "com.puppycrawl.tools:checkstyle:${project.checkstyle.toolVersion}"
}
compileJava.options.compilerArgs << "-Xlint:-deprecation,-rawtypes,-serial,-try,-unchecked"
apply plugin: 'nebula.ospackage'
// This is afterEvaluate because the bundlePlugin ZIP task is updated afterEvaluate and changes the ZIP name to match the plugin name
afterEvaluate {
project.tasks.getByName("run#installOpendistroAnomalyDetectorPlugin").dependsOn("run#installPlugin")
project.tasks.getByName("run#installPlugin").dependsOn.remove(project.tasks.getByName("run#installOpendistroAnomalyDetectorPlugin"))
project.tasks.getByName("run#installPlugin").dependsOn("run#copyPlugins")
project.tasks.getByName("run#start").dependsOn.remove(project.tasks.getByName("run#installPlugin"))
project.tasks.getByName("run#start").dependsOn("run#installOpendistroAnomalyDetectorPlugin")
if (_numNodes == 1) {
project.tasks.getByName("runMultiNode#installOpendistroAnomalyDetectorPlugin").dependsOn("runMultiNode#installPlugin")
project.tasks.getByName("runMultiNode#installPlugin").dependsOn.remove(project.tasks.getByName("runMultiNode#installOpendistroAnomalyDetectorPlugin"))
project.tasks.getByName("runMultiNode#installPlugin").dependsOn("runMultiNode#copyPlugins")
project.tasks.getByName("runMultiNode#start").dependsOn.remove(project.tasks.getByName("runMultiNode#installPlugin"))
project.tasks.getByName("runMultiNode#start").dependsOn("runMultiNode#installOpendistroAnomalyDetectorPlugin")
} else {
(0..<_numNodes).each {
n ->
project.tasks.getByName("runMultiNode#node${n}.installOpendistroAnomalyDetectorPlugin").dependsOn("runMultiNode#node${n}.installPlugin")
project.tasks.getByName("runMultiNode#node${n}.installPlugin").dependsOn.remove(project.tasks.getByName("runMultiNode#node${n}.installOpendistroAnomalyDetectorPlugin"))
project.tasks.getByName("runMultiNode#node${n}.installPlugin").dependsOn("runMultiNode#node${n}.copyPlugins")
project.tasks.getByName("runMultiNode#node${n}.start").dependsOn.remove(project.tasks.getByName("runMultiNode#node${n}.installPlugin"))
project.tasks.getByName("runMultiNode#node${n}.start").dependsOn("runMultiNode#node${n}.installOpendistroAnomalyDetectorPlugin")
}
}
ospackage {
packageName = "${name}"
release = isSnapshot ? "0.1" : '1'
version = "${project.version}" - "-SNAPSHOT"
into '/usr/share/elasticsearch/plugins'
from(zipTree(bundlePlugin.archivePath)) {
into esplugin.name
}
user 'root'
permissionGroup 'root'
fileMode 0644
dirMode 0755
requires('elasticsearch-oss', versions.elasticsearch, EQUAL)
packager = 'Amazon'
vendor = 'Amazon'
os = 'LINUX'
prefix '/usr'
license 'ASL-2.0'
maintainer 'OpenDistro for Elasticsearch Team <[email protected]>'
url 'https://opendistro.github.io/elasticsearch/downloads'
summary '''
Anomaly Detection plugin for OpenDistro for Elasticsearch.
Reference documentation can be found at https://opendistro.github.io/for-elasticsearch-docs/.
'''.stripIndent().replace('\n', ' ').trim()
}
buildRpm {
arch = 'NOARCH'
archiveName "${packageName}-${version}.rpm"
dependsOn 'assemble'
}
buildDeb {
arch = 'amd64'
archiveName "${packageName}-${version}.deb"
dependsOn 'assemble'
}
task buildPackages(type: GradleBuild) {
tasks = ['build', 'buildRpm', 'buildDeb']
}
}
tasks.whenTaskAdded { task ->
if (task.name == "integTestCluster#wait") {
project.tasks.getByName("integTestCluster#installOpendistroAnomalyDetectorPlugin").dependsOn("integTestCluster#installPlugin")
project.tasks.getByName("integTestCluster#installPlugin").dependsOn.remove(project.tasks.getByName("integTestCluster#installOpendistroAnomalyDetectorPlugin"))
project.tasks.getByName("integTestCluster#installPlugin").dependsOn("integTestCluster#copyPlugins")
project.tasks.getByName("integTestCluster#start").dependsOn.remove(project.tasks.getByName("integTestCluster#installPlugin"))
project.tasks.getByName("integTestCluster#start").dependsOn("integTestCluster#installOpendistroAnomalyDetectorPlugin")
}
}
spotless {
java {
eclipse().configFile rootProject.file('.eclipseformat.xml')
}
}