2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.jk.status;
20 import java.io.UnsupportedEncodingException;
21 import java.net.URLEncoder;
23 import org.apache.tools.ant.BuildException;
26 * Ant task that implements the <code>/status</code> update worker command, supported by the
27 * mod_jk status (1.2.20) application.
30 * @author Peter Rossbach
31 * @version $Revision: 802231 $
32 * @since mod_jk 1.2.20
34 public class JkStatusUpdateWorkerTask extends AbstractJkStatusTask {
37 * The descriptive information about this implementation.
39 private static final String info = "org.apache.jk.status.JkStatusUpdateWorkerTask/1.0";
41 protected String loadbalancer ;
43 protected String worker ;
45 protected int loadfactor =-1;
47 protected String route ;
49 protected int distance = -1;
51 protected String redirect;
53 protected String domain;
55 protected int activationCode = -1;
57 protected String activation ;
60 * Return descriptive information about this implementation and the
61 * corresponding version number, in the format
62 * <code><description>/<version></code>.
64 public String getInfo() {
73 public JkStatusUpdateWorkerTask() {
75 setUrl("http://localhost/jkstatus");
79 * @return the activation
81 public String getActivation() {
86 * @param activation the activation to set
88 public void setActivation(String activation) {
89 this.activation = activation;
93 * @return the activationCode
95 public int getActivationCode() {
96 return activationCode;
100 * @param activationCode the activationCode to set
102 public void setActivationCode(int activationCode) {
103 this.activationCode = activationCode;
107 * @return the distance
109 public int getDistance() {
114 * @param distance the distance to set
116 public void setDistance(int distance) {
117 this.distance = distance;
123 public String getDomain() {
128 * @param domain the domain to set
130 public void setDomain(String domain) {
131 this.domain = domain;
135 * @return the loadbalancer
137 public String getLoadbalancer() {
142 * @param loadbalancer the loadbalaner to set
144 public void setLoadbalancer(String loadbalancer) {
145 this.loadbalancer = loadbalancer;
149 * @return the loadfactor
151 public int getLoadfactor() {
156 * @param loadfactor the loadfactor to set
158 public void setLoadfactor(int loadfactor) {
159 this.loadfactor = loadfactor;
163 * @return the redirect
165 public String getRedirect() {
170 * @param redirect the redirect to set
172 public void setRedirect(String redirect) {
173 this.redirect = redirect;
179 public String getRoute() {
184 * @param route the route to set
186 public void setRoute(String route) {
193 public String getWorker() {
198 * @param worker the worker to set
200 public void setWorker(String worker) {
201 this.worker = worker;
207 * Create JkStatus worker update link
209 * </b>http://localhost/jkstatus?cmd=update&mime=txt&w=loadbalancer&sw=node01&wn=node01&l=lb&wf=1&wa=1&wd=0
213 * <br/>Tcp worker parameter:
216 * <li><b>w:<b/> name loadbalancer</li>
217 * <li><b>sw:<b/> name tcp worker node</li>
218 * <li><b>wf:<b/> load factor</li>
219 * <li><b>wn:<b/> route</li>
220 * <li><b>wd:<b/> distance</li>
221 * <li><b>wa:<b/> activation state</li>
222 * <li><b>wr:<b/> redirect route</li>
223 * <li><b>wc:<b/> cluster domain</li>
226 * <li>wa=1 active</li>
227 * <li>wa=2 disabled</li>
228 * <li>wa=3 stopped</li>
233 * @return create jkstatus update worker link
235 protected StringBuffer createLink() {
237 StringBuffer sb = new StringBuffer();
239 sb.append("?cmd=update&mime=txt");
241 sb.append(URLEncoder.encode(loadbalancer, getCharset()));
243 sb.append(URLEncoder.encode(worker, getCharset()));
244 if (loadfactor >= 0) {
246 sb.append(loadfactor);
250 sb.append(URLEncoder.encode(route, getCharset()));
252 if (activation == null && activationCode > 0 && activationCode < 4) {
254 sb.append(activation);
256 if (activation != null) {
258 sb.append(URLEncoder.encode(activation, getCharset()));
264 if (redirect != null) { // other worker conrecte lb's
266 sb.append(URLEncoder.encode(redirect, getCharset()));
268 if (domain != null) {
270 sb.append(URLEncoder.encode(domain, getCharset()));
273 } catch (UnsupportedEncodingException e) {
274 throw new BuildException("Invalid 'charset' attribute: "
281 * check correct lb and worker pararmeter
283 protected void checkParameter() {
284 if (worker == null) {
285 throw new BuildException("Must specify 'worker' attribute");
287 if (loadbalancer == null) {
288 throw new BuildException("Must specify 'loadbalancer' attribute");