/** {@inheritDoc} */
  @Nullable
  @Override
  public Map<? extends GridComputeJob, GridNode> map(
      List<GridNode> subgrid, @Nullable GridBiTuple<Set<UUID>, A> arg) throws GridException {
    assert arg != null;
    assert arg.get1() != null;

    start = U.currentTimeMillis();

    boolean debug = debugState(g);

    if (debug) logStart(g.log(), getClass(), start);

    Set<UUID> nodeIds = arg.get1();

    Map<GridComputeJob, GridNode> map = U.newHashMap(nodeIds.size());

    try {
      taskArg = arg.get2();

      for (GridNode node : subgrid) if (nodeIds.contains(node.id())) map.put(job(taskArg), node);

      return map;
    } finally {
      if (debug) logMapped(g.log(), getClass(), map.values());
    }
  }
  /**
   * Maps list by node ID.
   *
   * @param subgrid Subgrid.
   * @return Map.
   */
  private Map<UUID, GridNode> mapSubgrid(Collection<GridNode> subgrid) {
    Map<UUID, GridNode> res = U.newHashMap(subgrid.size());

    for (GridNode node : subgrid) res.put(node.id(), node);

    return res;
  }
Exemple #3
0
    /** {@inheritDoc} */
    @Override
    public Map<? extends GridComputeJob, GridNode> map(List<GridNode> subgrid, String arg)
        throws GridException {
      assert locNodeId != null;

      if (log.isInfoEnabled()) {
        log.info("Mapping jobs [subgrid=" + subgrid + ", arg=" + arg + ']');
      }

      GridNode remoteNode = null;

      for (GridNode node : subgrid) {
        if (!node.id().equals(locNodeId)) {
          remoteNode = node;
        }
      }

      return Collections.singletonMap(
          new GridComputeJobAdapter(locNodeId) {
            /** */
            @GridLocalNodeIdResource private UUID nodeId;

            /** {@inheritDoc} */
            @SuppressWarnings("NakedNotify")
            @Override
            public Serializable execute() throws GridException {
              assert nodeId != null;

              if (!nodeId.equals(argument(0))) {
                try {
                  synchronized (mux) {
                    mux.notifyAll();
                  }

                  Thread.sleep(Integer.MAX_VALUE);
                } catch (InterruptedException e) {
                  throw new GridComputeExecutionRejectedException(
                      "Expected interruption during execution.", e);
                }
              } else {
                return "success";
              }

              throw new GridComputeExecutionRejectedException(
                  "Expected exception during execution.");
            }
          },
          remoteNode);
    }
  /** {@inheritDoc} */
  @Override
  public Map<? extends GridComputeJob, GridNode> map(List<GridNode> subgrid, Integer arg)
      throws GridException {
    assert taskSes != null;
    assert arg != null;
    assert arg > 0;

    Map<GridSessionLoadTestJob, GridNode> map = new HashMap<>(subgrid.size());

    Iterator<GridNode> iter = subgrid.iterator();

    Random rnd = new Random();

    params = new HashMap<>(arg);

    Collection<UUID> assigned = new ArrayList<>(subgrid.size());

    for (int i = 0; i < arg; i++) {
      // Recycle iterator.
      if (!iter.hasNext()) iter = subgrid.iterator();

      String paramName = UUID.randomUUID().toString();

      int paramVal = rnd.nextInt();

      taskSes.setAttribute(paramName, paramVal);

      GridNode node = iter.next();

      assigned.add(node.id());

      map.put(new GridSessionLoadTestJob(paramName), node);

      params.put(paramName, paramVal);

      if (log.isDebugEnabled())
        log.debug("Set session attribute [name=" + paramName + ", value=" + paramVal + ']');
    }

    taskSes.setAttribute("nodes", assigned);

    return map;
  }