system-clustering.jsp 16.1 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1 2 3 4 5
<%--
  -	$RCSfile$
  -	$Revision: $
  -	$Date: 2007-09-21 $
  -
6
  - Copyright (C) 2005-2008 Jive Software. All rights reserved.
Gaston Dombiak's avatar
Gaston Dombiak committed
7
  -
8 9 10 11 12 13 14 15 16 17 18
  - 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.
Gaston Dombiak's avatar
Gaston Dombiak committed
19 20
--%>

21 22
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
23

24
<%@ page import="org.jivesoftware.database.DbConnectionManager"
Gaston Dombiak's avatar
Gaston Dombiak committed
25 26
    errorPage="error.jsp"
%>
27
<%@ page import="org.jivesoftware.openfire.XMPPServer" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
28 29 30 31
<%@ 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" %>
32
<%@ page import="org.jivesoftware.util.Log" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
33 34 35 36 37 38 39
<%@ 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" %>
Sven Tantau's avatar
Sven Tantau committed
40
<%@ page import="java.net.URLEncoder" %>
41
<%@ page import="org.jivesoftware.util.Base64" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
42

43 44 45
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<% webManager.init(request, response, session, application, out ); %>

Gaston Dombiak's avatar
Gaston Dombiak committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
<html>
<head>
<title><fmt:message key="system.clustering.title"/></title>
<meta name="pageID" content="system-clustering"/>
<style type="text/css">
.jive-contentBox .local {
    background-color: #ffc;
    }
</style>
</head>
<body>

<% // Get parameters
    boolean update = request.getParameter("update") != null;
    boolean clusteringEnabled = ParamUtils.getBooleanParameter(request, "clusteringEnabled");
    boolean updateSucess = false;

    if (update) {
        if (!clusteringEnabled) {
            ClusterManager.setClusteringEnabled(false);
66 67
            // Log the event
            webManager.logEvent("disabled clustering", null);
Gaston Dombiak's avatar
Gaston Dombiak committed
68
            updateSucess = true;
69 70
        }
        else {
Gaston Dombiak's avatar
Gaston Dombiak committed
71 72
            if (ClusterManager.isClusteringAvailable()) {
                ClusterManager.setClusteringEnabled(true);
73 74
                // Log the event
                webManager.logEvent("enabled clustering", null);
Gaston Dombiak's avatar
Gaston Dombiak committed
75
                updateSucess = ClusterManager.isClusteringStarted();
76 77
            }
            else {
Gaston Dombiak's avatar
Gaston Dombiak committed
78 79
                Log.error("Failed to enable clustering. Clustering is not installed.");
            }
Gaston Dombiak's avatar
Gaston Dombiak committed
80 81 82
        }
    }

83
    boolean usingEmbeddedDB = DbConnectionManager.isEmbeddedDB();
84
    boolean clusteringAvailable = !usingEmbeddedDB && ClusterManager.isClusteringAvailable();
Gaston Dombiak's avatar
Gaston Dombiak committed
85 86
    int maxClusterNodes = ClusterManager.getMaxClusterNodes();
    clusteringEnabled = ClusterManager.isClusteringStarted() || ClusterManager.isClusteringStarting();
Gaston Dombiak's avatar
Gaston Dombiak committed
87 88 89 90

    Collection<ClusterNodeInfo> 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
Gaston Dombiak's avatar
Gaston Dombiak committed
91 92
    Collection<Object> statistics =
            CacheFactory.doSynchronousClusterTask(new GetBasicStatistics(), true);
