Maor Lipchuk has uploaded a new change for review. Change subject: core: Create cinder snapshot call back ......................................................................
core: Create cinder snapshot call back Add Cinder snapshot disk call back Change-Id: I986b41aba646c84d0d9d7fe771957cba6faf777a Bug-Url: https://bugzilla.redhat.com/?????? Signed-off-by: Maor Lipchuk <[email protected]> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/CreateCinderSnapshotCommandCallback.java 1 file changed, 96 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/78/40978/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/CreateCinderSnapshotCommandCallback.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/CreateCinderSnapshotCommandCallback.java new file mode 100644 index 0000000..4e83666 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/CreateCinderSnapshotCommandCallback.java @@ -0,0 +1,96 @@ +package org.ovirt.engine.core.bll.storage; + +import java.util.List; + +import org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil; +import org.ovirt.engine.core.common.action.ImagesContainterParametersBase; +import org.ovirt.engine.core.common.businessentities.storage.CinderDisk; +import org.ovirt.engine.core.common.businessentities.storage.DiskImage; +import org.ovirt.engine.core.common.businessentities.storage.ImageStatus; +import org.ovirt.engine.core.compat.CommandStatus; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dao.BaseDiskDao; +import org.ovirt.engine.core.dao.DiskDao; +import org.ovirt.engine.core.dao.DiskImageDAO; +import org.ovirt.engine.core.dao.ImageDao; + +public class CreateCinderSnapshotCommandCallback extends AbstractCinderDiskCommandCallback<CreateCinderSnapshotCommand<ImagesContainterParametersBase>> { + + @Override + public void doPolling(Guid cmdId, List<Guid> childCmdIds) { + super.doPolling(cmdId, childCmdIds); + + ImageStatus imageStatus = getCinderBroker().getSnapshotStatus(getDiskId()); + DiskImage disk = getDisk(); + if (imageStatus != null && imageStatus != disk.getImageStatus()) { + switch (imageStatus) { + case OK: + getCommand().setCommandStatus(CommandStatus.SUCCEEDED); + break; + case ILLEGAL: + getCommand().setCommandStatus(CommandStatus.FAILED); + break; + } + } + } + + @Override + public void onFailed(Guid cmdId, List<Guid> childCmdIds) { + super.onFailed(cmdId, childCmdIds); + + // If the cinder disk has a snapshot and it is not a part of a template. + if ((!getDisk().getParentId().equals(Guid.Empty)) + && (!getDisk().getParentId().equals(getDisk().getImageTemplateId()))) { + DiskImage previousSnapshot = getDiskImageDAO().getSnapshotById(getDisk().getParentId()); + previousSnapshot.setActive(true); + getImageDao().update(previousSnapshot.getImage()); + } + onFinish(cmdId); + } + + @Override + public void onSucceeded(Guid cmdId, List<Guid> childCmdIds) { + super.onSucceeded(cmdId, childCmdIds); + onFinish(cmdId); + } + + private void onFinish(Guid cmdId) { + getCommand().endAction(); + CommandCoordinatorUtil.removeAllCommandsInHierarchy(cmdId); + } + + @Override + protected Guid getDiskId() { + return getCommand().getParameters().getDestinationImageId(); + } + + @Override + protected CinderDisk getDisk() { + if (disk == null) { + disk = (CinderDisk) getDiskImageDAO().get(getCommand().getParameters().getDestinationImageId()); + } + return disk; + } + + protected DiskDao getDiskDao() { + return DbFacade.getInstance().getDiskDao(); + } + + protected ImageDao getImageDao() { + return DbFacade.getInstance().getImageDao(); + } + + protected BaseDiskDao getBaseDiskDao() { + return DbFacade.getInstance().getBaseDiskDao(); + } + + protected DiskImageDAO getDiskImageDAO() { + return DbFacade.getInstance().getDiskImageDao(); + } + + @Override + protected CinderBroker getCinderBroker() { + return getCommand().getCinderBroker(); + } +} -- To view, visit https://gerrit.ovirt.org/40978 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I986b41aba646c84d0d9d7fe771957cba6faf777a Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Maor Lipchuk <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
