]> granicus.if.org Git - apache/blobdiff - modules/proxy/mod_proxy_balancer.c
Again, abstract out the worker status magic to it's handled
[apache] / modules / proxy / mod_proxy_balancer.c
index 36825cb6385400584314b59e6e835495841b1a25..8ea81c93789bc0219c8ed609eb80afd39fe0b5b5 100644 (file)
@@ -331,7 +331,7 @@ static proxy_worker *find_best_worker(proxy_balancer *balancer,
         return NULL;
     }
 
-    candidate = (*balancer->lbmethod->finder)(balancer, r);
+    candidate = (*balancer->s->lbmethod->finder)(balancer, r);
 
     if (candidate)
         candidate->s->elected++;
@@ -480,9 +480,9 @@ static int proxy_balancer_pre_request(proxy_worker **worker,
     /* Step 4: find the session route */
     runtime = find_session_route(*balancer, r, &route, &sticky, url);
     if (runtime) {
-        if ((*balancer)->lbmethod && (*balancer)->lbmethod->updatelbstatus) {
+        if ((*balancer)->s->lbmethod && (*balancer)->s->lbmethod->updatelbstatus) {
             /* Call the LB implementation */
-            (*balancer)->lbmethod->updatelbstatus(*balancer, runtime, r->server);
+            (*balancer)->s->lbmethod->updatelbstatus(*balancer, runtime, r->server);
         }
         else { /* Use the default one */
             int i, total_factor = 0;
@@ -755,7 +755,10 @@ static int balancer_post_config(apr_pool_t *pconf, apr_pool_t *plog,
             unsigned int index;
 
             balancer->max_workers = balancer->workers->nelts + balancer->growth;
-            ap_pstr2_alnum(pconf, balancer->name, &balancer->sname);
+            /* no need for the 'balancer://' prefix */
+            ap_pstr2_alnum(pconf, balancer->name + sizeof(BALANCER_PREFIX) - 1, 
+                           &balancer->sname);
+            balancer->sname = apr_pstrcat(pconf, conf->id, "_", balancer->sname, NULL);
 
             /* Create global mutex */
             rv = ap_global_mutex_create(&(balancer->mutex), NULL, balancer_mutex_type,
@@ -839,6 +842,7 @@ static int balancer_handler(request_rec *r)
     apr_table_t *params;
     int access_status;
     int i, n;
+    int ok2change = 1;
     const char *name;
 
     /* is this for us? */
@@ -897,14 +901,11 @@ static int balancer_handler(request_rec *r)
         )
        ) {
         apr_table_clear(params);
+        ok2change = 0;
     }
 
     /* First set the params */
-    /*
-     * Note that it is not possible set the proxy_balancer because it is not
-     * in shared memory.
-     */
-    if (wsel) {
+    if (wsel && ok2change) {
         const char *val;
         if ((val = apr_table_get(params, "lf"))) {
             int ival = atoi(val);
@@ -940,6 +941,17 @@ static int balancer_handler(request_rec *r)
         }
 
     }
+
+    if (bsel && ok2change) {
+        const char *val;
+        if ((val = apr_table_get(params, "lbm"))) {
+            proxy_balancer_method *lbmethod;
+            lbmethod = ap_lookup_provider(PROXY_LBMETHOD, val, "0");
+            if (lbmethod)
+                bsel->s->lbmethod = lbmethod;
+        }
+    }
+
     if (apr_table_get(params, "xml")) {
         ap_set_content_type(r, "text/xml");
         ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n", r);
@@ -984,7 +996,11 @@ static int balancer_handler(request_rec *r)
         for (i = 0; i < conf->balancers->nelts; i++) {
 
             ap_rputs("<hr />\n<h3>LoadBalancer Status for ", r);
-            ap_rvputs(r, balancer->name, "</h3>\n\n", NULL);
+            ap_rvputs(r, "<a href=\"", r->uri, "?b=",
+                      balancer->name + sizeof(BALANCER_PREFIX) - 1,
+                      "&nonce=", balancer->s->nonce,
+                      "\">", NULL);
+            ap_rvputs(r, balancer->name, "</a></h3>\n\n", NULL);
             ap_rputs("\n\n<table border=\"0\" style=\"text-align: left;\"><tr>"
                 "<th>MaxMembers</th><th>StickySession</th><th>Timeout</th><th>FailoverAttempts</th><th>Method</th>"
                 "</tr>\n<tr>", r);
@@ -1005,7 +1021,7 @@ static int balancer_handler(request_rec *r)
                 apr_time_sec(balancer->s->timeout));
             ap_rprintf(r, "<td align=\"center\">%d</td>\n", balancer->s->max_attempts);
             ap_rprintf(r, "<td align=\"center\">%s</td>\n",
-                       balancer->lbmethod->name);
+                       balancer->s->lbmethod->name);
             ap_rputs("</table>\n<br />", r);
             ap_rputs("\n\n<table border=\"0\" style=\"text-align: left;\"><tr>"
                 "<th>Worker URL</th>"
@@ -1030,18 +1046,7 @@ static int balancer_handler(request_rec *r)
                           ap_escape_html(r->pool, worker->s->redirect), NULL);
                 ap_rprintf(r, "</td><td align=\"center\">%d</td>", worker->s->lbfactor);
                 ap_rprintf(r, "<td align=\"center\">%d</td><td align=\"center\">", worker->s->lbset);
-                if (worker->s->status & PROXY_WORKER_DISABLED)
-                   ap_rputs("Dis ", r);
-                if (worker->s->status & PROXY_WORKER_IN_ERROR)
-                   ap_rputs("Err ", r);
-                if (worker->s->status & PROXY_WORKER_STOPPED)
-                   ap_rputs("Stop ", r);
-                if (worker->s->status & PROXY_WORKER_HOT_STANDBY)
-                   ap_rputs("Stby ", r);
-                if (PROXY_WORKER_IS_USABLE(worker))
-                    ap_rputs("Ok", r);
-                if (!PROXY_WORKER_IS_INITIALIZED(worker))
-                    ap_rputs("-", r);
+                ap_rvputs(r, ap_proxy_parse_wstatus(r->pool, worker), NULL);
                 ap_rputs("</td>", r);
                 ap_rprintf(r, "<td align=\"center\">%" APR_SIZE_T_FMT "</td><td align=\"center\">", worker->s->elected);
                 ap_rputs(apr_strfsize(worker->s->transferred, fbuf), r);
@@ -1089,10 +1094,40 @@ static int balancer_handler(request_rec *r)
                       bsel->s->nonce, "\">\n", NULL);
             ap_rvputs(r, "</form>\n", NULL);
             ap_rputs("<hr />\n", r);
+        } else if (bsel) {
+            const apr_array_header_t *provs;
+            const ap_list_provider_names_t *pname;
+            int i;
+            ap_rputs("<h3>Edit balancer settings for ", r);
+            ap_rvputs(r, bsel->name, "</h3>\n", NULL);
+            ap_rvputs(r, "<form method=\"GET\" action=\"", NULL);
+            ap_rvputs(r, r->uri, "\">\n<dl>\n<table>\n", NULL);
+            provs = ap_list_provider_names(r->pool, PROXY_LBMETHOD, "0");
+            if (provs) {
+                ap_rputs("<tr><td>LBmethod:</td>", r);
+                ap_rputs("<td>\n<select name=\"lbm\" id=\"lbm\">", r);
+                pname = (ap_list_provider_names_t *)provs->elts;
+                for (i = 0; i < provs->nelts; i++, pname++) {
+                    ap_rvputs(r,"<option value=\"", pname->provider_name, "\"", NULL);
+                    if (strcmp(pname->provider_name, bsel->s->lbmethod->name) == 0)
+                        ap_rputs(" selected ", r);
+                    ap_rvputs(r, ">", pname->provider_name, "\n", NULL);
+                }
+                ap_rputs("</select>\n</td></tr>\n", r);
+            }
+            ap_rputs("</td></tr>\n", r);
+            ap_rputs("<tr><td colspan=2><input type=submit value=\"Submit\"></td></tr>\n", r);
+            ap_rvputs(r, "</table>\n<input type=hidden name=\"b\" ", NULL);
+            ap_rvputs(r, "value=\"", bsel->name + sizeof(BALANCER_PREFIX) - 1,
+                      "\">\n", NULL);
+            ap_rvputs(r, "<input type=hidden name=\"nonce\" value=\"",
+                      bsel->s->nonce, "\">\n", NULL);
+            ap_rvputs(r, "</form>\n", NULL);
+            ap_rputs("<hr />\n", r);
         }
         ap_rputs(ap_psignature("",r), r);
         ap_rputs("</body></html>\n", r);
-    }
+}
     return OK;
 }
 
@@ -1146,8 +1181,8 @@ static void balancer_child_init(apr_pool_t *p, server_rec *s)
                 ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, 0, s, "slotmem_attach failed");
                 exit(1); /* Ugly, but what else? */
             }
-            if (balancer->lbmethod && balancer->lbmethod->reset)
-               balancer->lbmethod->reset(balancer, s);
+            if (balancer->s->lbmethod && balancer->s->lbmethod->reset)
+               balancer->s->lbmethod->reset(balancer, s);
             init_balancer_members(conf, s, balancer);
             balancer++;
         }