Federico Simoncelli has uploaded a new change for review.

Change subject: [wip] core,webadmin: add the image block alignment check
......................................................................

[wip] core,webadmin: add the image block alignment check

Change-Id: I4858b7bbfa453230fcafecfbc5358c715d5d825b
Signed-off-by: Federico Simoncelli <[email protected]>
---
M backend/manager/dbscripts/images_sp.sql
A backend/manager/dbscripts/upgrade/03_02_0430_image_block_alignment.sql
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CheckImageAlignmentCommand.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/CheckImageAlignmentParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImageBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Image.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/ImageBlockAlignment.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/CheckImageAlignmentVDSCommandParameters.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
A 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/CheckImageAlignmentVDSCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IIrsServer.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerConnector.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerWrapper.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
A 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/DiskAlignmentCell.java
A 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/DiskAlignmentColumn.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/vm/VmDiskListModelTable.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabDiskView.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/storage/SubTabStorageDiskView.java
24 files changed, 425 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/46/11946/1

diff --git a/backend/manager/dbscripts/images_sp.sql 
b/backend/manager/dbscripts/images_sp.sql
index 65f829e..145bd58 100644
--- a/backend/manager/dbscripts/images_sp.sql
+++ b/backend/manager/dbscripts/images_sp.sql
@@ -177,3 +177,14 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+Create or replace FUNCTION UpdateImageAlignment(
+    v_image_id UUID,
+    v_alignment SMALLINT)
+RETURNS VOID
+AS $procedure$
+BEGIN
+    UPDATE images
+    SET    alignment = v_alignment
+    WHERE  image_guid = v_image_id;
+END; $procedure$
+LANGUAGE plpgsql;
diff --git 
a/backend/manager/dbscripts/upgrade/03_02_0430_image_block_alignment.sql 
b/backend/manager/dbscripts/upgrade/03_02_0430_image_block_alignment.sql
new file mode 100644
index 0000000..a482546
--- /dev/null
+++ b/backend/manager/dbscripts/upgrade/03_02_0430_image_block_alignment.sql
@@ -0,0 +1,2 @@
+select fn_db_add_column('images', 'alignment', 'SMALLINT DEFAULT 0');
+select fn_db_add_column('images', 'lastAlignmentCheck', 'TIMESTAMP WITH TIME 
ZONE');
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CheckImageAlignmentCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CheckImageAlignmentCommand.java
new file mode 100644
index 0000000..809b73b
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CheckImageAlignmentCommand.java
@@ -0,0 +1,132 @@
+package org.ovirt.engine.core.bll;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.ovirt.engine.core.bll.utils.PermissionSubject;
+import org.ovirt.engine.core.common.VdcObjectType;
+import org.ovirt.engine.core.common.action.CheckImageAlignmentParameters;
+import org.ovirt.engine.core.common.businessentities.ActionGroup;
+import org.ovirt.engine.core.common.businessentities.Disk;
+import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.VMStatus;
+import org.ovirt.engine.core.common.businessentities.VmDevice;
+import org.ovirt.engine.core.common.businessentities.VmDeviceId;
+import org.ovirt.engine.core.common.businessentities.VmEntityType;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.VdcBllMessages;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.dal.dbbroker.auditloghandling.CustomLogField;
+import org.ovirt.engine.core.dal.dbbroker.auditloghandling.CustomLogFields;
+import org.ovirt.engine.core.dao.DiskDao;
+import org.ovirt.engine.core.dao.DiskImageDAO;
+import org.ovirt.engine.core.dao.VmDeviceDAO;
+
+@DisableInPrepareMode
+@CustomLogFields({ @CustomLogField("DiskAlias") })
+@NonTransactiveCommandAttribute
+public class CheckImageAlignmentCommand<T extends 
CheckImageAlignmentParameters> extends CommandBase<T> {
+    private static final long serialVersionUID = -7266894047095142486L;
+
+    private Disk disk;
+    private List<PermissionSubject> permsList = null;
+    private List<VM> listVms;
+
+    public CheckImageAlignmentCommand(T parameters) {
+        super(parameters);
+        setStorageDomainId(getParameters().getStorageDomainId());
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__REMOVE);
+        addCanDoActionMessage(VdcBllMessages.VAR__TYPE__VM_DISK);
+    }
+
+    @Override
+    protected boolean canDoAction() {
+        if (getDisk() == null) {
+            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST);
+        }
+
+        return acquireLockInternal() && validateAllVmsForDiskAreDown();
+    }
+
+    private boolean validateAllVmsForDiskAreDown() {
+        if (getDisk().getVmEntityType() == VmEntityType.VM) {
+            for (VM vm : getVmsForDiskId()) {
+                if (vm.getStatus() != VMStatus.Down) {
+                    VmDevice vmDevice = getVmDeviceDAO().get(new 
VmDeviceId(getDisk().getId(), vm.getId()));
+                    if (vmDevice.getIsPlugged()) {
+                        
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_VM_IS_NOT_DOWN);
+                        return false;
+                    }
+                }
+            }
+        }
+
+        return true;
+    }
+
+
+    /**
+     * Cache method to retrieve all the VMs related to image
+     * @return List of Vms.
+     */
+    private List<VM> getVmsForDiskId() {
+        if (listVms == null) {
+            listVms = getVmDAO().getVmsListForDisk((Guid) 
getParameters().getEntityId());
+        }
+        return listVms;
+    }
+
+    protected VmDeviceDAO getVmDeviceDAO() {
+        return DbFacade.getInstance()
+                .getVmDeviceDao();
+    }
+
+    protected DiskImageDAO getDiskImageDao() {
+        return DbFacade.getInstance().getDiskImageDao();
+    }
+
+    protected DiskDao getDiskDao() {
+        return DbFacade.getInstance().getDiskDao();
+    }
+
+    @Override
+    protected void executeCommand() {
+    }
+
+    @Override
+    protected void endSuccessfully() {
+        endCommand();
+    }
+
+    @Override
+    protected void endWithFailure() {
+        endCommand();
+    }
+
+    private void endCommand() {
+        setSucceeded(true);
+    }
+
+    @Override
+    public List<PermissionSubject> getPermissionCheckSubjects() {
+        if (permsList == null && getDisk() != null) {
+            permsList = new ArrayList<PermissionSubject>();
+            permsList.add(new PermissionSubject(getDisk().getId(),
+                    VdcObjectType.Disk,
+                    ActionGroup.ATTACH_DISK));
+        }
+        return permsList;
+    }
+
+    protected Disk getDisk() {
+        if (disk == null) {
+            disk = getDiskDao().get((Guid) getParameters().getEntityId());
+        }
+
+        return disk;
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/CheckImageAlignmentParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/CheckImageAlignmentParameters.java
new file mode 100644
index 0000000..6a908ad
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/CheckImageAlignmentParameters.java
@@ -0,0 +1,18 @@
+package org.ovirt.engine.core.common.action;
+
+import org.ovirt.engine.core.compat.Guid;
+
+public class CheckImageAlignmentParameters extends StorageDomainParametersBase 
{
+    private static final long serialVersionUID = -6587274019503875891L;
+
+    private Guid imageId = Guid.Empty;
+
+    public CheckImageAlignmentParameters(Guid storageDomainId, Guid imageId) {
+        super(storageDomainId);
+        this.imageId = imageId;
+    }
+
+    public Guid getImageId() {
+        return imageId;
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
index ed6cd19..ff130b4 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
@@ -116,6 +116,7 @@
     RemoveSnapshotSingleDisk(227, QuotaDependency.STORAGE),
     CreateCloneOfTemplate(229, QuotaDependency.STORAGE),
     RemoveDisk(230, QuotaDependency.STORAGE),
+    CheckImageAlignment(231, QuotaDependency.NONE),
     // VmPoolCommands
     AddVmPool(301, QuotaDependency.NONE),
     UpdateUserVm(303, QuotaDependency.NONE),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImageBase.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImageBase.java
index 796a94f..de8e28f 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImageBase.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DiskImageBase.java
@@ -49,6 +49,10 @@
         getImage().setVolumeFormat(value);
     }
 
+    public ImageBlockAlignment getBlockAlignment() {
+        return getImage().getBlockAlignment();
+    }
+
     public Guid getQuotaId() {
         return getImage().getQuotaId();
     }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Image.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Image.java
index dc681e6..6fcefca 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Image.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Image.java
@@ -38,6 +38,8 @@
     @NotNull(message = "VALIDATION.VOLUME_FORMAT.NOT_NULL", groups = { 
CreateEntity.class, UpdateEntity.class })
     private VolumeFormat volumeFormat;
 
+    private ImageBlockAlignment blockAlignment;
+
     /**
      * The quota id the image consumes from.
      */
@@ -72,6 +74,7 @@
         this.volumeType = volumeType;
         this.size = size;
         this.volumeFormat = volumeFormat;
+        this.blockAlignment = ImageBlockAlignment.Unknown;
         this.quotaId = quotaId;
     }
 
@@ -173,6 +176,14 @@
         this.volumeFormat = volumeFormat;
     }
 
