use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class ClientImpl method marshalCredentials.
/**
* Marshalls credentials with discovery SPI marshaller (will replace attribute value).
*
* @param node Node to marshall credentials for.
* @throws IgniteSpiException If marshalling failed.
*/
private void marshalCredentials(TcpDiscoveryNode node) throws IgniteSpiException {
try {
// Use security-unsafe getter.
Map<String, Object> attrs = new HashMap<>(node.getAttributes());
Object creds = attrs.get(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS);
assert !(creds instanceof byte[]);
attrs.put(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS, U.marshal(spi.marshaller(), creds));
node.setAttributes(attrs);
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Failed to marshal node security credentials: " + node.id(), e);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class ClientImpl method spiStart.
/**
* {@inheritDoc}
*/
@Override
public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException {
spi.initLocalNode(0, true);
locNode = spi.locNode;
// Marshal credentials for backward compatibility and security.
marshalCredentials(locNode);
sockWriter = new SocketWriter();
sockWriter.start();
sockReader = new SocketReader();
sockReader.start();
if (spi.ipFinder.isShared() && spi.isForceServerMode())
registerLocalNodeAddress();
msgWorker = new MessageWorker(log);
new IgniteSpiThread(msgWorker.igniteInstanceName(), msgWorker.name(), log) {
@Override
protected void body() {
msgWorker.run();
}
}.start();
executorService.scheduleAtFixedRate(new MetricsSender(), spi.metricsUpdateFreq, spi.metricsUpdateFreq, MILLISECONDS);
try {
joinLatch.await();
IgniteSpiException err = joinErr.get();
if (err != null)
throw err;
} catch (InterruptedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
spi.printStartInfo();
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpCommunicationConfigInitializer method getNodeAttributes.
/**
* {@inheritDoc}
*/
@Override
public Map<String, Object> getNodeAttributes() throws IgniteSpiException {
initFailureDetectionTimeout();
if (Boolean.TRUE.equals(ignite.configuration().isClientMode()))
assertParameter(cfg.localPort() > 1023 || cfg.localPort() == -1, "localPort > 1023 || localPort == -1");
else
assertParameter(cfg.localPort() > 1023, "localPort > 1023");
assertParameter(cfg.localPort() <= 0xffff, "locPort < 0xffff");
assertParameter(cfg.localPortRange() >= 0, "locPortRange >= 0");
assertParameter(cfg.idleConnectionTimeout() > 0, "idleConnTimeout > 0");
assertParameter(cfg.socketReceiveBuffer() >= 0, "sockRcvBuf >= 0");
assertParameter(cfg.socketSendBuffer() >= 0, "sockSndBuf >= 0");
assertParameter(cfg.messageQueueLimit() >= 0, "msgQueueLimit >= 0");
assertParameter(cfg.selectorsCount() > 0, "selectorsCnt > 0");
assertParameter(cfg.connectionsPerNode() > 0, "connectionsPerNode > 0");
assertParameter(cfg.connectionsPerNode() <= MAX_CONN_PER_NODE, "connectionsPerNode <= 1024");
if (!failureDetectionTimeoutEnabled()) {
assertParameter(cfg.reconCount() > 0, "reconnectCnt > 0");
assertParameter(cfg.connectionTimeout() >= 0, "connTimeout >= 0");
assertParameter(cfg.maxConnectionTimeout() >= cfg.connectionTimeout(), "maxConnTimeout >= connTimeout");
}
assertParameter(cfg.socketWriteTimeout() >= 0, "sockWriteTimeout >= 0");
assertParameter(cfg.ackSendThreshold() > 0, "ackSndThreshold > 0");
assertParameter(cfg.unackedMsgsBufferSize() >= 0, "unackedMsgsBufSize >= 0");
if (cfg.unackedMsgsBufferSize() > 0) {
assertParameter(cfg.unackedMsgsBufferSize() >= cfg.messageQueueLimit() * 5, "Specified 'unackedMsgsBufSize' is too low, it should be at least 'msgQueueLimit * 5'.");
assertParameter(cfg.unackedMsgsBufferSize() >= cfg.ackSendThreshold() * 5, "Specified 'unackedMsgsBufSize' is too low, it should be at least 'ackSndThreshold * 5'.");
}
// Set local node attributes.
try {
IgniteBiTuple<Collection<String>, Collection<String>> addrs = U.resolveLocalAddresses(cfg.localHost());
if (cfg.localPort() != -1 && addrs.get1().isEmpty() && addrs.get2().isEmpty())
throw new IgniteCheckedException("No network addresses found (is networking enabled?).");
Collection<InetSocketAddress> extAddrs = cfg.addrRslvr() == null ? null : U.resolveAddresses(cfg.addrRslvr(), F.flat(Arrays.asList(addrs.get1(), addrs.get2())), cfg.boundTcpPort());
Map<String, Object> res = new HashMap<>(5);
boolean setEmptyHostNamesAttr = !getBoolean(IGNITE_TCP_COMM_SET_ATTR_HOST_NAMES, false) && (!F.isEmpty(cfg.localAddress()) && cfg.localHost().getHostAddress().equals(cfg.localAddress())) && !cfg.localHost().isAnyLocalAddress() && !cfg.localHost().isLoopbackAddress();
res.put(createSpiAttributeName(ATTR_ADDRS), addrs.get1());
res.put(createSpiAttributeName(ATTR_HOST_NAMES), setEmptyHostNamesAttr ? emptyList() : addrs.get2());
res.put(createSpiAttributeName(ATTR_PORT), cfg.boundTcpPort() == -1 ? DISABLED_CLIENT_PORT : cfg.boundTcpPort());
res.put(createSpiAttributeName(ATTR_EXT_ADDRS), extAddrs);
res.put(createSpiAttributeName(ATTR_PAIRED_CONN), cfg.usePairedConnections());
res.put(createSpiAttributeName(ATTR_FORCE_CLIENT_SERVER_CONNECTIONS), cfg.forceClientToSrvConnections());
return res;
} catch (IOException | IgniteCheckedException e) {
throw new IgniteSpiException("Failed to resolve local host to addresses: " + cfg.localHost(), e);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class ConnectionClientPool method stop.
/**
*/
public void stop() {
this.stopping = true;
for (GridFutureAdapter<GridCommunicationClient> fut : clientFuts.values()) {
if (fut instanceof ConnectionRequestFuture) {
// There's no way it would be done by itself at this point.
fut.onDone(new IgniteSpiException("SPI is being stopped."));
}
}
handshakeTimeoutExecutorService.shutdown();
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class GridNioServerWrapper method openChannel.
/**
* @param remote Destination cluster node to communicate with.
* @param initMsg Configuration channel attributes wrapped into the message.
* @return The future, which will be finished on channel ready.
* @throws IgniteSpiException If fails.
*/
public IgniteInternalFuture<Channel> openChannel(ClusterNode remote, Message initMsg) throws IgniteSpiException {
assert !remote.isLocal() : remote;
assert initMsg != null;
assert chConnPlc != null;
assert nodeSupports(remote, CHANNEL_COMMUNICATION) : "Node doesn't support direct connection over socket channel " + "[nodeId=" + remote.id() + ']';
ConnectionKey key = new ConnectionKey(remote.id(), chConnPlc.connectionIndex());
GridFutureAdapter<Channel> chFut = new GridFutureAdapter<>();
connectGate.enter();
try {
GridNioSession ses = createNioSession(remote, key.connectionIndex());
assert ses != null : "Session must be established [remoteId=" + remote.id() + ", key=" + key + ']';
cleanupLocalNodeRecoveryDescriptor(key);
ses.addMeta(CHANNEL_FUT_META, chFut);
// Send configuration message over the created session.
ses.send(initMsg).listen(f -> {
if (f.error() != null) {
GridFutureAdapter<Channel> rq = ses.meta(CHANNEL_FUT_META);
assert rq != null;
rq.onDone(f.error());
ses.close();
return;
}
Runnable closeRun = () -> {
// Close session if request not complete yet.
GridFutureAdapter<Channel> rq = ses.meta(CHANNEL_FUT_META);
assert rq != null;
if (rq.onDone(handshakeTimeoutException()))
ses.close();
};
handshakeTimeoutExecutorService.schedule(closeRun, cfg.connectionTimeout(), TimeUnit.MILLISECONDS);
});
return chFut;
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Unable to create new channel connection to the remote node: " + remote, e);
} finally {
connectGate.leave();
}
}
Aggregations