Added context to ha work

This commit is contained in:
Alex Huang 2011-02-08 15:27:29 -08:00
parent b92fc074aa
commit c22d4948d0

View File

@ -31,6 +31,7 @@ import javax.ejb.Local;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import com.cloud.agent.AgentManager; import com.cloud.agent.AgentManager;
import com.cloud.alert.AlertManager; import com.cloud.alert.AlertManager;
@ -725,9 +726,10 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
public void run() { public void run() {
s_logger.info("Starting work"); s_logger.info("Starting work");
while (!_stopped) { while (!_stopped) {
HaWorkVO work = null;
try { try {
s_logger.trace("Checking the database"); s_logger.trace("Checking the database");
final HaWorkVO work = _haDao.take(_serverId); work = _haDao.take(_serverId);
if (work == null) { if (work == null) {
try { try {
synchronized(this) { synchronized(this) {
@ -740,6 +742,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
} }
} }
NDC.push("work-" + work.getId());
s_logger.info("Processing " + work); s_logger.info("Processing " + work);
try { try {
@ -776,6 +779,9 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
s_logger.error("Caught this throwable, ", th); s_logger.error("Caught this throwable, ", th);
} finally { } finally {
StackMaid.current().exitCleanup(); StackMaid.current().exitCleanup();
if (work != null) {
NDC.pop();
}
} }
} }
s_logger.info("Time to go home!"); s_logger.info("Time to go home!");