/** * Gets job priority from task context. If job has no priority default one will be used. * * @param ctx Job context. * @return Job priority. */ private int getJobPriority(ComputeJobContext ctx) { assert ctx != null; Integer p; try { p = ctx.getAttribute(STEALING_PRIORITY_ATTR); } catch (ClassCastException e) { U.error(log, "Type of job context priority attribute '" + STEALING_PRIORITY_ATTR + "' is not java.lang.Integer (will use default priority) [type=" + ctx.getAttribute(STEALING_PRIORITY_ATTR).getClass() + ", dfltPriority=" + DFLT_JOB_PRIORITY + ']', e); p = DFLT_JOB_PRIORITY; } if (p == null) p = DFLT_JOB_PRIORITY; return p; }
/** {@inheritDoc} */ @Override public Object reduce(List<ComputeJobResult> results) { for (ComputeJobResult res : results) { ComputeJobContext jobCtx = res.getJobContext(); assert jobCtx.getAttribute("nodeId").equals(res.getNode().id()); assert jobCtx.getAttributes().get("nodeId").equals(res.getNode().id()); assert jobCtx.getAttribute("jobId").equals(jobCtx.getJobId()); for (int i = 0; i < 10; i++) { String s = jobCtx.getJobId().toString() + i; assert jobCtx.getAttribute(s).equals(s); assert jobCtx.getAttributes().get(s).equals(s); } } return null; } }
/** * @param ctx Failed job context. * @param failed Failed node. * @param failCnt Failover count. */ private void checkAttributes(ComputeJobContext ctx, ClusterNode failed, int failCnt) { assert (Integer)ctx.getAttribute(FAILOVER_ATTEMPT_COUNT_ATTR) == failCnt; if (failed != null) { Collection<UUID> failedSet = (Collection<UUID>)ctx.getAttribute(FAILED_NODE_LIST_ATTR); assert failedSet.contains(failed.id()); } } }
/** {@inheritDoc} */ @Override public Serializable execute() { UUID locNodeId = ignite.configuration().getNodeId(); jobCtx.setAttribute("nodeId", locNodeId); jobCtx.setAttribute("jobId", jobCtx.getJobId()); Map<String, String> attrs = new HashMap<>(10); for (int i = 0; i < 10; i++) { String s = jobCtx.getJobId().toString() + i; attrs.put(s, s); } jobCtx.setAttributes(attrs); assert jobCtx.getAttribute("nodeId").equals(locNodeId); assert jobCtx.getAttributes().get("nodeId").equals(locNodeId); assert jobCtx.getAttributes().keySet().containsAll(attrs.keySet()); assert jobCtx.getAttributes().values().containsAll(attrs.values()); return null; } });
/** * @param res Job result. * @param cnt Failure count. */ private void checkFailedNodes(ComputeJobResult res, int cnt) { Collection<UUID> failedNodes = (Collection<UUID>)res.getJobContext().getAttribute(FAILED_NODE_LIST_ATTR); assert failedNodes != null; assert failedNodes.size() == cnt; } }
p = (Integer)jctx.getAttribute(jobPriAttrKey); "' is not java.lang.Integer [type=" + jctx.getAttribute(jobPriAttrKey).getClass() + ']');
/** * @param ctx Collision job context. */ private void checkActivated(GridTestCollisionJobContext ctx) { assert ctx.isActivated(); assert !ctx.isCanceled(); assert ctx.getJobContext().getAttribute(THIEF_NODE_ATTR) == null; }
/** * @param ctx Collision job context. */ private void checkNoAction(GridTestCollisionJobContext ctx) { assert !ctx.isActivated(); assert !ctx.isCanceled(); assert ctx.getJobContext().getAttribute(THIEF_NODE_ATTR) == null; }
/** * @param ctx Collision job context. * @param rmtNode Remote node. */ private void checkRejected(GridTestCollisionJobContext ctx, ClusterNode rmtNode) { assert ctx.isCanceled(); assert !ctx.isActivated(); assert ctx.getJobContext().getAttribute(THIEF_NODE_ATTR).equals(rmtNode.id()); }
/** * @param ctx Collision job context. */ private void checkNoAction(GridTestCollisionJobContext ctx) { assert !ctx.isActivated(); assert !ctx.isCanceled(); assert ctx.getJobContext().getAttribute(THIEF_NODE_ATTR) == null; }
/** {@inheritDoc} */ @Override public void run() { Integer attempt = jobCtx.getAttribute(ATTR_ATTEMPT); if (attempt == null) attempt = 1; assertEquals(ignite.affinity(NON_DFLT_CACHE_NAME).mapKeyToNode(key), ignite.cluster().localNode()); jobCtx.setAttribute(ATTR_ATTEMPT, attempt + 1); if (attempt < callAttempt) throw new ComputeJobFailoverException("Failover exception."); else assertEquals(callAttempt, attempt); } }
/** {@inheritDoc} */ @Override public Object call() throws IgniteCheckedException { Integer attempt = jobCtx.getAttribute(ATTR_ATTEMPT); if (attempt == null) attempt = 1; assertEquals(ignite.affinity(NON_DFLT_CACHE_NAME).mapKeyToNode(key), ignite.cluster().localNode()); jobCtx.setAttribute(ATTR_ATTEMPT, attempt + 1); if (attempt < callAttempt) throw new ComputeJobFailoverException("Failover exception."); else return attempt; } }
if (fut.isDone() || F.eq(jobCtx.getAttribute(ATTR_HELD), true)) return hadoop.status(jobId); else {
Integer affCallAttempt = ctx.getJobResult().getJobContext().getAttribute(AFFINITY_CALL_ATTEMPT); Collection<UUID> failedNodes = ctx.getJobResult().getJobContext().getAttribute(FAILED_NODE_LIST_ATTR);
Integer failoverCnt = ctx.getJobResult().getJobContext().getAttribute(FAILOVER_ATTEMPT_COUNT_ATTR); boolean isNodeFailed = false; UUID thiefId = ctx.getJobResult().getJobContext().getAttribute(THIEF_NODE_ATTR); Collection<UUID> failedNodes = ctx.getJobResult().getJobContext().getAttribute(FAILED_NODE_LIST_ATTR);
/** {@inheritDoc} */ @Override public ClusterNode failover(FailoverContext ctx, List<ClusterNode> top) { failedOverJobs.add(ctx.getJobResult().getJobContext()); // Clear failed nodes list - allow to failover on the same node. ctx.getJobResult().getJobContext().setAttribute(FAILED_NODE_LIST_ATTR, null); // Account for maximum number of failover attempts since we clear failed node list. Integer failoverCnt = ctx.getJobResult().getJobContext().getAttribute(FAILOVER_NUMBER_ATTR); if (failoverCnt == null) ctx.getJobResult().getJobContext().setAttribute(FAILOVER_NUMBER_ATTR, 1); else { if (failoverCnt >= getMaximumFailoverAttempts()) { U.warn(log, "Job failover failed because number of maximum failover attempts is exceeded " + "[failedJob=" + ctx.getJobResult().getJob() + ", maxFailoverAttempts=" + getMaximumFailoverAttempts() + ']'); return null; } ctx.getJobResult().getJobContext().setAttribute(FAILOVER_NUMBER_ATTR, failoverCnt + 1); } List<ClusterNode> cp = new ArrayList<>(top); // Keep collection type. F.retain(cp, false, new IgnitePredicate<ClusterNode>() { @Override public boolean apply(ClusterNode node) { return F.isAll(node, filter); } }); return super.failover(ctx, cp); //use cp to ensure we don't failover on failed node }
/** * @throws Exception If failed. */ @Test public void testCollision5() throws Exception { List<CollisionJobContext> activeJobs = makeContextList(null, false); List<CollisionJobContext> passiveJobs = makeContextList(null, false); getSpi().setParallelJobsNumber(12); getSpi().setStarvationPreventionEnabled(false); getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs)); String jobAttrKey = DFLT_JOB_PRIORITY_ATTRIBUTE_KEY; for (CollisionJobContext ctx : passiveJobs) { int taskP = ((GridTestCollisionTaskSession)ctx.getTaskSession()).getPriority(); if (taskP >= 8) { assert ((GridTestCollisionJobContext)ctx).isActivated(); assert !((GridTestCollisionJobContext)ctx).isCanceled(); } else { assert !((GridTestCollisionJobContext)ctx).isActivated(); assert !((GridTestCollisionJobContext)ctx).isCanceled(); } assert ctx.getJobContext().<String, Integer>getAttribute(jobAttrKey) == null; } for (CollisionJobContext ctx : activeJobs) { assert !((GridTestCollisionJobContext)ctx).isActivated(); assert !((GridTestCollisionJobContext)ctx).isCanceled(); } }
/** * @throws Exception If failed. */ @Test public void testCollision1() throws Exception { List<CollisionJobContext> activeJobs = makeContextList(null); List<CollisionJobContext> passiveJobs = makeContextList(null); getSpi().setParallelJobsNumber(12); getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs)); int incVal = getSpi().getStarvationIncrement(); String jobAttrKey = DFLT_JOB_PRIORITY_ATTRIBUTE_KEY; for (CollisionJobContext ctx : passiveJobs) { if (((GridTestCollisionTaskSession)ctx.getTaskSession()).getPriority() >= 8) { assert ((GridTestCollisionJobContext)ctx).isActivated(); assert !((GridTestCollisionJobContext)ctx).isCanceled(); } else { assert !((GridTestCollisionJobContext)ctx).isActivated(); assert !((GridTestCollisionJobContext)ctx).isCanceled(); } Integer p = ctx.getJobContext().<String, Integer>getAttribute(jobAttrKey); if (p != null) assert p == incVal + ((GridTestCollisionTaskSession)ctx.getTaskSession()).getPriority(); } for (CollisionJobContext ctx : activeJobs) { assert !((GridTestCollisionJobContext)ctx).isActivated(); assert !((GridTestCollisionJobContext)ctx).isCanceled(); } }
Integer p = ctx.getJobContext().getAttribute(jobAttrKey);
Integer p = ctx.getJobContext().getAttribute(jobAttrKey);