<%-- - $RCSfile$ - $Revision: $ - $Date: 2007-09-21 $ - - Copyright (C) 2005-2008 Jive Software. All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ page import="org.jivesoftware.database.DbConnectionManager" errorPage="error.jsp" %> <%@ page import="org.jivesoftware.openfire.XMPPServer" %> <%@ page import="org.jivesoftware.openfire.cluster.ClusterManager" %> <%@ page import="org.jivesoftware.openfire.cluster.ClusterNodeInfo" %> <%@ page import="org.jivesoftware.openfire.cluster.GetBasicStatistics" %> <%@ page import="org.jivesoftware.util.JiveGlobals" %> <%@ page import="org.jivesoftware.util.Log" %> <%@ page import="org.jivesoftware.util.ParamUtils" %> <%@ page import="org.jivesoftware.util.cache.CacheFactory" %> <%@ page import="java.text.DecimalFormat" %> <%@ page import="java.util.Arrays" %> <%@ page import="java.util.Collection" %> <%@ page import="java.util.Date" %> <%@ page import="java.util.Map" %> <%@ page import="org.jivesoftware.util.Base64" %> <% webManager.init(request, response, session, application, out ); %> <fmt:message key="system.clustering.title"/> <% // Get parameters boolean update = request.getParameter("update") != null; boolean clusteringEnabled = ParamUtils.getBooleanParameter(request, "clusteringEnabled"); boolean updateSucess = false; if (update) { if (!clusteringEnabled) { ClusterManager.setClusteringEnabled(false); // Log the event webManager.logEvent("disabled clustering", null); updateSucess = true; } else { if (ClusterManager.isClusteringAvailable()) { ClusterManager.setClusteringEnabled(true); // Log the event webManager.logEvent("enabled clustering", null); updateSucess = ClusterManager.isClusteringStarted(); } else { Log.error("Failed to enable clustering. Clustering is not installed."); } } } boolean usingEmbeddedDB = DbConnectionManager.isEmbeddedDB(); boolean clusteringAvailable = !usingEmbeddedDB && ClusterManager.isClusteringAvailable(); boolean clusteringStarting = ClusterManager.isClusteringStarting(); int maxClusterNodes = ClusterManager.getMaxClusterNodes(); clusteringEnabled = ClusterManager.isClusteringStarted() || ClusterManager.isClusteringStarting(); Collection clusterNodesInfo = ClusterManager.getNodesInfo(); // Get some basic statistics from the cluster nodes // TODO Set a timeout so the page can load fast even if a node is taking too long to answer Collection statistics = CacheFactory.doSynchronousClusterTask(new GetBasicStatistics(), true); // Calculate percentages int clients = 0; int incoming = 0; int outgoing = 0; for (Object stat : statistics) { Map statsMap = (Map) stat; if (statsMap == null) { continue; } clients += (Integer) statsMap.get(GetBasicStatistics.CLIENT); incoming += (Integer) statsMap.get(GetBasicStatistics.INCOMING); outgoing += (Integer) statsMap.get(GetBasicStatistics.OUTGOING); } for (Object stat : statistics) { Map statsMap = (Map) stat; if (statsMap == null) { continue; } int current = (Integer) statsMap.get(GetBasicStatistics.CLIENT); int percentage = clients == 0 ? 0 : current * 100 / clients; statsMap.put(GetBasicStatistics.CLIENT, current + " (" + Math.round(percentage) + "%)"); current = (Integer) statsMap.get(GetBasicStatistics.INCOMING); percentage = incoming == 0 ? 0 : current * 100 / incoming; statsMap.put(GetBasicStatistics.INCOMING, current + " (" + Math.round(percentage) + "%)"); current = (Integer) statsMap.get(GetBasicStatistics.OUTGOING); percentage = outgoing == 0 ? 0 : current * 100 / outgoing; statsMap.put(GetBasicStatistics.OUTGOING, current + " (" + Math.round(percentage) + "%)"); } %>

<% if (update) { if (updateSucess) { %>
<% if (ClusterManager.isClusteringStarted()) { %> <% } else { %> <% } %>

<% } else { %>

<% } } else if (!clusteringAvailable) { %>


<% if (usingEmbeddedDB) { %> <% } else if (maxClusterNodes == 0) { %> <% } else { %> <% } %>

<% } %>
<%= (!clusteringAvailable || clusteringStarting ? "disabled" : "") %>>
<%= (!clusteringAvailable || clusteringStarting ? "disabled" : "") %>>

<% if (clusteringAvailable && !clusteringStarting) { %> "> <% } %>

" %>" /> " %>" />

<% if (!clusterNodesInfo.isEmpty()) { for (ClusterNodeInfo nodeInfo : clusterNodesInfo) { boolean isLocalMember = XMPPServer.getInstance().getNodeID().equals(nodeInfo.getNodeID()); String nodeID = Base64.encodeBytes(nodeInfo.getNodeID().toByteArray(), Base64.URL_SAFE); Map nodeStats = null; for (Object stat : statistics) { Map statsMap = (Map) stat; if (statsMap == null) { continue; } if (Arrays.equals((byte[]) statsMap.get(GetBasicStatistics.NODE), nodeInfo.getNodeID().toByteArray())) { nodeStats = statsMap; break; } } %> " valign="middle"> <% } } else if (clusteringStarting) { %> <% } %>
 
<% if (isLocalMember) { %> <%= nodeInfo.getHostName() %> <% } else { %> <%= nodeInfo.getHostName() %> <% } %> <%= JiveGlobals.formatDateTime(new Date(nodeInfo.getJoinedTime())) %> <%= nodeStats != null ? nodeStats.get(GetBasicStatistics.CLIENT) : "N/A" %> <%= nodeStats != null ? nodeStats.get(GetBasicStatistics.INCOMING) : "N/A" %> <%= nodeStats != null ? nodeStats.get(GetBasicStatistics.OUTGOING) : "N/A" %> <% int percent = 0; String memory = "N/A"; if (nodeStats != null) { double usedMemory = (Double) nodeStats.get(GetBasicStatistics.MEMORY_CURRENT); double maxMemory = (Double) nodeStats.get(GetBasicStatistics.MEMORY_MAX); double percentFree = ((maxMemory - usedMemory) / maxMemory) * 100.0; percent = 100-(int)Math.round(percentFree); DecimalFormat mbFormat = new DecimalFormat("#0.00"); memory = mbFormat.format(usedMemory) + " MB of " + mbFormat.format(maxMemory) + " MB used"; } %>
<% if (percent == 0) { %> <% } else { %> <% if (percent >= 90) { %> <% } else { %> <% } %> <% } %>
<%= memory %>
 
" %>" /> " %>" />