Search in sources :

Example 71 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class HttpPostCommandProcessor method handlePartialStart.

private void handlePartialStart(HttpPostCommand command) throws UnsupportedEncodingException {
    String res;
    try {
        Node node = textCommandService.getNode();
        if (!checkCredentials(command)) {
            res = response(ResponseType.FORBIDDEN);
        } else {
            boolean success = node.getNodeExtension().getInternalHotRestartService().triggerPartialStart();
            res = response(success ? ResponseType.SUCCESS : ResponseType.FAIL);
        }
    } catch (Throwable throwable) {
        logger.warning("Error occurred while handling partial start", throwable);
        res = exceptionResponse(throwable);
    }
    sendResponse(command, res);
}
Also used : Node(com.hazelcast.instance.Node) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString)

Example 72 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class HttpPostCommandProcessor method handleClusterShutdown.

private void handleClusterShutdown(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);
            sendResponse(command, res);
            clusterService.shutdown();
            return;
        }
    } catch (Throwable throwable) {
        logger.warning("Error occurred while shutting down cluster", 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 73 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class HttpPostCommandProcessor method handleShutdownNode.

private void handleShutdownNode(HttpPostCommand command) throws UnsupportedEncodingException {
    String res;
    try {
        Node node = textCommandService.getNode();
        if (!checkCredentials(command)) {
            res = response(ResponseType.FORBIDDEN);
        } else {
            res = response(ResponseType.SUCCESS);
            sendResponse(command, res);
            node.hazelcastInstance.shutdown();
            return;
        }
    } catch (Throwable throwable) {
        logger.warning("Error occurred while shutting down", throwable);
        res = exceptionResponse(throwable);
    }
    sendResponse(command, res);
}
Also used : Node(com.hazelcast.instance.Node) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString)

Example 74 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class InternalCacheRecordStoreTest method batchEventMapShouldBeCleanedAfterRemoveAll.

/**
     * Test for issue: https://github.com/hazelcast/hazelcast/issues/6618
     */
@Test
public void batchEventMapShouldBeCleanedAfterRemoveAll() {
    String cacheName = randomString();
    CacheConfig<Integer, String> config = createCacheConfig();
    CacheFromDifferentNodesTest.SimpleEntryListener<Integer, String> listener = new CacheFromDifferentNodesTest.SimpleEntryListener<Integer, String>();
    MutableCacheEntryListenerConfiguration<Integer, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<Integer, String>(FactoryBuilder.factoryOf(listener), null, true, true);
    config.addCacheEntryListenerConfiguration(listenerConfiguration);
    Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);
    assertNotNull(cache);
    Integer key = 1;
    String value = "value";
    cache.put(key, value);
    HazelcastInstance instance = ((HazelcastCacheManager) cacheManager).getHazelcastInstance();
    int partitionId = instance.getPartitionService().getPartition(key).getPartitionId();
    cache.removeAll();
    Node node = getNode(instance);
    assertNotNull(node);
    ICacheService cacheService = node.getNodeEngine().getService(ICacheService.SERVICE_NAME);
    AbstractCacheRecordStore recordStore = (AbstractCacheRecordStore) cacheService.getRecordStore("/hz/" + cacheName, partitionId);
    assertEquals(0, recordStore.batchEvent.size());
}
Also used : MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) Node(com.hazelcast.instance.Node) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheFromDifferentNodesTest(com.hazelcast.cache.CacheFromDifferentNodesTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest) CacheFromDifferentNodesTest(com.hazelcast.cache.CacheFromDifferentNodesTest)

Example 75 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class InternalCacheRecordStoreTest method ownerStateShouldBeUpdatedAfterMigration.

/**
     * Test for issue: https://github.com/hazelcast/hazelcast/issues/6983
     */
@Test
public void ownerStateShouldBeUpdatedAfterMigration() throws Exception {
    HazelcastCacheManager hzCacheManager = (HazelcastCacheManager) cacheManager;
    HazelcastInstance instance1 = hzCacheManager.getHazelcastInstance();
    Node node1 = TestUtil.getNode(instance1);
    NodeEngineImpl nodeEngine1 = node1.getNodeEngine();
    InternalPartitionService partitionService1 = nodeEngine1.getPartitionService();
    int partitionCount = partitionService1.getPartitionCount();
    String cacheName = randomName();
    CacheConfig cacheConfig = new CacheConfig().setName(cacheName);
    Cache<String, String> cache = cacheManager.createCache(cacheName, cacheConfig);
    String fullCacheName = hzCacheManager.getCacheNameWithPrefix(cacheName);
    for (int i = 0; i < partitionCount; i++) {
        String key = generateKeyForPartition(instance1, i);
        cache.put(key, "Value");
    }
    for (int i = 0; i < partitionCount; i++) {
        verifyPrimaryState(node1, fullCacheName, i, true);
    }
    HazelcastInstance instance2 = getHazelcastInstance();
    Node node2 = TestUtil.getNode(instance2);
    warmUpPartitions(instance1, instance2);
    waitAllForSafeState(instance1, instance2);
    for (int i = 0; i < partitionCount; i++) {
        boolean ownedByNode1 = partitionService1.isPartitionOwner(i);
        if (ownedByNode1) {
            verifyPrimaryState(node1, fullCacheName, i, true);
            verifyPrimaryState(node2, fullCacheName, i, false);
        } else {
            verifyPrimaryState(node1, fullCacheName, i, false);
            verifyPrimaryState(node2, fullCacheName, i, true);
        }
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) CacheConfig(com.hazelcast.config.CacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest) CacheFromDifferentNodesTest(com.hazelcast.cache.CacheFromDifferentNodesTest)

Aggregations

Node (com.hazelcast.instance.Node)131 HazelcastInstance (com.hazelcast.core.HazelcastInstance)60 Test (org.junit.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)45 ParallelTest (com.hazelcast.test.annotation.ParallelTest)42 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)21 ClientEventRegistration (com.hazelcast.client.spi.impl.listener.ClientEventRegistration)18 Address (com.hazelcast.nio.Address)17 Config (com.hazelcast.config.Config)14 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 ILogger (com.hazelcast.logging.ILogger)10 Data (com.hazelcast.nio.serialization.Data)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)10 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)9 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 SerializationService (com.hazelcast.spi.serialization.SerializationService)7 ItemListener (com.hazelcast.core.ItemListener)6 Operation (com.hazelcast.spi.Operation)6