Author: jfrederic.clere(a)jboss.com
Date: 2008-05-22 09:26:46 -0400 (Thu, 22 May 2008)
New Revision: 1612
Modified:
trunk/mod_cluster/native/mod_manager/mod_manager.c
Log:
Add headers for the errors.
Add default values for node and balancer.
Add insert/update the balancer.
Modified: trunk/mod_cluster/native/mod_manager/mod_manager.c
===================================================================
--- trunk/mod_cluster/native/mod_manager/mod_manager.c 2008-05-22 11:25:43 UTC (rev 1611)
+++ trunk/mod_cluster/native/mod_manager/mod_manager.c 2008-05-22 13:26:46 UTC (rev 1612)
@@ -51,6 +51,7 @@
#define DEFMAXHOST 20
/* Error messages */
+#define TYPESYNTAX 1
#define SMESPAR "SYNTAX: Can't parse message"
#define SBALBIG "SYNTAX: Balancer field too big"
#define SROUBIG "SYNTAX: JVMRoute field too big"
@@ -63,10 +64,15 @@
#define SBADFLD "SYNTAX: Invalid field name in message"
#define SCMDUNS "SYNTAX: Command is not supported"
+#define TYPEMEM 2
#define MNODEUI "MEM: Can't update or insert node"
+#define MBALAUI "MEM: Can't update or insert balancer"
#define MNODERD "MEM: Can't read node"
#define MHOSTRD "MEM: Can't read host alias"
+/* Protocol version supported */
+#define VERSION_PROTOCOL "0.0.0"
+
/* shared memory */
mem_t *contextstatsmem = NULL;
mem_t *nodestatsmem = NULL;
@@ -254,17 +260,17 @@
char *s = buff;
char **ptr = NULL;
for (; *s != '\0'; s++) {
- if (*s == '&') {
+ if (*s == '&' || *s == '=') {
i++;
}
}
- ptr = apr_palloc(r->pool, sizeof(char *) * ((2 *i) +1));
+ ptr = apr_palloc(r->pool, sizeof(char *) * (i + 1));
if (ptr == NULL)
return NULL;
s = buff;
ptr[0] = s;
- ptr[2*i] = NULL;
+ ptr[i] = NULL;
i = 1;
for (; *s != '\0'; s++) {
if (*s == '&' || *s == '=') {
@@ -358,10 +364,11 @@
* Context corresponding to the applications.
* Context: <context list>
*/
-static char * process_config(request_rec *r, char *buff)
+static char * process_config(request_rec *r, char *buff, int *errtype)
{
- /* Process the node description */
+ /* Process the node/balancer description */
nodeinfo_t nodeinfo;
+ balancerinfo_t balancerinfo;
char *JVMRoute;
char *Domain;
char *Host;
@@ -373,8 +380,10 @@
struct cluster_host *phost;
char **ptr = process_buff(r, buff);
- if (ptr == NULL)
+ if (ptr == NULL) {
+ *errtype = TYPESYNTAX;
return SMESPAR;
+ }
vhost = apr_palloc(r->pool, sizeof(struct cluster_host));
/* Map nothing by default */
@@ -383,37 +392,67 @@
vhost->next = NULL;
phost = vhost;
+ /* Fill default nodes values */
+ memset(&nodeinfo.mess, '\0', sizeof(nodeinfo.mess));
+ strcpy(nodeinfo.mess.balancer, "mycluster");
+ strcpy(nodeinfo.mess.Host, "localhost");
+ strcpy(nodeinfo.mess.Port, "8009");
+ strcpy(nodeinfo.mess.Type, "ajp");
nodeinfo.mess.reversed = 0;
+
+ /* Fill default balancer values */
+ memset(&balancerinfo, '\0', sizeof(balancerinfo));
+ strcpy(balancerinfo.balancer, "mycluster");
+ balancerinfo.StickySession = 1;
+ strcpy(balancerinfo.StickySessionCookie, "JSESSIONID");
+ strcpy(balancerinfo.StickySessionPath, "jsessionid");
+ balancerinfo.Maxattempts = 1;
+
int i = 0;
while (ptr[i]) {
+ /* XXX: balancer part */
if (strcasecmp(ptr[i], "Balancer") == 0) {
- if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.balancer))
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.balancer)) {
+ *errtype = TYPESYNTAX;
return SBALBIG;
+ }
strcpy(nodeinfo.mess.balancer, ptr[i+1]);
+ strcpy(balancerinfo.balancer, ptr[i+1]);
}
+ /* XXX: Node part */
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
- if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute))
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute)) {
+ *errtype = TYPESYNTAX;
return SROUBIG;
+ }
strcpy(nodeinfo.mess.JVMRoute, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Domain") == 0) {
- if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Domain))
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Domain)) {
+ *errtype = TYPESYNTAX;
return SDOMBIG;
+ }
strcpy(nodeinfo.mess.Domain, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Host") == 0) {
- if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Host))
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Host)) {
+ *errtype = TYPESYNTAX;
return SHOSBIG;
+ }
strcpy(nodeinfo.mess.Host, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Port") == 0) {
- if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Port))
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Port)) {
+ *errtype = TYPESYNTAX;
return SPORBIG;
+ }
strcpy(nodeinfo.mess.Port, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Type") == 0) {
- if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Type))
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Type)) {
+ *errtype = TYPESYNTAX;
return STYPBIG;
+ }
strcpy(nodeinfo.mess.Type, ptr[i+1]);
}
if (strcasecmp(ptr[i], "Reversed") == 0) {
@@ -423,6 +462,7 @@
}
if (strcasecmp(ptr[i], "Alias") == 0) {
if (phost->host && !phost->context) {
+ *errtype = TYPESYNTAX;
return SALIBAD;
}
if (phost->host) {
@@ -437,6 +477,7 @@
}
if (strcasecmp(ptr[i], "Context") == 0) {
if (phost->context) {
+ *errtype = TYPESYNTAX;
return SCONBAD;
}
phost->context = ptr[i+1];
@@ -444,12 +485,18 @@
i++;
i++;
}
- /* XXX: Read the default balancer name is balancer empty */
+ /* Insert or update balancer description */
+ if (insert_update_balancer(balancerstatsmem, &balancerinfo) != APR_SUCCESS) {
+ *errtype = TYPEMEM;
+ return MBALAUI;
+ }
/* Insert or update node description */
int id;
- if (insert_update_node(nodestatsmem, &nodeinfo, &id) != APR_SUCCESS)
+ if (insert_update_node(nodestatsmem, &nodeinfo, &id) != APR_SUCCESS) {
+ *errtype = TYPEMEM;
return MNODEUI;
+ }
/* Insert the Alias and corresponding Context */
phost = vhost;
@@ -465,7 +512,7 @@
/*
* Process a DUMP command.
*/
-static char * process_dump(request_rec *r, char *buff)
+static char * process_dump(request_rec *r, char *buff, int *errtype)
{
int size, i;
int *id;
@@ -507,7 +554,7 @@
}
/* Process an enable/disable/stop application message */
-static char * process_appl_cmd(request_rec *r, char *buff, int status)
+static char * process_appl_cmd(request_rec *r, char *buff, int status, int *errtype)
{
char *JVMRoute;
nodeinfo_t nodeinfo;
@@ -516,8 +563,10 @@
struct cluster_host *phost;
char **ptr = process_buff(r, buff);
- if (ptr == NULL)
+ if (ptr == NULL) {
+ *errtype = TYPESYNTAX;
return SMESPAR;
+ }
/* Map nothing by default */
vhost->host = NULL;
@@ -529,13 +578,16 @@
int i = 0;
while (ptr[i]) {
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
- if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute))
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute)) {
+ *errtype = TYPESYNTAX;
return SROUBIG;
+ }
strcpy(nodeinfo.mess.JVMRoute, ptr[i+1]);
nodeinfo.mess.id = 0;
}
if (strcasecmp(ptr[i], "Alias") == 0) {
if (phost->host && !phost->context) {
+ *errtype = TYPESYNTAX;
return SALIBAD;
}
if (phost->host) {
@@ -550,6 +602,7 @@
}
if (strcasecmp(ptr[i], "Context") == 0) {
if (phost->context) {
+ *errtype = TYPESYNTAX;
return SCONBAD;
}
phost->context = ptr[i+1];
@@ -560,8 +613,10 @@
/* Read the node */
node = read_node(nodestatsmem, &nodeinfo);
- if (node == NULL)
+ if (node == NULL) {
+ *errtype = TYPEMEM;
return MNODERD;
+ }
/* Read the ID of the virtual corresponding to the first Alias */
hostinfo_t hostinfo;
@@ -576,6 +631,7 @@
hostinfo.id = 0;
host = read_host(hoststatsmem, &hostinfo);
if (host == NULL) {
+ *errtype = TYPEMEM;
return MHOSTRD;
}
@@ -583,21 +639,21 @@
insert_update_contexts(contextstatsmem, phost->context, node->mess.id,
host->vhost, status);
return NULL;
}
-static char * process_enable(request_rec *r, char *buff)
+static char * process_enable(request_rec *r, char *buff, int *errtype)
{
- return process_appl_cmd(r, buff, ENABLED);
+ return process_appl_cmd(r, buff, ENABLED, errtype);
}
-static char * process_disable(request_rec *r, char *buff)
+static char * process_disable(request_rec *r, char *buff, int *errtype)
{
- return process_appl_cmd(r, buff, DISABLED);
+ return process_appl_cmd(r, buff, DISABLED, errtype);
}
-static char * process_stop(request_rec *r, char *buff)
+static char * process_stop(request_rec *r, char *buff, int *errtype)
{
- return process_appl_cmd(r, buff, STOPPED);
+ return process_appl_cmd(r, buff, STOPPED, errtype);
}
-static char * process_remove(request_rec *r, char *buff)
+static char * process_remove(request_rec *r, char *buff, int *errtype)
{
- return process_appl_cmd(r, buff, REMOVE);
+ return process_appl_cmd(r, buff, REMOVE, errtype);
}
/*
@@ -617,36 +673,44 @@
* Load 0 : Standby.
* Load 1-100 : Load factor.
*/
-static char * process_status(request_rec *r, char *buff)
+static char * process_status(request_rec *r, char *buff, int *errtype)
{
int Load;
nodeinfo_t nodeinfo;
nodeinfo_t *node;
char **ptr = process_buff(r, buff);
- if (ptr == NULL)
+ if (ptr == NULL) {
+ *errtype = TYPESYNTAX;
return SMESPAR;
+ }
int i = 0;
while (ptr[i]) {
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
- if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute))
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute)) {
+ *errtype = TYPESYNTAX;
return SROUBIG;
+ }
strcpy(nodeinfo.mess.JVMRoute, ptr[i+1]);
nodeinfo.mess.id = 0;
}
else if (strcasecmp(ptr[i], "Load") == 0) {
Load = atoi(ptr[i+1]);
}
- else
+ else {
+ *errtype = TYPESYNTAX;
return SBADFLD;
+ }
i++;
i++;
}
/* Read the node */
node = read_node(nodestatsmem, &nodeinfo);
- if (node == NULL)
+ if (node == NULL) {
+ *errtype = TYPEMEM;
return MNODERD;
+ }
/*
* If the node is usualable do a ping/pong to prevent Split-Brain Syndrome
@@ -729,6 +793,7 @@
{
apr_bucket_brigade *input_brigade;
char *errstring = NULL;
+ int errtype = 0;
char buff[4096];
int bufsiz=sizeof(buff);
@@ -740,29 +805,43 @@
buff[bufsiz] = '\0';
decodeenc(buff);
if (strcasecmp(r->method, "CONFIG") == 0)
- errstring = process_config(r, buff);
+ errstring = process_config(r, buff, &errtype);
/* Application handling */
else if (strcasecmp(r->method, "ENABLE-APP") == 0)
- errstring = process_enable(r, buff);
+ errstring = process_enable(r, buff, &errtype);
else if (strcasecmp(r->method, "DISABLE-APP") == 0)
- errstring = process_disable(r, buff);
+ errstring = process_disable(r, buff, &errtype);
else if (strcasecmp(r->method, "STOP-APP") == 0)
- errstring = process_stop(r, buff);
+ errstring = process_stop(r, buff, &errtype);
else if (strcasecmp(r->method, "REMOVE-APP") == 0)
- errstring = process_remove(r, buff);
+ errstring = process_remove(r, buff, &errtype);
/* Status handling */
else if (strcasecmp(r->method, "STATUS") == 0)
- errstring = process_status(r, buff);
+ errstring = process_status(r, buff, &errtype);
else if (strcasecmp(r->method, "DUMP") == 0)
- errstring = process_dump(r, buff);
+ errstring = process_dump(r, buff, &errtype);
else {
errstring = SCMDUNS;
+ errtype = TYPESYNTAX;
}
/* 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;
+ 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);
+ return 500;
}
return (OK);