Commit 5e509a89 authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Add selection script for nodes acquirement tasks

parent cea6ff7f
......@@ -22,6 +22,8 @@ import org.ow2.proactive.scheduler.common.job.TaskFlowJob;
import org.ow2.proactive.scheduler.common.task.ScriptTask;
import org.ow2.proactive.scheduler.common.task.TaskResult;
import org.ow2.proactive.scheduler.common.task.TaskVariable;
import org.ow2.proactive.scripting.InvalidScriptException;
import org.ow2.proactive.scripting.SelectionScript;
import org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException;
import org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException;
......@@ -898,7 +900,7 @@ public class PAGateway {
try {
nodeConfigJson += "\", \"portsToOpen\": " + mapper.writeValueAsString(task.getPortsToOpen()) + "}";
} catch (IOException e) {
LOGGER.error(String.valueOf(e.getStackTrace()));
LOGGER.error(Arrays.toString(e.getStackTrace()));
}
}
variablesMap.put("nodeConfigJson", new TaskVariable("nodeConfigJson", nodeConfigJson, "PA:JSON", false));
......@@ -906,6 +908,18 @@ public class PAGateway {
LOGGER.debug("Variables to be added to the task: " + variablesMap.toString());
deployNodeTask.setVariables(variablesMap);
try {
String selectionScriptFileName = "check_node_source_regexp.groovy";
String[] nodeSourceNameRegex = {"^local$|^Default$"};
SelectionScript selectionScript = new SelectionScript(Utils.getContentWithFileName(selectionScriptFileName),
"groovy",
nodeSourceNameRegex,
true);
deployNodeTask.setSelectionScript(selectionScript);
} catch (InvalidScriptException e) {
LOGGER.warn("Selection script could not have been added.");
}
return deployNodeTask;
}
......
/**
* Script which verifies that the current node runs in a node source which matches the specified regular expression
*
* Arguments:
* node source name (regexp)
*/
import com.google.common.base.Strings
import java.util.regex.Pattern;
if (args.length != 1) {
println "Incorrect number of arguments, expected 1, received " + args.length;
selected = false;
return;
}
nodeSourceName = args[0]
if (Strings.isNullOrEmpty(nodeSourceName)) {
println "Given node source name was empty";
selected = false;
return;
}
nodeSourceName = nodeSourceName.trim()
vmPropValue = System.getProperty("proactive.node.nodesource");
if (vmPropValue == null) {
// if the node source property is not defined, set it as "Default"
vmPropValue = "Default";
}
println "Value of property " + "proactive.node.nodesource" + ": " + vmPropValue + " (expected : " + nodeSourceName + ")";
regex = Pattern.compile(nodeSourceName, Pattern.CASE_INSENSITIVE);
regexMatcher = regex.matcher(vmPropValue);
selected = regexMatcher.find()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment