use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class JdbcStatement method executeQuery.
/** {@inheritDoc} */
@Override
public ResultSet executeQuery(String sql) throws SQLException {
ensureNotClosed();
rs = null;
if (sql == null || sql.isEmpty())
throw new SQLException("SQL query is empty");
try {
byte[] packet = conn.client().compute().execute(TASK_NAME, JdbcUtils.marshalArgument(JdbcUtils.taskArgument(conn.nodeId(), conn.cacheName(), sql, timeout, args, fetchSize, maxRows)));
byte status = packet[0];
byte[] data = new byte[packet.length - 1];
U.arrayCopy(packet, 1, data, 0, data.length);
if (status == 1)
throw JdbcUtils.unmarshalError(data);
else {
List<?> msg = JdbcUtils.unmarshal(data);
assert msg.size() == 7;
UUID nodeId = (UUID) msg.get(0);
UUID futId = (UUID) msg.get(1);
List<String> tbls = (List<String>) msg.get(2);
List<String> cols = (List<String>) msg.get(3);
List<String> types = (List<String>) msg.get(4);
Collection<List<Object>> fields = (Collection<List<Object>>) msg.get(5);
boolean finished = (Boolean) msg.get(6);
return new JdbcResultSet(this, nodeId, futId, tbls, cols, types, fields, finished, fetchSize);
}
} catch (GridClientException e) {
throw new SQLException("Failed to query Ignite.", e);
}
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class ClientFailedInitSelfTest method testRoutersAndServersAddressesProvided.
/**
*
*/
public void testRoutersAndServersAddressesProvided() {
try {
GridClientConfiguration c = new GridClientConfiguration();
c.setRouters(Collections.singleton("127.0.0.1:10000"));
c.setServers(Collections.singleton("127.0.0.1:10000"));
GridClientFactory.start(c);
assert false;
} catch (GridClientException e) {
info("Caught expected exception: " + e);
}
}
use of org.apache.ignite.internal.client.GridClientException 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();
}
}
use of org.apache.ignite.internal.client.GridClientException 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. Server
* is picked up according to the projection affinity and key given. Connection will be made with the node
* on which key is cached. In case of communication exception client instance is notified and new instance
* of client is created. If none of servers can be reached, an exception is thrown.
*
* @param c Closure to be executed.
* @param cacheName Cache name for which mapped node will be calculated.
* @param affKey Affinity key.
* @param <R> Type of result in future.
* @return Operation future.
*/
protected <R> GridClientFuture<R> withReconnectHandling(ClientProjectionClosure<R> c, String cacheName, @Nullable Object affKey) {
GridClientDataAffinity affinity = client.affinity(cacheName);
// If pinned (fixed-nodes) or no affinity provided use balancer.
if (nodes != null || affinity == null || affKey == null)
return withReconnectHandling(c);
try {
Collection<? extends GridClientNode> prjNodes = projectionNodes();
if (prjNodes.isEmpty())
throw new GridServerUnreachableException("Failed to get affinity node (no nodes in topology were " + "accepted by the filter): " + filter);
GridClientNode node = affinity.node(affKey, prjNodes);
for (int i = 0; i < RETRY_CNT; i++) {
GridClientConnection conn = null;
try {
conn = client.connectionManager().connection(node);
return c.apply(conn, node.nodeId());
} catch (GridConnectionIdleClosedException e) {
client.connectionManager().terminateConnection(conn, node, e);
} catch (GridClientConnectionResetException e) {
client.connectionManager().terminateConnection(conn, node, e);
if (!checkNodeAlive(node.nodeId()))
throw new GridServerUnreachableException("Failed to communicate with mapped grid node for " + "given affinity key (node left the grid) [nodeId=" + node.nodeId() + ", affKey=" + affKey + ']', e);
} catch (RuntimeException | Error e) {
if (conn != null)
client.connectionManager().terminateConnection(conn, node, e);
throw e;
}
U.sleep(RETRY_DELAY);
}
throw new GridServerUnreachableException("Failed to communicate with mapped grid node for given affinity " + "key (did node leave the grid?) [nodeId=" + node.nodeId() + ", affKey=" + affKey + ']');
} 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));
}
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class MapReduceClient method client.
/**
* Gets the client.
*
* @return The client.
*/
public GridClient client() throws IOException {
GridClient cli0 = cli;
if (cli0 == null) {
synchronized (mux) {
cli0 = cli;
if (cli0 == null) {
GridClientConfiguration cliCfg = new GridClientConfiguration();
cliCfg.setProtocol(TCP);
cliCfg.setServers(addrs);
cliCfg.setMarshaller(new GridClientJdkMarshaller());
// 1 day.
cliCfg.setMaxConnectionIdleTime(24 * 60 * 60 * 1000L);
cliCfg.setDaemon(true);
try {
cli0 = GridClientFactory.start(cliCfg);
cli = cli0;
} catch (GridClientException e) {
throw new IOException("Failed to establish connection with Ignite: " + addrs, e);
}
}
}
}
return cli0;
}
Aggregations