Search in sources :

Example 6 with GridClientDisconnectedException

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

the class ClientFailedInitSelfTest method doTestClient.

/**
 * @param p Protocol.
 * @throws Exception If failed.
 */
@SuppressWarnings("BusyWait")
private void doTestClient(GridClientProtocol p) throws Exception {
    GridClient c = client(p, false);
    for (int i = 0; i < RECONN_CNT; i++) {
        try {
            c.compute().nodes();
        } catch (GridClientDisconnectedException e) {
            assertTrue(X.hasCause(e, GridServerUnreachableException.class, GridClientConnectionResetException.class));
        }
        startGrid();
        try {
            Thread.sleep(TOP_REFRESH_PERIOD * 2);
            c.compute().nodes();
            assertEquals("arg", c.compute().execute(TestTask.class.getName(), "arg"));
        } finally {
            stopGrid();
        }
        Thread.sleep(TOP_REFRESH_PERIOD * 2);
    }
}
Also used : GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) GridClient(org.apache.ignite.internal.client.GridClient)

Example 7 with GridClientDisconnectedException

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

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

the class PropertyAbstractSubCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public final Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
    try (GridClient client = Command.startClient(clientCfg)) {
        GridClientCompute compute = client.compute();
        // Try to find connectable server nodes.
        Collection<GridClientNode> nodes = compute.nodes((n) -> n.connectable() && !n.isClient());
        if (F.isEmpty(nodes)) {
            nodes = compute.nodes(GridClientNode::connectable);
            if (F.isEmpty(nodes))
                throw new GridClientDisconnectedException("Connectable nodes not found", null);
        }
        GridClientNode node = nodes.stream().findAny().orElse(null);
        if (node == null)
            node = compute.balancer().balancedNode(nodes);
        MetadataResultDto res = compute.projection(node).execute(taskName(), new VisorTaskArgument<>(node.nodeId(), arg(), false));
        printResult(res, log);
    } catch (Throwable e) {
        log.severe("Failed to execute metadata command='" + name() + "'");
        log.severe(CommandLogger.errorMessage(e));
        throw e;
    }
    return null;
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) GridClient(org.apache.ignite.internal.client.GridClient)

Example 9 with GridClientDisconnectedException

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

the class GridClientImpl method addresses.

/**
 * Return addresses for connection.
 *
 * @return Addresses for connection.
 * @throws GridClientException If failed.
 */
private Collection<InetSocketAddress> addresses() throws GridClientException {
    boolean hasSrvs = routers.isEmpty();
    final Collection<InetSocketAddress> connSrvs = (hasSrvs) ? new LinkedHashSet<>(srvs) : routers;
    if (hasSrvs) {
        // Add REST endpoints for all nodes from previous topology snapshot.
        try {
            for (GridClientNodeImpl node : top.nodes()) {
                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);
                boolean sameHost = node.attributes().isEmpty() || F.containsAny(U.allLocalMACs(), node.attribute(ATTR_MACS).toString().split(", "));
                if (sameHost) {
                    Collections.sort(resolvedEndpoints, U.inetAddressesComparator(true));
                    connSrvs.addAll(resolvedEndpoints);
                } else {
                    for (InetSocketAddress endpoint : resolvedEndpoints) if (!endpoint.getAddress().isLoopbackAddress())
                        connSrvs.add(endpoint);
                }
            }
        } catch (GridClientDisconnectedException ignored) {
        // Ignore if latest topology update failed.
        }
    }
    return connSrvs;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) GridClientDisconnectedException(org.apache.ignite.internal.client.GridClientDisconnectedException) ArrayList(java.util.ArrayList)

Aggregations

GridClientDisconnectedException (org.apache.ignite.internal.client.GridClientDisconnectedException)9 GridClient (org.apache.ignite.internal.client.GridClient)5 GridClientNode (org.apache.ignite.internal.client.GridClientNode)5 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)4 ArrayList (java.util.ArrayList)3 InetSocketAddress (java.net.InetSocketAddress)2 UUID (java.util.UUID)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 ComputeTask (org.apache.ignite.compute.ComputeTask)1 GridClientCacheMode (org.apache.ignite.internal.client.GridClientCacheMode)1