Search in sources :

Example 56 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class JmhThinClientAbstractBenchmark method setup.

/**
 * Setup routine. Child classes must invoke this method first.
 */
@Setup
public void setup() {
    System.out.println();
    System.out.println("--------------------");
    System.out.println("IGNITE BENCHMARK INFO: ");
    System.out.println("\tdata nodes:                 " + intProperty(PROP_DATA_NODES, DFLT_DATA_NODES));
    System.out.println("--------------------");
    System.out.println();
    int nodesCnt = intProperty(PROP_DATA_NODES, DFLT_DATA_NODES);
    A.ensure(nodesCnt >= 1, "nodesCnt >= 1");
    node = Ignition.start(configuration("node0"));
    for (int i = 1; i < nodesCnt; i++) Ignition.start(configuration("node" + i));
    String[] addrs = IntStream.range(10800, 10800 + nodesCnt).mapToObj(p -> "127.0.0.1:" + p).toArray(String[]::new);
    ClientConfiguration cfg = new ClientConfiguration().setAddresses(addrs).setPartitionAwarenessEnabled(true);
    client = Ignition.startClient(cfg);
    cache = client.getOrCreateCache(DEFAULT_CACHE_NAME);
    System.out.println("Loading test data...");
    for (int i = 0; i < CNT; i++) cache.put(i, PAYLOAD);
    System.out.println("Test data loaded: " + CNT);
}
Also used : IntStream(java.util.stream.IntStream) JmhAbstractBenchmark(org.apache.ignite.internal.benchmarks.jmh.JmhAbstractBenchmark) Setup(org.openjdk.jmh.annotations.Setup) A(org.apache.ignite.internal.util.typedef.internal.A) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) Scope(org.openjdk.jmh.annotations.Scope) Ignite(org.apache.ignite.Ignite) State(org.openjdk.jmh.annotations.State) ClientCache(org.apache.ignite.client.ClientCache) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) IgniteClient(org.apache.ignite.client.IgniteClient) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) TearDown(org.openjdk.jmh.annotations.TearDown) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Setup(org.openjdk.jmh.annotations.Setup)

Example 57 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class JavaThinCompatibilityTest method testTransactions.

/**
 */
private void testTransactions() throws Exception {
    X.println(">>>> Testing transactions");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        ClientCache<Object, Object> cache = client.getOrCreateCache(new ClientCacheConfiguration().setName("testTransactions").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
        try (ClientTransaction tx = client.transactions().txStart()) {
            cache.put(1, 1);
            cache.put(2, 2);
            tx.commit();
        }
        assertEquals(1, cache.get(1));
        assertEquals(2, cache.get(2));
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientTransaction(org.apache.ignite.client.ClientTransaction) BinaryObject(org.apache.ignite.binary.BinaryObject) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration)

Example 58 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class JavaThinCompatibilityTest method testCacheApi.

/**
 */
private void testCacheApi() throws Exception {
    X.println(">>>> Testing cache API");
    try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(ADDR))) {
        ClientCache<Object, Object> cache = client.getOrCreateCache("testCacheApi");
        cache.put(1, 1);
        assertEquals(1, cache.get(1));
        Person person = new Person(2, "name");
        cache.put(2, person);
        assertEquals(person, cache.get(2));
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) BinaryObject(org.apache.ignite.binary.BinaryObject) Person(org.apache.ignite.client.Person) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 59 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class WarningOnBigQueryResultsTest method testThinClient.

/**
 */
