Search in sources :

Example 66 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class ClientMessageEncoderDecoderTest method testAuthenticationResponse.

@Test
public void testAuthenticationResponse() throws UnknownHostException {
    Collection<Member> members = new LinkedList<>();
    Address address1 = new Address("127.0.0.1", 5702);
    members.add(new MemberImpl(address1, MemberVersion.of("3.12"), false, UUID.randomUUID()));
    Address address2 = new Address("127.0.0.1", 5703);
    members.add(new MemberImpl(address2, MemberVersion.of("3.12"), false, UUID.randomUUID()));
    UUID uuid = UUID.randomUUID();
    UUID clusterId = UUID.randomUUID();
    ClientMessage message = ClientAuthenticationCodec.encodeResponse((byte) 2, new Address("127.0.0.1", 5701), uuid, (byte) 1, "3.12", 271, clusterId, true);
    AtomicReference<ClientMessage> reference = new AtomicReference<>(message);
    ClientMessageEncoder encoder = new ClientMessageEncoder();
    encoder.src(() -> reference.getAndSet(null));
    ByteBuffer buffer = ByteBuffer.allocate(1000);
    upcast(buffer).flip();
    encoder.dst(buffer);
    HandlerStatus result = encoder.onWrite();
    assertEquals(CLEAN, result);
    AtomicReference<ClientMessage> resultingMessage = new AtomicReference<>();
    ClientMessageDecoder decoder = new ClientMessageDecoder(null, resultingMessage::set, null);
    decoder.setNormalPacketsRead(SwCounter.newSwCounter());
    upcast(buffer).position(buffer.limit());
    decoder.src(buffer);
    decoder.onRead();
    assertEquals(message.getMessageType(), resultingMessage.get().getMessageType());
    assertEquals(message.getFrameLength(), resultingMessage.get().getFrameLength());
    assertEquals(message.getHeaderFlags(), resultingMessage.get().getHeaderFlags());
    assertEquals(message.getPartitionId(), resultingMessage.get().getPartitionId());
    ClientAuthenticationCodec.ResponseParameters parameters = ClientAuthenticationCodec.decodeResponse(resultingMessage.get());
    assertEquals(2, parameters.status);
    assertEquals(new Address("127.0.0.1", 5701), parameters.address);
    assertEquals(uuid, parameters.memberUuid);
    assertEquals(1, parameters.serializationVersion);
    assertEquals("3.12", parameters.serverHazelcastVersion);
    assertEquals(271, parameters.partitionCount);
    assertEquals(clusterId, parameters.clusterId);
    assertEquals(true, parameters.failoverSupported);
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList) HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) ClientAuthenticationCodec(com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 67 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class TransactionManagerServiceImpl method memberRemoved.

@Override
public void memberRemoved(MembershipServiceEvent event) {
    MemberImpl member = event.getMember();
    final UUID uuid = member.getUuid();
    if (nodeEngine.isRunning()) {
        logger.info("Committing/rolling-back live transactions of " + member.getAddress() + ", UUID: " + uuid);
        nodeEngine.getExecutionService().execute(ExecutionService.SYSTEM_EXECUTOR, () -> finalizeTransactionsOf(uuid));
    } else if (logger.isFinestEnabled()) {
        logger.finest("Will not commit/roll-back transactions of " + member.getAddress() + ", UUID: " + uuid + " because this member is not running");
    }
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl) UUID(java.util.UUID)

Example 68 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class MapPublisherCreateMessageTask method createInvocations.

private void createInvocations(Collection<MemberImpl> members, List<Future> futures) {
    final OperationServiceImpl operationService = nodeEngine.getOperationService();
    for (MemberImpl member : members) {
        Predicate predicate = serializationService.toObject(parameters.predicate);
        AccumulatorInfo accumulatorInfo = AccumulatorInfo.toAccumulatorInfo(parameters.mapName, parameters.cacheName, predicate, parameters.batchSize, parameters.bufferSize, parameters.delaySeconds, false, parameters.populate, parameters.coalesce);
        PublisherCreateOperation operation = new PublisherCreateOperation(accumulatorInfo);
        operation.setCallerUuid(endpoint.getUuid());
        Address address = member.getAddress();
        InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(SERVICE_NAME, operation, address);
        Future future = invocationBuilder.invoke();
        futures.add(future);
    }
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Future(java.util.concurrent.Future) AccumulatorInfo(com.hazelcast.map.impl.querycache.accumulator.AccumulatorInfo) InvocationBuilder(com.hazelcast.spi.impl.operationservice.InvocationBuilder) PublisherCreateOperation(com.hazelcast.map.impl.querycache.subscriber.operation.PublisherCreateOperation) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) Predicate(com.hazelcast.query.Predicate)

Example 69 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class CollectionService method dispatchEvent.

@Override
public void dispatchEvent(CollectionEvent event, ItemListener<Data> listener) {
    final MemberImpl member = nodeEngine.getClusterService().getMember(event.getCaller());
    ItemEvent<Data> itemEvent = new DataAwareItemEvent<Data>(event.getName(), event.getEventType(), event.getData(), member, serializationService);
    if (member == null) {
        if (logger.isInfoEnabled()) {
            logger.info("Dropping event " + itemEvent + " from unknown address:" + event.getCaller());
        }
        return;
    }
    if (event.getEventType().equals(ItemEventType.ADDED)) {
        listener.itemAdded(itemEvent);
    } else {
        listener.itemRemoved(itemEvent);
    }
}
Also used : DataAwareItemEvent(com.hazelcast.collection.impl.common.DataAwareItemEvent) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Data(com.hazelcast.internal.serialization.Data)

Example 70 with MemberImpl

use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.

the class RaftService method promoteToCPMember.

public InternalCompletableFuture<Void> promoteToCPMember() {
    InternalCompletableFuture<Void> future = newCompletableFuture();
    if (!metadataGroupManager.isDiscoveryCompleted()) {
        return complete(future, new IllegalStateException("CP Subsystem discovery is not completed yet!"));
    }
    if (nodeEngine.getLocalMember().isLiteMember()) {
        return complete(future, new IllegalStateException("Lite members cannot be promoted to CP member!"));
    }
    if (getLocalCPMember() != null) {
        future.complete(null);
        return future;
    }
    MemberImpl localMember = nodeEngine.getLocalMember();
    // Local member may be recovered during restart, for instance via Hot Restart,
    // but Raft state cannot be recovered back.
    // That's why we generate a new UUID while promoting a member to CP.
    // This new UUID generation can be removed when Hot Restart allows to recover Raft state.
    CPMemberInfo member = new CPMemberInfo(newUnsecureUUID(), localMember.getAddress());
    logger.info("Adding new CP member: " + member);
    invocationManager.invoke(getMetadataGroupId(), new AddCPMemberOp(member)).whenCompleteAsync((response, t) -> {
        if (t == null) {
            metadataGroupManager.initPromotedCPMember(member);
            future.complete(null);
        } else {
            complete(future, t);
        }
    });
    return future;
}
Also used : MemberImpl(com.hazelcast.cluster.impl.MemberImpl) AddCPMemberOp(com.hazelcast.cp.internal.raftop.metadata.AddCPMemberOp)

Aggregations

MemberImpl (com.hazelcast.cluster.impl.MemberImpl)123 Address (com.hazelcast.cluster.Address)41 Test (org.junit.Test)37 QuickTest (com.hazelcast.test.annotation.QuickTest)34 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)32 Member (com.hazelcast.cluster.Member)21 HazelcastInstance (com.hazelcast.core.HazelcastInstance)16 UUID (java.util.UUID)14 ArrayList (java.util.ArrayList)10 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)9 HashMap (java.util.HashMap)9 InetAddress (java.net.InetAddress)8 HashSet (java.util.HashSet)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 Config (com.hazelcast.config.Config)6 Future (java.util.concurrent.Future)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 StaticMemberNodeContext (com.hazelcast.instance.StaticMemberNodeContext)4 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)4 MembersUpdateOp (com.hazelcast.internal.cluster.impl.operations.MembersUpdateOp)4