Search in sources :

Example 1 with GridifyJobAdapter

use of org.apache.ignite.internal.util.gridify.GridifyJobAdapter in project ignite by apache.

the class GridifyDefaultRangeTask method map.

/** {@inheritDoc} */
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, GridifyRangeArgument arg) {
    assert !subgrid.isEmpty() : "Subgrid should not be empty: " + subgrid;
    assert ignite != null : "Grid instance could not be injected";
    if (splitSize < threshold && splitSize != 0 && threshold != 0) {
        throw new IgniteException("Incorrect Gridify annotation parameters. Value for parameter " + "'splitSize' should not be less than parameter 'threshold' [splitSize=" + splitSize + ", threshold=" + threshold + ']');
    }
    Collection<ClusterNode> exclNodes = new LinkedList<>();
    // Filter nodes.
    if (nodeFilter != null) {
        for (ClusterNode node : subgrid) {
            if (!nodeFilter.apply(node, ses))
                exclNodes.add(node);
        }
        if (exclNodes.size() == subgrid.size())
            throw new IgniteException("Failed to execute on grid where all nodes excluded.");
    }
    int inputPerNode = splitSize;
    // Calculate input elements size per node for default annotation splitSize parameter.
    if (splitSize <= 0) {
        // For iterable input splitSize will be assigned with threshold value.
        if (threshold > 0 && arg.getInputSize() == UNKNOWN_SIZE)
            inputPerNode = threshold;
        else // Otherwise, splitSize equals (inputSize / nodesCount)
        {
            assert arg.getInputSize() != UNKNOWN_SIZE;
            int gridSize = subgrid.size() - exclNodes.size();
            gridSize = (gridSize <= 0 ? subgrid.size() : gridSize);
            inputPerNode = calculateInputSizePerNode(gridSize, arg.getInputSize(), threshold, limitedSplit);
            if (log.isDebugEnabled()) {
                log.debug("Calculated input elements size per node [inputSize=" + arg.getInputSize() + ", gridSize=" + gridSize + ", threshold=" + threshold + ", limitedSplit=" + limitedSplit + ", inputPerNode=" + inputPerNode + ']');
            }
        }
    }
    GridifyArgumentBuilder argBuilder = new GridifyArgumentBuilder();
    Iterator<?> inputIter = arg.getInputIterator();
    while (inputIter.hasNext()) {
        Collection<Object> nodeInput = new LinkedList<>();
        for (int i = 0; i < inputPerNode && inputIter.hasNext(); i++) nodeInput.add(inputIter.next());
        // Create job argument.
        GridifyArgument jobArg = argBuilder.createJobArgument(arg, nodeInput);
        ComputeJob job = new GridifyJobAdapter(jobArg);
        mapper.send(job, balancer.getBalancedNode(job, exclNodes));
    }
    // Map method can return null because job already sent by continuous mapper.
    return null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridifyArgument(org.apache.ignite.compute.gridify.GridifyArgument) ComputeJob(org.apache.ignite.compute.ComputeJob) IgniteException(org.apache.ignite.IgniteException) GridifyJobAdapter(org.apache.ignite.internal.util.gridify.GridifyJobAdapter) GridifyArgumentBuilder(org.apache.ignite.internal.util.gridify.GridifyArgumentBuilder) LinkedList(java.util.LinkedList)

Example 2 with GridifyJobAdapter

use of org.apache.ignite.internal.util.gridify.GridifyJobAdapter in project ignite by apache.

the class GridifyDefaultTask method map.

/** {@inheritDoc} */
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, GridifyArgument arg) {
    assert !subgrid.isEmpty() : "Subgrid should not be empty: " + subgrid;
    assert ignite != null : "Grid instance could not be injected";
    assert balancer != null : "Load balancer could not be injected";
    ComputeJob job = new GridifyJobAdapter(arg);
    ClusterNode node = balancer.getBalancedNode(job, Collections.<ClusterNode>singletonList(ignite.cluster().localNode()));
    if (node != null) {
        // Give preference to remote nodes.
        return Collections.singletonMap(job, node);
    }
    return Collections.singletonMap(job, balancer.getBalancedNode(job, null));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ComputeJob(org.apache.ignite.compute.ComputeJob) GridifyJobAdapter(org.apache.ignite.internal.util.gridify.GridifyJobAdapter)

Aggregations

ClusterNode (org.apache.ignite.cluster.ClusterNode)2 ComputeJob (org.apache.ignite.compute.ComputeJob)2 GridifyJobAdapter (org.apache.ignite.internal.util.gridify.GridifyJobAdapter)2 LinkedList (java.util.LinkedList)1 IgniteException (org.apache.ignite.IgniteException)1 GridifyArgument (org.apache.ignite.compute.gridify.GridifyArgument)1 GridifyArgumentBuilder (org.apache.ignite.internal.util.gridify.GridifyArgumentBuilder)1