bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / jkstatus / src / share / org / apache / jk / status / JkStatusUpdateWorkerTask.java
1 /*
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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.
16  */
17
18 package org.apache.jk.status;
19
20 import java.io.UnsupportedEncodingException;
21 import java.net.URLEncoder;
22
23 import org.apache.tools.ant.BuildException;
24
25 /**
26  * Ant task that implements the <code>/status</code> update worker command, supported by the
27  * mod_jk status (1.2.20) application.
28  * 
29  * 
30  * @author Peter Rossbach
31  * @version $Revision: 802231 $
32  * @since mod_jk 1.2.20
33  */
34 public class JkStatusUpdateWorkerTask extends AbstractJkStatusTask {
35
36     /**
37      * The descriptive information about this implementation.
38      */
39     private static final String info = "org.apache.jk.status.JkStatusUpdateWorkerTask/1.0";
40
41     protected String loadbalancer ;
42     
43     protected String worker ;
44
45     protected int loadfactor =-1;
46
47     protected String route ;
48     
49     protected int distance = -1;
50     
51     protected String redirect;
52
53     protected String domain;
54     
55     protected int activationCode = -1;
56
57     protected String activation ;
58
59     /**
60      * Return descriptive information about this implementation and the
61      * corresponding version number, in the format
62      * <code>&lt;description&gt;/&lt;version&gt;</code>.
63      */
64     public String getInfo() {
65
66         return (info);
67
68     }
69     
70     /**
71      *  
72      */
73     public JkStatusUpdateWorkerTask() {
74         super();
75         setUrl("http://localhost/jkstatus");
76     }
77
78         /**
79          * @return the activation
80          */
81         public String getActivation() {
82                 return activation;
83         }
84
85         /**
86          * @param activation the activation to set
87          */
88         public void setActivation(String activation) {
89                 this.activation = activation;
90         }
91
92         /**
93          * @return the activationCode
94          */
95         public int getActivationCode() {
96                 return activationCode;
97         }
98
99         /**
100          * @param activationCode the activationCode to set
101          */
102         public void setActivationCode(int activationCode) {
103                 this.activationCode = activationCode;
104         }
105
106         /**
107          * @return the distance
108          */
109         public int getDistance() {
110                 return distance;
111         }
112
113         /**
114          * @param distance the distance to set
115          */
116         public void setDistance(int distance) {
117                 this.distance = distance;
118         }
119
120         /**
121          * @return the domain
122          */
123         public String getDomain() {
124                 return domain;
125         }
126
127         /**
128          * @param domain the domain to set
129          */
130         public void setDomain(String domain) {
131                 this.domain = domain;
132         }
133
134         /**
135          * @return the loadbalancer
136          */
137         public String getLoadbalancer() {
138                 return loadbalancer;
139         }
140
141         /**
142          * @param loadbalancer the loadbalaner to set
143          */
144         public void setLoadbalancer(String loadbalancer) {
145                 this.loadbalancer = loadbalancer;
146         }
147
148         /**
149          * @return the loadfactor
150          */
151         public int getLoadfactor() {
152                 return loadfactor;
153         }
154
155         /**
156          * @param loadfactor the loadfactor to set
157          */
158         public void setLoadfactor(int loadfactor) {
159                 this.loadfactor = loadfactor;
160         }
161
162         /**
163          * @return the redirect
164          */
165         public String getRedirect() {
166                 return redirect;
167         }
168
169         /**
170          * @param redirect the redirect to set
171          */
172         public void setRedirect(String redirect) {
173                 this.redirect = redirect;
174         }
175
176         /**
177          * @return the route
178          */
179         public String getRoute() {
180                 return route;
181         }
182
183         /**
184          * @param route the route to set
185          */
186         public void setRoute(String route) {
187                 this.route = route;
188         }
189
190         /**
191          * @return the worker
192          */
193         public String getWorker() {
194                 return worker;
195         }
196
197         /**
198          * @param worker the worker to set
199          */
200         public void setWorker(String worker) {
201                 this.worker = worker;
202         }
203
204
205
206     /**
207      * Create JkStatus worker update link
208      * <ul>
209      * </b>http://localhost/jkstatus?cmd=update&mime=txt&w=loadbalancer&sw=node01&wn=node01&l=lb&wf=1&wa=1&wd=0
210      * <br/>
211      *
212      * 
213      * <br/>Tcp worker parameter:
214      * <br/>
215      * <ul>
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>
224      * </ul>
225      * <ul>
226      * <li>wa=1 active</li>
227      * <li>wa=2 disabled</li>
228      * <li>wa=3 stopped</li>
229      * </ul>
230      * </li>
231      * </ul>
232      * 
233      * @return create jkstatus update worker link
234      */
235     protected StringBuffer createLink() {
236         // Building URL
237         StringBuffer sb = new StringBuffer();
238         try {
239             sb.append("?cmd=update&mime=txt");
240             sb.append("&w=");
241             sb.append(URLEncoder.encode(loadbalancer, getCharset()));
242             sb.append("&sw=");
243             sb.append(URLEncoder.encode(worker, getCharset()));
244             if (loadfactor >= 0) {
245                                 sb.append("&wf=");
246                                 sb.append(loadfactor);
247                         }
248                         if (route != null) {
249                                 sb.append("&wn=");
250                                 sb.append(URLEncoder.encode(route, getCharset()));
251                         }
252                         if (activation == null && activationCode > 0 && activationCode < 4) {
253                                 sb.append("&wa=");
254                                 sb.append(activation);
255                         }
256                         if (activation != null) {
257                                 sb.append("&wa=");
258                                 sb.append(URLEncoder.encode(activation, getCharset()));
259                         }
260                         if (distance >= 0) {
261                                 sb.append("&wd=");
262                                 sb.append(distance);
263                         }
264                         if (redirect != null) { // other worker conrecte lb's
265                                 sb.append("&wr=");
266                                 sb.append(URLEncoder.encode(redirect, getCharset()));
267                         }
268                         if (domain != null) {
269                                 sb.append("&wc=");
270                                 sb.append(URLEncoder.encode(domain, getCharset()));
271                         }
272             
273         } catch (UnsupportedEncodingException e) {
274             throw new BuildException("Invalid 'charset' attribute: "
275                     + getCharset());
276         }
277         return sb;
278     }
279
280     /**
281          * check correct lb and worker pararmeter
282          */
283     protected void checkParameter() {
284         if (worker == null) {
285             throw new BuildException("Must specify 'worker' attribute");
286         }
287         if (loadbalancer == null) {
288             throw new BuildException("Must specify 'loadbalancer' attribute");
289         }
290     }
291 }