ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oleew...@apache.org
Subject [1/5] ambari git commit: AMBARI-20023. Add delete endpoint for logsearch (service + audit logs) (oleewere)
Date Wed, 22 Mar 2017 13:02:53 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk a8a1ee8b3 -> f8931a925


AMBARI-20023. Add delete endpoint for logsearch (service + audit logs) (oleewere)


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

Branch: refs/heads/trunk
Commit: 1310bf3b9e7e21ec8ba534bd765ddb63bbe27eb8
Parents: a8a1ee8
Author: oleewere <oleewere@gmail.com>
Authored: Fri Mar 10 14:31:32 2017 +0100
Committer: oleewere <oleewere@gmail.com>
Committed: Wed Mar 22 13:47:07 2017 +0100

----------------------------------------------------------------------
 .../ambari/logsearch/common/StatusMessage.java  | 40 ++++++++++++++++++++
 .../ambari/logsearch/conf/ApiDocConfig.java     |  4 +-
 .../ambari/logsearch/dao/SolrDaoBase.java       | 38 ++++++++++++++++---
 .../ambari/logsearch/doc/DocConstants.java      |  2 +
 .../logsearch/manager/AuditLogsManager.java     |  8 ++++
 .../logsearch/manager/ServiceLogsManager.java   |  8 ++++
 .../logsearch/rest/AuditLogsResource.java       |  9 +++++
 .../logsearch/rest/ServiceLogsResource.java     | 11 +++++-
 8 files changed, 111 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1310bf3b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/StatusMessage.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/StatusMessage.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/StatusMessage.java
