Search in sources :

Example 1 with ComputeJobContext

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

the class PriorityQueueCollisionSpi method getJobPriority.

/**
     * Gets job priority. At first tries to get from job context. If job context has no priority,
     * then tries to get from task session. If task session has no priority default one will be used.
     *
     * @param ctx Collision job context.
     * @return Job priority.
     */
private int getJobPriority(CollisionJobContext ctx) {
    assert ctx != null;
    Integer p = null;
    ComputeJobContext jctx = ctx.getJobContext();
    try {
        p = (Integer) jctx.getAttribute(jobPriAttrKey);
    } catch (ClassCastException e) {
        LT.error(log, e, "Type of job context priority attribute '" + jobPriAttrKey + "' is not java.lang.Integer [type=" + jctx.getAttribute(jobPriAttrKey).getClass() + ']');
    }
    if (p == null) {
        ComputeTaskSession ses = ctx.getTaskSession();
        try {
            p = (Integer) ses.getAttribute(taskPriAttrKey);
        } catch (ClassCastException e) {
            LT.error(log, e, "Type of task session priority attribute '" + taskPriAttrKey + "' is not java.lang.Integer [type=" + ses.getAttribute(taskPriAttrKey).getClass() + ']');
        }
        if (p == null) {
            if (log.isDebugEnabled()) {
                log.debug("Failed get priority from job context attribute '" + jobPriAttrKey + "' and task session attribute '" + taskPriAttrKey + "' (will use default priority): " + dfltPri);
            }
            p = dfltPri;
        }
    }
    assert p != null;
    return p;
}
Also used : ComputeJobContext(org.apache.ignite.compute.ComputeJobContext) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession)

Example 2 with ComputeJobContext

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

the class GridClosureSerializationTest method testAttributesSerializationFailure.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "Convert2Lambda" })
public void testAttributesSerializationFailure() throws Exception {
    final IgniteEx ignite0 = grid(0);
    final IgniteEx ignite1 = grid(1);
    GridTestUtils.assertThrows(null, new Callable<Object>() {

        @JobContextResource
        private ComputeJobContext jobCtx;

        @Override
        public Object call() throws Exception {
            ignite1.compute(ignite1.cluster().forNode(ignite0.localNode())).call(new IgniteCallable<Object>() {

                @Override
                public Object call() throws Exception {
                    jobCtx.setAttribute("test-attr", new BrokenAttribute());
                    return null;
                }
            });
            return null;
        }
    }, IgniteException.class, null);
}
Also used : ComputeJobContext(org.apache.ignite.compute.ComputeJobContext) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCallable(org.apache.ignite.lang.IgniteCallable) JobContextResource(org.apache.ignite.resources.JobContextResource) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 3 with ComputeJobContext

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

the class GridTaskExecutionSelfTest method testJobIdCollision.

/**
     * Test for https://issues.apache.org/jira/browse/IGNITE-1384
     *
     * @throws Exception If failed.
     */
public void testJobIdCollision() throws Exception {
    fail("Test refactoring is needed: https://issues.apache.org/jira/browse/IGNITE-4706");
    long locId = IgniteUuid.lastLocalId();
    ArrayList<IgniteFuture<Object>> futs = new ArrayList<>(2016);
    IgniteCompute compute = grid(1).compute(grid(1).cluster().forNodeId(grid(3).localNode().id()));
    for (int i = 0; i < 1000; i++) {
        futs.add(compute.callAsync(new IgniteCallable<Object>() {

            @JobContextResource
            ComputeJobContext ctx;

            boolean held;

            @Override
            public Object call() throws Exception {
                if (!held) {
                    ctx.holdcc(1000);
                    held = true;
                }
                return null;
            }
        }));
    }
    info("Finished first loop.");
    AtomicLong idx = U.field(IgniteUuid.class, "cntGen");
    idx.set(locId);
    IgniteCompute compute1 = grid(2).compute(grid(2).cluster().forNodeId(grid(3).localNode().id()));
    for (int i = 0; i < 100; i++) {
        futs.add(compute1.callAsync(new IgniteCallable<Object>() {

            @JobContextResource
            ComputeJobContext ctx;

            boolean held;

            @Override
            public Object call() throws Exception {
                if (!held) {
                    ctx.holdcc(1000);
                    held = true;
                }
                return null;
            }
        }));
    }
    for (IgniteFuture<Object> fut : futs) fut.get();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ComputeJobContext(org.apache.ignite.compute.ComputeJobContext) IgniteCallable(org.apache.ignite.lang.IgniteCallable) ArrayList(java.util.ArrayList) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteCompute(org.apache.ignite.IgniteCompute)

Aggregations

ComputeJobContext (org.apache.ignite.compute.ComputeJobContext)3 IgniteCallable (org.apache.ignite.lang.IgniteCallable)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteCompute (org.apache.ignite.IgniteCompute)1 IgniteException (org.apache.ignite.IgniteException)1 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)1 ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteFuture (org.apache.ignite.lang.IgniteFuture)1 JobContextResource (org.apache.ignite.resources.JobContextResource)1