Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
package org.apache.cloudstack.vm.schedule;

import com.cloud.api.ApiGsonHelper;
import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.dao.ManagementServerHostDao;
import com.cloud.event.ActionEventUtils;
import com.cloud.event.EventTypes;
import com.cloud.user.User;
import com.cloud.utils.DateUtil;
import com.cloud.utils.component.ComponentContext;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.Filter;
import com.cloud.utils.db.GlobalLock;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.VirtualMachine;
Expand All @@ -40,6 +43,7 @@
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
import org.apache.cloudstack.utils.identity.ManagementServerNode;
import org.apache.cloudstack.vm.schedule.dao.VMScheduleDao;
import org.apache.cloudstack.vm.schedule.dao.VMScheduledJobDao;
import org.apache.commons.lang.time.DateUtils;
Expand Down Expand Up @@ -68,6 +72,9 @@ public class VMSchedulerImpl extends ManagerBase implements VMScheduler, Configu
private UserVmManager userVmManager;
@Inject
private AsyncJobManager asyncJobManager;
@Inject
private ManagementServerHostDao managementServerHostDao;

private AsyncJobDispatcher asyncJobDispatcher;
private Timer vmSchedulerTimer;
private Date currentTimestamp;
Expand Down Expand Up @@ -190,6 +197,11 @@ public boolean start() {
final TimerTask schedulerPollTask = new ManagedContextTimerTask() {
@Override
protected void runInContext() {
ManagementServerHostVO msHost = managementServerHostDao.findOneInUpState(new Filter(ManagementServerHostVO.class, "id", false, 0L, 1L));
if (msHost == null || (msHost.getMsid() != ManagementServerNode.getManagementServerId())) {
logger.debug("Skipping the vm scheduler poll task on this management server");
return;
}
try {
poll(new Date());
} catch (final Throwable t) {
Expand Down
Loading