Search in sources :

Example 61 with IgniteClient

use of org.apache.ignite.client.IgniteClient 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 62 with IgniteClient

use of org.apache.ignite.client.IgniteClient 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 63 with IgniteClient

use of org.apache.ignite.client.IgniteClient 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 64 with IgniteClient

use of org.apache.ignite.client.IgniteClient 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)

Example 65 with IgniteClient

use of org.apache.ignite.client.IgniteClient 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)

Aggregations

IgniteClient (org.apache.ignite.client.IgniteClient)106 Test (org.junit.Test)76 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)43 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)26 UUID (java.util.UUID)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 Ignite (org.apache.ignite.Ignite)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)14 HashSet (java.util.HashSet)13 T2 (org.apache.ignite.internal.util.typedef.T2)13 Set (java.util.Set)12 CountDownLatch (java.util.concurrent.CountDownLatch)12 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 List (java.util.List)10 BinaryObject (org.apache.ignite.binary.BinaryObject)10 GridTestUtils (org.apache.ignite.testframework.GridTestUtils)10 GridTestUtils.assertThrowsWithCause (org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause)10 Map (java.util.Map)9 Duration (javax.cache.expiry.Duration)9 ClientCacheConfiguration (org.apache.ignite.client.ClientCacheConfiguration)9