Search in sources :

Example 41 with IgniteSpiException

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

the class TcpDiscoveryJdbcIpFinder method registerAddresses.

/**
 * {@inheritDoc}
 */
@Override
public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
    assert !F.isEmpty(addrs);
    init();
    Connection conn = null;
    PreparedStatement stmtUnreg = null;
    PreparedStatement stmtReg = null;
    boolean committed = false;
    try {
        conn = dataSrc.getConnection();
        conn.setAutoCommit(false);
        conn.setTransactionIsolation(TRANSACTION_READ_COMMITTED);
        stmtUnreg = conn.prepareStatement(unregAddrQry);
        stmtReg = conn.prepareStatement(regAddrQry);
        for (InetSocketAddress addr : addrs) {
            stmtUnreg.setString(1, addr.getAddress().getHostAddress());
            stmtUnreg.setInt(2, addr.getPort());
            stmtUnreg.addBatch();
            stmtReg.setString(1, addr.getAddress().getHostAddress());
            stmtReg.setInt(2, addr.getPort());
            stmtReg.addBatch();
        }
        stmtUnreg.executeBatch();
        stmtUnreg.close();
        stmtReg.executeBatch();
        stmtReg.close();
        conn.commit();
        committed = true;
    } catch (SQLException e) {
        U.rollbackConnectionQuiet(conn);
        throw new IgniteSpiException("Failed to register addresses: " + addrs, e);
    } finally {
        if (!committed)
            U.rollbackConnectionQuiet(conn);
        U.closeQuiet(stmtUnreg);
        U.closeQuiet(stmtReg);
        U.closeQuiet(conn);
    }
}
Also used : SQLException(java.sql.SQLException) InetSocketAddress(java.net.InetSocketAddress) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 42 with IgniteSpiException

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

the class TcpDiscoveryJdbcIpFinder method init.

/**
 * Checks configuration validity.
 *
 * @throws org.apache.ignite.spi.IgniteSpiException If any error occurs.
 */
private void init() throws IgniteSpiException {
    if (initGuard.compareAndSet(false, true)) {
        if (dataSrc == null)
            throw new IgniteSpiException("Data source is null (you must configure it via setDataSource(..)" + " configuration property)");
        if (!initSchema) {
            initLatch.countDown();
            checkSchema();
            return;
        }
        Connection conn = null;
        boolean committed = false;
        try {
            conn = dataSrc.getConnection();
            conn.setAutoCommit(false);
            conn.setTransactionIsolation(TRANSACTION_READ_COMMITTED);
            DatabaseMetaData dbm = conn.getMetaData();
            // so we do not use it.
            try (ResultSet tables = dbm.getTables(null, null, addrTableName, null)) {
                if (!tables.next()) {
                    // Create tbl_addrs.
                    try (Statement stmt = conn.createStatement()) {
                        stmt.executeUpdate(createAddrsTableQry);
                        conn.commit();
                    } catch (SQLException e) {
                        // see if the table has been created.
                        try (ResultSet tablesAgain = dbm.getTables(null, null, addrTableName, null)) {
                            if (!tablesAgain.next())
                                throw e;
                        }
                    }
                }
            }
            committed = true;
            if (log.isDebugEnabled())
                log.debug("DB schema has been initialized.");
        } catch (SQLException e) {
            U.rollbackConnectionQuiet(conn);
            throw new IgniteSpiException("Failed to initialize DB schema.", e);
        } finally {
            if (!committed)
                U.rollbackConnectionQuiet(conn);
            U.closeQuiet(conn);
            initLatch.countDown();
        }
    } else
        checkSchema();
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 43 with IgniteSpiException

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

the class TcpDiscoveryJdbcIpFinder method checkSchema.

/**
 * Checks correctness of existing DB schema.
 *
 * @throws org.apache.ignite.spi.IgniteSpiException If schema wasn't properly initialized.
 */
private void checkSchema() throws IgniteSpiException {
    try {
        U.await(initLatch);
    } catch (IgniteInterruptedCheckedException e) {
        throw new IgniteSpiException("Thread has been interrupted.", e);
    }
    Connection conn = null;
    Statement stmt = null;
    try {
        conn = dataSrc.getConnection();
        conn.setTransactionIsolation(TRANSACTION_READ_COMMITTED);
        // Check if tbl_addrs exists and database initialized properly.
        stmt = conn.createStatement();
        stmt.execute(chkQry);
    } catch (SQLException e) {
        throw new IgniteSpiException("IP finder has not been properly initialized.", e);
    } finally {
        U.closeQuiet(stmt);
        U.closeQuiet(conn);
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 44 with IgniteSpiException

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

the class KeystoreEncryptionSpi method doEncryption.

/**
 * @param data Plain data.
 * @param cipher Cipher.
 * @param key Encryption key.
 */
private void doEncryption(ByteBuffer data, Cipher cipher, Serializable key, ByteBuffer res) {
    assert key instanceof KeystoreEncryptionKey;
    ensureStarted();
    try {
        SecretKeySpec keySpec = new SecretKeySpec(((KeystoreEncryptionKey) key).key().getEncoded(), CIPHER_ALGO);
        byte[] iv = initVector(cipher);
        res.put(iv);
        cipher.init(ENCRYPT_MODE, keySpec, new IvParameterSpec(iv));
        cipher.doFinal(data, res);
    } catch (ShortBufferException | InvalidAlgorithmParameterException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
        throw new IgniteSpiException(e);
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) ShortBufferException(javax.crypto.ShortBufferException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) IvParameterSpec(javax.crypto.spec.IvParameterSpec) BadPaddingException(javax.crypto.BadPaddingException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) InvalidKeyException(java.security.InvalidKeyException)

Example 45 with IgniteSpiException

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

the class KeystoreEncryptionSpi method decryptNoPadding.

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

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