Search in sources :

Example 46 with IgniteSpiException

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

the class KeystoreEncryptionSpi method loadMasterKey.

/**
 * Loads and returns a master key by name.
 *
 * @param masterKeyName Master key name.
 * @return Master key.
 */
private KeystoreEncryptionKey loadMasterKey(String masterKeyName) {
    assertParameter(!F.isEmpty(keyStorePath), "KeyStorePath shouldn't be empty");
    assertParameter(keyStorePwd != null && keyStorePwd.length > 0, "KeyStorePassword shouldn't be empty");
    try (InputStream keyStoreFile = keyStoreFile()) {
        assertParameter(keyStoreFile != null, keyStorePath + " doesn't exists!");
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(keyStoreFile, keyStorePwd);
        if (log != null && log.isInfoEnabled())
            log.info("Successfully load keyStore [path=" + keyStorePath + "]");
        Key key = ks.getKey(masterKeyName, keyStorePwd);
        assertParameter(key != null, "No such master key found [masterKeyName=" + masterKeyName + ']');
        return new KeystoreEncryptionKey(key, null);
    } catch (GeneralSecurityException | IOException e) {
        throw new IgniteSpiException(e);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) KeyStore(java.security.KeyStore) Key(java.security.Key) SecretKey(javax.crypto.SecretKey)

Example 47 with IgniteSpiException

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

the class TcpDiscoveryVmIpFinder method address.

/**
 * Creates address from string.
 *
 * @param ipStr Address string.
 * @return Socket addresses (may contain 1 or more addresses if provided string
 *      includes port range).
 * @throws IgniteSpiException If failed.
 */
private static Collection<InetSocketAddress> address(String ipStr) throws IgniteSpiException {
    ipStr = ipStr.trim();
    String errMsg = "Failed to parse provided address: " + ipStr;
    int colonCnt = ipStr.length() - ipStr.replace(":", "").length();
    if (colonCnt > 1) {
        // https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443).
        if (ipStr.startsWith("[")) {
            ipStr = ipStr.substring(1);
            if (ipStr.contains("]:"))
                return addresses(ipStr, "\\]\\:", errMsg);
            else if (ipStr.endsWith("]"))
                ipStr = ipStr.substring(0, ipStr.length() - 1);
            else
                throw new IgniteSpiException(errMsg);
        }
    } else {
        // IPv4 address.
        if (ipStr.endsWith(":"))
            ipStr = ipStr.substring(0, ipStr.length() - 1);
        else if (ipStr.indexOf(':') >= 0)
            return addresses(ipStr, "\\:", errMsg);
    }
    Collection<InetSocketAddress> col = new LinkedHashSet<>();
    try {
        InetAddress[] inetAddresses = InetAddress.getAllByName(ipStr);
        for (InetAddress addrs : inetAddresses) col.add(new InetSocketAddress(addrs, 0));
    } catch (UnknownHostException ignored) {
        // Preserve existing behavior on UnknownHostException
        col = Collections.singleton(new InetSocketAddress(ipStr, 0));
    }
    return col;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) InetAddress(java.net.InetAddress)

Example 48 with IgniteSpiException

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

the class GridSpiAbstractConfigTest method checkNegativeSpiProperty.

/**
 * Checks that unacceptable property value prevents SPI from being started.
 *
 * @param spi Spi to test property on.
 * @param propName name of property to check.
 * @param val An illegal value.
 * @param checkExMsg If {@code true} then additional info will be added to failure.
 * @throws Exception If check failed.
 */
protected void checkNegativeSpiProperty(IgniteSpi spi, String propName, Object val, boolean checkExMsg) throws Exception {
    assert spi != null;
    assert propName != null;
    getTestData().getTestResources().inject(spi);
    String mtdName = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1);
    Method mtd = null;
    for (Method m : spi.getClass().getMethods()) if (m.getName().equals(mtdName)) {
        mtd = m;
        break;
    }
    assert mtd != null : "The setter is not found for property: " + propName;
    boolean err = false;
    try {
        mtd.invoke(spi, val);
    } catch (InvocationTargetException e) {
        info("SPI property setter thrown exception: " + e);
        if (e.getCause() instanceof IllegalArgumentException)
            err = true;
        else
            throw e;
    }
    if (!err)
        try {
            if (!(spi instanceof DiscoverySpi))
                spi.getNodeAttributes();
            spi.spiStart(getTestIgniteInstanceName());
        } catch (IgniteSpiException e) {
            info("SPI start thrown exception: " + e);
            if (checkExMsg)
                assert e.getMessage().contains("SPI parameter failed condition check: ") : "SPI has returned wrong exception message [propName=" + propName + ", msg=" + e + ']';
            err = true;
        }
    assert err : "No check for property [property=" + propName + ", value=" + val + ']';
}
Also used : DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) Method(java.lang.reflect.Method) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 49 with IgniteSpiException

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

