Search in sources :

Example 56 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class MasterContext method invokeOnParticipant.

private void invokeOnParticipant(MemberInfo memberInfo, Supplier<Operation> operationSupplier, @Nullable Consumer<Collection<Map.Entry<MemberInfo, Object>>> completionCallback, @Nullable BiConsumer<Address, Object> individualCallback, boolean retryOnTimeoutException, ConcurrentMap<MemberInfo, Object> collectedResponses, AtomicInteger remainingCount) {
    Operation operation = operationSupplier.get();
    InternalCompletableFuture<Object> future = nodeEngine.getOperationService().createInvocationBuilder(JetServiceBackend.SERVICE_NAME, operation, memberInfo.getAddress()).invoke();
    future.whenCompleteAsync(withTryCatch(logger, (r, throwable) -> {
        Object response = r != null ? r : throwable != null ? peel(throwable) : NULL_OBJECT;
        if (retryOnTimeoutException && throwable instanceof OperationTimeoutException) {
            logger.warning("Retrying " + operation.getClass().getName() + " that failed with " + OperationTimeoutException.class.getSimpleName() + " in " + jobIdString());
            invokeOnParticipant(memberInfo, operationSupplier, completionCallback, individualCallback, retryOnTimeoutException, collectedResponses, remainingCount);
            return;
        }
        if (individualCallback != null) {
            individualCallback.accept(memberInfo.getAddress(), throwable != null ? peel(throwable) : r);
        }
        Object oldResponse = collectedResponses.put(memberInfo, response);
        assert oldResponse == null : "Duplicate response for " + memberInfo.getAddress() + ". Old=" + oldResponse + ", new=" + response;
        if (remainingCount.decrementAndGet() == 0 && completionCallback != null) {
            completionCallback.accept(collectedResponses.entrySet().stream().map(e -> e.getValue() == NULL_OBJECT ? entry(e.getKey(), null) : e).collect(Collectors.toList()));
        }
    }));
}
Also used : Address(com.hazelcast.cluster.Address) NOT_RUNNING(com.hazelcast.jet.core.JobStatus.NOT_RUNNING) CompletableFuture(java.util.concurrent.CompletableFuture) StartExecutionOperation(com.hazelcast.jet.impl.operation.StartExecutionOperation) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Util.jobNameAndExecutionId(com.hazelcast.jet.impl.util.Util.jobNameAndExecutionId) ILogger(com.hazelcast.logging.ILogger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Operation(com.hazelcast.spi.impl.operationservice.Operation) Util.entry(com.hazelcast.jet.Util.entry) ExceptionUtil.withTryCatch(com.hazelcast.jet.impl.util.ExceptionUtil.withTryCatch) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) SUSPENDED(com.hazelcast.jet.core.JobStatus.SUSPENDED) JobStatus(com.hazelcast.jet.core.JobStatus) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Collectors.toConcurrentMap(java.util.stream.Collectors.toConcurrentMap) Collection(java.util.Collection) JobConfig(com.hazelcast.jet.config.JobConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Util.idToString(com.hazelcast.jet.Util.idToString) ExceptionUtil.peel(com.hazelcast.jet.impl.util.ExceptionUtil.peel) ExecutionPlan(com.hazelcast.jet.impl.execution.init.ExecutionPlan) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) Entry(java.util.Map.Entry) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) StartExecutionOperation(com.hazelcast.jet.impl.operation.StartExecutionOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 57 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class JetInstanceImpl method getJobsInt.

@Override
public Map<Address, GetJobIdsResult> getJobsInt(String onlyName, Long onlyJobId) {
    Map<Address, CompletableFuture<GetJobIdsResult>> futures = new HashMap<>();
    Address masterAddress = null;
    // if onlyName != null, only send the operation to master. Light jobs cannot have a name
    Collection<Member> targetMembers = onlyName == null ? nodeEngine.getClusterService().getMembers(DATA_MEMBER_SELECTOR) : singleton(nodeEngine.getClusterService().getMembers().iterator().next());
    for (Member member : targetMembers) {
        if (masterAddress == null) {
            masterAddress = member.getAddress();
        }
        GetJobIdsOperation operation = new GetJobIdsOperation(onlyName, onlyJobId);
        InvocationFuture<GetJobIdsResult> future = nodeEngine.getOperationService().createInvocationBuilder(JetServiceBackend.SERVICE_NAME, operation, member.getAddress()).invoke();
        futures.put(member.getAddress(), future);
    }
    Map<Address, GetJobIdsResult> res = new HashMap<>(futures.size());
    for (Entry<Address, CompletableFuture<GetJobIdsResult>> en : futures.entrySet()) {
        GetJobIdsResult result;
        try {
            result = en.getValue().get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            result = GetJobIdsResult.EMPTY;
        } catch (ExecutionException e) {
            // important. If we don't get response from the master, we report it to the user.
            if (!en.getKey().equals(masterAddress) && (e.getCause() instanceof TargetNotMemberException || e.getCause() instanceof MemberLeftException)) {
                result = GetJobIdsResult.EMPTY;
            } else {
                throw new RuntimeException("Error when getting job IDs: " + e, e);
            }
        }
        res.put(en.getKey(), result);
    }
    return res;
}
Also used : Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) GetJobIdsOperation(com.hazelcast.jet.impl.operation.GetJobIdsOperation) CompletableFuture(java.util.concurrent.CompletableFuture) TargetNotMemberException(com.hazelcast.spi.exception.TargetNotMemberException) ExecutionException(java.util.concurrent.ExecutionException) Member(com.hazelcast.cluster.Member) GetJobIdsResult(com.hazelcast.jet.impl.operation.GetJobIdsOperation.GetJobIdsResult) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 58 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class Util method assignPartitions.

