Search in sources :

Example 6 with Factory

use of javax.cache.configuration.Factory in project ignite by apache.

the class JdbcThinSSLUtil method getSSLSocketFactory.

/**
 * @param connProps Connection properties.
 * @return SSL socket factory.
 * @throws SQLException On error.
 */
private static SSLSocketFactory getSSLSocketFactory(ConnectionProperties connProps) throws SQLException {
    String sslFactory = connProps.getSslFactory();
    String cipherSuites = connProps.getSslCipherSuites();
    String cliCertKeyStoreUrl = connProps.getSslClientCertificateKeyStoreUrl();
    String cliCertKeyStorePwd = connProps.getSslClientCertificateKeyStorePassword();
    String cliCertKeyStoreType = connProps.getSslClientCertificateKeyStoreType();
    String trustCertKeyStoreUrl = connProps.getSslTrustCertificateKeyStoreUrl();
    String trustCertKeyStorePwd = connProps.getSslTrustCertificateKeyStorePassword();
    String trustCertKeyStoreType = connProps.getSslTrustCertificateKeyStoreType();
    String sslProtocol = connProps.getSslProtocol();
    String keyAlgorithm = connProps.getSslKeyAlgorithm();
    if (!F.isEmpty(sslFactory)) {
        try {
            Class<Factory<SSLSocketFactory>> cls = (Class<Factory<SSLSocketFactory>>) JdbcThinSSLUtil.class.getClassLoader().loadClass(sslFactory);
            Factory<SSLSocketFactory> f = cls.newInstance();
            return f.create();
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
            throw new SQLException("Could not fount SSL factory class: " + sslFactory, SqlStateCode.CLIENT_CONNECTION_FAILED, e);
        }
    }
    if (cliCertKeyStoreUrl == null && cliCertKeyStorePwd == null && cliCertKeyStoreType == null && trustCertKeyStoreUrl == null && trustCertKeyStorePwd == null && trustCertKeyStoreType == null && sslProtocol == null && cipherSuites == null) {
        try {
            return SSLContext.getDefault().getSocketFactory();
        } catch (NoSuchAlgorithmException e) {
            throw new SQLException("Could not create default SSL context", SqlStateCode.CLIENT_CONNECTION_FAILED, e);
        }
    }
    if (cliCertKeyStoreUrl == null)
        cliCertKeyStoreUrl = System.getProperty("javax.net.ssl.keyStore");
    if (cliCertKeyStorePwd == null)
        cliCertKeyStorePwd = System.getProperty("javax.net.ssl.keyStorePassword");
    if (cliCertKeyStoreType == null)
        cliCertKeyStoreType = System.getProperty("javax.net.ssl.keyStoreType", DFLT_STORE_TYPE);
    if (trustCertKeyStoreUrl == null)
        trustCertKeyStoreUrl = System.getProperty("javax.net.ssl.trustStore");
    if (trustCertKeyStorePwd == null)
        trustCertKeyStorePwd = System.getProperty("javax.net.ssl.trustStorePassword");
    if (trustCertKeyStoreType == null)
        trustCertKeyStoreType = System.getProperty("javax.net.ssl.trustStoreType", DFLT_STORE_TYPE);
    if (sslProtocol == null)
        sslProtocol = DFLT_SSL_PROTOCOL;
    if (keyAlgorithm == null)
        keyAlgorithm = DFLT_KEY_ALGORITHM;
    SslContextFactory f = new SslContextFactory();
    f.setProtocol(sslProtocol);
    f.setKeyAlgorithm(keyAlgorithm);
    f.setKeyStoreFilePath(cliCertKeyStoreUrl);
    f.setKeyStoreType(cliCertKeyStoreType);
    f.setKeyStorePassword((cliCertKeyStorePwd == null) ? EMPTY_CHARS : cliCertKeyStorePwd.toCharArray());
    if (connProps.isSslTrustAll())
        f.setTrustManagers(TRUST_ALL_MANAGER);
    else {
        f.setTrustStoreFilePath(trustCertKeyStoreUrl);
        f.setTrustStoreType(trustCertKeyStoreType);
        f.setTrustStorePassword((trustCertKeyStorePwd == null) ? EMPTY_CHARS : trustCertKeyStorePwd.toCharArray());
    }
    if (!F.isEmpty(cipherSuites))
        f.setCipherSuites(cipherSuites.split(","));
    try {
        final SSLContext sslContext = f.create();
        return sslContext.getSocketFactory();
    } catch (IgniteException e) {
        final Throwable cause = e.getCause();
        // Unwrap.
        if (cause instanceof SSLException)
            throw new SQLException(cause.getMessage(), SqlStateCode.CLIENT_CONNECTION_FAILED, e);
        else
            throw new SQLException("Unknown error.", SqlStateCode.CLIENT_CONNECTION_FAILED, e);
    }
}
Also used : SQLException(java.sql.SQLException) Factory(javax.cache.configuration.Factory) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) SslContextFactory(org.apache.ignite.ssl.SslContextFactory) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SSLContext(javax.net.ssl.SSLContext) SSLException(javax.net.ssl.SSLException) SslContextFactory(org.apache.ignite.ssl.SslContextFactory) IgniteException(org.apache.ignite.IgniteException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Example 7 with Factory

use of javax.cache.configuration.Factory in project ignite by apache.

the class ConfigVariations method nearCacheConfigurationFactory.

/**
 * @return Custom near cache config.
 */
private static Factory nearCacheConfigurationFactory() {
    return new Factory() {

        @Override
        public Object create() {
            NearCacheConfiguration cfg = new NearCacheConfiguration<>();
            cfg.setNearEvictionPolicy(new FifoEvictionPolicy());
            return cfg;
        }
    };
}
Also used : Factory(javax.cache.configuration.Factory) FifoEvictionPolicy(org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy) NearCacheConfiguration(org.apache.ignite.configuration.NearCacheConfiguration)

Example 8 with Factory

use of javax.cache.configuration.Factory in project ignite by apache.

the class GridP2PContinuousDeploymentClientDisconnectTest method testContinuousQueryRemoteTransformer.

/**
 * Test starts 1 server node and 1 client node. Class-loading request for the {@link #P2P_TEST_OBJ_RSRC_NAME}
 * resource blocks on the client node. The client node tries to deploy CQ with remote transformer for
 * the cache {@link #DEFAULT_CACHE_NAME}.
 * Expected that exception with 'Failed to unmarshal deployable object.' error message will be thrown and
 * the server node wouldn't be failed.
 *
 * @throws Exception If failed.
 */
@Test
public void testContinuousQueryRemoteTransformer() throws Exception {
    Class<Factory<IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Integer>, String>>> rmtTransformerFactoryCls = (Class<Factory<IgniteClosure<CacheEntryEvent<? extends Integer, ? extends Integer>, String>>>) getExternalClassLoader().loadClass(REMOTE_TRANSFORMER_FACTORY_CLS_NAME);
    ContinuousQueryWithTransformer<Integer, Integer, String> qry = new ContinuousQueryWithTransformer<Integer, Integer, String>().setLocalListener(evts -> {
    // No-op.
    }).setRemoteTransformerFactory(rmtTransformerFactoryCls.newInstance());
    LogListener lsnr = LogListener.matches("Failed to initialize a continuous query.").build();
    testLog.registerListener(lsnr);
    IgniteCache<Integer, Integer> cache = grid(1).cache(DEFAULT_CACHE_NAME);
    cache.query(qry);
    assertTrue(lsnr.check());
    // Check that the failure handler was not called.
    assertFalse(failure.get());
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) IgniteEx(org.apache.ignite.internal.IgniteEx) TOPIC_CLASSLOAD(org.apache.ignite.internal.GridTopic.TOPIC_CLASSLOAD) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridDeploymentManager(org.apache.ignite.internal.managers.deployment.GridDeploymentManager) AbstractFailureHandler(org.apache.ignite.failure.AbstractFailureHandler) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) FailureContext(org.apache.ignite.failure.FailureContext) IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) GridDeploymentRequest(org.apache.ignite.internal.managers.deployment.GridDeploymentRequest) CacheException(javax.cache.CacheException) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) Factory(javax.cache.configuration.Factory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) EventType(org.apache.ignite.events.EventType) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) IgniteClosure(org.apache.ignite.lang.IgniteClosure) LogListener(org.apache.ignite.testframework.LogListener) Factory(javax.cache.configuration.Factory) CacheEntryEvent(javax.cache.event.CacheEntryEvent) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with Factory

