Просмотр исходного кода

AMBARI-8447 - Update ConfigurationResourceProvider to handle Kerberos Administrative Credentials as a special case (tbeerbower)

tbeerbower 10 лет назад
Родитель
Сommit
f947bfb419
16 измененных файлов с 560 добавлено и 53 удалено
  1. 3 1
      ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
  2. 63 11
      ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariSessionManager.java
  3. 39 11
      ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java
  4. 1 1
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
  5. 56 10
      ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
  6. 14 0
      ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
  7. 17 0
      ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java
  8. 42 1
      ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
  9. 33 7
      ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
  10. 4 0
      ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java
  11. 7 5
      ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
  12. 118 0
      ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariSessionManagerTest.java
  13. 1 3
      ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
  14. 1 3
      ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java
  15. 89 0
      ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
  16. 72 0
      ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersImplTest.java

+ 3 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -1142,6 +1142,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     for (ClusterRequest request : requests) {
       // TODO : Is there ever a real world case where we could have multiple non-null responses?
       response = updateCluster(request);
+      // set any session attributes for this cluster request
+      clusters.addSessionAttributes(request.getClusterName(), request.getSessionAttributes());
     }
     return response;
   }
@@ -3316,7 +3318,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
   private Set<OperatingSystemResponse> getOperatingSystems(
       OperatingSystemRequest request) throws AmbariException {
 
-    Set<OperatingSystemResponse> responses = new HashSet<OperatingSystemResponse>();;
+    Set<OperatingSystemResponse> responses = new HashSet<OperatingSystemResponse>();
 
     String stackName = request.getStackName();
     String stackVersion = request.getStackVersion();

+ 63 - 11
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariSessionManager.java

@@ -47,19 +47,10 @@ public class AmbariSessionManager {
    * @return the current session id; null if no request is associated with the current thread
    */
   public String getCurrentSessionId() {
-    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
-
-    if (requestAttributes instanceof ServletRequestAttributes) {
-      ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
 
-      HttpServletRequest request = servletRequestAttributes.getRequest();
-      if (request != null) {
-        HttpSession session = request.getSession(true);
+    HttpSession session = getHttpSession();
 
-        return session.getId();
-      }
-    }
-    return null;
+    return session == null ? null : session.getId();
   }
 
   /**
@@ -70,4 +61,65 @@ public class AmbariSessionManager {
   public String getSessionCookie() {
     return sessionManager.getSessionCookie();
   }
+
+  /**
+   * Set an attribute value on the current session.
+   *
+   * @param name   the attribute name
+   * @param value  the attribute value
+   */
+  public void setAttribute(String name, Object value) {
+    HttpSession session = getHttpSession();
+    if (session != null) {
+      session.setAttribute(name, value);
+    }
+  }
+
+  /**
+   * Get an attribute value from the current session.
+   *
+   * @param name  the attribute name
+   *
+   * @return the attribute value
+   */
+  public Object getAttribute(String name) {
+    HttpSession session = getHttpSession();
+    if (session != null) {
+      return session.getAttribute(name);
+    }
+    return null;
+  }
+
+  /**
+   * Remove the attribute identified by the given name from the current session.
+   *
+   * @param name  the attribute name
+   */
+  public void removeAttribute(String name) {
+    HttpSession session = getHttpSession();
+    if (session != null) {
+      session.removeAttribute(name);
+    }
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Get the current session.
+   *
+   * @return the current session
+   */
+  protected HttpSession getHttpSession() {
+
+    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
+
+    if (requestAttributes != null && requestAttributes instanceof ServletRequestAttributes) {
+
+      HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
+
+      return request == null ? null : request.getSession(true);
+    }
+    return null;
+  }
 }

+ 39 - 11
ambari-server/src/main/java/org/apache/ambari/server/controller/ClusterRequest.java

@@ -19,6 +19,7 @@
 package org.apache.ambari.server.controller;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -40,21 +41,39 @@ public class ClusterRequest {
 
   private ServiceConfigVersionRequest serviceConfigVersionRequest = null;
 
-  public ClusterRequest(Long clusterId, String clusterName, 
+  /**
+   * The cluster session attributes.
+   */
+  private final Map<String, Object> sessionAttributes;
+
+
+  // ----- Constructors ------------------------------------------------------
+
+  public ClusterRequest(Long clusterId, String clusterName,
       String stackVersion, Set<String> hostNames) {
     this(clusterId, clusterName, null, stackVersion, hostNames);
   }  
   
   public ClusterRequest(Long clusterId, String clusterName, 
       String provisioningState, String stackVersion, Set<String> hostNames) {
+    this(clusterId, clusterName, provisioningState, stackVersion, hostNames, null);
+  }
+
+  public ClusterRequest(Long clusterId, String clusterName,
+                        String provisioningState, String stackVersion,
+                        Set<String> hostNames, Map<String, Object> sessionAttributes) {
     super();
-    this.clusterId = clusterId;
-    this.clusterName = clusterName;
+    this.clusterId         = clusterId;
+    this.clusterName       = clusterName;
     this.provisioningState = provisioningState;
-    this.stackVersion = stackVersion;
-    this.hostNames = hostNames;    
+    this.stackVersion      = stackVersion;
+    this.hostNames         = hostNames;
+    this.sessionAttributes = sessionAttributes;
   }
-  
+
+
+  // ----- ClusterRequest ----------------------------------------------------
+
   /**
    * @return the clusterId
    */
@@ -129,11 +148,12 @@ public class ClusterRequest {
   }
   
   /**
-   * Sets the configs requests (if any)
-   * @param configRequest
+   * Sets the configs requests (if any).
+   *
+   * @param configRequests  the list of configuration requests
    */
-  public void setDesiredConfig(List<ConfigurationRequest> configRequest) {
-    configs = configRequest;
+  public void setDesiredConfig(List<ConfigurationRequest> configRequests) {
+    configs = configRequests;
   }
   
   /**
@@ -168,11 +188,19 @@ public class ClusterRequest {
     return sb.toString();
   }
 
-
   public ServiceConfigVersionRequest getServiceConfigVersionRequest() {
     return serviceConfigVersionRequest;
   }
 
+  /**
+   * Get the session attributes of this request.
+   *
+   * @return the session attributes; may be null
+   */
+  public Map<String, Object> getSessionAttributes() {
+    return sessionAttributes;
+  }
+
   public void setServiceConfigVersionRequest(ServiceConfigVersionRequest serviceConfigVersionRequest) {
     this.serviceConfigVersionRequest = serviceConfigVersionRequest;
   }

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java

@@ -90,7 +90,7 @@ public abstract class AbstractControllerResourceProvider extends AbstractResourc
 
     switch (type.getInternalType()) {
       case Cluster:
-        return new ClusterResourceProvider(propertyIds, keyPropertyIds, managementController);
+        return new ClusterResourceProvider(managementController);
       case Service:
         return resourceProviderFactory.getServiceResourceProvider(propertyIds, keyPropertyIds, managementController);
       case Component:

+ 56 - 10
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java

@@ -68,6 +68,12 @@ public class ClusterResourceProvider extends BaseBlueprintProcessor {
   protected static final String CLUSTER_TOTAL_HOSTS_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "total_hosts");
   protected static final String CLUSTER_HEALTH_REPORT_PROPERTY_ID = PropertyHelper.getPropertyId("Clusters", "health_report");
   protected static final String BLUEPRINT_PROPERTY_ID = PropertyHelper.getPropertyId(null, "blueprint");
+  protected static final String SESSION_ATTRIBUTES_PROPERTY_ID = "session_attributes";
+
+  /**
+   * The session attributes property prefix.
+   */
+  private static final String SESSION_ATTRIBUTES_PROPERTY_PREFIX = SESSION_ATTRIBUTES_PROPERTY_ID + "/";
 
   /**
    * Request info property ID.  Allow internal getResources call to bypass permissions check.
@@ -80,6 +86,31 @@ public class ClusterResourceProvider extends BaseBlueprintProcessor {
   private static Set<String> pkPropertyIds =
       new HashSet<String>(Arrays.asList(new String[]{CLUSTER_ID_PROPERTY_ID}));
 
+  /**
+   * The key property ids for a cluster resource.
+   */
+  private static Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>();
+  static {
+    keyPropertyIds.put(Resource.Type.Cluster, CLUSTER_NAME_PROPERTY_ID);
+  }
+
+  /**
+   * The property ids for a cluster resource.
+   */
+  private static Set<String> propertyIds = new HashSet<String>();
+  static {
+    propertyIds.add(CLUSTER_ID_PROPERTY_ID);
+    propertyIds.add(CLUSTER_NAME_PROPERTY_ID);
+    propertyIds.add(CLUSTER_VERSION_PROPERTY_ID);
+    propertyIds.add(CLUSTER_PROVISIONING_STATE_PROPERTY_ID);
+    propertyIds.add(CLUSTER_DESIRED_CONFIGS_PROPERTY_ID);
+    propertyIds.add(CLUSTER_DESIRED_SERVICE_CONFIG_VERSIONS_PROPERTY_ID);
+    propertyIds.add(CLUSTER_TOTAL_HOSTS_PROPERTY_ID);
+    propertyIds.add(CLUSTER_HEALTH_REPORT_PROPERTY_ID);
+    propertyIds.add(BLUEPRINT_PROPERTY_ID);
+    propertyIds.add(SESSION_ATTRIBUTES_PROPERTY_ID);
+  }
+
   /**
    * Maps configuration type (string) to associated properties
    */
@@ -97,14 +128,9 @@ public class ClusterResourceProvider extends BaseBlueprintProcessor {
   /**
    * Create a  new resource provider for the given management controller.
    *
-   * @param propertyIds           the property ids
-   * @param keyPropertyIds        the key property ids
    * @param managementController  the management controller
    */
-  ClusterResourceProvider(Set<String> propertyIds,
-                          Map<Resource.Type, String> keyPropertyIds,
-                          AmbariManagementController managementController) {
-
+  ClusterResourceProvider(AmbariManagementController managementController) {
     super(propertyIds, keyPropertyIds, managementController);
   }
 
@@ -318,7 +344,6 @@ public class ClusterResourceProvider extends BaseBlueprintProcessor {
   }
 
 
-
   // ----- utility methods ---------------------------------------------------
 
   /**
@@ -334,7 +359,8 @@ public class ClusterResourceProvider extends BaseBlueprintProcessor {
         (String) properties.get(CLUSTER_NAME_PROPERTY_ID),
         (String) properties.get(CLUSTER_PROVISIONING_STATE_PROPERTY_ID),
         (String) properties.get(CLUSTER_VERSION_PROPERTY_ID),
-        null);
+        null,
+        getSessionAttributes(properties));
 
     List<ConfigurationRequest> configRequests = getConfigurationRequests("Clusters", properties);
 
@@ -350,6 +376,28 @@ public class ClusterResourceProvider extends BaseBlueprintProcessor {
     return cr;
   }
 
+  /**
+   * Get the map of session attributes from the given property map.
+   *
+   * @param properties  the property map from the request
+   *
+   * @return the map of session attributes
+   */
+  private Map<String, Object> getSessionAttributes(Map<String, Object> properties) {
+    Map<String, Object> sessionAttributes = new HashMap<String, Object>();
+
+    for (Map.Entry<String, Object> entry : properties.entrySet()) {
+
+      String property = entry.getKey();
+
+      if (property.startsWith(SESSION_ATTRIBUTES_PROPERTY_PREFIX)) {
+        String attributeName = property.substring(SESSION_ATTRIBUTES_PROPERTY_PREFIX.length());
+        sessionAttributes.put(attributeName, entry.getValue());
+      }
+    }
+    return sessionAttributes;
+  }
+
   /**
    * Helper method for creating rollback request
    */
@@ -371,10 +419,8 @@ public class ClusterResourceProvider extends BaseBlueprintProcessor {
         else if (propName.equals("service_config_version_note")) {
           serviceConfigVersionRequest.setNote(entry.getValue().toString());
         }
-
       }
     }
-
     return serviceConfigVersionRequest;
   }
 

+ 14 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java

@@ -412,4 +412,18 @@ public interface Cluster {
    * @return true if the access to this cluster is allowed
    */
   public boolean checkPermission(PrivilegeEntity privilegeEntity, boolean readOnly);
+
+  /**
+   * Add the given map of attributes to the session for this cluster.
+   *
+   * @param attributes  the session attributes
+   */
+  public void addSessionAttributes(Map<String, Object> attributes);
+
+  /**
+   * Get the map of session attributes for this cluster.
+   *
+   * @return the map of session attributes for this cluster; never null
+   */
+  public Map<String, Object> getSessionAttributes();
 }

+ 17 - 0
ambari-server/src/main/java/org/apache/ambari/server/state/Clusters.java

@@ -184,4 +184,21 @@ public interface Clusters {
    * @return true if access to the cluster is allowed
    */
   public boolean checkPermission(String clusterName, boolean readOnly);
+
+  /**
+   * Add the given map of attributes to the session for the cluster identified by the given name.
+   *
+   * @param name        the cluster name
+   * @param attributes  the session attributes
+   */
+  public void addSessionAttributes(String name, Map<String, Object> attributes);
+
+  /**
+   * Get the map of session attributes for the cluster identified by the given name.
+   *
+   * @param name  the cluster name
+   *
+   * @return the map of session attributes for the cluster; never null
+   */
+  public Map<String, Object> getSessionAttributes(String name);
 }

+ 42 - 1
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java

@@ -44,6 +44,7 @@ import org.apache.ambari.server.ParentObjectNotFoundException;
 import org.apache.ambari.server.ServiceComponentHostNotFoundException;
 import org.apache.ambari.server.ServiceNotFoundException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.AmbariSessionManager;
 import org.apache.ambari.server.controller.ClusterResponse;
 import org.apache.ambari.server.controller.ConfigurationResponse;
 import org.apache.ambari.server.controller.MaintenanceStateHelper;
@@ -98,7 +99,6 @@ import org.apache.ambari.server.state.ServiceFactory;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
-import org.apache.ambari.server.state.UpgradeState;
 import org.apache.ambari.server.state.configgroup.ConfigGroup;
 import org.apache.ambari.server.state.configgroup.ConfigGroupFactory;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
@@ -125,6 +125,11 @@ public class ClusterImpl implements Cluster {
   private static final Logger configChangeLog =
     LoggerFactory.getLogger("configchange");
 
+  /**
+   * Prefix for cluster session attributes name.
+   */
+  private static final String CLUSTER_SESSION_ATTRIBUTES_PREFIX = "cluster_session_attributes:";
+
   @Inject
   private Clusters clusters;
 
@@ -213,6 +218,9 @@ public class ClusterImpl implements Cluster {
   @Inject
   private UpgradeDAO upgradeDAO;
 
+  @Inject
+  private AmbariSessionManager sessionManager;
+
   private volatile boolean svcHostsLoaded = false;
 
   private volatile Multimap<String, String> serviceConfigTypes;
@@ -2317,4 +2325,37 @@ public class ClusterImpl implements Cluster {
     }
     return false;
   }
+
+  @Override
+  public void addSessionAttributes(Map<String, Object> attributes) {
+    if (attributes != null && !attributes.isEmpty()) {
+
+      Map<String, Object>  sessionAttributes = new HashMap<String, Object>(getSessionAttributes());
+
+      sessionAttributes.putAll(attributes);
+
+      String attributeName = CLUSTER_SESSION_ATTRIBUTES_PREFIX + getClusterName();
+
+      getSessionManager().setAttribute(attributeName, sessionAttributes);
+    }
+  }
+
+  @Override
+  public Map<String, Object> getSessionAttributes() {
+    String attributeName = CLUSTER_SESSION_ATTRIBUTES_PREFIX + getClusterName();
+
+    Map<String, Object>  attributes =
+        (Map<String, Object>) getSessionManager().getAttribute(attributeName);
+
+    return attributes == null ? Collections.<String, Object>emptyMap() : attributes;
+  }
+
+  /**
+   * Get the associated session manager.
+   *
+   * @return the session manager
+   */
+  protected AmbariSessionManager getSessionManager() {
+    return sessionManager;
+  }
 }

+ 33 - 7
ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java

@@ -47,7 +47,6 @@ import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.HostVersionDAO;
-import org.apache.ambari.server.orm.dao.ResourceDAO;
 import org.apache.ambari.server.orm.dao.ResourceTypeDAO;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
@@ -108,8 +107,6 @@ public class ClustersImpl implements Clusters {
   @Inject
   HostVersionDAO hostVersionDAO;
   @Inject
-  ResourceDAO resourceDAO;
-  @Inject
   ResourceTypeDAO resourceTypeDAO;
   @Inject
   ClusterFactory clusterFactory;
@@ -762,15 +759,44 @@ public class ClustersImpl implements Clusters {
   @Override
   public boolean checkPermission(String clusterName, boolean readOnly) {
 
+    Cluster cluster = findCluster(clusterName);
+
+    return (cluster == null && readOnly) || !configuration.getApiAuthentication()
+      || checkPermission(cluster, readOnly);
+  }
+
+  @Override
+  public void addSessionAttributes(String name, Map<String, Object> attributes) {
+    Cluster cluster = findCluster(name);
+    if (cluster != null) {
+      cluster.addSessionAttributes(attributes);
+    }
+  }
+
+  @Override
+  public Map<String, Object> getSessionAttributes(String name) {
+    Cluster cluster = findCluster(name);
+    return cluster == null ? Collections.<String, Object>emptyMap() : cluster.getSessionAttributes();
+  }
+
+
+  // ----- helper methods ---------------------------------------------------
+
+  /**
+   * Find the cluster for the given name.
+   *
+   * @param name  the cluster name
+   *
+   * @return the cluster for the given name; null if the cluster can not be found
+   */
+  protected Cluster findCluster(String name) {
     Cluster cluster = null;
     try {
-      cluster = clusterName == null ? null : getCluster(clusterName);
+      cluster = name == null ? null : getCluster(name);
     } catch (AmbariException e) {
       // do nothing
     }
-
-    return (cluster == null && readOnly) || !configuration.getApiAuthentication()
-      || checkPermission(cluster, readOnly);
+    return cluster;
   }
 
   /**

+ 4 - 0
ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java

@@ -75,6 +75,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import org.eclipse.jetty.server.SessionManager;
 import org.junit.Test;
 import javax.ws.rs.core.MediaType;
 
@@ -88,6 +89,7 @@ public class AgentResourceTest extends JerseyTest {
   protected Client client;
   HeartBeatHandler handler;
   ActionManager actionManager;
+  SessionManager sessionManager;
   Injector injector;
   AmbariMetaInfo ambariMetaInfo;
   OsFamily os_family;
@@ -288,9 +290,11 @@ public class AgentResourceTest extends JerseyTest {
       actionManager = mock(ActionManager.class);
       ambariMetaInfo = mock(AmbariMetaInfo.class);
       actionDBAccessor = mock(ActionDBAccessor.class);
+      sessionManager = mock(SessionManager.class);
       bind(OsFamily.class).toInstance(os_family);
       bind(ActionDBAccessor.class).toInstance(actionDBAccessor);
       bind(ActionManager.class).toInstance(actionManager);
+      bind(SessionManager.class).toInstance(sessionManager);
       bind(AgentCommand.class).to(ExecutionCommand.class);
       bind(HeartBeatHandler.class).toInstance(handler);
       bind(AmbariMetaInfo.class).toInstance(ambariMetaInfo);

+ 7 - 5
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java

@@ -103,10 +103,11 @@ public class AmbariManagementControllerImplTest {
   private static final ActionDBAccessorImpl actionDBAccessor = createNiceMock(ActionDBAccessorImpl.class);
   private static final AmbariMetaInfo ambariMetaInfo = createMock(AmbariMetaInfo.class);
   private static final Users users = createMock(Users.class);
+  private static final AmbariSessionManager sessionManager = createNiceMock(AmbariSessionManager.class);
 
   @Before
   public void before() throws Exception {
-    reset(ldapDataPopulator, clusters,actionDBAccessor, ambariMetaInfo, users);
+    reset(ldapDataPopulator, clusters,actionDBAccessor, ambariMetaInfo, users, sessionManager);
   }
 
   @Test
@@ -514,7 +515,7 @@ public class AmbariManagementControllerImplTest {
     expectLastCall();
 
     // replay mocks
-    replay(actionManager, cluster, clusters, injector, clusterRequest);
+    replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager);
 
     // test
     AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector);
@@ -522,7 +523,7 @@ public class AmbariManagementControllerImplTest {
 
     // assert and verify
     assertSame(controller, controllerCapture.getValue());
-    verify(actionManager, cluster, clusters, injector, clusterRequest);
+    verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager);
   }
 
   /**
@@ -553,7 +554,7 @@ public class AmbariManagementControllerImplTest {
     expectLastCall().andThrow(new RollbackException());
 
     // replay mocks
-    replay(actionManager, cluster, clusters, injector, clusterRequest);
+    replay(actionManager, cluster, clusters, injector, clusterRequest, sessionManager);
 
     // test
     AmbariManagementController controller = new AmbariManagementControllerImpl(actionManager, clusters, injector);
@@ -565,7 +566,7 @@ public class AmbariManagementControllerImplTest {
     }
     // assert and verify
     assertSame(controller, controllerCapture.getValue());
-    verify(actionManager, cluster, clusters, injector, clusterRequest);
+    verify(actionManager, cluster, clusters, injector, clusterRequest, sessionManager);
   }
 
   @Test
@@ -1573,6 +1574,7 @@ public class AmbariManagementControllerImplTest {
       binder.bind(ActionDBAccessorImpl.class).toInstance(actionDBAccessor);
       binder.bind(AmbariMetaInfo.class).toInstance(ambariMetaInfo);
       binder.bind(Users.class).toInstance(users);
+      binder.bind(AmbariSessionManager.class).toInstance(sessionManager);
     }
   }
 

+ 118 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariSessionManagerTest.java

@@ -0,0 +1,118 @@
+/**
+ * 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.eclipse.jetty.server.SessionManager;
+import org.junit.Test;
+
+import javax.servlet.http.HttpSession;
+
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class AmbariSessionManagerTest {
+
+  @Test
+  public void testGetCurrentSessionId() throws Exception {
+
+    HttpSession session = createNiceMock(HttpSession.class);
+    AmbariSessionManager sessionManager =
+        createMockBuilder(AmbariSessionManager.class).addMockedMethod("getHttpSession").createMock();
+
+    expect(sessionManager.getHttpSession()).andReturn(session);
+    expect(sessionManager.getHttpSession()).andReturn(null);
+    expect(session.getId()).andReturn("SESSION_ID").anyTimes();
+
+    replay(session, sessionManager);
+
+    assertEquals("SESSION_ID", sessionManager.getCurrentSessionId());
+    assertNull(sessionManager.getCurrentSessionId());
+
+    verify(session, sessionManager);
+  }
+
+  @Test
+  public void testGetSessionCookie() throws Exception {
+    SessionManager sessionManager = createNiceMock(SessionManager.class);
+    AmbariSessionManager ambariSessionManager = new AmbariSessionManager();
+
+    ambariSessionManager.sessionManager = sessionManager;
+
+    expect(sessionManager.getSessionCookie()).andReturn("SESSION_COOKIE").anyTimes();
+
+    replay(sessionManager);
+
+    assertEquals("SESSION_COOKIE", ambariSessionManager.getSessionCookie());
+
+    verify(sessionManager);
+  }
+
+  @Test
+  public void testSetAttribute() throws Exception {
+    HttpSession session = createNiceMock(HttpSession.class);
+    AmbariSessionManager sessionManager =
+        createMockBuilder(AmbariSessionManager.class).addMockedMethod("getHttpSession").createMock();
+
+    expect(sessionManager.getHttpSession()).andReturn(session);
+    session.setAttribute("foo", "bar");
+
+    replay(session, sessionManager);
+
+    sessionManager.setAttribute("foo", "bar");
+
+    verify(session, sessionManager);
+  }
+
+  @Test
+  public void testGetAttribute() throws Exception {
+    HttpSession session = createNiceMock(HttpSession.class);
+    AmbariSessionManager sessionManager =
+        createMockBuilder(AmbariSessionManager.class).addMockedMethod("getHttpSession").createMock();
+
+    expect(sessionManager.getHttpSession()).andReturn(session);
+    expect(session.getAttribute("foo")).andReturn("bar");
+
+    replay(session, sessionManager);
+
+    assertEquals("bar", sessionManager.getAttribute("foo"));
+
+    verify(session, sessionManager);
+  }
+
+  @Test
+  public void testRemoveAttribute() throws Exception {
+    HttpSession session = createNiceMock(HttpSession.class);
+    AmbariSessionManager sessionManager =
+        createMockBuilder(AmbariSessionManager.class).addMockedMethod("getHttpSession").createMock();
+
+    expect(sessionManager.getHttpSession()).andReturn(session);
+    session.removeAttribute("foo");
+
+    replay(session, sessionManager);
+
+    sessionManager.removeAttribute("foo");
+
+    verify(session, sessionManager);
+  }
+}

+ 1 - 3
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java

@@ -3418,9 +3418,7 @@ public class ClusterResourceProviderTest {
                                 ResourceProvider hostComponentResourceProvider,
                                 ResourceProvider configGroupResourceProvider) {
 
-      super(PropertyHelper.getPropertyIds(Resource.Type.Cluster),
-            PropertyHelper.getKeyPropertyIds(Resource.Type.Cluster),
-            managementController);
+      super(managementController);
 
       this.serviceResourceProvider = serviceResourceProvider;
       this.componentResourceProvider = componentResourceProvider;

+ 1 - 3
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/JMXHostProviderTest.java

@@ -414,9 +414,7 @@ public class JMXHostProviderTest {
     AbstractProviderModule {
 
     ResourceProvider clusterResourceProvider = new
-      ClusterResourceProvider(PropertyHelper.getPropertyIds(Resource.Type
-      .Cluster), PropertyHelper.getKeyPropertyIds(Resource.Type.Cluster),
-      controller);
+      ClusterResourceProvider(controller);
 
     Injector injector = createNiceMock(Injector.class);
     MaintenanceStateHelper maintenanceStateHelper = createNiceMock(MaintenanceStateHelper.class);

+ 89 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java

@@ -0,0 +1,89 @@
+/**
+ * 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.state.cluster;
+
+import org.apache.ambari.server.controller.AmbariSessionManager;
+import org.junit.Test;
+
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.*;
+
+public class ClusterImplTest {
+
+  @Test
+  public void testAddSessionAttributes() throws Exception {
+    Map<String, Object> attributes = new HashMap<String, Object>();
+    attributes.put("foo", "bar");
+
+    AmbariSessionManager sessionManager = createMock(AmbariSessionManager.class);
+
+    ClusterImpl cluster =
+        createMockBuilder(ClusterImpl.class).
+            addMockedMethod("getSessionManager").
+            addMockedMethod("getClusterName").
+            addMockedMethod("getSessionAttributes").
+            createMock();
+
+    expect(cluster.getSessionManager()).andReturn(sessionManager);
+    expect(cluster.getClusterName()).andReturn("c1");
+    expect(cluster.getSessionAttributes()).andReturn(attributes);
+    sessionManager.setAttribute("cluster_session_attributes:c1", attributes);
+
+    replay(sessionManager, cluster);
+
+    cluster.addSessionAttributes(attributes);
+
+    verify(sessionManager, cluster);
+  }
+
+  @Test
+  public void testGetSessionAttributes() throws Exception {
+    Map<String, Object> attributes = new HashMap<String, Object>();
+    attributes.put("foo", "bar");
+
+    AmbariSessionManager sessionManager = createMock(AmbariSessionManager.class);
+
+    ClusterImpl cluster =
+        createMockBuilder(ClusterImpl.class).
+            addMockedMethod("getSessionManager").
+            addMockedMethod("getClusterName").
+            createMock();
+
+    expect(cluster.getSessionManager()).andReturn(sessionManager).anyTimes();
+    expect(cluster.getClusterName()).andReturn("c1").anyTimes();
+    expect(sessionManager.getAttribute("cluster_session_attributes:c1")).andReturn(attributes);
+    expect(sessionManager.getAttribute("cluster_session_attributes:c1")).andReturn(null);
+
+    replay(sessionManager, cluster);
+
+    assertEquals(attributes, cluster.getSessionAttributes());
+    assertEquals(Collections.<String, Object>emptyMap(), cluster.getSessionAttributes());
+
+    verify(sessionManager, cluster);
+  }
+}

+ 72 - 0
ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersImplTest.java

@@ -0,0 +1,72 @@
+/**
+ * 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.state.cluster;
+
+import org.apache.ambari.server.state.Cluster;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.*;
+
+public class ClustersImplTest {
+
+  @Test
+  public void testAddSessionAttributes() throws Exception {
+
+    Map<String, Object> attributes = new HashMap<String, Object>();
+    attributes.put("foo", "bar");
+
+    Cluster cluster = createMock(Cluster.class);
+    ClustersImpl clusters =
+        createMockBuilder(ClustersImpl.class).addMockedMethod("findCluster", String.class).createMock();
+
+    expect(clusters.findCluster("c1")).andReturn(cluster);
+    cluster.addSessionAttributes(attributes);
+    replay(clusters, cluster);
+
+    clusters.addSessionAttributes("c1", attributes);
+
+    verify(clusters, cluster);
+  }
+
+  @Test
+  public void testGetSessionAttributes() throws Exception {
+    Map<String, Object> attributes = new HashMap<String, Object>();
+    attributes.put("foo", "bar");
+
+    Cluster cluster = createMock(Cluster.class);
+    ClustersImpl clusters =
+        createMockBuilder(ClustersImpl.class).addMockedMethod("findCluster", String.class).createMock();
+
+    expect(clusters.findCluster("c1")).andReturn(cluster);
+    expect(cluster.getSessionAttributes()).andReturn(attributes);
+    replay(clusters, cluster);
+
+    assertEquals(attributes, clusters.getSessionAttributes("c1"));
+
+    verify(clusters, cluster);
+  }
+}