/** {@inheritDoc} */ @Override public GridNode getBalancedNode(GridComputeTaskSession ses, List<GridNode> top, GridComputeJob job) throws GridException { A.notNull(ses, "ses", top, "top"); if (isPerTask) { // Note that every session operates from single thread which // allows us to use concurrent map and avoid synchronization. GridRoundRobinPerTaskLoadBalancer taskBalancer = perTaskBalancers.get(ses.getId()); if (taskBalancer == null) perTaskBalancers.put(ses.getId(), taskBalancer = new GridRoundRobinPerTaskLoadBalancer()); return taskBalancer.getBalancedNode(top); } return balancer.getBalancedNode(top); }
/** * THIS METHOD IS USED ONLY FOR TESTING. * * @param ses Task session. * @return Internal list of nodes. */ List<UUID> getNodeIds(GridComputeTaskSession ses) { if (isPerTask) { GridRoundRobinPerTaskLoadBalancer balancer = perTaskBalancers.get(ses.getId()); if (balancer == null) return Collections.emptyList(); List<UUID> ids = new ArrayList<>(); for (GridNode node : balancer.getNodes()) { ids.add(node.id()); } return ids; } return balancer.getNodeIds(); }
/** {@inheritDoc} */ @Override public GridNode getBalancedNode(GridComputeTaskSession ses, List<GridNode> top, GridComputeJob job) { A.notNull(ses, "ses"); A.notNull(top, "top"); A.notNull(job, "job"); // Optimization for non-weighted randomization. if (!isUseWeights) return top.get(RAND.nextInt(top.size())); GridBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(ses.getId()); // Create new cached topology if there is no one. Do not // use cached topology after task has been mapped. if (weightedTop == null) { // Called from GridComputeTask#map(). Put new topology and false as not mapped yet. taskTops.put(ses.getId(), weightedTop = F.t(false, new WeightedTopology(top))); } // We have topology - check if task has been mapped. else if (weightedTop.get1()) { // Do not use cache after GridComputeTask#map(). return new WeightedTopology(top).pickWeightedNode(); } return weightedTop.get2().pickWeightedNode(); }
/** {@inheritDoc} */ @Override public GridNode getBalancedNode(GridComputeTaskSession ses, List<GridNode> top, GridComputeJob job) throws GridException { A.notNull(ses, "ses"); A.notNull(top, "top"); A.notNull(job, "job"); GridBiTuple<Boolean, WeightedTopology> weightedTop = taskTops.get(ses.getId()); // Create new cached topology if there is no one. Do not // use cached topology after task has been mapped. if (weightedTop == null) // Called from GridComputeTask#map(). Put new topology and false as not mapped yet. taskTops.put(ses.getId(), weightedTop = F.t(false, new WeightedTopology(top))); // We have topology - check if task has been mapped. else if (weightedTop.get1()) // Do not use cache after GridComputeTask#map(). return new WeightedTopology(top).pickWeightedNode(); return weightedTop.get2().pickWeightedNode(); }
/** {@inheritDoc} */ @Override public GridNode failover(GridFailoverContext ctx, List<GridNode> top) { U.warn(log, "Returning 'null' node for failed job (failover will not happen) [job=" + ctx.getJobResult().getJob() + ", task=" + ctx.getTaskSession().getTaskName() + ", sessionId=" + ctx.getTaskSession().getId() + ']'); return null; }
/** * Cancel task on master leave event. Does not send cancel request to remote jobs and invokes master-leave * callback on local jobs. * * @return {@code True} if future was cancelled (i.e. was not finished prior to this call). * @throws GridException If failed. */ public boolean cancelOnMasterLeave() throws GridException { checkValid(); if (onCancelled()) { // Invoke master-leave callback on spawned jobs on local node and then cancel them. for (GridNode node : ctx.discovery().nodes(ses.getTopology())) { if (ctx.localNodeId().equals(node.id())) { ctx.job().masterLeaveLocal(ses.getId()); ctx.job().cancelJob(ses.getId(), null, false); } } return true; } return isCancelled(); }
/** {@inheritDoc} */ @Override public boolean cancel() throws GridException { ctx.security().authorize(ses.getTaskName(), GridSecurityPermission.TASK_CANCEL, null); checkValid(); if (onCancelled()) { ctx.task().onCancelled(ses.getId()); return true; } return isCancelled(); }
U.warn(log, "Failed over job to a new node [newNode=" + node.id() + ", oldNode=" + ctx.getJobResult().getNode().id() + ", sesId=" + ctx.getTaskSession().getId() + ", job=" + ctx.getJobResult().getJob() + ", jobCtx=" + ctx.getJobResult().getJobContext() +
U.warn(log, "Failed over job to a new node [newNode=" + thief.id() + ", oldNode=" + ctx.getJobResult().getNode().id() + ", sesId=" + ctx.getTaskSession().getId() + ", job=" + ctx.getJobResult().getJob() + ", jobCtx=" + ctx.getJobResult().getJobContext() + log.info("Stealing job to a new node [newNode=" + thief.id() + ", oldNode=" + ctx.getJobResult().getNode().id() + ", sesId=" + ctx.getTaskSession().getId() + ", job=" + ctx.getJobResult().getJob() + ", jobCtx=" + ctx.getJobResult().getJobContext() +
assert taskFut instanceof GridComputeTaskFuture; GridUuid tid = ((GridComputeTaskFuture)taskFut).getTaskSession().getId();
assert taskFut instanceof GridComputeTaskFuture; GridUuid tid = ((GridComputeTaskFuture)taskFut).getTaskSession().getId();