You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by wu...@apache.org on 2022/11/24 08:13:59 UTC
[ambari] branch trunk updated: AMBARI-25353: Seeing an error stack when running an API call against Ambari server (#3568)
This is an automated email from the ASF dual-hosted git repository.
wuzhiguo 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 3d89f6e507 AMBARI-25353: Seeing an error stack when running an API call against Ambari server (#3568)
3d89f6e507 is described below
commit 3d89f6e50726da4ae1d0320c4af506b3f5ed06d5
Author: Yu Hou <52...@qq.com>
AuthorDate: Thu Nov 24 16:13:52 2022 +0800
AMBARI-25353: Seeing an error stack when running an API call against Ambari server (#3568)
---
.../ambari/server/configuration/Configuration.java | 16 +++++++++++++
.../server/controller/AmbariHandlerList.java | 8 +++++++
.../server/configuration/ConfigurationTest.java | 27 ++++++++++++++++++++++
.../server/controller/AmbariHandlerListTest.java | 19 ++++++++++++---
4 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 5191b3ca05..825d214875 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -2658,6 +2658,13 @@ public class Configuration {
public static final ConfigurationProperty<Integer> KERBEROS_SERVER_ACTION_THREADPOOL_SIZE = new ConfigurationProperty<>(
"server.kerberos.action.threadpool.size", 1);
+ /**
+ * A flag to determine whether error stacks appear on the error page
+ */
+ @Markdown(description = "Show or hide the error stacks on the error page")
+ public static final ConfigurationProperty<String> SERVER_SHOW_ERROR_STACKS = new ConfigurationProperty<>(
+ "server.show.error.stacks", "false");
+
/**
* Fully qualified class name of the strategy used to form host groups for add service request layout recommendation.
*/
@@ -6198,6 +6205,15 @@ public class Configuration {
return Integer.parseInt(getProperty(SERVER_SIDE_ALERTS_CORE_POOL_SIZE));
}
+ /**
+ * Determines whether error stacks appear on the error page
+ *
+ * @return true if error stacks appear on the error page (defaults to {@code false})
+ */
+ public boolean isServerShowErrorStacks() {
+ return Boolean.parseBoolean(getProperty(SERVER_SHOW_ERROR_STACKS));
+ }
+
/**
* @return {@code true} if local files can be specified in the API to consume VDF
*/
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariHandlerList.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariHandlerList.java
index e3ebc77616..663592e2a9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariHandlerList.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariHandlerList.java
@@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.ambari.server.api.AmbariPersistFilter;
+import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.orm.entities.ViewEntity;
import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
import org.apache.ambari.server.security.AmbariViewsSecurityHeaderFilter;
@@ -104,6 +105,9 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
@Inject
SessionHandlerConfigurer sessionHandlerConfigurer;
+ @Inject
+ Configuration configuration;
+
/**
* Mapping of view instance entities to handlers.
*/
@@ -251,6 +255,10 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
webAppContext.addFilter(new FilterHolder(springSecurityFilter), "/*", AmbariServer.DISPATCHER_TYPES);
webAppContext.setAllowNullPathInfo(true);
+ if (webAppContext.getErrorHandler() != null) {
+ webAppContext.getErrorHandler().setShowStacks(configuration.isServerShowErrorStacks());
+ }
+
return webAppContext;
}
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
index 3e93e4c0b4..868f53045d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
@@ -977,4 +977,31 @@ public class ConfigurationTest {
// This is expected
}
}
+
+ @Test
+ public void testServerShowErrorStacksEnabled() throws Exception {
+ // given
+ final Properties ambariProperties = new Properties();
+ ambariProperties.setProperty(Configuration.SERVER_SHOW_ERROR_STACKS.getKey(), "true");
+ final Configuration configuration = new Configuration(ambariProperties);
+
+ // when
+ boolean result = configuration.isServerShowErrorStacks();
+
+ // then
+ Assert.assertTrue(result);
+ }
+
+ @Test
+ public void testServerShowErrorStacksDefault() throws Exception {
+ // given
+ final Properties ambariProperties = new Properties();
+ final Configuration configuration = new Configuration(ambariProperties);
+
+ // when
+ boolean result = configuration.isServerShowErrorStacks();
+
+ // then
+ Assert.assertEquals(result, Boolean.parseBoolean(Configuration.SERVER_SHOW_ERROR_STACKS.getDefaultValue()));
+ }
}
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariHandlerListTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariHandlerListTest.java
index effdf9d81a..37e7bb4d3f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariHandlerListTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariHandlerListTest.java
@@ -33,6 +33,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.ambari.server.api.AmbariPersistFilter;
+import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.orm.entities.ViewEntity;
import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
import org.apache.ambari.server.orm.entities.ViewInstanceEntityTest;
@@ -44,6 +45,7 @@ import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.SessionIdManager;
+import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.server.session.SessionCache;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.FilterHolder;
@@ -64,7 +66,7 @@ public class AmbariHandlerListTest {
private final SessionIdManager sessionIdManager = createNiceMock(SessionIdManager.class);
private final SessionHandlerConfigurer sessionHandlerConfigurer = createNiceMock(SessionHandlerConfigurer.class);
private final SessionCache sessionCache = createNiceMock(SessionCache.class);
-
+ private final Configuration configuration = createNiceMock(Configuration.class);
@Test
public void testAddViewInstance() throws Exception {
@@ -90,7 +92,16 @@ public class AmbariHandlerListTest {
handler.addFilter(capture(securityFilterCapture), eq("/*"), eq(AmbariServer.DISPATCHER_TYPES));
handler.setAllowNullPathInfo(true);
- replay(handler, server, sessionHandler);
+ final boolean showErrorStacks = true;
+ expect(configuration.isServerShowErrorStacks()).andReturn(showErrorStacks);
+
+ ErrorHandler errorHandler = createNiceMock(ErrorHandler.class);
+ Capture<Boolean> showStackCapture = EasyMock.newCapture();
+ errorHandler.setShowStacks(EasyMock.captureBoolean(showStackCapture));
+
+ expect(handler.getErrorHandler()).andReturn(errorHandler).times(2);
+
+ replay(handler, server, sessionHandler, configuration, errorHandler);
AmbariHandlerList handlerList = getAmbariHandlerList(handler);
@@ -103,8 +114,9 @@ public class AmbariHandlerListTest {
Assert.assertEquals(ambariViewsSecurityHeaderFilter, securityHeaderFilterCapture.getValue().getFilter());
Assert.assertEquals(persistFilter, persistFilterCapture.getValue().getFilter());
Assert.assertEquals(springSecurityFilter, securityFilterCapture.getValue().getFilter());
+ Assert.assertEquals(showErrorStacks, showStackCapture.getValue());
- verify(handler, server, sessionHandler);
+ verify(handler, server, sessionHandler, configuration, errorHandler);
}
@Test
@@ -185,6 +197,7 @@ public class AmbariHandlerListTest {
handlerList.springSecurityFilter = springSecurityFilter;
handlerList.sessionHandler = sessionHandler;
handlerList.sessionHandlerConfigurer = sessionHandlerConfigurer;
+ handlerList.configuration = configuration;
return handlerList;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ambari.apache.org
For additional commands, e-mail: commits-help@ambari.apache.org