001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Jeff Mesnil
020: * Contributor(s): ______________________.
021: */package org.continuent.sequoia.console.text.commands.dbadmin;
022:
023: import java.util.StringTokenizer;
024:
025: import org.continuent.sequoia.common.i18n.ConsoleTranslate;
026: import org.continuent.sequoia.common.jmx.mbeans.VirtualDatabaseMBean;
027: import org.continuent.sequoia.console.text.module.VirtualDatabaseAdmin;
028:
029: /**
030: * This class defines a InitializeCluster command.
031: */
032: public class InitializeCluster extends AbstractAdminCommand {
033:
034: /**
035: * Creates a new <code>InitializeCluster.java</code> object
036: *
037: * @param module the commands is attached to
038: */
039: public InitializeCluster(VirtualDatabaseAdmin module) {
040: super (module);
041: }
042:
043: /**
044: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String)
045: */
046: public void parse(String commandText) throws Exception {
047: StringTokenizer tokenizer = new StringTokenizer(commandText
048: .trim());
049:
050: if (tokenizer.countTokens() < 1) {
051: console.printError(getUsage());
052: return;
053: }
054:
055: String backendName = tokenizer.nextToken();
056: boolean force = false;
057:
058: if (tokenizer.hasMoreTokens()) {
059: if (!"force".equals(tokenizer.nextToken())) //$NON-NLS-1$
060: {
061: console.printError(getUsage());
062: return;
063: }
064: force = true;
065: }
066:
067: if ("".equals(backendName)) //$NON-NLS-1$
068: {
069: console.printError(getUsage());
070: return;
071: }
072:
073: VirtualDatabaseMBean db = jmxClient.getVirtualDatabaseProxy(
074: dbName, user, password);
075: db.initializeFromBackend(backendName, force);
076: console
077: .printInfo(ConsoleTranslate
078: .get(
079: "admin.command.initialize.success", new String[] { db.getVirtualDatabaseName(), backendName })); //$NON-NLS-1$
080: }
081:
082: /**
083: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandName()
084: */
085: public String getCommandName() {
086: return "initialize"; //$NON-NLS-1$
087: }
088:
089: /**
090: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandParameters()
091: */
092: public String getCommandParameters() {
093: return ConsoleTranslate.get("admin.command.initialize.params"); //$NON-NLS-1$
094: }
095:
096: /**
097: * @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription()
098: */
099: public String getCommandDescription() {
100: return ConsoleTranslate
101: .get("admin.command.initialize.description"); //$NON-NLS-1$
102: }
103:
104: }
|