JBoss Native SVN: r1702 - trunk/mod_cluster/native/mod_manager.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-06-16 13:21:34 -0400 (Mon, 16 Jun 2008)
New Revision: 1702
Modified:
trunk/mod_cluster/native/mod_manager/mod_manager.c
Log:
Start additing info stuff.
Modified: trunk/mod_cluster/native/mod_manager/mod_manager.c
===================================================================
--- trunk/mod_cluster/native/mod_manager/mod_manager.c 2008-06-16 14:33:38 UTC (rev 1701)
+++ trunk/mod_cluster/native/mod_manager/mod_manager.c 2008-06-16 17:21:34 UTC (rev 1702)
@@ -711,7 +711,35 @@
}
return NULL;
}
+/*
+ * Process a INFO command.
+ * Statics informations ;-)
+ */
+static char * process_info(request_rec *r, char *buff, int *errtype)
+{
+ int size, i;
+ int *id;
+ ap_set_content_type(r, "text/plain");
+
+ size = get_max_size_node(nodestatsmem);
+ id = apr_palloc(r->pool, sizeof(int) * size);
+ size = get_ids_used_node(nodestatsmem, id);
+ for (i=0; i<size; i++) {
+ nodeinfo_t *ou;
+ proxy_worker_stat *proxystat;
+ get_node(nodestatsmem, &ou, id[i]);
+ ap_rprintf(r, "node: [%d:%d] JVMRoute: %s Domain: [%s] Host: %s Port: %s Type: %s\n",
+ id[i], ou->mess.id, ou->mess.JVMRoute, ou->mess.Domain,
+ ou->mess.Host, ou->mess.Port, ou->mess.Type);
+ proxystat = (proxy_worker_stat *) ou->stat;
+ ap_rprintf(r, " [%d:%d] status: %d elected: %d lbstatus: %d lbfactor: %d lbset: %d\n",
+ id[i], ou->mess.id, proxystat->status, proxystat->elected, proxystat->lbstatus, proxystat->lbfactor, proxystat->lbset);
+
+ }
+ return NULL;
+}
+
/* Process a *-APP command that applies to the node */
static char * process_node_cmd(request_rec *r, int status, int *errtype, nodeinfo_t *node)
{
@@ -1031,6 +1059,8 @@
ours = 1;
else if (strcasecmp(r->method, "ERROR") == 0)
ours = 1;
+ else if (strcasecmp(r->method, "INFO") == 0)
+ ours = 1;
if (ours) {
/* The method one of ours */
r->handler = "mod-cluster";
@@ -1091,6 +1121,8 @@
errstring = process_status(r, buff, &errtype);
else if (strcasecmp(r->method, "DUMP") == 0)
errstring = process_dump(r, buff, &errtype);
+ else if (strcasecmp(r->method, "INFO") == 0)
+ errstring = process_info(r, buff, &errtype);
else {
errstring = SCMDUNS;
errtype = TYPESYNTAX;
16 years, 6 months
JBoss Native SVN: r1701 - trunk/mod_cluster/native/mod_proxy_cluster.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-06-16 10:33:38 -0400 (Mon, 16 Jun 2008)
New Revision: 1701
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Add a mutex and don't retry a broken node.
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-16 13:01:50 UTC (rev 1700)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-16 14:33:38 UTC (rev 1701)
@@ -55,6 +55,8 @@
static struct context_storage_method *context_storage = NULL;
static struct balancer_storage_method *balancer_storage = NULL;
+static apr_thread_mutex_t *lock = NULL;
+
/*
* Create/Get the worker before using it
*/
@@ -256,12 +258,16 @@
apr_time_t last;
int notok = 0;
+ apr_thread_mutex_lock(lock);
+
/* Check if we have to do something */
last = node_storage->worker_nodes_need_update(server, pool);
/* nodes_need_update will return 1 if last_updated is zero: first time we are called */
- if (last == 0)
+ if (last == 0) {
+ apr_thread_mutex_unlock(lock);
return;
+ }
/* read the ident of the nodes */
id = apr_pcalloc(pool, sizeof(int) * node_storage->get_max_size_node());
@@ -286,6 +292,8 @@
}
if (! notok)
node_storage->worker_nodes_are_updated(server);
+
+ apr_thread_mutex_unlock(lock);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server,
"update_workers_node done");
}
@@ -704,14 +712,10 @@
if (worker->s->lbfactor < 0 || (worker->s->lbfactor == 0 && !checking_standby))
continue;
- /* If the worker is in error state run
- * retry on that worker. It will be marked as
- * operational if the retry timeout is elapsed.
- * The worker might still be unusable, but we try
- * anyway.
- */
- if (!PROXY_WORKER_IS_USABLE(worker))
- ap_proxy_retry_worker("BALANCER", worker, r->server);
+ /* If the worker is in error state the STATUS logic will retry it */
+ if (!PROXY_WORKER_IS_USABLE(worker)) {
+ continue;
+ }
/* Take into calculation only the workers that are
* not in error state or not disabled.
@@ -1027,17 +1031,21 @@
/*
* Create a thread per process to make maintenance task.
+ * and the mutex of the node creation.
*/
static void proxy_cluster_child_init(apr_pool_t *p, server_rec *s)
{
apr_status_t rv;
apr_thread_t *wdt;
+ apr_thread_mutex_create(&lock, APR_THREAD_MUTEX_DEFAULT, p);
+
rv = apr_thread_create(&wdt, NULL, proxy_cluster_watchdog_func, s, p);
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
"proxy_cluster_child_init: apr_thread_create failed");
}
+
}
static int proxy_cluster_post_config(apr_pool_t *p, apr_pool_t *plog,
16 years, 6 months
JBoss Native SVN: r1700 - trunk/mod_cluster/native/mod_proxy_cluster.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-06-16 09:01:50 -0400 (Mon, 16 Jun 2008)
New Revision: 1700
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Oops typos.
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-16 09:04:05 UTC (rev 1699)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-16 13:01:50 UTC (rev 1700)
@@ -133,6 +133,7 @@
(*worker)->s->redirect[0] = '\0';
(*worker)->s->lbset = 0;
}
+ (*worker)->s->lbstatus = 1;
if (!reuse) {
/*
@@ -723,7 +724,7 @@
} else {
worker->s->lbstatus += worker->s->lbfactor;
total_factor += worker->s->lbfactor;
- if (!mycandidate || worker->s->lbstatus < mycandidate->s->lbstatus) {
+ if (!mycandidate || worker->s->lbstatus > mycandidate->s->lbstatus) {
mycandidate = worker;
}
}
16 years, 6 months
JBoss Native SVN: r1699 - trunk/mod_cluster/native/advertise.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-06-16 05:04:05 -0400 (Mon, 16 Jun 2008)
New Revision: 1699
Modified:
trunk/mod_cluster/native/advertise/mod_advertise.c
Log:
Allow it in ONE VirtualHost.
Try to guess the X-Manager-Address and X-Manager-Protocol from the Server configuration.
Modified: trunk/mod_cluster/native/advertise/mod_advertise.c
===================================================================
--- trunk/mod_cluster/native/advertise/mod_advertise.c 2008-06-16 07:39:46 UTC (rev 1698)
+++ trunk/mod_cluster/native/advertise/mod_advertise.c 2008-06-16 09:04:05 UTC (rev 1699)
@@ -133,10 +133,9 @@
static const char *cmd_advertise_m(cmd_parms *cmd, void *dummy,
const char *arg, const char *opt)
{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
- if (errs != NULL)
- return errs;
+ if (ma_advertise_adrs)
+ return "Duplicate ServerAdvertise directives are not allowed";
if (strcasecmp(arg, "Off") == 0)
ma_advertise_mode = ma_advertise_off;
@@ -158,6 +157,7 @@
!ma_advertise_srvp)
return "Invalid ServerAdvertise Address";
}
+ ma_server_rec = cmd->server; /* Virtual Host containing the directive */
return NULL;
}
@@ -170,12 +170,8 @@
static const char *cmd_advertise_g(cmd_parms *cmd, void *dummy,
const char *arg)
{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
if (ma_advertise_set)
- return "Duplicate AdvertiseGroup directives are not allowed";
+ return "Duplicate AdvertiseGroup directives are not allowed";
if (apr_parse_addr_port(&ma_advertise_adrs,
&ma_advertise_adsi,
@@ -200,10 +196,9 @@
{
apr_time_t s, u = 0;
const char *p;
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
- if (errs != NULL)
- return errs;
+ if (ma_advertise_freq != MA_DEFAULT_ADV_FREQ)
+ return "Duplicate AdvertiseFrequency directives are not allowed";
if ((p = ap_strchr_c(arg, '.')) || (p = ap_strchr_c(arg, ',')))
u = atoi(p + 1);
@@ -489,7 +484,6 @@
}
}
#endif
- ma_server_rec = s;
if (!magd->generation) {
/* Favor dynamic configuration */
if (ma_advertise_skey) {
@@ -504,9 +498,6 @@
}
if (!ma_advertise_srvh)
ma_advertise_srvh = magd->srvid;
- if (!ma_advertise_srvm)
- ma_advertise_srvm = apr_pstrdup(pconf, "http");
-
/* Check if we have advertise set */
if (ma_advertise_mode != ma_advertise_off &&
ma_advertise_set && ma_advertise_adrs) {
@@ -523,6 +514,44 @@
}
}
+ /* Fill default values */
+ if (!ma_advertise_srvm) {
+ if (ma_server_rec && ma_server_rec->server_scheme) {
+ /* ServerName scheme://fully-qualified-domain-name[:port] */
+ ma_advertise_srvm = apr_pstrdup(pconf, ma_server_rec->server_scheme);
+ } else {
+ ma_advertise_srvm = apr_pstrdup(pconf, "http");
+ }
+ }
+
+ if (ma_advertise_srvs == NULL && ma_server_rec) {
+ /*
+ * That is not easy just use ServerAdvertise with the server parameter
+ * if the code below doesn't work
+ */
+ char *ptr;
+ int port = DEFAULT_HTTP_PORT;
+ if (ma_server_rec->addrs && ma_server_rec->addrs->host_addr &&
+ ma_server_rec->addrs->host_addr->next == NULL) {
+ ptr = apr_psprintf(pproc, "%pI", ma_server_rec->addrs->host_addr);
+ } else {
+ if ( ma_server_rec->port !=0 || ma_server_rec->port !=1)
+ port = ma_server_rec->port;
+ ptr = apr_psprintf(pproc, "%s:%lu", ma_server_rec->server_hostname, port);
+ }
+ rv = apr_parse_addr_port(&ma_advertise_srvs,
+ &ma_advertise_srvi,
+ &ma_advertise_srvp,
+ ptr, pproc);
+ if (rv != APR_SUCCESS || !ma_advertise_srvs ||
+ !ma_advertise_srvp) {
+ ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
+ "mod_advertise: Invalid ServerAdvertise Address %s",
+ ptr);
+ return rv;
+ }
+ }
+
/* Create parent management thread */
is_mp_running = 1;
rv = apr_thread_create(&tp, NULL, parent_thread, s, pconf);
16 years, 6 months
JBoss Native SVN: r1698 - trunk/mod_cluster/native/mod_proxy_cluster.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-06-16 03:39:46 -0400 (Mon, 16 Jun 2008)
New Revision: 1698
Added:
trunk/mod_cluster/native/mod_proxy_cluster/patch.txt
Log:
Missing file.
Added: trunk/mod_cluster/native/mod_proxy_cluster/patch.txt
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/patch.txt (rev 0)
+++ trunk/mod_cluster/native/mod_proxy_cluster/patch.txt 2008-06-16 07:39:46 UTC (rev 1698)
@@ -0,0 +1,28 @@
+Index: config.m4
+===================================================================
+--- config.m4 (revision 663923)
++++ config.m4 (working copy)
+@@ -18,6 +18,7 @@
+ proxy_http_objs="mod_proxy_http.lo"
+ proxy_ajp_objs="mod_proxy_ajp.lo ajp_header.lo ajp_link.lo ajp_msg.lo ajp_utils.lo"
+ proxy_balancer_objs="mod_proxy_balancer.lo"
++proxy_cluster_objs="mod_proxy_cluster.lo"
+
+ case "$host" in
+ *os2*)
+@@ -28,6 +29,7 @@
+ proxy_http_objs="$proxy_http_objs mod_proxy.la"
+ proxy_ajp_objs="$proxy_ajp_objs mod_proxy.la"
+ proxy_balancer_objs="$proxy_balancer_objs mod_proxy.la"
++ proxy_cluster_objs="$proxy_cluster_objs mod_proxy.la"
+ ;;
+ esac
+
+@@ -36,6 +38,7 @@
+ APACHE_MODULE(proxy_http, Apache proxy HTTP module, $proxy_http_objs, , $proxy_mods_enable)
+ APACHE_MODULE(proxy_ajp, Apache proxy AJP module, $proxy_ajp_objs, , $proxy_mods_enable)
+ APACHE_MODULE(proxy_balancer, Apache proxy BALANCER module, $proxy_balancer_objs, , $proxy_mods_enable)
++APACHE_MODULE(proxy_cluster, proxy CLUSTER module, $proxy_cluster_objs, , $proxy_mods_enable)
+
+ APR_ADDTO(INCLUDES, [-I\$(top_srcdir)/$modpath_current/../generators])
+
16 years, 6 months
JBoss Native SVN: r1696 - in trunk/mod_cluster/native: mod_manager and 2 other directories.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-06-13 04:26:19 -0400 (Fri, 13 Jun 2008)
New Revision: 1696
Modified:
trunk/mod_cluster/native/advertise/Makefile.in
trunk/mod_cluster/native/mod_manager/Makefile.in
trunk/mod_cluster/native/mod_proxy_cluster/Makefile.in
trunk/mod_cluster/native/mod_slotmem/Makefile.in
Log:
Add *.so in the remove list.
Modified: trunk/mod_cluster/native/advertise/Makefile.in
===================================================================
--- trunk/mod_cluster/native/advertise/Makefile.in 2008-06-11 15:59:11 UTC (rev 1695)
+++ trunk/mod_cluster/native/advertise/Makefile.in 2008-06-13 08:26:19 UTC (rev 1696)
@@ -19,5 +19,5 @@
$(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_advertise.lo
clean:
- rm -f *.o *.lo *.slo
+ rm -f *.o *.lo *.slo *.so
rm -rf .libs
Modified: trunk/mod_cluster/native/mod_manager/Makefile.in
===================================================================
--- trunk/mod_cluster/native/mod_manager/Makefile.in 2008-06-11 15:59:11 UTC (rev 1695)
+++ trunk/mod_cluster/native/mod_manager/Makefile.in 2008-06-13 08:26:19 UTC (rev 1696)
@@ -19,5 +19,5 @@
$(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_manager.lo node.lo context.lo host.lo balancer.lo
clean:
- rm -f *.o *.lo *.slo
+ rm -f *.o *.lo *.slo *.so
rm -rf .libs
Modified: trunk/mod_cluster/native/mod_proxy_cluster/Makefile.in
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/Makefile.in 2008-06-11 15:59:11 UTC (rev 1695)
+++ trunk/mod_cluster/native/mod_proxy_cluster/Makefile.in 2008-06-13 08:26:19 UTC (rev 1696)
@@ -28,3 +28,7 @@
mod_proxy_cluster.la: mod_proxy_cluster.slo
$(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_proxy_cluster.lo $(MOD_OBJS_LO)
+
+clean:
+ rm -f *.o *.lo *.slo *.so
+ rm -rf .libs
Modified: trunk/mod_cluster/native/mod_slotmem/Makefile.in
===================================================================
--- trunk/mod_cluster/native/mod_slotmem/Makefile.in 2008-06-11 15:59:11 UTC (rev 1695)
+++ trunk/mod_cluster/native/mod_slotmem/Makefile.in 2008-06-13 08:26:19 UTC (rev 1696)
@@ -19,5 +19,5 @@
$(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_sharedmem.lo sharedmem_util.lo
clean:
- rm -f *.o *.lo *.slo
+ rm -f *.o *.lo *.slo *.so
rm -rf .libs
16 years, 6 months
JBoss Native SVN: r1695 - in trunk: mod_cluster/native/advertise and 1 other directory.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-06-11 11:59:11 -0400 (Wed, 11 Jun 2008)
New Revision: 1695
Added:
trunk/mod_cluster/native/advertise/.deps
Removed:
trunk/httpd/httpd-2.2/modules/advertise/.deps
Modified:
trunk/mod_cluster/native/advertise/configure.in
Log:
Arrange configure.
Deleted: trunk/httpd/httpd-2.2/modules/advertise/.deps
===================================================================
Added: trunk/mod_cluster/native/advertise/.deps
===================================================================
Modified: trunk/mod_cluster/native/advertise/configure.in
===================================================================
--- trunk/mod_cluster/native/advertise/configure.in 2008-06-11 15:25:22 UTC (rev 1694)
+++ trunk/mod_cluster/native/advertise/configure.in 2008-06-11 15:59:11 UTC (rev 1695)
@@ -21,4 +21,4 @@
AC_SUBST(APACHE_BASE)
AC_SUBST(CLUSTER_BASE)
-AC_OUTPUT(Makefile.apxs)
+AC_OUTPUT(Makefile)
16 years, 6 months
JBoss Native SVN: r1694 - trunk/mod_cluster/native/mod_proxy_cluster.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-06-11 11:25:22 -0400 (Wed, 11 Jun 2008)
New Revision: 1694
Added:
trunk/mod_cluster/native/mod_proxy_cluster/Makefile.in
trunk/mod_cluster/native/mod_proxy_cluster/buildconf
trunk/mod_cluster/native/mod_proxy_cluster/configure.in
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Remove ajp util dependencies.
Added: trunk/mod_cluster/native/mod_proxy_cluster/Makefile.in
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/Makefile.in (rev 0)
+++ trunk/mod_cluster/native/mod_proxy_cluster/Makefile.in 2008-06-11 15:25:22 UTC (rev 1694)
@@ -0,0 +1,30 @@
+#
+# Copyright 2006 Red Hat Middleware, LLC.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software distributed
+# under the License is distributed on an "AS IS" BASIS,i
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+APACHE_BASE = @APACHE_BASE@
+top_builddir = @APACHE_BASE@
+# For .deps.
+builddir = @CLUSTER_BASE@
+
+MOD_OBJS_LO=
+
+include $(APACHE_BASE)/build/rules.mk
+SH_COMPILE = $(LIBTOOL) --mode=compile $(BASE_CC) -I../include -prefer-pic -c $< && touch $@
+
+all: mod_proxy_cluster.so
+
+mod_proxy_cluster.so: mod_proxy_cluster.la
+ $(APACHE_BASE)/build/instdso.sh SH_LIBTOOL='$(LIBTOOL)' mod_proxy_cluster.la `pwd`
+
+mod_proxy_cluster.la: mod_proxy_cluster.slo
+ $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_proxy_cluster.lo $(MOD_OBJS_LO)
Added: trunk/mod_cluster/native/mod_proxy_cluster/buildconf
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/buildconf (rev 0)
+++ trunk/mod_cluster/native/mod_proxy_cluster/buildconf 2008-06-11 15:25:22 UTC (rev 1694)
@@ -0,0 +1,11 @@
+# Remove aclocal.m4 as it'll break some builds...
+rm -rf aclocal.m4 autom4te*.cache
+
+echo "Creating configure ..."
+### do some work to toss config.cache?
+if ${AUTOCONF:-autoconf}; then
+ :
+else
+ echo "autoconf failed"
+ exit 1
+fi
Property changes on: trunk/mod_cluster/native/mod_proxy_cluster/buildconf
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/mod_cluster/native/mod_proxy_cluster/configure.in
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/configure.in (rev 0)
+++ trunk/mod_cluster/native/mod_proxy_cluster/configure.in 2008-06-11 15:25:22 UTC (rev 1694)
@@ -0,0 +1,24 @@
+dnl configure for mod_manager
+dnl
+
+AC_INIT(mod_proxy_cluster.c)
+
+AC_MSG_CHECKING(for Apache httpd installation)
+AC_ARG_WITH(apache,
+[ --with-apache[=DIR] DIR is the apache base installation
+],
+[ if test "$withval" = "yes"; then
+ withval=/usr/local/etc/httpd
+ fi
+ if test "$withval" != "no"; then
+ APACHE_BASE=$withval
+ else
+ AC_MSG_ERROR(mod_manager need a valid apache location)
+ fi
+],
+[ AC_MSG_ERROR(Please use --with-apache[=DIR])])
+CLUSTER_BASE=`pwd`
+
+AC_SUBST(APACHE_BASE)
+AC_SUBST(CLUSTER_BASE)
+AC_OUTPUT(Makefile)
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-11 14:16:31 UTC (rev 1693)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-11 15:25:22 UTC (rev 1694)
@@ -35,7 +35,6 @@
#include "http_protocol.h"
#include "http_core.h"
#include "mod_proxy.h"
-#include "ajp.h"
#include "mod_proxy_cluster.h"
@@ -754,7 +753,67 @@
/*
* Do a ping/pong to the node
+ * XXX: ajp_handle_cping_cpong should come from a provider as
+ * it is already in modules/proxy/ajp_utils.c
*/
+static apr_status_t ajp_handle_cping_cpong(apr_socket_t *sock,
+ request_rec *r,
+ apr_interval_time_t timeout)
+{
+ char buf[5];
+ apr_size_t written = 5;
+ apr_interval_time_t org;
+ apr_status_t status;
+
+ /* built the cping message */
+ buf[0] = 0x12;
+ buf[1] = 0x34;
+ buf[2] = (apr_byte_t) 0;
+ buf[3] = (apr_byte_t) 1;
+ buf[4] = (unsigned char)10;
+
+ status = apr_socket_send(sock, buf, &written);
+ if (status != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
+ "ajp_handle_cping_cpong(): send failed");
+ return status;
+ }
+ status = apr_socket_timeout_get(sock, &org);
+ if (status != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
+ "ajp_handle_cping_cpong(): apr_socket_timeout_get failed");
+ return status;
+ }
+ status = apr_socket_timeout_set(sock, timeout);
+ written = 5;
+ status = apr_socket_recv(sock, buf, &written);
+ if (status != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: apr_socket_recv failed");
+ goto cleanup;
+ }
+ if (buf[0] != 0x41 || buf[1] != 0x42 || buf[2] != 0 || buf[3] != 1 || buf[4] != (unsigned char)9) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: awaited CPONG, received %02x %02x %02x %02x %02x",
+ buf[0] & 0xFF,
+ buf[1] & 0xFF,
+ buf[2] & 0xFF,
+ buf[3] & 0xFF,
+ buf[4] & 0xFF);
+ status = APR_EGENERAL;
+ }
+cleanup:
+ status = apr_socket_timeout_set(sock, org);
+ if (status != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
+ "ajp_handle_cping_cpong: apr_socket_timeout_set failed");
+ return status;
+ }
+
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "ajp_handle_cping_cpong: Done");
+ return status;
+}
static apr_status_t proxy_cluster_try_pingpong(request_rec *r, proxy_worker *worker, char *scheme)
{
apr_status_t rv;
16 years, 6 months
JBoss Native SVN: r1693 - in trunk: mod_cluster/native and 2 other directories.
by jbossnative-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-06-11 10:16:31 -0400 (Wed, 11 Jun 2008)
New Revision: 1693
Added:
trunk/mod_cluster/native/advertise/
trunk/mod_cluster/native/advertise/Makefile.in
trunk/mod_cluster/native/advertise/README
trunk/mod_cluster/native/advertise/buildconf
trunk/mod_cluster/native/advertise/configure.in
trunk/mod_cluster/native/advertise/mod_advertise.c
trunk/mod_cluster/native/advertise/mod_advertise.h
Removed:
trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in
trunk/httpd/httpd-2.2/modules/advertise/README
trunk/httpd/httpd-2.2/modules/advertise/buildconf
trunk/httpd/httpd-2.2/modules/advertise/configure.in
trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c
trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h
Modified:
trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
Log:
Put the files in mod_cluster directory.
Deleted: trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in 2008-06-11 14:15:14 UTC (rev 1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in 2008-06-11 14:16:31 UTC (rev 1693)
@@ -1,23 +0,0 @@
-# Makefile.in for mod_proxy_cluster
-# copy the source in the httpd Apache source tree
-APACHE_BASE = @APACHE_BASE@
-top_builddir = @APACHE_BASE@
-# For .deps.
-builddir = @CLUSTER_BASE@
-# For the apache includes
-top_srcdir = @APACHE_BASE@
-
-include $(APACHE_BASE)/build/rules.mk
-SH_COMPILE = $(LIBTOOL) --mode=compile $(BASE_CC) -I../include -prefer-pic -c $< && touch $@
-
-all: mod_advertise.so
-
-mod_advertise.so: mod_advertise.la
- $(APACHE_BASE)/build/instdso.sh SH_LIBTOOL='$(LIBTOOL)' mod_advertise.la `pwd`
-
-mod_advertise.la: mod_advertise.slo
- $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_advertise.lo
-
-clean:
- rm -f *.o *.lo *.slo
- rm -rf .libs
Deleted: trunk/httpd/httpd-2.2/modules/advertise/README
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/README 2008-06-11 14:15:14 UTC (rev 1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/README 2008-06-11 14:16:31 UTC (rev 1693)
@@ -1,17 +0,0 @@
-The source could be in httpd-2.2.x source tree.
-The ./buildconf must be run again amd the configure need at least:
-./configure --enable-advertise
-
-The source could build with a installed version of httpd-2-2.x:
-sh buildconf
-./configure --with-apache=apache_installation_directory.
-make -f Makefile.apxs
-The mod_advertise.so need to be copied to apache_installation_directory/modules
-
-Configuration use something like the following in httpd.conf:
-LoadModule advertise_module modules/mod_advertise.so
-ServerAdvertise on
-AdvertiseGroup 232.0.0.2
-AdvertiseFrequency 30
-
-Note default port is 23364.
Deleted: trunk/httpd/httpd-2.2/modules/advertise/buildconf
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/buildconf 2008-06-11 14:15:14 UTC (rev 1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/buildconf 2008-06-11 14:16:31 UTC (rev 1693)
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-rm -rf aclocal.m4 autom4te*.cache
-
-echo "Creating configure ..."
-### do some work to toss config.cache?
-if ${AUTOCONF:-autoconf}; then
- :
-else
- echo "autoconf failed"
- exit 1
-fi
Deleted: trunk/httpd/httpd-2.2/modules/advertise/configure.in
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/configure.in 2008-06-11 14:15:14 UTC (rev 1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/configure.in 2008-06-11 14:16:31 UTC (rev 1693)
@@ -1,24 +0,0 @@
-dnl configure for mod_manager
-dnl
-
-AC_INIT(mod_advertise.c)
-
-AC_MSG_CHECKING(for Apache httpd installation)
-AC_ARG_WITH(apache,
-[ --with-apache[=DIR] DIR is the apache base installation
-],
-[ if test "$withval" = "yes"; then
- withval=/usr/local/etc/httpd
- fi
- if test "$withval" != "no"; then
- APACHE_BASE=$withval
- else
- AC_MSG_ERROR(mod_manager need a valid apache location)
- fi
-],
-[ AC_MSG_ERROR(Please use --with-apache[=DIR])])
-CLUSTER_BASE=`pwd`
-
-AC_SUBST(APACHE_BASE)
-AC_SUBST(CLUSTER_BASE)
-AC_OUTPUT(Makefile.apxs)
Deleted: trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c 2008-06-11 14:15:14 UTC (rev 1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c 2008-06-11 14:16:31 UTC (rev 1693)
@@ -1,642 +0,0 @@
-/*
- * ModAdvertise - Apache Httpd advertising module
- *
- * 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 Mladen Turk
- */
-
-#define CORE_PRIVATE
-
-#include "mod_advertise.h"
-#include "mod_core.h"
-#include "util_script.h"
-
-#ifndef MAX
-#define MAX(x,y) ((x) >= (y) ? (x) : (y))
-#endif
-
-#define MOD_SRVCONF(p) ap_get_module_config((p)->server->module_config, \
- &advertise_module)
-#define MOD_GETCONF(s) ap_get_module_config((s)->module_config, \
- &advertise_module)
-
-/*
- * Declare ourselves so the configuration routines can find and know us.
- * We'll fill it in at the end of the module.
- */
-module AP_MODULE_DECLARE_DATA advertise_module;
-
-
-
-/*
- * Server private data
- */
-static int ma_generation = 0;
-static apr_time_t ma_child_started = 0;
-static pid_t ma_parent_pid = -1;
-
-/*
- * Global configuration
- */
-static int ma_manager_strict = 0;
-static int ma_advertise_set = 0;
-static int ma_advertise_run = 0;
-static int ma_advertise_stat = 0;
-static char *ma_advertise_adrs = NULL;
-static char *ma_advertise_adsi = NULL;
-static char *ma_advertise_srvm = NULL;
-static char *ma_advertise_srvh = NULL;
-static char *ma_advertise_srvs = NULL;
-static char *ma_advertise_srvi = NULL;
-static char *ma_advertise_uuid = NULL;
-
-static char *ma_advertise_skey = NULL;
-
-
-static ma_advertise_srv_t ma_advs_server;
-
-
-/* Advertise is by default turned off */
-static apr_port_t ma_advertise_port = MA_DEFAULT_ADVPORT;
-static apr_port_t ma_advertise_srvp = 0;
-static ma_advertise_e ma_advertise_mode = ma_advertise_off;
-static apr_interval_time_t ma_advertise_freq = MA_DEFAULT_ADV_FREQ;
-
-/* Advertise sockets */
-static apr_socket_t *ma_mgroup_socket = NULL;
-static apr_socket_t *ma_listen_socket = NULL;
-static apr_sockaddr_t *ma_mgroup_sa = NULL;
-static apr_sockaddr_t *ma_listen_sa = NULL;
-
-static server_rec *ma_server_rec = NULL;
-
-/* Advertise sequence number */
-static volatile apr_int64_t ma_sequence = 0;
-
-
-/* Parent and child manager thread statuses */
-static volatile int is_mp_running = 0;
-static volatile int is_mp_created = 0;
-
-/*
- * Server global data
- */
-typedef struct ma_global_data_t {
- int generation;
- unsigned char ssalt[APR_MD5_DIGESTSIZE];
- apr_uuid_t suuid;
- char srvid[APR_UUID_FORMATTED_LENGTH + 2];
- apr_pool_t *ppool;
- apr_pool_t *cpool;
-} ma_global_data_t;
-
-/*
- * Global data instance
- * For parent, registered in process pool
- */
-static ma_global_data_t *magd = NULL;
-
-/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the
- * IPv4 match-any-address, 0.0.0.0. */
-#define IS_INADDR_ANY(addr) ((addr)->family == APR_INET && \
- (addr)->sa.sin.sin_addr.s_addr == INADDR_ANY)
-
-/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the
- * IPv6 match-any-address, [::]. */
-#define IS_IN6ADDR_ANY(addr) ((addr)->family == APR_INET6 && \
- IN6_IS_ADDR_UNSPECIFIED(&(addr)->sa.sin6.sin6_addr))
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* ServerAdvertise directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_m(cmd_parms *cmd, void *dummy,
- const char *arg, const char *opt)
-{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
-
- if (strcasecmp(arg, "Off") == 0)
- ma_advertise_mode = ma_advertise_off;
- else if (strcasecmp(arg, "On") == 0)
- ma_advertise_mode = ma_advertise_on;
- else
- return "ServerAdvertise must be Off or On";
- if (opt) {
- const char *p = ap_strstr_c(opt, "://");
- if (p) {
- ma_advertise_srvm = apr_pstrndup(cmd->pool, opt, p - opt);
- opt = p + 3;
- }
- if (apr_parse_addr_port(&ma_advertise_srvs,
- &ma_advertise_srvi,
- &ma_advertise_srvp,
- opt, cmd->pool) != APR_SUCCESS ||
- !ma_advertise_srvs ||
- !ma_advertise_srvp)
- return "Invalid ServerAdvertise Address";
- }
- return NULL;
-}
-
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* AdvertiseGroup directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_g(cmd_parms *cmd, void *dummy,
- const char *arg)
-{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
- if (ma_advertise_set)
- return "Duplicate AdvertiseGroup directives are not allowed";
-
- if (apr_parse_addr_port(&ma_advertise_adrs,
- &ma_advertise_adsi,
- &ma_advertise_port,
- arg, cmd->pool) != APR_SUCCESS)
- return "Invalid AdvertiseGroup address";
- if (!ma_advertise_adrs)
- return "Missing Ip part from AdvertiseGroup address";
- if (!ma_advertise_port)
- ma_advertise_port = MA_DEFAULT_ADVPORT;
- ma_advertise_set = 1;
- return NULL;
-}
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* AdvertiseFrequency directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_f(cmd_parms *cmd, void *dummy,
- const char *arg)
-{
- apr_time_t s, u = 0;
- const char *p;
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
- if ((p = ap_strchr_c(arg, '.')) || (p = ap_strchr_c(arg, ',')))
- u = atoi(p + 1);
-
- s = atoi(arg);
- ma_advertise_freq = s * APR_USEC_PER_SEC + u * APR_TIME_C(1000);
- if (ma_advertise_freq == 0)
- return "Invalid AdvertiseFrequency value";
-
- return NULL;
-}
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* AdvertiseSecurityKey directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_k(cmd_parms *cmd, void *dummy,
- const char *arg)
-{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
- ma_advertise_skey = apr_pstrdup(cmd->pool, arg);
- return NULL;
-}
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* AdvertiseManagerUrl directive */
-/* */
-/*--------------------------------------------------------------------------*/
-static const char *cmd_advertise_h(cmd_parms *cmd, void *dummy,
- const char *arg)
-{
- const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
-
- if (errs != NULL)
- return errs;
- ma_advertise_srvh = apr_pstrdup(cmd->pool, arg);
- return NULL;
-}
-
-#define MA_ADVERTISE_SERVER_FMT \
- "HTTP/1.0 %s" CRLF \
- "Date: %s" CRLF \
- "Sequence: %" APR_INT64_T_FMT CRLF \
- "Digest: %s" CRLF \
- "Server: %s" CRLF
-
-static const char *hex = "0123456789abcdef";
-
-apr_status_t ma_advertise_server(server_rec *server, int type)
-{
- char buf[MA_BSIZE];
- char dat[APR_RFC822_DATE_LEN];
- unsigned char msig[APR_MD5_DIGESTSIZE];
- unsigned char ssig[APR_MD5_DIGESTSIZE * 2 + 1];
- const char *asl;
- char *p = buf;
- int i, c = 0;
- apr_size_t l = MA_BSIZE - 8;
- apr_size_t n = 0;
- apr_md5_ctx_t md;
-
- ma_sequence++;
- if (ma_sequence < 1)
- ma_sequence = 1;
- sprintf(buf, "%" APR_INT64_T_FMT, ma_sequence);
- ap_recent_rfc822_date(dat, apr_time_now());
- asl = ap_get_status_line(ma_advertise_stat);
-
- /* Create MD5 digest
- * salt + date + sequence + srvid
- */
- apr_md5_init(&md);
- apr_md5_update(&md, magd->ssalt, APR_MD5_DIGESTSIZE);
- apr_md5_update(&md, dat, strlen(dat));
- apr_md5_update(&md, buf, strlen(buf));
- apr_md5_update(&md, magd->srvid + 1, strlen(magd->srvid) - 1);
- apr_md5_final(msig, &md);
- /* Convert MD5 digest to hex string */
- for (i = 0; i < APR_MD5_DIGESTSIZE; i++) {
- ssig[c++] = hex[msig[i] >> 4];
- ssig[c++] = hex[msig[i] & 0x0F];
- }
- ssig[c] = '\0';
- n = apr_snprintf(p, l, MA_ADVERTISE_SERVER_FMT,
- asl, dat, ma_sequence, ssig, magd->srvid + 1);
- if (type == MA_ADVERTISE_SERVER) {
- l -= n;
- n += apr_snprintf(p + n, l,
- "X-Manager-Address: %s:%u" CRLF
- "X-Manager-Url: %s" CRLF
- "X-Manager-Protocol: %s" CRLF
- "X-Manager-Host: %s" CRLF,
- ma_advertise_srvs,
- ma_advertise_srvp,
- ma_advertise_srvh,
- ma_advertise_srvm,
- server->server_hostname);
-
- }
- strcat(p, CRLF);
- n += 2;
- return apr_socket_sendto(ma_mgroup_socket,
- ma_mgroup_sa, 0, buf, &n);
-}
-
-static apr_status_t ma_group_join(const char *addr, apr_port_t port,
- apr_pool_t *pool)
-{
- apr_status_t rv;
-
- if ((rv = apr_sockaddr_info_get(&ma_mgroup_sa, addr,
- APR_INET, port,
- APR_UNSPEC, pool)) != APR_SUCCESS)
- return rv;
- if ((rv = apr_socket_create(&ma_mgroup_socket,
- ma_mgroup_sa->family,
- SOCK_DGRAM,
- APR_PROTO_UDP,
- pool)) != APR_SUCCESS)
- return rv;
- if ((rv = apr_mcast_join(ma_mgroup_socket, ma_mgroup_sa,
- NULL, NULL)) != APR_SUCCESS) {
- apr_socket_close(ma_mgroup_socket);
- return rv;
- }
- if ((rv = apr_mcast_hops(ma_mgroup_socket,
- MA_ADVERTISE_HOPS)) != APR_SUCCESS) {
- apr_mcast_leave(ma_mgroup_socket, ma_mgroup_sa,
- NULL, NULL);
- apr_socket_close(ma_mgroup_socket);
- return rv;
- }
- return APR_SUCCESS;
-}
-
-static void ma_group_leave()
-{
- if (ma_mgroup_socket) {
- apr_mcast_leave(ma_mgroup_socket, ma_mgroup_sa,
- NULL, NULL);
- apr_socket_close(ma_mgroup_socket);
- ma_mgroup_socket = NULL;
- }
-}
-
-static void * APR_THREAD_FUNC parent_thread(apr_thread_t *thd, void *data)
-{
- static int current_status = 0;
- int f_time = 1;
- apr_interval_time_t a_step = 0;
- server_rec *s = (server_rec *)data;
- is_mp_created = 1;
-
- while (is_mp_running) {
- apr_sleep(MA_TM_RESOLUTION);
- if (!is_mp_running)
- break;
- if (ma_advertise_run) {
- a_step += MA_TM_RESOLUTION;
- if (current_status != ma_advertise_stat) {
- /* Force advertise on status change */
- current_status = ma_advertise_stat;
- f_time = 1;
- }
- if (a_step >= ma_advertise_freq || f_time) {
- /* Run advertise */
- ma_advertise_server(s, MA_ADVERTISE_SERVER);
- a_step = 0;
- f_time = 0;
- }
- if (!is_mp_running)
- break;
- }
- /* TODO: Implement actual work for parent thread */
- if (!is_mp_running)
- break;
- }
- is_mp_created = 0;
- return NULL;
-}
-
-static apr_status_t pconfig_cleanup(void *data);
-
-static apr_status_t process_cleanup(void *data)
-{
- int advertise_run = ma_advertise_run;
-
- is_mp_running = 0;
- ma_advertise_run = 0;
- if (advertise_run) {
- ma_advertise_stat = HTTP_FORBIDDEN;
- ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
- }
- if (is_mp_created) {
- apr_sleep(1000);
- /* Wait for the parent maintenance thread to finish */
- while (is_mp_created) {
- apr_sleep(MA_TM_RESOLUTION);
- }
- }
- if (advertise_run) {
- ma_advertise_stat = HTTP_GONE;
- ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
- ma_group_leave();
- }
- /* We don't need the post_config cleanup to run,
- */
- apr_pool_cleanup_kill(magd->cpool, magd, pconfig_cleanup);
- magd = NULL;
-
- return APR_SUCCESS;
-}
-
-static apr_status_t pconfig_cleanup(void *data)
-{
- int advertise_run = ma_advertise_run;
-
- is_mp_running = 0;
- ma_advertise_run = 0;
- if (advertise_run) {
- ma_advertise_stat = HTTP_FORBIDDEN;
- ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
- }
-
- if (is_mp_created) {
- apr_sleep(1000);
- /* Wait for the parent maintenance thread to finish */
- while (is_mp_created) {
- apr_sleep(MA_TM_RESOLUTION);
- }
- }
- if (advertise_run) {
- ma_advertise_stat = HTTP_FORBIDDEN;
- ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
- }
- if (magd) {
- /* Remove the process_cleanup.
- * We need to reattach again because the
- * module can be reloaded on different address
- */
- apr_pool_cleanup_kill(magd->ppool, magd, process_cleanup);
- }
- return APR_SUCCESS;
-}
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* Post config hook. */
-/* Create management thread in parent and initializes Manager */
-/* */
-/*--------------------------------------------------------------------------*/
-static int post_config_hook(apr_pool_t *pconf, apr_pool_t *plog,
- apr_pool_t *ptemp, server_rec *s)
-{
- apr_status_t rv;
- const char *pk = "advertise_init_module_tag";
- apr_pool_t *pproc = s->process->pool;
- apr_thread_t *tp;
-
- apr_pool_userdata_get((void *)&magd, pk, pproc);
- if (!magd) {
- if (!(magd = apr_pcalloc(pproc, sizeof(ma_global_data_t))))
- return apr_get_os_error();
- apr_pool_create(&magd->ppool, pproc);
- apr_pool_userdata_set(magd, pk, apr_pool_cleanup_null, pproc);
- /* First time config phase -- skip. */
- return OK;
- }
-#if defined(WIN32)
- {
- const char *ppid = getenv("AP_PARENT_PID");
- if (ppid) {
- ma_parent_pid = atol(ppid);
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
- "[%" APR_PID_T_FMT " - %" APR_PID_T_FMT
- "] in child post config hook",
- getpid(), ma_parent_pid);
- return OK;
- }
- }
-#endif
- ma_server_rec = s;
- if (!magd->generation) {
- /* Favor dynamic configuration */
- if (ma_advertise_skey) {
- apr_md5_ctx_t mc;
- apr_md5_init(&mc);
- apr_md5_update(&mc, ma_advertise_skey, strlen(ma_advertise_skey));
- apr_md5_final(magd->ssalt, &mc);
- }
- apr_uuid_get(&magd->suuid);
- magd->srvid[0] = '/';
- apr_uuid_format(&magd->srvid[1], &magd->suuid);
- }
- if (!ma_advertise_srvh)
- ma_advertise_srvh = magd->srvid;
- if (!ma_advertise_srvm)
- ma_advertise_srvm = apr_pstrdup(pconf, "http");
-
- /* Check if we have advertise set */
- if (ma_advertise_mode != ma_advertise_off &&
- ma_advertise_set && ma_advertise_adrs) {
- rv = ma_group_join(ma_advertise_adrs, ma_advertise_port, pconf);
- if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
- "mod_advertise: multicast join failed for %s:%d.",
- ma_advertise_adrs, ma_advertise_port);
- ma_advertise_run = 0;
- }
- else {
- ma_advertise_run = 1;
- ma_advertise_stat = 200;
- }
- }
-
- /* Create parent management thread */
- is_mp_running = 1;
- rv = apr_thread_create(&tp, NULL, parent_thread, s, pconf);
- if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
- "mod_advertise: parent apr_thread_create");
- return rv;
- }
- apr_thread_detach(tp);
-
- /* Create cleanup pool that will be destroyed first
- * in future use new apr_pool_pre_cleanup_register from APR 1.3
- */
- apr_pool_create(&magd->cpool, pconf);
- apr_pool_cleanup_register(magd->cpool, magd, pconfig_cleanup,
- apr_pool_cleanup_null);
-
- if (magd->generation++) {
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
- "Advertise reinitialized for process %" APR_PID_T_FMT,
- getpid());
- }
- else {
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
- "Advertise initialized for process %" APR_PID_T_FMT,
- getpid());
- }
-
- apr_pool_cleanup_register(magd->ppool, magd, process_cleanup,
- apr_pool_cleanup_null);
-
-
-
- return OK;
-}
-
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* List of directives specific to our module. */
-/* */
-/*--------------------------------------------------------------------------*/
-static const command_rec cmd_table[] =
-{
- AP_INIT_TAKE12(
- "ServerAdvertise", /* directive name */
- cmd_advertise_m, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Server advertise mode: On | Off [Address]"
- ),
- AP_INIT_TAKE1(
- "AdvertiseGroup", /* directive name */
- cmd_advertise_g, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Multicast group address"
- ),
- AP_INIT_TAKE1(
- "AdvertiseFrequency", /* directive name */
- cmd_advertise_f, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Advertise frequency in seconds[.miliseconds]"
- ),
- AP_INIT_TAKE1(
- "AdvertiseSecurityKey", /* directive name */
- cmd_advertise_k, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Advertise security key"
- ),
- AP_INIT_TAKE1(
- "AdvertiseManagerUrl", /* directive name */
- cmd_advertise_h, /* config action routine */
- NULL, /* argument to include in call */
- RSRC_CONF, /* where available */
- "Advertise manager url"
- ),
- {NULL}
-
-};
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* Which functions are responsible for which hooks in the server. */
-/* */
-/*--------------------------------------------------------------------------*/
-static void register_hooks(apr_pool_t *p)
-{
-
- /* Post config handling
- */
- ap_hook_post_config(post_config_hook,
- NULL,
- NULL,
- APR_HOOK_LAST);
-
-}
-
-
-/*--------------------------------------------------------------------------*/
-/* */
-/* The list of callback routines and data structures that provide */
-/* the static hooks into our module from the other parts of the server. */
-/* */
-/*--------------------------------------------------------------------------*/
-module AP_MODULE_DECLARE_DATA advertise_module =
-{
- STANDARD20_MODULE_STUFF,
- NULL, /* per-directory config creator */
- NULL, /* dir config merger */
- NULL, /* server config creator */
- NULL, /* server config merger */
- cmd_table, /* command table */
- register_hooks /* set up other request processing hooks */
-};
Deleted: trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h
===================================================================
--- trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h 2008-06-11 14:15:14 UTC (rev 1692)
+++ trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h 2008-06-11 14:16:31 UTC (rev 1693)
@@ -1,145 +0,0 @@
-/*
- * ModAdvertise - Apache Httpd advertising module
- *
- * 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 Mladen Turk
- */
-
-#ifndef MOD_ADVERTISE_H
-#define MOD_ADVERTISE_H
-
-/**
- * @file mod_advertise.h
- * @brief Advertise Module for Apache Httpd
- *
- * @defgroup MOD_ADVERTISE mod_advertise
- * @ingroup APACHE_MODS
- * @{
- */
-
-#define CORE_PRIVATE
-
-#include "apr_hooks.h"
-#include "apr.h"
-#include "apr_lib.h"
-#include "apr_strings.h"
-#include "apr_buckets.h"
-#include "apr_md5.h"
-#include "apr_network_io.h"
-#include "apr_pools.h"
-#include "apr_strings.h"
-#include "apr_uri.h"
-#include "apr_date.h"
-#include "apr_uuid.h"
-#include "apr_version.h"
-#include "apr_atomic.h"
-
-#define APR_WANT_STRFUNC
-#include "apr_want.h"
-
-#include "httpd.h"
-#include "http_config.h"
-#include "http_core.h"
-#include "http_protocol.h"
-#include "http_request.h"
-#include "http_vhost.h"
-#include "http_main.h"
-#include "http_log.h"
-#include "http_connection.h"
-#include "util_filter.h"
-#include "util_ebcdic.h"
-#include "util_time.h"
-#include "ap_provider.h"
-#include "ap_mpm.h"
-
-#if APR_HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#if APR_HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#if !APR_HAS_THREADS
-#error This module does not compile unless you have a thread capable APR!
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define MA_BSIZE 4096
-#define MA_SSIZE 1024
-#define MA_DEFAULT_ADVPORT 23364
-#define MA_TM_RESOLUTION APR_TIME_C(100000)
-#define MA_DEFAULT_ADV_FREQ apr_time_from_sec(10)
-#define MA_TM_MAINTAIN_STEP 10
-
-/**
- * Multicast Time to Live (ttl) for a advertise transmission.
- */
-#define MA_ADVERTISE_HOPS 10
-
-/**
- * Advertise protocol types
- */
-#define MA_ADVERTISE_SERVER 0
-#define MA_ADVERTISE_STATUS 1
-
-/**
- * Advertise mode enumeration.
- */
-typedef enum {
- ma_advertise_off,
- ma_advertise_status,
- ma_advertise_on
-} ma_advertise_e;
-
-/**
- * Advertise header data structure
- */
-typedef struct ma_advertise_hdr_t ma_advertise_hdr_t;
-struct ma_advertise_hdr_t {
- int type;
- apr_status_t status;
- char suuid[APR_UUID_FORMATTED_LENGTH + 1];
-};
-
-/**
- * Advertise server data structure
- */
-typedef struct ma_advertise_srv_t ma_advertise_srv_t;
-struct ma_advertise_srv_t {
- const char *handle;
- const char *address;
- const char *protocol;
- server_rec *server;
- apr_port_t port;
-};
-
-
-#ifdef __cplusplus
-}
-#endif
-
-/** @} */
-#endif /* MOD_ADVERTISE_H */
Copied: trunk/mod_cluster/native/advertise/Makefile.in (from rev 1691, trunk/httpd/httpd-2.2/modules/advertise/Makefile.apxs.in)
===================================================================
--- trunk/mod_cluster/native/advertise/Makefile.in (rev 0)
+++ trunk/mod_cluster/native/advertise/Makefile.in 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,23 @@
+# Makefile.in for mod_proxy_cluster
+# copy the source in the httpd Apache source tree
+APACHE_BASE = @APACHE_BASE@
+top_builddir = @APACHE_BASE@
+# For .deps.
+builddir = @CLUSTER_BASE@
+# For the apache includes
+top_srcdir = @APACHE_BASE@
+
+include $(APACHE_BASE)/build/rules.mk
+SH_COMPILE = $(LIBTOOL) --mode=compile $(BASE_CC) -I../include -prefer-pic -c $< && touch $@
+
+all: mod_advertise.so
+
+mod_advertise.so: mod_advertise.la
+ $(APACHE_BASE)/build/instdso.sh SH_LIBTOOL='$(LIBTOOL)' mod_advertise.la `pwd`
+
+mod_advertise.la: mod_advertise.slo
+ $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_advertise.lo
+
+clean:
+ rm -f *.o *.lo *.slo
+ rm -rf .libs
Copied: trunk/mod_cluster/native/advertise/README (from rev 1691, trunk/httpd/httpd-2.2/modules/advertise/README)
===================================================================
--- trunk/mod_cluster/native/advertise/README (rev 0)
+++ trunk/mod_cluster/native/advertise/README 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,17 @@
+The source could be in httpd-2.2.x source tree.
+The ./buildconf must be run again amd the configure need at least:
+./configure --enable-advertise
+
+The source could build with a installed version of httpd-2-2.x:
+sh buildconf
+./configure --with-apache=apache_installation_directory.
+make -f Makefile.apxs
+The mod_advertise.so need to be copied to apache_installation_directory/modules
+
+Configuration use something like the following in httpd.conf:
+LoadModule advertise_module modules/mod_advertise.so
+ServerAdvertise on
+AdvertiseGroup 232.0.0.2
+AdvertiseFrequency 30
+
+Note default port is 23364.
Copied: trunk/mod_cluster/native/advertise/buildconf (from rev 1691, trunk/httpd/httpd-2.2/modules/advertise/buildconf)
===================================================================
--- trunk/mod_cluster/native/advertise/buildconf (rev 0)
+++ trunk/mod_cluster/native/advertise/buildconf 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+rm -rf aclocal.m4 autom4te*.cache
+
+echo "Creating configure ..."
+### do some work to toss config.cache?
+if ${AUTOCONF:-autoconf}; then
+ :
+else
+ echo "autoconf failed"
+ exit 1
+fi
Copied: trunk/mod_cluster/native/advertise/configure.in (from rev 1691, trunk/httpd/httpd-2.2/modules/advertise/configure.in)
===================================================================
--- trunk/mod_cluster/native/advertise/configure.in (rev 0)
+++ trunk/mod_cluster/native/advertise/configure.in 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,24 @@
+dnl configure for mod_manager
+dnl
+
+AC_INIT(mod_advertise.c)
+
+AC_MSG_CHECKING(for Apache httpd installation)
+AC_ARG_WITH(apache,
+[ --with-apache[=DIR] DIR is the apache base installation
+],
+[ if test "$withval" = "yes"; then
+ withval=/usr/local/etc/httpd
+ fi
+ if test "$withval" != "no"; then
+ APACHE_BASE=$withval
+ else
+ AC_MSG_ERROR(mod_manager need a valid apache location)
+ fi
+],
+[ AC_MSG_ERROR(Please use --with-apache[=DIR])])
+CLUSTER_BASE=`pwd`
+
+AC_SUBST(APACHE_BASE)
+AC_SUBST(CLUSTER_BASE)
+AC_OUTPUT(Makefile.apxs)
Copied: trunk/mod_cluster/native/advertise/mod_advertise.c (from rev 1691, trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.c)
===================================================================
--- trunk/mod_cluster/native/advertise/mod_advertise.c (rev 0)
+++ trunk/mod_cluster/native/advertise/mod_advertise.c 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,642 @@
+/*
+ * ModAdvertise - Apache Httpd advertising module
+ *
+ * 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 Mladen Turk
+ */
+
+#define CORE_PRIVATE
+
+#include "mod_advertise.h"
+#include "mod_core.h"
+#include "util_script.h"
+
+#ifndef MAX
+#define MAX(x,y) ((x) >= (y) ? (x) : (y))
+#endif
+
+#define MOD_SRVCONF(p) ap_get_module_config((p)->server->module_config, \
+ &advertise_module)
+#define MOD_GETCONF(s) ap_get_module_config((s)->module_config, \
+ &advertise_module)
+
+/*
+ * Declare ourselves so the configuration routines can find and know us.
+ * We'll fill it in at the end of the module.
+ */
+module AP_MODULE_DECLARE_DATA advertise_module;
+
+
+
+/*
+ * Server private data
+ */
+static int ma_generation = 0;
+static apr_time_t ma_child_started = 0;
+static pid_t ma_parent_pid = -1;
+
+/*
+ * Global configuration
+ */
+static int ma_manager_strict = 0;
+static int ma_advertise_set = 0;
+static int ma_advertise_run = 0;
+static int ma_advertise_stat = 0;
+static char *ma_advertise_adrs = NULL;
+static char *ma_advertise_adsi = NULL;
+static char *ma_advertise_srvm = NULL;
+static char *ma_advertise_srvh = NULL;
+static char *ma_advertise_srvs = NULL;
+static char *ma_advertise_srvi = NULL;
+static char *ma_advertise_uuid = NULL;
+
+static char *ma_advertise_skey = NULL;
+
+
+static ma_advertise_srv_t ma_advs_server;
+
+
+/* Advertise is by default turned off */
+static apr_port_t ma_advertise_port = MA_DEFAULT_ADVPORT;
+static apr_port_t ma_advertise_srvp = 0;
+static ma_advertise_e ma_advertise_mode = ma_advertise_off;
+static apr_interval_time_t ma_advertise_freq = MA_DEFAULT_ADV_FREQ;
+
+/* Advertise sockets */
+static apr_socket_t *ma_mgroup_socket = NULL;
+static apr_socket_t *ma_listen_socket = NULL;
+static apr_sockaddr_t *ma_mgroup_sa = NULL;
+static apr_sockaddr_t *ma_listen_sa = NULL;
+
+static server_rec *ma_server_rec = NULL;
+
+/* Advertise sequence number */
+static volatile apr_int64_t ma_sequence = 0;
+
+
+/* Parent and child manager thread statuses */
+static volatile int is_mp_running = 0;
+static volatile int is_mp_created = 0;
+
+/*
+ * Server global data
+ */
+typedef struct ma_global_data_t {
+ int generation;
+ unsigned char ssalt[APR_MD5_DIGESTSIZE];
+ apr_uuid_t suuid;
+ char srvid[APR_UUID_FORMATTED_LENGTH + 2];
+ apr_pool_t *ppool;
+ apr_pool_t *cpool;
+} ma_global_data_t;
+
+/*
+ * Global data instance
+ * For parent, registered in process pool
+ */
+static ma_global_data_t *magd = NULL;
+
+/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the
+ * IPv4 match-any-address, 0.0.0.0. */
+#define IS_INADDR_ANY(addr) ((addr)->family == APR_INET && \
+ (addr)->sa.sin.sin_addr.s_addr == INADDR_ANY)
+
+/* Evaluates to true if the (apr_sockaddr_t *) addr argument is the
+ * IPv6 match-any-address, [::]. */
+#define IS_IN6ADDR_ANY(addr) ((addr)->family == APR_INET6 && \
+ IN6_IS_ADDR_UNSPECIFIED(&(addr)->sa.sin6.sin6_addr))
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* ServerAdvertise directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_m(cmd_parms *cmd, void *dummy,
+ const char *arg, const char *opt)
+{
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+
+ if (strcasecmp(arg, "Off") == 0)
+ ma_advertise_mode = ma_advertise_off;
+ else if (strcasecmp(arg, "On") == 0)
+ ma_advertise_mode = ma_advertise_on;
+ else
+ return "ServerAdvertise must be Off or On";
+ if (opt) {
+ const char *p = ap_strstr_c(opt, "://");
+ if (p) {
+ ma_advertise_srvm = apr_pstrndup(cmd->pool, opt, p - opt);
+ opt = p + 3;
+ }
+ if (apr_parse_addr_port(&ma_advertise_srvs,
+ &ma_advertise_srvi,
+ &ma_advertise_srvp,
+ opt, cmd->pool) != APR_SUCCESS ||
+ !ma_advertise_srvs ||
+ !ma_advertise_srvp)
+ return "Invalid ServerAdvertise Address";
+ }
+ return NULL;
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* AdvertiseGroup directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_g(cmd_parms *cmd, void *dummy,
+ const char *arg)
+{
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+ if (ma_advertise_set)
+ return "Duplicate AdvertiseGroup directives are not allowed";
+
+ if (apr_parse_addr_port(&ma_advertise_adrs,
+ &ma_advertise_adsi,
+ &ma_advertise_port,
+ arg, cmd->pool) != APR_SUCCESS)
+ return "Invalid AdvertiseGroup address";
+ if (!ma_advertise_adrs)
+ return "Missing Ip part from AdvertiseGroup address";
+ if (!ma_advertise_port)
+ ma_advertise_port = MA_DEFAULT_ADVPORT;
+ ma_advertise_set = 1;
+ return NULL;
+}
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* AdvertiseFrequency directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_f(cmd_parms *cmd, void *dummy,
+ const char *arg)
+{
+ apr_time_t s, u = 0;
+ const char *p;
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+ if ((p = ap_strchr_c(arg, '.')) || (p = ap_strchr_c(arg, ',')))
+ u = atoi(p + 1);
+
+ s = atoi(arg);
+ ma_advertise_freq = s * APR_USEC_PER_SEC + u * APR_TIME_C(1000);
+ if (ma_advertise_freq == 0)
+ return "Invalid AdvertiseFrequency value";
+
+ return NULL;
+}
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* AdvertiseSecurityKey directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_k(cmd_parms *cmd, void *dummy,
+ const char *arg)
+{
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+ ma_advertise_skey = apr_pstrdup(cmd->pool, arg);
+ return NULL;
+}
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* AdvertiseManagerUrl directive */
+/* */
+/*--------------------------------------------------------------------------*/
+static const char *cmd_advertise_h(cmd_parms *cmd, void *dummy,
+ const char *arg)
+{
+ const char *errs = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+
+ if (errs != NULL)
+ return errs;
+ ma_advertise_srvh = apr_pstrdup(cmd->pool, arg);
+ return NULL;
+}
+
+#define MA_ADVERTISE_SERVER_FMT \
+ "HTTP/1.0 %s" CRLF \
+ "Date: %s" CRLF \
+ "Sequence: %" APR_INT64_T_FMT CRLF \
+ "Digest: %s" CRLF \
+ "Server: %s" CRLF
+
+static const char *hex = "0123456789abcdef";
+
+apr_status_t ma_advertise_server(server_rec *server, int type)
+{
+ char buf[MA_BSIZE];
+ char dat[APR_RFC822_DATE_LEN];
+ unsigned char msig[APR_MD5_DIGESTSIZE];
+ unsigned char ssig[APR_MD5_DIGESTSIZE * 2 + 1];
+ const char *asl;
+ char *p = buf;
+ int i, c = 0;
+ apr_size_t l = MA_BSIZE - 8;
+ apr_size_t n = 0;
+ apr_md5_ctx_t md;
+
+ ma_sequence++;
+ if (ma_sequence < 1)
+ ma_sequence = 1;
+ sprintf(buf, "%" APR_INT64_T_FMT, ma_sequence);
+ ap_recent_rfc822_date(dat, apr_time_now());
+ asl = ap_get_status_line(ma_advertise_stat);
+
+ /* Create MD5 digest
+ * salt + date + sequence + srvid
+ */
+ apr_md5_init(&md);
+ apr_md5_update(&md, magd->ssalt, APR_MD5_DIGESTSIZE);
+ apr_md5_update(&md, dat, strlen(dat));
+ apr_md5_update(&md, buf, strlen(buf));
+ apr_md5_update(&md, magd->srvid + 1, strlen(magd->srvid) - 1);
+ apr_md5_final(msig, &md);
+ /* Convert MD5 digest to hex string */
+ for (i = 0; i < APR_MD5_DIGESTSIZE; i++) {
+ ssig[c++] = hex[msig[i] >> 4];
+ ssig[c++] = hex[msig[i] & 0x0F];
+ }
+ ssig[c] = '\0';
+ n = apr_snprintf(p, l, MA_ADVERTISE_SERVER_FMT,
+ asl, dat, ma_sequence, ssig, magd->srvid + 1);
+ if (type == MA_ADVERTISE_SERVER) {
+ l -= n;
+ n += apr_snprintf(p + n, l,
+ "X-Manager-Address: %s:%u" CRLF
+ "X-Manager-Url: %s" CRLF
+ "X-Manager-Protocol: %s" CRLF
+ "X-Manager-Host: %s" CRLF,
+ ma_advertise_srvs,
+ ma_advertise_srvp,
+ ma_advertise_srvh,
+ ma_advertise_srvm,
+ server->server_hostname);
+
+ }
+ strcat(p, CRLF);
+ n += 2;
+ return apr_socket_sendto(ma_mgroup_socket,
+ ma_mgroup_sa, 0, buf, &n);
+}
+
+static apr_status_t ma_group_join(const char *addr, apr_port_t port,
+ apr_pool_t *pool)
+{
+ apr_status_t rv;
+
+ if ((rv = apr_sockaddr_info_get(&ma_mgroup_sa, addr,
+ APR_INET, port,
+ APR_UNSPEC, pool)) != APR_SUCCESS)
+ return rv;
+ if ((rv = apr_socket_create(&ma_mgroup_socket,
+ ma_mgroup_sa->family,
+ SOCK_DGRAM,
+ APR_PROTO_UDP,
+ pool)) != APR_SUCCESS)
+ return rv;
+ if ((rv = apr_mcast_join(ma_mgroup_socket, ma_mgroup_sa,
+ NULL, NULL)) != APR_SUCCESS) {
+ apr_socket_close(ma_mgroup_socket);
+ return rv;
+ }
+ if ((rv = apr_mcast_hops(ma_mgroup_socket,
+ MA_ADVERTISE_HOPS)) != APR_SUCCESS) {
+ apr_mcast_leave(ma_mgroup_socket, ma_mgroup_sa,
+ NULL, NULL);
+ apr_socket_close(ma_mgroup_socket);
+ return rv;
+ }
+ return APR_SUCCESS;
+}
+
+static void ma_group_leave()
+{
+ if (ma_mgroup_socket) {
+ apr_mcast_leave(ma_mgroup_socket, ma_mgroup_sa,
+ NULL, NULL);
+ apr_socket_close(ma_mgroup_socket);
+ ma_mgroup_socket = NULL;
+ }
+}
+
+static void * APR_THREAD_FUNC parent_thread(apr_thread_t *thd, void *data)
+{
+ static int current_status = 0;
+ int f_time = 1;
+ apr_interval_time_t a_step = 0;
+ server_rec *s = (server_rec *)data;
+ is_mp_created = 1;
+
+ while (is_mp_running) {
+ apr_sleep(MA_TM_RESOLUTION);
+ if (!is_mp_running)
+ break;
+ if (ma_advertise_run) {
+ a_step += MA_TM_RESOLUTION;
+ if (current_status != ma_advertise_stat) {
+ /* Force advertise on status change */
+ current_status = ma_advertise_stat;
+ f_time = 1;
+ }
+ if (a_step >= ma_advertise_freq || f_time) {
+ /* Run advertise */
+ ma_advertise_server(s, MA_ADVERTISE_SERVER);
+ a_step = 0;
+ f_time = 0;
+ }
+ if (!is_mp_running)
+ break;
+ }
+ /* TODO: Implement actual work for parent thread */
+ if (!is_mp_running)
+ break;
+ }
+ is_mp_created = 0;
+ return NULL;
+}
+
+static apr_status_t pconfig_cleanup(void *data);
+
+static apr_status_t process_cleanup(void *data)
+{
+ int advertise_run = ma_advertise_run;
+
+ is_mp_running = 0;
+ ma_advertise_run = 0;
+ if (advertise_run) {
+ ma_advertise_stat = HTTP_FORBIDDEN;
+ ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
+ }
+ if (is_mp_created) {
+ apr_sleep(1000);
+ /* Wait for the parent maintenance thread to finish */
+ while (is_mp_created) {
+ apr_sleep(MA_TM_RESOLUTION);
+ }
+ }
+ if (advertise_run) {
+ ma_advertise_stat = HTTP_GONE;
+ ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
+ ma_group_leave();
+ }
+ /* We don't need the post_config cleanup to run,
+ */
+ apr_pool_cleanup_kill(magd->cpool, magd, pconfig_cleanup);
+ magd = NULL;
+
+ return APR_SUCCESS;
+}
+
+static apr_status_t pconfig_cleanup(void *data)
+{
+ int advertise_run = ma_advertise_run;
+
+ is_mp_running = 0;
+ ma_advertise_run = 0;
+ if (advertise_run) {
+ ma_advertise_stat = HTTP_FORBIDDEN;
+ ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
+ }
+
+ if (is_mp_created) {
+ apr_sleep(1000);
+ /* Wait for the parent maintenance thread to finish */
+ while (is_mp_created) {
+ apr_sleep(MA_TM_RESOLUTION);
+ }
+ }
+ if (advertise_run) {
+ ma_advertise_stat = HTTP_FORBIDDEN;
+ ma_advertise_server(ma_server_rec, MA_ADVERTISE_STATUS);
+ }
+ if (magd) {
+ /* Remove the process_cleanup.
+ * We need to reattach again because the
+ * module can be reloaded on different address
+ */
+ apr_pool_cleanup_kill(magd->ppool, magd, process_cleanup);
+ }
+ return APR_SUCCESS;
+}
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* Post config hook. */
+/* Create management thread in parent and initializes Manager */
+/* */
+/*--------------------------------------------------------------------------*/
+static int post_config_hook(apr_pool_t *pconf, apr_pool_t *plog,
+ apr_pool_t *ptemp, server_rec *s)
+{
+ apr_status_t rv;
+ const char *pk = "advertise_init_module_tag";
+ apr_pool_t *pproc = s->process->pool;
+ apr_thread_t *tp;
+
+ apr_pool_userdata_get((void *)&magd, pk, pproc);
+ if (!magd) {
+ if (!(magd = apr_pcalloc(pproc, sizeof(ma_global_data_t))))
+ return apr_get_os_error();
+ apr_pool_create(&magd->ppool, pproc);
+ apr_pool_userdata_set(magd, pk, apr_pool_cleanup_null, pproc);
+ /* First time config phase -- skip. */
+ return OK;
+ }
+#if defined(WIN32)
+ {
+ const char *ppid = getenv("AP_PARENT_PID");
+ if (ppid) {
+ ma_parent_pid = atol(ppid);
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
+ "[%" APR_PID_T_FMT " - %" APR_PID_T_FMT
+ "] in child post config hook",
+ getpid(), ma_parent_pid);
+ return OK;
+ }
+ }
+#endif
+ ma_server_rec = s;
+ if (!magd->generation) {
+ /* Favor dynamic configuration */
+ if (ma_advertise_skey) {
+ apr_md5_ctx_t mc;
+ apr_md5_init(&mc);
+ apr_md5_update(&mc, ma_advertise_skey, strlen(ma_advertise_skey));
+ apr_md5_final(magd->ssalt, &mc);
+ }
+ apr_uuid_get(&magd->suuid);
+ magd->srvid[0] = '/';
+ apr_uuid_format(&magd->srvid[1], &magd->suuid);
+ }
+ if (!ma_advertise_srvh)
+ ma_advertise_srvh = magd->srvid;
+ if (!ma_advertise_srvm)
+ ma_advertise_srvm = apr_pstrdup(pconf, "http");
+
+ /* Check if we have advertise set */
+ if (ma_advertise_mode != ma_advertise_off &&
+ ma_advertise_set && ma_advertise_adrs) {
+ rv = ma_group_join(ma_advertise_adrs, ma_advertise_port, pconf);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, s,
+ "mod_advertise: multicast join failed for %s:%d.",
+ ma_advertise_adrs, ma_advertise_port);
+ ma_advertise_run = 0;
+ }
+ else {
+ ma_advertise_run = 1;
+ ma_advertise_stat = 200;
+ }
+ }
+
+ /* Create parent management thread */
+ is_mp_running = 1;
+ rv = apr_thread_create(&tp, NULL, parent_thread, s, pconf);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s,
+ "mod_advertise: parent apr_thread_create");
+ return rv;
+ }
+ apr_thread_detach(tp);
+
+ /* Create cleanup pool that will be destroyed first
+ * in future use new apr_pool_pre_cleanup_register from APR 1.3
+ */
+ apr_pool_create(&magd->cpool, pconf);
+ apr_pool_cleanup_register(magd->cpool, magd, pconfig_cleanup,
+ apr_pool_cleanup_null);
+
+ if (magd->generation++) {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+ "Advertise reinitialized for process %" APR_PID_T_FMT,
+ getpid());
+ }
+ else {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s,
+ "Advertise initialized for process %" APR_PID_T_FMT,
+ getpid());
+ }
+
+ apr_pool_cleanup_register(magd->ppool, magd, process_cleanup,
+ apr_pool_cleanup_null);
+
+
+
+ return OK;
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* List of directives specific to our module. */
+/* */
+/*--------------------------------------------------------------------------*/
+static const command_rec cmd_table[] =
+{
+ AP_INIT_TAKE12(
+ "ServerAdvertise", /* directive name */
+ cmd_advertise_m, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Server advertise mode: On | Off [Address]"
+ ),
+ AP_INIT_TAKE1(
+ "AdvertiseGroup", /* directive name */
+ cmd_advertise_g, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Multicast group address"
+ ),
+ AP_INIT_TAKE1(
+ "AdvertiseFrequency", /* directive name */
+ cmd_advertise_f, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Advertise frequency in seconds[.miliseconds]"
+ ),
+ AP_INIT_TAKE1(
+ "AdvertiseSecurityKey", /* directive name */
+ cmd_advertise_k, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Advertise security key"
+ ),
+ AP_INIT_TAKE1(
+ "AdvertiseManagerUrl", /* directive name */
+ cmd_advertise_h, /* config action routine */
+ NULL, /* argument to include in call */
+ RSRC_CONF, /* where available */
+ "Advertise manager url"
+ ),
+ {NULL}
+
+};
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* Which functions are responsible for which hooks in the server. */
+/* */
+/*--------------------------------------------------------------------------*/
+static void register_hooks(apr_pool_t *p)
+{
+
+ /* Post config handling
+ */
+ ap_hook_post_config(post_config_hook,
+ NULL,
+ NULL,
+ APR_HOOK_LAST);
+
+}
+
+
+/*--------------------------------------------------------------------------*/
+/* */
+/* The list of callback routines and data structures that provide */
+/* the static hooks into our module from the other parts of the server. */
+/* */
+/*--------------------------------------------------------------------------*/
+module AP_MODULE_DECLARE_DATA advertise_module =
+{
+ STANDARD20_MODULE_STUFF,
+ NULL, /* per-directory config creator */
+ NULL, /* dir config merger */
+ NULL, /* server config creator */
+ NULL, /* server config merger */
+ cmd_table, /* command table */
+ register_hooks /* set up other request processing hooks */
+};
Copied: trunk/mod_cluster/native/advertise/mod_advertise.h (from rev 1691, trunk/httpd/httpd-2.2/modules/advertise/mod_advertise.h)
===================================================================
--- trunk/mod_cluster/native/advertise/mod_advertise.h (rev 0)
+++ trunk/mod_cluster/native/advertise/mod_advertise.h 2008-06-11 14:16:31 UTC (rev 1693)
@@ -0,0 +1,145 @@
+/*
+ * ModAdvertise - Apache Httpd advertising module
+ *
+ * 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 Mladen Turk
+ */
+
+#ifndef MOD_ADVERTISE_H
+#define MOD_ADVERTISE_H
+
+/**
+ * @file mod_advertise.h
+ * @brief Advertise Module for Apache Httpd
+ *
+ * @defgroup MOD_ADVERTISE mod_advertise
+ * @ingroup APACHE_MODS
+ * @{
+ */
+
+#define CORE_PRIVATE
+
+#include "apr_hooks.h"
+#include "apr.h"
+#include "apr_lib.h"
+#include "apr_strings.h"
+#include "apr_buckets.h"
+#include "apr_md5.h"
+#include "apr_network_io.h"
+#include "apr_pools.h"
+#include "apr_strings.h"
+#include "apr_uri.h"
+#include "apr_date.h"
+#include "apr_uuid.h"
+#include "apr_version.h"
+#include "apr_atomic.h"
+
+#define APR_WANT_STRFUNC
+#include "apr_want.h"
+
+#include "httpd.h"
+#include "http_config.h"
+#include "http_core.h"
+#include "http_protocol.h"
+#include "http_request.h"
+#include "http_vhost.h"
+#include "http_main.h"
+#include "http_log.h"
+#include "http_connection.h"
+#include "util_filter.h"
+#include "util_ebcdic.h"
+#include "util_time.h"
+#include "ap_provider.h"
+#include "ap_mpm.h"
+
+#if APR_HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#if APR_HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+
+#if !APR_HAS_THREADS
+#error This module does not compile unless you have a thread capable APR!
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define MA_BSIZE 4096
+#define MA_SSIZE 1024
+#define MA_DEFAULT_ADVPORT 23364
+#define MA_TM_RESOLUTION APR_TIME_C(100000)
+#define MA_DEFAULT_ADV_FREQ apr_time_from_sec(10)
+#define MA_TM_MAINTAIN_STEP 10
+
+/**
+ * Multicast Time to Live (ttl) for a advertise transmission.
+ */
+#define MA_ADVERTISE_HOPS 10
+
+/**
+ * Advertise protocol types
+ */
+#define MA_ADVERTISE_SERVER 0
+#define MA_ADVERTISE_STATUS 1
+
+/**
+ * Advertise mode enumeration.
+ */
+typedef enum {
+ ma_advertise_off,
+ ma_advertise_status,
+ ma_advertise_on
+} ma_advertise_e;
+
+/**
+ * Advertise header data structure
+ */
+typedef struct ma_advertise_hdr_t ma_advertise_hdr_t;
+struct ma_advertise_hdr_t {
+ int type;
+ apr_status_t status;
+ char suuid[APR_UUID_FORMATTED_LENGTH + 1];
+};
+
+/**
+ * Advertise server data structure
+ */
+typedef struct ma_advertise_srv_t ma_advertise_srv_t;
+struct ma_advertise_srv_t {
+ const char *handle;
+ const char *address;
+ const char *protocol;
+ server_rec *server;
+ apr_port_t port;
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @} */
+#endif /* MOD_ADVERTISE_H */
Modified: trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c
===================================================================
--- trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-11 14:15:14 UTC (rev 1692)
+++ trunk/mod_cluster/native/mod_proxy_cluster/mod_proxy_cluster.c 2008-06-11 14:16:31 UTC (rev 1693)
@@ -179,7 +179,7 @@
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->lbmethod = ap_lookup_provider(PROXY_LBMETHOD, "cluster_byrequests", "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
@@ -661,12 +661,11 @@
* context and host to prevent to route to application beeing redeploy or
* stopped in one node but not in others.
*/
-static proxy_worker *find_best_bytraffic(proxy_balancer *balancer,
+static proxy_worker *find_best_byrequests(proxy_balancer *balancer,
request_rec *r)
{
int i;
- apr_off_t mytraffic = 0;
- apr_off_t curmin = 0;
+ int total_factor = 0;
proxy_worker *worker;
proxy_worker *mycandidate = NULL;
int cur_lbset = 0;
@@ -678,7 +677,7 @@
ap_get_module_config(sconf, &proxy_module);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy: Entering bytraffic for CLUSTER (%s)",
+ "proxy: Entering byrequests for CLUSTER (%s)",
balancer->name);
/* create workers for new nodes */
@@ -723,11 +722,10 @@
mycandidate = worker;
break; /* Done */
} else {
- mytraffic = (worker->s->transferred/worker->s->lbfactor) +
- (worker->s->read/worker->s->lbfactor);
- if (!mycandidate || mytraffic < curmin) {
+ worker->s->lbstatus += worker->s->lbfactor;
+ total_factor += worker->s->lbfactor;
+ if (!mycandidate || worker->s->lbstatus < mycandidate->s->lbstatus) {
mycandidate = worker;
- curmin = mytraffic;
}
}
}
@@ -738,18 +736,19 @@
} while (cur_lbset <= max_lbset && !mycandidate);
if (mycandidate) {
+ mycandidate->s->lbstatus -= total_factor;
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy: bytraffic balancer DONE (%s)", mycandidate->name);
+ "proxy: byrequests balancer DONE (%s)", mycandidate->name);
} else {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy: bytraffic balancer FAILED");
+ "proxy: byrequests balancer FAILED");
}
return mycandidate;
}
-static const proxy_balancer_method bytraffic =
+static const proxy_balancer_method byrequests =
{
- "bytraffic",
- &find_best_bytraffic,
+ "byrequests",
+ &find_best_byrequests,
NULL
};
@@ -1451,7 +1450,7 @@
ap_hook_post_config(proxy_cluster_post_config, NULL, NULL, APR_HOOK_MIDDLE);
/* create the provider for the proxy logic */
- ap_register_provider(p, PROXY_LBMETHOD, "cluster_bytraffic", "0", &bytraffic);
+ ap_register_provider(p, PROXY_LBMETHOD, "cluster_byrequests", "0", &byrequests);
/* create the "maintenance" thread */
ap_hook_child_init(proxy_cluster_child_init, NULL, NULL, APR_HOOK_MIDDLE);
16 years, 6 months