Gaston Dombiak's avatar
Gaston Dombiak committed
93 94 95 96 97 98
    // Calculate percentages
    int clients = 0;
    int incoming = 0;
    int outgoing = 0;
    for (Object stat : statistics) {
        Map<String, Object> statsMap = (Map<String, Object>) stat;
Gaston Dombiak's avatar
Gaston Dombiak committed
99 100 101
        if (statsMap == null) {
            continue;
        }
Gaston Dombiak's avatar
Gaston Dombiak committed
102 103 104 105 106 107
        clients += (Integer) statsMap.get(GetBasicStatistics.CLIENT);
        incoming += (Integer) statsMap.get(GetBasicStatistics.INCOMING);
        outgoing += (Integer) statsMap.get(GetBasicStatistics.OUTGOING);
    }
    for (Object stat : statistics) {
        Map<String, Object> statsMap = (Map<String, Object>) stat;
Gaston Dombiak's avatar
Gaston Dombiak committed
108 109 110
        if (statsMap == null) {
            continue;
        }
Gaston Dombiak's avatar
Gaston Dombiak committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
        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) + "%)");
    }
%>

<p>
<fmt:message key="system.clustering.info"/>
</p>

<%  if (update) {
        if (updateSucess) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
133
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0" alt=""></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
        <td class="jive-icon-label">
        <% if (ClusterManager.isClusteringStarted()) { %>
            <fmt:message key="system.clustering.enabled" />
        <% } else { %>
            <fmt:message key="system.clustering.disabled" />
        <%
            }
        %>
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } else { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr>
153
            <td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""/></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
154 155 156 157 158 159 160 161 162
            <td class="jive-icon-label">
                <fmt:message key="system.clustering.failed-start" />
            </td>
        </tr>
    </tbody>
    </table>
    </div>
    <br>
<%  }
Gaston Dombiak's avatar
Gaston Dombiak committed
163
} else if (!clusteringAvailable) {
Gaston Dombiak's avatar
Gaston Dombiak committed
164
%>
Gaston Dombiak's avatar
Gaston Dombiak committed
165 166 167 168 169 170 171 172 173
    <div class="warning">
    <table cellpadding="0" cellspacing="0" border="0" >
    <tbody>
        <tr>
            <td class="jive-icon-label">
            <b><fmt:message key="system.clustering.not-available" /></b><br/><br/>
            </td>
        </tr>
        <td valign="top" align="left" colspan="2">
174 175 176
            <% if (usingEmbeddedDB) { %>
                <span><fmt:message key="system.clustering.using-embedded-db"/></span>
            <% } else if (maxClusterNodes == 0) { %>
Gaston Dombiak's avatar
Gaston Dombiak committed
177 178 179 180 181 182 183 184 185 186
                <span><fmt:message key="system.clustering.not-installed"/></span>
            <% } else { %>
                <span><fmt:message key="system.clustering.not-valid-license"/></span>
            <% } %>
        </td>
    </tbody>
    </table>
    </div>
    <br>
<% } %> 
Gaston Dombiak's avatar
Gaston Dombiak committed
187 188 189 190 191 192 193 194 195 196 197 198

<!-- BEGIN 'Clustering Enabled' -->
<form action="system-clustering.jsp" method="post">
	<div class="jive-contentBoxHeader">
		<fmt:message key="system.clustering.enabled.legend" />
	</div>
	<div class="jive-contentBox">
		<table cellpadding="3" cellspacing="0" border="0">
		<tbody>
			<tr>
				<td width="1%" valign="top" nowrap>
					<input type="radio" name="clusteringEnabled" value="false" id="rb01"
199
					 <%= (!clusteringEnabled ? "checked" : "") %> <%= clusteringAvailable ? "" : "disabled" %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
200 201 202 203 204 205 206 207 208 209
				</td>
				<td width="99%">
					<label for="rb01">
					<b><fmt:message key="system.clustering.label_disable" /></b> - <fmt:message key="system.clustering.label_disable_info" />
					</label>
				</td>
			</tr>
			<tr>
				<td width="1%" valign="top" nowrap>
					<input type="radio" name="clusteringEnabled" value="true" id="rb02"
210
					 <%= (clusteringEnabled ? "checked" : "") %> <%= clusteringAvailable ? "" : "disabled" %>>
