Author: jfrederic.clere(a)jboss.com
Date: 2008-03-19 10:45:04 -0400 (Wed, 19 Mar 2008)
New Revision: 1448
Added:
sandbox/httpd/src/java/DumpMethod.java
Modified:
sandbox/httpd/src/java/TestHttpClient.java
sandbox/httpd/src/native/common/context.h
sandbox/httpd/src/native/common/host.h
sandbox/httpd/src/native/common/node.h
sandbox/httpd/src/native/mod_manager/Makefile.in
sandbox/httpd/src/native/mod_manager/mod_manager.c
Log:
Add logic to insert Alias and Context.
Added: sandbox/httpd/src/java/DumpMethod.java
===================================================================
--- sandbox/httpd/src/java/DumpMethod.java (rev 0)
+++ sandbox/httpd/src/java/DumpMethod.java 2008-03-19 14:45:04 UTC (rev 1448)
@@ -0,0 +1,9 @@
+import org.apache.commons.httpclient.methods.PostMethod;
+public class DumpMethod extends PostMethod {
+ public String getName() {
+ return "DUMP";
+ }
+ public DumpMethod(String uri) {
+ super(uri);
+ }
+}
Modified: sandbox/httpd/src/java/TestHttpClient.java
===================================================================
--- sandbox/httpd/src/java/TestHttpClient.java 2008-03-19 08:23:13 UTC (rev 1447)
+++ sandbox/httpd/src/java/TestHttpClient.java 2008-03-19 14:45:04 UTC (rev 1448)
@@ -23,22 +23,33 @@
}
runit(args[0], args[1]);
}
- public static int runit(String URL, String Command) throws Exception
+ public static int runit(String URL, String command) throws Exception
{
HttpClient httpClient = new HttpClient();
- DisableMethod pm = new DisableMethod(URL);
+ PostMethod pm = null;
+ if (command.compareToIgnoreCase("DISABLE")==0) {
+ pm = (PostMethod) new DisableMethod(URL);
+ pm.addParameter("JVMRoute","node1");
+ pm.addParameter("context", "/hisapp");
+ }
+ else if (command.compareToIgnoreCase("CONFIG")==0) {
+ pm = (PostMethod) new ConfigMethod(URL);
+ pm.addParameter("JVMRoute","node1");
+ pm.addParameter("Domain", "domain1");
+ pm.addParameter("Host", "jfcpc");
+ pm.addParameter("Port", "8009");
+ pm.addParameter("Type", "ajp");
+ pm.addParameter("Context", "/hisapp,/myapp");
+ }
+ else if (command.compareToIgnoreCase("DUMP")==0) {
+ pm = (PostMethod) new DumpMethod(URL);
+ }
+ else
+ pm = (PostMethod) new InfoMethod(URL);
+
System.out.println("Connecting to " + URL);
- pm.addParameter("firstname","moi");
- pm.addParameter("lastname", "me");
- pm.addParameter("context", "/myapp");
- pm.addParameter("context", "/yourapp");
- pm.addParameter("context", "/hisapp");
-/*
- pm.setRequestEntity(new
StringRequestEntity("firstname=moi-meme&lastname=toi-meme&comment=test",
-
"application/x-www-form-urlencoded",
- "UTF8"));
- */
+
Integer connectionTimeout = 40000;
pm.getParams().setParameter("http.socket.timeout",
connectionTimeout);
pm.getParams().setParameter("http.connection.timeout",
connectionTimeout);
@@ -49,6 +60,9 @@
try {
httpResponseCode = httpClient.executeMethod(pm);
System.out.println("response: " + httpResponseCode);
+ System.out.println("response: " + pm.getStatusLine());
+ int len = (int) pm.getResponseContentLength();
+ System.out.println("response: " +
pm.getResponseBodyAsString(len));
} catch(HttpException e) {
e.printStackTrace();
}
Modified: sandbox/httpd/src/native/common/context.h
===================================================================
--- sandbox/httpd/src/native/common/context.h 2008-03-19 08:23:13 UTC (rev 1447)
+++ sandbox/httpd/src/native/common/context.h 2008-03-19 14:45:04 UTC (rev 1448)
@@ -39,12 +39,16 @@
#define CONTEXTEXE ".contexts"
+#ifndef MEM_T
typedef struct mem mem_t;
+#define MEM_T
+#endif
/* status of the context as read/store in httpd. */
struct contextinfo {
char context[40]; /* Context where the application is mapped. */
int vhost; /* id of the correspond virtual host in hosts table */
+ int node; /* id of the correspond node in nodes table */
int status; /* status: ENABLED/DISABLED/STOPPED */
unsigned long updatetime; /* time of last received message */
Modified: sandbox/httpd/src/native/common/host.h
===================================================================
--- sandbox/httpd/src/native/common/host.h 2008-03-19 08:23:13 UTC (rev 1447)
+++ sandbox/httpd/src/native/common/host.h 2008-03-19 14:45:04 UTC (rev 1448)
@@ -39,7 +39,10 @@
#define HOSTEXE ".hosts"
+#ifndef MEM_T
typedef struct mem mem_t;
+#define MEM_T
+#endif
/* status of the host as read/store in httpd. */
struct hostinfo {
Modified: sandbox/httpd/src/native/common/node.h
===================================================================
--- sandbox/httpd/src/native/common/node.h 2008-03-19 08:23:13 UTC (rev 1447)
+++ sandbox/httpd/src/native/common/node.h 2008-03-19 14:45:04 UTC (rev 1448)
@@ -39,7 +39,10 @@
#define NODEEXE ".nodes"
+#ifndef MEM_T
typedef struct mem mem_t;
+#define MEM_T
+#endif
/* To support IPv6 (and use IPv4-compatible address). */
struct contact {
Modified: sandbox/httpd/src/native/mod_manager/Makefile.in
===================================================================
--- sandbox/httpd/src/native/mod_manager/Makefile.in 2008-03-19 08:23:13 UTC (rev 1447)
+++ sandbox/httpd/src/native/mod_manager/Makefile.in 2008-03-19 14:45:04 UTC (rev 1448)
@@ -16,7 +16,7 @@
# For .deps.
builddir = @MANAGER_BASE@
-MOD_OBJS_LO=../common/node.lo ../common/sharedmem_util.lo
+MOD_OBJS_LO=../common/node.lo ../common/host.lo ../common/context.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-03-19 08:23:13 UTC (rev 1447)
+++ sandbox/httpd/src/native/mod_manager/mod_manager.c 2008-03-19 14:45:04 UTC (rev 1448)
@@ -26,13 +26,17 @@
#include "http_core.h"
#include "node.h"
+#include "host.h"
+#include "context.h"
#define DEFMAXCONTEXT 100
#define DEFMAXNODE 10
+#define DEFMAXHOST 20
/* shared memory */
mem_t *contextstatsmem = NULL;
mem_t *nodestatsmem = NULL;
+mem_t *hoststatsmem = NULL;
module AP_MODULE_DECLARE_DATA manager_module;
@@ -50,7 +54,10 @@
int maxcontext;
/* max munber of node supported */
int maxnode;
+ /* max munber of host supported */
+ int maxhost;
/* Balancer name */
+ /* Balancer name */
char *balancername;
/* store the balancer names */
struct baldata *baldata;
@@ -79,6 +86,12 @@
loc_get_max_size_node
};
+struct cluster_host {
+ char *host;
+ char *context;
+ struct cluster_host *next;
+};
+
/*
* read the balancer name from the conf and the port of client address
*/
@@ -112,13 +125,16 @@
{
char *node;
char *context;
+ char *host;
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);
} else {
node = "manager.node";
context = "manager.context";
+ context = "manager.host";
}
nodestatsmem = create_mem_node(node, &mconf->maxnode, p);
@@ -127,13 +143,17 @@
return !OK;
}
- /* XXX: need the context logic
contextstatsmem = create_mem_context(node, &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);
+ if (hoststatsmem == NULL) {
+ ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, s, "create_mem_host
failed");
+ return !OK;
+ }
return OK;
}
static char **process_buff(request_rec *r, char *buff)
@@ -163,8 +183,72 @@
}
return ptr;
}
+/*
+ * Insert the hosts from Alias information
+ */
+static int insert_update_hosts(mem_t *mem, char *str, int node, int vhost)
+{
+ char *ptr = str;
+ char *previous = str;
+ int ret = 0;
+ hostinfo_t info;
+ char empty[1] = {'\0'};
+ info.node = node;
+ info.vhost = vhost;
+ if (ptr == NULL) {
+ ptr = empty;
+ previous = ptr;
+ }
+ while (*ptr) {
+ if (*ptr == ',') {
+ *ptr = '\0';
+ strncpy(info.host, previous, sizeof(info.host));
+ insert_update_host(mem, &info);
+ if (!ret)
+ ret = info.id;
+ previous = ptr + 1;
+ }
+ ptr ++;
+ }
+ strncpy(info.host, previous, sizeof(info.host));
+ insert_update_host(mem, &info);
+ return ret;
+}
/*
+ * Insert the context from Context information
+ */
+static int insert_update_contexts(mem_t *mem, char *str, int node, int vhost)
+{
+ char *ptr = str;
+ char *previous = str;
+ int ret = 0;
+ contextinfo_t info;
+ char empty[2] = {'/','\0'};
+
+ info.node = node;
+ info.vhost = vhost;
+ if (ptr == NULL) {
+ ptr = empty;
+ previous = ptr;
+ }
+ while (*ptr) {
+ if (*ptr == ',') {
+ *ptr = '\0';
+ strncpy(info.context, previous, sizeof(info.context));
+ insert_update_context(mem, &info);
+ if (!ret)
+ ret = info.id;
+ previous = ptr + 1;
+ }
+ ptr ++;
+ }
+ strncpy(info.context, previous, sizeof(info.context));
+ insert_update_context(mem, &info);
+ return ret;
+}
+
+/*
* Process a CONFIG message
* JvmRoute?: <JvmRoute>
* Domain: <Domain>
@@ -187,9 +271,21 @@
char *Port;
char *Type;
/* XXX node conf */
+
+ struct cluster_host *vhost;
+ struct cluster_host *phost;
+
char **ptr = process_buff(r, buff);
if (ptr == NULL)
return 500;
+ vhost = apr_palloc(r->pool, sizeof(struct cluster_host));
+
+ /* Map nothing by default */
+ vhost->host = NULL;
+ vhost->host = NULL;
+ vhost->next = NULL;
+ phost = vhost;
+
int i = 0;
while (ptr[i]) {
if (strcasecmp(ptr[i], "JVMRoute") == 0) {
@@ -217,6 +313,26 @@
return 500;
strcpy(nodeinfo.mess.Type, ptr[i+1]);
}
+ if (strcasecmp(ptr[i], "Alias") == 0) {
+ if (phost->host && !phost->context) {
+ return 500;
+ }
+ if (phost->host) {
+ phost->next = apr_palloc(r->pool, sizeof(struct cluster_host));
+ phost = phost->next;
+ phost->next = NULL;
+ phost->host = ptr[i+1];
+ phost->context = NULL;
+ } else {
+ phost->host = ptr[i+1];
+ }
+ }
+ if (strcasecmp(ptr[i], "Context") == 0) {
+ if (phost->context) {
+ return 500;
+ }
+ phost->context = ptr[i+1];
+ }
ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, "manager_handler %s %s",
ptr[i], ptr[i+1]);
i++;
i++;
@@ -228,8 +344,61 @@
/* Insert or update node description */
if (insert_update_node(nodestatsmem, &nodeinfo) != APR_SUCCESS)
return 500;
+ int id = nodeinfo.mess.id;
+
+ /* Insert the Alias and corresponding Context */
+ phost = vhost;
+ int vid = 1; /* zero and "" is empty */
+ while (phost) {
+ insert_update_hosts(hoststatsmem, phost->host, id, vid);
+ insert_update_contexts(contextstatsmem, phost->context, id, vid);
+ phost = phost->next;
+ vid++;
+ }
return OK;
}
+/*
+ * Process a DUMP command.
+ */
+static int process_dump(request_rec *r, char *buff)
+{
+ 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;
+ get_node(nodestatsmem, &ou, id[i]);
+ ap_rprintf(r, "node: %d %s %s %s %s %s\n", id[i], ou->mess.JVMRoute,
ou->mess.Domain,
+ ou->mess.Host, ou->mess.Port, ou->mess.Type);
+ }
+
+ size = get_max_size_host(hoststatsmem);
+ id = apr_palloc(r->pool, sizeof(int) * size);
+ size = get_ids_used_host(hoststatsmem, id);
+ for (i=0; i<size; i++) {
+ hostinfo_t *ou;
+ get_host(hoststatsmem, &ou, id[i]);
+ ap_rprintf(r, "host: %d %s %d %d\n", id[i], ou->host, ou->vhost,
+ ou->node);
+ }
+
+ size = get_max_size_context(contextstatsmem);
+ id = apr_palloc(r->pool, sizeof(int) * size);
+ size = get_ids_used_context(contextstatsmem, id);
+ for (i=0; i<size; i++) {
+ contextinfo_t *ou;
+ get_context(contextstatsmem, &ou, id[i]);
+ ap_rprintf(r, "context: %d [%s] %d %d status: %d\n", id[i],
ou->context, ou->vhost,
+ ou->node, ou->status);
+ }
+ return OK;
+}
+
/* Process an enable application message */
static int process_enable(request_rec *r, char *buff)
{
@@ -303,6 +472,8 @@
/* Status handling */
else if (strcasecmp(r->method, "STATUS") == 0)
return(process_status(r, buff));
+ else if (strcasecmp(r->method, "DUMP") == 0)
+ return(process_dump(r, buff));
else {
/* The command is not supported */
r->status_line = apr_psprintf(r->pool, "%3.3u VERSION %d.%d.%d",
500, 0, 0, 0);
@@ -327,6 +498,12 @@
mconf->maxnode = atoi(word);
return NULL;
}
+AP_DECLARE_NONSTD(const char *) cmd_manager_maxhost(cmd_parms *cmd, void *mconfig, const
char *word)
+{
+ mod_manager_config *mconf = ap_get_module_config(cmd->server->module_config,
&manager_module);
+ mconf->maxhost = atoi(word);
+ return NULL;
+}
AP_DECLARE_NONSTD(const char *) cmd_manager_memmanagerfile(cmd_parms *cmd, void *mconfig,
const char *word)
{
mod_manager_config *mconf = ap_get_module_config(cmd->server->module_config,
&manager_module);
@@ -346,16 +523,23 @@
cmd_manager_maxcontext,
NULL,
OR_ALL,
- "Maxcontext - number max context support by mod_cluster"
+ "Maxcontext - number max context supported by mod_cluster"
),
AP_INIT_TAKE1(
"Maxnode",
cmd_manager_maxnode,
NULL,
OR_ALL,
- "Maxnode - number max node support by mod_cluster"
+ "Maxnode - number max node supported by mod_cluster"
),
AP_INIT_TAKE1(
+ "Maxhost",
+ cmd_manager_maxhost,
+ NULL,
+ OR_ALL,
+ "Maxhost - number max host (Alias in virtual hosts) supported by
mod_cluster"
+ ),
+ AP_INIT_TAKE1(
"MemManagerFile",
cmd_manager_memmanagerfile,
NULL,
@@ -397,6 +581,7 @@
mconf->basefilename = NULL;
mconf->maxcontext = DEFMAXCONTEXT;
mconf->maxnode = DEFMAXNODE;
+ mconf->maxhost = DEFMAXHOST;
mconf->balancername = NULL;
mconf->baldata = NULL;
return mconf;
@@ -440,6 +625,11 @@
else if (mconf1->maxnode != DEFMAXNODE)
mconf->maxnode = mconf1->maxnode;
+ if (mconf2->maxhost != DEFMAXHOST)
+ mconf->maxhost = mconf2->maxhost;
+ else if (mconf1->maxhost != DEFMAXHOST)
+ mconf->maxhost = mconf1->maxhost;
+
if (mconf2->balancername)
mconf->balancername = mconf2->balancername;
else if (mconf1->balancername)