1 package org.ultramonkey.l7.controller;
3 import java.io.Serializable;
4 import java.util.Vector;
5 import java.util.regex.*;
10 * class VirtualSetting
13 * Copyright(c) NTT COMWARE 2008
18 public class VirtualSetting implements Serializable {
19 static final long serialVersionUID = 1;
24 public EndPoint virtual;
29 public Vector<EndPoint> real;
32 * protocol module name
34 public String protomod = "";
37 * protocol module option strings
39 public String option = "";
42 * protocol module reschedule flag
44 public boolean reschedule;
49 public String sched = "";
52 * max connection setting
57 * QoS limit per virtual service
59 public long qosservice;
62 * QoS limit per client
64 public long qosclient;
69 public long throughput;
74 public EndPoint sorryserver;
79 public boolean sorryflag;
82 * timeout of real server monitor
87 * check count of real server monitor
89 public int checkcount;
92 * connection type of real server monitor
94 public String checktype = "";
97 * service type of real server monitor
99 public String service = "";
104 public String quiescent = "";
107 * check port of real server monitor
109 public int checkport;
112 * request string of real server monitor
114 public String request = "";
117 * response string of real server monitor
119 public String receive = "";
122 * HTTP method of real server monitor
124 public String httpmethod = "";
127 * HTTP virtual host of real server monitor
129 public String virtualhost = "";
132 * login user name for real server monitor
134 public String login = "";
137 * password for real server monitor
139 public String passwd = "";
142 * database name for real server monitor
144 public String database = "";
149 public String protocol = "";
152 * real server down callback script file path
154 public String downcallback = "";
157 * real server up callback script file path
159 public String upcallback = "";
162 * virtual position in l7directord.cf
171 public VirtualSetting() {
172 this.virtual = new EndPoint();
173 this.real = new Vector<EndPoint>();
174 this.sorryserver = new EndPoint();
183 public VirtualSetting(VirtualSetting v) {
184 this.virtual = new EndPoint(v.virtual);
185 this.real = (Vector<EndPoint>) v.real.clone();
186 this.protomod = new String(v.protomod);
187 this.option = new String(v.option);
188 this.sched = new String(v.sched);
189 this.maxconn = v.maxconn;
190 this.qosservice = v.qosservice;
191 this.qosclient = v.qosclient;
192 this.sorryserver = new EndPoint(v.sorryserver);
193 this.sorryflag = v.sorryflag;
194 this.timeout = v.timeout;
195 this.checkcount = v.checkcount;
196 this.checktype = new String(v.checktype);
197 this.service = new String(v.service);
198 this.quiescent = new String(v.quiescent);
199 this.checkport = v.checkport;
200 this.request = new String(v.request);
201 this.receive = new String(v.receive);
202 this.httpmethod = new String(v.httpmethod);
203 this.virtualhost = new String(v.virtualhost);
204 this.login = new String(v.login);
205 this.passwd = new String(v.passwd);
206 this.database = new String(v.database);
207 this.protocol = new String(v.protocol);
208 this.downcallback = new String(v.downcallback);
209 this.upcallback = new String(v.upcallback);
215 * complementOption method
221 public void complementOption() {
222 String fullOption = "";
223 if (this.protomod == null || this.option == null)
225 if (this.protomod.equals("cinsert")) {
226 Pattern p = Pattern.compile("(?:--cookie-name|-C)\\s+([^\\s]+)");
227 Matcher m = p.matcher(this.option);
229 fullOption = "--cookie-name " + m.group(1);
231 fullOption = "--cookie-name CookieName";
233 p = Pattern.compile("(?:--cookie-expire|-E)\\s+(\\d+)");
234 m = p.matcher(this.option);
236 fullOption += " --cookie-expire " + m.group(1);
238 fullOption += " --cookie-expire 86400";
240 p = Pattern.compile("(?:--forwarded-for|-F)");
241 m = p.matcher(this.option);
243 fullOption += " --forwarded-for";
244 p = Pattern.compile("(?:--reschedule|-R)");
245 m = p.matcher(this.option);
247 fullOption += " --reschedule";
248 p = Pattern.compile("(?:--no-reschedule|-N)");
249 m = p.matcher(this.option);
251 fullOption += " --no-reschedule";
253 else if (this.protomod.equals("url")) {
254 Pattern p = Pattern.compile("(?:--pattern-match|-P)\\s+([^\\s]+)");
255 Matcher m = p.matcher(this.option);
257 fullOption = "--pattern-match " + m.group(1);
258 p = Pattern.compile("(?:--forwarded-for|-F)");
259 m = p.matcher(this.option);
261 fullOption += " --forwarded-for";
263 else if (this.protomod.equals("sessionless")) {
264 Pattern p = Pattern.compile("(?:--forwarded-for|-F)");
265 Matcher m = p.matcher(this.option);
267 fullOption += "--forwarded-for";
269 else if (this.protomod.equals("sslid")) {
270 Pattern p = Pattern.compile("(?:--timeout|-T)\\s+(\\d+)");
271 Matcher m = p.matcher(this.option);
273 fullOption += "--timeout " + m.group(1);
275 fullOption += "--timeout 3600";
277 p = Pattern.compile("(?:--maxlist|-M)\\s+(\\d+)");
278 m = p.matcher(this.option);
280 fullOption += " --maxlist " + m.group(1);
282 fullOption += " --maxlist 1024";
284 p = Pattern.compile("(?:--reschedule|-R)");
285 m = p.matcher(this.option);
287 fullOption += " --reschedule";
288 p = Pattern.compile("(?:--no-reschedule|-N)");
289 m = p.matcher(this.option);
291 fullOption += " --no-reschedule";
293 this.option = fullOption;
299 * isSameService method
305 public boolean isSameService(VirtualSetting vs) {
306 if (this.virtual.equals(vs.virtual) && this.isSameKey(vs)) {
321 public boolean isSameKey(VirtualSetting vs) {
322 if (this.protomod.equals(vs.protomod)) {
323 String key1 = this.getKey();
324 String key2 = vs.getKey();
325 if (key1 != null && key2 != null && key1.equals(key2))
339 public String getKey() {
340 if (this.protomod == null || this.option == null)
342 this.complementOption();
343 if (this.protomod.equals("cinsert")) {
344 Pattern p = Pattern.compile("--cookie-name\\s+([^\\s]+)");
345 Matcher m = p.matcher(this.option);
347 return m.group(1).replaceAll("['\"]", "");
351 if (this.protomod.equals("url")) {
352 Pattern p = Pattern.compile("--pattern-match\\s+([^\\s]+)");
353 Matcher m = p.matcher(this.option);
355 return m.group(1).replaceAll("['\"]", "");
359 if (this.protomod.equals("sslid"))
361 if (this.protomod.equals("sessionless"))
376 public boolean equals(VirtualSetting vs) {
377 this.complementOption();
378 vs.complementOption();
379 if (this.virtual.equals(vs.virtual)
380 && this.protomod.equals(vs.protomod)
381 && this.option.equals(vs.option)
382 && this.sched.equals(vs.sched)
383 && this.maxconn == vs.maxconn
384 && this.qosservice == vs.qosservice
385 && this.qosclient == vs.qosclient
386 && this.sorryserver.equals(vs.sorryserver)
387 && this.sorryflag == vs.sorryflag
388 && this.timeout == vs.timeout
389 && this.checkcount == vs.checkcount
390 && this.checktype.equals(vs.checktype)
391 && this.service.equals(vs.service)
392 && this.quiescent == vs.quiescent
393 && this.checkport == vs.checkport
394 && this.request.equals(vs.request)
395 && this.receive.equals(vs.receive)
396 && this.httpmethod.equals(vs.httpmethod)
397 && this.virtualhost.equals(vs.virtualhost)
398 && this.login.equals(vs.login) && this.passwd.equals(vs.passwd)
399 && this.database.equals(vs.database)
400 && this.protocol.equals(vs.protocol)
401 && this.downcallback.equals(vs.downcallback)
402 && this.upcallback.equals(vs.upcallback)) {
403 if (this.real == null && vs.real == null)
405 if (this.real.size() == vs.real.size()) {
407 for (EndPoint e1: this.real) {
408 for (EndPoint e2: vs.real) {
414 if (sameCount == this.real.size())
430 public boolean equalsAdm(VirtualSetting vs) {
431 this.complementOption();
432 vs.complementOption();
433 if (this.virtual.equals(vs.virtual)
434 && this.protomod.equals(vs.protomod)
435 && this.option.equals(vs.option) && this.sched.equals(vs.sched)
436 && this.maxconn == vs.maxconn
437 && this.qosservice == vs.qosservice
438 && this.qosclient == vs.qosclient
439 && this.sorryserver.equals(vs.sorryserver)) {
440 if (this.real == null && vs.real == null)
442 if (this.real.size() == vs.real.size()) {
444 for (EndPoint e1: this.real) {
445 for (EndPoint e2: vs.real) {
451 if (sameCount == this.real.size())
462 public String toString() {
464 "virtual=(" + this.virtual + "), " +
465 "real=(" + this.real + "), " +
466 "protomod=\"" + this.protomod + "\", " +
467 "option=\"" + this.option + "\", " +
468 "sched=\"" + this.sched + "\", " +
469 "maxconn=" + this.maxconn + ", " +
470 "qosservice=" + this.qosservice + ", " +
471 "qosclient=" + this.qosclient + ", " +
472 "sorryserver=(" + this.sorryserver + "), " +
473 "sorryflag=" + this.sorryflag + ", " +
474 "timeout=" + this.timeout + ", " +
475 "checkcount=" + this.checkcount + ", " +
476 "checktype=\"" + this.checktype + "\", " +
477 "service=\"" + this.service + "\", " +
478 "quiescent=\"" + this.quiescent + "\", " +
479 "checkport=\"" + this.checkport + "\", " +
480 "request=\"" + this.request + "\", " +
481 "receive=\"" + this.receive + "\", " +
482 "httpmethod=\"" + this.httpmethod + "\", " +
483 "virtualhost=\"" + this.virtualhost + "\", " +
484 "login=\"" + this.login + "\", " +
485 "passwd=\"" + this.passwd + "\", " +
486 "database=\"" + this.database + "\", " +
487 "protocol=\"" + this.protocol + "\", " +
488 "downcallback=\"" + this.downcallback + "\", " +
489 "upcallback=\"" + this.upcallback + "\"";