Gaston Dombiak's avatar
Gaston Dombiak committed
211 212 213 214 215 216 217 218 219 220
				</td>
				<td width="99%">
					<label for="rb02">
					<b><fmt:message key="system.clustering.label_enable" /></b> - <fmt:message key="system.clustering.label_enable_info" /> <b><fmt:message key="system.clustering.label_enable_info2" /></b> 
					</label>
				</td>
			</tr>
		</tbody>
		</table>
        <br/>
221
        <% if (clusteringAvailable) { %>
Gaston Dombiak's avatar
Gaston Dombiak committed
222 223 224
        <input type="submit" name="update" value="<fmt:message key="global.save_settings" />">
        <% } %>
    </div>
Gaston Dombiak's avatar
Gaston Dombiak committed
225 226 227 228 229 230 231 232 233 234
</form>
<!-- END 'Clustering Enabled' -->
<br>
<div class="jive-contentBoxHeader">
    <fmt:message key="system.clustering.overview.label"/>
</div>
<div class="jive-contentBox">
    <p>
        <fmt:message key="system.clustering.overview.info">
            <fmt:param value="<%= clusterNodesInfo.size() %>" />
Gaston Dombiak's avatar
Gaston Dombiak committed
235
            <fmt:param value="<%= maxClusterNodes %>" />
236 237
            <fmt:param value="<span style='background-color:#ffc;'>" />
            <fmt:param value="</span>" />
Gaston Dombiak's avatar
Gaston Dombiak committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
        </fmt:message>
    </p>

      <table cellpadding="3" cellspacing="2" border="0">
          <thead>
              <tr>
                  <th colspan="2">
                      <fmt:message key="system.clustering.overview.node"/>
                  </th>
                  <th>
                      <fmt:message key="system.clustering.overview.joined"/>
                  </th>
                  <th style="text-align:center;">
                      <fmt:message key="system.clustering.overview.clients"/>
                  </th>
                  <th style="text-align:center;">
                      <fmt:message key="system.clustering.overview.incoming_servers"/>
                  </th>
                  <th style="text-align:center;">
                      <fmt:message key="system.clustering.overview.outgoing_servers"/>
                  </th>
                  <th style="text-align:center;">
                      <fmt:message key="system.clustering.overview.memory"/>
                  </th>
                  <th width="90%" class="last">&nbsp;</th>
              </tr>
          </thead>
          <tbody>
