00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.objectweb.cjdbc.controller.core;
00026
00027 import java.io.BufferedOutputStream;
00028 import java.io.BufferedReader;
00029 import java.io.BufferedWriter;
00030 import java.io.DataOutputStream;
00031 import java.io.File;
00032 import java.io.FileNotFoundException;
00033 import java.io.FileOutputStream;
00034 import java.io.FileReader;
00035 import java.io.FileWriter;
00036 import java.io.IOException;
00037 import java.io.InputStream;
00038 import java.net.URL;
00039 import java.net.URLDecoder;
00040 import java.text.SimpleDateFormat;
00041 import java.util.ArrayList;
00042 import java.util.Date;
00043 import java.util.Enumeration;
00044 import java.util.Hashtable;
00045 import java.util.Iterator;
00046 import java.util.Locale;
00047 import java.util.zip.ZipEntry;
00048 import java.util.zip.ZipFile;
00049
00050 import javax.management.NotCompliantMBeanException;
00051 import javax.management.ObjectName;
00052
00053 import org.objectweb.cjdbc.common.exceptions.ControllerException;
00054 import org.objectweb.cjdbc.common.exceptions.VirtualDatabaseException;
00055 import org.objectweb.cjdbc.common.i18n.Translate;
00056 import org.objectweb.cjdbc.common.jmx.JmxConstants;
00057 import org.objectweb.cjdbc.common.jmx.JmxException;
00058 import org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean;
00059 import org.objectweb.cjdbc.common.jmx.notifications.CjdbcNotificationList;
00060 import org.objectweb.cjdbc.common.log.LogManager;
00061 import org.objectweb.cjdbc.common.log.Trace;
00062 import org.objectweb.cjdbc.common.util.Constants;
00063 import org.objectweb.cjdbc.common.xml.ControllerXmlTags;
00064 import org.objectweb.cjdbc.common.xml.XmlComponent;
00065 import org.objectweb.cjdbc.common.xml.XmlTools;
00066 import org.objectweb.cjdbc.controller.core.security.ControllerSecurityManager;
00067 import org.objectweb.cjdbc.controller.core.shutdown.ControllerForceShutdownThread;
00068 import org.objectweb.cjdbc.controller.core.shutdown.ControllerSafeShutdownThread;
00069 import org.objectweb.cjdbc.controller.core.shutdown.ControllerShutdownThread;
00070 import org.objectweb.cjdbc.controller.core.shutdown.ControllerWaitShutdownThread;
00071 import org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean;
00072 import org.objectweb.cjdbc.controller.jmx.MBeanServerManager;
00073 import org.objectweb.cjdbc.controller.jmx.RmiConnector;
00074 import org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase;
00075 import org.objectweb.cjdbc.controller.xml.DatabasesParser;
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 public final class Controller extends AbstractStandardMBean
00088 implements
00089 ControllerMBean,
00090 XmlComponent
00091 {
00092
00093
00094 private int portNumber;
00095 private int backlogSize;
00096
00097
00098
00099
00100
00101
00102 private String ipAddress;
00103
00104
00105 private ControllerServerThread connectionThread;
00106
00107
00108 static Trace logger = Trace
00109 .getLogger("org.objectweb.cjdbc.controller.core.Controller");
00110
00111
00112 private Hashtable virtualDatabases;
00113
00114
00115 private Hashtable configuration;
00116
00117
00118 private ControllerSecurityManager security;
00119
00120
00121 private ReportManager report;
00122
00123 private boolean isShuttingDown;
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 public Controller(String ipAddress, int port, int backlog)
00138 throws NotCompliantMBeanException, JmxException
00139 {
00140 super(ControllerMBean.class);
00141 virtualDatabases = new Hashtable();
00142 this.ipAddress = ipAddress;
00143 this.portNumber = port;
00144 this.backlogSize = backlog;
00145 ObjectName name = JmxConstants.getControllerObjectName();
00146 MBeanServerManager.registerMBean(this, name);
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 public void addVirtualDatabases(String xml, String vdbName, int autoEnable,
00165 String checkpoint) throws ControllerException
00166 {
00167 if (logger.isDebugEnabled())
00168 logger.debug(Translate.get("controller.add.virtualdatabase", vdbName));
00169 if (vdbName != null && this.hasVirtualDatabase(vdbName))
00170 {
00171 throw new ControllerException(Translate
00172 .get("controller.add.virtualdatabase.already.used"));
00173 }
00174 try
00175 {
00176 DatabasesParser parser = new DatabasesParser(this, vdbName, autoEnable,
00177 checkpoint);
00178 parser.readXML(xml, true);
00179 }
00180 catch (Exception e)
00181 {
00182 String msg = Translate.get("controller.add.virtualdatabase.failed", e);
00183 logger.warn(msg, e);
00184 throw new ControllerException(msg);
00185 }
00186 }
00187
00188
00189
00190
00191
00192
00193 public void addVirtualDatabases(String xml) throws ControllerException
00194 {
00195 if (logger.isDebugEnabled())
00196 {
00197 logger.debug(Translate.get("controller.loading.virtualdatabase"));
00198 }
00199 this.addVirtualDatabases(xml, null,
00200 ControllerConstants.AUTO_ENABLE_BACKEND,
00201 ControllerConstants.DATABASE_DEFAULT_CHECKPOINT);
00202 }
00203
00204
00205
00206
00207
00208
00209
00210 public void addVirtualDatabase(VirtualDatabase vdb)
00211 throws ControllerException
00212 {
00213 this.addVirtualDatabase(vdb, ControllerConstants.AUTO_ENABLE_BACKEND,
00214 ControllerConstants.DATABASE_DEFAULT_CHECKPOINT);
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 public synchronized void addVirtualDatabase(VirtualDatabase vdb,
00228 int autoLoad, String checkPoint) throws ControllerException
00229 {
00230
00231 if (hasVirtualDatabase(vdb.getDatabaseName()))
00232 {
00233 String msg = Translate.get("controller.database.already.exists", vdb
00234 .getDatabaseName());
00235 logger.warn(msg);
00236 throw new ControllerException(msg);
00237 }
00238 else
00239 {
00240 virtualDatabases.put(vdb.getDatabaseName(), vdb);
00241
00242
00243 if (MBeanServerManager.isJmxEnabled())
00244 {
00245 Hashtable databases = new Hashtable();
00246 try
00247 {
00248 databases.put("backends", vdb.getAllBackendNames());
00249 }
00250 catch (VirtualDatabaseException e)
00251 {
00252
00253 }
00254 RmiConnector.broadcastNotification(this,
00255 CjdbcNotificationList.CONTROLLER_VIRTUALDATABASE_ADDED,
00256 CjdbcNotificationList.NOTIFICATION_LEVEL_INFO, Translate.get(
00257 "notification.virtualdatabase.added", vdb
00258 .getVirtualDatabaseName()), databases);
00259 }
00260 }
00261
00262
00263 try
00264 {
00265 if (logger.isDebugEnabled())
00266 logger.debug(Translate.get("controller.database.autoenable", autoLoad));
00267
00268 switch (autoLoad)
00269 {
00270 case ControllerConstants.AUTO_ENABLE_TRUE :
00271 vdb.enableAllBackendsFromCheckpoint();
00272 break;
00273 case ControllerConstants.AUTO_ENABLE_FALSE :
00274 break;
00275 case ControllerConstants.AUTO_ENABLE_FORCE :
00276 logger.warn("Backends enabled in force mode from checkpoint "
00277 + checkPoint);
00278 vdb.forceEnableAllBackendsFromCheckpoint(checkPoint);
00279 break;
00280 default :
00281 logger
00282 .error("Unsupported autoEnabledBackends mode in controller configuration");
00283 break;
00284 }
00285 }
00286 catch (VirtualDatabaseException e)
00287 {
00288 throw new ControllerException(e);
00289 }
00290
00291 logger.info(Translate.get("controller.add.virtualdatabase", vdb
00292 .getDatabaseName()));
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302 public VirtualDatabase getVirtualDatabase(String virtualDatabaseName)
00303 {
00304 return (VirtualDatabase) virtualDatabases.get(virtualDatabaseName);
00305 }
00306
00307
00308
00309
00310 public ArrayList getVirtualDatabaseNames()
00311 {
00312 ArrayList result = new ArrayList();
00313 for (Iterator iter = virtualDatabases.values().iterator(); iter.hasNext();)
00314 result.add(((VirtualDatabase) iter.next()).getVirtualDatabaseName());
00315 return result;
00316 }
00317
00318
00319
00320
00321
00322
00323 public ArrayList getVirtualDatabases()
00324 {
00325 ArrayList result = new ArrayList();
00326 for (Iterator iter = virtualDatabases.values().iterator(); iter.hasNext();)
00327 result.add(iter.next());
00328 return result;
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338 public boolean hasVirtualDatabase(String name)
00339 {
00340 return virtualDatabases.containsKey(name);
00341 }
00342
00343
00344
00345
00346 public String removeVirtualDatabase(String virtualname)
00347 throws ControllerException
00348 {
00349 if (hasVirtualDatabase(virtualname))
00350 {
00351 VirtualDatabase vdb = (VirtualDatabase) virtualDatabases.get(virtualname);
00352 try
00353 {
00354 vdb.disableAllBackends();
00355 }
00356 catch (VirtualDatabaseException e)
00357 {
00358 throw new ControllerException(e);
00359 }
00360 this.virtualDatabases.remove(virtualname);
00361
00362
00363 if (MBeanServerManager.isJmxEnabled())
00364 {
00365 Hashtable databases = new Hashtable();
00366 try
00367 {
00368 databases.put("backends", vdb.getAllBackendNames());
00369 }
00370 catch (VirtualDatabaseException e)
00371 {
00372
00373 }
00374 RmiConnector.broadcastNotification(this,
00375 CjdbcNotificationList.CONTROLLER_VIRTUALDATABASE_REMOVED,
00376 CjdbcNotificationList.NOTIFICATION_LEVEL_INFO, Translate.get(
00377 "notification.virtualdatabase.removed", vdb
00378 .getVirtualDatabaseName()), databases);
00379 }
00380 }
00381 return Translate.get("controller.removeVirtualDatabase.success",
00382 virtualname);
00383 }
00384
00385
00386
00387
00388
00389
00390
00391
00392 public void addDriver(byte[] bytes) throws Exception
00393 {
00394
00395 File driversDirectory = null;
00396 URL url = Controller.class
00397 .getResource(ControllerConstants.C_JDBC_DRIVER_JAR_FILE);
00398 boolean error = false;
00399 if (url != null)
00400 {
00401 driversDirectory = (new File(URLDecoder.decode(url.getFile())))
00402 .getParentFile();
00403 error = (driversDirectory == null) || !driversDirectory.exists();
00404 }
00405
00406 if (error)
00407 {
00408 String msg = Translate.get("controller.driver.dir.not.found");
00409 logger.error(msg);
00410 throw new ControllerException(msg);
00411 }
00412
00413
00414 File temp = null;
00415 try
00416 {
00417 temp = File.createTempFile("driver", "zip", driversDirectory);
00418 FileOutputStream output = new FileOutputStream(temp);
00419 output.write(bytes);
00420 output.close();
00421 }
00422 catch (IOException e)
00423 {
00424 String msg = Translate.get("controller.add.jar.read.failed", e);
00425 logger.error(msg);
00426 throw new ControllerException(msg);
00427 }
00428
00429
00430 try
00431 {
00432 Enumeration entries;
00433 ZipFile zipFile = new ZipFile(temp);
00434
00435
00436 int lenght;
00437 InputStream in;
00438 BufferedOutputStream out;
00439 byte[] buffer = new byte[1024];
00440
00441 entries = zipFile.entries();
00442 while (entries.hasMoreElements())
00443 {
00444 ZipEntry entry = (ZipEntry) entries.nextElement();
00445
00446 if (entry.isDirectory())
00447 {
00448
00449 if (logger.isDebugEnabled())
00450 logger.debug(Translate.get("controller.add.jar.extract.dir", entry
00451 .getName()));
00452
00453 (new File(driversDirectory, entry.getName())).mkdir();
00454 continue;
00455 }
00456
00457
00458 if (logger.isDebugEnabled())
00459 logger.debug(Translate.get("controller.add.jar.extract.file", entry
00460 .getName()));
00461
00462 in = zipFile.getInputStream(entry);
00463 out = new BufferedOutputStream(new FileOutputStream(driversDirectory
00464 + System.getProperty("file.separator") + entry.getName()));
00465 while ((lenght = in.read(buffer)) >= 0)
00466 out.write(buffer, 0, lenght);
00467
00468 in.close();
00469 out.close();
00470 }
00471
00472 zipFile.close();
00473 temp.delete();
00474 logger.info(Translate.get("controller.add.jar.to.directory",
00475 driversDirectory.toString()));
00476 }
00477 catch (IOException e)
00478 {
00479 String msg = Translate.get("controller.driver.extract.failed", e);
00480 logger.error(msg);
00481 throw new ControllerException(msg);
00482 }
00483 }
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499 public String loadXmlConfiguration(String filename, String virtualName,
00500 int autoLoad, String checkPoint) throws Exception
00501 {
00502 FileReader fileReader = null;
00503 try
00504 {
00505 filename = filename.trim();
00506 try
00507 {
00508 fileReader = new FileReader(filename);
00509 }
00510 catch (FileNotFoundException fnf)
00511 {
00512 return Translate.get("controller.file.not.found", filename);
00513 }
00514
00515
00516 BufferedReader in = new BufferedReader(fileReader);
00517 StringBuffer xml = new StringBuffer();
00518 String line;
00519 do
00520 {
00521 line = in.readLine();
00522 if (line != null)
00523 xml.append(line);
00524 }
00525 while (line != null);
00526
00527
00528 addVirtualDatabases(xml.toString(), virtualName, autoLoad, checkPoint);
00529 return Translate.get("controller.file.send", filename);
00530 }
00531 catch (Exception e)
00532 {
00533 logger.error(Translate.get("controller.loadXml.failed", e), e);
00534 throw new ControllerException(Translate.get("controller.loadXml.failed",
00535 e));
00536 }
00537 finally
00538 {
00539 if (fileReader != null)
00540 fileReader.close();
00541 }
00542 }
00543
00544
00545
00546
00547
00548
00549
00550
00551 public String loadXml(String filename) throws Exception
00552 {
00553 return this.loadXmlConfiguration(filename, null,
00554 ControllerConstants.AUTO_ENABLE_BACKEND,
00555 ControllerConstants.DATABASE_DEFAULT_CHECKPOINT);
00556 }
00557
00558
00559
00560
00561
00562
00563
00564
00565 public String saveConfiguration() throws VirtualDatabaseException
00566 {
00567 String msg = Translate.get("controller.save.configuration");
00568 try
00569 {
00570 String configurationFile = ControllerConstants
00571 .getSaveFile(new SimpleDateFormat("EEE, MMM d, yy")
00572 .format(new Date()));
00573 DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(
00574 new FileOutputStream(configurationFile)));
00575 StringBuffer xml = new StringBuffer();
00576 xml.append(XmlTools.prettyXml(getXmlVirtualDatabases().toString()));
00577 dos.write(xml.toString().getBytes());
00578 dos.close();
00579 }
00580 catch (Exception e)
00581 {
00582 msg = Translate.get("controller.save.configuration.failed", e);
00583 logger.error(msg);
00584 }
00585 return msg;
00586 }
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597 public void endOfController(Exception fatal)
00598 {
00599 logger.fatal(Translate.get("fatal.error"));
00600 if (report.isGenerateOnFatal())
00601 {
00602 new ReportManager(this, fatal).generate();
00603 logger.info(Translate.get("fatal.report.generated", report
00604 .getReportLocation()
00605 + File.separator + ControllerConstants.REPORT_FILE));
00606 }
00607 Runtime.getRuntime().exit(1);
00608 }
00609
00610
00611
00612
00613
00614
00615 public ControllerServerThread getConnectionThread()
00616 {
00617 return connectionThread;
00618 }
00619
00620
00621
00622
00623 public boolean isShuttingDown()
00624 {
00625 return isShuttingDown;
00626 }
00627
00628
00629
00630
00631 public void shutdown(int level) throws ControllerException
00632 {
00633 ControllerShutdownThread shutdownThread = null;
00634 synchronized (this)
00635 {
00636 if (isShuttingDown())
00637 {
00638 logger.info(Translate.get("controller.already.shutting.down", this
00639 .getControllerName()));
00640 return;
00641 }
00642
00643 if (isSecurityEnabled() && !security.getAllowConsoleShutdown())
00644 throw new ControllerException(Translate
00645 .get("controller.shutdown.refused"));
00646
00647 switch (level)
00648 {
00649 case Constants.SHUTDOWN_WAIT :
00650 shutdownThread = new ControllerWaitShutdownThread(this);
00651 logger.info(Translate.get("controller.shutdown.type.wait", this
00652 .getControllerName()));
00653 break;
00654 case Constants.SHUTDOWN_SAFE :
00655 isShuttingDown = true;
00656 shutdownThread = new ControllerSafeShutdownThread(this);
00657 logger.info(Translate.get("controller.shutdown.type.safe", this
00658 .getControllerName()));
00659 break;
00660 case Constants.SHUTDOWN_FORCE :
00661 isShuttingDown = true;
00662 shutdownThread = new ControllerForceShutdownThread(this);
00663 logger.warn(Translate.get("controller.shutdown.type.force", this
00664 .getControllerName()));
00665 break;
00666 default :
00667 String msg = Translate
00668 .get("controller.shutdown.unknown.level", level);
00669 logger.error(msg);
00670 throw new RuntimeException(msg);
00671 }
00672 }
00673
00674 Thread thread = new Thread(shutdownThread.getShutdownGroup(),
00675 shutdownThread, "Controller Shutdown Thread");
00676 thread.start();
00677
00678 try
00679 {
00680 logger.info("Waiting for shutdown");
00681 thread.join();
00682 logger.info("Shutdown over");
00683 }
00684 catch (InterruptedException e)
00685 {
00686 e.printStackTrace();
00687 }
00688 }
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717 public static void main(String args[]) throws Exception
00718 {
00719 logger.info(getVersion());
00720
00721 System.setProperty("javax.management.builder.initial",
00722 org.objectweb.cjdbc.controller.jmx.MBeanServerBuilder.class.getName());
00723
00724 ControllerFactory conf = new ControllerFactory(args);
00725 Controller controller = conf.getController();
00726 if (controller != null)
00727 controller.launch();
00728 else
00729 throw new Exception(Translate.get("controller.configure.failed"));
00730 }
00731
00732
00733
00734
00735
00736 public void launch()
00737 {
00738 connectionThread = new ControllerServerThread(this);
00739 connectionThread.start();
00740
00741 SimpleDateFormat formatter = new SimpleDateFormat(
00742 "yyyy.MM.dd ww 'at' hh:mm:ss a zzz");
00743 Date day = new Date();
00744 String date = formatter.format(day);
00745 logger.info(Translate.get("controller.date", date));
00746 logger.info(Translate.get("controller.ready", getControllerName()));
00747 }
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758 public String getControllerName()
00759 {
00760 return ipAddress + ":" + portNumber;
00761 }
00762
00763
00764
00765
00766
00767
00768 public String getIPAddress()
00769 {
00770 return ipAddress;
00771 }
00772
00773
00774
00775
00776
00777
00778 public void setIPAddress(String ipAddress)
00779 {
00780 this.ipAddress = ipAddress;
00781 }
00782
00783
00784
00785
00786
00787
00788 public int getPortNumber()
00789 {
00790 return portNumber;
00791 }
00792
00793
00794
00795
00796
00797
00798 public void setPortNumber(int port)
00799 {
00800 portNumber = port;
00801 }
00802
00803
00804
00805
00806 public int getBacklogSize()
00807 {
00808 return backlogSize;
00809 }
00810
00811
00812
00813
00814 public void setBacklogSize(int size)
00815 {
00816 backlogSize = size;
00817 }
00818
00819
00820
00821
00822
00823
00824 public boolean getJmxEnable()
00825 {
00826 return MBeanServerManager.isJmxEnabled();
00827 }
00828
00829
00830
00831
00832
00833
00834 public String getJmxName()
00835 {
00836 if (getJmxEnable())
00837 {
00838 RmiConnector connector = ((RmiConnector) RmiConnector.getRmiConnectors()
00839 .get(0));
00840 return connector.getHostName() + ":" + connector.getPort();
00841 }
00842 else
00843 return getControllerName();
00844 }
00845
00846
00847
00848
00849
00850
00851 public void setJmxEnable(boolean enable)
00852 {
00853 configuration.put(ControllerFactory.JMX_ENABLE, "" + enable);
00854 }
00855
00856
00857
00858
00859
00860
00861 public static String getVersion()
00862 {
00863 return Translate.get("controller.info", Constants.VERSION);
00864 }
00865
00866
00867
00868
00869
00870
00871 public Hashtable getConfiguration()
00872 {
00873 return configuration;
00874 }
00875
00876
00877
00878
00879
00880
00881 public boolean isSecurityEnabled()
00882 {
00883 return security != null;
00884 }
00885
00886
00887
00888
00889 public ControllerSecurityManager getSecurity()
00890 {
00891 return security;
00892 }
00893
00894
00895
00896
00897 public void setSecurity(ControllerSecurityManager security)
00898 {
00899 this.security = security;
00900 }
00901
00902
00903
00904
00905 public String generateReport() throws Exception
00906 {
00907 report.startReport();
00908 return report.generate();
00909 }
00910
00911
00912
00913
00914
00915
00916 public void setConfiguration(Hashtable configuration)
00917 {
00918 this.configuration = configuration;
00919 }
00920
00921
00922
00923
00924 public String getVersionNumber()
00925 {
00926 return Constants.VERSION;
00927 }
00928
00929
00930
00931
00932 public String getAssociatedString()
00933 {
00934 return "controller";
00935 }
00936
00937
00938
00939
00940 public String getXml()
00941 {
00942 try
00943 {
00944 return XmlTools.prettyXml(getXmlController());
00945 }
00946 catch (Exception e)
00947 {
00948 logger.error(Translate.get("controller.xml.transformation.failed", e));
00949 return e.getMessage();
00950 }
00951 }
00952
00953
00954
00955
00956
00957
00958
00959 public String getXmlController()
00960 {
00961 StringBuffer info = new StringBuffer();
00962 info.append("<C-JDBC-CONTROLLER>");
00963 info.append("<" + ControllerXmlTags.ELT_CONTROLLER + " "
00964 + ControllerXmlTags.ATT_CONTROLLER_IP + "=\"" + this.getIPAddress()
00965 + "\" " + ControllerXmlTags.ATT_CONTROLLER_PORT + "=\""
00966 + this.getPortNumber() + "\" " + ">");
00967
00968 info.append("<" + ControllerXmlTags.ELT_INTERNATIONALIZATION + " "
00969 + ControllerXmlTags.ATT_LANGUAGE + "=\""
00970 + Locale.getDefault().getLanguage() + "\"/>");
00971
00972 if (report.isReportEnabled())
00973 {
00974 info.append("<" + ControllerXmlTags.ELT_REPORT + " "
00975 + ControllerXmlTags.ATT_REPORT_ENABLE_FILE_LOGGING + "=\""
00976 + report.isEnableFileLogging() + "\" "
00977 + ControllerXmlTags.ATT_REPORT_HIDE_SENSITIVE_DATA + "=\""
00978 + report.isHideSensitiveData() + "\" "
00979 + ControllerXmlTags.ATT_REPORT_GENERATE_ON_FATAL + "=\""
00980 + report.isGenerateOnFatal() + "\" "
00981 + ControllerXmlTags.ATT_REPORT_GENERATE_ON_SHUTDOWN + "=\""
00982 + report.isGenerateOnShutdown() + "\" "
00983 + ControllerXmlTags.ATT_REPORT_REPORT_LOCATION + "=\""
00984 + report.getReportLocation() + "\" />");
00985 }
00986
00987 if (getJmxEnable())
00988 {
00989 info.append("<" + ControllerXmlTags.ELT_JMX + ">");
00990 if (configuration.containsKey(JmxConstants.ADAPTOR_TYPE_HTTP))
00991 {
00992 info.append("<" + ControllerXmlTags.ELT_HTTP_JMX_ADAPTOR + " "
00993 + ControllerXmlTags.ATT_JMX_ADAPTOR_PORT + "=\""
00994 + configuration.get(JmxConstants.ADAPTOR_TYPE_HTTP) + "\" />");
00995 }
00996 if (configuration.containsKey(JmxConstants.ADAPTOR_TYPE_RMI))
00997 {
00998 info.append("<" + ControllerXmlTags.ELT_RMI_JMX_ADAPTOR + " "
00999 + ControllerXmlTags.ATT_JMX_ADAPTOR_PORT + "=\""
01000 + configuration.get(JmxConstants.ADAPTOR_TYPE_RMI) + "\" />");
01001 }
01002
01003 info.append("</" + ControllerXmlTags.ELT_JMX + ">");
01004 }
01005
01006 if (this.isSecurityEnabled())
01007 info.append(this.getSecurity().getXml());
01008 info.append("</" + ControllerXmlTags.ELT_CONTROLLER + ">");
01009 info.append("</C-JDBC-CONTROLLER>");
01010 return info.toString();
01011 }
01012
01013
01014
01015
01016
01017
01018 public String getXmlVirtualDatabases()
01019 {
01020 try
01021 {
01022 StringBuffer info = new StringBuffer();
01023 info.append("<C-JDBC>");
01024 ArrayList virtualDatabases = this.getVirtualDatabases();
01025 for (int i = 0, size = virtualDatabases.size(); i < size; i++)
01026 info.append(((VirtualDatabase) virtualDatabases.get(i)).getXml());
01027 info.append("</C-JDBC>");
01028 return info.toString();
01029 }
01030 catch (Exception e)
01031 {
01032 logger.error(e.getMessage(), e);
01033 return e.getMessage();
01034 }
01035 }
01036
01037
01038
01039
01040 public String generateLogReport() throws Exception
01041 {
01042 ReportManager report = new ReportManager(this, true);
01043 return report.generateJustLogs();
01044 }
01045
01046
01047
01048
01049
01050
01051
01052
01053 public void refreshLogConfiguration() throws ControllerException
01054 {
01055 try
01056 {
01057 LogManager.configure(URLDecoder.decode(this.getClass().getResource(
01058 ControllerConstants.LOG4J_RESOURCE).getFile()));
01059 if (logger.isDebugEnabled())
01060 logger.info(Translate.get("controller.refresh.log.success"));
01061 }
01062 catch (Exception e)
01063 {
01064 throw new ControllerException(Translate
01065 .get("controller.logconfigfile.not.found"));
01066 }
01067 }
01068
01069
01070
01071
01072 public void updateLogConfigurationFile(String newConfiguration)
01073 throws IOException, ControllerException
01074 {
01075 File logFile = new File(URLDecoder.decode(getClass().getResource(
01076 ControllerConstants.LOG4J_RESOURCE).getFile()));
01077 BufferedWriter writer = new BufferedWriter(new FileWriter(logFile));
01078 writer.write(newConfiguration);
01079 writer.flush();
01080 writer.close();
01081 refreshLogConfiguration();
01082 }
01083
01084
01085
01086
01087 public String viewLogConfigurationFile() throws IOException
01088 {
01089 File logFile = new File(URLDecoder.decode(getClass().getResource(
01090 ControllerConstants.LOG4J_RESOURCE).getFile()));
01091 BufferedReader reader = new BufferedReader(new FileReader(logFile));
01092 StringBuffer buffer = new StringBuffer();
01093 String line;
01094 while ((line = reader.readLine()) != null)
01095 buffer.append(line + System.getProperty("line.separator"));
01096 reader.close();
01097 return buffer.toString();
01098 }
01099
01100
01101
01102
01103
01104
01105 public ReportManager getReport()
01106 {
01107 return report;
01108 }
01109
01110
01111
01112
01113
01114
01115 public void setReport(ReportManager report)
01116 {
01117 this.report = report;
01118 }
01119 }