Search in sources :

Example 1 with GroupConfig

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));
}
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 2 with GroupConfig

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));
}
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 3 with GroupConfig

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;
    }
}
Also used : GroupConfig(com.hazelcast.config.GroupConfig) UpdateManagementCenterUrlOperation(com.hazelcast.internal.management.operation.UpdateManagementCenterUrlOperation) Member(com.hazelcast.core.Member)

Example 4 with GroupConfig

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;
}
Also used : StatisticsAwareService(com.hazelcast.spi.StatisticsAwareService) Address(com.hazelcast.nio.Address) GroupConfig(com.hazelcast.config.GroupConfig) MemberStateImpl(com.hazelcast.monitor.impl.MemberStateImpl) MemberImpl(com.hazelcast.instance.MemberImpl) Member(com.hazelcast.core.Member) TimedMemberState(com.hazelcast.monitor.TimedMemberState)

Example 5 with GroupConfig

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) GroupConfig(com.hazelcast.config.GroupConfig) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

GroupConfig (com.hazelcast.config.GroupConfig)23 Config (com.hazelcast.config.Config)11 ClientConfig (com.hazelcast.client.config.ClientConfig)5 MapStoreConfig (com.hazelcast.config.MapStoreConfig)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 MapConfig (com.hazelcast.config.MapConfig)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)3 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)2 PartitionGroupConfig (com.hazelcast.config.PartitionGroupConfig)2 Member (com.hazelcast.core.Member)2 Node (com.hazelcast.instance.Node)2 ClusterService (com.hazelcast.internal.cluster.ClusterService)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 ClientSecurityConfig (com.hazelcast.client.config.ClientSecurityConfig)1 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)1 ClusterState (com.hazelcast.cluster.ClusterState)1 ExecutorConfig (com.hazelcast.config.ExecutorConfig)1