Search in sources :

Example 6 with GridClientNode

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

the class ClientAbstractSelfTest method testTopology.

/**
     * @throws Exception If failed.
     */
public void testTopology() throws Exception {
    GridClientCompute compute = client.compute();
    List<GridClientNode> top = compute.refreshTopology(true, true);
    assertNotNull(top);
    assertEquals(1, top.size());
    GridClientNode node = F.first(top);
    assertNotNull(node);
    assertFalse(node.attributes().isEmpty());
    assertNotNull(node.tcpAddresses());
    assertEquals(grid().localNode().id(), node.nodeId());
    assertNotNull(node.metrics());
    top = compute.refreshTopology(false, false);
    node = F.first(top);
    assertNotNull(top);
    assertEquals(1, top.size());
    assertNull(node.metrics());
    assertTrue(node.attributes().isEmpty());
    node = F.first(top);
    assertNotNull(node);
    assertTrue(node.attributes().isEmpty());
    assertNull(node.metrics());
    assertNotNull(node.tcpAddresses());
    assertEquals(grid().localNode().id(), node.nodeId());
    top = compute.refreshTopologyAsync(true, true).get();
    assertNotNull(top);
    assertEquals(1, top.size());
    node = F.first(top);
    assertNotNull(node);
    assertFalse(node.attributes().isEmpty());
    assertNotNull(node.metrics());
    assertNotNull(node.tcpAddresses());
    assertEquals(grid().localNode().id(), node.nodeId());
    top = compute.refreshTopologyAsync(false, false).get();
    assertNotNull(top);
    assertEquals(1, top.size());
    node = F.first(top);
    assertNotNull(node);
    assertTrue(node.attributes().isEmpty());
    assertNull(node.metrics());
    assertNotNull(node.tcpAddresses());
    assertEquals(grid().localNode().id(), node.nodeId());
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode)

Example 7 with GridClientNode

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

the class ClientAbstractSelfTest method testConnectable.

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

Example 8 with GridClientNode

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

the class GridClientImpl method data.

/** {@inheritDoc} */
@Override
public GridClientData data(@Nullable final String cacheName) throws GridClientException {
    checkClosed();
    Object key = maskNull(cacheName);
    GridClientDataImpl data = dataMap.get(key);
    if (data == null) {
        GridClientDataConfiguration dataCfg = cfg.getDataConfiguration(cacheName);
        if (dataCfg == null && cacheName != null)
            throw new GridClientException("Data configuration for given cache name was not provided: " + cacheName);
        GridClientLoadBalancer balancer = dataCfg != null ? dataCfg.getPinnedBalancer() : new GridClientRandomBalancer();
        GridClientPredicate<GridClientNode> cacheNodes = new GridClientPredicate<GridClientNode>() {

            @Override
            public boolean apply(GridClientNode e) {
                return e.caches().containsKey(cacheName);
            }

            @Override
            public String toString() {
                return "GridClientHasCacheFilter [cacheName=" + cacheName + "]";
            }
        };
        data = new GridClientDataImpl(cacheName, this, null, cacheNodes, balancer, null, cfg.isEnableMetricsCache());
        GridClientDataImpl old = dataMap.putIfAbsent(key, data);
        if (old != null)
            data = old;
    }
    return data;
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientPredicate(org.apache.ignite.internal.client.GridClientPredicate) GridClientLoadBalancer(org.apache.ignite.internal.client.balancer.GridClientLoadBalancer) GridClientDataConfiguration(org.apache.ignite.internal.client.GridClientDataConfiguration) GridClientRandomBalancer(org.apache.ignite.internal.client.balancer.GridClientRandomBalancer)

Example 9 with GridClientNode

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

the class GridClientTopology method nodeFailed.

/**
     * Updates topology when node that is expected to be in topology fails.
     *
     * @param nodeId Node id for which node failed to be obtained.
     */
public void nodeFailed(UUID nodeId) {
    lock.writeLock().lock();
    try {
        boolean nodeDeleted = nodes.containsKey(nodeId);
        GridClientNode deleted = null;
        // We update the whole topology if node was not in topology or we cache metrics.
        if (nodeDeleted) {
            Map<UUID, GridClientNodeImpl> updatedTop = new HashMap<>(nodes);
            deleted = updatedTop.remove(nodeId);
            // Change the reference to new topology.
            // So everyone who captured old version will see a consistent snapshot.
            nodes = updatedTop;
        }
        if (nodeDeleted)
            notifyEvents(Collections.singletonList(new TopologyEvent(false, deleted)));
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) HashMap(java.util.HashMap) GridClientNodeImpl(org.apache.ignite.internal.client.impl.GridClientNodeImpl) UUID(java.util.UUID)

Example 10 with GridClientNode

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

the class GridClientAbstractProjection method withReconnectHandling.

/**
     * This method executes request to a communication layer and handles connection error, if it occurs.
     * In case of communication exception client instance is notified and new instance of client is created.
     * If none of the grid servers can be reached, an exception is thrown.
     *
     * @param c Closure to be executed.
     * @param <R> Result future type.
     * @return Future returned by closure.
     */
protected <R> GridClientFuture<R> withReconnectHandling(ClientProjectionClosure<R> c) {
    try {
        GridClientNode node = null;
        boolean changeNode = false;
        Throwable cause = null;
        for (int i = 0; i < RETRY_CNT; i++) {
            if (node == null || changeNode)
                try {
                    node = balancedNode(node);
                } catch (GridClientException e) {
                    if (node == null)
                        throw e;
                    else
                        throw new GridServerUnreachableException("All nodes in projection failed when retrying to perform request. Attempts made: " + i, cause);
                }
            GridClientConnection conn = null;
            try {
                conn = client.connectionManager().connection(node);
                return c.apply(conn, node.nodeId());
            } catch (GridConnectionIdleClosedException e) {
                client.connectionManager().terminateConnection(conn, node, e);
                // It's ok, just reconnect to the same node.
                changeNode = false;
                cause = e;
            } catch (GridClientConnectionResetException e) {
                client.connectionManager().terminateConnection(conn, node, e);
                changeNode = true;
                cause = e;
            } catch (GridServerUnreachableException e) {
                changeNode = true;
                cause = e;
            }
            U.sleep(RETRY_DELAY);
        }
        assert cause != null;
        throw new GridServerUnreachableException("Failed to communicate with grid nodes " + "(maximum count of retries reached).", cause);
    } catch (GridClientException e) {
        return new GridClientFutureAdapter<>(e);
    } catch (IgniteInterruptedCheckedException | InterruptedException e) {
        Thread.currentThread().interrupt();
        return new GridClientFutureAdapter<>(new GridClientException("Interrupted when (re)trying to perform request.", e));
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) GridConnectionIdleClosedException(org.apache.ignite.internal.client.impl.connection.GridConnectionIdleClosedException) GridClientConnectionResetException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException) GridClientConnection(org.apache.ignite.internal.client.impl.connection.GridClientConnection) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

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