Search in sources :

Example 6 with ClusterService

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));
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Node(com.hazelcast.instance.Node) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString)

Example 7 with ClusterService

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));
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) GroupConfig(com.hazelcast.config.GroupConfig) Version(com.hazelcast.version.Version) Node(com.hazelcast.instance.Node) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with ClusterService

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);
}
Also used : ClusterService(com.hazelcast.internal.cluster.ClusterService) Node(com.hazelcast.instance.Node) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString)

Example 9 with ClusterService

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));
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) ClusterService(com.hazelcast.internal.cluster.ClusterService) GroupConfig(com.hazelcast.config.GroupConfig) Node(com.hazelcast.instance.Node) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString)

Example 10 with ClusterService

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);
}
Also used : HazelcastProperties(com.hazelcast.spi.properties.HazelcastProperties) MemberMapMetaDataFetcher(com.hazelcast.map.impl.nearcache.invalidation.MemberMapMetaDataFetcher) ClusterService(com.hazelcast.internal.cluster.ClusterService) RepairingTask(com.hazelcast.internal.nearcache.impl.invalidation.RepairingTask) ILogger(com.hazelcast.logging.ILogger) OperationService(com.hazelcast.spi.OperationService) ExecutionService(com.hazelcast.spi.ExecutionService) MetaDataFetcher(com.hazelcast.internal.nearcache.impl.invalidation.MetaDataFetcher) MemberMapMetaDataFetcher(com.hazelcast.map.impl.nearcache.invalidation.MemberMapMetaDataFetcher)

Aggregations

ClusterService (com.hazelcast.internal.cluster.ClusterService)32 Member (com.hazelcast.core.Member)8 ArrayList (java.util.ArrayList)8 Node (com.hazelcast.instance.Node)7 Address (com.hazelcast.nio.Address)7 OperationService (com.hazelcast.spi.OperationService)6 MemberImpl (com.hazelcast.instance.MemberImpl)5 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)5 Future (java.util.concurrent.Future)5 AbstractJobTracker (com.hazelcast.mapreduce.impl.AbstractJobTracker)4 NodeEngine (com.hazelcast.spi.NodeEngine)4 ILogger (com.hazelcast.logging.ILogger)3 Operation (com.hazelcast.spi.Operation)3 GroupConfig (com.hazelcast.config.GroupConfig)2 JobTrackerConfig (com.hazelcast.config.JobTrackerConfig)2 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)2 MapReduceService (com.hazelcast.mapreduce.impl.MapReduceService)2 MapReduceUtil.executeOperation (com.hazelcast.mapreduce.impl.MapReduceUtil.executeOperation)2 KeyValueJobOperation (com.hazelcast.mapreduce.impl.operation.KeyValueJobOperation)2 StartProcessingJobOperation (com.hazelcast.mapreduce.impl.operation.StartProcessingJobOperation)2