Search in sources :

Example 21 with IgniteSpiException

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);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 22 with IgniteSpiException

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();
}
Also used : IgniteSpiThread(org.apache.ignite.spi.IgniteSpiThread) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException)

Example 23 with IgniteSpiException

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);
    }
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Collection(java.util.Collection) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 24 with IgniteSpiException

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();
}
Also used : IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient)

Example 25 with IgniteSpiException

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();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) Channel(java.nio.channels.Channel) SocketChannel(java.nio.channels.SocketChannel) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Aggregations

IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)131 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)59 IOException (java.io.IOException)32 InetSocketAddress (java.net.InetSocketAddress)22 ClusterNode (org.apache.ignite.cluster.ClusterNode)21 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)21 IgniteException (org.apache.ignite.IgniteException)20 ArrayList (java.util.ArrayList)14 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)14 HashMap (java.util.HashMap)13 UUID (java.util.UUID)13 Nullable (org.jetbrains.annotations.Nullable)12 Test (org.junit.Test)12 File (java.io.File)10 Message (org.apache.ignite.plugin.extensions.communication.Message)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 SSLException (javax.net.ssl.SSLException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 SocketTimeoutException (java.net.SocketTimeoutException)7 Ignite (org.apache.ignite.Ignite)7