Skip to content

Commit a7a3fea

Browse files
Bruce Irschickbirschick-bq
andauthored
[AD-1049] Refactor internal SSH tunnel to be single-instance per process. (#472)
* [AD-1049] Refactor internal SSH tunnel to be single-instance per process. * [AD-1049] Fix portability of connection timeout test. * Commit Code Coverage Badge * Commit Code Coverage Badge * [AD-1049] Corrected tracing text to be more consistent. * Commit Code Coverage Badge * [AD-1049] Improved readability of close code. * Commit Code Coverage Badge * [AD-1049] Code review improvements. * Commit Code Coverage Badge * [AD-1049] Code review improvements #2. * Commit Code Coverage Badge * [AD-1049] Remove unused InterruptedException. * Commit Code Coverage Badge Co-authored-by: birschick-bq <birschick-bq@users.noreply.github.com>
1 parent 74523f9 commit a7a3fea

15 files changed

+737
-2113
lines changed

.github/badges/branches.svg

Lines changed: 1 addition & 1 deletion
Loading

.github/badges/jacoco.svg

Lines changed: 1 addition & 1 deletion
Loading

src/main/java/software/amazon/documentdb/jdbc/DocumentDbMain.java

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchemaColumn;
5858
import software.amazon.documentdb.jdbc.metadata.DocumentDbSchemaTable;
5959
import software.amazon.documentdb.jdbc.persist.DocumentDbSchemaSecurityException;
60-
import software.amazon.documentdb.jdbc.sshtunnel.DocumentDbSshTunnelService;
6160

6261
import java.io.Console;
6362
import java.io.File;
@@ -118,7 +117,6 @@ public class DocumentDbMain {
118117
private static final Options HELP_VERSION_OPTIONS;
119118
private static final Option HELP_OPTION;
120119
private static final Option VERSION_OPTION;
121-
private static final Options SSH_TUNNEL_SERVICE_OPTIONS;
122120
private static final OptionGroup COMMAND_OPTIONS;
123121
private static final List<Option> REQUIRED_OPTIONS;
124122
private static final List<Option> OPTIONAL_OPTIONS;
@@ -161,7 +159,6 @@ public class DocumentDbMain {
161159
private static final String USER_OPTION_FLAG = "u";
162160
private static final String USER_OPTION_NAME = "user";
163161
private static final String VERSION_OPTION_NAME = "version";
164-
public static final String SSH_TUNNEL_SERVICE_OPTION_NAME = "ssh-tunnel-service";
165162
// Option argument string constants
166163
private static final String DATABASE_NAME_ARG_NAME = "database-name";
167164
private static final String FILE_NAME_ARG_NAME = "file-name";
@@ -170,7 +167,6 @@ public class DocumentDbMain {
170167
private static final String METHOD_ARG_NAME = "method";
171168
private static final String USER_NAME_ARG_NAME = "user-name";
172169
private static final String TABLE_NAMES_ARG_NAME = "[table-name[,...]]";
173-
private static final String SSH_TUNNEL_SERVICE_ARG_NAME = "ssh-properties";
174170
// Option description string constants
175171
private static final String GENERATE_NEW_OPTION_DESCRIPTION =
176172
"Generates a new schema for the database. "
@@ -230,8 +226,6 @@ public class DocumentDbMain {
230226
private static final String OUTPUT_OPTION_DESCRIPTION =
231227
"Write the exported schema to <file-name> in your home directory (instead of stdout)."
232228
+ " This will overwrite any existing file with the same name";
233-
private static final String SSH_TUNNEL_SERVICE_OPTION_DESCRIPTION =
234-
"Starts an SSH Tunnel service.";
235229
// Messages string constants
236230
public static final String DUPLICATE_COLUMN_KEY_DETECTED_FOR_TABLE_SCHEMA =
237231
"Duplicate column key '%s' detected for table schema '%s'. Original column '%s'."
@@ -247,7 +241,6 @@ public class DocumentDbMain {
247241
LIBRARY_NAME = getLibraryName();
248242
HELP_OPTION = buildHelpOption();
249243
VERSION_OPTION = buildVersionOption();
250-
SSH_TUNNEL_SERVICE_OPTIONS = buildSshTunnelServiceOption();
251244
COMMAND_OPTIONS = buildCommandOptions();
252245
REQUIRED_OPTIONS = buildRequiredOptions();
253246
OPTIONAL_OPTIONS = buildOptionalOptions();
@@ -348,13 +341,6 @@ static void handleCommandLine(final String[] args, final StringBuilder output)
348341
}
349342
try {
350343
final CommandLineParser parser = new DefaultParser();
351-
// First check for the SSH tunnel service option separately from the other options.
352-
final CommandLine commandLineSshTunnelService = parser.parse(SSH_TUNNEL_SERVICE_OPTIONS, args, true);
353-
if (commandLineSshTunnelService.hasOption(SSH_TUNNEL_SERVICE_OPTION_NAME)) {
354-
performSshTunnelService(commandLineSshTunnelService, output);
355-
return;
356-
}
357-
// Otherwise, consider the "complete" options for metadata options.
358344
final CommandLine commandLine = parser.parse(COMPLETE_OPTIONS, args);
359345
final DocumentDbConnectionProperties properties = new DocumentDbConnectionProperties();
360346
if (!tryGetConnectionProperties(commandLine, properties, output)) {
@@ -420,30 +406,6 @@ private static void closeClient() {
420406
}
421407
}
422408

423-
private static void performSshTunnelService(
424-
final CommandLine commandLine,
425-
final StringBuilder output) throws DuplicateKeyException {
426-
try (DocumentDbSshTunnelService service = new DocumentDbSshTunnelService(
427-
commandLine.getOptionValue(SSH_TUNNEL_SERVICE_OPTION_NAME))) {
428-
final Thread serviceThread = new Thread(service);
429-
serviceThread.setDaemon(true);
430-
serviceThread.start();
431-
do {
432-
serviceThread.join(1000);
433-
} while (serviceThread.isAlive());
434-
service.getExceptions().forEach(
435-
e -> output
436-
.append(e.getMessage())
437-
.append(System.lineSeparator())
438-
.append(Arrays.stream(e.getStackTrace())
439-
.map(StackTraceElement::toString)
440-
.collect(Collectors.joining(System.lineSeparator())))
441-
.append(System.lineSeparator()));
442-
} catch (Exception e) {
443-
output.append(e.getMessage());
444-
}
445-
}
446-
447409
private static void performImport(
448410
final CommandLine commandLine,
449411
final DocumentDbConnectionProperties properties,
@@ -1034,16 +996,6 @@ private static Option buildVersionOption() {
1034996
.build();
1035997
}
1036998

1037-
private static Options buildSshTunnelServiceOption() {
1038-
return new Options().addOption(
1039-
Option.builder()
1040-
.longOpt(SSH_TUNNEL_SERVICE_OPTION_NAME)
1041-
.desc(SSH_TUNNEL_SERVICE_OPTION_DESCRIPTION)
1042-
.numberOfArgs(1)
1043-
.argName(SSH_TUNNEL_SERVICE_ARG_NAME)
1044-
.build());
1045-
}
1046-
1047999
private static Option buildHelpOption() {
10481000
return Option.builder(HELP_OPTION_FLAG)
10491001
.longOpt(HELP_OPTION_NAME)

src/main/java/software/amazon/documentdb/jdbc/sshtunnel/DocumentDbMultiThreadFileChannel.java

Lines changed: 0 additions & 143 deletions
This file was deleted.

0 commit comments

Comments
 (0)