[mod_cluster-commits] mod_cluster SVN: r795 - in trunk: native/mod_manager and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Apr 6 11:29:08 EDT 2012


Author: jfrederic.clere at jboss.com
Date: 2012-04-06 11:29:06 -0400 (Fri, 06 Apr 2012)
New Revision: 795

Added:
   trunk/native/include/jgroupsid.h
Modified:
   trunk/native/include/mod_clustersize.h
   trunk/native/mod_manager/Makefile.in
   trunk/native/mod_manager/mod_manager.c
   trunk/test/java/src/test/java/org/jboss/mod_cluster/TestBaseJgroups.java
Log:
Add logic for MODCLUSTER-282.


Added: trunk/native/include/jgroupsid.h
===================================================================
--- trunk/native/include/jgroupsid.h	                        (rev 0)
+++ trunk/native/include/jgroupsid.h	2012-04-06 15:29:06 UTC (rev 795)
@@ -0,0 +1,164 @@
+/*
+ *  mod_cluster
+ *
+ *  Copyright(c) 2012 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 JGROUPSID_H
+#define JGROUPSID_H
+
+/**
+ * @file  jgroupsid.h
+ * @brief jgroupsid description Storage Module for Apache
+ *
+ * @defgroup MEM jgroupsid
+ * @ingroup  APACHE_MODS
+ * @{
+ */
+
+#define JGROUPSIDEXE ".jgroupsids"
+
+#ifndef MEM_T
+typedef struct mem mem_t; 
+#define MEM_T
+#endif
+
+#include "mod_clustersize.h"
+
+/* jgroupsid information of the node received from jboss cluster. */
+struct jgroupsidinfo {
+    char jgroupsid[JGROUPSIDSZ];        /* jgroupuuid */
+    char data[JGROUPSDATASZ];           /* jgroupdata */
+
+    apr_time_t updatetime;    /* time of last received message */
+    int id;                      /* id in table */
+};
+typedef struct jgroupsidinfo jgroupsidinfo_t; 
+
+/**
+ * Insert(alloc) and update a jgroups record in the shared table
+ * @param pointer to the shared table.
+ * @param jgroupsid jgroupsid to store in the shared table.
+ * @return APR_SUCCESS if all went well
+ *
+ */
+apr_status_t insert_update_jgroupsid(mem_t *s, jgroupsidinfo_t *jgroupsid);
+
+/**
+ * read a jgroupsid record from the shared table
+ * @param pointer to the shared table.
+ * @param jgroupsid jgroupsid to read from the shared table.
+ * @return address of the read jgroupsid or NULL if error.
+ */
+jgroupsidinfo_t * read_jgroupsid(mem_t *s, jgroupsidinfo_t *jgroupsid);
+
+/**
+ * get a jgroups record from the shared table
+ * @param pointer to the shared table.
+ * @param jgroupsid address of the jgroupsid read from the shared table.
+ * @return APR_SUCCESS if all went well
+ */
+apr_status_t get_jgroupsid(mem_t *s, jgroupsidinfo_t **jgroupsid, int ids);
+
+/**
+ * remove(free) a jgroups record from the shared table
+ * @param pointer to the shared table.
+ * @param jgroupsid jgroupsid to remove from the shared table.
+ * @return APR_SUCCESS if all went well
+ */
+apr_status_t remove_jgroupsid(mem_t *s, jgroupsidinfo_t *jgroupsid);
+
+/**
+ * find a jgroups record from the shared table using JVMRoute
+ * @param pointer to the shared table.
+ * @param jgroupsid address where the jgroupsid is located in the shared table.
+ * @param route JVMRoute to search
+ * @return APR_SUCCESS if all went well
+ */
+apr_status_t find_jgroupsid(mem_t *s, jgroupsidinfo_t **jgroupsid, const char *route);
+
+/*
+ * get the ids for the used (not free) jgroups records 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 jgroupsid existing or -1 if error.
+ */
+int get_ids_used_jgroupsid(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.
+ */
+int get_max_size_jgroupsid(mem_t *s);
+
+/**
+ * attach to the shared jgroupsid 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_jgroupsid(char *string, int *num, apr_pool_t *p, slotmem_storage_method *storage);
+/**
+ * create a shared jgroupsid table
+ * @param name to use to create the table.
+ * @param size of the shared table.
+ * @param persist tell if the slotmem element are persistent.
+ * @param p pool to use for allocations.
+ * @return address of struct used to access the table.
+ */
+mem_t * create_mem_jgroupsid(char *string, int *num, int persist, apr_pool_t *p, slotmem_storage_method *storage);
+
+/**
+ * provider for the mod_proxy_cluster or mod_jk modules.
+ */
+struct jgroupsid_storage_method {
+/**
+ * the jgroupsid corresponding to the ident
+ * @param ids ident of the jgroupsid to read.
+ * @param jgroupsid address of pointer to return the jgroupsid.
+ * @return APR_SUCCESS if all went well
+ */
+apr_status_t (* read_jgroupsid)(int ids, jgroupsidinfo_t **jgroupsid);
+/**
+ * read the list of ident of used jgroupsid records.
+ * @param ids address to store the idents.
+ * @return APR_SUCCESS if all went well
+ */
+int (* get_ids_used_jgroupsid)(int *ids);
+/**
+ * read the max number of jgroupsid records in the shared table
+ */
+int (*get_max_size_jgroupsid)();
+/*
+ * Remove the jgroupsid from shared memory (free the slotmem)
+ */
+int (*remove_jgroupsid)(jgroupsidinfo_t *jgroupsid);
+/*
+ * Find the jgroupsid using the JVMRoute information
+ */
+apr_status_t (*find_jgroupsid)(jgroupsidinfo_t **jgroupsid, const char *route);
+};
+#endif /*JGROUPSID_H*/

Modified: trunk/native/include/mod_clustersize.h
===================================================================
--- trunk/native/include/mod_clustersize.h	2012-04-06 07:44:24 UTC (rev 794)
+++ trunk/native/include/mod_clustersize.h	2012-04-06 15:29:06 UTC (rev 795)
@@ -48,4 +48,8 @@
 /* For sessionid.h */
 #define SESSIONIDSZ 128
 
+/* For jgroupsid.h */
+#define JGROUPSIDSZ   80
+#define JGROUPSDATASZ 200
+
 #endif /* MOD_CLUSTERSIZE_H */

Modified: trunk/native/mod_manager/Makefile.in
===================================================================
--- trunk/native/mod_manager/Makefile.in	2012-04-06 07:44:24 UTC (rev 794)
+++ trunk/native/mod_manager/Makefile.in	2012-04-06 15:29:06 UTC (rev 795)
@@ -15,8 +15,8 @@
 mod_manager.so: mod_manager.la
 	 $(top_builddir)/build/instdso.sh SH_LIBTOOL='$(LIBTOOL)' mod_manager.la `pwd`
 
-mod_manager.la: mod_manager.slo node.slo context.slo host.slo balancer.slo sessionid.slo domain.slo
-	$(SH_LINK) -rpath $(libexecdir) -module -avoid-version  mod_manager.lo node.lo context.lo host.lo balancer.lo sessionid.lo domain.lo
+mod_manager.la: mod_manager.slo node.slo context.slo host.slo balancer.slo sessionid.slo domain.slo jgroupsid.slo
+	$(SH_LINK) -rpath $(libexecdir) -module -avoid-version  mod_manager.lo node.lo context.lo host.lo balancer.lo sessionid.lo domain.lo jgroupsid.lo
 
 clean:
 	rm -f *.o *.lo *.slo *.so

Modified: trunk/native/mod_manager/mod_manager.c
===================================================================
--- trunk/native/mod_manager/mod_manager.c	2012-04-06 07:44:24 UTC (rev 794)
+++ trunk/native/mod_manager/mod_manager.c	2012-04-06 15:29:06 UTC (rev 795)
@@ -51,11 +51,13 @@
 #include "balancer.h"
 #include "sessionid.h"
 #include "domain.h"
+#include "jgroupsid.h"
 
 #define DEFMAXCONTEXT   100
 #define DEFMAXNODE      20
 #define DEFMAXHOST      20
 #define DEFMAXSESSIONID 0 /* it has performance/security impact */
+#define DEFMAXJGROUPSID  0
 #define MAXMESSSIZE     1024
 
 /* Error messages */
@@ -78,6 +80,10 @@
 #define SMULCTB "SYNTAX: Only one Context in APP command"
 #define SREADER "SYNTAX: %s can't read POST data"
 
+#define SJIDBIG "SYNTAX: JGroupUuid field too big"
+#define SJDDBIG "SYNTAX: JGroupData field too big"
+#define SJIDBAD "SYNTAX: JGroupUuid can't be empty"
+
 #define TYPEMEM 2
 #define MNODEUI "MEM: Can't update or insert node"
 #define MNODERM "MEM: Old node still exist"
@@ -86,9 +92,10 @@
 #define MHOSTRD "MEM: Can't read host alias"
 #define MHOSTUI "MEM: Can't update or insert host alias"
 #define MCONTUI "MEM: Can't update or insert context"
+#define MJBIDRD "MEM: Can't read JGroupId"
 
 /* Protocol version supported */
-#define VERSION_PROTOCOL "0.2.0"
+#define VERSION_PROTOCOL "0.2.1"
 
 /* Internal substitution for node commands */
 #define NODE_COMMAND "/NODE_COMMAND"
@@ -108,6 +115,7 @@
 static mem_t *balancerstatsmem = NULL;
 static mem_t *sessionidstatsmem = NULL;
 static mem_t *domainstatsmem = NULL;
+static mem_t *jgroupsidstatsmem = NULL;
 
 static slotmem_storage_method *storage = NULL;
 static balancer_method *balancerhandler = NULL;
@@ -123,12 +131,14 @@
     char *basefilename;
     /* max number of context supported */
     int maxcontext;
-    /* max munber of node supported */
+    /* max number of node supported */
     int maxnode;
-    /* max munber of host supported */
+    /* max number of host supported */
     int maxhost;
-    /* max munber of session supported */
+    /* max number of session supported */
     int maxsessionid;
+    /* max number of jgroupsid supported */
+    int maxjgroupsid;
 
     /* last time the node update logic was called */
     apr_time_t last_updated;
@@ -173,6 +183,13 @@
     else
         return 0;
 }
+static int loc_get_max_size_jgroupsid()
+{
+    if (jgroupsidstatsmem)
+        return(get_max_size_jgroupsid(jgroupsidstatsmem));
+    else
+        return 0;
+}
 static apr_status_t loc_remove_node(nodeinfo_t *node)
 {
     return (remove_node(nodestatsmem, node));
@@ -438,6 +455,7 @@
     char *balancer;
     char *sessionid;
     char *domain;
+    char *jgroupsid;
     void *data;
     const char *userdata_key = "mod_manager_init";
     apr_uuid_t uuid;
@@ -456,6 +474,7 @@
         balancer = apr_pstrcat(ptemp, mconf->basefilename, "/manager.balancer", NULL);
         sessionid = apr_pstrcat(ptemp, mconf->basefilename, "/manager.sessionid", NULL);
         domain = apr_pstrcat(ptemp, mconf->basefilename, "/manager.domain", NULL);
+        jgroupsid = apr_pstrcat(ptemp, mconf->basefilename, "/manager.jgroupsid", NULL);
     } else {
         node = ap_server_root_relative(ptemp, "logs/manager.node");
         context = ap_server_root_relative(ptemp, "logs/manager.context");
@@ -463,6 +482,7 @@
         balancer = ap_server_root_relative(ptemp, "logs/manager.balancer");
         sessionid = ap_server_root_relative(ptemp, "logs/manager.sessionid");
         domain = ap_server_root_relative(ptemp, "logs/manager.domain");
+        jgroupsid = ap_server_root_relative(ptemp, "logs/manager.jgroupsid");
     }
 
     /* Do some sanity checks */
