Libor Spevak has uploaded a new change for review.

Change subject: webadmin: Default host for RunOnce dialog enabled
......................................................................

webadmin: Default host for RunOnce dialog enabled

New panel with default host selection is added to the RunOnce dialog.
The appearance is similar to the VM edit dialog Host tab.
The RunOnce dialog host panel is invisible in the User Portal application.

Change-Id: I1906caf40c91e12a56523ddda794c72690947d4c
Bug-Url: https://bugzilla.redhat.com/560981
Signed-off-by: Libor Spevak <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPayload.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.ui.xml
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/RunOnceModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
6 files changed, 245 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/54/10654/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPayload.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPayload.java
index 3bd42ff..381bf48 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPayload.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPayload.java
@@ -44,7 +44,7 @@
     }
 
     public static boolean isPayload(Map<String, Object> specParams) {
-        return specParams.containsKey(SpecParamsPayload);
+        return specParams == null ? false : 
specParams.containsKey(SpecParamsPayload);
     }
 
     public static boolean isPayloadSizeLegal(String payload) {
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.java
index c90daea..f428cad 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.java
@@ -1,8 +1,10 @@
 package org.ovirt.engine.ui.common.widget.uicommon.popup.vm;
 
+import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.compat.Event;
 import org.ovirt.engine.core.compat.EventArgs;
 import org.ovirt.engine.core.compat.IEventListener;
+import org.ovirt.engine.core.compat.PropertyChangedEventArgs;
 import org.ovirt.engine.ui.common.CommonApplicationConstants;
 import org.ovirt.engine.ui.common.CommonApplicationResources;
 import org.ovirt.engine.ui.common.idhandler.ElementIdHandler;
@@ -14,6 +16,7 @@
 import org.ovirt.engine.ui.common.widget.editor.EntityModelTextBoxEditor;
 import org.ovirt.engine.ui.common.widget.editor.ListModelListBoxEditor;
 import org.ovirt.engine.ui.common.widget.form.key_value.KeyValueWidget;
+import org.ovirt.engine.ui.common.widget.renderer.NullSafeRenderer;
 import 
org.ovirt.engine.ui.common.widget.uicommon.popup.AbstractModelBoundPopupWidget;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.BootSequenceModel;
@@ -26,6 +29,9 @@
 import com.google.gwt.event.dom.client.ChangeEvent;
 import com.google.gwt.event.dom.client.ChangeHandler;
 import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.logical.shared.ValueChangeEvent;
+import com.google.gwt.event.logical.shared.ValueChangeHandler;
 import com.google.gwt.resources.client.CssResource;
 import com.google.gwt.uibinder.client.UiBinder;
 import com.google.gwt.uibinder.client.UiFactory;
@@ -37,6 +43,7 @@
 import com.google.gwt.user.client.ui.FlowPanel;
 import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.RadioButton;
 import com.google.gwt.user.client.ui.VerticalPanel;
 
 public class VmRunOncePopupWidget extends 
AbstractModelBoundPopupWidget<RunOnceModel> {
@@ -75,6 +82,10 @@
     @UiField
     @WithElementId
     DisclosurePanel initialRunPanel;
+
+    @UiField
+    @WithElementId
+    DisclosurePanel hostPanel;
 
     @UiField
     @WithElementId
@@ -192,6 +203,21 @@
     @WithElementId("bootSequence")
     ListBox bootSequenceBox;
 
+    @UiField(provided = true)
+    @Path(value = "isAutoAssign.entity")
+    @WithElementId("isAutoAssign")
+    public EntityModelRadioButtonEditor isAutoAssignEditor;
+
+    @UiField(provided = true)
+    @Ignore
+    @WithElementId("specificHost")
+    public RadioButton specificHost;
+
+    @UiField(provided = true)
+    @Path(value = "defaultHost.selectedItem")
+    @WithElementId("defaultHost")
+    public ListModelListBoxEditor<Object> defaultHostEditor;
+
     private BootSequenceModel bootSequenceModel;
 
     private CommonApplicationResources resources;
@@ -243,6 +269,9 @@
         // Display Protocol
         
displayConsoleVncEditor.setLabel(constants.runOncePopupDisplayConsoleVncLabel());
         
displayConsoleSpiceEditor.setLabel(constants.runOncePopupDisplayConsoleSpiceLabel());
+
+        // Host Tab
+        isAutoAssignEditor.setLabel(constants.anyHostInClusterVmPopup());
     }
 
     void initCheckBoxEditors() {
@@ -256,6 +285,10 @@
     void initRadioButtonEditors() {
         displayConsoleVncEditor = new EntityModelRadioButtonEditor("1"); 
//$NON-NLS-1$
         displayConsoleSpiceEditor = new EntityModelRadioButtonEditor("1"); 
//$NON-NLS-1$
+
+        // host tab
+        specificHost = new RadioButton("runVmOnHostGroup"); //$NON-NLS-1$
+        isAutoAssignEditor = new 
EntityModelRadioButtonEditor("runVmOnHostGroup"); //$NON-NLS-1$
     }
 
     void initComboBox() {
@@ -263,6 +296,13 @@
         sysPrepDomainNameTextBoxEditor = new EntityModelTextBoxEditor();
 
         sysPrepDomainNameComboBox = new 
ComboBox(sysPrepDomainNameListBoxEditor, sysPrepDomainNameTextBoxEditor);
+
+        defaultHostEditor = new ListModelListBoxEditor<Object>(new 
NullSafeRenderer<Object>() {
+            @Override
+            public String renderNullSafe(Object object) {
+                return ((VDS) object).getvds_name();
+            }
+        });
     }
 
     void initBootSequenceBox() {
@@ -281,6 +321,7 @@
     void addStyles() {
         linuxBootOptionsPanel.setVisible(false);
         initialRunPanel.setVisible(true);
+        hostPanel.setVisible(true);
         
attachFloppyEditor.addContentWidgetStyleName(style.attachImageCheckBoxLabel());
         
attachIsoEditor.addContentWidgetStyleName(style.attachImageCheckBoxLabel());
         floppyImageEditor.addLabelStyleName(style.attachImageSelectBoxLabel());
@@ -294,7 +335,6 @@
         Driver.driver.edit(object);
 
         
object.getCustomPropertySheet().getKeyValueLines().getItemsChangedEvent().addListener(new
 IEventListener() {
-
             @Override
             public void eventRaised(Event ev, Object sender, EventArgs args) {
                 
customPropertiesSheetEditor.edit(object.getCustomPropertySheet());
@@ -311,6 +351,52 @@
             }
         });
 
+        // Update Host combo
+        object.getIsAutoAssign().getPropertyChangedEvent()
+                .addListener(new IEventListener() {
+                    @Override
+                    public void eventRaised(Event ev, Object sender, EventArgs 
args) {
+                        boolean isAutoAssign = (Boolean) 
object.getIsAutoAssign().getEntity();
+                        defaultHostEditor.setEnabled(!isAutoAssign);
+                        // only this is not bind to the model, so needs to
+                        // listen to the change explicitly
+                        specificHost.setValue(!isAutoAssign);
+                    }
+        });
+
+        specificHost.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
+            @Override
+            public void onValueChange(ValueChangeEvent<Boolean> event) {
+                defaultHostEditor.setEnabled(specificHost.getValue());
+                ValueChangeEvent.fire(isAutoAssignEditor.asRadioButton(), 
false);
+            }
+        });
+
+        isAutoAssignEditor.addDomHandler(new ClickHandler() {
+            @Override
+            public void onClick(ClickEvent event) {
+                defaultHostEditor.setEnabled(false);
+            }
+        }, ClickEvent.getType());
+
+        object.getIsAutoAssign().getEntityChangedEvent().addListener(new 
IEventListener() {
+            @Override
+            public void eventRaised(Event ev, Object sender, EventArgs args) {
+                if (!isAutoAssignEditor.asRadioButton().getValue())
+                    specificHost.setValue(true, true);
+            }
+        });
+
+        object.getPropertyChangedEvent().addListener(new IEventListener() {
+            @Override
+            public void eventRaised(Event ev, Object sender, EventArgs args) {
+                String propName = ((PropertyChangedEventArgs) 
args).PropertyName;
+                if ("IsHostTabValid".equals(propName)) { //$NON-NLS-1$
+                    hostPanel.setVisible(object.getIsHostTabValid());
+                }
+            }
+        });
+
         // Update BootSequence ListBox
         bootSequenceModel = object.getBootSequence();
         UpdateBootSequenceListBox();
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.ui.xml
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.ui.xml
index 7b2edb2..40e4159 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.ui.xml
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/widget/uicommon/popup/vm/VmRunOncePopupWidget.ui.xml
@@ -29,6 +29,10 @@
                        width: 100%;
                }
 
+        .runHostPanel {
+
+        }
+
                .attachImageSelectBoxLabel {
                        display: none;
                }
@@ -43,7 +47,7 @@
                .attachImageSelectbox {
                }
 
-               .attachImagePanel,.linuxBootOptionsPanel,.initialRunPanel {
+               
.attachImagePanel,.linuxBootOptionsPanel,.initialRunPanel,.hostPanel {
                        margin-top: 5px;
                        width: 98%;
                }
@@ -110,6 +114,19 @@
                .panelStyle a[class=header] {
                        font-weight: bold;
                }
+
+       .sectionLabel {
+            font-weight: bold;
+            margin-top: 10px;
+            margin-bottom: 5px;
+        }
+
+        .radioButton {
+        }
+
+        .radioButtonSpecificHost {
+            margin-left: 5px;
+        }
        </ui:style>
 
        <g:FlowPanel>
@@ -164,6 +181,20 @@
                        </g:VerticalPanel>
                </g:DisclosurePanel>
 
+        <g:DisclosurePanel ui:field="hostPanel" 
label="{constants.hostVmPopup}" addStyleNames="{style.panelStyle}">
+            <g:FlowPanel>
+                <g:Label addStyleNames="{style.sectionLabel}" 
text="{constants.runOnVmPopup}" />
+                <g:VerticalPanel addStyleNames="{style.runHostPanel}" 
verticalAlignment='ALIGN_MIDDLE'>
+                    <e:EntityModelRadioButtonEditor width="150px" 
ui:field="isAutoAssignEditor" addStyleNames="{style.radioButton}" />
+                    <g:HorizontalPanel verticalAlignment='ALIGN_MIDDLE'>
+                        <g:RadioButton ui:field="specificHost" 
addStyleNames="{style.radioButtonSpecificHost}" />
+                        <g:Label text="{constants.specificVmPopup}" />
+                        <e:ListModelListBoxEditor ui:field="defaultHostEditor" 
/>
+                    </g:HorizontalPanel>
+                </g:VerticalPanel>
+            </g:FlowPanel>
+        </g:DisclosurePanel>
+
                <g:DisclosurePanel ui:field="displayProtocolPanel" 
label="{constants.runOncePopupDisplayProtocolLabel}" 
addStyleNames="{style.panelStyle}">
                        <g:VerticalPanel>
                                <e:EntityModelRadioButtonEditor 
ui:field="displayConsoleVncEditor" />
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
index 49201e7..b29e2be 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/UserPortalListModel.java
@@ -719,6 +719,9 @@
         model.getRunAsStateless().setEntity(vm.isStateless());
         model.getRunAndPause().setEntity(false);
         model.setHwAcceleration(true);
+        // disable Host tab
+        model.setIsHostTabValid(false);
+        model.getIsAutoAssign().setEntity(true);
 
         fillIsoList(vm);
         fillFloppyImages(vm);
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/RunOnceModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/RunOnceModel.java
index 885bcf9..965283a 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/RunOnceModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/RunOnceModel.java
@@ -335,6 +335,53 @@
         }
     }
 
+    private boolean isHostTabValid;
+
+    public boolean getIsHostTabValid() {
+        return isHostTabValid;
+    }
+
+    public void setIsHostTabValid(boolean value) {
+        if (isHostTabValid != value) {
+            isHostTabValid = value;
+            OnPropertyChanged(new PropertyChangedEventArgs("IsHostTabValid")); 
//$NON-NLS-1$
+        }
+    }
+
+    // host tab
+    private ListModel defaultHost;
+
+    public ListModel getDefaultHost() {
+        return defaultHost;
+    }
+
+    private void setDefaultHost(ListModel value) {
+        this.defaultHost = value;
+    }
+
+    private boolean isHostAvailable;
+
+    public boolean getIsHostAvailable() {
+        return isHostAvailable;
+    }
+
+    public void setIsHostAvailable(boolean value) {
+        if (isHostAvailable != value) {
+            isHostAvailable = value;
+            OnPropertyChanged(new 
PropertyChangedEventArgs("IsHostAvailable")); //$NON-NLS-1$
+        }
+    }
+
+    private EntityModel isAutoAssign;
+
+    public EntityModel getIsAutoAssign() {
+        return isAutoAssign;
+    }
+
+    public void setIsAutoAssign(EntityModel value) {
+        this.isAutoAssign = value;
+    }
+
     // The "sysprep" option was moved from a standalone check box to a
     // pseudo floppy disk image. In order not to change the back-end
     // interface, the Reinitialize variable was changed to a read-only
@@ -422,6 +469,15 @@
         
getDisplayConsole_Vnc_IsSelected().getEntityChangedEvent().addListener(this);
 
         setIsLinuxOptionsAvailable(new EntityModel());
+
+        // host tab
+        setDefaultHost(new ListModel());
+        getDefaultHost().getSelectedItemChangedEvent().addListener(this);
+
+        setIsAutoAssign(new EntityModel());
+        getIsAutoAssign().getEntityChangedEvent().addListener(this);
+
+        setIsHostTabValid(true);
     }
 
     @Override
@@ -466,6 +522,10 @@
             {
                 getDisplayConsole_Vnc_IsSelected().setEntity(false);
             }
+            else if (sender == getIsAutoAssign())
+            {
+                IsAutoAssign_EntityChanged(sender, args);
+            }
         }
     }
 
@@ -505,6 +565,12 @@
     private void SysPrepDomainName_SelectedItemChanged()
     {
         
getSysPrepSelectedDomainName().setEntity(getSysPrepDomainName().getSelectedItem());
+    }
+
+    private void IsAutoAssign_EntityChanged(Object sender, EventArgs args) {
+        if ((Boolean) getIsAutoAssign().getEntity() == false) {
+            getDefaultHost().setIsChangable(true);
+        }
     }
 
     // Sysprep section is displayed only when VM's OS-type is 'Windows'