the class IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setCommunicationSpi(new TcpCommunicationSpi() {

        @Override
        public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackClosure) throws IgniteSpiException {
            if (getSpiContext().localNode().id().equals(failingNodeId)) {
                if (ignoredMessage((GridIoMessage) msg) && ignoreMsgNodeIds != null) {
                    for (UUID ignored : ignoreMsgNodeIds) {
                        if (node.id().equals(ignored))
                            return;
                    }
                }
            }
            super.sendMessage(node, msg, ackClosure);
        }
    });
    cfg.getTransactionConfiguration().setDefaultTxConcurrency(PESSIMISTIC);
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) UUID(java.util.UUID) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)

Example 50 with IgniteSpiException

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

the class LocalWalModeChangeDuringRebalancingSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true).setInitialSize(DataStorageConfiguration.DFLT_DATA_REGION_INITIAL_SIZE).setMaxSize(DataStorageConfiguration.DFLT_DATA_REGION_INITIAL_SIZE)).setCheckpointFrequency(999_999_999_999L).setWalMode(WALMode.LOG_ONLY).setFileIOFactory(new TestFileIOFactory(new DataStorageConfiguration().getFileIOFactory())));
    cfg.setCacheConfiguration(new CacheConfiguration(DEFAULT_CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setRebalanceDelay(-1).setAffinity(new RendezvousAffinityFunction(false, 32)).setBackups(dfltCacheBackupCnt), new CacheConfiguration(REPL_CACHE).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setRebalanceDelay(-1).setCacheMode(CacheMode.REPLICATED));
    cfg.setCommunicationSpi(new TcpCommunicationSpi() {

        @Override
        public void sendMessage(ClusterNode node, Message msg) throws IgniteSpiException {
            if (msg instanceof GridIoMessage && ((GridIoMessage) msg).message() instanceof GridDhtPartitionSupplyMessage) {
                int grpId = ((GridDhtPartitionSupplyMessage) ((GridIoMessage) msg).message()).groupId();
                if (grpId == CU.cacheId(DEFAULT_CACHE_NAME)) {
                    CountDownLatch latch0 = supplyMessageLatch.get();
                    if (latch0 != null)
                        try {
                            latch0.await();
                        } catch (InterruptedException ex) {
                            throw new IgniteException(ex);
                        }
                }
            }
            super.sendMessage(node, msg);
        }

        @Override
        public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) throws IgniteSpiException {
            if (msg instanceof GridIoMessage && ((GridIoMessage) msg).message() instanceof GridDhtPartitionSupplyMessage) {
                int grpId = ((GridDhtPartitionSupplyMessage) ((GridIoMessage) msg).message()).groupId();
                if (grpId == CU.cacheId(DEFAULT_CACHE_NAME)) {
                    CountDownLatch latch0 = supplyMessageLatch.get();
                    if (latch0 != null)
                        try {
                            latch0.await();
                        } catch (InterruptedException ex) {
                            throw new IgniteException(ex);
                        }
                }
            }
            super.sendMessage(node, msg, ackC);
        }
    });
    cfg.setConsistentId(igniteInstanceName);
    System.setProperty(IgniteSystemProperties.IGNITE_DISABLE_WAL_DURING_REBALANCING, Boolean.toString(disableWalDuringRebalancing));
    System.setProperty(IgniteSystemProperties.IGNITE_PENDING_TX_TRACKER_ENABLED, Boolean.toString(enablePendingTxTracker));
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) CountDownLatch(java.util.concurrent.CountDownLatch) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteException(org.apache.ignite.IgniteException) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

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