Kanagaraj M has uploaded a new change for review.

Change subject: webadmin: Adding confirmation for replicate gluster volumes
......................................................................

webadmin: Adding confirmation for replicate gluster volumes

While creating a Replicate or Distributed Replicate volume,
if more than one brick is added from the same server,
a confirmation popup will be shown.

Change-Id: Id783c1404eb79b32981bbf137d4228675f3e960f
Bug-Url: https://bugzilla.redhat.com/871261
Signed-off-by: Kanagaraj M <kmayi...@redhat.com>
---
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeBrickModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeModel.java
M 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/gluster/VolumePopupPresenterWidget.java
4 files changed, 116 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/18/10018/1

diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeBrickModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeBrickModel.java
index 125c6f0..82016b8 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeBrickModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeBrickModel.java
@@ -1,7 +1,9 @@
 package org.ovirt.engine.ui.uicommonweb.models.gluster;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.ovirt.engine.core.common.businessentities.VDS;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
@@ -585,6 +587,44 @@
         return getReplicaCount().getIsValid() && getStripeCount().getIsValid();
     }
 
+    public boolean validateReplicateBricks(GlusterVolumeType volumeType) {
+
+        if(volumeType == GlusterVolumeType.REPLICATE) {
+            Set<String> servers = new HashSet<String>();
+            for (Object model : bricks.getItems())
+            {
+                GlusterBrickEntity brick = (GlusterBrickEntity) ((EntityModel) 
model).getEntity();
+                if (servers.contains(brick.getServerName())) {
+                    return false;
+                }
+                else {
+                    servers.add(brick.getServerName());
+                }
+            }
+        }
+        else if (volumeType == GlusterVolumeType.DISTRIBUTED_REPLICATE) {
+            int replicaCount = getReplicaCountValue();
+            Set<String> servers = new HashSet<String>();
+            int count = 0;
+            for (Object model : bricks.getItems())
+            {
+                count++;
+                GlusterBrickEntity brick = (GlusterBrickEntity) ((EntityModel) 
model).getEntity();
+                if (servers.contains(brick.getServerName())) {
+                    return false;
+                }
+                else {
+                    servers.add(brick.getServerName());
+                }
+                if (count % replicaCount == 0) {
+                    servers.clear();
+                }
+            }
+        }
+
+        return true;
+    }
+
     @Override
     public void ExecuteCommand(UICommand command) {
         super.ExecuteCommand(command);
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeModel.java
index 3052c5a..993edea 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/gluster/VolumeModel.java
@@ -20,6 +20,7 @@
 import org.ovirt.engine.ui.uicommonweb.UICommand;
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
 import org.ovirt.engine.ui.uicommonweb.models.ApplicationModeHelper;
+import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
 import org.ovirt.engine.ui.uicommonweb.models.Model;
@@ -325,7 +326,7 @@
         else
             volumeBrickModel.getBricks().setItems(new 
ArrayList<EntityModel>());
 
-        UICommand command = new UICommand("Ok", this); //$NON-NLS-1$
+        UICommand command = new UICommand("OnAddBricks", this); //$NON-NLS-1$
         command.setTitle(ConstantsManager.getInstance().getConstants().ok());
         command.setIsDefault(true);
         volumeBrickModel.getCommands().add(command);
@@ -345,7 +346,8 @@
             return;
         }
 
-        if (!volumeBrickModel.validateBrickCount((GlusterVolumeType) 
getTypeList().getSelectedItem(), true))
+        GlusterVolumeType volumeType = (GlusterVolumeType) 
getTypeList().getSelectedItem();
+        if (!volumeBrickModel.validateBrickCount(volumeType, true))
         {
             String validationMsg =
                     
volumeBrickModel.getValidationFailedMsg((GlusterVolumeType) 
getTypeList().getSelectedItem(), true);
@@ -353,7 +355,43 @@
             {
                 volumeBrickModel.setMessage(validationMsg);
             }
+            return;
+        }
 
+        if ((volumeType == GlusterVolumeType.REPLICATE || volumeType == 
GlusterVolumeType.DISTRIBUTED_REPLICATE)
+                && !volumeBrickModel.validateReplicateBricks(volumeType)) {
+            ConfirmationModel confirmModel = new ConfirmationModel();
+            setConfirmWindow(confirmModel);
+            confirmModel.setTitle(ConstantsManager.getInstance()
+                    .getConstants()
+                    .addBricksReplicateConfirmationTitle());
+            confirmModel.setHashName("add_bricks_confirmation"); //$NON-NLS-1$
+            confirmModel.setMessage(ConstantsManager.getInstance()
+                    .getConstants()
+                    .addBricksToReplicateVolumeFromSameServerMsg());
+
+            UICommand okCommand = new UICommand("OnAddBricksInternal", this); 
//$NON-NLS-1$
+            
okCommand.setTitle(ConstantsManager.getInstance().getConstants().yes());
+            okCommand.setIsDefault(true);
+            getConfirmWindow().getCommands().add(okCommand);
+
+            UICommand cancelCommand = new UICommand("CancelConfirmation", 
this); //$NON-NLS-1$
+            
cancelCommand.setTitle(ConstantsManager.getInstance().getConstants().no());
+            cancelCommand.setIsCancel(true);
+            getConfirmWindow().getCommands().add(cancelCommand);
+        }
+        else {
+            onAddBricksInternal();
+        }
+    }
+
+    private void onAddBricksInternal() {
+        VolumeBrickModel volumeBrickModel = (VolumeBrickModel) getWindow();
+
+        cancelConfirmation();
+
+        if (!volumeBrickModel.validate())
+        {
             return;
         }
 
@@ -382,6 +420,10 @@
 
         setBricks(brickListModel);
         setWindow(null);
+    }
+
+    private void cancelConfirmation() {
+        setConfirmWindow(null);
     }
 
     public boolean validateBrickCount()
