use of com.hazelcast.internal.cluster.ClusterService in project hazelcast by hazelcast.
the class HttpPostCommandProcessor method handleGetClusterState.
private void handleGetClusterState(HttpPostCommand command) throws UnsupportedEncodingException {
String res;
try {
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
if (!checkCredentials(command)) {
res = response(ResponseType.FORBIDDEN);
} else {
res = response(ResponseType.SUCCESS, "state", clusterService.getClusterState().toString().toLowerCase());
}
} catch (Throwable throwable) {
logger.warning("Error occurred while getting cluster state", throwable);
res = exceptionResponse(throwable);
}
command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res));
}
use of com.hazelcast.internal.cluster.ClusterService 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.internal.cluster.ClusterService in project hazelcast by hazelcast.
the class HttpPostCommandProcessor method handleListNodes.
private void handleListNodes(HttpPostCommand command) throws UnsupportedEncodingException {
String res;
try {
Node node = textCommandService.getNode();
ClusterService clusterService = node.getClusterService();
if (!checkCredentials(command)) {
res = response(ResponseType.FORBIDDEN);
} else {
final String responseTxt = clusterService.getMembers().toString() + "\n" + node.getBuildInfo().getVersion() + "\n" + System.getProperty("java.version");
res = response(ResponseType.SUCCESS, "response", responseTxt);
sendResponse(command, res);
return;
}
} catch (Throwable throwable) {
logger.warning("Error occurred while listing nodes", throwable);
res = exceptionResponse(throwable);
}
sendResponse(command, res);
}
use of com.hazelcast.internal.cluster.ClusterService 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.internal.cluster.ClusterService in project hazelcast by hazelcast.
the class MapNearCacheManager method createRepairingInvalidationTask.
private RepairingTask createRepairingInvalidationTask() {
ExecutionService executionService = nodeEngine.getExecutionService();
ClusterService clusterService = nodeEngine.getClusterService();
OperationService operationService = nodeEngine.getOperationService();
HazelcastProperties properties = nodeEngine.getProperties();
ILogger logger = nodeEngine.getLogger(RepairingTask.class);
MetaDataFetcher metaDataFetcher = new MemberMapMetaDataFetcher(clusterService, operationService, logger);
String localUuid = nodeEngine.getLocalMember().getUuid();
return new RepairingTask(metaDataFetcher, executionService.getGlobalTaskScheduler(), partitionService, properties, localUuid, logger);
}
Aggregations