mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
Add manager context to CleanupMaid to allow management service access in cleanup() method
This commit is contained in:
parent
f57fc2beb7
commit
824f0586f7
@ -18,31 +18,31 @@
|
||||
|
||||
package com.cloud.cluster;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.cluster.dao.StackMaidDao;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.cluster.dao.StackMaidDao;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.serializer.SerializerHelper;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
|
||||
@Local(value=CheckPointManager.class)
|
||||
public class CheckPointManagerImpl implements CheckPointManager, Manager, ClusterManagerListener {
|
||||
@ -163,13 +163,15 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
@DB
|
||||
public long pushCheckPoint(CleanupMaid context) {
|
||||
long seq = _maidDao.pushCleanupDelegate(_msId, 0, context.getClass().getName(), context);
|
||||
return seq;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void updateCheckPointState(long taskId, CleanupMaid updatedContext) {
|
||||
CheckPointVO task = _maidDao.createForUpdate();
|
||||
task.setDelegate(updatedContext.getClass().getName());
|
||||
@ -178,6 +180,7 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void popCheckPoint(long taskId) {
|
||||
_maidDao.remove(taskId);
|
||||
}
|
||||
@ -187,7 +190,7 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste
|
||||
CleanupMaid delegate = (CleanupMaid)SerializerHelper.fromSerializedString(task.getContext());
|
||||
assert delegate.getClass().getName().equals(task.getDelegate()) : "Deserializer says " + delegate.getClass().getName() + " but it's suppose to be " + task.getDelegate();
|
||||
|
||||
int result = delegate.cleanup();
|
||||
int result = delegate.cleanup(this);
|
||||
if (result <= 0) {
|
||||
if (result == 0) {
|
||||
s_logger.info("Successfully cleaned up " + task.getId());
|
||||
|
||||
@ -33,7 +33,7 @@ public interface CleanupMaid {
|
||||
* indicates the cleanup was unsuccessful but don't retry. Positive number
|
||||
* indicates the cleanup was unsuccessful and retry in this many seconds.
|
||||
*/
|
||||
int cleanup();
|
||||
int cleanup(CheckPointManager checkPointMgr);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -216,7 +216,7 @@ public class CheckPointManagerTest extends TestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cleanup() {
|
||||
public int cleanup(CheckPointManager checkPointMgr) {
|
||||
s_logger.debug("Cleanup called for " + seq);
|
||||
map.remove(seq);
|
||||
return canBeCleanup ? 0 : -1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user