Add the ability to disable some vms from being scheduled

This commit is contained in:
Chiradeep Vittal 2011-08-31 12:09:57 -07:00
parent 1ddda37e13
commit 65414903b7
3 changed files with 61 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
@ -36,6 +37,8 @@ import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.mgmt.JmxUtil;
import com.cloud.vm.VirtualMachine.State;
import edu.emory.mathcs.backport.java.util.Collections;
/**
* Same as the base class -- except it uses the abstracted security group work queue
*
@ -46,6 +49,7 @@ public class SecurityGroupManagerImpl2 extends SecurityGroupManagerImpl{
SecurityManagerMBeanImpl _mBean;
WorkerThread[] _workers;
private Set<Long> _disabledVms = Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
protected class WorkerThread extends Thread {
@ -82,6 +86,7 @@ public class SecurityGroupManagerImpl2 extends SecurityGroupManagerImpl{
}
Set<Long> workItems = new TreeSet<Long>();
workItems.addAll(affectedVms);
workItems.removeAll(_disabledVms);
if (s_logger.isTraceEnabled()) {
s_logger.trace("Security Group Mgr v2: scheduling ruleset updates for " + affectedVms.size() + " vms " + " (unique=" + workItems.size() + "), current queue size=" + _workQueue.size());
@ -254,4 +259,22 @@ public class SecurityGroupManagerImpl2 extends SecurityGroupManagerImpl{
return super.configure(name, params);
}
public void disableSchedulerForVm(Long vmId, boolean disable) {
if (disable) {
_disabledVms.add(vmId);
} else {
_disabledVms.remove(vmId);
}
}
public Long[] getDisabledVmsForScheduler() {
Long [] result = new Long[_disabledVms.size()];
return _disabledVms.toArray(result );
}
public void enableAllVmsForScheduler() {
_disabledVms.clear();
}
}

View File

@ -28,6 +28,14 @@ import java.util.Date;
public interface SecurityGroupManagerMBean {
void enableUpdateMonitor(boolean enable);
void disableSchedulerForVm(Long vmId);
void enableSchedulerForVm(Long vmId);
Long[] getDisabledVmsForScheduler();
void enableSchedulerForAllVms();
Map<Long, Date> getScheduledTimestamps();
Map<Long, Date> getLastUpdateSentTimestamps();
@ -35,5 +43,6 @@ public interface SecurityGroupManagerMBean {
int getQueueSize();
List<Long> getVmsInQueue();
}

View File

@ -72,4 +72,33 @@ public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityG
return _sgMgr.getWorkQueue().getVmsInQueue();
}
@Override
public void disableSchedulerForVm(Long vmId) {
_sgMgr.disableSchedulerForVm(vmId, true);
}
@Override
public void enableSchedulerForVm(Long vmId) {
_sgMgr.disableSchedulerForVm(vmId, false);
}
@Override
public Long[] getDisabledVmsForScheduler() {
return _sgMgr.getDisabledVmsForScheduler();
}
@Override
public void enableSchedulerForAllVms() {
_sgMgr.enableAllVmsForScheduler();
}
}