diff options
| author | Dhandapani <dhandapani@gluster.com> | 2011-07-07 17:53:46 +0530 |
|---|---|---|
| committer | Dhandapani <dhandapani@gluster.com> | 2011-07-07 17:55:56 +0530 |
| commit | 7bc61b55432a68bc0845fcfab19f20f18822629a (patch) | |
| tree | 7503e711fc312c5f615668f74357c99a843daf94 /src/com.gluster.storage.management.core | |
| parent | 33795a983d4196d208faa9a376e85a61dcf80688 (diff) | |
Disk data model change
Diffstat (limited to 'src/com.gluster.storage.management.core')
5 files changed, 303 insertions, 98 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Device.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Device.java new file mode 100644 index 00000000..90f319bb --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Device.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * 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 java.io.File; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlTransient; + +import com.gluster.storage.management.core.utils.StringUtil; + + +/** + * + */ +public class Device extends Entity { + public enum DEVICE_STATUS { + INITIALIZED, UNINITIALIZED, INITIALIZING, IO_ERROR + }; + + public enum DEVICE_TYPE { + DATA, BOOT, SWAP, UNKNOWN + }; + + private static final String[] DEVICE_STATUS_STR = { "Initialized", "Uninitialized", "Initializing", "I/O Error" }; + private static final String[] DEVICE_TYPE_STR = { "Data", "Boot", "Swap", "Unknown" }; + + // type = data, boot, other + private DEVICE_TYPE type; + + private String fsType; + private String fsVersion; + + private String serverName; + private String mountPoint; + + private Double space; + private Double spaceInUse; + private DEVICE_STATUS status; + + public Device() { + } + + public Device(Server server, String name, String mountPoint, Double space, Double spaceInUse, DEVICE_STATUS status) { + super(name, server); + setServerName(server != null ? server.getName() : ""); + setMountPoint(mountPoint); + setSpace(space); + setSpaceInUse(spaceInUse); + setStatus(status); + } + + @XmlElement(name="size") + public Double getSpace() { + return space; + } + + public Double getFreeSpace() { + return getSpace() - getSpaceInUse(); + } + + public void setSpace(Double space) { + this.space = space; + } + + public boolean isUninitialized() { + return getStatus() == DEVICE_STATUS.UNINITIALIZED; + } + + public boolean hasErrors() { + return getStatus() == DEVICE_STATUS.IO_ERROR; + } + + public boolean isReady() { + // TODO: Check if status is INITIALIZED AND type = DATA + return getStatus() == DEVICE_STATUS.INITIALIZED; + } + + public DEVICE_STATUS getStatus() { + return status; + } + + public String getStatusStr() { + if(isReady()) { + return "Available"; + } + return DEVICE_STATUS_STR[getStatus().ordinal()]; + } + + public void setStatus(DEVICE_STATUS status) { + this.status = status; + } + + public Double getSpaceInUse() { + return spaceInUse; + } + + public void setSpaceInUse(Double spaceInUse) { + this.spaceInUse = spaceInUse; + } + + @XmlTransient + public String getServerName() { + return serverName; + } + + public void setServerName(String serverName) { + this.serverName = serverName; + } + + public void setMountPoint(String mountPoint) { + this.mountPoint = mountPoint; + } + + public String getMountPoint() { + return mountPoint; + } + + public DEVICE_TYPE getType() { + return type; + } + + public String getTypeStr() { + return DEVICE_TYPE_STR[type.ordinal()]; + } + + public void setType(DEVICE_TYPE diskType) { + this.type = diskType; + } + + public String getFsType() { + return fsType; + } + + public void setFsType(String fsType) { + this.fsType = fsType; + } + + public String getFsVersion() { + return fsVersion; + } + + public void setFsVersion(String fsVersion) { + this.fsVersion = fsVersion; + } + + @Override + public boolean filter(String filterString, boolean caseSensitive) { + return StringUtil.filterString(getServerName() + getName() + getStatusStr() + getSpace() + getFreeSpace() + + getType(), filterString, caseSensitive); + } + + public String getQualifiedName() { + return getServerName() + ":" + getName(); + } + + public String getQualifiedBrickName(String volumeName) { + return getServerName() + ":" + getMountPoint() + File.separator + volumeName; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof Device)) { + return false; + } + + Device disk = (Device)obj; + + if (getName().equals(disk.getName()) && getServerName().equals(disk.getServerName()) + && getMountPoint().equals(disk.getMountPoint()) && getStatus() == disk.getStatus() + && getSpace() == disk.getSpace() && getSpaceInUse() == disk.getSpaceInUse() + && getFsType().equals(disk.getFsType()) && getFsVersion().equals(disk.getFsVersion())) { + return true; + } + + return false; + } +} diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Disk.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Disk.java index d862df28..e623f3d6 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Disk.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Disk.java @@ -18,120 +18,70 @@ *******************************************************************************/ package com.gluster.storage.management.core.model; -import java.io.File; +import java.util.Collection; +import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import com.gluster.storage.management.core.utils.GlusterCoreUtil; import com.gluster.storage.management.core.utils.StringUtil; @XmlRootElement(name="Disk") -public class Disk extends Entity { - public enum DISK_STATUS { - AVAILABLE, UNINITIALIZED, INITIALIZING, IO_ERROR - }; - - private String[] DISK_STATUS_STR = { "Available", "Uninitialized", "Initializing", "I/O Error" }; - - private String serverName; - private String mountPoint; +public class Disk extends Device { private String description; - private Double space; - private Double spaceInUse; - private DISK_STATUS status; - - public Disk() { - - } - public Double getSpace() { - return space; - } + // interface = pci, raid0, raid3, etc + private String diskInterface; - public Double getFreeSpace() { - return getSpace() - getSpaceInUse(); - } - - public void setSpace(Double space) { - this.space = space; - } + private Collection<Partition> partitions; - public boolean isUninitialized() { - return true; -// return getStatus() == DISK_STATUS.UNINITIALIZED; - } - - public boolean hasErrors() { - return getStatus() == DISK_STATUS.IO_ERROR; - } - - public boolean isReady() { - return getStatus() == DISK_STATUS.AVAILABLE; - } - - public DISK_STATUS getStatus() { - return status; - } - - public String getStatusStr() { - return DISK_STATUS_STR[getStatus().ordinal()]; - } + // In case of a software raid, the disk will contain an array of other disks + private Collection<Disk> raidDisks; - public void setStatus(DISK_STATUS status) { - this.status = status; + public Disk() { } - public Double getSpaceInUse() { - return spaceInUse; + public void setDescription(String description) { + this.description = description; } - public void setSpaceInUse(Double spaceInUse) { - this.spaceInUse = spaceInUse; + public String getDescription() { + return description; } - public String getServerName() { - return serverName; + @XmlElement(name="interface") + public String getDiskInterface() { + return diskInterface; } - public void setServerName(String serverName) { - this.serverName = serverName; + public void setDiskInterface(String diskInterface) { + this.diskInterface = diskInterface; } - public void setMountPoint(String mountPoint) { - this.mountPoint = mountPoint; + public Collection<Disk> getRaidDisks() { + return raidDisks; } - public String getMountPoint() { - return mountPoint; + public void setRaidDisks(Collection<Disk> raidDisks) { + this.raidDisks = raidDisks; } - public void setDescription(String description) { - this.description = description; + public void setPartitions(Collection<Partition> partitions) { + this.partitions = partitions; } - public String getDescription() { - return description; + public Collection<Partition> getPartitions() { + return partitions; } - public Disk(Server server, String name, String mountPoint, Double space, Double spaceInUse, DISK_STATUS status) { - super(name, server); - setServerName(server != null ? server.getName() : ""); - setMountPoint(mountPoint); - setSpace(space); - setSpaceInUse(spaceInUse); - setStatus(status); + public Disk(Server server, String name, String mountPoint, Double space, Double spaceInUse, DEVICE_STATUS status) { + super(server, name, mountPoint, space, spaceInUse, status); } @Override public boolean filter(String filterString, boolean caseSensitive) { - return StringUtil.filterString(getServerName() + getName() + getStatusStr(), filterString, caseSensitive); - } - - public String getQualifiedName() { - return getServerName() + ":" + getName(); - } - - public String getQualifiedBrickName(String volumeName) { - return getServerName() + ":" + getMountPoint() + File.separator + volumeName; + return StringUtil.filterString(getServerName() + getName() + getStatusStr() + getSpace() + getFreeSpace() + + getType() + getDescription(), filterString, caseSensitive); } @Override @@ -141,13 +91,25 @@ public class Disk extends Entity { } Disk disk = (Disk)obj; - if (getName().equals(disk.getName()) && getServerName().equals(disk.getServerName()) - && getMountPoint().equals(disk.getMountPoint()) && getDescription().equals(disk.getDescription()) - && getStatus() == disk.getStatus() && getSpace() == disk.getSpace() - && getSpaceInUse() == disk.getSpaceInUse()) { - return true; + if (!(super.equals(obj) && getDescription().equals(disk.getDescription()) && getDiskInterface().equals( + disk.getDiskInterface()))) { + return false; } + for(Disk raidDisk : raidDisks) { + // check if the disk contains same raid disks + if (!(raidDisk.equals(GlusterCoreUtil.getEntity(disk.getRaidDisks(), raidDisk.getName(), false)))) { + return false; + } + } + + // check if the disk contains same partitions + for (Partition partition : partitions) { + if (!(partition.equals(GlusterCoreUtil.getEntity(disk.getPartitions(), partition.getName(), false)))) { + return false; + } + } + return false; } diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/GlusterDummyModel.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/GlusterDummyModel.java index f2ccc5db..22681919 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/GlusterDummyModel.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/GlusterDummyModel.java @@ -23,7 +23,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; -import com.gluster.storage.management.core.model.Disk.DISK_STATUS; +import com.gluster.storage.management.core.model.Device.DEVICE_STATUS; import com.gluster.storage.management.core.model.GlusterServer.SERVER_STATUS; import com.gluster.storage.management.core.model.Volume.TRANSPORT_TYPE; import com.gluster.storage.management.core.model.Volume.VOLUME_STATUS; @@ -72,7 +72,7 @@ public class GlusterDummyModel { private void addDiscoveredServer(List<Server> servers, Entity parent, String name, int numOfCPUs, double cpuUsage, double totalMemory, double memoryInUse, double totalDiskSpace, double diskSpaceInUse) { Server server = new Server(name, parent, numOfCPUs, cpuUsage, totalMemory, memoryInUse); - server.addDisk(new Disk(server, "sda", "/export/md0", totalDiskSpace, diskSpaceInUse, DISK_STATUS.AVAILABLE)); + server.addDisk(new Disk(server, "sda", "/export/md0", totalDiskSpace, diskSpaceInUse, DEVICE_STATUS.INITIALIZED)); addNetworkInterface(server, "eth0"); servers.add(server); @@ -138,18 +138,18 @@ public class GlusterDummyModel { } private void initializeDisks() { - s1da = new Disk(server1, "sda", "/export/md0", 100d, 80d, DISK_STATUS.AVAILABLE); - s1db = new Disk(server1, "sdb", "/export/md1", 100d, 67.83, DISK_STATUS.AVAILABLE); + s1da = new Disk(server1, "sda", "/export/md0", 100d, 80d, DEVICE_STATUS.INITIALIZED); + s1db = new Disk(server1, "sdb", "/export/md1", 100d, 67.83, DEVICE_STATUS.INITIALIZED); - s2da = new Disk(server2, "sda", "/export/md0", 200d, 157.12, DISK_STATUS.AVAILABLE); - s2db = new Disk(server2, "sdb", "/export/md1", 200d, 182.27, DISK_STATUS.AVAILABLE); - s2dc = new Disk(server2, "sdc", "/export/md0", 200d, -1d, DISK_STATUS.UNINITIALIZED); - s2dd = new Disk(server2, "sdd", "/export/md1", 200d, 124.89, DISK_STATUS.AVAILABLE); + s2da = new Disk(server2, "sda", "/export/md0", 200d, 157.12, DEVICE_STATUS.INITIALIZED); + s2db = new Disk(server2, "sdb", "/export/md1", 200d, 182.27, DEVICE_STATUS.INITIALIZED); + s2dc = new Disk(server2, "sdc", "/export/md0", 200d, -1d, DEVICE_STATUS.UNINITIALIZED); + s2dd = new Disk(server2, "sdd", "/export/md1", 200d, 124.89, DEVICE_STATUS.INITIALIZED); - s4da = new Disk(server4, "sda", "/export/md0", 100d, 85.39, DISK_STATUS.AVAILABLE); + s4da = new Disk(server4, "sda", "/export/md0", 100d, 85.39, DEVICE_STATUS.INITIALIZED); - s5da = new Disk(server5, "sda", "/export/md1", 100d, 92.83, DISK_STATUS.AVAILABLE); - s5db = new Disk(server5, "sdb", "/export/md1", 200d, 185.69, DISK_STATUS.AVAILABLE); + s5da = new Disk(server5, "sda", "/export/md1", 100d, 92.83, DEVICE_STATUS.INITIALIZED); + s5db = new Disk(server5, "sdb", "/export/md1", 200d, 185.69, DEVICE_STATUS.INITIALIZED); } private void addDisksToServers() { diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Partition.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Partition.java new file mode 100644 index 00000000..a06b1e1c --- /dev/null +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/model/Partition.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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; + +/** + * + */ +public class Partition extends Device { + +} diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java index 838612be..7b1eec36 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java @@ -21,6 +21,7 @@ package com.gluster.storage.management.core.utils; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -30,6 +31,8 @@ import java.util.Set; import com.gluster.storage.management.core.model.Brick; import com.gluster.storage.management.core.model.Disk; import com.gluster.storage.management.core.model.Entity; +import com.gluster.storage.management.core.model.Partition; +import com.gluster.storage.management.core.model.Server; public class GlusterCoreUtil { @@ -95,7 +98,7 @@ public class GlusterCoreUtil { return getEntity(entityList, searchEntity.getName(), caseInsensitive) != null; } - public static <T extends Entity> T getEntity(List<T> entityList, String searchEntityName, boolean caseInsensitive) { + public static <T extends Entity> T getEntity(Collection<T> entityList, String searchEntityName, boolean caseInsensitive) { if (caseInsensitive) { searchEntityName = searchEntityName.toUpperCase(); } @@ -112,4 +115,24 @@ public class GlusterCoreUtil { return null; } + + public static void updateServerNameOnDevices(Server server) { + String serverName = server.getName(); + for(Disk disk : server.getDisks()) { + disk.setServerName(serverName); + + if (disk.getRaidDisks() != null) { + for (Disk raidDisk : disk.getRaidDisks()) { + raidDisk.setServerName(serverName); + } + } + + if (disk.getPartitions() != null) { + for (Partition partition : disk.getPartitions()) { + partition.setServerName(serverName); + } + } + } + // TODO: do the same for raid disks and/or partitions whenever we start supporting them + } } |
