Search in sources :

Example 1 with ComputeJobResult

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;
}
Also used : HashMap(java.util.HashMap) GridCacheQueryDetailMetricsKey(org.apache.ignite.internal.processors.cache.query.GridCacheQueryDetailMetricsKey) GridCacheQueryDetailMetricsAdapter(org.apache.ignite.internal.processors.cache.query.GridCacheQueryDetailMetricsAdapter) ArrayList(java.util.ArrayList) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ComputeJobResult

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;
}
Also used : UUID(java.util.UUID) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult)

Example 3 with ComputeJobResult

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CountDownLatch(java.util.concurrent.CountDownLatch) ComputeJob(org.apache.ignite.compute.ComputeJob) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Event(org.apache.ignite.events.Event) Map(java.util.Map) Nullable(org.jetbrains.annotations.Nullable) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult)

Example 4 with ComputeJobResult

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);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) ArrayList(java.util.ArrayList) GridTestJobResult(org.apache.ignite.GridTestJobResult) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridFailoverTestContext(org.apache.ignite.spi.failover.GridFailoverTestContext) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult)

Example 5 with ComputeJobResult

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);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) ArrayList(java.util.ArrayList) GridTestJobResult(org.apache.ignite.GridTestJobResult) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridFailoverTestContext(org.apache.ignite.spi.failover.GridFailoverTestContext) 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