Search in sources :

Example 16 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)

Example 17 with GridClientException

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

the class GridTcpRouterNioListenerAdapter method onMessage.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("TypeMayBeWeakened")
@Override
public void onMessage(final GridNioSession ses, final GridClientMessage msg) {
    if (msg instanceof GridRouterRequest) {
        GridRouterRequest routerMsg = (GridRouterRequest) msg;
        final UUID clientId = routerMsg.clientId();
        final long reqId = routerMsg.requestId();
        try {
            client.forwardMessage(routerMsg, routerMsg.destinationId(), ses.<Byte>meta(MARSHALLER_ID.ordinal())).listen(new GridClientFutureListener() {

                @Override
                public void onDone(GridClientFuture fut) {
                    try {
                        GridRouterResponse res = (GridRouterResponse) fut.get();
                        // Restoring original request id, because it was overwritten by the client.
                        res.requestId(reqId);
                        ses.send(res);
                    } catch (GridClientException e) {
                        ses.send(makeFailureResponse(e, clientId, reqId));
                    }
                }
            });
        } catch (GridClientException e) {
            ses.send(makeFailureResponse(e, clientId, reqId));
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            U.warn(log, "Message forwarding was interrupted (will ignore last message): " + e.getMessage(), "Message forwarding was interrupted.");
        }
    } else if (msg instanceof GridClientHandshakeRequest) {
        GridClientHandshakeRequest hs = (GridClientHandshakeRequest) msg;
        short ver = hs.version();
        if (!SUPP_VERS.contains(ver)) {
            U.error(log, "Client protocol version is not supported [ses=" + ses + ", ver=" + ver + ", supported=" + SUPP_VERS + ']');
            ses.close();
        } else {
            byte marshId = hs.marshallerId();
            GridClientMarshaller marsh = marshMap.get(marshId);
            if (marsh == null) {
                U.error(log, "Client marshaller ID is invalid. Note that .NET and C++ clients " + "are supported only in enterprise edition [ses=" + ses + ", marshId=" + marshId + ']');
                ses.close();
            } else {
                ses.addMeta(MARSHALLER_ID.ordinal(), marshId);
                ses.addMeta(MARSHALLER.ordinal(), marsh);
                ses.send(GridClientHandshakeResponse.OK);
            }
        }
    } else if (msg instanceof GridClientPingPacket)
        ses.send(GridClientPingPacket.PING_MESSAGE);
    else
        throw new IllegalArgumentException("Unsupported input message: " + msg);
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientFuture(org.apache.ignite.internal.client.GridClientFuture) GridRouterResponse(org.apache.ignite.internal.processors.rest.client.message.GridRouterResponse) GridClientMarshaller(org.apache.ignite.internal.client.marshaller.GridClientMarshaller) GridRouterRequest(org.apache.ignite.internal.processors.rest.client.message.GridRouterRequest) GridClientPingPacket(org.apache.ignite.internal.processors.rest.client.message.GridClientPingPacket) GridClientFutureListener(org.apache.ignite.internal.client.GridClientFutureListener) GridClientHandshakeRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientHandshakeRequest) UUID(java.util.UUID)

Example 18 with GridClientException

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

the class GridClientDataImpl method affinity.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public <K> UUID affinity(K key) throws GridClientException {
    A.notNull(key, "key");
    GridClientDataAffinity affinity = client.affinity(cacheName);
    if (affinity == null)
        return null;
    Collection<? extends GridClientNode> prj = projectionNodes();
    if (prj.isEmpty())
        throw new GridClientException("Failed to get affinity node (projection node set for cache is empty): " + cacheName());
    GridClientNode node = affinity.node(key, prj);
    assert node != null;
    return node.nodeId();
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientDataAffinity(org.apache.ignite.internal.client.GridClientDataAffinity)

Example 19 with GridClientException

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

the class GridClientImpl method parseAddresses.

/**
 * Maps Collection of strings to collection of {@code InetSocketAddress}es.
 *
 * @param cfgAddrs Collection fo string representations of addresses.
 * @return Collection of {@code InetSocketAddress}es
 * @throws GridClientException In case of error.
 */
private static Collection<InetSocketAddress> parseAddresses(Collection<String> cfgAddrs) throws GridClientException {
    Collection<InetSocketAddress> addrs = new ArrayList<>(cfgAddrs.size());
    for (String srvStr : cfgAddrs) {
        try {
            String[] split = srvStr.split(":");
            InetSocketAddress addr = new InetSocketAddress(split[0], Integer.parseInt(split[1]));
            addrs.add(addr);
        } catch (RuntimeException e) {
            throw new GridClientException("Failed to create client (invalid server address specified): " + srvStr, e);
        }
    }
    return Collections.unmodifiableCollection(addrs);
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList)

Example 20 with GridClientException

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

the class GridClientNioTcpConnection method handleClientResponse.

/**
 * Handler responses addressed to this client.
 *
 * @param fut Response future.
 * @param resp Response.
 */
@SuppressWarnings("unchecked")
private void handleClientResponse(TcpClientFuture fut, GridClientResponse resp) {
    if (resp.sessionToken() != null)
        sesTok = resp.sessionToken();
    GridClientMessage src = fut.pendingMessage();
    switch(fut.retryState()) {
        case TcpClientFuture.STATE_INITIAL:
            {
                if (resp.successStatus() == GridClientResponse.STATUS_AUTH_FAILURE) {
                    if (credentials() == null) {
                        fut.onDone(new GridClientAuthenticationException("Authentication failed on server " + "(client has no credentials) [clientId=" + clientId + ", srvAddr=" + serverAddress() + ", errMsg=" + resp.errorMessage() + ']'));
                        removePending(resp.requestId());
                        return;
                    }
                    fut.retryState(TcpClientFuture.STATE_AUTH_RETRY);
                    GridClientAuthenticationRequest req = buildAuthRequest();
                    req.requestId(resp.requestId());
                    ses.send(req);
                    return;
                }
                break;
            }
        case TcpClientFuture.STATE_AUTH_RETRY:
            {
                if (resp.successStatus() == GridClientResponse.STATUS_SUCCESS) {
                    fut.retryState(TcpClientFuture.STATE_REQUEST_RETRY);
                    src.sessionToken(sesTok);
                    ses.send(src);
                    return;
                }
                break;
            }
    }
    removePending(resp.requestId());
    if (resp.successStatus() == GridClientResponse.STATUS_AUTH_FAILURE)
        fut.onDone(new GridClientAuthenticationException("Client authentication failed [clientId=" + clientId + ", srvAddr=" + serverAddress() + ", errMsg=" + resp.errorMessage() + ']'));
    else if (resp.errorMessage() != null)
        fut.onDone(new GridClientException(resp.errorMessage()));
    else
        fut.onDone(resp.result());
}
Also used : GridClientException(org.apache.ignite.internal.client.GridClientException) GridClientAuthenticationRequest(org.apache.ignite.internal.processors.rest.client.message.GridClientAuthenticationRequest) GridClientAuthenticationException(org.apache.ignite.internal.client.GridClientAuthenticationException) GridClientMessage(org.apache.ignite.internal.processors.rest.client.message.GridClientMessage)

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 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 GridConnectionIdleClosedException (org.apache.ignite.internal.client.impl.connection.GridConnectionIdleClosedException)2