Search in sources :

Example 6 with GroupConfig

use of com.hazelcast.config.GroupConfig in project Payara by payara.

the class HazelcastCore method buildConfiguration.

private Config buildConfiguration() {
    Config config = new Config();
    String hazelcastFilePath = "";
    URL serverConfigURL;
    try {
        serverConfigURL = new URL(context.getServerConfigURL());
        File serverConfigFile = new File(serverConfigURL.getPath());
        hazelcastFilePath = serverConfigFile.getParentFile().getAbsolutePath() + File.separator + configuration.getHazelcastConfigurationFile();
        File file = new File(hazelcastFilePath);
        if (file.exists()) {
            config = ConfigLoader.load(hazelcastFilePath);
            if (config == null) {
                Logger.getLogger(HazelcastCore.class.getName()).log(Level.WARNING, "Hazelcast Core could not find configuration file {0} using default configuration", hazelcastFilePath);
                config = new Config();
            }
            config.setClassLoader(clh.getCommonClassLoader());
            if (ctxUtil == null) {
                Logger.getLogger(HazelcastCore.class.getName()).log(Level.WARNING, "Hazelcast Application Object Serialization Not Available");
            } else {
                SerializationConfig serConfig = config.getSerializationConfig();
                if (serConfig == null) {
                    serConfig = new SerializationConfig();
                    setPayaraSerializerConfig(serConfig);
                    config.setSerializationConfig(serConfig);
                } else {
                    if (serConfig.getGlobalSerializerConfig() == null) {
                        setPayaraSerializerConfig(serConfig);
                    } else {
                        Serializer ser = serConfig.getGlobalSerializerConfig().getImplementation();
                        if (ser instanceof StreamSerializer) {
                            config.getSerializationConfig().getGlobalSerializerConfig().setImplementation(new PayaraHazelcastSerializer(ctxUtil, (StreamSerializer<?>) ser));
                        } else {
                            Logger.getLogger(HazelcastCore.class.getName()).log(Level.WARNING, "Global serializer is not StreamSerializer: {0}", ser.getClass().getName());
                        }
                    }
                }
            }
        } else {
            // there is no config override
            config.setClassLoader(clh.getCommonClassLoader());
            if (ctxUtil != null) {
                SerializationConfig serializationConfig = new SerializationConfig();
                setPayaraSerializerConfig(serializationConfig);
                config.setSerializationConfig(serializationConfig);
            }
            buildNetworkConfiguration(config);
            config.setLicenseKey(configuration.getLicenseKey());
            config.setLiteMember(Boolean.parseBoolean(nodeConfig.getLite()));
            // set group config
            GroupConfig gc = config.getGroupConfig();
            gc.setName(configuration.getClusterGroupName());
            gc.setPassword(configuration.getClusterGroupPassword());
            // build the configuration
            if ("true".equals(configuration.getHostAwarePartitioning())) {
                PartitionGroupConfig partitionGroupConfig = config.getPartitionGroupConfig();
                partitionGroupConfig.setEnabled(enabled);
                partitionGroupConfig.setGroupType(PartitionGroupConfig.MemberGroupType.HOST_AWARE);
            }
            // build the executor config
            ExecutorConfig executorConfig = config.getExecutorConfig(CLUSTER_EXECUTOR_SERVICE_NAME);
            executorConfig.setStatisticsEnabled(true);
            executorConfig.setPoolSize(Integer.valueOf(nodeConfig.getExecutorPoolSize()));
            executorConfig.setQueueCapacity(Integer.valueOf(nodeConfig.getExecutorQueueCapacity()));
            ScheduledExecutorConfig scheduledExecutorConfig = config.getScheduledExecutorConfig(SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME);
            scheduledExecutorConfig.setDurability(1);
            scheduledExecutorConfig.setCapacity(Integer.valueOf(nodeConfig.getScheduledExecutorQueueCapacity()));
            scheduledExecutorConfig.setPoolSize(Integer.valueOf(nodeConfig.getScheduledExecutorPoolSize()));
            config.setProperty("hazelcast.jmx", "true");
        }
    } catch (MalformedURLException ex) {
        Logger.getLogger(HazelcastCore.class.getName()).log(Level.WARNING, "Unable to parse server config URL", ex);
    } catch (IOException ex) {
        Logger.getLogger(HazelcastCore.class.getName()).log(Level.WARNING, "Hazelcast Core could not load configuration file " + hazelcastFilePath + " using default configuration", ex);
    }
    return config;
}
Also used : MalformedURLException(java.net.MalformedURLException) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) ExecutorConfig(com.hazelcast.config.ExecutorConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) MemberAddressProviderConfig(com.hazelcast.config.MemberAddressProviderConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) NetworkConfig(com.hazelcast.config.NetworkConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) SerializationConfig(com.hazelcast.config.SerializationConfig) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) IOException(java.io.IOException) URL(java.net.URL) ExecutorConfig(com.hazelcast.config.ExecutorConfig) ScheduledExecutorConfig(com.hazelcast.config.ScheduledExecutorConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) GroupConfig(com.hazelcast.config.GroupConfig) PartitionGroupConfig(com.hazelcast.config.PartitionGroupConfig) StreamSerializer(com.hazelcast.nio.serialization.StreamSerializer) File(java.io.File) StreamSerializer(com.hazelcast.nio.serialization.StreamSerializer) Serializer(com.hazelcast.nio.serialization.Serializer)

