Search in sources :

Example 1 with ThinClientKubernetesAddressFinder

use of org.apache.ignite.client.ThinClientKubernetesAddressFinder 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);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) Address(org.apache.ignite.examples.model.Address) KubernetesConnectionConfiguration(org.apache.ignite.kubernetes.configuration.KubernetesConnectionConfiguration) ThinClientKubernetesAddressFinder(org.apache.ignite.client.ThinClientKubernetesAddressFinder) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration)

Example 2 with ThinClientKubernetesAddressFinder

use of org.apache.ignite.client.ThinClientKubernetesAddressFinder in project ignite by apache.

the class TestClusterClientConnection method testClientConnectsToCluster.

/**
 */
@Test
public void testClientConnectsToCluster() throws Exception {
    mockServerResponse();
    IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(), false);
    IgniteEx crd = startGrid(cfg);
    String crdAddr = crd.localNode().addresses().iterator().next();
    mockServerResponse(crdAddr);
    ClientConfiguration ccfg = new ClientConfiguration();
    ccfg.setAddressesFinder(new ThinClientKubernetesAddressFinder(prepareConfiguration()));
    IgniteClient client = Ignition.startClient(ccfg);
    ClientCache cache = client.createCache("cache");
    cache.put(1, 2);
    assertEquals(2, cache.get(1));
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteClient(org.apache.ignite.client.IgniteClient) IgniteEx(org.apache.ignite.internal.IgniteEx) ClientCache(org.apache.ignite.client.ClientCache) ThinClientKubernetesAddressFinder(org.apache.ignite.client.ThinClientKubernetesAddressFinder) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) Test(org.junit.Test)

Aggregations

IgniteClient (org.apache.ignite.client.IgniteClient)2 ThinClientKubernetesAddressFinder (org.apache.ignite.client.ThinClientKubernetesAddressFinder)2 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)2 ClientCache (org.apache.ignite.client.ClientCache)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 Address (org.apache.ignite.examples.model.Address)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 KubernetesConnectionConfiguration (org.apache.ignite.kubernetes.configuration.KubernetesConnectionConfiguration)1 Test (org.junit.Test)1