anmolbabu has uploaded a new change for review. Change subject: webadmin : Import gluster cluster ......................................................................
webadmin : Import gluster cluster Change-Id: If347656d1ebe94c8331b0f84a4afcb25e16d14fc Signed-off-by: Anmol Babu <anb...@redhat.com> --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterListModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/DataCenterGuideModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/DataCenterListModel.java M frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/gin/uicommon/DataCenterModule.java 5 files changed, 400 insertions(+), 301 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/74/40474/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterListModel.java index 9241abb..6571fcf 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterListModel.java @@ -2,23 +2,17 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; -import com.google.inject.Inject; import org.ovirt.engine.core.common.action.ManagementNetworkOnClusterOperationParameters; 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.VdsGroupParametersBase; -import org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters; import org.ovirt.engine.core.common.businessentities.ServerCpu; import org.ovirt.engine.core.common.businessentities.StoragePool; 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.VmRngDevice; import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity; -import org.ovirt.engine.core.common.businessentities.network.Network; import org.ovirt.engine.core.common.interfaces.SearchType; import org.ovirt.engine.core.common.queries.ConfigurationValues; import org.ovirt.engine.core.common.queries.IdQueryParameters; @@ -28,7 +22,6 @@ import org.ovirt.engine.core.common.scheduling.OptimizationType; import org.ovirt.engine.core.common.utils.ObjectUtils; import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.searchbackend.SearchObjects; import org.ovirt.engine.ui.frontend.AsyncQuery; import org.ovirt.engine.ui.frontend.Frontend; @@ -52,15 +45,14 @@ import org.ovirt.engine.ui.uicommonweb.models.hosts.HostDetailModel; import org.ovirt.engine.ui.uicommonweb.models.hosts.MultipleHostsModel; import org.ovirt.engine.ui.uicommonweb.models.profiles.CpuProfileListModel; -import org.ovirt.engine.ui.uicommonweb.models.vms.key_value.KeyValueModel; import org.ovirt.engine.ui.uicommonweb.place.WebAdminApplicationPlaces; import org.ovirt.engine.ui.uicompat.ConstantsManager; -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.NotifyCollectionChangedEventArgs; import org.ovirt.engine.ui.uicompat.UIConstants; + +import com.google.inject.Inject; public class ClusterListModel<E> extends ListWithDetailsAndReportsModel<E, VDSGroup> implements ISupportSystemTreeContext { @@ -705,12 +697,36 @@ { if (model.getIsImportGlusterConfiguration().getEntity()) { - fetchAndImportClusterHosts(model); + model.setCallerModel(this); + model.fetchAndImportClusterHosts(this, model); } else { onSaveInternal(); } + } + + public void importClusterHosts(ClusterModel cModel, ArrayList<EntityModel<HostDetailModel>> hostList) + { + setWindow(null); + getAddMultipleHostsCommand().execute(); + + final MultipleHostsModel hostsModel = new MultipleHostsModel(); + setWindow(hostsModel); + hostsModel.setTitle(ConstantsManager.getInstance().getConstants().addMultipleHostsTitle()); + hostsModel.setHelpTag(HelpTag.add_hosts); + hostsModel.setHashName("add_hosts"); //$NON-NLS-1$ + hostsModel.setClusterModel(cModel); + hostsModel.getHosts().setItems(hostList); + + UICommand command = new UICommand("OnSaveHosts", this); //$NON-NLS-1$ + command.setTitle(ConstantsManager.getInstance().getConstants().ok()); + hostsModel.getCommands().add(command); + + command = new UICommand("Cancel", this); //$NON-NLS-1$ + command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); + command.setIsCancel(true); + hostsModel.getCommands().add(command); } public void onSaveInternal() @@ -725,293 +741,8 @@ // cancel confirm window if there is cancelConfirmation(); - onSaveInternalWithModel(model); - } - - private void onSaveInternalWithModel(final ClusterModel model) { - VDSGroup cluster = model.getIsNew() ? new VDSGroup() : (VDSGroup) Cloner.clone(getSelectedItem()); - - Version version = model.getVersion().getSelectedItem(); - - cluster.setName(model.getName().getEntity()); - cluster.setDescription(model.getDescription().getEntity()); - cluster.setComment(model.getComment().getEntity()); - cluster.setStoragePoolId(model.getDataCenter().getSelectedItem().getId()); - if (model.getCPU().getSelectedItem() != null) - { - cluster.setCpuName(model.getCPU().getSelectedItem().getCpuName()); - } - cluster.setMaxVdsMemoryOverCommit(model.getMemoryOverCommit()); - cluster.setCountThreadsAsCores(Boolean.TRUE.equals(model.getVersionSupportsCpuThreads().getEntity()) - && Boolean.TRUE.equals(model.getCountThreadsAsCores().getEntity())); - cluster.setEnableKsm(Boolean.TRUE.equals(model.getEnableKsm().getEntity())); - cluster.setEnableBallooning(Boolean.TRUE.equals(model.getEnableBallooning().getEntity()) - && version.compareTo(Version.v3_3) >= 0); - cluster.setTransparentHugepages(version.compareTo(new Version("3.0")) >= 0); //$NON-NLS-1$ - cluster.setCompatibilityVersion(version); - cluster.setMigrateOnError(model.getMigrateOnErrorOption()); - cluster.setVirtService(model.getEnableOvirtService().getEntity()); - cluster.setGlusterService(model.getEnableGlusterService().getEntity()); - cluster.setTrustedService(model.getEnableTrustedService().getEntity()); - cluster.setHaReservation(model.getEnableHaReservation().getEntity()); - cluster.setOptionalReasonRequired(model.getEnableOptionalReason().getEntity()); - cluster.setMaintenanceReasonRequired(model.getEnableHostMaintenanceReason().getEntity()); - cluster.setClusterPolicyId(model.getClusterPolicy().getSelectedItem().getId()); - cluster.setClusterPolicyProperties(KeyValueModel.convertProperties(model.getCustomPropertySheet().serialize())); - if (model.getOptimizeForSpeed().getEntity()) { - cluster.setOptimizationType(OptimizationType.OPTIMIZE_FOR_SPEED); - } else if (model.getAllowOverbooking().getEntity()) { - cluster.setOptimizationType(OptimizationType.ALLOW_OVERBOOKING); - } else { - cluster.setOptimizationType(OptimizationType.NONE); - } - - if (model.getCPU().getSelectedItem() == null) { - cluster.setArchitecture(model.getArchitecture().getSelectedItem()); - } else { - cluster.setArchitecture(null); - } - - if (model.getSpiceProxyEnabled().getEntity()) { - cluster.setSpiceProxy(model.getSpiceProxy().getEntity()); - } - - cluster.getFencingPolicy().setFencingEnabled(model.getFencingEnabledModel().getEntity()); - cluster.getFencingPolicy().setSkipFencingIfSDActive(model.getSkipFencingIfSDActiveEnabled().getEntity()); - cluster.getFencingPolicy().setSkipFencingIfConnectivityBroken(model.getSkipFencingIfConnectivityBrokenEnabled().getEntity()); - cluster.getFencingPolicy().setHostsWithBrokenConnectivityThreshold(model.getHostsWithBrokenConnectivityThreshold().getSelectedItem().intValue()); - - cluster.setSerialNumberPolicy(model.getSerialNumberPolicy().getSelectedSerialNumberPolicy()); - cluster.setCustomSerialNumber(model.getSerialNumberPolicy().getCustomSerialNumber().getEntity()); - - cluster.setAutoConverge(model.getAutoConverge().getSelectedItem()); - cluster.setMigrateCompressed(model.getMigrateCompressed().getSelectedItem()); - cluster.setGlusterTunedProfile(model.getGlusterTunedProfile().getSelectedItem()); - - cluster.getRequiredRngSources().clear(); - if (Boolean.TRUE.equals(model.getRngRandomSourceRequired().getEntity())) { - cluster.getRequiredRngSources().add(VmRngDevice.Source.RANDOM); - } - if (Boolean.TRUE.equals(model.getRngHwrngSourceRequired().getEntity())) { - cluster.getRequiredRngSources().add(VmRngDevice.Source.HWRNG); - } - - model.startProgress(null); - - final Network managementNetwork = model.getManagementNetwork().getSelectedItem(); - final ManagementNetworkOnClusterOperationParameters clusterOperationParameters = - new ManagementNetworkOnClusterOperationParameters(cluster, managementNetwork.getId()); - final VdcActionType actionType = model.getIsNew() ? VdcActionType.AddVdsGroup : VdcActionType.UpdateVdsGroup; - Frontend.getInstance().runAction( - actionType, - clusterOperationParameters, - new IFrontendActionAsyncCallback() { - @Override - public void executed(FrontendActionAsyncResult result) { - - ClusterListModel<Void> localModel = (ClusterListModel<Void>) result.getState(); - if (model.getIsImportGlusterConfiguration().getEntity()) { - localModel.postOnSaveInternalWithImport(result.getReturnValue()); - } - else { - localModel.postOnSaveInternal(result.getReturnValue()); - } - } - }, - this); - } - - private void fetchAndImportClusterHosts(final ClusterModel clusterModel) - { - getWindow().startProgress(null); - AsyncQuery aQuery = new AsyncQuery(); - aQuery.setModel(this); - aQuery.setHandleFailure(true); - aQuery.asyncCallback = new INewAsyncCallback() { - @Override - public void onSuccess(Object model, Object result) - { - getWindow().stopProgress(); - - VdcQueryReturnValue returnValue = (VdcQueryReturnValue) result; - if (returnValue == null) { - onEmptyGlusterHosts(clusterModel); - return; - } - else if (!returnValue.getSucceeded()) { - clusterModel.setMessage(Frontend.getInstance().getAppErrorsTranslator() - .translateErrorTextSingle(returnValue.getExceptionString())); - return; - } - - Map<String, String> hostMap = returnValue.getReturnValue(); - if (hostMap == null) - { - onEmptyGlusterHosts(clusterModel); - return; - } - if (hostMap.containsValue(null) || hostMap.containsValue(""))//$NON-NLS-1$ - { - onGlusterHostsWithoutFingerprint(hostMap, clusterModel); - return; - } - ArrayList<EntityModel<HostDetailModel>> list = new ArrayList<>(); - for (Map.Entry<String, String> host : hostMap.entrySet()) - { - HostDetailModel hostModel = new HostDetailModel(host.getKey(), host.getValue()); - hostModel.setName(host.getKey()); - hostModel.setPassword("");//$NON-NLS-1$ - EntityModel<HostDetailModel> entityModel = new EntityModel<>(hostModel); - list.add(entityModel); - } - importClusterHosts(clusterModel, list); - } - }; - AsyncDataProvider.getInstance().getGlusterHosts(aQuery, - clusterModel.getGlusterHostAddress().getEntity(), - clusterModel.getGlusterHostPassword().getEntity(), - clusterModel.getGlusterHostFingerprint().getEntity()); - } - - private void onEmptyGlusterHosts(ClusterModel clusterModel) - { - clusterModel.setMessage(ConstantsManager.getInstance().getConstants().emptyGlusterHosts()); - } - - private void onGlusterHostsWithoutFingerprint(Map<String, String> hostMap, ClusterModel clusterModel) - { - ArrayList<String> problematicHosts = new ArrayList<>(); - for (Map.Entry<String, String> host : hostMap.entrySet()) - { - if (host.getValue() == null || host.getValue().equals("")) //$//$NON-NLS-1$ - { - problematicHosts.add(host.getKey()); - } - } - - clusterModel.setMessage(ConstantsManager.getInstance().getMessages().unreachableGlusterHosts(problematicHosts)); - } - - private void importClusterHosts(ClusterModel clusterModel, ArrayList<EntityModel<HostDetailModel>> hostList) - { - setWindow(null); - getAddMultipleHostsCommand().execute(); - - final MultipleHostsModel hostsModel = new MultipleHostsModel(); - setWindow(hostsModel); - hostsModel.setTitle(ConstantsManager.getInstance().getConstants().addMultipleHostsTitle()); - hostsModel.setHelpTag(HelpTag.add_hosts); - hostsModel.setHashName("add_hosts"); //$NON-NLS-1$ - hostsModel.setClusterModel(clusterModel); - hostsModel.getHosts().setItems(hostList); - - UICommand command = UICommand.createOkUiCommand("OnSaveHosts", this); //$NON-NLS-1$ - hostsModel.getCommands().add(command); - - hostsModel.getCommands().add(UICommand.createCancelUiCommand("Cancel", this)); //$NON-NLS-1$ - } - - private void onSaveHosts() - { - MultipleHostsModel hostsModel = (MultipleHostsModel) getWindow(); - if(hostsModel == null) - { - return; - } - if (!hostsModel.validate()) - { - return; - } - if (hostsModel.getClusterModel().getClusterId() != null) - { - addHosts(hostsModel); - } - else - { - onSaveInternalWithModel(hostsModel.getClusterModel()); - } - } - - public void postOnSaveInternal(VdcReturnValueBase returnValue) - { - ClusterModel model = (ClusterModel) getWindow(); - - model.stopProgress(); - - if (returnValue != null && returnValue.getSucceeded()) - { - cancel(); - - if (model.getIsNew()) - { - setGuideContext(returnValue.getActionReturnValue()); - updateActionAvailability(); - getGuideCommand().execute(); - } - } - } - - public void postOnSaveInternalWithImport(VdcReturnValueBase returnValue) - { - MultipleHostsModel hostsModel = (MultipleHostsModel) getWindow(); - if (returnValue != null && returnValue.getSucceeded()) - { - hostsModel.getClusterModel().setClusterId((Guid) returnValue.getActionReturnValue()); - addHosts(hostsModel); - } - } - - private void addHosts(final MultipleHostsModel hostsModel) { - hostsModel.startProgress(null); - ArrayList<VdcActionParametersBase> parametersList = new ArrayList<>(); - for (Object object : hostsModel.getHosts().getItems()) { - HostDetailModel hostDetailModel = (HostDetailModel) ((EntityModel) object).getEntity(); - - VDS host = new VDS(); - host.setVdsName(hostDetailModel.getName()); - host.setHostName(hostDetailModel.getAddress()); - host.setSshKeyFingerprint(hostDetailModel.getFingerprint()); - host.setPort(54321); - host.setSshPort(22); // TODO: get from UI, till then using defaults. - host.setSshUsername("root"); //$NON-NLS-1$ - - host.setVdsGroupId(hostsModel.getClusterModel().getClusterId()); - host.setPmEnabled(false); - - AddVdsActionParameters parameters = new AddVdsActionParameters(); - parameters.setVdsId(host.getId()); - parameters.setvds(host); - parameters.setPassword(hostDetailModel.getPassword()); - parameters.setOverrideFirewall(hostsModel.isConfigureFirewall()); - parameters.setRebootAfterInstallation(hostsModel.getClusterModel().getEnableOvirtService().getIsSelected()); - - parametersList.add(parameters); - } - - - Frontend.getInstance().runMultipleAction(VdcActionType.AddVds, - parametersList, - true, - new IFrontendMultipleActionAsyncCallback() { - - @Override - public void executed(FrontendMultipleActionAsyncResult result) { - hostsModel.stopProgress(); - boolean isAllCanDoPassed = true; - for (VdcReturnValueBase returnValueBase : result.getReturnValue()) - { - isAllCanDoPassed = isAllCanDoPassed && returnValueBase.getCanDoAction(); - if (!isAllCanDoPassed) - { - break; - } - } - if (isAllCanDoPassed) - { - cancel(); - } - } - }, null); + model.setCallerModel(this); + model.onSaveInternalWithModel(model.getIsNew() ? new VDSGroup() : (VDSGroup) Cloner.clone(getSelectedItem())); } public void cancel() @@ -1058,7 +789,7 @@ } } - private void updateActionAvailability() + protected void updateActionAvailability() { getEditCommand().setIsExecutionAllowed(getSelectedItem() != null && getSelectedItems() != null && getSelectedItems().size() == 1); @@ -1146,7 +877,8 @@ } else if ("OnSaveHosts".equals(command.getName())) //$NON-NLS-1$ { - onSaveHosts(); + ((MultipleHostsModel) getWindow()).getClusterModel().setCallerModel(this); + ((MultipleHostsModel) getWindow()).getClusterModel().onSaveHosts((MultipleHostsModel) getWindow()); } } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterModel.java index 4cf842c..cbc76ec 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/clusters/ClusterModel.java @@ -9,11 +9,17 @@ import java.util.List; import java.util.Map; +import org.ovirt.engine.core.common.action.ManagementNetworkOnClusterOperationParameters; +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.hostdeploy.AddVdsActionParameters; import org.ovirt.engine.core.common.businessentities.ArchitectureType; import org.ovirt.engine.core.common.businessentities.MigrateOnErrorOptions; import org.ovirt.engine.core.common.businessentities.SerialNumberPolicy; import org.ovirt.engine.core.common.businessentities.ServerCpu; import org.ovirt.engine.core.common.businessentities.StoragePool; +import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VmRngDevice; import org.ovirt.engine.core.common.businessentities.network.Network; @@ -23,6 +29,7 @@ import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.common.scheduling.ClusterPolicy; +import org.ovirt.engine.core.common.scheduling.OptimizationType; import org.ovirt.engine.core.common.scheduling.PolicyUnit; import org.ovirt.engine.core.common.utils.ObjectUtils; import org.ovirt.engine.core.common.utils.Pair; @@ -33,15 +40,20 @@ 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.models.ApplicationModeHelper; import org.ovirt.engine.ui.uicommonweb.models.EntityModel; -import org.ovirt.engine.ui.uicommonweb.models.HasEntity; import org.ovirt.engine.ui.uicommonweb.models.FilteredListModel; +import org.ovirt.engine.ui.uicommonweb.models.HasEntity; import org.ovirt.engine.ui.uicommonweb.models.HasValidatedTabs; import org.ovirt.engine.ui.uicommonweb.models.ListModel; +import org.ovirt.engine.ui.uicommonweb.models.ListWithDetailsAndReportsModel; import org.ovirt.engine.ui.uicommonweb.models.TabName; import org.ovirt.engine.ui.uicommonweb.models.ValidationCompleteEvent; +import org.ovirt.engine.ui.uicommonweb.models.datacenters.DataCenterListModel; +import org.ovirt.engine.ui.uicommonweb.models.hosts.HostDetailModel; +import org.ovirt.engine.ui.uicommonweb.models.hosts.MultipleHostsModel; import org.ovirt.engine.ui.uicommonweb.models.vms.SerialNumberPolicyModel; import org.ovirt.engine.ui.uicommonweb.models.vms.key_value.KeyValueModel; import org.ovirt.engine.ui.uicommonweb.validation.HostWithProtocolAndPortAddressValidation; @@ -52,8 +64,13 @@ import org.ovirt.engine.ui.uicompat.ConstantsManager; import org.ovirt.engine.ui.uicompat.Event; import org.ovirt.engine.ui.uicompat.EventArgs; +import org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult; +import org.ovirt.engine.ui.uicompat.FrontendMultipleActionAsyncResult; import org.ovirt.engine.ui.uicompat.IEventListener; +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.external.StringUtils; public class ClusterModel extends EntityModel<VDSGroup> implements HasValidatedTabs { @@ -61,6 +78,16 @@ private ListModel<ClusterPolicy> clusterPolicy; private Map<Guid, Network> defaultManagementNetworkCache = new HashMap<>(); private Boolean detached; + + private ListWithDetailsAndReportsModel callerModel; + + public ListWithDetailsAndReportsModel getCallerModel() { + return callerModel; + } + + public void setCallerModel(ListWithDetailsAndReportsModel callerModel) { + this.callerModel = callerModel; + } private ListModel<String> glusterTunedProfile; @@ -1347,6 +1374,276 @@ getIsImportGlusterConfiguration().setEntity(false); } + public void onSaveHosts(MultipleHostsModel hostsModel) + { + if(hostsModel == null) + { + return; + } + if (!hostsModel.validate()) + { + return; + } + if (hostsModel.getClusterModel().getClusterId() != null) + { + hostsModel.getClusterModel().addHosts(hostsModel); + } + else + { + hostsModel.getClusterModel().onSaveInternalWithModel(new VDSGroup()); + } + } + + public void onSaveInternalWithModel(VDSGroup cluster) { + Version version = getVersion().getSelectedItem(); + + cluster.setName(getName().getEntity()); + cluster.setDescription(getDescription().getEntity()); + cluster.setComment(getComment().getEntity()); + cluster.setStoragePoolId(getDataCenter().getSelectedItem().getId()); + if (getCPU().getSelectedItem() != null) + { + cluster.setCpuName(getCPU().getSelectedItem().getCpuName()); + } + cluster.setMaxVdsMemoryOverCommit(getMemoryOverCommit()); + cluster.setCountThreadsAsCores(Boolean.TRUE.equals(getVersionSupportsCpuThreads().getEntity()) + && Boolean.TRUE.equals(getCountThreadsAsCores().getEntity())); + cluster.setEnableKsm(Boolean.TRUE.equals(getEnableKsm().getEntity())); + cluster.setEnableBallooning(Boolean.TRUE.equals(getEnableBallooning().getEntity()) + && version.compareTo(Version.v3_3) >= 0); + cluster.setTransparentHugepages(version.compareTo(new Version("3.0")) >= 0); //$NON-NLS-1$ + cluster.setCompatibilityVersion(version); + cluster.setMigrateOnError(getMigrateOnErrorOption()); + cluster.setVirtService(getEnableOvirtService().getEntity()); + cluster.setGlusterService(getEnableGlusterService().getEntity()); + cluster.setTrustedService(getEnableTrustedService().getEntity()); + cluster.setHaReservation(getEnableHaReservation().getEntity()); + cluster.setOptionalReasonRequired(getEnableOptionalReason().getEntity()); + cluster.setClusterPolicyId(getClusterPolicy().getSelectedItem().getId()); + cluster.setClusterPolicyProperties(KeyValueModel.convertProperties(getCustomPropertySheet().serialize())); + if (getOptimizeForSpeed().getEntity()) { + cluster.setOptimizationType(OptimizationType.OPTIMIZE_FOR_SPEED); + } else if (getAllowOverbooking().getEntity()) { + cluster.setOptimizationType(OptimizationType.ALLOW_OVERBOOKING); + } else { + cluster.setOptimizationType(OptimizationType.NONE); + } + + if (getCPU().getSelectedItem() == null) { + cluster.setArchitecture(getArchitecture().getSelectedItem()); + } else { + cluster.setArchitecture(null); + } + + if (getSpiceProxyEnabled().getEntity()) { + cluster.setSpiceProxy(getSpiceProxy().getEntity()); + } + + cluster.getFencingPolicy().setFencingEnabled(getFencingEnabledModel().getEntity()); + cluster.getFencingPolicy().setSkipFencingIfSDActive(getSkipFencingIfSDActiveEnabled().getEntity()); + cluster.getFencingPolicy().setSkipFencingIfConnectivityBroken(getSkipFencingIfConnectivityBrokenEnabled().getEntity()); + cluster.getFencingPolicy().setHostsWithBrokenConnectivityThreshold(getHostsWithBrokenConnectivityThreshold().getSelectedItem().intValue()); + + cluster.setSerialNumberPolicy(getSerialNumberPolicy().getSelectedSerialNumberPolicy()); + cluster.setCustomSerialNumber(getSerialNumberPolicy().getCustomSerialNumber().getEntity()); + + cluster.setAutoConverge(getAutoConverge().getSelectedItem()); + cluster.setMigrateCompressed(getMigrateCompressed().getSelectedItem()); + + cluster.getRequiredRngSources().clear(); + if (Boolean.TRUE.equals(getRngRandomSourceRequired().getEntity())) { + cluster.getRequiredRngSources().add(VmRngDevice.Source.RANDOM); + } + if (Boolean.TRUE.equals(getRngHwrngSourceRequired().getEntity())) { + cluster.getRequiredRngSources().add(VmRngDevice.Source.HWRNG); + } + + startProgress(null); + + final Network managementNetwork = getManagementNetwork().getSelectedItem(); + final ManagementNetworkOnClusterOperationParameters clusterOperationParameters = + new ManagementNetworkOnClusterOperationParameters(cluster, managementNetwork.getId()); + + Frontend.getInstance().runAction(getIsNew() ? VdcActionType.AddVdsGroup : VdcActionType.UpdateVdsGroup, + clusterOperationParameters, + new IFrontendActionAsyncCallback() { + @Override + public void executed(FrontendActionAsyncResult result) { + + ClusterModel localModel = (ClusterModel) result.getState(); + VdcReturnValueBase returnValue = result.getReturnValue(); + localModel.stopProgress(); + if (getIsImportGlusterConfiguration().getEntity()) { + localModel.postOnSaveInternalWithImport(returnValue); + } + else { + if (returnValue != null && returnValue.getSucceeded()) + { + callerModel.setWindow(null); + } + localModel.postOnSaveInternal(returnValue); + } + } + }, + this); + } + + public void postOnSaveInternal(VdcReturnValueBase returnValue) + { + ListWithDetailsAndReportsModel callerModel = getCallerModel(); + if (this.getIsNew()) + { + if(callerModel instanceof ClusterListModel) { + ((ClusterListModel)callerModel).setGuideContext(returnValue.getActionReturnValue()); + ((ClusterListModel)callerModel).updateActionAvailability(); + ((ClusterListModel)callerModel).getGuideCommand().execute(); + } + if(callerModel instanceof DataCenterListModel) { + ((DataCenterListModel)callerModel).setGuideContext(returnValue.getActionReturnValue()); + ((DataCenterListModel)callerModel).getGuideCommand().execute(); + } + } + } + + private void postOnSaveInternalWithImport(VdcReturnValueBase returnValue) + { + ListWithDetailsAndReportsModel callerModel = getCallerModel(); + MultipleHostsModel hostsModel = (MultipleHostsModel) callerModel.getWindow(); + if (returnValue != null && returnValue.getSucceeded()) + { + setClusterId((Guid) returnValue.getActionReturnValue()); + addHosts(hostsModel); + } + } + + public void addHosts(final MultipleHostsModel hostsModel) { + hostsModel.startProgress(null); + ArrayList<VdcActionParametersBase> parametersList = new ArrayList<VdcActionParametersBase>(); + for (Object object : hostsModel.getHosts().getItems()) { + HostDetailModel hostDetailModel = (HostDetailModel) ((EntityModel) object).getEntity(); + + VDS host = new VDS(); + host.setVdsName(hostDetailModel.getName()); + host.setHostName(hostDetailModel.getAddress()); + host.setSshKeyFingerprint(hostDetailModel.getFingerprint()); + host.setPort(54321); + host.setSshPort(22); // TODO: get from UI, till then using defaults. + host.setSshUsername("root"); //$NON-NLS-1$ + + host.setVdsGroupId(hostsModel.getClusterModel().getClusterId()); + host.setPmEnabled(false); + + AddVdsActionParameters parameters = new AddVdsActionParameters(); + parameters.setVdsId(host.getId()); + parameters.setvds(host); + parameters.setPassword(hostDetailModel.getPassword()); + parameters.setOverrideFirewall(hostsModel.isConfigureFirewall()); + parameters.setRebootAfterInstallation(hostsModel.getClusterModel().getEnableOvirtService().getIsSelected()); + + parametersList.add(parameters); + } + + + Frontend.getInstance().runMultipleAction(VdcActionType.AddVds, + parametersList, + true, + new IFrontendMultipleActionAsyncCallback() { + + @Override + public void executed(FrontendMultipleActionAsyncResult result) { + hostsModel.stopProgress(); + boolean isAllCanDoPassed = true; + for (VdcReturnValueBase returnValueBase : result.getReturnValue()) + { + isAllCanDoPassed = isAllCanDoPassed && returnValueBase.getCanDoAction(); + if (!isAllCanDoPassed) + { + break; + } + } + if (isAllCanDoPassed) + { + callerModel.setWindow(null); + } + } + }, null); + } + + public void fetchAndImportClusterHosts(final ListWithDetailsAndReportsModel callerModel, final ClusterModel clusterModel) + { + setCallerModel(callerModel); + this.startProgress(null); + AsyncQuery aQuery = new AsyncQuery(); + aQuery.setModel(this); + aQuery.setHandleFailure(true); + aQuery.asyncCallback = new INewAsyncCallback() { + @Override + public void onSuccess(Object model, Object result) + { + VdcQueryReturnValue returnValue = (VdcQueryReturnValue) result; + if (returnValue == null) { + onEmptyGlusterHosts(); + return; + } + else if (!returnValue.getSucceeded()) { + clusterModel.setMessage(Frontend.getInstance().getAppErrorsTranslator() + .translateErrorTextSingle(returnValue.getExceptionString())); + return; + } + + Map<String, String> hostMap = returnValue.getReturnValue(); + if (hostMap == null) + { + onEmptyGlusterHosts(); + return; + } + if (hostMap.containsValue(null) || hostMap.containsValue(""))//$NON-NLS-1$ + { + onGlusterHostsWithoutFingerprint(hostMap); + return; + } + ArrayList<EntityModel<HostDetailModel>> list = new ArrayList<EntityModel<HostDetailModel>>(); + for (Map.Entry<String, String> host : hostMap.entrySet()) + { + HostDetailModel hostModel = new HostDetailModel(host.getKey(), host.getValue()); + hostModel.setName(host.getKey()); + hostModel.setPassword("");//$NON-NLS-1$ + EntityModel<HostDetailModel> entityModel = new EntityModel<HostDetailModel>(hostModel); + list.add(entityModel); + } + if (callerModel instanceof ClusterListModel) { + ((ClusterListModel)callerModel).importClusterHosts(clusterModel, list); + } + if (callerModel instanceof DataCenterListModel) { + ((DataCenterListModel) callerModel).importClusterHosts(clusterModel, list); + } + } + }; + AsyncDataProvider.getInstance().getGlusterHosts(aQuery, + this.getGlusterHostAddress().getEntity(), + this.getGlusterHostPassword().getEntity(), + this.getGlusterHostFingerprint().getEntity()); + } + + private void onEmptyGlusterHosts() + { + setMessage(ConstantsManager.getInstance().getConstants().emptyGlusterHosts()); + } + + private void onGlusterHostsWithoutFingerprint(Map<String, String> hostMap) + { + ArrayList<String> problematicHosts = new ArrayList<String>(); + for (Map.Entry<String, String> host : hostMap.entrySet()) + { + if (StringUtils.isEmpty(host.getValue())) //$//$NON-NLS-1$ + { + problematicHosts.add(host.getKey()); + } + } + + setMessage(ConstantsManager.getInstance().getMessages().unreachableGlusterHosts(problematicHosts)); + } + private void fetchFingerprint(String hostAddress) { AsyncQuery aQuery = new AsyncQuery(); aQuery.setModel(this); @@ -2034,4 +2331,10 @@ ? "" : srcs; } + + @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/datacenters/DataCenterGuideModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/DataCenterGuideModel.java index 832f2e1..5760b64 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/DataCenterGuideModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/DataCenterGuideModel.java @@ -50,6 +50,7 @@ import org.ovirt.engine.ui.uicommonweb.models.EntityModel; import org.ovirt.engine.ui.uicommonweb.models.GuideModel; import org.ovirt.engine.ui.uicommonweb.models.ListModel; +import org.ovirt.engine.ui.uicommonweb.models.ListWithDetailsAndReportsModel; import org.ovirt.engine.ui.uicommonweb.models.Model; import org.ovirt.engine.ui.uicommonweb.models.clusters.ClusterModel; import org.ovirt.engine.ui.uicommonweb.models.hosts.HostModel; @@ -136,6 +137,15 @@ private List<VDS> allHosts; private VDS localStorageHost; private boolean noLocalStorageHost; + private ListWithDetailsAndReportsModel callerModel; + + public ListWithDetailsAndReportsModel getCallerModel() { + return callerModel; + } + + public void setCallerModel(ListWithDetailsAndReportsModel callerModel) { + this.callerModel = callerModel; + } public DataCenterGuideModel() { } @@ -1283,6 +1293,7 @@ public void addCluster() { + setWindow(null); ClusterModel model = new ClusterModel(); model.init(false); setWindow(model); @@ -1346,6 +1357,9 @@ model.startProgress(null); + if(model.getIsImportGlusterConfiguration().getEntity()) { + model.fetchAndImportClusterHosts(getCallerModel(), model); + } else { Frontend.getInstance().runAction(VdcActionType.AddVdsGroup, new ManagementNetworkOnClusterOperationParameters(cluster), new IFrontendActionAsyncCallback() { @Override @@ -1356,6 +1370,7 @@ } }, this); + } } public void postOnAddCluster(VdcReturnValueBase returnValue) diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/DataCenterListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/DataCenterListModel.java index 4f96891..cbdc3e2 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/DataCenterListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/DataCenterListModel.java @@ -50,10 +50,13 @@ import org.ovirt.engine.ui.uicommonweb.models.ListWithDetailsAndReportsModel; import org.ovirt.engine.ui.uicommonweb.models.SystemTreeItemModel; import org.ovirt.engine.ui.uicommonweb.models.SystemTreeItemType; +import org.ovirt.engine.ui.uicommonweb.models.clusters.ClusterModel; import org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel; import org.ovirt.engine.ui.uicommonweb.models.datacenters.qos.DataCenterCpuQosListModel; import org.ovirt.engine.ui.uicommonweb.models.datacenters.qos.DataCenterHostNetworkQosListModel; import org.ovirt.engine.ui.uicommonweb.models.datacenters.qos.DataCenterStorageQosListModel; +import org.ovirt.engine.ui.uicommonweb.models.hosts.HostDetailModel; +import org.ovirt.engine.ui.uicommonweb.models.hosts.MultipleHostsModel; import org.ovirt.engine.ui.uicommonweb.models.macpool.NewSharedMacPoolModel; import org.ovirt.engine.ui.uicommonweb.models.macpool.SharedMacPoolModel; import org.ovirt.engine.ui.uicommonweb.place.WebAdminApplicationPlaces; @@ -154,6 +157,18 @@ this.addMacPoolCommand = addMacPoolCommand; } + private UICommand privateAddMultipleHostsCommand; + + public UICommand getAddMultipleHostsCommand() + { + return privateAddMultipleHostsCommand; + } + + private void setAddMultipleHostsCommand(UICommand value) + { + privateAddMultipleHostsCommand = value; + } + protected Object[] getSelectedKeys() { if (getSelectedItems() == null) @@ -235,6 +250,8 @@ public void guide() { DataCenterGuideModel model = new DataCenterGuideModel(); + model.setCallerModel(this); + setAddMultipleHostsCommand(new UICommand("AddHosts", this));//$NON-NLS-1$ setWindow(model); model.setTitle(ConstantsManager.getInstance().getConstants().newDataCenterGuideMeTitle()); model.setHelpTag(HelpTag.new_data_center___guide_me); @@ -284,6 +301,29 @@ list.add(permissionListModel); list.add(dataCenterEventListModel); setDetailModels(list); + } + + public void importClusterHosts(ClusterModel cModel, ArrayList<EntityModel<HostDetailModel>> hostList) + { + setWindow(null); + getAddMultipleHostsCommand().execute(); + + final MultipleHostsModel hostsModel = new MultipleHostsModel(); + setWindow(hostsModel); + hostsModel.setTitle(ConstantsManager.getInstance().getConstants().addMultipleHostsTitle()); + hostsModel.setHelpTag(HelpTag.add_hosts); + hostsModel.setHashName("add_hosts"); //$NON-NLS-1$ + hostsModel.setClusterModel(cModel); + hostsModel.getHosts().setItems(hostList); + + UICommand command = new UICommand("OnSaveHosts", this); //$NON-NLS-1$ + command.setTitle(ConstantsManager.getInstance().getConstants().ok()); + hostsModel.getCommands().add(command); + + command = new UICommand("Cancel", this); //$NON-NLS-1$ + command.setTitle(ConstantsManager.getInstance().getConstants().cancel()); + command.setIsCancel(true); + hostsModel.getCommands().add(command); } @Override @@ -1018,6 +1058,11 @@ { onRecover(); } + else if ("OnSaveHosts".equals(command.getName())) //$NON-NLS-1$ + { + ((MultipleHostsModel) getWindow()).getClusterModel().setCallerModel(this); + ((MultipleHostsModel) getWindow()).getClusterModel().onSaveHosts((MultipleHostsModel) getWindow()); + } } @Override diff --git a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/gin/uicommon/DataCenterModule.java b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/gin/uicommon/DataCenterModule.java index 566f7cf..344976c 100644 --- a/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/gin/uicommon/DataCenterModule.java +++ b/frontend/webadmin/modules/webadmin/src/main/java/org/ovirt/engine/ui/webadmin/gin/uicommon/DataCenterModule.java @@ -52,6 +52,7 @@ import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.datacenter.RecoveryStoragePopupPresenterWidget; import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.event.EventPopupPresenterWidget; import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.guide.GuidePopupPresenterWidget; +import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.host.MultipleHostsPopupPresenterWidget; import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.macpool.SharedMacPoolPopupPresenterWidget; import org.ovirt.engine.ui.webadmin.section.main.presenter.popup.quota.QuotaPopupPresenterWidget; import org.ovirt.engine.ui.webadmin.uicommon.model.PermissionModelProvider; @@ -79,6 +80,7 @@ final Provider<DataCenterForceRemovePopupPresenterWidget> forceRemovePopupProvider, final Provider<SharedMacPoolPopupPresenterWidget> macPoolPopupProvider, final Provider<DataCenterListModel> modelProvider, + final Provider<MultipleHostsPopupPresenterWidget> addMultipleHostsPopupProvider, final Provider<CommonModel> commonModelProvider) { MainTabModelProvider<StoragePool, DataCenterListModel> result = new MainTabModelProvider<StoragePool, DataCenterListModel>(eventBus, defaultConfirmPopupProvider, @@ -93,6 +95,8 @@ return guidePopupProvider.get(); } else if (lastExecutedCommand == getModel().getAddMacPoolCommand()) { return macPoolPopupProvider.get(); + } else if (lastExecutedCommand == getModel().getAddMultipleHostsCommand()) { + return addMultipleHostsPopupProvider.get(); } else { return super.getModelPopup(source, lastExecutedCommand, windowModel); } -- To view, visit https://gerrit.ovirt.org/40474 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If347656d1ebe94c8331b0f84a4afcb25e16d14fc Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: anmolbabu <anb...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches