mirror of
https://github.com/apache/sqoop.git
synced 2025-05-08 13:21:48 +08:00
SQOOP-576 Implement command show framework
git-svn-id: https://svn.apache.org/repos/asf/sqoop/branches/sqoop2@1377752 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
36807b99b0
commit
c1e44563d5
@ -28,10 +28,11 @@ public class ShowCommand extends SqoopCommand
|
||||
private ShowServerFunction serverFunction;
|
||||
private ShowVersionFunction versionFunction;
|
||||
private ShowConnectorFunction connectorFunction;
|
||||
private ShowFrameworkFunction frameworkFunction;
|
||||
|
||||
protected ShowCommand(Shell shell) {
|
||||
super(shell, "show", "\\sh",
|
||||
new String[] {"server", "version", "connector"},
|
||||
new String[] {"server", "version", "connector", "framework"},
|
||||
"Show", "info");
|
||||
}
|
||||
|
||||
@ -63,6 +64,12 @@ public Object execute(List args) {
|
||||
}
|
||||
return connectorFunction.execute(args);
|
||||
|
||||
} else if (func.equals("framework")) {
|
||||
if (frameworkFunction == null) {
|
||||
frameworkFunction = new ShowFrameworkFunction(io);
|
||||
}
|
||||
return frameworkFunction.execute(args);
|
||||
|
||||
} else if (func.equals("connection")) {
|
||||
return null;
|
||||
|
||||
@ -74,4 +81,4 @@ public Object execute(List args) {
|
||||
throw new SqoopException(ClientError.CLIENT_0002, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
package org.apache.sqoop.client.shell;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
@ -27,13 +26,11 @@
|
||||
import org.apache.sqoop.client.request.ConnectorRequest;
|
||||
import org.apache.sqoop.json.ConnectorBean;
|
||||
import org.apache.sqoop.model.MConnector;
|
||||
import org.apache.sqoop.model.MForm;
|
||||
import org.apache.sqoop.model.MInput;
|
||||
import org.apache.sqoop.model.MInputType;
|
||||
import org.apache.sqoop.model.MJobForms;
|
||||
import org.apache.sqoop.model.MStringInput;
|
||||
import org.codehaus.groovy.tools.shell.IO;
|
||||
|
||||
import static org.apache.sqoop.client.display.FormDisplayer.*;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ShowConnectorFunction extends SqoopFunction
|
||||
{
|
||||
@ -100,57 +97,11 @@ private void showConnector(String cid) {
|
||||
io.out.println(connector.getUniqueName());
|
||||
io.out.print(" Class: ");
|
||||
io.out.println(connector.getClassName());
|
||||
io.out.print(" Supported job types: ");
|
||||
io.out.println(connector.getAllJobsForms().keySet().toString());
|
||||
|
||||
displayForms(connector.getConnectionForms().getForms(), "Connection");
|
||||
displayFormDetails(io, connector);
|
||||
|
||||
for (MJobForms jobForms : connector.getAllJobsForms().values()) {
|
||||
io.out.print(" Forms for jobForms type ");
|
||||
io.out.print(jobForms.getType().name());
|
||||
io.out.println(":");
|
||||
|
||||
displayForms(jobForms.getForms(), "Job");
|
||||
}
|
||||
}
|
||||
|
||||
io.out.println();
|
||||
}
|
||||
|
||||
private void displayForms(List<MForm> forms, String type) {
|
||||
Iterator<MForm> fiter = forms.iterator();
|
||||
int findx = 1;
|
||||
while (fiter.hasNext()) {
|
||||
io.out.print(" ");
|
||||
io.out.print(type);
|
||||
io.out.print(" form ");
|
||||
io.out.print(findx++);
|
||||
io.out.println(":");
|
||||
|
||||
MForm form = fiter.next();
|
||||
io.out.print(" Name: ");
|
||||
io.out.println(form.getName());
|
||||
|
||||
List<MInput<?>> inputs = form.getInputs();
|
||||
Iterator<MInput<?>> iiter = inputs.iterator();
|
||||
int iindx = 1;
|
||||
while (iiter.hasNext()) {
|
||||
io.out.print(" Input ");
|
||||
io.out.print(iindx++);
|
||||
io.out.println(":");
|
||||
|
||||
MInput<?> input = iiter.next();
|
||||
io.out.print(" Name: ");
|
||||
io.out.println(input.getName());
|
||||
io.out.print(" Type: ");
|
||||
io.out.println(input.getType());
|
||||
if (input.getType() == MInputType.STRING) {
|
||||
io.out.print(" Mask: ");
|
||||
io.out.println(((MStringInput)input).isMasked());
|
||||
io.out.print(" Size: ");
|
||||
io.out.println(((MStringInput)input).getMaxLength());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,30 +27,13 @@
|
||||
import org.apache.sqoop.model.MJobForms;
|
||||
import org.apache.sqoop.model.MConnector;
|
||||
import org.apache.sqoop.model.MForm;
|
||||
import org.apache.sqoop.model.MFormType;
|
||||
import org.apache.sqoop.model.MInput;
|
||||
import org.apache.sqoop.model.MInputType;
|
||||
import org.apache.sqoop.model.MMapInput;
|
||||
import org.apache.sqoop.model.MStringInput;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import static org.apache.sqoop.json.util.FormSerialization.*;
|
||||
|
||||
public class ConnectorBean implements JsonBean {
|
||||
|
||||
public static final String ID = "id";
|
||||
public static final String NAME = "name";
|
||||
public static final String CLASS = "class";
|
||||
public static final String CON_FORMS = "con_forms";
|
||||
public static final String JOB_FORMS = "job_forms";
|
||||
|
||||
public static final String FORM_NAME = "name";
|
||||
public static final String FORM_TYPE = "type";
|
||||
public static final String FORM_INPUTS = "inputs";
|
||||
public static final String FORM_INPUT_NAME = "name";
|
||||
public static final String FORM_INPUT_TYPE = "type";
|
||||
public static final String FORM_INPUT_MASK = "mask";
|
||||
public static final String FORM_INPUT_SIZE = "size";
|
||||
|
||||
private MConnector[] connectors;
|
||||
|
||||
// for "extract"
|
||||
@ -98,42 +81,6 @@ public JSONObject extract() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private JSONArray extractForms(List<MForm> mForms) {
|
||||
JSONArray forms = new JSONArray();
|
||||
|
||||
for (MForm mForm : mForms) {
|
||||
forms.add(extractForm(mForm));
|
||||
}
|
||||
|
||||
return forms;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private JSONObject extractForm(MForm mForm) {
|
||||
JSONObject form = new JSONObject();
|
||||
form.put(FORM_NAME, mForm.getName());
|
||||
form.put(FORM_TYPE, MFormType.CONNECTION.toString());
|
||||
JSONArray mInputs = new JSONArray();
|
||||
form.put(FORM_INPUTS, mInputs);
|
||||
|
||||
for (MInput<?> mInput : mForm.getInputs()) {
|
||||
JSONObject input = new JSONObject();
|
||||
mInputs.add(input);
|
||||
|
||||
input.put(FORM_INPUT_NAME, mInput.getName());
|
||||
input.put(FORM_INPUT_TYPE, mInput.getType().toString());
|
||||
if (mInput.getType() == MInputType.STRING) {
|
||||
input.put(FORM_INPUT_MASK,
|
||||
((MStringInput)mInput).isMasked());
|
||||
input.put(FORM_INPUT_SIZE,
|
||||
((MStringInput)mInput).getMaxLength());
|
||||
}
|
||||
}
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void restore(JSONObject jsonObject) {
|
||||
@ -172,43 +119,4 @@ public void restore(JSONObject jsonObject) {
|
||||
connectors[i] = connector;
|
||||
}
|
||||
}
|
||||
|
||||
private List<MForm> restoreForms(JSONArray forms) {
|
||||
List<MForm> mForms = new ArrayList<MForm>();
|
||||
|
||||
for (int i = 0; i < forms.size(); i++) {
|
||||
mForms.add(restoreForm((JSONObject) forms.get(i)));
|
||||
}
|
||||
|
||||
return mForms;
|
||||
}
|
||||
|
||||
private MForm restoreForm(JSONObject form) {
|
||||
JSONArray inputs = (JSONArray) form.get(FORM_INPUTS);
|
||||
|
||||
List<MInput<?>> mInputs = new ArrayList<MInput<?>>();
|
||||
for (int i = 0; i < inputs.size(); i++) {
|
||||
JSONObject input = (JSONObject) inputs.get(i);
|
||||
MInputType type =
|
||||
MInputType.valueOf((String) input.get(FORM_INPUT_TYPE));
|
||||
switch (type) {
|
||||
case STRING: {
|
||||
String name = (String) input.get(FORM_INPUT_NAME);
|
||||
boolean mask = (Boolean) input.get(FORM_INPUT_MASK);
|
||||
long size = (Long) input.get(FORM_INPUT_SIZE);
|
||||
MInput<String> mInput = new MStringInput(name, mask, (short)size);
|
||||
mInputs.add(mInput);
|
||||
break;
|
||||
}
|
||||
case MAP: {
|
||||
String name = (String) input.get(FORM_INPUT_NAME);
|
||||
MInput<Map<String, String>> mInput = new MMapInput(name);
|
||||
mInputs.add(mInput);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new MForm((String) form.get(FORM_NAME), mInputs);
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,10 @@ public static synchronized void initialize() {
|
||||
}
|
||||
}
|
||||
|
||||
public static MFramework getFramework() {
|
||||
return mFramework;
|
||||
}
|
||||
|
||||
public static synchronized void destroy() {
|
||||
LOG.trace("Begin framework manager destroy");
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ limitations under the License.
|
||||
<listener-class>org.apache.sqoop.server.ServerInitializer</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- Version servlet -->
|
||||
<servlet>
|
||||
<servlet-name>VersionServlet</servlet-name>
|
||||
<servlet-class>org.apache.sqoop.server.VersionServlet</servlet-class>
|
||||
@ -38,6 +39,7 @@ limitations under the License.
|
||||
<url-pattern>/version</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Connector servlet -->
|
||||
<servlet>
|
||||
<servlet-name>v1.ConnectorServlet</servlet-name>
|
||||
<servlet-class>org.apache.sqoop.server.v1.ConnectorServlet</servlet-class>
|
||||
@ -49,5 +51,17 @@ limitations under the License.
|
||||
<url-pattern>/v1/connector/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Framework servlet -->
|
||||
<servlet>
|
||||
<servlet-name>v1.FrameworkServlet</servlet-name>
|
||||
<servlet-class>org.apache.sqoop.server.v1.FrameworkServlet</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>v1.FrameworkServlet</servlet-name>
|
||||
<url-pattern>/v1/framework/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user