use of org.apache.ignite.internal.client.GridServerUnreachableException in project ignite by apache.
the class GridClientConnectionManagerAdapter method connection.
/**
* Gets active communication facade.
*
* @param node Remote node to which connection should be established.
* @throws GridServerUnreachableException If none of the servers can be reached after the exception.
* @throws GridClientClosedException If client was closed manually.
* @throws InterruptedException If connection was interrupted.
*/
@Override
public GridClientConnection connection(GridClientNode node) throws GridClientClosedException, GridServerUnreachableException, InterruptedException {
assert node != null;
// Use router's connections if defined.
if (!routers.isEmpty())
return connection(null, routers);
GridClientConnection conn = nodeConns.get(node.nodeId());
if (conn != null) {
// Ignore closed connections.
if (conn.closeIfIdle(cfg.getMaxConnectionIdleTime()))
closeIdle();
else
return conn;
}
// Use node's connection, if node is available over rest.
Collection<InetSocketAddress> endpoints = node.availableAddresses(cfg.getProtocol(), true);
List<InetSocketAddress> resolvedEndpoints = new ArrayList<>(endpoints.size());
for (InetSocketAddress endpoint : endpoints) if (!endpoint.isUnresolved())
resolvedEndpoints.add(endpoint);
if (resolvedEndpoints.isEmpty()) {
throw new GridServerUnreachableException("No available endpoints to connect " + "(is rest enabled for this node?): " + node);
}
boolean sameHost = node.attributes().isEmpty() || F.containsAny(macs, node.attribute(ATTR_MACS).toString().split(", "));
Collection<InetSocketAddress> srvs = new LinkedHashSet<>();
if (sameHost) {
Collections.sort(resolvedEndpoints, U.inetAddressesComparator(true));
srvs.addAll(resolvedEndpoints);
} else {
for (InetSocketAddress endpoint : resolvedEndpoints) if (!endpoint.getAddress().isLoopbackAddress())
srvs.add(endpoint);
}
return connection(node.nodeId(), srvs);
}
use of org.apache.ignite.internal.client.GridServerUnreachableException in project ignite by apache.
the class GridRouterClientImpl method forwardMessage.
/**
* Send a raw packet "as is" directly to the given node.
* The exact types of acceptable arguments and return values depends on underlying connections.
*
* @param msg Raw message to send.
* @param destId Id of node to send message to. If {@code null} than node will be chosen
* from the topology randomly.
* @return Future, representing forwarded message.
* @throws GridServerUnreachableException If destination node can't be reached.
* @throws GridClientClosedException If client is closed.
* @throws GridClientException If any other client-related error occurs.
* @throws InterruptedException If router was interrupted while trying.
* to establish connection with destination node.
*/
GridClientFutureAdapter<?> forwardMessage(Object msg, @Nullable UUID destId, byte marshId) throws GridClientException, InterruptedException {
GridClientTopology top = clientImpl.topology();
GridClientNode dest = destId != null ? top.node(destId) : cliCfg.getBalancer().balancedNode(applyFilter(top.nodes(), new GridClientPredicate<GridClientNodeImpl>() {
@Override
public boolean apply(GridClientNodeImpl e) {
return restAvailable(e, cliCfg.getProtocol());
}
}));
if (dest == null)
throw new GridServerUnreachableException("Failed to resolve node for specified destination ID: " + destId);
GridClientConnectionManager connMgr = connectionManager(marshId);
GridClientConnection conn = null;
// No reconnection handling there. Let client to do it if needed.
GridClientException cause;
try {
conn = connMgr.connection(dest);
return conn.forwardMessage(msg);
} catch (GridClientConnectionResetException e) {
if (destId != null)
connMgr.terminateConnection(conn, top.node(destId), e);
else
connMgr.terminateConnection(conn, null, e);
cause = e;
} catch (GridClientException e) {
cause = e;
}
GridClientFutureAdapter<Object> fail = new GridClientFutureAdapter<>();
fail.onDone(cause);
return fail;
}
use of org.apache.ignite.internal.client.GridServerUnreachableException 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.
}
}
}
Aggregations