Search in sources :

Example 1 with ComputeJobStatusEnum

use of org.apache.ignite.internal.processors.job.ComputeJobStatusEnum in project ignite by apache.

the class GridTaskWorker method jobStatuses.

/**
 * Collects statistics on jobs locally, only for those jobs that have
 * already sent a response or are being executed locally.
 *
 * @return Job statistics for the task. Mapping: Job status -> count of jobs.
 */
Map<ComputeJobStatusEnum, Long> jobStatuses() {
    List<GridJobResultImpl> jobResults = null;
    synchronized (mux) {
        if (jobRes != null)
            jobResults = new ArrayList<>(jobRes.values());
    }
    // Jobs have not been mapped yet.
    if (F.isEmpty(jobResults))
        return emptyMap();
    UUID locNodeId = ctx.localNodeId();
    boolean getLocJobStatistics = false;
    Map<ComputeJobStatusEnum, Long> res = new EnumMap<>(ComputeJobStatusEnum.class);
    for (GridJobResultImpl jobResult : jobResults) {
        if (jobResult.hasResponse()) {
            ComputeJobStatusEnum jobStatus;
            if (jobResult.isCancelled())
                jobStatus = CANCELLED;
            else if (jobResult.getException() != null)
                jobStatus = FAILED;
            else
                jobStatus = FINISHED;
            res.merge(jobStatus, 1L, Long::sum);
        } else if (!getLocJobStatistics && locNodeId.equals(jobResult.getNode().id()))
            getLocJobStatistics = true;
    }
    if (getLocJobStatistics) {
        Map<ComputeJobStatusEnum, Long> jobStatuses = ctx.job().jobStatuses(getTaskSessionId());
        for (Map.Entry<ComputeJobStatusEnum, Long> e : jobStatuses.entrySet()) res.merge(e.getKey(), e.getValue(), Long::sum);
    }
    return res;
}
Also used : GridJobResultImpl(org.apache.ignite.internal.GridJobResultImpl) ArrayList(java.util.ArrayList) UUID(java.util.UUID) EnumMap(java.util.EnumMap) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) ComputeJobStatusEnum(org.apache.ignite.internal.processors.job.ComputeJobStatusEnum)

Aggregations

ArrayList (java.util.ArrayList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 GridJobResultImpl (org.apache.ignite.internal.GridJobResultImpl)1 ComputeJobStatusEnum (org.apache.ignite.internal.processors.job.ComputeJobStatusEnum)1