1 24 25 package org.objectweb.cjdbc.console.text.module; 26 27 import java.util.HashSet ; 28 import java.util.Set ; 29 30 import org.objectweb.cjdbc.common.i18n.ConsoleTranslate; 31 import org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean; 32 import org.objectweb.cjdbc.common.jmx.mbeans.VirtualDatabaseMBean; 33 import org.objectweb.cjdbc.console.text.Console; 34 import org.objectweb.cjdbc.console.text.commands.Help; 35 import org.objectweb.cjdbc.console.text.commands.History; 36 import org.objectweb.cjdbc.console.text.commands.Quit; 37 import org.objectweb.cjdbc.console.text.commands.dbadmin.Backup; 38 import org.objectweb.cjdbc.console.text.commands.dbadmin.CopyLogFromCheckpoint; 39 import org.objectweb.cjdbc.console.text.commands.dbadmin.DeleteLogUpToCheckpoint; 40 import org.objectweb.cjdbc.console.text.commands.dbadmin.Disable; 41 import org.objectweb.cjdbc.console.text.commands.dbadmin.DisableRead; 42 import org.objectweb.cjdbc.console.text.commands.dbadmin.Enable; 43 import org.objectweb.cjdbc.console.text.commands.dbadmin.EnableRead; 44 import org.objectweb.cjdbc.console.text.commands.dbadmin.ExpertMode; 45 import org.objectweb.cjdbc.console.text.commands.dbadmin.ForceDisable; 46 import org.objectweb.cjdbc.console.text.commands.dbadmin.ForceEnable; 47 import org.objectweb.cjdbc.console.text.commands.dbadmin.GetBackendSchema; 48 import org.objectweb.cjdbc.console.text.commands.dbadmin.GetXml; 49 import org.objectweb.cjdbc.console.text.commands.dbadmin.ListBackends; 50 import org.objectweb.cjdbc.console.text.commands.dbadmin.RemoveDump; 51 import org.objectweb.cjdbc.console.text.commands.dbadmin.Replicate; 52 import org.objectweb.cjdbc.console.text.commands.dbadmin.Restore; 53 import org.objectweb.cjdbc.console.text.commands.dbadmin.SetCheckpoint; 54 import org.objectweb.cjdbc.console.text.commands.dbadmin.ShowBackend; 55 import org.objectweb.cjdbc.console.text.commands.dbadmin.ShowControllers; 56 import org.objectweb.cjdbc.console.text.commands.dbadmin.TransferBackend; 57 import org.objectweb.cjdbc.console.text.commands.dbadmin.TransferDump; 58 import org.objectweb.cjdbc.console.text.commands.dbadmin.UpdateDumpPath; 59 import org.objectweb.cjdbc.console.text.commands.dbadmin.ViewBackupers; 60 import org.objectweb.cjdbc.console.text.commands.dbadmin.ViewCheckpointNames; 61 import org.objectweb.cjdbc.console.text.commands.dbadmin.ViewDumps; 62 63 71 public class VirtualDatabaseAdmin extends AbstractConsoleModule 72 { 73 private String virtualDbName, login, password; 74 75 80 public String getLogin() 81 { 82 return login; 83 } 84 85 90 public String getPassword() 91 { 92 return password; 93 } 94 95 100 public String getVirtualDbName() 101 { 102 return virtualDbName; 103 } 104 105 108 public void login(String [] params) 109 { 110 quit = false; 112 String vdbName = params[0]; 113 try 114 { 115 console.getConsoleReader().addCompletor(this.getCompletor()); 116 console.getConsoleReader().removeCompletor( 117 console.getControllerModule().getCompletor()); 118 119 if (vdbName == null || vdbName.trim().equals("")) 120 { 121 vdbName = console.readLine(ConsoleTranslate.get("admin.login.dbname")); 122 if (vdbName == null) 123 return; 124 } 125 126 login = console.readLine(ConsoleTranslate.get("admin.login.user")); 127 if (login == null) 128 return; 129 130 password = console.readPassword(ConsoleTranslate 131 .get("admin.login.password")); 132 if (password == null) 133 return; 134 135 try 136 { 137 ControllerMBean mbean = console.getJmxClient().getControllerProxy(); 138 if (!mbean.hasVirtualDatabase(vdbName)) 139 { 140 console.printError(ConsoleTranslate.get("module.database.invalid", 141 vdbName)); 142 quit(); 143 return; 144 } 145 } 146 catch (Exception e) 147 { 148 e.printStackTrace(); 149 console.printError(ConsoleTranslate.get("module.database.invalid", 151 vdbName), e); 152 quit(); 153 } 154 try 155 { 156 VirtualDatabaseMBean vdb = console.getJmxClient() 157 .getVirtualDatabaseProxy(vdbName, login, password); 158 if (!vdb.checkAdminAuthentication(login, password)) 159 { 160 console.printError(ConsoleTranslate.get("module.database.login.fail", 161 login)); 162 quit(); 163 } 164 } 165 catch (Exception e) 166 { 167 console.printError(ConsoleTranslate.get("module.database.login.fail", 168 login)); 169 quit(); 170 } 171 this.virtualDbName = vdbName; 172 if (quit) 173 return; 174 175 loadCommands(); 177 console.println(ConsoleTranslate.get("admin.login.ready", virtualDbName)); 178 } 179 catch (Exception e) 180 { 181 console.printError(e.getMessage(), e); 182 quit(); 183 } 184 185 } 186 187 190 public String getDescriptionString() 191 { 192 return "VirtualDatabase Administration"; 193 } 194 195 198 public String getPromptString() 199 { 200 return virtualDbName + "(" + login + ")"; 201 } 202 203 206 protected void loadCommands() 207 { 208 commands.clear(); 209 commands.add(new Help(this)); 210 commands.add(new History(this)); 211 commands.add(new Quit(this)); 212 commands.add(new Backup(this)); 213 commands.add(new Disable(this)); 214 commands.add(new Enable(this)); 215 commands.add(new ExpertMode(this)); 216 commands.add(new GetXml(this)); 217 commands.add(new ListBackends(this)); 218 commands.add(new RemoveDump(this)); 219 commands.add(new Restore(this)); 220 commands.add(new ShowBackend(this)); 221 commands.add(new ShowControllers(this)); 222 commands.add(new TransferDump(this)); 223 commands.add(new ViewBackupers(this)); 224 commands.add(new ViewDumps(this)); 225 } 226 227 234 private Set expertCommandsSet() 235 { 236 Set expertCmds = new HashSet (); 237 expertCmds.add(new CopyLogFromCheckpoint(this)); 238 expertCmds.add(new DeleteLogUpToCheckpoint(this)); 239 expertCmds.add(new DisableRead(this)); 240 expertCmds.add(new EnableRead(this)); 241 expertCmds.add(new ForceEnable(this)); 242 expertCmds.add(new ForceDisable(this)); 243 expertCmds.add(new GetBackendSchema(this)); 244 expertCmds.add(new Replicate(this)); 245 expertCmds.add(new SetCheckpoint(this)); 246 expertCmds.add(new TransferBackend(this)); 247 expertCmds.add(new UpdateDumpPath(this)); 248 expertCmds.add(new ViewCheckpointNames(this)); 249 return expertCmds; 250 } 251 252 256 public void addExpertCommands() 257 { 258 commands.addAll(expertCommandsSet()); 259 reloadCompletor(); 262 } 263 264 268 public void removeExpertCommands() 269 { 270 commands.removeAll(expertCommandsSet()); 271 reloadCompletor(); 274 } 275 276 281 public VirtualDatabaseAdmin(Console console) 282 { 283 super(console); 284 } 285 } | Popular Tags |