use of com.hazelcast.config.GroupConfig in project hazelcast by hazelcast.
the class HttpPostCommandProcessor method handleChangeClusterVersion.
private void handleChangeClusterVersion(HttpPostCommand command) throws UnsupportedEncodingException {
byte[] data = command.getData();
String[] strList = bytesToString(data).split("&");
String groupName = URLDecoder.decode(strList[0], "UTF-8");
String groupPass = URLDecoder.decode(strList[1], "UTF-8");
String versionParam = URLDecoder.decode(strList[2], "UTF-8");
String res;
try {
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
GroupConfig groupConfig = node.getConfig().getGroupConfig();
if (!(groupConfig.getName().equals(groupName) && groupConfig.getPassword().equals(groupPass))) {
res = response(ResponseType.FORBIDDEN);
} else {
Version version;
try {
version = Version.of(versionParam);
clusterService.changeClusterVersion(version);
res = response(ResponseType.SUCCESS, "version", clusterService.getClusterVersion().toString());
} catch (Exception ex) {
res = response(ResponseType.FAIL, "version", clusterService.getClusterVersion().toString());
}
}
} catch (Throwable throwable) {
logger.warning("Error occurred while changing cluster version", throwable);
res = exceptionResponse(throwable);
}
command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res));
}
use of com.hazelcast.config.GroupConfig in project hazelcast by hazelcast.
the class HttpPostCommandProcessor method handleChangeClusterState.
private void handleChangeClusterState(HttpPostCommand command) throws UnsupportedEncodingException {
byte[] data = command.getData();
String[] strList = bytesToString(data).split("&");
String groupName = URLDecoder.decode(strList[0], "UTF-8");
String groupPass = URLDecoder.decode(strList[1], "UTF-8");
String stateParam = URLDecoder.decode(strList[2], "UTF-8");
String res;
try {
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
GroupConfig groupConfig = node.getConfig().getGroupConfig();
if (!(groupConfig.getName().equals(groupName) && groupConfig.getPassword().equals(groupPass))) {
res = response(ResponseType.FORBIDDEN);
} else {
ClusterState state = clusterService.getClusterState();
if (stateParam.equals("frozen")) {
state = ClusterState.FROZEN;
}
if (stateParam.equals("active")) {
state = ClusterState.ACTIVE;
}
if (stateParam.equals("passive")) {
state = ClusterState.PASSIVE;
}
if (!state.equals(clusterService.getClusterState())) {
clusterService.changeClusterState(state);
res = response(ResponseType.SUCCESS, "state", state.toString().toLowerCase());
} else {
res = response(ResponseType.FAIL, "state", state.toString().toLowerCase());
}
}
} catch (Throwable throwable) {
logger.warning("Error occurred while changing cluster state", throwable);
res = exceptionResponse(throwable);
}
command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res));
}
use of com.hazelcast.config.GroupConfig in project hazelcast by hazelcast.
the class ManagementCenterService method clusterWideUpdateManagementCenterUrl.
public byte[] clusterWideUpdateManagementCenterUrl(String groupName, String groupPass, String newUrl) {
try {
GroupConfig groupConfig = instance.getConfig().getGroupConfig();
if (!(groupConfig.getName().equals(groupName) && groupConfig.getPassword().equals(groupPass))) {
return HttpCommand.RES_403;
}
final Collection<Member> memberList = instance.node.clusterService.getMembers();
for (Member member : memberList) {
send(member.getAddress(), new UpdateManagementCenterUrlOperation(newUrl));
}
return HttpCommand.RES_204;
} catch (Throwable throwable) {
logger.warning("New Management Center url cannot be assigned.", throwable);
return HttpCommand.RES_500;
}
}
use of com.hazelcast.config.GroupConfig in project hazelcast by hazelcast.
the class TimedMemberStateFactory method createTimedMemberState.
public TimedMemberState createTimedMemberState() {
MemberStateImpl memberState = new MemberStateImpl();
Collection<StatisticsAwareService> services = instance.node.nodeEngine.getServices(StatisticsAwareService.class);
TimedMemberState timedMemberState = new TimedMemberState();
createMemberState(timedMemberState, memberState, services);
timedMemberState.setMaster(instance.node.isMaster());
timedMemberState.setMemberList(new ArrayList<String>());
if (timedMemberState.getMaster()) {
Set<Member> memberSet = instance.getCluster().getMembers();
for (Member member : memberSet) {
MemberImpl memberImpl = (MemberImpl) member;
Address address = memberImpl.getAddress();
timedMemberState.getMemberList().add(address.getHost() + ":" + address.getPort());
}
}
timedMemberState.setMemberState(memberState);
GroupConfig groupConfig = instance.getConfig().getGroupConfig();
timedMemberState.setClusterName(groupConfig.getName());
return timedMemberState;
}
use of com.hazelcast.config.GroupConfig in project hazelcast by hazelcast.
the class MapStoreTest method testInitialLoadModeEagerWhileStoppigOneNode.
@Test(timeout = 120000)
public void testInitialLoadModeEagerWhileStoppigOneNode() throws InterruptedException {
final int instanceCount = 2;
final int size = 10000;
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(instanceCount);
final CountDownLatch countDownLatch = new CountDownLatch(instanceCount - 1);
final Config config = getConfig();
GroupConfig groupConfig = new GroupConfig("testEager");
config.setGroupConfig(groupConfig);
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(new SimpleMapLoader(size, true));
mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
config.getMapConfig("testInitialLoadModeEagerWhileStoppigOneNode").setMapStoreConfig(mapStoreConfig);
final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
new Thread(new Runnable() {
@Override
public void run() {
sleepSeconds(3);
instance1.getLifecycleService().shutdown();
sleepSeconds(3);
final IMap<Object, Object> map = instance2.getMap("testInitialLoadModeEagerWhileStoppigOneNode");
assertEquals(size, map.size());
countDownLatch.countDown();
}
}).start();
assertOpenEventually(countDownLatch);
final IMap<Object, Object> map2 = instance2.getMap("testInitialLoadModeEagerWhileStoppigOneNode");
final int map2Size = map2.size();
assertEquals(size, map2Size);
}
Aggregations