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