Author: jfrederic.clere(a)jboss.com
Date: 2009-04-21 13:59:13 -0400 (Tue, 21 Apr 2009)
New Revision: 2395
Modified:
trunk/mod_cluster/native/mod_manager/mod_manager.c
Log:
Fix partialy MODCLUSTER-69 (allow to disable/enable individual apps).
Modified: trunk/mod_cluster/native/mod_manager/mod_manager.c
===================================================================
--- trunk/mod_cluster/native/mod_manager/mod_manager.c 2009-04-21 10:10:35 UTC (rev 2394)
+++ trunk/mod_cluster/native/mod_manager/mod_manager.c 2009-04-21 17:59:13 UTC (rev 2395)
@@ -1020,7 +1020,7 @@
}
/* Process an enable/disable/stop/remove application message */
-static char * process_appl_cmd(request_rec *r, char *buff, int status, int *errtype)
+static char * process_appl_cmd(request_rec *r, char *buff, int status, int *errtype, int
global)
{
nodeinfo_t nodeinfo;
nodeinfo_t *node;
@@ -1098,7 +1098,7 @@
}
/* Process the * APP commands */
- if (strstr(r->filename, NODE_COMMAND)) {
+ if (global) {
return (process_node_cmd(r, status, errtype, node));
}
@@ -1153,21 +1153,21 @@
}
return NULL;
}
-static char * process_enable(request_rec *r, char *buff, int *errtype)
+static char * process_enable(request_rec *r, char *buff, int *errtype, int global)
{
- return process_appl_cmd(r, buff, ENABLED, errtype);
+ return process_appl_cmd(r, buff, ENABLED, errtype, global);
}
-static char * process_disable(request_rec *r, char *buff, int *errtype)
+static char * process_disable(request_rec *r, char *buff, int *errtype, int global)
{
- return process_appl_cmd(r, buff, DISABLED, errtype);
+ return process_appl_cmd(r, buff, DISABLED, errtype, global);
}
-static char * process_stop(request_rec *r, char *buff, int *errtype)
+static char * process_stop(request_rec *r, char *buff, int *errtype, int global)
{
- return process_appl_cmd(r, buff, STOPPED, errtype);
+ return process_appl_cmd(r, buff, STOPPED, errtype, global);
}
-static char * process_remove(request_rec *r, char *buff, int *errtype)
+static char * process_remove(request_rec *r, char *buff, int *errtype, int global)
{
- return process_appl_cmd(r, buff, REMOVE, errtype);
+ return process_appl_cmd(r, buff, REMOVE, errtype, global);
}
/*
@@ -1383,10 +1383,26 @@
return DECLINED;
}
+/* Create the commands that are possible on the context */
+static char*context_string(request_rec *r, contextinfo_t *ou, char *Alias, char
*JVMRoute)
+{
+ char *raw = apr_pstrcat(r->pool, "JVMRoute%3d", JVMRoute,
"%26Alias%3d", Alias, "%26Context%3d", ou->context);
+ return raw;
+}
+static void context_command_string(request_rec *r, contextinfo_t *ou, char *Alias, char
*JVMRoute)
+{
+ if (ou->status == DISABLED)
+ ap_rprintf(r, "<a
href=\"%s?nonce=%s&Cmd=ENABLE-APP&Range=CONTEXT&String=%s\">Enable</a>
",
+ r->uri, balancer_nonce, context_string(r, ou, Alias, JVMRoute));
+ if (ou->status == ENABLED)
+ ap_rprintf(r, "<a
href=\"%s?nonce=%s&Cmd=DISABLE-APP&Range=CONTEXT&String=%s\">Disable</a>",
+ r->uri, balancer_nonce, context_string(r, ou, Alias, JVMRoute));
+}
+
/*
* Process the parameters and display corresponding informations.
*/
-static void manager_info_contexts(request_rec *r, int node, int host)
+static void manager_info_contexts(request_rec *r, int node, int host, char *Alias, char
*JVMRoute)
{
int size, i;
int *id;
@@ -1415,11 +1431,13 @@
status = "STOPPED";
break;
}
- ap_rprintf(r, "%s, Status: %s\n", ou->context, status);
+ ap_rprintf(r, "%s, Status: %s ", ou->context, status);
+ context_command_string(r, ou, Alias, JVMRoute);
+ ap_rprintf(r, "\n");
}
ap_rprintf(r, "</pre>");
}
-static void manager_info_hosts(request_rec *r, int node)
+static void manager_info_hosts(request_rec *r, int node, char *JVMRoute)
{
int size, i;
int *id;
@@ -1439,7 +1457,7 @@
if (vhost)
ap_rprintf(r, "</pre>");
ap_rprintf(r, "<h2> Virtual Host %d:</h2>",
ou->vhost);
- manager_info_contexts(r, ou->node, ou->vhost);
+ manager_info_contexts(r, ou->node, ou->vhost, ou->host, JVMRoute);
ap_rprintf(r, "<h3>Aliases:</h3>");
ap_rprintf(r, "<pre>");
vhost = ou->vhost;
@@ -1488,9 +1506,28 @@
}
return count;
}
+static void process_error(request_rec *r, char *errstring, int errtype)
+{
+ r->status_line = apr_psprintf(r->pool, "ERROR");
+ apr_table_setn(r->err_headers_out, "Version", VERSION_PROTOCOL);
+ switch (errtype) {
+ case TYPESYNTAX:
+ apr_table_setn(r->err_headers_out, "Type", "SYNTAX");
+ break;
+ case TYPEMEM:
+ apr_table_setn(r->err_headers_out, "Type", "MEM");
+ break;
+ default:
+ apr_table_setn(r->err_headers_out, "Type", "GENERAL");
+ break;
+ }
+ apr_table_setn(r->err_headers_out, "Mess", errstring);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "manager_handler %s error: %s", r->method, errstring);
+}
static int manager_info(request_rec *r)
{
- int size, i;
+ int size, i, sizesessionid;
int *id;
apr_table_t *params = apr_table_make(r->pool, 10);
int access_status;
@@ -1508,7 +1545,7 @@
* Special case: contexts contain path information
*/
if ((access_status = ap_unescape_url(val)) != OK)
- if (strcmp(args, "context") || (access_status !=
HTTP_NOT_FOUND))
+ if (strcmp(args, "String") || (access_status !=
HTTP_NOT_FOUND))
return access_status;
apr_table_setn(params, args, val);
args = tok;
@@ -1529,12 +1566,40 @@
/* process the parameters */
if (r->args) {
+ const char *val = apr_table_get(params, "Refresh");
+ const char *cmd = apr_table_get(params, "Cmd");
+ const char *typ = apr_table_get(params, "Range");
+ const char *string = apr_table_get(params, "String");
/* Process the Refresh parameter */
- const char *val = apr_table_get(params, "Refresh");
if (val) {
long t = atol(val);
apr_table_set(r->headers_out, "Refresh", apr_ltoa(r->pool,t
< 1 ? 10 : t));
}
+ /* Process command if any */
+ if (cmd != NULL && typ !=NULL && string != NULL) {
+ int global = 0;
+ char *errstring = NULL;
+ int errtype = 0;
+ char *buff = apr_pstrdup(r->pool, string);
+ if (strcasecmp(typ,"NODE")==0)
+ global = 1;
+ if (strcasecmp(cmd, "ENABLE-APP") == 0)
+ errstring = process_enable(r, buff, &errtype, global);
+ else if (strcasecmp(cmd, "DISABLE-APP") == 0)
+ errstring = process_disable(r, buff, &errtype, global);
+ else if (strcasecmp(cmd, "STOP-APP") == 0)
+ errstring = process_stop(r, buff, &errtype, global);
+ else if (strcasecmp(cmd, "REMOVE-APP") == 0)
+ errstring = process_remove(r, buff, &errtype, global);
+ else {
+ errstring = SCMDUNS;
+ errtype = TYPESYNTAX;
+ }
+ if (errstring) {
+ process_error(r, errstring, errtype);
+ return 500;
+ }
+ }
}
ap_set_content_type(r, "text/html; charset=ISO-8859-1");
@@ -1546,6 +1611,9 @@
"\">Auto Refresh</a>", NULL);
ap_rputs("<pre>", r);
+
+ sizesessionid = get_max_size_sessionid(sessionidstatsmem);
+
size = get_max_size_node(nodestatsmem);
id = apr_palloc(r->pool, sizeof(int) * size);
size = get_ids_used_node(nodestatsmem, id);
@@ -1572,15 +1640,20 @@
flushpackets, ou->mess.flushwait,
ou->mess.ping, ou->mess.smax, ou->mess.ttl);
proxystat = (proxy_worker_stat *) ou->stat;
- ap_rprintf(r, ",Elected: %d,Read: %d,Transferred: %d,Connected: %d,Load: %d
Num sessions: %d\n",
+ ap_rprintf(r, ",Elected: %d,Read: %d,Transferred: %d,Connected: %d,Load:
%d",
proxystat->elected, proxystat->read, proxystat->transferred,
- proxystat->busy, proxystat->lbfactor, count_sessionid(r,
ou->mess.JVMRoute));
+ proxystat->busy, proxystat->lbfactor);
+ if (sizesessionid)
+ ap_rprintf(r, ",Num sessions: %d\n", count_sessionid(r,
ou->mess.JVMRoute));
+ else
+ ap_rprintf(r, "\n");
/* Process the Vhosts */
- manager_info_hosts(r, id[i]);
+ manager_info_hosts(r, id[i], ou->mess.JVMRoute);
}
/* Display the sessions */
- manager_sessionid(r);
+ if (sizesessionid)
+ manager_sessionid(r);
ap_rputs("</body></html>\n", r);
@@ -1596,6 +1669,7 @@
char *buff;
apr_size_t bufsiz=MAXMESSSIZE;
apr_status_t status;
+ int global = 0;
if (strcmp(r->handler, "mod_cluster-manager") == 0) {
/* Display the nodes information */
@@ -1628,17 +1702,19 @@
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"manager_handler %s (%s) processing: \"%s\"",
r->method, r->filename, buff);
decodeenc(buff);
+ if (strstr(r->filename, NODE_COMMAND))
+ global = 1;
if (strcasecmp(r->method, "CONFIG") == 0)
errstring = process_config(r, buff, &errtype);
/* Application handling */
else if (strcasecmp(r->method, "ENABLE-APP") == 0)
- errstring = process_enable(r, buff, &errtype);
+ errstring = process_enable(r, buff, &errtype, global);
else if (strcasecmp(r->method, "DISABLE-APP") == 0)
- errstring = process_disable(r, buff, &errtype);
+ errstring = process_disable(r, buff, &errtype, global);
else if (strcasecmp(r->method, "STOP-APP") == 0)
- errstring = process_stop(r, buff, &errtype);
+ errstring = process_stop(r, buff, &errtype, global);
else if (strcasecmp(r->method, "REMOVE-APP") == 0)
- errstring = process_remove(r, buff, &errtype);
+ errstring = process_remove(r, buff, &errtype, global);
/* Status handling */
else if (strcasecmp(r->method, "STATUS") == 0)
errstring = process_status(r, buff, &errtype);
@@ -1653,22 +1729,7 @@
/* Check error string and build the error message */
if (errstring) {
- r->status_line = apr_psprintf(r->pool, "ERROR");
- apr_table_setn(r->err_headers_out, "Version", VERSION_PROTOCOL);
- switch (errtype) {
- case TYPESYNTAX:
- apr_table_setn(r->err_headers_out, "Type",
"SYNTAX");
- break;
- case TYPEMEM:
- apr_table_setn(r->err_headers_out, "Type", "MEM");
- break;
- default:
- apr_table_setn(r->err_headers_out, "Type",
"GENERAL");
- break;
- }
- apr_table_setn(r->err_headers_out, "Mess", errstring);
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "manager_handler %s error: %s", r->method, errstring);
+ process_error(r, errstring, errtype);
return 500;
}