You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by mp...@apache.org on 2017/10/05 15:19:19 UTC
ambari git commit: AMBARI-22143. Admin View opening redirects back to
ambari. (mpapirkovskyy)
Repository: ambari
Updated Branches:
refs/heads/branch-3.0-perf 6ecac18cb -> cc835ae54
AMBARI-22143. Admin View opening redirects back to ambari. (mpapirkovskyy)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cc835ae5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cc835ae5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cc835ae5
Branch: refs/heads/branch-3.0-perf
Commit: cc835ae54a065051da319d96b17fe457cccbb818
Parents: 6ecac18
Author: Myroslav Papirkovskyi <mp...@hortonworks.com>
Authored: Thu Oct 5 15:11:59 2017 +0300
Committer: Myroslav Papirkovskyi <mp...@hortonworks.com>
Committed: Thu Oct 5 15:11:59 2017 +0300
----------------------------------------------------------------------
.../server/controller/AmbariHandlerList.java | 27 ++++++----
.../ambari/server/controller/AmbariServer.java | 30 ++---------
.../server/controller/ControllerModule.java | 1 -
.../controller/SessionHandlerConfigurer.java | 57 ++++++++++++++++++++
.../server/view/ViewInstanceHandlerList.java | 7 +++
.../server/controller/AmbariServerTest.java | 8 +--
6 files changed, 91 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc835ae5/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariHandlerList.java
----------------------------------------------------------------------
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 cfd3d4e..e73795b 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
@@ -44,6 +44,7 @@ import org.apache.ambari.view.ViewContext;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.server.session.SessionCache;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.webapp.WebAppContext;
@@ -100,10 +101,13 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
@Inject
AmbariViewsSecurityHeaderFilter ambariViewsSecurityHeaderFilter;
+ @Inject
+ SessionHandlerConfigurer sessionHandlerConfigurer;
+
/**
* Mapping of view instance entities to handlers.
*/
- private final Map<ViewInstanceEntity, Handler> viewHandlerMap = new HashMap<>();
+ private final Map<ViewInstanceEntity, WebAppContext> viewHandlerMap = new HashMap<>();
/**
* The non-view handlers.
@@ -164,7 +168,7 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
@Override
public void addViewInstance(ViewInstanceEntity viewInstanceDefinition) throws SystemException {
- Handler handler = getHandler(viewInstanceDefinition);
+ WebAppContext handler = getHandler(viewInstanceDefinition);
viewHandlerMap.put(viewInstanceDefinition, handler);
super.addHandler(handler);
// if this is running then start the handler being added...
@@ -178,6 +182,13 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
}
@Override
+ public void shareSessionCacheToViews(SessionCache serverSessionCache) {
+ for (WebAppContext webAppContext : viewHandlerMap.values()) {
+ webAppContext.getSessionHandler().setSessionCache(serverSessionCache);
+ }
+ }
+
+ @Override
public void removeViewInstance(ViewInstanceEntity viewInstanceDefinition) {
Handler handler = viewHandlerMap.get(viewInstanceDefinition);
if (handler != null) {
@@ -204,7 +215,7 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
}
// call the given handlers until the request is handled; return true if the request is handled
- private boolean processHandlers(Collection<Handler> handlers, String target, Request baseRequest,
+ private boolean processHandlers(Collection<? extends Handler> handlers, String target, Request baseRequest,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
@@ -226,7 +237,7 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
*
* @throws org.apache.ambari.view.SystemException if an handler can not be obtained for the given view instance
*/
- private Handler getHandler(ViewInstanceEntity viewInstanceDefinition)
+ private WebAppContext getHandler(ViewInstanceEntity viewInstanceDefinition)
throws SystemException {
ViewEntity viewDefinition = viewInstanceDefinition.getViewEntity();
@@ -265,8 +276,7 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
* A session handler that shares its session manager with another app.
* This handler DOES NOT attempt stop the shared session manager.
*/
- private static class SharedSessionHandler extends SessionHandler {
- final SessionHandler sessionHandler;
+ private class SharedSessionHandler extends SessionHandler {
// ----- Constructors ----------------------------------------------------
@@ -276,7 +286,8 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
* @param sessionHandler the shared session manager.
*/
public SharedSessionHandler(SessionHandler sessionHandler) {
- this.sessionHandler = sessionHandler;
+ setSessionIdManager(sessionHandler.getSessionIdManager());
+ sessionHandlerConfigurer.configureSessionHandler(this);
}
@@ -286,7 +297,5 @@ public class AmbariHandlerList extends HandlerCollection implements ViewInstance
protected void doStop() throws Exception {
// do nothing...
}
-
- //TODO delagate all other?
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc835ae5/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index c749846..0d59832 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -275,6 +275,9 @@ public class AmbariServer {
@Inject
ViewDirectoryWatcher viewDirectoryWatcher;
+ @Inject
+ SessionHandlerConfigurer sessionHandlerConfigurer;
+
public String getServerOsType() {
return configs.getServerOsType();
}
@@ -354,7 +357,7 @@ public class AmbariServer {
ServletContextHandler.SECURITY | ServletContextHandler.SESSIONS);
configureRootHandler(root);
- configureSessionHandler(sessionHandler);
+ sessionHandlerConfigurer.configureSessionHandler(sessionHandler);
root.setSessionHandler(sessionHandler);
//ContextLoaderListener handles all work on registration in servlet container
@@ -553,6 +556,7 @@ public class AmbariServer {
* Start the server after controller state is recovered.
*/
server.start();
+ handlerList.shareSessionCacheToViews(sessionHandler.getSessionCache());
serverForAgent.start();
LOG.info("********* Started Server **********");
@@ -836,30 +840,6 @@ public class AmbariServer {
}
/**
- * Performs basic configuration of session handler with static values and values from
- * configuration file.
- *
- * @param sessionHandler session handler
- */
- protected void configureSessionHandler(SessionHandler sessionHandler) {
- // use AMBARISESSIONID instead of JSESSIONID to avoid conflicts with
- // other services (like HDFS) that run on the same context but a different
- // port
- sessionHandler.setSessionCookie("AMBARISESSIONID");
-
- sessionHandler.getSessionCookieConfig().setHttpOnly(true);
- if (configs.getApiSSLAuthentication()) {
- sessionHandler.getSessionCookieConfig().setSecure(true);
- }
-
- // each request that does not use AMBARISESSIONID will create a new
- // HashedSession in Jetty; these MUST be reaped after inactivity in order
- // to prevent a memory leak
- int sessionInactivityTimeout = configs.getHttpSessionInactiveTimeout();
- sessionHandler.setMaxInactiveInterval(sessionInactivityTimeout);
- }
-
- /**
* Creates default users if in-memory database is used
*/
@Transactional
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc835ae5/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index b707c88..5981287 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -312,7 +312,6 @@ public class ControllerModule extends AbstractModule {
installFactories();
final SessionHandler sessionHandler = new SessionHandler();
- sessionHandler.getSessionCookieConfig().setPath("/");
bind(SessionHandler.class).toInstance(sessionHandler);
bind(KerberosOperationHandlerFactory.class);
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc835ae5/ambari-server/src/main/java/org/apache/ambari/server/controller/SessionHandlerConfigurer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/SessionHandlerConfigurer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/SessionHandlerConfigurer.java
new file mode 100644
index 0000000..449cf2b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/SessionHandlerConfigurer.java
@@ -0,0 +1,57 @@
+/**
+ * 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.server.controller;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.eclipse.jetty.server.session.SessionHandler;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+@Singleton
+public class SessionHandlerConfigurer {
+
+ @Inject
+ Configuration configuration;
+
+ /**
+ * Performs basic configuration of session handler with static values and values from
+ * configuration file.
+ *
+ * @param sessionHandler session handler
+ */
+ protected void configureSessionHandler(SessionHandler sessionHandler) {
+ sessionHandler.getSessionCookieConfig().setPath("/");
+
+ // use AMBARISESSIONID instead of JSESSIONID to avoid conflicts with
+ // other services (like HDFS) that run on the same context but a different
+ // port
+ sessionHandler.setSessionCookie("AMBARISESSIONID");
+
+ sessionHandler.getSessionCookieConfig().setHttpOnly(true);
+ if (configuration.getApiSSLAuthentication()) {
+ sessionHandler.getSessionCookieConfig().setSecure(true);
+ }
+
+ // each request that does not use AMBARISESSIONID will create a new
+ // HashedSession in Jetty; these MUST be reaped after inactivity in order
+ // to prevent a memory leak
+ int sessionInactivityTimeout = configuration.getHttpSessionInactiveTimeout();
+ sessionHandler.setMaxInactiveInterval(sessionInactivityTimeout);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc835ae5/ambari-server/src/main/java/org/apache/ambari/server/view/ViewInstanceHandlerList.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewInstanceHandlerList.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewInstanceHandlerList.java
index 648959b..025ea2a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewInstanceHandlerList.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewInstanceHandlerList.java
@@ -19,6 +19,7 @@ package org.apache.ambari.server.view;
import org.apache.ambari.server.orm.entities.ViewInstanceEntity;
import org.apache.ambari.view.SystemException;
+import org.eclipse.jetty.server.session.SessionCache;
/**
* List of handlers for deployed view instances.
@@ -35,6 +36,12 @@ public interface ViewInstanceHandlerList {
void addViewInstance(ViewInstanceEntity viewInstanceDefinition) throws SystemException;
/**
+ * Shares specified sessionCache between all views' handlers
+ * @param serverSessionCache the sessionCache instance
+ */
+ void shareSessionCacheToViews(SessionCache serverSessionCache);
+
+ /**
* Remove the handler for the given view instance.
*
* @param viewInstanceDefinition the view instance
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc835ae5/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
index 3732e93..1fce5b6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariServerTest.java
@@ -98,13 +98,13 @@ public class AmbariServerTest {
@Test
public void testConfigureSessionManager() throws Exception {
- AmbariServer ambariServer = new AmbariServer();
+ SessionHandlerConfigurer sessionHandlerConfigurer = new SessionHandlerConfigurer();
Configuration configuration = createNiceMock(Configuration.class);
SessionHandler sessionHandler = createNiceMock(SessionHandler.class);
SessionCookieConfig sessionCookieConfig = createNiceMock(SessionCookieConfig.class);
- ambariServer.configs = configuration;
+ sessionHandlerConfigurer.configuration = configuration;
expect(sessionHandler.getSessionCookieConfig()).andReturn(sessionCookieConfig).anyTimes();
@@ -118,10 +118,10 @@ public class AmbariServerTest {
replay(configuration, sessionHandler, sessionCookieConfig);
// getApiSSLAuthentication == false
- ambariServer.configureSessionHandler(sessionHandler);
+ sessionHandlerConfigurer.configureSessionHandler(sessionHandler);
// getApiSSLAuthentication == true
- ambariServer.configureSessionHandler(sessionHandler);
+ sessionHandlerConfigurer.configureSessionHandler(sessionHandler);
verify(configuration, sessionHandler, sessionCookieConfig);
}