ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oleew...@apache.org
Subject [ambari] branch trunk updated: AMBARI-22855. Log Search: using shipperconfig api should be configurable
Date Mon, 29 Jan 2018 10:46:46 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/trunk by this push:
     new b3395b4  AMBARI-22855. Log Search: using shipperconfig api should be configurable
b3395b4 is described below

commit b3395b43878ab9ee274f39d06d48c98a32f0a1e2
Author: Oliver Szabo <oleewere@gmail.com>
AuthorDate: Fri Jan 26 19:32:24 2018 +0100

    AMBARI-22855. Log Search: using shipperconfig api should be configurable
---
 .../ambari/logsearch/common/MessageEnums.java      |  2 +-
 .../logsearch/conf/LogSearchConfigApiConfig.java   | 47 ++++++++++++++++++++++
 .../ambari/logsearch/conf/LogSearchSslConfig.java  |  2 +-
 .../ambari/logsearch/conf/SecurityConfig.java      |  7 +++-
 .../configurer/LogSearchConfigConfigurer.java      | 12 +++++-
 .../apache/ambari/logsearch/dao/SolrDaoBase.java   | 16 ++++++--
 .../apache/ambari/logsearch/doc/DocConstants.java  |  1 +
 .../logsearch/handler/CreateCollectionHandler.java |  2 +-
 .../ambari/logsearch/manager/InfoManager.java      | 12 +++++-
 .../apache/ambari/logsearch/rest/InfoResource.java | 25 ++++++++----
 .../web/filters/LogSearchConfigStateFilter.java    | 13 ++++--
 11 files changed, 117 insertions(+), 22 deletions(-)

diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java
index 9dd8b34..228f1c6 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/MessageEnums.java
@@ -34,7 +34,7 @@ public enum MessageEnums {
   ZK_CONFIG_NOT_READY("logsearch.zk.config.error", "Collection configuration has not uploaded
yet"),
   SOLR_COLLECTION_NOT_READY("logsearch.solr.collection.error", "Solr has not accessible yet
for collection."),
   CONFIGURATION_NOT_AVAILABLE("logsearch.config.not_available", "Log Search configuration
is not available"),
-  
+  CONFIGURATION_API_DISABLED("logsearch.config.api.disabled", "Log Search configuration is
not available"),
   // Common Validations
   INVALID_PASSWORD("logsearch.validation.invalid_password", "Invalid password"),
   INVALID_INPUT_DATA("logsearch.validation.invalid_input_data", "Invalid input data"),
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchConfigApiConfig.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchConfigApiConfig.java
new file mode 100644
index 0000000..6e16179
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchConfigApiConfig.java
@@ -0,0 +1,47 @@
+/*
+ * 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.conf;
+
+import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE;
+
+@Configuration
+public class LogSearchConfigApiConfig {
+
+  @Value("${logsearch.config.api.enabled:true}")
+  @LogSearchPropertyDescription(
+    name = "logsearch.config.api.enabled",
+    description = "Enable config API feature and shipperconfig API endpoints.",
+    examples = {"false"},
+    defaultValue = "true",
+    sources = {LOGSEARCH_PROPERTIES_FILE}
+  )
+  private boolean configApiEnabled;
+
+  public boolean isConfigApiEnabled() {
+    return configApiEnabled;
+  }
+
+  public void setConfigApiEnabled(boolean configApiEnabled) {
+    this.configApiEnabled = configApiEnabled;
+  }
+}
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSslConfig.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSslConfig.java
index afa2293..15579b6 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSslConfig.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSslConfig.java
@@ -27,7 +27,7 @@ import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PR
 @Configuration
 public class LogSearchSslConfig {
 
-  public static final String LOGSEARCH_CERT_DEFAULT_FOLDER = "/etc/ambari-logsearch-portal/conf/keys";
+  public static final String LOGSEARCH_CERT_DEFAULT_FOLDER = "/usr/lib/ambari-logsearch-portal/conf/keys";
   public static final String LOGSEARCH_CERT_DEFAULT_ALGORITHM = "sha256WithRSA";
   public static final String CREDENTIAL_STORE_PROVIDER_PATH = "hadoop.security.credential.provider.path";
 
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
index 6f8d7ba..c996195 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
@@ -22,6 +22,7 @@ import com.google.common.collect.Lists;
 
 import org.apache.ambari.logsearch.conf.global.LogSearchConfigState;
 import org.apache.ambari.logsearch.conf.global.SolrCollectionState;
+import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription;
 import org.apache.ambari.logsearch.web.authenticate.LogsearchAuthFailureHandler;
 import org.apache.ambari.logsearch.web.authenticate.LogsearchAuthSuccessHandler;
 import org.apache.ambari.logsearch.web.authenticate.LogsearchLogoutSuccessHandler;
@@ -43,7 +44,6 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 import org.springframework.security.config.http.SessionCreationPolicy;
 import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
-import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
 import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
 import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
 import org.springframework.security.web.util.matcher.OrRequestMatcher;
@@ -89,6 +89,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
   @Inject
   private LogSearchConfigState logSearchConfigState;
 
+  @Inject
+  private LogSearchConfigApiConfig logSearchConfigApiConfig;
+
   @Override
   protected void configure(HttpSecurity http) throws Exception {
     http
@@ -184,7 +187,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
 
   @Bean
   public LogSearchConfigStateFilter logSearchConfigStateFilter() {
-    return new LogSearchConfigStateFilter(logsearchConfigRequestMatcher(), logSearchConfigState);
+    return new LogSearchConfigStateFilter(logsearchConfigRequestMatcher(), logSearchConfigState,
logSearchConfigApiConfig.isConfigApiEnabled());
   }
 
   @Bean
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/configurer/LogSearchConfigConfigurer.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/configurer/LogSearchConfigConfigurer.java
index baf5adb..fc71409 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/configurer/LogSearchConfigConfigurer.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/configurer/LogSearchConfigConfigurer.java
@@ -23,6 +23,7 @@ import javax.annotation.PostConstruct;
 import javax.inject.Inject;
 import javax.inject.Named;
 
+import org.apache.ambari.logsearch.conf.LogSearchConfigApiConfig;
 import org.apache.ambari.logsearch.conf.LogSearchConfigMapHolder;
 import org.apache.ambari.logsearch.conf.global.LogSearchConfigState;
 import org.apache.ambari.logsearch.config.api.LogSearchConfigFactory;
@@ -48,6 +49,9 @@ public class LogSearchConfigConfigurer implements Configurer {
   @Inject
   private LogSearchConfigMapHolder logSearchConfigMapHolder;
 
+  @Inject
+  private LogSearchConfigApiConfig logSearchConfigApiConfig;
+
   @PostConstruct
   @Override
   public void start() {
@@ -57,9 +61,13 @@ public class LogSearchConfigConfigurer implements Configurer {
         logger.info("Started thread to set up log search config");
         while (true) {
           try {
-            logSearchConfig = LogSearchConfigFactory.createLogSearchConfigServer(logSearchConfigMapHolder.getLogsearchProperties(),
+            if (logSearchConfigApiConfig.isConfigApiEnabled()) {
+              logSearchConfig = LogSearchConfigFactory.createLogSearchConfigServer(logSearchConfigMapHolder.getLogsearchProperties(),
                 LogSearchConfigServerZK.class);
-            logSearchConfigState.setLogSearchConfigAvailable(true);
+              logSearchConfigState.setLogSearchConfigAvailable(true);
+            } else {
+              logger.info("Config API is disabled. Shipper configs won't be accessible from
the Rest API.");
+            }
             break;
           } catch (Exception e) {
             logger.warn("Could not initialize Log Search config, going to sleep for " + RETRY_INTERVAL_SECONDS
+ " seconds ", e);
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
index 05217d9..218d1a0 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/dao/SolrDaoBase.java
@@ -22,6 +22,7 @@ package org.apache.ambari.logsearch.dao;
 import org.apache.ambari.logsearch.common.LogSearchContext;
 import org.apache.ambari.logsearch.common.LogType;
 import org.apache.ambari.logsearch.common.MessageEnums;
+import org.apache.ambari.logsearch.conf.LogSearchConfigApiConfig;
 import org.apache.ambari.logsearch.conf.SolrKerberosConfig;
 import org.apache.ambari.logsearch.conf.SolrPropsConfig;
 import org.apache.ambari.logsearch.conf.global.LogSearchConfigState;
@@ -61,6 +62,9 @@ public abstract class SolrDaoBase {
   private LogSearchConfigState logSearchConfigState;
 
   @Inject
+  private LogSearchConfigApiConfig logSearchConfigApiConfig;
+
+  @Inject
   private LogSearchConfigConfigurer logSearchConfigConfigurer;
 
   protected SolrDaoBase(LogType logType) {
@@ -68,9 +72,15 @@ public abstract class SolrDaoBase {
   }
 
   public void waitForLogSearchConfig() {
-    while (!logSearchConfigState.isLogSearchConfigAvailable()) {
-      LOG.info("Log Search config not available yet, waiting...");
-      try { Thread.sleep(1000); } catch (Exception e) { LOG.warn("Exception during waiting
for Log Search Config", e); }
+    if (logSearchConfigApiConfig.isConfigApiEnabled()) {
+      while (!logSearchConfigState.isLogSearchConfigAvailable()) {
+        LOG.info("Log Search config not available yet, waiting...");
+        try {
+          Thread.sleep(1000);
+        } catch (Exception e) {
+          LOG.warn("Exception during waiting for Log Search Config", e);
+        }
+      }
     }
   }
 
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
index 34e923f..5ab9265 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/doc/DocConstants.java
@@ -101,6 +101,7 @@ public class DocConstants {
   }
 
   public class PublicOperationDescriptions {
+    public static final String GET_FEATURES_LIST = "Get features list.";
     public static final String GET_APP_DETAILS_OD = "Get application details.";
     public static final String GET_AUTH_DETAILS_OD = "Get authentication details.";
     public static final String GET_ALL_PROPERTIES_INFO_OD = "List all available properties
for Log Search and Log Feeder";
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/handler/CreateCollectionHandler.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/handler/CreateCollectionHandler.java
index 6c259cd..c3a5956 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/handler/CreateCollectionHandler.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/handler/CreateCollectionHandler.java
@@ -88,7 +88,7 @@ public class CreateCollectionHandler implements SolrZkRequestHandler<Boolean>
{
     // Default is true, because if the collection and shard is already there, then it will
return true
     boolean returnValue = true;
 
-    List<String> shardsList = new ArrayList<String>();
+    List<String> shardsList = new ArrayList<>();
     for (int i = 0; i < solrPropsConfig.getNumberOfShards(); i++) {
       shardsList.add("shard" + i);
     }
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/InfoManager.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/InfoManager.java
index c17f24a..26907fa 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/InfoManager.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/manager/InfoManager.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import org.apache.ambari.logsearch.conf.AuthPropsConfig;
 import org.apache.ambari.logsearch.common.PropertyDescriptionStorage;
 import org.apache.ambari.logsearch.common.ShipperConfigDescriptionStorage;
+import org.apache.ambari.logsearch.conf.LogSearchConfigApiConfig;
 import org.apache.ambari.logsearch.model.response.PropertyDescriptionData;
 import org.apache.ambari.logsearch.model.response.ShipperConfigDescriptionData;
 import org.springframework.beans.factory.annotation.Value;
@@ -45,11 +46,13 @@ public class InfoManager extends JsonManagerBase {
   @Value("${java.runtime.version}")
   private String javaRuntimeVersion;
 
-
   @Inject
   private AuthPropsConfig authPropsConfig;
 
   @Inject
+  private LogSearchConfigApiConfig logSearchConfigApiConfig;
+
+  @Inject
   private PropertyDescriptionStorage propertyDescriptionStore;
 
   @Inject
@@ -73,6 +76,13 @@ public class InfoManager extends JsonManagerBase {
     return authMap;
   }
 
+  public Map<String, Object> getFeaturesMap() {
+    Map<String, Object> featuresMap = new HashMap<>();
+    featuresMap.put("auth", getAuthMap());
+    featuresMap.put("config_api", logSearchConfigApiConfig.isConfigApiEnabled());
+    return featuresMap;
+  }
+
   public Map<String, List<PropertyDescriptionData>> getPropertyDescriptions()
{
     return propertyDescriptionStore.getPropertyDescriptions();
   }
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/InfoResource.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/InfoResource.java
index 9507c25..52ecdca 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/InfoResource.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/rest/InfoResource.java
@@ -38,6 +38,7 @@ import java.util.Map;
 import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.GET_ALL_PROPERTIES_INFO_OD;
 import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.GET_ALL_SHIPPER_CONFIG_INFO_OD;
 import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.GET_APP_DETAILS_OD;
+import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.GET_FEATURES_LIST;
 import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.GET_LOGSEARCH_PROPERTIES_INFO_OD;
 import static org.apache.ambari.logsearch.doc.DocConstants.PublicOperationDescriptions.GET_AUTH_DETAILS_OD;
 
@@ -58,14 +59,6 @@ public class InfoResource {
   }
 
   @GET
-  @Path("/auth")
-  @Produces({"application/json"})
-  @ApiOperation(GET_AUTH_DETAILS_OD)
-  public Map<String, Boolean> getAuthInfo() {
-    return infoManager.getAuthMap();
-  }
-
-  @GET
   @Path("/properties")
   @Produces({"application/json"})
   @ApiOperation(GET_ALL_PROPERTIES_INFO_OD)
@@ -82,6 +75,22 @@ public class InfoResource {
   }
 
   @GET
+  @Path("/features")
+  @Produces({"application/json"})
+  @ApiOperation(GET_FEATURES_LIST)
+  public Map<String, Object> getFeatures() {
+    return infoManager.getFeaturesMap();
+  }
+
+  @GET
+  @Path("/features/auth")
+  @Produces({"application/json"})
+  @ApiOperation(GET_AUTH_DETAILS_OD)
+  public Map<String, Boolean> getAuthInfo() {
+    return infoManager.getAuthMap();
+  }
+
+  @GET
   @Path("/shipperconfig")
   @Produces({"application/json"})
   @ApiOperation(GET_ALL_SHIPPER_CONFIG_INFO_OD)
diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/filters/LogSearchConfigStateFilter.java
b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/filters/LogSearchConfigStateFilter.java
index 9b6cdfe..aa1e20d 100644
--- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/filters/LogSearchConfigStateFilter.java
+++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/web/filters/LogSearchConfigStateFilter.java
@@ -47,13 +47,16 @@ public class LogSearchConfigStateFilter implements Filter {
   private static final Logger LOG = LoggerFactory.getLogger(LogSearchConfigStateFilter.class);
 
   private static final String CONFIG_NOT_AVAILABLE = "Configuration is not available";
+  private static final String CONFIG_API_DISABLED = "Configuration API is disabled";
 
   private final RequestMatcher requestMatcher;
   private final LogSearchConfigState logSearchConfigState;
+  private final boolean enabled;
   
-  public LogSearchConfigStateFilter(RequestMatcher requestMatcher, LogSearchConfigState logSearchConfigState)
{
+  public LogSearchConfigStateFilter(RequestMatcher requestMatcher, LogSearchConfigState logSearchConfigState,
boolean enabled) {
     this.requestMatcher = requestMatcher;
     this.logSearchConfigState = logSearchConfigState;
+    this.enabled = enabled;
   }
 
   @Override
@@ -67,9 +70,10 @@ public class LogSearchConfigStateFilter implements Filter {
     if (requestMatcher.matches(request)) {
       VResponse errorResponse = getErrorResponse();
       if (errorResponse != null) {
-        LOG.info("{} request is filtered out: {}", request.getRequestURL(), errorResponse.getMsgDesc());
+        int statusCode = enabled ? 500 : 409;
+          LOG.info("{} request is filtered out: {}", request.getRequestURL(), errorResponse.getMsgDesc());
         HttpServletResponse resp = (HttpServletResponse) servletResponse;
-        resp.setStatus(500);
+        resp.setStatus(statusCode);
         resp.setContentType("application/json");
         resp.getWriter().print(createStringFromErrorMessageObject(errorResponse));
         return;
@@ -80,6 +84,9 @@ public class LogSearchConfigStateFilter implements Filter {
   }
 
   private VResponse getErrorResponse() {
+    if (!enabled) {
+      return RESTErrorUtil.createMessageResponse(CONFIG_API_DISABLED, MessageEnums.CONFIGURATION_API_DISABLED);
+    }
     if (!logSearchConfigState.isLogSearchConfigAvailable()) {
       return RESTErrorUtil.createMessageResponse(CONFIG_NOT_AVAILABLE, MessageEnums.CONFIGURATION_NOT_AVAILABLE);
     }

-- 
To stop receiving notification emails like this one, please contact
oleewere@apache.org.

Mime
View raw message