Author: jfrederic.clere(a)jboss.com
Date: 2008-03-16 17:00:11 -0400 (Sun, 16 Mar 2008)
New Revision: 1440
Modified:
sandbox/httpd/src/native/common/node.c
sandbox/httpd/src/native/common/node.h
sandbox/httpd/src/native/mod_manager/mod_manager.c
sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Add logic to create the node.
Modified: sandbox/httpd/src/native/common/node.c
===================================================================
--- sandbox/httpd/src/native/common/node.c 2008-03-16 19:21:42 UTC (rev 1439)
+++ sandbox/httpd/src/native/common/node.c 2008-03-16 21:00:11 UTC (rev 1440)
@@ -64,9 +64,9 @@
}
storename = apr_pstrcat(p, string, NODEEXE, NULL);
if (type)
- rv = ptr->storage->ap_slotmem_create(&ptr->slotmem, storename,
sizeof(nodeinfo_t) + SIZEOFSCORE, *num, p);
+ rv = ptr->storage->ap_slotmem_create(&ptr->slotmem, storename,
sizeof(nodeinfo_t), *num, p);
else {
- apr_size_t size = sizeof(nodeinfo_t) + SIZEOFSCORE;
+ apr_size_t size = sizeof(nodeinfo_t);
rv = ptr->storage->ap_slotmem_attach(&ptr->slotmem, storename,
&size, num, p);
}
if (rv != APR_SUCCESS) {
@@ -87,11 +87,9 @@
{
nodeinfo_t *in = (nodeinfo_t *)*data;
nodeinfo_t *ou = (nodeinfo_t *)mem;
- if (strcmp(in->mess.hostname, ou->mess.hostname) == 0) {
- char *ptr = (char *) ou + sizeof(nodeinfo_t);
+ if (strcmp(in->mess.JVMRoute, ou->mess.JVMRoute) == 0) {
memcpy(ou, in, sizeof(nodeinfo_t));
ou->mess.id = id;
- ou->status = ptr;
ou->updatetime = apr_time_sec(apr_time_now());
*data = ou;
return APR_SUCCESS;
@@ -118,6 +116,10 @@
memcpy(ou, node, sizeof(nodeinfo_t));
ou->mess.id = ident;
ou->updatetime = apr_time_sec(apr_time_now());
+
+ /* set of offset to the proxy_worker_stat */
+ ou->status = sizeof(nodemess_t) + sizeof(unsigned long) + sizeof(ou->balancer)
+ sizeof(int);
+
return APR_SUCCESS;
}
@@ -130,7 +132,7 @@
static apr_status_t loc_read_node(void* mem, void **data, int id, apr_pool_t *pool) {
nodeinfo_t *in = (nodeinfo_t *)*data;
nodeinfo_t *ou = (nodeinfo_t *)mem;
- if (strcmp(in->mess.hostname, ou->mess.hostname) == 0) {
+ if (strcmp(in->mess.JVMRoute, ou->mess.JVMRoute) == 0) {
*data = ou;
return APR_SUCCESS;
}
Modified: sandbox/httpd/src/native/common/node.h
===================================================================
--- sandbox/httpd/src/native/common/node.h 2008-03-16 19:21:42 UTC (rev 1439)
+++ sandbox/httpd/src/native/common/node.h 2008-03-16 21:00:11 UTC (rev 1440)
@@ -48,36 +48,38 @@
unsigned short __pad;
};
-/* status of the node received from jboss nodes. */
+/* configuration of the node received from jboss cluster. */
struct nodemess {
- /* part receive from the node */
- char hostname[40]; /* 000: something like ajp://localhost:8009 */
- char strtime[8]; /* 040: date when send by the node */
- struct contact contact; /* 048: IP/port (node view) */
- char route[8]; /* 068: JVM route */
+ char JVMRoute[20];
+ char Domain[20];
+ char Host[64];
+ char Port[7];
+ char Type[6];
/* XXX: add the load balancing information */
- char schni[44]; /* 076: hugly filler */
+ char schni[44]; /* hugly filler */
+ char strtime[8]; /* date when send by the node */
+
/* part updated in httpd */
- int id; /* 120: id in table and worker it */
- /* 124: end */
+ int id; /* id in table and worker it */
};
typedef struct nodemess nodemess_t;
+#define SIZEOFSCORE 200 /* size of the proxy_worker_stat structure */
+
/* status of the node as read/store in httpd. */
struct nodeinfo {
- /* received from jboss/tomcat */
+ /* config from jboss/tomcat */
nodemess_t mess;
/* filled by httpd */
- unsigned long updatetime; /* 124: time of last received message */
- char balancer[40]; /* 128: name of the balancer */
- void *status; /* 168: to the proxy_worker_stat structure */
- /* 172: end */
+ unsigned long updatetime; /* time of last received message */
+ char balancer[40]; /* name of the balancer */
+ int status; /* offset to the proxy_worker_stat structure */
+ char stat[SIZEOFSCORE]; /* to store the status */
};
typedef struct nodeinfo nodeinfo_t;
-#define SIZEOFSCORE 100 /* size of the proxy_worker_stat structure */
/**
* Insert(alloc) and update a node record in the shared table
Modified: sandbox/httpd/src/native/mod_manager/mod_manager.c
===================================================================
--- sandbox/httpd/src/native/mod_manager/mod_manager.c 2008-03-16 19:21:42 UTC (rev 1439)
+++ sandbox/httpd/src/native/mod_manager/mod_manager.c 2008-03-16 21:00:11 UTC (rev 1440)
@@ -13,6 +13,7 @@
*/
#include "apr_strings.h"
+#include "apr_lib.h"
#define CORE_PRIVATE
@@ -49,20 +50,13 @@
int maxcontext;
/* max munber of node supported */
int maxnode;
- /* enablePort */
- int enable;
+ /* Balancer name */
+ char *balancername;
/* store the balancer names */
struct baldata *baldata;
} mod_manager_config;
-/* message from the node */
-typedef struct node_mess
-{
- int type;
- nodeinfo_t node;
-} node_mess;
-
/*
* routines for the node_storage_method
*/
@@ -142,6 +136,145 @@
*/
return OK;
}
+static char **process_buff(request_rec *r, char *buff)
+{
+ int i = 0;
+ char *s = buff;
+ char **ptr = NULL;
+ for (; *s != '\0'; s++) {
+ if (*s == '&') {
+ i++;
+ }
+ }
+ ptr = apr_palloc(r->pool, sizeof(char *) * ((2 *i) +1));
+ if (ptr == NULL)
+ return NULL;
+
+ s = buff;
+ ptr[0] = s;
+ ptr[2*i] = NULL;
+ i = 1;
+ for (; *s != '\0'; s++) {
+ if (*s == '&' || *s == '=') {
+ *s = '\0';
+ ptr[i] = s + 1;
+ i++;
+ }
+ }
+ return ptr;
+}
+
+/*
+ * Process a CONFIG message
+ * JvmRoute?: <JvmRoute>
+ * Domain: <Domain>
+ * <Host: <Node IP>
+ * Port: <Connector Port>
+ * Type: <Type of the connector>
+ * (<node conf>
+ * Virtual hosts in JBossAS
+ * Alias: <vhost list>
+ * Context corresponding to the applications.
+ * Context: <context list>
+ */
+static int process_config(request_rec *r, char *buff)
+{
+ /* Process the node description */
+ nodeinfo_t nodeinfo;
+ char *JVMRoute;
+ char *Domain;
+ char *Host;
+ char *Port;
+ char *Type;
+ /* XXX node conf */
+ char **ptr = process_buff(r, buff);
+ if (ptr == NULL)
+ return 500;
+ int i = 0;
+ while (ptr[i]) {
+ if (strcasecmp(ptr[i], "JVMRoute") == 0) {
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.JVMRoute))
+ return 500;
+ strcpy(nodeinfo.mess.JVMRoute, ptr[i+1]);
+ }
+ if (strcasecmp(ptr[i], "Domain") == 0) {
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Domain))
+ return 500;
+ strcpy(nodeinfo.mess.Domain, ptr[i+1]);
+ }
+ if (strcasecmp(ptr[i], "Host") == 0) {
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Host))
+ return 500;
+ strcpy(nodeinfo.mess.Host, ptr[i+1]);
+ }
+ if (strcasecmp(ptr[i], "Port") == 0) {
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Port))
+ return 500;
+ strcpy(nodeinfo.mess.Port, ptr[i+1]);
+ }
+ if (strcasecmp(ptr[i], "Type") == 0) {
+ if (strlen(ptr[i+1])>=sizeof(nodeinfo.mess.Type))
+ return 500;
+ strcpy(nodeinfo.mess.Type, ptr[i+1]);
+ }
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "manager_handler %s %s",
ptr[i], ptr[i+1]);
+ i++;
+ i++;
+ }
+ /* Read the balancer name */
+ mod_manager_config *mconf = ap_get_module_config(r->server->module_config,
&manager_module);
+ strcpy(nodeinfo.balancer,mconf->balancername);
+
+ /* Insert or update node description */
+ if (insert_update_node(nodestatsmem, &nodeinfo) != APR_SUCCESS)
+ return 500;
+ return OK;
+}
+/* Process an enable application message */
+static int process_enable(request_rec *r, char *buff)
+{
+ return OK;
+}
+static int process_disable(request_rec *r, char *buff)
+{
+ return OK;
+}
+static int process_stop(request_rec *r, char *buff)
+{
+ return OK;
+}
+static int process_remove(request_rec *r, char *buff)
+{
+ return OK;
+}
+static int process_status(request_rec *r, char *buff)
+{
+ return OK;
+}
+
+/*
+ * Decodes a '%' escaped string, and returns the number of characters
+ * (From mod_proxy_ftp.c).
+ */
+static int decodeenc(char *x)
+{
+ int i, j, ch;
+
+ if (x[0] == '\0')
+ return 0; /* special case for no characters */
+ for (i = 0, j = 0; x[i] != '\0'; i++, j++) {
+ /* decode it if not already done */
+ ch = x[i];
+ if (ch == '%' && apr_isxdigit(x[i + 1]) &&
apr_isxdigit(x[i + 2])) {
+ ch = ap_proxy_hex2c(&x[i + 1]);
+ i += 2;
+ }
+ x[j] = ch;
+ }
+ x[j] = '\0';
+ return j;
+}
+
/* Process the requests from the ModClusterService */
static int manager_handler(request_rec *r)
{
@@ -155,6 +288,27 @@
apr_brigade_flatten(input_brigade, buff, &bufsiz);
buff[bufsiz] = '\0';
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "%s %s manager_handler buff
%s", r->method, r->uri, buff);
+ decodeenc(buff);
+ if (strcasecmp(r->method, "CONFIG") == 0)
+ return(process_config(r, buff));
+ /* Application handling */
+ else if (strcasecmp(r->method, "ENABLE-APP") == 0)
+ return(process_enable(r, buff));
+ else if (strcasecmp(r->method, "DISABLE-APP") == 0)
+ return(process_disable(r, buff));
+ else if (strcasecmp(r->method, "STOP-APP") == 0)
+ return(process_stop(r, buff));
+ else if (strcasecmp(r->method, "REMOVE-APP") == 0)
+ return(process_remove(r, buff));
+ /* Status handling */
+ else if (strcasecmp(r->method, "STATUS") == 0)
+ return(process_status(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);
+ return 500;
+ }
+
return (OK);
}
@@ -179,6 +333,12 @@
mconf->basefilename = apr_pstrdup(cmd->pool, word);
return NULL;
}
+AP_DECLARE_NONSTD(const char *) cmd_manager_balancername(cmd_parms *cmd, void *mconfig,
const char *word)
+{
+ mod_manager_config *mconf = ap_get_module_config(cmd->server->module_config,
&manager_module);
+ mconf->balancername = apr_pstrdup(cmd->pool, word);
+ return NULL;
+}
static const command_rec manager_cmds[] =
{
AP_INIT_TAKE1(
@@ -202,6 +362,13 @@
OR_ALL,
"MemManagerFile - base name of the files used to create/attach to shared
memory"
),
+ AP_INIT_TAKE1(
+ "ManagerBalancerName",
+ cmd_manager_balancername,
+ NULL,
+ OR_ALL,
+ "ManagerBalancerName - name of the balancer corresponding to the
manager"
+ ),
{NULL}
};
@@ -230,7 +397,7 @@
mconf->basefilename = NULL;
mconf->maxcontext = DEFMAXCONTEXT;
mconf->maxnode = DEFMAXNODE;
- mconf->enable = 0;
+ mconf->balancername = NULL;
mconf->baldata = NULL;
return mconf;
}
@@ -255,7 +422,7 @@
mconf->basefilename = NULL;
mconf->maxcontext = DEFMAXCONTEXT;
mconf->maxnode = DEFMAXNODE;
- mconf->enable = 0;
+ mconf->balancername = NULL;
mconf->baldata = NULL;
if (mconf2->basefilename)
@@ -273,10 +440,10 @@
else if (mconf1->maxnode != DEFMAXNODE)
mconf->maxnode = mconf1->maxnode;
- if (mconf2->enable)
- mconf->enable = mconf2->enable;
- else if (mconf1->enable)
- mconf->enable = mconf1->enable;
+ if (mconf2->balancername)
+ mconf->balancername = mconf2->balancername;
+ else if (mconf1->balancername)
+ mconf->balancername = mconf1->balancername;
/* XXX: Shouldn't be the baldata chains duplicated */
if (mconf2->baldata)
Modified: sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-03-16 19:21:42 UTC
(rev 1439)
+++ sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-03-16 21:00:11 UTC
(rev 1440)
@@ -51,29 +51,39 @@
request_rec *r, proxy_worker **worker,
nodeinfo_t *node)
{
- char *name;
- char *p;
- proxy_worker_stat *proxy_worker_stat;
+ char url[6+64+7+4]; /* Type :// Host : Port */
/* build the name (scheme and port) when needed */
- p = strchr(node->mess.hostname, ':');
- if (p == NULL || p[1] != '/' || p[2] != '/' || p[3] == '\0')
{
- name = apr_pstrcat(conf->pool, "http://", node->mess.hostname,
NULL);
- } else {
- name = apr_pstrdup(conf->pool, node->mess.hostname);
- }
+ strcpy(url, node->mess.Type);
+ strcat(url, "://");
+ strcat(url, node->mess.Host);
+ strcat(url, ":");
+ strcat(url, node->mess.Port);
- *worker = ap_proxy_get_worker(conf->pool, conf, name);
+ *worker = ap_proxy_get_worker(conf->pool, conf, url);
if (*worker == NULL) {
+ char *ptr;
+ proxy_worker *proxy_worker;
+
/* creates it */
- struct proxy_worker *proxy_worker;
- ap_proxy_add_worker(worker, conf->pool, conf, name);
+ const char *err = ap_proxy_add_worker(worker, conf->pool, conf, url);
+ if (err) {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, r->server,
+ "Created: worker for %s failed: %s", url, err);
+ return;
+ }
proxy_worker = (struct proxy_worker *) *worker;
- proxy_worker->s = node->status;
+ /* Get the shared memory for this worker */
+ ptr = (char *) node;
+ ptr = ptr + node->status;
+ proxy_worker->s = (proxy_worker_stat *) ptr;
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "Created: worker for %s", url);
+ proxy_worker->s->status = PROXY_WORKER_INITIALIZED;
+
ap_proxy_add_worker_to_balancer(conf->pool, balancer, *worker);
- proxy_worker->s->status = PROXY_WORKER_INITIALIZED;
- strncpy(proxy_worker->s->route, node->mess.route,
PROXY_WORKER_MAX_ROUTE_SIZ);
+ strncpy(proxy_worker->s->route, node->mess.JVMRoute,
PROXY_WORKER_MAX_ROUTE_SIZ);
proxy_worker->s->route[PROXY_WORKER_MAX_ROUTE_SIZ] = '\0';
/* XXX: We need that information from TC */
proxy_worker->s->redirect[0] = '\0';