You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by bl...@apache.org on 2012/05/30 21:54:50 UTC
svn commit: r1344434 - in
/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell:
ShowCommand.java ShowServerFunction.java ShowVersionFunction.java
SqoopShell.java
Author: blee
Date: Wed May 30 19:54:49 2012
New Revision: 1344434
URL: http://svn.apache.org/viewvc?rev=1344434&view=rev
Log:
SQOOP-365 Show server/version commands
Added:
sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java (with props)
sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java (with props)
sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java (with props)
Modified:
sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java?rev=1344434&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java Wed May 30 19:54:49 2012
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import java.util.List;
+
+import org.apache.sqoop.client.core.ClientError;
+import org.apache.sqoop.common.SqoopException;
+import org.codehaus.groovy.tools.shell.Shell;
+
+public class ShowCommand extends SqoopCommand
+{
+ private ShowServerFunction serverFunction;
+ private ShowVersionFunction versionFunction;
+ private ShowConnectorFunction connectorFunction;
+
+ protected ShowCommand(Shell shell) {
+ super(shell, "show", "\\sh",
+ new String[] {"server", "version", "connector", "connection", "job"},
+ "Show", "info");
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Override
+ public Object execute(List args) {
+ if (args.size() == 0) {
+ shell.getIo().out.println("Usage: show " + getUsage());
+ io.out.println();
+ return null;
+ }
+
+ String func = (String)args.get(0);
+ if (func.equals("server")) {
+ if (serverFunction == null) {
+ serverFunction = new ShowServerFunction(io);
+ }
+ return serverFunction.execute(args);
+
+ } else if (func.equals("version")) {
+ if (versionFunction == null) {
+ versionFunction = new ShowVersionFunction(io);
+ }
+ return versionFunction.execute(args);
+
+ } else if (func.equals("connector")) {
+ return null;
+
+ } else if (func.equals("connection")) {
+ return null;
+
+ } else if (func.equals("job")) {
+ return null;
+
+ } else {
+ String msg = "Usage: show " + getUsage();
+ throw new SqoopException(ClientError.CLIENT_0002, msg);
+ }
+ }
+}
\ No newline at end of file
Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowCommand.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java?rev=1344434&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java Wed May 30 19:54:49 2012
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import java.io.PrintWriter;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.client.core.Environment;
+import org.codehaus.groovy.tools.shell.IO;
+
+@SuppressWarnings("serial")
+public class ShowServerFunction extends SqoopFunction
+{
+ public static final String ALL = "all";
+ public static final String HOST = "host";
+ public static final String PORT = "port";
+ public static final String WEBAPP = "webapp";
+
+ private IO io;
+
+ @SuppressWarnings("static-access")
+ protected ShowServerFunction(IO io) {
+ this.io = io;
+
+ this.addOption(OptionBuilder
+ .withDescription("Display all information")
+ .withLongOpt(ALL)
+ .create(ALL.charAt(0)));
+ this.addOption(OptionBuilder
+ .withDescription("Display server host name")
+ .withLongOpt(HOST)
+ .create(HOST.charAt(0)));
+ this.addOption(OptionBuilder
+ .withDescription("Display server port number")
+ .withLongOpt(PORT)
+ .create(PORT.charAt(0)));
+ this.addOption(OptionBuilder
+ .withDescription("Display server web app name")
+ .withLongOpt(WEBAPP)
+ .create(WEBAPP.charAt(0)));
+ }
+
+ public void printHelp(PrintWriter out) {
+ out.println("Usage: show server");
+ super.printHelp(out);
+ }
+
+ public Object execute(List<String> args) {
+ if (args.size() == 1) {
+ printHelp(io.out);
+ io.out.println();
+ return null;
+ }
+
+ CommandLine line = parseOptions(this, 1, args);
+ if (line.hasOption(ALL)) {
+ showServer(true, true, true, true);
+
+ } else {
+ boolean host = false, port = false, webapp = false, version = false;
+ if (line.hasOption(HOST)) {
+ host = true;
+ }
+ if (line.hasOption(PORT)) {
+ port = true;
+ }
+ if (line.hasOption(WEBAPP)) {
+ webapp = true;
+ }
+
+ showServer(host, port, webapp, version);
+ }
+
+ return null;
+ }
+
+ private void showServer(boolean host, boolean port, boolean webapp,
+ boolean version) {
+ if (host) {
+ io.out.print("@|bold Server host:|@ ");
+ io.out.println(Environment.getServerHost());
+ }
+
+ if (port) {
+ io.out.print("@|bold Server port:|@ ");
+ io.out.println(Environment.getServerPort());
+ }
+
+ if (webapp) {
+ io.out.print("@|bold Server webapp:|@ ");
+ io.out.println(Environment.getServerWebapp());
+ }
+
+ io.out.println();
+ }
+}
\ No newline at end of file
Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowServerFunction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java?rev=1344434&view=auto
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java (added)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java Wed May 30 19:54:49 2012
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.client.shell;
+
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.client.core.Environment;
+import org.apache.sqoop.client.request.VersionRequest;
+import org.apache.sqoop.common.VersionInfo;
+import org.apache.sqoop.json.VersionBean;
+import org.codehaus.groovy.tools.shell.IO;
+
+@SuppressWarnings("serial")
+public class ShowVersionFunction extends SqoopFunction
+{
+ public static final String ALL = "all";
+ public static final String SERVER = "server";
+ public static final String CLIENT = "client";
+ public static final String PROTOCOL = "protocol";
+
+ private IO io;
+ private VersionRequest versionRequest;
+
+ @SuppressWarnings("static-access")
+ protected ShowVersionFunction(IO io) {
+ this.io = io;
+
+ this.addOption(OptionBuilder
+ .withDescription("Display all versions")
+ .withLongOpt(ALL)
+ .create(ALL.charAt(0)));
+ this.addOption(OptionBuilder
+ .withDescription("Display server version")
+ .withLongOpt(SERVER)
+ .create(SERVER.charAt(0)));
+ this.addOption(OptionBuilder
+ .withDescription("Display client version")
+ .withLongOpt(CLIENT)
+ .create(CLIENT.charAt(0)));
+ this.addOption(OptionBuilder
+ .withDescription("Display protocol version")
+ .withLongOpt(PROTOCOL)
+ .create(PROTOCOL.charAt(0)));
+ }
+
+ public void printHelp(PrintWriter out) {
+ out.println("Usage: show version");
+ super.printHelp(out);
+ }
+
+ public Object execute(List<String> args) {
+ if (args.size() == 1) {
+ printHelp(io.out);
+ io.out.println();
+ return null;
+ }
+
+ CommandLine line = parseOptions(this, 1, args);
+ if (line.hasOption(ALL)) {
+ showVersion(true, true, true);
+
+ } else {
+ boolean server = false, client = false, protocol = false;
+ if (line.hasOption(SERVER)) {
+ server = true;
+ }
+ if (line.hasOption(CLIENT)) {
+ client = true;
+ }
+ if (line.hasOption(PROTOCOL)) {
+ protocol = true;
+ }
+
+ showVersion(server, client, protocol);
+ }
+
+ return null;
+ }
+
+ private void showVersion(boolean server, boolean client, boolean protocol) {
+ if (versionRequest == null) {
+ versionRequest = new VersionRequest();
+ }
+ VersionBean versionBean =
+ versionRequest.version(Environment.getServerUrl());
+
+ if (server) {
+ io.out.println("@|bold Server version:|@");
+ io.out.print(" Sqoop ");
+ io.out.print(versionBean.getVersion());
+ io.out.print(" revision ");
+ io.out.println(versionBean.getRevision());
+ io.out.print(" Compiled by ");
+ io.out.print(versionBean.getUser());
+ io.out.print(" on ");
+ io.out.println(versionBean.getDate());
+ }
+
+ if (client) {
+ io.out.println("@|bold Client version:|@");
+ io.out.print(" Sqoop ");
+ io.out.print(VersionInfo.getVersion());
+ io.out.print(" revision ");
+ io.out.println(VersionInfo.getRevision());
+ io.out.print(" Compiled by ");
+ io.out.print(VersionInfo.getUser());
+ io.out.print(" on ");
+ io.out.println(VersionInfo.getDate());
+ }
+
+ if (protocol) {
+ io.out.println("@|bold Protocol version:|@");
+ io.out.print(" ");
+ io.out.println(Arrays.toString(versionBean.getProtocols()));
+ }
+
+ io.out.println();
+ }
+}
\ No newline at end of file
Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/ShowVersionFunction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java
URL: http://svn.apache.org/viewvc/sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java?rev=1344434&r1=1344433&r2=1344434&view=diff
==============================================================================
--- sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java (original)
+++ sqoop/branches/sqoop2/client/src/main/java/org/apache/sqoop/client/shell/SqoopShell.java Wed May 30 19:54:49 2012
@@ -59,6 +59,7 @@ public class SqoopShell
shell.register(new HelpCommand(shell));
shell.register(new SetCommand(shell));
+ shell.register(new ShowCommand(shell));
if (args.length == 0) {
// Interactive mode: