Moti Asayag has uploaded a new change for review.

Change subject: webadmin: Support 'Upgrade' in action items
......................................................................

webadmin: Support 'Upgrade' in action items

The upgrade host command is now supported for hosts
and ovirt-nodes from the host general subtab, as an
action item.

Change-Id: I7e9053aec1cb4aa69e5b35c882b8ac71224f6a9b
Bug-Url: https://bugzilla.redhat.com/1186196
Signed-off-by: Moti Asayag <[email protected]>
---
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostGeneralModel.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationMessages.java
M 
frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/host/SubTabHostGeneralInfoPresenter.java
3 files changed, 191 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/23/41023/1

diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostGeneralModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostGeneralModel.java
index b754f3e..36a85c4 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostGeneralModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostGeneralModel.java
@@ -2,32 +2,42 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Date;
 
 import org.ovirt.engine.core.common.VdcActionUtils;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.action.VdcReturnValueBase;
 import org.ovirt.engine.core.common.action.VdsActionParameters;
+import org.ovirt.engine.core.common.action.hostdeploy.UpgradeHostParameters;
 import org.ovirt.engine.core.common.businessentities.NonOperationalReason;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
+import org.ovirt.engine.core.common.businessentities.VDSType;
 import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
 import org.ovirt.engine.core.common.utils.ObjectUtils;
+import org.ovirt.engine.core.common.utils.RpmVersionUtils;
 import org.ovirt.engine.core.compat.RpmVersion;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.ui.frontend.AsyncQuery;
 import org.ovirt.engine.ui.frontend.Frontend;
 import org.ovirt.engine.ui.frontend.INewAsyncCallback;
+import org.ovirt.engine.ui.uicommonweb.Linq;
 import org.ovirt.engine.ui.uicommonweb.UICommand;
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
 import org.ovirt.engine.ui.uicommonweb.help.HelpTag;
+import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
 import org.ovirt.engine.ui.uicompat.EnumTranslator;
 import org.ovirt.engine.ui.uicompat.Event;
 import org.ovirt.engine.ui.uicompat.EventArgs;
 import org.ovirt.engine.ui.uicompat.EventDefinition;
+import org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult;
 import org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult;
+import org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback;
 import org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback;
 import org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs;
 import org.ovirt.engine.ui.uicompat.UIConstants;
@@ -41,6 +51,15 @@
 
     public static final EventDefinition requestEditEventDefinition;
     private Event<EventArgs> privateRequestEditEvent;
+    private UICommand upgradeHostCommand;
+
+    public UICommand getUpgradeHostCommand() {
+        return upgradeHostCommand;
+    }
+
+    private void setUpgradeHostCommand(UICommand upgradeHostCommand) {
+        this.upgradeHostCommand = upgradeHostCommand;
+    }
 
     public Event<EventArgs> getRequestEditEvent()
     {
@@ -835,6 +854,7 @@
 
         setSaveNICsConfigCommand(new UICommand("SaveNICsConfig", this)); 
//$NON-NLS-1$
         setEditHostCommand(new UICommand("EditHost", this)); //$NON-NLS-1$
+        setUpgradeHostCommand(new UICommand("Upgrade", this)); //$NON-NLS-1$
         setGoToEventsCommand(new UICommand("GoToEvents", this)); //$NON-NLS-1$
     }
 
@@ -964,9 +984,7 @@
         setHasReinstallAlertInstallFailed(false);
         setHasReinstallAlertMaintenance(false);
         setHasNICsAlert(false);
-        
getEditHostCommand().setIsExecutionAllowed(VdcActionUtils.canExecute(new 
ArrayList<VDS>(Arrays.asList(new VDS[]{getEntity()})),
-                VDS.class,
-                VdcActionType.UpdateVds));
+        
getEditHostCommand().setIsExecutionAllowed(canExecuteCommand(VdcActionType.UpdateVds));
         // Check the network alert presense.
         setHasNICsAlert((getEntity().getNetConfigDirty() == null ? false : 
getEntity().getNetConfigDirty()));
 
@@ -982,7 +1000,7 @@
             setHasNoPowerManagementAlert(true);
         }
 
-        // Check the reinstall alert presense.
+        // Check the reinstall alert presence.
         if (getEntity().getStatus() == VDSStatus.NonResponsive)
         {
             setHasReinstallAlertNonResponsive(true);
@@ -996,10 +1014,19 @@
             setHasReinstallAlertMaintenance(true);
         }
 
