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