diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..a00102e8e --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,84 @@ +pipeline { + agent none + + triggers { + pollSCM 'H/10 * * * *' + upstream(upstreamProjects: "spring-data-commons/master", threshold: hudson.model.Result.SUCCESS) + } + + options { + disableConcurrentBuilds() + } + + stages { + stage("Test") { + parallel { + stage("test: baseline") { + agent { + docker { + image 'adoptopenjdk/openjdk8:latest' + args '-v $HOME/.m2:/root/.m2' + } + } + steps { + sh "./mvnw clean dependency:list test -Dsort -B" + } + } + } + } + stage('Release to artifactory') { + when { + branch 'issue/*' + } + agent { + docker { + image 'adoptopenjdk/openjdk8:latest' + args '-v $HOME/.m2:/root/.m2' + } + } + + environment { + ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c') + } + + steps { + sh "USERNAME=${ARTIFACTORY_USR} PASSWORD=${ARTIFACTORY_PSW} ./mvnw -Pci,snapshot -Dmaven.test.skip=true clean deploy -B" + } + } + stage('Release to artifactory with docs') { + when { + branch 'master' + } + agent { + docker { + image 'adoptopenjdk/openjdk8:latest' + args '-v $HOME/.m2:/root/.m2' + } + } + + environment { + ARTIFACTORY = credentials('02bd1690-b54f-4c9f-819d-a77cb7a9822c') + } + + steps { + sh "USERNAME=${ARTIFACTORY_USR} PASSWORD=${ARTIFACTORY_PSW} ./mvnw -Pci,snapshot -Dmaven.test.skip=true clean deploy -B" + } + } + } + + post { + changed { + script { + slackSend( + color: (currentBuild.currentResult == 'SUCCESS') ? 'good' : 'danger', + channel: '#spring-data-dev', + message: "${currentBuild.fullDisplayName} - `${currentBuild.currentResult}`\n${env.BUILD_URL}") + emailext( + subject: "[${currentBuild.fullDisplayName}] ${currentBuild.currentResult}", + mimeType: 'text/html', + recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']], + body: "${currentBuild.fullDisplayName} is reported as ${currentBuild.currentResult}") + } + } + } +} diff --git a/README.md b/README.adoc similarity index 62% rename from README.md rename to README.adoc index 04644c299..8f2145aaf 100644 --- a/README.md +++ b/README.adoc @@ -1,44 +1,48 @@ -Spring Data Elasticsearch -========================= +image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-elasticsearch%2Fmaster&subject=Moore%20(master)[link=https://jenkins.spring.io/view/SpringData/job/spring-data-elasticsearch/] +image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-elasticsearch%2F3.1.x&subject=Lovelace%20(3.1.x)[link=https://jenkins.spring.io/view/SpringData/job/spring-data-elasticsearch/] +image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-elasticsearch%2F2.1.x&subject=Ingalls%20(2.1.x)[link=https://jenkins.spring.io/view/SpringData/job/spring-data-elasticsearch/] + + += Spring Data Elasticsearch Spring Data implementation for ElasticSearch Spring Data makes it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services as well as provide improved support for relational database technologies. -The Spring Data Elasticsearch project provides integration with the [elasticsearch](https://www.elastic.co/) search engine. +The Spring Data Elasticsearch project provides integration with the https://www.elastic.co/[elasticsearch] search engine. -Guide ------------- +== Guide -* [Reference Documentation](https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/) -* [API Documentation](https://docs.spring.io/spring-data/elasticsearch/docs/current/api/) -* [Spring Data Project](https://projects.spring.io/spring-data) -* [Sample Test Application](https://github.com/BioMedCentralLtd/spring-data-elasticsearch-sample-application) -* [Issues](https://jira.springsource.org/browse/DATAES) -* [Spring Data Elasticsearch Google Group](https://groups.google.com/d/forum/spring-data-elasticsearch-devs) -* [Questions](https://stackoverflow.com/questions/tagged/spring-data-elasticsearch) +* https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/[Reference Documentation] +* https://docs.spring.io/spring-data/elasticsearch/docs/current/api/[API Documentation] +* https://projects.spring.io/spring-data[Spring Data Project] +* https://github.com/BioMedCentralLtd/spring-data-elasticsearch-sample-application[Sample Test Application] +* https://jira.springsource.org/browse/DATAES[Issues] +* https://groups.google.com/d/forum/spring-data-elasticsearch-devs[Spring Data Elasticsearch Google Group] +* https://stackoverflow.com/questions/tagged/spring-data-elasticsearch[Questions] +== Quick Start -Quick Start ------------ -Wiki page for [Getting Started](https://github.com/spring-projects/spring-data-elasticsearch/wiki/How-to-start-with-spring-data-elasticsearch) +Wiki page for https://github.com/spring-projects/spring-data-elasticsearch/wiki/How-to-start-with-spring-data-elasticsearch[Getting Started] -### Maven configuration +=== Maven configuration Add the Maven dependency: -```xml +[source,xml] +---- org.springframework.data spring-data-elasticsearch x.y.z.RELEASE -``` +---- If you'd rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version. -```xml +[source,xml] +---- org.springframework.data spring-data-elasticsearch @@ -50,37 +54,42 @@ the appropriate dependency version. Spring Snapshot Repository https://repo.spring.io/libs-snapshot -``` +---- -| spring data elasticsearch | elasticsearch | -|:-------------------------:|:-------------:| -| 3.2.x | 6.5.0 | -| 3.1.x | 6.2.2 | -| 3.0.x | 5.5.0 | -| 2.1.x | 2.4.0 | -| 2.0.x | 2.2.0 | -| 1.3.x | 1.5.2 | +[cols="^,^"] +|=== +|spring data elasticsearch |elasticsearch +|3.2.x |6.5.0 +|3.1.x |6.2.2 +|3.0.x |5.5.0 +|2.1.x |2.4.0 +|2.0.x |2.2.0 +|1.3.x |1.5.2 +|=== + +=== ElasticsearchRepository -### ElasticsearchRepository A default implementation of ElasticsearchRepository, aligning to the generic Repository Interfaces, is provided. Spring can do the Repository implementation for you depending on method names in the interface definition. The ElasticsearchCrudRepository extends PagingAndSortingRepository -```java +[source,java] +---- public interface ElasticsearchCrudRepository extends ElasticsearchRepository, PagingAndSortingRepository { } -``` +---- Extending ElasticsearchRepository for custom methods -```java +[source,java] +---- public interface BookRepository extends Repository { List findByNameAndPrice(String name, Integer price); List findByNameOrPrice(String name, Integer price); - + Page findByName(String name,Pageable page); Page findByNameNot(String name,Pageable page); @@ -92,10 +101,12 @@ Extending ElasticsearchRepository for custom methods @Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}") Page findByMessage(String message, Pageable pageable); } -``` +---- + Indexing a single document with Repository -```java +[source,java] +---- @Autowired private SampleElasticsearchRepository repository; @@ -105,11 +116,12 @@ Indexing a single document with Repository sampleEntity.setMessage("some message"); repository.save(sampleEntity); -``` +---- Indexing multiple Document(bulk index) using Repository -```java +[source,java] +---- @Autowired private SampleElasticsearchRepository repository; @@ -127,27 +139,28 @@ Indexing multiple Document(bulk index) using Repository //bulk index repository.save(sampleEntities); -``` +---- - -### ElasticsearchTemplate +=== ElasticsearchTemplate ElasticsearchTemplate is the central support class for elasticsearch operations. Indexing a single document using Elasticsearch Template -```java +[source,java] +---- String documentId = "123456"; SampleEntity sampleEntity = new SampleEntity(); sampleEntity.setId(documentId); sampleEntity.setMessage("some message"); IndexQuery indexQuery = new IndexQueryBuilder().withId(sampleEntity.getId()).withObject(sampleEntity).build(); elasticsearchTemplate.index(indexQuery); -``` +---- Indexing multiple Document(bulk index) using Elasticsearch Template -```java +[source,java] +---- @Autowired private ElasticsearchTemplate elasticsearchTemplate; @@ -172,11 +185,12 @@ Indexing multiple Document(bulk index) using Elasticsearch Template //bulk index elasticsearchTemplate.bulkIndex(indexQueries); -``` +---- Searching entities using Elasticsearch Template -```java +[source,java] +---- @Autowired private ElasticsearchTemplate elasticsearchTemplate; @@ -184,14 +198,15 @@ Searching entities using Elasticsearch Template .withQuery(queryString(documentId).field("id")) .build(); Page sampleEntities = elasticsearchTemplate.queryForPage(searchQuery,SampleEntity.class); -``` +---- -### Reactive Elasticsearch +=== Reactive Elasticsearch The `ReactiveElasticsearchClient` is a non official driver based on `WebClient`. It uses the request/response objects provided by the Elasticsearch core project. -```java +[source,java] +---- @Configuration public class Config { @@ -216,14 +231,15 @@ Mono response = client.index(request -> .source(singletonMap("feature", "reactive-client")) .setRefreshPolicy(IMMEDIATE) ); -``` +---- -The reactive client response, especially for search operations, is bound to the `from` (offset) & `size` (limit) options of the request. +The reactive client response, especially for search operations, is bound to the `from` (offset) & `size` (limit) options of the request. `ReactiveElasticsearchOperations` is the gateway to executing high level commands against an Elasticsearch cluster using the `ReactiveElasticsearchClient`. The easiest way of setting up the `ReactiveElasticsearchTemplate` is via `AbstractReactiveElasticsearchConfiguration`. -```java +[source,java] +---- @Configuration public class Config extends AbstractReactiveElasticsearchConfiguration { @@ -233,11 +249,12 @@ public class Config extends AbstractReactiveElasticsearchConfiguration { // ... } } -``` +---- If needed the `ReactiveElasticsearchTemplate` can be configured with default `RefreshPolicy` and `IndicesOptions` that get applied to the related requests by overriding the defaults of `refreshPolicy()` and `indicesOptions()`. -```java +[source,java] +---- template.save(new Person("Bruce Banner", 42)) .doOnNext(System.out::println) .flatMap(person -> template.findById(person.id, Person.class)) @@ -247,24 +264,26 @@ template.save(new Person("Bruce Banner", 42)) .flatMap(id -> template.count(Person.class)) .doOnNext(System.out::println) .subscribe(); -``` +---- The above outputs the following sequence on the console. -```bash +[source,bash] +---- > Person(id=QjWCWWcBXiLAnp77ksfR, name=Bruce Banner, age=42) > Person(id=QjWCWWcBXiLAnp77ksfR, name=Bruce Banner, age=42) > QjWCWWcBXiLAnp77ksfR > 0 -``` +---- -### XML Namespace +=== XML Namespace You can set up repository scanning via xml configuration, which will happily create your repositories. Using Node Client -```xml +[source,xml] +---- -``` +---- Using Transport Client -```xml +[source,xml] +---- -``` +---- -## Help Pages +== Help Pages -* [Geo distance and location search](https://github.com/spring-projects/spring-data-elasticsearch/wiki/Geo-indexing-and-request) -* [Custom object mapper](https://github.com/spring-projects/spring-data-elasticsearch/wiki/Custom-ObjectMapper) +* https://github.com/spring-projects/spring-data-elasticsearch/wiki/Geo-indexing-and-request[Geo distance and location search] +* https://github.com/spring-projects/spring-data-elasticsearch/wiki/Custom-ObjectMapper[Custom object mapper] -## Contributing to Spring Data +== Contributing to Spring Data Here are some ways for you to get involved in the community: -* Get involved with the Spring community on Stack OverFlow. Please help out on the [forum](https://stackoverflow.com/questions/tagged/spring-data-elasticsearch) by responding to questions and joining the debate. -* Create [JIRA](https://jira.spring.io/browse/DATAES/) tickets for bugs and new features and comment and vote on the ones that you are interested in. -* Github is for social coding: if you want to write code, we encourage contributions through pull requests from [forks of this repository](https://help.github.com/forking/). If you want to contribute code this way, please reference a JIRA ticket as well covering the specific issue you are addressing. -* Watch for upcoming articles on Spring by [subscribing](https://www.springsource.org/node/feed) to springframework.org +* Get involved with the Spring community on Stack OverFlow. Please help out on the https://stackoverflow.com/questions/tagged/spring-data-elasticsearch[forum] by responding to questions and joining the debate. +* Create https://jira.spring.io/browse/DATAES/[JIRA] tickets for bugs and new features and comment and vote on the ones that you are interested in. +* Github is for social coding: if you want to write code, we encourage contributions through pull requests from https://help.github.com/forking/[forks of this repository]. If you want to contribute code this way, please reference a JIRA ticket as well covering the specific issue you are addressing. +* Watch for upcoming articles on Spring by https://www.springsource.org/node/feed[subscribing] to springframework.org -Before we accept a non-trivial patch or pull request we will need you to [sign the Contributor License Agreement](https://cla.pivotal.io/sign/spring). Signing the contributor’s agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. If you forget to do so, you'll be reminded when you submit a pull request. Active contributors might be asked to join the core team, and given the ability to merge pull requests. +Before we accept a non-trivial patch or pull request we will need you to https://cla.pivotal.io/sign/spring[sign the Contributor License Agreement]. Signing the contributor’s agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. If you forget to do so, you'll be reminded when you submit a pull request. Active contributors might be asked to join the core team, and given the ability to merge pull requests. +Code formatting for https://github.com/spring-projects/spring-data-build/tree/master/etc/ide[Eclipse and Intellij] -Code formatting for [Eclipse and Intellij](https://github.com/spring-projects/spring-data-build/tree/master/etc/ide) +https://github.com/spring-projects/spring-data-build/blob/master/CONTRIBUTING.adoc[More information about contributing to Spring Data] + +== Running CI tasks locally + +Since this pipeline is purely Docker-based, it's easy to: + +* Debug what went wrong on your local machine. +* Test out a a tweak to your `test.sh` script before sending it out. +* Experiment against a new image before submitting your pull request. + +All of these use cases are great reasons to essentially run what the CI server does on your local machine. + +IMPORTANT: To do this you must have Docker installed on your machine. + +1. `docker run -it --mount type=bind,source="$(pwd)",target=/spring-data-elasticsearch-github adoptopenjdk/openjdk8:latest /bin/bash` ++ +This will launch the Docker image and mount your source code at `spring-data-elasticsearch-github`. ++ +2. `cd spring-data-elasticsearch-github` ++ +Next, run your tests from inside the container: ++ +3. `./mvnw clean dependency:list test -Dsort` (or whatever profile you need to test out) + +Since the container is binding to your source, you can make edits from your IDE and continue to run build jobs. + +If you need to test the `build.sh` script, do this: + +1. `docker run -it --mount type=bind,source="$(pwd)",target=/spring-data-elasticsearch-github adoptopenjdk/openjdk8:latest /bin/bash` ++ +This will launch the Docker image and mount your source code at `spring-data-elasticsearch-github`. ++ +2. `cd spring-data-elasticsearch-github` ++ +Next, try to package everything up from inside the container: ++ +3. `./mvnw -Pci,snapshot -Dmaven.test.skip=true clean deploy` + +IMPORTANT: This will attempt to deploy to artifactory, but without credentials, it will fail, leaving you simply with a built artifact. + +NOTE: Docker containers can eat up disk space fast! From time to time, run `docker system prune` to clean out old images. -[More information about contributing to Spring Data](https://github.com/spring-projects/spring-data-build/blob/master/CONTRIBUTING.adoc) diff --git a/ci/build.sh b/ci/build.sh deleted file mode 100755 index 863b8d46d..000000000 --- a/ci/build.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env sh - -set -euo pipefail - -[[ -d $PWD/maven && ! -d $HOME/.m2 ]] && ln -s $PWD/maven $HOME/.m2 - -spring_data_elasticsearch_artifactory=$(pwd)/spring-data-elasticsearch-artifactory - -rm -rf $HOME/.m2/repository/org/springframework/data 2> /dev/null || : - -cd spring-data-elasticsearch-github - -./mvnw deploy \ - -Dmaven.test.skip=true \ - -DaltDeploymentRepository=distribution::default::file://${spring_data_elasticsearch_artifactory} diff --git a/ci/build.yml b/ci/build.yml deleted file mode 100644 index 759d679e4..000000000 --- a/ci/build.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -platform: linux - -image_resource: - type: docker-image - source: - repository: openjdk - tag: 8-jdk-alpine - -inputs: -- name: spring-data-elasticsearch-github - -outputs: -- name: spring-data-elasticsearch-artifactory - -caches: -- path: maven - -run: - path: spring-data-elasticsearch-github/ci/build.sh diff --git a/ci/test.sh b/ci/test.sh deleted file mode 100755 index 5d8f6a17b..000000000 --- a/ci/test.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env sh - -set -euo pipefail - -[[ -d $PWD/maven && ! -d $HOME/.m2 ]] && ln -s $PWD/maven $HOME/.m2 - -rm -rf $HOME/.m2/repository/org/springframework/data 2> /dev/null || : - -cd spring-data-elasticsearch-github - -./mvnw clean dependency:list test -P${PROFILE} -Dsort diff --git a/ci/test.yml b/ci/test.yml deleted file mode 100644 index 3b0971ea4..000000000 --- a/ci/test.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -platform: linux - -image_resource: - type: docker-image - source: - repository: openjdk - tag: 8-jdk-alpine - -inputs: -- name: spring-data-elasticsearch-github - -outputs: -- name: spring-data-elasticsearch-artifactory - -caches: -- path: maven - -run: - path: spring-data-elasticsearch-github/ci/test.sh diff --git a/pom.xml b/pom.xml index 2eaf9ca47..35adf61c8 100644 --- a/pom.xml +++ b/pom.xml @@ -286,6 +286,47 @@ + + snapshot + + + + + org.jfrog.buildinfo + artifactory-maven-plugin + 2.6.1 + false + + + build-info + + publish + + + + {{BUILD_URL}} + + + spring-data-elasticsearch + spring-data-elasticsearch + false + *:*:*:*@zip + + + https://repo.spring.io + {{USERNAME}} + {{PASSWORD}} + libs-snapshot-local + libs-snapshot-local + + + + + + + + + release