Search in sources :

Example 26 with ClientConfig

use of org.voltdb.client.ClientConfig in project voltdb by VoltDB.

the class RegressionSuite method getClientSha1.

/**
     * Get a VoltClient instance connected to the server driven by the
     * VoltServerConfig instance. Just pick from the list of listeners
     * randomly.
     *
     * Only uses the time
     *
     * @return A VoltClient instance connected to the server driven by the
     * VoltServerConfig instance.
     */
public Client getClientSha1(long timeout) throws IOException {
    final List<String> listeners = m_config.getListenerAddresses();
    final Random r = new Random();
    String listener = listeners.get(r.nextInt(listeners.size()));
    ClientConfig config = new ClientConfigForTest(m_username, m_password, ClientAuthScheme.HASH_SHA1);
    config.setConnectionResponseTimeout(timeout);
    config.setProcedureCallTimeout(timeout);
    final Client client = ClientFactory.createClient(config);
    // Use the port generated by LocalCluster if applicable
    try {
        client.createConnection(listener);
    }// retry once
     catch (ConnectException e) {
        listener = listeners.get(r.nextInt(listeners.size()));
        client.createConnection(listener);
    }
    m_clients.add(client);
    return client;
}
Also used : Random(java.util.Random) ClientConfig(org.voltdb.client.ClientConfig) ClientConfigForTest(org.voltdb.client.ClientConfigForTest) Client(org.voltdb.client.Client) ConnectException(java.net.ConnectException)

Example 27 with ClientConfig

use of org.voltdb.client.ClientConfig in project voltdb by VoltDB.

the class TestStatisticsSuiteDRStats method testDRPartitionStatisticsWithConsumers.

