|
@@ -19,324 +19,405 @@
|
|
|
|
|
|
package org.apache.ambari.logsearch.graph;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
-import org.apache.ambari.logsearch.common.LogSearchConstants;
|
|
|
-import org.apache.ambari.logsearch.common.MessageEnums;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
import org.apache.ambari.logsearch.model.response.BarGraphData;
|
|
|
import org.apache.ambari.logsearch.model.response.BarGraphDataListResponse;
|
|
|
+import org.apache.ambari.logsearch.model.response.CountData;
|
|
|
+import org.apache.ambari.logsearch.model.response.CountDataListResponse;
|
|
|
+import org.apache.ambari.logsearch.model.response.GraphData;
|
|
|
+import org.apache.ambari.logsearch.model.response.GraphDataListResponse;
|
|
|
import org.apache.ambari.logsearch.model.response.NameValueData;
|
|
|
-import org.apache.ambari.logsearch.query.model.SearchCriteria;
|
|
|
-import org.apache.ambari.logsearch.dao.SolrDaoBase;
|
|
|
-import org.apache.ambari.logsearch.query.QueryGeneration;
|
|
|
-import org.apache.ambari.logsearch.util.RESTErrorUtil;
|
|
|
-import org.apache.ambari.logsearch.util.SolrUtil;
|
|
|
+import org.apache.ambari.logsearch.model.response.NameValueDataListResponse;
|
|
|
+import org.apache.ambari.logsearch.model.response.NodeData;
|
|
|
+import org.apache.ambari.logsearch.model.response.NodeListResponse;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
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.PivotField;
|
|
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
|
|
import org.apache.solr.client.solrj.response.RangeFacet;
|
|
|
-import org.apache.solr.common.SolrException;
|
|
|
-import org.apache.solr.common.util.SimpleOrderedMap;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
+import org.apache.solr.common.util.NamedList;
|
|
|
|
|
|
-import javax.inject.Inject;
|
|
|
+import javax.inject.Named;
|
|
|
|
|
|
-@Component
|
|
|
-public class GraphDataGenerator extends GraphDataGeneratorBase {
|
|
|
+@Named
|
|
|
+public class GraphDataGenerator {
|
|
|
|
|
|
- private static final Logger logger = Logger.getLogger(GraphDataGenerator.class);
|
|
|
+ public BarGraphDataListResponse generateBarGraphDataResponseWithRanges(QueryResponse response, String typeField, boolean typeUppercase) {
|
|
|
+ BarGraphDataListResponse dataList = new BarGraphDataListResponse();
|
|
|
+ if (response == null) {
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
+ NamedList<List<PivotField>> facetPivotResponse = response.getFacetPivot();
|
|
|
+ if (response.getFacetPivot() == null) {
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
+ List<PivotField> pivotFields = facetPivotResponse.get(typeField);
|
|
|
+ for (int pivotIndex = 0; pivotIndex < pivotFields.size(); pivotIndex++) {
|
|
|
+ PivotField pivotField = facetPivotResponse.get(typeField).get(pivotIndex);
|
|
|
+ List<NameValueData> nameValues = generateNameValueDataList(pivotField.getFacetRanges());
|
|
|
+ BarGraphData barGraphData = new BarGraphData();
|
|
|
+ barGraphData.setDataCount(nameValues);
|
|
|
+ String typeValue = typeUppercase ? StringUtils.upperCase(pivotField.getValue().toString()) : pivotField.getValue().toString();
|
|
|
+ barGraphData.setName(typeValue);
|
|
|
+ dataList.getGraphData().add(barGraphData);
|
|
|
+ }
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
|
|
|
- @Inject
|
|
|
- private QueryGeneration queryGenerator;
|
|
|
+ public BarGraphDataListResponse generateSecondLevelBarGraphDataResponse(QueryResponse response, int val) {
|
|
|
+ BarGraphDataListResponse barGraphDataListResponse = new BarGraphDataListResponse();
|
|
|
+ NamedList<List<PivotField>> pivotFieldNameList = response.getFacetPivot();
|
|
|
+ if (pivotFieldNameList == null) {
|
|
|
+ return barGraphDataListResponse;
|
|
|
+ }
|
|
|
+ List<PivotField> pivotFields = pivotFieldNameList.getVal(val);
|
|
|
+ List<BarGraphData> barGraphDataList = new ArrayList<>();
|
|
|
+ for (PivotField pivotField : pivotFields) {
|
|
|
+ BarGraphData barGraphData = new BarGraphData();
|
|
|
+ barGraphData.setName(String.valueOf(pivotField.getValue()));
|
|
|
+ List<PivotField> secondLevelPivotFields = pivotField.getPivot();
|
|
|
+ List<NameValueData> nameValueDataList = new ArrayList<>();
|
|
|
+ for (PivotField sPivotField : secondLevelPivotFields) {
|
|
|
+ NameValueData nvD = new NameValueData();
|
|
|
+ nvD.setName(String.valueOf(sPivotField.getValue()));
|
|
|
+ nvD.setValue(String.valueOf(sPivotField.getCount()));
|
|
|
+ nameValueDataList.add(nvD);
|
|
|
+ }
|
|
|
+ barGraphData.setDataCount(nameValueDataList);
|
|
|
+ barGraphDataList.add(barGraphData);
|
|
|
+ }
|
|
|
+ barGraphDataListResponse.setGraphData(barGraphDataList);
|
|
|
+ return barGraphDataListResponse;
|
|
|
+ }
|
|
|
|
|
|
- public BarGraphDataListResponse getAnyGraphData(SearchCriteria searchCriteria, SolrDaoBase solrDaoBase, SolrQuery solrQuery) {
|
|
|
- // X axis credentials
|
|
|
- String xAxisField = (String) searchCriteria.getParamValue("xAxis");
|
|
|
- String stackField = (String) searchCriteria.getParamValue("stackBy");
|
|
|
- String from = (String) searchCriteria.getParamValue("from");
|
|
|
- String to = (String) searchCriteria.getParamValue("to");
|
|
|
- String unit = (String) searchCriteria.getParamValue("unit");
|
|
|
- String typeXAxis = solrDaoBase.schemaFieldNameMap.get(xAxisField);
|
|
|
- typeXAxis = (StringUtils.isBlank(typeXAxis)) ? "string" : typeXAxis;
|
|
|
+ public BarGraphDataListResponse generateBarGraphFromFieldFacet(QueryResponse response, String facetField) {
|
|
|
+ BarGraphDataListResponse dataList = new BarGraphDataListResponse();
|
|
|
+ Collection<BarGraphData> vaDatas = new ArrayList<>();
|
|
|
+ dataList.setGraphData(vaDatas);
|
|
|
+ if (response == null) {
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
+ FacetField facetFieldObj = response.getFacetField(facetField);
|
|
|
+ if (facetFieldObj == null) {
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Count> counts = facetFieldObj.getValues();
|
|
|
+ if (counts == null) {
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
+ for (Count cnt : counts) {
|
|
|
+ List<NameValueData> valueList = new ArrayList<>();
|
|
|
+ BarGraphData vBarGraphData = new BarGraphData();
|
|
|
+ vaDatas.add(vBarGraphData);
|
|
|
+ NameValueData vNameValue = new NameValueData();
|
|
|
+ vNameValue.setName(cnt.getName());
|
|
|
+ vBarGraphData.setName(cnt.getName().toUpperCase());
|
|
|
+ vNameValue.setValue("" + cnt.getCount());
|
|
|
+ valueList.add(vNameValue);
|
|
|
+ vBarGraphData.setDataCount(valueList);
|
|
|
+ }
|
|
|
+ return dataList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<NameValueData> generateNameValueDataList(List<RangeFacet> rangeFacet) {
|
|
|
+ List<NameValueData> nameValues = new ArrayList<>();
|
|
|
+ if (rangeFacet == null) {
|
|
|
+ return nameValues;
|
|
|
+ }
|
|
|
+ RangeFacet range = rangeFacet.get(0);
|
|
|
|
|
|
- // Y axis credentials
|
|
|
- String yAxisField = (String) searchCriteria.getParamValue("yAxis");
|
|
|
- // add updated typeXAxis as a type parameter
|
|
|
- searchCriteria.addParam("type", typeXAxis);
|
|
|
- String fieldTime = (String) searchCriteria.getParamValue("fieldTime");
|
|
|
- // decide graph type based on user request parameter
|
|
|
- GraphType garphType = getGraphType(searchCriteria);
|
|
|
- switch (garphType) {
|
|
|
- case NORMAL_GRAPH:
|
|
|
- return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase, typeXAxis, fieldTime, solrQuery);
|
|
|
- case RANGE_NON_STACK_GRAPH:
|
|
|
- return rangeNonStackGraph(xAxisField, yAxisField, from, to, unit, solrDaoBase, typeXAxis, fieldTime, solrQuery);
|
|
|
- case NON_RANGE_STACK_GRAPH:
|
|
|
- return nonRangeStackGraph(xAxisField, yAxisField, stackField, from, to, solrDaoBase, typeXAxis, fieldTime, solrQuery);
|
|
|
- case RANGE_STACK_GRAPH:
|
|
|
- return rangeStackGraph(xAxisField, stackField, from, to, unit, solrDaoBase, solrQuery);
|
|
|
- default:
|
|
|
- logger.warn("Invalid graph type :" + garphType.name());
|
|
|
- return null;
|
|
|
+ if (range == null) {
|
|
|
+ return nameValues;
|
|
|
+ }
|
|
|
+ List<RangeFacet.Count> listCount = range.getCounts();
|
|
|
+ for (RangeFacet.Count cnt : listCount) {
|
|
|
+ NameValueData nameValue = new NameValueData();
|
|
|
+ nameValue.setName(String.valueOf(cnt.getValue()));
|
|
|
+ nameValue.setValue(String.valueOf(cnt.getCount()));
|
|
|
+ nameValues.add(nameValue);
|
|
|
}
|
|
|
+ return nameValues;
|
|
|
}
|
|
|
|
|
|
- private GraphType getGraphType(SearchCriteria searchCriteria) {
|
|
|
- // default graph type is unknown
|
|
|
- GraphType graphType = GraphType.UNKNOWN;
|
|
|
- // X axis credentials
|
|
|
- String xAxisField = (String) searchCriteria.getParamValue("xAxis");
|
|
|
- String stackField = (String) searchCriteria.getParamValue("stackBy");
|
|
|
- String from = (String) searchCriteria.getParamValue("from");
|
|
|
- String to = (String) searchCriteria.getParamValue("to");
|
|
|
- String xType = (String) searchCriteria.getParamValue("type");
|
|
|
- if (xType != null) {
|
|
|
- // Y axis credentials
|
|
|
- String yAxisField = (String) searchCriteria.getParamValue("yAxis");
|
|
|
- if (StringUtils.isBlank(xAxisField) || StringUtils.isBlank(yAxisField)) {
|
|
|
- graphType = GraphType.UNKNOWN;
|
|
|
- } else if (StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(from)
|
|
|
- && !(xType.contains("date") || xType.contains("time"))) {
|
|
|
- graphType = GraphType.NORMAL_GRAPH;
|
|
|
- } else if (StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(from)
|
|
|
- && (xType.contains("date") || xType.contains("time"))) {
|
|
|
- graphType = GraphType.RANGE_NON_STACK_GRAPH;
|
|
|
- } else if (!StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(from)
|
|
|
- && !(xType.contains("date") || xType.contains("time"))) {
|
|
|
- graphType = GraphType.NON_RANGE_STACK_GRAPH;
|
|
|
- } else if (!StringUtils.isBlank(stackField) && !StringUtils.isBlank(to) && !StringUtils.isBlank(from)
|
|
|
- && (xType.contains("date") || xType.contains("time"))) {
|
|
|
- graphType = GraphType.RANGE_STACK_GRAPH;
|
|
|
+ public List<Count> generateCount(QueryResponse response) {
|
|
|
+ List<Count> counts = new ArrayList<>();
|
|
|
+ List<FacetField> facetFields = null;
|
|
|
+ FacetField facetField = null;
|
|
|
+ if (response == null) {
|
|
|
+ return counts;
|
|
|
+ }
|
|
|
+
|
|
|
+ facetFields = response.getFacetFields();
|
|
|
+ if (facetFields == null) {
|
|
|
+ return counts;
|
|
|
+ }
|
|
|
+ if (!facetFields.isEmpty()) {
|
|
|
+ facetField = facetFields.get(0);
|
|
|
+ }
|
|
|
+ if (facetField != null) {
|
|
|
+ counts = facetField.getValues();
|
|
|
+ }
|
|
|
+ return counts;
|
|
|
+ }
|
|
|
+
|
|
|
+ public BarGraphDataListResponse getGraphDataWithDefaults(QueryResponse queryResponse, String field, String[] defaults) {
|
|
|
+ BarGraphDataListResponse response = new BarGraphDataListResponse();
|
|
|
+ BarGraphData barGraphData = new BarGraphData();
|
|
|
+ List<NameValueData> nameValues = generateLevelCountData(queryResponse, defaults);
|
|
|
+ barGraphData.setName(field);
|
|
|
+ barGraphData.setDataCount(nameValues);
|
|
|
+ response.setGraphData(Lists.newArrayList(barGraphData));
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ public NameValueDataListResponse getNameValueDataListResponseWithDefaults(QueryResponse response, String[] defaults) {
|
|
|
+ NameValueDataListResponse result = new NameValueDataListResponse();
|
|
|
+ result.setvNameValues(generateLevelCountData(response, defaults));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public NodeListResponse generateServiceNodeTreeFromFacetResponse(QueryResponse queryResponse,
|
|
|
+ String firstHierarchy, String secondHierarchy,
|
|
|
+ String firstType, String secondType) {
|
|
|
+ NodeListResponse response = new NodeListResponse();
|
|
|
+ if (queryResponse == null) {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ NamedList<List<PivotField>> namedPivotFieldList = queryResponse.getFacetPivot();
|
|
|
+ List<PivotField> firstLevelPivots = namedPivotFieldList.get(firstHierarchy);
|
|
|
+ List<PivotField> secondLevelPivots = namedPivotFieldList.get(secondHierarchy);
|
|
|
+ if (!CollectionUtils.isNotEmpty(firstLevelPivots) || !CollectionUtils.isNotEmpty(secondLevelPivots)) {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ List<NodeData> nodeDataList = buidTreeData(firstLevelPivots, secondLevelPivots, firstType, secondType);
|
|
|
+ response.setvNodeList(nodeDataList);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ public NodeListResponse generateOneLevelServiceNodeTree(QueryResponse queryResponse, String componentLevelHirachy) {
|
|
|
+ NodeListResponse response = new NodeListResponse();
|
|
|
+ List<NodeData> datatList = new ArrayList<>();
|
|
|
+ List<List<PivotField>> listPivotField = new ArrayList<>();
|
|
|
+ NamedList<List<PivotField>> namedList = queryResponse.getFacetPivot();
|
|
|
+ if (namedList != null) {
|
|
|
+ listPivotField = namedList.getAll(componentLevelHirachy);
|
|
|
+ }
|
|
|
+ List<PivotField> secondHirarchicalPivotFields = null;
|
|
|
+ if (listPivotField == null || listPivotField.isEmpty()) {
|
|
|
+ return response;
|
|
|
+ } else {
|
|
|
+ secondHirarchicalPivotFields = listPivotField.get(0);
|
|
|
+ }
|
|
|
+ for (PivotField singlePivotField : secondHirarchicalPivotFields) {
|
|
|
+ if (singlePivotField != null) {
|
|
|
+ NodeData comp = new NodeData();
|
|
|
+ comp.setName("" + singlePivotField.getValue());
|
|
|
+ List<PivotField> levelList = singlePivotField.getPivot();
|
|
|
+ List<NameValueData> levelCountList = new ArrayList<>();
|
|
|
+ comp.setLogLevelCount(levelCountList);
|
|
|
+ if (levelList != null) {
|
|
|
+ for (PivotField levelPivot : levelList) {
|
|
|
+ NameValueData level = new NameValueData();
|
|
|
+ level.setName(("" + levelPivot.getValue()).toUpperCase());
|
|
|
+ level.setValue("" + levelPivot.getCount());
|
|
|
+ levelCountList.add(level);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ datatList.add(comp);
|
|
|
}
|
|
|
}
|
|
|
- return graphType;
|
|
|
+ response.setvNodeList(datatList);
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private BarGraphDataListResponse normalGraph(String xAxisField, String yAxisField, String from, String to, SolrDaoBase solrDaoBase,
|
|
|
- String typeXAxis, String fieldTime, SolrQuery solrQuery) {
|
|
|
- BarGraphDataListResponse dataList = new BarGraphDataListResponse();
|
|
|
- Collection<BarGraphData> vBarGraphDatas = new ArrayList<BarGraphData>();
|
|
|
- BarGraphData vBarGraphData = new BarGraphData();
|
|
|
- Collection<NameValueData> vNameValues = new ArrayList<NameValueData>();
|
|
|
- SolrUtil.setMainQuery(solrQuery, null);
|
|
|
- queryGenerator.setSingleIncludeFilter(solrQuery, fieldTime, "[" + from + " TO " + to + "]");
|
|
|
- if (typeXAxis.contains("string") || typeXAxis.contains("key_lower_case") || typeXAxis.contains("text")) {
|
|
|
- SolrUtil.setFacetField(solrQuery, xAxisField);
|
|
|
- try {
|
|
|
- QueryResponse response = solrDaoBase.process(solrQuery);
|
|
|
- if (response != null && response.getResults() != null) {
|
|
|
- long count = response.getResults().getNumFound();
|
|
|
- if (count > 0) {
|
|
|
- FacetField facetField = response.getFacetField(xAxisField);
|
|
|
- if (facetField != null) {
|
|
|
- List<Count> countValues = facetField.getValues();
|
|
|
- if (countValues != null) {
|
|
|
- for (Count countValue : countValues) {
|
|
|
- if (countValue != null) {
|
|
|
- NameValueData vNameValue = new NameValueData();
|
|
|
- vNameValue.setName(countValue.getName());
|
|
|
- vNameValue.setValue("" + countValue.getCount());
|
|
|
- vNameValues.add(vNameValue);
|
|
|
- }
|
|
|
- }
|
|
|
+ private List<NodeData> buidTreeData(List<PivotField> firstHirarchicalPivotFields,
|
|
|
+ List<PivotField> secondHirarchicalPivotFields,
|
|
|
+ String firstPriority, String secondPriority) {
|
|
|
+ List<NodeData> extensionTree = new ArrayList<>();
|
|
|
+ if (firstHirarchicalPivotFields != null) {
|
|
|
+ for (PivotField pivotHost : firstHirarchicalPivotFields) {
|
|
|
+ if (pivotHost != null) {
|
|
|
+ NodeData hostNode = new NodeData();
|
|
|
+ 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 : secondHirarchicalPivotFields) {
|
|
|
+ if (!StringUtils.isBlank(hostNode.getName())
|
|
|
+ && hostNode.getName().equals(searchHost.getValue())) {
|
|
|
+ hostPivot = searchHost;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PivotField> pivotLevelHost = hostPivot == null? null : hostPivot.getPivot();
|
|
|
+ if (pivotLevelHost != null) {
|
|
|
+ Collection<NameValueData> logLevelCount = new ArrayList<>();
|
|
|
+ for (PivotField pivotLevel : pivotLevelHost) {
|
|
|
+ if (pivotLevel != null) {
|
|
|
+ NameValueData vnameValue = new NameValueData();
|
|
|
+ String levelName = (pivotLevel.getValue() == null ? "" : "" + pivotLevel.getValue());
|
|
|
+ vnameValue.setName(levelName.toUpperCase());
|
|
|
+ vnameValue.setValue("" + pivotLevel.getCount());
|
|
|
+ logLevelCount.add(vnameValue);
|
|
|
}
|
|
|
- vBarGraphData.setName(xAxisField);
|
|
|
- vBarGraphDatas.add(vBarGraphData);
|
|
|
- dataList.setGraphData(vBarGraphDatas);
|
|
|
}
|
|
|
+ hostNode.setLogLevelCount(logLevelCount);
|
|
|
}
|
|
|
- }
|
|
|
- if (xAxisField.equalsIgnoreCase(LogSearchConstants.SOLR_LEVEL)) {
|
|
|
- Collection<NameValueData> sortedVNameValues = new ArrayList<NameValueData>();
|
|
|
- for (String level : LogSearchConstants.SUPPORTED_LOG_LEVEL) {
|
|
|
- NameValueData value = new NameValueData();
|
|
|
- value.setName(level);
|
|
|
- String val = "0";
|
|
|
- for (NameValueData valueLevel : vNameValues) {
|
|
|
- if (valueLevel.getName().equalsIgnoreCase(level)) {
|
|
|
- val = valueLevel.getValue();
|
|
|
- break;
|
|
|
+ List<PivotField> pivotComponents = pivotHost.getPivot();
|
|
|
+ if (pivotComponents != null) {
|
|
|
+ Collection<NodeData> componentNodes = new ArrayList<>();
|
|
|
+ for (PivotField pivotComp : pivotComponents) {
|
|
|
+ if (pivotComp != null) {
|
|
|
+ NodeData compNode = new NodeData();
|
|
|
+ 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<PivotField> pivotLevels = pivotComp.getPivot();
|
|
|
+ if (pivotLevels != null) {
|
|
|
+ Collection<NameValueData> logLevelCount = new ArrayList<>();
|
|
|
+ for (PivotField pivotLevel : pivotLevels) {
|
|
|
+ if (pivotLevel != null) {
|
|
|
+ NameValueData vnameValue = new NameValueData();
|
|
|
+ String compLevel = pivotLevel.getValue() == null ? "" : "" + pivotLevel.getValue();
|
|
|
+ vnameValue.setName((compLevel).toUpperCase());
|
|
|
+
|
|
|
+ vnameValue.setValue("" + pivotLevel.getCount());
|
|
|
+ logLevelCount.add(vnameValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ compNode.setLogLevelCount(logLevelCount);
|
|
|
+ }
|
|
|
+ componentNodes.add(compNode);
|
|
|
}
|
|
|
}
|
|
|
- value.setValue(val);
|
|
|
- sortedVNameValues.add(value);
|
|
|
+ hostNode.setChilds(componentNodes);
|
|
|
}
|
|
|
- vBarGraphData.setDataCount(sortedVNameValues);
|
|
|
- } else {
|
|
|
- vBarGraphData.setDataCount(vNameValues);
|
|
|
- }
|
|
|
- return dataList;
|
|
|
- } catch (SolrException | SolrServerException | IOException e) {
|
|
|
- String query = solrQuery != null ? solrQuery.toQueryString() : "";
|
|
|
- logger.error("Got exception for solr query :" + query, e.getCause());
|
|
|
- }
|
|
|
- } else {
|
|
|
- SolrUtil.setRowCount(solrQuery, 0);
|
|
|
- String yAxis = yAxisField.contains("count") ? "sum" : yAxisField;
|
|
|
- String jsonQuery = queryGenerator.buildJSONFacetAggregatedFuncitonQuery(yAxis, xAxisField);
|
|
|
- SolrUtil.setJSONFacet(solrQuery, jsonQuery);
|
|
|
- try {
|
|
|
- QueryResponse response = solrDaoBase.process(solrQuery);
|
|
|
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
|
|
|
- if (jsonFacetResponse.toString().equals("{count=0}")) {
|
|
|
- return dataList;
|
|
|
+ extensionTree.add(hostNode);
|
|
|
}
|
|
|
- NameValueData value = new NameValueData();
|
|
|
- String sum = (String) jsonFacetResponse.getVal(1);
|
|
|
- value.setName(xAxisField);
|
|
|
- value.setValue(sum != null ? sum.substring(0, sum.indexOf(".")) : "");
|
|
|
- vNameValues.add(value);
|
|
|
- vBarGraphData.setDataCount(vNameValues);
|
|
|
- vBarGraphData.setName(xAxisField);
|
|
|
- vBarGraphDatas.add(vBarGraphData);
|
|
|
- dataList.setGraphData(vBarGraphDatas);
|
|
|
- return dataList;
|
|
|
- } catch (SolrException | SolrServerException | IOException e) {
|
|
|
- String query = solrQuery != null ? solrQuery.toQueryString() : "";
|
|
|
- logger.error("Got exception for solr query :" + query, e.getCause());
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
+
|
|
|
+ return extensionTree;
|
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private BarGraphDataListResponse nonRangeStackGraph(String xAxisField, String yAxisField, String stackField, String from, String to,
|
|
|
- SolrDaoBase solrDaoBase, String typeXAxis, String fieldTime, SolrQuery solrQuery) {
|
|
|
- BarGraphDataListResponse dataList = new BarGraphDataListResponse();
|
|
|
- Collection<BarGraphData> vGraphData = new ArrayList<BarGraphData>();
|
|
|
- String mainQuery = queryGenerator.buildInclusiveRangeFilterQuery(fieldTime, from, to);
|
|
|
- SolrUtil.setMainQuery(solrQuery, mainQuery);
|
|
|
- SolrUtil.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
|
|
|
- String jsonQuery = "";
|
|
|
- if (SolrUtil.isSolrFieldNumber(typeXAxis,solrDaoBase)) {
|
|
|
- String function = (yAxisField.contains("count")) ? "sum" : yAxisField;
|
|
|
- jsonQuery = queryGenerator.buidlJSONFacetRangeQueryForNumber(stackField, xAxisField, function);
|
|
|
- } else {
|
|
|
- jsonQuery = queryGenerator.buildJsonFacetTermsRangeQuery(stackField, xAxisField);
|
|
|
- }
|
|
|
- try {
|
|
|
- SolrUtil.setJSONFacet(solrQuery, jsonQuery);
|
|
|
- dataList.setGraphData(vGraphData);
|
|
|
- QueryResponse response = solrDaoBase.process(solrQuery);
|
|
|
- if (response == null) {
|
|
|
- response = new QueryResponse();
|
|
|
- }
|
|
|
- Long count = response.getResults().getNumFound();
|
|
|
- if (count <= 0) {
|
|
|
- return dataList;
|
|
|
- }
|
|
|
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
|
|
|
- if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
|
|
|
- return dataList;
|
|
|
- }
|
|
|
- extractNonRangeStackValuesFromBucket(jsonFacetResponse, stackField, vGraphData, typeXAxis);
|
|
|
- if (LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(stackField) && LogSearchConstants.SOLR_LEVEL.equalsIgnoreCase(xAxisField)) {
|
|
|
- Collection<BarGraphData> levelVGraphData = dataList.getGraphData();
|
|
|
- for (BarGraphData graphData : levelVGraphData) {
|
|
|
- Collection<NameValueData> valueList = graphData.getDataCount();
|
|
|
- Collection<NameValueData> valueListSorted = new ArrayList<NameValueData>();
|
|
|
- for (String level : LogSearchConstants.SUPPORTED_LOG_LEVEL) {
|
|
|
- String val = "0";
|
|
|
- for (NameValueData value : valueList) {
|
|
|
- if (value.getName().equalsIgnoreCase(level)) {
|
|
|
- val = value.getValue();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- NameValueData v1 = new NameValueData();
|
|
|
- v1.setName(level.toUpperCase());
|
|
|
- v1.setValue(val);
|
|
|
- valueListSorted.add(v1);
|
|
|
- }
|
|
|
- graphData.setDataCount(valueListSorted);
|
|
|
- }
|
|
|
+ private List<NameValueData> generateLevelCountData(QueryResponse queryResponse, String[] defaults) {
|
|
|
+ List<NameValueData> nameValues = Lists.newLinkedList();
|
|
|
+ Map<String, NameValueData> linkedMap = Maps.newLinkedHashMap();
|
|
|
+ List<Count> counts = generateCount(queryResponse);
|
|
|
+ if (!CollectionUtils.isNotEmpty(counts)) {
|
|
|
+ return nameValues;
|
|
|
+ }
|
|
|
+ for (String defaultValue : defaults) {
|
|
|
+ NameValueData nameValue = new NameValueData();
|
|
|
+ nameValue.setName(defaultValue);
|
|
|
+ nameValue.setValue("0");
|
|
|
+ linkedMap.put(defaultValue, nameValue);
|
|
|
+ }
|
|
|
+ for (Count count : counts) {
|
|
|
+ if (!linkedMap.containsKey(count.getName())) {
|
|
|
+ NameValueData nameValue = new NameValueData();
|
|
|
+ String name = count.getName().toUpperCase();
|
|
|
+ nameValue.setName(name);
|
|
|
+ nameValue.setValue(String.valueOf(count.getCount()));
|
|
|
+ linkedMap.put(name, nameValue);
|
|
|
}
|
|
|
- return dataList;
|
|
|
- } catch (SolrException | IOException | SolrServerException e) {
|
|
|
- String query = solrQuery != null ? solrQuery.toQueryString() : "";
|
|
|
- logger.error("Got exception for solr query :" + query, e.getCause());
|
|
|
- throw RESTErrorUtil.createRESTException(MessageEnums.DATA_NOT_FOUND.getMessage().getMessage(), MessageEnums.DATA_NOT_FOUND);
|
|
|
}
|
|
|
+
|
|
|
+ for (Map.Entry<String, NameValueData> nameValueDataEntry : linkedMap.entrySet()) {
|
|
|
+ nameValues.add(nameValueDataEntry.getValue());
|
|
|
+ }
|
|
|
+ return nameValues;
|
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private BarGraphDataListResponse rangeNonStackGraph(String xAxisField, String yAxisField, String from, String to, String unit,
|
|
|
- SolrDaoBase solrDaoBase, String typeXAxis, String fieldTime, SolrQuery solrQuery) {
|
|
|
- BarGraphDataListResponse dataList = new BarGraphDataListResponse();
|
|
|
- Collection<BarGraphData> vBarGraphDatas = new ArrayList<BarGraphData>();
|
|
|
- BarGraphData vBarGraphData = new BarGraphData();
|
|
|
- Collection<NameValueData> vNameValues = new ArrayList<NameValueData>();
|
|
|
- SolrUtil.setMainQuery(solrQuery, null);
|
|
|
- if (SolrUtil.isSolrFieldNumber(typeXAxis,solrDaoBase)) {
|
|
|
- queryGenerator.setSingleRangeFilter(solrQuery, fieldTime, from, to);
|
|
|
- return normalGraph(xAxisField, yAxisField, from, to, solrDaoBase, typeXAxis, fieldTime, solrQuery);
|
|
|
- } else {
|
|
|
- try {
|
|
|
- SolrUtil.setFacetRange(solrQuery, xAxisField, from, to, unit);
|
|
|
- QueryResponse response = solrDaoBase.process(solrQuery);
|
|
|
- if (response != null) {
|
|
|
- Long count = response.getResults().getNumFound();
|
|
|
- if (count > 0) {
|
|
|
- @SuppressWarnings("rawtypes")
|
|
|
- List<RangeFacet> rangeFacet = response.getFacetRanges();
|
|
|
- if (rangeFacet != null && rangeFacet.size() > 0) {
|
|
|
- List<RangeFacet.Count> listCount = rangeFacet.get(0).getCounts();
|
|
|
- if (listCount != null) {
|
|
|
- for (RangeFacet.Count cnt : listCount) {
|
|
|
- NameValueData vNameValue = new NameValueData();
|
|
|
- vNameValue.setName(cnt.getValue());
|
|
|
- vNameValue.setValue("" + cnt.getCount());
|
|
|
- vNameValues.add(vNameValue);
|
|
|
- }
|
|
|
- vBarGraphData.setDataCount(vNameValues);
|
|
|
- vBarGraphDatas.add(vBarGraphData);
|
|
|
- vBarGraphData.setName(xAxisField);
|
|
|
- dataList.setGraphData(vBarGraphDatas);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return dataList;
|
|
|
- } catch (SolrException | SolrServerException | IOException e) {
|
|
|
- logger.error("Got exception for solr query :" + solrQuery, e.getCause());
|
|
|
+ public CountDataListResponse generateCountResponseByField(QueryResponse response, String field) {
|
|
|
+ CountDataListResponse collection = new CountDataListResponse();
|
|
|
+ List<CountData> vCounts = new ArrayList<>();
|
|
|
+ if (response == null) {
|
|
|
+ return collection;
|
|
|
+ }
|
|
|
+ FacetField facetFields = response.getFacetField(field);
|
|
|
+ if (facetFields == null) {
|
|
|
+ return collection;
|
|
|
+ }
|
|
|
+ List<Count> fieldList = facetFields.getValues();
|
|
|
+
|
|
|
+ if (fieldList == null) {
|
|
|
+ return collection;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Count cnt : fieldList) {
|
|
|
+ if (cnt != null) {
|
|
|
+ CountData vCount = new CountData();
|
|
|
+ vCount.setName(cnt.getName());
|
|
|
+ vCount.setCount(cnt.getCount());
|
|
|
+ vCounts.add(vCount);
|
|
|
}
|
|
|
}
|
|
|
- return null;
|
|
|
+ collection.setvCounts(vCounts);
|
|
|
+ return collection;
|
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private BarGraphDataListResponse rangeStackGraph(String xAxisField, String stackField, String from, String to, String unit,
|
|
|
- SolrDaoBase solrDaoBase, SolrQuery solrQuery) {
|
|
|
- BarGraphDataListResponse dataList = new BarGraphDataListResponse();
|
|
|
- List<BarGraphData> histogramData = new ArrayList<BarGraphData>();
|
|
|
- SolrUtil.setMainQuery(solrQuery, null);
|
|
|
- SolrUtil.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
|
|
|
- String jsonHistogramQuery =
|
|
|
- queryGenerator.buildJSONFacetTermTimeRangeQuery(stackField, xAxisField, from, to, unit).replace("\\", "");
|
|
|
- try {
|
|
|
- solrQuery.set("json.facet", jsonHistogramQuery);
|
|
|
- SolrUtil.setRowCount(solrQuery, 0);
|
|
|
- QueryResponse response = solrDaoBase.process(solrQuery);
|
|
|
- if (response != null) {
|
|
|
- SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
|
|
|
- if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
|
|
|
- return dataList;
|
|
|
+ public GraphDataListResponse generateSimpleGraphResponse(QueryResponse response, String hierarchy) {
|
|
|
+ GraphDataListResponse graphInfo = new GraphDataListResponse();
|
|
|
+ if (response == null) {
|
|
|
+ return graphInfo;
|
|
|
+ }
|
|
|
+ List<List<PivotField>> hirarchicalPivotField = new ArrayList<List<PivotField>>();
|
|
|
+ List<GraphData> dataList = new ArrayList<>();
|
|
|
+ NamedList<List<PivotField>> 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 graphInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<GraphData> buidGraphData(List<PivotField> pivotFields) {
|
|
|
+ List<GraphData> logList = new ArrayList<>();
|
|
|
+ if (pivotFields != null) {
|
|
|
+ for (PivotField pivotField : pivotFields) {
|
|
|
+ if (pivotField != null) {
|
|
|
+ GraphData logLevel = new GraphData();
|
|
|
+ logLevel.setName("" + pivotField.getValue());
|
|
|
+ logLevel.setCount(Long.valueOf(pivotField.getCount()));
|
|
|
+ if (pivotField.getPivot() != null) {
|
|
|
+ logLevel.setDataList(buidGraphData(pivotField.getPivot()));
|
|
|
+ }
|
|
|
+ logList.add(logLevel);
|
|
|
}
|
|
|
- extractRangeStackValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
|
|
|
- dataList.setGraphData(histogramData);
|
|
|
}
|
|
|
- return dataList;
|
|
|
- } catch (SolrException | IOException | SolrServerException e) {
|
|
|
- logger.error("Got exception for solr query :" + solrQuery, e.getCause());
|
|
|
}
|
|
|
- return null;
|
|
|
+ return logList;
|
|
|
}
|
|
|
}
|