/**
 * Assigns given partitions to given {@code members}.
 * Set of partitions belonging to non-members are assigned to
 * {@code members} in a round robin fashion.
 */
public static Map<Address, List<Integer>> assignPartitions(Collection<Address> members0, Map<Address, List<Integer>> partitionsByOwner) {
    assert !members0.isEmpty();
    LinkedHashSet<Address> members = new LinkedHashSet<>(members0);
    Iterator<Address> iterator = members.iterator();
    Map<Address, List<Integer>> partitionsByMember = new HashMap<>();
    for (Entry<Address, List<Integer>> entry : partitionsByOwner.entrySet()) {
        Address partitionOwner = entry.getKey();
        List<Integer> partitions = entry.getValue();
        Address target;
        if (members.contains(partitionOwner)) {
            target = partitionOwner;
        } else {
            if (!iterator.hasNext()) {
                iterator = members.iterator();
            }
            target = iterator.next();
        }
        partitionsByMember.merge(target, new ArrayList<>(partitions), (existing, incoming) -> {
            existing.addAll(incoming);
            return existing;
        });
    }
    return partitionsByMember;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Address(com.hazelcast.cluster.Address) HashMap(java.util.HashMap) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 59 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class MapGetInvalidationMetaDataOperation method getOwnedPartitions.

private List<Integer> getOwnedPartitions() {
    IPartitionService partitionService = getNodeEngine().getPartitionService();
    Map<Address, List<Integer>> memberPartitionsMap = partitionService.getMemberPartitionsMap();
    List<Integer> ownedPartitions = memberPartitionsMap.get(getNodeEngine().getThisAddress());
    return ownedPartitions == null ? Collections.emptyList() : ownedPartitions;
}
Also used : Address(com.hazelcast.cluster.Address) IPartitionService(com.hazelcast.internal.partition.IPartitionService) ArrayList(java.util.ArrayList) List(java.util.List)

Example 60 with Address

use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.

the class MapClearExpiredOperation method isOwner.

private boolean isOwner() {
    final NodeEngine nodeEngine = getNodeEngine();
    final Address owner = nodeEngine.getPartitionService().getPartitionOwner(getPartitionId());
    return nodeEngine.getThisAddress().equals(owner);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Address(com.hazelcast.cluster.Address)

Aggregations

Address (com.hazelcast.cluster.Address)540 Test (org.junit.Test)211 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)178 HazelcastInstance (com.hazelcast.core.HazelcastInstance)92 InetAddress (java.net.InetAddress)75 ArrayList (java.util.ArrayList)66 Member (com.hazelcast.cluster.Member)63 Accessors.getAddress (com.hazelcast.test.Accessors.getAddress)54 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)48 Config (com.hazelcast.config.Config)43 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)43 UUID (java.util.UUID)43 ILogger (com.hazelcast.logging.ILogger)37 HashMap (java.util.HashMap)36 Operation (com.hazelcast.spi.impl.operationservice.Operation)35 List (java.util.List)35 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)34 Map (java.util.Map)33 InetSocketAddress (java.net.InetSocketAddress)32