Example 7 with GroupConfig

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

the class AuthenticationBaseMessageTask method authenticate.

private AuthenticationStatus authenticate(UsernamePasswordCredentials credentials) {
    GroupConfig groupConfig = nodeEngine.getConfig().getGroupConfig();
    String nodeGroupName = groupConfig.getName();
    String nodeGroupPassword = groupConfig.getPassword();
    boolean usernameMatch = nodeGroupName.equals(credentials.getUsername());
    boolean passwordMatch = nodeGroupPassword.equals(credentials.getPassword());
    return usernameMatch && passwordMatch ? AuthenticationStatus.AUTHENTICATED : AuthenticationStatus.CREDENTIALS_FAILED;
}
Also used : GroupConfig(com.hazelcast.config.GroupConfig)

Example 8 with GroupConfig

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

the class HttpPostCommandProcessor method checkCredentials.

private boolean checkCredentials(HttpPostCommand command) throws UnsupportedEncodingException {
    byte[] data = command.getData();
    final String[] strList = bytesToString(data).split("&");
    final String groupName = URLDecoder.decode(strList[0], "UTF-8");
    final String groupPass = URLDecoder.decode(strList[1], "UTF-8");
    final GroupConfig groupConfig = textCommandService.getNode().getConfig().getGroupConfig();
    return groupConfig.getName().equals(groupName) && groupConfig.getPassword().equals(groupPass);
}
Also used : GroupConfig(com.hazelcast.config.GroupConfig) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString)

Example 9 with GroupConfig

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

the class HazelcastClientInstanceImpl method initCredentials.

private Credentials initCredentials(ClientConfig config) {
    final GroupConfig groupConfig = config.getGroupConfig();
    final ClientSecurityConfig securityConfig = config.getSecurityConfig();
    Credentials c = securityConfig.getCredentials();
    if (c == null) {
        final String credentialsClassname = securityConfig.getCredentialsClassname();
        if (credentialsClassname != null) {
            try {
                c = ClassLoaderUtil.newInstance(config.getClassLoader(), credentialsClassname);
            } catch (Exception e) {
                throw ExceptionUtil.rethrow(e);
            }
        }
    }
    if (c == null) {
        c = new UsernamePasswordCredentials(groupConfig.getName(), groupConfig.getPassword());
    }
    return c;
}
Also used : GroupConfig(com.hazelcast.config.GroupConfig) ClientSecurityConfig(com.hazelcast.client.config.ClientSecurityConfig) UsernamePasswordCredentials(com.hazelcast.security.UsernamePasswordCredentials) Credentials(com.hazelcast.security.Credentials) TransactionException(com.hazelcast.transaction.TransactionException) UsernamePasswordCredentials(com.hazelcast.security.UsernamePasswordCredentials)

