Search in sources :

Example 96 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class TcpDiscoverySharedFsIpFinder method registerAddresses.

/**
 * {@inheritDoc}
 */
@Override
public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
    assert !F.isEmpty(addrs);
    initFolder();
    try {
        for (String name : distinctNames(addrs)) {
            File file = new File(folder, name);
            file.createNewFile();
        }
    } catch (IOException e) {
        throw new IgniteSpiException("Failed to create file.", e);
    }
}
Also used : IOException(java.io.IOException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) File(java.io.File)

Example 97 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class TcpDiscoverySharedFsIpFinder method initFolder.

/**
 * Initializes folder to work with.
 *
 * @return Folder.
 * @throws org.apache.ignite.spi.IgniteSpiException If failed.
 */
private File initFolder() throws IgniteSpiException {
    if (initGuard.compareAndSet(false, true)) {
        if (path == null)
            throw new IgniteSpiException("Shared file system path is null " + "(it should be configured via setPath(..) configuration property).");
        if (path.equals(DFLT_PATH) && warnGuard.compareAndSet(false, true))
            U.warn(log, "Default local computer-only share is used by IP finder.");
        try {
            File tmp;
            if (new File(path).exists())
                tmp = new File(path);
            else {
                try {
                    tmp = U.resolveWorkDirectory(ignite.configuration().getWorkDirectory(), path, false);
                } catch (IgniteCheckedException e) {
                    throw new IgniteSpiException("Failed to resolve directory [path=" + path + ", exception=" + e.getMessage() + ']');
                }
            }
            if (!tmp.isDirectory())
                throw new IgniteSpiException("Failed to initialize shared file system path " + "(path must point to folder): " + path);
            if (!tmp.canRead() || !tmp.canWrite())
                throw new IgniteSpiException("Failed to initialize shared file system path " + "(path must be readable and writable): " + path);
            folder = tmp;
        } finally {
            initLatch.countDown();
        }
    } else {
        try {
            U.await(initLatch);
        } catch (IgniteInterruptedCheckedException e) {
            throw new IgniteSpiException("Thread has been interrupted.", e);
        }
        if (folder == null)
            throw new IgniteSpiException("Failed to initialize shared file system folder (check logs for errors).");
    }
    return folder;
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) File(java.io.File)

Example 98 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class TcpDiscoveryVmIpFinder method addresses.

/**
 * Creates address from string with port information.
 *
 * @param ipStr Address string
 * @param regexDelim Port regex delimiter.
 * @param errMsg Error message.
 * @return Socket addresses (may contain 1 or more addresses if provided string
 *      includes port range).
 * @throws IgniteSpiException If failed.
 */
private static Collection<InetSocketAddress> addresses(String ipStr, String regexDelim, String errMsg) throws IgniteSpiException {
    String[] tokens = ipStr.split(regexDelim);
    if (tokens.length == 2) {
        String addrStr = tokens[0];
        String portStr = tokens[1];
        int port1, port2;
        if (portStr.contains("..")) {
            port1 = Integer.parseInt(portStr.substring(0, portStr.indexOf("..")));
            port2 = Integer.parseInt(portStr.substring(portStr.indexOf("..") + 2, portStr.length()));
        } else
            port1 = port2 = Integer.parseInt(portStr);
        if ((port1 != port2 && port2 < port1) || port1 <= 0 || port2 <= 0)
            throw new IgniteSpiException(errMsg);
        try {
            Collection<InetSocketAddress> res = new ArrayList<>();
            InetAddress[] inetAddresses;
            try {
                inetAddresses = InetAddress.getAllByName(addrStr);
            } catch (UnknownHostException e) {
                // Ignore
                for (int i = port1; i <= port2; i++) res.add(new InetSocketAddress(addrStr, i));
                return res;
            }
            for (InetAddress curAddr : inetAddresses) {
                // Upper bound included.
                for (int i = port1; i <= port2; i++) res.add(new InetSocketAddress(curAddr, i));
            }
            return res;
        } catch (IllegalArgumentException e) {
            throw new IgniteSpiException(errMsg, e);
        }
    } else
        throw new IgniteSpiException(errMsg);
}
Also used : UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) InetAddress(java.net.InetAddress)

Example 99 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class KeystoreEncryptionSpi method decrypt.

/**
 * {@inheritDoc}
 */
@Override
public byte[] decrypt(byte[] data, Serializable key) {
    assert key instanceof KeystoreEncryptionKey;
    ensureStarted();
    try {
        SecretKeySpec keySpec = new SecretKeySpec(((KeystoreEncryptionKey) key).key().getEncoded(), CIPHER_ALGO);
        Cipher cipher = aesWithPadding.get();
        cipher.init(DECRYPT_MODE, keySpec, new IvParameterSpec(data, 0, cipher.getBlockSize()));
        return cipher.doFinal(data, cipher.getBlockSize(), data.length - cipher.getBlockSize());
    } catch (InvalidAlgorithmParameterException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
        throw new IgniteSpiException(e);
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) BadPaddingException(javax.crypto.BadPaddingException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) InvalidKeyException(java.security.InvalidKeyException)

Example 100 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class TcpDiscoveryImpl method registerLocalNodeAddress.

/**
 * @throws IgniteSpiException If failed.
 */
protected final void registerLocalNodeAddress() throws IgniteSpiException {
    long spiJoinTimeout = spi.getJoinTimeout();
    // Make sure address registration succeeded.
    // ... but limit it if join timeout is configured.
    long startNanos = spiJoinTimeout > 0 ? System.nanoTime() : 0;
    while (true) {
        try {
            spi.ipFinder.initializeLocalAddresses(U.resolveAddresses(spi.getAddressResolver(), locNode.socketAddresses()));
            // Success.
            break;
        } catch (IllegalStateException e) {
            throw new IgniteSpiException("Failed to register local node address with IP finder: " + locNode.socketAddresses(), e);
        } catch (IgniteSpiException e) {
            LT.error(log, e, "Failed to register local node address in IP finder on start " + "(retrying every " + spi.getReconnectDelay() + " ms; " + "change 'reconnectDelay' to configure the frequency of retries).");
        }
        ;
        if (spiJoinTimeout > 0 && U.millisSinceNanos(startNanos) > spiJoinTimeout)
            throw new IgniteSpiException("Failed to register local addresses with IP finder within join timeout " + "(make sure IP finder configuration is correct, and operating system firewalls are disabled " + "on all host machines, or consider increasing 'joinTimeout' configuration property) " + "[joinTimeout=" + spiJoinTimeout + ']');
        try {
            U.sleep(spi.getReconnectDelay());
        } catch (IgniteInterruptedCheckedException e) {
            throw new IgniteSpiException("Thread has been interrupted.", e);
        }
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) 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