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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations