Search in sources :

Example 6 with GridServerUnreachableException

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);
}
Also used : GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) LinkedHashSet(java.util.LinkedHashSet) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList)

Example 7 with GridServerUnreachableException

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;
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientTopology(org.apache.ignite.internal.client.impl.connection.GridClientTopology) GridClientConnectionResetException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException) GridClientConnectionManager(org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager) GridClientConnection(org.apache.ignite.internal.client.impl.connection.GridClientConnection) GridClientFutureAdapter(org.apache.ignite.internal.client.impl.GridClientFutureAdapter) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl)

Example 8 with GridServerUnreachableException

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.
        }
    }
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientFuture(org.apache.ignite.internal.client.GridClientFuture) GridClient(org.apache.ignite.internal.client.GridClient) LinkedHashMap(java.util.LinkedHashMap) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) GridClientData(org.apache.ignite.internal.client.GridClientData) GridClientClosedException(org.apache.ignite.internal.client.GridClientClosedException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)8 GridClientException (org.apache.ignite.internal.client.GridClientException)5 GridClientNode (org.apache.ignite.internal.client.GridClientNode)5 GridClientConnection (org.apache.ignite.internal.client.impl.connection.GridClientConnection)3 GridClientConnectionResetException (org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException)3 InetSocketAddress (java.net.InetSocketAddress)2 ArrayList (java.util.ArrayList)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 GridConnectionIdleClosedException (org.apache.ignite.internal.client.impl.connection.GridConnectionIdleClosedException)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 GridClient (org.apache.ignite.internal.client.GridClient)1 GridClientClosedException (org.apache.ignite.internal.client.GridClientClosedException)1 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)1 GridClientData (org.apache.ignite.internal.client.GridClientData)1