5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-17 01:11:07 +08:00

SQOOP-2717: Sqoop2: Use connector name in shell

(Colin Ma via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2015-12-10 12:34:04 +01:00
parent 05e60b969b
commit de7fb4f670
8 changed files with 55 additions and 105 deletions

View File

@ -46,11 +46,11 @@ public class CreateLinkFunction extends SqoopFunction {
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public CreateLinkFunction() { public CreateLinkFunction() {
this.addOption(OptionBuilder this.addOption(OptionBuilder
.withDescription(resourceString(Constants.RES_CONNECTOR_ID)) .withDescription(resourceString(Constants.RES_CONNECTOR_NAME))
.withLongOpt(Constants.OPT_CID) .withLongOpt(Constants.OPT_CONNECTOR_NAME)
.isRequired() .isRequired()
.hasArg() .hasArg()
.create(Constants.OPT_CID_CHAR)); .create(Constants.OPT_CONNECTOR_NAME_CHAR));
} }
@Override @Override
@ -60,31 +60,12 @@ public Object executeFunction(CommandLine line, boolean isInteractive) throws IO
} }
private Status createLink(CommandLine line, List<String> args, boolean isInteractive) throws IOException { private Status createLink(CommandLine line, List<String> args, boolean isInteractive) throws IOException {
String connectorName = line.getOptionValue(Constants.OPT_CONNECTOR_NAME);
//Check if the command argument is a connector name //Command line had connector name
MLink link = null; //This will call getConnector() inside createLink()
Long cid; MLink link = getClient().createLink(connectorName);
String connectorName = line.getOptionValue(Constants.OPT_CID); printlnResource(Constants.RES_CREATE_CREATING_LINK, connectorName);
MConnector connector = getClient().getConnector(connectorName);
if (null == connector) {
//Now check if command line argument is a connector id
//This works as getConnector(String...) does not throw an exception
cid = getLong(line, Constants.OPT_CID);
getClient().getConnector(cid);
//Would have thrown an exception before this if input was an invalid connector name
//This will do an extra getConnector() call again inside createLink()
//but should not matter as connectors are cached
link = getClient().createLink(connectorName);
printlnResource(Constants.RES_CREATE_CREATING_LINK, cid);
}
else {
//Command line had connector name
//This will do an extra getConnector() call again inside createLink() but
//should not matter as connectors are cached
link = getClient().createLink(connectorName);
printlnResource(Constants.RES_CREATE_CREATING_LINK, connectorName);
}
ConsoleReader reader = getConsoleReader(); ConsoleReader reader = getConsoleReader();

View File

@ -23,6 +23,8 @@
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.OptionBuilder;
import org.apache.sqoop.client.ClientError;
import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.model.MConnector; import org.apache.sqoop.model.MConnector;
import org.apache.sqoop.shell.core.Constants; import org.apache.sqoop.shell.core.Constants;
import org.apache.sqoop.shell.utils.TableDisplayer; import org.apache.sqoop.shell.utils.TableDisplayer;
@ -41,17 +43,17 @@ public ShowConnectorFunction() {
.withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS)) .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS))
.withLongOpt(Constants.OPT_ALL) .withLongOpt(Constants.OPT_ALL)
.create(Constants.OPT_ALL_CHAR)); .create(Constants.OPT_ALL_CHAR));
this.addOption(OptionBuilder.hasArg().withArgName("cid") this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_NAME)
.withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID)) .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_CONNECTOR_NAME))
.withLongOpt(Constants.OPT_CID) .withLongOpt(Constants.OPT_NAME)
.create(Constants.OPT_CID_CHAR)); .create(Constants.OPT_NAME_CHAR));
} }
@Override @Override
public Object executeFunction(CommandLine line, boolean isInteractive) { public Object executeFunction(CommandLine line, boolean isInteractive) {
if (line.hasOption(Constants.OPT_ALL)) { if (line.hasOption(Constants.OPT_ALL)) {
showConnectors(); showConnectors();
} else if (line.hasOption(Constants.OPT_CID)) { } else if (line.hasOption(Constants.OPT_NAME)) {
showConnector(line); showConnector(line);
} else { } else {
showSummary(); showSummary();
@ -64,27 +66,24 @@ private void showSummary() {
Collection<MConnector> connectors = client.getConnectors(); Collection<MConnector> connectors = client.getConnectors();
List<String> header = new LinkedList<String>(); List<String> header = new LinkedList<String>();
header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
header.add(resourceString(Constants.RES_TABLE_HEADER_NAME)); header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
header.add(resourceString(Constants.RES_TABLE_HEADER_VERSION)); header.add(resourceString(Constants.RES_TABLE_HEADER_VERSION));
header.add(resourceString(Constants.RES_TABLE_HEADER_CLASS)); header.add(resourceString(Constants.RES_TABLE_HEADER_CLASS));
header.add(resourceString(Constants.RES_TABLE_HEADER_SUPPORTED_DIRECTIONS)); header.add(resourceString(Constants.RES_TABLE_HEADER_SUPPORTED_DIRECTIONS));
List<String> ids = new LinkedList<String>();
List<String> uniqueNames = new LinkedList<String>(); List<String> uniqueNames = new LinkedList<String>();
List<String> versions = new LinkedList<String>(); List<String> versions = new LinkedList<String>();
List<String> classes = new LinkedList<String>(); List<String> classes = new LinkedList<String>();
List<String> supportedDirections = new LinkedList<String>(); List<String> supportedDirections = new LinkedList<String>();
for(MConnector connector : connectors) { for(MConnector connector : connectors) {
ids.add(String.valueOf(connector.getPersistenceId()));
uniqueNames.add(connector.getUniqueName()); uniqueNames.add(connector.getUniqueName());
versions.add(connector.getVersion()); versions.add(connector.getVersion());
classes.add(connector.getClassName()); classes.add(connector.getClassName());
supportedDirections.add(connector.getSupportedDirections().toString()); supportedDirections.add(connector.getSupportedDirections().toString());
} }
TableDisplayer.display(header, ids, uniqueNames, versions, classes, supportedDirections); TableDisplayer.display(header, uniqueNames, versions, classes, supportedDirections);
} }
private void showConnectors() { private void showConnectors() {
@ -99,17 +98,13 @@ private void showConnectors() {
private void showConnector(CommandLine line) { private void showConnector(CommandLine line) {
//Check if the command argument is a connector name //Check if the command argument is a connector name
String connectorName = line.getOptionValue(Constants.OPT_CID); String connectorName = line.getOptionValue(Constants.OPT_NAME);
MConnector connector = client.getConnector(connectorName); MConnector connector = client.getConnector(connectorName);
if (null == connector) {
//Now check if command line argument is a connector id
//This works as getConnector(String...) does not throw an exception
Long cid = getLong(line, Constants.OPT_CID);
connector = client.getConnector(cid);
}
//No null checks here - as before. This is because getConnector(long...) // check if the connector exist
//throws an exception if connector is not found. if (connector == null) {
throw new SqoopException(ClientError.CLIENT_0003, connectorName);
}
printlnResource(Constants.RES_SHOW_PROMPT_CONNECTORS_TO_SHOW, 1); printlnResource(Constants.RES_SHOW_PROMPT_CONNECTORS_TO_SHOW, 1);
@ -118,7 +113,6 @@ private void showConnector(CommandLine line) {
private void displayConnector(MConnector connector) { private void displayConnector(MConnector connector) {
printlnResource(Constants.RES_SHOW_PROMPT_CONNECTOR_INFO, printlnResource(Constants.RES_SHOW_PROMPT_CONNECTOR_INFO,
connector.getPersistenceId(),
connector.getUniqueName(), connector.getUniqueName(),
connector.getClassName(), connector.getClassName(),
connector.getVersion(), connector.getVersion(),

View File

@ -47,10 +47,10 @@ public ShowJobFunction() {
.withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_JOBS)) .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_JOBS))
.withLongOpt(Constants.OPT_ALL) .withLongOpt(Constants.OPT_ALL)
.create(Constants.OPT_ALL_CHAR)); .create(Constants.OPT_ALL_CHAR));
this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_CID) this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_CONNECTOR_NAME)
.withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOBS_CID)) .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOBS_CN))
.withLongOpt(Constants.OPT_CID) .withLongOpt(Constants.OPT_CONNECTOR_NAME)
.create(Constants.OPT_CID_CHAR)); .create(Constants.OPT_CONNECTOR_NAME_CHAR));
this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID) this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_JID)
.withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOB_JID)) .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_JOB_JID))
.withLongOpt(Constants.OPT_JID) .withLongOpt(Constants.OPT_JID)
@ -61,11 +61,9 @@ public ShowJobFunction() {
public Object executeFunction(CommandLine line, boolean isInteractive) { public Object executeFunction(CommandLine line, boolean isInteractive) {
if (line.hasOption(Constants.OPT_ALL)) { if (line.hasOption(Constants.OPT_ALL)) {
showJobs(null); showJobs(null);
} else if (line.hasOption(Constants.OPT_CID)) { } else if (line.hasOption(Constants.OPT_CONNECTOR_NAME)) {
//showJobs(getLong(line, Constants.OPT_CID)); showJobs(line.getOptionValue(Constants.OPT_CONNECTOR_NAME));
showJobs(line.getOptionValue(Constants.OPT_CID));
} else if (line.hasOption(Constants.OPT_JID)) { } else if (line.hasOption(Constants.OPT_JID)) {
//showJob(getLong(line, Constants.OPT_JID));
showJob(line.getOptionValue(Constants.OPT_JID)); showJob(line.getOptionValue(Constants.OPT_JID));
} else { } else {
showSummary(); showSummary();

View File

@ -74,13 +74,11 @@ private void showSummary() {
List<String> header = new LinkedList<String>(); List<String> header = new LinkedList<String>();
header.add(resourceString(Constants.RES_TABLE_HEADER_ID)); header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
header.add(resourceString(Constants.RES_TABLE_HEADER_NAME)); header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR_ID));
header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR_NAME)); header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR_NAME));
header.add(resourceString(Constants.RES_TABLE_HEADER_ENABLED)); header.add(resourceString(Constants.RES_TABLE_HEADER_ENABLED));
List<String> ids = new LinkedList<String>(); List<String> ids = new LinkedList<String>();
List<String> names = new LinkedList<String>(); List<String> names = new LinkedList<String>();
List<String> connectorIds = new LinkedList<String>();
List<String> connectorNames = new LinkedList<String>(); List<String> connectorNames = new LinkedList<String>();
List<String> availabilities = new LinkedList<String>(); List<String> availabilities = new LinkedList<String>();
@ -91,7 +89,7 @@ private void showSummary() {
availabilities.add(String.valueOf(link.getEnabled())); availabilities.add(String.valueOf(link.getEnabled()));
} }
TableDisplayer.display(header, ids, names, connectorIds, connectorNames, availabilities); TableDisplayer.display(header, ids, names, connectorNames, availabilities);
} }
private void showLinks() { private void showLinks() {
@ -125,7 +123,7 @@ private void displayLink(MLink link) {
formatter.format(link.getLastUpdateDate()) formatter.format(link.getLastUpdateDate())
); );
printlnResource(Constants.RES_SHOW_PROMPT_LINK_CID_INFO, link.getConnectorName()); printlnResource(Constants.RES_SHOW_PROMPT_LINK_CN_INFO, link.getConnectorName());
// Display link config // Display link config
displayConfig(link.getConnectorLinkConfig().getConfigs(), displayConfig(link.getConnectorLinkConfig().getConfigs(),

View File

@ -39,8 +39,8 @@ public class Constants {
public static final String OPT_TO = "to"; public static final String OPT_TO = "to";
public static final String OPT_ALL = "all"; public static final String OPT_ALL = "all";
public static final String OPT_JID = "jid"; public static final String OPT_JID = "jid";
public static final String OPT_CID = "cid";
public static final String OPT_NAME = "name"; public static final String OPT_NAME = "name";
public static final String OPT_CONNECTOR_NAME = "connector";
public static final String OPT_VALUE = "value"; public static final String OPT_VALUE = "value";
public static final String OPT_VERBOSE = "verbose"; public static final String OPT_VERBOSE = "verbose";
public static final String OPT_HOST = "host"; public static final String OPT_HOST = "host";
@ -66,8 +66,8 @@ public class Constants {
public static final char OPT_TO_CHAR = 't'; public static final char OPT_TO_CHAR = 't';
public static final char OPT_ALL_CHAR = 'a'; public static final char OPT_ALL_CHAR = 'a';
public static final char OPT_JID_CHAR = 'j'; public static final char OPT_JID_CHAR = 'j';
public static final char OPT_CID_CHAR = 'c';
public static final char OPT_NAME_CHAR = 'n'; public static final char OPT_NAME_CHAR = 'n';
public static final char OPT_CONNECTOR_NAME_CHAR = 'c';
public static final char OPT_VALUE_CHAR = 'v'; public static final char OPT_VALUE_CHAR = 'v';
public static final char OPT_HOST_CHAR = 'h'; public static final char OPT_HOST_CHAR = 'h';
public static final char OPT_PORT_CHAR = 'p'; public static final char OPT_PORT_CHAR = 'p';
@ -157,8 +157,6 @@ public class Constants {
"args.to_missing"; "args.to_missing";
public static final String RES_ARGS_JID_MISSING = public static final String RES_ARGS_JID_MISSING =
"args.jid_missing"; "args.jid_missing";
public static final String RES_ARGS_CID_MISSING =
"args.cid_missing";
public static final String RES_ARGS_NAME_MISSING = public static final String RES_ARGS_NAME_MISSING =
"args.name_missing"; "args.name_missing";
public static final String RES_ARGS_VALUE_MISSING = public static final String RES_ARGS_VALUE_MISSING =
@ -168,8 +166,8 @@ public class Constants {
"prompt.link_id"; "prompt.link_id";
public static final String RES_PROMPT_JOB_ID = public static final String RES_PROMPT_JOB_ID =
"prompt.job_id"; "prompt.job_id";
public static final String RES_CONNECTOR_ID = public static final String RES_CONNECTOR_NAME =
"prompt.connector_id"; "prompt.connector_name";
public static final String RES_PROMPT_UPDATE_LINK_CONFIG = public static final String RES_PROMPT_UPDATE_LINK_CONFIG =
"prompt.update_link_config"; "prompt.update_link_config";
public static final String RES_PROMPT_UPDATE_JOB_CONFIG = public static final String RES_PROMPT_UPDATE_JOB_CONFIG =
@ -265,8 +263,8 @@ public class Constants {
"show.prompt_links_to_show"; "show.prompt_links_to_show";
public static final String RES_SHOW_PROMPT_LINK_INFO = public static final String RES_SHOW_PROMPT_LINK_INFO =
"show.prompt_link_info"; "show.prompt_link_info";
public static final String RES_SHOW_PROMPT_LINK_CID_INFO = public static final String RES_SHOW_PROMPT_LINK_CN_INFO =
"show.prompt_link_cid_info"; "show.prompt_link_cn_info";
public static final String RES_SHOW_ROLE_BAD_ARGUMENTS_PRINCIPAL_TYPE = public static final String RES_SHOW_ROLE_BAD_ARGUMENTS_PRINCIPAL_TYPE =
"show.role.bad_arguments_principal_type"; "show.role.bad_arguments_principal_type";
public static final String RES_SHOW_PRIVILEGE_BAD_ARGUMENTS_RESOURCE_TYPE = public static final String RES_SHOW_PRIVILEGE_BAD_ARGUMENTS_RESOURCE_TYPE =
@ -274,8 +272,8 @@ public class Constants {
public static final String RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS = public static final String RES_SHOW_PROMPT_DISPLAY_ALL_CONNECTORS =
"show.prompt_display_all_connectors"; "show.prompt_display_all_connectors";
public static final String RES_SHOW_PROMPT_DISPLAY_CONNECTOR_CID = public static final String RES_SHOW_PROMPT_DISPLAY_CONNECTOR_NAME =
"show.prompt_display_connector_cid"; "show.prompt_display_connector_name";
public static final String RES_SHOW_PROMPT_CONNECTORS_TO_SHOW = public static final String RES_SHOW_PROMPT_CONNECTORS_TO_SHOW =
"show.prompt_connectors_to_show"; "show.prompt_connectors_to_show";
public static final String RES_SHOW_PROMPT_CONNECTOR_INFO = public static final String RES_SHOW_PROMPT_CONNECTOR_INFO =
@ -288,8 +286,8 @@ public class Constants {
public static final String RES_SHOW_PROMPT_DISPLAY_ALL_JOBS = public static final String RES_SHOW_PROMPT_DISPLAY_ALL_JOBS =
"show.prompt_display_all_jobs"; "show.prompt_display_all_jobs";
public static final String RES_SHOW_PROMPT_DISPLAY_JOBS_CID = public static final String RES_SHOW_PROMPT_DISPLAY_JOBS_CN =
"show.prompt_display_all_jobs_cid"; "show.prompt_display_all_jobs_cn";
public static final String RES_SHOW_PROMPT_DISPLAY_JOB_JID = public static final String RES_SHOW_PROMPT_DISPLAY_JOB_JID =
"show.prompt_display_job_jid"; "show.prompt_display_job_jid";
public static final String RES_SHOW_PROMPT_JOBS_TO_SHOW = public static final String RES_SHOW_PROMPT_JOBS_TO_SHOW =
@ -369,8 +367,6 @@ public class Constants {
"table.header.supported_directions"; "table.header.supported_directions";
public static final String RES_TABLE_HEADER_CONNECTOR_NAME = public static final String RES_TABLE_HEADER_CONNECTOR_NAME =
"table.header.connector.name"; "table.header.connector.name";
public static final String RES_TABLE_HEADER_CONNECTOR_ID =
"table.header.connector.id";
public static final String RES_TABLE_HEADER_FROM_CONNECTOR = public static final String RES_TABLE_HEADER_FROM_CONNECTOR =
"table.header.connector.from"; "table.header.connector.from";
public static final String RES_TABLE_HEADER_TO_CONNECTOR = public static final String RES_TABLE_HEADER_TO_CONNECTOR =

View File

@ -42,7 +42,7 @@ args.value_missing = Required argument --value is missing.
## Generic description of various ids, types etc ## Generic description of various ids, types etc
prompt.link_id = Link Id prompt.link_id = Link Id
prompt.connector_id = Connector Id prompt.connector_name = Connector Name
prompt.job_id = Job Id prompt.job_id = Job Id
prompt.job_type = Job type prompt.job_type = Job type
@ -78,7 +78,7 @@ create.link_successful = New link was successfully created with \
create.job_successful = New job was successfully created with validation \ create.job_successful = New job was successfully created with validation \
status {0} and persistent id {1} status {0} and persistent id {1}
create.role_successful = New role was successfully created with name {0} create.role_successful = New role was successfully created with name {0}
create.creating_link = Creating link for connector with id {0} create.creating_link = Creating link for connector with name {0}
create.creating_job = Creating job for links with from id {0} and to id {1} create.creating_job = Creating job for links with from id {0} and to id {1}
# Delete command # Delete command
@ -133,13 +133,13 @@ show.prompt_display_link_lid = Display the link with lid
show.link_usage = Usage: show link show.link_usage = Usage: show link
show.prompt_links_to_show = @|bold {0} link(s) to show: |@ show.prompt_links_to_show = @|bold {0} link(s) to show: |@
show.prompt_link_info = link with id {0} and name {1} (Enabled: {2}, Created by {3} at {4}, Updated by {5} at {6}) show.prompt_link_info = link with id {0} and name {1} (Enabled: {2}, Created by {3} at {4}, Updated by {5} at {6})
show.prompt_link_cid_info = Using Connector @|bold {0}|@ with id @|bold {1}|@ show.prompt_link_cn_info = Using Connector @|bold {0}|@ with name @|bold {1}|@
show.prompt_display_all_connectors = Display all connectors show.prompt_display_all_connectors = Display all connectors
show.prompt_display_connector_cid = Display the connector with cid show.prompt_display_connector_name = Display the connector with name
show.connector_usage = Usage: show connector show.connector_usage = Usage: show connector
show.prompt_connectors_to_show = @|bold {0} connector(s) to show: |@ show.prompt_connectors_to_show = @|bold {0} connector(s) to show: |@
show.prompt_connector_info = Connector with id {0}:\n Name: {1} \n \ show.prompt_connector_info = Connector with Name: {0} \n \
Class: {2}\n Version: {3}\n Supported Directions {4} Class: {2}\n Version: {3}\n Supported Directions {4}
show.role.bad_arguments_principal_type = @|bold principal |@ and @|bold principal-type |@ must be used together. show.role.bad_arguments_principal_type = @|bold principal |@ and @|bold principal-type |@ must be used together.
show.privilege.bad_arguments_resource_type = @|bold resource |@ and @|bold resource-type |@ must be used together. show.privilege.bad_arguments_resource_type = @|bold resource |@ and @|bold resource-type |@ must be used together.
@ -148,7 +148,7 @@ show.driver_usage = Usage: show driver
show.prompt_driver_opts = @|bold Driver specific options: |@\nPersistent id: {0} show.prompt_driver_opts = @|bold Driver specific options: |@\nPersistent id: {0}
show.prompt_display_all_jobs = Display all jobs show.prompt_display_all_jobs = Display all jobs
show.prompt_display_all_jobs_cid = Display all jobs with given cid show.prompt_display_all_jobs_cn = Display all jobs with given connector name
show.prompt_display_job_jid = Display job with given jid show.prompt_display_job_jid = Display job with given jid
show.job_usage = Usage: show job show.job_usage = Usage: show job
show.prompt_jobs_to_show = @|bold {0} job(s) to show: |@ show.prompt_jobs_to_show = @|bold {0} job(s) to show: |@
@ -213,7 +213,6 @@ table.header.name = Name
table.header.version = Version table.header.version = Version
table.header.class = Class table.header.class = Class
table.header.supported_directions = Supported Directions table.header.supported_directions = Supported Directions
table.header.connector.id = Connector Id
table.header.connector.name = Connector Name table.header.connector.name = Connector Name
table.header.connector.from = From Connector table.header.connector.from = From Connector
table.header.connector.to = To Connector table.header.connector.to = To Connector

View File

@ -112,34 +112,20 @@ public void testCreateLink() {
Status status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c", "connector_test")); Status status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c", "connector_test"));
assertTrue(status != null && status == Status.OK); assertTrue(status != null && status == Status.OK);
// create link -cid connector_test // create link -connector connector_test
status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-cid", "connector_test")); status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-connector", "connector_test"));
assertTrue(status != null && status == Status.OK); assertTrue(status != null && status == Status.OK);
// incorrect command: create link -c // incorrect command: create link -c
try { try {
status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c")); status = (Status) createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c"));
fail("Create link should fail as connector id/name is missing!"); fail("Create link should fail as connector name is missing!");
} catch (SqoopException e) { } catch (SqoopException e) {
assertEquals(ShellError.SHELL_0003, e.getErrorCode()); assertEquals(ShellError.SHELL_0003, e.getErrorCode());
assertTrue(e.getMessage().contains("Missing argument for option")); assertTrue(e.getMessage().contains("Missing argument for option"));
} }
} }
@Test
public void testCreateLinkWithNonExistingConnector() {
ShellEnvironment.setInteractive(false);
when(client.getConnector(any(String.class))).thenThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "Connector doesn't exist"));
when(client.getConnector(any(Integer.class))).thenThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "Connector doesn't exist"));
try {
createCmd.execute(Arrays.asList(Constants.FN_LINK, "-c", "connector_test"));
fail("Create link should fail as requested connector doesn't exist!");
} catch (SqoopException e) {
assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());
}
}
@Test @Test
public void testCreateLinkInteractive() { public void testCreateLinkInteractive() {
ShellEnvironment.setInteractive(true); ShellEnvironment.setInteractive(true);

View File

@ -154,7 +154,7 @@ public void testShowVersion() {
public void testShowConnector() { public void testShowConnector() {
when(client.getConnectors()).thenReturn(new ArrayList<MConnector>()); when(client.getConnectors()).thenReturn(new ArrayList<MConnector>());
when(client.getConnector(any(String.class))).thenReturn( when(client.getConnector(any(String.class))).thenReturn(
new MConnector("", "", "", new MConnector("test_connector", "", "",
new MLinkConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()), new MLinkConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()), new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()))); new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>())));
@ -164,7 +164,6 @@ public void testShowConnector() {
Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_CONNECTOR)); Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_CONNECTOR));
Assert.assertTrue(status != null && status == Status.OK); Assert.assertTrue(status != null && status == Status.OK);
String str = new String(out.toByteArray()); String str = new String(out.toByteArray());
Assert.assertTrue(str.contains("Id"));
Assert.assertTrue(str.contains("Name")); Assert.assertTrue(str.contains("Name"));
Assert.assertTrue(str.contains("Version")); Assert.assertTrue(str.contains("Version"));
Assert.assertTrue(str.contains("Class")); Assert.assertTrue(str.contains("Class"));
@ -177,12 +176,12 @@ public void testShowConnector() {
str = new String(out.toByteArray()); str = new String(out.toByteArray());
Assert.assertTrue(str.contains("connector(s) to show:")); Assert.assertTrue(str.contains("connector(s) to show:"));
// show connector -cid 1 // show connector -name test_connector
out.reset(); out.reset();
status = (Status) showCmd.execute(Arrays.asList(Constants.FN_CONNECTOR, "-cid", "1")); status = (Status) showCmd.execute(Arrays.asList(Constants.FN_CONNECTOR, "-name", "test_connector"));
Assert.assertTrue(status != null && status == Status.OK); Assert.assertTrue(status != null && status == Status.OK);
str = new String(out.toByteArray()); str = new String(out.toByteArray());
Assert.assertTrue(str.contains("Connector with id")); Assert.assertTrue(str.contains("Connector with Name: test_connector"));
} }
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@ -212,7 +211,6 @@ public void testShowLink() {
String str = new String(out.toByteArray()); String str = new String(out.toByteArray());
Assert.assertTrue(str.contains("Id")); Assert.assertTrue(str.contains("Id"));
Assert.assertTrue(str.contains("Name")); Assert.assertTrue(str.contains("Name"));
Assert.assertTrue(str.contains("Connector Id"));
Assert.assertTrue(str.contains("Connector Name")); Assert.assertTrue(str.contains("Connector Name"));
Assert.assertTrue(str.contains("Enabled")); Assert.assertTrue(str.contains("Enabled"));
@ -239,7 +237,7 @@ public void testShowJob() {
new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()), new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()), new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
new MDriverConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()))); new MDriverConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>())));
when(client.getJobsByConnector("2")).thenReturn(Arrays.asList(new MJob("fromConnectorName", "toConnectorName", when(client.getJobsByConnector("fromConnectorName")).thenReturn(Arrays.asList(new MJob("fromConnectorName", "toConnectorName",
"linkName1", "linkName2", new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()), "linkName1", "linkName2", new MFromConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()), new MToConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()),
new MDriverConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>())))); new MDriverConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()))));
@ -269,9 +267,9 @@ public void testShowJob() {
str = new String(out.toByteArray()); str = new String(out.toByteArray());
Assert.assertTrue(str.contains("Job with id")); Assert.assertTrue(str.contains("Job with id"));
// show job -cid 2 // show job -connector fromConnectorName
out.reset(); out.reset();
status = (Status) showCmd.execute(Arrays.asList(Constants.FN_JOB, "-cid", "2")); status = (Status) showCmd.execute(Arrays.asList(Constants.FN_JOB, "-connector", "fromConnectorName"));
Assert.assertTrue(status != null && status == Status.OK); Assert.assertTrue(status != null && status == Status.OK);
str = new String(out.toByteArray()); str = new String(out.toByteArray());
Assert.assertTrue(str.contains("job(s) to show:")); Assert.assertTrue(str.contains("job(s) to show:"));