Author: jfrederic.clere(a)jboss.com
Date: 2009-07-20 10:29:34 -0400 (Mon, 20 Jul 2009)
New Revision: 2497
Modified:
trunk/mod_cluster/native/mod_manager/mod_manager.c
Log:
Fix MODCLUSTER-50, and sort the node by domain.
Modified: trunk/mod_cluster/native/mod_manager/mod_manager.c
===================================================================
--- trunk/mod_cluster/native/mod_manager/mod_manager.c 2009-07-20 08:12:06 UTC (rev 2496)
+++ trunk/mod_cluster/native/mod_manager/mod_manager.c 2009-07-20 14:29:34 UTC (rev 2497)
@@ -89,6 +89,11 @@
/* Internal substitution for node commands */
#define NODE_COMMAND "/NODE_COMMAND"
+/* range of the commands */
+#define RANGECONTEXT 0
+#define RANGENODE 1
+#define RANGEDOMAIN 2
+
/* shared memory */
mem_t *contextstatsmem = NULL;
mem_t *nodestatsmem = NULL;
@@ -1385,6 +1390,15 @@
ap_rprintf(r, "<a
href=\"%s?nonce=%s&Cmd=DISABLE-APP&Range=NODE&%s\">Disable
Contexts</a>",
r->uri, balancer_nonce, node_string(r, JVMRoute));
}
+static void domain_command_string(request_rec *r, int status, char *Domain)
+{
+ if (status == ENABLED)
+ ap_rprintf(r, "<a
href=\"%s?nonce=%s&Cmd=ENABLE-APP&Range=DOMAIN&Domain=%s\">Enable
Nodes</a> ",
+ r->uri, balancer_nonce, Domain);
+ if (status == DISABLED)
+ ap_rprintf(r, "<a
href=\"%s?nonce=%s&Cmd=DISABLE-APP&Range=DOMAIN&Domain=%s\">Disable
Nodes</a>",
+ r->uri, balancer_nonce, Domain);
+}
/*
* Process the parameters and display corresponding informations.
@@ -1512,6 +1526,60 @@
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"manager_handler %s error: %s", r->method, errstring);
}
+static void sort_nodes(nodeinfo_t *nodes, int nbnodes)
+{
+ int i;
+ int changed = -1;
+ if (nbnodes <=1)
+ return;
+ while(changed) {
+ changed = 0;
+ for (i=0; i<nbnodes-1; i++) {
+ if (strcmp(nodes[i].mess.Domain, nodes[i+1].mess.Domain)> 0) {
+ nodeinfo_t node;
+ node = nodes[i+1];
+ nodes[i+1] = nodes[i];
+ nodes[i] = node;
+ changed = -1;
+ }
+ }
+ }
+}
+static char *process_domain(request_rec *r, char **ptr, int *errtype, const char *cmd,
const char *domain)
+{
+ int size, i;
+ int *id;
+ int pos;
+ char *errstring = NULL;
+ size = get_max_size_node(nodestatsmem);
+ id = apr_palloc(r->pool, sizeof(int) * size);
+ size = get_ids_used_node(nodestatsmem, id);
+
+ for (pos=0;ptr[pos]!=NULL && ptr[pos+1]!=NULL; pos=pos+2) ;
+
+ ptr[pos] = apr_pstrdup(r->pool, "JVMRoute");
+ ptr[pos+2] = NULL;
+ ptr[pos+3] = NULL;
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, r->server,
"process_domain");
+ for (i=0; i<size; i++) {
+ nodeinfo_t *ou;
+ if (get_node(nodestatsmem, &ou, id[i]) != APR_SUCCESS)
+ continue;
+ if (strcmp(ou->mess.Domain, domain) != 0)
+ continue;
+ /* add the JVMRoute */
+ ptr[pos+1] = apr_pstrdup(r->pool, ou->mess.JVMRoute);
+ if (strcasecmp(cmd, "ENABLE-APP") == 0)
+ errstring = process_enable(r, ptr, errtype, RANGENODE);
+ else if (strcasecmp(cmd, "DISABLE-APP") == 0)
+ errstring = process_disable(r, ptr, errtype, RANGENODE);
+ else if (strcasecmp(cmd, "STOP-APP") == 0)
+ errstring = process_stop(r, ptr, errtype, RANGENODE);
+ else if (strcasecmp(cmd, "REMOVE-APP") == 0)
+ errstring = process_remove(r, ptr, errtype, RANGENODE);
+ }
+ return errstring;
+}
static int manager_info(request_rec *r)
{
int size, i, sizesessionid;
@@ -1519,6 +1587,9 @@
apr_table_t *params = apr_table_make(r->pool, 10);
int access_status;
const char *name;
+ nodeinfo_t *nodes;
+ int nbnodes = 0;
+ char *domain = "";
if (r->args) {
char *args = apr_pstrdup(r->pool, r->args);
@@ -1556,6 +1627,7 @@
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 *domain = apr_table_get(params, "Domain");
/* Process the Refresh parameter */
if (val) {
long t = atol(val);
@@ -1563,7 +1635,7 @@
}
/* Process command if any */
if (cmd != NULL && typ !=NULL) {
- int global = 0;
+ int global = RANGECONTEXT;
char *errstring = NULL;
int errtype = 0;
int i;
@@ -1571,7 +1643,15 @@
const apr_array_header_t *arr = apr_table_elts(params);
const apr_table_entry_t *elts = (const apr_table_entry_t *)arr->elts;
- ptr = apr_palloc(r->pool, sizeof(char *) * (arr->nelts + 1) * 2);
+ if (strcasecmp(typ,"NODE")==0)
+ global = RANGENODE;
+ else if (strcasecmp(typ,"DOMAIN")==0)
+ global = RANGEDOMAIN;
+
+ if (global == RANGEDOMAIN)
+ ptr = apr_palloc(r->pool, sizeof(char *) * (arr->nelts + 2) * 2);
+ else
+ ptr = apr_palloc(r->pool, sizeof(char *) * (arr->nelts + 1) * 2);
for (i = 0; i < arr->nelts; i++) {
ptr[i*2] = elts[i].key;
ptr[i*2+1] = elts[i].val;
@@ -1579,9 +1659,9 @@
ptr[arr->nelts*2] = NULL;
ptr[arr->nelts*2+1] = NULL;
- if (strcasecmp(typ,"NODE")==0)
- global = 1;
- if (strcasecmp(cmd, "ENABLE-APP") == 0)
+ if (global == RANGEDOMAIN)
+ errstring = process_domain(r, ptr, &errtype, cmd, domain);
+ else if (strcasecmp(cmd, "ENABLE-APP") == 0)
errstring = process_enable(r, ptr, &errtype, global);
else if (strcasecmp(cmd, "DISABLE-APP") == 0)
errstring = process_disable(r, ptr, &errtype, global);
@@ -1631,12 +1711,32 @@
size = get_max_size_node(nodestatsmem);
id = apr_palloc(r->pool, sizeof(int) * size);
size = get_ids_used_node(nodestatsmem, id);
+
+
+ /* read the node to sort them by domain */
+ nodes = apr_palloc(r->pool, sizeof(nodeinfo_t) * size);
for (i=0; i<size; i++) {
nodeinfo_t *ou;
+ if (get_node(nodestatsmem, &ou, id[i]) != APR_SUCCESS)
+ continue;
+ memcpy(&nodes[nbnodes],ou, sizeof(nodeinfo_t));
+ nbnodes++;
+ }
+ sort_nodes(nodes, nbnodes);
+
+ /* display the ordered nodes */
+ for (i=0; i<size; i++) {
proxy_worker_stat *proxystat;
char *flushpackets;
- if (get_node(nodestatsmem, &ou, id[i]) != APR_SUCCESS)
- continue;
+ nodeinfo_t *ou = &nodes[i];
+
+ if (strcmp(domain, ou->mess.Domain) != 0) {
+ ap_rprintf(r, "<h1> Domain %s: ", ou->mess.Domain);
+ domain = ou->mess.Domain;
+ domain_command_string(r, ENABLED, domain);
+ domain_command_string(r, DISABLED, domain);
+ ap_rprintf(r, "</h1>\n");
+ }
ap_rprintf(r, "<h1> Node %s (%s://%s:%s): ",
ou->mess.JVMRoute, ou->mess.Type, ou->mess.Host,
ou->mess.Port);