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
The following commit(s) were added to refs/heads/master by this push: new 04a4552 SCB-1877 Fixed AlphaUI's Saga list sorted by time bug 04a4552 is described below commit 04a455278a6bd102f9f5ada05ec73e94a9dd3dde Author: Lei Zhang <zhang...@apache.org> AuthorDate: Thu Apr 30 00:48:03 2020 +0800 SCB-1877 Fixed AlphaUI's Saga list sorted by time bug --- .../ElasticsearchTransactionRepository.java | 50 ++++++++++------------ alpha/alpha-ui/pom.xml | 5 +++ .../main/resources/static/js/alpha-transaction.js | 19 +++----- .../resources/templates/fragments/main_layout.html | 1 + .../templates/fragments/transaction_table.html | 3 +- distribution/src/release/LICENSE | 8 ++++ distribution/src/release/licenses/LICENSE-moment | 22 ++++++++++ 7 files changed, 66 insertions(+), 42 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 dffffcf..e612c17 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 @@ -45,10 +45,9 @@ import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.elasticsearch.core.DefaultResultMapper; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; -import org.springframework.data.elasticsearch.core.ScrolledPage; import org.springframework.data.elasticsearch.core.SearchResultMapper; import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage; import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl; @@ -117,6 +116,7 @@ public class ElasticsearchTransactionRepository implements TransactionRepository @Override 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(); List<GlobalTransaction> globalTransactions = new ArrayList(); QueryBuilder query; @@ -125,32 +125,26 @@ public class ElasticsearchTransactionRepository implements TransactionRepository } else { query = QueryBuilders.matchAllQuery(); } - SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withIndices(INDEX_NAME) - .withTypes(INDEX_TYPE) - .withQuery(query) - .withPageable(PageRequest.of(page, size)) - .build(); - ScrolledPage<GlobalTransactionDocument> scroll = (ScrolledPage<GlobalTransactionDocument>) this.template - .startScroll(SCROLL_TIMEOUT, searchQuery, GlobalTransactionDocument.class, - searchResultMapper); - int pageCursor = 0; - while (scroll.hasContent()) { - if (pageCursor < page) { - scroll = (ScrolledPage<GlobalTransactionDocument>) this.template - .continueScroll(scroll.getScrollId(), SCROLL_TIMEOUT, GlobalTransactionDocument.class, - searchResultMapper); - pageCursor++; - } else { - for (GlobalTransactionDocument dto : scroll.getContent()) { - globalTransactions.add(dto); - } - break; + 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); } - } - LOG.info("Query total hits {}, return page {}, size {}", scroll.getTotalElements(), page, size); - this.template.clearScroll(scroll.getScrollId()); - return PagingGlobalTransactions.builder().page(page).size(size).total(scroll.getTotalElements()) + }); + 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(); } @@ -200,7 +194,7 @@ public class ElasticsearchTransactionRepository implements TransactionRepository return globalTransactions; } - private final SearchResultMapper searchResultMapper = new SearchResultMapper() { + private final SearchResultMapper searchResultMapper = new DefaultResultMapper() { @Override public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> aClass, Pageable pageable) { diff --git a/alpha/alpha-ui/pom.xml b/alpha/alpha-ui/pom.xml index 201ef16..5470a7a 100644 --- a/alpha/alpha-ui/pom.xml +++ b/alpha/alpha-ui/pom.xml @@ -87,6 +87,11 @@ </dependency> <dependency> <groupId>org.webjars</groupId> + <artifactId>momentjs</artifactId> + <version>2.24.0</version> + </dependency> + <dependency> + <groupId>org.webjars</groupId> <artifactId>sockjs-client</artifactId> <version>1.0.2</version> </dependency> diff --git a/alpha/alpha-ui/src/main/resources/static/js/alpha-transaction.js b/alpha/alpha-ui/src/main/resources/static/js/alpha-transaction.js index fad1a75..dba6c33 100644 --- a/alpha/alpha-ui/src/main/resources/static/js/alpha-transaction.js +++ b/alpha/alpha-ui/src/main/resources/static/js/alpha-transaction.js @@ -61,20 +61,11 @@ $(document).ready(function () { {"data": "subTxSize"}, {"data": "beginTime"}, {"data": "durationTime"}, - {"data": "state"}, - {"data": ""} + {"data": "state"} ], columnDefs: [ { render: function (data, type, row) { - return '<i class="fas fa-fw fa-bullseye row-transaction" style="cursor:pointer" globalTxId=' - + row.globalTxId + '></i>'; - }, - width: "50px", - targets: -1 - }, - { - render: function (data, type, row) { if (data == 'COMMITTED') { return '<span class="text-success">' + data + '</span>' } else if (data == 'SUSPENDED') { @@ -87,8 +78,12 @@ $(document).ready(function () { }, width: "50px", targets: 6 - }, - {"visible": false, "targets": [4]} + },{ + render: function (data, type, row) { + return moment(data).format('LLL'); + }, + targets: 4 + } ] }); diff --git a/alpha/alpha-ui/src/main/resources/templates/fragments/main_layout.html b/alpha/alpha-ui/src/main/resources/templates/fragments/main_layout.html index a632f70..a6a2357 100644 --- a/alpha/alpha-ui/src/main/resources/templates/fragments/main_layout.html +++ b/alpha/alpha-ui/src/main/resources/templates/fragments/main_layout.html @@ -76,6 +76,7 @@ <script th:src="@{/webjars/jquery/jquery.min.js}"></script> <script th:src="@{/webjars/bootstrap/js/bootstrap.bundle.min.js}"></script> <script th:src="@{/webjars/jquery-easing/jquery.easing.min.js}"></script> +<script th:src="@{/webjars/momentjs/min/moment.min.js}"></script> <!-- Custom scripts for all pages--> <script th:src="@{/js/sb-admin-2.min.js}"></script> diff --git a/alpha/alpha-ui/src/main/resources/templates/fragments/transaction_table.html b/alpha/alpha-ui/src/main/resources/templates/fragments/transaction_table.html index 7455a35..0f5f77a 100644 --- a/alpha/alpha-ui/src/main/resources/templates/fragments/transaction_table.html +++ b/alpha/alpha-ui/src/main/resources/templates/fragments/transaction_table.html @@ -24,10 +24,9 @@ <th>Instance ID</th> <th>Global Tx ID</th> <th>Children</th> - <th>Created At</th> + <th>Time</th> <th>Duration(ms)</th> <th>Final State</th> - <th style="width:50px;"></th> </tr> </thead> </table> diff --git a/distribution/src/release/LICENSE b/distribution/src/release/LICENSE index c7a5a28..3e5e9c3 100644 --- a/distribution/src/release/LICENSE +++ b/distribution/src/release/LICENSE @@ -699,6 +699,14 @@ You can find a copy of the License at licenses/LICENSE-jquery * jQuery Easing Plugin (org.webjars:jquery-easing:1.4.1 - http://webjars.org) =========================================================================== +This product bundles moment which is licensed under the +Moment license. +For details, see https://github.com/moment/moment/ +You can find a copy of the License at licenses/LICENSE-moment + +* jquery (org.webjars:momentjs:2.24.0 - http://webjars.org) + +=========================================================================== This product bundles Font Awesome which is licensed under the Font Awesome license. For details, see https://github.com/FortAwesome/Font-Awesome diff --git a/distribution/src/release/licenses/LICENSE-moment b/distribution/src/release/licenses/LICENSE-moment new file mode 100644 index 0000000..96ad692 --- /dev/null +++ b/distribution/src/release/licenses/LICENSE-moment @@ -0,0 +1,22 @@ +Copyright (c) JS Foundation and other contributors + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file