Author: jfrederic.clere(a)jboss.com
Date: 2008-05-16 05:04:09 -0400 (Fri, 16 May 2008)
New Revision: 1608
Modified:
trunk/mod_cluster/native/mod_manager/mod_manager.c
Log:
Arrange the error messages.
Modified: trunk/mod_cluster/native/mod_manager/mod_manager.c
===================================================================
--- trunk/mod_cluster/native/mod_manager/mod_manager.c 2008-05-15 14:57:35 UTC (rev 1607)
+++ trunk/mod_cluster/native/mod_manager/mod_manager.c 2008-05-16 09:04:09 UTC (rev 1608)
@@ -50,6 +50,23 @@
#define DEFMAXNODE 10
#define DEFMAXHOST 20
+/* Error messages */
+#define SMESPAR "SYNTAX: Can't parse message"
+#define SBALBIG "SYNTAX: Balancer field too big"
+#define SROUBIG "SYNTAX: JVMRoute field too big"
+#define SDOMBIG "SYNTAX: Domain field too big"
+#define SHOSBIG "SYNTAX: Host field too big"
+#define SPORBIG "SYNTAX: Port field too big"
+#define STYPBIG "SYNTAX: Type field too big"
+#define SALIBAD "SYNTAX: Alias without Context"
+#define SCONBAD "SYNTAX: Context without Alias"
+#define SBADFLD "SYNTAX: Invalid field name in message"
+#define SCMDUNS "SYNTAX: Command is not supported"
+
+#define MNODEUI "MEM: Can't update or insert node"
+#define MNODERD "MEM: Can't read node"
+#define MHOSTRD "MEM: Can't read host alias"
+
/* shared memory */
mem_t *contextstatsmem = NULL;
mem_t *nodestatsmem = NULL;
@@ -341,7 +358,7 @@
* Context corresponding to the applications.
* Context: <context list>
*/
-static int process_config(request_rec *r, char *buff)
+static char * process_config(request_rec *r, char *buff)
{
/* Process the node description */
nodeinfo_t nodeinfo;
@@ -357,7 +374,7 @@
char **ptr = process_buff(r, buff);
if (ptr == NULL)
- return 500;
+ return SMESPAR;
vhost = apr_palloc(r->pool, sizeof(struct cluster_host));
/* Map nothing by default */
@@ -371,32 +388,32 @@
while (ptr[i]) {
if (strcasecmp(ptr[i], "Balancer") == 0) {
if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.balancer))
- return 500;
+ return SBALBIG;
strcpy(nodeinfo.mess.balancer, ptr[i+1]);
}
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute))
- return 500;
+ return SROUBIG;
strcpy(nodeinfo.mess.JVMRoute, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Domain") == 0) {
if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Domain))
- return 500;
+ return SDOMBIG;
strcpy(nodeinfo.mess.Domain, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Host") == 0) {
if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Host))
- return 500;
+ return SHOSBIG;
strcpy(nodeinfo.mess.Host, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Port") == 0) {
if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Port))
- return 500;
+ return SPORBIG;
strcpy(nodeinfo.mess.Port, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Type") == 0) {
if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Type))
- return 500;
+ return STYPBIG;
strcpy(nodeinfo.mess.Type, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Reversed") == 0) {
@@ -406,7 +423,7 @@
}
if (strcasecmp(ptr[i], "Alias") == 0) {
if (phost->host && !phost->context) {
- return 500;
+ return SALIBAD;
}
if (phost->host) {
phost->next = apr_palloc(r->pool, sizeof(struct cluster_host));
@@ -420,7 +437,7 @@
}
if (strcasecmp(ptr[i], "Context") == 0) {
if (phost->context) {
- return 500;
+ return SCONBAD;
}
phost->context = ptr[i+1];
}
@@ -432,7 +449,7 @@
/* Insert or update node description */
int id;
if (insert_update_node(nodestatsmem, &nodeinfo, &id) != APR_SUCCESS)
- return 500;
+ return MNODEUI;
/* Insert the Alias and corresponding Context */
phost = vhost;
@@ -443,12 +460,12 @@
phost = phost->next;
vid++;
}
- return OK;
+ return NULL;
}
/*
* Process a DUMP command.
*/
-static int process_dump(request_rec *r, char *buff)
+static char * process_dump(request_rec *r, char *buff)
{
int size, i;
int *id;
@@ -486,11 +503,11 @@
ou->vhost, ou->node,
ou->status);
}
- return OK;
+ return NULL;
}
/* Process an enable/disable/stop application message */
-static int process_appl_cmd(request_rec *r, char *buff, int status)
+static char * process_appl_cmd(request_rec *r, char *buff, int status)
{
char *JVMRoute;
nodeinfo_t nodeinfo;
@@ -500,7 +517,7 @@
char **ptr = process_buff(r, buff);
if (ptr == NULL)
- return 500;
+ return SMESPAR;
/* Map nothing by default */
vhost->host = NULL;
@@ -513,13 +530,13 @@
while (ptr[i]) {
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute))
- return 500;
+ return SROUBIG;
strcpy(nodeinfo.mess.JVMRoute, ptr[i+1]);
nodeinfo.mess.id = 0;
}
if (strcasecmp(ptr[i], "Alias") == 0) {
if (phost->host && !phost->context) {
- return 500;
+ return SALIBAD;
}
if (phost->host) {
phost->next = apr_palloc(r->pool, sizeof(struct cluster_host));
@@ -533,7 +550,7 @@
}
if (strcasecmp(ptr[i], "Context") == 0) {
if (phost->context) {
- return 500;
+ return SCONBAD;
}
phost->context = ptr[i+1];
}
@@ -544,7 +561,7 @@
/* Read the node */
node = read_node(nodestatsmem, &nodeinfo);
if (node == NULL)
- return 500;
+ return MNODERD;
/* Read the ID of the virtual corresponding to the first Alias */
hostinfo_t hostinfo;
@@ -559,26 +576,26 @@
hostinfo.id = 0;
host = read_host(hoststatsmem, &hostinfo);
if (host == NULL) {
- return 500;
+ return MHOSTRD;
}
/* Now update each context from Context: part */
insert_update_contexts(contextstatsmem, phost->context, node->mess.id,
host->vhost, status);
- return OK;
+ return NULL;
}
-static int process_enable(request_rec *r, char *buff)
+static char * process_enable(request_rec *r, char *buff)
{
return process_appl_cmd(r, buff, ENABLED);
}
-static int process_disable(request_rec *r, char *buff)
+static char * process_disable(request_rec *r, char *buff)
{
return process_appl_cmd(r, buff, DISABLED);
}
-static int process_stop(request_rec *r, char *buff)
+static char * process_stop(request_rec *r, char *buff)
{
return process_appl_cmd(r, buff, STOPPED);
}
-static int process_remove(request_rec *r, char *buff)
+static char * process_remove(request_rec *r, char *buff)
{
return process_appl_cmd(r, buff, REMOVE);
}
@@ -600,20 +617,20 @@
* Load 0 : Standby.
* Load 1-100 : Load factor.
*/
-static int process_status(request_rec *r, char *buff)
+static char * process_status(request_rec *r, char *buff)
{
int Load;
nodeinfo_t nodeinfo;
nodeinfo_t *node;
char **ptr = process_buff(r, buff);
if (ptr == NULL)
- return 500;
+ return SMESPAR;
int i = 0;
while (ptr[i]) {
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute))
- return 500;
+ return SROUBIG;
strcpy(nodeinfo.mess.JVMRoute, ptr[i+1]);
nodeinfo.mess.id = 0;
}
@@ -621,7 +638,7 @@
Load = atoi(ptr[i+1]);
}
else
- return 500;
+ return SBADFLD;
i++;
i++;
}
@@ -629,7 +646,7 @@
/* Read the node */
node = read_node(nodestatsmem, &nodeinfo);
if (node == NULL)
- return 500;
+ return MNODERD;
/*
* If the node is usualable do a ping/pong to prevent Split-Brain Syndrome
@@ -648,7 +665,7 @@
ap_rprintf(r, "&id=%d",
ap_scoreboard_image->global->restart_time);
ap_rprintf(r, "\n");
- return OK;
+ return NULL;
}
/*
@@ -695,6 +712,8 @@
ours = 1;
else if (strcasecmp(r->method, "DUMP") == 0)
ours = 1;
+ else if (strcasecmp(r->method, "ERROR") == 0)
+ ours = 1;
if (ours) {
/* The method one of ours */
r->handler = "mod-cluster";
@@ -709,8 +728,10 @@
static int manager_handler(request_rec *r)
{
apr_bucket_brigade *input_brigade;
+ char *errstring = NULL;
char buff[4096];
int bufsiz=sizeof(buff);
+
if (strcmp(r->handler, "mod-cluster"))
return DECLINED;
input_brigade = apr_brigade_create(r->connection->pool,
r->connection->bucket_alloc);
@@ -719,24 +740,28 @@
buff[bufsiz] = '\0';
decodeenc(buff);
if (strcasecmp(r->method, "CONFIG") == 0)
- return(process_config(r, buff));
+ errstring = process_config(r, buff);
/* Application handling */
else if (strcasecmp(r->method, "ENABLE-APP") == 0)
- return(process_enable(r, buff));
+ errstring = process_enable(r, buff);
else if (strcasecmp(r->method, "DISABLE-APP") == 0)
- return(process_disable(r, buff));
+ errstring = process_disable(r, buff);
else if (strcasecmp(r->method, "STOP-APP") == 0)
- return(process_stop(r, buff));
+ errstring = process_stop(r, buff);
else if (strcasecmp(r->method, "REMOVE-APP") == 0)
- return(process_remove(r, buff));
+ errstring = process_remove(r, buff);
/* Status handling */
else if (strcasecmp(r->method, "STATUS") == 0)
- return(process_status(r, buff));
+ errstring = process_status(r, buff);
else if (strcasecmp(r->method, "DUMP") == 0)
- return(process_dump(r, buff));
+ errstring = process_dump(r, buff);
else {
- /* The command is not supported */
- r->status_line = apr_psprintf(r->pool, "%3.3u VERSION %d.%d.%d",
500, 0, 0, 0);
+ errstring = SCMDUNS;
+ }
+
+ /* Check error string and build the error message */
+ if (errstring) {
+ r->status_line = apr_psprintf(r->pool, "%3.3u %d.%d.%d
\"%s\"", 500, 0, 0, 0, errstring);
return 500;
}