Author: jfrederic.clere(a)jboss.com
Date: 2008-05-07 03:49:47 -0400 (Wed, 07 May 2008)
New Revision: 1594
Added:
sandbox/httpd/src/native/common/balancer.c
sandbox/httpd/src/native/common/balancer.h
Modified:
sandbox/httpd/src/native/common/Makefile.in
sandbox/httpd/src/native/mod_manager/Makefile.in
sandbox/httpd/src/native/mod_manager/mod_manager.c
sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Add the table to store balancers.
Logic to create it. (From the ManagerBalancerName name for the moment).
Modified: sandbox/httpd/src/native/common/Makefile.in
===================================================================
--- sandbox/httpd/src/native/common/Makefile.in 2008-05-06 15:24:35 UTC (rev 1593)
+++ sandbox/httpd/src/native/common/Makefile.in 2008-05-07 07:49:47 UTC (rev 1594)
@@ -15,7 +15,7 @@
INCLUDES=-I$(APACHE_BASE)/include/
LINK_PROG = $(LIBTOOL) $(LTFLAGS) --mode=link $(LT_LDFLAGS) $(COMPILE) $(ALL_LDFLAGS) -o
$@
-OBJS=sharedmem_util.lo node.lo context.lo host.lo
+OBJS=sharedmem_util.lo node.lo context.lo host.lo balancer.lo
all: $(OBJS)
Added: sandbox/httpd/src/native/common/balancer.c
===================================================================
--- sandbox/httpd/src/native/common/balancer.c (rev 0)
+++ sandbox/httpd/src/native/common/balancer.c 2008-05-07 07:49:47 UTC (rev 1594)
@@ -0,0 +1,228 @@
+/*
+ * mod_cluster
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision$
+ */
+
+/**
+ * @file balancer.c
+ * @brief balancer description Storage Module for Apache
+ *
+ * @defgroup MEM balancers
+ * @ingroup APACHE_MODS
+ * @{
+ */
+
+#include "apr.h"
+#include "apr_strings.h"
+#include "apr_pools.h"
+#include "apr_time.h"
+
+#include "balancer.h"
+#include "slotmem.h"
+
+struct mem {
+ ap_slotmem_t *slotmem;
+ const slotmem_storage_method *storage;
+ int num;
+ apr_pool_t *p;
+};
+
+static mem_t * create_attach_mem_balancer(char *string, int *num, int type, apr_pool_t
*p) {
+ mem_t *ptr;
+ const char *storename;
+ apr_status_t rv;
+
+ ptr = apr_pcalloc(p, sizeof(mem_t));
+ if (!ptr) {
+ return NULL;
+ }
+ ptr->storage = mem_getstorage(p, "shared");
+ if (!ptr->storage) {
+ return NULL;
+ }
+ storename = apr_pstrcat(p, string, BALANCEREXE, NULL);
+ if (type)
+ rv = ptr->storage->ap_slotmem_create(&ptr->slotmem, storename,
sizeof(balancerinfo_t), *num, p);
+ else {
+ apr_size_t size = sizeof(balancerinfo_t);
+ rv = ptr->storage->ap_slotmem_attach(&ptr->slotmem, storename,
&size, num, p);
+ }
+ if (rv != APR_SUCCESS) {
+ return NULL;
+ }
+ ptr->num = *num;
+ ptr->p = p;
+ return ptr;
+}
+/**
+ * Insert(alloc) and update a balancer record in the shared table
+ * @param pointer to the shared table.
+ * @param balancer balancer to store in the shared table.
+ * @return APR_SUCCESS if all went well
+ *
+ */
+static apr_status_t insert_update(void* mem, void **data, int id, apr_pool_t *pool)
+{
+ balancerinfo_t *in = (balancerinfo_t *)*data;
+ balancerinfo_t *ou = (balancerinfo_t *)mem;
+ if (strcmp(in->balancer, ou->balancer) == 0) {
+ memcpy(ou, in, sizeof(balancerinfo_t));
+ ou->id = id;
+ ou->updatetime = apr_time_sec(apr_time_now());
+ *data = ou;
+ return APR_SUCCESS;
+ }
+ return APR_NOTFOUND;
+}
+apr_status_t insert_update_balancer(mem_t *s, balancerinfo_t *balancer)
+{
+ apr_status_t rv;
+ balancerinfo_t *ou;
+ int ident;
+
+ balancer->id = 0;
+ rv = s->storage->ap_slotmem_do(s->slotmem, insert_update, &balancer,
s->p);
+ if (balancer->id != 0 && rv == APR_SUCCESS) {
+ return APR_SUCCESS; /* updated */
+ }
+
+ /* we have to insert it */
+ rv = s->storage->ap_slotmem_alloc(s->slotmem, &ident, (void **)
&ou);
+ if (rv != APR_SUCCESS) {
+ return rv;
+ }
+ memcpy(ou, balancer, sizeof(balancerinfo_t));
+ ou->id = ident;
+ ou->updatetime = apr_time_sec(apr_time_now());
+
+ return APR_SUCCESS;
+}
+
+/**
+ * read a balancer record from the shared table
+ * @param pointer to the shared table.
+ * @param balancer balancer to read from the shared table.
+ * @return address of the read balancer or NULL if error.
+ */
+static apr_status_t loc_read_balancer(void* mem, void **data, int id, apr_pool_t *pool)
{
+ balancerinfo_t *in = (balancerinfo_t *)*data;
+ balancerinfo_t *ou = (balancerinfo_t *)mem;
+
+ if (strcmp(in->balancer, ou->balancer) == 0) {
+ *data = ou;
+ return APR_SUCCESS;
+ }
+ return APR_NOTFOUND;
+}
+APR_DECLARE(balancerinfo_t *) read_balancer(mem_t *s, balancerinfo_t *balancer)
+{
+ apr_status_t rv;
+ balancerinfo_t *ou = balancer;
+
+ if (balancer->id)
+ rv = s->storage->ap_slotmem_mem(s->slotmem, balancer->id, (void **)
&ou);
+ else {
+ rv = s->storage->ap_slotmem_do(s->slotmem, loc_read_balancer, &ou,
s->p);
+ }
+ if (rv == APR_SUCCESS)
+ return ou;
+ return NULL;
+}
+/**
+ * get a balancer record from the shared table
+ * @param pointer to the shared table.
+ * @param balancer address where the balancer is locate in the shared table.
+ * @param ids in the balancer table.
+ * @return APR_SUCCESS if all went well
+ */
+APR_DECLARE(apr_status_t) get_balancer(mem_t *s, balancerinfo_t **balancer, int ids)
+{
+ return(s->storage->ap_slotmem_mem(s->slotmem, ids, (void **) balancer));
+}
+
+/**
+ * remove(free) a balancer record from the shared table
+ * @param pointer to the shared table.
+ * @param balancer balancer to remove from the shared table.
+ * @return APR_SUCCESS if all went well
+ */
+APR_DECLARE(apr_status_t) remove_balancer(mem_t *s, balancerinfo_t *balancer)
+{
+ apr_status_t rv;
+ balancerinfo_t *ou = balancer;
+ if (balancer->id)
+ s->storage->ap_slotmem_free(s->slotmem, balancer->id, balancer);
+ else {
+ /* XXX: for the moment January 2007 ap_slotmem_free only uses ident to remove */
+ rv = s->storage->ap_slotmem_do(s->slotmem, loc_read_balancer, &ou,
s->p);
+ if (rv == APR_SUCCESS)
+ rv = s->storage->ap_slotmem_free(s->slotmem, ou->id, balancer);
+ }
+ return rv;
+}
+
+/*
+ * get the ids for the used (not free) balancers in the table
+ * @param pointer to the shared table.
+ * @param ids array of int to store the used id (must be big enough).
+ * @return number of balancer existing or -1 if error.
+ */
+APR_DECLARE(int) get_ids_used_balancer(mem_t *s, int *ids)
+{
+ return (s->storage->ap_slotmem_get_used(s->slotmem, ids));
+}
+
+/*
+ * read the size of the table.
+ * @param pointer to the shared table.
+ * @return number of balancer existing or -1 if error.
+ */
+APR_DECLARE(int) get_max_size_balancer(mem_t *s)
+{
+ return (s->storage->ap_slotmem_get_max_size(s->slotmem));
+}
+
+/**
+ * attach to the shared balancer table
+ * @param name of an existing shared table.
+ * @param address to store the size of the shared table.
+ * @param p pool to use for allocations.
+ * @return address of struct used to access the table.
+ */
+mem_t * get_mem_balancer(char *string, int *num, apr_pool_t *p)
+{
+ return(create_attach_mem_balancer(string, num, 0, p));
+}
+/**
+ * create a shared balancer table
+ * @param name to use to create the table.
+ * @param size of the shared table.
+ * @param p pool to use for allocations.
+ * @return address of struct used to access the table.
+ */
+mem_t * create_mem_balancer(char *string, int *num, apr_pool_t *p)
+{
+ return(create_attach_mem_balancer(string, num, 1, p));
+}
Added: sandbox/httpd/src/native/common/balancer.h
===================================================================
--- sandbox/httpd/src/native/common/balancer.h (rev 0)
+++ sandbox/httpd/src/native/common/balancer.h 2008-05-07 07:49:47 UTC (rev 1594)
@@ -0,0 +1,144 @@
+/*
+ * mod_cluster
+ *
+ * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision$
+ */
+
+#ifndef BALANCER_H
+#define BALANCER_H
+
+/**
+ * @file balancer.h
+ * @brief balancer description Storage Module for Apache
+ *
+ * @defgroup MEM balancers
+ * @ingroup APACHE_MODS
+ * @{
+ */
+
+#define BALANCEREXE ".balancers"
+
+#ifndef MEM_T
+typedef struct mem mem_t;
+#define MEM_T
+#endif
+
+/* status of the balancer as read/store in httpd. */
+struct balancerinfo {
+ char balancer[40]; /* Name of the balancer */
+
+ unsigned long updatetime; /* time of last received message */
+ int id; /* id in table */
+};
+typedef struct balancerinfo balancerinfo_t;
+
+
+/**
+ * Insert(alloc) and update a balancer record in the shared table
+ * @param pointer to the shared table.
+ * @param balancer balancer to store in the shared table.
+ * @return APR_SUCCESS if all went well
+ *
+ */
+APR_DECLARE(apr_status_t) insert_update_balancer(mem_t *s, balancerinfo_t *balancer);
+
+/**
+ * read a balancer record from the shared table
+ * @param pointer to the shared table.
+ * @param balancer balancer to read from the shared table.
+ * @return address of the read balancer or NULL if error.
+ */
+APR_DECLARE(balancerinfo_t *) read_balancer(mem_t *s, balancerinfo_t *balancer);
+
+/**
+ * get a balancer record from the shared table
+ * @param pointer to the shared table.
+ * @param balancer address of the balancer read from the shared table.
+ * @return APR_SUCCESS if all went well
+ */
+APR_DECLARE(apr_status_t) get_balancer(mem_t *s, balancerinfo_t **balancer, int ids);
+
+/**
+ * remove(free) a balancer record from the shared table
+ * @param pointer to the shared table.
+ * @param balancer balancer to remove from the shared table.
+ * @return APR_SUCCESS if all went well
+ */
+APR_DECLARE(apr_status_t) remove_balancer(mem_t *s, balancerinfo_t *balancer);
+
+/*
+ * get the ids for the used (not free) balancers in the table
+ * @param pointer to the shared table.
+ * @param ids array of int to store the used id (must be big enough).
+ * @return number of balancer existing or -1 if error.
+ */
+APR_DECLARE(int) get_ids_used_balancer(mem_t *s, int *ids);
+
+/*
+ * get the size of the table (max size).
+ * @param pointer to the shared table.
+ * @return size of the existing table or -1 if error.
+ */
+APR_DECLARE(int) get_max_size_balancer(mem_t *s);
+
+/**
+ * attach to the shared balancer table
+ * @param name of an existing shared table.
+ * @param address to store the size of the shared table.
+ * @param p pool to use for allocations.
+ * @return address of struct used to access the table.
+ */
+APR_DECLARE(mem_t *) get_mem_balancer(char *string, int *num, apr_pool_t *p);
+/**
+ * create a shared balancer table
+ * @param name to use to create the table.
+ * @param size of the shared table.
+ * @param p pool to use for allocations.
+ * @return address of struct used to access the table.
+ */
+APR_DECLARE(mem_t *) create_mem_balancer(char *string, int *num, apr_pool_t *p);
+
+/**
+ * provider for the mod_proxy_cluster or mod_jk modules.
+ */
+struct balancer_storage_method {
+/**
+ * the balancer corresponding to the ident
+ * @param ids ident of the balancer to read.
+ * @param balancer address of pointer to return the balancer.
+ * @return APR_SUCCESS if all went well
+ */
+APR_DECLARE(apr_status_t) (* read_balancer)(int ids, balancerinfo_t **balancer);
+/**
+ * read the list of ident of used balancers.
+ * @param ids address to store the idents.
+ * @return APR_SUCCESS if all went well
+ */
+APR_DECLARE(int) (* get_ids_used_balancer)(int *ids);
+/**
+ * read the max number of balancers in the shared table
+ */
+APR_DECLARE(int) (*get_max_size_balancer)();
+};
+#endif /*BALANCER_H*/
Modified: sandbox/httpd/src/native/mod_manager/Makefile.in
===================================================================
--- sandbox/httpd/src/native/mod_manager/Makefile.in 2008-05-06 15:24:35 UTC (rev 1593)
+++ sandbox/httpd/src/native/mod_manager/Makefile.in 2008-05-07 07:49:47 UTC (rev 1594)
@@ -16,7 +16,7 @@
# For .deps.
builddir = @MANAGER_BASE@
-MOD_OBJS_LO=../common/node.lo ../common/host.lo ../common/context.lo
../common/sharedmem_util.lo
+MOD_OBJS_LO=../common/node.lo ../common/host.lo ../common/context.lo
../common/balancer.lo ../common/sharedmem_util.lo
include $(APACHE_BASE)/build/rules.mk
SH_COMPILE = $(LIBTOOL) --mode=compile $(BASE_CC) -I../common -prefer-pic -c $<
&& touch $@
Modified: sandbox/httpd/src/native/mod_manager/mod_manager.c
===================================================================
--- sandbox/httpd/src/native/mod_manager/mod_manager.c 2008-05-06 15:24:35 UTC (rev 1593)
+++ sandbox/httpd/src/native/mod_manager/mod_manager.c 2008-05-07 07:49:47 UTC (rev 1594)
@@ -27,6 +27,7 @@
#include "node.h"
#include "host.h"
#include "context.h"
+#include "balancer.h"
#define DEFMAXCONTEXT 100
#define DEFMAXNODE 10
@@ -36,6 +37,7 @@
mem_t *contextstatsmem = NULL;
mem_t *nodestatsmem = NULL;
mem_t *hoststatsmem = NULL;
+mem_t *balancerstatsmem = NULL;
module AP_MODULE_DECLARE_DATA manager_module;
@@ -119,6 +121,28 @@
loc_get_max_size_host
};
+/*
+ * routines for the balancer_storage_method
+ */
+static apr_status_t loc_read_balancer(int ids, balancerinfo_t **balancer)
+{
+ return (get_balancer(balancerstatsmem, balancer, ids));
+}
+static int loc_get_ids_used_balancer(int *ids)
+{
+ return(get_ids_used_balancer(balancerstatsmem, ids));
+}
+static int loc_get_max_size_balancer()
+{
+ return(get_max_size_balancer(balancerstatsmem));
+}
+static const struct balancer_storage_method balancer_storage =
+{
+ loc_read_balancer,
+ loc_get_ids_used_balancer,
+ loc_get_max_size_balancer
+};
+
/* helper for the handling of the Alias: host1,... Context: context1,... */
struct cluster_host {
char *host;
@@ -137,15 +161,18 @@
char *node;
char *context;
char *host;
+ char *balancer;
mod_manager_config *mconf = ap_get_module_config(s->module_config,
&manager_module);
if (mconf->basefilename) {
node = apr_pstrcat(ptemp, mconf->basefilename, ".node", NULL);
context = apr_pstrcat(ptemp, mconf->basefilename, ".context",
NULL);
- context = apr_pstrcat(ptemp, mconf->basefilename, ".host", NULL);
+ host = apr_pstrcat(ptemp, mconf->basefilename, ".host", NULL);
+ balancer = apr_pstrcat(ptemp, mconf->basefilename, ".balancer",
NULL);
} else {
node = "manager.node";
context = "manager.context";
- context = "manager.host";
+ host = "manager.host";
+ host = "manager.balancer";
}
nodestatsmem = create_mem_node(node, &mconf->maxnode, p);
@@ -154,18 +181,24 @@
return !OK;
}
- contextstatsmem = create_mem_context(node, &mconf->maxcontext, p);
+ contextstatsmem = create_mem_context(context, &mconf->maxcontext, p);
if (contextstatsmem == NULL) {
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, s,
"create_mem_context failed");
return !OK;
}
- hoststatsmem = create_mem_host(node, &mconf->maxhost, p);
+ hoststatsmem = create_mem_host(host, &mconf->maxhost, p);
if (hoststatsmem == NULL) {
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, s, "create_mem_host
failed");
return !OK;
}
+ balancerstatsmem = create_mem_balancer(balancer, &mconf->maxhost, p);
+ if (balancerstatsmem == NULL) {
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, s,
"create_mem_balancer failed");
+ return !OK;
+ }
+
sharedmem_initialize_cleanup(p);
return OK;
}
@@ -760,6 +793,7 @@
ap_register_provider(p, "manager" , "shared", "0",
&node_storage);
ap_register_provider(p, "manager" , "shared", "1",
&host_storage);
ap_register_provider(p, "manager" , "shared", "2",
&context_storage);
+ ap_register_provider(p, "manager" , "shared", "3",
&balancer_storage);
}
/*
Modified: sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-05-06 15:24:35 UTC
(rev 1593)
+++ sandbox/httpd/src/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-05-07 07:49:47 UTC
(rev 1594)
@@ -43,6 +43,7 @@
static struct node_storage_method *node_storage = NULL;
static struct host_storage_method *host_storage = NULL;
static struct context_storage_method *context_storage = NULL;
+static struct balancer_storage_method *balancer_storage = NULL;
/*
* XXX: Should use the proxy_util.c one?.
@@ -189,6 +190,8 @@
proxy_worker *worker;
int i, j;
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
+ "create_workers_node starting");
worker = (proxy_worker *)conf->workers->elts;
for (i = 0; i < conf->workers->nelts; i++) {
/* check the id against the table of used ids */
@@ -210,8 +213,27 @@
"create_workers_node can't read id %d",
ids[j]);
continue;
}
- proxy_balancer *balancer = ap_proxy_get_balancer(pool, conf,
- apr_pstrcat(pool, "balancer://", node->balancer,
NULL));
+ char *name = apr_pstrcat(pool, "balancer://",
node->balancer, NULL);
+ proxy_balancer *balancer = ap_proxy_get_balancer(pool, conf, name);
+ if (!balancer) {
+ /* Create one */
+ ap_log_error(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, server,
+ "create_workers_node: Create balancer %s",
name);
+ balancer = apr_array_push(conf->balancers);
+ memset(balancer, 0, sizeof(proxy_balancer));
+ balancer->name = apr_pstrdup(conf->pool, name);
+ balancer->lbmethod = ap_lookup_provider(PROXY_LBMETHOD,
"cluster_bytraffic", "0");
+ balancer->workers = apr_array_make(conf->pool, 5,
sizeof(proxy_worker));
+ /* XXX Is this a right place to create mutex */
+#if APR_HAS_THREADS
+ if (apr_thread_mutex_create(&(balancer->mutex),
+ APR_THREAD_MUTEX_DEFAULT, conf->pool) != APR_SUCCESS)
{
+ /* XXX: Do we need to log something here */
+ ap_log_error(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, 0, server,
+ "create_workers_node: Can't create lock
for balancer");
+ }
+#endif
+ }
if (balancer) {
create_worker(conf, balancer, server, &worker, node);
} else {
@@ -220,6 +242,8 @@
}
}
}
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
+ "create_workers_node done");
}
}
@@ -453,6 +477,122 @@
}
/*
+ * Check that the request has a sessionid (even invalid)
+ * Use the name of the balancer.
+ */
+static int hassession_byname(request_rec *r, char *balancer_name, proxy_server_conf
*conf)
+{
+ proxy_balancer *balancer;
+ char *route;
+ char *uri = r->filename + 6;
+ char *sticky_path, *sticky, *path;
+ int i;
+
+ balancer = (proxy_balancer *)conf->balancers->elts;
+ for (i = 0; i < conf->balancers->nelts; i++) {
+ if (strcasecmp(balancer->name, uri) == 0)
+ break;
+ }
+
+ /* XXX: We don't find the balancer, that is BAD */
+ if (i == conf->balancers->nelts)
+ return 0;
+
+ if (balancer->sticky == NULL)
+ return 0;
+
+ /* for 2.2.x the sticky parameter may contain 2 values */
+ sticky = sticky_path = apr_pstrdup(r->pool, balancer->sticky);
+ if ((path = strchr(sticky, '|'))) {
+ *path++ = '\0';
+ sticky_path = path;
+ }
+ route = get_path_param(r->pool, uri , sticky_path);
+ if (route == NULL)
+ route = get_cookie_param(r, sticky);
+ if (route) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "mod_proxy_cluster: found route %s", route);
+ return 1;
+ }
+ return 0;
+}
+/*
+ * Search the balancer that corresponds to the pair context/host
+ */
+static char *get_context_host_balancer(request_rec *r)
+{
+ void *sconf = r->server->module_config;
+ proxy_server_conf *conf = (proxy_server_conf *)
+ ap_get_module_config(sconf, &proxy_module);
+
+ int sizenode = node_storage->get_max_size_node();
+ int n;
+ int *nodes = apr_palloc(r->pool, sizeof(int)*sizenode);
+ sizenode = node_storage->get_ids_used_node(nodes);
+ for (n=0; n<sizenode; n++) {
+ nodeinfo_t *node;
+ node_storage->read_node(nodes[n], &node);
+
+ /*
+ * check the hosts and contexts
+ * A node may have several virtual hosts and
+ * each virtual hosts may have several context
+ */
+ int sizevhost = host_storage->get_max_size_host();
+ int *vhosts = apr_palloc(r->pool, sizeof(int)*sizevhost);
+ sizevhost = host_storage->get_ids_used_host(vhosts);
+ int i;
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "get_context_host_balancer testing node %s",
node->mess.JVMRoute);
+ for (i=0; i<sizevhost; i++) {
+ hostinfo_t *vhost;
+ host_storage->read_host(vhosts[i], &vhost);
+ if (vhost->node == node->mess.id) {
+ /* XXX Check the virtual host */
+
+ /* Check the contexts */
+ int sizecontext = context_storage->get_max_size_context();
+ int *contexts = apr_palloc(r->pool, sizeof(int)*sizecontext);
+ sizecontext = context_storage->get_ids_used_context(contexts);
+ int j;
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "get_context_host_balancer testing host %s",
vhost->host);
+ for (j=0; j<sizecontext; j++) {
+ contextinfo_t *context;
+ context_storage->read_context(contexts[j], &context);
+ if (context->vhost != vhost->vhost)
+ continue;
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "get_context_host_balancer testing context
%s", context->context);
+
+ /* check for /context[/] in the URL */
+ int len = strlen(context->context);
+ if (strncmp(r->uri, context->context, len) == 0) {
+ if (r->uri[len] == '\0' || r->uri[len] ==
'/') {
+ /* Check status */
+ switch (context->status)
+ {
+ case ENABLED:
+ return node->balancer;
+ break;
+ case DISABLED:
+ /* Only the request with sessionid ok for it */
+ if (hassession_byname(r, node->balancer, conf))
+ return node->balancer;
+ break;
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+ return NULL;
+}
+
+/*
* The ModClusterService from the cluster fills the lbfactor values.
* Our logic is a bit different the mod_balancer one. We check the
* context and host to prevent to route to application beeing redeploy or
@@ -528,7 +668,14 @@
return mycandidate;
}
+static const proxy_balancer_method bytraffic =
+{
+ "bytraffic",
+ &find_best_bytraffic,
+ NULL
+};
+
/*
* Check if the socket is still connected
* XXX: Should use the mod_proxy_balancer ones.
@@ -943,22 +1090,47 @@
"proxy_cluster_post_config: Can't find mod_manager for
contexts");
return !OK;
}
+ balancer_storage = ap_lookup_provider("manager" , "shared",
"3");
+ if (balancer_storage == NULL) {
+ ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
+ "proxy_cluster_post_config: Can't find mod_manager for
balancers");
+ return !OK;
+ }
return OK;
}
-static const proxy_balancer_method bytraffic =
+/*
+ * See if we could map the request.
+ */
+static int proxy_cluster_trans(request_rec *r)
{
- "bytraffic",
- &find_best_bytraffic,
- NULL
-};
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, r->server,
+ "proxy_cluster_trans for %d %s %s uri: %s",
+ r->proxyreq, r->filename, r->handler, r->uri);
+ char *balancer = get_context_host_balancer(r);
+ if (balancer) {
+ r->filename = apr_pstrcat(r->pool, "proxy:balancer://",
balancer, r->uri, NULL);
+ r->handler = "proxy-server";
+ r->proxyreq = PROXYREQ_REVERSE;
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, r->server,
+ "proxy_cluster_trans using %s uri: %s",
+ balancer, r->filename);
+ return OK; /* Mod_proxy will process it */
+ }
+
+ return DECLINED;
+}
+
/*
* Register the hooks on our module.
*/
static void proxy_cluster_hooks(apr_pool_t *p)
{
+ static const char * const aszPre[]={ "mod_manager.c", NULL };
+ static const char * const aszSucc[]={ "mod_proxy.c", NULL };
+
ap_hook_post_config(proxy_cluster_post_config, NULL, NULL, APR_HOOK_MIDDLE);
/* create the provider for the proxy logic */
@@ -967,6 +1139,8 @@
/* create the "maintenance" thread */
ap_hook_child_init(proxy_cluster_child_init, NULL, NULL, APR_HOOK_MIDDLE);
+ /* check the url and give the mapping to mod_proxy */
+ ap_hook_translate_name(proxy_cluster_trans, aszPre, aszSucc, APR_HOOK_FIRST);
}
static void *create_proxy_cluster_dir_config(apr_pool_t *p, char *dir)