1 package org.ultramonkey.l7.controller;
6 import org.apache.log4j.Logger;
7 import org.ultramonkey.l7.model.LogCategorySet;
10 * /usr/sbin/l7directored control class
16 public class DirectorController implements Serializable {
17 static final long serialVersionUID = 1L;
19 private final String l7directord = "/usr/sbin/l7directord";
21 protected String filename = "";
23 protected String CHECKTIMEOUT_KEY = "checktimeout";
25 protected String CHECKINTERVAL_KEY = "checkinterval";
27 protected String CHECKCOUNT_KEY = "checkcount";
29 protected String FALLBACK_KEY = "fallback";
31 protected String AUTORELOAD_KEY = "autoreload";
33 protected String EXECUTE_KEY = "execute";
35 protected String LOGFILE_KEY = "logfile";
37 protected String QUIESCENT_KEY = "quiescent";
39 protected String CALLBACK_KEY = "callback";
41 protected String NEGOTIATE_TIMEOUT_KEY = "negotiatetimeout";
43 protected String SUPERVISED_KEY = "supervised";
45 protected String VIRTUAL_KEY = "virtual";
47 protected String CHECKTYPE_KEY = "checktype";
49 protected String CHECKPORT_KEY = "checkport";
51 protected String MAXCONN_KEY = "maxconn";
53 protected String MODULE_KEY = "module";
55 protected String PROTOCOL_KEY = "protocol";
57 protected String QOSCLIENTS_KEY = "qosclients";
59 protected String QOSSERVICE_KEY = "qosservice";
61 protected String RECEIVE_KEY = "receive";
63 protected String SERVICE_KEY = "service";
65 protected String REAL_KEY = "real";
67 protected String REQUEST_KEY = "request";
69 protected String SCHEDULER_KEY = "scheduler";
71 protected String SORRYSERVER_KEY = "sorryserver";
73 protected String HTTPMETHOD_KEY = "httpmethod";
75 protected String VIRTUALHOST_KEY = "virtualhost";
77 protected String PASSWORD_KEY = "passwd";
79 protected String LOGIN_KEY = "login";
81 protected String DATABASE_KEY = "database";
83 protected String REALDOWNCALLBACK_KEY = "realdowncallback";
85 protected String REALRECOVERCALLBACK_KEY = "realrecovercallback";
93 * Copyright(c) NTT COMWARE 2008
98 protected class Pair<E, N> {
99 protected E elementFirst;
101 protected N elementSecond;
103 public Pair(E firstIn, N secondIn) {
104 elementFirst = firstIn;
105 elementSecond = secondIn;
108 public void set(E firstIn, N secondIn) {
109 elementFirst = firstIn;
110 elementSecond = secondIn;
118 return elementSecond;
122 protected Pair<String, String> paseKey(String inLine) {
125 int pos = inLine.indexOf("=");
127 return new Pair(inLine, "");
128 String first = inLine.substring(0, pos);
129 String second = inLine.substring(pos + 1, inLine.length());
130 if (first.indexOf('#') != -1)
131 return new Pair<String, String>("", "");
132 if (second.indexOf('#') != -1) {
133 pos = second.indexOf('#');
134 second = second.substring(0, pos);
136 first = first.trim();
137 second = second.trim();
138 Pair<String, String> pair = new Pair<String, String>(first, second);
142 protected boolean serchfile() {
143 // sengenbasyo kentou yousu
144 final String confname = "l7directord.cf";
145 final String confdir1 = "/etc/ha.d/";
146 final String confdir2 = "/etc/ha.d/conf/";
147 String conf = confdir1 + confname;
148 File objFile = new File(conf);
149 if (!objFile.exists()) {
150 conf = confdir2 + confname;
151 objFile = new File(conf);
152 if (!objFile.exists()) {
156 if (!objFile.isFile()) {
159 filename = objFile.getPath();
163 private static String trimQuote(String s) {
164 if (s != null && s.matches("^\".*\"$")) {
165 s = s.substring(1, s.length() - 1);
170 protected DirectorData loadFromFile()
171 throws org.ultramonkey.l7.model.FileNotReadException {
174 java.io.FileReader file = new java.io.FileReader(filename);
175 java.io.BufferedReader reader = new java.io.BufferedReader(file);
177 data = new DirectorData();
178 Stack<String> stack = new Stack<String>();
180 while ((buffer = reader.readLine()) != null) {
181 buffer = buffer.replaceAll("\\s+$", "");
182 buffer = buffer.replaceAll("\\t", " ");
183 if (buffer.length() == 0 || buffer.matches("^\\s*#.*"))
185 if (buffer.indexOf(VIRTUAL_KEY) == 0)
189 String tmpGlobalLogFile = "";
190 String tmpGlobalExecute = "";
191 boolean tmpGlobalAutoreaload = false;
192 String tmpGlobalCallback = "";
193 String tmpGlobalFallback = "";
194 String tmpGlobalCheckInterval = "";
195 String tmpGlobalCheckTimeOut = "";
196 String tmpGlobalCheckCount = "";
197 String tmpGlobalNegotiateTimeOut = "";
198 String tmpGlobalQuiescent = "";
199 String tmpGlobalSupervised = "no";
200 String tmpCheckTimeOut = "";
201 String tmpCheckCount = "";
202 String tmpNegotiateTimeOut = "";
203 String tmpQuiescent = "";
204 String tmpQosClients = "";
205 String tmpQosService = "";
206 String tmpSorryServer = "";
207 String tmpMaxConn = "";
208 String tmpProtocol = "";
209 String tmpScheduler = "";
210 String tmpReceive = "";
211 String tmpRequest = "";
212 String tmpService = "";
213 String tmpModule = "";
214 Vector<String> tmpReal = new Vector<String>();
215 String tmpCheckType = "";
216 String tmpCheckport = "";
217 String tmpHttpMethod = "";
218 String tmpVirtualHost = "";
219 String tmpPassword = "";
220 String tmpLogin = "";
221 String tmpDatabase = "";
222 String tmpRealDownCallback = "";
223 String tmpRealRecoverCallback = "";
224 while (!stack.empty()) {
225 buffer = stack.pop();
226 if (buffer.indexOf(AUTORELOAD_KEY) == 0) {
227 Pair<String, String> pair = paseKey(buffer);
228 if (pair.second().indexOf("yes") != -1)
229 tmpGlobalAutoreaload = true;
231 tmpGlobalAutoreaload = false;
233 if (buffer.indexOf(CALLBACK_KEY) == 0) {
234 Pair<String, String> pair = paseKey(buffer);
235 tmpGlobalCallback = trimQuote(pair.second());
236 } else if (buffer.indexOf(CHECKTIMEOUT_KEY) == 0) {
237 Pair<String, String> pair = paseKey(buffer);
238 tmpGlobalCheckTimeOut = pair.second();
239 } else if (buffer.indexOf(CHECKINTERVAL_KEY) == 0) {
240 Pair<String, String> pair = paseKey(buffer);
241 tmpGlobalCheckInterval = pair.second();
242 } else if (buffer.indexOf(CHECKCOUNT_KEY) == 0) {
243 Pair<String, String> pair = paseKey(buffer);
244 tmpGlobalCheckCount = pair.second();
245 } else if (buffer.indexOf(FALLBACK_KEY) == 0) {
246 Pair<String, String> pair = paseKey(buffer);
247 tmpGlobalFallback = pair.second();
248 } else if (buffer.indexOf(EXECUTE_KEY) == 0) {
249 Pair<String, String> pair = paseKey(buffer);
250 tmpGlobalExecute = trimQuote(pair.second());
251 } else if (buffer.indexOf(LOGFILE_KEY) == 0) {
252 Pair<String, String> pair = paseKey(buffer);
253 tmpGlobalLogFile = trimQuote(pair.second());
254 } else if (buffer.indexOf(NEGOTIATE_TIMEOUT_KEY) == 0) {
255 Pair<String, String> pair = paseKey(buffer);
256 tmpGlobalNegotiateTimeOut = pair.second();
257 } else if (buffer.indexOf(QUIESCENT_KEY) == 0) {
258 Pair<String, String> pair = paseKey(buffer);
259 tmpGlobalQuiescent = pair.second();
260 } else if (buffer.indexOf(SUPERVISED_KEY) == 0) {
261 tmpGlobalSupervised = "yes";
262 } else if (buffer.indexOf(CHECKTIMEOUT_KEY) >= 4) {
263 Pair<String, String> pair = paseKey(buffer);
264 tmpCheckTimeOut = pair.second();
265 } else if (buffer.indexOf(CHECKCOUNT_KEY) >= 4) {
266 Pair<String, String> pair = paseKey(buffer);
267 tmpCheckCount = pair.second();
268 } else if (buffer.indexOf(NEGOTIATE_TIMEOUT_KEY) >= 4) {
269 Pair<String, String> pair = paseKey(buffer);
270 tmpNegotiateTimeOut = pair.second();
271 } else if (buffer.indexOf(QUIESCENT_KEY) >= 4) {
272 Pair<String, String> pair = paseKey(buffer);
273 tmpQuiescent = pair.second();
274 } else if (buffer.indexOf(CHECKTYPE_KEY) >= 4) {
275 Pair<String, String> pair = paseKey(buffer);
276 tmpCheckType = pair.second();
277 } else if (buffer.indexOf(CHECKPORT_KEY) >= 4) {
278 Pair<String, String> pair = paseKey(buffer);
279 tmpCheckport = pair.second();
280 } else if (buffer.indexOf(MAXCONN_KEY) >= 4) {
281 Pair<String, String> pair = paseKey(buffer);
282 tmpMaxConn = pair.second();
283 } else if (buffer.indexOf(MODULE_KEY) >= 4) {
284 Pair<String, String> pair = paseKey(buffer);
285 tmpModule = pair.second();
286 } else if (buffer.indexOf(PROTOCOL_KEY) >= 4) {
287 Pair<String, String> pair = paseKey(buffer);
288 tmpProtocol = pair.second();
289 } else if (buffer.indexOf(QOSCLIENTS_KEY) >= 4) {
290 Pair<String, String> pair = paseKey(buffer);
291 tmpQosClients = pair.second();
292 } else if (buffer.indexOf(QOSSERVICE_KEY) >= 4) {
293 Pair<String, String> pair = paseKey(buffer);
294 tmpQosService = pair.second();
295 } else if (buffer.indexOf(REAL_KEY) >= 4
296 && buffer.indexOf(REALRECOVERCALLBACK_KEY) == -1
297 && buffer.indexOf(REALDOWNCALLBACK_KEY) == -1) {
298 Pair<String, String> pair = paseKey(buffer);
299 String real = pair.second();
301 } else if (buffer.indexOf(RECEIVE_KEY) >= 4) {
302 Pair<String, String> pair = paseKey(buffer);
303 tmpReceive = trimQuote(pair.second());
304 } else if (buffer.indexOf(REQUEST_KEY) >= 4) {
305 Pair<String, String> pair = paseKey(buffer);
306 tmpRequest = trimQuote(pair.second());
307 } else if (buffer.indexOf(SCHEDULER_KEY) >= 4) {
308 Pair<String, String> pair = paseKey(buffer);
309 tmpScheduler = pair.second();
310 } else if (buffer.indexOf(SERVICE_KEY) >= 4) {
311 Pair<String, String> pair = paseKey(buffer);
312 tmpService = trimQuote(pair.second());
313 } else if (buffer.indexOf(HTTPMETHOD_KEY) >= 4) {
314 Pair<String, String> pair = paseKey(buffer);
315 tmpHttpMethod = pair.second();
316 } else if (buffer.indexOf(VIRTUALHOST_KEY) >= 4) {
317 Pair<String, String> pair = paseKey(buffer);
318 tmpVirtualHost = trimQuote(pair.second());
319 } else if (buffer.indexOf(PASSWORD_KEY) >= 4) {
320 Pair<String, String> pair = paseKey(buffer);
321 tmpPassword = trimQuote(pair.second());
322 } else if (buffer.indexOf(LOGIN_KEY) >= 4) {
323 Pair<String, String> pair = paseKey(buffer);
324 tmpLogin = trimQuote(pair.second());
325 } else if (buffer.indexOf(DATABASE_KEY) >= 4) {
326 Pair<String, String> pair = paseKey(buffer);
327 tmpDatabase = trimQuote(pair.second());
328 } else if (buffer.indexOf(SORRYSERVER_KEY) >= 4) {
329 Pair<String, String> pair = paseKey(buffer);
330 tmpSorryServer = pair.second();
331 } else if (buffer.indexOf(REALDOWNCALLBACK_KEY) >= 4) {
332 Pair<String, String> pair = paseKey(buffer);
333 tmpRealDownCallback = trimQuote(pair.second());
334 } else if (buffer.indexOf(REALRECOVERCALLBACK_KEY) >= 4) {
335 Pair<String, String> pair = paseKey(buffer);
336 tmpRealRecoverCallback = trimQuote(pair.second());
337 } else if (buffer.indexOf(VIRTUAL_KEY) == 0) {
338 Pair<String, String> pair = paseKey(buffer);
339 VirtualSetting vs = new VirtualSetting();
340 int pos = pair.second().indexOf(":");
341 vs.virtual.host = pair.second().substring(0, pos);
342 vs.virtual.port = pair.second().substring(pos + 1,
343 pair.second().length());
344 if (! vs.virtual.port.matches("^\\d+$"))
345 vs.virtual.port = GetServ.byName(vs.virtual.port, "tcp");
346 for (Iterator<String> itr = tmpReal.iterator(); itr
348 String realstr = itr.next();
349 pos = realstr.indexOf(":");
350 EndPoint ed = new EndPoint();
351 ed.host = realstr.substring(0, pos);
352 int spacepos = realstr.lastIndexOf(" ");
353 String tmpWeight = "";
354 if (spacepos == -1) {
355 ed.port = realstr.substring(pos + 1, realstr
358 ed.port = realstr.substring(pos + 1, spacepos).replaceAll(" masq", "");
359 tmpWeight = realstr.substring(spacepos + 1, realstr
362 if (! ed.port.matches("^\\d+$"))
363 ed.port = GetServ.byName(ed.port, "tcp");
365 if (tmpWeight.length() != 0) {
367 ed.weight = Integer.parseInt(tmpWeight);
368 } catch (java.lang.NumberFormatException e) {
374 vs.checktype = tmpCheckType;
375 if (tmpMaxConn.length() != 0)
376 vs.maxconn = Integer.parseInt(tmpMaxConn);
377 pos = tmpModule.indexOf(" ");
379 vs.protomod = tmpModule.substring(0, pos);
380 vs.option = tmpModule
381 .substring(pos + 1, tmpModule.length());
383 vs.protomod = tmpModule;
386 vs.protocol = tmpProtocol;
387 if (tmpQosClients.length() != 0) {
388 if ((pos = tmpQosClients.indexOf('k')) != -1
389 || (pos = tmpQosClients.indexOf('K')) != -1) {
390 vs.qosclient = Long.parseLong(tmpQosClients
392 vs.qosclient = vs.qosclient * 1000;
393 } else if ((pos = tmpQosClients.indexOf('M')) != -1
394 || (pos = tmpQosClients.indexOf('m')) != -1) {
395 vs.qosclient = Long.parseLong(tmpQosClients
397 vs.qosclient = vs.qosclient * 1000000;
399 vs.qosclient = Long.parseLong(tmpQosClients);
403 if (tmpQosService.length() != 0) {
404 if ((pos = tmpQosService.indexOf('K')) != -1
405 || (pos = tmpQosService.indexOf('k')) != -1) {
406 vs.qosservice = Long.parseLong(tmpQosService
408 vs.qosservice = vs.qosservice * 1000;
409 } else if ((pos = tmpQosService.indexOf('M')) != -1
410 || (pos = tmpQosService.indexOf('m')) != -1) {
411 vs.qosservice = Long.parseLong(tmpQosService
413 vs.qosservice = vs.qosservice * 1000000;
415 vs.qosservice = Long.parseLong(tmpQosService);
418 vs.receive = tmpReceive;
419 vs.service = tmpService;
420 vs.request = tmpRequest;
421 vs.sched = tmpScheduler;
422 pos = tmpSorryServer.indexOf(":");
424 vs.sorryserver.host = tmpSorryServer.substring(0, pos);
425 vs.sorryserver.port = tmpSorryServer.substring(pos + 1,
426 tmpSorryServer.length());
427 if (! vs.sorryserver.port.matches("^\\d+$"))
428 vs.sorryserver.port = GetServ.byName(vs.sorryserver.port, "tcp");
430 vs.quiescent = tmpQuiescent;
431 vs.upcallback = tmpRealRecoverCallback;
432 vs.downcallback = tmpRealDownCallback;
433 if (tmpCheckport.length() != 0)
434 vs.checkport = Integer.parseInt(tmpCheckport);
435 vs.httpmethod = tmpHttpMethod;
436 vs.virtualhost = tmpVirtualHost;
438 vs.database = tmpDatabase;
439 vs.passwd = tmpPassword;
440 if (tmpCheckType != null &&
441 ((tmpCheckType.equals("connect") || tmpCheckType.equals("ping")) ||
442 ((tmpCheckType.equals("negotiate") || tmpCheckType.matches("^\\d$")) &&
443 tmpService != null && (tmpService.equals("dns") || tmpService.equals("sip"))
447 if (tmpCheckTimeOut.matches("^\\d+$"))
448 vs.timeout = Integer.parseInt(tmpCheckTimeOut);
451 if (tmpNegotiateTimeOut.matches("^\\d+$"))
452 vs.timeout = Integer.parseInt(tmpNegotiateTimeOut);
454 if (tmpCheckCount.matches("^\\d+$"))
455 vs.checkcount = Integer.parseInt(tmpCheckCount);
456 vs.cfPosition = position;
458 data.virtualSettings.add(vs);
459 tmpCheckTimeOut = "";
461 tmpNegotiateTimeOut = "";
473 tmpReal = new Vector<String>();
481 tmpRealDownCallback = "";
482 tmpRealRecoverCallback = "";
485 data.autoreload = tmpGlobalAutoreaload;
486 data.callback = tmpGlobalCallback;
487 data.checkCount = tmpGlobalCheckCount;
488 data.checkInterval = tmpGlobalCheckInterval;
489 data.checkTimeOut = tmpGlobalCheckTimeOut;
490 data.fallback = tmpGlobalFallback;
491 data.logfile = tmpGlobalLogFile;
492 data.execute = tmpGlobalExecute;
493 data.negotiateTimeOut = tmpGlobalNegotiateTimeOut;
494 data.quiescent = tmpGlobalQuiescent;
495 data.supervised = tmpGlobalSupervised;
496 } catch (Exception e) {
497 org.ultramonkey.l7.model.FileNotReadException ex = new org.ultramonkey.l7.model.FileNotReadException();
507 * buildNewConf method
511 * @return new configuration lines
512 * @throws org.ultramonkey.l7.model.FileNotWriteException
514 protected LinkedList<String> buildNewConf(DirectorData in)
515 throws org.ultramonkey.l7.model.FileNotWriteException {
516 LinkedList<String> datas = new LinkedList();
518 java.io.FileReader file = new java.io.FileReader(filename);
519 java.io.BufferedReader reader = new java.io.BufferedReader(file);
521 while ((buffer = reader.readLine()) != null) {
522 datas.addLast(buffer);
524 } catch (Exception e) {
525 org.ultramonkey.l7.model.FileNotWriteException ex = new org.ultramonkey.l7.model.FileNotWriteException();
526 ex.setErrMessage("Cannot open file : " + filename);
531 HashMap<String, String> map = new HashMap<String, String>();
532 map.put(CHECKTIMEOUT_KEY, in.checkTimeOut);
533 map.put(CHECKINTERVAL_KEY, in.checkInterval);
534 map.put(CHECKCOUNT_KEY, in.checkCount);
535 map.put(FALLBACK_KEY, in.fallback);
537 map.put(AUTORELOAD_KEY, "yes");
539 map.put(AUTORELOAD_KEY, "no");
540 if (in.logfile != null && in.logfile.length() > 0)
541 map.put(LOGFILE_KEY, "\"" + in.logfile + "\"");
543 map.put(LOGFILE_KEY, null);
544 if (in.execute != null && in.execute.length() > 0)
545 map.put(EXECUTE_KEY, "\"" + in.execute + "\"");
547 map.put(EXECUTE_KEY, null);
548 map.put(QUIESCENT_KEY, in.quiescent);
549 if (in.callback != null && in.callback.length() > 0)
550 map.put(CALLBACK_KEY, "\"" + in.callback + "\"");
552 map.put(CALLBACK_KEY, null);
553 map.put(NEGOTIATE_TIMEOUT_KEY, in.negotiateTimeOut);
554 if (in.supervised != null && in.supervised.equals("yes"))
555 map.put(SUPERVISED_KEY, in.supervised);
557 map.put(SUPERVISED_KEY, null);
560 for (Iterator<String> itr = map.keySet().iterator(); itr.hasNext();) {
561 String key = itr.next();
562 String value = map.get(key);
563 int commentLines = 0;
564 boolean inserted = false;
565 for (int i = 0; i < datas.size(); ++i) {
566 String line = datas.get(i);
567 String buffer = line.replaceAll("\\s+$", "");
568 if (buffer.length() == 0 || buffer.matches("^\\s*#.*")) {
572 else if (buffer.indexOf(VIRTUAL_KEY) == 0) {
573 if (value != null && value.length() > 0) {
574 StringBuffer buf = new StringBuffer(key);
575 if (! key.equals(SUPERVISED_KEY)) {
579 datas.add(i - commentLines, buf.toString());
585 Pair<String, String> pair = paseKey(buffer);
586 if (pair.first().equals(key)) {
587 if (value == null || ! pair.second().equals(value)) {
588 StringBuffer buf = new StringBuffer("#");
590 datas.set(i, buf.toString());
591 if (value != null && value.length() > 0) {
592 buf = new StringBuffer();
594 if (! key.equals(SUPERVISED_KEY)) {
598 datas.add(i, buf.toString());
605 if (inserted == false) {
606 if (value != null && value.length() > 0) {
607 StringBuffer buf = new StringBuffer(key);
608 if (! key.equals(SUPERVISED_KEY)) {
612 datas.add(buf.toString());
617 DirectorData currentData = null;
618 currentData = this.loadFromFile();
619 LinkedList<Integer> delVsPosition = new LinkedList<Integer>();
620 LinkedList<VirtualSetting> addVs = new LinkedList<VirtualSetting>();
621 for (Iterator<VirtualSetting> itr = in.virtualSettings
622 .iterator(); itr.hasNext();) {
623 VirtualSetting vs = itr.next();
624 boolean sameFlag = false;
625 for (Iterator<VirtualSetting> curItr = currentData.virtualSettings
626 .iterator(); curItr.hasNext();) {
627 VirtualSetting curVs = curItr.next();
628 if (curVs.equals(vs)) {
630 curVs.cfPosition = 0;
634 if (sameFlag == false) {
638 for (Iterator<VirtualSetting> curItr = currentData.virtualSettings
639 .iterator(); curItr.hasNext();) {
640 VirtualSetting curVs = curItr.next();
641 if (curVs.cfPosition != 0)
642 delVsPosition.add(curVs.cfPosition);
646 int commentLines = 0;
647 for (int i = 0; i < datas.size(); ++i) {
648 String buffer = datas.get(i);
649 String line = buffer.replaceAll("\\s+$", "");
650 if (line.length() == 0 || line.matches("^\\s*#.*")) {
653 else if (buffer.indexOf(VIRTUAL_KEY) == 0) {
655 if (delVsPosition.contains(position)) {
657 for (; i < datas.size(); ++i) {
658 buffer = datas.get(i);
659 line = buffer.replaceAll("\\s+$", "");
660 if (line.length() == 0 || line.matches("^\\s*#.*")) {
664 if (buffer.indexOf(VIRTUAL_KEY) == 0 && i != vsStartLine) {
665 i -= 1 + commentLines;
670 StringBuffer buf = new StringBuffer("#");
671 buf.append(datas.get(i));
672 datas.set(i, buf.toString());
677 for (VirtualSetting vs : addVs) {
678 datas.add(VIRTUAL_KEY + "=" + vs.virtual.host
679 + ":" + vs.virtual.port);
680 if (vs.real.size() != 0) {
681 for (java.util.Iterator<EndPoint> realitr = vs.real
682 .iterator(); realitr.hasNext();) {
683 EndPoint endpoint = realitr.next();
684 datas.add("\t" + REAL_KEY + "=" + endpoint.host
685 + ":" + endpoint.port + " masq "
686 + String.valueOf(endpoint.weight));
689 if (vs.checktype.length() != 0)
690 datas.add("\t" + CHECKTYPE_KEY + "=" + vs.checktype);
691 if (vs.checkport != 0)
692 datas.add("\t" + CHECKPORT_KEY + "=" + vs.checkport);
694 datas.add("\t" + MAXCONN_KEY + "="
695 + String.valueOf(vs.maxconn));
696 if (vs.protomod.length() != 0)
697 datas.add("\t" + MODULE_KEY + "=" + vs.protomod + " "
699 if (vs.qosclient != 0) {
700 StringBuffer buf = new StringBuffer();
701 if (vs.qosclient > 1000000) {
702 buf.append(vs.qosclient / 1000000);
704 } else if (vs.qosclient > 1000) {
705 buf.append(vs.qosclient / 1000);
708 buf.append(vs.qosclient);
709 datas.add("\t" + QOSCLIENTS_KEY + "="
712 if (vs.qosservice != 0) {
713 StringBuffer buf = new StringBuffer();
714 if (vs.qosservice > 1000000) {
715 buf.append(vs.qosservice / 1000000);
717 } else if (vs.qosservice > 1000) {
718 buf.append(vs.qosservice / 1000);
721 buf.append(vs.qosservice);
722 datas.add("\t" + QOSSERVICE_KEY + "="
725 if (vs.receive.length() != 0)
726 datas.add("\t" + RECEIVE_KEY + "=\"" + vs.receive + "\"");
727 if (vs.service.length() != 0)
728 datas.add("\t" + SERVICE_KEY + "=\"" + vs.service + "\"");
729 if (vs.request.length() != 0)
730 datas.add("\t" + REQUEST_KEY + "=\"" + vs.request + "\"");
731 if (vs.sched.length() != 0)
732 datas.add("\t" + SCHEDULER_KEY + "=" + vs.sched);
733 if (vs.sorryserver.host.length() != 0)
734 datas.add("\t" + SORRYSERVER_KEY + "="
735 + vs.sorryserver.host + ":" + vs.sorryserver.port);
736 if (vs.httpmethod.length() != 0)
737 datas.add("\t" + HTTPMETHOD_KEY + "=" + vs.httpmethod);
738 if (vs.virtualhost.length() != 0)
739 datas.add("\t" + VIRTUALHOST_KEY + "=\"" + vs.virtualhost + "\"");
740 if (vs.passwd.length() != 0)
741 datas.add("\t" + PASSWORD_KEY + "=\"" + vs.passwd + "\"");
742 if (vs.login.length() != 0)
743 datas.add("\t" + LOGIN_KEY + "=\"" + vs.login + "\"");
744 if (vs.database.length() != 0)
745 datas.add("\t" + DATABASE_KEY + "=\"" + vs.database + "\"");
746 if (vs.downcallback.length() != 0)
747 datas.add("\t" + REALDOWNCALLBACK_KEY + "=\""
748 + vs.downcallback + "\"");
749 if (vs.upcallback.length() != 0)
750 datas.add("\t" + REALRECOVERCALLBACK_KEY + "=\""
751 + vs.upcallback + "\"");
752 // if (vs.checkcount != 0)
753 // datas.add("\t" + CHECKCOUNT_KEY + "=" + vs.checkcount);
754 if (vs.timeout != 0) {
755 if (vs.checktype != null &&
756 ((vs.checktype.equals("connect") || vs.checktype.equals("ping")) ||
757 ((vs.checktype.equals("negotiate") || vs.checktype.matches("^\\d$")) &&
758 vs.service != null && (vs.service.equals("dns") || vs.service.equals("sip"))
762 datas.add("\t" + CHECKTIMEOUT_KEY + "=" + vs.timeout);
765 datas.add("\t" + NEGOTIATE_TIMEOUT_KEY + "=" + vs.timeout);
768 if (vs.quiescent.length() != 0)
769 datas.add("\t" + QUIESCENT_KEY + "=" + vs.quiescent);
770 if (vs.protocol.length() != 0)
771 datas.add("\t" + PROTOCOL_KEY + "=" + vs.protocol);
774 } catch (Exception e) {
775 org.ultramonkey.l7.model.FileNotWriteException ex = new org.ultramonkey.l7.model.FileNotWriteException();
776 ex.setErrMessage("Cannot open file : " + filename
777 + "BaseException : " + e.getMessage());
791 * @throws org.ultramonkey.l7.model.FileNotWriteException
793 protected void saveToFile(DirectorData in)
794 throws org.ultramonkey.l7.model.FileNotWriteException {
795 LinkedList<String> datas = this.buildNewConf(in);
797 java.io.File file = new java.io.File(filename);
799 Date date = new Date();
800 java.io.File backfile = new java.io.File(filename + ".bak."
801 + String.valueOf(date.getTime()));
802 file.renameTo(backfile);
803 file = new java.io.File(filename);
805 java.io.FileWriter writer = new java.io.FileWriter(file);
806 for (Iterator<String> itr = datas.iterator(); itr
808 StringBuffer buf = new StringBuffer(itr.next());
810 writer.write(buf.toString());
814 } catch (Exception e) {
815 org.ultramonkey.l7.model.FileNotWriteException ex = new org.ultramonkey.l7.model.FileNotWriteException();
816 ex.setErrMessage("Cannot write file : " + filename);
828 * @throws org.ultramonkey.l7.model.FileNotWriteException
830 protected String syntaxCheck(DirectorData in)
831 throws org.ultramonkey.l7.model.FileNotWriteException {
832 StringBuffer result = new StringBuffer();
833 LinkedList<String> datas = this.buildNewConf(in);
835 Date date = new Date();
836 String tmpFile = filename + "." + String.valueOf(date.getTime());
837 File file = new java.io.File(tmpFile);
838 FileWriter writer = new FileWriter(file);
839 for (Iterator<String> itr = datas.iterator(); itr
841 StringBuffer buf = new StringBuffer(itr.next());
843 writer.write(buf.toString());
849 String command = "sudo " + l7directord + " -t " + tmpFile;
850 Process p = Runtime.getRuntime().exec(command);
851 InputStream stderr = p.getErrorStream();
852 BufferedReader br = new BufferedReader(new InputStreamReader(stderr));
854 while ((line = br.readLine()) != null) {
855 result.append(line + "\n");
857 InputStream is = p.getInputStream();
858 br = new BufferedReader(new InputStreamReader(is));
859 while ((line = br.readLine()) != null) {
860 result.append(line + "\n");
864 } catch (Exception e) {
865 org.ultramonkey.l7.model.FileNotWriteException ex = new org.ultramonkey.l7.model.FileNotWriteException();
866 ex.setErrMessage("Cannot write file : " + filename);
870 return result.toString();
874 * get DirectorData from l7directord.cf
876 * getDirectorData method
879 * @return DirectorData l7directord.cf datas
880 * @throws org.ultramonkey.l7.model.FileNotReadException
882 public DirectorData getDirectorData()
883 throws org.ultramonkey.l7.model.FileNotReadException {
884 // --- debug log (in method) ---
885 Logger ioFileLogger = Logger.getLogger(LogCategorySet.GUI_IO_FILE);
886 if (ioFileLogger.isDebugEnabled()) {
887 ioFileLogger.debug("11575 DirectorController::getDirectorData() in");
889 // --- debug log (in method) ---
891 DirectorData data = null;
892 synchronized (this) {
894 data = loadFromFile();
898 // --- debug log (out method) ---
899 if (ioFileLogger.isDebugEnabled()) {
900 ioFileLogger.debug("11576 DirectorController::getDirectorData() out return=(" + data + ")");
902 // --- debug log (out method) ---
907 * set DirectorData to l7directord.cf
909 * setDirectorData method
914 public void setDirectorData(DirectorData in)
915 throws org.ultramonkey.l7.model.FileNotWriteException {
916 // --- debug log (in method) ---
917 Logger ioFileLogger = Logger.getLogger(LogCategorySet.GUI_IO_FILE);
918 if (ioFileLogger.isDebugEnabled()) {
919 ioFileLogger.debug("11577 DirectorController::setDirectorData(DirectorData in) in in=(" + in + ")");
921 // --- debug log (in method) ---
923 synchronized (this) {
924 if (in != null && serchfile()) {
929 // --- debug log (out method) ---
930 if (ioFileLogger.isDebugEnabled()) {
931 ioFileLogger.debug("11578 DirectorController::setDirectorData(DirectorData in) out");
933 // --- debug log (out method) ---
937 * check new l7directord.cf
939 * checkDirectorData method
944 public String checkDirectorData(DirectorData in)
945 throws org.ultramonkey.l7.model.FileNotWriteException {
946 // --- debug log (in method) ---
947 Logger ioFileLogger = Logger.getLogger(LogCategorySet.GUI_IO_FILE);
948 if (ioFileLogger.isDebugEnabled()) {
949 ioFileLogger.debug("11579 DirectorController::checkDirectorData(DirectorData in) in in=(" + in + ")");
951 // --- debug log (in method) ---
953 synchronized (this) {
954 if (in != null && serchfile()) {
955 String ret = this.syntaxCheck(in);
957 // --- debug log (out method) ---
958 if (ioFileLogger.isDebugEnabled()) {
959 ioFileLogger.debug("11580 DirectorController::checkDirectorData(DirectorData in) out return=\"" + ret + "\"");
961 // --- debug log (out method) ---
965 // --- debug log (out method) ---
966 if (ioFileLogger.isDebugEnabled()) {
967 ioFileLogger.debug("11581 DirectorController::checkDirectorData(DirectorData in) out return=null");
969 // --- debug log (out method) ---