@@ -492,10 +534,14 @@
         if (command == getAddBricksCommand())
         {
             addBricks();
-        } else if (command.getName().equals("Ok")) { //$NON-NLS-1$
+        } else if (command.getName().equals("OnAddBricks")) { //$NON-NLS-1$
             onAddBricks();
         } else if (command.getName().equals("Cancel")) { //$NON-NLS-1$
             setWindow(null);
+        } else if (command.getName().equals("OnAddBricksInternal")) { 
//$NON-NLS-1$
+            onAddBricksInternal();
+        } else if (command.getName().equals("CancelConfirmation")) { 
//$NON-NLS-1$
+            cancelConfirmation();
         }
     }
 
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
index f934c4a..86c53d7 100644
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java
@@ -12,6 +12,12 @@
     @DefaultStringValue("Cancel")
     String cancel();
 
+    @DefaultStringValue("Yes")
+    String yes();
+
+    @DefaultStringValue("No")
+    String no();
+
     @DefaultStringValue("Close")
     String close();
 
@@ -1311,6 +1317,9 @@
     @DefaultStringValue("Move Down")
     String moveBricksDownButtonLabel();
 
+    @DefaultStringValue("Replicate Confirmation")
+    String addBricksReplicateConfirmationTitle();
+
     @DefaultStringValue("Add")
     String AddVolume();
 
@@ -1413,6 +1422,9 @@
     @DefaultStringValue("Bricks cannot be empty")
     String emptyAddBricksMsg();
 
+    @DefaultStringValue("Multiple bricks of a Replicate volume are present on 
the same server. This setup is not optimal. \nDo you still want to continue?")
+    String addBricksToReplicateVolumeFromSameServerMsg();
+
     @DefaultStringValue("Cannot choose Volume's Data Center in tree context")
     String cannotChooseVolumesDataCenterinTreeContect();
 
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/gluster/VolumePopupPresenterWidget.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/gluster/VolumePopupPresenterWidget.java
index b071d69..217c942 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/gluster/VolumePopupPresenterWidget.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/popup/gluster/VolumePopupPresenterWidget.java
@@ -1,7 +1,9 @@
 package org.ovirt.engine.ui.webadmin.section.main.presenter.popup.gluster;
 
 import 
org.ovirt.engine.ui.common.presenter.AbstractModelBoundPopupPresenterWidget;
+import 
org.ovirt.engine.ui.common.presenter.popup.DefaultConfirmationPopupPresenterWidget;
 import org.ovirt.engine.ui.uicommonweb.UICommand;
+import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
 import org.ovirt.engine.ui.uicommonweb.models.Model;
 import org.ovirt.engine.ui.uicommonweb.models.gluster.VolumeModel;
 
@@ -15,12 +17,15 @@
     }
 
     private Provider<AddBrickPopupPresenterWidget> popupProvider;
+    Provider<DefaultConfirmationPopupPresenterWidget> 
defaultConfirmPopupProvider;
 
     @Inject
     public VolumePopupPresenterWidget(EventBus eventBus, ViewDef view,
-            Provider<AddBrickPopupPresenterWidget> popupProvider) {
+            Provider<AddBrickPopupPresenterWidget> popupProvider,
+            Provider<DefaultConfirmationPopupPresenterWidget> 
defaultConfirmPopupProvider) {
         super(eventBus, view);
         this.popupProvider = popupProvider;
+        this.defaultConfirmPopupProvider = defaultConfirmPopupProvider;
     }
 
     @Override
@@ -33,4 +38,13 @@
         }
     }
 
+    @Override
+    public AbstractModelBoundPopupPresenterWidget<? extends ConfirmationModel, 
?> getConfirmModelPopup(VolumeModel source,
+            UICommand lastExecutedCommand) {
+        if (lastExecutedCommand.getName().equals("OnAddBricks")) { 
//$NON-NLS-1$
+            return defaultConfirmPopupProvider.get();
+        } else {
+            return super.getConfirmModelPopup(source, lastExecutedCommand);
+        }
+    }
 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id783c1404eb79b32981bbf137d4228675f3e960f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Kanagaraj M <kmayi...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to