use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class ClientKubernetesPutGetExample method main.
/**
* Entry point.
*
* @param args Command line arguments.
*/
public static void main(String[] args) {
KubernetesConnectionConfiguration kcfg = new KubernetesConnectionConfiguration();
kcfg.setNamespace("ignite");
ClientConfiguration cfg = new ClientConfiguration();
cfg.setAddressesFinder(new ThinClientKubernetesAddressFinder(kcfg));
try (IgniteClient igniteClient = Ignition.startClient(cfg)) {
System.out.println();
System.out.println(">>> Thin client put-get example started.");
final String CACHE_NAME = "put-get-example";
ClientCache<Integer, Address> cache = igniteClient.getOrCreateCache(CACHE_NAME);
System.out.format(">>> Created cache [%s].\n", CACHE_NAME);
Integer key = 1;
Address val = new Address("1545 Jackson Street", 94612);
cache.put(key, val);
System.out.format(">>> Saved [%s] in the cache.\n", val);
Address cachedVal = cache.get(key);
System.out.format(">>> Loaded [%s] from the cache.\n", cachedVal);
}
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class ClientSizeCacheCreationDestructionTest method createCache.
/**
* Create cache with specified configuration through thin/thick client or jdbc thin.
*
* @param node Cluster node or jdbc connection.
* @param cacheCfg Cache or ClientCache configuration
* @throws SQLException If failed to create cache through Jdbc Thin connection.
*/
private void createCache(AutoCloseable node, Serializable cacheCfg) throws SQLException {
if (node instanceof IgniteClient)
((IgniteClient) node).createCache((ClientCacheConfiguration) cacheCfg);
else if (node instanceof Ignite)
((Ignite) node).createCache((CacheConfiguration) cacheCfg);
else if (node instanceof JdbcThinConnection) {
CacheConfiguration jdbcCacheCfg = (CacheConfiguration) cacheCfg;
srv.addCacheConfiguration(jdbcCacheCfg);
try (Statement stmt = jdbcConn.createStatement()) {
stmt.execute("CREATE TABLE " + jdbcCacheCfg.getName() + " (id int, name varchar, primary key (id)) WITH \"template=" + jdbcCacheCfg.getName() + "\"");
}
} else
fail(" Unexpected node/client type");
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class NodeSslConnectionMetricTest method testClientConnector.
/**
* Tests SSL metrics produced by thin client connection.
*/
@Test
public void testClientConnector() throws Exception {
MetricRegistry reg = mreg(startClusterNode(0), CLIENT_CONNECTOR_METRICS);
assertEquals(0, reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value());
assertEquals(0, reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value());
try (IgniteClient ignored = startClient(clientConfiguration("thinClient", "trusttwo", CIPHER_SUITE, "TLSv1.2"))) {
checkSslCommunicationMetrics(reg, 1, 1, 0);
}
assertTrue(reg.<LongMetric>findMetric(SENT_BYTES_METRIC_NAME).value() > 0);
assertTrue(reg.<LongMetric>findMetric(RECEIVED_BYTES_METRIC_NAME).value() > 0);
checkSslCommunicationMetrics(reg, 1, 0, 0);
// Tests untrusted certificate.
assertThrowsWithCause(() -> startClient(clientConfiguration("client", "trustboth", CIPHER_SUITE, "TLSv1.2")), ClientConnectionException.class);
checkSslCommunicationMetrics(reg, 2, 0, 1);
// Tests unsupported cipher suites.
assertThrowsWithCause(() -> startClient(clientConfiguration("thinClient", "trusttwo", UNSUPPORTED_CIPHER_SUITE, "TLSv1.2")), ClientConnectionException.class);
checkSslCommunicationMetrics(reg, 3, 0, 2);
// Tests mismatched protocol versions.
assertThrowsWithCause(() -> startClient(clientConfiguration("thinClient", "trusttwo", null, "TLSv1.1")), ClientConnectionException.class);
checkSslCommunicationMetrics(reg, 4, 0, 3);
}
use of org.apache.ignite.client.IgniteClient in project ignite by apache.
the class RunningQueryInfoCheckInitiatorTest method testThinClientInitiatorId.
/**
* @throws Exception If failed.
*/
@Test
public void testThinClientInitiatorId() throws Exception {
Consumer<String> sqlExec = sql -> {
GridTestUtils.runAsync(() -> {
try (IgniteClient cli = Ignition.startClient(new ClientConfiguration().setAddresses("127.0.0.1:" + clientPort(grid(0))).setUserName("ignite").setUserPassword("ignite"))) {
cli.query(new SqlFieldsQuery(sql)).getAll();
} catch (Exception e) {
log.error("Unexpected exception", e);
}
});
};
Consumer<String> initiatorChecker = initiatorId -> {
assertTrue("Invalid initiator ID: " + initiatorId, Pattern.compile("cli:127\\.0\\.0\\.1:[0-9]+@ignite").matcher(initiatorId).matches());
};
check(sqlExec, initiatorChecker);
}
use of org.apache.ignite.client.IgniteClient 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[]
}
Aggregations