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;
}
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);
}
}
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();
}
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());
}
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;
}
Aggregations