ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oleew...@apache.org
Subject [3/6] ambari git commit: AMBARI-20300. LogSearch Portal UI Fails on Last Page selection if logs were deleted in the meantime (Miklos Gergely via oleewere)
Date Wed, 12 Apr 2017 12:32:04 GMT
AMBARI-20300. LogSearch Portal UI Fails on Last Page selection if logs were deleted in the
meantime (Miklos Gergely via oleewere)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a65c5a05
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a65c5a05
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a65c5a05

Branch: refs/heads/branch-2.5
Commit: a65c5a0564c28f781fe5a3407c0ba4dd9a89a92e
Parents: 76ff5e0
Author: Miklos Gergely <mgergely@hortonworks.com>
Authored: Fri Mar 10 14:44:15 2017 +0100
Committer: oleewere <oleewere@gmail.com>
Committed: Wed Apr 12 14:31:27 2017 +0200

----------------------------------------------------------------------
 .../AbstractSearchRequestQueryConverter.java    | 31 +++++++++++++++++---
 .../logsearch/manager/AuditLogsManager.java     | 20 +++++++++++--
 .../ambari/logsearch/manager/ManagerBase.java   | 11 ++++---
 .../logsearch/manager/ServiceLogsManager.java   | 13 ++++++--
 .../scripts/collections/BaseCollection.js       |  4 +--
 .../webapp/scripts/views/common/TableLayout.js  |  2 +-
 6 files changed, 64 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a65c5a05/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/converter/AbstractSearchRequestQueryConverter.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/converter/AbstractSearchRequestQueryConverter.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/converter/AbstractSearchRequestQueryConverter.java
index d44b866..d4fc48b 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/converter/AbstractSearchRequestQueryConverter.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/converter/AbstractSearchRequestQueryConverter.java
@@ -18,10 +18,15 @@
  */
 package org.apache.ambari.logsearch.converter;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ambari.logsearch.model.request.LastPageParamDefinition;
 import org.apache.ambari.logsearch.model.request.impl.CommonSearchRequest;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.solr.core.query.Criteria;
 import org.springframework.data.solr.core.query.Query;
 import org.springframework.data.solr.core.query.SimpleStringCriteria;
@@ -32,14 +37,32 @@ public abstract class AbstractSearchRequestQueryConverter<REQUEST_TYPE
extends C
   @Override
   public QUERY_TYPE convert(REQUEST_TYPE request) {
     QUERY_TYPE query = createQuery();
-    int page = StringUtils.isNumeric(request.getPage()) ? new Integer(request.getPage())
: 0;
-    int pageSize = StringUtils.isNumeric(request.getPageSize()) ? new Integer(request.getPageSize())
: 99999;
-    PageRequest pageRequest = new PageRequest(page, pageSize, sort(request));
-    query.setPageRequest(pageRequest);
+    addPageRequest(request, query);
     Criteria criteria = new SimpleStringCriteria("*:*");
     query.addCriteria(criteria);
     return extendSolrQuery(request, query);
   }
+  
+  private void addPageRequest(REQUEST_TYPE request, QUERY_TYPE query) {
+    int page = StringUtils.isNumeric(request.getPage()) ? new Integer(request.getPage())
: 0;
+    int pageSize = StringUtils.isNumeric(request.getPageSize()) ? new Integer(request.getPageSize())
: 99999;
+    Sort sort = sort(request);
+    
+    boolean isLastPage = (request instanceof LastPageParamDefinition) ?
+        ((LastPageParamDefinition)request).isLastPage() :
+        false;
+    if (isLastPage) {
+      page = 0;
+      List<Sort.Order> newOrders = new ArrayList<>();
+      for (Sort.Order order : sort) {
+        newOrders.add(new Sort.Order(order.getDirection() == Direction.ASC ? Direction.DESC
: Direction.ASC, order.getProperty()));
+      }
+      sort = new Sort(newOrders);
+    }
+    
+    PageRequest pageRequest = new PageRequest(page, pageSize, sort);
+    query.setPageRequest(pageRequest);
+  }
 
   public abstract QUERY_TYPE extendSolrQuery(REQUEST_TYPE request, QUERY_TYPE query);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65c5a05/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
index 2a18415..49465d5 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
@@ -58,6 +58,7 @@ import org.apache.ambari.logsearch.solr.model.SolrAuditLogData;
 import org.apache.ambari.logsearch.solr.model.SolrComponentTypeLogData;
 import org.apache.ambari.logsearch.util.DownloadUtil;
 import org.apache.ambari.logsearch.util.RESTErrorUtil;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.ambari.logsearch.common.VResponse;
 import org.apache.log4j.Logger;
 import org.apache.solr.client.solrj.SolrQuery;
@@ -87,8 +88,23 @@ public class AuditLogsManager extends ManagerBase<SolrAuditLogData,
AuditLogResp
   @Inject
   private SolrSchemaFieldDao solrSchemaFieldDao;
 
