use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.
the class VisorQueryDetailMetricsCollectorTask method reduce0.
/** {@inheritDoc} */
@Nullable
@Override
protected Collection<VisorQueryDetailMetrics> reduce0(List<ComputeJobResult> results) throws IgniteException {
Map<GridCacheQueryDetailMetricsKey, GridCacheQueryDetailMetricsAdapter> taskRes = new HashMap<>();
for (ComputeJobResult res : results) {
if (res.getException() != null)
throw res.getException();
Collection<GridCacheQueryDetailMetricsAdapter> metrics = res.getData();
VisorCacheQueryDetailMetricsCollectorJob.aggregateMetrics(-1, taskRes, metrics);
}
Collection<GridCacheQueryDetailMetricsAdapter> aggMetrics = taskRes.values();
Collection<VisorQueryDetailMetrics> res = new ArrayList<>(aggMetrics.size());
for (GridCacheQueryDetailMetricsAdapter m : aggMetrics) res.add(new VisorQueryDetailMetrics(m));
return res;
}
use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.
the class JobStealingTask method reduce.
/** {@inheritDoc} */
@SuppressWarnings("SuspiciousMethodCalls")
@Override
public Map<UUID, Integer> reduce(List<ComputeJobResult> results) {
Map<UUID, Integer> ret = U.newHashMap(results.size());
for (ComputeJobResult res : results) {
log.info("Job result: " + res.getData());
UUID resUuid = (UUID) res.getData();
ret.put(resUuid, ret.containsKey(resUuid) ? ret.get(resUuid) + 1 : 1);
}
return ret;
}
use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.
the class GridTaskJobRejectSelfTest method testReject.
/**
* @throws Exception If failed.
*/
public void testReject() throws Exception {
grid(1).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
X.println("Task event: " + evt);
return true;
}
}, EVTS_TASK_EXECUTION);
grid(1).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
X.println("Job event: " + evt);
return true;
}
}, EVTS_JOB_EXECUTION);
final CountDownLatch startedLatch = new CountDownLatch(1);
grid(1).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
startedLatch.countDown();
return true;
}
}, EVT_JOB_STARTED);
final AtomicInteger failedOver = new AtomicInteger(0);
grid(1).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
failedOver.incrementAndGet();
return true;
}
}, EVT_JOB_FAILED_OVER);
final CountDownLatch finishedLatch = new CountDownLatch(1);
grid(1).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
finishedLatch.countDown();
return true;
}
}, EVT_TASK_FINISHED, EVT_TASK_FAILED);
final ClusterNode node = grid(1).localNode();
ComputeTaskFuture<?> fut = grid(1).compute().executeAsync(new ComputeTaskAdapter<Void, Void>() {
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable Void arg) {
return F.asMap(new SleepJob(), node, new SleepJob(), node);
}
/** {@inheritDoc} */
@Nullable
@Override
public Void reduce(List<ComputeJobResult> results) {
return null;
}
}, null);
assert startedLatch.await(2, SECONDS);
fut.cancel();
assert finishedLatch.await(2, SECONDS);
assert failedOver.get() == 0;
}
use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.
the class GridAlwaysFailoverSpiSelfTest method testTwoNodes.
/**
* @throws Exception If test failed.
*/
@SuppressWarnings("unchecked")
public void testTwoNodes() throws Exception {
AlwaysFailoverSpi spi = getSpi();
List<ClusterNode> nodes = new ArrayList<>();
nodes.add(new GridTestNode(UUID.randomUUID()));
nodes.add(new GridTestNode(UUID.randomUUID()));
ComputeJobResult jobRes = new GridTestJobResult(nodes.get(0));
ClusterNode node = spi.failover(new GridFailoverTestContext(new GridTestTaskSession(), jobRes), nodes);
assert node != null;
assert node.equals(nodes.get(1));
checkFailedNodes(jobRes, 1);
}
use of org.apache.ignite.compute.ComputeJobResult in project ignite by apache.
the class GridAlwaysFailoverSpiSelfTest method testMaxAttempts.
/**
* @throws Exception If failed.
*/
public void testMaxAttempts() throws Exception {
AlwaysFailoverSpi spi = getSpi();
spi.setMaximumFailoverAttempts(1);
List<ClusterNode> nodes = new ArrayList<>();
nodes.add(new GridTestNode(UUID.randomUUID()));
nodes.add(new GridTestNode(UUID.randomUUID()));
ComputeJobResult jobRes = new GridTestJobResult(nodes.get(0));
// First attempt.
ClusterNode node = spi.failover(new GridFailoverTestContext(new GridTestTaskSession(), jobRes), nodes);
assert node != null;
assert node.equals(nodes.get(1));
checkFailedNodes(jobRes, 1);
// Second attempt (exceeds default max attempts of 1).
node = spi.failover(new GridFailoverTestContext(new GridTestTaskSession(), jobRes), nodes);
assert node == null;
checkFailedNodes(jobRes, 1);
}
Aggregations