Search in sources :

Example 16 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.

the class GridClientTopology method nodes.

/**
     * Gets a collection of nodes from last saved topology snapshot by their ids.
     *
     * @param ids Collection of ids for which nodes should be retrieved..
     * @return Collection of nodes that are in topology.
     * @throws GridClientException If topology is failed and no nodes available.
     */
public Collection<GridClientNode> nodes(Iterable<UUID> ids) throws GridClientException {
    assert ids != null;
    Collection<GridClientNode> res = new LinkedList<>();
    lock.readLock().lock();
    try {
        if (lastError != null)
            throw new GridClientDisconnectedException("Latest topology update failed.", lastError);
        for (UUID id : ids) {
            GridClientNodeImpl node = nodes.get(id);
            if (node != null)
                res.add(node);
        }
        return res;
    } finally {
        lock.readLock().unlock();
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl) UUID(java.util.UUID) LinkedList(java.util.LinkedList)

Example 17 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.

the class GridClientTopology method fail.

/**
     * Marks topology as failed. After this method called all accessors will throw exception
     * until a next successful update.
     *
     * @param cause Exception caused the failure.
     */
public void fail(GridClientException cause) {
    lock.writeLock().lock();
    try {
        lastError = cause;
        for (GridClientNode n : nodes.values()) notifyEvents(Collections.singletonList(new TopologyEvent(false, n)));
        nodes = Collections.emptyMap();
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode)

Example 18 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode 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 19 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.

the class TcpRouterAbstractSelfTest method testConnectable.

/**
     * @throws Exception If failed.
     */
@Override
public void testConnectable() throws Exception {
    GridClient client = client();
    List<GridClientNode> nodes = client.compute().refreshTopology(false, false);
    assertFalse(F.first(nodes).connectable());
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClient(org.apache.ignite.internal.client.GridClient)

Example 20 with GridClientNode

use of org.apache.ignite.internal.client.GridClientNode in project ignite by apache.

the class GridClientRoundRobinBalancer method balancedNode.

/** {@inheritDoc} */
@Override
public GridClientNode balancedNode(Collection<? extends GridClientNode> nodes) throws GridClientException {
    assert !nodes.isEmpty();
    if (isPreferDirectNodes()) {
        Collection<GridClientNode> direct = selectDirectNodes(nodes);
        int directSize = direct.size();
        // replace original set of nodes with directly available.
        if (directSize > 0 && directSize < nodes.size())
            nodes = direct;
    }
    Map<UUID, GridClientNode> lookup = U.newHashMap(nodes.size());
    for (GridClientNode node : nodes) lookup.put(node.nodeId(), node);
    lock.lock();
    try {
        GridClientNode balanced = null;
        for (Iterator<UUID> iter = nodeQueue.iterator(); iter.hasNext(); ) {
            UUID nodeId = iter.next();
            balanced = lookup.get(nodeId);
            if (balanced != null) {
                iter.remove();
                break;
            }
        }
        if (balanced != null) {
            nodeQueue.addLast(balanced.nodeId());
            return balanced;
        }
        throw new GridClientException("Passed nodes doesn't present in topology " + "[nodes=" + nodes + ", top=" + nodeQueue);
    } finally {
        lock.unlock();
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) UUID(java.util.UUID)

Aggregations

GridClientNode (org.apache.ignite.internal.client.GridClientNode)21 GridClientException (org.apache.ignite.internal.client.GridClientException)8 GridClient (org.apache.ignite.internal.client.GridClient)7 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)5 UUID (java.util.UUID)4 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)4 GridClientNodeImpl (org.apache.ignite.internal.client.impl.GridClientNodeImpl)3 GridClientConnection (org.apache.ignite.internal.client.impl.connection.GridClientConnection)3 GridClientConnectionResetException (org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Ignite (org.apache.ignite.Ignite)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 GridClientDataAffinity (org.apache.ignite.internal.client.GridClientDataAffinity)2 GridClientPredicate (org.apache.ignite.internal.client.GridClientPredicate)2 GridConnectionIdleClosedException (org.apache.ignite.internal.client.impl.connection.GridConnectionIdleClosedException)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1