public void testDRPartitionStatisticsWithConsumers() throws Exception {
    if (!VoltDB.instance().getConfig().m_isEnterprise) {
        System.out.println("SKIPPING DRPRODUCERPARTITION STATS TESTS FOR COMMUNITY VERSION");
        return;
    }
    System.out.println("\n\nTESTING DRPRODUCERPARTITION STATS\n\n\n");
    Client primaryClient = getFullyConnectedClient();
    List<Client> consumerClients = new ArrayList<>();
    List<LocalCluster> consumerClusters = new ArrayList<>();
    VoltTable expectedTable1 = new VoltTable(expectedDRPartitionStatsSchema);
    ClientResponse cr = primaryClient.callProcedure("@AdHoc", "insert into employee values(1, 25);");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    // create a consumer cluster and connect to producer cluster so that there will be rows for partition stats
    String secondaryRoot = "/tmp/" + System.getProperty("user.name") + "-dr-stats-secondary";
    try {
        int CONSUMER_CLUSTER_COUNT = 2;
        for (int n = 1; n <= CONSUMER_CLUSTER_COUNT; n++) {
            LocalCluster consumerCluster = LocalCluster.createLocalCluster(drSchema, SITES, HOSTS, KFACTOR, n, REPLICATION_PORT + 100 * n, REPLICATION_PORT, secondaryRoot, jarName, true);
            ClientConfig clientConfig = new ClientConfig();
            clientConfig.setProcedureCallTimeout(10 * 60 * 1000);
            Client consumerClient = createClient(clientConfig, consumerCluster);
            consumerClusters.add(consumerCluster);
            consumerClients.add(consumerClient);
            boolean hasSnapshotData = false;
            for (int i = 0; i < 60; i++) {
                cr = consumerClient.callProcedure("@AdHoc", "select count(e_id) from employee;");
                assertEquals(ClientResponse.SUCCESS, cr.getStatus());
                VoltTable result = cr.getResults()[0];
                assertTrue(result.advanceRow());
                if (result.getLong(0) == 1) {
                    // get all snapshot records
                    hasSnapshotData = true;
                    break;
                }
                Thread.sleep(1000);
            }
            assertTrue(hasSnapshotData);
        }
        //
        // DRPARTITION
        //
        VoltTable[] results = primaryClient.callProcedure("@Statistics", "DRPRODUCERPARTITION", 0).getResults();
        // one aggregate tables returned
        assertEquals(1, results.length);
        System.out.println("Test DR table: " + results[0].toString());
        validateSchema(results[0], expectedTable1);
        // One row per site (including the MPI on each host),
        // don't have HSID for ease of check, just check a bunch of stuff
        assertEquals(CONSUMER_CLUSTER_COUNT * (HOSTS * SITES + HOSTS), results[0].getRowCount());
        results[0].advanceRow();
        Map<String, String> columnTargets = new HashMap<>();
        columnTargets.put("HOSTNAME", results[0].getString("HOSTNAME"));
        validateRowSeenAtAllHosts(results[0], columnTargets, false);
        validateRowSeenAtAllPartitions(results[0], "HOSTNAME", results[0].getString("HOSTNAME"), false);
    } finally {
        primaryClient.close();
        for (Client consumerClient : consumerClients) {
            if (consumerClient != null) {
                consumerClient.close();
            }
        }
        for (LocalCluster consumerCluster : consumerClusters) {
            if (consumerCluster != null) {
                consumerCluster.shutDown();
            }
        }
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) LocalCluster(org.voltdb.regressionsuites.LocalCluster) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VoltTable(org.voltdb.VoltTable) Client(org.voltdb.client.Client) ClientConfig(org.voltdb.client.ClientConfig)

Example 28 with ClientConfig

use of org.voltdb.client.ClientConfig in project voltdb by VoltDB.

the class ConnectionHelper method createConnection.

/**
     * Creates a factory used to connect to a VoltDB instance.
     * (Note that if a corresponding connection exists, all parameters other than 'servers' are ignored)
     * @param clientId A unique identifier for the connecting client
     * @param servers The comma separated list of VoltDB servers in hostname[:port] format that the instance will use.
     * @param user The username for the connection
     * @param password The password for the specified user
     * @param ratelimit A limit on the number of transactions per second for the VoltDB instance
     * @return The existing factory if a corresponding connection has already been created; the newly created
     * one otherwise.
     * @throws IOException Throws if a connection is already open with a different server string.
     * @throws InterruptedException
     */
public static synchronized Client createConnection(Long clientId, String servers, String user, String password, int ratelimit) throws IOException, InterruptedException {
    ClientConnection conn = clientMapping.get(clientId);
    if (conn != null) {
        return conn.m_client;
    }
    if (activeConnection != null && activeConnection.m_connectionCount.get() <= THREADS_PER_CLIENT) {
        activeConnection.connect();
        clientMapping.put(clientId, activeConnection);
        return activeConnection.m_client;
    }
    ClientConfig config = new ClientConfig(user, password);
    config.setMaxTransactionsPerSecond(ratelimit);
    Client client = ClientFactory.createClient(config);
    connect(client, servers);
    activeConnection = new ClientConnection(client);
    clientMapping.put(clientId, activeConnection);
    return client;
}
Also used : ClientConfig(org.voltdb.client.ClientConfig) Client(org.voltdb.client.Client)

Example 29 with ClientConfig

use of org.voltdb.client.ClientConfig 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)

Example 30 with ClientConfig

use of org.voltdb.client.ClientConfig in project voltdb by VoltDB.

the class TestSSL method ntestLocalClusterRejoin.

