diff options
| author | Tim <timothyasir@gluster.com> | 2011-07-06 20:30:54 +0530 |
|---|---|---|
| committer | Tim <timothyasir@gluster.com> | 2011-07-06 20:30:54 +0530 |
| commit | 89b6d425449fc6db353bdffc76a0926e8a6cc25d (patch) | |
| tree | 178ef5540e4dea367bbf64e75365b734b4f381c2 | |
| parent | 87167e5c2ab3c78738dd929a2844bad56700954f (diff) | |
| parent | 1e74112c748f1f872f80d2e539d29f7894f8ddc1 (diff) | |
Merge remote branch 'upstream/master'
36 files changed, 707 insertions, 260 deletions
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java index 6f4ba050..3c6a2d40 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java @@ -22,7 +22,6 @@ import javax.ws.rs.core.MultivaluedMap; import com.gluster.storage.management.client.utils.ClientUtil;
import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
-import com.gluster.storage.management.core.model.TaskInfo;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.UniformInterfaceException;
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java index 221651a3..8d821174 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterDataModelManager.java @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import org.apache.log4j.Logger; + import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.model.Brick; import com.gluster.storage.management.core.model.Cluster; @@ -53,6 +55,8 @@ public class GlusterDataModelManager { private List<ClusterListener> listeners = new ArrayList<ClusterListener>(); private List<VolumeOptionInfo> volumeOptionsDefaults; private String clusterName; + private static Boolean syncInProgress = false; + private static final Logger logger = Logger.getLogger(GlusterDataModelManager.class); private GlusterDataModelManager() { } @@ -106,7 +110,17 @@ public class GlusterDataModelManager { } public void refreshModel() { + synchronized (syncInProgress) { + if(syncInProgress) { + logger.info("Previous data sync is still running. Skipping this one."); + return; + } + syncInProgress = true; + } + + logger.info("Starting data sync"); updateModel(fetchData(clusterName)); + syncInProgress = false; } private void updateModel(GlusterDataModel model) { @@ -600,8 +614,7 @@ public class GlusterDataModelManager { } public void removeTask(TaskInfo taskInfo) { - Cluster cluster = model.getCluster(); - cluster.removeTaskInfo(taskInfo); + model.getCluster().removeTaskInfo(taskInfo); for (ClusterListener listener : listeners) { listener.taskAdded(taskInfo); } 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 b6d0a426..fa925842 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 @@ -62,8 +62,10 @@ public class GlusterServersClient extends AbstractClient { postRequest(form); } - public void initializeDisk(String serverName, String diskName) { - putRequest(serverName + "/" + RESTConstants.RESOURCE_DISKS + "/" + diskName); + public void 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); } 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 f48f33cf..567eda61 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,4 +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_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.core/src/com/gluster/storage/management/core/constants/RESTConstants.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java index 527ae2a1..9450ac48 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/RESTConstants.java @@ -60,6 +60,7 @@ public class RESTConstants { public static final String FORM_PARAM_BRICKS = "bricks"; public static final String FORM_PARAM_ACCESS_PROTOCOLS = "accessProtocols"; public static final String FORM_PARAM_VOLUME_OPTIONS = "options"; + public static final String FORM_PARAM_FSTYPE = "fsType"; public static final String FORM_PARAM_CLUSTER_NAME = "clusterName"; public static final String FORM_PARAM_SERVER_NAME = "serverName"; diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Cluster.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Cluster.java index 4f6c317c..289978ad 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Cluster.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Cluster.java @@ -155,7 +155,7 @@ public class Cluster extends Entity { public GlusterServer getServer(String serverName) { for(GlusterServer server : servers) { - if (server.getName().equals(serverName)) { + if (server.getName().equalsIgnoreCase(serverName)) { return server; } } diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/InitDiskStatusResponse.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/InitDiskStatusResponse.java new file mode 100644 index 00000000..6d1e83e3 --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/InitDiskStatusResponse.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * InitDiskStatusResponse.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.core.model; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class InitDiskStatusResponse { + + public enum FORMAT_STATUS { + IN_PROGRESS, COMPLETED, NOT_RUNNING + }; + + private String[] FORMAT_STATUS_STR = { "In Progress", "Completed", "Not Running" }; + + private String device; + private String message; + private float totalBlocks; + private float completedBlocks; + private FORMAT_STATUS status; + + public InitDiskStatusResponse() { + + } + + public void setDevice(String device) { + this.device = device; + } + + public String getDevice() { + return device; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + + public void setTotalBlocks(float totalBlocks) { + this.totalBlocks = totalBlocks; + } + + public float getTotalBlocks() { + return totalBlocks; + } + + public void setCompletedBlocks(float completedBlocks) { + this.completedBlocks = completedBlocks; + } + + public float getCompletedBlocks() { + return completedBlocks; + } + + public String getStatusStr() { + return FORMAT_STATUS_STR[getStatus().ordinal()]; + } + + public FORMAT_STATUS getStatus() { + return status; + } + + public void setStatus(FORMAT_STATUS status) { + this.status = status; + } + +} diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Server.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Server.java index 9e9212dc..39696665 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Server.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Server.java @@ -1,5 +1,4 @@ /******************************************************************************* - * 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 @@ -35,8 +34,6 @@ public class Server extends Entity { private double cpuUsage; private double totalMemory; private double memoryInUse; - private double totalDiskSpace = 0; - private double diskSpaceInUse = 0; private List<Disk> disks = new ArrayList<Disk>(); private List<NetworkInterface> networkInterfaces = new ArrayList<NetworkInterface>(); @@ -89,19 +86,22 @@ public class Server extends Entity { } public double getTotalDiskSpace() { + double totalDiskSpace = 0; + for(Disk disk : getDisks()) { + if(disk.isReady()) { + totalDiskSpace += disk.getSpace(); + } + } return totalDiskSpace; } - /** - * Total disk space is automatically calculated, and hence this method should never be called. It is required only - * to make sure that the element "totalDiskSpace" gets added to the XML tag when jersey converts the server object - * to XML for sending to client. - */ - public void setTotalDiskSpace(double totalDiskSpace) { - this.totalDiskSpace = totalDiskSpace; - } - public double getDiskSpaceInUse() { + double diskSpaceInUse = 0; + for(Disk disk : getDisks()) { + if(disk.isReady()) { + diskSpaceInUse += disk.getSpaceInUse(); + } + } return diskSpaceInUse; } @@ -109,15 +109,6 @@ public class Server extends Entity { return getTotalDiskSpace() - getDiskSpaceInUse(); } - /** - * Total disk space in use is automatically calculated, and hence this method should never be called. It is required - * only to make sure that the element "diskSpaceInUse" gets added to the XML tag when jersey converts the server - * object to XML for sending to client. - */ - public void setDiskSpaceInUse(double diskSpaceInUse) { - this.diskSpaceInUse = diskSpaceInUse; - } - @XmlElementWrapper(name = "networkInterfaces") @XmlElement(name = "networkInterface", type = NetworkInterface.class) public List<NetworkInterface> getNetworkInterfaces() { @@ -139,10 +130,7 @@ public class Server extends Entity { } public void addDisk(Disk disk) { - if (disks.add(disk) && disk.isReady()) { - totalDiskSpace += disk.getSpace(); - diskSpaceInUse += disk.getSpaceInUse(); - } + disks.add(disk); } public void addDisks(Collection<Disk> disks) { @@ -152,16 +140,11 @@ public class Server extends Entity { } public void removeDisk(Disk disk) { - if (disks.remove(disk)) { - totalDiskSpace -= disk.getSpace(); - diskSpaceInUse -= disk.getSpaceInUse(); - } + disks.remove(disk); } public void removeAllDisks() { disks.clear(); - totalDiskSpace = 0; - diskSpaceInUse = 0; } public void setDisks(List<Disk> disks) { @@ -203,8 +186,6 @@ public class Server extends Entity { setCpuUsage(server.getCpuUsage()); setTotalMemory(server.getTotalMemory()); setMemoryInUse(server.getMemoryInUse()); - setTotalDiskSpace(server.getTotalDiskSpace()); - setDiskSpaceInUse(server.getDiskSpaceInUse()); } @Override diff --git a/src/com.gluster.storage.management.gui/plugin.xml b/src/com.gluster.storage.management.gui/plugin.xml index b0dfa9a9..0a4c068d 100644 --- a/src/com.gluster.storage.management.gui/plugin.xml +++ b/src/com.gluster.storage.management.gui/plugin.xml @@ -403,7 +403,7 @@ icon="icons/volume-delete.png" id="com.gluster.storage.management.gui.actions.DeleteVolumeAction" label="&Delete Volume(s)" - menubarPath="com.gluster.storage.management.gui.menu.volumes/volumes" + menubarPath="com.gluster.storage.management.gui.actionsets.volumes/volumes" mode="FORCE_TEXT" pulldown="false" retarget="false" @@ -419,7 +419,7 @@ icon="icons/volume-stop.png" id="com.gluster.storage.management.gui.actions.StopVolumeAction" label="S&top Volume(s)" - menubarPath="com.gluster.storage.management.gui.menu.volumes/volumes" + menubarPath="com.gluster.storage.management.gui.actionsets.volumes/volumes" mode="FORCE_TEXT" pulldown="false" retarget="false" @@ -435,7 +435,7 @@ icon="icons/volume-start.png" id="com.gluster.storage.management.gui.actions.StartVolumeAction" label="&Start Volume(s)" - menubarPath="com.gluster.storage.management.gui.menu.volumes/volumes" + menubarPath="com.gluster.storage.management.gui.actionsets.volumes/volumes" mode="FORCE_TEXT" pulldown="false" retarget="false" @@ -448,10 +448,10 @@ allowLabelUpdate="false" class="com.gluster.storage.management.gui.actions.CreateVolumeAction" definitionId="com.gluster.storage.management.gui.commands.CreateVolume" - icon="icons/volume-create.png" + icon="icons/tango/32x32/volume-create.png" id="com.gluster.storage.management.gui.actions.CreateVolumeAction" - label="&Create Volume" - menubarPath="com.gluster.storage.management.gui.menu.volumes/volumes" + label="Create &Volume" + menubarPath="com.gluster.storage.management.gui.actionsets.volumes/volumes" mode="FORCE_TEXT" pulldown="false" retarget="false" @@ -461,7 +461,7 @@ tooltip="Create a new Volume"> </action> <menu - id="com.gluster.storage.management.gui.menu.volumes" + id="com.gluster.storage.management.gui.actionsets.volumes" label="&Gluster" path="additions"> <groupMarker @@ -623,100 +623,6 @@ toolbarPath="Normal" tooltip="Add Brick to Volume"> </action> - <menu - id="com.gluster.storage.management.gui.menu.volume" - label="&Gluster" - path="additions"> - <groupMarker - name="volume"> - </groupMarker> - </menu> - </actionSet> - <actionSet - description="Set of actions that can be performed from "Cluster" context" - id="com.gluster.storage.management.gui.actionsets.gluster" - label="Cluster Action Set" - visible="false"> - <action - allowLabelUpdate="false" - class="com.gluster.storage.management.gui.actions.ClearTaskAction" - definitionId="com.gluster.storage.management.gui.commands.Clear" - icon="icons/close_task.png" - id="com.gluster.storage.management.gui.actions.Clear" - label="&Clear Task" - menubarPath="com.gluster.storage.management.gui.menu.cluster/cluster" - mode="FORCE_TEXT" - pulldown="false" - retarget="false" - state="false" - style="push" - toolbarPath="Normal" - tooltip="To clear selected task from task list"> - </action> - <action - allowLabelUpdate="false" - class="com.gluster.storage.management.gui.actions.CommitTaskAction" - definitionId="com.gluster.storage.management.gui.commands.Commit" - icon="icons/stop.png" - id="com.gluster.storage.management.gui.actions.Commit" - label="&Commit Task" - menubarPath="com.gluster.storage.management.gui.menu.cluster/cluster" - mode="FORCE_TEXT" - pulldown="false" - retarget="false" - state="false" - style="push" - toolbarPath="Normal" - tooltip="To Commit the selected task"> - </action> - <action - allowLabelUpdate="false" - class="com.gluster.storage.management.gui.actions.StopTaskAction" - definitionId="com.gluster.storage.management.gui.commands.Stop" - icon="icons/stop_task.png" - id="com.gluster.storage.management.gui.actions.Stop" - label="&Stop Task" - menubarPath="com.gluster.storage.management.gui.menu.cluster/cluster" - mode="FORCE_TEXT" - pulldown="false" - retarget="false" - state="false" - style="push" - toolbarPath="Normal" - tooltip="To Stop the selected task"> - </action> - <action - allowLabelUpdate="false" - class="com.gluster.storage.management.gui.actions.ResumeTaskAction" - definitionId="com.gluster.storage.management.gui.commands.Pause" - icon="icons/start_task.gif" - id="com.gluster.storage.management.gui.actions.Resume" - label="&Resume Task" - menubarPath="com.gluster.storage.management.gui.menu.cluster/cluster" - mode="FORCE_TEXT" - pulldown="false" - retarget="false" - state="false" - style="push" - toolbarPath="Normal" - tooltip="To Resume the selected task"> - </action> - <action - allowLabelUpdate="false" - class="com.gluster.storage.management.gui.actions.PauseTaskAction" - definitionId="com.gluster.storage.management.gui.commands.Pause" - icon="icons/pause_task.png" - id="com.gluster.storage.management.gui.actions.Pause" - label="&Pause Task" - menubarPath="com.gluster.storage.management.gui.menu.cluster/cluster" - mode="FORCE_TEXT" - pulldown="false" - retarget="false" - state="false" - style="push" - toolbarPath="Normal" - tooltip="To Pause the selected task"> - </action> <action allowLabelUpdate="false" class="com.gluster.storage.management.gui.actions.CreateVolumeAction" @@ -724,7 +630,7 @@ icon="icons/tango/32x32/volume-create.png" id="com.gluster.storage.management.gui.actions.CreateVolumeAction" label="Create &Volume" - menubarPath="com.gluster.storage.management.gui.menu.cluster/cluster" + menubarPath="com.gluster.storage.management.gui.menu.volume/volume" mode="FORCE_TEXT" pulldown="false" retarget="false" @@ -734,10 +640,11 @@ tooltip="Create a new Volume"> </action> <menu - id="com.gluster.storage.management.gui.menu.cluster" - label="&Gluster"> + id="com.gluster.storage.management.gui.menu.volume" + label="&Gluster" + path="additions"> <groupMarker - name="cluster"> + name="volume"> </groupMarker> </menu> </actionSet> @@ -762,6 +669,22 @@ toolbarPath="Normal" tooltip="Remove Server(s)"> </action> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.CreateVolumeAction" + definitionId="com.gluster.storage.management.gui.commands.CreateVolume" + icon="icons/tango/32x32/volume-create.png" + id="com.gluster.storage.management.gui.actions.CreateVolumeAction" + label="Create &Volume" + menubarPath="com.gluster.storage.management.gui.menu.servers/servers" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="Create a new Volume"> + </action> <menu id="com.gluster.storage.management.gui.menu.servers" label="&Gluster" @@ -792,6 +715,22 @@ toolbarPath="Normal" tooltip="Remove Server"> </action> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.CreateVolumeAction" + definitionId="com.gluster.storage.management.gui.commands.CreateVolume" + icon="icons/tango/32x32/volume-create.png" + id="com.gluster.storage.management.gui.actions.CreateVolumeAction" + label="Create &Volume" + menubarPath="com.gluster.storage.management.gui.menu.glusterserver/glusterserver" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="Create a new Volume"> + </action> <menu id="com.gluster.storage.management.gui.menu.glusterserver" label="&Gluster" @@ -822,6 +761,22 @@ toolbarPath="Normal" tooltip="Add Server(s) to Cluster"> </action> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.CreateVolumeAction" + definitionId="com.gluster.storage.management.gui.commands.CreateVolume" + icon="icons/tango/32x32/volume-create.png" + id="com.gluster.storage.management.gui.actions.CreateVolumeAction" + label="Create &Volume" + menubarPath="com.gluster.storage.management.gui.menu.discoveredservers/discoveredservers" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="Create a new Volume"> + </action> <menu id="com.gluster.storage.management.gui.menu.discoveredservers" label="&Gluster" @@ -852,6 +807,22 @@ toolbarPath="Normal" tooltip="Add Server(s) to Cluster"> </action> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.CreateVolumeAction" + definitionId="com.gluster.storage.management.gui.commands.CreateVolume" + icon="icons/tango/32x32/volume-create.png" + id="com.gluster.storage.management.gui.actions.CreateVolumeAction" + label="Create &Volume" + menubarPath="com.gluster.storage.management.gui.menu.discoveredserver/discoveredserver" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="Create a new Volume"> + </action> <menu id="com.gluster.storage.management.gui.menu.discoveredserver" label="&Gluster" @@ -862,6 +833,145 @@ </menu> </actionSet> <actionSet + description="Set of actions that can be performed from "Cluster" context" + id="com.gluster.storage.management.gui.actionsets.task" + label="Task Action Set" + visible="false"> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.ClearTaskAction" + definitionId="com.gluster.storage.management.gui.commands.Clear" + icon="icons/close_task.png" + id="com.gluster.storage.management.gui.actions.Clear" + label="&Clear Task" + menubarPath="com.gluster.storage.management.gui.menu.task/task" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="To clear selected task from task list"> + </action> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.CommitTaskAction" + definitionId="com.gluster.storage.management.gui.commands.Commit" + icon="icons/stop.png" + id="com.gluster.storage.management.gui.actions.Commit" + label="&Commit Task" + menubarPath="com.gluster.storage.management.gui.menu.task/task" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="To Commit the selected task"> + </action> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.StopTaskAction" + definitionId="com.gluster.storage.management.gui.commands.Stop" + icon="icons/stop_task.png" + id="com.gluster.storage.management.gui.actions.Stop" + label="&Stop Task" + menubarPath="com.gluster.storage.management.gui.menu.task/task" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="To Stop the selected task"> + </action> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.ResumeTaskAction" + definitionId="com.gluster.storage.management.gui.commands.Pause" + icon="icons/start_task.gif" + id="com.gluster.storage.management.gui.actions.Resume" + label="&Resume Task" + menubarPath="com.gluster.storage.management.gui.menu.task/task" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="To Resume the selected task"> + </action> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.PauseTaskAction" + definitionId="com.gluster.storage.management.gui.commands.Pause" + icon="icons/pause_task.png" + id="com.gluster.storage.management.gui.actions.Pause" + label="&Pause Task" + menubarPath="com.gluster.storage.management.gui.menu.task/task" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="To Pause the selected task"> + </action> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.CreateVolumeAction" + definitionId="com.gluster.storage.management.gui.commands.CreateVolume" + icon="icons/tango/32x32/volume-create.png" + id="com.gluster.storage.management.gui.actions.CreateVolumeAction" + label="Create &Volume" + menubarPath="com.gluster.storage.management.gui.menu.task/task" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="Create a new Volume"> + </action> + <menu + id="com.gluster.storage.management.gui.menu.task" + label="&Gluster"> + <groupMarker + name="task"> + </groupMarker> + </menu> + </actionSet> + <actionSet + description="Set of actions that can be performed at Cluster context" + id="com.gluster.storage.management.gui.actionsets.gluster" + label="Gluster Actions" + visible="false"> + <action + allowLabelUpdate="false" + class="com.gluster.storage.management.gui.actions.CreateVolumeAction" + definitionId="com.gluster.storage.management.gui.commands.CreateVolume" + icon="icons/tango/32x32/volume-create.png" + id="com.gluster.storage.management.gui.actions.CreateVolumeAction" + label="Create &Volume" + menubarPath="com.gluster.storage.management.gui.menu.gluster/gluster" + mode="FORCE_TEXT" + pulldown="false" + retarget="false" + state="false" + style="push" + toolbarPath="Normal" + tooltip="Create a new Volume"> + </action> + <menu + id="com.gluster.storage.management.gui.menu.gluster" + label="&Gluster" + path="additions"> + <groupMarker + name="gluster"> + </groupMarker> + </menu> + </actionSet> + <actionSet description="Set of Actions in "Edit" menu" id="com.gluster.storage.management.gui.actionsets.edit" label="Edit Action Set" @@ -896,7 +1006,7 @@ state="false" style="push" toolbarPath="Normal" - tooltip="Preferences"> + tooltip="Settings"> </action> <menu id="com.gluster.storage.management.gui.menu.edit" diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/Application.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/Application.java index 598f9639..bff46096 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/Application.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/Application.java @@ -23,10 +23,14 @@ import java.util.Collections; import java.util.List; import org.eclipse.core.databinding.observable.Realm; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -35,6 +39,8 @@ import org.eclipse.ui.PlatformUI; import com.gluster.storage.management.core.model.Entity; import com.gluster.storage.management.gui.dialogs.LoginDialog; +import com.gluster.storage.management.gui.jobs.DataSyncJob; +import com.gluster.storage.management.gui.preferences.PreferenceConstants; /** * This class controls all aspects of the application's execution @@ -45,6 +51,7 @@ public class Application implements IApplication { private static Application instance; private List<IEntityListener> entityListeners = Collections.synchronizedList(new ArrayList<IEntityListener>()); private IStatusLineManager statusLineManager; + private Job syncJob; public Application() { instance = this; @@ -88,16 +95,36 @@ public class Application implements IApplication { return IApplication.EXIT_OK; } try { + setupBackgroundJobs(); + int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) { return IApplication.EXIT_RESTART; } + return IApplication.EXIT_OK; } finally { display.dispose(); } } + private void setupBackgroundJobs() { + // 1 minute delay for first run + final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); + final long JOB_INTERVAL = preferenceStore.getLong(PreferenceConstants.P_DATA_SYNC_INTERVAL) * 1000; + + syncJob = new DataSyncJob("Syncing cluster data in background"); + syncJob.schedule(JOB_INTERVAL); + syncJob.addJobChangeListener(new JobChangeAdapter() { + @Override + public void done(IJobChangeEvent event) { + super.done(event); + // job done. schedule again after the pre-defined interval + syncJob.schedule(JOB_INTERVAL); + } + }); + } + private void setSystemProperties() { // TODO: Trying this to avoid the webstart authentication dialog // to be tested, and removed if this doesn't work. @@ -116,6 +143,7 @@ public class Application implements IApplication { final Display display = workbench.getDisplay(); display.syncExec(new Runnable() { public void run() { + syncJob.cancel(); if (!display.isDisposed()) workbench.close(); } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ClearTaskAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ClearTaskAction.java index 6fff4f44..4a580d05 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ClearTaskAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/ClearTaskAction.java @@ -17,7 +17,7 @@ public class ClearTaskAction extends AbstractActionDelegate { final String actionDesc = action.getDescription(); try { - new TasksClient().resumeTask(taskInfo.getName()); + new TasksClient().deleteTask(taskInfo.getName()); // taskId modelManager.removeTask(taskInfo); } catch (Exception e) { showErrorDialog(actionDesc, @@ -33,6 +33,8 @@ public class ClearTaskAction extends AbstractActionDelegate { taskInfo = (TaskInfo) selectedEntity; action.setEnabled(taskInfo.getStatus().getCode() == Status.STATUS_CODE_SUCCESS || taskInfo.getStatus().getCode() == Status.STATUS_CODE_FAILURE); + } else { + action.setEnabled(false); } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CommitTaskAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CommitTaskAction.java index 86e3032e..86a71882 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CommitTaskAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CommitTaskAction.java @@ -5,11 +5,9 @@ import org.eclipse.jface.viewers.ISelection; import com.gluster.storage.management.client.GlusterDataModelManager; import com.gluster.storage.management.client.TasksClient; -import com.gluster.storage.management.client.VolumesClient; import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.TaskInfo; import com.gluster.storage.management.core.model.TaskStatus; -import com.gluster.storage.management.core.model.Volume; public class CommitTaskAction extends AbstractActionDelegate { private TaskInfo taskInfo; @@ -21,12 +19,8 @@ public class CommitTaskAction extends AbstractActionDelegate { try { new TasksClient().commitTask(taskInfo.getName()); taskInfo.setStatus(new TaskStatus(new Status(Status.STATUS_CODE_SUCCESS, "Committed"))); - modelManager.removeTask(taskInfo); - Volume volume = (new VolumesClient()).getVolume(taskInfo.getReference()); - modelManager.updateVolumeBricks(modelManager.getModel().getCluster().getVolume(taskInfo.getReference()), - volume.getBricks()); - showInfoDialog(actionDesc, "Commit successful"); + modelManager.removeTask(taskInfo); } catch (Exception e) { showErrorDialog(actionDesc, "Task [" + taskInfo.getName() + "] could not be Committed! Error: [" + e.getMessage() + "]"); diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java index 2cfa0916..9bafd2b0 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java @@ -54,16 +54,4 @@ public class CreateVolumeAction extends AbstractActionDelegate { public void dispose() { window = null; } - - @SuppressWarnings("rawtypes") - @Override - public void selectionChanged(IAction action, ISelection selection) { - super.selectionChanged(action, selection); - - action.setEnabled(true); - if(selectedEntity instanceof EntityGroup && ((EntityGroup)selectedEntity).getEntityType() != Volume.class) { - // selected entity is either "servers" or "discovered servers". - action.setEnabled(false); - } - } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/IActionConstants.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/IActionConstants.java index 2f696709..c5e8958f 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/IActionConstants.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/IActionConstants.java @@ -28,7 +28,7 @@ public interface IActionConstants { public static final String ACTION_SET_GLUSTER_SERVER = "com.gluster.storage.management.gui.actionsets.glusterserver"; public static final String ACTION_SET_DISCOVERED_SERVERS = "com.gluster.storage.management.gui.actionsets.serversdiscovered"; public static final String ACTION_SET_DISCOVERED_SERVER = "com.gluster.storage.management.gui.actionsets.serverdiscovered"; - + public static final String ACTION_SET_TASK = "com.gluster.storage.management.gui.actionsets.task"; public static final String ACTION_SET_EDIT = "com.gluster.storage.management.gui.actionsets.edit"; public static final String COMMAND_CREATE_VOLUME = "com.gluster.storage.management.gui.commands.CreateVolume"; diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/PauseTaskAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/PauseTaskAction.java index e3a4b835..872df738 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/PauseTaskAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/PauseTaskAction.java @@ -28,6 +28,7 @@ import com.gluster.storage.management.client.TasksClient; import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.TaskInfo; import com.gluster.storage.management.core.model.TaskStatus; +import com.gluster.storage.management.gui.toolbar.GlusterToolbarManager; public class PauseTaskAction extends AbstractActionDelegate { diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopTaskAction.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopTaskAction.java index 12d14b43..306edbf3 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopTaskAction.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/StopTaskAction.java @@ -2,13 +2,11 @@ package com.gluster.storage.management.gui.actions; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.widgets.Display; import com.gluster.storage.management.client.GlusterDataModelManager; import com.gluster.storage.management.client.TasksClient; import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.TaskInfo; -import com.gluster.storage.management.core.model.TaskStatus; public class StopTaskAction extends AbstractActionDelegate { private TaskInfo taskInfo; @@ -19,9 +17,10 @@ public class StopTaskAction extends AbstractActionDelegate { final String actionDesc = action.getDescription(); try { - new TasksClient().resumeTask(taskInfo.getName()); - taskInfo.setStatus(new TaskStatus(new Status(Status.STATUS_CODE_SUCCESS, "Stopped"))); - modelManager.updateTask(taskInfo); + new TasksClient().stopTask(taskInfo.getName()); + // On successful stop clear from the task list + modelManager.removeTask(taskInfo); + action.setEnabled(false); // TODO disable other task buttons } catch (Exception e) { showErrorDialog(actionDesc, "Task [" + taskInfo.getDescription() + "] could not be Stopped! Error: [" + e.getMessage() + "]"); @@ -42,7 +41,6 @@ public class StopTaskAction extends AbstractActionDelegate { @Override public void dispose() { - } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/jobs/DataSyncJob.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/jobs/DataSyncJob.java new file mode 100644 index 00000000..f6fd1ba4 --- /dev/null +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/jobs/DataSyncJob.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * 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.jobs; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.swt.widgets.Display; + +import com.gluster.storage.management.client.GlusterDataModelManager; +import com.gluster.storage.management.gui.utils.GUIHelper; + +/** + * + */ +public class DataSyncJob extends Job { + public DataSyncJob(String name) { + super(name); + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + protected IStatus run(IProgressMonitor monitor) { + Display.getDefault().asyncExec(new Runnable() { + + @Override + public void run() { + GUIHelper.getInstance().setStatusMessage("Data sync in progress..."); + GlusterDataModelManager.getInstance().refreshModel(); + GUIHelper.getInstance().setStatusMessage(null); + } + }); + + return Status.OK_STATUS; + } +} diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/GlusterPreferencePage.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/GlusterPreferencePage.java index 431a8128..d8eee3e4 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/GlusterPreferencePage.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/GlusterPreferencePage.java @@ -77,7 +77,7 @@ public class GlusterPreferencePage addField(new ComboFieldEditor(PreferenceConstants.P_DEFAULT_CLUSTER_NAME, "Default &Cluster to manage:", clusterNamesArr, getFieldEditorParent())); - addField(new IntegerFieldEditor(PreferenceConstants.P_DATA_REFRESH_INTERVAL, "&Data Refresh Interval:", + addField(new IntegerFieldEditor(PreferenceConstants.P_DATA_SYNC_INTERVAL, "&Data Sync Interval (sec):", getFieldEditorParent())); } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceConstants.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceConstants.java index 260aadb6..039cf488 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceConstants.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceConstants.java @@ -25,12 +25,11 @@ public class PreferenceConstants { public static final String P_SHOW_CLUSTER_SELECTION_DIALOG = "show.cluster.selection.dialog"; public static final String P_DEFAULT_CLUSTER_NAME = "default.cluster.name"; - public static final String P_DATA_REFRESH_INTERVAL = "data.refresh.interval"; + public static final String P_DATA_SYNC_INTERVAL = "data.sync.interval"; // TODO: Remove after proper preferences are added public static final String P_PATH = "pathPreference"; public static final String P_BOOLEAN = "booleanPreference"; public static final String P_CHOICE = "choicePreference"; public static final String P_STRING = "stringPreference"; - } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceInitializer.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceInitializer.java index 1a4104ac..909b957a 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceInitializer.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/preferences/PreferenceInitializer.java @@ -37,5 +37,8 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer { IPreferenceStore store = Activator.getDefault().getPreferenceStore(); store.setDefault(PreferenceConstants.P_SHOW_CLUSTER_SELECTION_DIALOG, true); + + // default data sync interval = 5 minutes + store.setDefault(PreferenceConstants.P_DATA_SYNC_INTERVAL, 300); } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/toolbar/GlusterToolbarManager.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/toolbar/GlusterToolbarManager.java index cef0bf5d..88c18a7f 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/toolbar/GlusterToolbarManager.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/toolbar/GlusterToolbarManager.java @@ -29,12 +29,13 @@ import com.gluster.storage.management.core.model.Entity; import com.gluster.storage.management.core.model.EntityGroup; import com.gluster.storage.management.core.model.GlusterServer; import com.gluster.storage.management.core.model.Server; +import com.gluster.storage.management.core.model.TaskInfo; import com.gluster.storage.management.core.model.Volume; import com.gluster.storage.management.gui.actions.IActionConstants; public class GlusterToolbarManager implements ToolbarManager { private enum ENTITY_TYPE { - CLUSTER, VOLUMES, VOLUME, GLUSTER_SERVERS, GLUSTER_SERVER, DISCOVERED_SERVERS, DISCOVERED_SERVER + CLUSTER, VOLUMES, VOLUME, GLUSTER_SERVERS, GLUSTER_SERVER, DISCOVERED_SERVERS, DISCOVERED_SERVER, TASK }; private IWorkbenchWindow window; @@ -47,6 +48,7 @@ public class GlusterToolbarManager implements ToolbarManager { entityTypeMap.put(Volume.class, ENTITY_TYPE.VOLUME); entityTypeMap.put(Server.class, ENTITY_TYPE.DISCOVERED_SERVER); entityTypeMap.put(GlusterServer.class, ENTITY_TYPE.GLUSTER_SERVER); + entityTypeMap.put(TaskInfo.class, ENTITY_TYPE.TASK); return entityTypeMap; } @@ -60,6 +62,7 @@ public class GlusterToolbarManager implements ToolbarManager { actionSetMap.put(ENTITY_TYPE.GLUSTER_SERVER, IActionConstants.ACTION_SET_GLUSTER_SERVER); actionSetMap.put(ENTITY_TYPE.DISCOVERED_SERVERS, IActionConstants.ACTION_SET_DISCOVERED_SERVERS); actionSetMap.put(ENTITY_TYPE.DISCOVERED_SERVER, IActionConstants.ACTION_SET_DISCOVERED_SERVER); + actionSetMap.put(ENTITY_TYPE.TASK, IActionConstants.ACTION_SET_TASK); return actionSetMap; } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServerSummaryView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServerSummaryView.java index 77e902ab..f9526ef9 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServerSummaryView.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterServerSummaryView.java @@ -41,11 +41,17 @@ import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; import org.eclipse.ui.part.ViewPart; +import com.gluster.storage.management.client.GlusterDataModelManager; +import com.gluster.storage.management.core.model.ClusterListener; +import com.gluster.storage.management.core.model.DefaultClusterListener; +import com.gluster.storage.management.core.model.Event; import com.gluster.storage.management.core.model.GlusterServer; import com.gluster.storage.management.core.model.GlusterServer.SERVER_STATUS; +import com.gluster.storage.management.core.model.Volume; import com.gluster.storage.management.core.utils.NumberUtil; import com.gluster.storage.management.gui.IImageKeys; import com.gluster.storage.management.gui.NetworkInterfaceTableLabelProvider; +import com.gluster.storage.management.gui.toolbar.GlusterToolbarManager; import com.gluster.storage.management.gui.utils.GUIHelper; import com.richclientgui.toolbox.gauges.CoolGauge; @@ -55,6 +61,7 @@ public class GlusterServerSummaryView extends ViewPart { private final FormToolkit toolkit = new FormToolkit(Display.getCurrent()); private ScrolledForm form; private GlusterServer server; + private ClusterListener serverChangedListener; public enum NETWORK_INTERFACE_TABLE_COLUMN_INDICES { INTERFACE, MODEL, SPEED, IP_ADDRESS, NETMASK, GATEWAY @@ -62,6 +69,7 @@ public class GlusterServerSummaryView extends ViewPart { private static final String[] NETWORK_INTERFACE_TABLE_COLUMN_NAMES = { "Interface", "Model", "Speed", "IP Address", "Netmask", "Gateway" }; + private CoolGauge cpuGauge; @Override public void createPartControl(Composite parent) { @@ -70,6 +78,28 @@ public class GlusterServerSummaryView extends ViewPart { } setPartName("Summary"); createSections(parent); + + final GlusterToolbarManager toolbarManager = new GlusterToolbarManager(getSite().getWorkbenchWindow()); + // Refresh the navigation tree whenever there is a change to the data model + serverChangedListener = new DefaultClusterListener() { + @Override + public void serverChanged(GlusterServer server, Event event) { + updateServerDetails(); + toolbarManager.updateToolbar(server); + } + }; + GlusterDataModelManager.getInstance().addClusterListener(serverChangedListener); + } + + private void updateServerDetails() { + // TODO Auto-generated method stub + + } + + @Override + public void dispose() { + super.dispose(); + GlusterDataModelManager.getInstance().removeClusterListener(serverChangedListener); } private void createSections(Composite parent) { @@ -100,15 +130,15 @@ public class GlusterServerSummaryView extends ViewPart { // toolkit.createLabel(section, online ? "" + server.getCpuUsage() : "NA", SWT.NONE); toolkit.createLabel(section, "% CPU Usage (avg): ", SWT.NONE); - CoolGauge gauge = new CoolGauge(section, guiHelper.getImage(IImageKeys.GAUGE_SMALL)); - gauge.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false)); - gauge.setGaugeNeedleColour(Display.getDefault().getSystemColor(SWT.COLOR_RED)); - gauge.setGaugeNeedleWidth(2); - gauge.setGaugeNeedlePivot(new Point(66, 65)); - - gauge.setPoints(getPnts()); - gauge.setLevel(server.getCpuUsage() / 100); - gauge.setToolTipText(server.getCpuUsage() + "%"); + cpuGauge = new CoolGauge(section, guiHelper.getImage(IImageKeys.GAUGE_SMALL)); + cpuGauge.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false)); + cpuGauge.setGaugeNeedleColour(Display.getDefault().getSystemColor(SWT.COLOR_RED)); + cpuGauge.setGaugeNeedleWidth(2); + cpuGauge.setGaugeNeedlePivot(new Point(66, 65)); + + cpuGauge.setPoints(getPnts()); + cpuGauge.setLevel(server.getCpuUsage() / 100); + cpuGauge.setToolTipText(server.getCpuUsage() + "%"); toolkit.createLabel(section, "Memory Usage: ", SWT.NONE); ProgressBar memoryUsageBar = new ProgressBar(section, SWT.SMOOTH); diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterViewsManager.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterViewsManager.java index ab1e55ab..a13d41d7 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterViewsManager.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/GlusterViewsManager.java @@ -49,7 +49,6 @@ public class GlusterViewsManager implements ViewsManager { public void updateViews(Entity entity) { closeAllViews(); - try { if (entity instanceof EntityGroup) { showViewsForEntityGroup((EntityGroup)entity); diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumeSummaryView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumeSummaryView.java index 17bb28f4..e0df170b 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumeSummaryView.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/VolumeSummaryView.java @@ -80,24 +80,14 @@ public class VolumeSummaryView extends ViewPart { setPartName("Summary"); createSections(); + final GlusterToolbarManager toolbarManager = new GlusterToolbarManager(getSite().getWorkbenchWindow()); // Refresh the navigation tree whenever there is a change to the data model volumeChangedListener = new DefaultClusterListener() { - @SuppressWarnings("unchecked") @Override public void volumeChanged(Volume volume, Event event) { - if (event.getEventType() == EVENT_TYPE.VOLUME_STATUS_CHANGED) { - updateVolumeStatusLabel(); - new GlusterToolbarManager(getSite().getWorkbenchWindow()).updateToolbar(volume); - } else if (event.getEventType() == EVENT_TYPE.VOLUME_OPTION_SET) { - Entry<String, String> option = (Entry<String, String>) event.getEventData(); - if (option.getKey().equals(Volume.OPTION_AUTH_ALLOW)) { - // access control option value has changed. update the text field with new value. - populateAccessControlText(); - } - } else if (event.getEventType() == EVENT_TYPE.VOLUME_OPTIONS_RESET) { - // all volume options reset. populate access control text with default value. - populateAccessControlText(); - } + updateVolumeStatusLabel(); + populateAccessControlText(); + toolbarManager.updateToolbar(volume); } }; GlusterDataModelManager.getInstance().addClusterListener(volumeChangedListener); 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 221e82b1..63cf65ed 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 @@ -20,6 +20,7 @@ package com.gluster.storage.management.gui.views.pages; 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; @@ -39,6 +40,7 @@ import org.eclipse.ui.forms.events.HyperlinkEvent; import org.eclipse.ui.forms.widgets.ImageHyperlink; import com.gluster.storage.management.client.GlusterServersClient; +import com.gluster.storage.management.core.constants.GlusterConstants; import com.gluster.storage.management.core.model.ClusterListener; import com.gluster.storage.management.core.model.DefaultClusterListener; import com.gluster.storage.management.core.model.Disk; @@ -46,7 +48,9 @@ import com.gluster.storage.management.core.model.Disk.DISK_STATUS; import com.gluster.storage.management.core.model.Entity; 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; public abstract class AbstractDisksPage extends AbstractTableViewerPage<Disk> implements IEntityListener { private List<Disk> disks; @@ -199,10 +203,27 @@ public abstract class AbstractDisksPage extends AbstractTableViewerPage<Disk> im @Override public void linkActivated(HyperlinkEvent e) { - updateStatus(DISK_STATUS.INITIALIZING, true); - + 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) + 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()); + serversClient.initializeDisk(disk.getServerName(), disk.getName(), fsType); + + updateStatus(DISK_STATUS.INITIALIZING, true); guiHelper.showProgressView(); new InitializeDiskJob(disk).schedule(); diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/AbstractTableViewerPage.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/AbstractTableViewerPage.java index a37773e1..5aaf7094 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/AbstractTableViewerPage.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/AbstractTableViewerPage.java @@ -25,6 +25,7 @@ import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.SWT; @@ -39,6 +40,8 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.forms.events.HyperlinkAdapter; import org.eclipse.ui.forms.widgets.FormToolkit; @@ -46,22 +49,26 @@ import org.eclipse.ui.forms.widgets.Hyperlink; import com.gluster.storage.management.client.GlusterDataModelManager; import com.gluster.storage.management.core.model.ClusterListener; +import com.gluster.storage.management.core.model.TaskInfo; import com.gluster.storage.management.gui.utils.GUIHelper; -public abstract class AbstractTableViewerPage<T> extends Composite { +public abstract class AbstractTableViewerPage<T> extends Composite implements ISelectionListener { - protected final FormToolkit toolkit = new FormToolkit(Display.getCurrent()); - protected TableViewer tableViewer; private boolean useCheckboxes; private boolean multiSelection; + + protected final FormToolkit toolkit = new FormToolkit(Display.getCurrent()); + protected TableViewer tableViewer; protected GUIHelper guiHelper = GUIHelper.getInstance(); protected Composite parent; + protected IWorkbenchSite site; private Hyperlink linkAll, linkNone; public AbstractTableViewerPage(IWorkbenchSite site, final Composite parent, int style, boolean useChechboxes, boolean multiSelection, Object model) { super(parent, style); this.parent = parent; + this.site = site; this.useCheckboxes = useChechboxes; this.multiSelection = multiSelection; @@ -76,8 +83,12 @@ public abstract class AbstractTableViewerPage<T> extends Composite { Text filterText = guiHelper.createFilterText(toolkit, this); setupTableViewer(site, filterText); - tableViewer.setInput(model); + // register as selection provider so that other views can listen to any selection events on the tree + site.setSelectionProvider(tableViewer); + site.getPage().addSelectionListener(this); + + parent.layout(); // Important - this actually paints the table createListeners(parent); @@ -213,4 +224,11 @@ public abstract class AbstractTableViewerPage<T> extends Composite { // Create a case insensitive filter for the table viewer using the filter text field guiHelper.createFilter(tableViewer, filterText, false); } + + /* (non-Javadoc) + * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + } } diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/TasksPage.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/TasksPage.java index 8d48af76..8fbeb891 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/TasksPage.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/pages/TasksPage.java @@ -25,21 +25,27 @@ import java.util.List; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.IBaseLabelProvider; import org.eclipse.jface.viewers.IContentProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchSite; import com.gluster.storage.management.core.model.ClusterListener; import com.gluster.storage.management.core.model.DefaultClusterListener; +import com.gluster.storage.management.core.model.Entity; import com.gluster.storage.management.core.model.Event; +import com.gluster.storage.management.core.model.Event.EVENT_TYPE; import com.gluster.storage.management.core.model.TaskInfo; import com.gluster.storage.management.core.model.Volume; -import com.gluster.storage.management.core.model.Event.EVENT_TYPE; import com.gluster.storage.management.gui.TasksTableLabelProvider; +import com.gluster.storage.management.gui.toolbar.GlusterToolbarManager; public class TasksPage extends AbstractTableViewerPage<TaskInfo> { private List<TaskInfo> taskInfoList; + private TaskInfo selectedTask; public enum TASK_TABLE_COLUMN_INDICES { TASK, STATUS @@ -67,11 +73,17 @@ public class TasksPage extends AbstractTableViewerPage<TaskInfo> { @Override public void taskRemoved(TaskInfo taskInfo) { refreshViewer(); + // hide the task related actionset as no task is selected + // site.getPage().hideActionSet(IActionConstants.ACTION_SET_TASK); + tableViewer.setSelection(new StructuredSelection(taskInfo)); } @Override public void taskUpdated(TaskInfo taskInfo) { refreshViewer(); + // fire selection event so that toolbar gets updated + // (the action class listens to selection and enables/disables automatically) + tableViewer.setSelection(new StructuredSelection(taskInfo)); } private void refreshViewer() { @@ -132,4 +144,18 @@ public class TasksPage extends AbstractTableViewerPage<TaskInfo> { protected List<TaskInfo> getAllEntities() { return taskInfoList; } + + /* (non-Javadoc) + * @see com.gluster.storage.management.gui.views.pages.AbstractTableViewerPage#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if (selection instanceof StructuredSelection) { + Entity selectedEntity = (Entity) ((StructuredSelection) selection).getFirstElement(); + if (selectedEntity != null && selectedEntity instanceof TaskInfo && selectedEntity != selectedTask) { + selectedTask = (TaskInfo)selectedEntity; + new GlusterToolbarManager(part.getSite().getWorkbenchWindow()).updateToolbar(selectedTask); + } + } + } } diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java index 619e4f55..b97d47f8 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java @@ -19,6 +19,7 @@ package com.gluster.storage.management.server.resources.v1_0; import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_SERVER_NAME; +import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_FSTYPE; import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_CLUSTER_NAME; import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_DISK_NAME; import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_SERVER_NAME; @@ -400,7 +401,8 @@ public class GlusterServersResource extends AbstractServersResource { @Produces(MediaType.APPLICATION_XML) @Path("{" + PATH_PARAM_SERVER_NAME + "}/" + RESOURCE_DISKS + "/{" + PATH_PARAM_DISK_NAME + "}") public Response initializeDisk(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName, - @PathParam(PATH_PARAM_SERVER_NAME) String serverName, @PathParam(PATH_PARAM_DISK_NAME) String diskName) { + @PathParam(PATH_PARAM_SERVER_NAME) String serverName, @PathParam(PATH_PARAM_DISK_NAME) String diskName, + @FormParam(FORM_PARAM_FSTYPE) String fsType) { if (clusterName == null || clusterName.isEmpty()) { return badRequestResponse("Cluster name must not be empty!"); @@ -413,8 +415,12 @@ public class GlusterServersResource extends AbstractServersResource { if (diskName == null || diskName.isEmpty()) { return badRequestResponse("Disk name must not be empty!"); } + + if (fsType == null || fsType.isEmpty()) { + return badRequestResponse("Parameter [" + FORM_PARAM_FSTYPE + "] is missing in request!"); + } - InitializeDiskTask initializeTask = new InitializeDiskTask(clusterService, clusterName, serverName, diskName); + InitializeDiskTask initializeTask = new InitializeDiskTask(clusterService, clusterName, serverName, diskName, fsType); try { initializeTask.start(); taskResource.addTask(initializeTask); diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/TasksResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/TasksResource.java index 777565eb..38b68040 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/TasksResource.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/TasksResource.java @@ -42,6 +42,8 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.springframework.stereotype.Component; + import com.gluster.storage.management.core.constants.RESTConstants; import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.exceptions.GlusterValidationException; @@ -52,6 +54,7 @@ import com.sun.jersey.spi.resource.Singleton; @Path(RESOURCE_PATH_CLUSTERS + "/{" + PATH_PARAM_CLUSTER_NAME + "}/" + RESOURCE_TASKS) @Singleton +@Component public class TasksResource extends AbstractResource { private Map<String, Task> tasksMap = new HashMap<String, Task>(); @@ -84,6 +87,16 @@ public class TasksResource extends AbstractResource { return null; } + public List<Task> getAllTasks() { + List<Task> tasks = new ArrayList<Task>(); + for (Map.Entry<String, Task> entry : tasksMap.entrySet()) { + checkTaskStatus(entry.getKey()); + tasks.add( (Task) entry.getValue()); + } + return tasks; + } + + @GET @Produces(MediaType.APPLICATION_XML) public Response getTasks() { @@ -140,7 +153,7 @@ public class TasksResource extends AbstractResource { @DELETE @Path("/{" + PATH_PARAM_TASK_ID + "}") @Produces(MediaType.APPLICATION_XML) - public Response deleteTask(@PathParam(PATH_PARAM_TASK_ID) String taskId, + public Response clearTask(@PathParam(PATH_PARAM_TASK_ID) String taskId, @QueryParam(FORM_PARAM_OPERATION) String taskOperation) { Task task = getTask(taskId); if (task == null) { diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/BrickMigrationStatusTask.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/BrickMigrationStatusTask.java new file mode 100644 index 00000000..0f00ad3a --- /dev/null +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/BrickMigrationStatusTask.java @@ -0,0 +1,42 @@ +/** + * DiskMigrationStatusTask.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.server.tasks; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.gluster.storage.management.core.model.TaskInfo.TASK_TYPE; +import com.gluster.storage.management.server.resources.v1_0.TasksResource; + +@Component +public class BrickMigrationStatusTask { + + @Autowired + private TasksResource tasksResource; + + public void checkMigrationStatus() { + for (Task task : tasksResource.getAllTasks() ) { + if (task.getType() == TASK_TYPE.BRICK_MIGRATE && ((MigrateBrickTask) task).getAutoCommit()) { + tasksResource.getTaskStatus( task.getId()); + } + } + } +} diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitServerTask.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitServerTask.java index 8e38bd40..3fe794f5 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitServerTask.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/InitServerTask.java @@ -94,7 +94,7 @@ public class InitServerTask extends JdbcDaoSupport { } private void initDatabase() { - logger.debug("Initializing server data..."); + logger.info("Initializing server data..."); executeScriptsFrom(getDirFromRelativePath(SCRIPT_DIR + appVersion)); securePasswords(); // encrypt the passwords @@ -134,7 +134,7 @@ public class InitServerTask extends JdbcDaoSupport { upgradeData(dbVersion, appVersion); } } catch (Exception ex) { - ex.printStackTrace(); + logger.info("No cluster created yet. DB version query failed with error [" + ex.getMessage() + "]", ex); // Database not created yet. Create it! initDatabase(); } @@ -148,7 +148,7 @@ public class InitServerTask extends JdbcDaoSupport { logger.info("Cluster: [" + cluster.getId() + "][" + cluster.getName() + "]"); } } else { - logger.info("No cluster created yet."); + } } 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 4592b759..89c8c20f 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 @@ -38,15 +38,17 @@ public class InitializeDiskTask extends Task { private String serverName; private String diskName; + private String fsType; private SshUtil sshUtil = new SshUtil(); private GlusterUtil glusterUtil; - public InitializeDiskTask(ClusterService clusterService, String clusterName, String serverName, String diskName) { + public InitializeDiskTask(ClusterService clusterService, String clusterName, String serverName, String diskName, String fsType) { super(clusterService, clusterName, TASK_TYPE.DISK_FORMAT, diskName, "Initialize disk " + serverName + ":" + diskName, false, false, false); setServerName(serverName); setDiskName(diskName); + setFsType(fsType); } public InitializeDiskTask(ClusterService clusterService, String clusterName, TaskInfo info) { @@ -106,9 +108,17 @@ public class InitializeDiskTask extends Task { } private void startInitializeDisk(String serverName) { - ProcessResult processResult = sshUtil.executeRemote(serverName, INITIALIZE_DISK_SCRIPT + " " + getDiskName()); + ProcessResult processResult = sshUtil.executeRemote(serverName, INITIALIZE_DISK_SCRIPT + " -t " + getFsType() + + " " + 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); + } + return; } @@ -143,4 +153,12 @@ public class InitializeDiskTask extends Task { public String getServerName() { return serverName; } + + public void setFsType(String fsType) { + this.fsType = fsType; + } + + public String getFsType() { + return fsType; + } } diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/MigrateBrickTask.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/MigrateBrickTask.java index 3961c427..9236a6d3 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/MigrateBrickTask.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/MigrateBrickTask.java @@ -20,20 +20,16 @@ */ package com.gluster.storage.management.server.tasks; -import java.util.concurrent.ExecutionException; - -import org.apache.derby.iapi.sql.execute.ExecPreparedStatement; +import org.springframework.context.ApplicationContext; +import org.springframework.web.context.ContextLoader; import com.gluster.storage.management.core.exceptions.ConnectionException; -import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.model.Status; -import com.gluster.storage.management.core.model.TaskInfo; import com.gluster.storage.management.core.model.TaskInfo.TASK_TYPE; import com.gluster.storage.management.core.model.TaskStatus; import com.gluster.storage.management.core.utils.ProcessResult; import com.gluster.storage.management.server.services.ClusterService; import com.gluster.storage.management.server.utils.GlusterUtil; -import com.gluster.storage.management.server.utils.SshUtil; import com.sun.jersey.core.util.Base64; public class MigrateBrickTask extends Task { @@ -43,8 +39,6 @@ public class MigrateBrickTask extends Task { private Boolean autoCommit; private GlusterUtil glusterUtil = new GlusterUtil(); - private SshUtil sshUtil = new SshUtil(); - public String getFromBrick() { return fromBrick; } @@ -78,10 +72,6 @@ public class MigrateBrickTask extends Task { taskInfo.setName(getId()); } - public MigrateBrickTask(ClusterService clusterService, String clusterName, TaskInfo info) { - super(clusterService, clusterName, info); - } - @Override public String getId() { return new String(Base64.encode(clusterName + "-" + taskInfo.getType() + "-" + taskInfo.getReference() + "-" + fromBrick + "-" @@ -99,6 +89,8 @@ public class MigrateBrickTask extends Task { } private void startMigration(String onlineServerName) { + ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); + glusterUtil = ctx.getBean(GlusterUtil.class); ProcessResult processResult = glusterUtil.executeBrickMigration(onlineServerName, getTaskInfo().getReference(), getFromBrick(), getToBrick(), "start"); if (processResult.getOutput().trim().matches(".*started successfully$")) { @@ -144,6 +136,19 @@ public class MigrateBrickTask extends Task { commitMigration(getNewOnlineServer().getName()); } } + + private void commitMigration(String serverName) { + ProcessResult processResult = glusterUtil.executeBrickMigration(serverName, getTaskInfo().getReference(), + getFromBrick(), getToBrick(), "commit"); + TaskStatus taskStatus = new TaskStatus(); + if (processResult.isSuccess()) { + if (processResult.getOutput().trim().matches(".*commit successful$")) { + taskStatus.setCode(Status.STATUS_CODE_SUCCESS); + taskStatus.setMessage(processResult.getOutput()); + getTaskInfo().setStatus(taskStatus); + } + } + } @Override public void stop() { @@ -175,30 +180,25 @@ public class MigrateBrickTask extends Task { return checkMigrationStatus(getNewOnlineServer().getName()); } } - - public void commitMigration(String serverName) { - ProcessResult processResult = glusterUtil.executeBrickMigration(serverName, getTaskInfo().getReference(), - getFromBrick(), getToBrick(), "commit"); - TaskStatus taskStatus = new TaskStatus(); - if (processResult.isSuccess()) { - if (processResult.getOutput().trim().matches(".*commit successful$")) { - taskStatus.setCode(Status.STATUS_CODE_SUCCESS); - taskStatus.setMessage(processResult.getOutput()); // Common - getTaskInfo().setStatus(taskStatus); - } - } - } - + private TaskStatus checkMigrationStatus(String serverName) { if (getTaskInfo().getStatus().getCode() == Status.STATUS_CODE_PAUSE) { return getTaskInfo().getStatus(); } + // For committed task, status command (CLI) is invalid, just return current status + if (getTaskInfo().getStatus().getCode() == Status.STATUS_CODE_SUCCESS) { + return getTaskInfo().getStatus(); + } + TaskStatus taskStatus = new TaskStatus(); try { ProcessResult processResult = glusterUtil.executeBrickMigration(serverName, getTaskInfo().getReference(), getFromBrick(), getToBrick(), "status"); - if (processResult.getOutput().trim().matches("^Number of files migrated.*Migration complete$")) { + if (processResult.getOutput().trim().matches("^Number of files migrated.*Migration complete$") + || processResult.getOutput().trim().matches("^Number of files migrated = 0 .*Current file=")) { + // Note: Workaround - if no file in the volume brick to migrate, Gluster CLI is not giving proper + // (complete) status taskStatus.setCode(Status.STATUS_CODE_COMMIT_PENDING); if (autoCommit) { commitMigration(serverName); 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 a24e147c..e614641c 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 @@ -35,6 +35,8 @@ import com.gluster.storage.management.core.model.Brick; import com.gluster.storage.management.core.model.Brick.BRICK_STATUS; import com.gluster.storage.management.core.model.GlusterServer; import com.gluster.storage.management.core.model.GlusterServer.SERVER_STATUS; +import com.gluster.storage.management.core.model.InitDiskStatusResponse; +import com.gluster.storage.management.core.model.InitDiskStatusResponse.FORMAT_STATUS; import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.TaskStatus; import com.gluster.storage.management.core.model.Volume; @@ -76,6 +78,9 @@ public class GlusterUtil { @Autowired private SshUtil sshUtil; + @Autowired + private ServerUtil serverUtil; + @InjectParam private TasksResource taskResource; @@ -574,21 +579,27 @@ public class GlusterUtil { } public TaskStatus checkInitializeDiskStatus(String serverName, String diskName) { - ProcessResult processResult = sshUtil.executeRemote(serverName, INITIALIZE_DISK_STATUS_SCRIPT + " " + diskName); + Object response = serverUtil.executeOnServer(true, serverName, INITIALIZE_DISK_STATUS_SCRIPT + " " + diskName, + InitDiskStatusResponse.class); + TaskStatus taskStatus = new TaskStatus(); - if (processResult.isSuccess()) { - // TODO: Message needs to change according to the script return - if (processResult.getOutput().trim().matches(".*Initailize completed$")) { - taskStatus.setCode(Status.STATUS_CODE_SUCCESS); - } else { - // TODO: Percentage completed needs to be set, according to the script output - taskStatus.setCode(Status.STATUS_CODE_RUNNING); - // taskStatus.setPercentCompleted(processResult.getOutput()); - } - } else { + if (response instanceof Status) { taskStatus.setCode(Status.STATUS_CODE_FAILURE); + taskStatus.setMessage(((Status) response).getMessage()); + throw new GlusterRuntimeException(((Status) response).getMessage()); } - taskStatus.setMessage(processResult.getOutput()); + + InitDiskStatusResponse initDiskStatusResponse = (InitDiskStatusResponse) response; + + if (initDiskStatusResponse.getStatus() == FORMAT_STATUS.COMPLETED) { + taskStatus.setCode(Status.STATUS_CODE_SUCCESS); + } else if (initDiskStatusResponse.getStatus() == FORMAT_STATUS.IN_PROGRESS) { + taskStatus.setCode(Status.STATUS_CODE_RUNNING); + taskStatus.setPercentCompleted(Math.round(initDiskStatusResponse.getCompletedBlocks() + / initDiskStatusResponse.getTotalBlocks() * 100)); + } + + taskStatus.setMessage(initDiskStatusResponse.getMessage()); return taskStatus; } diff --git a/src/com.gluster.storage.management.server/src/spring/gluster-server-base.xml b/src/com.gluster.storage.management.server/src/spring/gluster-server-base.xml index 700d996f..b9fb2126 100644 --- a/src/com.gluster.storage.management.server/src/spring/gluster-server-base.xml +++ b/src/com.gluster.storage.management.server/src/spring/gluster-server-base.xml @@ -16,6 +16,12 @@ <task:scheduled ref="serverDiscoveryTask" method="discoverServers" fixed-delay="60000" /> </task:scheduled-tasks> + <!-- This task keeps checking status of disk migration tasks (wherever auto-commit is set to true) + so that auto-commit can be performed as soon as the migration is complete --> + <task:scheduled-tasks> + <task:scheduled ref="brickMigrationStatusTask" method="checkMigrationStatus" fixed-delay="60000" /> + </task:scheduled-tasks> + <!-- Cluster environment. Valid values: vmware, aws, baremetal --> <bean id="environment" class="java.lang.String"> <constructor-arg value="vmware" /> diff --git a/src/com.gluster.storage.management.server/src/spring/gluster-server-security.xml b/src/com.gluster.storage.management.server/src/spring/gluster-server-security.xml index c8301c7b..6f3ad72f 100644 --- a/src/com.gluster.storage.management.server/src/spring/gluster-server-security.xml +++ b/src/com.gluster.storage.management.server/src/spring/gluster-server-security.xml @@ -11,15 +11,13 @@ "> <http auto-config="true" use-expressions="true"> - <!-- intercept-url pattern="/resources/*" + <!-- intercept-url pattern="/1.0/*" access="hasRole('ROLE_ADMIN') and fullyAuthenticated" /> <intercept-url pattern="/*" access="permitAll" /--> <!-- SSL Protection --> - <intercept-url pattern="/1.0/*" access="hasRole('ROLE_ADMIN') - and fullyAuthenticated" - requires-channel="https" /> - <intercept-url pattern="/*" access="permitAll" requires-channel="any" /> + <intercept-url pattern="/*" access="hasRole('ROLE_ADMIN') and fullyAuthenticated" requires-channel="https" /> + <!-- intercept-url pattern="/*" access="permitAll" requires-channel="any" /--> <port-mappings> <port-mapping http="8080" https="8443" /> </port-mappings> |
