Search in sources :

Example 1 with VmsComparer

use of org.ovirt.engine.core.common.businessentities.comparators.VmsComparer in project ovirt-engine by oVirt.

the class MigrateVMActionRunner method sortCommands.

@Override
protected void sortCommands() {
    List<CommandBase<?>> commands = getCommands();
    final Map<Guid, VM> vms = new HashMap<>(commands.size());
    for (CommandBase<?> cmd : commands) {
        vms.put(cmd.getVmId(), vmDao.get(cmd.getVmId()));
    }
    Collections.sort(commands, Comparator.comparing((CommandBase<?> c) -> vms.get(c.getVmId()), new VmsComparer()).reversed());
}
Also used : HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) VmsComparer(org.ovirt.engine.core.common.businessentities.comparators.VmsComparer) Guid(org.ovirt.engine.core.compat.Guid)

Example 2 with VmsComparer

use of org.ovirt.engine.core.common.businessentities.comparators.VmsComparer in project ovirt-engine by oVirt.

the class ClearNonResponsiveVdsVmsCommand method executeCommand.

@Override
protected void executeCommand() {
    List<VM> vms = vmDao.getAllRunningForVds(getVdsId());
    Collections.sort(vms, Collections.reverseOrder(new VmsComparer()));
    List<Guid> autoStartVmIdsToRerun = new ArrayList<>();
    for (VM vm : vms) {
        if (vm.isAutoStartup()) {
            autoStartVmIdsToRerun.add(vm.getId());
        }
        VDSReturnValue returnValue = runVdsCommand(VDSCommandType.SetVmStatus, new SetVmStatusVDSCommandParameters(vm.getId(), VMStatus.Down, VmExitStatus.Error));
        // Write that this VM was shut down by host reboot or manual fence
        if (returnValue != null && returnValue.getSucceeded()) {
            logSettingVmToDown(vm);
        }
        runInternalActionWithTasksContext(ActionType.ProcessDownVm, new ProcessDownVmParameters(vm.getId(), true));
    }
    runVdsCommand(VDSCommandType.UpdateVdsVMsCleared, new UpdateVdsVMsClearedVDSCommandParameters(getVdsId()));
    if (!autoStartVmIdsToRerun.isEmpty()) {
        haAutoStartVmsRunner.addVmsToRun(autoStartVmIdsToRerun);
    }
    setSucceeded(true);
}
Also used : ProcessDownVmParameters(org.ovirt.engine.core.common.action.ProcessDownVmParameters) VM(org.ovirt.engine.core.common.businessentities.VM) SetVmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters) VmsComparer(org.ovirt.engine.core.common.businessentities.comparators.VmsComparer) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) UpdateVdsVMsClearedVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.UpdateVdsVMsClearedVDSCommandParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

VM (org.ovirt.engine.core.common.businessentities.VM)2 VmsComparer (org.ovirt.engine.core.common.businessentities.comparators.VmsComparer)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ProcessDownVmParameters (org.ovirt.engine.core.common.action.ProcessDownVmParameters)1 SetVmStatusVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters)1 UpdateVdsVMsClearedVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.UpdateVdsVMsClearedVDSCommandParameters)1 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)1