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);
}
}
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();
}
}
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;
}
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;
}
Aggregations