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: validate transfer phase #92

Merged
merged 1 commit into from
Sep 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 @@ -10,6 +10,7 @@

import org.ovirt.engine.core.bll.LockMessagesMatchUtil;
import org.ovirt.engine.core.common.businessentities.storage.ImageTransfer;
import org.ovirt.engine.core.common.businessentities.storage.ImageTransferPhase;
import org.ovirt.engine.core.common.errors.EngineMessage;
import org.ovirt.engine.core.common.locks.LockingGroup;
import org.ovirt.engine.core.compat.Guid;
Expand Down Expand Up @@ -50,12 +51,18 @@ public ImageTransfer updateEntity(ImageTransfer updates, Guid commandId, boolean
entity.setId(updates.getId());
}
if (updates.getPhase() != null) {
// TODO: Validate that phase change is valid. For now just log.
log.info("Updating image transfer '{}' phase from '{}' to '{}'",
commandId,
entity.getPhase(),
updates.getPhase());
entity.setPhase(updates.getPhase());
if (!ImageTransferPhase.isValidTransition(entity.getPhase(), updates.getPhase())) {
log.error("Image transfer '{}' transition from phase '{}' to '{}' is invalid",
commandId,
entity.getPhase(),
updates.getPhase());
} else {
log.info("Updating image transfer '{}' phase from '{}' to '{}'",
commandId,
entity.getPhase(),
updates.getPhase());
entity.setPhase(updates.getPhase());
}
}
if (updates.getType() != null) {
entity.setType(updates.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,39 @@ public enum ImageTransferPhase implements Identifiable {
private String description;
private static final Map<Integer, ImageTransferPhase> valueToPhase = new HashMap<>();

// TODO: revisit this in the future to validate all transitions
// private static final EnumMap<ImageTransferPhase, EnumSet<ImageTransferPhase>> validTransitions = new EnumMap<>(ImageTransferPhase.class);

static {
for (ImageTransferPhase phase : values()) {
valueToPhase.put(phase.getValue(), phase);
}

// TODO: revisit this in the future to validate all transitions
// validTransitions.put(INITIALIZING, EnumSet.of(TRANSFERRING, PAUSED_SYSTEM, CANCELLED_SYSTEM));
// validTransitions.put(TRANSFERRING, EnumSet.of(FINALIZING_SUCCESS, PAUSED_SYSTEM, CANCELLED_SYSTEM, CANCELLED_USER, PAUSED_USER));
// validTransitions.put(RESUMING, EnumSet.of(TRANSFERRING, PAUSED_SYSTEM, CANCELLED_SYSTEM));
// validTransitions.put(PAUSED_SYSTEM, EnumSet.of(RESUMING, CANCELLED_USER, CANCELLED_SYSTEM));
// validTransitions.put(PAUSED_USER, EnumSet.of(RESUMING, CANCELLED_USER, CANCELLED_SYSTEM));
// validTransitions.put(CANCELLED_USER, EnumSet.of(FINALIZING_CLEANUP));
// validTransitions.put(CANCELLED_SYSTEM, EnumSet.of(FINALIZING_FAILURE));
// validTransitions.put(FINALIZING_SUCCESS, EnumSet.of(FINALIZING_FAILURE, FINISHED_SUCCESS));
// validTransitions.put(FINALIZING_FAILURE, EnumSet.of(FINISHED_FAILURE));
// validTransitions.put(FINALIZING_CLEANUP, EnumSet.of(FINISHED_CLEANUP));
// validTransitions.put(FINISHED_FAILURE, EnumSet.of(FINISHED_FAILURE));
// validTransitions.put(FINISHED_SUCCESS, EnumSet.of(FINISHED_SUCCESS));

}

ImageTransferPhase(int value, String description) {
this.value = value;
this.description = description;
}

public static boolean isValidTransition(ImageTransferPhase from, ImageTransferPhase to) {
return !from.isFinished();
}
ahadas marked this conversation as resolved.
Show resolved Hide resolved

@Override
public int getValue() {
return value;
Expand Down