@@ -519,6 +539,12 @@
         return  !OK;
     }
 
+    jgroupsidstatsmem = create_mem_jgroupsid(jgroupsid, &mconf->maxjgroupsid, mconf->persistent, p, storage);
+    if (jgroupsidstatsmem == NULL) {
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, s, "create_mem_jgroupsid failed");
+        return  !OK;
+    }
+
     /* Get a provider to ping/pong logics */
 
     balancerhandler = ap_lookup_provider("proxy_cluster", "balancer", "0");
@@ -1366,6 +1392,124 @@
 }
 
 /*
+ * JGroups feature routines
+ */
+static char * process_addid(request_rec *r, char **ptr, int *errtype)
+{
+    jgroupsidinfo_t jgroupsid;
+    int i = 0;
+    jgroupsid.jgroupsid[0] = '\0';
+    while (ptr[i]) {
+        if (strcasecmp(ptr[i], "JGroupUuid") == 0) {
+            if (strlen(ptr[i+1])>=sizeof(jgroupsid.jgroupsid)) {
+                 *errtype = TYPESYNTAX;
+                 return SJIDBIG;
+            }
+            strcpy(jgroupsid.jgroupsid, ptr[i+1]);
+        }
+        if (strcasecmp(ptr[i], "JGroupData") == 0) {
+            if (strlen(ptr[i+1])>=sizeof(jgroupsid.data)) {
+                 *errtype = TYPESYNTAX;
+                 return SJDDBIG;
+            }
+            strcpy(jgroupsid.data, ptr[i+1]);
+        }
+        i++;
+        i++;
+    }
+    if (jgroupsid.jgroupsid[0] == '\0') {
+        *errtype = TYPESYNTAX;
+        return SJIDBAD;
+    }
+    if (insert_update_jgroupsid(jgroupsidstatsmem, &jgroupsid) != APR_SUCCESS) {
+        *errtype = TYPEMEM;
+        return MBALAUI;
+    }
+
+    return NULL;
+}
+static char * process_removeid(request_rec *r, char **ptr, int *errtype)
+{
+    jgroupsidinfo_t jgroupsid;
+    int i = 0;
+    jgroupsid.jgroupsid[0] = '\0';
+    while (ptr[i]) {
+        if (strcasecmp(ptr[i], "JGroupUuid") == 0) {
+            if (strlen(ptr[i+1])>=sizeof(jgroupsid.jgroupsid)) {
+                 *errtype = TYPESYNTAX;
+                 return SJIDBIG;
+            }
+            strcpy(jgroupsid.jgroupsid, ptr[i+1]);
+        }
+        i++;
+        i++;
+    }
+    if (jgroupsid.jgroupsid[0] == '\0') {
+        *errtype = TYPESYNTAX;
+        return SJIDBAD;
+    }
+    remove_jgroupsid(jgroupsidstatsmem, &jgroupsid);
+    return NULL;
+}
+/*
+ * Query out should be something like:
+ * JGroup: [9],JGroupUuid: node4, JGroupData: jgroupdata4
+ * JGroup: [11],JGroupUuid: node6, JGroupData: jgroupdata6
+ */
+static void print_jgroupsid(request_rec *r, int id, jgroupsidinfo_t *jgroupsid)
+{
+    ap_rprintf(r, "JGroup: [%d],JGroupUuid: %.*s,JGroupData: %.*s\n",
+               id,
+               (int) sizeof(jgroupsid->jgroupsid), jgroupsid->jgroupsid,
+               (int) sizeof(jgroupsid->data), jgroupsid->data);
+}
+static char * process_query(request_rec *r, char **ptr, int *errtype)
+{
+    jgroupsidinfo_t jgroupsid;
+    int i = 0;
+    jgroupsid.jgroupsid[0] = '\0';
+    while (ptr[i]) {
+        if (strcasecmp(ptr[i], "JGroupUuid") == 0) {
+            if (strlen(ptr[i+1])>=sizeof(jgroupsid.jgroupsid)) {
+                 *errtype = TYPESYNTAX;
+                 return SJIDBIG;
+            }
+            strcpy(jgroupsid.jgroupsid, ptr[i+1]);
+        }
+        i++;
+        i++;
+    }
+    if (jgroupsid.jgroupsid[0] == '\0') {
+        jgroupsid.jgroupsid[0] = '*';
+        jgroupsid.jgroupsid[1] = '\0';
+    }
+    if (strcmp(jgroupsid.jgroupsid, "*") == 0) {
+        int size, i;
+        int *id;
+        size = loc_get_max_size_jgroupsid();
+        if (size == 0)
+            return NULL;
+        id = apr_palloc(r->pool, sizeof(int) * size);
+        size = get_ids_used_jgroupsid(jgroupsidstatsmem, id);
+        for (i=0; i<size; i++) {
+             jgroupsidinfo_t *ou;
+             if (get_jgroupsid(jgroupsidstatsmem, &ou, id[i]) != APR_SUCCESS)
+                 continue;
+             print_jgroupsid(r, id[i], ou);
+        }
+    } else {
+        jgroupsidinfo_t *ou;
+        ou = read_jgroupsid(jgroupsidstatsmem, &jgroupsid);
+        if (ou == NULL) {
+           *errtype = TYPEMEM;
+           return MJBIDRD;
+        } else
+            print_jgroupsid(r, ou->id, ou);
+    }
+    return NULL;
+}
+
+/*
  * Call the ping/pong logic
  * Do a ping/png request to the node and set the load factor.
  */
