Skip to content

Commit

Permalink
core: fix execution of RemoveImage
Browse files Browse the repository at this point in the history
RemoveImage now attaches the created async task to itself rather than to
its parent command and its EndProcedure type is changed to COMMAND_MANAGED.
With these changes, first the execution of RemoveImage is completed and
then its parent's callback detects it and completes the execution of the
parent command.

Signed-off-by: Arik Hadas <ahadas@redhat.com>
  • Loading branch information
ahadas committed Dec 4, 2022
1 parent 9493182 commit f9d1503
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ private RemoveImageParameters buildRemoveImageParameters(DiskImage diskImage) {
RemoveImageParameters result = new RemoveImageParameters(diskImage.getImageId());
result.setTransactionScopeOption(TransactionScopeOption.Suppress);
result.setDiskImage(diskImage);
result.setParentCommand(ActionType.RemoveDisk);
result.setParentCommand(getActionType());
result.setEntityInfo(new EntityInfo(VdcObjectType.Disk, getParameters().getDiskId()));
result.setParentParameters(getParameters());
result.setRemoveFromSnapshots(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Typed;
import javax.inject.Inject;

import org.apache.commons.lang.StringUtils;
import org.ovirt.engine.core.bll.InternalCommandAttribute;
import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute;
import org.ovirt.engine.core.bll.context.CommandContext;
import org.ovirt.engine.core.bll.storage.domain.PostDeleteActionHandler;
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.ActionType;
Expand Down Expand Up @@ -88,10 +85,6 @@ public class RemoveImageCommand<T extends RemoveImageParameters> extends BaseIma
@Inject
private VmDao vmDao;

@Inject
@Typed(RemoveImageCommandCallback.class)
private Instance<RemoveImageCommandCallback> callbackProvider;


public RemoveImageCommand(T parameters, CommandContext cmdContext) {
super(parameters, cmdContext);
Expand Down Expand Up @@ -136,7 +129,7 @@ protected void executeCommand() {
VDSReturnValue vdsReturnValue = performDeleteImageVdsmOperation();
Guid vdsmTaskId = createTask(taskId,
vdsReturnValue.getCreationInfo(),
getParameters().getParentCommand(),
ActionType.RemoveImage,
VdcObjectType.Storage,
getStorageDomainId());
getTaskIdList().add(vdsmTaskId);
Expand Down Expand Up @@ -286,11 +279,21 @@ protected List<Snapshot> prepareSnapshotConfigWithoutImage(Guid imageGroupToRemo

@Override
protected void endSuccessfully() {
performImageDbOperations();
setSucceeded(true);
}

@Override
protected void endWithFailure() {
List<Guid> snapshotIds = diskImageDao
.getAllSnapshotsForImageGroup(getImageGroupId()).stream()
.map(DiskImage::getImageId)
.collect(Collectors.toList());
addCustomValue("DiskId", getImageGroupId().toString());
addCustomValue("VolumeIds", StringUtils.join(snapshotIds, ','));
auditLog(this, AuditLogType.DELETE_IMAGE_GROUP_TASK_FAILED);

imageDao.updateStatusOfImagesByImageGroupId(getImageGroupId(), ImageStatus.ILLEGAL);
setSucceeded(true);
}

Expand Down Expand Up @@ -337,33 +340,4 @@ protected VDSReturnValue performDeleteImageVdsmOperation() {
getDiskImage().isWipeAfterDelete(), getStorageDomain().getDiscardAfterDelete(),
getParameters().isForceDelete())));
}

@Override
public CommandCallback getCallback() {
return callbackProvider.get();
}

public void onSucceeded() {
performImageDbOperations();
}

public void onFailed() {
if (getParameters().getAsyncTaskErrorMessage() != null) {
Guid diskId = getParameters().getDiskImage().getId();
List<Guid> snapshotIds = diskImageDao
.getAllSnapshotsForImageGroup(diskId).stream()
.map(DiskImage::getImageId)
.collect(Collectors.toList());
addCustomValue("DiskId", diskId.toString());
addCustomValue("VolumeIds", StringUtils.join(snapshotIds, ','));
addCustomValue("ErrorMessage", getParameters().getAsyncTaskErrorMessage());
auditLog(this, AuditLogType.DELETE_IMAGE_GROUP_TASK_FAILED);
}
imageDao.updateStatusOfImagesByImageGroupId(getImageGroupId(), ImageStatus.ILLEGAL);
}

@Override
protected void setSucceeded(boolean value) {
super.setSucceeded(value);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public class RemoveImageParameters extends ImagesContainterParametersBase implem
private ImageDbOperationScope dbOperationScope;
private boolean removeFromSnapshots;
private boolean shouldLockImage;
private String asyncTaskErrorMessage;

public RemoveImageParameters(Guid imageId) {
super(imageId, null);
setForceDelete(false);
dbOperationScope = ImageDbOperationScope.IMAGE;
shouldLockImage= true;
setEndProcedure(EndProcedure.COMMAND_MANAGED);
}

public RemoveImageParameters() {
Expand Down Expand Up @@ -56,12 +56,4 @@ public boolean isRemoveFromSnapshots() {
public void setRemoveFromSnapshots(boolean removeFromSnapshots) {
this.removeFromSnapshots = removeFromSnapshots;
}

public String getAsyncTaskErrorMessage() {
return asyncTaskErrorMessage;
}

public void setAsyncTaskErrorMessage(String asyncTaskErrorMessage) {
this.asyncTaskErrorMessage = asyncTaskErrorMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1360,4 +1360,4 @@ VNICS_OUT_OF_SYNC_ON_NETWORK_UPDATE=Update to network ${NetworkName} was not app
VNICS_OUT_OF_SYNC_ON_PROFILE_UPDATE=Update to network interface profile ${ProfileName} was not applied to virtual network interfaces [${VnicNames}]. The actual configuration on the interfaces may differ from the displayed one.
VM_BACKUP_SNAPSHOT_POSSIBLE_LEFTOVER=Possible failure while removing a snapshot that was generated automatically during backup of VM '${VmName}'. The snapshot may be removed manually
VM_BACKUP_FAILED_UNMONITORED=Backup ${BackupId} for VM ${VmName} was marked as failed since it is no longer monitored, cleanup may be required.
DELETE_IMAGE_GROUP_TASK_FAILED=Image group deletion task for disk ${DiskId} with volume(s) [${VolumeIds}] failed. Manual volume removal might be required. Underlying error message: ${ErrorMessage}
DELETE_IMAGE_GROUP_TASK_FAILED=Image group deletion task for disk ${DiskId} with volume(s) [${VolumeIds}] failed. Manual volume removal might be required.

0 comments on commit f9d1503

Please sign in to comment.