commit 0c06540434314a4f843f26691cda3e3e967f2e6f
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Tue May 29 08:47:03 2012 +0000

diff --git a/.gitattributes b/.gitattributes
index a558186..5ddaae7 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -43,11 +43,13 @@ src/main/webapp/css/style.css -text
 src/main/webapp/favicon.ico -text
 src/main/webapp/index.html -text
 src/main/webapp/index.jsp -text
+src/main/webapp/js/instance-status.js -text
 src/main/webapp/js/jquery.js -text
 src/main/webapp/js/jquery.min.js -text
+src/main/webapp/js/memory-status.js -text
 src/main/webapp/js/oai-pmh-status.js -text
-src/main/webapp/js/server-status.js -text
 src/main/webapp/manage/BootloaderService.jsp -text
+src/main/webapp/manage/MemoryService.jsp -text
 src/main/webapp/manage/index.jsp -text
 src/main/webapp/robots.txt -text
 src/site/apt/getting-started.apt -text
diff --git a/src/main/webapp/js/instance-status.js b/src/main/webapp/js/instance-status.js
new file mode 100644
index 0000000..1d40e16
--- /dev/null
+++ b/src/main/webapp/js/instance-status.js
@@ -0,0 +1,42 @@
+
+$(document).ready(function(){
+
+  function updateInstaceStatus(){
+      $.getJSON(
+        "BootloaderService.jsp",
+        function(data){
+          for(var i in data) {
+            var dataSourceName = data[i].dataSourceName;
+            var status = data[i].status;
+            var problems = data[i].problems;
+            $('#' + dataSourceName + ' .status').html(status).attr('class', 'status '+ status);
+            if(data[i].status == "error" || !data[i].enabled){
+             /*out.append("<tr class=\"error-log " + oddOrEven + "\">");
+                                                     out.append("<td></td><td  class=\"error\" colspan=\"4\">");
+                                                         for( String problem : props.getProblems()){
+                                                           out.append("<div>" + problem + "</div>");
+                                                         }
+                                                     out.append("</td>");
+                                                     out.append("</tr>");
+              */
+              if($('#' + dataSourceName + '-error-log').size() == 0){
+                // append new table row
+                var oddeven = $('#' + dataSourceName).attr('class').indexOf('even') > -1 ? 'even': 'odd';
+                $('#' + dataSourceName).after('<tr id="' + dataSourceName + '-error-log" class="error-log ' + oddeven + '"><td></td><td class="error message" colspan="4"></td></tr>');
+              }
+              $('#' + dataSourceName + '-error-log .message').html('<h1>x</h1>');
+              for(var k in data[i].problems){
+                $('#' + dataSourceName + '-error-log .message').appendTo('<div>' + data[i].problems[k] + '</div>');
+              }
+            }
+          }
+        });
+
+    setTimeout(function(){
+      updateInstaceStatus()
+      }, 1000);
+  }
+
+  updateInstaceStatus();
+
+});
\ No newline at end of file
diff --git a/src/main/webapp/js/memory-status.js b/src/main/webapp/js/memory-status.js
new file mode 100644
index 0000000..d329a61
--- /dev/null
+++ b/src/main/webapp/js/memory-status.js
@@ -0,0 +1,39 @@
+
+$(document).ready(function(){
+
+  function updateMemoryStatus() {
+     $.getJSON(
+        "MemoryService.jsp",
+        function(data){
+          $("#status").html(''); // make empty
+          $("#status").append(memoryUsageEntry(data.heapMemoryUsage, data.recommendedMinimumHeap, "HeapUsage", "100%", "#F48B65", "#65B1F4"));
+          $("#status").append(memoryUsageEntry(data.permGenSpaceUsage, data.recommendedMinimumPermGenSpace, "PermGenSpaceUsage", "100%","#F48B65", "#65B1F4"));
+     }); // end JSON
+
+
+    setTimeout(function(){
+        updateMemoryStatus()
+        }, 1000);
+
+  } // end updateMemory
+
+  function memoryUsageEntry(memoryUsage, recommended, label, barWidth, cssColorUsed, cssColorMax){
+    var mb = 1024 * 1024;
+    var gb = mb * 1024;
+    var max = memoryUsage.max / mb;
+    var used = memoryUsage.used / mb;
+    var percent = used * 100 / max;
+    var recommendedMB = recommended / mb;
+    var html;
+
+    html += '<span class="memory-usage">';
+    html += label + '(' + used + ' of '  + max+ ' MB, recommended: '  + recommendedMB + ' MB)&nbsp;';
+    html += '<div style="height: 100%; width:' + barWidth + ';background-color:' + cssColorMax + '">';
+    html += '<div style="background-color:' + cssColorUsed + '; width:' + percent + '%">&nbsp;</div></div></span>';
+
+    return html;
+  }
+
+  updateMemoryStatus()
+
+});
\ No newline at end of file
diff --git a/src/main/webapp/js/server-status.js b/src/main/webapp/js/server-status.js
deleted file mode 100644
index dee5322..0000000
--- a/src/main/webapp/js/server-status.js
+++ /dev/null
@@ -1,20 +0,0 @@
-
-$(document).ready(function(){
-	
-	$("#datasources table .entry").each(function(){
-		var entry = $(this);
-		var url = entry.find('.base-url a').attr('href');
-
-		$.getJSON(
-			"http://wp5.e-taxonomy.eu/registry/oai/providers.php?format=json&callback=?&find="+encodeURIComponent(url),
-			function(data){
-				if(data.providers != undefined && data.providers.provider != undefined){
-					entry.find('.oai-pmh').css('color', 'green').html("Registered");
-				} else {
-					entry.find('.oai-pmh').html("<a href=\"mailto:editsupport@bgbm.org?subject=OAI-PHM Provider Registration&body=" + encodeURIComponent(url) + "\">Request for registration</a>");
-				}
-			});
-		
-		
-	});
-});
\ No newline at end of file
diff --git a/src/main/webapp/manage/MemoryService.jsp b/src/main/webapp/manage/MemoryService.jsp
new file mode 100644
index 0000000..d1aa9de
--- /dev/null
+++ b/src/main/webapp/manage/MemoryService.jsp
@@ -0,0 +1,40 @@
+<%@page import="org.codehaus.jackson.node.JsonNodeFactory"
+%><%@page import="org.codehaus.jackson.node.ArrayNode"
+%><%@ page contentType="application/json;charset=UTF-8" language="java"
+%><%@page import="java.util.Set"
+%><%@page import="org.codehaus.jackson.map.ObjectMapper"
+%><%@page import="org.codehaus.jackson.JsonNode"
+%><%@page import="org.codehaus.jackson.node.ObjectNode"
+%><%@page import="eu.etaxonomy.cdm.server.JvmManager"
+%><%@page import="java.lang.management.MemoryUsage"
+%><%@page import="org.codehaus.jackson.JsonFactory"
+%><%@page import="org.codehaus.jackson.JsonGenerator"
+%><%@page import="org.codehaus.jackson.map.ser.StdSerializerProvider"
+%><%@page import="eu.etaxonomy.cdm.server.Bootloader"
+%><%
+
+    //the servelt context must use the class loader of the Bootloader class otherwise
+    //getting the status will not work in mulithreading environments !!!
+    Bootloader bootloader = Bootloader.getBootloader();
+    long recommendedMinimumHeap = bootloader.recommendedMinimumSpace(Bootloader.HEAP_CDMSERVER, Bootloader.HEAP_PER_INSTANCE, null);
+    long recommendedMinimumPermGenSpace = bootloader.recommendedMinimumSpace(Bootloader.PERM_GEN_SPACE_CDMSERVER, Bootloader.PERM_GEN_SPACE_PER_INSTANCE, null);
+
+    ObjectMapper jsonMapper = new ObjectMapper();
+
+    response.setHeader("Content-Type", "application/json;charset=UTF-8");
+
+    MemoryUsage  heapMemoryUsage = JvmManager.getHeapMemoryUsage();
+    MemoryUsage  permGenSpaceUsage = JvmManager.getPermGenSpaceUsage();
+
+    ObjectNode node = jsonMapper.createObjectNode();
+    node.put("recommendedMinimumHeap", recommendedMinimumHeap);
+    node.put("recommendedMinimumPermGenSpace", recommendedMinimumPermGenSpace);
+    node.putPOJO("heapMemoryUsage", heapMemoryUsage);
+    node.putPOJO("permGenSpaceUsage", permGenSpaceUsage);
+
+    JsonFactory jsonFactory = new JsonFactory();
+    JsonGenerator jg = jsonFactory.createJsonGenerator(out);
+    jg.setCodec(jsonMapper);
+    node.serialize(jg, new StdSerializerProvider());
+    out.append("}"); //TODO why do we have to add the closing bracket ecplicitely ???? ==> it seems as if the serialization stops at some point du to an exception
+%>
\ No newline at end of file
