Search in sources :

Example 21 with GridClientException

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);
    }
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) SQLException(java.sql.SQLException) Collection(java.util.Collection) List(java.util.List) UUID(java.util.UUID)

Example 22 with GridClientException

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);
    }
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration)

Example 23 with GridClientException

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();
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) UUID(java.util.UUID)

Example 24 with GridClientException

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));
    }
}
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) GridClientDataAffinity(org.apache.ignite.internal.client.GridClientDataAffinity) GridClientConnection(org.apache.ignite.internal.client.impl.connection.GridClientConnection) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 25 with GridClientException

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;
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientJdkMarshaller(org.apache.ignite.internal.client.marshaller.jdk.GridClientJdkMarshaller) GridClient(org.apache.ignite.internal.client.GridClient) IOException(java.io.IOException) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration)

Aggregations

GridClientException (org.apache.ignite.internal.client.GridClientException)25 GridClientNode (org.apache.ignite.internal.client.GridClientNode)6 GridServerUnreachableException (org.apache.ignite.internal.client.GridServerUnreachableException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 SQLException (java.sql.SQLException)3 List (java.util.List)3 UUID (java.util.UUID)3 GridClient (org.apache.ignite.internal.client.GridClient)3 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)3 GridClientConnection (org.apache.ignite.internal.client.impl.connection.GridClientConnection)3 GridClientConnectionResetException (org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InetSocketAddress (java.net.InetSocketAddress)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 GridClientCompute (org.apache.ignite.internal.client.GridClientCompute)2 GridClientDataAffinity (org.apache.ignite.internal.client.GridClientDataAffinity)2 GridClientFuture (org.apache.ignite.internal.client.GridClientFuture)2 GridClientConnectionManager (org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager)2