Merge remote-tracking branch 'manage/master' into subtree

this merges master branch of https://github.com/helma-org/apps-manage-mirror into helma
This commit is contained in:
Simon Oberhammer 2012-03-27 11:47:36 +02:00
commit ca2b08a5df
58 changed files with 2678 additions and 0 deletions

View file

@ -0,0 +1,67 @@
/**
* renders AppManager
*/
function main_action() {
if (checkAddress() == false)
return;
if (checkAuth(this) == false)
return;
res.data.body = this.renderSkinAsString("main");
renderSkin("global");
}
/**
* prints session- and thread-stats for mrtg-tool
* doesn't check username or password, so that we don't have
* to write them cleartext in a mrtg-configfile but checks the
* remote address.
*/
function mrtg_action() {
if (checkAddress() == false)
return;
if (this.isActive() == false) {
res.write("0\n0\n0\n0\n");
return;
}
if (req.data.action == "sessions") {
res.write(this.sessions.size());
res.write("\n0\n0\n0\n");
} else if (req.data.action == "threads") {
res.write(this.countActiveEvaluators() + "\n");
res.write(this.countEvaluators() + "\n");
res.write("0\n0\n");
} else if (req.data.action == "cache") {
res.write(this.getCacheUsage() + "\n");
res.write(this.getProperty("cachesize", "1000") + "\n");
res.write("0\n0\n");
} else if (req.data.action == "requests") {
// res.write (
} else {
res.write("0\n0\n0\n0\n");
}
}
/**
* performs a redirect to the public site
* (workaround, we can't access application object from docapplication for some reason)
* @see application.url_macro
*/
function redirectpublic_action() {
if (checkAddress() == false) return;
if (checkAuth(this) == false) return;
res.redirect(this.url_macro());
}

View file

@ -0,0 +1,42 @@
/**
* construct an application object so that we can use
* skins for non-active applications too
* @arg name
*/
function constructor(name) {
this.name = name;
}
/**
* return true/false to determine if application is running
*/
function isActive() {
if (root.getApplication(this.name) == null)
return false;
else
return true;
}
/**
* Method used by Helma for URL composition.
*/
function href(action) {
var base = root.href() + this.name + "/";
return action ? base + action : base;
}
/**
* Method used by Helma for URL composition.
*/
function getParentElement() {
return root;
}
/**
* Method used by Helma request path resolution.
*/
function getChildElement(name) {
if (name == "api")
return this.getDoc();
return null;
}

View file

@ -0,0 +1,11 @@
<p><big>AppManager <% this.title %></big>
<% this.description prefix="<br/>" %>
<br/>
-&gt;
<a href="<% this.href action="api" %>/read">showAPI</a> |
<a href="<% this.href action="api" %>/render">renderAPI</a> |
<a href="<% this.url %>">public</a> |
<a href="<% root.href action="main" %>?app=<% this.title %>&action=flush">flush</a> |
<a href="<% root.href action="main" %>?app=<% this.title %>&action=restart">restart</a> |
<a href="<% root.href action="main" %>?app=<% this.title %>&action=stop">stop</a>
</p>

View file

