Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

VirtualDatabaseAdmin.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2005 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Emmanuel Cecchet.
00022  * Contributor(s): Mathieu Peltier, Nicolas Modrzyk
00023  */
00024 
00025 package org.objectweb.cjdbc.console.text.module;
00026 
00027 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate;
00028 import org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean;
00029 import org.objectweb.cjdbc.common.jmx.mbeans.VirtualDatabaseMBean;
00030 import org.objectweb.cjdbc.console.text.Console;
00031 import org.objectweb.cjdbc.console.text.commands.Help;
00032 import org.objectweb.cjdbc.console.text.commands.History;
00033 import org.objectweb.cjdbc.console.text.commands.Native;
00034 import org.objectweb.cjdbc.console.text.commands.Quit;
00035 import org.objectweb.cjdbc.console.text.commands.dbadmin.Backup;
00036 import org.objectweb.cjdbc.console.text.commands.dbadmin.Disable;
00037 import org.objectweb.cjdbc.console.text.commands.dbadmin.DisableAll;
00038 import org.objectweb.cjdbc.console.text.commands.dbadmin.DisableRead;
00039 import org.objectweb.cjdbc.console.text.commands.dbadmin.Enable;
00040 import org.objectweb.cjdbc.console.text.commands.dbadmin.EnableAll;
00041 import org.objectweb.cjdbc.console.text.commands.dbadmin.EnableRead;
00042 import org.objectweb.cjdbc.console.text.commands.dbadmin.GetBackendSchema;
00043 import org.objectweb.cjdbc.console.text.commands.dbadmin.RemoveCheckpoint;
00044 import org.objectweb.cjdbc.console.text.commands.dbadmin.RemoveDumpFile;
00045 import org.objectweb.cjdbc.console.text.commands.dbadmin.Replicate;
00046 import org.objectweb.cjdbc.console.text.commands.dbadmin.Restore;
00047 import org.objectweb.cjdbc.console.text.commands.dbadmin.SetCheckpoint;
00048 import org.objectweb.cjdbc.console.text.commands.dbadmin.ShowBackendState;
00049 import org.objectweb.cjdbc.console.text.commands.dbadmin.ShowBackends;
00050 import org.objectweb.cjdbc.console.text.commands.dbadmin.TransferBackend;
00051 import org.objectweb.cjdbc.console.text.commands.dbadmin.ViewCheckpointNames;
00052 import org.objectweb.cjdbc.console.text.commands.dbadmin.ViewDumpNames;
00053 
00054 /**
00055  * This is the C-JDBC controller console virtual database administration module.
00056  * 
00057  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00058  * @author <a href="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a>
00059  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
00060  * @version 1.0
00061  */
00062 public class VirtualDatabaseAdmin extends AbstractConsoleModule
00063 {
00064   private String virtualDbName, login, password;
00065 
00066   /**
00067    * Returns the login value.
00068    * 
00069    * @return Returns the login.
00070    */
00071   public String getLogin()
00072   {
00073     return login;
00074   }
00075 
00076   /**
00077    * Returns the password value.
00078    * 
00079    * @return Returns the password.
00080    */
00081   public String getPassword()
00082   {
00083     return password;
00084   }
00085 
00086   /**
00087    * Returns the virtualDbName value.
00088    * 
00089    * @return Returns the virtualDbName.
00090    */
00091   public String getVirtualDbName()
00092   {
00093     return virtualDbName;
00094   }
00095 
00096   /**
00097    * @see org.objectweb.cjdbc.console.text.module.AbstractConsoleModule#login(java.lang.String[])
00098    */
00099   public void login(String[] params)
00100   {
00101     // In case a login has failed before
00102     quit = false;
00103     String vdbName = params[0];
00104     try
00105     {
00106       if (vdbName == null || vdbName.trim().equals(""))
00107       {
00108         vdbName = console.readLine(ConsoleTranslate.get("admin.login.dbname"));
00109         if (vdbName == null)
00110           return;
00111       }
00112 
00113       login = console.readLine(ConsoleTranslate.get("admin.login.user"));
00114       if (login == null)
00115         return;
00116 
00117       password = console.readPassword(ConsoleTranslate
00118           .get("admin.login.password"));
00119       if (password == null)
00120         return;
00121 
00122       try
00123       {
00124         ControllerMBean mbean = console.getJmxClient().getControllerProxy();
00125         if (!mbean.hasVirtualDatabase(vdbName))
00126         {
00127           console.printError(ConsoleTranslate.get("module.database.invalid",
00128               vdbName));
00129           quit();
00130           return;
00131         }
00132         VirtualDatabaseMBean vdb = console.getJmxClient()
00133             .getVirtualDatabaseProxy(vdbName, login, password);
00134         if (!vdb.checkAdminAuthentication(login, password))
00135         {
00136           console.printError(ConsoleTranslate.get("module.database.login.fail",
00137               login));
00138           quit();
00139         }
00140       }
00141       catch (Exception e)
00142       {
00143         // does not exists: quit
00144         console.printError(ConsoleTranslate.get("module.database.invalid",
00145             vdbName), e);
00146         quit();
00147       }
00148       this.virtualDbName = vdbName;
00149       if (quit)
00150         return;
00151 
00152       // Reload commands because target has changed
00153       loadCommands();
00154       console.println(ConsoleTranslate.get("admin.login.ready", virtualDbName));
00155     }
00156     catch (Exception e)
00157     {
00158       console.printError(e.getMessage(), e);
00159       quit();
00160     }
00161 
00162   }
00163 
00164   /**
00165    * @see org.objectweb.cjdbc.console.text.module.AbstractConsoleModule#getDescriptionString()
00166    */
00167   public String getDescriptionString()
00168   {
00169     return "VirtualDatabase Administration";
00170   }
00171 
00172   /**
00173    * @see org.objectweb.cjdbc.console.text.module.AbstractConsoleModule#getPromptString()
00174    */
00175   public String getPromptString()
00176   {
00177     return virtualDbName + "(" + login + ")";
00178   }
00179 
00180   /**
00181    * @see org.objectweb.cjdbc.console.text.module.AbstractConsoleModule#loadCommands()
00182    */
00183   protected void loadCommands()
00184   {
00185     commands.clear();
00186     commands.add(new Help(this));
00187     commands.add(new History(this));
00188     commands.add(new Quit(this));
00189     commands.add(new Backup(this));
00190     commands.add(new Disable(this));
00191     commands.add(new DisableRead(this));
00192     commands.add(new DisableAll(this));
00193     commands.add(new Enable(this));
00194     commands.add(new EnableRead(this));
00195     commands.add(new EnableAll(this));
00196     commands.add(new GetBackendSchema(this));
00197     commands.add(new Native(this));
00198     commands.add(new RemoveCheckpoint(this));
00199     commands.add(new RemoveDumpFile(this));
00200     commands.add(new Replicate(this));
00201     commands.add(new Restore(this));
00202     commands.add(new TransferBackend(this));
00203     commands.add(new ShowBackends(this));
00204     commands.add(new ShowBackendState(this));
00205     commands.add(new SetCheckpoint(this));
00206     commands.add(new ViewCheckpointNames(this));
00207     commands.add(new ViewDumpNames(this));
00208   }
00209 
00210   /**
00211    * Creates a new <code>VirtualDatabaseAdmin</code> instance.
00212    * 
00213    * @param console console console
00214    */
00215   public VirtualDatabaseAdmin(Console console)
00216   {
00217     super(console);
00218   }
00219 }

Generated on Mon Apr 11 22:01:35 2005 for C-JDBC by  doxygen 1.3.9.1