@Test
public void ntestLocalClusterRejoin() throws Exception {
    org.voltdb.utils.VoltFile.resetSubrootForThisProcess();
    VoltProjectBuilder builder = getBuilderForTest();
    builder.setKeyStoreInfo(getResourcePath(KEYSTORE_RESOURCE), KEYSTORE_PASSWD);
    builder.setCertStoreInfo(getResourcePath(KEYSTORE_RESOURCE), KEYSTORE_PASSWD);
    int sitesPerHost = 2;
    int hostCount = 3;
    int kFactor = 2;
    m_cluster = new LocalCluster("sslRejoin.jar", sitesPerHost, hostCount, kFactor, BackendTarget.NATIVE_EE_JNI, false);
    m_cluster.setMaxHeap(1400);
    m_cluster.overrideAnyRequestForValgrind();
    m_cluster.setHasLocalServer(false);
    boolean success = m_cluster.compile(builder);
    assertTrue(success);
    MiscUtils.copyFile(builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("sslRejoin.xml"));
    m_cluster.startUp();
    ClientConfig clientConfig = new ClientConfig("", "", null);
    clientConfig.setTrustStoreConfigFromPropertyFile(getResourcePath(SSL_PROPS_FILE));
    clientConfig.enableSSL();
    ClientResponse response;
    Client client;
    client = ClientFactory.createClient(clientConfig);
    client.createConnection("localhost", m_cluster.port(0));
    response = client.callProcedure("InsertA", 1, 1);
    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    response = client.callProcedure("CountA");
    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    assertEquals(1, response.getResults()[0].asScalarLong());
    client.drain();
    client.close();
    client = ClientFactory.createClient(clientConfig);
    client.createConnection("localhost", m_cluster.port(1));
    response = client.callProcedure("InsertA", 2, 2);
    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    response = client.callProcedure("CountA");
    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    assertEquals(2, response.getResults()[0].asScalarLong());
    client.drain();
    client.close();
    m_cluster.killSingleHost(0);
    Thread.sleep(100);
    VoltDB.Configuration config = new VoltDB.Configuration(m_cluster.portGenerator);
    config.m_startAction = m_cluster.isNewCli() ? StartAction.PROBE : StartAction.REJOIN;
    config.m_pathToCatalog = Configuration.getPathToCatalogForTest("sslRejoin.jar");
    if (m_cluster.isNewCli()) {
        config.m_voltdbRoot = new File(m_cluster.getServerSpecificRoot("0"));
        config.m_forceVoltdbCreate = false;
        config.m_hostCount = hostCount;
    }
    config.m_pathToDeployment = Configuration.getPathToCatalogForTest("sslRejoin.xml");
    config.m_leader = ":" + m_cluster.internalPort(1);
    config.m_coordinators = m_cluster.coordinators(1);
    config.m_isRejoinTest = true;
    m_cluster.setPortsFromConfig(0, config);
    m_server = new ServerThread(config);
    m_server.start();
    m_server.waitForRejoin();
    Thread.sleep(5000);
    System.out.println("ServerThread joined");
    client = ClientFactory.createClient(clientConfig);
    System.out.println("Try connect to port:" + m_cluster.port(0));
    client.createConnection("localhost", m_cluster.port(0));
    System.out.println("Start Proc");
    response = client.callProcedure("InsertA", 3, 3);
    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    response = client.callProcedure("CountA");
    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    assertEquals(3, response.getResults()[0].asScalarLong());
    client.drain();
    client.close();
    client = ClientFactory.createClient(clientConfig);
    System.out.println("Try connect to port:" + m_cluster.port(2));
    client.createConnection("localhost", m_cluster.port(2));
    System.out.println("Start Proc");
    response = client.callProcedure("InsertA", 4, 4);
    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    response = client.callProcedure("CountA");
    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    assertEquals(4, response.getResults()[0].asScalarLong());
    client.drain();
    client.close();
    m_server.shutdown();
    m_cluster.shutDown();
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) LocalCluster(org.voltdb.regressionsuites.LocalCluster) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ClientConfig(org.voltdb.client.ClientConfig) Client(org.voltdb.client.Client) File(java.io.File) Test(org.junit.Test)

Aggregations

ClientConfig (org.voltdb.client.ClientConfig)38 Client (org.voltdb.client.Client)25 IOException (java.io.IOException)11 VoltTable (org.voltdb.VoltTable)10 Configuration (org.voltdb.VoltDB.Configuration)9 File (java.io.File)7 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)7 ClientResponse (org.voltdb.client.ClientResponse)6 ServerThread (org.voltdb.ServerThread)5 ConnectException (java.net.ConnectException)4 UnknownHostException (java.net.UnknownHostException)4 Random (java.util.Random)4 Test (org.junit.Test)4 ClientConfigForTest (org.voltdb.client.ClientConfigForTest)4 ClientImpl (org.voltdb.client.ClientImpl)4 ProcCallException (org.voltdb.client.ProcCallException)4 FileNotFoundException (java.io.FileNotFoundException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 VoltDB (org.voltdb.VoltDB)3