@@ -1661,6 +1805,12 @@
         ours = 1;
     else if (strcasecmp(r->method, "PING") == 0)
         ours = 1;
+    else if (strcasecmp(r->method, "ADDID") == 0)
+        ours = 1;
+    else if (strcasecmp(r->method, "REMOVEID") == 0)
+        ours = 1;
+    else if (strcasecmp(r->method, "QUERY") == 0)
+        ours = 1;
     if (ours) {
         int i;
         /* The method one of ours */
@@ -2352,6 +2502,12 @@
         errstring = process_info(r, &errtype);
     else if (strcasecmp(r->method, "PING") == 0)
         errstring = process_ping(r, ptr, &errtype);
+    else if (strcasecmp(r->method, "ADDID") == 0)
+        errstring = process_addid(r, ptr, &errtype);
+    else if (strcasecmp(r->method, "REMOVEID") == 0)
+        errstring = process_removeid(r, ptr, &errtype);
+    else if (strcasecmp(r->method, "QUERY") == 0)
+        errstring = process_query(r, ptr, &errtype);
     else {
         errstring = SCMDUNS;
         errtype = TYPESYNTAX;
@@ -2483,6 +2639,16 @@
     mconf->maxsessionid = atoi(word);
     return NULL;
 }
+static const char *cmd_manager_maxjgroupsid(cmd_parms *cmd, void *mconfig, const char *word)
+{
+    mod_manager_config *mconf = ap_get_module_config(cmd->server->module_config, &manager_module);
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
+    if (err != NULL) {
+        return err;
+    }
+    mconf->maxjgroupsid = atoi(word);
+    return NULL;
+}
 static 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);