-  public AuditLogResponse getLogs(AuditLogRequest auditLogRequest) {
-    return getLogAsPaginationProvided(conversionService.convert(auditLogRequest, SimpleQuery.class),
auditSolrDao, "/audit/logs");
+  public AuditLogResponse getLogs(AuditLogRequest request) {
+    String event = "/audit/logs";
+    SimpleQuery solrQuery = conversionService.convert(request, SimpleQuery.class);
+    if (request.isLastPage()) {
+      return getLastPage(auditSolrDao, solrQuery, event);
+    } else {
+      AuditLogResponse response = getLogAsPaginationProvided(solrQuery, auditSolrDao, event);
+      if (response.getTotalCount() > 0 && CollectionUtils.isEmpty(response.getLogList()))
{
+        request.setLastPage(true);
+        solrQuery = conversionService.convert(request, SimpleQuery.class);
+        AuditLogResponse lastResponse = getLastPage(auditSolrDao, solrQuery, event);
+        if (lastResponse != null){
+          response = lastResponse;
+        }
+      }
+      return response;
+    }
   }
 
   private List<LogData> getComponents(AuditComponentRequest request) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65c5a05/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ManagerBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ManagerBase.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ManagerBase.java
index 89873f3..6b40cb5 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ManagerBase.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ManagerBase.java
@@ -26,7 +26,6 @@ import java.util.List;
 import org.apache.ambari.logsearch.model.response.LogData;
 import org.apache.ambari.logsearch.model.response.LogSearchResponse;
 import org.apache.ambari.logsearch.dao.SolrDaoBase;
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.log4j.Logger;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.response.QueryResponse;
@@ -45,9 +44,9 @@ public abstract class ManagerBase<LOG_DATA_TYPE extends LogData, SEARCH_RESPONSE
   protected SEARCH_RESPONSE getLastPage(SolrDaoBase solrDoaBase, SimpleQuery lastPageQuery,
String event) {
     int maxRows = lastPageQuery.getRows();
     SEARCH_RESPONSE logResponse = getLogAsPaginationProvided(lastPageQuery, solrDoaBase,
event);
-    Long totalLogs = solrDoaBase.count(lastPageQuery);
-    int startIndex = Integer.parseInt("" + ((totalLogs / maxRows) * maxRows));
-    int numberOfLogsOnLastPage = Integer.parseInt("" + (totalLogs - startIndex));
+    Long totalLogs = logResponse.getTotalCount();
+    int startIndex = (int)(totalLogs - totalLogs % maxRows);
+    int numberOfLogsOnLastPage = (int)(totalLogs - startIndex);
     logResponse.setStartIndex(startIndex);
     logResponse.setTotalCount(totalLogs);
     logResponse.setPageSize(maxRows);
@@ -75,11 +74,11 @@ public abstract class ManagerBase<LOG_DATA_TYPE extends LogData, SEARCH_RESPONSE
     QueryResponse response = solrDaoBase.process(solrQuery, event);
     SEARCH_RESPONSE logResponse = createLogSearchResponse();
     SolrDocumentList docList = response.getResults();
+    logResponse.setTotalCount(docList.getNumFound());
     List<LOG_DATA_TYPE> serviceLogDataList = convertToSolrBeans(response);
-    if (CollectionUtils.isNotEmpty(docList)) {
+    if (!docList.isEmpty()) {
       logResponse.setLogList(serviceLogDataList);
       logResponse.setStartIndex((int) docList.getStart());
-      logResponse.setTotalCount(docList.getNumFound());
       Integer rowNumber = solrQuery.getRows();
       if (rowNumber == null) {
         logger.error("No RowNumber was set in solrQuery");

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65c5a05/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
index 157335a..9ce209b 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
@@ -139,12 +139,21 @@ public class ServiceLogsManager extends ManagerBase<SolrServiceLogData,
ServiceL
       }
     } else if (isLastPage) {
       ServiceLogResponse logResponse = getLastPage(serviceLogsSolrDao, solrQuery, event);
-      if(logResponse == null){
+      if (logResponse == null){
         logResponse = new ServiceLogResponse();
       }
       return logResponse;
     } else {
-      return getLogAsPaginationProvided(solrQuery, serviceLogsSolrDao, event);
+      ServiceLogResponse response = getLogAsPaginationProvided(solrQuery, serviceLogsSolrDao,
event);
+      if (response.getTotalCount() > 0 && CollectionUtils.isEmpty(response.getLogList()))
{
+        request.setLastPage(true);
+        solrQuery = conversionService.convert(request, SimpleQuery.class);
+        ServiceLogResponse lastResponse = getLastPage(serviceLogsSolrDao, solrQuery, event);
+        if (lastResponse != null){
+          response = lastResponse;
+        }
+      }
+      return response;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65c5a05/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/collections/BaseCollection.js
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/collections/BaseCollection.js
b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/collections/BaseCollection.js
index c175397..82fe6a9 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/collections/BaseCollection.js
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/collections/BaseCollection.js
@@ -129,9 +129,9 @@ define(['require',
 	    },
 	    getPage : function(index, options){
 		if(index === "last"){
-			this.queryParams.isLastPage = true;
+			this.queryParams.lastPage = true;
 		}else{
-			delete this.queryParams.isLastPage;
+			delete this.queryParams.lastPage;
 		}
 		var fn = Backbone.PageableCollection.prototype.getPage;
 		fn.apply(this,arguments);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a65c5a05/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/TableLayout.js
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/TableLayout.js
b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/TableLayout.js
index 1066510..b2f0871 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/TableLayout.js
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/TableLayout.js
@@ -392,7 +392,7 @@ define(['require',
 			this.collection.state.pageSize = parseInt(pagesize,10);
 
 			this.collection.state.currentPage = this.collection.state.firstPage;
-			delete this.collection.queryParams.isLastPage;
+			delete this.collection.queryParams.lastPage;
 			this.collection.fetch({
 				sort: false,
 				reset: true,


Mime
View raw message