Search in sources :

Example 1 with UserCodeDeploymentConfig

use of com.hazelcast.config.UserCodeDeploymentConfig in project hazelcast by hazelcast.

the class CacheTypesConfigTest method cacheConfigShouldBeAddedOnJoiningMember_whenKVTypesAvailableViaUserCodeDeployment.

// When the joining member is not aware of key or value class but it is later resolvable via user code deployment, then
// all Cache features should work
@Test
public void cacheConfigShouldBeAddedOnJoiningMember_whenKVTypesAvailableViaUserCodeDeployment() {
    // create a HazelcastInstance with a CacheConfig referring to a Class resolvable via user code deployment
    Config config = getConfig();
    UserCodeDeploymentConfig codeDeploymentConfig = new UserCodeDeploymentConfig().setEnabled(true).setClassCacheMode(OFF).setWhitelistedPrefixes("classloading");
    config.setUserCodeDeploymentConfig(codeDeploymentConfig);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    CachingProvider cachingProvider = createServerCachingProvider(hz1);
    cachingProvider.getCacheManager().createCache(cacheName, createCacheConfig());
    // joining member cannot resolve Person class but it is resolvable on other member via user code deployment
    Config joiningMemberConfig = getClassFilteringConfig();
    joiningMemberConfig.setUserCodeDeploymentConfig(codeDeploymentConfig);
    HazelcastInstance hz2 = factory.newHazelcastInstance(joiningMemberConfig);
    assertClusterSize(2, hz1, hz2);
    ICache<String, Person> testCache = hz1.getCacheManager().getCache(cacheName);
    String key = generateKeyOwnedBy(hz2);
    testCache.put(key, new Person());
    testCache.invoke(key, new PersonEntryProcessor());
    assertNotNull(testCache.get(key));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Config(com.hazelcast.config.Config) CacheConfig(com.hazelcast.config.CacheConfig) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) Person(classloading.domain.Person) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) PersonEntryProcessor(classloading.domain.PersonEntryProcessor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with UserCodeDeploymentConfig

use of com.hazelcast.config.UserCodeDeploymentConfig in project hazelcast by hazelcast.

the class Node method getConfigClassloader.

private static ClassLoader getConfigClassloader(Config config) {
    UserCodeDeploymentConfig userCodeDeploymentConfig = config.getUserCodeDeploymentConfig();
    ClassLoader classLoader;
    if (userCodeDeploymentConfig.isEnabled()) {
        ClassLoader parent = config.getClassLoader();
        final ClassLoader theParent = parent == null ? Node.class.getClassLoader() : parent;
        classLoader = doPrivileged(new PrivilegedAction<UserCodeDeploymentClassLoader>() {

            @Override
            public UserCodeDeploymentClassLoader run() {
                return new UserCodeDeploymentClassLoader(theParent);
            }
        });
    } else {
        classLoader = config.getClassLoader();
    }
    return classLoader;
}
Also used : PrivilegedAction(java.security.PrivilegedAction) UserCodeDeploymentClassLoader(com.hazelcast.internal.usercodedeployment.UserCodeDeploymentClassLoader) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) UserCodeDeploymentClassLoader(com.hazelcast.internal.usercodedeployment.UserCodeDeploymentClassLoader) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig)

Example 3 with UserCodeDeploymentConfig

use of com.hazelcast.config.UserCodeDeploymentConfig in project hazelcast by hazelcast.

the class Node method getConfigClassloader.

private ClassLoader getConfigClassloader(Config config) {
    UserCodeDeploymentConfig userCodeDeploymentConfig = config.getUserCodeDeploymentConfig();
    ClassLoader classLoader;
    if (userCodeDeploymentConfig.isEnabled()) {
        ClassLoader parent = config.getClassLoader();
        final ClassLoader theParent = parent == null ? Node.class.getClassLoader() : parent;
        classLoader = doPrivileged(new PrivilegedAction<UserCodeDeploymentClassLoader>() {

            @Override
            public UserCodeDeploymentClassLoader run() {
                return new UserCodeDeploymentClassLoader(theParent);
            }
        });
    } else {
        classLoader = config.getClassLoader();
    }
    return classLoader;
}
Also used : PrivilegedAction(java.security.PrivilegedAction) UserCodeDeploymentClassLoader(com.hazelcast.internal.usercodedeployment.UserCodeDeploymentClassLoader) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) UserCodeDeploymentClassLoader(com.hazelcast.internal.usercodedeployment.UserCodeDeploymentClassLoader) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig)

Example 4 with UserCodeDeploymentConfig

