use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class ClientAbstractSelfTest method testShutdown.
/**
* @throws Exception If failed.
*/
public void testShutdown() throws Exception {
GridClient c = client();
GridClientCompute compute = c.compute();
String taskName = getTaskName();
Object taskArg = getTaskArgument();
Collection<GridClientFuture<Object>> futs = new ArrayList<>();
// Validate connection works.
compute.execute(taskName, taskArg);
info(">>> First task executed successfully, running batch.");
for (int i = 0; i < 10; i++) futs.add(compute.executeAsync(taskName, taskArg));
// Stop client.
GridClientFactory.stop(c.id(), true);
info(">>> Completed stop request.");
int failed = 0;
for (GridClientFuture<Object> fut : futs) {
try {
assertEquals(17, fut.get());
} catch (GridClientException e) {
failed++;
log.warning("Task execution failed.", e);
}
}
assertEquals(0, failed);
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class GridClientConnectionManagerAdapter method init.
/** {@inheritDoc} */
@SuppressWarnings("BusyWait")
@Override
public void init(Collection<InetSocketAddress> srvs) throws GridClientException, InterruptedException {
init0();
GridClientException firstEx = null;
for (int i = 0; i < INIT_RETRY_CNT; i++) {
Collection<InetSocketAddress> srvsCp = new ArrayList<>(srvs);
while (!srvsCp.isEmpty()) {
GridClientConnection conn = null;
try {
conn = connect(null, srvsCp);
conn.topology(cfg.isAutoFetchAttributes(), cfg.isAutoFetchMetrics(), null).get();
return;
} catch (GridServerUnreachableException e) {
// No connection could be opened to any of initial addresses - exit to retry loop.
assert conn == null : "GridClientConnectionResetException was thrown from GridClientConnection#topology";
if (firstEx == null)
firstEx = e;
break;
} catch (GridClientConnectionResetException e) {
// trying other initial addresses if any.
assert conn != null : "GridClientConnectionResetException was thrown from connect()";
if (firstEx == null)
firstEx = e;
if (!srvsCp.remove(conn.serverAddress()))
// We have misbehaving collection or equals - just exit to avoid infinite loop.
break;
}
}
Thread.sleep(INIT_RETRY_INTERVAL);
}
for (GridClientConnection c : conns.values()) {
conns.remove(c.serverAddress(), c);
c.close(FAILED, false);
}
throw firstEx;
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class GridClientConnectionManagerAdapter method connect.
/**
* Create new connection to specified server.
*
* @param nodeId {@code UUID} of node for mapping with connection.
* {@code null} if no need of mapping.
* @param addr Remote socket to connect.
* @return Established connection.
* @throws IOException If connection failed.
* @throws GridClientException If protocol error happened.
* @throws InterruptedException If thread was interrupted before connection was established.
*/
protected GridClientConnection connect(@Nullable UUID nodeId, InetSocketAddress addr) throws IOException, GridClientException, InterruptedException {
endpointStripedLock.lock(addr);
try {
GridClientConnection old = conns.get(addr);
if (old != null) {
if (old.isClosed()) {
conns.remove(addr, old);
if (nodeId != null)
nodeConns.remove(nodeId, old);
} else {
if (nodeId != null)
nodeConns.put(nodeId, old);
return old;
}
}
SecurityCredentials cred = null;
try {
if (cfg.getSecurityCredentialsProvider() != null)
cred = cfg.getSecurityCredentialsProvider().credentials();
} catch (IgniteCheckedException e) {
throw new GridClientException("Failed to obtain client credentials.", e);
}
GridClientConnection conn;
if (cfg.getProtocol() == GridClientProtocol.TCP) {
GridClientMarshaller marsh = cfg.getMarshaller();
try {
conn = new GridClientNioTcpConnection(srv, clientId, addr, sslCtx, pingExecutor, cfg.getConnectTimeout(), cfg.getPingInterval(), cfg.getPingTimeout(), cfg.isTcpNoDelay(), marsh, marshId, top, cred, keepBinariesThreadLocal());
} catch (GridClientException e) {
if (marsh instanceof GridClientZipOptimizedMarshaller) {
log.warning("Failed to connect with GridClientZipOptimizedMarshaller," + " trying to fallback to default marshaller: " + e);
conn = new GridClientNioTcpConnection(srv, clientId, addr, sslCtx, pingExecutor, cfg.getConnectTimeout(), cfg.getPingInterval(), cfg.getPingTimeout(), cfg.isTcpNoDelay(), ((GridClientZipOptimizedMarshaller) marsh).defaultMarshaller(), marshId, top, cred, keepBinariesThreadLocal());
} else
throw e;
}
} else
throw new GridServerUnreachableException("Failed to create client (protocol is not supported): " + cfg.getProtocol());
old = conns.putIfAbsent(addr, conn);
assert old == null;
if (nodeId != null)
nodeConns.put(nodeId, conn);
return conn;
} finally {
endpointStripedLock.unlock(addr);
}
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class GridTcpRouterImpl method start.
/**
* Starts router.
*
* @throws IgniteException If failed.
*/
@Override
public void start() throws IgniteException {
try {
client = createClient(cfg);
} catch (GridClientException e) {
throw new IgniteException("Failed to initialise embedded client.", e);
}
GridNioServerListener<GridClientMessage> lsnr;
try {
Class<?> cls = Class.forName(ENT_NIO_LSNR_CLS);
Constructor<?> cons = cls.getDeclaredConstructor(IgniteLogger.class, GridRouterClientImpl.class);
cons.setAccessible(true);
lsnr = (GridNioServerListener<GridClientMessage>) cons.newInstance(log, client);
} catch (ClassNotFoundException ignored) {
lsnr = new GridTcpRouterNioListenerOsImpl(log, client);
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new IgniteException("Failed to create NIO listener.", e);
}
parser = new GridTcpRouterNioParser();
final InetAddress hostAddr;
try {
hostAddr = InetAddress.getByName(cfg.getHost());
} catch (UnknownHostException e) {
throw new IgniteException("Failed to resolve grid address for configured host: " + cfg.getHost(), e);
}
SSLContext sslCtx;
try {
GridSslContextFactory sslCtxFactory = cfg.getSslContextFactory();
sslCtx = sslCtxFactory == null ? null : sslCtxFactory.createSslContext();
} catch (SSLException e) {
throw new IgniteException("Failed to create SSL context.", e);
}
for (int port = cfg.getPort(), last = port + cfg.getPortRange(); port <= last; port++) {
if (startTcpServer(hostAddr, port, lsnr, parser, cfg.isNoDelay(), sslCtx, cfg.isSslClientAuth(), cfg.isSslClientAuth())) {
if (log.isInfoEnabled())
log.info("TCP router successfully started for endpoint: " + hostAddr.getHostAddress() + ":" + port);
bindPort = port;
bindHost = hostAddr.getHostName();
break;
} else
U.warn(log, "TCP REST router failed to start on endpoint: " + hostAddr.getHostAddress() + ":" + port + ". Will try next port within allowed port range.");
}
if (bindPort == 0)
throw new IgniteException("Failed to bind TCP router server (possibly all ports in range " + "are in use) [firstPort=" + cfg.getPort() + ", lastPort=" + (cfg.getPort() + cfg.getPortRange()) + ", addr=" + hostAddr + ']');
try {
ObjectName objName = U.registerMBean(ManagementFactory.getPlatformMBeanServer(), "Router", "TCP Router " + id, getClass().getSimpleName(), this, GridTcpRouterMBean.class);
if (log.isDebugEnabled())
log.debug("Registered MBean: " + objName);
mbeanName = objName;
} catch (JMException e) {
U.error(log, "Failed to register MBean.", e);
}
}
use of org.apache.ignite.internal.client.GridClientException in project ignite by apache.
the class GridClientImpl method data.
/** {@inheritDoc} */
@Override
public GridClientData data(@Nullable final String cacheName) throws GridClientException {
checkClosed();
Object key = maskNull(cacheName);
GridClientDataImpl data = dataMap.get(key);
if (data == null) {
GridClientDataConfiguration dataCfg = cfg.getDataConfiguration(cacheName);
if (dataCfg == null && cacheName != null)
throw new GridClientException("Data configuration for given cache name was not provided: " + cacheName);
GridClientLoadBalancer balancer = dataCfg != null ? dataCfg.getPinnedBalancer() : new GridClientRandomBalancer();
GridClientPredicate<GridClientNode> cacheNodes = new GridClientPredicate<GridClientNode>() {
@Override
public boolean apply(GridClientNode e) {
return e.caches().containsKey(cacheName);
}
@Override
public String toString() {
return "GridClientHasCacheFilter [cacheName=" + cacheName + "]";
}
};
data = new GridClientDataImpl(cacheName, this, null, cacheNodes, balancer, null, cfg.isEnableMetricsCache());
GridClientDataImpl old = dataMap.putIfAbsent(key, data);
if (old != null)
data = old;
}
return data;
}
Aggregations