From 395ef4b07a33611931eec4ad5b31c3dd66f28350 Mon Sep 17 00:00:00 2001 From: Jack Mazanec Date: Fri, 22 May 2020 16:51:32 -0700 Subject: [PATCH 1/4] Fix test structure (#125) --- .../knn/plugin/stats/KNNCounter.java | 7 ++++ .../knn/{index => }/KNNRestTestCase.java | 3 +- .../knn/{index => }/KNNResult.java | 2 +- .../knn/KNNTestCase.java | 33 +++++++++++++++++++ .../knn/index/KNNCircuitBreakerIT.java | 1 + .../knn/index/KNNESIT.java | 2 ++ .../knn/index/KNNESSettingsTestIT.java | 1 + .../knn/index/KNNIndexCacheTests.java | 10 ++++++ .../knn/index/KNNJNITests.java | 4 +-- .../knn/index/KNNMapperSearcherIT.java | 2 ++ .../knn/index/KNNQueryBuilderTests.java | 4 +-- .../knn/index/codec/KNNCodecTestCase.java | 4 +-- .../plugin/action/RestKNNStatsHandlerIT.java | 2 +- .../knn/plugin/stats/KNNCounterTests.java | 4 +-- .../suppliers/KNNCounterSupplierTests.java | 4 +-- 15 files changed, 70 insertions(+), 13 deletions(-) rename src/test/java/com/amazon/opendistroforelasticsearch/knn/{index => }/KNNRestTestCase.java (99%) rename src/test/java/com/amazon/opendistroforelasticsearch/knn/{index => }/KNNResult.java (94%) create mode 100644 src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNTestCase.java diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounter.java b/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounter.java index 0d3ff4c6..dcac112c 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounter.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounter.java @@ -64,4 +64,11 @@ public Long getCount() { public void increment() { count.getAndIncrement(); } + + /** + * Set the value of a counter + */ + public void set(long value) { + count.set(value); + } } \ No newline at end of file diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNRestTestCase.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNRestTestCase.java similarity index 99% rename from src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNRestTestCase.java rename to src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNRestTestCase.java index ba3b1358..7523cb8d 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNRestTestCase.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNRestTestCase.java @@ -13,8 +13,9 @@ * permissions and limitations under the License. */ -package com.amazon.opendistroforelasticsearch.knn.index; +package com.amazon.opendistroforelasticsearch.knn; +import com.amazon.opendistroforelasticsearch.knn.index.KNNQueryBuilder; import com.amazon.opendistroforelasticsearch.knn.plugin.KNNPlugin; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNResult.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNResult.java similarity index 94% rename from src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNResult.java rename to src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNResult.java index d3178520..93fed763 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNResult.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNResult.java @@ -13,7 +13,7 @@ * permissions and limitations under the License. */ -package com.amazon.opendistroforelasticsearch.knn.index; +package com.amazon.opendistroforelasticsearch.knn; public class KNNResult { private String docId; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNTestCase.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNTestCase.java new file mode 100644 index 00000000..5ad2cbab --- /dev/null +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/KNNTestCase.java @@ -0,0 +1,33 @@ +/* + * 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. + */ + +package com.amazon.opendistroforelasticsearch.knn; + +import com.amazon.opendistroforelasticsearch.knn.plugin.stats.KNNCounter; +import org.elasticsearch.test.ESTestCase; +import org.junit.Before; + +/** + * Base class for integration tests for KNN plugin. Contains several methods for testing KNN ES functionality. + */ +public class KNNTestCase extends ESTestCase { + @Before + public void resetCounters() { + // Reset all of the counters + for (KNNCounter knnCounter : KNNCounter.values()) { + knnCounter.set(0L); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNCircuitBreakerIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNCircuitBreakerIT.java index 3a18a131..bc153c7a 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNCircuitBreakerIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNCircuitBreakerIT.java @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.knn.index; +import com.amazon.opendistroforelasticsearch.knn.KNNRestTestCase; import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Response; import org.elasticsearch.common.settings.Settings; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNESIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNESIT.java index c559a34b..be585524 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNESIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNESIT.java @@ -15,6 +15,8 @@ package com.amazon.opendistroforelasticsearch.knn.index; +import com.amazon.opendistroforelasticsearch.knn.KNNRestTestCase; +import com.amazon.opendistroforelasticsearch.knn.KNNResult; import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNESSettingsTestIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNESSettingsTestIT.java index ec9eeb96..f0975a5b 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNESSettingsTestIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNESSettingsTestIT.java @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.knn.index; +import com.amazon.opendistroforelasticsearch.knn.KNNRestTestCase; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.common.settings.Settings; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNIndexCacheTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNIndexCacheTests.java index a139b0d0..9e4651a5 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNIndexCacheTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNIndexCacheTests.java @@ -16,6 +16,7 @@ package com.amazon.opendistroforelasticsearch.knn.index; import com.amazon.opendistroforelasticsearch.knn.plugin.KNNPlugin; +import com.amazon.opendistroforelasticsearch.knn.plugin.stats.KNNCounter; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; @@ -41,6 +42,15 @@ public class KNNIndexCacheTests extends ESSingleNodeTestCase { private final String testIndexName = "test_index"; private final String testFieldName = "test_field"; + @Override + public void setUp() throws Exception { + super.setUp(); + // Reset all of the counters + for (KNNCounter knnCounter : KNNCounter.values()) { + knnCounter.set(0L); + } + } + @Override protected Collection> getPlugins() { return Collections.singletonList(KNNPlugin.class); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNJNITests.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNJNITests.java index 081b8af9..422f7f6f 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNJNITests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNJNITests.java @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.knn.index; +import com.amazon.opendistroforelasticsearch.knn.KNNTestCase; import com.amazon.opendistroforelasticsearch.knn.index.v1736.KNNIndex; import org.apache.logging.log4j.LogManager; @@ -22,7 +23,6 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.FilterDirectory; -import org.elasticsearch.test.ESTestCase; import java.nio.file.Paths; import java.security.AccessController; @@ -31,7 +31,7 @@ import java.util.Map; import java.util.stream.Collectors; -public class KNNJNITests extends ESTestCase { +public class KNNJNITests extends KNNTestCase { private static final Logger logger = LogManager.getLogger(KNNJNITests.class); public void testCreateHnswIndex() throws Exception { diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNMapperSearcherIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNMapperSearcherIT.java index 05b92c96..2a02a140 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNMapperSearcherIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNMapperSearcherIT.java @@ -15,6 +15,8 @@ package com.amazon.opendistroforelasticsearch.knn.index; +import com.amazon.opendistroforelasticsearch.knn.KNNRestTestCase; +import com.amazon.opendistroforelasticsearch.knn.KNNResult; import org.apache.http.util.EntityUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNQueryBuilderTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNQueryBuilderTests.java index 855aab38..25fb4be3 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNQueryBuilderTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/KNNQueryBuilderTests.java @@ -15,15 +15,15 @@ package com.amazon.opendistroforelasticsearch.knn.index; +import com.amazon.opendistroforelasticsearch.knn.KNNTestCase; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryShardContext; -import org.elasticsearch.test.ESTestCase; import org.mockito.Mockito; -public class KNNQueryBuilderTests extends ESTestCase { +public class KNNQueryBuilderTests extends KNNTestCase { public void testInvalidK() { float[] queryVector = {1.0f, 1.0f}; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNNCodecTestCase.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNNCodecTestCase.java index 6d980b73..6b095100 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNNCodecTestCase.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/index/codec/KNNCodecTestCase.java @@ -15,6 +15,7 @@ package com.amazon.opendistroforelasticsearch.knn.index.codec; +import com.amazon.opendistroforelasticsearch.knn.KNNTestCase; import com.amazon.opendistroforelasticsearch.knn.index.KNNIndexCache; import com.amazon.opendistroforelasticsearch.knn.index.KNNQuery; import com.amazon.opendistroforelasticsearch.knn.index.KNNSettings; @@ -37,7 +38,6 @@ import org.apache.lucene.store.IOContext; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.ResourceWatcherService; import org.mockito.Mockito; @@ -52,7 +52,7 @@ /** * Test used for testing Codecs */ -public class KNNCodecTestCase extends ESTestCase { +public class KNNCodecTestCase extends KNNTestCase { protected void setUpMockClusterService() { ClusterService clusterService = mock(ClusterService.class, RETURNS_DEEP_STUBS); diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/action/RestKNNStatsHandlerIT.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/action/RestKNNStatsHandlerIT.java index 06f09125..487560f2 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/action/RestKNNStatsHandlerIT.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/action/RestKNNStatsHandlerIT.java @@ -15,7 +15,7 @@ package com.amazon.opendistroforelasticsearch.knn.plugin.action; -import com.amazon.opendistroforelasticsearch.knn.index.KNNRestTestCase; +import com.amazon.opendistroforelasticsearch.knn.KNNRestTestCase; import com.amazon.opendistroforelasticsearch.knn.index.KNNQueryBuilder; import com.amazon.opendistroforelasticsearch.knn.plugin.stats.KNNStats; diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounterTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounterTests.java index 3f730dac..bfd62b9e 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounterTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounterTests.java @@ -15,9 +15,9 @@ package com.amazon.opendistroforelasticsearch.knn.plugin.stats; -import org.elasticsearch.test.ESTestCase; +import com.amazon.opendistroforelasticsearch.knn.KNNTestCase; -public class KNNCounterTests extends ESTestCase { +public class KNNCounterTests extends KNNTestCase { public void testGetName() { assertEquals(StatNames.GRAPH_QUERY_ERRORS.getName(), KNNCounter.GRAPH_QUERY_ERRORS.getName()); } diff --git a/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/suppliers/KNNCounterSupplierTests.java b/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/suppliers/KNNCounterSupplierTests.java index c9ae2c13..2a4398f7 100644 --- a/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/suppliers/KNNCounterSupplierTests.java +++ b/src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/suppliers/KNNCounterSupplierTests.java @@ -15,10 +15,10 @@ package com.amazon.opendistroforelasticsearch.knn.plugin.stats.suppliers; +import com.amazon.opendistroforelasticsearch.knn.KNNTestCase; import com.amazon.opendistroforelasticsearch.knn.plugin.stats.KNNCounter; -import org.elasticsearch.test.ESTestCase; -public class KNNCounterSupplierTests extends ESTestCase { +public class KNNCounterSupplierTests extends KNNTestCase { public void testNormal() { KNNCounterSupplier knnCounterSupplier = new KNNCounterSupplier(KNNCounter.GRAPH_QUERY_REQUESTS); assertEquals((Long) 0L, knnCounterSupplier.get()); From 52dd13b6aba29cc8d1a96f4b2f4706561493df3f Mon Sep 17 00:00:00 2001 From: Jack Mazanec Date: Tue, 26 May 2020 08:45:03 -0700 Subject: [PATCH 2/4] Build separate artifacts for library using CPack (#123) --- .gitignore | 6 ++- README.md | 14 +++++- build.gradle | 14 ++++-- jni/CMakeLists.txt | 47 ++++++++++++++++--- ...orelasticsearch_knn_index_v1736_KNNIndex.h | 0 ...elasticsearch_knn_index_v1736_KNNIndex.cpp | 0 6 files changed, 69 insertions(+), 12 deletions(-) rename jni/{src/v1736 => include}/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.h (100%) rename jni/src/{v1736 => }/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.cpp (100%) diff --git a/.gitignore b/.gitignore index f28dea7c..7670d112 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,8 @@ oss/* jni/CMakeCache.txt jni/CMakeFiles jni/Makefile -jni/cmake_install.cmake +jni/cmake* +jni/CPack* +jni/_CPack* +jni/release +jni/packages diff --git a/README.md b/README.md index 50f5778c..b397e85b 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,19 @@ cmake . make ``` -The library will be placed in the `buildSrc` directory. +The library will be placed in the `jni/release` directory. + +## Build JNI Library RPM/DEB + +To build an RPM or DEB of the JNI library, follow these steps: + +``` +cd jni +cmake . +make package +``` + +The artifacts will be placed in the `jni/packages` directory. ## Running Multi-node Cluster Locally diff --git a/build.gradle b/build.gradle index 51e60a02..c88eb32a 100644 --- a/build.gradle +++ b/build.gradle @@ -148,8 +148,15 @@ task buildJniLib(type:Exec) { commandLine 'make' } -test { +task makeJniLib(type: Copy) { dependsOn buildJniLib + from "$buildDir/jni/release" + include "*" + into "$buildDir/buildSrc" +} + +test { + dependsOn makeJniLib systemProperty 'tests.security.manager', 'false' systemProperty "java.library.path", "$rootDir/buildSrc" } @@ -157,7 +164,7 @@ test { def _numNodes = findProperty('numNodes') as Integer ?: 1 integTest { if (integTestDependOnJniLib) { - dependsOn buildJniLib + dependsOn makeJniLib } runner { systemProperty 'tests.security.manager', 'false' @@ -205,7 +212,7 @@ testClusters.integTest { } run { - dependsOn buildJniLib + dependsOn makeJniLib 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 @@ -248,6 +255,7 @@ afterEvaluate { dirMode 0755 requires('elasticsearch-oss', versions.elasticsearch, EQUAL) + requires("opendistro-knnlib", "1.8.0.0", EQUAL) packager = 'Amazon' vendor = 'Amazon' os = 'LINUX' diff --git a/jni/CMakeLists.txt b/jni/CMakeLists.txt index 96ab053c..4a18302d 100644 --- a/jni/CMakeLists.txt +++ b/jni/CMakeLists.txt @@ -22,6 +22,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) # Target Library to be built set(KNN_INDEX KNNIndexV1_7_3_6) +set(KNN_PACKAGE_NAME opendistro-knnlib) # Check if similarity search exists find_path(NMS_REPO_DIR NAMES similarity_search PATHS ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib REQUIRED) @@ -33,10 +34,11 @@ if (NOT EXISTS ${NMS_REPO_DIR}) endif () # Add the subdirectory so it is possible to use its targets -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib/similarity_search) +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib/similarity_search EXCLUDE_FROM_ALL) # Set OS specific variables if (${CMAKE_SYSTEM_NAME} STREQUAL Darwin) + set(CMAKE_MACOSX_RPATH 1) set(JVM_OS_TYPE darwin) set(LIB_EXT .jnilib) elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux) @@ -47,14 +49,45 @@ else() endif() # Compile the library -add_library(${KNN_INDEX} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/v1736/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.cpp) +add_library(${KNN_INDEX} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.cpp) target_link_libraries(${KNN_INDEX} NonMetricSpaceLib) -target_include_directories(${KNN_INDEX} PRIVATE $ENV{JAVA_HOME}/include $ENV{JAVA_HOME}/include/${JVM_OS_TYPE} ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib/similarity_search/include) +target_include_directories(${KNN_INDEX} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include $ENV{JAVA_HOME}/include $ENV{JAVA_HOME}/include/${JVM_OS_TYPE} ${CMAKE_CURRENT_SOURCE_DIR}/external/nmslib/similarity_search/include) set_target_properties(${KNN_INDEX} PROPERTIES SUFFIX ${LIB_EXT}) set_target_properties(${KNN_INDEX} PROPERTIES POSITION_INDEPENDENT_CODE ON) -set_target_properties(${KNN_INDEX} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../buildSrc) +set_target_properties(${KNN_INDEX} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/release) -# Log directory where library will be placed -get_target_property(JNILibDir ${KNN_INDEX} LIBRARY_OUTPUT_DIRECTORY) -message(STATUS "JNI Library Output Directory: ${JNILibDir}") \ No newline at end of file +# Installation rules for shared library +install(TARGETS ${KNN_INDEX} + LIBRARY DESTINATION lib + COMPONENT library) + +# CPack section to build artifacts +set(KNN_MAINTAINER "OpenDistro for Elasticsearch Team ") +set(ODFE_DOWNLOAD_URL "https://opendistro.github.io/elasticsearch/downloads") +set(CPACK_PACKAGE_NAME ${KNN_PACKAGE_NAME}) +set(CPACK_PACKAGE_VERSION 1.8.0.0) +set(CMAKE_INSTALL_PREFIX /usr) +set(CPACK_GENERATOR "RPM;DEB") +SET(CPACK_OUTPUT_FILE_PREFIX packages) +set(CPACK_PACKAGE_RELEASE 0.1) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "KNN JNI library built off of NMSLIB for OpenDistro for Elasticsearch. Reference documentation can be found at https://opendistro.github.io/for-elasticsearch-docs/.") +set(CPACK_PACKAGE_VENDOR "Amazon") +set(CPACK_PACKAGE_CONTACT "Maintainer: ${KNN_MAINTAINER}") +set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) +set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}_${JVM_OS_TYPE}.${CMAKE_SYSTEM_PROCESSOR}") + +# RPM Specific variables +set(CPACK_RPM_PACKAGE_RELEASE ${CPACK_PACKAGE_RELEASE}) +set(CPACK_RPM_PACKAGE_URL ${ODFE_DOWNLOAD_URL}) +set(CPACK_RPM_PACKAGE_DESCRIPTION "Open Distro for Elasticsearch KNN JNI Library") +set(CPACK_RPM_PACKAGE_LICENSE "ASL-2.0") + +# DEB Specific variables +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${ODFE_DOWNLOAD_URL}) +set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${KNN_MAINTAINER}) +set(CPACK_DEBIAN_PACKAGE_SOURCE ${CPACK_PACKAGE_NAME}) +set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) +set(CPACK_DEBIAN_PACKAGE_SECTION "libs") + +include(CPack) \ No newline at end of file diff --git a/jni/src/v1736/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.h b/jni/include/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.h similarity index 100% rename from jni/src/v1736/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.h rename to jni/include/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.h diff --git a/jni/src/v1736/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.cpp b/jni/src/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.cpp similarity index 100% rename from jni/src/v1736/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.cpp rename to jni/src/com_amazon_opendistroforelasticsearch_knn_index_v1736_KNNIndex.cpp From 5c6b607a67247254b1fa4f3485ae94fcb26ce4ea Mon Sep 17 00:00:00 2001 From: qchea Date: Sun, 31 May 2020 17:49:43 -0500 Subject: [PATCH 3/4] FIX: buildDir->rootDir --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index c88eb32a..58e83e4b 100644 --- a/build.gradle +++ b/build.gradle @@ -150,9 +150,9 @@ task buildJniLib(type:Exec) { task makeJniLib(type: Copy) { dependsOn buildJniLib - from "$buildDir/jni/release" + from "$rootDir/jni/release" include "*" - into "$buildDir/buildSrc" + into "$rootDir/buildSrc" } test { From 29f31194f78b5196e7221f2402a3ed3979ec0400 Mon Sep 17 00:00:00 2001 From: Jack Mazanec Date: Sun, 7 Jun 2020 12:24:22 -0700 Subject: [PATCH 4/4] added github action to build library artifacts (#132) --- .github/workflows/CD.yml | 24 +++++++++++++++++++++--- README.md | 2 ++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index c4360457..07eafcda 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -9,13 +9,14 @@ jobs: strategy: matrix: java: [14] + compiler: [g++-5] name: Build and Release k-NN Plugin - runs-on: ubuntu-latest + runs-on: ubuntu-16.04 steps: - name: Checkout k-NN - uses: actions/checkout@v1 + uses: actions/checkout@v2 - name: Configure AWS uses: aws-actions/configure-aws-credentials@v1 @@ -29,7 +30,24 @@ jobs: with: java-version: ${{ matrix.java }} - - name: Run build + - name: Build and ship library artifacts + env: + CXX: ${{ matrix.compiler }} + run: | + cd jni + cmake . + make package + + artifact=`ls release/*.so` + rpm_artifact=`ls packages/*.rpm` + deb_artifact=`ls packages/*.deb` + + aws s3 cp $artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/elasticsearch-plugins/opendistro-knn/ + aws s3 cp $rpm_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/rpms/opendistro-knn/ + aws s3 cp $deb_artifact s3://artifacts.opendistroforelasticsearch.amazon.com/downloads/debs/opendistro-knn/ + aws cloudfront create-invalidation --distribution-id E1VG5HMIWI4SA2 --paths "/*" + + - name: Build and ship plugin artifacts run: | ./gradlew buildPackages --console=plain -Dbuild.snapshot=false artifact=`ls build/distributions/*.zip` diff --git a/README.md b/README.md index b397e85b..145d938f 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ make package The artifacts will be placed in the `jni/packages` directory. +Additionally, we build the RPM and DEB in [this GitHub action](https://github.com/opendistro-for-elasticsearch/k-NN/blob/master/.github/workflows/CD.yml). We use Ubuntu 16.04 with g++ 5.4.0. + ## Running Multi-node Cluster Locally It can be useful to test and debug on a multi-node cluster. In order to launch a 3 node cluster with the KNN plugin installed, run the following command: