Search in sources :

Example 1 with TargetType

use of org.ow2.proactive.resourcemanager.utils.TargetType in project scheduling by ow2-proactive.

the class RMCore method executeScript.

/**
 * {@inheritDoc}
 */
public <T> List<ScriptResult<T>> executeScript(Script<T> script, String targetType, Set<String> targets) {
    // Depending on the target type, select nodes for script execution
    final TargetType tType = TargetType.valueOf(targetType);
    final HashSet<RMNode> selectedRMNodes = new HashSet<>();
    switch(tType) {
        case NODESOURCE_NAME:
            // If target is a nodesource name select all its nodes
            for (String target : targets) {
                NodeSource nodeSource = this.deployedNodeSources.get(target);
                if (nodeSource != null) {
                    for (RMNode candidateNode : this.allNodes.values()) {
                        if (candidateNode.getNodeSource().equals(nodeSource)) {
                            this.selectCandidateNode(selectedRMNodes, candidateNode);
                        }
                    }
                }
            }
            break;
        case NODE_URL:
            // If target is node url select the node
            for (String target : targets) {
                RMNode candidateNode = this.allNodes.get(target);
                if (candidateNode != null) {
                    this.selectCandidateNode(selectedRMNodes, candidateNode);
                }
            }
            break;
        case HOSTNAME:
            // If target is hostname select first node from that host
            for (String target : targets) {
                for (RMNode node : this.allNodes.values()) {
                    if (node.getHostName().equals(target)) {
                        this.selectCandidateNode(selectedRMNodes, node);
                        break;
                    }
                }
            }
            break;
        default:
            throw new IllegalArgumentException("Unable to execute script, unknown target type: " + targetType);
    }
    // Return a ProActive future on the list of results
    return this.selectionManager.executeScript(script, selectedRMNodes, null);
// To avoid blocking rmcore ao the call is delegated to the selection
// manager ao and each node is unlocked as soon as the script has
// finished it's execution.
}
Also used : NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) TargetType(org.ow2.proactive.resourcemanager.utils.TargetType) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)1 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)1 TargetType (org.ow2.proactive.resourcemanager.utils.TargetType)1