diff options
| author | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-07-07 04:59:42 -0700 |
|---|---|---|
| committer | Shireesh Anjal <anjalshireesh@gmail.com> | 2011-07-07 04:59:42 -0700 |
| commit | 8ad430f0dfd3c6ae45c8982631715d41d951c6a4 (patch) | |
| tree | 99343f777e95f820c4915b88a4bca52e705e3edf | |
| parent | bcef8a077f87b760fd04be847676e7ab9000f6f3 (diff) | |
| parent | c4d3ad9972e9ca3e44fad553e5ee33b16b1aa378 (diff) | |
Merge pull request #101 from Dhandapani/f26f15a68baf2c068445f818ccdb2d1b94bc6143
Initialize Disk confirmation dialog added
6 files changed, 194 insertions, 39 deletions
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java index fa925842..865ec5f2 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java @@ -21,6 +21,7 @@ package com.gluster.storage.management.client; import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_CLUSTERS; import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_SERVERS; +import java.net.URI; import java.util.List; import com.gluster.storage.management.core.constants.RESTConstants; @@ -62,10 +63,10 @@ public class GlusterServersClient extends AbstractClient { postRequest(form); } - public void initializeDisk(String serverName, String diskName, String fsType) { + public URI initializeDisk(String serverName, String diskName, String fsType) { Form form = new Form(); form.add(RESTConstants.FORM_PARAM_FSTYPE, fsType); - putRequest(serverName + "/" + RESTConstants.RESOURCE_DISKS + "/" + diskName, form); + return putRequestURI(serverName + "/" + RESTConstants.RESOURCE_DISKS + "/" + diskName, form); } public void removeServer(String serverName) { diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/GlusterConstants.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/GlusterConstants.java index 567eda61..b87d38f5 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/GlusterConstants.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/GlusterConstants.java @@ -31,6 +31,7 @@ public class GlusterConstants { }; public static final List<String> VOLUME_LOG_LEVELS_ARR = StringUtil.enumToArray(VOLUME_LOG_LEVELS.values()); + public static final String FSTYPE_DEFAULT = "default"; public static final String FSTYPE_EXT_3 = "ext3"; public static final String FSTYPE_EXT_4 = "ext4"; public static final String FSTYPE_XFS = "xfs"; diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/InitializeDiskTypeSelection.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/InitializeDiskTypeSelection.java new file mode 100644 index 00000000..bb700de5 --- /dev/null +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/dialogs/InitializeDiskTypeSelection.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * + * InitializeDiskTypeSelection.java + * + * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Gluster Management Console is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + *******************************************************************************/ +package com.gluster.storage.management.gui.dialogs; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; + +import com.gluster.storage.management.core.constants.GlusterConstants; +import com.gluster.storage.management.gui.utils.GUIHelper; + +public class InitializeDiskTypeSelection extends Dialog { + + private Combo formatTypeCombo = null; + private final GUIHelper guiHelper = GUIHelper.getInstance(); + private Composite initializeDiskTypeComposite; + private Composite composite; + private String fsType; + + public InitializeDiskTypeSelection(Shell parentShell) { + super(parentShell); + // TODO Auto-generated constructor stub + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + + newShell.setText("Gluster Management Console - Select Cluster"); + addEscapeListener(newShell); + } + + private void addEscapeListener(Shell shell) { + shell.addTraverseListener(new TraverseListener() { + + @Override + public void keyTraversed(TraverseEvent e) { + if (e.keyCode == SWT.ESC) { + cancelPressed(); + } + } + }); + } + + @Override + protected Control createDialogArea(Composite parent) { + // Makes sure that child composites inherit the same background + parent.setBackgroundMode(SWT.INHERIT_FORCE); + + composite = (Composite) super.createDialogArea(parent); + configureDialogLayout(composite); + createComposite(composite); + return composite; + } + + private void configureDialogLayout(Composite composite) { + GridLayout layout = (GridLayout) composite.getLayout(); + layout.numColumns = 3; + layout.marginLeft = 20; + layout.marginRight = 20; + layout.marginTop = 20; + layout.horizontalSpacing = 20; + layout.verticalSpacing = 20; + } + + private void createComposite(Composite composite) { + initializeDiskTypeComposite = new Composite(composite, SWT.NONE); + GridLayout layout = new GridLayout(3, false); + initializeDiskTypeComposite.setLayout(layout); + + createLabel(initializeDiskTypeComposite, "Format disk using "); + createFormatTypeCombo(initializeDiskTypeComposite); + createLabel(initializeDiskTypeComposite, " file system"); + } + + private void createLabel(Composite composite, String labelText) { + Label formatTypeLabel = new Label(composite, SWT.NONE); + formatTypeLabel.setText(labelText); + formatTypeLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); + } + + private void createFormatTypeCombo(Composite composite) { + List<String> fsType = new ArrayList<String>(); + fsType.add(GlusterConstants.FSTYPE_DEFAULT); + fsType.add(GlusterConstants.FSTYPE_EXT_3); + fsType.add(GlusterConstants.FSTYPE_EXT_4); + fsType.add(GlusterConstants.FSTYPE_XFS); + formatTypeCombo = new Combo(composite, SWT.READ_ONLY); + formatTypeCombo.setItems(fsType.toArray(new String[0])); + formatTypeCombo.select(0); + } + + @Override + protected void okPressed() { + fsType = formatTypeCombo.getText(); + super.okPressed(); + } + + @Override + public void cancelPressed() { + super.cancelPressed(); + } + + /** + * Overriding to make sure that the dialog is centered in screen + */ + @Override + protected void initializeBounds() { + super.initializeBounds(); + + guiHelper.centerShellInScreen(getShell()); + } + + public String getFSType() { + return fsType.trim(); + } + +} diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/AbstractDisksPage.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/AbstractDisksPage.java index 63cf65ed..cc12415e 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/AbstractDisksPage.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/AbstractDisksPage.java @@ -18,12 +18,14 @@ *******************************************************************************/ package com.gluster.storage.management.gui.views.pages; +import java.net.URI; import java.util.List; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.TableEditor; import org.eclipse.swt.events.DisposeEvent; @@ -39,18 +41,18 @@ import org.eclipse.ui.forms.events.HyperlinkAdapter; import org.eclipse.ui.forms.events.HyperlinkEvent; import org.eclipse.ui.forms.widgets.ImageHyperlink; +import com.gluster.storage.management.client.GlusterDataModelManager; import com.gluster.storage.management.client.GlusterServersClient; -import com.gluster.storage.management.core.constants.GlusterConstants; +import com.gluster.storage.management.client.TasksClient; import com.gluster.storage.management.core.model.ClusterListener; import com.gluster.storage.management.core.model.DefaultClusterListener; import com.gluster.storage.management.core.model.Disk; import com.gluster.storage.management.core.model.Disk.DISK_STATUS; import com.gluster.storage.management.core.model.Entity; +import com.gluster.storage.management.core.model.TaskInfo; import com.gluster.storage.management.gui.Application; import com.gluster.storage.management.gui.IEntityListener; -import com.gluster.storage.management.gui.IImageKeys; -import com.gluster.storage.management.gui.jobs.InitializeDiskJob; -import com.gluster.storage.management.gui.utils.GUIHelper; +import com.gluster.storage.management.gui.dialogs.InitializeDiskTypeSelection; public abstract class AbstractDisksPage extends AbstractTableViewerPage<Disk> implements IEntityListener { private List<Disk> disks; @@ -203,30 +205,26 @@ public abstract class AbstractDisksPage extends AbstractTableViewerPage<Disk> im @Override public void linkActivated(HyperlinkEvent e) { - Integer formatOption = new MessageDialog(getShell(), "Initialize Disk", GUIHelper.getInstance().getImage( - IImageKeys.DISK), "Please choose the file system to Initialize the disk?", MessageDialog.QUESTION, new String[] { - "Cancel", GlusterConstants.FSTYPE_EXT_3, GlusterConstants.FSTYPE_EXT_4, GlusterConstants.FSTYPE_XFS }, -1).open(); - - if (formatOption <= 0) { // By Cancel button(0) or Escape key(-1) + InitializeDiskTypeSelection formatDialog = new InitializeDiskTypeSelection(getShell()); + int userAction = formatDialog.open(); + if (userAction == Window.CANCEL) { + formatDialog.cancelPressed(); return; } - String fsType = null; - if (formatOption == 1) { - fsType = GlusterConstants.FSTYPE_EXT_3; - } else if (formatOption == 2) { - fsType = GlusterConstants.FSTYPE_EXT_4; - } else if (formatOption == 3) { - fsType = GlusterConstants.FSTYPE_XFS; - } - GlusterServersClient serversClient = new GlusterServersClient(); - serversClient.initializeDisk(disk.getServerName(), disk.getName(), fsType); + try { + URI uri = serversClient.initializeDisk(disk.getServerName(), disk.getName(), formatDialog.getFSType()); - updateStatus(DISK_STATUS.INITIALIZING, true); - - guiHelper.showProgressView(); - new InitializeDiskJob(disk).schedule(); + TasksClient taskClient = new TasksClient(); + TaskInfo taskInfo = taskClient.getTaskInfo(uri); + if (taskInfo != null && taskInfo instanceof TaskInfo) { + GlusterDataModelManager.getInstance().getModel().getCluster().addTaskInfo(taskInfo); + } + updateStatus(DISK_STATUS.INITIALIZING, true); + } catch (Exception e1) { + MessageDialog.openError(getShell(), "Error: Initialize disk", e1.getMessage()); + } } } diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitializeDiskTask.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitializeDiskTask.java index 89c8c20f..ea9dd7e5 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitializeDiskTask.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitializeDiskTask.java @@ -20,6 +20,10 @@ */ package com.gluster.storage.management.server.tasks; +import org.springframework.context.ApplicationContext; +import org.springframework.web.context.ContextLoader; + +import com.gluster.storage.management.core.constants.GlusterConstants; import com.gluster.storage.management.core.exceptions.ConnectionException; import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.model.Status; @@ -34,12 +38,12 @@ import com.sun.jersey.core.util.Base64; public class InitializeDiskTask extends Task { - private static final String INITIALIZE_DISK_SCRIPT = "initialize_disk.py"; + private static final String INITIALIZE_DISK_SCRIPT = "format_device.py"; private String serverName; private String diskName; private String fsType; - private SshUtil sshUtil = new SshUtil(); + private SshUtil sshUtil; private GlusterUtil glusterUtil; public InitializeDiskTask(ClusterService clusterService, String clusterName, String serverName, String diskName, String fsType) { @@ -49,12 +53,20 @@ public class InitializeDiskTask extends Task { setServerName(serverName); setDiskName(diskName); setFsType(fsType); + init(); } public InitializeDiskTask(ClusterService clusterService, String clusterName, TaskInfo info) { super(clusterService, clusterName, info); + init(); } + private void init() { + ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); + glusterUtil = ctx.getBean(GlusterUtil.class); + sshUtil = ctx.getBean(SshUtil.class); + } + @Override public String getId() { return new String( @@ -108,23 +120,18 @@ public class InitializeDiskTask extends Task { } private void startInitializeDisk(String serverName) { - ProcessResult processResult = sshUtil.executeRemote(serverName, INITIALIZE_DISK_SCRIPT + " -t " + getFsType() - + " " + getDiskName()); + String fsTypeCommand = (getFsType().equals(GlusterConstants.FSTYPE_DEFAULT)) ? "" : " -t " + getFsType(); + ProcessResult processResult = sshUtil.executeRemote(serverName, INITIALIZE_DISK_SCRIPT + fsTypeCommand + " " + + getDiskName()); if (processResult.isSuccess()) { - getTaskInfo().setStatus(new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, processResult.getOutput()))); - TaskStatus taskStatus = null; - if (fsType.equals("xfs")) { - taskStatus.setPercentageSupported(false); - } else { - taskStatus.setPercentageSupported(true); - } - + TaskStatus taskStatus = new TaskStatus(new Status(Status.STATUS_CODE_RUNNING, processResult.getOutput())); + taskStatus.setPercentageSupported((getFsType().equals(GlusterConstants.FSTYPE_XFS)) ? false : true); + getTaskInfo().setStatus(taskStatus); return; } // if we reach here, it means Initialize disk start failed. throw new GlusterRuntimeException(processResult.toString()); - } @Override diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java index e614641c..4bd3b632 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java @@ -73,7 +73,7 @@ public class GlusterUtil { private static final GlusterCoreUtil glusterCoreUtil = new GlusterCoreUtil(); - private static final String INITIALIZE_DISK_STATUS_SCRIPT = "initialize_disk_status.py"; + private static final String INITIALIZE_DISK_STATUS_SCRIPT = "format_device_status.py"; @Autowired private SshUtil sshUtil; |