@Test
public void testThinClient() throws Exception {
    try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses(THIN_CLI_ADDR))) {
        assertEquals(KEYS_PER_NODE * 2, cli.query(new SqlFieldsQueryEx("SELECT * FROM TEST0", true).setSchema("TEST0")).getAll().size());
        checkStateAfterQuery0("TEST0");
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Example 60 with ClientConfiguration

use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.

the class ClientSslUtils method getSslContext.

/**
 * Gets SSL context for the given client configuration.
 *
 * @param cfg Configuration.
 * @return {@link SSLContext} when SSL is enabled in the configuration; null otherwise.
 */
public static SSLContext getSslContext(ClientConfiguration cfg) {
    if (cfg.getSslMode() == SslMode.DISABLED)
        return null;
    Factory<SSLContext> sslCtxFactory = cfg.getSslContextFactory();
    if (sslCtxFactory != null) {
        try {
            return sslCtxFactory.create();
        } catch (Exception e) {
            throw new ClientError("SSL Context Factory failed", e);
        }
    }
    BiFunction<String, String, String> or = (val, dflt) -> val == null || val.isEmpty() ? dflt : val;
    String keyStore = or.apply(cfg.getSslClientCertificateKeyStorePath(), System.getProperty("javax.net.ssl.keyStore"));
    String keyStoreType = or.apply(cfg.getSslClientCertificateKeyStoreType(), or.apply(System.getProperty("javax.net.ssl.keyStoreType"), DFLT_STORE_TYPE));
    String keyStorePwd = or.apply(cfg.getSslClientCertificateKeyStorePassword(), System.getProperty("javax.net.ssl.keyStorePassword"));
    String trustStore = or.apply(cfg.getSslTrustCertificateKeyStorePath(), System.getProperty("javax.net.ssl.trustStore"));
    String trustStoreType = or.apply(cfg.getSslTrustCertificateKeyStoreType(), or.apply(System.getProperty("javax.net.ssl.trustStoreType"), DFLT_STORE_TYPE));
    String trustStorePwd = or.apply(cfg.getSslTrustCertificateKeyStorePassword(), System.getProperty("javax.net.ssl.trustStorePassword"));
    String algorithm = or.apply(cfg.getSslKeyAlgorithm(), DFLT_KEY_ALGORITHM);
    String proto = toString(cfg.getSslProtocol());
    if (Stream.of(keyStore, keyStorePwd, keyStoreType, trustStore, trustStorePwd, trustStoreType).allMatch(s -> s == null || s.isEmpty())) {
        try {
            return SSLContext.getDefault();
        } catch (NoSuchAlgorithmException e) {
            throw new ClientError("Default SSL context cryptographic algorithm is not available", e);
        }
    }
    KeyManager[] keyManagers = getKeyManagers(algorithm, keyStore, keyStoreType, keyStorePwd);
    TrustManager[] trustManagers = cfg.isSslTrustAll() ? new TrustManager[] { ignoreErrorsTrustMgr } : getTrustManagers(algorithm, trustStore, trustStoreType, trustStorePwd);
    try {
        SSLContext sslCtx = SSLContext.getInstance(proto);
        sslCtx.init(keyManagers, trustManagers, null);
        return sslCtx;
    } catch (NoSuchAlgorithmException e) {
        throw new ClientError("SSL context cryptographic algorithm is not available", e);
    } catch (KeyManagementException e) {
        throw new ClientError("Failed to create SSL Context", e);
    }
}
Also used : X509Certificate(java.security.cert.X509Certificate) SSLContext(javax.net.ssl.SSLContext) BiFunction(java.util.function.BiFunction) TrustManager(javax.net.ssl.TrustManager) DFLT_STORE_TYPE(org.apache.ignite.ssl.SslContextFactory.DFLT_STORE_TYPE) SslMode(org.apache.ignite.client.SslMode) KeyStoreException(java.security.KeyStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) Factory(javax.cache.configuration.Factory) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) Predicate(java.util.function.Predicate) DFLT_KEY_ALGORITHM(org.apache.ignite.ssl.SslContextFactory.DFLT_KEY_ALGORITHM) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) IOException(java.io.IOException) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) KeyManager(javax.net.ssl.KeyManager) Stream(java.util.stream.Stream) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) X509TrustManager(javax.net.ssl.X509TrustManager) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SslProtocol(org.apache.ignite.client.SslProtocol) InputStream(java.io.InputStream) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager) KeyManager(javax.net.ssl.KeyManager)

Aggregations

ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)83 Test (org.junit.Test)44 IgniteClient (org.apache.ignite.client.IgniteClient)42 Ignite (org.apache.ignite.Ignite)28 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)23 BinaryObject (org.apache.ignite.binary.BinaryObject)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 List (java.util.List)11 Ignition (org.apache.ignite.Ignition)10 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)9 Collections (java.util.Collections)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 IgniteBinary (org.apache.ignite.IgniteBinary)7 Connection (java.sql.Connection)6 Arrays (java.util.Arrays)6 Map (java.util.Map)6 Consumer (java.util.function.Consumer)6 ScanQuery (org.apache.ignite.cache.query.ScanQuery)6