Search in sources :

Example 6 with ComputeJobResult

use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.

the class ComputeClientTask method reduce.

/** {@inheritDoc} */
@Nullable
@Override
public Long reduce(List<ComputeJobResult> results) {
    long sum = 0;
    int cnt = 0;
    for (ComputeJobResult res : results) {
        IgniteBiTuple<Long, Integer> t = res.getData();
        sum += t.get1();
        cnt += t.get2();
    }
    return sum / cnt;
}
Also used : ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with ComputeJobResult

use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.

the class GridCacheQueryJdbcTask method reduce.

/** {@inheritDoc} */
@Override
public byte[] reduce(List<ComputeJobResult> results) throws IgniteException {
    try {
        byte status;
        byte[] bytes;
        ComputeJobResult res = F.first(results);
        if (res.getException() == null) {
            status = 0;
            bytes = U.marshal(MARSHALLER, res.getData());
        } else {
            status = 1;
            bytes = U.marshal(MARSHALLER, new SQLException(res.getException().getMessage()));
        }
        byte[] packet = new byte[bytes.length + 1];
        packet[0] = status;
        U.arrayCopy(bytes, 0, packet, 1, bytes.length);
        return packet;
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLException(java.sql.SQLException) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult)

Example 8 with ComputeJobResult

use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.

the class VisorGatewayTask method reduce.

/** {@inheritDoc} */
@Nullable
@Override
public Object reduce(List<ComputeJobResult> results) throws IgniteException {
    assert results.size() == 1;
    ComputeJobResult res = F.first(results);
    assert res != null;
    IgniteException ex = res.getException();
    if (ex != null)
        throw ex;
    return res.getData();
}
Also used : IgniteException(org.apache.ignite.IgniteException) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with ComputeJobResult

use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.

the class VisorCacheMetricsCollectorTask method reduce0.

/** {@inheritDoc} */
@Nullable
@Override
protected Iterable<VisorCacheAggregatedMetrics> reduce0(List<ComputeJobResult> results) {
    Map<String, VisorCacheAggregatedMetrics> grpAggrMetrics = U.newHashMap(results.size());
    for (ComputeJobResult res : results) {
        if (res.getException() == null) {
            Collection<VisorCacheMetrics> cms = res.getData();
            for (VisorCacheMetrics cm : cms) {
                VisorCacheAggregatedMetrics am = grpAggrMetrics.get(cm.getName());
                if (am == null) {
                    am = new VisorCacheAggregatedMetrics(cm);
                    grpAggrMetrics.put(cm.getName(), am);
                }
                am.getMetrics().put(res.getNode().id(), cm);
            }
        }
    }
    // Create serializable result.
    return new ArrayList<>(grpAggrMetrics.values());
}
Also used : ArrayList(java.util.ArrayList) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with ComputeJobResult

use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.

the class VisorNodeDataCollectorTask method reduce.

/**
     * @param taskRes Task result.
     * @param results Results.
     * @return Data collector task result.
     */
protected VisorNodeDataCollectorTaskResult reduce(VisorNodeDataCollectorTaskResult taskRes, List<ComputeJobResult> results) {
    for (ComputeJobResult res : results) {
        VisorNodeDataCollectorJobResult jobRes = res.getData();
        if (jobRes != null) {
            UUID nid = res.getNode().id();
            IgniteException unhandledEx = res.getException();
            if (unhandledEx == null)
                reduceJobResult(taskRes, jobRes, nid);
            else {
                // Ignore nodes that left topology.
                if (!(unhandledEx instanceof ClusterGroupEmptyException))
                    taskRes.getUnhandledEx().put(nid, new VisorExceptionWrapper(unhandledEx));
            }
        }
    }
    taskRes.setActive(ignite.active());
    return taskRes;
}
Also used : IgniteException(org.apache.ignite.IgniteException) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) VisorExceptionWrapper(org.apache.ignite.internal.visor.util.VisorExceptionWrapper) UUID(java.util.UUID) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult)

Aggregations

ComputeJobResult (org.apache.ignite.compute.ComputeJobResult)14 Nullable (org.jetbrains.annotations.Nullable)8 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)5 IgniteException (org.apache.ignite.IgniteException)4 HashMap (java.util.HashMap)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 GridTestJobResult (org.apache.ignite.GridTestJobResult)2 GridTestTaskSession (org.apache.ignite.GridTestTaskSession)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 GridFailoverTestContext (org.apache.ignite.spi.failover.GridFailoverTestContext)2 GridTestNode (org.apache.ignite.testframework.GridTestNode)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ClusterGroupEmptyException (org.apache.ignite.cluster.ClusterGroupEmptyException)1