use of javax.cache.configuration.Factory in project ignite by apache.

the class GridP2PContinuousDeploymentClientDisconnectTest method testContinuousQueryRemoteFilterFactory.

/**
 * Test starts 1 server node and 1 client node. Class-loading request for the {@link #P2P_TEST_OBJ_RSRC_NAME}
 * resource blocks on the client node. The client node tries to deploy CQ with remote filter factory for
 * the cache {@link #DEFAULT_CACHE_NAME}.
 * Expected that exception with 'Failed to initialize a continuous query.' error message will be thrown and
 * the server node wouldn't be failed.
 *
 * @throws Exception If failed.
 */
@Test
public void testContinuousQueryRemoteFilterFactory() throws Exception {
    final Class<Factory<? extends CacheEntryEventFilter<Integer, Integer>>> rmtFilterFactoryCls = (Class<Factory<? extends CacheEntryEventFilter<Integer, Integer>>>) getExternalClassLoader().loadClass(REMOTE_FILTER_FACTORY_CLS_NAME);
    AbstractContinuousQuery<Integer, Integer> qry = new ContinuousQuery<Integer, Integer>().setLocalListener(evts -> {
    // No-op.
    }).setRemoteFilterFactory(rmtFilterFactoryCls.newInstance());
    IgniteEx client = grid(1);
    LogListener lsnr = LogListener.matches("Failed to initialize a continuous query.").build();
    testLog.registerListener(lsnr);
    IgniteCache<Integer, Integer> cache = client.cache(DEFAULT_CACHE_NAME);
    cache.query(qry);
    assertTrue(lsnr.check());
    // Check that the failure handler was not called.
    assertFalse(failure.get());
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CacheEntryEventSerializableFilter(org.apache.ignite.cache.CacheEntryEventSerializableFilter) IgniteEx(org.apache.ignite.internal.IgniteEx) TOPIC_CLASSLOAD(org.apache.ignite.internal.GridTopic.TOPIC_CLASSLOAD) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridDeploymentManager(org.apache.ignite.internal.managers.deployment.GridDeploymentManager) AbstractFailureHandler(org.apache.ignite.failure.AbstractFailureHandler) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) FailureContext(org.apache.ignite.failure.FailureContext) IgniteClosure(org.apache.ignite.lang.IgniteClosure) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) GridDeploymentRequest(org.apache.ignite.internal.managers.deployment.GridDeploymentRequest) CacheException(javax.cache.CacheException) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) Factory(javax.cache.configuration.Factory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) EventType(org.apache.ignite.events.EventType) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) Factory(javax.cache.configuration.Factory) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 10 with Factory

