You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ji...@apache.org on 2012/10/04 01:19:43 UTC
svn commit: r1393811 - in /incubator/ambari/branches/AMBARI-666: ./
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/
ambari-server/src/main/java/org/apache/ambari/server/agent/
ambari-server/src/main/java/org/apache/ambari/server/uti...
Author: jitendra
Date: Wed Oct 3 23:19:42 2012
New Revision: 1393811
URL: http://svn.apache.org/viewvc?rev=1393811&view=rev
Log:
AMBARI-800. Hack to add a stage for testing in in-memory db.
Modified:
incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostAction.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Wed Oct 3 23:19:42 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
NEW FEATURES
+ AMBARI-800. Hack to add a stage for testing in in-memory db. (jitendra)
+
AMBARI-801. Fix heartbeat message from the agent which is causing NPE at the
server. (mahadev)
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java Wed Oct 3 23:19:42 2012
@@ -43,4 +43,6 @@ public interface ActionDBAccessor {
public void updateHostRoleState(String hostname, long requestId,
long stageId, String role, CommandReport report);
+ public void abortHostRole(String host, long requestId, long stageId, Role role);
+
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java Wed Oct 3 23:19:42 2012
@@ -85,4 +85,10 @@ public class ActionDBAccessorImpl implem
// TODO Auto-generated method stub
}
+
+ @Override
+ public void abortHostRole(String host, long requestId, long stageId, Role role) {
+ // TODO Auto-generated method stub
+
+ }
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java Wed Oct 3 23:19:42 2012
@@ -22,6 +22,7 @@ import java.util.List;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.agent.CommandReport;
+import org.apache.ambari.server.utils.StageUtils;
public class ActionDBInMemoryImpl implements ActionDBAccessor {
@@ -80,6 +81,17 @@ public class ActionDBInMemoryImpl implem
l.add(s);
}
}
+ //TODO: Remove this code
+ //HACK to add a stage so that something is sent to the agent
+ long requestId = 1;
+ long stageId = 1;
+ if (l.isEmpty()) {
+ requestId = stageList.get(stageList.size() - 1).getRequestId() + 1;
+ stageId = stageList.get(stageList.size() - 1).getStageId() + 1;
+ }
+ Stage s = StageUtils.getATestStage(requestId, stageId);
+ stageList.add(s);
+ l.add(s);
return l;
}
@@ -103,4 +115,13 @@ public class ActionDBInMemoryImpl implem
}
}
}
+ @Override
+ public void abortHostRole(String host, long requestId, long stageId, Role role) {
+ CommandReport report = new CommandReport();
+ report.setExitCode(999);
+ report.setStdErr("Host Role in invalid state");
+ report.setStdOut("");
+ report.setStatus("ABORTED");
+ updateHostRoleState(host, requestId, stageId, role.toString(), report);
+ }
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java Wed Oct 3 23:19:42 2012
@@ -77,6 +77,9 @@ public class ActionManager {
}
public void actionResponse(String hostname, List<CommandReport> reports) {
+ if (reports == null) {
+ return;
+ }
//persist the action response into the db.
for (CommandReport report : reports) {
String actionId = report.getActionId();
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java Wed Oct 3 23:19:42 2012
@@ -140,35 +140,41 @@ class ActionScheduler implements Runnabl
.handleServiceComponentHostEvent("", hrc.getRole().toString(),
host, timeoutEvent);
} catch (InvalidStateTransitonException e) {
- // Propagate exception
- e.printStackTrace();
- } catch (AmbariException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.info("Transition failed for host: "+host+", role: "+hrc.getRole(), e);
}
db.timeoutHostRole(host, stage.getRequestId(), stage.getStageId(),
hrc.getRole());
} else {
- scheduleHostRole(stage, host, hrc);
+ try {
+ scheduleHostRole(stage, host, hrc);
+ } catch (InvalidStateTransitonException ex) {
+ LOG.info("Cannot make this transition..aborting host role", ex);
+ db.abortHostRole(host, stage.getRequestId(), stage.getStageId(),
+ hrc.getRole());
+ }
}
}
}
}
- private void scheduleHostRole(Stage s, String hostname, HostRoleCommand hrc) {
+ private void scheduleHostRole(Stage s, String hostname, HostRoleCommand hrc)
+ throws InvalidStateTransitonException, AmbariException {
LOG.info("Host:" + hostname + ", role:" + hrc.getRole() + ", actionId:"
+ s.getActionId() + " being scheduled");
long now = System.currentTimeMillis();
if (s.getStartTime(hostname) < 0) {
try {
fsmObject.getCluster(s.getClusterName())
- .handleServiceComponentHostEvent("", "", hostname,
- hrc.getEvent());
+ .handleServiceComponentHostEvent("", "", hostname, hrc.getEvent());
} catch (InvalidStateTransitonException e) {
- e.printStackTrace();
+ LOG.info(
+ "Transition failed for host: " + hostname + ", role: "
+ + hrc.getRole(), e);
+ throw e;
} catch (AmbariException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.info("Exception in fsm: " + hostname + ", role: " + hrc.getRole(),
+ e);
+ throw e;
}
}
s.setLastAttemptTime(hostname, now);
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostAction.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostAction.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostAction.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostAction.java Wed Oct 3 23:19:42 2012
@@ -22,6 +22,7 @@ import java.util.List;
import org.apache.ambari.server.agent.AgentCommand;
import org.apache.ambari.server.agent.ExecutionCommand;
+import org.apache.ambari.server.utils.StageUtils;
/**
* Encapsulates entire task for a host for a stage or action. This class
@@ -50,7 +51,7 @@ public class HostAction {
this.host = host;
roles = new ArrayList<HostRoleCommand>();
commandToHost = new ExecutionCommand();
- commandToHost.setHostName(host);
+ commandToHost.setHostname(host);
}
public HostAction(HostAction ha) {
@@ -90,11 +91,11 @@ public class HostAction {
return this.attemptCount;
}
- public AgentCommand getCommandToHost() {
+ public ExecutionCommand getCommandToHost() {
return this.commandToHost;
}
public synchronized void setCommandId(long requestId, long stageId) {
- commandToHost.setCommandId(requestId+ "-" + stageId);
+ commandToHost.setCommandId(StageUtils.getActionId(requestId, stageId));
}
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java Wed Oct 3 23:19:42 2012
@@ -52,7 +52,7 @@ public class HostRoleCommand {
return event;
}
- void setStatus(HostRoleStatus status) {
+ public void setStatus(HostRoleStatus status) {
this.status = status;
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Stage.java Wed Oct 3 23:19:42 2012
@@ -23,6 +23,7 @@ import java.util.TreeMap;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.agent.AgentCommand;
+import org.apache.ambari.server.agent.ExecutionCommand;
import org.apache.ambari.server.utils.StageUtils;
//This class encapsulates the stage. The stage encapsulates all the information
@@ -63,7 +64,7 @@ public class Stage {
return StageUtils.getActionId(requestId, stageId);
}
- synchronized void addHostAction(String host, HostAction ha) {
+ public synchronized void addHostAction(String host, HostAction ha) {
ha.setCommandId(requestId, stageId);
hostActions.put(host, ha);
}
@@ -118,7 +119,7 @@ public class Stage {
getHostAction(hostname).setLastAttemptTime(t);
}
- public AgentCommand getExecutionCommand(String hostname) {
+ public ExecutionCommand getExecutionCommand(String hostname) {
return getHostAction(hostname).getCommandToHost();
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java Wed Oct 3 23:19:42 2012
@@ -17,6 +17,7 @@
*/
package org.apache.ambari.server.agent;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -77,6 +78,15 @@ public class ExecutionCommand extends Ag
this.commandId = commandId;
}
+ public synchronized void addRoleCommand(String role, String cmd,
+ Map<String, String> roleParams) {
+ RoleExecution rec = new RoleExecution(role, cmd, roleParams);
+ if (rolesCommands == null) {
+ rolesCommands = new ArrayList<RoleExecution>();
+ }
+ rolesCommands.add(rec);
+ }
+
@Override //Object
public boolean equals(Object other) {
if (!(other instanceof ExecutionCommand)) {
@@ -92,10 +102,6 @@ public class ExecutionCommand extends Ag
return (hostname + commandId).hashCode();
}
- public void setHostName(String host) {
- this.hostname = host;
- }
-
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {})
@@ -112,6 +118,13 @@ public class ExecutionCommand extends Ag
@XmlElement
private String cmd;
+ public RoleExecution(String role, String cmd,
+ Map<String, String> roleParams) {
+ this.role = role;
+ this.cmd = cmd;
+ this.roleParams = roleParams;
+ }
+
public String getRole() {
return role;
}
@@ -136,4 +149,44 @@ public class ExecutionCommand extends Ag
this.cmd = cmd;
}
}
+
+ public String getClusterName() {
+ return clusterName;
+ }
+
+ public void setClusterName(String clusterName) {
+ this.clusterName = clusterName;
+ }
+
+ public String getHostname() {
+ return hostname;
+ }
+
+ public void setHostname(String hostname) {
+ this.hostname = hostname;
+ }
+
+ public Map<String, String> getParams() {
+ return params;
+ }
+
+ public void setParams(Map<String, String> params) {
+ this.params = params;
+ }
+
+ public Map<String, List<String>> getClusterHostInfo() {
+ return clusterHostInfo;
+ }
+
+ public void setClusterHostInfo(Map<String, List<String>> clusterHostInfo) {
+ this.clusterHostInfo = clusterHostInfo;
+ }
+
+ public Map<String, Map<String, String>> getConfigurations() {
+ return configurations;
+ }
+
+ public void setConfigurations(Map<String, Map<String, String>> configurations) {
+ this.configurations = configurations;
+ }
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java Wed Oct 3 23:19:42 2012
@@ -17,6 +17,20 @@
*/
package org.apache.ambari.server.utils;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.ambari.server.Role;
+import org.apache.ambari.server.actionmanager.HostAction;
+import org.apache.ambari.server.actionmanager.HostRoleCommand;
+import org.apache.ambari.server.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.agent.ExecutionCommand;
+import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostInstallEvent;
+
public class StageUtils {
public static String getActionId(long requestId, long stageId) {
return requestId + "-" + stageId;
@@ -29,4 +43,41 @@ public class StageUtils {
requestStageIds[1] = Long.parseLong(fields[1]);
return requestStageIds;
}
+
+ //For testing only
+ public static Stage getATestStage(long requestId, long stageId) {
+ InetSocketAddress sa = new InetSocketAddress(0);
+ String hostname = sa.getAddress().getHostName();
+ Stage s = new Stage(requestId, "/tmp", "cluster1");
+ s.setStageId(stageId);
+ HostAction ha = new HostAction(hostname);
+ long now = System.currentTimeMillis();
+ HostRoleCommand hrc = new HostRoleCommand(Role.NAMENODE,
+ new ServiceComponentHostInstallEvent("NAMENODE", hostname, now));
+ hrc.setStatus(HostRoleStatus.PENDING);
+ ha.addHostRoleCommand(hrc);
+ ExecutionCommand execCmd = ha.getCommandToHost();
+ execCmd.setCommandId(s.getActionId());
+ execCmd.setClusterName("cluster1");
+ Map<String, List<String>> clusterHostInfo = new TreeMap<String, List<String>>();
+ List<String> slaveHostList = new ArrayList<String>();
+ slaveHostList.add(hostname);
+ slaveHostList.add("host2");
+ clusterHostInfo.put("slave_hosts", slaveHostList);
+ execCmd.setClusterHostInfo(clusterHostInfo);
+ Map<String, String> hdfsSite = new TreeMap<String, String>();
+ hdfsSite.put("dfs.block.size", "2560000000");
+ Map<String, Map<String, String>> configurations =
+ new TreeMap<String, Map<String, String>>();
+ configurations.put("hdfs-site", hdfsSite);
+ execCmd.setConfigurations(configurations);
+ Map<String, String> params = new TreeMap<String, String>();
+ params.put("jdklocation", "/x/y/z");
+ execCmd.setParams(params);
+ Map<String, String> roleParams = new TreeMap<String, String>();
+ roleParams.put("format", "false");
+ execCmd.addRoleCommand("NAMENODE", "INSTALL", roleParams);
+ s.addHostAction(hostname, ha);
+ return s;
+ }
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java?rev=1393811&r1=1393810&r2=1393811&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java Wed Oct 3 23:19:42 2012
@@ -43,7 +43,7 @@ public class TestHeartbeatHandler {
ActionQueue aq = new ActionQueue();
ExecutionCommand execCmd = new ExecutionCommand();
execCmd.setCommandId("2-34");
- execCmd.setHostName(hostname);
+ execCmd.setHostname(hostname);
aq.enqueue(hostname, new ExecutionCommand());
HeartBeatHandler handler = new HeartBeatHandler(fsm, aq, am);
HeartBeat hb = new HeartBeat();