diff --git a/Jenkinsfile-Agent-Test-4 b/Jenkinsfile-Agent-Test-4 index 0ba437d5c570ff9ed49d9fa4753676521f239869..d3b74e5b099e663ee19893a73c20c6439fcae944 100755 --- a/Jenkinsfile-Agent-Test-4 +++ b/Jenkinsfile-Agent-Test-4 @@ -68,7 +68,7 @@ pipeline { } } - stage('Test Cases Report (154)') { + stage('Test Cases Report (165)') { steps { echo "Test Cases Report" } @@ -118,6 +118,12 @@ pipeline { stage('Group2') { stages { + stage('elasticsearch-7.x-scenario 7.0.0-7.4.2 (11)') { + steps { + sh 'bash test/plugin/run.sh elasticsearch-7.x-scenario' + } + } + stage('spring-webflux 2.x (18)') { steps { sh 'bash test/plugin/run.sh webflux-scenario' diff --git a/docs/en/guides/Plugin-test.md b/docs/en/guides/Plugin-test.md index 996f17d0438b24142d17bcb1ec954386a736d88e..26d9204ddb0dadebe315806c86c3453988d6b87e 100644 --- a/docs/en/guides/Plugin-test.md +++ b/docs/en/guides/Plugin-test.md @@ -670,9 +670,10 @@ ehcache 2.8.x-2.10.x | 19 | 442.00 undertow 1.3.0-2.0.27 | 23 | 596.00 jedis 2.4.0-2.9.0 | 18 | 524.00 -#### Group 2 (2148.155s) +#### Group 2 (2398.155s) scenario name | versions | elapsed time (sec) ---|---|--- +elasticsearch-7.x-scenario | 11 | 250.00 spring-webflux 2.x | 18 | 705.60 spring 4.1.x-4.2.x | 20 | 574.75 solrj 7.x | 12 | 367.05 diff --git a/docs/en/setup/service-agent/java-agent/Supported-list.md b/docs/en/setup/service-agent/java-agent/Supported-list.md index 7ac9fc2e4d7c7fcd5c97cea0e977f750d1bf8217..7f2be18dbf4f8746b89a93c48621993b4b5036b6 100644 --- a/docs/en/setup/service-agent/java-agent/Supported-list.md +++ b/docs/en/setup/service-agent/java-agent/Supported-list.md @@ -58,6 +58,7 @@ * [Elasticsearch](https://github.com/elastic/elasticsearch) * [transport-client](https://github.com/elastic/elasticsearch/tree/master/client/transport) 5.2.x-5.6.x * [rest-high-level-client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.7/index.html) 6.7.1-6.8.4 + * [rest-high-level-client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.0/java-rest-high.html) 7.0.0-7.4.2 * [Solr](https://github.com/apache/lucene-solr/) * [SolrJ](https://github.com/apache/lucene-solr/tree/master/solr/solrj) 7.x * [Cassandra](https://github.com/apache/cassandra) 3.x diff --git a/test/plugin/scenarios/elasticsearch-5.x-scenario/configuration.yml b/test/plugin/scenarios/elasticsearch-5.x-scenario/configuration.yml index ce958778f4376827ec6a82bca06ec65e09469a14..df23943329447c437b26341c56643c9023268a3e 100644 --- a/test/plugin/scenarios/elasticsearch-5.x-scenario/configuration.yml +++ b/test/plugin/scenarios/elasticsearch-5.x-scenario/configuration.yml @@ -18,11 +18,11 @@ healthCheck: http://localhost:8080/elasticsearch-case/case/healthcheck startScript: ./bin/startup.sh framework: elasticsearch environment: - - elasticsearch.server=elasticsearch-server + - elasticsearch.server=elasticsearch-server-5.x dependencies: - elasticsearch-server: + elasticsearch-server-5.x: image: docker.elastic.co/elasticsearch/elasticsearch:5.4.0 - hostname: elasticsearch-server + hostname: elasticsearch-server-5.x expose: - 9300 - 9200 diff --git a/test/plugin/scenarios/elasticsearch-6.x-scenario/configuration.yml b/test/plugin/scenarios/elasticsearch-6.x-scenario/configuration.yml index ddad2d58a2413e8b6a58c6a651b9adaa511cdd99..edb99a886bdf26f7c8b4eb42a26fc16ff6180a3a 100644 --- a/test/plugin/scenarios/elasticsearch-6.x-scenario/configuration.yml +++ b/test/plugin/scenarios/elasticsearch-6.x-scenario/configuration.yml @@ -18,11 +18,11 @@ healthCheck: http://localhost:8080/elasticsearch-case/case/healthcheck startScript: ./bin/startup.sh framework: elasticsearch environment: - - elasticsearch.server=elasticsearch-server:9200 + - elasticsearch.server=elasticsearch-server-6.x:9200 dependencies: - elasticsearch-server: - image: elasticsearch:6.7.1 - hostname: elasticsearch-server + elasticsearch-server-6.x: + image: elasticsearch:${CASE_SERVER_IMAGE_VERSION} + hostname: elasticsearch-server-6.x expose: - 9200 environment: diff --git a/test/plugin/scenarios/elasticsearch-6.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/controller/CaseController.java b/test/plugin/scenarios/elasticsearch-6.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/controller/CaseController.java index e872d1bae347e1ec22cddce367d033d84f203df7..3cd0d7d871d26733eabd519c218630ad07b4274f 100644 --- a/test/plugin/scenarios/elasticsearch-6.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/controller/CaseController.java +++ b/test/plugin/scenarios/elasticsearch-6.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/controller/CaseController.java @@ -27,7 +27,7 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; -import org.elasticsearch.action.admin.indices.flush.FlushRequest; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequest; @@ -88,7 +88,7 @@ public class CaseController { // index index(client, indexName); - client.indices().flush(new FlushRequest(indexName), RequestOptions.DEFAULT); + client.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT); //get get(client, indexName); diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/bin/startup.sh b/test/plugin/scenarios/elasticsearch-7.x-scenario/bin/startup.sh new file mode 100644 index 0000000000000000000000000000000000000000..34c8fd1ab65e3b63cc5d03c24aa234452eb3ff79 --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/bin/startup.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License 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. + +home="$(cd "$(dirname $0)"; pwd)" + +java -jar ${agent_opts} -Dskywalking.plugin.elasticsearch.trace_dsl=true ${home}/../libs/elasticsearch-7.x-scenario.jar & diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/config/expectedData.yaml b/test/plugin/scenarios/elasticsearch-7.x-scenario/config/expectedData.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e2e3b51a74f0b7bad658e875823778dd1e509d19 --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/config/expectedData.yaml @@ -0,0 +1,149 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License 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. +registryItems: + applications: + - {elasticsearch-7.x-scenario: nq 0} + instances: + - {elasticsearch-7.x-scenario: 1} + operationNames: + - elasticsearch-7.x-scenario: [Elasticsearch/CreateRequest, Elasticsearch/IndexRequest, + Elasticsearch/GetRequest, Elasticsearch/SearchRequest, + Elasticsearch/UpdateRequest, Elasticsearch/DeleteRequest, + /elasticsearch-case/case/elasticsearch] + heartbeat: [] +segmentItems: +- applicationCode: elasticsearch-7.x-scenario + segmentSize: ge 1 + segments: + - segmentId: not null + spans: + - operationName: Elasticsearch/CreateRequest + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + - operationName: Elasticsearch/IndexRequest + operationId: 0 + parentSpanId: 0 + spanId: 2 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + - operationName: Elasticsearch/GetRequest + operationId: 0 + parentSpanId: 0 + spanId: 3 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + - operationName: Elasticsearch/SearchRequest + operationId: 0 + parentSpanId: 0 + spanId: 4 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + - operationName: Elasticsearch/UpdateRequest + operationId: 0 + parentSpanId: 0 + spanId: 5 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - {key: db.statement, value: not null} + - operationName: Elasticsearch/DeleteRequest + operationId: 0 + parentSpanId: 0 + spanId: 6 + spanLayer: Database + startTime: nq 0 + endTime: nq 0 + componentId: 77 + componentName: '' + isError: false + spanType: Exit + peer: not null + peerId: 0 + tags: + - {key: db.type, value: Elasticsearch} + - {key: db.instance, value: not null} + - operationName: /elasticsearch-case/case/elasticsearch + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: nq 0 + endTime: nq 0 + componentId: 1 + componentName: '' + isError: false + spanType: Entry + peer: '' + peerId: 0 + tags: + - {key: url, value: 'http://localhost:8080/elasticsearch-case/case/elasticsearch'} + - {key: http.method, value: GET} diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/configuration.yml b/test/plugin/scenarios/elasticsearch-7.x-scenario/configuration.yml new file mode 100644 index 0000000000000000000000000000000000000000..1abc433d1f6c1f92b5c1d72dadd1d20f67b6b1bc --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/configuration.yml @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License 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. + +type: jvm +entryService: http://localhost:8080/elasticsearch-case/case/elasticsearch +healthCheck: http://localhost:8080/elasticsearch-case/case/healthCheck +startScript: ./bin/startup.sh +framework: elasticsearch-7.x-scenario +environment: +- elasticsearch.server=elasticsearch-server-7.x:9200 +dependencies: + elasticsearch-server-7.x: + image: elasticsearch:${CASE_SERVER_IMAGE_VERSION} + hostname: elasticsearch-server-7.x + expose: + - 9200 + environment: + - cluster.name=docker-node + - xpack.security.enabled=false + - bootstrap.memory_lock=true + - "ES_JAVA_OPTS=-Xms256m -Xmx256m" + - discovery.type=single-node diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/pom.xml b/test/plugin/scenarios/elasticsearch-7.x-scenario/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..a1e7919e50c0351fecbeaaedee2c9a75ed507444 --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/pom.xml @@ -0,0 +1,147 @@ + + + + + org.apache.skywalking.apm.testcase + elasticsearch-7.x-scenario + 1.0.0 + jar + + 4.0.0 + + + UTF-8 + 1.8 + + 7.3.0 + + 7.3.0 + 2.1.6.RELEASE + + + skywalking-elasticsearch-7.x-scenario + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot-version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + jul-to-slf4j + org.slf4j + + + + + + org.elasticsearch.client + elasticsearch-rest-high-level-client + ${test.framework.version} + + + elasticsearch + org.elasticsearch + + + elasticsearch-rest-client + org.elasticsearch.client + + + + + org.elasticsearch.client + elasticsearch-rest-client + ${test.framework.version} + + + org.elasticsearch + elasticsearch + ${test.framework.version} + + + + + elasticsearch-7.x-scenario + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-version} + + + + repackage + + + + + + maven-compiler-plugin + + ${compiler.version} + ${compiler.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-assembly-plugin + + + assemble + package + + single + + + + src/main/assembly/assembly.xml + + ./target/ + + + + + + + diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/assembly/assembly.xml b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/assembly/assembly.xml new file mode 100644 index 0000000000000000000000000000000000000000..52790912f5fa575cf9d557d92828ec9d21ad9b19 --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/assembly/assembly.xml @@ -0,0 +1,41 @@ + + + + + zip + + + + + ./bin + 0775 + + + + + + ${project.build.directory}/elasticsearch-7.x-scenario.jar + ./libs + 0775 + + + diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/Application.java b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/Application.java new file mode 100644 index 0000000000000000000000000000000000000000..57e75377c5645bed0a539b3cec8b65d39d4b4622 --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/Application.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License 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 org.apache.skywalking.apm.testcase.elasticsearch; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author aderm + */ +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + try { + SpringApplication.run(Application.class, args); + } catch (Exception e) { + // Never do this + } + } +} diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/config/ElasticsearchConfig.java b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/config/ElasticsearchConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..46edcefdb0438150027f37c3950317f6207d3f14 --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/config/ElasticsearchConfig.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License 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 org.apache.skywalking.apm.testcase.elasticsearch.config; + +import org.apache.http.HttpHost; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestHighLevelClient; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author aderm + */ +@Configuration +public class ElasticsearchConfig { + + @Value("${elasticsearch.server}") + private String elasticsearchHost; + + @Bean(destroyMethod = "close") + public RestHighLevelClient client() { + HttpHost[] httpHostArry = parseEsHost(); + RestHighLevelClient client = new RestHighLevelClient((RestClient.builder(httpHostArry))); + return client; + } + + private HttpHost[] parseEsHost() { + HttpHost[] httpHostArray = null; + if (!elasticsearchHost.isEmpty()) { + String[] hostIp = elasticsearchHost.split(","); + httpHostArray = new HttpHost[hostIp.length]; + + for (int i = 0; i < hostIp.length; ++i) { + String[] hostIpItem = hostIp[i].split(":"); + String ip = hostIpItem[0].trim(); + String port = hostIpItem[1].trim(); + httpHostArray[i] = new HttpHost(ip, Integer.parseInt(port), "http"); + } + } + return httpHostArray; + } +} diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/controller/CaseController.java b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/controller/CaseController.java new file mode 100644 index 0000000000000000000000000000000000000000..dce7ee27b91876e74d8ebb646ce4f8be241c33af --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/java/org/apache/skywalking/apm/testcase/elasticsearch/controller/CaseController.java @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License 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 org.apache.skywalking.apm.testcase.elasticsearch.controller; + +import static java.util.Collections.singletonMap; + +import java.io.IOException; +import java.util.Map; +import java.util.UUID; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; +import org.elasticsearch.action.get.GetRequest; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.action.update.UpdateRequest; +import org.elasticsearch.action.update.UpdateResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.client.indices.CreateIndexRequest; +import org.elasticsearch.client.indices.CreateIndexResponse; +import org.elasticsearch.cluster.health.ClusterHealthStatus; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.script.Script; +import org.elasticsearch.script.ScriptType; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author aderm + */ +@RestController +@RequestMapping("/case") +public class CaseController { + + private static Logger logger = LogManager.getLogger(CaseController.class); + + @Autowired + private RestHighLevelClient client; + + @GetMapping("/healthCheck") + public String healthcheck() throws Exception { + ClusterHealthRequest request = new ClusterHealthRequest(); + request.timeout(TimeValue.timeValueSeconds(10)); + request.waitForStatus(ClusterHealthStatus.GREEN); + + ClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT); + if (response.isTimedOut()) { + String message = "elastic search node start fail!"; + logger.error(message); + throw new RuntimeException(message); + } + return "Success"; + } + + @GetMapping("/elasticsearch") + public String elasticsearch() throws Exception { + String indexName = UUID.randomUUID().toString(); + try { + //create + createIndex(client, indexName); + // index + index(client, indexName); + + client.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT); + + //get + get(client, indexName); + // search + search(client, indexName); + // update + update(client, indexName); + // delete + delete(client, indexName); + } finally { + if (null != client) { + client.close(); + } + } + return "Success"; + } + + private void createIndex(RestHighLevelClient client, String indexName) throws IOException { + CreateIndexRequest request = new CreateIndexRequest(indexName); + + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + { + builder.startObject("properties"); + { + builder.startObject("author"); + { + builder.field("type", "keyword"); + } + builder.endObject(); + builder.startObject("title"); + { + builder.field("type", "keyword"); + } + builder.endObject(); + } + builder.endObject(); + } + builder.endObject(); + request.mapping(builder); + + request.settings(Settings.builder() + .put("index.number_of_shards", 1) + .put("index.number_of_replicas", 0) + ); + + CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT); + if (createIndexResponse.isAcknowledged() == false) { + String message = "elasticsearch create index fail."; + logger.error(message); + throw new RuntimeException(message); + } + } + + private void index(RestHighLevelClient client, String indexName) throws IOException { + XContentBuilder builder = XContentFactory.jsonBuilder(); + builder.startObject(); + { + builder.field("author", "Marker"); + builder.field("title", "Java programing."); + } + builder.endObject(); + IndexRequest indexRequest = new IndexRequest(indexName).id("1").source(builder); + + IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); + if (indexResponse.status().getStatus() >= 400) { + String message = "elasticsearch index data fail."; + logger.error(message); + throw new RuntimeException(message); + } + } + + private void get(RestHighLevelClient client, String indexName) throws IOException { + GetRequest getRequest = new GetRequest(indexName, "1"); + GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT); + + if (!getResponse.isExists()) { + String message = "elasticsearch get data fail."; + logger.error(message); + throw new RuntimeException(message); + } + } + + private void update(RestHighLevelClient client, String indexName) throws IOException { + UpdateRequest request = new UpdateRequest(indexName, "1"); + Map parameters = singletonMap("title", "c++ programing."); + Script inline = new Script(ScriptType.INLINE, "painless", "ctx._source.title = params.title", parameters); + request.script(inline); + + UpdateResponse updateResponse = client.update(request, RequestOptions.DEFAULT); + if (updateResponse.getVersion() != 2) { + String message = "elasticsearch update data fail."; + logger.error(message); + throw new RuntimeException(message); + } + } + + private void delete(RestHighLevelClient client, String indexName) throws IOException { + DeleteIndexRequest request = new DeleteIndexRequest(indexName); + AcknowledgedResponse deleteIndexResponse = client.indices().delete(request, RequestOptions.DEFAULT); + if (!deleteIndexResponse.isAcknowledged()) { + String message = "elasticsearch delete index fail."; + logger.error(message); + throw new RuntimeException(message); + } + } + + private void search(RestHighLevelClient client, String indexName) throws IOException { + SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); + sourceBuilder.query(QueryBuilders.termQuery("author", "Marker")); + sourceBuilder.from(0); + sourceBuilder.size(10); + + SearchRequest searchRequest = new SearchRequest(); + searchRequest.indices(indexName); + searchRequest.source(sourceBuilder); + SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); + + int length = searchResponse.getHits().getHits().length; + if (!(length > 0)) { + String message = "elasticsearch search data fail."; + logger.error(message); + throw new RuntimeException(message); + } + } +} + + diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/resources/application.yaml b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/resources/application.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7cc560285a6a2be35d4b771a2823e5618dd66cd3 --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/resources/application.yaml @@ -0,0 +1,23 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License 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. +# +# +server: + port: 8080 + servlet: + context-path: /elasticsearch-case +logging: + config: classpath:log4j2.xml diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/resources/log4j2.xml b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/resources/log4j2.xml new file mode 100644 index 0000000000000000000000000000000000000000..9849ed5a8abd116a9000e64cc18f05e583f21c98 --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/src/main/resources/log4j2.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plugin/scenarios/elasticsearch-7.x-scenario/support-version.list b/test/plugin/scenarios/elasticsearch-7.x-scenario/support-version.list new file mode 100644 index 0000000000000000000000000000000000000000..6f580b790382ec9feecb22ed6c600dad357cc03e --- /dev/null +++ b/test/plugin/scenarios/elasticsearch-7.x-scenario/support-version.list @@ -0,0 +1,27 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License 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. + +7.0.0 +7.1.0 +7.1.1 +7.2.0 +7.2.1 +7.3.0 +7.3.1 +7.3.2 +7.4.0 +7.4.1 +7.4.2