Search in sources :

Example 6 with GridClientException

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

the class GridClientImpl method createConnectionManager.

/**
     * @param clientId Client ID.
     * @param sslCtx SSL context to enable secured connection or {@code null} to use unsecured one.
     * @param cfg Client configuration.
     * @param routers Routers or empty collection to use endpoints from topology info.
     * @param top Topology.
     * @throws GridClientException In case of error.
     */
private GridClientConnectionManager createConnectionManager(UUID clientId, SSLContext sslCtx, GridClientConfiguration cfg, Collection<InetSocketAddress> routers, GridClientTopology top, @Nullable Byte marshId, boolean routerClient) throws GridClientException {
    GridClientConnectionManager mgr;
    try {
        Class<?> cls = Class.forName(ENT_CONN_MGR_CLS);
        Constructor<?> cons = cls.getConstructor(UUID.class, SSLContext.class, GridClientConfiguration.class, Collection.class, GridClientTopology.class, Byte.class, boolean.class);
        mgr = (GridClientConnectionManager) cons.newInstance(clientId, sslCtx, cfg, routers, top, marshId, routerClient);
    } catch (ClassNotFoundException ignored) {
        mgr = new GridClientConnectionManagerOsImpl(clientId, sslCtx, cfg, routers, top, marshId, routerClient);
    } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new GridClientException("Failed to create client connection manager.", e);
    }
    return mgr;
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientConnectionManagerOsImpl(org.apache.ignite.internal.client.impl.connection.GridClientConnectionManagerOsImpl) GridClientConnectionManager(org.apache.ignite.internal.client.impl.connection.GridClientConnectionManager) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with GridClientException

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

the class GridClientNioTcpConnection method execute.

/** {@inheritDoc} */
@Override
public <R> GridClientFutureAdapter<R> execute(String taskName, Object arg, UUID destNodeId, final boolean keepBinaries) throws GridClientConnectionResetException, GridClientClosedException {
    GridClientTaskRequest msg = new GridClientTaskRequest();
    msg.taskName(taskName);
    msg.argument(arg);
    msg.keepBinaries(keepBinaries);
    return this.<GridClientTaskResultBean>makeRequest(msg, destNodeId).chain(new GridClientFutureCallback<GridClientTaskResultBean, R>() {

        @Override
        public R onComplete(GridClientFuture<GridClientTaskResultBean> fut) throws GridClientException {
            return fut.get().getResult();
        }
    });
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientTaskResultBean(org.apache.ignite.internal.processors.rest.client.message.GridClientTaskResultBean) MARSHALLER(org.apache.ignite.internal.util.nio.GridNioSessionMetaKey.MARSHALLER) GridClientTaskRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientTaskRequest)

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

Example 9 with GridClientException

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

the class CommandHandler method main.

/**
     * @param args Args.
     */
public static void main(String[] args) throws GridClientException {
    String host = "127.0.0.1";
    String port = "11212";
    Boolean activate = null;
    if (args.length == 1 && "help".equals(args[0])) {
        System.out.println("Example: --host {ip} --port {port} --{activate/deactivate} " + "or without command --host {ip} --port {port} then will print status.");
        return;
    }
    if (args.length > 5)
        throw new IllegalArgumentException("incorrect number of arguments");
    for (int i = 0; i < args.length; i++) {
        String str = args[i];
        if ("--host".equals(str))
            host = args[i + 1];
        else if ("--port".equals(str))
            port = args[i + 1];
        else if ("--activate".equals(str))
            activate = true;
        else if ("--deactivate".equals(str))
            activate = false;
    }
    if (host == null)
        throw new IllegalArgumentException("host can not be empty");
    if (port == null)
        throw new IllegalArgumentException("port can not be empty");
    GridClientConfiguration cfg = new GridClientConfiguration();
    cfg.setServers(Collections.singletonList(host + ":" + port));
    try (GridClient client = GridClientFactory.start(cfg)) {
        GridClientClusterState state = client.state();
        if (activate != null)
            try {
                state.active(activate);
                System.out.println(host + ":" + port + " - was " + (activate ? "activate" : "deactivate"));
            } catch (Exception e) {
                System.out.println("Something fail during " + (activate ? "activation" : "deactivation") + ", exception message: " + e.getMessage());
            }
        else
            System.out.println(host + ":" + port + " - " + (state.active() ? "active" : "inactive"));
    }
}
Also used : GridClientClusterState(org.apache.ignite.internal.client.GridClientClusterState) GridClient(org.apache.ignite.internal.client.GridClient) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientException(org.apache.ignite.internal.client.GridClientException)

Example 10 with GridClientException

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

the class JdbcResultSet method next.

/** {@inheritDoc} */
@Override
public boolean next() throws SQLException {
    ensureNotClosed();
    if (fields == null && !finished) {
        assert nodeId != null;
        assert futId != null;
        try {
            GridClientCompute compute = stmt.connection().client().compute();
            GridClientCompute prj = compute.projection(compute.node(nodeId));
            byte[] packet = prj.execute(TASK_NAME, JdbcUtils.marshalArgument(JdbcUtils.taskArgument(nodeId, futId, fetchSize, stmt.getMaxRows())));
            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() == 2;
                fields = ((Collection<List<Object>>) msg.get(0)).iterator();
                finished = (Boolean) msg.get(1);
            }
        } catch (GridClientException e) {
            throw new SQLException("Failed to query Ignite.", e);
        }
    }
    if (fields != null && fields.hasNext()) {
        curr = fields.next();
        if (!fields.hasNext())
            fields = null;
        pos++;
        return true;
    } else {
        curr = null;
        return false;
    }
}
Also used : GridClientCompute(org.apache.ignite.internal.client.GridClientCompute) GridClientException(org.apache.ignite.internal.client.GridClientException) SQLException(java.sql.SQLException) List(java.util.List)

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