|
@@ -19,6 +19,7 @@
|
|
|
|
|
|
package org.apache.ambari.logsearch.manager;
|
|
|
|
|
|
+import javax.inject.Inject;
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
@@ -27,6 +28,7 @@ import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
@@ -36,21 +38,26 @@ import org.apache.ambari.logsearch.common.ConfigHelper;
|
|
|
import org.apache.ambari.logsearch.common.LogSearchConstants;
|
|
|
import org.apache.ambari.logsearch.common.ManageStartEndTime;
|
|
|
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.conf.SolrAuditLogConfig;
|
|
|
import org.apache.ambari.logsearch.dao.AuditSolrDao;
|
|
|
import org.apache.ambari.logsearch.graph.GraphDataGenerator;
|
|
|
+import org.apache.ambari.logsearch.model.response.AuditLogResponse;
|
|
|
+import org.apache.ambari.logsearch.model.response.BarGraphData;
|
|
|
+import org.apache.ambari.logsearch.model.response.BarGraphDataListResponse;
|
|
|
+import org.apache.ambari.logsearch.model.response.GroupListResponse;
|
|
|
+import org.apache.ambari.logsearch.model.response.LogData;
|
|
|
+import org.apache.ambari.logsearch.model.response.LogSearchResponse;
|
|
|
+import org.apache.ambari.logsearch.model.response.NameValueData;
|
|
|
+import org.apache.ambari.logsearch.model.response.NameValueDataListResponse;
|
|
|
+import org.apache.ambari.logsearch.solr.model.SolrAuditLogData;
|
|
|
+import org.apache.ambari.logsearch.solr.model.SolrComponentTypeLogData;
|
|
|
import org.apache.ambari.logsearch.util.BizUtil;
|
|
|
import org.apache.ambari.logsearch.util.DateUtil;
|
|
|
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.VGroupList;
|
|
|
-import org.apache.ambari.logsearch.view.VNameValue;
|
|
|
-import org.apache.ambari.logsearch.view.VNameValueList;
|
|
|
import org.apache.ambari.logsearch.view.VResponse;
|
|
|
-import org.apache.ambari.logsearch.view.VSolrLogList;
|
|
|
+import org.apache.ambari.logsearch.query.model.AuditLogSearchCriteria;
|
|
|
+import org.apache.ambari.logsearch.query.model.SearchCriteria;
|
|
|
import org.apache.log4j.Logger;
|
|
|
import org.apache.solr.client.solrj.SolrQuery;
|
|
|
import org.apache.solr.client.solrj.SolrServerException;
|
|
@@ -58,43 +65,39 @@ 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.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.stereotype.Component;
|
|
|
|
|
|
@Component
|
|
|
-public class AuditMgr extends MgrBase {
|
|
|
- private static final Logger logger = Logger.getLogger(AuditMgr.class);
|
|
|
+public class AuditLogsManager extends ManagerBase<SolrAuditLogData, AuditLogResponse> {
|
|
|
+ private static final Logger logger = Logger.getLogger(AuditLogsManager.class);
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Inject
|
|
|
private AuditSolrDao auditSolrDao;
|
|
|
- @Autowired
|
|
|
+ @Inject
|
|
|
private GraphDataGenerator graphDataGenerator;
|
|
|
-
|
|
|
- public String getLogs(SearchCriteria searchCriteria) {
|
|
|
- String lastPage = (String) searchCriteria.getParamValue("isLastPage");
|
|
|
- Boolean isLastPage = Boolean.parseBoolean(lastPage);
|
|
|
- if (isLastPage) {
|
|
|
- SolrQuery lastPageQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
- VSolrLogList collection = getLastPage(searchCriteria, LogSearchConstants.AUDIT_EVTTIME, auditSolrDao, lastPageQuery);
|
|
|
- if(collection == null){
|
|
|
- collection = new VSolrLogList();
|
|
|
- }
|
|
|
- return convertObjToString(collection);
|
|
|
+ @Inject
|
|
|
+ private SolrAuditLogConfig solrAuditLogConfig;
|
|
|
+
|
|
|
+ public AuditLogResponse getLogs(AuditLogSearchCriteria searchCriteria) {
|
|
|
+ Boolean isLastPage = (Boolean) searchCriteria.getParamValue("isLastPage");
|
|
|
+ if (isLastPage) {
|
|
|
+ SolrQuery lastPageQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
+ LogSearchResponse logResponse = getLastPage(searchCriteria, LogSearchConstants.AUDIT_EVTTIME, auditSolrDao, lastPageQuery);
|
|
|
+ if (logResponse == null) {
|
|
|
+ logResponse = new AuditLogResponse();
|
|
|
+ }
|
|
|
+ return (AuditLogResponse) logResponse;
|
|
|
}
|
|
|
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
- VSolrLogList collection = getLogAsPaginationProvided(solrQuery, auditSolrDao);
|
|
|
- return convertObjToString(collection);
|
|
|
-
|
|
|
+ return getLogAsPaginationProvided(solrQuery, auditSolrDao);
|
|
|
}
|
|
|
|
|
|
- private SolrDocumentList getComponents(SearchCriteria searchCriteria) {
|
|
|
+ private List<LogData> getComponents(SearchCriteria searchCriteria) {
|
|
|
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
- SolrDocumentList docList = new SolrDocumentList();
|
|
|
+ List<LogData> docList = new ArrayList<>();
|
|
|
try {
|
|
|
SolrUtil.setFacetField(solrQuery, LogSearchConstants.AUDIT_COMPONENT);
|
|
|
SolrUtil.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
|
|
@@ -117,11 +120,11 @@ public class AuditMgr extends MgrBase {
|
|
|
if (facetField != null) {
|
|
|
componentsCount = facetField.getValues();
|
|
|
}
|
|
|
-
|
|
|
- for (Count compnonet : componentsCount) {
|
|
|
- SolrDocument solrDocument = new SolrDocument();
|
|
|
- solrDocument.addField("type", compnonet.getName());
|
|
|
- docList.add(solrDocument);
|
|
|
+
|
|
|
+ for (Count component : componentsCount) {
|
|
|
+ SolrComponentTypeLogData logData = new SolrComponentTypeLogData();
|
|
|
+ logData.setType(component.getName());
|
|
|
+ docList.add(logData);
|
|
|
}
|
|
|
return docList;
|
|
|
} catch (SolrException | SolrServerException | IOException e) {
|
|
@@ -130,24 +133,23 @@ public class AuditMgr extends MgrBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String getAuditComponents(SearchCriteria searchCriteria) {
|
|
|
- VGroupList vGroupList = new VGroupList();
|
|
|
- SolrDocumentList docList = getComponents(searchCriteria);
|
|
|
-
|
|
|
- vGroupList.setGroupDocuments(docList);
|
|
|
- return convertObjToString(vGroupList);
|
|
|
+ public GroupListResponse getAuditComponents(SearchCriteria searchCriteria) {
|
|
|
+ GroupListResponse componentResponse = new GroupListResponse();
|
|
|
+ List<LogData> docList = getComponents(searchCriteria);
|
|
|
+ componentResponse.setGroupList(docList);
|
|
|
+ return componentResponse;
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- public String getAuditLineGraphData(SearchCriteria searchCriteria) {
|
|
|
- VBarDataList dataList = new VBarDataList();
|
|
|
+ public BarGraphDataListResponse getAuditBarGraphData(SearchCriteria searchCriteria) {
|
|
|
+ BarGraphDataListResponse dataList = new BarGraphDataListResponse();
|
|
|
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
|
|
|
String from = getFrom((String) searchCriteria.getParamValue("startTime"));
|
|
|
String to = getTo((String) searchCriteria.getParamValue("endTime"));
|
|
|
String unit = getUnit((String) searchCriteria.getParamValue("unit"));
|
|
|
|
|
|
- List<VBarGraphData> histogramData = new ArrayList<VBarGraphData>();
|
|
|
+ List<BarGraphData> histogramData = new ArrayList<BarGraphData>();
|
|
|
String jsonHistogramQuery = queryGenerator.buildJSONFacetTermTimeRangeQuery(LogSearchConstants.AUDIT_COMPONENT,
|
|
|
LogSearchConstants.AUDIT_EVTTIME, from, to, unit).replace("\\", "");
|
|
|
|
|
@@ -155,19 +157,19 @@ public class AuditMgr extends MgrBase {
|
|
|
SolrUtil.setJSONFacet(solrQuery, jsonHistogramQuery);
|
|
|
SolrUtil.setRowCount(solrQuery, 0);
|
|
|
QueryResponse response = auditSolrDao.process(solrQuery);
|
|
|
- if (response == null){
|
|
|
- return convertObjToString(dataList);
|
|
|
+ if (response == null) {
|
|
|
+ return dataList;
|
|
|
}
|
|
|
SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
|
|
|
|
|
|
if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
|
|
|
- return convertObjToString(dataList);
|
|
|
+ return dataList;
|
|
|
}
|
|
|
|
|
|
extractValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
|
|
|
|
|
|
dataList.setGraphData(histogramData);
|
|
|
- return convertObjToString(dataList);
|
|
|
+ return dataList;
|
|
|
|
|
|
} catch (SolrServerException | SolrException | IOException e) {
|
|
|
logger.error(e);
|
|
@@ -176,55 +178,9 @@ public class AuditMgr extends MgrBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String getTopAuditFieldCount(SearchCriteria searchCriteria) {
|
|
|
- int topCounts = 10;
|
|
|
- Integer top = (Integer) searchCriteria.getParamValue("top");
|
|
|
- String facetField = (String) searchCriteria.getParamValue("field");
|
|
|
- if (top == null){
|
|
|
- top = new Integer(topCounts);
|
|
|
- }
|
|
|
- SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
- try {
|
|
|
-
|
|
|
- List<VNameValue> nameValues = new ArrayList<VNameValue>();
|
|
|
-
|
|
|
- VNameValueList nameValueList = new VNameValueList(nameValues);
|
|
|
-
|
|
|
- SolrUtil.setFacetField(solrQuery, facetField);
|
|
|
- SolrUtil.setFacetSort(solrQuery, LogSearchConstants.FACET_COUNT);
|
|
|
- SolrUtil.setFacetLimit(solrQuery, top.intValue());
|
|
|
-
|
|
|
- List<Count> countList = new ArrayList<FacetField.Count>();
|
|
|
- QueryResponse queryResponse = auditSolrDao.process(solrQuery);
|
|
|
- if (queryResponse == null) {
|
|
|
- return convertObjToString(nameValueList);
|
|
|
- }
|
|
|
-
|
|
|
- if (queryResponse.getFacetField(facetField) != null) {
|
|
|
- FacetField queryFacetField = queryResponse.getFacetField(facetField);
|
|
|
- if (queryFacetField != null) {
|
|
|
- countList = queryFacetField.getValues();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (Count cnt : countList) {
|
|
|
- VNameValue nameValue = new VNameValue();
|
|
|
- nameValue.setName(cnt.getName());
|
|
|
-
|
|
|
- nameValue.setValue("" + cnt.getCount());
|
|
|
- nameValues.add(nameValue);
|
|
|
- }
|
|
|
- return convertObjToString(nameValueList);
|
|
|
-
|
|
|
- } catch (SolrException | IOException | SolrServerException e) {
|
|
|
- logger.error("Error during solrQuery=" + solrQuery, e);
|
|
|
- throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
- public String getLiveLogCounts() {
|
|
|
- VNameValueList nameValueList = new VNameValueList();
|
|
|
+ @SuppressWarnings({"unchecked", "rawtypes"})
|
|
|
+ public NameValueDataListResponse getLiveLogCounts() {
|
|
|
+ NameValueDataListResponse nameValueList = new NameValueDataListResponse();
|
|
|
SolrQuery solrQuery = new SolrQuery();
|
|
|
solrQuery.setParam("event", "/audit/logs/live/count");
|
|
|
try {
|
|
@@ -237,30 +193,30 @@ public class AuditMgr extends MgrBase {
|
|
|
List<RangeFacet.Count> listCount;
|
|
|
|
|
|
QueryResponse response = auditSolrDao.process(solrQuery);
|
|
|
-
|
|
|
+
|
|
|
List<RangeFacet> rangeFacet = response.getFacetRanges();
|
|
|
- if (rangeFacet == null){
|
|
|
- return convertObjToString(nameValueList);
|
|
|
+ if (rangeFacet == null) {
|
|
|
+ return nameValueList;
|
|
|
}
|
|
|
- RangeFacet range=rangeFacet.get(0);
|
|
|
-
|
|
|
- if(range == null){
|
|
|
- return convertObjToString(nameValueList);
|
|
|
+ RangeFacet range = rangeFacet.get(0);
|
|
|
+
|
|
|
+ if (range == null) {
|
|
|
+ return nameValueList;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
listCount = range.getCounts();
|
|
|
|
|
|
- List<VNameValue> nameValues = new ArrayList<VNameValue>();
|
|
|
+ List<NameValueData> nameValues = new ArrayList<>();
|
|
|
int count = 0;
|
|
|
for (RangeFacet.Count cnt : listCount) {
|
|
|
- VNameValue nameValue = new VNameValue();
|
|
|
+ NameValueData nameValue = new NameValueData();
|
|
|
nameValue.setName("" + count);
|
|
|
nameValue.setValue("" + cnt.getCount());
|
|
|
nameValues.add(nameValue);
|
|
|
count++;
|
|
|
}
|
|
|
- nameValueList.setVNameValues(nameValues);
|
|
|
- return convertObjToString(nameValueList);
|
|
|
+ nameValueList.setvNameValues(nameValues);
|
|
|
+ return nameValueList;
|
|
|
|
|
|
} catch (SolrException | SolrServerException | ParseException
|
|
|
| IOException e) {
|
|
@@ -269,36 +225,36 @@ public class AuditMgr extends MgrBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String topTenUsers(SearchCriteria searchCriteria) {
|
|
|
+ public BarGraphDataListResponse topTenUsers(SearchCriteria searchCriteria) {
|
|
|
|
|
|
String jsonUserQuery =
|
|
|
- "{Users:{type:terms, field:reqUser, facet:{ Repo:{ type:terms, field:repo, facet:{eventCount:\"sum(event_count)\"}}}}}";
|
|
|
+ "{Users:{type:terms, field:reqUser, facet:{ Repo:{ type:terms, field:repo, facet:{eventCount:\"sum(event_count)\"}}}}}";
|
|
|
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
SolrUtil.setJSONFacet(solrQuery, jsonUserQuery);
|
|
|
SolrUtil.setRowCount(solrQuery, 0);
|
|
|
try {
|
|
|
- VBarDataList vBarDataList = new VBarDataList();
|
|
|
+ BarGraphDataListResponse barGraphDataListResponse = new BarGraphDataListResponse();
|
|
|
QueryResponse queryResponse = auditSolrDao.process(solrQuery);
|
|
|
if (queryResponse == null) {
|
|
|
- return convertObjToString(vBarDataList);
|
|
|
+ return barGraphDataListResponse;
|
|
|
}
|
|
|
|
|
|
NamedList<Object> namedList = queryResponse.getResponse();
|
|
|
-
|
|
|
+
|
|
|
if (namedList == null) {
|
|
|
- return convertObjToString(vBarDataList);
|
|
|
+ return barGraphDataListResponse;
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList.get("facets");
|
|
|
if (jsonFacetResponse == null) {
|
|
|
- return convertObjToString(vBarDataList);
|
|
|
+ return barGraphDataListResponse;
|
|
|
}
|
|
|
if (jsonFacetResponse.toString().equals("{count=0}")) {
|
|
|
- return convertObjToString(vBarDataList);
|
|
|
+ return barGraphDataListResponse;
|
|
|
}
|
|
|
- vBarDataList = BizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
|
|
|
- return convertObjToString(vBarDataList);
|
|
|
+ barGraphDataListResponse = BizUtil.buildSummaryForTopCounts(jsonFacetResponse, "Repo", "Users");
|
|
|
+ return barGraphDataListResponse;
|
|
|
|
|
|
} catch (SolrServerException | SolrException | IOException e) {
|
|
|
logger.error("Error during solrQuery=" + e);
|
|
@@ -306,30 +262,30 @@ public class AuditMgr extends MgrBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String topTenResources(SearchCriteria searchCriteria) {
|
|
|
+ public BarGraphDataListResponse topTenResources(SearchCriteria searchCriteria) {
|
|
|
|
|
|
String jsonUserQuery =
|
|
|
- "{Users:{type:terms,field:resource,facet:{Repo:{type:terms,field:repo,facet:{eventCount:\"sum(event_count)\"}}}}}";
|
|
|
+ "{Users:{type:terms,field:resource,facet:{Repo:{type:terms,field:repo,facet:{eventCount:\"sum(event_count)\"}}}}}";
|
|
|
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
SolrUtil.setJSONFacet(solrQuery, jsonUserQuery);
|
|
|
SolrUtil.setRowCount(solrQuery, 0);
|
|
|
try {
|
|
|
- VBarDataList vBarDataList = new VBarDataList();
|
|
|
+ BarGraphDataListResponse barGraphDataListResponse = new BarGraphDataListResponse();
|
|
|
QueryResponse queryResponse = auditSolrDao.process(solrQuery);
|
|
|
- if(queryResponse == null){
|
|
|
- return convertObjToString(vBarDataList);
|
|
|
+ if (queryResponse == null) {
|
|
|
+ return barGraphDataListResponse;
|
|
|
}
|
|
|
|
|
|
NamedList<Object> namedList = queryResponse.getResponse();
|
|
|
if (namedList == null) {
|
|
|
- return convertObjToString(vBarDataList);
|
|
|
+ return barGraphDataListResponse;
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList.get("facets");
|
|
|
|
|
|
- vBarDataList = BizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
|
|
|
- return convertObjToString(vBarDataList);
|
|
|
+ barGraphDataListResponse = BizUtil.buildSummaryForTopCounts(jsonFacetResponse, "Repo", "Users");
|
|
|
+ return barGraphDataListResponse;
|
|
|
|
|
|
} catch (SolrServerException | SolrException | IOException e) {
|
|
|
logger.error("Error during solrQuery=" + solrQuery, e);
|
|
@@ -338,38 +294,38 @@ public class AuditMgr extends MgrBase {
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- public String getRequestUserLineGraph(SearchCriteria searchCriteria) {
|
|
|
+ public BarGraphDataListResponse getRequestUserLineGraph(SearchCriteria searchCriteria) {
|
|
|
|
|
|
String from = getFrom((String) searchCriteria.getParamValue("startTime"));
|
|
|
String to = getTo((String) searchCriteria.getParamValue("endTime"));
|
|
|
String unit = getUnit((String) searchCriteria.getParamValue("unit"));
|
|
|
-
|
|
|
+
|
|
|
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
|
|
|
- VBarDataList dataList = new VBarDataList();
|
|
|
- List<VBarGraphData> histogramData = new ArrayList<VBarGraphData>();
|
|
|
+ BarGraphDataListResponse dataList = new BarGraphDataListResponse();
|
|
|
+ List<BarGraphData> histogramData = new ArrayList<BarGraphData>();
|
|
|
|
|
|
SolrUtil.setFacetSort(solrQuery, LogSearchConstants.FACET_INDEX);
|
|
|
|
|
|
String jsonHistogramQuery = queryGenerator.buildJSONFacetTermTimeRangeQuery(LogSearchConstants.AUDIT_REQUEST_USER,
|
|
|
- LogSearchConstants.AUDIT_EVTTIME, from, to, unit).replace("\\", "");
|
|
|
+ LogSearchConstants.AUDIT_EVTTIME, from, to, unit).replace("\\", "");
|
|
|
|
|
|
try {
|
|
|
SolrUtil.setJSONFacet(solrQuery, jsonHistogramQuery);
|
|
|
SolrUtil.setRowCount(solrQuery, 0);
|
|
|
QueryResponse response = auditSolrDao.process(solrQuery);
|
|
|
- if (response == null){
|
|
|
- return convertObjToString(dataList);
|
|
|
+ if (response == null) {
|
|
|
+ return dataList;
|
|
|
}
|
|
|
SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) response.getResponse().get("facets");
|
|
|
|
|
|
if (jsonFacetResponse == null || jsonFacetResponse.toString().equals("{count=0}")) {
|
|
|
- return convertObjToString(dataList);
|
|
|
+ return dataList;
|
|
|
}
|
|
|
extractValuesFromBucket(jsonFacetResponse, "x", "y", histogramData);
|
|
|
|
|
|
dataList.setGraphData(histogramData);
|
|
|
- return convertObjToString(dataList);
|
|
|
+ return dataList;
|
|
|
|
|
|
} catch (SolrException | IOException | SolrServerException e) {
|
|
|
logger.error("Error during solrQuery=" + solrQuery, e);
|
|
@@ -379,13 +335,14 @@ public class AuditMgr extends MgrBase {
|
|
|
}
|
|
|
|
|
|
public String getAuditLogsSchemaFieldsName() {
|
|
|
- String excludeArray[] = PropertiesHelper.getPropertyStringList("logsearch.solr.audit.logs.exclude.columnlist");
|
|
|
+ String excludeArray[] = Arrays.copyOf(solrAuditLogConfig.getExcludeColumnList().toArray(),
|
|
|
+ solrAuditLogConfig.getExcludeColumnList().size(), String[].class);
|
|
|
List<String> fieldNames = new ArrayList<String>();
|
|
|
HashMap<String, String> uiFieldColumnMapping = new HashMap<String, String>();
|
|
|
- ConfigHelper.getSchemaFieldsName(excludeArray, fieldNames,auditSolrDao);
|
|
|
+ ConfigHelper.getSchemaFieldsName(excludeArray, fieldNames, auditSolrDao);
|
|
|
|
|
|
for (String fieldName : fieldNames) {
|
|
|
- String uiField = ConfigHelper.auditLogsColumnMapping.get(fieldName + LogSearchConstants.SOLR_SUFFIX);
|
|
|
+ String uiField = solrAuditLogConfig.getSolrAndUiColumns().get(fieldName + LogSearchConstants.SOLR_SUFFIX);
|
|
|
if (uiField == null) {
|
|
|
uiFieldColumnMapping.put(fieldName, fieldName);
|
|
|
} else {
|
|
@@ -398,38 +355,38 @@ public class AuditMgr extends MgrBase {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public String getAnyGraphData(SearchCriteria searchCriteria) {
|
|
|
+ public BarGraphDataListResponse getAnyGraphData(SearchCriteria searchCriteria) {
|
|
|
searchCriteria.addParam("fieldTime", LogSearchConstants.AUDIT_EVTTIME);
|
|
|
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
- VBarDataList result = graphDataGenerator.getAnyGraphData(searchCriteria, auditSolrDao, solrQuery);
|
|
|
+ BarGraphDataListResponse result = graphDataGenerator.getAnyGraphData(searchCriteria, auditSolrDao, solrQuery);
|
|
|
if (result == null) {
|
|
|
- result = new VBarDataList();
|
|
|
+ result = new BarGraphDataListResponse();
|
|
|
}
|
|
|
- return convertObjToString(result);
|
|
|
+ return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private void extractValuesFromBucket(SimpleOrderedMap<Object> jsonFacetResponse, String outerField, String innerField,
|
|
|
- List<VBarGraphData> histogramData) {
|
|
|
+ List<BarGraphData> histogramData) {
|
|
|
NamedList<Object> stack = (NamedList<Object>) jsonFacetResponse.get(outerField);
|
|
|
ArrayList<Object> stackBuckets = (ArrayList<Object>) stack.get("buckets");
|
|
|
for (Object temp : stackBuckets) {
|
|
|
- VBarGraphData vBarGraphData = new VBarGraphData();
|
|
|
+ BarGraphData vBarGraphData = new BarGraphData();
|
|
|
|
|
|
SimpleOrderedMap<Object> level = (SimpleOrderedMap<Object>) temp;
|
|
|
String name = ((String) level.getVal(0)).toUpperCase();
|
|
|
vBarGraphData.setName(name);
|
|
|
|
|
|
- Collection<VNameValue> vNameValues = new ArrayList<VNameValue>();
|
|
|
- vBarGraphData.setDataCounts(vNameValues);
|
|
|
+ Collection<NameValueData> vNameValues = new ArrayList<NameValueData>();
|
|
|
+ vBarGraphData.setDataCount(vNameValues);
|
|
|
ArrayList<Object> levelBuckets = (ArrayList<Object>) ((NamedList<Object>) level.get(innerField)).get("buckets");
|
|
|
for (Object temp1 : levelBuckets) {
|
|
|
SimpleOrderedMap<Object> countValue = (SimpleOrderedMap<Object>) temp1;
|
|
|
String value = DateUtil.convertDateWithMillisecondsToSolrDate((Date) countValue.getVal(0));
|
|
|
|
|
|
String count = "" + countValue.getVal(1);
|
|
|
- VNameValue vNameValue = new VNameValue();
|
|
|
+ NameValueData vNameValue = new NameValueData();
|
|
|
vNameValue.setName(value);
|
|
|
vNameValue.setValue(count);
|
|
|
vNameValues.add(vNameValue);
|
|
@@ -441,7 +398,7 @@ public class AuditMgr extends MgrBase {
|
|
|
@SuppressWarnings({"unchecked"})
|
|
|
public Response exportUserTableToTextFile(SearchCriteria searchCriteria) {
|
|
|
String jsonUserQuery =
|
|
|
- "{ Users: { type: terms, field: reqUser, facet: {Repo: { type: terms, field: repo, facet: { eventCount: \"sum(event_count)\"}}}},x:{ type: terms,field: resource, facet: {y: { type: terms, field: repo,facet: { eventCount: \"sum(event_count)\"}}}}}";
|
|
|
+ "{ Users: { type: terms, field: reqUser, facet: {Repo: { type: terms, field: repo, facet: { eventCount: \"sum(event_count)\"}}}},x:{ type: terms,field: resource, facet: {y: { type: terms, field: repo,facet: { eventCount: \"sum(event_count)\"}}}}}";
|
|
|
|
|
|
SolrQuery solrQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
|
String startTime = (String) searchCriteria.getParamValue("startTime");
|
|
@@ -457,24 +414,24 @@ public class AuditMgr extends MgrBase {
|
|
|
FileOutputStream fis = null;
|
|
|
try {
|
|
|
QueryResponse queryResponse = auditSolrDao.process(solrQuery);
|
|
|
- if(queryResponse == null){
|
|
|
+ if (queryResponse == null) {
|
|
|
VResponse response = new VResponse();
|
|
|
- response.setMsgDesc("Query was not able to execute "+solrQuery);
|
|
|
+ response.setMsgDesc("Query was not able to execute " + solrQuery);
|
|
|
throw RESTErrorUtil.createRESTException(response);
|
|
|
}
|
|
|
|
|
|
NamedList<Object> namedList = queryResponse.getResponse();
|
|
|
if (namedList == null) {
|
|
|
VResponse response = new VResponse();
|
|
|
- response.setMsgDesc("Query was not able to execute "+solrQuery);
|
|
|
+ response.setMsgDesc("Query was not able to execute " + solrQuery);
|
|
|
throw RESTErrorUtil.createRESTException(response);
|
|
|
}
|
|
|
- VBarDataList vBarUserDataList = new VBarDataList();
|
|
|
- VBarDataList vBarResourceDataList = new VBarDataList();
|
|
|
+ BarGraphDataListResponse vBarUserDataList = new BarGraphDataListResponse();
|
|
|
+ BarGraphDataListResponse vBarResourceDataList = new BarGraphDataListResponse();
|
|
|
|
|
|
SimpleOrderedMap<Object> jsonFacetResponse = (SimpleOrderedMap<Object>) namedList.get("facets");
|
|
|
- vBarUserDataList = BizUtil.buildSummaryForTopCounts(jsonFacetResponse,"Repo","Users");
|
|
|
- vBarResourceDataList = BizUtil.buildSummaryForTopCounts(jsonFacetResponse,"y","x");
|
|
|
+ vBarUserDataList = BizUtil.buildSummaryForTopCounts(jsonFacetResponse, "Repo", "Users");
|
|
|
+ vBarResourceDataList = BizUtil.buildSummaryForTopCounts(jsonFacetResponse, "y", "x");
|
|
|
String data = "";
|
|
|
String summary = "";
|
|
|
if ("text".equals(dataFormat)) {
|
|
@@ -483,8 +440,8 @@ public class AuditMgr extends MgrBase {
|
|
|
summary += "\n\n\n\n";
|
|
|
data += addBlank("Users") + "Components/Access" + "\n";
|
|
|
data += "--------------------------------------------------------------------------\n";
|
|
|
- Collection<VBarGraphData> tableUserData = vBarUserDataList.getGraphData();
|
|
|
- for (VBarGraphData graphData : tableUserData) {
|
|
|
+ Collection<BarGraphData> tableUserData = vBarUserDataList.getGraphData();
|
|
|
+ for (BarGraphData graphData : tableUserData) {
|
|
|
String userName = graphData.getName();
|
|
|
String largeUserName = "";
|
|
|
|
|
@@ -494,10 +451,10 @@ public class AuditMgr extends MgrBase {
|
|
|
} else
|
|
|
data += addBlank(userName);
|
|
|
|
|
|
- Collection<VNameValue> vnameValueList = graphData.getDataCount();
|
|
|
+ Collection<NameValueData> vnameValueList = graphData.getDataCount();
|
|
|
int count = 0;
|
|
|
String blank = "";
|
|
|
- for (VNameValue vNameValue : vnameValueList) {
|
|
|
+ for (NameValueData vNameValue : vnameValueList) {
|
|
|
data += blank + vNameValue.getName() + " " + vNameValue.getValue() + "\n";
|
|
|
if (count == 0)
|
|
|
blank = addBlank(blank);
|
|
@@ -513,8 +470,8 @@ public class AuditMgr extends MgrBase {
|
|
|
data += "\n\n\n\n\n\n";
|
|
|
data += addBlank("Resources") + "Components/Access" + "\n";
|
|
|
data += "--------------------------------------------------------------------------\n";
|
|
|
- Collection<VBarGraphData> tableResourceData = vBarResourceDataList.getGraphData();
|
|
|
- for (VBarGraphData graphData : tableResourceData) {
|
|
|
+ Collection<BarGraphData> tableResourceData = vBarResourceDataList.getGraphData();
|
|
|
+ for (BarGraphData graphData : tableResourceData) {
|
|
|
String resourceName = graphData.getName();
|
|
|
String largeResourceName = resourceName;
|
|
|
if (largeResourceName.length() > 45) {
|
|
@@ -526,10 +483,10 @@ public class AuditMgr extends MgrBase {
|
|
|
|
|
|
//resourceName = resourceName.replaceAll("(.{45})", resourceName.substring(0, 45)+"\n");
|
|
|
data += addBlank(resourceName);
|
|
|
- Collection<VNameValue> vnameValueList = graphData.getDataCount();
|
|
|
+ Collection<NameValueData> vnameValueList = graphData.getDataCount();
|
|
|
int count = 0;
|
|
|
String blank = "";
|
|
|
- for (VNameValue vNameValue : vnameValueList) {
|
|
|
+ for (NameValueData vNameValue : vnameValueList) {
|
|
|
data += blank + vNameValue.getName() + " " + vNameValue.getValue() + "\n";
|
|
|
if (count == 0)
|
|
|
blank = addBlank(blank);
|
|
@@ -586,9 +543,9 @@ public class AuditMgr extends MgrBase {
|
|
|
return fieldWithBlank;
|
|
|
}
|
|
|
|
|
|
- public String getServiceLoad(SearchCriteria searchCriteria) {
|
|
|
- VBarDataList dataList = new VBarDataList();
|
|
|
- Collection<VBarGraphData> vaDatas = new ArrayList<VBarGraphData>();
|
|
|
+ public BarGraphDataListResponse getServiceLoad(SearchCriteria searchCriteria) {
|
|
|
+ BarGraphDataListResponse dataList = new BarGraphDataListResponse();
|
|
|
+ Collection<BarGraphData> vaDatas = new ArrayList<BarGraphData>();
|
|
|
dataList.setGraphData(vaDatas);
|
|
|
|
|
|
SolrQuery serivceLoadQuery = queryGenerator.commonAuditFilterQuery(searchCriteria);
|
|
@@ -596,35 +553,45 @@ public class AuditMgr extends MgrBase {
|
|
|
try {
|
|
|
SolrUtil.setFacetField(serivceLoadQuery, LogSearchConstants.AUDIT_COMPONENT);
|
|
|
QueryResponse serviceLoadResponse = auditSolrDao.process(serivceLoadQuery);
|
|
|
- if (serviceLoadResponse == null){
|
|
|
- return convertObjToString(dataList);
|
|
|
+ if (serviceLoadResponse == null) {
|
|
|
+ return dataList;
|
|
|
}
|
|
|
- FacetField serviceFacetField =serviceLoadResponse.getFacetField(LogSearchConstants.AUDIT_COMPONENT);
|
|
|
+ FacetField serviceFacetField = serviceLoadResponse.getFacetField(LogSearchConstants.AUDIT_COMPONENT);
|
|
|
if (serviceFacetField == null) {
|
|
|
- return convertObjToString(dataList);
|
|
|
+ return dataList;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
List<Count> serviceLoadFacets = serviceFacetField.getValues();
|
|
|
if (serviceLoadFacets == null) {
|
|
|
- return convertObjToString(dataList);
|
|
|
+ return dataList;
|
|
|
}
|
|
|
for (Count cnt : serviceLoadFacets) {
|
|
|
- List<VNameValue> valueList = new ArrayList<VNameValue>();
|
|
|
- VBarGraphData vBarGraphData = new VBarGraphData();
|
|
|
+ List<NameValueData> valueList = new ArrayList<NameValueData>();
|
|
|
+ BarGraphData vBarGraphData = new BarGraphData();
|
|
|
vaDatas.add(vBarGraphData);
|
|
|
- VNameValue vNameValue = new VNameValue();
|
|
|
+ NameValueData vNameValue = new NameValueData();
|
|
|
vNameValue.setName(cnt.getName());
|
|
|
vBarGraphData.setName(cnt.getName().toUpperCase());
|
|
|
vNameValue.setValue("" + cnt.getCount());
|
|
|
valueList.add(vNameValue);
|
|
|
- vBarGraphData.setDataCounts(valueList);
|
|
|
+ vBarGraphData.setDataCount(valueList);
|
|
|
}
|
|
|
|
|
|
- return convertObjToString(dataList);
|
|
|
+ return dataList;
|
|
|
|
|
|
} catch (SolrException | SolrServerException | IOException e) {
|
|
|
logger.error("Error during solrQuery=" + e);
|
|
|
throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(), MessageEnums.ERROR_SYSTEM);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected List<SolrAuditLogData> convertToSolrBeans(QueryResponse response) {
|
|
|
+ return response.getBeans(SolrAuditLogData.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected AuditLogResponse createLogSearchResponse() {
|
|
|
+ return new AuditLogResponse();
|
|
|
+ }
|
|
|
}
|