Search in sources :

Example 6 with ClientImpl

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);
    }
}
Also used : ClientImpl(org.voltdb.client.ClientImpl) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ClientConfig(org.voltdb.client.ClientConfig) Client(org.voltdb.client.Client)

Example 7 with ClientImpl

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();
    }
}
Also used : ClientImpl(org.voltdb.client.ClientImpl) IOException(java.io.IOException)

Example 8 with ClientImpl

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;
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) NoConnectionsException(org.voltdb.client.NoConnectionsException) ClientImpl(org.voltdb.client.ClientImpl)

Example 9 with ClientImpl

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;
}
Also used : UnknownHostException(java.net.UnknownHostException) ClientImpl(org.voltdb.client.ClientImpl) IOException(java.io.IOException)

Example 10 with ClientImpl

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 = '';
    }
    configuration();
    final Tokenizer tokenizer;
    ICsvListReader listReader = null;
    try {
        if (CSVLoader.standin) {
            tokenizer = new Tokenizer(new BufferedReader(new InputStreamReader(System.in)), csvPreference, config.strictquotes, config.escape, config.columnsizelimit, config.skip, config.header);
            listReader = new CsvListReader(tokenizer, csvPreference);
        } else {
            tokenizer = new Tokenizer(new FileReader(config.file), csvPreference, config.strictquotes, config.escape, config.columnsizelimit, config.skip, config.header);
            listReader = new CsvListReader(tokenizer, csvPreference);
        }
    } catch (FileNotFoundException e) {
        m_log.error("CSV file '" + config.file + "' could not be found.");
        System.exit(-1);
    }
    // Split server list
    final String[] serverlist = config.servers.split(",");
    // If we need to prompt the user for a password, do so.
    config.password = CLIConfig.readPasswordIfNeeded(config.user, config.password, "Enter password: ");
    // Create connection
    final ClientConfig c_config = new ClientConfig(config.user, config.password, null);
    if (config.ssl != null && !config.ssl.trim().isEmpty()) {
        c_config.setTrustStoreConfigFromPropertyFile(config.ssl);
        c_config.enableSSL();
    }
    // Set procedure all to infinite
    c_config.setProcedureCallTimeout(0);
    Client csvClient = null;
    try {
        csvClient = CSVLoader.getClient(c_config, serverlist, config.port);
    } catch (Exception e) {
        m_log.error("Error connecting to the servers: " + config.servers);
        System.exit(-1);
    }
    assert (csvClient != null);
    try {
        long readerTime;
        long insertCount;
        long ackCount;
        long rowsQueued;
        final CSVLoader errHandler = new CSVLoader();
        final CSVDataLoader dataLoader;
        errHandler.launchErrorFlushProcessor();
        if (config.useSuppliedProcedure) {
            dataLoader = new CSVTupleDataLoader((ClientImpl) csvClient, config.procedure, errHandler);
        } else {
            dataLoader = new CSVBulkDataLoader((ClientImpl) csvClient, config.table, config.batch, config.update, errHandler);
        }
        CSVFileReader.initializeReader(cfg, csvClient, listReader);
        CSVFileReader csvReader = new CSVFileReader(dataLoader, errHandler);
        Thread readerThread = new Thread(csvReader);
        readerThread.setName("CSVFileReader");
        readerThread.setDaemon(true);
        //Wait for reader to finish.
        readerThread.start();
        readerThread.join();
        insertTimeEnd = System.currentTimeMillis();
        csvClient.close();
        errHandler.waitForErrorFlushComplete();
        readerTime = (csvReader.m_parsingTime) / 1000000;
        insertCount = dataLoader.getProcessedRows();
        ackCount = insertCount - dataLoader.getFailedRows();
        rowsQueued = CSVFileReader.m_totalRowCount.get();
        //Close the reader.
        try {
            listReader.close();
        } catch (Exception ex) {
            m_log.error("Error closing reader: " + ex);
        } finally {
            m_log.debug("Rows Queued by Reader: " + rowsQueued);
        }
        if (errHandler.hasReachedErrorLimit()) {
            m_log.warn("The number of failed rows exceeds the configured maximum failed rows: " + config.maxerrors);
        }
        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 (!CSVLoader.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);
    }
}
Also used : CsvListReader(org.supercsv.io.CsvListReader) ICsvListReader(org.supercsv.io.ICsvListReader) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) ClientImpl(org.voltdb.client.ClientImpl) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) ICsvListReader(org.supercsv.io.ICsvListReader) FileReader(java.io.FileReader) ClientConfig(org.voltdb.client.ClientConfig) Client(org.voltdb.client.Client) Tokenizer(org.supercsv_voltpatches.tokenizer.Tokenizer)

Aggregations

ClientImpl (org.voltdb.client.ClientImpl)10 IOException (java.io.IOException)6 ClientConfig (org.voltdb.client.ClientConfig)4 FileNotFoundException (java.io.FileNotFoundException)2 Client (org.voltdb.client.Client)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 UnknownHostException (java.net.UnknownHostException)1 Test (org.junit.Test)1 CsvListReader (org.supercsv.io.CsvListReader)1 ICsvListReader (org.supercsv.io.ICsvListReader)1 Tokenizer (org.supercsv_voltpatches.tokenizer.Tokenizer)1 Configuration (org.voltdb.VoltDB.Configuration)1 ClientResponse (org.voltdb.client.ClientResponse)1 NoConnectionsException (org.voltdb.client.NoConnectionsException)1 ProcCallException (org.voltdb.client.ProcCallException)1 ProcedureCallback (org.voltdb.client.ProcedureCallback)1 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)1