Arik Hadas has uploaded a new change for review. Change subject: userportal: [WIP] introduce UserPortalRunOnceModel ......................................................................
userportal: [WIP] introduce UserPortalRunOnceModel Changed RunOnceModel to be abstract and add UserPortalRunOnceModel that extends it. the code that initialize the run-once-model in the user portal was moved from UserPortalListModel to it. Change-Id: I6561df71f093e2739e689722ead4f85428c04d06 Signed-off-by: Arik Hadas <[email protected]> --- 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 A frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UserPortalRunOnceModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java 4 files changed, 208 insertions(+), 197 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/07/13207/1 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 1ff1083..e679ad7 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 @@ -17,7 +17,6 @@ import org.ovirt.engine.core.common.action.VdcActionParametersBase; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VmManagementParametersBase; -import org.ovirt.engine.core.common.businessentities.Disk; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.DisplayType; import org.ovirt.engine.core.common.businessentities.MigrationSupport; @@ -34,9 +33,6 @@ import org.ovirt.engine.core.common.businessentities.VmType; import org.ovirt.engine.core.common.businessentities.VolumeType; import org.ovirt.engine.core.common.businessentities.storage_pool; -import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; -import org.ovirt.engine.core.common.queries.GetAllDisksByVmIdParameters; -import org.ovirt.engine.core.common.queries.IdQueryParameters; import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; @@ -67,6 +63,7 @@ import org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel; import org.ovirt.engine.ui.uicommonweb.models.vms.UserPortalExistingVmModelBehavior; import org.ovirt.engine.ui.uicommonweb.models.vms.UserPortalNewVmModelBehavior; +import org.ovirt.engine.ui.uicommonweb.models.vms.UserPortalRunOnceModel; import org.ovirt.engine.ui.uicommonweb.models.vms.UserPortalVmEventListModel; import org.ovirt.engine.ui.uicommonweb.models.vms.UserPortalVmSnapshotListModel; import org.ovirt.engine.ui.uicommonweb.models.vms.VmAppListModel; @@ -709,57 +706,11 @@ VM vm = (VM) selectedItem.getEntity(); - RunOnceModel model = new RunOnceModel(); + RunOnceModel model = new UserPortalRunOnceModel(vm, + getCustomPropertiesKeysList().get(vm.getVdsGroupCompatibilityVersion())); setWindow(model); - model.setTitle(ConstantsManager.getInstance().getConstants().runVirtualMachinesTitle()); - model.setHashName("run_virtual_machine"); //$NON-NLS-1$ - model.getAttachIso().setEntity(false); - model.getAttachFloppy().setEntity(false); - model.getRunAsStateless().setEntity(vm.isStateless()); - model.getRunAndPause().setEntity(false); - model.setHwAcceleration(true); - // disable Host tab - model.setIsHostTabVisible(false); - // disable Custom properties sheet - model.setIsCustomPropertiesSheetVisible(false); - fillIsoList(vm); - fillFloppyImages(vm); - - // passing Kernel parameters - model.getKernel_parameters().setEntity(vm.getKernelParams()); - model.getKernel_path().setEntity(vm.getKernelUrl()); - model.getInitrd_path().setEntity(vm.getInitrdUrl()); - - model.getCustomProperties().setEntity(vm.getCustomProperties()); - - model.setIsLinuxOS(AsyncDataProvider.IsLinuxOsType(vm.getVmOs())); - - model.getIsLinuxOptionsAvailable().setEntity(model.getIsLinuxOS()); - model.setIsWindowsOS(AsyncDataProvider.IsWindowsOsType(vm.getVmOs())); - model.getIsVmFirstRun().setEntity(!vm.isInitialized()); - model.getSysPrepDomainName().setSelectedItem(vm.getVmDomain()); - - // Update Domain list - AsyncDataProvider.GetDomainList(new AsyncQuery(model, - new INewAsyncCallback() { - @Override - public void OnSuccess(Object target, Object returnValue1) { - - RunOnceModel runOnceModel = (RunOnceModel) target; - List<String> domains = (List<String>) returnValue1; - String oldDomain = (String) runOnceModel.getSysPrepDomainName().getSelectedItem(); - if (oldDomain != null && !oldDomain.equals("") && !domains.contains(oldDomain)) //$NON-NLS-1$ - { - domains.add(0, oldDomain); - } - runOnceModel.getSysPrepDomainName().setItems(domains); - runOnceModel.getSysPrepDomainName().setSelectedItem((oldDomain != null) ? oldDomain - : Linq.FirstOrDefault(domains)); - - } - }), - true); + model.init(); // Display protocols. EntityModel tempVar = new EntityModel(); @@ -772,23 +723,12 @@ tempVar2.setEntity(DisplayType.qxl); EntityModel qxlProtocol = tempVar2; - boolean isVncSelected = vm.getDefaultDisplayType() == DisplayType.vnc; - model.getDisplayConsole_Vnc_IsSelected().setEntity(isVncSelected); - model.getDisplayConsole_Spice_IsSelected().setEntity(!isVncSelected); - ArrayList<EntityModel> items = new ArrayList<EntityModel>(); items.add(vncProtocol); items.add(qxlProtocol); model.getDisplayProtocol().setItems(items); model.getDisplayProtocol().setSelectedItem(vm.getDefaultDisplayType() == DisplayType.vnc ? vncProtocol : qxlProtocol); - - model.setCustomPropertiesKeysList(getCustomPropertiesKeysList() - .get(vm.getVdsGroupCompatibilityVersion())); - - // Boot sequence. - setIsBootFromNetworkAllowedForVm(vm); - setIsBootFromHardDiskAllowedForVm(vm); UICommand tempVar3 = new UICommand("OnRunOnce", this); //$NON-NLS-1$ tempVar3.setTitle(ConstantsManager.getInstance().getConstants().ok()); @@ -798,137 +738,6 @@ tempVar4.setTitle(ConstantsManager.getInstance().getConstants().cancel()); tempVar4.setIsCancel(true); model.getCommands().add(tempVar4); - } - - private void setIsBootFromNetworkAllowedForVm(VM vm) { - AsyncQuery _asyncQuery2 = new AsyncQuery(); - _asyncQuery2.setModel(this); - - _asyncQuery2.asyncCallback = new INewAsyncCallback() { - @Override - public void OnSuccess(Object model3, Object ReturnValue) - { - UserPortalListModel userPortalListModel = (UserPortalListModel) model3; - boolean hasNics = - ((ArrayList<VmNetworkInterface>) ((VdcQueryReturnValue) ReturnValue).getReturnValue()).size() > 0; - - if (!hasNics) - { - BootSequenceModel bootSequenceModel = - ((RunOnceModel) userPortalListModel.getWindow()).getBootSequence(); - bootSequenceModel.getNetworkOption().setIsChangable(false); - bootSequenceModel.getNetworkOption() - .setChangeProhibitionReason(ConstantsManager.getInstance().getMessages().interfaceIsRequiredToBootFromNetwork()); - } - } - }; - - Frontend.RunQuery(VdcQueryType.GetVmInterfacesByVmId, new IdQueryParameters(vm.getId()), _asyncQuery2); - } - - private void setIsBootFromHardDiskAllowedForVm(VM vm) { - AsyncQuery vmDisksQuery = new AsyncQuery(); - vmDisksQuery.setModel(this); - - vmDisksQuery.asyncCallback = new INewAsyncCallback() { - @Override - public void OnSuccess(Object model, Object returnValue) - { - UserPortalListModel userPortalListModel = (UserPortalListModel) model; - ArrayList<Disk> vmDisks = (ArrayList<Disk>) ((VdcQueryReturnValue) returnValue).getReturnValue(); - RunOnceModel runOnceModel = (RunOnceModel) userPortalListModel.getWindow(); - - if (vmDisks.isEmpty()) { - runOnceModel.getRunAsStateless().setIsChangable(false); - runOnceModel.getRunAsStateless() - .setChangeProhibitionReason(ConstantsManager.getInstance().getMessages().disklessVmCannotRunAsStateless()); - runOnceModel.getRunAsStateless().setEntity(false); - } - - boolean hasBootableDisk = false; - for (Disk disk : vmDisks) { - if (disk.isBoot()) { - hasBootableDisk = true; - break; - } - } - - if (!hasBootableDisk) - { - BootSequenceModel bootSequenceModel = runOnceModel.getBootSequence(); - bootSequenceModel.getHardDiskOption().setIsChangable(false); - bootSequenceModel.getHardDiskOption() - .setChangeProhibitionReason(ConstantsManager.getInstance().getMessages().bootableDiskIsRequiredToBootFromDisk()); - } - } - }; - - Frontend.RunQuery(VdcQueryType.GetAllDisksByVmId, new GetAllDisksByVmIdParameters(vm.getId()), vmDisksQuery); - } - - protected void fillIsoList(VM vm) { - AsyncQuery getIsoImagesQuery = new AsyncQuery(); - getIsoImagesQuery.setModel(this); - - getIsoImagesQuery.asyncCallback = new INewAsyncCallback() { - @Override - public void OnSuccess(Object model1, Object result) - { - UserPortalListModel userPortalListModel = (UserPortalListModel) model1; - RunOnceModel runOnceModel = (RunOnceModel) userPortalListModel.getWindow(); - List<String> images = (List<String>) result; - runOnceModel.getIsoImage().setItems(images); - - if (runOnceModel.getIsoImage().getIsChangable() - && runOnceModel.getIsoImage().getSelectedItem() == null) - { - runOnceModel.getIsoImage().setSelectedItem(Linq.FirstOrDefault(images)); - } - } - }; - - AsyncDataProvider.GetIrsImageList(getIsoImagesQuery, vm.getStoragePoolId()); - } - - protected void fillFloppyImages(VM vm) { - AsyncQuery getFloppyQuery = new AsyncQuery(); - getFloppyQuery.setModel(this); - - getFloppyQuery.asyncCallback = new INewAsyncCallback() { - @Override - public void OnSuccess(Object model2, Object result) - { - UserPortalListModel userPortalListModel = (UserPortalListModel) model2; - UserPortalItemModel userPortalItemModel = - (UserPortalItemModel) userPortalListModel.getSelectedItem(); - RunOnceModel runOnceModel = (RunOnceModel) userPortalListModel.getWindow(); - VM selectedVM = (VM) userPortalItemModel.getEntity(); - List<String> images = (List<String>) result; - - if (AsyncDataProvider.IsWindowsOsType(selectedVM.getVmOs())) - { - // Add a pseudo floppy disk image used for Windows' sysprep. - if (!selectedVM.isInitialized()) - { - images.add(0, "[sysprep]"); //$NON-NLS-1$ - runOnceModel.getAttachFloppy().setEntity(true); - } - else - { - images.add("[sysprep]"); //$NON-NLS-1$ - } - } - runOnceModel.getFloppyImage().setItems(images); - - if (runOnceModel.getFloppyImage().getIsChangable() - && runOnceModel.getFloppyImage().getSelectedItem() == null) - { - runOnceModel.getFloppyImage().setSelectedItem(Linq.FirstOrDefault(images)); - } - } - }; - - AsyncDataProvider.GetFloppyImageList(getFloppyQuery, vm.getStoragePoolId()); } private void OnRunOnce() 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 d9316ec..5bafce4 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 @@ -17,7 +17,7 @@ import org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs; @SuppressWarnings("unused") -public class RunOnceModel extends Model +public abstract class RunOnceModel extends Model { private EntityModel privateAttachFloppy; @@ -485,6 +485,8 @@ setIsCustomPropertiesSheetVisible(true); } + public abstract void init(); + @Override public void eventRaised(Event ev, Object sender, EventArgs args) { diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UserPortalRunOnceModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UserPortalRunOnceModel.java new file mode 100644 index 0000000..fcce047 --- /dev/null +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UserPortalRunOnceModel.java @@ -0,0 +1,200 @@ +package org.ovirt.engine.ui.uicommonweb.models.vms; + +import java.util.ArrayList; +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.Disk; +import org.ovirt.engine.core.common.businessentities.DisplayType; +import org.ovirt.engine.core.common.businessentities.VM; +import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; +import org.ovirt.engine.core.common.queries.GetAllDisksByVmIdParameters; +import org.ovirt.engine.core.common.queries.IdQueryParameters; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; +import org.ovirt.engine.core.common.queries.VdcQueryType; +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.dataprovider.AsyncDataProvider; +import org.ovirt.engine.ui.uicompat.ConstantsManager; + +public class UserPortalRunOnceModel extends RunOnceModel { + + private VM vm; + private ArrayList<String> customPropertiesKeysList; + + public UserPortalRunOnceModel(VM vm, ArrayList<String> customPropertiesKeysList) { + this.vm = vm; + this.customPropertiesKeysList = customPropertiesKeysList; + } + + @Override + public void init() { + setTitle(ConstantsManager.getInstance().getConstants().runVirtualMachinesTitle()); + setHashName("run_virtual_machine"); //$NON-NLS-1$ + getAttachIso().setEntity(false); + getAttachFloppy().setEntity(false); + getRunAsStateless().setEntity(vm.isStateless()); + getRunAndPause().setEntity(false); + setHwAcceleration(true); + // disable Host tab + setIsHostTabVisible(false); + // disable Custom properties sheet + setIsCustomPropertiesSheetVisible(false); + // passing Kernel parameters + getKernel_parameters().setEntity(vm.getKernelParams()); + getKernel_path().setEntity(vm.getKernelUrl()); + getInitrd_path().setEntity(vm.getInitrdUrl()); + + getCustomProperties().setEntity(vm.getCustomProperties()); + + setIsLinuxOS(AsyncDataProvider.IsLinuxOsType(vm.getVmOs())); + + getIsLinuxOptionsAvailable().setEntity(getIsLinuxOS()); + setIsWindowsOS(AsyncDataProvider.IsWindowsOsType(vm.getVmOs())); + getIsVmFirstRun().setEntity(!vm.isInitialized()); + getSysPrepDomainName().setSelectedItem(vm.getVmDomain()); + + fillIsoList(vm); + fillFloppyImages(vm); + + // Update Domain list + updateDomainList(); + + boolean isVncSelected = vm.getDefaultDisplayType() == DisplayType.vnc; + getDisplayConsole_Vnc_IsSelected().setEntity(isVncSelected); + getDisplayConsole_Spice_IsSelected().setEntity(!isVncSelected); + + // Boot sequence. + setIsBootFromNetworkAllowedForVm(vm); + setIsBootFromHardDiskAllowedForVm(vm); + + setCustomPropertiesKeysList(customPropertiesKeysList); + } + + private void updateDomainList() { + AsyncDataProvider.GetDomainList(new AsyncQuery(this, + new INewAsyncCallback() { + @Override + public void OnSuccess(Object target, Object returnValue) { + List<String> domains = (List<String>) returnValue; + String oldDomain = (String) getSysPrepDomainName().getSelectedItem(); + if (oldDomain != null && !oldDomain.equals("") && !domains.contains(oldDomain)) //$NON-NLS-1$ + { + domains.add(0, oldDomain); + } + getSysPrepDomainName().setItems(domains); + getSysPrepDomainName().setSelectedItem((oldDomain != null) ? oldDomain + : Linq.FirstOrDefault(domains)); + + } + }), + true); + } + + protected void fillIsoList(VM vm) { + AsyncDataProvider.GetIrsImageList(new AsyncQuery(this, + new INewAsyncCallback() { + @Override + public void OnSuccess(Object model, Object returnValue) { + List<String> images = (List<String>) returnValue; + getIsoImage().setItems(images); + + if (getIsoImage().getIsChangable() + && getIsoImage().getSelectedItem() == null) + { + getIsoImage().setSelectedItem(Linq.FirstOrDefault(images)); + } + + } + }), + vm.getStoragePoolId()); + } + + protected void fillFloppyImages(final VM vm) { + AsyncDataProvider.GetFloppyImageList(new AsyncQuery(this, + new INewAsyncCallback() { + @Override + public void OnSuccess(Object model, Object returnValue) { + VM selectedVM = (VM) vm; + List<String> images = (List<String>) returnValue; + + if (AsyncDataProvider.IsWindowsOsType(selectedVM.getVmOs())) + { + // Add a pseudo floppy disk image used for Windows' sysprep. + if (!selectedVM.isInitialized()) + { + images.add(0, "[sysprep]"); //$NON-NLS-1$ + getAttachFloppy().setEntity(true); + } + else + { + images.add("[sysprep]"); //$NON-NLS-1$ + } + } + getFloppyImage().setItems(images); + + if (getFloppyImage().getIsChangable() + && getFloppyImage().getSelectedItem() == null) + { + getFloppyImage().setSelectedItem(Linq.FirstOrDefault(images)); + } + } + }), + vm.getStoragePoolId()); + } + + private void setIsBootFromNetworkAllowedForVm(VM vm) { + Frontend.RunQuery(VdcQueryType.GetVmInterfacesByVmId, new IdQueryParameters(vm.getId()), + new AsyncQuery(this, new INewAsyncCallback() { + + @Override + public void OnSuccess(Object model, Object returnValue) { + boolean hasNics = + ((ArrayList<VmNetworkInterface>) ((VdcQueryReturnValue) returnValue).getReturnValue()).size() > 0; + + if (!hasNics) + { + BootSequenceModel bootSequenceModel = getBootSequence(); + bootSequenceModel.getNetworkOption().setIsChangable(false); + bootSequenceModel.getNetworkOption() + .setChangeProhibitionReason(ConstantsManager.getInstance().getMessages().interfaceIsRequiredToBootFromNetwork()); + } + } + })); + } + + private void setIsBootFromHardDiskAllowedForVm(VM vm) { + Frontend.RunQuery(VdcQueryType.GetAllDisksByVmId, new GetAllDisksByVmIdParameters(vm.getId()), + new AsyncQuery(this, new INewAsyncCallback() { + + @Override + public void OnSuccess(Object model, Object returnValue) { + ArrayList<Disk> vmDisks = (ArrayList<Disk>) ((VdcQueryReturnValue) returnValue).getReturnValue(); + + if (vmDisks.isEmpty()) { + getRunAsStateless().setIsChangable(false); + getRunAsStateless() + .setChangeProhibitionReason(ConstantsManager.getInstance().getMessages().disklessVmCannotRunAsStateless()); + getRunAsStateless().setEntity(false); + } + + boolean hasBootableDisk = false; + for (Disk disk : vmDisks) { + if (disk.isBoot()) { + hasBootableDisk = true; + break; + } + } + + if (!hasBootableDisk) + { + BootSequenceModel bootSequenceModel = getBootSequence(); + bootSequenceModel.getHardDiskOption().setIsChangable(false); + bootSequenceModel.getHardDiskOption() + .setChangeProhibitionReason(ConstantsManager.getInstance().getMessages().bootableDiskIsRequiredToBootFromDisk()); + } + } + })); + } +} 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 14dc75f..8aa7d1e 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 @@ -1369,7 +1369,7 @@ private void RunOnce() { VM vm = (VM) getSelectedItem(); - RunOnceModel model = new RunOnceModel(); + RunOnceModel model = new WebadminRunOnceModel(); setWindow(model); model.setTitle(ConstantsManager.getInstance().getConstants().runVirtualMachinesTitle()); model.setHashName("run_virtual_machine"); //$NON-NLS-1$ -- To view, visit http://gerrit.ovirt.org/13207 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6561df71f093e2739e689722ead4f85428c04d06 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Arik Hadas <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
