diff options
author | Shireesh Anjal <shireesh@gluster.com> | 2011-08-04 21:11:42 +0530 |
---|---|---|
committer | Shireesh Anjal <shireesh@gluster.com> | 2011-08-04 21:12:21 +0530 |
commit | e655257be1ce29eaecd64783f5139222a6209c6d (patch) | |
tree | 6db9cbfd66d6976ce943f394ada24f6e2e3aeeec | |
parent | 4c71d851c5d773375c6a67cdcf4c3f03a207bedb (diff) |
Fixed Bug 3284 - Landing page throws null pointer exception
4 files changed, 87 insertions, 17 deletions
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 e5624954..e59d53e6 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 @@ -132,6 +132,74 @@ public class GlusterCoreUtil { } } } - // TODO: do the same for raid disks and/or partitions whenever we start supporting them + } + + /** + * Skips (removes) the entities from given list till (including) the given {@code tillServer}, upto a maximum of + * {@code maxCount} entities<br> + * + * @param entities + * List of entities to be pruned + * @param maxCount + * Maximum number of entities to be returned + * @param tillEntity + * A list of entities after skipping the ones appearing before, and including {@code tillEntity}. If the + * resulting list is bigger than {@code maxCount}, then the first {@code maxCount} number of entities + * will be returned. + */ + public static <T extends Entity> List<T> skipEntities(List<T> entities, Integer maxCount, String tillEntity) { + List<T> servers = skipEntitiesTill(entities, tillEntity); + return skipEntitiesByMaxCount(servers, maxCount); + } + + /** + * Removes extra entities from given list to return the first (or maximum of) {@code maxCount} entities<br> + * + * @param entities + * List of entities to be pruned + * @param maxCount + * Maximum number of entities to be returned + * @param tillEntity + * the first (or a maximum of) {@code maxCount} entities from the given list + */ + public static <T extends Entity> List<T> skipEntitiesByMaxCount(List<T> entities, Integer maxCount) { + if(maxCount == null || maxCount <= 0 || maxCount > entities.size()) { + return entities; + } + + return entities.subList(0, maxCount - 1); + } + + /** + * Skips (removes) the entities from given list till (including) the given entity. <br> + * + * @param entities + * List of entities to be pruned + * @param tillEntity + * A list of entities after skipping the ones appearing before, and including {@code tillEntity} + */ + public static <T extends Entity> List<T> skipEntitiesTill(List<T> entities, String tillEntity) { + if(tillEntity == null) { + return entities; + } + + int index = indexOfEntity(entities, tillEntity); + if(index != -1) { + return entities.subList(index + 1, entities.size()-1); + } + + // given entity not found. return the input list as it is. + return entities; + } + + public static <T extends Entity> int indexOfEntity(List<T> entities, String entityName) { + int index = -1; + for(int i = 0; i < entities.size(); i++) { + if(entities.get(i).getName().equalsIgnoreCase(entityName)) { + index = i; + break; + } + } + return index; } } diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java index 45c06b99..cbb8043f 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java @@ -27,8 +27,10 @@ import com.gluster.storage.management.core.constants.CoreConstants; import com.gluster.storage.management.core.exceptions.ConnectionException; import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.exceptions.GlusterValidationException; +import com.gluster.storage.management.core.model.Entity; import com.gluster.storage.management.core.model.GlusterServer; import com.gluster.storage.management.core.model.Server.SERVER_STATUS; +import com.gluster.storage.management.core.utils.GlusterCoreUtil; import com.gluster.storage.management.gateway.data.ClusterInfo; import com.gluster.storage.management.gateway.utils.GlusterUtil; import com.gluster.storage.management.gateway.utils.ServerUtil; @@ -66,22 +68,24 @@ public class GlusterServerService { } try { - glusterServers = getGlusterServers(clusterName, onlineServer, fetchDetails); + glusterServers = getGlusterServers(clusterName, onlineServer, fetchDetails, maxCount, previousServerName); } catch (ConnectionException e) { // online server has gone offline! try with a different one. onlineServer = clusterService.getNewOnlineServer(clusterName); if (onlineServer == null) { throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]"); } - glusterServers = getGlusterServers(clusterName, onlineServer, fetchDetails); + glusterServers = getGlusterServers(clusterName, onlineServer, fetchDetails, maxCount, previousServerName); } return glusterServers; } - private List<GlusterServer> getGlusterServers(String clusterName, GlusterServer onlineServer, boolean fetchDetails) { + private List<GlusterServer> getGlusterServers(String clusterName, GlusterServer onlineServer, boolean fetchDetails, + Integer maxCount, String previousServerName) { List<GlusterServer> glusterServers; try { glusterServers = glusterUtil.getGlusterServers(onlineServer); + return GlusterCoreUtil.skipEntities(glusterServers, maxCount, previousServerName); } catch (ConnectionException e) { // online server has gone offline! try with a different one. onlineServer = clusterService.getNewOnlineServer(clusterName); @@ -100,7 +104,7 @@ public class GlusterServerService { } return glusterServers; } - + private String fetchDetailsOfServers(List<GlusterServer> glusterServers, GlusterServer onlineServer) { String errMsg = ""; diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java index b6a0daa5..1c46064b 100644 --- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java +++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java @@ -115,8 +115,8 @@ public class ServerUtil { * as it will be automatically identified by the method. * @param expectedClass * Class of the object expected from script execution - * @return Object of the expected class from remote execution of the command. In case the remote execution fails - * ungracefully, an object of class {@link Status} will be returned. + * @return Object of the expected class from remote execution of the command. + * @throws GlusterRuntimeException in case the remote execution fails. */ public <T> T executeScriptOnServer(boolean runInForeground, String serverName, String scriptWithArgs, Class<T> expectedClass) { diff --git a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java index 37269711..5d44881d 100644 --- a/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java +++ b/src/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/ClusterSummaryView.java @@ -312,6 +312,14 @@ public class ClusterSummaryView extends ViewPart { private void createSections(Composite parent) { form = guiHelper.setupForm(parent, toolkit, "Cluster Summary"); + if (cluster.getServers().size() > 0 + && (cluster.getAggregatedCpuStats().getRows() == null || cluster.getAggregatedNetworkStats().getRows() == null)) { + // cluster has servers, but stats are null. Happens when user logs in to a new cluster, ' + // and then adds the first server. + GlusterDataModelManager.getInstance().initializeAggregatedCpuStats(cluster); + GlusterDataModelManager.getInstance().initializeAggregatedNetworkStats(cluster); + } + createServersSection(); createDiskSpaceSection(); createCPUUsageSection(); @@ -332,16 +340,6 @@ public class ClusterSummaryView extends ViewPart { } ChartUtil.getInstance().createAreaChart(toolkit, section, stats, dataColumnIndex, unit, timestampFormat, listener, maxValue, chartLinkColumnCount); - -// Calendar[] timestamps = new Calendar[] { new CDateTime(1000l*1310468100), new CDateTime(1000l*1310468400), new CDateTime(1000l*1310468700), -// new CDateTime(1000l*1310469000), new CDateTime(1000l*1310469300), new CDateTime(1000l*1310469600), new CDateTime(1000l*1310469900), -// new CDateTime(1000l*1310470200), new CDateTime(1000l*1310470500), new CDateTime(1000l*1310470800), new CDateTime(1000l*1310471100), -// new CDateTime(1000l*1310471400), new CDateTime(1000l*1310471700), new CDateTime(1000l*1310472000), new CDateTime(1000l*1310472300), -// new CDateTime(1000l*1310472600), new CDateTime(1000l*1310472900), new CDateTime(1000l*1310473200), new CDateTime(1000l*1310473500), -// new CDateTime(1000l*1310473800) }; -// -// Double[] values = new Double[] { 10d, 11.23d, 17.92d, 18.69d, 78.62d, 89.11d, 92.43d, 89.31d, 57.39d, 18.46d, 10.44d, 16.28d, 13.51d, 17.53d, 12.21, 20d, 21.43d, 16.45d, 14.86d, 15.27d }; -// createLineChart(section, timestamps, values, "%"); return section; } |