forked from opensearch-project/k-NN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
320 lines (273 loc) · 10.2 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
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
/*
* Copyright 2020 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 {
opensearch_version = System.getProperty("opensearch.version", "1.0.0")
opensearch_group = "org.opensearch"
}
// This isn't applying from repositories.gradle so repeating git diff it here
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
mavenLocal()
jcenter()
}
repositories {
mavenLocal()
}
dependencies {
classpath "${opensearch_group}.gradle:build-tools:${opensearch_version}"
}
}
//****************************************************************************/
// Build configurations
//****************************************************************************/
plugins {
id 'java-library'
id 'nebula.ospackage' version "8.3.0" apply false
id 'idea'
id 'jacoco'
}
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
mavenLocal()
jcenter()
}
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.rest-test'
checkstyle {
toolVersion = '8.24'
configFile file("checkstyle/checkstyle.xml")
}
checkstyleMain.ignoreFailures = true
checkstyleTest.ignoreFailures = true
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
def integTestDependOnJniLib = false
if (!usingRemoteCluster) {
integTestDependOnJniLib = true
if (!usingMultiNode) {
apply from: 'build-tools/knnplugin-coverage.gradle'
}
}
ext {
opensearchVersion = '1.0.0'
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
projectSubstitutions = [:]
licenseFile = rootProject.file('LICENSE.TXT')
noticeFile = rootProject.file('NOTICE.TXT')
}
allprojects {
group = 'org.opensearch'
version = "${opensearchVersion}.0"
apply from: 'build-tools/repositories.gradle'
plugins.withId('java') {
sourceCompatibility = targetCompatibility = "1.8"
}
}
jacoco {
toolVersion = "0.8.5"
}
check.dependsOn jacocoTestReport
opensearchplugin {
name 'opensearch-knn'
// zip file name and plugin name in ${opensearch.plugin.name} read by OpenSearch when plugin loading
description 'OpenSearch k-NN plugin'
classname 'org.opensearch.knn.plugin.KNNPlugin'
extendedPlugins = ['lang-painless']
}
tasks.named("integTest").configure {
it.dependsOn(project.tasks.named("bundlePlugin"))
}
task release(type: Copy, group: 'build') {
dependsOn allprojects*.tasks.build
from(zipTree(project.tasks.bundlePlugin.outputs.files.getSingleFile()))
into "build/plugins/opensearch-knn"
includeEmptyDirs = false
eachFile { it.path = it.path - "opensearch/" }
}
//****************************************************************************/
// Dependencies
//****************************************************************************/
dependencies {
compile "org.opensearch:opensearch:${opensearch_version}"
compileOnly "org.opensearch.plugin:opensearch-scripting-painless-spi:${versions.opensearch}"
compile group: 'com.google.guava', name: 'failureaccess', version:'1.0.1'
compile group: 'com.google.guava', name: 'guava', version:'29.0-jre'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
testImplementation "org.opensearch.test:framework:${opensearch_version}"
configurations.all {
resolutionStrategy {
force "com.puppycrawl.tools:checkstyle:${project.checkstyle.toolVersion}"
}
}
}
licenseHeaders.enabled = true
dependencyLicenses.enabled = false
thirdPartyAudit.enabled = false
loggerUsageCheck.enabled = false
def opensearch_tmp_dir = rootProject.file('build/private/opensearch_tmp').absoluteFile
opensearch_tmp_dir.mkdirs()
task cmakeJniLib(type:Exec) {
workingDir 'jni'
commandLine 'cmake', '.'
}
task buildJniLib(type:Exec) {
dependsOn cmakeJniLib
workingDir 'jni'
commandLine 'make'
}
test {
dependsOn buildJniLib
systemProperty 'tests.security.manager', 'false'
systemProperty "java.library.path", "$rootDir/jni/release"
}
def _numNodes = findProperty('numNodes') as Integer ?: 1
integTest {
if (integTestDependOnJniLib) {
dependsOn buildJniLib
}
systemProperty 'tests.security.manager', 'false'
systemProperty 'java.io.tmpdir', opensearch_tmp_dir.absolutePath
systemProperty "java.library.path", "$rootDir/jni/release"
// allows integration test classes to access test resource from project root path
systemProperty('project.root', project.rootDir.absolutePath)
systemProperty "https", System.getProperty("https")
systemProperty "user", System.getProperty("user")
systemProperty "password", System.getProperty("password")
doFirst {
// Tell the test JVM if the cluster JVM is running under a debugger so that tests can
// use longer timeouts for requests.
def isDebuggingCluster = getDebug() || System.getProperty("test.debug") != null
systemProperty 'cluster.debug', isDebuggingCluster
// 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 -Ddebug.es 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'
}
}
testClusters.integTest {
testDistribution = "ARCHIVE"
plugin(project.tasks.bundlePlugin.archiveFile)
// 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 opensearch 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
}
}
systemProperty("java.library.path", "$rootDir/jni/release")
}
run {
useCluster project.testClusters.integTest
dependsOn buildJniLib
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()
}
}
}
//TODO fix these
forbiddenApis.ignoreFailures = true
forbiddenPatterns {
setEnabled(false)
}
// We don't need to follow OpenSearch testing naming conventions.
// see https://github.com/opensearch-project/OpenSearch/blob/main/buildSrc/src/main/java/org/opensearch/gradle/precommit/TestingConventionsTasks.java
// enable testingConventions check will cause errors like: "Classes ending with [Tests] must subclass [LuceneTestCase]"
testingConventions.enabled = false
validateNebulaPom.enabled = false
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 {
ospackage {
packageName = "${name}"
release = isSnapshot ? "0.1" : '1'
version = "${project.version}" - "-SNAPSHOT"
into '/usr/share/opensearch/plugins'
from(zipTree(bundlePlugin.archivePath)) {
into opensearchplugin.name
}
user 'root'
permissionGroup 'root'
fileMode 0644
dirMode 0755
requires('opensearch', versions.opensearch, EQUAL)
requires("opensearch-knnlib", "${opensearchVersion}.0", EQUAL)
packager = 'Amazon'
vendor = 'Amazon'
os = 'LINUX'
prefix '/usr'
license 'ASL-2.0'
maintainer 'OpenSearch <[email protected]>'
url 'https://opensearch.org/downloads.html'
summary '''
KNN plugin for OpenSearch.
'''.stripIndent().replace('\n', ' ').trim()
}
buildRpm {
arch = 'NOARCH'
dependsOn 'assemble'
finalizedBy 'renameRpm'
task renameRpm(type: Copy) {
from("$buildDir/distributions")
into("$buildDir/distributions")
include archiveName
rename archiveName, "${packageName}-${version}.rpm"
doLast { delete file("$buildDir/distributions/$archiveName") }
}
}
buildDeb {
arch = 'all'
dependsOn 'assemble'
finalizedBy 'renameDeb'
task renameDeb(type: Copy) {
from("$buildDir/distributions")
into("$buildDir/distributions")
include archiveName
rename archiveName, "${packageName}-${version}.deb"
doLast { delete file("$buildDir/distributions/$archiveName") }
}
}
task buildPackages(type: GradleBuild) {
tasks = ['build', 'buildRpm', 'buildDeb']
}
}