Search in sources :

Example 1 with GetJobIdsResult

use of com.hazelcast.jet.impl.operation.GetJobIdsOperation.GetJobIdsResult 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)

Aggregations

Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1 MemberLeftException (com.hazelcast.core.MemberLeftException)1 GetJobIdsOperation (com.hazelcast.jet.impl.operation.GetJobIdsOperation)1 GetJobIdsResult (com.hazelcast.jet.impl.operation.GetJobIdsOperation.GetJobIdsResult)1 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)1 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1