You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2020/05/04 22:38:33 UTC
[servicecomb-pack] branch master updated (04a4552 -> a0e5cfe)
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git.
from 04a4552 SCB-1877 Fixed AlphaUI's Saga list sorted by time bug
new b55ddcf SCB-1852 Fixed Alpha UI query error when the ES index not exits or empty
new a0e5cfe SCB-1852 No mapping for beginTime then ignore unmapped
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../ElasticsearchTransactionRepository.java | 68 +++++++++++++---------
1 file changed, 42 insertions(+), 26 deletions(-)
[servicecomb-pack] 02/02: SCB-1852 No mapping for beginTime then
ignore unmapped
Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git
commit a0e5cfe9b1bd3ee2f0a056806b2cc249879b587a
Author: Lei Zhang <zh...@apache.org>
AuthorDate: Mon May 4 00:25:01 2020 +0800
SCB-1852 No mapping for beginTime then ignore unmapped
---
.../repository/elasticsearch/ElasticsearchTransactionRepository.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
index c5b5a0f..a92b27b 100644
--- a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
+++ b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
@@ -119,7 +119,7 @@ public class ElasticsearchTransactionRepository implements TransactionRepository
public PagingGlobalTransactions getGlobalTransactions(String state, int page, int size) {
//ElasticsearchTemplate.prepareScroll() does not add sorting https://jira.spring.io/browse/DATAES-457
long start = System.currentTimeMillis();
- PagingGlobalTransactions pagingGlobalTransactions = PagingGlobalTransactions.builder().build();
+ PagingGlobalTransactions pagingGlobalTransactions;
List<GlobalTransaction> globalTransactions = new ArrayList();
try{
IndicesExistsRequest request = new IndicesExistsRequest(INDEX_NAME);
@@ -133,7 +133,7 @@ public class ElasticsearchTransactionRepository implements TransactionRepository
SearchResponse response = this.template.getClient().prepareSearch(INDEX_NAME)
.setTypes(INDEX_TYPE)
.setQuery(query)
- .addSort(SortBuilders.fieldSort("beginTime").order(SortOrder.DESC).missing("_last"))
+ .addSort(SortBuilders.fieldSort("beginTime").order(SortOrder.DESC).unmappedType("date"))
.setSize(size)
.setFrom(page * size)
.execute()
[servicecomb-pack] 01/02: SCB-1852 Fixed Alpha UI query error when
the ES index not exits or empty
Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git
commit b55ddcff03068aa7592715beaa5fa707d97b37ec
Author: Lei Zhang <zh...@apache.org>
AuthorDate: Sun May 3 19:35:26 2020 +0800
SCB-1852 Fixed Alpha UI query error when the ES index not exits or empty
---
.../ElasticsearchTransactionRepository.java | 68 +++++++++++++---------
1 file changed, 42 insertions(+), 26 deletions(-)
diff --git a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
index e612c17..c5b5a0f 100644
--- a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
+++ b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
@@ -31,6 +31,7 @@ import org.apache.servicecomb.pack.alpha.core.fsm.repository.model.GlobalTransac
import org.apache.servicecomb.pack.alpha.core.fsm.repository.model.PagingGlobalTransactions;
import org.apache.servicecomb.pack.alpha.fsm.metrics.MetricsService;
import org.apache.servicecomb.pack.alpha.fsm.repository.TransactionRepository;
+import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
@@ -118,34 +119,49 @@ public class ElasticsearchTransactionRepository implements TransactionRepository
public PagingGlobalTransactions getGlobalTransactions(String state, int page, int size) {
//ElasticsearchTemplate.prepareScroll() does not add sorting https://jira.spring.io/browse/DATAES-457
long start = System.currentTimeMillis();
+ PagingGlobalTransactions pagingGlobalTransactions = PagingGlobalTransactions.builder().build();
List<GlobalTransaction> globalTransactions = new ArrayList();
- QueryBuilder query;
- if (state != null && state.trim().length() > 0) {
- query = QueryBuilders.termQuery("state.keyword", state);
- } else {
- query = QueryBuilders.matchAllQuery();
- }
- SearchResponse response = this.template.getClient().prepareSearch(INDEX_NAME)
- .setTypes(INDEX_TYPE)
- .setQuery(query)
- .addSort(SortBuilders.fieldSort("beginTime").order(SortOrder.DESC))
- .setSize(size)
- .setFrom(page * size)
- .execute()
- .actionGet();
- ObjectMapper jsonMapper = new ObjectMapper();
- response.getHits().forEach(hit -> {
- try {
- GlobalTransactionDocument dto = jsonMapper
- .readValue(hit.getSourceAsString(), GlobalTransactionDocument.class);
- globalTransactions.add(dto);
- } catch (Exception e) {
- LOG.error(e.getMessage(), e);
+ try{
+ IndicesExistsRequest request = new IndicesExistsRequest(INDEX_NAME);
+ if (this.template.getClient().admin().indices().exists(request).actionGet().isExists()) {
+ QueryBuilder query;
+ if (state != null && state.trim().length() > 0) {
+ query = QueryBuilders.termQuery("state.keyword", state);
+ } else {
+ query = QueryBuilders.matchAllQuery();
+ }
+ SearchResponse response = this.template.getClient().prepareSearch(INDEX_NAME)
+ .setTypes(INDEX_TYPE)
+ .setQuery(query)
+ .addSort(SortBuilders.fieldSort("beginTime").order(SortOrder.DESC).missing("_last"))
+ .setSize(size)
+ .setFrom(page * size)
+ .execute()
+ .actionGet();
+ ObjectMapper jsonMapper = new ObjectMapper();
+ response.getHits().forEach(hit -> {
+ try {
+ GlobalTransactionDocument dto = jsonMapper
+ .readValue(hit.getSourceAsString(), GlobalTransactionDocument.class);
+ globalTransactions.add(dto);
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ }
+ });
+ pagingGlobalTransactions = PagingGlobalTransactions.builder().page(page).size(size).total(response.getHits().getTotalHits())
+ .globalTransactions(globalTransactions).elapsed(System.currentTimeMillis() - start).build();
+ } else {
+ LOG.warn("[alpha_global_transaction] index not exist");
+ pagingGlobalTransactions = PagingGlobalTransactions.builder().page(page).size(size).total(0)
+ .globalTransactions(globalTransactions).elapsed(System.currentTimeMillis() - start).build();
}
- });
- LOG.info("Query total hits {}, return page {}, size {}", response.getHits().getTotalHits(), page, size);
- return PagingGlobalTransactions.builder().page(page).size(size).total(response.getHits().getTotalHits())
- .globalTransactions(globalTransactions).elapsed(System.currentTimeMillis() - start).build();
+ }catch (Exception ex){
+ LOG.error(ex.getMessage(),ex);
+ pagingGlobalTransactions = PagingGlobalTransactions.builder().page(page).size(size).total(0)
+ .globalTransactions(globalTransactions).elapsed(System.currentTimeMillis() - start).build();
+ }
+ LOG.info("Query total hits {}, return page {}, size {}", pagingGlobalTransactions.getTotal(), page, size);
+ return pagingGlobalTransactions;
}
public Map<String, Long> getTransactionStatistics() {