use of org.voltdb.client.ClientImpl in project voltdb by VoltDB.
the class JDBCLoader method main.
/**
* jdbcloader main. (main is directly used by tests as well be sure to reset statics that you need to start over)
*
* @param args
* @throws IOException
* @throws InterruptedException
*
*/
public static void main(String[] args) throws IOException, InterruptedException {
start = System.currentTimeMillis();
long insertTimeStart = start;
long insertTimeEnd;
final JDBCLoaderConfig cfg = new JDBCLoaderConfig();
cfg.parse(JDBCLoader.class.getName(), args);
m_config = cfg;
configuration();
// Split server list
final String[] serverlist = m_config.servers.split(",");
// If we need to prompt the user for a VoltDB password, do so.
m_config.password = CLIConfig.readPasswordIfNeeded(m_config.user, m_config.password, "Enter VoltDB password: ");
// Create connection
final ClientConfig c_config = new ClientConfig(m_config.user, m_config.password, null);
if (m_config.ssl != null && !m_config.ssl.trim().isEmpty()) {
c_config.setTrustStoreConfigFromPropertyFile(m_config.ssl);
c_config.enableSSL();
}
// Set procedure all to infinite
c_config.setProcedureCallTimeout(0);
Client csvClient = null;
try {
csvClient = JDBCLoader.getClient(c_config, serverlist, m_config.port);
} catch (Exception e) {
m_log.error("Error connecting to the servers: " + m_config.servers, e);
System.exit(-1);
}
assert (csvClient != null);
try {
long readerTime;
long insertCount;
long ackCount;
final JDBCLoader errHandler = new JDBCLoader();
final CSVDataLoader dataLoader;
errHandler.launchErrorFlushProcessor();
if (m_config.useSuppliedProcedure) {
dataLoader = new CSVTupleDataLoader((ClientImpl) csvClient, m_config.procedure, errHandler);
} else {
dataLoader = new CSVBulkDataLoader((ClientImpl) csvClient, m_config.table, m_config.batch, m_config.update, errHandler);
}
// If we need to prompt the user for a JDBC datasource password, do so.
m_config.jdbcpassword = CLIConfig.readPasswordIfNeeded(m_config.jdbcuser, m_config.jdbcpassword, "Enter JDBC source database password: ");
//Created Source reader
JDBCStatementReader.initializeReader(cfg, csvClient);
JDBCStatementReader jdbcReader = new JDBCStatementReader(dataLoader, errHandler);
Thread readerThread = new Thread(jdbcReader);
readerThread.setName("JDBCSourceReader");
readerThread.setDaemon(true);
//Wait for reader to finish.
readerThread.start();
readerThread.join();
insertTimeEnd = System.currentTimeMillis();
csvClient.close();
errHandler.waitForErrorFlushComplete();
readerTime = (jdbcReader.m_parsingTime) / 1000000;
insertCount = dataLoader.getProcessedRows();
ackCount = insertCount - dataLoader.getFailedRows();
if (errHandler.hasReachedErrorLimit()) {
m_log.warn("The number of failed rows exceeds the configured maximum failed rows: " + m_config.maxerrors);
}
if (m_log.isDebugEnabled()) {
m_log.debug("Parsing CSV file took " + readerTime + " milliseconds.");
m_log.debug("Inserting Data took " + ((insertTimeEnd - insertTimeStart) - readerTime) + " milliseconds.");
}
m_log.info("Read " + insertCount + " rows from file and successfully inserted " + ackCount + " rows (final)");
errHandler.produceFiles(ackCount, insertCount);
close_cleanup();
//In test junit mode we let it continue for reuse
if (!JDBCLoader.testMode) {
System.exit(errHandler.m_errorInfo.isEmpty() ? 0 : -1);
}
} catch (Exception ex) {
m_log.error("Exception Happened while loading CSV data", ex);
System.exit(1);
}
}
use of org.voltdb.client.ClientImpl in project voltdb by VoltDB.
the class TestAdhocCompilerException method tryNewClientWithValidDDL.
private void tryNewClientWithValidDDL() throws Exception {
// For fun see if a client can connect.
ClientImpl client = (ClientImpl) ClientFactory.createClient();
try {
client.createConnection("localhost");
tryValidDDL(client);
} catch (IOException e) {
fail("Additional client connection failed. " + e.getLocalizedMessage());
} finally {
client.close();
}
}
use of org.voltdb.client.ClientImpl in project voltdb by VoltDB.
the class JDBC4ClientConnection method executeAsync.
/**
* Executes a procedure asynchronously, returning a Future that can be used by the caller to
* wait upon completion before processing the server response.
*
* @param procedure
* the name of the procedure to call.
* @param parameters
* the list of parameters to pass to the procedure.
* @return the Future created to wrap around the asynchronous process.
*/
public Future<ClientResponse> executeAsync(String procedure, Object... parameters) throws NoConnectionsException, IOException {
ClientImpl currentClient = this.getClient();
final JDBC4ExecutionFuture future = new JDBC4ExecutionFuture(this.defaultAsyncTimeout);
try {
currentClient.callProcedure(new TrackingCallback(this, procedure, new ProcedureCallback() {
@SuppressWarnings("unused")
final JDBC4ExecutionFuture result;
{
this.result = future;
}
@Override
public void clientCallback(ClientResponse response) throws Exception {
future.set(response);
}
}), procedure, parameters);
} catch (NoConnectionsException e) {
this.dropClient(currentClient);
throw e;
}
return future;
}
use of org.voltdb.client.ClientImpl in project voltdb by VoltDB.
the class JDBC4ClientConnection method createClientAndConnect.
/**
* Private method to (re)initialize a client connection.
* @return new ClientImpl
* @throws UnknownHostException
* @throws IOException
*/
private ClientImpl createClientAndConnect() throws UnknownHostException, IOException {
// Make client connections.
ClientImpl clientTmp = (ClientImpl) ClientFactory.createClient(this.config);
// ENG-6231: Only fail if we can't connect to any of the provided servers.
boolean connectedAnything = false;
for (String server : this.servers) {
try {
clientTmp.createConnection(server);
connectedAnything = true;
} catch (UnknownHostException e) {
} catch (IOException e) {
}
}
if (!connectedAnything) {
try {
clientTmp.close();
} catch (InterruptedException ie) {
}
throw new IOException("Unable to connect to VoltDB cluster with servers: " + this.servers);
}
this.client.set(clientTmp);
this.users++;
return clientTmp;
}
use of org.voltdb.client.ClientImpl in project voltdb by VoltDB.
the class CSVLoader method main.
/**
* csvloader main. (main is directly used by tests as well be sure to reset statics that you need to start over)
*
* @param args
* @throws IOException
* @throws InterruptedException
*
*/
public static void main(String[] args) throws IOException, InterruptedException {
start = System.currentTimeMillis();
long insertTimeStart = start;
long insertTimeEnd;
final CSVConfig cfg = new CSVConfig();
cfg.parse(CSVLoader.class.getName(), args);
config = cfg;
if (config.noquotechar) {
config.quotechar = '