use of javax.cache.configuration.Factory in project ignite by apache.

the class CacheHibernateStoreSessionListenerSelfTest method sessionListenerFactory.

/**
 * {@inheritDoc}
 */
@Override
protected Factory<CacheStoreSessionListener> sessionListenerFactory() {
    return new Factory<CacheStoreSessionListener>() {

        @Override
        public CacheStoreSessionListener create() {
            CacheHibernateStoreSessionListener lsnr = new CacheHibernateStoreSessionListener();
            SessionFactory sesFactory = new Configuration().setProperty("hibernate.connection.url", URL).addAnnotatedClass(Table1.class).addAnnotatedClass(Table2.class).buildSessionFactory();
            lsnr.setSessionFactory(sesFactory);
            return lsnr;
        }
    };
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) Factory(javax.cache.configuration.Factory) SessionFactory(org.hibernate.SessionFactory)

Aggregations

Factory (javax.cache.configuration.Factory)20 CacheEntryEventFilter (javax.cache.event.CacheEntryEventFilter)10 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)10 IgniteCache (org.apache.ignite.IgniteCache)6 CacheEntryEvent (javax.cache.event.CacheEntryEvent)5 Ignite (org.apache.ignite.Ignite)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 Test (org.junit.Test)5 Map (java.util.Map)4 AbstractContinuousQuery (org.apache.ignite.cache.query.AbstractContinuousQuery)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Cache (javax.cache.Cache)3 CacheException (javax.cache.CacheException)3 FactoryBuilder (javax.cache.configuration.FactoryBuilder)3 IgniteException (org.apache.ignite.IgniteException)3 ContinuousQueryWithTransformer (org.apache.ignite.cache.query.ContinuousQueryWithTransformer)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 GridDeploymentRequest (org.apache.ignite.internal.managers.deployment.GridDeploymentRequest)3