001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2005 Emic Networks.
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Emmanuel Cecchet.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.console.text.commands.dbadmin;
021:
022: import java.text.SimpleDateFormat;
023:
024: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
025: import org.continuent.sequoia.common.jmx.management.DumpInfo;
026: import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
027: import org.continuent.sequoia.console.text.formatter.TableFormatter;
028: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
029:
030: /**
031: * This class defines the command used to display available dumps of a given
032: * virtual database.
033: *
034: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
035: * </a>
036: * @version 1.0
037: */
038: public class ViewDumps extends AbstractAdminCommand {
039:
040: /**
041: * Creates a "view dumps" command for the admin module.
042: *
043: * @param module module that owns this commands
044: */
045: public ViewDumps(VirtualDatabaseAdmin module) {
046: super (module);
047: }
048:
049: /**
050: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
051: */
052: public void parse(String commandText) throws Exception {
053: VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(
054: dbName, user, password);
055: DumpInfo[] dumps = vdjc.getAvailableDumps();
056: if (dumps.length == 0) {
057: console.printError(ConsoleTranslate
058: .get("admin.command.view.dumps.nodump")); //$NON-NLS-1$
059: } else {
060: String formattedDumps = TableFormatter.format(
061: getDumpsDescriptions(), getDumpsAsStrings(dumps),
062: true); // FIXME should display dumps
063: // headers in colums
064: console.println(formattedDumps);
065: }
066: }
067:
068: /**
069: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
070: */
071: public String getCommandName() {
072: return "show dumps"; //$NON-NLS-1$
073: }
074:
075: /**
076: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
077: */
078: public String getCommandDescription() {
079: return ConsoleTranslate
080: .get("admin.command.view.dumps.description"); //$NON-NLS-1$
081: }
082:
083: private static String[][] getDumpsAsStrings(DumpInfo[] dumps) {
084: SimpleDateFormat sdf = new SimpleDateFormat();
085: String[][] dumpStr = new String[dumps.length][7];
086: for (int i = 0; i < dumpStr.length; i++) {
087: DumpInfo dump = dumps[i];
088: dumpStr[i][0] = dump.getDumpName();
089: dumpStr[i][1] = dump.getCheckpointName();
090: dumpStr[i][2] = dump.getDumpFormat();
091: dumpStr[i][3] = dump.getDumpPath();
092: dumpStr[i][4] = sdf.format(dump.getDumpDate());
093: dumpStr[i][5] = dump.getBackendName();
094: dumpStr[i][6] = dump.getTables();
095: }
096: return dumpStr;
097: }
098:
099: private static String[] getDumpsDescriptions() {
100: String[] desc = new String[7];
101: desc[0] = ConsoleTranslate
102: .get("admin.command.view.dumps.prop.name"); //$NON-NLS-1$
103: desc[1] = ConsoleTranslate
104: .get("admin.command.view.dumps.prop.checkpoint"); //$NON-NLS-1$
105: desc[2] = ConsoleTranslate
106: .get("admin.command.view.dumps.prop.format"); //$NON-NLS-1$
107: desc[3] = ConsoleTranslate
108: .get("admin.command.view.dumps.prop.path"); //$NON-NLS-1$
109: desc[4] = ConsoleTranslate
110: .get("admin.command.view.dumps.prop.date"); //$NON-NLS-1$
111: desc[5] = ConsoleTranslate
112: .get("admin.command.view.dumps.prop.backend"); //$NON-NLS-1$
113: desc[6] = ConsoleTranslate
114: .get("admin.command.view.dumps.prop.tables"); //$NON-NLS-1$
115: return desc;
116: }
117: }
|