Example 10 with GroupConfig

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

the class ClientEntryListenerDisconnectTest method main.

public static void main(String[] args) throws InterruptedException {
    Config config = new Config();
    config.setGroupConfig(new GroupConfig("test", "test"));
    config.getNetworkConfig().setPort(6701);
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    IMap<Integer, GenericEvent> map = hazelcastInstance.getMap("test");
    map.addIndex("userId", false);
    Hazelcast.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().addAddress("localhost:6701", "localhost:6702");
    clientConfig.setGroupConfig(new GroupConfig("test", "test"));
    clientConfig.getNetworkConfig().setConnectionAttemptLimit(100);
    clientConfig.getNetworkConfig().setSmartRouting(false);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    IMap<Integer, GenericEvent> mapClient = client.getMap("test");
    mapClient.addEntryListener(new EntryAdapter<Integer, GenericEvent>() {

        public void entryAdded(EntryEvent<Integer, GenericEvent> event) {
            adds++;
        }

        public void entryEvicted(EntryEvent<Integer, GenericEvent> event) {
            if (event.getValue() == null)
                evictionsNull++;
        }
    }, true);
    HazelcastInstance client2 = HazelcastClient.newHazelcastClient(clientConfig);
    IMap<Integer, GenericEvent> mapClient2 = client2.getMap("test");
    map.put(1, new GenericEvent(1), 5, TimeUnit.SECONDS);
    Thread.sleep(20);
    mapClient.remove(1);
    hazelcastInstance.getLifecycleService().terminate();
    Thread.sleep(15000);
    mapClient2.put(2, new GenericEvent(2), 1, TimeUnit.SECONDS);
    Thread.sleep(20);
    mapClient2.remove(2);
    mapClient2.put(3, new GenericEvent(3), 1, TimeUnit.SECONDS);
    Thread.sleep(15000);
    hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    map = hazelcastInstance.getMap("test");
    map.put(4, new GenericEvent(4), 1, TimeUnit.SECONDS);
    map.put(5, new GenericEvent(5), 5, TimeUnit.SECONDS);
    map.put(6, new GenericEvent(6), 1, TimeUnit.SECONDS);
    map.put(7, new GenericEvent(7), 1, TimeUnit.SECONDS);
    Thread.sleep(10000);
    if (evictionsNull != 0) {
        System.out.println("ERROR: got " + evictionsNull + " evictions with null values");
    } else {
        System.out.println("OK");
    }
    mapClient.put(8, new GenericEvent(8), 1, TimeUnit.SECONDS);
    Thread.sleep(5000);
    if (adds != 8) {
        System.out.println("ERROR: got " + adds + " instead of 8");
    } else {
        System.out.println("OK");
    }
    System.exit(0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) GroupConfig(com.hazelcast.config.GroupConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientConfig(com.hazelcast.client.config.ClientConfig)

Aggregations

GroupConfig (com.hazelcast.config.GroupConfig)14 ClientConfig (com.hazelcast.client.config.ClientConfig)5 Config (com.hazelcast.config.Config)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Test (org.junit.Test)3 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)2 ClientSecurityConfig (com.hazelcast.client.config.ClientSecurityConfig)1 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)1 ExecutorConfig (com.hazelcast.config.ExecutorConfig)1 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 MapIndexConfig (com.hazelcast.config.MapIndexConfig)1 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)1 MemberAddressProviderConfig (com.hazelcast.config.MemberAddressProviderConfig)1 MemberGroupConfig (com.hazelcast.config.MemberGroupConfig)1 MulticastConfig (com.hazelcast.config.MulticastConfig)1 NetworkConfig (com.hazelcast.config.NetworkConfig)1 SSLConfig (com.hazelcast.config.SSLConfig)1 ScheduledExecutorConfig (com.hazelcast.config.ScheduledExecutorConfig)1