@ -0,0 +1,210 @@
/**
* macro rendering a skin
* @param name name of skin
*/
function skin_macro(par) {
if (par && par.name) {
this.renderSkin(par.name);
}
}
/**
* macro-wrapper for href-function
* @param action name of action to call on this prototype, default main
*/
function href_macro(par) {
return this.href((par && par.action) ? par.action : "main");
}
/**
* Macro returning the URL of an application.
* using absoluteURI if set in app.properties, otherwise we go for the href calculated by
* the application (which is using baseURI if set)
*/
function url_macro() {
var str = this.getProperty("absoluteuri");
if (str != null && str != "") {
return str;
} else {
return this.getRootHref();
}
}
/**
* Macro returning the title of an application
*/
function title_macro() {
var title = this.name;
return(title);
}
/**
* Macro rendering a description of an application from a
* file called description.txt or doc.html located in the
* app's root. Limits description to 200 chars.
* @param Object Macro parameter object
*/
function description_macro(param) {
var str = "";
var appHome = this.getAppDir();
var f = new File(this.getAppDir().toString(), "description.txt");
if (!f.exists())
f = new File(this.getAppDir().toString(), "doc.html");
if (f.exists()) {
str = f.readAll();
if (str.length > 200)
str = str.substring(0, 200) + "...";
}
return(str);
}
/**
* Macro returning the server's uptime nicely formatted
*/
function uptime_macro() {
return formatAge((java.lang.System.currentTimeMillis() - this.starttime) / 1000);
}
/**
* Macro returning the number of active sessions.
* parameter used by global.formatCount
* @see global.formatCount
*/
function countSessions_macro(par) {
if (this.isActive() == true)
return this.sessions.size() + formatCount(this.sessions.size(), par);
else
return 0;
}
/**
* Macro returning the number of logged-in users or the list
* of logged-in users if http-parameter showusers is set to true.
* Makes use of this.countUsers_macro and this.listUsers_macro
* @see application.countUsers_macro
* @see application.listUsers_macro
*/
function users_macro(par) {
if (req.data.showusers == "true") {
this.listUsers_macro(par);
} else {
this.countUsers_macro(par);
}
}
/**
* Macro returning the number of logged-in users if application
* is active
* parameter used by global.formatCount
* @see global.formatCount
*/
function countUsers_macro(par) {
if (this.isActive() == true)
return this.activeUsers.size() + formatCount(this.activeUsers.size(), par);
else
return 0;
}
/**
* Macro rendering the list of logged-in users if application is active
* @param separator html-code written between elements
*/
function listUsers_macro(par) {
var separator = (par && par.separator) ? par.separator : ", ";
if (this.activeUsers.size() == 0)
return "";
var users = this.activeUsers.iterator();
while (users.hasNext()) {
res.write(users.next().__name__);
if (users.hasNext()) {
res.write(separator);
}
}
}
/**
* Macro returning the number of active evaluators (=threads)
*/
function countActiveEvaluators_macro() {
return this.countActiveEvaluators();
}
/**
* Macro returning the number of free evaluators (=threads)
*/
function countFreeEvaluators_macro() {
return this.countFreeEvaluators();
}
/**
* Macro returning the current number of objects in the cache
*/
function cacheusage_macro(param) {
return this.getCacheUsage();
}
/**
* Macro returning the number of objects allowed in the cache
*/
function cachesize_macro(param) {
return this.getProperty("cachesize", "1000");
}
/**
* Macro formatting the number of requests in the last 5 minutes
*/
function requestCount_macro(par) {
if (app.data.stat == null || app.data.stat[this.name] == null)
return "not available";
if (this.isActive()) {
var obj = app.data.stat[this.name];
return obj.requestCount + formatCount(obj.requestCount, par);
} else {
return 0 + formatCount(0, par);
}
}
/**
* Macro formatting the number of errors in the last 5 minutes
*/
function errorCount_macro(par) {
if (app.data.stat == null || app.data.stat[this.name] == null)
return "not available";
if (this.isActive()) {
var obj = app.data.stat[this.name];
return obj.errorCount + formatCount(obj.errorCount, par);
} else {
return 0 + formatCount(0, par);
}
}
/**
* Macro formatting app.properties
*/
function properties_macro(par) {
formatProperties(this.getProperties(), par);
}
function repositories_macro(param) {
var repos = this.getRepositories().iterator();
while (repos.hasNext())
res.writeln(repos.next().getName());
}

View file

@ -0,0 +1,62 @@
<% this.skin name="head" %>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="list_separator" colspan="3">application</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="list_property" align="left">active sessions</td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.countSessions %></td>
</tr>
<tr>
<td class="list_property" align="left"><a href="<% this.href action="main" %>?showusers=true">logged-in users</a></td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.users %>&nbsp;</td>
</tr>
<tr>
<td class="list_property" align="left">active evaluators</td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.countActiveEvaluators %></td>
</tr>
<tr>
<td class="list_property" align="left">free evaluators</td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.countFreeEvaluators %></td>
</tr>
<tr>
<td class="list_property" align="left">requests / 5 min</td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.requestCount %></td>
</tr>
<tr>
<td class="list_property" align="left">errors / 5 min</td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.errorCount %></td>
</tr>
<tr>
<td class="list_property" align="left">cache usage</td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.cacheusage %> objects of <% this.cachesize %></td>
</tr>
<tr>
<td class="list_property" align="left">uptime</td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.uptime %></td>
</tr>
<tr>
<td class="list_property" align="left" valign="top">repositories</td>
<td class="list_property" width="5">&nbsp;</td>
<td class="list_property" align="left"><% this.repositories %></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="list_separator" colspan="3">app.properties</td>
</tr>
<% this.properties itemprefix='<tr><td class="list_property" valign="top">' separator='</td><td class="list_property" width="5">&nbsp;</td><td class="list_property" valign="top">' itemsuffix='</td></tr>' %>
</table>

View file

@ -0,0 +1,18 @@
<div class="list_apps">
<b><a href="<% this.href action="main" %>"><% this.title %></a></b><br />
<small><% this.countSessions singular=" Session" plural=" Sessions" %>,
<% this.requestCount singular=" Request" plural=" Requests" %>/5min</small>
<div align="right">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right" valign="top"><small style="font-size:9px;">
<a href="<% this.href action="api" %>/read">showAPI</a> |
<a href="<% this.href action="api" %>/render">renderAPI</a> |
<a href="<% this.url %>">public</a> |
<a href="<% root.href action="main" %>?app=<% this.title %>&action=flush">flush</a> |
<a href="<% root.href action="main" %>?app=<% this.title %>&action=restart">restart</a>
</small></td>
</tr>
</table>
</div>
</div>

View file

@ -0,0 +1,10 @@
<div class="list_apps">
<table border="0" cellspacing="0" cellpadding="0" align="right">
<tr>
<td align="right" valign="top"><small>
<a href="<% root.href action="main" %>?app=<% this.title %>&action=start">start</a>
</td>
</tr>
</table>
<b><% this.title %></b>
</div>