Search in sources :

Example 21 with Node

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

the class HttpGetCommandProcessor method handleHealthcheck.

private void handleHealthcheck(HttpGetCommand command, String uri) {
    Node node = textCommandService.getNode();
    NodeState nodeState = node.getState();
    ClusterServiceImpl clusterService = node.getClusterService();
    ClusterState clusterState = clusterService.getClusterState();
    int clusterSize = clusterService.getMembers().size();
    InternalPartitionService partitionService = node.getPartitionService();
    long migrationQueueSize = partitionService.getMigrationQueueSize();
    String healthParameter = uri.substring(URI_HEALTH_URL.length());
    if (healthParameter.equals(HEALTH_PATH_PARAM_NODE_STATE)) {
        if (NodeState.SHUT_DOWN.equals(nodeState)) {
            command.send503();
        } else {
            prepareResponse(command, Json.value(nodeState.toString()));
        }
    } else if (healthParameter.equals(HEALTH_PATH_PARAM_CLUSTER_STATE)) {
        prepareResponse(command, Json.value(clusterState.toString()));
    } else if (healthParameter.equals(HEALTH_PATH_PARAM_CLUSTER_SAFE)) {
        if (isClusterSafe()) {
            command.send200();
        } else {
            command.send503();
        }
    } else if (healthParameter.equals(HEALTH_PATH_PARAM_MIGRATION_QUEUE_SIZE)) {
        prepareResponse(command, Json.value(migrationQueueSize));
    } else if (healthParameter.equals(HEALTH_PATH_PARAM_CLUSTER_SIZE)) {
        prepareResponse(command, Json.value(clusterSize));
    } else if (healthParameter.isEmpty()) {
        JsonObject response = new JsonObject().add("nodeState", nodeState.toString()).add("clusterState", clusterState.toString()).add("clusterSafe", isClusterSafe()).add("migrationQueueSize", migrationQueueSize).add("clusterSize", clusterSize);
        prepareResponse(command, response);
    } else {
        command.send400();
    }
}
Also used : ClusterState(com.hazelcast.cluster.ClusterState) NodeState(com.hazelcast.instance.impl.NodeState) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.impl.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 22 with Node

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

the class InvocationFuture_GetNewInstanceTest method invocationToLocalMember.

@Test
public void invocationToLocalMember() throws ExecutionException, InterruptedException {
    Node localNode = getNode(local);
    Data response = localNode.nodeEngine.toData(new DummyObject());
    Operation op = new OperationWithResponse(response);
    OperationService service = getOperationService(local);
    Future future = service.createInvocationBuilder(null, op, localNode.address).invoke();
    Object instance1 = future.get();
    Object instance2 = future.get();
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertTrue(instance1 instanceof DummyObject);
    assertTrue(instance2 instanceof DummyObject);
    assertNotSame(instance1, instance2);
    assertNotSame(instance1, response);
    assertNotSame(instance2, response);
}
Also used : Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.internal.serialization.Data) Operation(com.hazelcast.spi.impl.operationservice.Operation) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with Node

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

the class InvocationFuture_GetNewInstanceTest method invocationToRemoteMember.

@Test
public void invocationToRemoteMember() throws ExecutionException, InterruptedException {
    Node localNode = getNode(local);
    Data response = localNode.nodeEngine.toData(new DummyObject());
    Operation op = new OperationWithResponse(response);
    Address remoteAddress = getAddress(remote);
    OperationService operationService = getOperationService(local);
    Future future = operationService.createInvocationBuilder(null, op, remoteAddress).invoke();
    Object instance1 = future.get();
    Object instance2 = future.get();
    assertNotNull(instance1);
    assertNotNull(instance2);
    assertTrue(instance1 instanceof DummyObject);
    assertTrue(instance2 instanceof DummyObject);
    assertNotSame(instance1, instance2);
    assertNotSame(instance1, response);
    assertNotSame(instance2, response);
}
Also used : Address(com.hazelcast.cluster.Address) Accessors.getAddress(com.hazelcast.test.Accessors.getAddress) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) Future(java.util.concurrent.Future) Data(com.hazelcast.internal.serialization.Data) Operation(com.hazelcast.spi.impl.operationservice.Operation) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with Node

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