Gaston Dombiak's avatar
Gaston Dombiak committed
266 267
            <% if (!clusterNodesInfo.isEmpty()) {
                for (ClusterNodeInfo nodeInfo : clusterNodesInfo) {
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
                    boolean isLocalMember =
                            XMPPServer.getInstance().getNodeID().equals(nodeInfo.getNodeID());
                    String nodeID = Base64.encodeBytes(nodeInfo.getNodeID().toByteArray(), Base64.URL_SAFE);
                    Map<String, Object> nodeStats = null;
                    for (Object stat : statistics) {
                        Map<String, Object> statsMap = (Map<String, Object>) stat;
                        if (statsMap == null) {
                            continue;
                        }
                        if (Arrays.equals((byte[]) statsMap.get(GetBasicStatistics.NODE),
                                nodeInfo.getNodeID().toByteArray())) {
                            nodeStats = statsMap;
                            break;
                        }
                    }
            %>
Gaston Dombiak's avatar
Gaston Dombiak committed
284
              <tr class="<%= (isLocalMember ? "local" : "") %>" valign="middle">
Gaston Dombiak's avatar
Gaston Dombiak committed
285
                  <td align="center" width="1%">
Sven Tantau's avatar
Sven Tantau committed
286
                      <a href="plugins/<%= CacheFactory.getPluginName() %>/system-clustering-node.jsp?UID=<%= URLEncoder.encode(nodeID) %>"
Gaston Dombiak's avatar
Gaston Dombiak committed
287 288 289 290
                       title="Click for more details"
                       ><img src="images/server-network-24x24.gif" width="24" height="24" border="0" alt=""></a>
                  </td>
                  <td class="jive-description" nowrap width="1%" valign="middle">
Sven Tantau's avatar
Sven Tantau committed
291
                      <a href="plugins/<%= CacheFactory.getPluginName() %>/system-clustering-node.jsp?UID=<%= URLEncoder.encode(nodeID) %>">
Gaston Dombiak's avatar
Gaston Dombiak committed
292 293 294 295 296
                      <%  if (isLocalMember) { %>
                          <b><%= nodeInfo.getHostName() %></b>
                      <%  } else { %>
                          <%= nodeInfo.getHostName() %>
                      <%  } %></a>
297 298
                      <br />
                      <%= nodeInfo.getNodeID() %>
Gaston Dombiak's avatar
Gaston Dombiak committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
                  </td>
                  <td class="jive-description" nowrap width="1%" valign="middle">
                      <%= JiveGlobals.formatDateTime(new Date(nodeInfo.getJoinedTime())) %>
                  </td>
                  <td class="jive-description" nowrap width="1%" valign="middle">
                      <%= nodeStats != null ? nodeStats.get(GetBasicStatistics.CLIENT) : "N/A" %>
                  </td>
                  <td class="jive-description" nowrap width="1%" valign="middle">
                      <%= nodeStats != null ? nodeStats.get(GetBasicStatistics.INCOMING) : "N/A" %>
                  </td>
                  <td class="jive-description" nowrap width="1%" valign="middle">
                      <%= nodeStats != null ? nodeStats.get(GetBasicStatistics.OUTGOING) : "N/A" %>
                  </td>
                  <td class="jive-description" nowrap width="75%" valign="middle">
                  <table width="100%">
                    <tr>
                      <%
                          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";
                          }
                      %>
327
                        <td width="30%">
Gaston Dombiak's avatar
Gaston Dombiak committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
                          <div class="bar">
                          <table cellpadding="0" cellspacing="0" border="0" width="100%" style="border:1px #666 solid;">
                          <tr>
                              <%  if (percent == 0) { %>

                                  <td width="100%"><img src="images/percent-bar-left.gif" width="100%" height="4" border="0" alt=""></td>

                              <%  } else { %>

                                  <%  if (percent >= 90) { %>

                                      <td width="<%= percent %>%" background="images/percent-bar-used-high.gif"
                                          ><img src="images/blank.gif" width="1" height="4" border="0" alt=""></td>

                                  <%  } else { %>

                                      <td width="<%= percent %>%" background="images/percent-bar-used-low.gif"
                                          ><img src="images/blank.gif" width="1" height="4" border="0" alt=""></td>

                                  <%  } %>
                                  <td width="<%= (100-percent) %>%" background="images/percent-bar-left.gif"
                                      ><img src="images/blank.gif" width="1" height="4" border="0" alt=""></td>
                              <%  } %>
                          </tr>
                          </table>
                          </div>
                        </td>
355 356
                        <td class="jive-description">
                          <%= memory %>
Gaston Dombiak's avatar
Gaston Dombiak committed
357 358 359 360 361 362
                        </td>
                      </tr>
                    </table>
                  </td>
                  <td width="20%">&nbsp;</td>
              </tr>
Gaston Dombiak's avatar
Gaston Dombiak committed
363
              <% }
364
              } else if (ClusterManager.isClusteringStarting()) { %>
Gaston Dombiak's avatar
Gaston Dombiak committed
365 366 367
              <tr valign="middle" align="middle" class="local">
                  <td colspan=8>
                      <fmt:message key="system.clustering.starting">
368 369
                          <fmt:param value="<a href=\"system-clustering.jsp\">"/>
                          <fmt:param value="</a>"/>
Gaston Dombiak's avatar
Gaston Dombiak committed
370 371 372
                      </fmt:message>
                  </td>
              </tr>
Gaston Dombiak's avatar
Gaston Dombiak committed
373 374 375 376 377 378 379 380
              <% } %>
        </tbody>
        </table>
</div>


</body>
</html>