Search in sources :

Example 51 with ClientConfiguration

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

the class JavaThinClient method clientAddressFinder.

void clientAddressFinder() throws Exception {
    // tag::client-address-finder[]
    ClientAddressFinder finder = () -> {
        String[] dynamicServerAddresses = fetchServerAddresses();
        return dynamicServerAddresses;
    };
    ClientConfiguration cfg = new ClientConfiguration().setAddressesFinder(finder).setPartitionAwarenessEnabled(true);
    try (IgniteClient client = Ignition.startClient(cfg)) {
        ClientCache<Integer, String> cache = client.cache("myCache");
    // Put, get, or remove data from the cache...
    } catch (ClientException e) {
        System.err.println(e.getMessage());
    }
// end::client-address-finder[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientAddressFinder(org.apache.ignite.client.ClientAddressFinder) ClientException(org.apache.ignite.client.ClientException) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 52 with ClientConfiguration

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

the class JavaThinClient method veiwsystemview.

void veiwsystemview() {
    // tag::system-views[]
    ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
    try (IgniteClient igniteClient = Ignition.startClient(cfg)) {
        // getting the id of the first node
        UUID nodeId = (UUID) igniteClient.query(new SqlFieldsQuery("SELECT * from NODES").setSchema("IGNITE")).getAll().iterator().next().get(0);
        double cpu_load = (Double) igniteClient.query(new SqlFieldsQuery("select CUR_CPU_LOAD * 100 from NODE_METRICS where NODE_ID = ? ").setSchema("IGNITE").setArgs(nodeId.toString())).getAll().iterator().next().get(0);
        System.out.println("node's cpu load = " + cpu_load);
    } catch (ClientException e) {
        System.err.println(e.getMessage());
    } catch (Exception e) {
        System.err.format("Unexpected failure: %s\n", e);
    }
// end::system-views[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientException(org.apache.ignite.client.ClientException) UUID(java.util.UUID) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) ClientException(org.apache.ignite.client.ClientException) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException)

Example 53 with ClientConfiguration

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

the class JavaThinClient method main.

public static void main(String[] args) throws ClientException, Exception {
    JavaThinClient test = new JavaThinClient();
    ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
    try (IgniteClient client = Ignition.startClient(cfg)) {
        test.scanQuery(client);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 54 with ClientConfiguration

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

the class JavaThinClient method configureSSL.

@Test
void configureSSL() throws ClientException, Exception {
    // tag::ssl-configuration[]
    ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
    clientCfg.setSslMode(SslMode.REQUIRED).setSslClientCertificateKeyStorePath(KEYSTORE).setSslClientCertificateKeyStoreType("JKS").setSslClientCertificateKeyStorePassword("123456").setSslTrustCertificateKeyStorePath(TRUSTSTORE).setSslTrustCertificateKeyStorePassword("123456").setSslTrustCertificateKeyStoreType("JKS").setSslKeyAlgorithm("SunX509").setSslTrustAll(false).setSslProtocol(SslProtocol.TLS);
    try (IgniteClient client = Ignition.startClient(clientCfg)) {
    // ...
    }
// end::ssl-configuration[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration) Test(org.junit.jupiter.api.Test)

Example 55 with ClientConfiguration

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

the class CacheCreateDestroyEventSecurityContextTest method testIgniteClient.

/**
 * Tests cache create/destroy event security context in case operation is initiated from the {@link IgniteClient}.
 */
@Test
public void testIgniteClient() throws Exception {
    operationInitiatorLogin = "thin_client";
    ClientConfiguration cfg = new ClientConfiguration().setAddresses(Config.SERVER).setUserName(operationInitiatorLogin).setUserPassword("");
    ClientCacheConfiguration ccfg = clientCacheConfiguration();
    try (IgniteClient cli = Ignition.startClient(cfg)) {
        checkCacheEvents(() -> cli.createCache(ccfg), EVT_CACHE_STARTED);
        checkCacheEvents(() -> cli.destroyCache(ccfg.getName()), EVT_CACHE_STOPPED);
        checkCacheEvents(() -> cli.createCacheAsync(ccfg).get(), EVT_CACHE_STARTED);
        checkCacheEvents(() -> cli.destroyCacheAsync(ccfg.getName()).get(), EVT_CACHE_STOPPED);
        checkCacheEvents(() -> cli.getOrCreateCache(clientCacheConfiguration()), EVT_CACHE_STARTED);
        checkCacheEvents(() -> cli.getOrCreateCacheAsync(clientCacheConfiguration()).get(), EVT_CACHE_STARTED);
        checkCacheEvents(() -> cli.cluster().state(INACTIVE), EVT_CACHE_STOPPED);
        checkCacheEvents(() -> cli.cluster().state(ACTIVE), EVT_CACHE_STARTED);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ClientCacheConfiguration(org.apache.ignite.client.ClientCacheConfiguration) Test(org.junit.Test)

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