Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C55E3200BBA for ; Sat, 5 Nov 2016 15:55:55 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C404F160B12; Sat, 5 Nov 2016 14:55:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 369DC160B15 for ; Sat, 5 Nov 2016 15:55:53 +0100 (CET) Received: (qmail 76927 invoked by uid 500); 5 Nov 2016 14:55:52 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 76642 invoked by uid 99); 5 Nov 2016 14:55:52 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Nov 2016 14:55:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1127DE0AD9; Sat, 5 Nov 2016 14:55:52 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: oleewere@apache.org To: commits@ambari.apache.org Date: Sat, 05 Nov 2016 14:56:00 -0000 Message-Id: In-Reply-To: <5392687e54dd464a8709c8df26d7396d@git.apache.org> References: <5392687e54dd464a8709c8df26d7396d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [10/58] [abbrv] ambari git commit: AMBARI-18310. Refactor logsearch portal side code (oleewere) archived-at: Sat, 05 Nov 2016 14:55:56 -0000 http://git-wip-us.apache.org/repos/asf/ambari/blob/77f9e8ff/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java deleted file mode 100644 index e227c6c..0000000 --- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogFileMgr.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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.ambari.logsearch.manager; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.ambari.logsearch.common.LogSearchConstants; -import org.apache.ambari.logsearch.common.MessageEnums; -import org.apache.ambari.logsearch.common.SearchCriteria; -import org.apache.ambari.logsearch.dao.AuditSolrDao; -import org.apache.ambari.logsearch.dao.ServiceLogsSolrDao; -import org.apache.ambari.logsearch.dao.SolrDaoBase; -import org.apache.ambari.logsearch.util.RESTErrorUtil; -import org.apache.ambari.logsearch.util.SolrUtil; -import org.apache.ambari.logsearch.view.VLogFile; -import org.apache.ambari.logsearch.view.VLogFileList; -import org.apache.ambari.logsearch.view.VSolrLogList; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.FacetField; -import org.apache.solr.client.solrj.response.FacetField.Count; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - -@Component -public class LogFileMgr extends MgrBase { - - private static final Logger logger = Logger.getLogger(LogFileMgr.class); - - @Autowired - private ServiceLogsSolrDao serviceLogsSolrDao; - @Autowired - private AuditSolrDao auditSolrDao; - - public String searchLogFiles(SearchCriteria searchCriteria) { - VLogFileList logFileList = new VLogFileList(); - List logFiles = new ArrayList(); - String componentName = (String) searchCriteria.getParamValue("component"); - String host = (String) searchCriteria.getParamValue("host"); - int minCount = 1;// to remove zero count facet - SolrQuery solrQuery = new SolrQuery(); - SolrUtil.setMainQuery(solrQuery, null); - SolrUtil.setFacetFieldWithMincount(solrQuery, LogSearchConstants.SOLR_PATH, minCount); - // adding filter - queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_COMPONENT, componentName); - queryGenerator.setSingleIncludeFilter(solrQuery, LogSearchConstants.SOLR_HOST, host); - try { - String logType = (String) searchCriteria.getParamValue("logType"); - if (StringUtils.isBlank(logType)) { - logType = LogType.SERVICE.name();// default is service Log - } - SolrDaoBase daoMgr = null; - if (logType.equalsIgnoreCase(LogType.SERVICE.name())) { - daoMgr = serviceLogsSolrDao; - } else if (logType.equalsIgnoreCase(LogType.AUDIT.name())) { - daoMgr = auditSolrDao; - } else { - throw RESTErrorUtil.createRESTException(logType + " is not a valid logType", MessageEnums.INVALID_INPUT_DATA); - } - QueryResponse queryResponse = daoMgr.process(solrQuery); - if (queryResponse.getFacetField(LogSearchConstants.SOLR_PATH) != null) { - FacetField queryFacetField = queryResponse.getFacetField(LogSearchConstants.SOLR_PATH); - if (queryFacetField != null) { - List countList = queryFacetField.getValues(); - for (Count count : countList) { - VLogFile vLogFile = new VLogFile(); - String filePath = count.getName(); - String fileName = FilenameUtils.getName(filePath); - vLogFile.setPath(filePath); - vLogFile.setName(fileName); - logFiles.add(vLogFile); - } - } - } - } catch (SolrException | SolrServerException | IOException e) { - logger.error("Error in solr query :" + e.getLocalizedMessage() + "\n Query :" + solrQuery.toQueryString(), e.getCause()); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - logFileList.setLogFiles(logFiles); - String jsonStr = ""; - jsonStr = convertObjToString(logFileList); - - return jsonStr; - } - - public String getLogFileTail(SearchCriteria searchCriteria) { - String host = (String) searchCriteria.getParamValue("host"); - String logFile = (String) searchCriteria.getParamValue("name"); - String component = (String) searchCriteria.getParamValue("component"); - String tailSize = (String) searchCriteria.getParamValue("tailSize"); - if (StringUtils.isBlank(host)) { - throw RESTErrorUtil.createRESTException("missing Host Name", MessageEnums.ERROR_SYSTEM); - } - tailSize = (StringUtils.isBlank(tailSize)) ? "10" : tailSize; - SolrQuery logFileTailQuery = new SolrQuery(); - try { - int tail = Integer.parseInt(tailSize); - tail = tail > 100 ? 100 : tail; - SolrUtil.setMainQuery(logFileTailQuery, null); - queryGenerator.setSingleIncludeFilter(logFileTailQuery, LogSearchConstants.SOLR_HOST, host); - if (!StringUtils.isBlank(logFile)) { - queryGenerator.setSingleIncludeFilter(logFileTailQuery, LogSearchConstants.SOLR_PATH, SolrUtil.makeSolrSearchString(logFile)); - } else if (!StringUtils.isBlank(component)) { - queryGenerator.setSingleIncludeFilter(logFileTailQuery, LogSearchConstants.SOLR_COMPONENT, component); - } else { - throw RESTErrorUtil.createRESTException("component or logfile parameter must be present", MessageEnums.ERROR_SYSTEM); - } - - SolrUtil.setRowCount(logFileTailQuery, tail); - queryGenerator.setSortOrderDefaultServiceLog(logFileTailQuery, new SearchCriteria()); - VSolrLogList solrLogList = getLogAsPaginationProvided(logFileTailQuery, serviceLogsSolrDao); - return convertObjToString(solrLogList); - - } catch (NumberFormatException ne) { - - throw RESTErrorUtil.createRESTException(ne.getMessage(), - MessageEnums.ERROR_SYSTEM); - - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/77f9e8ff/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java deleted file mode 100644 index 53e0aab..0000000 --- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/LogsMgr.java +++ /dev/null @@ -1,1896 +0,0 @@ -/* - * 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.ambari.logsearch.manager; - -import java.io.IOException; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TimeZone; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; - -import javax.ws.rs.core.Response; - -import org.apache.ambari.logsearch.common.ConfigHelper; -import org.apache.ambari.logsearch.common.LogSearchConstants; -import org.apache.ambari.logsearch.common.MessageEnums; -import org.apache.ambari.logsearch.common.PropertiesHelper; -import org.apache.ambari.logsearch.common.SearchCriteria; -import org.apache.ambari.logsearch.dao.ServiceLogsSolrDao; -import org.apache.ambari.logsearch.graph.GraphDataGenerator; -import org.apache.ambari.logsearch.query.QueryGenerationBase; -import org.apache.ambari.logsearch.util.BizUtil; -import org.apache.ambari.logsearch.util.DateUtil; -import org.apache.ambari.logsearch.util.FileUtil; -import org.apache.ambari.logsearch.util.RESTErrorUtil; -import org.apache.ambari.logsearch.util.SolrUtil; -import org.apache.ambari.logsearch.view.VBarDataList; -import org.apache.ambari.logsearch.view.VBarGraphData; -import org.apache.ambari.logsearch.view.VCount; -import org.apache.ambari.logsearch.view.VCountList; -import org.apache.ambari.logsearch.view.VGraphData; -import org.apache.ambari.logsearch.view.VGraphInfo; -import org.apache.ambari.logsearch.view.VGroupList; -import org.apache.ambari.logsearch.view.VNameValue; -import org.apache.ambari.logsearch.view.VNameValueList; -import org.apache.ambari.logsearch.view.VNode; -import org.apache.ambari.logsearch.view.VNodeList; -import org.apache.ambari.logsearch.view.VSolrLogList; -import org.apache.ambari.logsearch.view.VSummary; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.time.DateUtils; -import org.apache.log4j.Logger; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.FacetField; -import org.apache.solr.client.solrj.response.FacetField.Count; -import org.apache.solr.client.solrj.response.PivotField; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.client.solrj.response.RangeFacet; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; -import org.apache.solr.common.SolrException; -import org.apache.solr.common.util.NamedList; -import org.apache.solr.common.util.SimpleOrderedMap; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; - -import com.google.common.collect.Lists; - -@Component -public class LogsMgr extends MgrBase { - private static final Logger logger = Logger.getLogger(LogsMgr.class); - - private static List cancelByDate = new CopyOnWriteArrayList(); - - private static Map mapUniqueId = new ConcurrentHashMap(); - - private static enum CONDITION { - OR, AND - } - - @Autowired - private ServiceLogsSolrDao serviceLogsSolrDao; - @Autowired - private GraphDataGenerator graphDataGenerator; - - public String searchLogs(SearchCriteria searchCriteria) { - String keyword = (String) searchCriteria.getParamValue("keyword"); - String logId = (String) searchCriteria.getParamValue("sourceLogId"); - String lastPage = (String) searchCriteria.getParamValue("isLastPage"); - Boolean isLastPage = Boolean.parseBoolean(lastPage); - - if (!StringUtils.isBlank(keyword)) { - try { - return getPageByKeyword(searchCriteria); - } catch (SolrException | SolrServerException e) { - logger.error("Error while getting keyword=" + keyword, e); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - } else if (!StringUtils.isBlank(logId)) { - try { - return getPageByLogId(searchCriteria); - } catch (SolrException e) { - logger.error("Error while getting keyword=" + keyword, e); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - } else if (isLastPage) { - SolrQuery lastPageQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - VSolrLogList collection = getLastPage(searchCriteria,LogSearchConstants.LOGTIME,serviceLogsSolrDao,lastPageQuery); - if(collection == null){ - collection = new VSolrLogList(); - } - return convertObjToString(collection); - } else { - SolrQuery solrQuery = queryGenerator - .commonServiceFilterQuery(searchCriteria); - - solrQuery.setParam("event", "/service/logs"); - - VSolrLogList collection = getLogAsPaginationProvided(solrQuery, - serviceLogsSolrDao); - return convertObjToString(collection); - } - } - - public String getHosts() { - return getFields(LogSearchConstants.SOLR_HOST); - } - - private String getFields(String field){ - - SolrQuery solrQuery = new SolrQuery(); - VGroupList collection = new VGroupList(); - SolrUtil.setMainQuery(solrQuery, null); - SolrUtil.setFacetField(solrQuery, - field); - SolrUtil.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX); - try { - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - if(response == null){ - return convertObjToString(collection); - } - FacetField facetField = response - .getFacetField(field); - if (facetField == null){ - return convertObjToString(collection); - } - List fieldList = facetField.getValues(); - if (fieldList == null){ - return convertObjToString(collection); - } - SolrDocumentList docList = response.getResults(); - if(docList == null){ - return convertObjToString(collection); - } - String temp = ""; - for (Count cnt : fieldList) { - SolrDocument solrDoc = new SolrDocument(); - temp = cnt.getName(); - solrDoc.put(field, temp); - docList.add(solrDoc); - } - - collection.setGroupDocuments(docList); - if(!docList.isEmpty()){ - collection.setStartIndex((int) docList.getStart()); - collection.setTotalCount(docList.getNumFound()); - } - return convertObjToString(collection); - } catch (IOException | SolrServerException | SolrException e) { - logger.error(e); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - - } - - public String getComponents() { - return getFields(LogSearchConstants.SOLR_COMPONENT); - } - - public String getAggregatedInfo(SearchCriteria searchCriteria) { - SolrQuery solrQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - String hierarchy = "host,type,level"; - VGraphInfo graphInfo = new VGraphInfo(); - try { - SolrUtil.setMainQuery(solrQuery, null); - SolrUtil.setFacetPivot(solrQuery, 1, hierarchy); - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - if (response == null) { - return convertObjToString(graphInfo); - } - - List> hirarchicalPivotField = new ArrayList>(); - List dataList = new ArrayList(); - NamedList> namedList = response.getFacetPivot(); - if (namedList != null) { - hirarchicalPivotField = namedList.getAll(hierarchy); - } - if (!hirarchicalPivotField.isEmpty()) { - dataList = buidGraphData(hirarchicalPivotField.get(0)); - } - if (!dataList.isEmpty()) { - graphInfo.setGraphData(dataList); - } - - return convertObjToString(graphInfo); - } catch (SolrException | SolrServerException | IOException e) { - logger.error("Error during solrQuery=" + solrQuery, e); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - } - - public List buidGraphData(List pivotFields) { - List logList = new ArrayList(); - if (pivotFields != null) { - for (PivotField pivotField : pivotFields) { - if (pivotField != null) { - VGraphData logLevel = new VGraphData(); - logLevel.setName("" + pivotField.getValue()); - logLevel.setCount(Long.valueOf(pivotField.getCount())); - if (pivotField.getPivot() != null) { - logLevel.setDataList(buidGraphData(pivotField.getPivot())); - } - logList.add(logLevel); - } - } - } - return logList; - } - - public VCountList getFieldCount(String field){ - VCountList collection = new VCountList(); - List vCounts = new ArrayList(); - SolrQuery solrQuery = new SolrQuery(); - SolrUtil.setMainQuery(solrQuery, null); - if(field == null){ - return collection; - } - SolrUtil.setFacetField(solrQuery, field); - try { - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - if (response == null){ - return collection; - } - FacetField facetFields = response.getFacetField(field); - if (facetFields == null){ - return collection; - } - List fieldList = facetFields.getValues(); - - if(fieldList == null){ - return collection; - } - - for (Count cnt : fieldList) { - if (cnt != null) { - VCount vCount = new VCount(); - vCount.setName(cnt.getName()); - vCount.setCount(cnt.getCount()); - vCounts.add(vCount); - } - } - - } catch (SolrException | SolrServerException | IOException e) { - logger.error("Error during solrQuery=" + solrQuery, e); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - - collection.setCounts(vCounts); - return collection; - } - - public VCountList getLogLevelCount() { - return getFieldCount(LogSearchConstants.SOLR_LEVEL); - } - - public VCountList getComponentsCount() { - return getFieldCount(LogSearchConstants.SOLR_COMPONENT); - } - - public VCountList getHostsCount() { - return getFieldCount(LogSearchConstants.SOLR_HOST); - } - - public List buidTreeData(List pivotFields, - List pivotFieldHost, SolrQuery query, - String firstPriority, String secondPriority) { - List extensionTree = new ArrayList(); - String hostQuery = null; - if (pivotFields != null) { - // For Host - for (PivotField pivotHost : pivotFields) { - if (pivotHost != null) { - VNode hostNode = new VNode(); - String name = (pivotHost.getValue() == null ? "" : ""+ pivotHost.getValue()); - String value = "" + pivotHost.getCount(); - if(!StringUtils.isBlank(name)){ - hostNode.setName(name); - } - if(!StringUtils.isBlank(value)){ - hostNode.setValue(value); - } - if(!StringUtils.isBlank(firstPriority)){ - hostNode.setType(firstPriority); - } - - hostNode.setParent(true); - hostNode.setRoot(true); - PivotField hostPivot = null; - for (PivotField searchHost : pivotFieldHost) { - if (!StringUtils.isBlank(hostNode.getName()) - && hostNode.getName().equals(searchHost.getValue())) { - hostPivot = searchHost; - break; - } - } - List pivotLevelHost = hostPivot.getPivot(); - if (pivotLevelHost != null) { - Collection logLevelCount = new ArrayList(); - for (PivotField pivotLevel : pivotLevelHost) { - if (pivotLevel != null) { - VNameValue vnameValue = new VNameValue(); - String levelName = (pivotLevel.getValue() == null ? "" : "" - + pivotLevel.getValue()); - vnameValue.setName(levelName.toUpperCase()); - vnameValue.setValue("" + pivotLevel.getCount()); - logLevelCount.add(vnameValue); - } - } - hostNode.setLogLevelCount(logLevelCount); - } - - query.addFilterQuery(hostQuery); - List pivotComponents = pivotHost.getPivot(); - // For Components - if (pivotComponents != null) { - Collection componentNodes = new ArrayList(); - for (PivotField pivotComp : pivotComponents) { - if (pivotComp != null) { - VNode compNode = new VNode(); - String compName = (pivotComp.getValue() == null ? "" : "" - + pivotComp.getValue()); - compNode.setName(compName); - if (!StringUtils.isBlank(secondPriority)) { - compNode.setType(secondPriority); - } - compNode.setValue("" + pivotComp.getCount()); - compNode.setParent(false); - compNode.setRoot(false); - List pivotLevels = pivotComp.getPivot(); - if (pivotLevels != null) { - Collection logLevelCount = new ArrayList(); - for (PivotField pivotLevel : pivotLevels) { - if (pivotLevel != null) { - VNameValue vnameValue = new VNameValue(); - String compLevel = pivotLevel.getValue() == null ? "" - : "" + pivotLevel.getValue(); - vnameValue.setName((compLevel).toUpperCase()); - - vnameValue.setValue("" + pivotLevel.getCount()); - logLevelCount.add(vnameValue); - } - } - compNode.setLogLevelCount(logLevelCount); - } - componentNodes.add(compNode); - }} - hostNode.setChilds(componentNodes); - } - extensionTree.add(hostNode); - }} - } - - return extensionTree; - } - - public VNodeList getTreeExtension(SearchCriteria searchCriteria) { - SolrQuery solrQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - solrQuery.setParam("event", "/getTreeExtension"); - - if (searchCriteria.getSortBy() == null) { - searchCriteria.setSortBy(LogSearchConstants.SOLR_HOST); - searchCriteria.setSortType(SolrQuery.ORDER.asc.toString()); - } - queryGenerator.setFilterFacetSort(solrQuery, searchCriteria); - String hostName = "" - + ((searchCriteria.getParamValue("hostName") == null) ? "" - : searchCriteria.getParamValue("hostName")); - if (!StringUtils.isBlank(hostName)){ - solrQuery.addFilterQuery(LogSearchConstants.SOLR_HOST + ":*" - + hostName + "*"); - } - String firstHirarchy = "host,type,level"; - String secondHirarchy = "host,level"; - VNodeList list = new VNodeList(); - try { - - SolrUtil.setFacetPivot(solrQuery, 1, firstHirarchy, - secondHirarchy); - - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - List> listFirstHirarchicalPivotFields = new ArrayList>(); - NamedList> firstNamedList = response - .getFacetPivot(); - if (firstNamedList != null) { - listFirstHirarchicalPivotFields = firstNamedList - .getAll(firstHirarchy); - } - List> listSecondHirarchicalPivotFields = new ArrayList>(); - NamedList> secondNamedList = response - .getFacetPivot(); - if (secondNamedList != null) { - listSecondHirarchicalPivotFields = secondNamedList - .getAll(secondHirarchy); - } - List firstHirarchicalPivotFields = new ArrayList(); - List secondHirarchicalPivotFields = new ArrayList(); - if (!listFirstHirarchicalPivotFields.isEmpty()) { - firstHirarchicalPivotFields = listFirstHirarchicalPivotFields - .get(0); - } - if (!listSecondHirarchicalPivotFields.isEmpty()) { - secondHirarchicalPivotFields = listSecondHirarchicalPivotFields - .get(0); - } - List dataList = buidTreeData(firstHirarchicalPivotFields, - secondHirarchicalPivotFields, solrQuery, - LogSearchConstants.HOST, LogSearchConstants.COMPONENT); - - list.setvNodeList(dataList); - } catch (SolrException | SolrServerException | IOException e) { - logger.error("Error during solrQuery=" + solrQuery, e); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - - return list; - } - - public String getHostListByComponent(SearchCriteria searchCriteria) { - SolrQuery solrQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - solrQuery.setParam("event", "/service/hosts/component"); - - VNodeList list = new VNodeList(); - if (searchCriteria.getSortBy() == null) { - searchCriteria.setSortBy(LogSearchConstants.SOLR_HOST); - searchCriteria.setSortType(SolrQuery.ORDER.asc.toString()); - } - queryGenerator.setFilterFacetSort(solrQuery, searchCriteria); - String componentName = "" - + ((searchCriteria.getParamValue("componentName") == null) ? "" - : searchCriteria.getParamValue("componentName")); - if (!StringUtils.isBlank(componentName)){ - solrQuery.addFilterQuery(LogSearchConstants.SOLR_COMPONENT + ":" - + componentName); - } else { - return convertObjToString(list); - } - - String firstHirarchy = "type,host,level"; - String secondHirarchy = "type,level"; - - try { - SolrUtil.setFacetPivot(solrQuery, 1, firstHirarchy, - secondHirarchy); - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - List> firstHirarchicalPivotFields = null; - List> secondHirarchicalPivotFields = null; - NamedList> firstNamedList = response - .getFacetPivot(); - if (firstNamedList != null) { - firstHirarchicalPivotFields = firstNamedList - .getAll(firstHirarchy); - secondHirarchicalPivotFields = firstNamedList - .getAll(secondHirarchy); - } - - if (firstHirarchicalPivotFields == null - || secondHirarchicalPivotFields == null) { - return convertObjToString(list); - } - - List dataList = buidTreeData( - firstHirarchicalPivotFields.get(0), - secondHirarchicalPivotFields.get(0), solrQuery, - LogSearchConstants.COMPONENT, LogSearchConstants.HOST); - if(dataList == null){ - return convertObjToString(list); - } - - list.setvNodeList(dataList); - return convertObjToString(list); - } catch (SolrException | SolrServerException | IOException e) { - logger.error("Error during solrQuery=" + solrQuery, e); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - } - - public VNameValueList getLogsLevelCount(SearchCriteria sc) { - VNameValueList nameValueList = new VNameValueList(); - SolrQuery query = queryGenerator.commonServiceFilterQuery(sc); - query.setParam("event", "/service/logs/levels/counts/namevalues"); - List logsCounts = getLogLevelFacets(query); - nameValueList.setVNameValues(logsCounts); - - return nameValueList; - } - - public List getLogLevelFacets(SolrQuery query) { - String defalutValue = "0"; - HashMap map = new HashMap(); - List logsCounts = new ArrayList(); - try { - SolrUtil.setFacetField(query, LogSearchConstants.SOLR_LEVEL); - List logLevelCounts = getFacetCounts(query, - LogSearchConstants.SOLR_LEVEL); - if (logLevelCounts == null) { - return logsCounts; - } - for (Count count : logLevelCounts) { - map.put(count.getName().toUpperCase(), "" + count.getCount()); - } - for (String level : LogSearchConstants.SUPPORTED_LOG_LEVEL) { - VNameValue nameValue = new VNameValue(); - String value = map.get(level); - if (StringUtils.isBlank(value)) { - value = defalutValue; - } - nameValue.setName(level); - nameValue.setValue(value); - logsCounts.add(nameValue); - } - } catch (SolrException | SolrServerException | IOException e) { - logger.error("Error during solrQuery=" + query, e); - } - return logsCounts; - } - - // Get Facet Count According to FacetFeild - public List getFacetCounts(SolrQuery solrQuery, String facetField) - throws SolrServerException, IOException, SolrException { - List list = new ArrayList(); - - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - if(response == null){ - return list; - } - - FacetField field = response.getFacetField(facetField); - if (field == null) { - return list; - } - list = field.getValues(); - - - return list; - } - - public String getPageByKeyword(SearchCriteria searchCriteria) - throws SolrServerException { - String defaultChoice = "0"; - - String key = (String) searchCriteria.getParamValue("keyword"); - if(StringUtils.isBlank(key)){ - throw RESTErrorUtil.createRESTException("Keyword was not given", - MessageEnums.DATA_NOT_FOUND); - } - - String keyword = SolrUtil.escapeForStandardTokenizer(key); - - if(keyword.startsWith("\"") && keyword.endsWith("\"")){ - keyword = keyword.substring(1); - keyword = keyword.substring(0, keyword.length()-1); - } - keyword = "*" + keyword + "*"; - - - String keyType = (String) searchCriteria.getParamValue("keywordType"); - QueryResponse queryResponse = null; - - if (!defaultChoice.equals(keyType)) { - try { - int currentPageNumber = searchCriteria.getPage(); - int maxRows = searchCriteria.getMaxRows(); - String nextPageLogID = ""; - - int lastLogIndexNumber = ((currentPageNumber + 1) - * maxRows); - String nextPageLogTime = ""; - - - // Next Page Start Time Calculation - SolrQuery nextPageLogTimeQuery = queryGenerator - .commonServiceFilterQuery(searchCriteria); - nextPageLogTimeQuery.remove("start"); - nextPageLogTimeQuery.remove("rows"); - nextPageLogTimeQuery.setStart(lastLogIndexNumber); - nextPageLogTimeQuery.setRows(1); - - queryResponse = serviceLogsSolrDao.process( - nextPageLogTimeQuery); - if(queryResponse == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - - SolrDocumentList docList = queryResponse.getResults(); - if(docList ==null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - - SolrDocument solrDoc = docList.get(0); - - Date logDate = (Date) solrDoc.get(LogSearchConstants.LOGTIME); - if(logDate == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - nextPageLogTime = DateUtil - .convertDateWithMillisecondsToSolrDate(logDate); - nextPageLogID = "" - + solrDoc.get(LogSearchConstants.ID); - - if (StringUtils.isBlank(nextPageLogID)){ - nextPageLogID = "0"; - } - - String filterQueryListIds = ""; - // Remove the same Time Ids - SolrQuery listRemoveIds = queryGenerator - .commonServiceFilterQuery(searchCriteria); - listRemoveIds.remove("start"); - listRemoveIds.remove("rows"); - queryGenerator.setSingleIncludeFilter(listRemoveIds, - LogSearchConstants.LOGTIME, "\"" + nextPageLogTime + "\""); - queryGenerator.setSingleExcludeFilter(listRemoveIds, - LogSearchConstants.ID, nextPageLogID); - SolrUtil.setFl(listRemoveIds, LogSearchConstants.ID); - queryResponse = serviceLogsSolrDao.process( - listRemoveIds); - if(queryResponse == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - - SolrDocumentList docListIds = queryResponse.getResults(); - if(docListIds ==null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - boolean isFirst = true; - for (SolrDocument solrDocId : docListIds ) { - String id = "" + solrDocId.get(LogSearchConstants.ID); - if (isFirst) { - filterQueryListIds += LogSearchConstants.MINUS_OPERATOR + LogSearchConstants.ID + ":" + id; - isFirst = false; - } else { - filterQueryListIds += " "+CONDITION.AND+" " + LogSearchConstants.MINUS_OPERATOR + LogSearchConstants.ID + ":" + id; - } - } - - // Keyword Sequence Number Calculation - String endTime = (String) searchCriteria.getParamValue("to"); - String startTime = (String) searchCriteria - .getParamValue("from"); - SolrQuery logTimeThroughRangeQuery = queryGenerator - .commonServiceFilterQuery(searchCriteria); - logTimeThroughRangeQuery.remove("start"); - logTimeThroughRangeQuery.remove("rows"); - logTimeThroughRangeQuery.setRows(1); - if (!StringUtils.isBlank(filterQueryListIds)){ - logTimeThroughRangeQuery.setFilterQueries(filterQueryListIds); - } - - String sortByType = searchCriteria.getSortType(); - - if (!StringUtils.isBlank(sortByType) && sortByType - .equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) { - - queryGenerator.setSingleRangeFilter(logTimeThroughRangeQuery, - LogSearchConstants.LOGTIME, nextPageLogTime, - endTime); - logTimeThroughRangeQuery.set(LogSearchConstants.SORT, - LogSearchConstants.LOGTIME + " " - + LogSearchConstants.ASCENDING_ORDER); - - } else { - - queryGenerator.setSingleRangeFilter(logTimeThroughRangeQuery, - LogSearchConstants.LOGTIME, startTime, - nextPageLogTime); - logTimeThroughRangeQuery.set(LogSearchConstants.SORT, - LogSearchConstants.LOGTIME + " " - + LogSearchConstants.DESCENDING_ORDER); - } - queryGenerator.setSingleIncludeFilter(logTimeThroughRangeQuery, - LogSearchConstants.SOLR_KEY_LOG_MESSAGE, keyword); - - - queryResponse = serviceLogsSolrDao.process( - logTimeThroughRangeQuery); - if(queryResponse == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - - SolrDocumentList documentList = queryResponse.getResults(); - if(documentList ==null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - - SolrDocument solrDocument = new SolrDocument(); - if (!documentList.isEmpty()){ - solrDocument = documentList.get(0); - } - - Date keywordLogDate = (Date) solrDocument.get(LogSearchConstants.LOGTIME); - if(keywordLogDate == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - String originalKeywordDate = DateUtil - .convertDateWithMillisecondsToSolrDate(keywordLogDate); - String keywordId = "" + solrDocument.get(LogSearchConstants.ID); - - // Getting Range Count from StartTime To Keyword Log Time - SolrQuery rangeLogQuery = nextPageLogTimeQuery.getCopy(); - rangeLogQuery.remove("start"); - rangeLogQuery.remove("rows"); - - if (!StringUtils.isBlank(sortByType) && sortByType - .equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) { - keywordLogDate = DateUtils.addMilliseconds(keywordLogDate, 1); - String keywordDateTime = DateUtil - .convertDateWithMillisecondsToSolrDate(keywordLogDate); - queryGenerator.setSingleRangeFilter(rangeLogQuery, - LogSearchConstants.LOGTIME, startTime, - keywordDateTime); - } else { - keywordLogDate = DateUtils.addMilliseconds(keywordLogDate, -1); - String keywordDateTime = DateUtil - .convertDateWithMillisecondsToSolrDate(keywordLogDate); - queryGenerator.setSingleRangeFilter(rangeLogQuery, - LogSearchConstants.LOGTIME, keywordDateTime, - endTime); - } - - - long countNumberLogs = countQuery(rangeLogQuery,serviceLogsSolrDao) - 1; - - - //Adding numbers on - - - try { - SolrQuery sameIdQuery = queryGenerator - .commonServiceFilterQuery(searchCriteria); - queryGenerator.setSingleIncludeFilter(sameIdQuery, - LogSearchConstants.LOGTIME, "\"" + originalKeywordDate + "\""); - SolrUtil.setFl(sameIdQuery, LogSearchConstants.ID); - SolrDocumentList sameQueryDocList = serviceLogsSolrDao.process(sameIdQuery) - .getResults(); - for (SolrDocument solrDocumenent : sameQueryDocList) { - String id = (String) solrDocumenent - .getFieldValue(LogSearchConstants.ID); - countNumberLogs++; - - if (StringUtils.isBlank(id) && id.equals(keywordId)){ - break; - } - } - } catch (SolrException | SolrServerException | IOException e) { - logger.error(e); - } - - int start = (int) ((countNumberLogs / maxRows) * maxRows); - SolrQuery logIdQuery = nextPageLogTimeQuery.getCopy(); - rangeLogQuery.remove("start"); - rangeLogQuery.remove("rows"); - logIdQuery.setStart(start); - logIdQuery.setRows(searchCriteria.getMaxRows()); - VSolrLogList vSolrLogList = getLogAsPaginationProvided(logIdQuery, serviceLogsSolrDao); - return convertObjToString(vSolrLogList); - - } catch (Exception e) { - //do nothing - } - - } else { - try { - int currentPageNumber = searchCriteria.getPage(); - int maxRows = searchCriteria.getMaxRows(); - - if (currentPageNumber == 0) { - throw RESTErrorUtil.createRESTException("This is first Page Not", - MessageEnums.DATA_NOT_FOUND); - } - - int firstLogCurrentPage = (currentPageNumber * maxRows); - String lastLogsLogTime = ""; - - // Next Page Start Time Calculation - SolrQuery lastLogTime = queryGenerator - .commonServiceFilterQuery(searchCriteria); - lastLogTime.remove("start"); - lastLogTime.remove("rows"); - - lastLogTime.setStart(firstLogCurrentPage); - lastLogTime.setRows(1); - - queryResponse = serviceLogsSolrDao.process( - lastLogTime); - if(queryResponse == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - - SolrDocumentList docList = queryResponse.getResults(); - if(docList ==null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - SolrDocument solrDoc = docList.get(0); - - Date logDate = (Date) solrDoc.get(LogSearchConstants.LOGTIME); - String sortByType = searchCriteria.getSortType(); - lastLogsLogTime = DateUtil - .convertDateWithMillisecondsToSolrDate(logDate); - String lastLogsLogId = "" - + solrDoc.get(LogSearchConstants.ID); - - - String filterQueryListIds = ""; - // Remove the same Time Ids - SolrQuery listRemoveIds = queryGenerator - .commonServiceFilterQuery(searchCriteria); - listRemoveIds.remove("start"); - listRemoveIds.remove("rows"); - queryGenerator.setSingleIncludeFilter(listRemoveIds, - LogSearchConstants.LOGTIME, "\"" + lastLogsLogTime + "\""); - queryGenerator.setSingleExcludeFilter(listRemoveIds, - LogSearchConstants.ID, lastLogsLogId); - SolrUtil.setFl(listRemoveIds, LogSearchConstants.ID); - queryResponse = serviceLogsSolrDao.process( - lastLogTime); - if(queryResponse == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - - SolrDocumentList docListIds = queryResponse.getResults(); - if(docListIds == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - boolean isFirst = true; - for (SolrDocument solrDocId : docListIds) { - if (solrDocId != null) { - String id = "" + solrDocId.get(LogSearchConstants.ID); - if (isFirst) { - filterQueryListIds += LogSearchConstants.MINUS_OPERATOR + LogSearchConstants.ID + ":" + id; - isFirst = false; - } else { - filterQueryListIds += " "+CONDITION.AND+" " + LogSearchConstants.MINUS_OPERATOR + LogSearchConstants.ID + ":" - + id; - } - } - } - - - // Keyword LogTime Calculation - String endTime = (String) searchCriteria.getParamValue("to"); - String startTime = (String) searchCriteria - .getParamValue("from"); - SolrQuery logTimeThroughRangeQuery = queryGenerator - .commonServiceFilterQuery(searchCriteria); - logTimeThroughRangeQuery.remove("start"); - logTimeThroughRangeQuery.remove("rows"); - logTimeThroughRangeQuery.setRows(1); - queryGenerator.setSingleExcludeFilter(logTimeThroughRangeQuery, - LogSearchConstants.ID, lastLogsLogId); - if (!StringUtils.isBlank(filterQueryListIds)){ - logTimeThroughRangeQuery.setFilterQueries(filterQueryListIds); - } - - if (!StringUtils.isBlank(sortByType) && sortByType - .equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) { - - logTimeThroughRangeQuery.remove(LogSearchConstants.SORT); - logTimeThroughRangeQuery.set(LogSearchConstants.SORT, - LogSearchConstants.LOGTIME + " " - + LogSearchConstants.DESCENDING_ORDER); - - - queryGenerator.setSingleRangeFilter( - logTimeThroughRangeQuery, - LogSearchConstants.LOGTIME, startTime, - lastLogsLogTime); - - } else { - - logTimeThroughRangeQuery.remove(LogSearchConstants.SORT); - logTimeThroughRangeQuery.set(LogSearchConstants.SORT, - LogSearchConstants.LOGTIME + " " - + LogSearchConstants.ASCENDING_ORDER); - - - queryGenerator.setSingleRangeFilter(logTimeThroughRangeQuery, - LogSearchConstants.LOGTIME, lastLogsLogTime, endTime); - } - queryGenerator.setSingleIncludeFilter(logTimeThroughRangeQuery, - LogSearchConstants.SOLR_KEY_LOG_MESSAGE, keyword); - - - queryResponse = serviceLogsSolrDao.process( - logTimeThroughRangeQuery); - if(queryResponse == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - - SolrDocumentList documentList = queryResponse.getResults(); - if(documentList == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - SolrDocument solrDocument = new SolrDocument(); - if (!documentList.isEmpty()){ - solrDocument = documentList.get(0); - } - - Date keywordLogDate = (Date) solrDocument.get(LogSearchConstants.LOGTIME); - if(keywordLogDate == null){ - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - String originalKeywordDate = DateUtil - .convertDateWithMillisecondsToSolrDate(keywordLogDate); - String keywordId = "" + solrDocument.get(LogSearchConstants.ID); - - // Getting Range Count from StartTime To Keyword Log Time - SolrQuery rangeLogQuery = lastLogTime.getCopy(); - rangeLogQuery.remove("start"); - rangeLogQuery.remove("rows"); - - if (!StringUtils.isBlank(sortByType) && sortByType - .equalsIgnoreCase(LogSearchConstants.ASCENDING_ORDER)) { - // keywordLogDate = DateUtil.addMilliSecondsToDate(keywordLogDate, 1); - String keywordDateTime = DateUtil - .convertDateWithMillisecondsToSolrDate(keywordLogDate); - queryGenerator.setSingleRangeFilter(rangeLogQuery, - LogSearchConstants.LOGTIME, startTime, - keywordDateTime); - - - } else { - // keywordLogDate = DateUtil.addMilliSecondsToDate(keywordLogDate, -1); - String keywordDateTime = DateUtil - .convertDateWithMillisecondsToSolrDate(keywordLogDate); - queryGenerator.setSingleRangeFilter(rangeLogQuery, - LogSearchConstants.LOGTIME, keywordDateTime, - endTime); - } - - - long countNumberLogs = countQuery(rangeLogQuery,serviceLogsSolrDao) - 1; - - //Adding numbers on - try { - SolrQuery sameIdQuery = queryGenerator - .commonServiceFilterQuery(searchCriteria); - queryGenerator.setSingleIncludeFilter(sameIdQuery, - LogSearchConstants.LOGTIME, "\"" + originalKeywordDate + "\""); - SolrUtil.setFl(sameIdQuery, LogSearchConstants.ID); - SolrDocumentList sameQueryDocList = serviceLogsSolrDao.process(sameIdQuery) - .getResults(); - for (SolrDocument solrDocumenent : sameQueryDocList) { - if (solrDocumenent != null) { - String id = (String) solrDocumenent - .getFieldValue(LogSearchConstants.ID); - countNumberLogs++; - if ( StringUtils.isBlank(id) && id.equals(keywordId)) { - break; - } - } - } - } catch (SolrException | SolrServerException | IOException e) { - logger.error(e); - } - int start = (int) ((countNumberLogs / maxRows) * maxRows); - - SolrQuery logIdQuery = lastLogTime.getCopy(); - rangeLogQuery.remove("start"); - rangeLogQuery.remove("rows"); - logIdQuery.setStart(start); - logIdQuery.setRows(searchCriteria.getMaxRows()); - VSolrLogList vSolrLogList = getLogAsPaginationProvided(logIdQuery, serviceLogsSolrDao); - return convertObjToString(vSolrLogList); - } catch (Exception e) { - //do nothing - } - - } - throw RESTErrorUtil.createRESTException("The keyword "+"\""+key+"\""+" was not found", - MessageEnums.ERROR_SYSTEM); - } - - private String getPageByLogId(SearchCriteria searchCriteria) { - VSolrLogList vSolrLogList = new VSolrLogList(); - String endLogTime = (String) searchCriteria.getParamValue("to"); - if(StringUtils.isBlank(endLogTime)){ - return convertObjToString(vSolrLogList); - } - long startIndex = 0l; - - String logId = (String) searchCriteria.getParamValue("sourceLogId"); - if(StringUtils.isBlank(logId)){ - return convertObjToString(vSolrLogList); - } - SolrQuery solrQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - - String endTimeMinusOneMilli = ""; - String logTime = ""; - try { - - SolrQuery logTimeByIdQuery = new SolrQuery(); - SolrUtil.setMainQuery(logTimeByIdQuery, null); - queryGenerator.setSingleIncludeFilter(logTimeByIdQuery, - LogSearchConstants.ID, logId); - SolrUtil.setRowCount(solrQuery, 1); - - QueryResponse queryResponse = serviceLogsSolrDao - .process(logTimeByIdQuery); - - if(queryResponse == null){ - return convertObjToString(new VSolrLogList()); - } - - SolrDocumentList docList = queryResponse.getResults(); - Date dateOfLogId = null; - if (docList != null && !docList.isEmpty()) { - SolrDocument dateLogIdDoc = docList.get(0); - if(dateLogIdDoc != null){ - dateOfLogId = (Date) dateLogIdDoc.get(LogSearchConstants.LOGTIME); - } - } - - if (dateOfLogId != null) { - logTime = DateUtil.convertDateWithMillisecondsToSolrDate(dateOfLogId); - Date endDate = DateUtils.addMilliseconds(dateOfLogId, 1); - endTimeMinusOneMilli = (String) DateUtil - .convertDateWithMillisecondsToSolrDate(endDate); - } - - } catch (SolrException | SolrServerException | IOException e) { - logger.error(e); - } - - try { - solrQuery.remove(LogSearchConstants.ID); - solrQuery.remove(LogSearchConstants.LOGTIME); - queryGenerator.setSingleRangeFilter(solrQuery, - LogSearchConstants.LOGTIME, endTimeMinusOneMilli, endLogTime); - SolrUtil.setRowCount(solrQuery, 0); - startIndex = countQuery(solrQuery,serviceLogsSolrDao); - } catch (SolrException | SolrServerException | IOException e) { - logger.error(e); - } - - try { - SolrQuery sameIdQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - queryGenerator.setSingleIncludeFilter(sameIdQuery, - LogSearchConstants.LOGTIME, "\"" + logTime + "\""); - sameIdQuery.set("fl", LogSearchConstants.ID); - - QueryResponse sameIdResponse = serviceLogsSolrDao.process(sameIdQuery); - SolrDocumentList docList = sameIdResponse.getResults(); - - for (SolrDocument solrDocumenent : docList) { - String id = (String) solrDocumenent - .getFieldValue(LogSearchConstants.ID); - startIndex++; - if (!StringUtils.isBlank(id)) { - if (id.equals(logId)) { - break; - } - } - } - - SolrQuery logIdQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - logIdQuery.remove("rows"); - logIdQuery.remove("start"); - int start = (int) ((startIndex / searchCriteria.getMaxRows()) * searchCriteria - .getMaxRows()); - logIdQuery.setStart(start); - logIdQuery.setRows(searchCriteria.getMaxRows()); - vSolrLogList = getLogAsPaginationProvided(logIdQuery, - serviceLogsSolrDao); - return convertObjToString(vSolrLogList); - } catch (SolrException | SolrServerException | IOException e) { - logger.error(e); - } - - throw RESTErrorUtil.createRESTException("LogId not Found", - MessageEnums.ERROR_SYSTEM); - } - - @SuppressWarnings("unchecked") - public List getHistogramCounts(SolrQuery solrQuery, - String from, String to, String unit) { - List logsCounts = new ArrayList(); - try { - - SolrUtil.setFacetRange(solrQuery, LogSearchConstants.LOGTIME, - from, to, unit); - - List logLevelCounts = null; - - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - if(response == null){ - return logsCounts; - } - @SuppressWarnings("rawtypes") - List rangeFacetList = response.getFacetRanges(); - if (rangeFacetList == null) { - return logsCounts; - - } - - @SuppressWarnings("rawtypes") - RangeFacet rangeFacet=rangeFacetList.get(0); - if (rangeFacet == null) { - return logsCounts; - } - logLevelCounts = rangeFacet.getCounts(); - - if(logLevelCounts == null){ - return logsCounts; - } - for (RangeFacet.Count logCount : logLevelCounts) { - VNameValue nameValue = new VNameValue(); - nameValue.setName(logCount.getValue()); - nameValue.setValue("" + logCount.getCount()); - logsCounts.add(nameValue); - } - } catch (SolrException | SolrServerException | IOException e) { - logger.error("Error during solrQuery=" + solrQuery, e); - } - return logsCounts; - } - - public List getFacetCountsByDate(SolrQuery solrQuery, - String facetField) throws SolrServerException, IOException, - SolrException { - - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - - FacetField field = response.getFacetDate(facetField); - return field.getValues(); - } - - @SuppressWarnings("unchecked") - public String getHistogramData(SearchCriteria searchCriteria) { - String deafalutValue = "0"; - VBarDataList dataList = new VBarDataList(); - SolrQuery solrQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - solrQuery.set("event", "/audit/logs/histogram"); - String from = getFrom((String) searchCriteria.getParamValue("from")); - String to = getTo((String) searchCriteria.getParamValue("to")); - String unit = getUnit((String) searchCriteria.getParamValue("unit")); - - List histogramData = new ArrayList(); - - String jsonHistogramQuery = queryGenerator - .buildJSONFacetTermTimeRangeQuery( - LogSearchConstants.SOLR_LEVEL, - LogSearchConstants.LOGTIME, from, to, unit).replace( - "\\", ""); - - try { - SolrUtil.setJSONFacet(solrQuery, jsonHistogramQuery); - SolrUtil.setRowCount(solrQuery,Integer.parseInt(deafalutValue)); - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - if (response == null){ - return convertObjToString(dataList); - } - SimpleOrderedMap jsonFacetResponse = (SimpleOrderedMap) response - .getResponse().get("facets"); - - if (jsonFacetResponse == null - || jsonFacetResponse.toString().equals("{count=0}")){ - return convertObjToString(dataList); - } - - extractValuesFromBuckets(jsonFacetResponse, "x", "y", histogramData); - - Collection vNameValues = new ArrayList(); - List graphDatas = new ArrayList(); - for (String level : LogSearchConstants.SUPPORTED_LOG_LEVEL) { - boolean isLevelPresent = false; - VBarGraphData vData1 = null; - for (VBarGraphData vData2 : histogramData) { - String name = vData2.getName(); - if (level.contains(name)) { - isLevelPresent = true; - vData1 = vData2; - break; - } - if (vNameValues.isEmpty()) { - Collection vNameValues2 = vData2 - .getDataCount(); - for (VNameValue value : vNameValues2) { - VNameValue value2 = new VNameValue(); - value2.setValue(deafalutValue); - value2.setName(value.getName()); - vNameValues.add(value2); - } - } - } - if (!isLevelPresent) { - VBarGraphData vBarGraphData = new VBarGraphData(); - vBarGraphData.setName(level); - vBarGraphData.setDataCounts(vNameValues); - graphDatas.add(vBarGraphData); - } else { - graphDatas.add(vData1); - } - } - - dataList.setGraphData(graphDatas); - return convertObjToString(dataList); - - } catch (SolrServerException | SolrException | IOException e) { - logger.error(e); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - - } - } - - public void arrangeLevel(String level, - List histogramDataLocal, - List histogramData) { - for (VBarGraphData histData : histogramData) { - if (histData != null && level.equals(histData.getName())) { - histogramDataLocal.add(histData); - } - } - } - - public String cancelFindRequestByDate(String uniqueId) { - if (StringUtils.isEmpty(uniqueId)) { - logger.error("Unique id is Empty"); - throw RESTErrorUtil.createRESTException("Unique id is Empty", - MessageEnums.DATA_NOT_FOUND); - } - - if (cancelByDate.remove(uniqueId)) { - mapUniqueId.remove(uniqueId); - return "Cancel Request Successfully Procssed "; - } - return "Cancel Request Unable to Process"; - } - - public boolean cancelRequest(String uniqueId) { - if (StringUtils.isBlank(uniqueId)) { - logger.error("Unique id is Empty"); - throw RESTErrorUtil.createRESTException("Unique id is Empty", - MessageEnums.DATA_NOT_FOUND); - } - for (String date : cancelByDate) { - if (uniqueId.equalsIgnoreCase(date)){ - return false; - } - } - return true; - } - - public Response exportToTextFile(SearchCriteria searchCriteria) { - String defaultFormat = "text"; - SolrQuery solrQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - String from = (String) searchCriteria.getParamValue("from"); - String to = (String) searchCriteria.getParamValue("to"); - String utcOffset = (String) searchCriteria.getParamValue("utcOffset"); - String format = (String) searchCriteria.getParamValue("format"); - - format = defaultFormat.equalsIgnoreCase(format) && format != null ? ".txt" - : ".json"; - - if(StringUtils.isBlank(utcOffset)){ - utcOffset = "0"; - } - - if (!DateUtil.isDateValid(from) || !DateUtil.isDateValid(to)) { - logger.error("Not valid date format. Valid format should be" - + LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z); - throw RESTErrorUtil.createRESTException("Not valid date format. Valid format should be" - + LogSearchConstants.SOLR_DATE_FORMAT_PREFIX_Z, - MessageEnums.INVALID_INPUT_DATA); - - } else { - from = from.replace("T", " "); - from = from.replace(".", ","); - - to = to.replace("T", " "); - to = to.replace(".", ","); - - to = DateUtil.addOffsetToDate(to, Long.parseLong(utcOffset), - "yyyy-MM-dd HH:mm:ss,SSS"); - from = DateUtil.addOffsetToDate(from, Long.parseLong(utcOffset), - "yyyy-MM-dd HH:mm:ss,SSS"); - } - - String fileName = DateUtil.getCurrentDateInString(); - if (searchCriteria.getParamValue("hostLogFile") != null - && searchCriteria.getParamValue("compLogFile") != null) { - fileName = searchCriteria.getParamValue("hostLogFile") + "_" - + searchCriteria.getParamValue("compLogFile"); - } - - String textToSave = ""; - try { - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - if (response == null) { - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - SolrDocumentList docList = response.getResults(); - if (docList == null) { - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - - VSummary vsummary = BizUtil.buildSummaryForLogFile(docList); - vsummary.setFormat(format); - vsummary.setFrom(from); - vsummary.setTo(to); - - String includeString = (String) searchCriteria.getParamValue("iMessage"); - if (StringUtils.isBlank(includeString)) { - includeString = ""; - } - - String include[] = includeString.split(LogSearchConstants.I_E_SEPRATOR); - - for (String inc : include) { - includeString = includeString + ",\"" + inc + "\""; - } - includeString = includeString.replaceFirst(",", ""); - if (!StringUtils.isBlank(includeString)) { - vsummary.setIncludeString(includeString); - } - - String excludeString = null; - boolean isNormalExcluded = false; - - excludeString = (String) searchCriteria.getParamValue("eMessage"); - if (StringUtils.isBlank(excludeString)) { - excludeString = ""; - } - - String exclude[] = excludeString.split(LogSearchConstants.I_E_SEPRATOR); - for (String exc : exclude) { - excludeString = excludeString + ",\"" + exc + "\""; - } - - excludeString = excludeString.replaceFirst(",", ""); - if (!StringUtils.isBlank(excludeString)) { - vsummary.setExcludeString(excludeString); - isNormalExcluded = true; - } - - String globalExcludeString = (String) searchCriteria - .getParamValue("gEMessage"); - if (StringUtils.isBlank(globalExcludeString)) { - globalExcludeString = ""; - } - - String globalExclude[] = globalExcludeString - .split(LogSearchConstants.I_E_SEPRATOR); - - for (String exc : globalExclude) { - excludeString = excludeString + ",\"" + exc + "\""; - } - - if (!StringUtils.isBlank(excludeString)) { - if (!isNormalExcluded) { - excludeString = excludeString.replaceFirst(",", ""); - } - vsummary.setExcludeString(excludeString); - } - - for (SolrDocument solrDoc : docList) { - - Date logTimeDateObj = (Date) solrDoc.get(LogSearchConstants.LOGTIME); - if(logTimeDateObj != null){ - String logTime = DateUtil.convertSolrDateToNormalDateFormat( - logTimeDateObj.getTime(), Long.parseLong(utcOffset)); - solrDoc.remove(LogSearchConstants.LOGTIME); - solrDoc.addField(LogSearchConstants.LOGTIME, logTime); - } - } - - if (format.toLowerCase(Locale.ENGLISH).equals(".txt")) { - textToSave = BizUtil.convertObjectToNormalText(docList); - } else if (format.toLowerCase(Locale.ENGLISH).equals(".json")) { - textToSave = convertObjToString(docList); - } else { - throw RESTErrorUtil.createRESTException( - "unsoported format either should be json or text", - MessageEnums.ERROR_SYSTEM); - } - return FileUtil.saveToFile(textToSave, fileName, vsummary); - - } catch (SolrException | SolrServerException | IOException - | ParseException e) { - logger.error("Error during solrQuery=" + solrQuery, e); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - } - - public String getComponentListWithLevelCounts(SearchCriteria searchCriteria) { - SolrQuery solrQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - solrQuery.setParam("event", "/service/logs/components/level/counts"); - - if (searchCriteria.getSortBy() == null) { - searchCriteria.setSortBy(LogSearchConstants.SOLR_COMPONENT); - searchCriteria.setSortType(SolrQuery.ORDER.asc.toString()); - } - queryGenerator.setFilterFacetSort(solrQuery, searchCriteria); - String componentLevelHirachy = "type,level"; - VNodeList list = new VNodeList(); - try { - - SolrUtil.setFacetPivot(solrQuery, 1, componentLevelHirachy); - - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - - List> listPivotField = new ArrayList>(); - NamedList> namedList = response.getFacetPivot(); - if (namedList != null) { - listPivotField = namedList.getAll(componentLevelHirachy); - } - List secondHirarchicalPivotFields = null; - if (listPivotField == null || listPivotField.isEmpty()) { - return convertObjToString(list); - } else { - secondHirarchicalPivotFields = listPivotField.get(0); - } - List datatList = new ArrayList(); - for (PivotField singlePivotField : secondHirarchicalPivotFields) { - if (singlePivotField != null) { - VNode comp = new VNode(); - comp.setName("" + singlePivotField.getValue()); - List levelList = singlePivotField.getPivot(); - List levelCountList = new ArrayList(); - comp.setLogLevelCount(levelCountList); - if(levelList != null){ - for (PivotField levelPivot : levelList) { - VNameValue level = new VNameValue(); - level.setName(("" + levelPivot.getValue()).toUpperCase()); - level.setValue("" + levelPivot.getCount()); - levelCountList.add(level); - } - } - datatList.add(comp); - } - } - list.setvNodeList(datatList); - return convertObjToString(list); - } catch (SolrException | SolrServerException | IOException e) { - logger.error(e.getMessage() + "SolrQuery"+solrQuery); - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - } - - public String getExtremeDatesForBundelId(SearchCriteria searchCriteria) { - SolrQuery solrQuery = new SolrQuery(); - VNameValueList nameValueList = new VNameValueList(); - try { - String bundelId = (String) searchCriteria - .getParamValue(LogSearchConstants.BUNDLE_ID); - if(StringUtils.isBlank(bundelId)){ - bundelId = ""; - } - - queryGenerator.setSingleIncludeFilter(solrQuery, - LogSearchConstants.BUNDLE_ID, bundelId); - - SolrUtil.setMainQuery(solrQuery, null); - solrQuery.setSort(LogSearchConstants.LOGTIME, SolrQuery.ORDER.asc); - SolrUtil.setRowCount(solrQuery, 1); - - List vNameValues = new ArrayList(); - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - - if(response == null){ - return convertObjToString(nameValueList); - } - - SolrDocumentList solrDocList = response.getResults(); - if(solrDocList == null){ - return convertObjToString(nameValueList); - } - for (SolrDocument solrDoc : solrDocList) { - - Date logTimeAsc = (Date) solrDoc - .getFieldValue(LogSearchConstants.LOGTIME); - if (logTimeAsc != null) { - VNameValue nameValue = new VNameValue(); - nameValue.setName("From"); - nameValue.setValue("" + logTimeAsc.getTime()); - vNameValues.add(nameValue); - } - } - - solrQuery.clear(); - SolrUtil.setMainQuery(solrQuery, null); - queryGenerator.setSingleIncludeFilter(solrQuery, - LogSearchConstants.BUNDLE_ID, bundelId); - solrQuery.setSort(LogSearchConstants.LOGTIME, SolrQuery.ORDER.desc); - SolrUtil.setRowCount(solrQuery, 1); - - solrDocList.clear(); - response = serviceLogsSolrDao.process(solrQuery); - - solrDocList = response.getResults(); - for (SolrDocument solrDoc : solrDocList) { - if (solrDoc != null) { - Date logTimeDesc = (Date) solrDoc - .getFieldValue(LogSearchConstants.LOGTIME); - - if (logTimeDesc != null) { - VNameValue nameValue = new VNameValue(); - nameValue.setName("To"); - nameValue.setValue("" + logTimeDesc.getTime()); - vNameValues.add(nameValue); - } - } - } - nameValueList.setVNameValues(vNameValues); - - - } catch (SolrServerException | SolrException | IOException e) { - logger.error(e.getMessage() + "SolrQuery"+solrQuery); - nameValueList=new VNameValueList(); - } - return convertObjToString(nameValueList); - } - - protected VGroupList getSolrGroupList(SolrQuery query) - throws SolrServerException, IOException, SolrException { - VGroupList collection = new VGroupList(); - QueryResponse response = serviceLogsSolrDao.process(query); - if (response == null) { - return collection; - } - SolrDocumentList docList = response.getResults(); - if (docList != null) { - collection.setGroupDocuments(docList); - collection.setStartIndex((int) docList.getStart()); - collection.setTotalCount(docList.getNumFound()); - } - - return collection; - } - - public String getServiceLogsFieldsName() { - String fieldsNameStrArry[] = PropertiesHelper - .getPropertyStringList("logsearch.service.logs.fields"); - if (fieldsNameStrArry.length > 0) { - - List uiFieldNames = new ArrayList(); - String temp = null; - for (String field : fieldsNameStrArry) { - temp = ConfigHelper.serviceLogsColumnMapping.get(field - + LogSearchConstants.SOLR_SUFFIX); - if (temp == null){ - uiFieldNames.add(field); - }else{ - uiFieldNames.add(temp); - } - } - return convertObjToString(uiFieldNames); - - } - throw RESTErrorUtil.createRESTException( - "No field name found in property file", - MessageEnums.DATA_NOT_FOUND); - - } - - public String getServiceLogsSchemaFieldsName() { - - List fieldNames = new ArrayList(); - String excludeArray[] = PropertiesHelper - .getPropertyStringList("logsearch.solr.service.logs.exclude.columnlist"); - - HashMap uiFieldColumnMapping = new LinkedHashMap(); - ConfigHelper.getSchemaFieldsName(excludeArray, fieldNames,serviceLogsSolrDao); - - for (String fieldName : fieldNames) { - String uiField = ConfigHelper.serviceLogsColumnMapping.get(fieldName - + LogSearchConstants.SOLR_SUFFIX); - if (uiField != null) { - uiFieldColumnMapping.put(fieldName, uiField); - } else { - uiFieldColumnMapping.put(fieldName, fieldName); - } - } - - HashMap uiFieldColumnMappingSorted = new LinkedHashMap(); - uiFieldColumnMappingSorted.put(LogSearchConstants.SOLR_LOG_MESSAGE, LogSearchConstants.SOLR_LOG_MESSAGE); - - Iterator> it = BizUtil - .sortHashMapByValues(uiFieldColumnMapping).entrySet().iterator(); - while (it.hasNext()) { - @SuppressWarnings("rawtypes") - Map.Entry pair = (Map.Entry) it.next(); - uiFieldColumnMappingSorted.put("" + pair.getKey(), "" + pair.getValue()); - } - - return convertObjToString(uiFieldColumnMappingSorted); - - } - - @SuppressWarnings("unchecked") - public void extractValuesFromBuckets( - SimpleOrderedMap jsonFacetResponse, String outerField, - String innerField, List histogramData) { - NamedList stack = (NamedList) jsonFacetResponse - .get(outerField); - ArrayList stackBuckets = (ArrayList) stack - .get("buckets"); - for (Object temp : stackBuckets) { - VBarGraphData vBarGraphData = new VBarGraphData(); - - SimpleOrderedMap level = (SimpleOrderedMap) temp; - String name = ((String) level.getVal(0)).toUpperCase(); - vBarGraphData.setName(name); - - Collection vNameValues = new ArrayList(); - vBarGraphData.setDataCounts(vNameValues); - ArrayList levelBuckets = (ArrayList) ((NamedList) level - .get(innerField)).get("buckets"); - for (Object temp1 : levelBuckets) { - SimpleOrderedMap countValue = (SimpleOrderedMap) temp1; - String value = DateUtil - .convertDateWithMillisecondsToSolrDate((Date) countValue - .getVal(0)); - - String count = "" + countValue.getVal(1); - VNameValue vNameValue = new VNameValue(); - vNameValue.setName(value); - vNameValue.setValue(count); - vNameValues.add(vNameValue); - } - histogramData.add(vBarGraphData); - } - } - - public String getAnyGraphData(SearchCriteria searchCriteria) { - searchCriteria.addParam("fieldTime", LogSearchConstants.LOGTIME); - SolrQuery solrQuery = queryGenerator.commonServiceFilterQuery(searchCriteria); - VBarDataList result = graphDataGenerator.getAnyGraphData(searchCriteria, - serviceLogsSolrDao, solrQuery); - if (result == null) { - result = new VBarDataList(); - } - return convertObjToString(result); - - } - - public String getAfterBeforeLogs(SearchCriteria searchCriteria) { - VSolrLogList vSolrLogList = new VSolrLogList(); - SolrDocumentList docList = null; - String id = (String) searchCriteria - .getParamValue(LogSearchConstants.ID); - if (StringUtils.isBlank(id)) { - return convertObjToString(vSolrLogList); - - } - String maxRows = ""; - - maxRows = (String) searchCriteria.getParamValue("numberRows"); - if (StringUtils.isBlank(maxRows)){ - maxRows = ""+maxRows; - } - String scrollType = (String) searchCriteria.getParamValue("scrollType"); - if(StringUtils.isBlank(scrollType)){ - scrollType = ""; - } - - String logTime = null; - String sequenceId = null; - try { - SolrQuery solrQuery = new SolrQuery(); - SolrUtil.setMainQuery(solrQuery, - queryGenerator.buildFilterQuery(LogSearchConstants.ID, id)); - SolrUtil.setRowCount(solrQuery, 1); - QueryResponse response = serviceLogsSolrDao.process(solrQuery); - if(response == null){ - return convertObjToString(vSolrLogList); - } - docList = response.getResults(); - if (docList != null && !docList.isEmpty()) { - Date date = (Date) docList.get(0).getFieldValue( - LogSearchConstants.LOGTIME); - logTime = DateUtil.convertDateWithMillisecondsToSolrDate(date); - sequenceId = "" - + docList.get(0).getFieldValue( - LogSearchConstants.SEQUNCE_ID); - } - if (StringUtils.isBlank(logTime)) { - return convertObjToString(vSolrLogList); - } - } catch (SolrServerException | SolrException | IOException e) { - throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR - .getMessage().getMessage(), MessageEnums.ERROR_SYSTEM); - } - if (LogSearchConstants.SCROLL_TYPE_BEFORE.equals(scrollType)) { - vSolrLogList = whenScrollUp(searchCriteria, logTime, - sequenceId, maxRows); - - SolrDocumentList solrDocList = new SolrDocumentList(); - for (SolrDocument solrDoc : vSolrLogList.getList()) { - solrDocList.add(solrDoc); - } - vSolrLogList.setSolrDocuments(solrDocList); - return convertObjToString(vSolrLogList); - - } else if (LogSearchConstants.SCROLL_TYPE_AFTER.equals(scrollType)) { - SolrDocumentList solrDocList = new SolrDocumentList(); - vSolrLogList = new VSolrLogList(); - for (SolrDocument solrDoc : whenScrollDown(searchCriteria, logTime, - sequenceId, maxRows).getList()) { - solrDocList.add(solrDoc); - } - vSolrLogList.setSolrDocuments(solrDocList); - return convertObjToString(vSolrLogList); - - } else { - vSolrLogList = new VSolrLogList(); - SolrDocumentList initial = new SolrDocumentList(); - SolrDocumentList before = whenScrollUp(searchCriteria, logTime, - sequenceId, maxRows).getList(); - SolrDocumentList after = whenScrollDown(searchCriteria, logTime, - sequenceId, maxRows).getList(); - if (before != null && !before.isEmpty()) { - for (SolrDocument solrDoc : Lists.reverse(before)) { - initial.add(solrDoc); - } - } - - initial.add(docList.get(0)); - if (after != null && !after.isEmpty()){ - for (SolrDocument solrDoc : after) { - initial.add(solrDoc); - } - } - - vSolrLogList.setSolrDocuments(initial); - - return convertObjToString(vSolrLogList); - - } - } - - private VSolrLogList whenScrollUp(SearchCriteria searchCriteria, - String logTime, String sequenceId, String maxRows) { - SolrQuery solrQuery = new SolrQuery(); - SolrUtil.setMainQuery(solrQuery, null); - /*queryGenerator.setSingleExcludeFilter(solrQuery, - LogSearchConstants.SEQUNCE_ID, sequenceId);*/ - try { - int seq_num = Integer.parseInt(sequenceId) - 1; - sequenceId = "" + seq_num; - } catch (Exception e) { - - } - queryGenerator.setSingleRangeFilter( - solrQuery, - LogSearchConstants.SEQUNCE_ID, "*", sequenceId); - - queryGenerator.applyLogFileFilter(solrQuery, searchCriteria); - - queryGenerator.setSingleRangeFilter(solrQuery, - LogSearchConstants.LOGTIME, "*", logTime); - SolrUtil.setRowCount(solrQuery, Integer.parseInt(maxRows)); - String order1 = LogSearchConstants.LOGTIME + " " - + LogSearchConstants.DESCENDING_ORDER; - String order2 = LogSearchConstants.SEQUNCE_ID + " " - + LogSearchConstants.DESCENDING_ORDER; - List sortOrder = new ArrayList(); - sortOrder.add(order1); - sortOrder.add(order2); - searchCriteria.addParam(LogSearchConstants.SORT, sortOrder); - queryGenerator.setMultipleSortOrder(solrQuery, searchCriteria); - - return getLogAsPaginationProvided(solrQuery, serviceLogsSolrDao); - } - - private VSolrLogList whenScrollDown(SearchCriteria searchCriteria, - String logTime, String sequenceId, String maxRows) { - SolrQuery solrQuery = new SolrQuery(); - SolrUtil.setMainQuery(solrQuery, null); - queryGenerator.applyLogFileFilter(solrQuery, searchCriteria); - - /*queryGenerator.setSingleExcludeFilter(solrQuery, - LogSearchConstants.SEQUNCE_ID, sequenceId);*/ - try { - int seq_num = Integer.parseInt(sequenceId) + 1; - sequenceId = "" + seq_num; - } catch (Exception e) { - - } - queryGenerator.setSingleRangeFilter( - solrQuery, - LogSearchConstants.SEQUNCE_ID, sequenceId, "*"); - queryGenerator.setSingleRangeFilter(solrQuery, - LogSearchConstants.LOGTIME, logTime, "*"); - SolrUtil.setRowCount(solrQuery, Integer.parseInt(maxRows)); - - String order1 = LogSearchConstants.LOGTIME + " " - + LogSearchConstants.ASCENDING_ORDER; - String order2 = LogSearchConstants.SEQUNCE_ID + " " - + LogSearchConstants.ASCENDING_ORDER; - List sortOrder = new ArrayList(); - sortOrder.add(order1); - sortOrder.add(order2); - searchCriteria.addParam(LogSearchConstants.SORT, sortOrder); - queryGenerator.setMultipleSortOrder(solrQuery, searchCriteria); - - return getLogAsPaginationProvided(solrQuery, serviceLogsSolrDao); - } - - @Scheduled(cron = "${logsearch.solr.warming.cron}") - public void warmingSolrServer(){ - logger.info("solr warming triggered."); - SolrQuery solrQuery = new SolrQuery(); - TimeZone gmtTimeZone = TimeZone.getTimeZone("GMT"); - GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); - utc.setTimeInMillis(new Date().getTime()); - utc.set(Calendar.HOUR, 0); - utc.set(Calendar.MINUTE, 0); - utc.set(Calendar.MILLISECOND, 001); - utc.set(Calendar.SECOND, 0); - DateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime()); - String from = DateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime()); - utc.set(Calendar.MILLISECOND, 999); - utc.set(Calendar.SECOND, 59); - utc.set(Calendar.MINUTE, 59); - utc.set(Calendar.HOUR, 23); - String to = DateUtil.convertDateWithMillisecondsToSolrDate(utc.getTime()); - queryGenerator.setSingleRangeFilter(solrQuery, - LogSearchConstants.LOGTIME, from,to); - String level = LogSearchConstants.FATAL+","+LogSearchConstants.ERROR+","+LogSearchConstants.WARN; - queryGenerator.setFilterClauseWithFieldName(solrQuery, level, - LogSearchConstants.SOLR_LEVEL, "", QueryGenerationBase.Condition.OR); - try { - serviceLogsSolrDao.process(solrQuery); - } catch (SolrServerException | IOException e) { - logger.error("Error while warming solr server",e); - } - } - - -}