Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Return validation messages from SchedulingManager #519

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -17,6 +17,7 @@
import org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback;
import org.ovirt.engine.core.common.AuditLogType;
import org.ovirt.engine.core.common.VdcObjectType;
import org.ovirt.engine.core.common.action.ActionReturnValue;
import org.ovirt.engine.core.common.action.ActionType;
import org.ovirt.engine.core.common.action.MaintenanceVdsParameters;
import org.ovirt.engine.core.common.action.MigrateMultipleVmsParameters;
Expand Down Expand Up @@ -89,7 +90,12 @@ protected void executeCommand() {
}
}

setSucceeded(migrateAllVms(getExecutionContext()));
ActionReturnValue returnValue = migrateAllVms(getExecutionContext());
setSucceeded(returnValue.getSucceeded());
if (!returnValue.isValid()) {
getReturnValue().setValid(false);
getReturnValue().getValidationMessages().addAll(returnValue.getValidationMessages());
}

// if non responsive move directly to maintenance
if (getVds().getStatus() == VDSStatus.NonResponsive
Expand Down Expand Up @@ -120,17 +126,14 @@ protected void orderListOfRunningVmsOnVds(Guid vdsId) {
/**
* Note: you must call {@link #orderListOfRunningVmsOnVds(Guid)} before calling this method
*/
protected boolean migrateAllVms(ExecutionContext parentContext) {
protected ActionReturnValue migrateAllVms(ExecutionContext parentContext) {
return migrateAllVms(parentContext, false);
}

/**
* Note: you must call {@link #orderListOfRunningVmsOnVds(Guid)} before calling this method
*/
protected boolean migrateAllVms(ExecutionContext parentContext, boolean HAOnly) {

boolean succeeded = true;

protected ActionReturnValue migrateAllVms(ExecutionContext parentContext, boolean HAOnly) {
if (shouldSetMigrationClientCerts()) {
runAnsibleMigrationCerts();
}
Expand All @@ -143,17 +146,19 @@ protected boolean migrateAllVms(ExecutionContext parentContext, boolean HAOnly)
}
}

if (!migrateVms(vmsToMigrate, parentContext)) {
succeeded = false;
ActionReturnValue returnValue = migrateVms(vmsToMigrate, parentContext);
if (!returnValue.getSucceeded()) {
// There is no way to find out which VMs failed to migrate, so the error message is general.
log.error("Failed to migrate one or more VMs.");
}
return succeeded;
return returnValue;
}

private boolean migrateVms(List<VM> vms, ExecutionContext parentContext) {
private ActionReturnValue migrateVms(List<VM> vms, ExecutionContext parentContext) {
if (vms.isEmpty()) {
return true;
ActionReturnValue returnValue = new ActionReturnValue();
returnValue.setSucceeded(true);
return returnValue;
}

boolean forceMigration = !getParameters().isInternal();
Expand All @@ -177,8 +182,7 @@ private boolean migrateVms(List<VM> vms, ExecutionContext parentContext) {
parameters.setReason(MessageBundler.getMessage(AuditLogType.MIGRATION_REASON_HOST_IN_MAINTENANCE));
return runInternalAction(ActionType.MigrateMultipleVms,
parameters,
createMigrateVmsContext(parentContext))
.getSucceeded();
createMigrateVmsContext(parentContext));
}

protected CommandContext createMigrateVmsContext(ExecutionContext parentContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected boolean validate() {
.hostBlackList(getHostBlackList())
.hostWhiteList(getHostWhiteList())
.ignoreHardVmToVmAffinity(getParameters().isCanIgnoreHardVmAffinity())
// TODO - Use error messages from scheduling
.outputMessages(getReturnValue().getValidationMessages())
.canSchedule(getVms());

possibleVmsToMigrate = new ArrayList<>(getVms().size());
Expand Down