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[]
}
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);
}
}
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[]
}
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);
}
}
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));
}
}
Aggregations