You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by hi...@apache.org on 2012/10/09 23:40:39 UTC
svn commit: r1396346 - 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/controller/
Author: hitesh
Date: Tue Oct 9 21:40:39 2012
New Revision: 1396346
URL: http://svn.apache.org/viewvc?rev=1396346&view=rev
Log:
AMBARI-836. Fix generation of requestId to be unique across restarts. (Contributed by hitesh)
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/controller/AmbariManagementControllerImpl.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=1396346&r1=1396345&r2=1396346&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Tue Oct 9 21:40:39 2012
@@ -227,6 +227,8 @@ AMBARI-666 branch (unreleased changes)
BUG FIXES
+ AMBARI-836. Fix generation of requestId to be unique across restarts. (hitesh)
+
AMBARI-834. Use RoleCommand instead of ServiceComponentHostEventType for HostAction
in Controller. (hitesh)
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=1396346&r1=1396345&r2=1396346&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 Tue Oct 9 21:40:39 2012
@@ -43,6 +43,15 @@ 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);
+ public void abortHostRole(String host, long requestId, long stageId,
+ Role role);
+
+ /**
+ * Return the last persisted Request ID as seen when the DBAccessor object
+ * was initialized.
+ * Value should remain unchanged through the lifetime of the object instance.
+ * @return Request Id seen at init time
+ */
+ public long getLastPersistedRequestIdWhenInitialized();
}
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=1396346&r1=1396345&r2=1396346&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 Tue Oct 9 21:40:39 2012
@@ -27,8 +27,6 @@ import com.google.inject.Singleton;
@Singleton
public class ActionDBAccessorImpl implements ActionDBAccessor {
- private long stageId = 0;
-
public ActionDBAccessorImpl() {
//this.stageId = greatest stage id in the database + 1
}
@@ -86,12 +84,18 @@ public class ActionDBAccessorImpl implem
public void updateHostRoleState(String hostname, long requestId,
long stageId, String role, CommandReport report) {
// TODO Auto-generated method stub
-
+
}
@Override
public void abortHostRole(String host, long requestId, long stageId, Role role) {
// TODO Auto-generated method stub
-
+
+ }
+
+ @Override
+ public long getLastPersistedRequestIdWhenInitialized() {
+ // TODO Auto-generated method stub
+ return 0;
}
}
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=1396346&r1=1396345&r2=1396346&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 Tue Oct 9 21:40:39 2012
@@ -29,6 +29,10 @@ import com.google.inject.Singleton;
@Singleton
public class ActionDBInMemoryImpl implements ActionDBAccessor {
+ // for a persisted DB, this will be initialized in the ctor
+ // with the highest persisted requestId value in the DB
+ private final long lastRequestId = 0;
+
List<Stage> stageList = new ArrayList<Stage>();
@Override
@@ -129,4 +133,9 @@ public class ActionDBInMemoryImpl implem
report.setStatus("ABORTED");
updateHostRoleState(host, requestId, stageId, role.toString(), report);
}
+
+ @Override
+ public synchronized long getLastPersistedRequestIdWhenInitialized() {
+ return lastRequestId;
+ }
}
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=1396346&r1=1396345&r2=1396346&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 Tue Oct 9 21:40:39 2012
@@ -18,10 +18,10 @@
package org.apache.ambari.server.actionmanager;
import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.ambari.server.agent.ActionQueue;
import org.apache.ambari.server.agent.CommandReport;
-import org.apache.ambari.server.agent.rest.AgentResource;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.utils.StageUtils;
import org.slf4j.Logger;
@@ -42,7 +42,8 @@ public class ActionManager {
private final ActionQueue actionQueue;
private final Clusters fsm;
private static Logger LOG = LoggerFactory.getLogger(ActionManager.class);
-
+ private final AtomicLong requestCounter;
+
@Inject
public ActionManager(@Named("schedulerSleeptime") long schedulerSleepTime,
@Named("actionTimeout") long actionTimeout,
@@ -52,6 +53,7 @@ public class ActionManager {
scheduler = new ActionScheduler(schedulerSleepTime, actionTimeout, db,
actionQueue, fsm, 2);
this.fsm = fsm;
+ requestCounter = new AtomicLong(db.getLastPersistedRequestIdWhenInitialized());
}
public void start() {
@@ -82,7 +84,7 @@ public class ActionManager {
for (CommandReport report : reports) {
String actionId = report.getActionId();
long [] requestStageIds = StageUtils.getRequestStage(actionId);
- long requestId = requestStageIds[0];
+ long requestId = requestStageIds[0];
long stageId = requestStageIds[1];
db.updateHostRoleState(hostname, requestId, stageId, report.getRole(),
report);
@@ -95,4 +97,9 @@ public class ActionManager {
//if action timeout happens to be much larger than
//heartbeat timeout.
}
+
+ public long getNextRequestId() {
+ return requestCounter.incrementAndGet();
+ }
+
}
Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1396346&r1=1396345&r2=1396346&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Tue Oct 9 21:40:39 2012
@@ -33,15 +33,12 @@ import org.apache.ambari.server.state.Ho
import org.apache.ambari.server.state.Service;
import org.apache.ambari.server.state.ServiceComponent;
import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.ServiceComponentHostEvent;
import org.apache.ambari.server.state.ServiceComponentImpl;
import org.apache.ambari.server.state.StackVersion;
import org.apache.ambari.server.state.State;
import org.apache.ambari.server.state.ServiceImpl;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent;
-import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
-import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStopEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,7 +51,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
-import java.util.concurrent.atomic.AtomicLong;
public class AmbariManagementControllerImpl implements
AmbariManagementController {
@@ -64,10 +60,6 @@ public class AmbariManagementControllerI
private final Clusters clusters;
- // FIXME this needs to be unique across restarts
- // TODO change requestId to string and use server start timestamp + in-memory
- // request counter to make the request id unique?
- private final AtomicLong requestCounter;
private String baseLogDir = "/tmp/ambari/";
private final ActionManager actionManager;
@@ -75,7 +67,6 @@ public class AmbariManagementControllerI
public AmbariManagementControllerImpl(@Assisted ActionManager actionManager
, @Assisted Clusters clusters) {
this.clusters = clusters;
- this.requestCounter = new AtomicLong();
this.actionManager = actionManager;
}
@@ -795,7 +786,7 @@ public class AmbariManagementControllerI
orderedCompNames.add("HDFS_CLIENT");
long nowTimestamp = System.currentTimeMillis();
- long requestId = requestCounter.incrementAndGet();
+ long requestId = actionManager.getNextRequestId();
List<Stage> stages = new ArrayList<Stage>();
long stageId = 0;
@@ -948,7 +939,7 @@ public class AmbariManagementControllerI
// TODO lets continue hacking
long nowTimestamp = System.currentTimeMillis();
- long requestId = requestCounter.incrementAndGet();
+ long requestId = actionManager.getNextRequestId();
long stageId = 0;
List<Stage> stages = new ArrayList<Stage>();
Stage stage = createNewStage(cluster, requestId);
@@ -1108,7 +1099,7 @@ public class AmbariManagementControllerI
// TODO lets continue hacking
long nowTimestamp = System.currentTimeMillis();
- long requestId = requestCounter.incrementAndGet();
+ long requestId = actionManager.getNextRequestId();
long stageId = 0;
List<Stage> stages = new ArrayList<Stage>();