new file mode 100644
index 0000000..d4567de
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/StatusMessage.java
@@ -0,0 +1,40 @@
+/*
+ * 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.common;
+
+public class StatusMessage {
+
+  private String status;
+
+  public StatusMessage(String status) {
+    this.status = status;
+  }
+
+  public StatusMessage(int status) {
+    this.status = String.valueOf(status);
+  }
+
+  public String getStatus() {
+    return status;
+  }
+
+  public void setStatus(String status) {
+    this.status = status;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/1310bf3b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
index 4a8fdea..630e73a 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
@@ -25,8 +25,6 @@ import io.swagger.jaxrs.listing.SwaggerSerializers;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
-import java.net.UnknownHostException;
-
 @Configuration
 public class ApiDocConfig {
 
@@ -41,7 +39,7 @@ public class ApiDocConfig {
   }
 
   @Bean
-  public BeanConfig swaggerConfig() throws UnknownHostException {
+  public BeanConfig swaggerConfig() {
     BeanConfig beanConfig = new BeanConfig();
     beanConfig.setSchemes(new String[]{"http", "https"});
     beanConfig.setBasePath("/api/v1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/1310bf3b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
index 0568fd7..b30b6ef 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
@@ -34,6 +34,8 @@ import org.apache.solr.client.solrj.SolrRequest.METHOD;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.impl.CloudSolrClient;
 import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.SolrResponseBase;
+import org.apache.solr.client.solrj.response.UpdateResponse;
 import org.springframework.data.solr.core.DefaultQueryParser;
 import org.springframework.data.solr.core.SolrCallback;
 import org.springframework.data.solr.core.SolrTemplate;
@@ -64,11 +66,7 @@ public abstract class SolrDaoBase {
       solrQuery.remove("event");
       try {
         QueryResponse queryResponse = getSolrClient().query(solrQuery, METHOD.POST);
-        if (event != null) {
-          LOG_PERFORMANCE.info("\n Username :- " + LogSearchContext.getCurrentUsername()
+ " Event :- " + event + " SolrQuery :- " +
-            solrQuery + "\nQuery Time Execution :- " + queryResponse.getQTime() + " Total
Time Elapsed is :- " +
-            queryResponse.getElapsedTime());
-        }
+        logSolrEvent(event, solrQuery, queryResponse);
         return queryResponse;
       } catch (Exception e){
         LOG.error("Error during solrQuery=" + e);
@@ -80,6 +78,28 @@ public abstract class SolrDaoBase {
     }
   }
 
+  public UpdateResponse deleteByQuery(SolrQuery solrQuery, String event) {
+    SolrUtil.removeDoubleOrTripleEscapeFromFilters(solrQuery);
+    LOG.info("Solr delete query will be processed: " + solrQuery);
+    if (getSolrClient() != null) {
+      try {
+        UpdateResponse updateResponse = getSolrClient().deleteByQuery(solrQuery.getQuery());
+        logSolrEvent(event, solrQuery, updateResponse);
+        return updateResponse;
+      } catch (Exception e) {
+        LOG.error("Error during delete solrQuery=" + e);
+        throw RESTErrorUtil.createRESTException(MessageEnums.SOLR_ERROR.getMessage().getMessage(),
MessageEnums.ERROR_SYSTEM);
+      }
+    } else {
+      throw RESTErrorUtil.createRESTException("Solr configuration improper for " + logType.getLabel()
+ " logs",
+        MessageEnums.ERROR_SYSTEM);
+    }
+  }
+
+  public UpdateResponse deleteByQuery(SolrDataQuery solrDataQuery, String event) {
+    return deleteByQuery(new DefaultQueryParser().doConstructSolrQuery(solrDataQuery), event);
+  }
+
   public QueryResponse process(SolrQuery solrQuery) {
     return process(solrQuery, null);
   }
@@ -109,6 +129,14 @@ public abstract class SolrDaoBase {
     return process(new DefaultQueryParser().doConstructSolrQuery(solrDataQuery), event);
   }
 
+  private void logSolrEvent(String event, SolrQuery solrQuery, SolrResponseBase solrResponseBase)
{
+    if (event != null) {
+      LOG_PERFORMANCE.info("\n Username :- " + LogSearchContext.getCurrentUsername() + "
Event :- " + event + " SolrQuery :- " +
+        solrQuery + "\nQuery Time Execution :- " + solrResponseBase.getQTime() + " Total
Time Elapsed is :- " +
+        solrResponseBase.getElapsedTime());
+    }
+  }
+
   public CloudSolrClient getSolrClient() {
     return (CloudSolrClient) getSolrTemplate().getSolrClient();
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1310bf3b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
index 713c9f6..d57e1ee 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
@@ -50,6 +50,7 @@ public class DocConstants {
   public class AuditOperationDescriptions {
     public static final String GET_AUDIT_SCHEMA_FIELD_LIST_OD = "Get list of schema fields
in audit collection";
     public static final String GET_AUDIT_LOGS_OD = "Get the list of logs details";
+    public static final String PURGE_AUDIT_LOGS_OD = "Purge service logs based by criteria";
     public static final String GET_AUDIT_COMPONENTS_OD = "Get the list of audit components
currently active or having data in Solr";
     public static final String GET_AUDIT_LINE_GRAPH_DATA_OD = "Get the data required for
line graph";
     public static final String GET_TOP_AUDIT_RESOURCES_OD = "Get the top audit resource count
(grouped by type)";
@@ -76,6 +77,7 @@ public class DocConstants {
 
   public class ServiceOperationDescriptions {
     public static final String SEARCH_LOGS_OD = "Searching logs entry";
+    public static final String PURGE_LOGS_OD = "Purge service logs based by criteria";
     public static final String GET_HOSTS_OD = "Get the list of service hosts currently active
or having data in Solr";
     public static final String GET_COMPONENTS_OD = "Get the list of service components currently
active or having data in Solr";
     public static final String GET_AGGREGATED_INFO_OD = "not required";

http://git-wip-us.apache.org/repos/asf/ambari/blob/1310bf3b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
index 2dc0ef7..2a18415 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/AuditLogsManager.java
@@ -39,6 +39,7 @@ import freemarker.template.TemplateException;
 
 import org.apache.ambari.logsearch.common.LogType;
 import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.ambari.logsearch.common.StatusMessage;
 import org.apache.ambari.logsearch.dao.AuditSolrDao;
 import org.apache.ambari.logsearch.dao.SolrSchemaFieldDao;
 import org.apache.ambari.logsearch.model.request.impl.AuditBarGraphRequest;
@@ -62,6 +63,7 @@ import org.apache.log4j.Logger;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.response.FacetField.Count;
 import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.UpdateResponse;
 import org.springframework.core.convert.ConversionService;
 import org.springframework.data.solr.core.query.SimpleFacetQuery;
 import org.springframework.data.solr.core.query.SimpleQuery;
@@ -196,4 +198,10 @@ public class AuditLogsManager extends ManagerBase<SolrAuditLogData,
AuditLogResp
   protected AuditLogResponse createLogSearchResponse() {
     return new AuditLogResponse();
   }
+
+  public StatusMessage deleteLogs(AuditLogRequest request) {
+    SimpleQuery solrQuery = conversionService.convert(request, SimpleQuery.class);
+    UpdateResponse updateResponse = auditSolrDao.deleteByQuery(solrQuery, "/audit/logs");
+    return new StatusMessage(updateResponse.getStatus());
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1310bf3b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
index f960250..cb1e48f 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/manager/ServiceLogsManager.java
@@ -43,6 +43,7 @@ import org.apache.ambari.logsearch.common.HadoopServiceConfigHelper;
 import org.apache.ambari.logsearch.common.LogSearchConstants;
 import org.apache.ambari.logsearch.common.LogType;
 import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.ambari.logsearch.common.StatusMessage;
 import org.apache.ambari.logsearch.dao.ServiceLogsSolrDao;
 import org.apache.ambari.logsearch.dao.SolrSchemaFieldDao;
 import org.apache.ambari.logsearch.model.request.impl.HostLogFilesRequest;
@@ -85,6 +86,7 @@ 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.client.solrj.response.UpdateResponse;
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.SolrDocumentList;
 import org.apache.solr.common.SolrException;
@@ -589,4 +591,10 @@ public class ServiceLogsManager extends ManagerBase<SolrServiceLogData,
ServiceL
     QueryResponse queryResponse = serviceLogsSolrDao.process(facetQuery, "/service/logs/hostlogfiles");
     return responseDataGenerator.generateHostLogFilesResponse(queryResponse);
   }
+
+  public StatusMessage deleteLogs(ServiceLogRequest request) {
+    SimpleQuery solrQuery = conversionService.convert(request, SimpleQuery.class);
+    UpdateResponse updateResponse = serviceLogsSolrDao.deleteByQuery(solrQuery, "/service/logs");
+    return new StatusMessage(updateResponse.getStatus());
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/1310bf3b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditLogsResource.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditLogsResource.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditLogsResource.java
index d5b6525..2013dc7 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditLogsResource.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/AuditLogsResource.java
@@ -22,6 +22,7 @@ package org.apache.ambari.logsearch.rest;
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.ws.rs.BeanParam;
+import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
@@ -30,6 +31,7 @@ import javax.ws.rs.core.Response;
 import freemarker.template.TemplateException;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.apache.ambari.logsearch.common.StatusMessage;
 import org.apache.ambari.logsearch.model.request.impl.AuditBarGraphRequest;
 import org.apache.ambari.logsearch.model.request.impl.AuditComponentRequest;
 import org.apache.ambari.logsearch.model.request.impl.AuditServiceLoadRequest;
@@ -68,6 +70,13 @@ public class AuditLogsResource {
     return auditLogsManager.getLogs(auditLogRequest);
   }
 
+  @DELETE
+  @Produces({"application/json"})
+  @ApiOperation(PURGE_AUDIT_LOGS_OD)
+  public StatusMessage deleteAuditLogs(@BeanParam AuditLogRequest auditLogRequest) {
+    return auditLogsManager.deleteLogs(auditLogRequest);
+  }
+
   @GET
   @Path("/components")
   @Produces({"application/json"})

http://git-wip-us.apache.org/repos/asf/ambari/blob/1310bf3b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsResource.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsResource.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsResource.java
index 40247a8..135986f 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsResource.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/rest/ServiceLogsResource.java
@@ -23,6 +23,7 @@ import javax.inject.Named;
 import javax.validation.Valid;
 import javax.validation.executable.ValidateOnExecution;
 import javax.ws.rs.BeanParam;
+import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
@@ -31,6 +32,7 @@ import javax.ws.rs.core.Response;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 
+import org.apache.ambari.logsearch.common.StatusMessage;
 import org.apache.ambari.logsearch.model.request.impl.HostLogFilesRequest;
 import org.apache.ambari.logsearch.model.request.impl.ServiceAnyGraphRequest;
 import org.apache.ambari.logsearch.model.request.impl.ServiceGraphRequest;
@@ -67,10 +69,17 @@ public class ServiceLogsResource {
   @GET
   @Produces({"application/json"})
   @ApiOperation(SEARCH_LOGS_OD)
-  public ServiceLogResponse searchSolrData(@BeanParam ServiceLogRequest request) {
+  public ServiceLogResponse searchServiceLogs(@BeanParam ServiceLogRequest request) {
     return serviceLogsManager.searchLogs(request);
   }
 
+  @DELETE
+  @Produces({"application/json"})
+  @ApiOperation(PURGE_LOGS_OD)
+  public StatusMessage deleteServiceLogs(@BeanParam ServiceLogRequest request) {
+    return serviceLogsManager.deleteLogs(request);
+  }
+
   @GET
   @Path("/hosts")
   @Produces({"application/json"})


Mime
View raw message