You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vg...@apache.org on 2012/01/04 02:43:23 UTC

svn commit: r1227018 - in /incubator/ambari/trunk: ./ client/src/main/java/org/apache/ambari/common/rest/entities/ controller/src/main/java/org/apache/ambari/controller/ controller/src/test/java/org/apache/ambari/controller/

Author: vgogate
Date: Wed Jan  4 01:43:23 2012
New Revision: 1227018

URL: http://svn.apache.org/viewvc?rev=1227018&view=rev
Log:
AMBARI-183. Pass the appropriate component user to agent as specified in the stack

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Stack.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
    incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
    incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1227018&r1=1227017&r2=1227018&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Jan  4 01:43:23 2012
@@ -2,6 +2,8 @@ Ambari Change log
 
 Release 0.1.0 - unreleased
 
+  AMBARI-183. Pass the appropriate component user to agent as specified in the stack (vgogate)
+
   AMBARI-182. rename controller/src/main/resources/org/apache/ambari/acd/mapred-0.1.0.acd to mapreduce-0.1.0.acd (vgogate)
 
   AMBARI-180. Fixes the agent to do better process management (ddas)

Modified: incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Stack.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Stack.java?rev=1227018&r1=1227017&r2=1227018&view=diff
==============================================================================
--- incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Stack.java (original)
+++ incubator/ambari/trunk/client/src/main/java/org/apache/ambari/common/rest/entities/Stack.java Wed Jan  4 01:43:23 2012
@@ -336,4 +336,16 @@ public class Stack {
     public void setCreationTime(XMLGregorianCalendar creationTime) {
         this.creationTime = creationTime;
     }
+    
+    /**
+     * @param componentName 
+     */
+    public Component getComponentByName (String name) {
+        for (Component c : this.components) {
+            if (c.getName().equals(name)) {
+                return c;
+            }
+        }
+        return null;
+    }
 }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java?rev=1227018&r1=1227017&r2=1227018&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/Clusters.java Wed Jan  4 01:43:23 2012
@@ -716,8 +716,7 @@ public class Clusters {
         if (!expanded) {
             bp = stacks.getStack(stackName, stackRevision);
         } else {
-            // TODO: Get the derived/expanded stack
-            bp = stacks.getStack(stackName, stackRevision);
+            bp = this.flattener.flattenStack(stackName, stackRevision);
         }
         return bp;
     }

Modified: incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java?rev=1227018&r1=1227017&r2=1227018&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java (original)
+++ incubator/ambari/trunk/controller/src/main/java/org/apache/ambari/controller/HeartbeatHandler.java Wed Jan  4 01:43:23 2012
@@ -37,6 +37,7 @@ import org.apache.ambari.common.rest.age
 import org.apache.ambari.common.rest.agent.ControllerResponse;
 import org.apache.ambari.common.rest.agent.HeartBeat;
 import org.apache.ambari.common.rest.entities.NodeState;
+import org.apache.ambari.common.rest.entities.Stack;
 import org.apache.ambari.components.ComponentPlugin;
 import org.apache.ambari.resource.statemachine.ClusterFSM;
 import org.apache.ambari.resource.statemachine.FSMDriverInterface;
@@ -63,7 +64,7 @@ public class HeartbeatHandler {
   private final StateMachineInvokerInterface stateMachineInvoker;
   private final FSMDriverInterface driver;
   
-  static final String DEFAULT_USER = "hdfs"; //TODO: this needs to come from the stack definition or something (AMBARI-169)
+  static final String DEFAULT_USER = "hadoop"; //TODO: this needs to come from the stack definition or something (AMBARI-169)
     
   @Inject
   HeartbeatHandler(Clusters clusters, Nodes nodes, 
@@ -268,7 +269,7 @@ public class HeartbeatHandler {
       List<Action> allActions) {
     ConfigFile file = new ConfigFile();
     file.setData(script);
-    file.setOwner(DEFAULT_USER); //TODO (AMBARI-169)
+    //file.setOwner(DEFAULT_USER); //It should be the user that is running the ambari agent
     
     Action action = new Action();
     action.setFile(file);
@@ -467,15 +468,18 @@ public class HeartbeatHandler {
   }
   
   private void fillActionDetails(Action action, String clusterId, 
-      long clusterDefRev, String component, String role) {
+      long clusterDefRev, String component, String role) throws Exception {
     if (action == null) {
       return;
     }
+    // TODO: Should cluster store the flattened/expanded stack to avoid 
+    // expanding it every time?
+    Stack stack = this.clusters.getClusterStack(clusterId, true);
     action.setClusterId(clusterId);
     action.setClusterDefinitionRevision(clusterDefRev);
     action.setComponent(component);
     action.setRole(role);
-    action.setUser(DEFAULT_USER); //TODO (AMBARI-169)
+    action.setUser(stack.getComponentByName(component).getUser_group().getUser());
     action.setCleanUpCommand(new Command("foobar","",new String[]{"foobar"}));//TODO: this needs fixing at some point
     String workDir = role.equals(component + "-client") ? 
         (clusterId + "-client") : (clusterId + "-" + role);
@@ -484,7 +488,7 @@ public class HeartbeatHandler {
   
   private void fillDetailsAndAddAction(Action action, List<Action> allActions, 
       String clusterId, 
-      long clusterDefRev, String component, String role) {
+      long clusterDefRev, String component, String role) throws Exception {
     fillActionDetails(action, clusterId, clusterDefRev, component, role);
     addAction(action, allActions);
   }

Modified: incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java?rev=1227018&r1=1227017&r2=1227018&view=diff
==============================================================================
--- incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java (original)
+++ incubator/ambari/trunk/controller/src/test/java/org/apache/ambari/controller/TestHeartbeat.java Wed Jan  4 01:43:23 2012
@@ -42,6 +42,9 @@ import org.apache.ambari.common.rest.ent
 import org.apache.ambari.common.rest.entities.ClusterState;
 import org.apache.ambari.common.rest.entities.Node;
 import org.apache.ambari.common.rest.entities.NodeState;
+import org.apache.ambari.common.rest.entities.Stack;
+import org.apache.ambari.common.rest.entities.Component;
+import org.apache.ambari.common.rest.entities.UserGroup;
 import org.apache.ambari.components.ComponentPlugin;
 import org.apache.ambari.configuration.Configuration;
 import org.apache.ambari.controller.HeartbeatHandler.ClusterNameAndRev;
@@ -75,6 +78,9 @@ public class TestHeartbeat {
   Cluster cluster;
   Nodes nodes;
   Clusters clusters;
+  Stack stack;
+  Component component;
+  UserGroup usergroup;
   StateMachineInvokerInterface invoker;
   FSMDriverInterface driver;
   HeartBeat heartbeat;
@@ -141,6 +147,15 @@ public class TestHeartbeat {
     when(clusters.getClusterByName("cluster1")).thenReturn(cluster);
     when(clusters.getInstallAndConfigureScript(anyString(), anyInt()))
         .thenReturn(script);
+    
+    stack = mock(Stack.class);
+    usergroup = mock(UserGroup.class);
+    component = mock (Component.class);
+    when (clusters.getClusterStack("cluster1", true)).thenReturn(stack);
+    when (stack.getComponentByName(anyString())).thenReturn(component);
+    when (component.getUser_group()).thenReturn(usergroup);
+    when (usergroup.getUser()).thenReturn("hadoop");
+
     heartbeat = new HeartBeat();
     heartbeat.setIdle(true);
     heartbeat.setInstallScriptHash(-1);