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