oleewere closed pull request #47: AMBARI-24939. Refactor logsearch_metadata 
schema and usage for logsearch portal
URL: https://github.com/apache/ambari-logsearch/pull/47
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/ambari-logsearch-config-solr/src/main/java/org/apache/ambari/logsearch/config/solr/LogLevelFilterManagerSolr.java
 
b/ambari-logsearch-config-solr/src/main/java/org/apache/ambari/logsearch/config/solr/LogLevelFilterManagerSolr.java
index 90005fa8be..8ebd5d27a4 100644
--- 
a/ambari-logsearch-config-solr/src/main/java/org/apache/ambari/logsearch/config/solr/LogLevelFilterManagerSolr.java
+++ 
b/ambari-logsearch-config-solr/src/main/java/org/apache/ambari/logsearch/config/solr/LogLevelFilterManagerSolr.java
@@ -62,10 +62,10 @@ public void createLogLevelFilter(String clusterName, String 
logId, LogLevelFilte
     if (useClusterParam) {
       doc.addField("cluster_string", clusterName);
     }
-    doc.addField("filtername", logId);
-    doc.addField("rowtype", "log_level_filter");
-    doc.addField("jsons", gson.toJson(filter));
-    doc.addField("username", "default");
+    doc.addField("name", logId);
+    doc.addField("type", "log_level_filter");
+    doc.addField("value", gson.toJson(filter));
+    doc.addField("username", "none");
     logger.debug("Creating log level filter - logid: {}, cluster: {}", logId, 
clusterName);
     solrClient.add(doc);
   }