@@ -2624,6 +2790,13 @@
         "Maxsessionid - number session (Used to track number of sessions per nodes) supported by mod_cluster"
     ),
     AP_INIT_TAKE1(
+        "Maxjgroupsid",
+        cmd_manager_maxjgroupsid,
+        NULL,
+        OR_ALL,
+        "Maxjgroupsid - number jgroupsid supported by mod_cluster"
+    ),
+    AP_INIT_TAKE1(
         "MemManagerFile",
         cmd_manager_memmanagerfile,
         NULL,
@@ -2729,6 +2902,7 @@
     mconf->maxnode = DEFMAXNODE;
     mconf->maxhost = DEFMAXHOST;
     mconf->maxsessionid = DEFMAXSESSIONID;
+    mconf->maxjgroupsid = DEFMAXJGROUPSID;
     mconf->last_updated = 0;
     mconf->persistent = 0;
     mconf->nonce = -1;
@@ -2787,6 +2961,11 @@
     else if (mconf1->maxsessionid != DEFMAXSESSIONID)
         mconf->maxsessionid = mconf1->maxsessionid;
 
+    if (mconf2->maxjgroupsid != DEFMAXJGROUPSID)
+        mconf->maxjgroupsid = mconf2->maxjgroupsid;
+    else if (mconf1->maxjgroupsid != DEFMAXJGROUPSID)
+        mconf->maxjgroupsid = mconf1->maxjgroupsid;
+
     if (mconf2->persistent != 0)
         mconf->persistent = mconf2->persistent;
     else if (mconf1->persistent != 0)

Modified: trunk/test/java/src/test/java/org/jboss/mod_cluster/TestBaseJgroups.java
===================================================================
--- trunk/test/java/src/test/java/org/jboss/mod_cluster/TestBaseJgroups.java	2012-04-06 07:44:24 UTC (rev 794)
+++ trunk/test/java/src/test/java/org/jboss/mod_cluster/TestBaseJgroups.java	2012-04-06 15:29:06 UTC (rev 795)
@@ -38,6 +38,10 @@
 import org.apache.catalina.connector.Connector;
 import org.apache.catalina.core.StandardServer;
 
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+
 public class TestBaseJgroups extends TestCase {
 
     /* Test that the sessions are really sticky */
@@ -62,7 +66,7 @@
         // start the server thread.
         ServerThread wait = new ServerThread(3000, server);
         wait.start();
-         
+
         // Wait until httpd we know about httpd.
         String [] nodes = new String[1];
         nodes[0] = "node1";
@@ -76,6 +80,58 @@
             countinfo++;
         }
 
+        // Create 2 JGroups ID and query the result and remove them.
+        String proxy = Maintest.getProxyAddress(cluster);
+        String URL = "http://" + proxy + "/";
+        HttpClient httpClient = new HttpClient();
+        PostMethod pm = null;
+        pm = (PostMethod) new AddIdMethod(URL);
+        pm.addParameter("JGroupUuid", "ID1");
+        pm.addParameter("JGroupData", "DATA1");
+        String response = processrequest(pm, httpClient);
+        if (response == null)
+            fail("ADDID(1) failed");
+
+        pm = (PostMethod) new AddIdMethod(URL);
+        pm.addParameter("JGroupUuid", "ID2");
+        pm.addParameter("JGroupData", "DATA2");
+        response = processrequest(pm, httpClient);
+        if (response == null)
+            fail("ADDID(2) failed");
+
+        pm = (PostMethod) new QueryMethod(URL);
+        pm.addParameter("JGroupUuid", "*");
+        response = processrequest(pm, httpClient);
+        if (response == null)
+            fail("QUERY failed");
+        System.out.println("Response:\n" + response);
+        String [] records = response.split("\n");
+        if (records.length != 2)
+            fail("QUERY return " + records.length + " JGroupUuid instead 2");
+
+        pm = (PostMethod) new RemoveIdMethod(URL);
+        pm.addParameter("JGroupUuid", "ID2");
+        response = processrequest(pm, httpClient);
+        if (response == null)
+            fail("REMOVE(ID2) failed");
+
+        pm = (PostMethod) new RemoveIdMethod(URL);
+        pm.addParameter("JGroupUuid", "ID1");
+        response = processrequest(pm, httpClient);
+        if (response == null)
+            fail("REMOVE(ID1) failed");
+
+        pm = (PostMethod) new QueryMethod(URL);
+        pm.addParameter("JGroupUuid", "*");
+        response = processrequest(pm, httpClient);
+        if (response == null)
+            fail("QUERY failed");
+        System.out.println("Response:\n" + response);
+        if (response.length() == 0)
+            System.out.println("AddId + Remove OK");
+        else
+            fail("QUERY returns " + response + " instead nothing");
+
         // Stop the jboss and remove the services.
         try {
             wait.stopit();
@@ -103,4 +159,58 @@
         System.gc();
         System.out.println("TestBaseJgroups Done");
     }
+
+    public static String processrequest(PostMethod pm, HttpClient httpClient)
+    {
+        Integer connectionTimeout = 40000;
+        pm.getParams().setParameter("http.socket.timeout", connectionTimeout);
+        pm.getParams().setParameter("http.connection.timeout", connectionTimeout);
+        httpClient.getParams().setParameter("http.socket.timeout", connectionTimeout);
+        httpClient.getParams().setParameter("http.connection.timeout", connectionTimeout);
+
+        int httpResponseCode = 0;
+        try {
+            httpResponseCode = httpClient.executeMethod(pm);
+            System.out.println("response: " + httpResponseCode);
+            System.out.println("response: " + pm.getStatusLine());
+            if (httpResponseCode == 500) {
+                System.out.println(pm.getResponseHeader("Version"));
+                System.out.println(pm.getResponseHeader("Type"));
+                System.out.println(pm.getResponseHeader("Mess"));
+                return null;
+            }
+            if (httpResponseCode == 200) {
+                int len = (int) pm.getResponseContentLength();
+                return pm.getResponseBodyAsString(len);
+            }
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public class AddIdMethod extends PostMethod {
+        public String getName() {
+            return "ADDID";
+        }
+        public AddIdMethod(String uri) {
+            super(uri);
+        }
+    }
+    public class RemoveIdMethod extends PostMethod {
+        public String getName() {
+            return "REMOVEID";
+        }
+        public RemoveIdMethod(String uri) {
+            super(uri);
+        }
+    }
+    public class QueryMethod extends PostMethod {
+        public String getName() {
+            return "QUERY";
+        }
+        public QueryMethod(String uri) {
+            super(uri);
+        }
+    }
 }



More information about the mod_cluster-commits mailing list