5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-15 16:31:17 +08:00

SQOOP-2692: Sqoop2: Use link name in shell

(Colin Ma via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2015-12-15 15:10:55 +01:00
parent d89f64adc8
commit 3f87658372
17 changed files with 86 additions and 91 deletions

View File

@ -45,18 +45,18 @@ public class CloneLinkFunction extends SqoopFunction {
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public CloneLinkFunction() { public CloneLinkFunction() {
this.addOption(OptionBuilder this.addOption(OptionBuilder
.withDescription(resourceString(Constants.RES_PROMPT_LINK_ID)) .withDescription(resourceString(Constants.RES_PROMPT_LINK_NAME))
.withLongOpt(Constants.OPT_LID) .withLongOpt(Constants.OPT_NAME)
.hasArg() .hasArg()
.isRequired() .isRequired()
.create(Constants.OPT_LID_CHAR) .create(Constants.OPT_NAME_CHAR)
); );
} }
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException { public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
return cloneLink(line.getOptionValue(Constants.OPT_LID), line.getArgList(), isInteractive); return cloneLink(line.getOptionValue(Constants.OPT_NAME), line.getArgList(), isInteractive);
} }
private Status cloneLink(String linkArg, List<String> args, boolean isInteractive) throws IOException { private Status cloneLink(String linkArg, List<String> args, boolean isInteractive) throws IOException {

View File

@ -47,14 +47,14 @@ public class CreateJobFunction extends SqoopFunction {
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public CreateJobFunction() { public CreateJobFunction() {
this.addOption(OptionBuilder this.addOption(OptionBuilder
.withDescription(resourceString(Constants.RES_PROMPT_LINK_ID)) .withDescription(resourceString(Constants.RES_PROMPT_LINK_NAME))
.withLongOpt(Constants.OPT_FROM) .withLongOpt(Constants.OPT_FROM)
.isRequired() .isRequired()
.hasArg() .hasArg()
.create(Constants.OPT_FROM_CHAR) .create(Constants.OPT_FROM_CHAR)
); );
this.addOption(OptionBuilder this.addOption(OptionBuilder
.withDescription(resourceString(Constants.RES_PROMPT_LINK_ID)) .withDescription(resourceString(Constants.RES_PROMPT_LINK_NAME))
.withLongOpt(Constants.OPT_TO) .withLongOpt(Constants.OPT_TO)
.isRequired() .isRequired()
.hasArg() .hasArg()

View File

@ -106,7 +106,7 @@ private Status createLink(CommandLine line, List<String> args, boolean isInterac
} }
ConfigDisplayer.displayConfigWarning(link); ConfigDisplayer.displayConfigWarning(link);
printlnResource(Constants.RES_CREATE_LINK_SUCCESSFUL, status.name(), link.getPersistenceId()); printlnResource(Constants.RES_CREATE_LINK_SUCCESSFUL, status.name(), link.getName());
return status; return status;
} }

View File

@ -34,16 +34,16 @@ public class DeleteLinkFunction extends SqoopFunction {
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public DeleteLinkFunction() { public DeleteLinkFunction() {
this.addOption(OptionBuilder this.addOption(OptionBuilder
.withDescription(resourceString(Constants.RES_PROMPT_LINK_ID)) .withDescription(resourceString(Constants.RES_PROMPT_LINK_NAME))
.withLongOpt(Constants.OPT_LID) .withLongOpt(Constants.OPT_NAME)
.isRequired() .isRequired()
.hasArg() .hasArg()
.create(Constants.OPT_LID_CHAR)); .create(Constants.OPT_NAME_CHAR));
} }
@Override @Override
public Object executeFunction(CommandLine line, boolean isInteractive) { public Object executeFunction(CommandLine line, boolean isInteractive) {
client.deleteLink(line.getOptionValue(Constants.OPT_LID)); client.deleteLink(line.getOptionValue(Constants.OPT_NAME));
return Status.OK; return Status.OK;
} }
} }

View File

@ -34,16 +34,16 @@ public class DisableLinkFunction extends SqoopFunction {
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public DisableLinkFunction() { public DisableLinkFunction() {
this.addOption(OptionBuilder this.addOption(OptionBuilder
.withDescription(resourceString(Constants.RES_PROMPT_LINK_ID)) .withDescription(resourceString(Constants.RES_PROMPT_LINK_NAME))
.withLongOpt(Constants.OPT_LID) .withLongOpt(Constants.OPT_NAME)
.isRequired() .isRequired()
.hasArg() .hasArg()
.create(Constants.OPT_LID_CHAR)); .create(Constants.OPT_NAME_CHAR));
} }
@Override @Override
public Object executeFunction(CommandLine line, boolean isInteractive) { public Object executeFunction(CommandLine line, boolean isInteractive) {
client.enableLink(line.getOptionValue(Constants.OPT_LID), false); client.enableLink(line.getOptionValue(Constants.OPT_NAME), false);
return Status.OK; return Status.OK;
} }
} }

View File

@ -34,16 +34,16 @@ public class EnableLinkFunction extends SqoopFunction {
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public EnableLinkFunction() { public EnableLinkFunction() {
this.addOption(OptionBuilder this.addOption(OptionBuilder
.withDescription(resourceString(Constants.RES_PROMPT_LINK_ID)) .withDescription(resourceString(Constants.RES_PROMPT_LINK_NAME))
.withLongOpt(Constants.OPT_LID) .withLongOpt(Constants.OPT_NAME)
.isRequired() .isRequired()
.hasArg() .hasArg()
.create(Constants.OPT_LID_CHAR)); .create(Constants.OPT_NAME_CHAR));
} }
@Override @Override
public Object executeFunction(CommandLine line, boolean isInteractive) { public Object executeFunction(CommandLine line, boolean isInteractive) {
client.enableLink(line.getOptionValue(Constants.OPT_LID), true); client.enableLink(line.getOptionValue(Constants.OPT_NAME), true);
return Status.OK; return Status.OK;
} }
} }

View File

@ -136,11 +136,11 @@ private void displayJob(MJob job) {
displayConfig(job.getDriverConfig().getConfigs(), displayConfig(job.getDriverConfig().getConfigs(),
client.getDriverConfigBundle()); client.getDriverConfigBundle());
printlnResource(Constants.RES_SHOW_PROMPT_JOB_FROM_LID_INFO, printlnResource(Constants.RES_SHOW_PROMPT_JOB_FROM_LN_INFO,
job.getFromLinkName()); job.getFromLinkName());
displayConfig(job.getFromJobConfig().getConfigs(), displayConfig(job.getFromJobConfig().getConfigs(),
client.getConnectorConfigBundle(job.getFromConnectorName())); client.getConnectorConfigBundle(job.getFromConnectorName()));
printlnResource(Constants.RES_SHOW_PROMPT_JOB_TO_LID_INFO, printlnResource(Constants.RES_SHOW_PROMPT_JOB_TO_LN_INFO,
job.getToLinkName()); job.getToLinkName());
displayConfig(job.getToJobConfig().getConfigs(), displayConfig(job.getToJobConfig().getConfigs(),
client.getConnectorConfigBundle(job.getToConnectorName())); client.getConnectorConfigBundle(job.getToConnectorName()));

View File

@ -49,18 +49,18 @@ public ShowLinkFunction() {
.withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_LINKS)) .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_ALL_LINKS))
.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_LID) this.addOption(OptionBuilder.hasArg().withArgName(Constants.OPT_NAME)
.withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_LINK_LID)) .withDescription(resourceString(Constants.RES_SHOW_PROMPT_DISPLAY_LINK_LN))
.withLongOpt(Constants.OPT_LID) .withLongOpt(Constants.OPT_NAME)
.create(Constants.OPT_LID_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)) {
showLinks(); showLinks();
} else if (line.hasOption(Constants.OPT_LID)) { } else if (line.hasOption(Constants.OPT_NAME)) {
showLink(line.getOptionValue(Constants.OPT_LID)); showLink(line.getOptionValue(Constants.OPT_NAME));
} else { } else {
showSummary(); showSummary();
} }
@ -72,24 +72,21 @@ private void showSummary() {
List<MLink> links = client.getLinks(); List<MLink> links = client.getLinks();
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_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> names = new LinkedList<String>(); List<String> names = 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>();
for (MLink link : links) { for (MLink link : links) {
ids.add(String.valueOf(link.getPersistenceId()));
names.add(link.getName()); names.add(link.getName());
connectorNames.add(link.getConnectorName()); connectorNames.add(link.getConnectorName());
availabilities.add(String.valueOf(link.getEnabled())); availabilities.add(String.valueOf(link.getEnabled()));
} }
TableDisplayer.display(header, ids, names, connectorNames, availabilities); TableDisplayer.display(header, names, connectorNames, availabilities);
} }
private void showLinks() { private void showLinks() {
@ -114,7 +111,6 @@ private void displayLink(MLink link) {
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
printlnResource(Constants.RES_SHOW_PROMPT_LINK_INFO, printlnResource(Constants.RES_SHOW_PROMPT_LINK_INFO,
link.getPersistenceId(),
link.getName(), link.getName(),
link.getEnabled(), link.getEnabled(),
link.getCreationUser(), link.getCreationUser(),

View File

@ -45,17 +45,17 @@ public class UpdateLinkFunction extends SqoopFunction {
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public UpdateLinkFunction() { public UpdateLinkFunction() {
this.addOption(OptionBuilder this.addOption(OptionBuilder
.withDescription(resourceString(Constants.RES_PROMPT_LINK_ID)) .withDescription(resourceString(Constants.RES_PROMPT_LINK_NAME))
.withLongOpt(Constants.OPT_LID) .withLongOpt(Constants.OPT_NAME)
.isRequired() .isRequired()
.hasArg() .hasArg()
.create(Constants.OPT_LID_CHAR)); .create(Constants.OPT_NAME_CHAR));
} }
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException { public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
return updateLink(line.getOptionValue(Constants.OPT_LID), line.getArgList(), isInteractive); return updateLink(line.getOptionValue(Constants.OPT_NAME), line.getArgList(), isInteractive);
} }
private Status updateLink(String linkArg, List<String> args, boolean isInteractive) throws IOException { private Status updateLink(String linkArg, List<String> args, boolean isInteractive) throws IOException {

View File

@ -34,7 +34,6 @@ public class Constants {
// Options // Options
public static final String OPT_LID = "lid";
public static final String OPT_FROM = "from"; public static final String OPT_FROM = "from";
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";
@ -61,7 +60,6 @@ public class Constants {
public static final String OPT_WITH_GRANT = "with-grant"; public static final String OPT_WITH_GRANT = "with-grant";
public static final String OPT_WITH_JOB = "job"; public static final String OPT_WITH_JOB = "job";
public static final char OPT_LID_CHAR = 'l';
public static final char OPT_FROM_CHAR = 'f'; public static final char OPT_FROM_CHAR = 'f';
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';
@ -162,8 +160,8 @@ public class Constants {
public static final String RES_ARGS_VALUE_MISSING = public static final String RES_ARGS_VALUE_MISSING =
"args.value_missing"; "args.value_missing";
public static final String RES_PROMPT_LINK_ID = public static final String RES_PROMPT_LINK_NAME =
"prompt.link_id"; "prompt.link_name";
public static final String RES_PROMPT_JOB_NAME = public static final String RES_PROMPT_JOB_NAME =
"prompt.job_name"; "prompt.job_name";
public static final String RES_CONNECTOR_NAME = public static final String RES_CONNECTOR_NAME =
@ -257,8 +255,8 @@ public class Constants {
public static final String RES_SHOW_PROMPT_DISPLAY_ALL_LINKS = public static final String RES_SHOW_PROMPT_DISPLAY_ALL_LINKS =
"show.prompt_display_all_links"; "show.prompt_display_all_links";
public static final String RES_SHOW_PROMPT_DISPLAY_LINK_LID = public static final String RES_SHOW_PROMPT_DISPLAY_LINK_LN =
"show.prompt_display_link_lid"; "show.prompt_display_link_name";
public static final String RES_SHOW_PROMPT_LINKS_TO_SHOW = public static final String RES_SHOW_PROMPT_LINKS_TO_SHOW =
"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 =
@ -294,10 +292,10 @@ public class Constants {
"show.prompt_jobs_to_show"; "show.prompt_jobs_to_show";
public static final String RES_SHOW_PROMPT_JOB_INFO = public static final String RES_SHOW_PROMPT_JOB_INFO =
"show.prompt_job_info"; "show.prompt_job_info";
public static final String RES_SHOW_PROMPT_JOB_FROM_LID_INFO = public static final String RES_SHOW_PROMPT_JOB_FROM_LN_INFO =
"show.prompt_job_from_lid_info"; "show.prompt_job_from_ln_info";
public static final String RES_SHOW_PROMPT_JOB_TO_LID_INFO = public static final String RES_SHOW_PROMPT_JOB_TO_LN_INFO =
"show.prompt_job_to_lid_info"; "show.prompt_job_to_ln_info";
public static final String RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS = public static final String RES_SHOW_PROMPT_DISPLAY_ALL_SUBMISSIONS =
"show.prompt_display_all_submissions"; "show.prompt_display_all_submissions";

View File

@ -41,7 +41,7 @@ args.name_missing = Required argument --name is missing.
args.value_missing = Required argument --value is missing. 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_name = Link Name
prompt.connector_name = Connector Name prompt.connector_name = Connector Name
prompt.job_name = Job Name prompt.job_name = Job Name
prompt.job_type = Job type prompt.job_type = Job type
@ -57,7 +57,7 @@ job object
# Update command # Update command
update.description = Update objects in Sqoop repository update.description = Update objects in Sqoop repository
update.link = Updating link with id {0} update.link = Updating link with name {0}
update.job = Updating job with name {0} update.job = Updating job with name {0}
update.link_successful = link was successfully updated with status {0} update.link_successful = link was successfully updated with status {0}
update.job_successful = Job was successfully updated with status {0} update.job_successful = Job was successfully updated with status {0}
@ -74,12 +74,12 @@ clone.cloning_job = Cloning job with name {0}
# Create command # Create command
create.description = Create new object in Sqoop repository create.description = Create new object in Sqoop repository
create.link_successful = New link was successfully created with \ create.link_successful = New link was successfully created with \
validation status {0} and persistent id {1} validation status {0} and name {1}
create.job_successful = New job was successfully created with validation \ create.job_successful = New job was successfully created with validation \
status {0} and name {1} status {0} and name {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 name {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 name {0} and to name {1}
# Delete command # Delete command
delete.description = Delete existing object in Sqoop repository delete.description = Delete existing object in Sqoop repository
@ -129,10 +129,10 @@ set.server_ignored = --host, --port or --webapp option is ignored, because --url
# Show command # Show command
show.description = Display various objects and configuration options show.description = Display various objects and configuration options
show.prompt_display_all_links = Display all links show.prompt_display_all_links = Display all links
show.prompt_display_link_lid = Display the link with lid show.prompt_display_link_name = Display the link with name
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 name {0} (Enabled: {1}, Created by {2} at {3}, Updated by {4} at {5})
show.prompt_link_cn_info = Using Connector @|bold {0}|@ with name @|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
@ -153,8 +153,8 @@ show.prompt_display_job_name = Display job with given name
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: |@
show.prompt_job_info = Job with name {0} (Enabled: {1}, Created by {2} at {3}, Updated by {4} at {5}) show.prompt_job_info = Job with name {0} (Enabled: {1}, Created by {2} at {3}, Updated by {4} at {5})
show.prompt_job_from_lid_info = From link: {0} show.prompt_job_from_ln_info = From link: {0}
show.prompt_job_to_lid_info = To link: {0} show.prompt_job_to_ln_info = To link: {0}
show.prompt_display_all_submissions = Display all submissions show.prompt_display_all_submissions = Display all submissions
show.prompt_display_all_submissions_jn = Display all submissions given job name show.prompt_display_all_submissions_jn = Display all submissions given job name

View File

@ -93,22 +93,22 @@ public void testCloneLink() {
when(client.saveLink(link)).thenReturn(Status.OK); when(client.saveLink(link)).thenReturn(Status.OK);
// clone link -lid link_test // clone link -lid link_test
Status status = (Status) cloneCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test")); Status status = (Status) cloneCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
assertTrue(status != null && status == Status.OK); assertTrue(status != null && status == Status.OK);
// Missing argument for option lid // Missing argument for option name
try { try {
cloneCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid")); cloneCmd.execute(Arrays.asList(Constants.FN_LINK, "-name"));
fail("Update link should fail as parameters aren't complete!"); fail("Update link should fail as parameters aren't complete!");
} 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"));
} }
// Missing option lid // Missing option name
try { try {
cloneCmd.execute(Arrays.asList(Constants.FN_LINK)); cloneCmd.execute(Arrays.asList(Constants.FN_LINK));
fail("Update link should fail as option lid is missing"); fail("Update link should fail as option 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 required option")); assertTrue(e.getMessage().contains("Missing required option"));
@ -125,7 +125,7 @@ public void testCloneLinkInteractive() {
when(client.saveLink(link)).thenReturn(Status.OK); when(client.saveLink(link)).thenReturn(Status.OK);
when(client.getConnector(any(Long.class))).thenReturn(new MConnector("", "", "", null, null, null)); when(client.getConnector(any(Long.class))).thenReturn(new MConnector("", "", "", null, null, null));
// clone link -lid link_test // clone link -name link_test
initData("linkname\r" + // link name initData("linkname\r" + // link name
"abc\r" + // for input with name "String" "abc\r" + // for input with name "String"
"12345\r" + // for input with name "Integer" "12345\r" + // for input with name "Integer"
@ -135,7 +135,7 @@ public void testCloneLinkInteractive() {
"0\r" + // for input with name "Enum" "0\r" + // for input with name "Enum"
"l1\rl2\rl3\r\r" + // for input with name "List" "l1\rl2\rl3\r\r" + // for input with name "List"
"12345678\r"); // for input with name "DateTime" "12345678\r"); // for input with name "DateTime"
Status status = (Status) cloneCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test")); Status status = (Status) cloneCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
assertTrue(status != null && status == Status.OK); assertTrue(status != null && status == Status.OK);
assertEquals(link.getName(), "linkname"); assertEquals(link.getName(), "linkname");
assertEquals(link.getConnectorLinkConfig("CONFIGFROMNAME").getStringInput("CONFIGFROMNAME.String").getValue(), "abc"); assertEquals(link.getConnectorLinkConfig("CONFIGFROMNAME").getStringInput("CONFIGFROMNAME.String").getValue(), "abc");

View File

@ -54,14 +54,14 @@ public void setup() {
public void testDeleteLink() { public void testDeleteLink() {
doNothing().when(client).deleteLink("link_test"); doNothing().when(client).deleteLink("link_test");
// delete link -l link_test // delete link -name link_test
Status status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_LINK, "-l", "link_test")); Status status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
Assert.assertTrue(status != null && status == Status.OK); Assert.assertTrue(status != null && status == Status.OK);
// Missing argument for option lid // Missing argument for option name
try { try {
status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid")); status = (Status) deleteCmd.execute(Arrays.asList(Constants.FN_LINK, "-name"));
Assert.fail("Delete link should fail as link id/name is missing!"); Assert.fail("Delete link should fail as link name is missing!");
} catch (SqoopException e) { } catch (SqoopException e) {
Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode()); Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
Assert.assertTrue(e.getMessage().contains("Missing argument for option")); Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
@ -73,7 +73,7 @@ public void testDeleteLinkWithNonExistingLink() {
doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "link doesn't exist")).when(client).deleteLink(any(String.class)); doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "link doesn't exist")).when(client).deleteLink(any(String.class));
try { try {
deleteCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test")); deleteCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
Assert.fail("Delete link should fail as requested link doesn't exist!"); Assert.fail("Delete link should fail as requested link doesn't exist!");
} catch (SqoopException e) { } catch (SqoopException e) {
Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode()); Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());

View File

@ -53,14 +53,14 @@ public void setup() {
public void testDisableLink() { public void testDisableLink() {
doNothing().when(client).enableLink("link_test", false); doNothing().when(client).enableLink("link_test", false);
// disable link -l link_test // disable link -name link_test
Status status = (Status) disableCmd.execute(Arrays.asList(Constants.FN_LINK, "-l", "link_test")); Status status = (Status) disableCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
Assert.assertTrue(status != null && status == Status.OK); Assert.assertTrue(status != null && status == Status.OK);
// Missing argument for option lid // Missing argument for option name
try { try {
status = (Status) disableCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid")); status = (Status) disableCmd.execute(Arrays.asList(Constants.FN_LINK, "-name"));
Assert.fail("Disable link should fail as link id/name is missing!"); Assert.fail("Disable link should fail as link name is missing!");
} catch (SqoopException e) { } catch (SqoopException e) {
Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode()); Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
Assert.assertTrue(e.getMessage().contains("Missing argument for option")); Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
@ -72,7 +72,7 @@ public void testDisableLinkWithNonExistingLink() {
doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "link doesn't exist")).when(client).enableLink(any(String.class), any(Boolean.class)); doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "link doesn't exist")).when(client).enableLink(any(String.class), any(Boolean.class));
try { try {
disableCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test")); disableCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
Assert.fail("Disable link should fail as requested link doesn't exist!"); Assert.fail("Disable link should fail as requested link doesn't exist!");
} catch (SqoopException e) { } catch (SqoopException e) {
Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode()); Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());

View File

@ -53,14 +53,14 @@ public void setup() {
public void testEnableLink() { public void testEnableLink() {
doNothing().when(client).enableLink("link_test", true); doNothing().when(client).enableLink("link_test", true);
// enable link -l link_test // enable link -name link_test
Status status = (Status) enableCmd.execute(Arrays.asList(Constants.FN_LINK, "-l", "link_test")); Status status = (Status) enableCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
Assert.assertTrue(status != null && status == Status.OK); Assert.assertTrue(status != null && status == Status.OK);
// Missing argument for option lid // Missing argument for option name
try { try {
status = (Status) enableCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid")); status = (Status) enableCmd.execute(Arrays.asList(Constants.FN_LINK, "-name"));
Assert.fail("Enable link should fail as link id/name is missing!"); Assert.fail("Enable link should fail as link name is missing!");
} catch (SqoopException e) { } catch (SqoopException e) {
Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode()); Assert.assertEquals(ShellError.SHELL_0003, e.getErrorCode());
Assert.assertTrue(e.getMessage().contains("Missing argument for option")); Assert.assertTrue(e.getMessage().contains("Missing argument for option"));
@ -72,7 +72,7 @@ public void testEnableLinkWithNonExistingLink() {
doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "link doesn't exist")).when(client).enableLink(any(String.class), any(Boolean.class)); doThrow(new SqoopException(TestShellError.TEST_SHELL_0000, "link doesn't exist")).when(client).enableLink(any(String.class), any(Boolean.class));
try { try {
enableCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test")); enableCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
Assert.fail("Enable link should fail as requested link doesn't exist!"); Assert.fail("Enable link should fail as requested link doesn't exist!");
} catch (SqoopException e) { } catch (SqoopException e) {
Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode()); Assert.assertEquals(TestShellError.TEST_SHELL_0000, e.getErrorCode());

View File

@ -201,15 +201,16 @@ public void testShowDriver() {
@Test @Test
public void testShowLink() { public void testShowLink() {
MLink fakeLink = new MLink("connector_test", new MLinkConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()));
fakeLink.setName("linkName");
when(client.getLinks()).thenReturn(new ArrayList<MLink>()); when(client.getLinks()).thenReturn(new ArrayList<MLink>());
when(client.getLink(any(String.class))).thenReturn(new MLink("connector_test", new MLinkConfig(new ArrayList<MConfig>(), new ArrayList<MValidator>()))); when(client.getLink(any(String.class))).thenReturn(fakeLink);
// show link summary // show link summary
out.reset(); out.reset();
Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_LINK)); Status status = (Status) showCmd.execute(Arrays.asList(Constants.FN_LINK));
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("Connector Name")); Assert.assertTrue(str.contains("Connector Name"));
Assert.assertTrue(str.contains("Enabled")); Assert.assertTrue(str.contains("Enabled"));
@ -221,12 +222,12 @@ public void testShowLink() {
str = new String(out.toByteArray()); str = new String(out.toByteArray());
Assert.assertTrue(str.contains("link(s) to show:")); Assert.assertTrue(str.contains("link(s) to show:"));
// show link -lid 1 // show link -name linkName
out.reset(); out.reset();
status = (Status) showCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "1")); status = (Status) showCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "linkName"));
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("link with id")); Assert.assertTrue(str.contains("link with name"));
} }
@Test @Test

View File

@ -110,20 +110,20 @@ public void testUpdateLink() throws InterruptedException {
when(client.getConnectorConfigBundle("connector_test")).thenReturn(new MapResourceBundle(new HashMap())); when(client.getConnectorConfigBundle("connector_test")).thenReturn(new MapResourceBundle(new HashMap()));
when(client.updateLink(any(MLink.class))).thenReturn(Status.OK); when(client.updateLink(any(MLink.class))).thenReturn(Status.OK);
// update link -lid link_test // update link -name link_test
Status status = (Status) updateCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test")); Status status = (Status) updateCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
assertTrue(status != null && status == Status.OK); assertTrue(status != null && status == Status.OK);
// Missing argument for option lid // Missing argument for option name
try { try {
updateCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid")); updateCmd.execute(Arrays.asList(Constants.FN_LINK, "-name"));
fail("Update link should fail as parameters aren't complete!"); fail("Update link should fail as parameters aren't complete!");
} 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"));
} }
// Missing option lid // Missing option name
try { try {
updateCmd.execute(Arrays.asList(Constants.FN_LINK)); updateCmd.execute(Arrays.asList(Constants.FN_LINK));
fail("Update link should fail as option lid is missing"); fail("Update link should fail as option lid is missing");
@ -143,7 +143,7 @@ public void testUpdateLinkInteractive() throws Exception {
when(client.updateLink(any(MLink.class))).thenReturn(Status.OK); when(client.updateLink(any(MLink.class))).thenReturn(Status.OK);
when(client.getConnectorConfigBundle(any(String.class))).thenReturn(resourceBundle); when(client.getConnectorConfigBundle(any(String.class))).thenReturn(resourceBundle);
// update link -lid link_test // update link -name link_test
initData("linkname\r" + // link name initData("linkname\r" + // link name
"abc\r" + // for input with name "String" "abc\r" + // for input with name "String"
"12345\r" + // for input with name "Integer" "12345\r" + // for input with name "Integer"
@ -153,7 +153,7 @@ public void testUpdateLinkInteractive() throws Exception {
"0\r" + // for input with name "Enum" "0\r" + // for input with name "Enum"
"l1\rl2\rl3\r\r" + // for input with name "List" "l1\rl2\rl3\r\r" + // for input with name "List"
"12345678\r"); // for input with name "DateTime" "12345678\r"); // for input with name "DateTime"
Status status = (Status) updateCmd.execute(Arrays.asList(Constants.FN_LINK, "-lid", "link_test")); Status status = (Status) updateCmd.execute(Arrays.asList(Constants.FN_LINK, "-name", "link_test"));
assertTrue(status != null && status == Status.OK); assertTrue(status != null && status == Status.OK);
assertEquals(link.getName(), "linkname"); assertEquals(link.getName(), "linkname");
assertEquals(link.getConnectorLinkConfig("CONFIGFROMNAME").getStringInput("CONFIGFROMNAME.String").getValue(), "abc"); assertEquals(link.getConnectorLinkConfig("CONFIGFROMNAME").getStringInput("CONFIGFROMNAME.String").getValue(), "abc");