@@ -112,16 +112,16 @@ public LogLevelFilterMap getLogLevelFilters(String 
clusterName) {
       if (useClusterParam) {
         solrQuery.addFilterQuery("cluster_string:" + clusterName);
       }
-      solrQuery.addFilterQuery("rowtype:log_level_filter");
-      solrQuery.setFields("jsons", "filtername");
+      solrQuery.addFilterQuery("type:log_level_filter");
+      solrQuery.setFields("value", "name");
 
       final QueryResponse response = solrClient.query(solrQuery);
       if (response != null) {
         final SolrDocumentList documents = response.getResults();
         if (documents != null && !documents.isEmpty()) {
           for(SolrDocument document : documents) {
-            String jsons = (String) document.getFieldValue("jsons");
-            String logId = (String) document.getFieldValue("filtername");
+            String jsons = (String) document.getFieldValue("value");
+            String logId = (String) document.getFieldValue("name");
             if (jsons != null) {
               LogLevelFilter logLevelFilter = gson.fromJson(jsons, 
LogLevelFilter.class);
               logLevelFilterTreeMap.put(logId,logLevelFilter);
@@ -149,13 +149,11 @@ public Gson getGson() {
   }
 
   private void waitForSolr(SolrClient solrClient) {
-    boolean solrAvailable = false;
-    while (!solrAvailable) {
+    while (true) {
       try {
         logger.debug("Start solr ping for log level filter collection");
         SolrPingResponse pingResponse = solrClient.ping();
         if (pingResponse.getStatus() == 0) {
-          solrAvailable = true;
           break;
         }
       } catch (Exception e) {
diff --git 
a/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/LogFeederConstants.java
 
b/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/LogFeederConstants.java
index 62c05333a4..b8e047d3e1 100644
--- 
a/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/LogFeederConstants.java
+++ 
b/ambari-logsearch-logfeeder/src/main/java/org/apache/ambari/logfeeder/common/LogFeederConstants.java
@@ -31,10 +31,6 @@
   public static final String SOLR_COMPONENT = "type";
   public static final String SOLR_HOST = "host";
 
-  // Event History Constants History
-  public static final String VALUES = "jsons";
-  public static final String ROW_TYPE = "rowtype";
-
   public static final String IN_MEMORY_TIMESTAMP = "in_memory_timestamp";
 
   public static final String LOGFEEDER_PROPERTIES_FILE = 
"logfeeder.properties";
diff --git 
a/ambari-logsearch-server/src/main/configsets/logsearch_metadata/conf/managed-schema
 
b/ambari-logsearch-server/src/main/configsets/logsearch_metadata/conf/managed-schema
index 76e3aea553..bebd95f559 100644
--- 
a/ambari-logsearch-server/src/main/configsets/logsearch_metadata/conf/managed-schema
+++ 
b/ambari-logsearch-server/src/main/configsets/logsearch_metadata/conf/managed-schema
@@ -80,12 +80,11 @@
   </fieldType>
 
   <field name="_version_" type="long" indexed="false" stored="true"/>
-  <field name="filtername" type="key_lower_case" indexed="true" 
required="true" stored="true"/>
   <field name="id" type="string" required="true"/>
-  <field name="jsons" type="string"/>
-  <field name="rowtype" type="string" required="true"/>
-  <field name="share_username_list" type="string" multiValued="true"/>
+  <field name="name" type="key_lower_case" indexed="true" required="true" 
stored="true"/>
   <field name="username" type="key_lower_case" indexed="true" required="true" 
stored="true"/>
+  <field name="type" type="string" required="true"/>
+  <field name="value" type="string"/>
   <field name="text" type="text_std_token_lower_case" multiValued="true" 
indexed="true" stored="false"/>
 
   <dynamicField name='ngram_*' type="n_gram" multiValued="false" 
stored="false"/>
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java
index a0c5aa9c19..23bd528cc8 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java
@@ -133,8 +133,9 @@
   public static final String REQUEST_PARAM_SOURCE_LOG_ID = "sourceLogId";
   public static final String REQUEST_PARAM_KEYWORD_TYPE = "keywordType";
   public static final String REQUEST_PARAM_TOKEN = "token";
-  public static final String REQUEST_PARAM_FILTER_NAME = "filterName";
-  public static final String REQUEST_PARAM_ROW_TYPE = "rowType";
+  public static final String REQUEST_PARAM_METADATA_NAME = "name";
+  public static final String REQUEST_PARAM_METADATA_TYPE = "type";
+  public static final String REQUEST_PARAM_METADATA_USER_NAME = "userName";
   public static final String REQUEST_PARAM_UTC_OFFSET = "utcOffset";
   public static final String REQUEST_PARAM_HOSTS = "hostList";
   public static final String REQUEST_PARAM_USERS = "userList";
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/converter/MetadataRequestQueryConverter.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/converter/MetadataRequestQueryConverter.java
index 10107707d0..085e4cca22 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/converter/MetadataRequestQueryConverter.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/converter/MetadataRequestQueryConverter.java
@@ -29,8 +29,8 @@
 import java.util.List;
 
 import static 
org.apache.ambari.logsearch.solr.SolrConstants.CommonLogConstants.CLUSTER;
-import static 
org.apache.ambari.logsearch.solr.SolrConstants.EventHistoryConstants.FILTER_NAME;
-import static 
org.apache.ambari.logsearch.solr.SolrConstants.EventHistoryConstants.ROW_TYPE;
+import static 
org.apache.ambari.logsearch.solr.SolrConstants.MetadataConstants.NAME;
+import static 
org.apache.ambari.logsearch.solr.SolrConstants.MetadataConstants.TYPE;
 
 @Named
 public class MetadataRequestQueryConverter extends 
AbstractConverterAware<MetadataRequest, SolrQuery> {
@@ -39,28 +39,18 @@
   public SolrQuery convert(MetadataRequest metadataRequest) {
     SolrQuery metadataQuery = new SolrQuery();
     metadataQuery.setQuery("*:*");
+    metadataQuery.addFilterQuery(String.format("%s:%s", TYPE, 
metadataRequest.getType()));
+    if (StringUtils.isNotBlank(metadataRequest.getName())) {
+      metadataQuery.addFilterQuery(String.format("%s:%s", NAME, 
metadataRequest.getName()));
+    }
 
-    int startIndex = StringUtils.isNotEmpty(metadataRequest.getStartIndex()) 
&& StringUtils.isNumeric(metadataRequest.getStartIndex())
-      ? Integer.parseInt(metadataRequest.getStartIndex()) : 0;
-    int maxRows = StringUtils.isNotEmpty(metadataRequest.getPageSize()) && 
StringUtils.isNumeric(metadataRequest.getPageSize())
-      ? Integer.parseInt(metadataRequest.getPageSize()) : 10;
-
-    SolrQuery.ORDER order = metadataRequest.getSortType() != null && 
SolrQuery.ORDER.desc.equals(SolrQuery.ORDER.valueOf(metadataRequest.getSortType()))
-      ? SolrQuery.ORDER.desc : SolrQuery.ORDER.asc;
-    String sortBy = StringUtils.isNotEmpty(metadataRequest.getSortBy()) ? 
metadataRequest.getSortBy() : FILTER_NAME;
-    String filterName = StringUtils.isBlank(metadataRequest.getFilterName()) ? 
"*" : "*" + metadataRequest.getFilterName() + "*";
-
-    metadataQuery.addFilterQuery(String.format("%s:%s", ROW_TYPE, 
metadataRequest.getRowType()));
-    metadataQuery.addFilterQuery(String.format("%s:%s", FILTER_NAME, 
SolrUtil.makeSearcableString(filterName)));
-    metadataQuery.setStart(startIndex);
-    metadataQuery.setRows(maxRows);
-
-    SolrQuery.SortClause sortOrder = SolrQuery.SortClause.create(sortBy, 
order);
+    SolrQuery.SortClause sortOrder = SolrQuery.SortClause.create(NAME, 
SolrQuery.ORDER.asc);
     List<SolrQuery.SortClause> sort = new ArrayList<>();
     sort.add(sortOrder);
+    metadataQuery.setRows(10000);
     metadataQuery.setSorts(sort);
 
-    SolrUtil.addListFilterToSolrQuery(metadataQuery, CLUSTER, 
metadataRequest.getClusters());
+    SolrUtil.addListFilterToSolrQuery(metadataQuery, CLUSTER + "_string", 
metadataRequest.getClusters());
 
     return metadataQuery;
   }
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 68218c1281..61f18b3b6f 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
@@ -89,8 +89,8 @@ public void postConstructor() {
     }
   }
 
-  public UpdateResponse deleteEventHistoryData(String id) {
-    return removeDoc("id:" + id);
+  public UpdateResponse deleteMetadata(String name, String type) {
+    return removeDoc(String.format("name:%s AND type:%s", name, type));
   }
 
   private UpdateResponse removeDoc(String query) {
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
index c2c6013740..21eb18f78d 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
@@ -113,16 +113,16 @@
     public static final String GET_ALL_SHIPPER_CONFIG_INFO_OD = "List all 
available shipper configuration element";
   }
 
-  public class EventHistoryDescriptions {
-    public static final String FILTER_NAME_D = "The saved query as filter in 
Solr, search is sopprted by this param";
-    public static final String ROW_TYPE_D = "Row type is solr to identify as 
filter query";
+  public class MetadataDescriptions {
+    public static final String NAME_D = "Name identifier of the metadata";
+    public static final String TYPE_D = "Type of the metadata";
+    public static final String USER_NAME_D = "User name of the metadata";
   }
 
-  public class EventHistoryOperationDescriptions {
+  public class MetadataOperationDescriptions {
     public static final String SAVE_METADATA_OD = "Save metadata";
     public static final String DELETE_METADATA_OD = "Delete metadata";
-    public static final String GET_METADATA_OD = "Get event metadata";
-    public static final String GET_ALL_USER_NAMES_OD = "Get all user names";
+    public static final String GET_METADATA_OD = "Get metadata";
   }
 
   public class ShipperConfigOperationDescriptions {
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 d98842e35f..95d2fd76f8 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
@@ -21,36 +21,29 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
+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.response.LogsearchMetaData;
-import 
org.apache.ambari.logsearch.model.response.LogSearchMetaDataListResponse;
-import org.apache.ambari.logsearch.util.SolrUtil;
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.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.common.SolrDocument;
 import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
 import org.springframework.core.convert.ConversionService;
 
 import javax.inject.Inject;
 import javax.inject.Named;
 
-import static 
org.apache.ambari.logsearch.solr.SolrConstants.EventHistoryConstants.ID;
-import static 
org.apache.ambari.logsearch.solr.SolrConstants.EventHistoryConstants.USER_NAME;
-import static 
org.apache.ambari.logsearch.solr.SolrConstants.EventHistoryConstants.VALUES;
-import static 
org.apache.ambari.logsearch.solr.SolrConstants.EventHistoryConstants.FILTER_NAME;
-import static 
org.apache.ambari.logsearch.solr.SolrConstants.EventHistoryConstants.ROW_TYPE;
-import static 
org.apache.ambari.logsearch.solr.SolrConstants.EventHistoryConstants.SHARE_NAME_LIST;
+import static 
org.apache.ambari.logsearch.solr.SolrConstants.MetadataConstants.ID;
+import static 
org.apache.ambari.logsearch.solr.SolrConstants.MetadataConstants.USER_NAME;
+import static 
org.apache.ambari.logsearch.solr.SolrConstants.MetadataConstants.VALUE;
+import static 
org.apache.ambari.logsearch.solr.SolrConstants.MetadataConstants.NAME;
+import static 
org.apache.ambari.logsearch.solr.SolrConstants.MetadataConstants.TYPE;
 
 @Named
 public class MetadataManager extends JsonManagerBase {
@@ -63,120 +56,73 @@
   private ConversionService conversionService;
 
   public String saveMetadata(LogsearchMetaData metadata) {
-    String filterName = metadata.getFiltername();
+    String name = metadata.getName();
 
     SolrInputDocument solrInputDoc = new SolrInputDocument();
-    if (!isValid(metadata)) {
-      throw new MalformedInputException("No FilterName Specified");
-    }
-
-    if (isNotUnique(filterName)) {
-      throw new AlreadyExistsException(String.format("Name '%s' already 
exists", metadata.getFiltername()));
-    }
-    solrInputDoc.addField(ID, metadata.getId());
-    solrInputDoc.addField(USER_NAME, LogSearchContext.getCurrentUsername());
-    solrInputDoc.addField(VALUES, metadata.getValues());
-    solrInputDoc.addField(FILTER_NAME, filterName);
-    solrInputDoc.addField(ROW_TYPE, metadata.getRowType());
-    List<String> shareNameList = metadata.getShareNameList();
-    if (CollectionUtils.isNotEmpty(shareNameList)) {
-      solrInputDoc.addField(SHARE_NAME_LIST, shareNameList);
+    if (!isValid(metadata, false)) {
+      throw new MalformedInputException("Name,type and value should be 
specified");
     }
+    final String userName = 
LogSearchContext.getCurrentUsername().toLowerCase();
+    solrInputDoc.addField(ID, generateUniqueId(metadata, userName));
+    solrInputDoc.addField(USER_NAME, userName);
+    solrInputDoc.addField(VALUE, metadata.getValue());
+    solrInputDoc.addField(NAME, name);
+    solrInputDoc.addField(TYPE, metadata.getType());
 
     metadataSolrDao.addDocs(solrInputDoc);
     return convertObjToString(solrInputDoc);
   }
 
-  private boolean isNotUnique(String filterName) {
-
-    if (filterName != null) {
-      SolrQuery solrQuery = new SolrQuery();
-      filterName = SolrUtil.makeSearcableString(filterName);
-      solrQuery.setQuery("*:*");
-      solrQuery.addFilterQuery(FILTER_NAME + ":" + filterName);
-      solrQuery.addFilterQuery(USER_NAME + ":" + 
LogSearchContext.getCurrentUsername());
-      SolrUtil.setRowCount(solrQuery, 0);
-      try {
-        Long numFound = 
metadataSolrDao.process(solrQuery).getResults().getNumFound();
-        if (numFound > 0) {
-          return true;
-        }
-      } catch (SolrException e) {
-        logger.error("Error while checking if metadata is unique.", e);
-      }
+  public void deleteMetadata(LogsearchMetaData metaData) {
+    if (!isValid(metaData, true)) {
+      throw new MalformedInputException("Name and type should be specified");
     }
-    return false;
-  }
-
-  private boolean isValid(LogsearchMetaData mData) {
-    return StringUtils.isNotBlank(mData.getFiltername())
-        && StringUtils.isNotBlank(mData.getRowType())
-        && StringUtils.isNotBlank(mData.getValues());
-  }
-
-  public void deleteMetadata(String id) {
-    metadataSolrDao.deleteEventHistoryData(id);
+    metadataSolrDao.deleteMetadata(metaData.getName(), metaData.getType());
   }
 
   @SuppressWarnings("unchecked")
-  public LogSearchMetaDataListResponse getMetadata(MetadataRequest request) {
-    LogSearchMetaDataListResponse response = new 
LogSearchMetaDataListResponse();
-    String rowType = request.getRowType();
-    if (StringUtils.isBlank(rowType)) {
-      throw new MalformedInputException("Row type was not specified");
-    }
-
+  public Collection<LogsearchMetaData> getMetadata(MetadataRequest request) {
     SolrQuery metadataQueryQuery = conversionService.convert(request, 
SolrQuery.class);
-    metadataQueryQuery.addFilterQuery(String.format("%s:%s OR %s:%s", 
USER_NAME, LogSearchContext.getCurrentUsername(),
-        SHARE_NAME_LIST, LogSearchContext.getCurrentUsername()));
+
+    final String userName;
+    if (StringUtils.isNotBlank(request.getUserName())) {
+      userName = request.getUserName();
+    } else {
+      userName = LogSearchContext.getCurrentUsername();
+    }
+    if (StringUtils.isBlank(userName)) {
+      throw new IllegalArgumentException("User name is not found for metadata 
request.");
+    }
+    metadataQueryQuery.addFilterQuery(String.format("%s:%s", USER_NAME, 
userName.toLowerCase()));
     SolrDocumentList solrList = 
metadataSolrDao.process(metadataQueryQuery).getResults();
 
-    Collection<LogsearchMetaData> configList = new ArrayList<>();
+    Collection<LogsearchMetaData> metadataList = new ArrayList<>();
 
     for (SolrDocument solrDoc : solrList) {
       LogsearchMetaData metadata = new LogsearchMetaData();
-      metadata.setFiltername("" + solrDoc.get(FILTER_NAME));
-      metadata.setId("" + solrDoc.get(ID));
-      metadata.setValues("" + solrDoc.get(VALUES));
-      metadata.setRowType("" + solrDoc.get(ROW_TYPE));
-      try {
-        List<String> shareNameList = (List<String>) 
solrDoc.get(SHARE_NAME_LIST);
-        metadata.setShareNameList(shareNameList);
-      } catch (Exception e) {
-        // do nothing
-      }
-
-      metadata.setUserName("" + solrDoc.get(USER_NAME));
-
-      configList.add(metadata);
-    }
-
-    response.setName("metadataList");
-    response.setMetadataList(configList);
+      metadata.setName(solrDoc.get(NAME).toString());
+      metadata.setId(solrDoc.get(ID).toString());
+      metadata.setValue(solrDoc.getOrDefault(VALUE, "").toString());
+      metadata.setType(solrDoc.get(TYPE).toString());
+      metadata.setUserName(solrDoc.get(USER_NAME).toString());
 
-    response.setStartIndex(Integer.parseInt(request.getStartIndex()));
-    response.setPageSize(Integer.parseInt(request.getPageSize()));
+      metadataList.add(metadata);
+    }
 
-    response.setTotalCount(solrList.getNumFound());
+    return metadataList;
 
-    return response;
+  }
 
+  private String generateUniqueId(LogsearchMetaData metaData, String userName) 
{
+    String strToUUID = metaData.getName() +
+      metaData.getType() +
+      userName;
+    return UUID.nameUUIDFromBytes(strToUUID.getBytes()).toString();
   }
 
-  public List<String> getAllUserName() {
-    List<String> userList = new ArrayList<>();
-    SolrQuery userListQuery = new SolrQuery();
-    userListQuery.setQuery("*:*");
-    SolrUtil.setFacetField(userListQuery, USER_NAME);
-    QueryResponse queryResponse = metadataSolrDao.process(userListQuery);
-    if (queryResponse == null) {
-      return userList;
-    }
-    List<Count> counList = queryResponse.getFacetField(USER_NAME).getValues();
-    for (Count cnt : counList) {
-      String userName = cnt.getName();
-      userList.add(userName);
-    }
-    return userList;
+  private boolean isValid(LogsearchMetaData mData, boolean skipValueCheck) {
+    return StringUtils.isNotBlank(mData.getName())
+      && StringUtils.isNotBlank(mData.getType())
+      && (skipValueCheck || StringUtils.isNotBlank(mData.getValue()));
   }
 }
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/MetadataParamDefinition.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/MetadataParamDefinition.java
index 39375df7ae..8a579b84d1 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/MetadataParamDefinition.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/MetadataParamDefinition.java
@@ -21,18 +21,24 @@
 import io.swagger.annotations.ApiParam;
 import org.apache.ambari.logsearch.common.LogSearchConstants;
 
-import static 
org.apache.ambari.logsearch.doc.DocConstants.EventHistoryDescriptions.FILTER_NAME_D;
-import static 
org.apache.ambari.logsearch.doc.DocConstants.EventHistoryDescriptions.ROW_TYPE_D;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataDescriptions.NAME_D;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataDescriptions.TYPE_D;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataDescriptions.USER_NAME_D;
 
 public interface MetadataParamDefinition {
 
-  String getFilterName();
+  String getName();
 
-  @ApiParam(value = FILTER_NAME_D, name = 
LogSearchConstants.REQUEST_PARAM_FILTER_NAME)
-  void setFilterName(String filterName);
+  @ApiParam(value = NAME_D, name = 
LogSearchConstants.REQUEST_PARAM_METADATA_NAME)
+  void setName(String name);
 
-  String getRowType();
+  String getType();
 
-  @ApiParam(value = ROW_TYPE_D, name = 
LogSearchConstants.REQUEST_PARAM_ROW_TYPE)
-  void setRowType(String rowType);
+  @ApiParam(value = TYPE_D, name = 
LogSearchConstants.REQUEST_PARAM_METADATA_TYPE)
+  void setType(String type);
+
+  String getUserName();
+
+  @ApiParam(value = USER_NAME_D, name = 
LogSearchConstants.REQUEST_PARAM_METADATA_USER_NAME)
+  void setUserName(String userName);
 }
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/MetadataRequest.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/MetadataRequest.java
index 3a2c1e6c4f..d3acb4e5ba 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/MetadataRequest.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/MetadataRequest.java
@@ -19,8 +19,9 @@
 package org.apache.ambari.logsearch.model.request.impl;
 
 import org.apache.ambari.logsearch.common.Marker;
+import org.apache.ambari.logsearch.model.request.ClustersParamDefinition;
 import org.apache.ambari.logsearch.model.request.MetadataParamDefinition;
 
 @Marker
-public interface MetadataRequest extends CommonSearchRequest, 
MetadataParamDefinition {
+public interface MetadataRequest extends MetadataParamDefinition, 
ClustersParamDefinition {
 }
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/query/MetadataQueryRequest.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/query/MetadataQueryRequest.java
index ec55d9c253..391f5a239f 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/query/MetadataQueryRequest.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/request/impl/query/MetadataQueryRequest.java
@@ -21,33 +21,64 @@
 import org.apache.ambari.logsearch.common.LogSearchConstants;
 import org.apache.ambari.logsearch.model.request.impl.MetadataRequest;
 
+import javax.annotation.Nullable;
+import javax.validation.constraints.NotNull;
 import javax.ws.rs.QueryParam;
 
-public class MetadataQueryRequest extends CommonSearchQueryRequest implements 
MetadataRequest {
+public class MetadataQueryRequest implements MetadataRequest {
 
-  @QueryParam(LogSearchConstants.REQUEST_PARAM_FILTER_NAME)
-  private String filterName;
+  @QueryParam(LogSearchConstants.REQUEST_PARAM_METADATA_NAME)
+  private String name;
 
-  @QueryParam(LogSearchConstants.REQUEST_PARAM_ROW_TYPE)
-  private String rowType;
+  @QueryParam(LogSearchConstants.REQUEST_PARAM_METADATA_TYPE)
+  @NotNull
+  private String type;
+
+  @QueryParam(LogSearchConstants.REQUEST_PARAM_METADATA_USER_NAME)
+  private String userName;
+
+  @Nullable
+  @QueryParam(LogSearchConstants.REQUEST_PARAM_CLUSTER_NAMES)
+  private String clusters;
+
+  @Override
+  public String getName() {
+    return name;
+  }
+
+  @Override
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  @Override
+  public String getType() {
+    return type;
+  }
+
+  @Override
+  public void setType(String type) {
+    this.type = type;
+  }
 
   @Override
-  public String getFilterName() {
-    return filterName;
+  public String getUserName() {
+    return userName;
   }
 
   @Override
-  public void setFilterName(String filterName) {
-    this.filterName = filterName;
+  public void setUserName(String userName) {
+    this.userName = userName;
   }
 
   @Override
-  public String getRowType() {
-    return rowType;
+  @Nullable
+  public String getClusters() {
+    return clusters;
   }
 
   @Override
-  public void setRowType(String rowType) {
-    this.rowType = rowType;
+  public void setClusters(@Nullable String clusters) {
+    this.clusters = clusters;
   }
 }
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/LogSearchMetaDataListResponse.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/LogSearchMetaDataListResponse.java
deleted file mode 100644
index 04523c2b36..0000000000
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/LogSearchMetaDataListResponse.java
+++ /dev/null
@@ -1,55 +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.model.response;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
-import java.util.Collection;
-
-@ApiModel
-public class LogSearchMetaDataListResponse extends SearchResponse{
-
-  @ApiModelProperty
-  private String name;
-
-  @ApiModelProperty
-  private Collection<LogsearchMetaData> metadataList;
-
-  public String getName() {
-    return name;
-  }
-
-  public void setName(String name) {
-    this.name = name;
-  }
-
-  public Collection<LogsearchMetaData> getMetadataList() {
-    return metadataList;
-  }
-
-  public void setMetadataList(Collection<LogsearchMetaData> metadataList) {
-    this.metadataList = metadataList;
-  }
-
-  @Override
-  public int getListSize() {
-    return metadataList != null ? metadataList.size() : 0;
-  }
-}
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/LogsearchMetaData.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/LogsearchMetaData.java
index be5164b18f..2a0763ffe3 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/LogsearchMetaData.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/model/response/LogsearchMetaData.java
@@ -21,7 +21,6 @@
 import io.swagger.annotations.ApiModelProperty;
 
 import java.util.Date;
-import java.util.List;
 
 public class LogsearchMetaData {
 
@@ -32,16 +31,13 @@
   private String userName;
 
   @ApiModelProperty
-  private String filtername;
+  private String name;
 
   @ApiModelProperty
-  private String values;
+  private String value;
 
   @ApiModelProperty
-  private List<String> shareNameList;
-
-  @ApiModelProperty
-  private String rowType;
+  private String type;
 
   public LogsearchMetaData() {
     id = String.valueOf(new Date().getTime());
@@ -63,35 +59,27 @@ public void setUserName(String userName) {
     this.userName = userName;
   }
 
-  public String getFiltername() {
-    return filtername;
-  }
-
-  public void setFiltername(String filtername) {
-    this.filtername = filtername;
-  }
-
-  public List<String> getShareNameList() {
-    return shareNameList;
+  public String getName() {
+    return name;
   }
 
-  public void setShareNameList(List<String> shareNameList) {
-    this.shareNameList = shareNameList;
+  public void setName(String name) {
+    this.name = name;
   }
 
-  public String getValues() {
-    return values;
+  public String getValue() {
+    return value;
   }
 
-  public void setValues(String values) {
-    this.values = values;
+  public void setValue(String value) {
+    this.value = value;
   }
 
-  public String getRowType() {
-    return rowType;
+  public String getType() {
+    return type;
   }
 
-  public void setRowType(String rowType) {
-    this.rowType = rowType;
+  public void setType(String type) {
+    this.type = type;
   }
 }
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 e6ce11f7f6..c0f256cb58 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,15 +19,15 @@
 
 package org.apache.ambari.logsearch.rest;
 
-import static 
org.apache.ambari.logsearch.doc.DocConstants.EventHistoryOperationDescriptions.DELETE_METADATA_OD;
-import static 
org.apache.ambari.logsearch.doc.DocConstants.EventHistoryOperationDescriptions.GET_ALL_USER_NAMES_OD;
-import static 
org.apache.ambari.logsearch.doc.DocConstants.EventHistoryOperationDescriptions.GET_METADATA_OD;
-import static 
org.apache.ambari.logsearch.doc.DocConstants.EventHistoryOperationDescriptions.SAVE_METADATA_OD;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.DELETE_METADATA_OD;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.GET_METADATA_OD;
+import static 
org.apache.ambari.logsearch.doc.DocConstants.MetadataOperationDescriptions.SAVE_METADATA_OD;
 
-import java.util.List;
+import java.util.Collection;
 
 import javax.inject.Inject;
 import javax.inject.Named;
+import javax.validation.Valid;
 import javax.ws.rs.BeanParam;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -39,7 +39,6 @@
 import org.apache.ambari.logsearch.manager.MetadataManager;
 import 
org.apache.ambari.logsearch.model.request.impl.query.MetadataQueryRequest;
 import org.apache.ambari.logsearch.model.response.LogsearchMetaData;
-import 
org.apache.ambari.logsearch.model.response.LogSearchMetaDataListResponse;
 import org.springframework.context.annotation.Scope;
 
 import io.swagger.annotations.Api;
@@ -63,25 +62,16 @@ public String saveMetadata(LogsearchMetaData metadata) {
   }
 
   @DELETE
-  @Path("/{id}")
   @ApiOperation(DELETE_METADATA_OD)
-  public void deleteMetadata(@PathParam("id") String id) {
-    metadataManager.deleteMetadata(id);
+  public void deleteMetadata(LogsearchMetaData metadata) {
+    metadataManager.deleteMetadata(metadata);
   }
 
   @GET
   @Produces({"application/json"})
   @ApiOperation(GET_METADATA_OD)
-  public LogSearchMetaDataListResponse getMetadataList(@BeanParam 
MetadataQueryRequest request) {
+  public Collection<LogsearchMetaData> getMetadataList(@Valid @BeanParam 
MetadataQueryRequest request) {
     return metadataManager.getMetadata(request);
   }
 
-  @GET
-  @Path("/names")
-  @Produces({"application/json"})
-  @ApiOperation(GET_ALL_USER_NAMES_OD)
-  public List<String> getAllUserName() {
-    return metadataManager.getAllUserName();
-  }
-
 }
diff --git 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/solr/SolrConstants.java
 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/solr/SolrConstants.java
index a999f930d1..899ad11218 100644
--- 
a/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/solr/SolrConstants.java
+++ 
b/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/solr/SolrConstants.java
@@ -105,15 +105,14 @@ private AuditLogConstants() {
     public static final String AUDIT_TAGS_STR = "tags_str";
   }
 
-  public class EventHistoryConstants {
-    private EventHistoryConstants() {
+  public class MetadataConstants {
+    private MetadataConstants() {
     }
 
     public static final String ID = "id";
     public static final String USER_NAME = "username";
-    public static final String VALUES = "jsons";
-    public static final String FILTER_NAME = "filtername";
-    public static final String ROW_TYPE = "rowtype";
-    public static final String SHARE_NAME_LIST = "share_username_list";
+    public static final String VALUE = "value";
+    public static final String NAME = "name";
+    public static final String TYPE = "type";
   }
 }
diff --git 
a/ambari-logsearch-server/src/test/java/org/apache/ambari/logsearch/converter/MetadataRequestQueryConverterTest.java
 
b/ambari-logsearch-server/src/test/java/org/apache/ambari/logsearch/converter/MetadataRequestQueryConverterTest.java
index b30fdd4ba4..e29bcc77e3 100644
--- 
a/ambari-logsearch-server/src/test/java/org/apache/ambari/logsearch/converter/MetadataRequestQueryConverterTest.java
+++ 
b/ambari-logsearch-server/src/test/java/org/apache/ambari/logsearch/converter/MetadataRequestQueryConverterTest.java
@@ -39,13 +39,14 @@ public void setUp() {
   public void testConvert() {
     // GIVEN
     MetadataRequest request = new MetadataQueryRequest();
-    request.setRowType("myRowType"); // TODO: validate these 3 fields @Valid 
on EventHistoryRequest object -> not null
-    request.setFilterName("myFilterName");
+    request.setType("myRowType");
+    request.setName("myFilterName");
+    request.setUserName("myUserName");
     request.setClusters("cl1,cl2");
     // WHEN
     SolrQuery queryResult = underTest.convert(request);
     // THEN
-    
assertEquals("?q=*%3A*&fq=rowtype%3AmyRowType&fq=filtername%3A*myFilterName*&fq=cluster%3A%28cl1+OR+cl2%29&start=0&rows=10&sort=filtername+asc",
+    
assertEquals("?q=*%3A*&fq=type%3AmyRowType&fq=name%3AmyFilterName&fq=cluster_string%3A%28cl1+OR+cl2%29&rows=10000&sort=name+asc",
       queryResult.toQueryString());
   }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to