[test/plugin] add elasticsearch 7.x plugin test scenario. (#3868)
* [test/plugin] add elasticsearch 7.x plugin test scenario. * refresh index, make can search. * remove unused package. * update supported framework document. * fix service name repeat.
This commit is contained in:
parent
77019ba665
commit
33d2962593
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 &
|
||||
|
|
@ -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}
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<groupId>org.apache.skywalking.apm.testcase</groupId>
|
||||
<artifactId>elasticsearch-7.x-scenario</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<compiler.version>1.8</compiler.version>
|
||||
|
||||
<test.framework.version>7.3.0</test.framework.version>
|
||||
|
||||
<elasticsearch.version>7.3.0</elasticsearch.version>
|
||||
<spring-boot-version>2.1.6.RELEASE</spring-boot-version>
|
||||
</properties>
|
||||
|
||||
<name>skywalking-elasticsearch-7.x-scenario</name>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot-version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>jul-to-slf4j</artifactId>
|
||||
<groupId>org.slf4j</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- elasticsearch rest-high-level-client -->
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||
<version>${test.framework.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>elasticsearch-rest-client</artifactId>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-client</artifactId>
|
||||
<version>${test.framework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<version>${test.framework.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>elasticsearch-7.x-scenario</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>${compiler.version}</source>
|
||||
<target>${compiler.version}</target>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>assemble</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
<outputDirectory>./target/</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~
|
||||
-->
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>./bin</directory>
|
||||
<fileMode>0775</fileMode>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
|
||||
<files>
|
||||
<file>
|
||||
<source>${project.build.directory}/elasticsearch-7.x-scenario.jar</source>
|
||||
<outputDirectory>./libs</outputDirectory>
|
||||
<fileMode>0775</fileMode>
|
||||
</file>
|
||||
</files>
|
||||
</assembly>
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String, Object> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
~
|
||||
-->
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_ERR">
|
||||
<PatternLayout charset="UTF-8" pattern="[%d{yyyy-MM-dd HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="WARN">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue