Search in sources :

Example 1 with ClientClusterGroup

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

the class JavaThinClient method clientClusterGroups.

void clientClusterGroups() throws Exception {
    ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
    // tag::client-cluster-groups[]
    try (IgniteClient client = Ignition.startClient(clientCfg)) {
        ClientClusterGroup serversInDc1 = client.cluster().forServers().forAttribute("dc", "dc1");
        serversInDc1.nodes().forEach(n -> System.out.println("Node ID: " + n.id()));
    }
// end::client-cluster-groups[]
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 2 with ClientClusterGroup

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

the class ComputeTaskTest method testExecuteTaskOnEmptyClusterGroup.

/**
 */
@Test(expected = ClientException.class)
public void testExecuteTaskOnEmptyClusterGroup() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientClusterGroup grp = client.cluster().forNodeIds(Collections.emptyList());
        client.compute(grp).execute(TestTask.class.getName(), null);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) Test(org.junit.Test)

Example 3 with ClientClusterGroup

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

the class ServicesTest method testServicesOnClusterGroup.

/**
 * Test that services executed on cluster group.
 */
@Test
public void testServicesOnClusterGroup() throws Exception {
    try (IgniteClient client = startClient(0)) {
        // Local node.
        ClientClusterGroup grp = client.cluster().forNodeId(nodeId(0), nodeId(3));
        TestNodeIdServiceInterface nodeSvc0 = client.services(grp).serviceProxy(NODE_ID_SERVICE_NAME, TestNodeIdServiceInterface.class);
        assertEquals(nodeId(0), nodeSvc0.nodeId());
        // Remote node.
        grp = client.cluster().forNodeId(nodeId(1), nodeId(3));
        nodeSvc0 = client.services(grp).serviceProxy(NODE_ID_SERVICE_NAME, TestNodeIdServiceInterface.class);
        assertEquals(nodeId(1), nodeSvc0.nodeId());
        // Client node.
        grp = client.cluster().forNodeId(nodeId(3));
        TestNodeIdServiceInterface nodeSvc1 = client.services(grp).serviceProxy(NODE_ID_SERVICE_NAME, TestNodeIdServiceInterface.class);
        GridTestUtils.assertThrowsAnyCause(log, nodeSvc1::nodeId, ClientException.class, "Failed to find deployed service");
        // All nodes, except service node.
        grp = client.cluster().forNodeId(nodeId(0), nodeId(2), nodeId(3));
        TestServiceInterface nodeSvc2 = client.services(grp).serviceProxy(CLUSTER_SINGLTON_SERVICE_NAME, TestServiceInterface.class);
        GridTestUtils.assertThrowsAnyCause(log, nodeSvc2::testMethod, ClientException.class, "Failed to find deployed service");
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) Test(org.junit.Test)

Example 4 with ClientClusterGroup

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

the class ComputeTaskTest method testComputeWithMixedModificators.

/**
 */
@Test
public void testComputeWithMixedModificators() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientClusterGroup grp = client.cluster().forNodeId(nodeId(1), nodeId(2));
        ClientCompute compute = client.compute(grp).withNoFailover().withNoResultCache().withTimeout(TIMEOUT / 5);
        T2<UUID, List<UUID>> val = client.compute(grp).execute(TestTask.class.getName(), null);
        assertEquals(nodeIds(1, 2), val.get2());
        assertFalse(compute.execute(TestFailoverTask.class.getName(), null));
        assertFalse(compute.execute(TestResultCacheTask.class.getName(), null));
        GridTestUtils.assertThrowsAnyCause(null, () -> compute.execute(TestTask.class.getName(), TIMEOUT), ClientException.class, null);
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) ClientCompute(org.apache.ignite.client.ClientCompute) Test(org.junit.Test)

Example 5 with ClientClusterGroup

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

the class ComputeTaskTest method testExecuteTaskOnClusterGroup.

/**
 */
@Test
public void testExecuteTaskOnClusterGroup() throws Exception {
    try (IgniteClient client = startClient(0)) {
        ClientClusterGroup grp = client.cluster().forNodeIds(nodeIds(1, 2));
        T2<UUID, List<UUID>> val = client.compute(grp).execute(TestTask.class.getName(), null);
        assertEquals(nodeId(0), val.get1());
        assertEquals(nodeIds(1, 2), val.get2());
        // Compute on client node defined explicitly.
        grp = client.cluster().forNodeIds(nodeIds(3));
        val = client.compute(grp).execute(TestTask.class.getName(), null);
        assertEquals(nodeId(0), val.get1());
        assertEquals(nodeIds(3), val.get2());
        // Compute on all nodes (clients + servers).
        grp = client.cluster();
        val = client.compute(grp).execute(TestTask.class.getName(), null);
        assertEquals(nodeId(0), val.get1());
        assertEquals(new HashSet<>(F.nodeIds(grid(0).cluster().nodes())), val.get2());
    }
}
Also used : IgniteClient(org.apache.ignite.client.IgniteClient) ClientClusterGroup(org.apache.ignite.client.ClientClusterGroup) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ClientClusterGroup (org.apache.ignite.client.ClientClusterGroup)6 IgniteClient (org.apache.ignite.client.IgniteClient)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UUID (java.util.UUID)2 ClientCompute (org.apache.ignite.client.ClientCompute)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ClientConfiguration (org.apache.ignite.configuration.ClientConfiguration)1 ThinClientConfiguration (org.apache.ignite.configuration.ThinClientConfiguration)1