Search in sources :

Example 1 with GetJobIdsOperation

use of com.hazelcast.jet.impl.operation.GetJobIdsOperation in project hazelcast-jet by hazelcast.

the class JetInstanceImpl method getJobs.

@Nonnull
@Override
public List<Job> getJobs() {
    Address masterAddress = nodeEngine.getMasterAddress();
    Future<Set<Long>> future = nodeEngine.getOperationService().createInvocationBuilder(JetService.SERVICE_NAME, new GetJobIdsOperation(), masterAddress).invoke();
    return uncheckCall(() -> future.get().stream().map(jobId -> new JobProxy((NodeEngineImpl) nodeEngine, jobId)).collect(toList()));
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Set(java.util.Set) Address(com.hazelcast.nio.Address) GetJobIdsOperation(com.hazelcast.jet.impl.operation.GetJobIdsOperation) Nonnull(javax.annotation.Nonnull)

Example 2 with GetJobIdsOperation

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

GetJobIdsOperation (com.hazelcast.jet.impl.operation.GetJobIdsOperation)2 Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1 MemberLeftException (com.hazelcast.core.MemberLeftException)1 GetJobIdsResult (com.hazelcast.jet.impl.operation.GetJobIdsOperation.GetJobIdsResult)1 Address (com.hazelcast.nio.Address)1 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 Nonnull (javax.annotation.Nonnull)1