1 23 24 package org.continuent.sequoia.console.text.module; 25 26 import java.util.HashSet ; 27 import java.util.Set ; 28 29 import org.continuent.sequoia.common.i18n.ConsoleTranslate; 30 import org.continuent.sequoia.common.jmx.mbeans.ControllerMBean; 31 import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean; 32 import org.continuent.sequoia.console.text.Console; 33 import org.continuent.sequoia.console.text.ConsoleException; 34 35 44 public class VirtualDatabaseAdmin extends AbstractConsoleModule 45 { 46 private String virtualDbName, login, password; 47 48 53 public String getLogin() 54 { 55 return login; 56 } 57 58 63 public String getPassword() 64 { 65 return password; 66 } 67 68 73 public String getVirtualDbName() 74 { 75 return virtualDbName; 76 } 77 78 81 public void login(String [] params) throws ConsoleException 82 { 83 quit = false; 85 String vdbName = params[0]; 86 console.getConsoleReader().addCompletor(this.getCompletor()); 87 console.getConsoleReader().removeCompletor( 88 console.getControllerModule().getCompletor()); 89 90 if (vdbName == null || vdbName.trim().equals("")) 91 { 92 vdbName = console.readLine(ConsoleTranslate.get("admin.login.dbname")); 93 if (vdbName == null) 94 return; 95 } 96 97 login = console.readLine(ConsoleTranslate.get("admin.login.user")); 98 if (login == null) 99 return; 100 101 password = console.readPassword(ConsoleTranslate 102 .get("admin.login.password")); 103 if (password == null) 104 return; 105 106 try 107 { 108 ControllerMBean mbean = console.getJmxClient().getControllerProxy(); 109 if (!mbean.getVirtualDatabaseNames().contains(vdbName)) 110 { 111 throw new ConsoleException(ConsoleTranslate.get("module.database.invalid", 112 vdbName)); 113 } 114 VirtualDatabaseMBean vdb = console.getJmxClient() 115 .getVirtualDatabaseProxy(vdbName, login, password); 116 if (!vdb.checkAdminAuthentication(login, password)) 117 { 118 throw new ConsoleException(ConsoleTranslate.get("module.database.login.fail", login)); 119 } 120 } catch (ConsoleException e) 121 { 122 quit(); 123 throw e; 124 } 125 catch (Exception e) 126 { 127 quit(); 128 throw new ConsoleException(e); 129 } 130 131 virtualDbName = vdbName; 132 loadCommands(); 134 console.printInfo(ConsoleTranslate.get("admin.login.ready", virtualDbName)); 135 } 136 137 140 public String getDescriptionString() 141 { 142 return "VirtualDatabase Administration"; 143 } 144 145 148 public String getPromptString() 149 { 150 return virtualDbName + "(" + login + ")"; 151 } 152 153 161 private Set expertCommandsSet() 162 { 163 Set expertCmds = new HashSet (); 164 String expertCommandsList = loadCommandsFromProperties("admin.expert"); 165 String [] expertCommands = parseCommands(expertCommandsList); 166 addCommands(expertCommands, expertCmds); 167 return expertCmds; 168 } 169 170 178 private Set debugCommandsSet() 179 { 180 Set debugCmds = new HashSet (); 181 String debugCommandsList = loadCommandsFromProperties("admin.debug"); 182 String [] debugCommands = parseCommands(debugCommandsList); 183 addCommands(debugCommands, debugCmds); 184 return debugCmds; 185 } 186 187 190 public void addExpertCommands() 191 { 192 commands.addAll(expertCommandsSet()); 193 reloadCompletor(); 196 } 197 198 201 public void removeExpertCommands() 202 { 203 commands.removeAll(expertCommandsSet()); 204 reloadCompletor(); 207 } 208 209 212 public void addDebugCommands() 213 { 214 commands.addAll(debugCommandsSet()); 215 reloadCompletor(); 218 } 219 220 223 public void removeDebugCommands() 224 { 225 commands.removeAll(debugCommandsSet()); 226 reloadCompletor(); 229 } 230 231 236 public VirtualDatabaseAdmin(Console console) 237 { 238 super(console); 239 } 240 241 244 protected String getModuleID() 245 { 246 return "admin"; } 248 } | Popular Tags |