+        
getUpgradeHostCommand().setIsExecutionAllowed(getEntity().isUpdateAvailable()
+                && canExecuteCommand(VdcActionType.UpgradeHost));
+
         setNonOperationalReasonEntity((getEntity().getNonOperationalReason() 
== NonOperationalReason.NONE ? null
                 : (NonOperationalReason) 
getEntity().getNonOperationalReason()));
 
         setHasAnyAlert();
+    }
+
+    private boolean canExecuteCommand(VdcActionType actionType) {
+        return VdcActionUtils.canExecute(new ArrayList<VDS>(Arrays.asList(new 
VDS[] { getEntity() })),
+                VDS.class,
+                actionType);
     }
 
     public void setHasAnyAlert() {
@@ -1053,6 +1080,161 @@
         else if ("Cancel".equals(command.getName())) //$NON-NLS-1$
         {
             cancel();
+        } else if (command == getUpgradeHostCommand()) {
+            upgrade();
+        } else if ("OnUpgrade".equals(command.getName())) { //$NON-NLS-1$
+            onUpgrade();
         }
     }
+
+    private void upgrade() {
+        if (getWindow() != null) {
+            return;
+        }
+
+        final VDS host = getEntity();
+        if (host.getVdsType() == VDSType.oVirtNode) {
+            upgradeOvirtNode(host);
+        } else {
+            upgradeHost(host);
+        }
+    }
+
+    private void upgradeHost(VDS host) {
+        final UIConstants constants = 
ConstantsManager.getInstance().getConstants();
+        ConfirmationModel model = new ConfirmationModel();
+        setConfirmWindow(model);
+        model.setTitle(constants.upgradeHostsTitle());
+        model.setHelpTag(HelpTag.upgrade_host);
+        model.setHashName(HelpTag.upgrade_host.name);
+
+        if (host.getVmCount() > 0) {
+            
model.setMessage(constants.areYouSureYouWantToUpgradeTheFollowingHostWithRunningVmsMsg());
+        } else {
+            
model.setMessage(constants.areYouSureYouWantToUpgradeTheFollowingHostMsg());
+        }
+
+        UICommand tempVar = new UICommand("OnUpgrade", this); //$NON-NLS-1$
+        tempVar.setTitle(constants.ok());
+        tempVar.setIsDefault(true);
+        model.getCommands().add(tempVar);
+        UICommand tempVar2 = new UICommand("Cancel", this); //$NON-NLS-1$
+        tempVar2.setTitle(constants.cancel());
+        tempVar2.setIsCancel(true);
+        model.getCommands().add(tempVar2);
+    }
+
+    private void upgradeOvirtNode(final VDS host) {
+        if (getWindow() != null) {
+            return;
+        }
+
+        InstallModel model = new InstallModel();
+        model.setVds(host);
+        setWindow(model);
+        
model.setTitle(ConstantsManager.getInstance().getConstants().installHostTitle());
+        model.setHelpTag(HelpTag.upgrade_host);
+        model.setHashName(HelpTag.upgrade_host.name);
+        model.getOVirtISO().setIsAvailable(false);
+        model.getOverrideIpTables().setIsAvailable(false);
+        model.getActivateHostAfterInstall().setEntity(true);
+        model.getHostVersion().setEntity(host.getHostOs());
+        model.getHostVersion().setIsAvailable(false);
+
+        getWindow().startProgress(null);
+        AsyncDataProvider.getInstance().getoVirtISOsList(new AsyncQuery(model,
+                new INewAsyncCallback() {
+                    @Override
+                    public void onSuccess(Object target, Object returnValue) {
+
+                        InstallModel model = (InstallModel) target;
+
+                        @SuppressWarnings("unchecked")
+                        ArrayList<RpmVersion> isos = (ArrayList<RpmVersion>) 
returnValue;
+                        Collections.sort(isos, new Comparator<RpmVersion>() {
+                            @Override
+                            public int compare(RpmVersion rpmV1, RpmVersion 
rpmV2) {
+                                return 
RpmVersionUtils.compareRpmParts(rpmV2.getRpmName(), rpmV1.getRpmName());
+                            }
+                        });
+                        model.getOVirtISO().setItems(isos);
+                        
model.getOVirtISO().setSelectedItem(Linq.firstOrDefault(isos));
+                        model.getOVirtISO().setIsAvailable(true);
+                        model.getOVirtISO().setIsChangeable(!isos.isEmpty());
+                        model.getHostVersion().setIsAvailable(true);
+
+                        if (isos.isEmpty()) {
+                            
model.setMessage(ConstantsManager.getInstance().getConstants()
+                                    
.thereAreNoISOversionsVompatibleWithHostCurrentVerMsg());
+                        }
+
+                        if (host.getHostOs() == null) {
+                            
model.setMessage(ConstantsManager.getInstance().getConstants()
+                                    .hostMustBeInstalledBeforeUpgrade());
+                        }
+
+                        addUpgradeCommands(model, host, isos.isEmpty());
+                        getWindow().stopProgress();
+                    }
+                }),
+                host.getId());
+    }
+
+    private void addUpgradeCommands(InstallModel model, VDS host, boolean 
isOnlyClose) {
+        if (!isOnlyClose) {
+            UICommand command = 
UICommand.createDefaultOkUiCommand("OnUpgrade", this); //$NON-NLS-1$
+            model.getCommands().add(command);
+        }
+        model.getUserName().setEntity(host.getSshUsername());
+        UICommand command = new UICommand("Cancel", this); //$NON-NLS-1$
+        command.setTitle(isOnlyClose ? 
ConstantsManager.getInstance().getConstants().close()
+                : ConstantsManager.getInstance().getConstants().cancel());
+        command.setIsCancel(true);
+        model.getCommands().add(command);
+    }
+
+    public void onUpgrade() {
+        final VDS host = getEntity();
+        if (host.getVdsType() == VDSType.oVirtNode) {
+            onUpgradeOvirtNode(host);
+        } else {
+            onUpgradeHost(host);
+        }
+
+    }
+
+    private void onUpgradeOvirtNode(final VDS host) {
+        InstallModel model = (InstallModel) getWindow();
+        if (!model.validate(true)) {
+            return;
+        }
+
+        UpgradeHostParameters params = new UpgradeHostParameters(host.getId());
+        
params.setoVirtIsoFile(model.getOVirtISO().getSelectedItem().getRpmName());
+        invokeHostUpgrade(params);
+    }
+
+    private void onUpgradeHost(final VDS host) {
+        ConfirmationModel model = (ConfirmationModel) getConfirmWindow();
+        if (model.getProgress() != null) {
+            return;
+        }
+
+        model.startProgress(null);
+        setConfirmWindow(null);
+        UpgradeHostParameters params = new UpgradeHostParameters(host.getId());
+        invokeHostUpgrade(params);
+    }
+
+    private void invokeHostUpgrade(UpgradeHostParameters params) {
+        Frontend.getInstance().runAction(VdcActionType.UpgradeHost, params, 
new IFrontendActionAsyncCallback() {
+            @Override
+            public void executed(FrontendActionAsyncResult result) {
+                VdcReturnValueBase returnValue = result.getReturnValue();
+                if (returnValue != null && returnValue.getSucceeded()) {
+                    cancel();
+                }
+            }
+        });
+    }
 }
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationMessages.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationMessages.java
index 7444885..305b429 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationMessages.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/ApplicationMessages.java
@@ -8,7 +8,7 @@
     @DefaultMessage("A new version is available; an upgrade option will appear 
once the Host is moved to maintenance mode.")
     String hostHasUpgradeAlert();
 
-    @DefaultMessage("A new version is available.")
+    @DefaultMessage("A new version is available. <a>Upgrade</a>")
     String hostInSupportedStatusHasUpgradeAlert();
 
     @DefaultMessage("This host is in non responding state. Try to Activate it; 
If the problem persists, switch Host to Maintenance mode and try to reinstall 
it.")
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/host/SubTabHostGeneralInfoPresenter.java
 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/host/SubTabHostGeneralInfoPresenter.java
index 74b633f..5874c48 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/host/SubTabHostGeneralInfoPresenter.java
+++ 
b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/section/main/presenter/tab/host/SubTabHostGeneralInfoPresenter.java
@@ -130,7 +130,10 @@
         // Review the alerts and add those that are active:
         if (model.getHasUpgradeAlert()) {
             if (VdcActionUtils.canExecute(Arrays.asList(model.getEntity()), 
VDS.class, VdcActionType.UpgradeHost)) {
-                addTextAlert(view, 
messages.hostInSupportedStatusHasUpgradeAlert(), AlertType.UPDATE_AVAILABLE);
+                addTextAndLinkAlert(view,
+                        messages.hostInSupportedStatusHasUpgradeAlert(),
+                        model.getUpgradeHostCommand(),
+                        AlertType.UPDATE_AVAILABLE);
             } else {
                 addTextAlert(view, messages.hostHasUpgradeAlert(), 
AlertType.UPDATE_AVAILABLE);
             }


-- 
To view, visit https://gerrit.ovirt.org/41023
To unsubscribe, visit https://gerrit.ovirt.org/settings

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

Reply via email to