00001
00025 package org.objectweb.cjdbc.console.gui;
00026
00027
import java.awt.BorderLayout;
00028
import java.awt.Color;
00029
import java.awt.Container;
00030
import java.awt.Cursor;
00031
import java.awt.FlowLayout;
00032
import java.awt.GridLayout;
00033
import java.awt.dnd.DnDConstants;
00034
import java.awt.dnd.DropTarget;
00035
import java.io.BufferedReader;
00036
import java.io.BufferedWriter;
00037
import java.io.File;
00038
import java.io.FileReader;
00039
import java.io.FileWriter;
00040
import java.io.IOException;
00041
import java.io.PrintWriter;
00042
import java.io.StringReader;
00043
import java.util.ArrayList;
00044
import java.util.Enumeration;
00045
import java.util.HashMap;
00046
import java.util.Hashtable;
00047
00048
import javax.management.MBeanException;
00049
import javax.swing.BorderFactory;
00050
import javax.swing.JButton;
00051
import javax.swing.JFileChooser;
00052
import javax.swing.JFrame;
00053
import javax.swing.JPanel;
00054
import javax.swing.JScrollPane;
00055
import javax.swing.JTabbedPane;
00056
import javax.swing.JTextArea;
00057
import javax.swing.JTextField;
00058
import javax.swing.JTextPane;
00059
import javax.swing.JToolTip;
00060
import javax.swing.filechooser.FileFilter;
00061
00062
import org.objectweb.cjdbc.common.exceptions.CJDBCException;
00063
import org.objectweb.cjdbc.common.i18n.GuiTranslate;
00064
import org.objectweb.cjdbc.common.jmx.JmxException;
00065
import org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean;
00066
import org.objectweb.cjdbc.common.jmx.mbeans.DataCollectorMBean;
00067
import org.objectweb.cjdbc.common.jmx.mbeans.DatabaseBackendMBean;
00068
import org.objectweb.cjdbc.common.jmx.mbeans.VirtualDatabaseMBean;
00069
import org.objectweb.cjdbc.common.jmx.notifications.CjdbcNotificationList;
00070
import org.objectweb.cjdbc.common.shared.BackendInfo;
00071
import org.objectweb.cjdbc.common.util.Constants;
00072
import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00073
import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00074
import org.objectweb.cjdbc.console.gui.dnd.listeners.BackendTransferListener;
00075
import org.objectweb.cjdbc.console.gui.dnd.listeners.ControllerTransferListener;
00076
import org.objectweb.cjdbc.console.gui.frames.GuiExceptionFrame;
00077
import org.objectweb.cjdbc.console.gui.frames.GuiNewControllerFrame;
00078
import org.objectweb.cjdbc.console.gui.frames.GuiSelectCheckpoint;
00079
import org.objectweb.cjdbc.console.gui.frames.GuiSelectShutdown;
00080
import org.objectweb.cjdbc.console.gui.frames.GuiVirtualDatabaseLoginFrame;
00081
import org.objectweb.cjdbc.console.gui.frames.NewBackendFrame;
00082
import org.objectweb.cjdbc.console.gui.jtools.JMultiLineToolTip;
00083
import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter;
00084
import org.objectweb.cjdbc.console.gui.objects.BackendObject;
00085
import org.objectweb.cjdbc.console.gui.objects.ConfigurationFileObject;
00086
import org.objectweb.cjdbc.console.gui.objects.ControllerObject;
00087
import org.objectweb.cjdbc.console.gui.objects.DatabaseObject;
00088
import org.objectweb.cjdbc.console.gui.objects.DumpFileObject;
00089
import org.objectweb.cjdbc.console.gui.objects.tooltips.BackendToolTip;
00090
import org.objectweb.cjdbc.console.gui.popups.ConfigurationFilePopUpMenu;
00091
import org.objectweb.cjdbc.console.gui.popups.ControllerListPopUpMenu;
00092
import org.objectweb.cjdbc.console.gui.popups.ControllerPopUpMenu;
00093
import org.objectweb.cjdbc.console.gui.popups.DatabasePopUpMenu;
00094
import org.objectweb.cjdbc.console.gui.popups.DumpPopUpMenu;
00095
import org.objectweb.cjdbc.console.gui.popups.LogEditPopUpMenu;
00096
import org.objectweb.cjdbc.console.gui.session.GuiSession;
00097
import org.objectweb.cjdbc.console.gui.threads.GuiLoggingThread;
00098
import org.objectweb.cjdbc.console.gui.threads.GuiParsingThread;
00099
import org.objectweb.cjdbc.console.gui.threads.task.BackupBackendTask;
00100
import org.objectweb.cjdbc.console.gui.threads.task.RestoreBackendTask;
00101
import org.objectweb.cjdbc.console.jmx.ControllerJmxClient;
00102
import org.objectweb.cjdbc.console.jmx.RmiJmxClient;
00103
import org.objectweb.cjdbc.console.monitoring.MonitoringConsole;
00104
import org.objectweb.cjdbc.console.views.CacheStatsViewer;
00105
import org.objectweb.cjdbc.console.views.CacheViewer;
00106
import org.objectweb.cjdbc.console.views.RecoveryLogViewer;
00107
import org.objectweb.cjdbc.console.views.SQLStatViewer;
00108
00115 public class CjdbcGui extends JFrame
00116 {
00118
00120
00121 GuiSession
guiSession;
00123 Hashtable
databaseMBeans;
00125 Hashtable
controllerMBeans;
00127 Hashtable
backendsState;
00129 Hashtable
backendList;
00131 Hashtable
databaseList;
00133 Hashtable
controllerList;
00134
00136 Hashtable
jmxClients;
00137 RmiJmxClient
currentJmxClient;
00138 String
selectedController;
00139 String
selectedDatabase;
00140
00141 Object
credentials = null;
00142
00144
00146
00147 Thread
logginThread;
00148
00150
00152
00153 JPanel
vdbListPanel;
00155 JPanel
fileListPanel;
00157 JPanel
controllerListPanel;
00158
00160
00162
00163 GuiVirtualDatabaseLoginFrame
loginFrame;
00165 GuiNewControllerFrame
newControllerFrame;
00167 GuiExceptionFrame
exceptionFrame;
00169 NewBackendFrame
newBackendFrame;
00171 GuiSelectCheckpoint
selectCheckpointFrame;
00173 GuiSelectShutdown
selectShutdownFrame;
00174
00176
00178
00179 BackendTransferListener
backendTransferListener;
00181 ControllerTransferListener
configurationFileTransferListener;
00182
00184 CjdbcGuiListener guiActionListener;
00185
00187
00189
00191 String
debugText,
loggingText;
00193 JTextArea
debugTextPane,
loggingTextPane;
00195 JTextPane
infoTextPane;
00197 GuiParsingThread
parsingThread;
00199 JTextPane
xmlTextPane;
00201 JFileChooser
configurationFileChooser;
00203 JFileChooser
jarFileChooser;
00205 JFileChooser
saveFileChooser;
00207 JPanel
backendPanel;
00209 ControllerListPopUpMenu
controllerListPopUpMenu;
00211 JTabbedPane
centerPane;
00213 JScrollPane
helpScroll,
debugScroll,
xmlScroll,
00214
loggingScroll,
infoScroll,
logConfigScroll;
00216 JScrollPane
fileScroll;
00218 JTextArea
debugTraceTextPane;
00220 JTextAreaWriter
traceWriter;
00222 JTextPane
logConfigTextPane;
00224 JPanel
backendButtons,
backendIcons;
00225
00229 public CjdbcGui()
00230 {
00231 super(
GuiTranslate.get(
"gui.name"));
00232
new Thread(
new CjdbcGuiLoader(
this)).start();
00233 }
00234
00235 private ControllerMBean actionGETControllerBean(String controllerName)
00236 {
00237
if (
controllerMBeans.containsKey(controllerName))
00238 {
00239
currentJmxClient = (RmiJmxClient)
jmxClients.get(controllerName);
00240
if (
currentJmxClient.isValidConnection())
00241 {
00242
ControllerMBean controllerMBean = (
ControllerMBean)
controllerMBeans
00243 .get(controllerName);
00244
return controllerMBean;
00245 }
00246
else
00247 {
00248
appendDebugText(
"Controller :" + controllerName
00249 +
" cannot be accessed anymore. Trying to reconnect...");
00250
controllerMBeans.remove(controllerName);
00251
return actionGETControllerBean(controllerName);
00252 }
00253 }
00254
else
00255 {
00256
try
00257 {
00258 RmiJmxClient jmxClient =
new RmiJmxClient(controllerName,
credentials);
00259
appendDebugText(
"Setting listener for controller:" + controllerName);
00260 jmxClient.setNotificationListener(
guiActionListener);
00261
jmxClients.put(controllerName, jmxClient);
00262
controllerMBeans.put(controllerName, jmxClient.getControllerProxy());
00263
if (
selectedController == null
00264 || controllerName.equalsIgnoreCase(
selectedController))
00265
currentJmxClient = jmxClient;
00266
00267
appendDebugText(
"Connected to: " + controllerName);
00268
actionStartControllerLoggingThread(controllerName);
00269
00270
return jmxClient.getControllerProxy();
00271 }
00272
catch (Exception e)
00273 {
00274
appendDebugText(
"Failed to connect to: " + controllerName);
00275
return null;
00276 }
00277 }
00278 }
00279
00280 private void actionStartControllerLoggingThread(String controllerName)
00281 {
00282
try
00283 {
00284
ControllerJmxClient controllerMBean = (
ControllerJmxClient)
controllerMBeans
00285 .get(controllerName);
00286
logginThread =
new Thread(
new GuiLoggingThread(
loggingTextPane,
00287 controllerMBean.
getRemoteHostName()));
00288
logginThread.start();
00289
appendDebugText(
"Log4j logging thread started for: <" + controllerName
00290 +
">");
00291 }
00292
catch (Exception e1)
00293 {
00294
appendDebugText(
"Could not start log4j logging thread to: <"
00295 + controllerName +
">");
00296 }
00297 }
00298
00299 private VirtualDatabaseMBean actionGETDatabaseBean(String databaseName)
00300 {
00301
if (
databaseMBeans.containsKey(databaseName))
00302 {
00303
return (
VirtualDatabaseMBean)
databaseMBeans.get(databaseName);
00304 }
00305
else
00306 {
00307
appendDebugText(
"Login to database:" + databaseName);
00308
DatabaseObject dob = (
DatabaseObject)
databaseList.get(databaseName);
00309
loginFrame =
new GuiVirtualDatabaseLoginFrame(
this,
guiActionListener,
00310 databaseName, dob.
getIpAdress(), dob.
getPort(),
guiSession);
00311
loginFrame.setVisible(
true);
00312
return null;
00313 }
00314 }
00315
00316 private void actionLoadDatabaseList(String controllerName)
00317 {
00319
00321
ControllerMBean controllerMBean =
actionGETControllerBean(controllerName);
00322 ArrayList databases;
00323
try
00324 {
00325
vdbListPanel.removeAll();
00326 databases = controllerMBean.
listVirtualDatabases();
00327
int size = databases.size();
00328
appendDebugText(
"Loading virtual databases list...");
00329
for (
int i = 0; i < size; i++)
00330
actionLoadDatabase((String) databases.get(i), controllerName);
00331 }
00332
catch (Exception e1)
00333 {
00334
appendDebugText(
"Cannot load virtual database list");
00335
vdbListPanel.removeAll();
00336 }
00337
paintDatabasePanel();
00338 repaint();
00339 }
00340
00341 void actionUnloadBackends(String controller)
00342 {
00343
appendDebugText(
"Unloading backends from controller:" + controller);
00344 Enumeration enume;
00345
BackendObject bo;
00346 String name;
00347
while ((enume =
backendList.keys()).hasMoreElements())
00348 {
00349 name = (String) enume.nextElement();
00350 bo = (
BackendObject)
backendList.get(name);
00351 bo.setVisible(
false);
00352
backendList.remove(name);
00353 }
00354 }
00355
00356 void paintDatabasePanel()
00357 {
00358
vdbListPanel.validate();
00359
vdbListPanel.repaint();
00360 validate();
00361 repaint();
00362 }
00363
00364 private void actionLoadDatabase(String databaseName, String controllerName)
00365 {
00367
00369
boolean isDistributed =
false;
00370 isDistributed =
actionGETControllerBean(controllerName)
00371 .
isDistributedVirtualDatabase(databaseName);
00372
DatabaseObject dob =
new DatabaseObject(databaseName, controllerName,
00373 isDistributed);
00374 dob.setActionCommand(
GuiCommands.COMMAND_SELECT_DATABASE);
00375 dob.addActionListener(
guiActionListener);
00376 dob.addMouseListener(
new DatabasePopUpMenu(
this, dob));
00377
databaseList.put(databaseName, dob);
00378
actionAddObjectToGridLayout(
vdbListPanel, dob);
00379
appendDebugText(
"Loaded:" + databaseName +
" for controller:"
00380 + controllerName);
00381 }
00382
00383 private void actionAddObjectToGridLayout(JPanel panel, JButton button)
00384 {
00385 GridLayout layout = (GridLayout) panel.getLayout();
00386
int pcount = panel.getComponentCount();
00387 layout.setRows(pcount + 1);
00388 panel.add(button);
00389 panel.validate();
00390 panel.repaint();
00391 }
00392
00398 public void publicActionLoadBackendsList(String databaseName)
00399 {
00400
try
00401 {
00402
VirtualDatabaseMBean databaseMBean =
actionGETDatabaseBean(databaseName);
00403
00404 ArrayList backends = databaseMBean.
viewAllBackendNames();
00405
appendDebugText(
"Local Backend list for controller("
00406 +
currentJmxClient.getRemoteName() +
") is:" + backends);
00407
for (
int i = 0; i < backends.size(); i++)
00408
actionLoadBackend(databaseName, (String) backends.get(i),
00409
currentJmxClient.getRemoteName(),
true);
00410
00411
if (databaseMBean.
isDistributed())
00412 {
00413 databaseMBean =
actionGETDatabaseBean(databaseName);
00414 Hashtable map;
00415
try
00416 {
00417 map = databaseMBean.
viewGroupBackends();
00418 Enumeration enumeration = map.keys();
00419
while (enumeration.hasMoreElements())
00420 {
00421 String controllerName = (String) enumeration.nextElement();
00422 ArrayList list = (ArrayList) map.get(controllerName);
00423
for (
int i = 0; i < list.size(); i++)
00424 {
00425
BackendInfo info = (
BackendInfo) list.get(i);
00426 String backendName = info.
getName();
00427
actionLoadBackend(databaseName, backendName, controllerName,
00428
false);
00429 }
00430 }
00431 }
00432
catch (RuntimeException e1)
00433 {
00434
appendDebugText(
00435
"Runtime exception while loading distributed database:"
00436 + databaseName, e1);
00437 }
00438
00439 }
00440
paintBackendPane();
00441 }
00442
catch (Exception e)
00443 {
00444
appendDebugText(
"Could not retrieve backend list for database"
00445 + databaseName, e);
00446 }
00447 }
00448
00457 public void actionLoadBackend(String database, String backendName,
00458 String controllerName,
boolean enable)
00459 {
00460
BackendObject backend = null;
00461
if (!
backendList.containsKey(backendName))
00462 {
00463
appendDebugText(
"Loading backend:" + backendName +
" from controller:"
00464 + controllerName);
00465
try
00466 {
00467 backend =
new BackendObject(
this,
backendTransferListener, database,
00468 backendName, controllerName)
00469 {
00470
public JToolTip createToolTip()
00471 {
00472
return new JMultiLineToolTip();
00473 }
00474 };
00475 }
00476
catch (Exception e)
00477 {
00478 e.printStackTrace();
00479 }
00480 backend.setBorder(BorderFactory.createTitledBorder(
00481
GuiConstants.LOWERED_BORDER, controllerName));
00482 backend.
setControllerName(controllerName);
00483
backendList.put(backendName, backend);
00484 }
00485
else
00486 {
00487 backend = (
BackendObject)
backendList.get(backendName);
00488 backend.setBorder(BorderFactory.createTitledBorder(
00489
GuiConstants.LOWERED_BORDER, controllerName));
00490 backend.
setControllerName(controllerName);
00491 backend.setEnabled(controllerName.equals(
selectedController));
00492
appendDebugText(
"ReLoading backend:" + backendName);
00493 }
00494
00495
try
00496 {
00497
actionSetBackendState(backendName);
00498 }
00499
catch (RuntimeException e)
00500 {
00501
appendDebugText(
"cannot access mbean anymore");
00502
publicActionRemoveBackendFromGui(backendName);
00503 }
00504 }
00505
00512 private String
actionConvertState(String fromJmx)
00513 {
00514
if (fromJmx == null)
00515
return null;
00516
00517 System.out.println(fromJmx);
00518
00519
if (fromJmx
00520 .equalsIgnoreCase(
CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED))
00521
return GuiConstants.BACKEND_STATE_ENABLED;
00522
else if (fromJmx
00523 .equalsIgnoreCase(
CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED_WRITE))
00524
return GuiConstants.BACKEND_STATE_ENABLED;
00525
else if (fromJmx
00526 .equalsIgnoreCase(
CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLED))
00527
return GuiConstants.BACKEND_STATE_DISABLED;
00528
else if (fromJmx
00529 .equalsIgnoreCase(
CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLING))
00530
return GuiConstants.BACKEND_STATE_DISABLED;
00531
else if (fromJmx
00532 .equalsIgnoreCase(
CjdbcNotificationList.VIRTUALDATABASE_BACKEND_BACKINGUP))
00533
return GuiConstants.BACKEND_STATE_BACKUP;
00534
else if (fromJmx
00535 .equalsIgnoreCase(
CjdbcNotificationList.VIRTUALDATABASE_BACKEND_RECOVERING))
00536
return GuiConstants.BACKEND_STATE_RECOVERY;
00537
else
00538
return null;
00539 }
00540
00551 public void actionChangeBackendState(
BackendObject bo, String newState)
00552 {
00553
00554
if (!
GuiConstants.isValidBackendState(newState))
00555
return;
00556
00557
00558
00559
00560 String oldState = bo.
getState();
00561 JPanel oldpanel = (JPanel)
backendsState.get(oldState);
00562 oldpanel.remove(bo);
00563 oldpanel.validate();
00564 oldpanel.repaint();
00565
00566
00567 bo.
setState(newState);
00568
00569
00570 JPanel panel = (JPanel)
backendsState.get(newState);
00571 panel.add(bo);
00572 panel.validate();
00573 panel.repaint();
00574 }
00575
00582 public void actionSetBackendState(String backendName)
00583 {
00584
try
00585 {
00586
BackendObject bo = (
BackendObject)
backendList.get(backendName);
00587 String controllerName = bo.
getControllerName();
00588
if (
selectedController.equals(controllerName))
00589 bo.setEnabled(
true);
00590
else
00591 bo.setEnabled(
false);
00592 String state = bo.
getState();
00593
appendDebugText(
"STATE:" + state);
00594 String login =
guiSession.getAuthenticatedDatabaseLogin(bo.
getDatabase());
00595 String password =
guiSession.getAuthenticatedDatabasePassword(bo
00596 .getDatabase());
00597 RmiJmxClient client = (RmiJmxClient)
jmxClients.get(controllerName);
00598
DatabaseBackendMBean backend = null;
00599
VirtualDatabaseMBean databaseMBean = null;
00600
00601
try
00602 {
00603 backend = client.getDatabaseBackendProxy(bo.
getDatabase(), backendName,
00604 login, password);
00605 databaseMBean = client.getVirtualDatabaseProxy(bo.
getDatabase(), login,
00606 password);
00607 }
00608
catch (Exception e)
00609 {
00610
appendDebugText(
"Could not change state of backend:" + backendName,
00611
new JmxException(
"MBean connection was lost"));
00612 }
00613 String newState =
actionConvertState(backend.
getState());
00614
appendDebugText(
"Setting backend(" + backendName +
"):"
00615 + backend.
getName() +
" to state:" + newState);
00616
00617
if (state == null)
00618 {
00619
00620 }
00621
else
00622 {
00623
00624 JPanel panel = (JPanel)
backendsState.get(state);
00625 panel.remove(bo);
00626 panel.validate();
00627 panel.repaint();
00628 }
00629
00630
00631 JPanel panel = (JPanel)
backendsState.get(newState);
00632 bo.
setState(newState);
00633
00634
00635
try
00636 {
00637 String[] data = databaseMBean.
viewBackendInformation(backendName);
00638 bo.setToolTipText(
new BackendToolTip(data).getFormattedToolTip());
00639 }
00640
catch (Exception e)
00641 {
00642
appendDebugText(
"Tool tip could not be collected for backend:"
00643 + backendName);
00644 }
00645 panel.add(bo);
00646 panel.validate();
00647 panel.repaint();
00648 }
00649
catch (Exception e)
00650 {
00651
appendDebugText(
"Could not change state of backend:" + backendName, e);
00652 }
00653 }
00654
00658 public void paintBackendPane()
00659 {
00661
00663
backendPanel.validate();
00664
backendPanel.repaint();
00665 }
00666
00667 void paintConfigurationPane()
00668 {
00670
00672
fileScroll.setVisible(
true);
00673
fileListPanel.setVisible(
true);
00674
fileScroll.validate();
00675
fileListPanel.validate();
00676
fileScroll.repaint();
00677 }
00678
00679 String
actionLoadXmlText(File filePath)
00680 {
00682
00684
try
00685 {
00686
if (filePath == null || !filePath.exists())
00687 {
00688
return "";
00689 }
00690 StringBuffer buffer =
new StringBuffer();
00691 BufferedReader reader =
new BufferedReader(
new FileReader(filePath));
00692 String line =
"";
00693
while ((line = reader.readLine()) != null)
00694 {
00695 buffer.append(line + System.getProperty(
"line.separator"));
00696 }
00697 reader.close();
00698
return buffer.toString();
00699 }
00700
catch (Exception e)
00701 {
00702
appendDebugText(
"Error while reading from file:" + e.getMessage());
00703
return "";
00704 }
00705 }
00706
00712 public void appendDebugText(String text)
00713 {
00714
debugText += text + System.getProperty(
"line.separator");
00715
debugTextPane.setText(
debugText);
00716 }
00717
00724 public void appendDebugText(String text, Exception e)
00725 {
00726
try
00727 {
00728
if (
GuiConstants.DEBUG_LEVEL <=
GuiConstants.DEBUG_NO_EXCEPTION_WINDOW)
00729 {
00730
if (e instanceof MBeanException)
00731
exceptionFrame.showException(((MBeanException) e)
00732 .getTargetException());
00733
else
00734
exceptionFrame.showException(e);
00735 }
00736
appendDebugText(text +
"[Message:" + e.getMessage() +
"]");
00737
traceWriter.write(
"---- Exception ----\n");
00738 e.printStackTrace(
new PrintWriter(
traceWriter));
00739 traceWriter.flush();
00740 }
00741
catch (IOException e1)
00742 {
00743
00744 }
00745 }
00746
00750 public void publicActionAddXmlFile()
00751 {
00752
if (
configurationFileChooser == null)
00753 {
00754
configurationFileChooser =
new JFileChooser(
".");
00755
configurationFileChooser.setFileFilter(
new FileFilter()
00756 {
00760
public boolean accept(File f)
00761 {
00762
if (f.getAbsolutePath().endsWith(
".xml") || f.isDirectory())
00763
return true;
00764
else
00765
return false;
00766 }
00767
00771
public String getDescription()
00772 {
00773
return "Xml Files";
00774 }
00775 });
00776 }
00777 configurationFileChooser.showOpenDialog(
this);
00778 File selFile = configurationFileChooser.getSelectedFile();
00779
if (selFile != null)
00780 {
00781 appendDebugText(
"Selected new file:" + selFile.getAbsolutePath());
00782 guiSession.addFileToConfigurationFiles(selFile);
00783 ConfigurationFileObject cfo =
new ConfigurationFileObject(
00784 configurationFileTransferListener, selFile);
00785 ConfigurationFilePopUpMenu cfpum =
new ConfigurationFilePopUpMenu(
this,
00786 cfo);
00787 cfo.addActionListener(cfpum);
00788 cfo.addMouseListener(cfpum);
00789 actionAddObjectToGridLayout(fileListPanel, cfo);
00790 paintConfigurationPane();
00791 }
00792 }
00793
00794 void actionLoadXmlList()
00795 {
00796
if (fileListPanel != null)
00797 {
00798 ArrayList vfileItems = guiSession.getConfigurationFiles();
00799
int vsize = vfileItems.size();
00800
ConfigurationFileObject cfo;
00801
for (
int i = 0; i < vsize; i++)
00802 {
00803 cfo =
new ConfigurationFileObject(configurationFileTransferListener,
00804 (File) vfileItems.get(i));
00805
ConfigurationFilePopUpMenu cfpum =
new ConfigurationFilePopUpMenu(
this,
00806 cfo);
00807 cfo.addActionListener(cfpum);
00808 cfo.addMouseListener(cfpum);
00809 fileListPanel.add(cfo);
00810 actionAddObjectToGridLayout(fileListPanel, cfo);
00811 }
00812
00813 }
00814 }
00815
00816 private ArrayList actionLoadCheckpointNames(String databaseName)
00817 {
00818 ArrayList list = actionGETDatabaseBean(databaseName).viewCheckpointNames();
00819
for (
int i = 0; i < list.size(); i++)
00820 appendDebugText(
"Found checkpoint:" + list.get(i) +
" for database:"
00821 + databaseName);
00822
return list;
00823 }
00824
00830 public void publicActionLoadControllerList()
00831 {
00832
if (controllerListPanel != null)
00833 {
00834 controllerListPanel.removeAll();
00835 ArrayList controllerItems = guiSession.getControllerItems();
00836
int size = controllerItems.size();
00837
for (
int i = 0; i < size; i++)
00838 actionLoadController((String) controllerItems.get(i));
00839 paintControllerPane();
00840 }
00841 }
00842
00846 void paintControllerPane()
00847 {
00848 controllerListPanel.validate();
00849 controllerListPanel.repaint();
00850 }
00851
00855 public void publicActionAddControllerView()
00856 {
00857 newControllerFrame.setVisible(
true);
00858 }
00859
00866 public void publicActionDatabaseEnableAll(String databaseName)
00867 {
00868
try
00869 {
00870 actionGETDatabaseBean(databaseName).enableAllBackend();
00871 publicActionLoadBackendsList(databaseName);
00872 centerPane.setSelectedComponent(backendPanel);
00873 appendDebugText(
"Enabled All backends for :" + databaseName
00874 +
" was a success");
00875 }
00876
catch (Exception e)
00877 {
00878 appendDebugText(
"Enabled All backends for :" + databaseName +
" failed",
00879 e);
00880 }
00881 }
00882
00888 public void actionLoadBackendActionButton(String name)
00889 {
00890
00892 appendDebugText(
"Loading backend action panel:" + name);
00893 Color color =
GuiConstants.getBackendBgColor(name);
00894
00895 JPanel paneContent =
new JPanel(
new FlowLayout());
00896 paneContent.setBackground(color);
00897 paneContent.setName(name);
00898 paneContent.setVisible(
true);
00899
00900 JButton paneLabel =
new JButton(name);
00901 paneLabel.setActionCommand(name);
00902 paneLabel.setBackground(color);
00903 paneLabel.setSize(100, 50);
00904 paneLabel.setVisible(
true);
00905
00906 DropTarget target1 =
new DropTarget(paneLabel, DnDConstants.ACTION_MOVE,
00907 backendTransferListener);
00908 target1.setActive(
true);
00909
00910 DropTarget target2 =
new DropTarget(paneContent, DnDConstants.ACTION_MOVE,
00911 backendTransferListener);
00912 target2.setActive(
true);
00913
00914 GridLayout iconLayout = (GridLayout) backendIcons.getLayout();
00915 iconLayout.setColumns(iconLayout.getColumns() + 1);
00916 GridLayout buttonsLayout = (GridLayout) backendButtons.getLayout();
00917 buttonsLayout.setColumns(buttonsLayout.getColumns() + 1);
00918 backendIcons.add(paneContent);
00919 backendButtons.add(paneLabel);
00920
00921 backendsState.put(name, paneContent);
00922 }
00923
00930 public void actionLoadBackendPane(
boolean recoveryEnabled)
00931 {
00933
00935
if (backendPanel == null)
00936 {
00937 backendPanel =
new JPanel(
new BorderLayout());
00938 backendPanel.setEnabled(
true);
00939 backendPanel.setBackground(Color.white);
00940 backendPanel.setVisible(
true);
00941 }
00942
else
00943 {
00944 backendPanel.remove(backendButtons);
00945 backendPanel.remove(backendIcons);
00946 }
00947
00948 backendButtons =
new JPanel(
new GridLayout(1, 0));
00949 backendIcons =
new JPanel(
new GridLayout(1, 0));
00950 backendIcons.setBackground(Color.white);
00951 backendIcons.setVisible(
true);
00952 backendButtons.setVisible(
true);
00953
00954 actionLoadBackendActionButton(
GuiConstants.BACKEND_STATE_ENABLED);
00955
if (recoveryEnabled)
00956 actionLoadBackendActionButton(
GuiConstants.BACKEND_STATE_RECOVERY);
00957 actionLoadBackendActionButton(
GuiConstants.BACKEND_STATE_DISABLED);
00958
if (recoveryEnabled)
00959 actionLoadBackendActionButton(
GuiConstants.BACKEND_STATE_BACKUP);
00960
if (recoveryEnabled)
00961 actionLoadBackendActionButton(
GuiConstants.BACKEND_STATE_RESTORE);
00962 backendPanel.add(backendIcons, BorderLayout.CENTER);
00963 backendPanel.add(backendButtons, BorderLayout.NORTH);
00964
00965 centerPane.validate();
00966 centerPane.repaint();
00967 validate();
00968 repaint();
00969 }
00970
00974 public void publicActionLoadAuthenticatedDatabase()
00975 {
00976 loginFrame.setVisible(
false);
00977
try
00978 {
00979 String databaseName = loginFrame.getDatabaseName();
00980 String login = loginFrame.getLoginBox().getText().trim();
00981 String password = loginFrame.getPasswordBox().getText().trim();
00982
00983
VirtualDatabaseMBean mbean = currentJmxClient.getVirtualDatabaseProxy(
00984 databaseName, login, password);
00985
00986
if (!mbean.
checkAdminAuthentication(login, password))
00987 {
00988
throw new Exception(
"Authentication failed");
00989 }
00990
00991 databaseMBeans.put(databaseName, mbean);
00992 guiSession.addDatabaseToSession(databaseName, login, password);
00993
00994 String[] list = mbean.
viewControllerList();
00995
for (
int i = 0; i < list.length; i++)
00996 {
00997 appendDebugText(
"Found controllerL" + list[i]);
00998
if (!guiSession.checkControllerInSession(list[i]))
00999 {
01000 actionLoadController(list[i]);
01001 RmiJmxClient client = (RmiJmxClient) jmxClients.get(list[i]);
01002
01003 client.getVirtualDatabaseProxy(databaseName, login, password);
01004 paintControllerPane();
01005 }
01006 }
01007
01008
boolean recoveryExist = mbean.
hasRecoveryLog();
01009 appendDebugText(
"RecoveryLog is defined for this database:"
01010 + recoveryExist);
01011 actionLoadBackendPane(recoveryExist);
01012
01013 publicActionLoadBackendsList(databaseName);
01014 actionLoadCheckpointNames(databaseName);
01015 publicActionLoadDumpList(currentJmxClient.getRemoteName());
01016
01017 }
01018
catch (Exception e1)
01019 {
01020 appendDebugText(
"Could not connect to database", e1);
01021 }
01022 }
01023
01027 public void publicActionQuit()
01028 {
01029
try
01030 {
01031 guiSession.saveSessionToFile(
new File(
01032
GuiConstants.CJDBC_DEFAULT_SESSION_FILE));
01033 }
01034
catch (IOException e)
01035 {
01036 System.out.println(
"Could not save session");
01037 }
01038 System.exit(0);
01039 }
01040
01047 public void publicActionLoadDriver(String controllerName)
01048 {
01049
if (jarFileChooser == null)
01050 {
01051 jarFileChooser =
new JFileChooser(
".");
01052 jarFileChooser.setFileFilter(
new FileFilter()
01053 {
01057
public boolean accept(File f)
01058 {
01059
if (f.getAbsolutePath().endsWith(
".jar") || f.isDirectory())
01060
return true;
01061
else
01062
return false;
01063 }
01064
01068
public String getDescription()
01069 {
01070
return "Jar Files";
01071 }
01072 });
01073 }
01074 jarFileChooser.showOpenDialog(
this);
01075 File selFile = jarFileChooser.getSelectedFile();
01076
try
01077 {
01078
if (selFile != null)
01079 {
01080 ControllerMBean controllerMBean = actionGETControllerBean(controllerName);
01081 controllerMBean.addDriver(selFile.getAbsolutePath());
01082 }
01083 }
01084
catch (Exception e)
01085 {
01086 appendDebugText(
"Could not load driver from jar file:"
01087 + selFile.getName());
01088 }
01089 }
01090
01096 public void publicActionRefreshLogs(String controllerName)
01097 {
01098
try
01099 {
01100
ControllerMBean controllerMBean = actionGETControllerBean(controllerName);
01101 loggingTextPane.setText(controllerMBean.
generateLogReport());
01102 appendDebugText(
"Re-Fetched logs for controller:" + controllerName);
01103 }
01104
catch (Exception e)
01105 {
01106 appendDebugText(
"Fail to fetch logs for controller:" + controllerName, e);
01107 }
01108 }
01109
01113 public void publicActionCleanDebugBuffer()
01114 {
01115 debugText =
"";
01116 debugTextPane.setText(
"");
01117 }
01118
01123 public void publicActionSaveConfigurationFile()
01124 {
01125
try
01126 {
01127
if (saveFileChooser == null)
01128 {
01129 saveFileChooser =
new JFileChooser();
01130 saveFileChooser.showSaveDialog(
this);
01131 File selected = saveFileChooser.getSelectedFile();
01132
if (selected != null)
01133 {
01134 BufferedWriter writer =
new BufferedWriter(
new FileWriter(selected));
01135 writer.write(xmlTextPane.getText());
01136 writer.close();
01137 }
01138
else
01139 {
01140 appendDebugText(
"Did not select a file was saving...");
01141 }
01142 }
01143 }
01144
catch (Exception e)
01145 {
01146 appendDebugText(
"Error while writing to file:" + e.getMessage());
01147 }
01148 }
01149
01153 public void publicActionAddController()
01154 {
01155 newControllerFrame.setVisible(
false);
01156 String ipAddress = newControllerFrame.getIpAddressBox().getText().trim();
01157 String port = newControllerFrame.getPortNumber().getText().trim();
01158 appendDebugText(
"Add controller with ip:" + ipAddress +
" amd port:" + port);
01159 String name = ipAddress +
":" + port;
01160
if (guiSession.checkControllerInSession(name))
01161 {
01162 String message =
GuiTranslate.get(
"error.controller.already.in.session");
01163
CJDBCException e =
new CJDBCException(message);
01164 appendDebugText(message, e);
01165 }
01166
else
01167 {
01168 actionLoadController(name);
01169 paintControllerPane();
01170 }
01171 }
01172
01179 private void actionLoadController(String name)
01180 {
01181 guiSession.addControllerToList(name);
01182
ControllerObject co =
new ControllerObject(name);
01183 co.setActionCommand(
GuiCommands.COMMAND_SELECT_CONTROLLER);
01184 co.addActionListener(guiActionListener);
01185 co.addMouseListener(
new ControllerPopUpMenu(
this, co));
01186
ControllerMBean controllerMBean = actionGETControllerBean(name);
01187
if (controllerMBean == null)
01188 {
01189 appendDebugText(
"Cannot load controller:" + name);
01190
return;
01191 }
01192 DropTarget target =
new DropTarget(co, DnDConstants.ACTION_MOVE,
01193 configurationFileTransferListener);
01194 co.setDropTarget(target);
01195 appendDebugText(
"Loading controller:" + controllerMBean.
getJmxName());
01196
if (currentJmxClient.isValidConnection())
01197 {
01198 co.
setState(
GuiConstants.CONTROLLER_STATE_UP);
01199 }
01200
else
01201 {
01202 co.
setState(
GuiConstants.CONTROLLER_STATE_DOWN);
01203 }
01204 actionAddObjectToGridLayout(controllerListPanel, co);
01205 controllerList.put(name, co);
01206 }
01207
01213 public void publicActionSelectNewController(String connectUrl)
01214 {
01215 Enumeration enume = controllerList.keys();
01216 String key =
"";
01217
ControllerObject controller;
01218
while (enume.hasMoreElements())
01219 {
01220 key = (String) enume.nextElement();
01221 controller = (
ControllerObject) controllerList.get(key);
01222
if (key.equalsIgnoreCase(connectUrl))
01223 {
01224 controller.setBorder(
GuiConstants.TITLED_BORDER);
01225 controller.setBorderPainted(
true);
01226 }
01227
else
01228 controller.setBorderPainted(
false);
01229 }
01230 actionGETControllerBean(connectUrl);
01231 selectedController = connectUrl;
01232 actionLoadDatabaseList(connectUrl);
01233 publicActionLoadXmlController(connectUrl);
01234
01235
if (selectedDatabase != null)
01236 publicActionLoadAuthenticatedDatabase();
01237
01238 }
01239
01245 public void publicActionLoadDumpList(String connectUrl)
01246 {
01247
ControllerMBean controllerMBean = actionGETControllerBean(connectUrl);
01248
try
01249 {
01250 File[] dumps = controllerMBean.
listAvailableDumpFiles();
01251 appendDebugText(
"Loaded dumps for controller:" + connectUrl);
01252 JPanel dumpPane = (JPanel) backendsState
01253 .get(
GuiConstants.BACKEND_STATE_RESTORE);
01254 dumpPane.removeAll();
01255
for (
int i = 0; i < dumps.length; i++)
01256 {
01257 appendDebugText(
"Adding dump:" + dumps[i]);
01258
DumpFileObject dfo =
new DumpFileObject(dumps[i])
01259 {
01260
public JToolTip createToolTip()
01261 {
01262
return new JMultiLineToolTip();
01263 }
01264 };
01265 dfo.addMouseListener(
new DumpPopUpMenu(
this, connectUrl, dfo));
01266 DropTarget target =
new DropTarget(dfo, DnDConstants.ACTION_MOVE,
01267 backendTransferListener);
01268 dfo.setDropTarget(target);
01269 dumpPane.add(dfo);
01270 }
01271 paintBackendPane();
01272 }
01273
catch (Exception e)
01274 {
01275 e.printStackTrace();
01276 appendDebugText(
"Failed to load dumps for controller:" + connectUrl
01277 +
" because of:" + e.getMessage());
01278 }
01279 }
01280
01287 public void publicActionLoadXmlController(String connectUrl)
01288 {
01289
try
01290 {
01291
ControllerMBean controllerMBean = actionGETControllerBean(connectUrl);
01292 xmlTextPane.setText(controllerMBean.
viewInfo());
01293 appendDebugText(
"Loaded xml configuration for controller:" + connectUrl);
01294 }
01295
catch (Exception e)
01296 {
01297 appendDebugText(
"Failed to get xml configuration for controller:"
01298 + connectUrl);
01299 }
01300 }
01301
01307 public void publicActionSelectNewDatabase(String value)
01308 {
01309 selectedDatabase = value;
01310
try
01311 {
01312
VirtualDatabaseMBean databaseClient = actionGETDatabaseBean(value);
01313
if (databaseClient != null)
01314 {
01315 databaseClient.
viewControllerList();
01316 publicActionLoadAuthenticatedDatabase();
01317 }
01318 Enumeration enume = databaseList.keys();
01319 String key =
"";
01320
DatabaseObject database;
01321
while (enume.hasMoreElements())
01322 {
01323 key = (String) enume.nextElement();
01324 database = (
DatabaseObject) databaseList.get(key);
01325
if (key.equalsIgnoreCase(value))
01326 {
01327 database.setBorder(
GuiConstants.TITLED_BORDER);
01328 database.setBorderPainted(
true);
01329 }
01330
else
01331 database.setBorderPainted(
false);
01332 }
01333 }
01334
catch (Exception e)
01335 {
01336 appendDebugText(
"Failed to get access to database:" + value, e);
01337 }
01338 }
01339
01345 public void publicActionLoadXmlDatabase(String databaseName)
01346 {
01347
try
01348 {
01349
DatabaseObject dob = (
DatabaseObject) databaseList.get(databaseName);
01350
ControllerMBean controllerMBean = actionGETControllerBean(dob
01351 .getControllerName());
01352 xmlTextPane.setText(controllerMBean.
viewDatabaseXml(databaseName));
01353 appendDebugText(
"Loaded xml configuration for database:" + databaseName);
01354 centerPane.setSelectedComponent(xmlScroll);
01355 }
01356
catch (Exception e)
01357 {
01358 appendDebugText(
"Failed to get xml configuration for database:"
01359 + databaseName, e);
01360 }
01361 }
01362
01369 public void publicActionSelectNewConfigurationFile(String file)
01370 {
01371
try
01372 {
01373 xmlTextPane.setText(actionLoadXmlText(
new File(file)));
01374 appendDebugText(
"Loaded xml configuration for file:" + file);
01375 centerPane.setSelectedComponent(xmlScroll);
01376 }
01377
catch (Exception e)
01378 {
01379 appendDebugText(
"Failed to load xml for file:" + file);
01380 }
01381 }
01382
01389 public void publicActionShutdownDatabase(
DatabaseObject dob,
int shutdownLevel)
01390 {
01391
try
01392 {
01393
ControllerMBean controllerMBean = actionGETControllerBean(dob
01394 .getControllerName());
01395 String databaseName = dob.getName();
01396 controllerMBean.
shutdownDatabase(databaseName, shutdownLevel);
01397 controllerListPanel.remove(dob);
01398 guiSession.getDatabaseItems().remove(databaseName);
01399 actionUnloadBackends(dob.
getControllerName());
01400 actionLoadDatabaseList(dob.
getControllerName());
01401 }
01402
catch (Exception e)
01403 {
01404 appendDebugText(
"Failed to shutdown database", e);
01405 }
01406 }
01407
01414 public void publicActionExecuteBackendDrop(JButton target, String backendName)
01415 {
01416
01417 String actionName = target.getActionCommand();
01418
if (actionName.equals(
GuiConstants.BACKEND_STATE_RESTORE))
01419 publicActionRestoreBackend(backendName, target.getText());
01420
else
01421 publicActionExecuteBackendDrop(actionName, backendName);
01422 }
01423
01424 private String actionDisplaySelectCheckpointFrame(String database)
01425 {
01426
VirtualDatabaseMBean databaseMBean = actionGETDatabaseBean(database);
01427
if (selectCheckpointFrame == null)
01428 {
01429 ArrayList list = databaseMBean.
viewCheckpointNames();
01430 list.add(
GuiConstants.BACKEND_NO_CHECKPOINT);
01431 String[] entries = (String[]) list.toArray(
new String[list.size()]);
01432 selectCheckpointFrame =
new GuiSelectCheckpoint(
this, entries,
01433 guiActionListener);
01434 selectCheckpointFrame.show();
01435 }
01436
01437 JTextField field = selectCheckpointFrame.getValueField();
01438 selectCheckpointFrame = null;
01439
if(field==null)
01440
return null;
01441 String checkpoint = field.getText();
01442
return checkpoint;
01443 }
01444
01451 public void publicActionExecuteBackendDrop(String actionName,
01452 String backendName)
01453 {
01454 appendDebugText(
"Got drop backend action:" + actionName +
" from:"
01455 + backendName);
01456
BackendObject bob = (
BackendObject) backendList.get(backendName);
01457 String database = bob.
getDatabase();
01458
VirtualDatabaseMBean databaseMBean = actionGETDatabaseBean(bob
01459 .getDatabase());
01460
01461
if (actionName.equals(
GuiConstants.BACKEND_STATE_ENABLED))
01462 {
01463
try
01464 {
01465 String checkpoint = actionDisplaySelectCheckpointFrame(database);
01466
if(checkpoint == null)
01467 {
01468 appendDebugText(
"Cancelling enable backend...");
01469
return;
01470 }
01471 appendDebugText(
"Using checkpoint:" + checkpoint
01472 +
" to enable backend:" + backendName);
01473
if (checkpoint.equals(
GuiConstants.BACKEND_NO_CHECKPOINT))
01474 databaseMBean.
enableBackend(backendName);
01475
else
01476 databaseMBean.
enableBackendFromCheckpoint(backendName, checkpoint);
01477 actionSetBackendState(backendName);
01478 }
01479
catch (Exception e)
01480 {
01481 appendDebugText(
"Failed to enable backend", e);
01482 }
01483 }
01484
else if (actionName.equals(
GuiConstants.BACKEND_STATE_DISABLED))
01485 {
01486
try
01487 {
01488 String checkpoint = actionDisplaySelectCheckpointFrame(database);
01489
if(checkpoint == null)
01490 {
01491 appendDebugText(
"Cancelling disable backend...");
01492
return;
01493 }
01494 appendDebugText(
"Using checkpoint:" + checkpoint
01495 +
" to disable backend:" + backendName);
01496
if (checkpoint.equals(
GuiConstants.BACKEND_NO_CHECKPOINT))
01497 databaseMBean.
disableBackend(backendName);
01498
else
01499 databaseMBean.
disableBackendForCheckpoint(backendName, checkpoint);
01500 actionSetBackendState(backendName);
01501 }
01502
catch (Exception e)
01503 {
01504 appendDebugText(
"Failed to disable backend", e);
01505 }
01506 }
01507
else if (actionName.equals(
GuiConstants.BACKEND_STATE_NEW))
01508 {
01509 appendDebugText(
"Creating new backend from backend:" + bob.getName());
01510 publicActionNewBackendPrompt(bob);
01511 }
01512
else if (actionName.equals(
GuiConstants.BACKEND_STATE_BACKUP))
01513 {
01514 publicActionBackupBackendPrompt(bob);
01515 }
01516 }
01517
01523 public void publicActionNewBackendPrompt(
BackendObject bob)
01524 {
01525
if (newBackendFrame == null)
01526 newBackendFrame =
new NewBackendFrame(bob, guiActionListener);
01527
else
01528 newBackendFrame.setBob(bob);
01529 newBackendFrame.setVisible(
true);
01530 }
01531
01538 public void publicActionRestoreBackend(String backendName, String dumpName)
01539 {
01540 appendDebugText(
"Restoring backend:" + backendName +
" with dump name:"
01541 + dumpName);
01542
BackendObject bob = (
BackendObject) backendList.get(backendName);
01543
VirtualDatabaseMBean database = actionGETDatabaseBean(bob.
getDatabase());
01544
new Thread(
new RestoreBackendTask(
this, database, bob, dumpName)).start();
01545 }
01546
01552 public void publicActionBackupBackendPrompt(
BackendObject bob)
01553 {
01554 String checkpoint = actionDisplaySelectCheckpointFrame(bob.
getDatabase());
01555
VirtualDatabaseMBean database = actionGETDatabaseBean(bob.
getDatabase());
01556
new Thread(
new BackupBackendTask(
this, database, bob, checkpoint)).start();
01557 }
01558
01562 public void publicActionRefreshCursorShape()
01563 {
01564 appendDebugText(
"Refresh cursor for main frame");
01565 Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
01566 setCursor(cursor);
01567 backendPanel.setCursor(cursor);
01568 validate();
01569 repaint();
01570 }
01571
01578 public void publicActionExecuteControllerDrop(String filePath,
01579 String controllerName)
01580 {
01581 File file =
new File(filePath);
01582
try
01583 {
01584
ControllerMBean controllerMBean = actionGETControllerBean(controllerName);
01585 controllerMBean.
addVirtualDatabases(actionLoadXmlText(file));
01586 appendDebugText(
"Execute public action on controller drop for:"
01587 + filePath +
" and:" + controllerName);
01588 actionLoadDatabaseList(controllerName);
01589 }
01590
catch (Exception e)
01591 {
01592 appendDebugText(
"Failed to load configuration file :" + file.getName(), e);
01593 }
01594 }
01595
01602 public void publicActionDatabaseDisableAll(String databaseName)
01603 {
01604
try
01605 {
01606 actionGETDatabaseBean(databaseName).disableAllBackend();
01607 publicActionLoadBackendsList(databaseName);
01608 centerPane.setSelectedComponent(backendPanel);
01609 appendDebugText(
"Disable All backends for :" + databaseName
01610 +
" was a success");
01611 }
01612
catch (Exception e)
01613 {
01614 appendDebugText(
"Disable All backends for :" + databaseName +
" failed.",
01615 e);
01616 }
01617 }
01618
01624 public void publicActionGetControllerInfo(String controllerName)
01625 {
01626
try
01627 {
01628
ControllerMBean controllerMBean = actionGETControllerBean(controllerName);
01629 infoTextPane.setText(controllerMBean.
viewInfo());
01630 centerPane.setSelectedComponent(infoScroll);
01631 }
01632
catch (Exception e)
01633 {
01634 appendDebugText(
"Failed to get info for controller:" + controllerName, e);
01635 }
01636 }
01637
01643 public void publicActionShutdownController(String controllerName)
01644 {
01645
try
01646 {
01647
ControllerMBean controllerMBean = actionGETControllerBean(controllerName);
01648 controllerMBean.
shutdown(2);
01649 publicActionLoadControllerList();
01650 }
01651
catch (Exception e)
01652 {
01653 appendDebugText(
"Failed to shutdown the controller:" + controllerName, e);
01654 }
01655 }
01656
01662 public void publicActionControllerReport(String controllerName)
01663 {
01664
try
01665 {
01666
ControllerMBean controllerMBean = actionGETControllerBean(controllerName);
01667 infoTextPane.setText(controllerMBean.
generateReport());
01668 centerPane.setSelectedComponent(infoScroll);
01669 }
01670
catch (Exception e)
01671 {
01672 appendDebugText(
"Failed to get info for controller:" + controllerName, e);
01673 }
01674 }
01675
01682 public void publicActionDeleteDump(String controllerName,
DumpFileObject dump)
01683 {
01684
ControllerMBean controller = actionGETControllerBean(controllerName);
01685
try
01686 {
01687 controller.
removeDumpFile(dump.
getDumpFile());
01688 appendDebugText(
"Removed dump file:" + dump.
getDumpFile().getName()
01689 +
" from controller:" + controllerName);
01690 publicActionLoadDumpList(controllerName);
01691 }
01692
catch (Exception e)
01693 {
01694 appendDebugText(
01695
"Failed to removed dump file:" + dump.
getDumpFile().getName()
01696 +
" from controller:" + controllerName, e);
01697 }
01698 }
01699
01706 public void publicActionExecuteBackendDrop(JPanel panel, String backendName)
01707 {
01708 publicActionExecuteBackendDrop(panel.getName(), backendName);
01709 }
01710
01716 public void publicActionControllerLogConfiguration(String controllerName)
01717 {
01718
try
01719 {
01720
ControllerMBean controllerMBean = actionGETControllerBean(controllerName);
01721 logConfigTextPane.setText(controllerMBean.
viewLogConfigurationFile());
01722 centerPane.setSelectedComponent(logConfigScroll);
01723 logConfigTextPane.addMouseListener(
new LogEditPopUpMenu(
this,
01724 controllerName, logConfigTextPane));
01725 }
01726
catch (Exception e)
01727 {
01728 appendDebugText(
"Failed to get log4j configuration for controller:"
01729 + controllerName, e);
01730 }
01731 }
01732
01740 public void publicActionUpdateControllerLogConfiguration(
01741 String controllerName, String newContent)
01742 {
01743
try
01744 {
01745 appendDebugText(
"Updating log4j configuration for controller:"
01746 + controllerName);
01747
ControllerMBean controllerMBean = actionGETControllerBean(controllerName);
01748 controllerMBean.
updateLogConfigurationFile(newContent);
01749 actionStartControllerLoggingThread(controllerName);
01750 }
01751
catch (Exception e)
01752 {
01753 appendDebugText(
"Failed to update log4j configuration for controller:"
01754 + controllerName, e);
01755 }
01756 }
01757
01765 public void publicActionSetLogConfigurationDebug(String controllerName,
01766 String logConfiguration)
01767 {
01768
try
01769 {
01770 String newContent = actionReplaceInConfiguration(logConfiguration,
01771
"INFO",
"DEBUG");
01772 publicActionUpdateControllerLogConfiguration(controllerName, newContent);
01773 }
01774
catch (Exception e)
01775 {
01776 appendDebugText(
"Setting log configation to debug failed for controller:"
01777 + controllerName, e);
01778 }
01779 }
01780
01781 private String actionReplaceInConfiguration(String logConfiguration,
01782 String oldMode, String newMode)
throws IOException
01783 {
01784 BufferedReader reader =
new BufferedReader(
new StringReader(
01785 logConfiguration));
01786 StringBuffer buffer =
new StringBuffer();
01787 String line;
01788
int index = 0;
01789
while ((line = reader.readLine()) != null)
01790 {
01791
while ((index = line.indexOf(oldMode, index)) != -1)
01792 line = line.substring(0, index) + newMode
01793 + line.substring(index + oldMode.length());
01794 buffer.append(line + System.getProperty(
"line.separator"));
01795 }
01796 logConfigTextPane.setText(buffer.toString());
01797
return buffer.toString();
01798 }
01799
01807 public void publicActionSetLogConfigurationInfo(String controllerName,
01808 String logConfiguration)
01809 {
01810
try
01811 {
01812 String newContent = actionReplaceInConfiguration(logConfiguration,
01813
"DEBUG",
"INFO");
01814 publicActionUpdateControllerLogConfiguration(controllerName, newContent);
01815 }
01816
catch (Exception e)
01817 {
01818 appendDebugText(
"Setting log configation to debug failed for controller:"
01819 + controllerName, e);
01820 }
01821
01822 }
01823
01829 public Hashtable getBackendList()
01830 {
01831
return backendList;
01832 }
01833
01837 public void publicActioncleanLoggingPane()
01838 {
01839 loggingTextPane.setText(
"");
01840 loggingTextPane.validate();
01841 loggingTextPane.repaint();
01842 }
01843
01849 public void publicActionRemoveConfigurationFile(
ConfigurationFileObject cfo)
01850 {
01851 Container container = cfo.getParent();
01852 container.remove(cfo);
01853 System.out.println(guiSession.getConfigurationFiles().remove(
01854
new File(cfo.
getFilePath())));
01855 container.validate();
01856 container.repaint();
01857 }
01858
01864 public void publicActionControllerRemove(String controllerName)
01865 {
01866
ControllerObject co = (
ControllerObject) controllerList
01867 .remove(controllerName);
01868
if (co != null)
01869 {
01870 controllerListPanel.remove(co);
01871 controllerListPanel.validate();
01872 controllerListPanel.repaint();
01873 }
01874 guiSession.getControllerItems().remove(controllerName);
01875 }
01876
01880 public void publicActionControllerMonitor(String controllerName)
01881 {
01882 appendDebugText(
"Creating monitoring console for controller:"
01883 + controllerName);
01884
try
01885 {
01886
new MonitoringConsole(controllerName);
01887 }
01888
catch (Exception e)
01889 {
01890 appendDebugText(
"Loading of monitoring console failed for controller:"
01891 + controllerName, e);
01892 }
01893 }
01894
01898 public void publicActionCreateBackendExecute()
01899 {
01900 newBackendFrame.setVisible(
false);
01901
BackendObject bob = newBackendFrame.getBob();
01902
VirtualDatabaseMBean database = actionGETDatabaseBean(bob.
getDatabase());
01903 String oldname = bob.getName();
01904 String newname = newBackendFrame.getNewName().getText();
01905 String url = newBackendFrame.getNewUrl().getText();
01906 HashMap map =
new HashMap();
01907 map.put(
"url", url);
01908
try
01909 {
01910 database.
replicateBackend(oldname, newname, map);
01911 }
01912
catch (Exception e)
01913 {
01914 appendDebugText(
"Failed to create new backend:" + newname, e);
01915 }
01916 }
01917
01923 public void publicActionViewCache(String databaseName)
01924 {
01925
try
01926 {
01927
DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy();
01928
CacheViewer viewer =
new CacheViewer(collector
01929 .retrieveCacheData(databaseName));
01930 viewer.
display();
01931 }
01932
catch (Exception e)
01933 {
01934 appendDebugText(
"Failed to collect cache data for database:"
01935 + databaseName, e);
01936 }
01937 }
01938
01944 public void publicActionViewSQLStats(String databaseName)
01945 {
01946
try
01947 {
01948
DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy();
01949
SQLStatViewer viewer =
new SQLStatViewer(collector
01950 .retrieveSQLStats(databaseName));
01951 viewer.
display();
01952 }
01953
catch (Exception e)
01954 {
01955 appendDebugText(
01956
"Failed to collect sql data for database:" + databaseName, e);
01957 }
01958
01959 }
01960
01966 public void publicActionViewCacheStats(String databaseName)
01967 {
01968
try
01969 {
01970
DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy();
01971
CacheStatsViewer viewer =
new CacheStatsViewer(collector
01972 .retrieveCacheStatsData(databaseName));
01973 viewer.
display();
01974 }
01975
catch (Exception e)
01976 {
01977 appendDebugText(
"Failed to collect cache stats for database:"
01978 + databaseName, e);
01979 }
01980 }
01981
01987 public CjdbcGuiListener getGuiActionListener()
01988 {
01989
return guiActionListener;
01990 }
01991
01997 public GuiSession getGuiSession()
01998 {
01999
return guiSession;
02000 }
02001
02007 public Hashtable getJmxClients()
02008 {
02009
return jmxClients;
02010 }
02011
02017 public void publicActionRemoveBackendFromGui(String backendName)
02018 {
02019
BackendObject bo = (
BackendObject) backendList.remove(backendName);
02020
if (bo != null)
02021 {
02022 backendIcons.remove(bo);
02023 JPanel panel = (JPanel) backendsState.get(bo.
getState());
02024 panel.remove(bo);
02025 paintBackendPane();
02026 }
02027 }
02028
02034 public void publicActionRemoveBackend(
BackendObject bo)
02035 {
02036 String controllerName = bo.
getControllerName();
02037 String databaseName = bo.
getDatabase();
02038 String backendName = bo.getName();
02039 RmiJmxClient jmxClient = (RmiJmxClient) jmxClients.get(controllerName);
02040 String user = guiSession.getAuthenticatedDatabaseLogin(databaseName);
02041 String password = guiSession.getAuthenticatedDatabasePassword(databaseName);
02042
try
02043 {
02044
VirtualDatabaseMBean mbean = jmxClient.getVirtualDatabaseProxy(
02045 databaseName, user, password);
02046 mbean.
removeBackend(backendName);
02047 publicActionRemoveBackendFromGui(backendName);
02048 }
02049
catch (Exception e)
02050 {
02051 appendDebugText(
"Cannot remove backend:" + backendName, e);
02052 }
02053
02054 }
02055
02062 public void publicActionExecuteTransfer(String backendName,
02063 String controllerName)
02064 {
02065
BackendObject bo = (
BackendObject) backendList.get(backendName);
02066 String controllerNameOrigin = bo.
getControllerName();
02067 RmiJmxClient jmxClient = (RmiJmxClient) jmxClients
02068 .get(controllerNameOrigin);
02069 String databaseName = bo.
getDatabase();
02070 String user = guiSession.getAuthenticatedDatabaseLogin(databaseName);
02071 String password = guiSession.getAuthenticatedDatabasePassword(databaseName);
02072
try
02073 {
02074
VirtualDatabaseMBean mbean = jmxClient.getVirtualDatabaseProxy(
02075 databaseName, user, password);
02076 mbean.
transferBackend(backendName, controllerName);
02077 bo.
setControllerName(controllerName);
02078
02079 }
02080
catch (Exception e)
02081 {
02082 appendDebugText(
"Cannot remove backend:" + backendName, e);
02083 }
02084 }
02085
02093 public void publicActionRemoveBackendFromGui(String backendName,
02094 String controller)
02095 {
02096
BackendObject bo = (
BackendObject) backendList.get(backendName);
02097
if (bo != null)
02098 {
02099 String boController = bo.
getControllerName();
02100
if (boController.equals(controller))
02101 publicActionRemoveBackendFromGui(backendName);
02102
else
02103 {
02104 appendDebugText(
"Call for removing backend:" + backendName
02105 +
" from controller:" + controller
02106 +
" but backend is on controller:" + boController);
02107 }
02108 }
02109
02110 }
02111
02118 public void publicActionDisplayShutdownFrame(
DatabaseObject database)
02119 {
02120
if (selectShutdownFrame == null)
02121 {
02122 selectShutdownFrame =
new GuiSelectShutdown(
this, guiActionListener);
02123 selectShutdownFrame.show();
02124 }
02125 String shutdownLevel = selectShutdownFrame.getValueField().getText();
02126
int iLevel =
Constants.DEFAULT_SHUTDOWN_MODE;
02127
if (shutdownLevel.equals(
GuiCommands.COMMAND_SHUTDOWN_FAST))
02128 iLevel =
Constants.CONTROLLER_SHUTDOWN_FAST;
02129
else if (shutdownLevel.equals(
GuiCommands.COMMAND_SHUTDOWN_IMMEDIATE))
02130 iLevel =
Constants.CONTROLLER_SHUTDOWN_IMMEDIATE;
02131
else if (shutdownLevel.equals(
GuiCommands.COMMAND_SHUTDOWN_SMART))
02132 iLevel =
Constants.CONTROLLER_SHUTDOWN_SMART;
02133 appendDebugText(
"shudown level of database:" + database.getName() +
" is:"
02134 + shutdownLevel);
02135 selectShutdownFrame = null;
02136 publicActionShutdownDatabase(database, iLevel);
02137 }
02138
02144 public void publicActionViewRecoveryLog(String databaseName)
02145 {
02146
try
02147 {
02148
DataCollectorMBean collector = currentJmxClient.getDataCollectorProxy();
02149
RecoveryLogViewer viewer =
new RecoveryLogViewer(collector
02150 .retrieveRecoveryLogData(databaseName));
02151 viewer.
display();
02152 }
02153
catch (Exception e)
02154 {
02155 appendDebugText(
"Failed to collect cache stats for database:"
02156 + databaseName, e);
02157 }
02158 }
02159 }