@@ -585,7 +651,18 @@
             getKernel_path().getInvalidityReasons().add(msg);
         }
 
+        if ((Boolean) getIsAutoAssign().getEntity() == false)
+        {
+            getDefaultHost().ValidateSelectedItem(new IValidation[] { new 
NotEmptyValidation() });
+        }
+        else
+        {
+            getDefaultHost().setIsValid(true);
+        }
+
         return getIsoImage().getIsValid() && getFloppyImage().getIsValid() && 
getKernel_path().getIsValid()
+                && getDefaultHost().getIsValid()
                 && customPropertyValidation;
     }
+
 }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
index 9409cb8..2b2e0dc 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
@@ -40,6 +40,7 @@
 import org.ovirt.engine.core.common.businessentities.UsbPolicy;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
+import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmOsType;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
@@ -95,7 +96,6 @@
 
 public class VmListModel extends VmBaseListModel<VM> implements 
ISupportSystemTreeContext
 {
-
     private UICommand privateNewServerCommand;
 
     public UICommand getNewServerCommand()
@@ -1365,6 +1365,7 @@
         RunOnceUpdateImages(vm);
         RunOnceUpdateDomains();
         RunOnceUpdateBootSequence(vm);
+        RunOnceLoadHosts(vm);
 
         UICommand tempVar = new UICommand("OnRunOnce", this); //$NON-NLS-1$
         tempVar.setTitle(ConstantsManager.getInstance().getConstants().ok());
@@ -1374,6 +1375,8 @@
         
tempVar2.setTitle(ConstantsManager.getInstance().getConstants().cancel());
         tempVar2.setIsCancel(true);
         model.getCommands().add(tempVar2);
+
+        model.getIsAutoAssign().setEntity(true);
     }
 
     private void RunOnceUpdateDisplayProtocols(VM vm)
@@ -1524,6 +1527,35 @@
 
     }
 
+    /**
+     * Load active hosts bound to active cluster.
+     *
+     */
+    private void RunOnceLoadHosts(VM vm) {
+        RunOnceModel model = (RunOnceModel) getWindow();
+
+        // append just active hosts
+        AsyncDataProvider.GetHostListByCluster(new AsyncQuery(model,
+                new INewAsyncCallback() {
+                    @Override
+                    public void OnSuccess(Object target, Object returnValue) {
+                        final RunOnceModel model = (RunOnceModel) target;
+                        final List<VDS> hosts = (ArrayList<VDS>) returnValue;
+                        final List<VDS> activeHosts = new ArrayList<VDS>();
+                        for(VDS host : hosts) {
+                            if(VDSStatus.Up.equals(host.getstatus())) {
+                                activeHosts.add(host);
+                            }
+                        }
+
+                        model.getDefaultHost().setItems(activeHosts);
+                    }
+                }), vm.getVdsGroupName());
+
+        // disable host tab when no active host is available
+        model.setIsHostTabValid(!model.getDefaultHost().getIsEmpty());
+    }
+
     private void OnRunOnce()
     {
         VM vm = (VM) getSelectedItem();
@@ -1554,6 +1586,16 @@
         tempVar.setRunAsStateless((Boolean) 
model.getRunAsStateless().getEntity());
         tempVar.setReinitialize(model.getReinitialize());
         
tempVar.setCustomProperties(model.getCustomPropertySheet().getEntity());
+
+        // set destination host if specified
+        VDS defaultHost = (VDS) model.getDefaultHost().getSelectedItem();
+
+        if ((Boolean) model.getIsAutoAssign().getEntity()) {
+            tempVar.setDestinationVdsId(null);
+        } else {
+            tempVar.setDestinationVdsId(defaultHost != null ? 
defaultHost.getId() : null);
+        }
+
         RunVmOnceParams param = tempVar;
 
         // kernel params
@@ -2941,4 +2983,6 @@
     protected Guid extractStoragePoolIdNullSafe(VM entity) {
         return entity.getStoragePoolId();
     }
+
+
 }


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

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

Reply via email to