/** {@inheritDoc} */ @Override public void cancel() { synchronized (mux) { isCancelled = true; cancelCnt++; mux.notifyAll(); } log.warning("Job cancelled: " + jobCtx.getJobId()); } }
/** {@inheritDoc} */ @Override public Serializable execute() { synchronized (mux) { execCnt++; } if (log.isInfoEnabled()) log.info("Executing job: " + jobCtx.getJobId()); long now = System.currentTimeMillis(); while (!isCancelled && now < thresholdTime) { synchronized (mux) { try { mux.wait(thresholdTime - now); } catch (InterruptedException ignored) { // No-op. } } now = System.currentTimeMillis(); } synchronized (mux) { return isCancelled ? 1 : 0; } }
/** {@inheritDoc} */ @Override public Serializable execute() { Integer i = argument(0); int arg = i != null ? i : 0; ses.setAttribute("sendJob" + ctx.getJobId(), 1 + arg); return arg; } }
/** {@inheritDoc} */ @Override public Serializable execute() { IgniteUuid jobId = jobCtx.getJobId(); String attr = (String)taskSes.getAttribute(jobId); assert attr != null : "Attribute is null."; assert attr.equals("test-" + jobId) : "Attribute has incorrect value: " + attr; if (log.isInfoEnabled()) log.info("Executing job: " + jobId); return null; } });
/** * Gives job description in standard log format. * * @return String with current job representation. */ private String getJobInfo() { return "[taskId=" + taskSes.getId() + ", jobId=" + cntx.getJobId() + ", nodeId=" + ignite.configuration().getNodeId() + "]"; } }
/** {@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; } });
/** {@inheritDoc} */ @Override public Serializable execute() { UUID nodeId = ignite.configuration().getNodeId(); if (log.isDebugEnabled()) log.debug("Executing job on node [nodeId=" + nodeId + ", jobId=" + ctx.getJobId() + ']'); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } // Here we gonna return node id which executed this job. // Hopefully it would be stealing node. return nodeId; } }
/** {@inheritDoc} */ @Override public ComputeJobResultPolicy result(ComputeJobResult result, List<ComputeJobResult> received) { if (received.size() == 1) { Collection<ComputeJobSibling> jobSiblings = taskSes.getJobSiblings(); IgniteUuid jobId = received.get(0).getJobContext().getJobId(); assert jobId != null; // Cancel all jobs except first job with argument 1. for (ComputeJobSibling jobSibling : jobSiblings) { if (!jobId.equals(jobSibling.getJobId())) jobSibling.cancel(); } } return received.size() == SPLIT_COUNT ? ComputeJobResultPolicy.REDUCE : ComputeJobResultPolicy.WAIT; }
/** {@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; } }
", jobId=" + cntx.getJobId() + ", attrs=" + attrs + ", nodeId=" + ignite.configuration().getNodeId() + "]";
jr.getJobContext().getJobId(), null, null, null, null, null, null, false, null);
ctx.job().cancelJob(ses.getId(), res.getJobContext().getJobId(), /*courtesy*/true); else { try { ctx.io().sendToGridTopic(node, TOPIC_JOB_CANCEL, new GridJobCancelRequest(ses.getId(), res.getJobContext().getJobId(), /*courtesy*/true), PUBLIC_POOL); U.error(log, "Failed to send cancel request to node (will ignore) [nodeId=" + nodeId + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']', e);
/** * @param jobRes Job result. */ private void sendFailoverRequest(GridJobResultImpl jobRes) { // Internal failover notification. evtLsnr.onJobFailover(this, jobRes.getSibling(), jobRes.getNode().id()); long timeout = ses.getEndTime() - U.currentTimeMillis(); if (timeout > 0) { recordJobEvent(EVT_JOB_FAILED_OVER, jobRes.getJobContext().getJobId(), jobRes.getNode(), FAILOVER, "Job failed over."); // Send new reference to remote nodes for execution. sendRequest(jobRes); } else // Don't apply 'finishTask(..)' here as it will // be called from 'onTimeout(..)' callback. U.warn(log, "Failed to fail-over job due to task timeout: " + jobRes); }
IgniteUuid jobId = jobCtx.getJobId();
/** {@inheritDoc} */ @Override public void onCollision(CollisionContext ctx) { Collection<CollisionJobContext> waitJobs = ctx.waitingJobs(); for (CollisionJobContext job : waitJobs) { IgniteUuid jobId = job.getJobContext().getJobId(); try { job.getTaskSession().setAttribute(jobId, "test-" + jobId); if (log.isInfoEnabled()) log.info("Set session attribute for job: " + jobId); } catch (IgniteException e) { log.error("Failed to set session attribute: " + job, e); } job.activate(); } } }
recordJobEvent(EVT_JOB_RESULTED, jobRes.getJobContext().getJobId(), jobRes.getNode(), plc, "Job got resulted with: " + plc);
/** {@inheritDoc} */ @Override public Serializable execute() { WaitAttributeType m = argument(0); checkSessionAttributes(taskSes, "fut", m); IgniteUuid jobId = jobCtx.getJobId(); for (int i = 0; i < ATTR_NUM; i ++) { String key = createKey(jobId.toString(), m, i); String val = createValue(jobId.toString(), m, i); taskSes.setAttribute(key, val); } // Check that attributes just set are present. checkSessionAttributes(taskSes, jobId.toString(), m); Collection<ComputeJobSibling> siblings = taskSes.getJobSiblings(); if (log.isInfoEnabled()) log.info("Got siblings from job [size=" + siblings.size() + ", siblings=" + siblings + ']'); // Check attributes from siblings. for (ComputeJobSibling sibling : taskSes.getJobSiblings()) { if (!sibling.getJobId().equals(jobId)) checkSessionAttributes(taskSes, sibling.getJobId().toString(), m); } try { taskSes.waitForAttribute("done", true, 0); } catch (InterruptedException e) { throw new IgniteException("Got interrupted while waiting for 'done' attribute.", e); } return null; } }
U.warn(log, "Failed to send job request because remote node left grid (if fail-over is enabled, " + "will attempt fail-over to another node) [node=" + node + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); res.getJobContext().getJobId(), null, null, null, null, null, null, false, null); res.getJobContext().getJobId(), ses.getTaskName(), ses.getUserVersion(), U.warn(log, "Failed to send job request because remote node left grid (if failover is enabled, " + "will attempt fail-over to another node) [node=" + node + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); log.debug("Failed to send job request, client disconnected [node=" + node + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); res.getJobContext().getJobId(), null, null, null, null, null, null, false, null);
/** * @param jobRes Job result. */ private void sendFailoverRequest(GridJobResultImpl jobRes) { // Internal failover notification. evtLsnr.onJobFailover(this, jobRes.getSibling(), jobRes.getNode().id()); long timeout = ses.getEndTime() - U.currentTimeMillis(); if (timeout > 0) { recordJobEvent(EVT_JOB_FAILED_OVER, jobRes.getJobContext().getJobId(), jobRes.getNode(), FAILOVER, "Job failed over."); // Send new reference to remote nodes for execution. sendRequest(jobRes); } else // Don't apply 'finishTask(..)' here as it will // be called from 'onTimeout(..)' callback. U.warn(log, "Failed to fail-over job due to task timeout: " + jobRes); }