the class QueryCacheIMapEventHandlingTest method executeMergeOperation.

private void executeMergeOperation(HazelcastInstance member, String mapName, int key, int mergedValue) throws Exception {
    Node node = getNode(member);
    NodeEngineImpl nodeEngine = node.nodeEngine;
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    SerializationService serializationService = getSerializationService(member);
    Data keyData = serializationService.toData(key);
    Data valueData = serializationService.toData(mergedValue);
    SplitBrainMergeTypes.MapMergeTypes mergingEntry = createMergingEntry(serializationService, keyData, valueData, Mockito.mock(Record.class), ExpiryMetadata.NULL);
    Operation mergeOperation = new MergeOperation(mapName, singletonList(mergingEntry), new PassThroughMergePolicy<>(), false);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    Future<Object> future = operationService.invokeOnPartition(SERVICE_NAME, mergeOperation, partitionId);
    future.get();
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) MergeOperation(com.hazelcast.map.impl.operation.MergeOperation) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) SerializationService(com.hazelcast.internal.serialization.SerializationService) Accessors.getSerializationService(com.hazelcast.test.Accessors.getSerializationService) Data(com.hazelcast.internal.serialization.Data) Operation(com.hazelcast.spi.impl.operationservice.Operation) MergeOperation(com.hazelcast.map.impl.operation.MergeOperation) Record(com.hazelcast.map.impl.record.Record) SplitBrainMergeTypes(com.hazelcast.spi.merge.SplitBrainMergeTypes) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)

Example 25 with Node

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

the class QueryCacheRecoveryUponEventLossTest method getBrokenSequences.

private Map getBrokenSequences(HazelcastInstance instance, String mapName, QueryCache queryCache) {
    Node node = getNode(instance);
    MapService service = node.getNodeEngine().getService(MapService.SERVICE_NAME);
    MapServiceContext mapServiceContext = service.getMapServiceContext();
    QueryCacheContext context = mapServiceContext.getQueryCacheContext();
    SubscriberContext subscriberContext = context.getSubscriberContext();
    MapSubscriberRegistry mapSubscriberRegistry = subscriberContext.getMapSubscriberRegistry();
    SubscriberRegistry subscriberRegistry = mapSubscriberRegistry.getOrNull(mapName);
    if (subscriberRegistry == null) {
        return Collections.emptyMap();
    }
    String cacheId = ((InternalQueryCache) queryCache).getCacheId();
    Accumulator accumulator = subscriberRegistry.getOrNull(cacheId);
    if (accumulator == null) {
        return Collections.emptyMap();
    }
    SubscriberAccumulator subscriberAccumulator = (SubscriberAccumulator) accumulator;
    return subscriberAccumulator.getBrokenSequences();
}
Also used : Accumulator(com.hazelcast.map.impl.querycache.accumulator.Accumulator) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) QueryCacheContext(com.hazelcast.map.impl.querycache.QueryCacheContext) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Aggregations

Node (com.hazelcast.instance.impl.Node)144 Accessors.getNode (com.hazelcast.test.Accessors.getNode)84 HazelcastInstance (com.hazelcast.core.HazelcastInstance)68 Test (org.junit.Test)60 QuickTest (com.hazelcast.test.annotation.QuickTest)57 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)44 Config (com.hazelcast.config.Config)22 Address (com.hazelcast.cluster.Address)20 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)19 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 UUID (java.util.UUID)13 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)12 SerializationService (com.hazelcast.internal.serialization.SerializationService)12 ILogger (com.hazelcast.logging.ILogger)10 MapService (com.hazelcast.map.impl.MapService)10 ClientConnectionRegistration (com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration)9 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 HashMap (java.util.HashMap)9 Data (com.hazelcast.internal.serialization.Data)8 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)8