use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class GridClientAbstractProjection method balancedNode.
/**
* Return balanced node for current projection.
*
* @param exclude Nodes to exclude.
* @return Balanced node.
* @throws GridServerUnreachableException If topology is empty.
*/
private GridClientNode balancedNode(@Nullable final GridClientNode exclude) throws GridClientException {
GridClientPredicate<GridClientNode> excludeFilter = exclude == null ? new GridClientPredicate<GridClientNode>() {
@Override
public boolean apply(GridClientNode e) {
return restAvailable(e, client.cfg.getProtocol());
}
@Override
public String toString() {
return "Filter nodes with available REST.";
}
} : new GridClientPredicate<GridClientNode>() {
@Override
public boolean apply(GridClientNode e) {
return !exclude.equals(e) && restAvailable(e, client.cfg.getProtocol());
}
@Override
public String toString() {
return "Filter nodes with available REST and " + "exclude (probably due to connection failure) node: " + exclude.nodeId();
}
};
Collection<? extends GridClientNode> prjNodes = projectionNodes(excludeFilter);
if (prjNodes.isEmpty())
throw new GridServerUnreachableException("Failed to get balanced node (no nodes in topology were " + "accepted by the filters): " + Arrays.asList(filter, excludeFilter));
if (prjNodes.size() == 1) {
GridClientNode ret = GridClientUtils.first(prjNodes);
assert ret != null;
return ret;
}
return balancer.balancedNode(prjNodes);
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class ClientAbstractConnectivitySelfTest method testTwoNodesDefaultHostAndPort.
/**
* Tests correct behavior in case of 2 REST-enabled nodes with default
* settings.
*
* @throws Exception If error occurs.
*/
public void testTwoNodesDefaultHostAndPort() throws Exception {
startRestNode("grid1", null, null);
startRestNode("grid2", null, null);
GridClient cli = startClient(LOOPBACK_IP, defaultRestPort());
List<GridClientNode> nodes = cli.compute().refreshTopology(true, false);
assertEquals(2, nodes.size());
assertTrue(F.forAll(nodes, new P1<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
return node.tcpAddresses().contains(LOOPBACK_IP);
}
}));
GridTestUtils.assertOneToOne(nodes, new P1<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
try {
return eqAddresses(getAllIps(), node) && Integer.valueOf(defaultRestPort()).equals(node.attribute(restPortAttributeName()));
} catch (Exception ignored) {
return false;
}
}
}, new P1<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
try {
return eqAddresses(getAllIps(), node) && Integer.valueOf(defaultRestPort() + 1).equals(node.attribute(restPortAttributeName()));
} catch (Exception ignored) {
return false;
}
}
});
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class ClientAbstractSelfTest method testNoAsyncExceptions.
/**
* Check async API methods don't generate exceptions.
*
* @throws Exception If failed.
*/
public void testNoAsyncExceptions() throws Exception {
GridClient client = client();
GridClientData data = client.data(CACHE_NAME);
GridClientCompute compute = client.compute().projection(new GridClientPredicate<GridClientNode>() {
@Override
public boolean apply(GridClientNode e) {
return false;
}
});
Map<String, GridClientFuture<?>> futs = new LinkedHashMap<>();
futs.put("exec", compute.executeAsync("taskName", "taskArg"));
futs.put("affExec", compute.affinityExecuteAsync("taskName", "cacheName", "affKey", "taskArg"));
futs.put("refreshById", compute.refreshNodeAsync(UUID.randomUUID(), true, true));
futs.put("refreshByIP", compute.refreshNodeAsync("nodeIP", true, true));
futs.put("refreshTop", compute.refreshTopologyAsync(true, true));
GridClientFactory.stop(client.id(), false);
futs.put("put", data.putAsync("key", "val"));
futs.put("putAll", data.putAllAsync(F.asMap("key", "val")));
futs.put("get", data.getAsync("key"));
futs.put("getAll", data.getAllAsync(Collections.singletonList("key")));
futs.put("remove", data.removeAsync("key"));
futs.put("removeAll", data.removeAllAsync(Collections.singletonList("key")));
futs.put("replace", data.replaceAsync("key", "val"));
futs.put("cas", data.casAsync("key", "val", "val2"));
futs.put("metrics", data.metricsAsync());
for (Map.Entry<String, GridClientFuture<?>> e : futs.entrySet()) {
try {
e.getValue().get();
info("Expects '" + e.getKey() + "' fails with grid client exception.");
} catch (GridServerUnreachableException | GridClientClosedException ignore) {
// No op: compute projection is empty.
}
}
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class ClientAbstractMultiNodeSelfTest method testTopologyListener.
/**
* @throws Exception If failed.
*/
public void testTopologyListener() throws Exception {
final Collection<UUID> added = new ArrayList<>(1);
final Collection<UUID> rmvd = new ArrayList<>(1);
final CountDownLatch addedLatch = new CountDownLatch(1);
final CountDownLatch rmvLatch = new CountDownLatch(1);
assertEquals(NODES_CNT, client.compute().refreshTopology(false, false).size());
GridClientTopologyListener lsnr = new GridClientTopologyListener() {
@Override
public void onNodeAdded(GridClientNode node) {
added.add(node.nodeId());
addedLatch.countDown();
}
@Override
public void onNodeRemoved(GridClientNode node) {
rmvd.add(node.nodeId());
rmvLatch.countDown();
}
};
client.addTopologyListener(lsnr);
try {
Ignite g = startGrid(NODES_CNT + 1);
UUID id = g.cluster().localNode().id();
assertTrue(addedLatch.await(2 * TOP_REFRESH_FREQ, MILLISECONDS));
assertEquals(1, added.size());
assertEquals(id, F.first(added));
stopGrid(NODES_CNT + 1);
assertTrue(rmvLatch.await(2 * TOP_REFRESH_FREQ, MILLISECONDS));
assertEquals(1, rmvd.size());
assertEquals(id, F.first(rmvd));
} finally {
client.removeTopologyListener(lsnr);
stopGrid(NODES_CNT + 1);
}
}
use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.
the class GridClientDataImpl method affinity.
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <K> UUID affinity(K key) throws GridClientException {
A.notNull(key, "key");
GridClientDataAffinity affinity = client.affinity(cacheName);
if (affinity == null)
return null;
Collection<? extends GridClientNode> prj = projectionNodes();
if (prj.isEmpty())
throw new GridClientException("Failed to get affinity node (projection node set for cache is empty): " + cacheName());
GridClientNode node = affinity.node(key, prj);
assert node != null;
return node.nodeId();
}
Aggregations