+    public ImageBlockAlignment getBlockAlignment() {
+        return blockAlignment;
+    }
+
+    public void setBlockAlignment(ImageBlockAlignment blockAlignment) {
+        this.blockAlignment = blockAlignment;
+    }
+
     public Guid getQuotaId() {
         return quotaId;
     }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/ImageBlockAlignment.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/ImageBlockAlignment.java
new file mode 100644
index 0000000..f5097b9
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/ImageBlockAlignment.java
@@ -0,0 +1,16 @@
+package org.ovirt.engine.core.common.businessentities;
+
+public enum ImageBlockAlignment implements Identifiable {
+    Unknown(0), Aligned(1), Misaligned(2);
+
+    private int intValue;
+
+    private ImageBlockAlignment(int value) {
+        intValue = value;
+    }
+
+    @Override
+    public int getValue() {
+        return intValue;
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/CheckImageAlignmentVDSCommandParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/CheckImageAlignmentVDSCommandParameters.java
new file mode 100644
index 0000000..2744d6f
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/CheckImageAlignmentVDSCommandParameters.java
@@ -0,0 +1,12 @@
+package org.ovirt.engine.core.common.vdscommands;
+
+import org.ovirt.engine.core.compat.*;
+
+public class CheckImageAlignmentVDSCommandParameters extends 
AllStorageAndImageIdVDSCommandParametersBase {
+    public CheckImageAlignmentVDSCommandParameters(Guid storagePoolId, Guid 
storageDomainId, Guid imageGroupId, Guid imageId) {
+        super(storagePoolId, storageDomainId, imageGroupId, imageId);
+    }
+
+    public CheckImageAlignmentVDSCommandParameters() {
+    }
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDao.java
index 17bda44..a2e9863 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDao.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.dao;
 
 import org.ovirt.engine.core.common.businessentities.Image;
+import org.ovirt.engine.core.common.businessentities.ImageBlockAlignment;
 import org.ovirt.engine.core.common.businessentities.ImageStatus;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.NGuid;
@@ -12,4 +13,6 @@
     void updateQuotaForImageAndSnapshots(Guid imageGroupId, NGuid quotaId);
 
     public void updateImageVmSnapshotId(Guid id, Guid vmSnapshotId);
+
+    public void updateImageBlockAlignment(Guid id, ImageBlockAlignment 
alignment);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
index f8ce502..fa5a325 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ImageDaoDbFacadeImpl.java
@@ -4,6 +4,7 @@
 import java.sql.SQLException;
 
 import org.ovirt.engine.core.common.businessentities.Image;
+import org.ovirt.engine.core.common.businessentities.ImageBlockAlignment;
 import org.ovirt.engine.core.common.businessentities.ImageStatus;
 import org.ovirt.engine.core.common.businessentities.VolumeFormat;
 import org.ovirt.engine.core.common.businessentities.VolumeType;
@@ -36,6 +37,14 @@
     }
 
     @Override
+    public void updateImageBlockAlignment(Guid id, ImageBlockAlignment 
alignment)
+    {
+        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
+                .addValue("alignment", alignment);
+        getCallsHandler().executeModification("UpdateImageAlignment", 
parameterSource);
+    }
+
+    @Override
     protected MapSqlParameterSource createFullParametersMapper(Image entity) {
         return createIdParameterMapper(entity.getId())
                 .addValue("creation_date", entity.getCreationDate())
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/CheckImageAlignmentVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/CheckImageAlignmentVDSCommand.java
new file mode 100644
index 0000000..ecd6973
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/CheckImageAlignmentVDSCommand.java
@@ -0,0 +1,19 @@
+package org.ovirt.engine.core.vdsbroker.irsbroker;
+
+import org.ovirt.engine.core.compat.*;
+import org.ovirt.engine.core.common.asynctasks.*;
+import org.ovirt.engine.core.common.vdscommands.*;
+
+public class CheckImageAlignmentVDSCommand<P extends 
CheckImageAlignmentVDSCommandParameters> extends IrsBrokerCommand<P> {
+    public CheckImageAlignmentVDSCommand(P parameters) {
+        super(parameters);
+    }
+
+    @Override
+    protected void ExecuteIrsBrokerCommand() {
+        
getIrsProxy().checkImageAlignment(getParameters().getStorageDomainId().toString(),
+                getParameters().getStoragePoolId().toString(), 
getParameters().getImageGroupId().toString());
+
+        ProceedProxyReturnValue();
+    }
+}
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IIrsServer.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IIrsServer.java
index 5fff8aa..b93f81c 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IIrsServer.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IIrsServer.java
@@ -70,6 +70,8 @@
     OneUuidReturnForXmlRpc moveImage(String spUUID, String srcDomUUID, String 
dstDomUUID, String imgGUID,
             String vmGUID, int op, String postZero, String force);
 
+    StatusOnlyReturnForXmlRpc checkImageAlignment(String sdUUID, String 
spUUID, String imgGUID);
+
     OneUuidReturnForXmlRpc cloneImageStructure(String spUUID, String 
srcDomUUID, String imgGUID, String dstDomUUID);
 
     OneUuidReturnForXmlRpc syncImageData(String spUUID, String srcDomUUID, 
String imgGUID, String dstDomUUID, String syncType);
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerConnector.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerConnector.java
index 506ef9b..27ba2de 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerConnector.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerConnector.java
@@ -88,6 +88,8 @@
 
     public Map<String, Object> getImageDomainsList(String spUUID, String 
imgUUID);
 
+    public Map<String, Object> checkImageAlignment(String sdUUID, String 
spUUID, String imgGUID);
+
     public Map<String, Object> setMaxHosts(int maxHosts);
 
     public Map<String, Object> updateVM(String spUUID, Map[] vms);
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerWrapper.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerWrapper.java
index 0ff238e..980ed1f 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerWrapper.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsServerWrapper.java
@@ -217,6 +217,12 @@
         return wrapper;
     }
 
+    public StatusOnlyReturnForXmlRpc checkImageAlignment(String sdUUID, String 
spUUID, String imgGUID) {
+        Map<String, Object> xmlRpcReturnValue = 
irsServer.checkImageAlignment(sdUUID, spUUID, imgGUID);
+        StatusOnlyReturnForXmlRpc wrapper = new 
StatusOnlyReturnForXmlRpc(xmlRpcReturnValue);
+        return wrapper;
+    }
+
     public StatusOnlyReturnForXmlRpc setMaxHosts(int maxHosts) {
         Map<String, Object> xmlRpcReturnValue = 
irsServer.setMaxHosts(maxHosts);
         StatusOnlyReturnForXmlRpc wrapper = new 
StatusOnlyReturnForXmlRpc(xmlRpcReturnValue);
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
index 5ab4dba..f447fc1 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/CommonApplicationConstants.java
@@ -618,6 +618,9 @@
     @DefaultStringValue("Move")
     String moveDisk();
 
+    @DefaultStringValue("Check Alignment")
+    String checkAlignmentDisk();
+
     @DefaultStringValue("Name")
     String nameDisk();
 
@@ -678,6 +681,9 @@
     @DefaultStringValue("Destination")
     String destDisk();
 
+    @DefaultStringValue("Aligned")
+    String alignedDisk();
+
     @DefaultStringValue("Attached To")
     String attachedToDisk();
 
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/DiskAlignmentCell.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/DiskAlignmentCell.java
new file mode 100644
index 0000000..cda1876
--- /dev/null
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/DiskAlignmentCell.java
@@ -0,0 +1,32 @@
+package org.ovirt.engine.ui.common.widget.table.column;
+
+import com.google.gwt.cell.client.Cell;
+import com.google.gwt.cell.client.ValueUpdater;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.NativeEvent;
+
+public class DiskAlignmentCell extends TextCellWithTooltip {
+
+    private String title = ""; //$NON-NLS-1$
+
+    public DiskAlignmentCell() {
+        super(TextCellWithTooltip.UNLIMITED_LENGTH);
+    }
+
+    @Override
+    public void onBrowserEvent(Cell.Context context, Element parent,
+            String value, NativeEvent event, ValueUpdater<String> 
valueUpdater) {
+        super.onBrowserEvent(context, parent, value, event, valueUpdater);
+
+        // Ignore events other than 'mouseover'
+        if (!"mouseover".equals(event.getType())) { //$NON-NLS-1$
+            return;
+        }
+
+        parent.setTitle(title);
+    }
+
+    public void setTitle(String title) {
+        this.title = title != null ? title : ""; //$NON-NLS-1$
+    }
+}
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/DiskAlignmentColumn.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/DiskAlignmentColumn.java
new file mode 100644
index 0000000..33f2558
--- /dev/null
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/table/column/DiskAlignmentColumn.java
@@ -0,0 +1,37 @@
+package org.ovirt.engine.ui.common.widget.table.column;
+
+import org.ovirt.engine.core.common.businessentities.Disk;
+import org.ovirt.engine.core.common.businessentities.DiskImage;
+import org.ovirt.engine.core.common.businessentities.ImageBlockAlignment;
+import org.ovirt.engine.ui.common.CommonApplicationConstants;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.cellview.client.Column;
+
+public class DiskAlignmentColumn extends Column<Disk, String> implements 
ColumnWithElementId {
+
+    private static final CommonApplicationConstants CONSTANTS = 
GWT.create(CommonApplicationConstants.class);
+
+    public DiskAlignmentColumn() {
+        super(new DiskAlignmentCell());
+    }
+
+    @Override
+    public String getValue(Disk object) {
+        ImageBlockAlignment alignment = ((DiskImage) 
object).getBlockAlignment();
+        getCell().setTitle(alignment.toString());
+//        getCell().setTitle("Unknown"); //$NON-NLS-1$
+        return "Unknown"; //$NON-NLS-1$
+    }
+
+    @Override
+    public void configureElementId(String elementIdPrefix, String columnId) {
+        getCell().setElementIdPrefix(elementIdPrefix);
+        getCell().setColumnId(columnId);
+    }
+
+    @Override
+    public DiskAlignmentCell getCell() {
+        return (DiskAlignmentCell) super.getCell();
+    }
+}
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
index 583fe8d..6c3759f 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/disks/DisksViewColumns.java
@@ -13,6 +13,7 @@
 import org.ovirt.engine.ui.common.CommonApplicationConstants;
 import org.ovirt.engine.ui.common.CommonApplicationResources;
 import 
org.ovirt.engine.ui.common.widget.renderer.DiskSizeRenderer.DiskSizeUnit;
+import org.ovirt.engine.ui.common.widget.table.column.DiskAlignmentColumn;
 import org.ovirt.engine.ui.common.widget.table.column.DiskContainersColumn;
 import org.ovirt.engine.ui.common.widget.table.column.DiskSizeColumn;
 import org.ovirt.engine.ui.common.widget.table.column.DiskStatusColumn;
@@ -110,6 +111,8 @@
 
     public static final DiskContainersColumn diskContainersColumn = new 
DiskContainersColumn();
 
+    public static final DiskAlignmentColumn diskAlignmentColumn = new 
DiskAlignmentColumn();
+
     public static final StorageDomainsColumn storageDomainsColumn = new 
StorageDomainsColumn();
 
     public static final DiskSizeColumn<Disk> sizeColumn = new 
DiskSizeColumn<Disk>() {
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/vm/VmDiskListModelTable.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/vm/VmDiskListModelTable.java
index 5d48a74..4f12d56 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/vm/VmDiskListModelTable.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/vm/VmDiskListModelTable.java
@@ -112,6 +112,13 @@
             });
         }
 
+        getTable().addActionButton(new 
UiCommandButtonDefinition<Disk>(getEventBus(), constants.checkAlignmentDisk()) {
+            @Override
+            protected UICommand resolveCommand() {
+                return getModel().getCheckAlignmentCommand();
+            }
+        });
+
         getTable().addActionButton(new 
UiCommandButtonDefinition<Disk>(getEventBus(), constants.assignQuota()) {
             @Override
             protected UICommand resolveCommand() {
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
index 0ca1805..d1302ca 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/disks/DiskListModel.java
@@ -5,6 +5,7 @@
 import org.ovirt.engine.core.common.action.AddDiskParameters;
 import org.ovirt.engine.core.common.action.AttachDettachVmDiskParameters;
 import org.ovirt.engine.core.common.action.ChangeQuotaParameters;
+import org.ovirt.engine.core.common.action.CheckImageAlignmentParameters;
 import org.ovirt.engine.core.common.action.RemoveDiskParameters;
 import org.ovirt.engine.core.common.action.UpdateVmDiskParameters;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
@@ -14,6 +15,7 @@
 import org.ovirt.engine.core.common.businessentities.Disk.DiskStorageType;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.DiskInterface;
+// import org.ovirt.engine.core.common.businessentities.ImageBlockAlignment;
 import org.ovirt.engine.core.common.businessentities.ImageStatus;
 import org.ovirt.engine.core.common.businessentities.LUNs;
 import org.ovirt.engine.core.common.businessentities.LunDisk;
@@ -109,6 +111,18 @@
         privateMoveCommand = value;
     }
 
+    private UICommand privateCheckAlignmentCommand;
+
+    public UICommand getCheckAlignmentCommand()
+    {
+        return privateCheckAlignmentCommand;
+    }
+
+    private void setCheckAlignmentCommand(UICommand value)
+    {
+        privateCheckAlignmentCommand = value;
+    }
+
     private UICommand privateChangeQuotaCommand;
 
     public UICommand getChangeQuotaCommand()
@@ -177,6 +191,7 @@
         setMoveCommand(new UICommand("Move", this)); //$NON-NLS-1$
         setChangeQuotaCommand(new UICommand("changeQuota", this)); 
//$NON-NLS-1$
         setCopyCommand(new UICommand("Copy", this)); //$NON-NLS-1$
+        setCheckAlignmentCommand(new UICommand("Check Alignment", this)); 
//$NON-NLS-1$
 
         UpdateActionAvailability();
 
@@ -473,6 +488,30 @@
         model.StartProgress(null);
     }
 
+    private void CheckAlignment()
+    {
+        DiskImage disk;
+        Guid storageId;
+
+        try {
+            disk = (DiskImage) getSelectedItems().get(0);
+            storageId = disk.getstorage_ids().get(0);
+        } catch (IndexOutOfBoundsException e) {
+            return;
+        }
+
+        ArrayList<VdcActionParametersBase> parameterList = new 
ArrayList<VdcActionParametersBase>();
+        parameterList.add(new CheckImageAlignmentParameters(storageId, 
disk.getImageId()));
+
+        Frontend.RunMultipleAction(VdcActionType.CheckImageAlignment, 
parameterList,
+                new IFrontendMultipleActionAsyncCallback() {
+                    @Override
+                    public void Executed(FrontendMultipleActionAsyncResult 
result) {
+                    }
+                },
+                this);
+    }
+
     private void changeQuota()
     {
         ArrayList<DiskImage> disks = (ArrayList<DiskImage>) getSelectedItems();
@@ -630,6 +669,7 @@
         getRemoveCommand().setIsExecutionAllowed(disks != null && disks.size() 
> 0 && isRemoveCommandAvailable());
         getMoveCommand().setIsExecutionAllowed(disks != null && disks.size() > 
0 && isMoveCommandAvailable());
         getCopyCommand().setIsExecutionAllowed(disks != null && disks.size() > 
0 && isCopyCommandAvailable());
+        getCheckAlignmentCommand().setIsExecutionAllowed(disks != null && 
disks.size() == 1 && isCheckAlignmentCommandAvailable());
         getChangeQuotaCommand().setIsAvailable(false);
         if (getSystemTreeSelectedItem() != null
                 && getSystemTreeSelectedItem().getType() == 
SystemTreeItemType.DataCenter
@@ -723,6 +763,11 @@
         return true;
     }
 
+    private boolean isCheckAlignmentCommandAvailable() {
+        // TODO: return false if the image is locked and/or the VM is running
+        return true;
+    }
+
     private void CancelConfirm()
     {
         DiskModel model = (DiskModel) getWindow();
@@ -756,6 +801,10 @@
         {
             Copy();
         }
+        else if (command == getCheckAlignmentCommand())
+        {
+            CheckAlignment();
+        }
         else if (StringHelper.stringsEqual(command.getName(), "OnSave")) 
//$NON-NLS-1$
         {
             OnSave();
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
index be10615..b6bffd9 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmDiskListModel.java
@@ -152,6 +152,18 @@
         privateMoveCommand = value;
     }
 
+    private UICommand privateCheckAlignmentCommand;
+
+    public UICommand getCheckAlignmentCommand()
+    {
+        return privateCheckAlignmentCommand;
+    }
+
+    private void setCheckAlignmentCommand(UICommand value)
+    {
+        privateCheckAlignmentCommand = value;
+    }
+
     private boolean privateIsDiskHotPlugSupported;
 
     public boolean getIsDiskHotPlugSupported()
@@ -204,6 +216,7 @@
         setPlugCommand(new UICommand("Plug", this)); //$NON-NLS-1$
         setUnPlugCommand(new UICommand("Unplug", this)); //$NON-NLS-1$
         setMoveCommand(new UICommand("Move", this)); //$NON-NLS-1$
+        setCheckAlignmentCommand(new UICommand("Check Alignment", this)); 
//$NON-NLS-1$
         setChangeQuotaCommand(new UICommand("changeQuota", this)); 
//$NON-NLS-1$
         getChangeQuotaCommand().setIsAvailable(false);
 
@@ -854,6 +867,10 @@
         model.StartProgress(null);
     }
 
+    private void CheckAlignment()
+    {
+    }
+
     private void ResetData() {
         presets = null;
         nextAlias = null;
@@ -916,6 +933,9 @@
 
         getMoveCommand().setIsExecutionAllowed(getSelectedItems() != null && 
getSelectedItems().size() > 0
                 && (isMoveCommandAvailable() || isLiveMoveCommandAvailable()));
+
+        getCheckAlignmentCommand().setIsExecutionAllowed(getSelectedItems() != 
null
+                && getSelectedItems().size() == 1 && 
isCheckAlignmentCommandAvailable());
 
         getPlugCommand().setIsExecutionAllowed(isPlugCommandAvailable(true));
 
@@ -1034,6 +1054,11 @@
         return true;
     }
 
+    private boolean isCheckAlignmentCommandAvailable() {
+        // TODO: return false if the image is locked and/or the VM is running
+        return true;
+    }
+
     @Override
     public void ExecuteCommand(UICommand command)
     {
@@ -1055,6 +1080,10 @@
         {
             Move();
         }
+        else if (command == getCheckAlignmentCommand())
+        {
+            CheckAlignment();
+        }
         else if (StringHelper.stringsEqual(command.getName(), "OnSave")) 
//$NON-NLS-1$
         {
             OnSave();
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabDiskView.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabDiskView.java
index ef22bc6..596a316 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabDiskView.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/MainTabDiskView.java
@@ -108,6 +108,10 @@
                 "125px"); //$NON-NLS-1$
 
         getTable().ensureColumnPresent(
+                DisksViewColumns.diskAlignmentColumn, constants.alignedDisk(), 
all || images || luns,
+                "125px"); //$NON-NLS-1$
+
+        getTable().ensureColumnPresent(
                 DisksViewColumns.storageDomainsColumn, 
constants.storageDomainsDisk(), images,
                 "125px"); //$NON-NLS-1$
 
@@ -188,6 +192,13 @@
             }
         });
 
+        getTable().addActionButton(new 
WebAdminButtonDefinition<Disk>(constants.checkAlignmentDisk()) {
+            @Override
+            protected UICommand resolveCommand() {
+                return getMainModel().getCheckAlignmentCommand();
+            }
+        });
+
         getTable().addActionButton(new 
WebAdminButtonDefinition<Disk>(constants.assignQuota()) {
             @Override
             protected UICommand resolveCommand() {
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/storage/SubTabStorageDiskView.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/storage/SubTabStorageDiskView.java
index 679e6dc..3ce08f0 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/storage/SubTabStorageDiskView.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/view/tab/storage/SubTabStorageDiskView.java
@@ -69,6 +69,9 @@
                 DisksViewColumns.diskContainersColumn, 
constants.attachedToDisk(), true, "120px"); //$NON-NLS-1$
 
         getTable().ensureColumnPresent(
+                DisksViewColumns.diskContainersColumn, 
constants.alignedDisk(), true, "120px"); //$NON-NLS-1$
+
+        getTable().ensureColumnPresent(
                 DisksViewColumns.interfaceColumn, constants.interfaceDisk(), 
true, "100px"); //$NON-NLS-1$
 
         getTable().ensureColumnPresent(


--
To view, visit http://gerrit.ovirt.org/11946
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4858b7bbfa453230fcafecfbc5358c715d5d825b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to