KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > agent > AgentAdmin


1 /*
2  * Copyright (C) 2002 - 2004 ScalAgent Distributed Technologies
3  * Copyright (C) 2004 - France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): ScalAgent Distributed Technologies
21  */

22 package fr.dyade.aaa.agent;
23
24 import java.util.*;
25 import java.lang.*;
26
27 import org.objectweb.util.monolog.api.BasicLevel;
28 import org.objectweb.util.monolog.api.Logger;
29
30 import fr.dyade.aaa.admin.cmd.*;
31 import fr.dyade.aaa.admin.script.*;
32 import fr.dyade.aaa.agent.conf.*;
33
34
35 final public class AgentAdmin extends Agent {
36   static Logger logmon;
37
38   // current operation
39
public static final int NONE = 0;
40   public static final int CONFIGURED = 1;
41   public static final int STOPED = 2;
42   public static final int STARTED = 3;
43   static String JavaDoc[] statusName = {"NONE", "CONFIGURED", "STOPED", "STARTED"};
44
45   /** silence use for idempotence */
46   private boolean silence = false;
47   /** configuration */
48   private transient A3CMLConfig a3cmlConfig = null;
49   /** start script */
50   private StartScript startScript = null;
51   /** stop script */
52   private StopScript stopScript = null;
53   /** script use to rollback a configuration */
54   private Script rollback = null;
55   /** server id counter */
56   private short maxId = 0;
57
58   /** get default AgentId of AgentAdmin */
59   public static AgentId getDefault(short serverId) {
60     return new AgentId(serverId, serverId, AgentId.AdminIdStamp);
61   }
62
63   /** get AgentId of AgentServer */
64   public static AgentId getDefault() {
65     return getDefault(AgentServer.getServerId());
66   }
67
68   /**
69    * Initializes the package as a well known service.
70    * <p>
71    * Creates a <code>AgentAdmin</code> agent with the well known stamp
72    * <code>AgentId.AdminIdStamp</code>.
73    *
74    * @param args parameters from the configuration file
75    * @param firstTime <code>true</code> when agent server starts anew
76    *
77    * @exception Exception
78    * unspecialized exception
79    */

80   public static void init(String JavaDoc args, boolean firstTime) throws Exception JavaDoc {
81     // Get the logging monitor from current server MonologMonitorFactory
82
logmon = Debug.getLogger("fr.dyade.aaa.agent.Admin");
83     if (logmon.isLoggable(BasicLevel.DEBUG))
84       logmon.log(BasicLevel.DEBUG,
85                  "AgentAdmin.init(" + args + ", " + firstTime + ")");
86     
87     if (! firstTime) return;
88     
89     short maxId;
90     if (args == null) {
91       maxId = -1;
92     } else {
93       try {
94         maxId = Short.parseShort(args);
95       } catch (Exception JavaDoc exc) {
96         if (logmon.isLoggable(BasicLevel.WARN))
97           logmon.log(BasicLevel.WARN, "", exc);
98         maxId = -1;
99       }
100     }
101     AgentAdmin agentAdmin = new AgentAdmin(maxId);
102     agentAdmin.deploy();
103   }
104
105   public static void stopService() {
106     // Does nothing
107
}
108   
109   protected void agentInitialize(boolean firstTime) throws Exception JavaDoc {
110     super.agentInitialize(firstTime);
111   }
112
113   /**
114    * Creates a local administration agent.
115    */

116   public AgentAdmin(short maxId) {
117     super("AgentAdmin#" + AgentServer.getServerId(),
118           true, AgentId.adminId);
119     this.maxId = maxId;
120   }
121
122   /**
123    * Reacts to <code>AgentAdmin</code> specific notifications.
124    * Analyzes the notification request code, then do the appropriate
125    * work. By default calls <code>react</code> from base class.
126    * Handled notification types are :
127    * <code>AdminRequest</code>,
128    * <code>AdminStartStopNot</code>
129    *
130    * @param from agent sending notification
131    * @param not notification to react to
132    *
133    * @exception Exception
134    * unspecialized exception
135    */

136   public void react(AgentId from, Notification not) throws Exception JavaDoc {
137     if (logmon.isLoggable(BasicLevel.DEBUG))
138       logmon.log(BasicLevel.DEBUG,
139                  "\n\n\nAgentAdmin.react(" + from + "," + not + ")");
140     if (not instanceof AdminRequestNot) {
141       doReact(from, (AdminRequestNot) not);
142     } else if (not instanceof AdminStartStopNot) {
143       doReact(from, (AdminStartStopNot) not);
144     } else {
145       super.react(from, not);
146     }
147   }
148
149  /**
150    * doReact to <code>AdminRequestNot</code> notifications.
151    *
152    * @param from agent sending AdminRequestNot
153    * @param not AdminRequestNot notification
154    *
155    * @exception Exception
156    */

157   private void doReact(AgentId from, AdminRequestNot not) throws Exception JavaDoc {
158     if (logmon.isLoggable(BasicLevel.DEBUG))
159       logmon.log(BasicLevel.DEBUG, "AgentAdmin.doReact(AdminRequestNot)");
160     
161     startScript = new StartScript();
162     stopScript = new StopScript();
163     rollback = new Script();
164     silence = not.silence;
165
166     try {
167       // configuration phase
168
doReact(not.script);
169     } catch (Exception JavaDoc exc) {
170       logmon.log(BasicLevel.WARN, "AgentAdmin.react", exc);
171       if (exc instanceof ExceptionCmd) {
172         // send exception to agent sending AdminRequestNot.
173
AdminReplyNot reply = new AdminReplyNot((ExceptionCmd) exc);
174         reply.setContext(not.getContext());
175         reply.status = NONE;
176         sendTo(from, reply);
177         // remove all i do (rollback)
178
doReact(rollback);
179         startScript = null;
180         stopScript = null;
181         rollback = null;
182       } else
183         throw exc;
184     }
185
186     if (not.autoStart) {
187       // start/stop configuration in same reaction
188
AdminStartStopNot startstop = new AdminStartStopNot();
189       startstop.setContext(not.getContext());
190       startstop.startScript = startScript;
191       startstop.stopScript = stopScript;
192       doReact(from, startstop);
193     } else {
194       // reply to agent sending AdminRequestNot.
195
// set in AdminReplyNot startScript and stopScript.
196
// use to start this configuration.
197
AdminReplyNot reply = new AdminReplyNot();
198       reply.setContext(not.getContext());
199       reply.startScript = startScript;
200       reply.stopScript = stopScript;
201       reply.status = CONFIGURED;
202       sendTo(from, reply);
203     }
204   }
205
206  /**
207    * doReact to <code>AdminStartStopNot</code> notifications.
208    *
209    * @param from agent sending AdminStartStopNot
210    * @param not AdminStartStopNot notification
211    *
212    * @exception Exception
213    */

214   private void doReact(AgentId from, AdminStartStopNot not) throws Exception JavaDoc {
215     if (logmon.isLoggable(BasicLevel.DEBUG))
216       logmon.log(BasicLevel.DEBUG,
217                  "AgentAdmin.doReact(AdminStartStopNot)\n startScript = " + startScript);
218
219     AdminAckStartStopNot ack = new AdminAckStartStopNot();
220     ack.setContext(not.getContext());
221     ack.status = CONFIGURED;
222     try {
223       startScript = not.startScript;
224       stopScript = not.stopScript;
225       // first execute stop script
226
if (stopScript != null) {
227         stop();
228         ack.status = STOPED;
229       }
230       // second execute start script
231
if (startScript != null) {
232         start();
233         ack.status = STARTED;
234       }
235       // startScript should be null
236
ack.startScript = startScript;
237       // stopScript contains the complementary
238
// of initial startScript.
239
ack.stopScript = stopScript;
240       sendTo(from, ack);
241     } catch (Exception JavaDoc exc) {
242       logmon.log(BasicLevel.WARN,
243                  "AgentAdmin.doReact(AdminStartStopNot) Exception : " + exc);
244       if (exc instanceof ExceptionCmd) {
245         ack.exc = (ExceptionCmd) exc;
246         // startScript should not be empty
247
// depend where exception is catch
248
ack.startScript = startScript;
249         ack.stopScript = stopScript;
250         sendTo(from, ack);
251       } else
252         throw exc;
253     }
254   }
255
256   /** execute start script */
257   private void start() throws Exception JavaDoc {
258     if (logmon.isLoggable(BasicLevel.DEBUG))
259       logmon.log(BasicLevel.DEBUG,
260                  "AgentAdmin.start()\nstartScript = " + startScript);
261     if (startScript == null) return;
262
263     Vector toRemove = new Vector();
264     try {
265       // add serverDesc
266
for (Enumeration e = startScript.serverDesc.elements(); e.hasMoreElements();)
267         AgentServer.addServerDesc((ServerDesc) e.nextElement());
268
269       // start network, server and service.
270
for (Enumeration e = startScript.elements(); e.hasMoreElements();) {
271         StartAdminCmd cmd = (StartAdminCmd) e.nextElement();
272 // if (cmd instanceof UpdateNetworkPortCmd) {
273
// doReact((UpdateNetworkPortCmd) cmd);
274
// } else
275
if (cmd instanceof StartNetworkCmd) {
276           doReact((StartNetworkCmd) cmd);
277         } else if (cmd instanceof StartServiceCmd) {
278           doReact((StartServiceCmd) cmd);
279         } else if (cmd instanceof StartServerCmd) {
280           doReact((StartServerCmd) cmd);
281         }
282         // add command done.
283
toRemove.addElement(cmd);
284       }
285       
286       // remove from startScript all done command.
287
for (Enumeration e = toRemove.elements(); e.hasMoreElements();) {
288         StartAdminCmd cmd = (StartAdminCmd) e.nextElement();
289         startScript.remove(cmd);
290       }
291       if (startScript.size() == 0)
292         startScript = null;
293     } catch (Exception JavaDoc exc) {
294       // remove from startScript all done command.
295
for (Enumeration e = toRemove.elements(); e.hasMoreElements();) {
296         StartAdminCmd cmd = (StartAdminCmd) e.nextElement();
297         startScript.remove(cmd);
298       }
299       if (startScript.size() == 0)
300         startScript = null;
301       throw exc;
302     }
303   }
304
305    /** execute stop script */
306   private void stop() throws Exception JavaDoc {
307     if (logmon.isLoggable(BasicLevel.DEBUG))
308       logmon.log(BasicLevel.DEBUG,
309                  "AgentAdmin.stop()\nstopScript = " + stopScript);
310     if (stopScript == null) return;
311
312     Vector toRemove = new Vector();
313     try {
314       for (Enumeration e = stopScript.elements(); e.hasMoreElements();) {
315         StopAdminCmd cmd = (StopAdminCmd) e.nextElement();
316         if (cmd instanceof StopNetworkCmd) {
317           doReact((StopNetworkCmd) cmd);
318         } else if (cmd instanceof StopServiceCmd) {
319           doReact((StopServiceCmd) cmd);
320         }
321         // add command done.
322
toRemove.addElement(cmd);
323       }
324
325       // remove from stopScript all done command.
326
for (Enumeration e = toRemove.elements(); e.hasMoreElements();) {
327         StopAdminCmd cmd = (StopAdminCmd) e.nextElement();
328         stopScript.remove(cmd);
329       }
330       if (stopScript.size() == 0)
331         stopScript = null;
332     } catch (Exception JavaDoc exc) {
333       // remove from stopScript all done command.
334
for (Enumeration e = toRemove.elements(); e.hasMoreElements();) {
335         StartAdminCmd cmd = (StartAdminCmd) e.nextElement();
336         startScript.remove(cmd);
337       }
338       if (startScript.size() == 0)
339         startScript = null;
340       throw exc;
341     }
342   }
343
344   /**
345    * execute configuration script
346    *
347    * @param script Script
348    *
349    * @exception Exception
350    */

351   private void doReact(Script script) throws Exception JavaDoc {
352     if (logmon.isLoggable(BasicLevel.DEBUG))
353       logmon.log(BasicLevel.DEBUG,
354                  "AgentAdmin.doReact(" + script + ")");
355
356     if (script.newConfig) {
357       a3cmlConfig = new A3CMLConfig();
358     } else {
359       // keep AgentServer configuration
360
a3cmlConfig = AgentServer.getConfig();
361     }
362
363     if (a3cmlConfig == null) {
364       throw new ExceptionCmd("a3cmlConfig is null");
365     }
366
367     for (Enumeration e = script.elements(); e.hasMoreElements();) {
368       AdminCmd cmd = (AdminCmd) e.nextElement();
369       if (cmd instanceof NewDomainCmd) {
370         doReact((NewDomainCmd) cmd);
371       } else if (cmd instanceof NewServerCmd) {
372         doReact((NewServerCmd) cmd);
373       } else if (cmd instanceof NewServiceCmd) {
374         doReact((NewServiceCmd) cmd);
375       } else if (cmd instanceof NewNetworkCmd) {
376         doReact((NewNetworkCmd) cmd);
377       } else if (cmd instanceof SetJvmArgsCmd) {
378         doReact((SetJvmArgsCmd) cmd);
379       } else if (cmd instanceof SetServerPropertyCmd) {
380         doReact((SetServerPropertyCmd) cmd);
381       } else if (cmd instanceof SetPropertyCmd) {
382         doReact((SetPropertyCmd) cmd);
383       } else if (cmd instanceof SetServerNatCmd) {
384         doReact((SetServerNatCmd) cmd);
385       } else if (cmd instanceof RemoveDomainCmd) {
386         doReact((RemoveDomainCmd) cmd);
387       } else if (cmd instanceof RemoveNetworkCmd) {
388         doReact((RemoveNetworkCmd) cmd);
389       } else if (cmd instanceof RemoveServerCmd) {
390         doReact((RemoveServerCmd) cmd);
391       } else if (cmd instanceof RemoveServiceCmd) {
392         doReact((RemoveServiceCmd) cmd);
393       } else if (cmd instanceof UnsetServerPropertyCmd) {
394         doReact((UnsetServerPropertyCmd) cmd);
395       } else if (cmd instanceof UnsetPropertyCmd) {
396         doReact((UnsetPropertyCmd) cmd);
397       } else if (cmd instanceof UnsetJvmArgsCmd) {
398         doReact((UnsetJvmArgsCmd) cmd);
399       } else if (cmd instanceof UnsetServerNatCmd) {
400         doReact((UnsetServerNatCmd) cmd);
401       } else if (cmd instanceof SetNetworkPortCmd) {
402         doReact((SetNetworkPortCmd) cmd);
403       }
404     }
405
406     A3CMLServer root = a3cmlConfig.getServer(AgentServer.getServerId());
407     a3cmlConfig.configure(root);
408
409     if (script.newConfig)
410       AgentServer.setConfig(a3cmlConfig);
411
412     // save configuration (transaction)
413
a3cmlConfig.save();
414   }
415
416   /**
417    * create new domain
418    *
419    * @param cmd NewDomainCmd
420    *
421    * @exception DomainCmdException
422    */

423   private void doReact(NewDomainCmd cmd) throws DomainCmdException {
424     if (logmon.isLoggable(BasicLevel.DEBUG))
425       logmon.log(BasicLevel.DEBUG,
426                  "AgentAdmin.doReact(" + cmd + ")");
427     
428     try {
429       if (!a3cmlConfig.containsDomain(cmd.name)) {
430         a3cmlConfig.addDomain(
431           new A3CMLDomain(cmd.name,
432                           cmd.networkClass));
433         rollback.add(new RemoveDomainCmd(cmd.name,cmd.networkClass));
434       } else {
435         if (silence) return;
436         throw new DomainCmdException("Domain " + cmd.name + " already exist.");
437       }
438     } catch (Exception JavaDoc exc) {
439       if (logmon.isLoggable(BasicLevel.ERROR))
440         logmon.log(BasicLevel.ERROR, "", exc);
441       throw new DomainCmdException(exc);
442     }
443   }
444
445   /**
446    * create new server
447    *
448    * @param cmd NewServerCmd
449    *
450    * @exception ServerCmdException
451    */

452   private void doReact(NewServerCmd cmd) throws ServerCmdException {
453     if (logmon.isLoggable(BasicLevel.DEBUG))
454       logmon.log(BasicLevel.DEBUG,
455                  "AgentAdmin.doReact(" + cmd + ")");
456     
457     try {
458       if (!a3cmlConfig.containsServer(cmd.name)) {
459         // set id for new server
460
Short JavaDoc id = null;
461         if (cmd.sid == null) {
462           id = getSid();
463           if (id == null)
464             throw new ServerCmdException(
465               "AgentAdmin : NewServerCmd(" + cmd +
466               ")not authorized on " +
467               AgentServer.getServerId());
468         } else
469           id = cmd.sid;
470         
471         a3cmlConfig.addServer(
472           new A3CMLServer(id.shortValue(),
473                            cmd.name,
474                            cmd.hostname));
475         rollback.add(new RemoveServerCmd(cmd.name,cmd.hostname));
476
477         // prepare serverDesc and add to startScript
478
ServerDesc sd = new ServerDesc(id.shortValue(),
479                                        cmd.name,
480                                        cmd.hostname,
481                                        -1);
482 // sd.isTransient = false;
483
sd.gateway = id.shortValue();
484         startScript.serverDesc.put(id, sd);
485         startScript.add(new StartServerCmd(id.shortValue(),cmd.name));
486         if (logmon.isLoggable(BasicLevel.DEBUG))
487           logmon.log(BasicLevel.DEBUG,
488                      "AgentAdmin startScript.serverDesc.put(" + id + "," + sd + ")");
489       } else {
490         if (silence) {
491           short sid;
492           if (cmd.sid == null) {
493             sid = a3cmlConfig.getServerIdByName(cmd.name);
494           } else {
495             sid = cmd.sid.shortValue();
496           }
497           if (sid != AgentServer.getServerId()) {
498             startScript.add(new StartServerCmd(
499               sid,
500               cmd.name));
501           }
502         } else {
503           throw new ServerCmdException(
504             "Server " + cmd.name + " already exists");
505         }
506       }
507     } catch (Exception JavaDoc exc) {
508       if (logmon.isLoggable(BasicLevel.DEBUG))
509         logmon.log(BasicLevel.DEBUG,
510                    "AgentAdmin.doReact(NewServerCmd)",exc);
511       throw new ServerCmdException(exc);
512     }
513   }
514   
515   /**
516    * create new service
517    *
518    * @param cmd NewServiceCmd
519    *
520    * @exception ServiceCmdException
521    */

522   private void doReact(NewServiceCmd cmd) throws ServiceCmdException {
523     if (logmon.isLoggable(BasicLevel.DEBUG))
524       logmon.log(BasicLevel.DEBUG,
525                  "AgentAdmin.doReact(" + cmd + ")");
526     
527     try {
528       A3CMLServer server = a3cmlConfig.getServer(cmd.serverName);
529       A3CMLService newService = new A3CMLService(cmd.className,cmd.args);
530       if (!server.services.contains(newService)) {
531         server.services.addElement(newService);
532         rollback.add(new RemoveServiceCmd(cmd.serverName,
533                                           cmd.className,
534                                           cmd.args));
535         
536         A3CMLServer adm = a3cmlConfig.getServer(AgentServer.getServerId());
537         if (cmd.serverName.equals(adm.name)) {
538           if (logmon.isLoggable(BasicLevel.DEBUG))
539             logmon.log(BasicLevel.DEBUG,
540                        "NewServiceCmd startScript.add(" + cmd.className + ")");
541           startScript.add(new StartServiceCmd(cmd.className,cmd.args));
542         }
543       } else {
544         if (silence) {
545           startScript.add(new StartServiceCmd(cmd.className,cmd.args));
546           return;
547         }
548         throw new ServiceCmdException("Service " + newService + " already exist in server " + server);
549       }
550     } catch (Exception JavaDoc exc) {
551       if (logmon.isLoggable(BasicLevel.ERROR))
552         logmon.log(BasicLevel.ERROR, "", exc);
553       throw new ServiceCmdException(exc);
554     }
555   }
556   
557   /**
558    * create new network
559    *
560    * @param cmd NewNetworkCmd
561    *
562    * @exception NetworkCmdException
563    */

564   private void doReact(NewNetworkCmd cmd) throws NetworkCmdException {
565     if (logmon.isLoggable(BasicLevel.DEBUG))
566       logmon.log(BasicLevel.DEBUG,
567                  "AgentAdmin.doReact(" + cmd + ")");
568
569     try {
570       A3CMLServer server = a3cmlConfig.getServer(cmd.serverName);
571       A3CMLNetwork toadd = new A3CMLNetwork(cmd.domain,cmd.port);
572       if (server.networks.contains(toadd)) {
573         if (silence) {
574           if (server.sid == AgentServer.getServerId()) {
575             startScript.add(new StartNetworkCmd(server.sid,
576                                                 cmd.domain));
577           }
578           return;
579         }
580         throw new NetworkCmdException(cmd.serverName + " already contains network " + toadd);
581       }
582       server.networks.addElement(toadd);
583       rollback.add(new RemoveNetworkCmd(cmd.serverName,
584                                         cmd.domain));
585       
586       if (!cmd.domain.equals("transient")) {
587         // add server in domains
588
A3CMLDomain domain = (A3CMLDomain) a3cmlConfig.getDomain(cmd.domain);
589         domain.addServer(server);
590         
591         if (server.sid == AgentServer.getServerId()) {
592           if (logmon.isLoggable(BasicLevel.DEBUG))
593             logmon.log(BasicLevel.DEBUG,
594                        "startScript.add(" + server.sid + ")");
595           startScript.add(new StartNetworkCmd(server.sid,
596                                               cmd.domain));
597         }
598
599         // prepare serverDesc and add to startScript
600
ServerDesc serverDesc =
601           (ServerDesc) startScript.serverDesc.get(new Short JavaDoc(server.sid));
602         if (serverDesc == null)
603           serverDesc = AgentServer.getServerDesc(server.sid);
604 // if (serverDesc != null) {
605
// serverDesc.port = cmd.port;
606
// }
607
}
608     } catch (Exception JavaDoc exc) {
609       if (logmon.isLoggable(BasicLevel.ERROR))
610         logmon.log(BasicLevel.ERROR, "", exc);
611       throw new NetworkCmdException(exc);
612     }
613   }
614
615   /**
616    * Set the port of a network
617    *
618    * @param cmd SetNetworkPortCmd
619    *
620    * @exception NetworkCmdException
621    */

622   private void doReact(SetNetworkPortCmd cmd) throws NetworkCmdException {
623     if (logmon.isLoggable(BasicLevel.DEBUG))
624       logmon.log(BasicLevel.DEBUG,
625                  "AgentAdmin.doReact(" + cmd + ")");
626     try {
627       A3CMLServer server = a3cmlConfig.getServer(cmd.serverName);
628       A3CMLNetwork network = null;
629       for (int i = 0; i < server.networks.size(); i++) {
630         A3CMLNetwork nw =
631           (A3CMLNetwork)server.networks.elementAt(i);
632         if (nw.domain.equals(cmd.domain)) {
633           network = nw;
634         }
635       }
636       if (network != null) {
637         // DF: the rollback script doesn't
638
// work properly:
639
// 1- a 'remove' command is not rollbacked
640
// because it is considered as a rollback action.
641
// 2- a 'set' command is its own reverse command.
642
// So a rollback loops indefinitely.
643
// rollback.add(
644
// new SetNetworkPortCmd(
645
// cmd.serverName, cmd.domain, network.port));
646
network.port = cmd.port;
647         startScript.add(
648           new StartNetworkCmd(
649             server.sid,
650             cmd.domain));
651       } else {
652         throw new Exception JavaDoc("Unknown network");
653       }
654     } catch (Exception JavaDoc exc) {
655       if (logmon.isLoggable(BasicLevel.ERROR))
656         logmon.log(BasicLevel.ERROR, "", exc);
657       throw new NetworkCmdException(exc);
658     }
659   }
660
661   /**
662    * set jvm arguments
663    *
664    * @param cmd SetJvmArgsCmd
665    *
666    * @exception JvmArgsCmdException
667    */

668   private void doReact(SetJvmArgsCmd cmd) throws JvmArgsCmdException {
669     if (logmon.isLoggable(BasicLevel.DEBUG))
670       logmon.log(BasicLevel.DEBUG,
671                  "AgentAdmin.doReact(" + cmd + ")");
672
673     try {
674       A3CMLServer server = a3cmlConfig.getServer(cmd.serverName);
675       server.jvmArgs = cmd.args;
676       rollback.add(new UnsetJvmArgsCmd(cmd.serverName,cmd.args));
677     } catch (Exception JavaDoc exc) {
678       if (logmon.isLoggable(BasicLevel.ERROR))
679         logmon.log(BasicLevel.ERROR, "", exc);
680       throw new JvmArgsCmdException(exc);
681     }
682   }
683   
684   /**
685    * set property
686    *
687    * @param cmd SetPropertyCmd
688    *
689    * @exception PropertyCmdException
690    */

691   private void doReact(SetPropertyCmd cmd) throws PropertyCmdException {
692     if (logmon.isLoggable(BasicLevel.DEBUG))
693       logmon.log(BasicLevel.DEBUG,
694                  "AgentAdmin.doReact(" + cmd + ")");
695
696     try {
697       if (!a3cmlConfig.containsProperty(cmd.name)) {
698         a3cmlConfig.addProperty(
699           new A3CMLProperty(cmd.name,
700                             cmd.value));
701         rollback.add(new UnsetPropertyCmd(cmd.name,cmd.value));
702       } else {
703         if (silence) return;
704         throw new PropertyCmdException("Property " + cmd.name + " already exist.");
705       }
706     } catch (Exception JavaDoc exc) {
707       if (logmon.isLoggable(BasicLevel.ERROR))
708         logmon.log(BasicLevel.ERROR, "", exc);
709       throw new PropertyCmdException(exc);
710     }
711   }
712   
713   /**
714    * set server property
715    *
716    * @param cmd SetServerPropertyCmd
717    *
718    * @exception PropertyCmdException
719    */

720   private void doReact(SetServerPropertyCmd cmd) throws PropertyCmdException {
721     if (logmon.isLoggable(BasicLevel.DEBUG))
722       logmon.log(BasicLevel.DEBUG,
723                  "AgentAdmin.doReact(" + cmd + ")");
724
725     try {
726       A3CMLServer server = a3cmlConfig.getServer(cmd.serverName);
727       if (!server.containsProperty(cmd.name)) {
728         server.addProperty(
729           new A3CMLProperty(cmd.name,
730                             cmd.value));
731         rollback.add(new UnsetServerPropertyCmd(cmd.serverName,cmd.name,cmd.value));
732       } else {
733         if (silence) return;
734         throw new PropertyCmdException("Property " + cmd.name +
735                                        " already exist in server " + cmd.serverName);
736       }
737     } catch (Exception JavaDoc exc) {
738       if (logmon.isLoggable(BasicLevel.ERROR))
739         logmon.log(BasicLevel.ERROR, "", exc);
740       throw new PropertyCmdException(exc);
741     }
742   }
743   
744   /**
745    * set network address translation
746    *
747    * @param cmd SetServerNatCmd
748    *
749    * @exception NatCmdException
750    */

751   private void doReact(SetServerNatCmd cmd) throws NatCmdException {
752     if (logmon.isLoggable(BasicLevel.DEBUG))
753       logmon.log(BasicLevel.DEBUG,
754                  "AgentAdmin.doReact(" + cmd + ")");
755
756     try {
757       A3CMLServer server = a3cmlConfig.getServer(cmd.serverName);
758       short sid = a3cmlConfig.getServerIdByName(cmd.translationServerName);
759       if (!server.containsNat(sid)) {
760         server.addNat(
761           new A3CMLNat(sid,
762                        cmd.translationHostName,
763                        cmd.translationHostPort));
764         rollback.add(new UnsetServerNatCmd(cmd.serverName,
765                                            cmd.translationServerName,
766                                            cmd.translationHostName,
767                                            cmd.translationHostPort));
768       } else {
769         if (silence) return;
770         throw new NatCmdException("Nat " + cmd.translationServerName +
771                                   " already exist in server " + cmd.serverName);
772       }
773     } catch (Exception JavaDoc exc) {
774       if (logmon.isLoggable(BasicLevel.ERROR))
775         logmon.log(BasicLevel.ERROR, "", exc);
776       throw new NatCmdException(exc);
777     }
778   }
779
780   /**
781    * start service
782    *
783    * @param cmd StartServiceCmd
784    *
785    * @exception ServiceCmdException
786    */

787   private void doReact(StartServiceCmd cmd) throws ServiceCmdException {
788     if (logmon.isLoggable(BasicLevel.DEBUG))
789       logmon.log(BasicLevel.DEBUG,
790                  "AgentAdmin.doReact(" + cmd + ")");
791     
792     try {
793       A3CMLServer a3cmlServer =
794         a3cmlConfig.getServer(AgentServer.getServerId());
795       A3CMLService a3cmlService =
796         a3cmlServer.getService(cmd.className);
797       ServiceManager.register(
798         a3cmlService.classname, a3cmlService.args);
799       ServiceDesc desc =
800         (ServiceDesc) ServiceManager.manager.registry.get(
801           a3cmlService.classname);
802       if (desc.running) return;
803       ServiceManager.start(desc);
804       if (stopScript == null) stopScript = new StopScript();
805       stopScript.add(new StopServiceCmd(a3cmlService.classname,
806                                         a3cmlService.args));
807     } catch (Exception JavaDoc exc) {
808       if (logmon.isLoggable(BasicLevel.ERROR))
809         logmon.log(BasicLevel.ERROR, "", exc);
810       throw new ServiceCmdException(exc);
811     }
812   }
813
814   /**
815    * Starts a network (idempotent).
816    *
817    * @param cmd StartNetworkCmd
818    *
819    * @exception NetworkCmdException
820    */

821   private void doReact(StartNetworkCmd cmd) throws NetworkCmdException {
822     if (logmon.isLoggable(BasicLevel.DEBUG))
823       logmon.log(BasicLevel.DEBUG,
824                  "AgentAdmin.doReact(" + cmd + ")");
825     try {
826       if (a3cmlConfig == null)
827         a3cmlConfig = AgentServer.getConfig();
828       A3CMLServer a3cmlServer = a3cmlConfig.getServer(cmd.sid);
829       A3CMLNetwork a3cmlNetwork = null;
830       for (int i = 0; i < a3cmlServer.networks.size(); i++) {
831         A3CMLNetwork nw =
832           (A3CMLNetwork)a3cmlServer.networks.elementAt(i);
833         if (nw.domain.equals(cmd.domainName)) {
834           a3cmlNetwork = nw;
835         }
836       }
837       
838       if (a3cmlNetwork == null)
839         throw new NetworkCmdException(
840           "Unknown network: " +
841           cmd.sid + '.' + cmd.domainName);
842
843       if (cmd.sid == AgentServer.getServerId()) {
844         Network network;
845         try {
846           // The network may have already been
847
// added (idempotency).
848
network =
849             (Network) AgentServer.getConsumer(cmd.domainName);
850         } catch (Exception JavaDoc exc) {
851           network = null;
852         }
853
854         if (network != null) {
855           if (network.getPort() != a3cmlNetwork.port) {
856             if (logmon.isLoggable(BasicLevel.DEBUG))
857               logmon.log(BasicLevel.DEBUG,
858                          " -> port change (before = " +
859                          network.getPort() +
860                          ", after = " +
861                          a3cmlNetwork.port + ')');
862             // The network is local so we have to
863
// stop it in order to update the listen port.
864
network.stop();
865             network.setPort(a3cmlNetwork.port);
866           }
867           network.start();
868         } else {
869           A3CMLDomain a3cmlDomain =
870             (A3CMLDomain) a3cmlConfig.getDomain(cmd.domainName);
871           network =
872             (Network) Class.forName(a3cmlDomain.network).newInstance();
873           short[] domainSids = new short[a3cmlDomain.servers.size()];
874           for (int i = 0; i < domainSids.length; i++) {
875             domainSids[i] =
876               ((A3CMLServer) a3cmlDomain.servers.elementAt(i)).sid;
877           }
878           AgentServer.addConsumer(cmd.domainName, network);
879           network.init(a3cmlDomain.name,
880                        a3cmlNetwork.port,
881                        domainSids);
882           network.start();
883         }
884       } else {
885         // The network is remote so we just
886
// may have to update the port value
887
// of the server desc.
888
try {
889           ServerDesc serverDesc =
890             AgentServer.getServerDesc(cmd.sid);
891           if (cmd.domainName.equals(serverDesc.getDomainName())) {
892             //serverDesc.setPort(a3cmlNetwork.port);
893
serverDesc.updateSockAddr(
894               serverDesc.getHostname(),
895               a3cmlNetwork.port);
896           }
897         } catch (UnknownServerException exc) {
898           // Nothing to do
899
}
900       }
901       if (stopScript == null) stopScript = new StopScript();
902       stopScript.add(new StopNetworkCmd(cmd.sid,
903                                         cmd.domainName));
904     } catch (Exception JavaDoc exc) {
905       if (logmon.isLoggable(BasicLevel.ERROR))
906         logmon.log(BasicLevel.ERROR, "", exc);
907       throw new NetworkCmdException(exc);
908     }
909   }
910
911   // DF: removed this command. It is replaced by StartNetworkCmd
912
//
913
// private void doReact(UpdateNetworkPortCmd cmd) throws NetworkCmdException {
914
// try {
915
// ServerDesc serverDesc = AgentServer.getServerDesc(cmd.sid);
916
// if (cmd.domainName.equals(serverDesc.getDomainName())) {
917
// // DF: Don't add the reverse action into the
918
// // stopScript because the meaning of the
919
// // update command does not fit into the start/stop
920
// // script principle.
921
// serverDesc.port = cmd.port;
922
// }
923
// } catch (Exception exc) {
924
// if (logmon.isLoggable(BasicLevel.ERROR))
925
// logmon.log(BasicLevel.ERROR, "", exc);
926
// throw new NetworkCmdException(exc);
927
// }
928
// }
929

930   /**
931    * start server
932    *
933    * @param cmd StartServerCmd
934    *
935    * @exception ServerCmdException
936    */

937   private void doReact(StartServerCmd cmd) throws ServerCmdException {
938     if (logmon.isLoggable(BasicLevel.DEBUG))
939       logmon.log(BasicLevel.DEBUG, "AgentAdmin.doReact(" + cmd + ")");
940
941     try {
942       // Attention, on prend des infos de la config courante (!= de celle
943
// de l'AgentServer et on reporte les modifs dans les ServerDesc de
944
// l'AgentServer.
945
if (a3cmlConfig == null)
946         a3cmlConfig = AgentServer.getConfig();
947       A3CMLServer current = a3cmlConfig.getServer(AgentServer.getServerId());
948       A3CMLServer server = a3cmlConfig.getServer(cmd.sid);
949       ServerDesc desc = AgentServer.getServerDesc(server.sid);
950
951       if (logmon.isLoggable(BasicLevel.DEBUG))
952         logmon.log(BasicLevel.DEBUG,
953                    "AgentAdmin.StartServerCmd : desc = " + desc);
954
955 // if (current.containsNat(server.sid)) {
956
// A3CMLNat nat = current.getNat(server.sid);
957
// desc.setPort(nat.portT);
958
// desc.setHostname(nat.hostT);
959
// if (logmon.isLoggable(BasicLevel.DEBUG))
960
// logmon.log(BasicLevel.DEBUG,
961
// "AgentAdmin.StartServerCmd : NAT desc = " + desc);
962
// }
963

964       AgentServer.initServerDesc(desc, server);
965         if (desc.gateway == desc.sid)
966           ((Network) desc.domain).addServer(server.sid);
967
968       if (logmon.isLoggable(BasicLevel.DEBUG))
969         logmon.log(BasicLevel.DEBUG,
970                    "AgentAdmin.StartServerCmd : " +
971                    "desc = " + AgentServer.getServerDesc(server.sid));
972     } catch (Exception JavaDoc exc) {
973       if (logmon.isLoggable(BasicLevel.ERROR))
974         logmon.log(BasicLevel.ERROR, "", exc);
975       throw new ServerCmdException(exc);
976     }
977   }
978
979   /**
980    * stop network
981    *
982    * @param cmd StopNetworkCmd
983    *
984    * @exception NetworkCmdException
985    */

986   private void doReact(StopNetworkCmd cmd) throws NetworkCmdException {
987     if (logmon.isLoggable(BasicLevel.DEBUG))
988       logmon.log(BasicLevel.DEBUG,
989                  "AgentAdmin.doReact(" + cmd + ")");
990
991     try {
992       for (Enumeration c=AgentServer.getConsumers(); c.hasMoreElements(); ) {
993     MessageConsumer consumer = (MessageConsumer) c.nextElement();
994         if (logmon.isLoggable(BasicLevel.DEBUG))
995           logmon.log(BasicLevel.DEBUG,
996                      "AgentAdmin consumer = " + consumer);
997         
998         if (consumer.getDomainName().equals(cmd.domainName)
999             && consumer.isRunning()) {
1000          if (logmon.isLoggable(BasicLevel.DEBUG))
1001            logmon.log(BasicLevel.DEBUG,
1002                       "AgentAdmin Stop domain = " + cmd.domainName);
1003          consumer.stop();
1004
1005          A3CMLNetwork nw = getNetwork(
1006            AgentServer.getServerId(), cmd.domainName);
1007          if (nw == null) {
1008            // Means that the network has been removed.
1009
AgentServer.removeConsumer(cmd.domainName);
1010          }
1011        }
1012      }
1013    } catch (Exception JavaDoc exc) {
1014      if (logmon.isLoggable(BasicLevel.ERROR))
1015        logmon.log(BasicLevel.ERROR, "", exc);
1016      throw new NetworkCmdException(exc);
1017    }
1018  }
1019  
1020  private A3CMLNetwork getNetwork(short sid, String JavaDoc domainName)
1021    throws Exception JavaDoc {
1022    if (a3cmlConfig == null)
1023      a3cmlConfig = AgentServer.getConfig();
1024    A3CMLServer server = a3cmlConfig.getServer(sid);
1025    if (server == null) return null;
1026    for (int i = 0; i < server.networks.size(); i++) {
1027      A3CMLNetwork network = (A3CMLNetwork) server.networks.elementAt(i);
1028      if (network.domain.equals(domainName)) {
1029        return network;
1030      }
1031    }
1032    return null;
1033  }
1034
1035  /**
1036   * stop service
1037   *
1038   * @param cmd StopServiceCmd
1039   *
1040   * @exception ServiceCmdException
1041   */

1042  private void doReact(StopServiceCmd cmd) throws ServiceCmdException {
1043    if (logmon.isLoggable(BasicLevel.DEBUG))
1044      logmon.log(BasicLevel.DEBUG,
1045                 "AgentAdmin.doReact(" + cmd + ")");
1046
1047   try {
1048      ServiceManager.stop(cmd.className);
1049    } catch (Exception JavaDoc exc) {
1050      if (logmon.isLoggable(BasicLevel.ERROR))
1051        logmon.log(BasicLevel.ERROR, "", exc);
1052      throw new ServiceCmdException(exc);
1053    }
1054  }
1055
1056  /**
1057   * remove domain
1058   *
1059   * @param cmd RemoveDomainCmd
1060   *
1061   * @exception DomainCmdException
1062   */

1063  private void doReact(RemoveDomainCmd cmd) throws DomainCmdException {
1064    if (logmon.isLoggable(BasicLevel.DEBUG))
1065      logmon.log(BasicLevel.DEBUG,
1066                 "AgentAdmin.doReact(" + cmd + ")");
1067    
1068    try {
1069      if (a3cmlConfig.containsDomain(cmd.name)) {
1070        A3CMLDomain domain = a3cmlConfig.getDomain(cmd.name);
1071
1072        if (domain.servers == null) {
1073          removeDomain(cmd.name);
1074          return;
1075        }
1076
1077        Vector toRemove = new Vector();
1078        for (Enumeration s = domain.servers.elements(); s.hasMoreElements(); ) {
1079          A3CMLServer server = (A3CMLServer) s.nextElement();
1080
1081          if (server.networks.size() > 2) {
1082            doReact(new RemoveNetworkCmd(server.name,
1083                                         cmd.name));
1084          } else if (server.networks.size() == 2) {
1085            if ((((A3CMLNetwork) server.networks.elementAt(0)).domain.equals("transient") &&
1086                 ((A3CMLNetwork) server.networks.elementAt(1)).domain.equals(cmd.name)) ||
1087                (((A3CMLNetwork) server.networks.elementAt(1)).domain.equals("transient") &&
1088                 ((A3CMLNetwork) server.networks.elementAt(0)).domain.equals(cmd.name)))
1089              toRemove.addElement(new RemoveServerCmd(server.name,
1090                                                      server.hostname));
1091            else
1092              doReact(new RemoveNetworkCmd(server.name,
1093                                           cmd.name));
1094          } else
1095            toRemove.addElement(new RemoveServerCmd(server.name,
1096                                             server.hostname));
1097        }
1098        
1099        for (int i = 0; i < toRemove.size(); i++)
1100          doReact((RemoveServerCmd)toRemove.elementAt(i));
1101        
1102        removeDomain(cmd.name);
1103      }
1104    } catch (Exception JavaDoc exc) {
1105      if (logmon.isLoggable(BasicLevel.ERROR))
1106        logmon.log(BasicLevel.ERROR, "", exc);
1107      throw new DomainCmdException(exc);
1108    }
1109  }
1110
1111  /**
1112   * remove network
1113   *
1114   * @param cmd RemoveNetworkCmd
1115   *
1116   * @exception NetworkCmdException
1117   */

1118  private void doReact(RemoveNetworkCmd cmd) throws NetworkCmdException {
1119    if (logmon.isLoggable(BasicLevel.DEBUG))
1120      logmon.log(BasicLevel.DEBUG,
1121                 "AgentAdmin.doReact(" + cmd + ")");
1122    
1123    A3CMLServer server = null;
1124    try {
1125      server = a3cmlConfig.getServer(cmd.serverName);
1126    } catch(fr.dyade.aaa.agent.conf.UnknownServerException e) { return;}
1127    if (server == null) return;
1128    
1129    try {
1130      if (server.sid == AgentServer.getServerId()) {
1131        if (logmon.isLoggable(BasicLevel.DEBUG))
1132          logmon.log(BasicLevel.DEBUG,
1133                     "stopScript.add( StopNetworkCmd(" +
1134                     cmd.serverName + "))");
1135        stopScript.add(new StopNetworkCmd(server.sid,
1136                                          cmd.domain));
1137      }
1138      removeNetwork(server.sid,cmd.domain);
1139    } catch (Exception JavaDoc exc) {
1140      if (logmon.isLoggable(BasicLevel.ERROR))
1141        logmon.log(BasicLevel.ERROR, "", exc);
1142      throw new NetworkCmdException(exc);
1143    }
1144  }
1145
1146  /**
1147   * remove server
1148   *
1149   * @param cmd RemoveServerCmd
1150   *
1151   * @exception ServerCmdException
1152   */

1153  private void doReact(RemoveServerCmd cmd) throws ServerCmdException {
1154    if (logmon.isLoggable(BasicLevel.DEBUG))
1155      logmon.log(BasicLevel.DEBUG,
1156                 "AgentAdmin.doReact(" + cmd + ")");
1157    
1158    A3CMLServer svr = null;
1159    try {
1160      svr = a3cmlConfig.getServer(cmd.name);
1161    } catch (fr.dyade.aaa.agent.conf.UnknownServerException exc) {
1162      return;
1163    }
1164    if (svr == null) return;
1165
1166    try {
1167      removeServer(svr.sid);
1168    } catch (Exception JavaDoc exc) {
1169      if (logmon.isLoggable(BasicLevel.ERROR))
1170        logmon.log(BasicLevel.ERROR, "", exc);
1171      throw new ServerCmdException(exc);
1172    }
1173  }
1174
1175  /**
1176   * remove service
1177   *
1178   * @param cmd RemoveServiceCmd
1179   *
1180   * @exception ServiceCmdException
1181   */

1182  private void doReact(RemoveServiceCmd cmd) throws ServiceCmdException {
1183    if (logmon.isLoggable(BasicLevel.DEBUG))
1184      logmon.log(BasicLevel.DEBUG,
1185                 "AgentAdmin.doReact(" + cmd + ")");
1186    
1187    A3CMLServer server = null;
1188    try {
1189      server = a3cmlConfig.getServer(cmd.serverName);
1190    } catch(fr.dyade.aaa.agent.conf.UnknownServerException exc) { return;}
1191
1192    if (server == null) return;
1193    try {
1194      if (server.sid == AgentServer.getServerId()) {
1195        if (logmon.isLoggable(BasicLevel.DEBUG))
1196          logmon.log(BasicLevel.DEBUG,
1197                     "stopScript.add( StopServiceCmd(" +
1198                     cmd.className + "))");
1199        stopScript.add(new StopServiceCmd(cmd.className,
1200                                          cmd.args));
1201      }
1202      removeService(server.sid,cmd.className);
1203    } catch (Exception JavaDoc exc) {
1204      if (logmon.isLoggable(BasicLevel.ERROR))
1205        logmon.log(BasicLevel.ERROR, "", exc);
1206      throw new ServiceCmdException(exc);
1207    }
1208  }
1209
1210  /**
1211   * unset server property
1212   *
1213   * @param cmd UnsetServerPropertyCmd
1214   *
1215   * @exception PropertyCmdException
1216   */

1217  private void doReact(UnsetServerPropertyCmd cmd) throws PropertyCmdException {
1218    if (logmon.isLoggable(BasicLevel.DEBUG))
1219      logmon.log(BasicLevel.DEBUG,
1220                 "AgentAdmin.doReact(" + cmd + ")");
1221    
1222    A3CMLServer server = null;
1223    try {
1224      server = a3cmlConfig.getServer(cmd.serverName);
1225    } catch(fr.dyade.aaa.agent.conf.UnknownServerException exc) { return;}
1226    
1227    if (server == null) return;
1228    try {
1229      unsetServerProperty(server.sid,cmd.name);
1230    } catch (Exception JavaDoc exc) {
1231      if (logmon.isLoggable(BasicLevel.ERROR))
1232        logmon.log(BasicLevel.ERROR, "", exc);
1233      throw new PropertyCmdException(exc);
1234    }
1235  }
1236
1237  /**
1238   * unset property
1239   *
1240   * @param cmd UnsetPropertyCmd
1241   *
1242   * @exception PropertyCmdException
1243   */

1244  private void doReact(UnsetPropertyCmd cmd) throws PropertyCmdException {
1245    if (logmon.isLoggable(BasicLevel.DEBUG))
1246      logmon.log(BasicLevel.DEBUG,
1247                 "AgentAdmin.doReact(" + cmd + ")");
1248    
1249    try {
1250      unsetProperty(cmd.name);
1251    } catch (Exception JavaDoc exc) {
1252      if (logmon.isLoggable(BasicLevel.ERROR))
1253        logmon.log(BasicLevel.ERROR, "", exc);
1254      throw new PropertyCmdException(exc);
1255    }
1256  }
1257
1258  /**
1259   * unset network address translation
1260   *
1261   * @param cmd UnsetServerNatCmd
1262   *
1263   * @exception NatCmdException
1264   */

1265  private void doReact(UnsetServerNatCmd cmd) throws NatCmdException {
1266    if (logmon.isLoggable(BasicLevel.DEBUG))
1267      logmon.log(BasicLevel.DEBUG,
1268                 "AgentAdmin.doReact(" + cmd + ")");
1269
1270    try {
1271      A3CMLServer server = a3cmlConfig.getServer(cmd.serverName);
1272      short sid = a3cmlConfig.getServerIdByName(cmd.translationServerName);
1273      server.removeNat(sid);
1274    } catch (Exception JavaDoc exc) {
1275      if (logmon.isLoggable(BasicLevel.ERROR))
1276        logmon.log(BasicLevel.ERROR, "", exc);
1277      throw new NatCmdException(exc);
1278    }
1279  }
1280  /**
1281   * unset jvm args
1282   *
1283   * @param cmd UnsetJvmArgsCmd
1284   *
1285   * @exception JvmArgsCmdException
1286   */

1287  private void doReact(UnsetJvmArgsCmd cmd) throws JvmArgsCmdException {
1288    if (logmon.isLoggable(BasicLevel.DEBUG))
1289      logmon.log(BasicLevel.DEBUG,
1290                 "AgentAdmin.doReact(" + cmd + ")");
1291    
1292    A3CMLServer server = null;
1293    try {
1294      server = a3cmlConfig.getServer(cmd.serverName);
1295    } catch(fr.dyade.aaa.agent.conf.UnknownServerException exc) { return;}
1296    
1297    if (server == null) return;
1298    try {
1299      unsetJvmArgs(server.sid,cmd.args);
1300    } catch (Exception JavaDoc exc) {
1301      if (logmon.isLoggable(BasicLevel.ERROR))
1302        logmon.log(BasicLevel.ERROR, "", exc);
1303      throw new JvmArgsCmdException(exc);
1304    }
1305  }
1306
1307  private void removeDomain(String JavaDoc domainName) throws Exception JavaDoc {
1308    if (logmon.isLoggable(BasicLevel.DEBUG))
1309      logmon.log(BasicLevel.DEBUG,
1310                 "AgentAdmin.removeDomain(" + domainName + ")");
1311    
1312    a3cmlConfig.removeDomain(domainName);
1313  }
1314
1315  private void removeNetwork(short sid, String JavaDoc domainName) throws Exception JavaDoc {
1316    if (logmon.isLoggable(BasicLevel.DEBUG))
1317      logmon.log(BasicLevel.DEBUG,
1318                 "AgentAdmin.removeNetwork(" + sid +
1319                 "," + domainName + ")");
1320    try {
1321      A3CMLServer server = a3cmlConfig.getServer(sid);
1322      if (server == null) return;
1323      for (int i = 0; i < server.networks.size(); i++) {
1324        A3CMLNetwork network =
1325          (A3CMLNetwork)server.networks.elementAt(i);
1326        if (network.domain.equals(domainName)) {
1327          if (logmon.isLoggable(BasicLevel.DEBUG))
1328            logmon.log(BasicLevel.DEBUG,
1329                       "AgentAdmin.removeNetwork remove : " + network);
1330          server.networks.removeElementAt(i);
1331        }
1332      }
1333    } catch (fr.dyade.aaa.agent.conf.UnknownServerException exc) {
1334      if (logmon.isLoggable(BasicLevel.ERROR))
1335        logmon.log(BasicLevel.ERROR, "", exc);
1336      return;
1337    }
1338  }
1339
1340  private void removeServer(short sid) throws Exception JavaDoc {
1341    if (logmon.isLoggable(BasicLevel.DEBUG))
1342      logmon.log(BasicLevel.DEBUG,
1343                 "AgentAdmin.removeServer(" + sid + ")");
1344
1345    try {
1346      ServerDesc servDesc = AgentServer.getServerDesc(sid);
1347      if (servDesc.domain instanceof Network)
1348        ((Network) servDesc.domain).delServer(sid);
1349    } catch (Exception JavaDoc exc) {
1350      if (logmon.isLoggable(BasicLevel.DEBUG))
1351        logmon.log(BasicLevel.DEBUG,
1352                   "AgentAdmin.removeServer remove server #" + sid, exc);
1353      return;
1354    }
1355
1356    try {
1357      // remove server in serverDesc
1358
AgentServer.removeServerDesc(sid);
1359      for (Enumeration e = AgentServer.elementsServerDesc(); e.hasMoreElements(); ) {
1360        ServerDesc sd = (ServerDesc)e.nextElement();
1361        if (sd.gateway == sid) {
1362          sd.gateway = -1;
1363          sd.domain = null;
1364        }
1365      }
1366    } catch (Exception JavaDoc exc) {
1367      if (logmon.isLoggable(BasicLevel.DEBUG))
1368        logmon.log(BasicLevel.DEBUG,
1369                   "AgentAdmin.removeServer remove server #" + sid, exc);
1370    }
1371
1372    // remove server in a3cmlConfig
1373
a3cmlConfig.removeServer(sid);
1374    for (Enumeration d = a3cmlConfig.domains.elements(); d.hasMoreElements(); ) {
1375      A3CMLDomain domain = (A3CMLDomain)d.nextElement();
1376      for (int i = 0; i < domain.servers.size(); i++) {
1377        A3CMLServer server = (A3CMLServer) domain.servers.elementAt(i);
1378        if (server.sid == sid) {
1379          domain.servers.removeElementAt(i);
1380          if (logmon.isLoggable(BasicLevel.DEBUG))
1381            logmon.log(BasicLevel.DEBUG,
1382                       "AgentAdmin.removeServer remove server #" + sid +
1383                       " in domain " + domain);
1384        }
1385      }
1386    }
1387  }
1388
1389  private void removeService(short sid, String JavaDoc className) throws Exception JavaDoc {
1390    if (logmon.isLoggable(BasicLevel.DEBUG))
1391      logmon.log(BasicLevel.DEBUG,
1392                 "AgentAdmin.removeService(" + sid +
1393                 "," + className + ")");
1394
1395    A3CMLServer server = a3cmlConfig.getServer(sid);
1396    if (server == null) return;
1397    for (int i = 0; i < server.services.size(); i++) {
1398      A3CMLService service =
1399        (A3CMLService) server.services.elementAt(i);
1400      if (service.classname.equals(className)) {
1401        server.services.removeElementAt(i);
1402        if (logmon.isLoggable(BasicLevel.DEBUG))
1403          logmon.log(BasicLevel.DEBUG,
1404                     "AgentAdmin.removeService service = " + service);
1405      }
1406    }
1407  }
1408
1409  private void unsetServerProperty(short sid, String JavaDoc name) throws Exception JavaDoc {
1410    if (logmon.isLoggable(BasicLevel.DEBUG))
1411      logmon.log(BasicLevel.DEBUG,
1412                 "AgentAdmin.unsetServerProperty(" + sid +
1413                 "," + name + ")");
1414    
1415    A3CMLServer server = a3cmlConfig.getServer(sid);
1416    if (server == null) return;
1417    server.removeProperty(name);
1418  }
1419
1420  private void unsetProperty(String JavaDoc name) throws Exception JavaDoc {
1421    if (logmon.isLoggable(BasicLevel.DEBUG))
1422      logmon.log(BasicLevel.DEBUG,
1423                 "AgentAdmin.unsetProperty(" + name + ")");
1424
1425    a3cmlConfig.removeProperty(name);
1426  }
1427
1428  private void unsetJvmArgs(short sid, String JavaDoc args) throws Exception JavaDoc {
1429    if (logmon.isLoggable(BasicLevel.DEBUG))
1430      logmon.log(BasicLevel.DEBUG,
1431                 "AgentAdmin.unsetArgs(" + sid +
1432                 "," + name + ")");
1433
1434    A3CMLServer server = a3cmlConfig.getServer(sid);
1435    if (server == null) return;
1436    //server.jvmArgs = server.jvmArgs.replaceAll(args,"");
1437

1438     StringTokenizer st = new StringTokenizer(args);
1439     while (st.hasMoreTokens()) {
1440       String JavaDoc toRemove = st.nextToken();
1441       int i = server.jvmArgs.indexOf(toRemove);
1442       if (i > -1) {
1443         String JavaDoc begin = server.jvmArgs.substring(0,i);
1444         String JavaDoc end = server.jvmArgs.substring(i + toRemove.length());
1445         server.jvmArgs = begin.concat(end);
1446       }
1447     }
1448
1449    if (server.jvmArgs == "")
1450      server.jvmArgs = null;
1451    if (logmon.isLoggable(BasicLevel.DEBUG))
1452      logmon.log(BasicLevel.DEBUG,
1453                 "AgentAdmin.unsetArgs jvmArgs = " + server.jvmArgs);
1454  }
1455
1456  public Short JavaDoc getSid() {
1457    if (maxId > -1) {
1458      maxId += 1;
1459      return new Short JavaDoc(maxId);
1460    } else {
1461      return null;
1462    }
1463  }
1464
1465// private boolean setGatewayAndDomain(A3CMLPServer server,
1466
// A3CMLPServer current) throws Exception {
1467
// if (logmon.isLoggable(BasicLevel.DEBUG))
1468
// logmon.log(BasicLevel.DEBUG,
1469
// "AgentAdmin.setGatewayAndDomain(" + server + "," + current + ")");
1470

1471// ServerDesc desc = AgentServer.getServerDesc(server.sid);
1472
// logmon.log(BasicLevel.DEBUG,
1473
// "AgentAdmin.setGatewayAndDomain:" + desc);
1474

1475// // Get routing infos from config
1476
// if (server.domain != null) {
1477
// if (server.gateway != -1)
1478
// desc.gateway = server.gateway;
1479
// else
1480
// desc.gateway = server.sid;
1481
// // desc.domain = a3cmlConfig.getDomain(server.domain).consumer;
1482
// desc.domain = AgentServer.getConsumer(server.domain);
1483
// logmon.log(BasicLevel.DEBUG, "AgentAdmin.setGatewayAndDomain:" + desc);
1484

1485// return true;
1486
// }
1487

1488// return false;
1489
// }
1490
}
1491
Popular Tags