Skip to content

Commit dd640ea

Browse files
use non-zero exit code on exception
1 parent 0c961b9 commit dd640ea

File tree

3 files changed

+271
-181
lines changed

3 files changed

+271
-181
lines changed

pom.xml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,29 @@
5151
<artifactId>log4j-core</artifactId>
5252
<version>2.22.1</version>
5353
</dependency>
54+
5455
<!-- junit -->
5556
<dependency>
56-
<groupId>junit</groupId>
57-
<artifactId>junit</artifactId>
58-
<version>4.13.1</version>
57+
<groupId>org.junit.jupiter</groupId>
58+
<artifactId>junit-jupiter-api</artifactId>
59+
<version>5.11.4</version>
60+
<scope>test</scope>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.junit.jupiter</groupId>
65+
<artifactId>junit-jupiter-engine</artifactId>
66+
<version>5.11.4</version>
5967
<scope>test</scope>
6068
</dependency>
69+
70+
<dependency>
71+
<groupId>com.github.stefanbirkner</groupId>
72+
<artifactId>system-lambda</artifactId>
73+
<version>1.2.1</version>
74+
<scope>test</scope>
75+
</dependency>
76+
6177
<!-- JSON -->
6278
<dependency>
6379
<groupId>com.googlecode.json-simple</groupId>

src/main/java/com/aerospike/load/AerospikeLoad.java

Lines changed: 139 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.commons.cli.CommandLineParser;
4242
import org.apache.commons.cli.HelpFormatter;
4343
import org.apache.commons.cli.Options;
44+
import org.apache.commons.cli.ParseException;
4445
import org.apache.commons.cli.PosixParser;
4546
import org.apache.logging.log4j.Level;
4647
import org.apache.logging.log4j.LogManager;
@@ -104,143 +105,145 @@ private static void printVersion()
104105
}
105106
}
106107