use of com.hazelcast.config.UserCodeDeploymentConfig in project hazelcast by hazelcast.

the class MemberDomConfigProcessor method handleUserCodeDeployment.

private void handleUserCodeDeployment(Node dcRoot) {
    UserCodeDeploymentConfig dcConfig = config.getUserCodeDeploymentConfig();
    Node attrEnabled = getNamedItemNode(dcRoot, "enabled");
    boolean enabled = getBooleanValue(getTextContent(attrEnabled));
    dcConfig.setEnabled(enabled);
    for (Node n : childElements(dcRoot)) {
        String name = cleanNodeName(n);
        if (matches("class-cache-mode", name)) {
            UserCodeDeploymentConfig.ClassCacheMode classCacheMode = UserCodeDeploymentConfig.ClassCacheMode.valueOf(getTextContent(n));
            dcConfig.setClassCacheMode(classCacheMode);
        } else if (matches("provider-mode", name)) {
            UserCodeDeploymentConfig.ProviderMode providerMode = UserCodeDeploymentConfig.ProviderMode.valueOf(getTextContent(n));
            dcConfig.setProviderMode(providerMode);
        } else if (matches("blacklist-prefixes", name)) {
            dcConfig.setBlacklistedPrefixes(getTextContent(n));
        } else if (matches("whitelist-prefixes", name)) {
            dcConfig.setWhitelistedPrefixes(getTextContent(n));
        } else if (matches("provider-filter", name)) {
            dcConfig.setProviderFilter(getTextContent(n));
        }
    }
    config.setUserCodeDeploymentConfig(dcConfig);
}
Also used : Node(org.w3c.dom.Node) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig)

Example 5 with UserCodeDeploymentConfig

use of com.hazelcast.config.UserCodeDeploymentConfig in project hazelcast by hazelcast.

the class UserCodeDeploymentService method init.

@Override
public void init(NodeEngine nodeEngine, Properties properties) {
    UserCodeDeploymentConfig config = nodeEngine.getConfig().getUserCodeDeploymentConfig();
    if (!config.isEnabled()) {
        return;
    }
    ClassLoader parent = nodeEngine.getConfigClassLoader().getParent();
    Filter<String> classNameFilter = parseClassNameFilters(config);
    Filter<Member> memberFilter = parseMemberFilter(config.getProviderFilter());
    ConcurrentMap<String, ClassSource> classMap = new ConcurrentHashMap<String, ClassSource>();
    ConcurrentMap<String, ClassSource> clientClassMap = new ConcurrentHashMap<String, ClassSource>();
    UserCodeDeploymentConfig.ProviderMode providerMode = config.getProviderMode();
    ILogger providerLogger = nodeEngine.getLogger(ClassDataProvider.class);
    provider = new ClassDataProvider(providerMode, parent, classMap, clientClassMap, providerLogger);
    UserCodeDeploymentConfig.ClassCacheMode classCacheMode = config.getClassCacheMode();
    locator = new ClassLocator(classMap, clientClassMap, parent, classNameFilter, memberFilter, classCacheMode, nodeEngine);
    enabled = config.isEnabled();
}
Also used : ClassLocator(com.hazelcast.internal.usercodedeployment.impl.ClassLocator) ClassDataProvider(com.hazelcast.internal.usercodedeployment.impl.ClassDataProvider) ILogger(com.hazelcast.logging.ILogger) UserCodeDeploymentConfig(com.hazelcast.config.UserCodeDeploymentConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Member(com.hazelcast.cluster.Member) ClassSource(com.hazelcast.internal.usercodedeployment.impl.ClassSource)

Aggregations

UserCodeDeploymentConfig (com.hazelcast.config.UserCodeDeploymentConfig)5 UserCodeDeploymentClassLoader (com.hazelcast.internal.usercodedeployment.UserCodeDeploymentClassLoader)2 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)2 PrivilegedAction (java.security.PrivilegedAction)2 Person (classloading.domain.Person)1 PersonEntryProcessor (classloading.domain.PersonEntryProcessor)1 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)1 Member (com.hazelcast.cluster.Member)1 CacheConfig (com.hazelcast.config.CacheConfig)1 Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 ClassDataProvider (com.hazelcast.internal.usercodedeployment.impl.ClassDataProvider)1 ClassLocator (com.hazelcast.internal.usercodedeployment.impl.ClassLocator)1 ClassSource (com.hazelcast.internal.usercodedeployment.impl.ClassSource)1 ILogger (com.hazelcast.logging.ILogger)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CachingProvider (javax.cache.spi.CachingProvider)1 Test (org.junit.Test)1