This is an automated email from the ASF dual-hosted git repository.

oleewere pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ambari-logsearch.git


The following commit(s) were added to refs/heads/master by this push:
     new ee6688e  AMBARI-24939. ADDENDUM - Optimize /metadata post operation
ee6688e is described below

commit ee6688ecbb2324d9f7bfbd75cfda462c6f2c4b43
Author: Oliver Szabo <oleew...@gmail.com>
AuthorDate: Wed Nov 28 15:03:47 2018 +0100

    AMBARI-24939. ADDENDUM - Optimize /metadata post operation
---
 .../org/apache/ambari/logsearch/dao/MetadataSolrDao.java  | 10 ++++++++--
 .../apache/ambari/logsearch/manager/MetadataManager.java  | 13 +++++++------
 .../apache/ambari/logsearch/rest/MetadataResource.java    | 15 +++++++--------
 3 files changed, 22 insertions(+), 16 deletions(-)

diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/dao/MetadataSolrDao.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/dao/MetadataSolrDao.java
index f6c3b1e..06c5775 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/dao/MetadataSolrDao.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/dao/MetadataSolrDao.java
@@ -21,6 +21,7 @@ package org.apache.ambari.logsearch.dao;
 
 import java.io.IOException;
 import java.io.UncheckedIOException;
+import java.util.List;
 
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
@@ -33,6 +34,7 @@ import org.apache.ambari.logsearch.conf.SolrPropsConfig;
 import org.apache.ambari.logsearch.conf.SolrMetadataPropsConfig;
 import org.apache.ambari.logsearch.conf.global.SolrCollectionState;
 import org.apache.ambari.logsearch.configurer.SolrCollectionConfigurer;
+import org.apache.curator.shaded.com.google.common.collect.ImmutableList;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.solr.client.solrj.SolrServerException;
@@ -107,9 +109,13 @@ public class MetadataSolrDao extends SolrDaoBase {
     }
   }
 
-  public UpdateResponse addDocs(SolrInputDocument doc) {
+  public UpdateResponse addDoc(SolrInputDocument doc) {
+    return addDocs(ImmutableList.of(doc));
+  }
+
+  public UpdateResponse addDocs(List<SolrInputDocument> docs) {
     try {
-      UpdateResponse updateResoponse = getSolrClient().add(doc);
+      UpdateResponse updateResoponse = getSolrClient().add(docs);
       LOG_PERFORMANCE.info("Username :- " + 
LogSearchContext.getCurrentUsername() +
               " Update Time Execution :- " + updateResoponse.getQTime() + " 
Total Time Elapsed is :- " + updateResoponse.getElapsedTime());
       getSolrClient().commit();
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/MetadataManager.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/MetadataManager.java
index a0be60f..40e2f57 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/MetadataManager.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/MetadataManager.java
@@ -27,7 +27,6 @@ import java.util.UUID;
 import org.apache.ambari.logsearch.common.LogSearchContext;
 import org.apache.ambari.logsearch.dao.MetadataSolrDao;
 import org.apache.ambari.logsearch.model.request.impl.MetadataRequest;
-import 
org.apache.ambari.logsearch.model.request.impl.query.MetadataQueryRequest;
 import org.apache.ambari.logsearch.model.response.LogsearchMetaData;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -61,18 +60,20 @@ public class MetadataManager extends JsonManagerBase {
   public String saveMetadata(Collection<LogsearchMetaData> 
logsearchMetaDataList) {
     List<SolrInputDocument> solrInputDocList = new ArrayList<>();
     for (LogsearchMetaData metaData : logsearchMetaDataList) {
-      solrInputDocList.add(saveOneMetadata(metaData));
+      solrInputDocList.add(createMetadata(metaData));
     }
+    metadataSolrDao.addDocs(solrInputDocList);
     return convertObjToString(solrInputDocList);
   }
 
   public String saveMetadata(LogsearchMetaData metadata) {
-    return convertObjToString(saveOneMetadata(metadata));
+    SolrInputDocument solrInputDocument = createMetadata(metadata);
+    metadataSolrDao.addDoc(solrInputDocument);
+    return convertObjToString(solrInputDocument);
   }
 
-  private SolrInputDocument saveOneMetadata(LogsearchMetaData metadata) {
+  private SolrInputDocument createMetadata(LogsearchMetaData metadata) {
     String name = metadata.getName();
-
     SolrInputDocument solrInputDoc = new SolrInputDocument();
     if (!isValid(metadata, false)) {
       throw new MalformedInputException("Name,type and value should be 
specified, input:" + ToStringBuilder.reflectionToString(metadata));
@@ -83,8 +84,8 @@ public class MetadataManager extends JsonManagerBase {
     solrInputDoc.addField(VALUE, metadata.getValue());
     solrInputDoc.addField(NAME, name);
     solrInputDoc.addField(TYPE, metadata.getType());
+    logger.info("Created metadata: name: {}, type: {}, user: {}", name, 
metadata.getType(), userName);
 
-    metadataSolrDao.addDocs(solrInputDoc);
     return solrInputDoc;
   }
 
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/MetadataResource.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/MetadataResource.java
index c91abbc..17103cc 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/MetadataResource.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/MetadataResource.java
@@ -19,13 +19,6 @@
 
 package org.apache.ambari.logsearch.rest;
 
-import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.DELETE_METADATA_OD;
-import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.DELETE_METADATA_LIST_OD;
-import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.GET_METADATA_OD;
-import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.GET_METADATA_LIST_OD;
-import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.SAVE_METADATA_LIST_OD;
-import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.SAVE_METADATA_OD;
-
 import java.util.Collection;
 
 import javax.inject.Inject;
@@ -36,7 +29,6 @@ import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 
 import org.apache.ambari.logsearch.manager.MetadataManager;
@@ -48,6 +40,13 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.Authorization;
 
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.DELETE_METADATA_OD;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.DELETE_METADATA_LIST_OD;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.GET_METADATA_OD;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.GET_METADATA_LIST_OD;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.SAVE_METADATA_LIST_OD;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.SAVE_METADATA_OD;
+
 @Api(value = "metadata", description = "Log Search metadata operations", 
authorizations = {@Authorization(value = "basicAuth")})
 @Path("metadata")
 @Named

Reply via email to