107-
public static void main(String[] args) throws IOException {
108-
long processStart = System.currentTimeMillis();
108+
public static void main(String[] args) throws IOException {
109+
int exitCode = -1;
110+
try {
111+
CommandLine cl = parseArgs(args);
112+
exitCode = launch(cl);
113+
} catch (Exception e) {
114+
if (log.isDebugEnabled()) {
115+
e.printStackTrace();
116+
}
117+
}
118+
System.exit(exitCode);
119+
}
120+
121+
public static int launch(CommandLine cl) throws Exception {
122+
long processStart = System.currentTimeMillis();
123+
124+
AerospikeClient client = null;
125+
statPrinter = new Thread(new PrintStat(counters));
126+
// Create Abstract derived params from provided commandline params.
127+
params = Utils.parseParameters(cl);
128+
if (params.verbose) {
129+
Configurator.setAllLevels(LogManager.getRootLogger().getName(), Level.DEBUG);
130+
}
131+
132+
initReadWriteThreadCnt(cl);
133+
134+
// Get and validate user roles for client.
135+
client = getAerospikeClient(cl);
136+
if (client == null) {
137+
return -1;
138+
}
139+
140+
List<String> dataFileNames = new ArrayList<String>();
141+
initDataFileNameList(cl, dataFileNames);
142+
if (dataFileNames.size() == 0) {
143+
return -1;
144+
}
145+
146+
// Remove column definition file from list. if directory containing config file is passed.
147+
String columnDefinitionFileName = cl.getOptionValue("c", "");
148+
dataFileNames.remove(columnDefinitionFileName);
149+
log.info("Number of data files:" + dataFileNames.size());
150+
151+
initBytesToRead(dataFileNames);
152+
153+
log.info("Aerospike loader started");
154+
// Perform main Read Write job.
155+
runLoader(client, columnDefinitionFileName, dataFileNames);
156+
157+
// Stop statistic printer thread.
158+
statPrinter.interrupt();
159+
log.info("Aerospike loader completed");
160+
if (client != null) {
161+
client.close();
162+
}
163+
164+
long processStop = System.currentTimeMillis();
165+
log.info(String.format("Loader completed in %.3fsec", (float) (processStop - processStart) / 1000));
166+
return 0;
167+
}
168+
169+
public static CommandLine parseArgs(String[] args) throws ParseException {
170+
counters = new Counter();
171+
CommandLine cl;
172+
173+
Options options = new Options();
174+
options.addOption("h", "hosts", true,
175+
"List of seed hosts in format:\n" +
176+
"hostname1[:tlsname][:port1],...\n" +
177+
"The tlsname is only used when connecting with a secure TLS enabled server. " +
178+
"If the port is not specified, the default port is used.\n" +
179+
"IPv6 addresses must be enclosed in square brackets.\n" +
180+
"Default: localhost\n" +
181+
"Examples:\n" +
182+
"host1\n" +
183+
"host1:3000,host2:3000\n" +
184+
"192.168.1.10:cert1:3000,[2001::1111]:cert2:3000\n"
185+
);
186+
options.addOption("V", "version", false, "Aerospike Loader Version");
187+
options.addOption("p", "port", true, "Server port (default: 3000)");
188+
options.addOption("U", "user", true, "User name");
189+
options.addOption("P", "password", true, "Password");
190+
options.addOption("n", "namespace", true, "Namespace (default: test)");
191+
options.addOption("c", "config", true, "Column definition file name");
192+
options.addOption("g", "max-throughput", true, "It limit numer of writes/sec in aerospike.");
193+
options.addOption("T", "transaction-timeout", true, "write transaction timeout in milliseconds(default: No timeout)");
194+
options.addOption("e", "expirationTime", true,
195+
"Set expiration time of each record in seconds." +
196+
" -1: Never expire, " +
197+
" 0: Default to namespace," +
198+
" >0: Actual given expiration time"
199+
);
200+
options.addOption("tz", "timezone", true, "Timezone of source where data dump is taken (default: local timezone)");
201+
options.addOption("ec", "abort-error-count", true, "Error count to abort (default: 0)");
202+
options.addOption("wa", "write-action", true, "Write action if key already exists (default: update)");
203+
options.addOption("sa", "services_alternate", false, "Enable alternate services.");
204+
options.addOption("tls", "tls-enable", false, "Use TLS/SSL sockets");
205+
options.addOption("tp", "tls-protocols", true,
206+
"Allow TLS protocols\n" +
207+
"Values: TLSv1,TLSv1.1,TLSv1.2 separated by comma\n" +
208+
"Default: TLSv1.2"
209+
);
210+
options.addOption("tlsCiphers", "tls-cipher-suite", true,
211+
"Allow TLS cipher suites\n" +
212+
"Values: cipher names defined by JVM separated by comma\n" +
213+
"Default: null (default cipher list provided by JVM)"
214+
);
215+
options.addOption("tr", "tlsRevoke", true,
216+
"Revoke certificates identified by their serial number\n" +
217+
"Values: serial numbers separated by comma\n" +
218+
"Default: null (Do not revoke certificates)"
219+
);
220+
221+
options.addOption("tlsLoginOnly", false, "Use TLS/SSL sockets on node login only");
222+
options.addOption("auth", true, "Authentication mode. Values: " + Arrays.toString(AuthMode.values()));
223+
224+
options.addOption("uk", "send-user-key", false,
225+
"Send user defined key in addition to hash digest to store on the server. (default: userKey is not sent to reduce meta-data overhead)"
226+
);
227+
options.addOption("v", "verbose", false, "Logging all");
228+
options.addOption("um", "unorderdMaps", false, "Write all maps as unorderd maps");
229+
options.addOption("u", "usage", false, "Print usage.");
230+
231+
CommandLineParser parser = new PosixParser();
232+
cl = parser.parse(options, args, false);
233+
234+
if (args.length == 0 || cl.hasOption("u")) {
235+
printUsage(options);
236+
return cl;
237+
}
238+
239+
if (cl.hasOption("V")) {
240+
printVersion();
241+
return cl;
242+
}
243+
244+
return cl;
245+
}
109246

110-
AerospikeClient client = null;
111-
counters = new Counter();
112-
CommandLine cl;
113-
114-
try {
115-
Options options = new Options();
116-
options.addOption("h", "hosts", true,
117-
"List of seed hosts in format:\n" +
118-
"hostname1[:tlsname][:port1],...\n" +
119-
"The tlsname is only used when connecting with a secure TLS enabled server. " +
120-
"If the port is not specified, the default port is used.\n" +
121-
"IPv6 addresses must be enclosed in square brackets.\n" +
122-
"Default: localhost\n" +
123-
"Examples:\n" +
124-
"host1\n" +
125-
"host1:3000,host2:3000\n" +
126-
"192.168.1.10:cert1:3000,[2001::1111]:cert2:3000\n"
127-
);
128-
options.addOption("V", "version", false, "Aerospike Loader Version");
129-
options.addOption("p", "port", true, "Server port (default: 3000)");
130-
options.addOption("U", "user", true, "User name");
131-
options.addOption("P", "password", true, "Password");
132-
options.addOption("n", "namespace", true, "Namespace (default: test)");
133-
options.addOption("c", "config", true, "Column definition file name");
134-
options.addOption("g", "max-throughput", true, "It limit numer of writes/sec in aerospike.");
135-
options.addOption("T", "transaction-timeout", true, "write transaction timeout in milliseconds(default: No timeout)");
136-
options.addOption("e", "expirationTime", true,
137-
"Set expiration time of each record in seconds." +
138-
" -1: Never expire, " +
139-
" 0: Default to namespace," +
140-
" >0: Actual given expiration time"
141-
);
142-
options.addOption("tz", "timezone", true, "Timezone of source where data dump is taken (default: local timezone)");
143-
options.addOption("ec", "abort-error-count", true, "Error count to abort (default: 0)");
144-
options.addOption("wa", "write-action", true, "Write action if key already exists (default: update)");
145-
options.addOption("sa", "services_alternate", false, "Enable alternate services.");
146-
options.addOption("tls", "tls-enable", false, "Use TLS/SSL sockets");
147-
options.addOption("tp", "tls-protocols", true,
148-
"Allow TLS protocols\n" +
149-
"Values: TLSv1,TLSv1.1,TLSv1.2 separated by comma\n" +
150-
"Default: TLSv1.2"
151-
);
152-
options.addOption("tlsCiphers", "tls-cipher-suite", true,
153-
"Allow TLS cipher suites\n" +
154-
"Values: cipher names defined by JVM separated by comma\n" +
155-
"Default: null (default cipher list provided by JVM)"
156-
);
157-
options.addOption("tr", "tlsRevoke", true,
158-
"Revoke certificates identified by their serial number\n" +
159-
"Values: serial numbers separated by comma\n" +
160-
"Default: null (Do not revoke certificates)"
161-
);
162-
163-
options.addOption("tlsLoginOnly", false, "Use TLS/SSL sockets on node login only");
164-
options.addOption("auth", true, "Authentication mode. Values: " + Arrays.toString(AuthMode.values()));
165-
166-
options.addOption("uk", "send-user-key", false,
167-
"Send user defined key in addition to hash digest to store on the server. (default: userKey is not sent to reduce meta-data overhead)"
168-
);
169-
options.addOption("v", "verbose", false, "Logging all");
170-
options.addOption("um", "unorderdMaps", false, "Write all maps as unorderd maps");
171-
options.addOption("u", "usage", false, "Print usage.");
172-
173-
CommandLineParser parser = new PosixParser();
174-
cl = parser.parse(options, args, false);
175-
176-
if (args.length == 0 || cl.hasOption("u")) {
177-
printUsage(options);
178-
return;
179-
}
180-
181-
if (cl.hasOption("V")) {
182-
printVersion();
183-
return;
184-
}
185-
} catch (Exception e) {
186-
log.error(e);
187-
if (log.isDebugEnabled()) {
188-
e.printStackTrace();
189-
}
190-
return;
191-
}
192-
193-
try {
194-
statPrinter = new Thread(new PrintStat(counters));
195-
// Create Abstract derived params from provided commandline params.
196-
params = Utils.parseParameters(cl);
197-
if (params.verbose) {
198-
Configurator.setAllLevels(LogManager.getRootLogger().getName(), Level.DEBUG);
199-
}
200-
201-
initReadWriteThreadCnt(cl);
202-
203-
// Get and validate user roles for client.
204-
client = getAerospikeClient(cl);
205-
if (client == null) {
206-
return;
207-
}
208-
209-
List<String> dataFileNames = new ArrayList<String>();
210-
initDataFileNameList(cl, dataFileNames);
211-
if (dataFileNames.size() == 0) {
212-
return;
213-
}
214-
215-
// Remove column definition file from list. if directory containing config file is passed.
216-
String columnDefinitionFileName = cl.getOptionValue("c", "");
217-
dataFileNames.remove(columnDefinitionFileName);
218-
log.info("Number of data files:" + dataFileNames.size());
219-
220-
initBytesToRead(dataFileNames);
221-
222-
log.info("Aerospike loader started");
223-
// Perform main Read Write job.
224-
runLoader(client, columnDefinitionFileName, dataFileNames);
225-
226-
} catch (Exception e) {
227-
log.error(e);
228-
if (log.isDebugEnabled()) {
229-
e.printStackTrace();
230-
}
231-
} finally {
232-
// Stop statistic printer thread.
233-
statPrinter.interrupt();
234-
log.info("Aerospike loader completed");
235-
if (client != null) {
236-
client.close();
237-
}
238-
}
239-
240-
long processStop = System.currentTimeMillis();
241-
log.info(String.format("Loader completed in %.3fsec", (float) (processStop - processStart) / 1000));
242-
}
243-
244247
private static AerospikeClient getAerospikeClient(CommandLine cl) {
245248
ClientPolicy clientPolicy = new ClientPolicy();
246249

0 commit comments

Comments
 (0)