use of org.ow2.proactive.scripting.Script in project scheduling by ow2-proactive.
the class SchedulerStarter method executeStartScripts.
private static void executeStartScripts() throws InvalidScriptException, IOException {
// Nothing to do if no script path is specified
if (!PASchedulerProperties.SCHEDULER_STARTSCRIPTS_PATHS.isSet())
return;
// Retrieve the start scripts paths
List<String> scriptsPaths = PASchedulerProperties.SCHEDULER_STARTSCRIPTS_PATHS.getValueAsList(";");
// Scripts binding
ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
scriptHandler.addBindings(PASchedulerProperties.getPropertiesAsHashMap());
scriptHandler.addBindings(PAResourceManagerProperties.getPropertiesAsHashMap());
scriptHandler.addBindings(WebProperties.getPropertiesAsHashMap());
// Execute all the listed scripts
ByteArrayOutputStream os = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(os, true);
ScriptResult scriptResult;
File scriptFile;
for (String scriptPath : scriptsPaths) {
scriptFile = new File(PASchedulerProperties.getAbsolutePath(scriptPath));
if (scriptFile.exists()) {
scriptResult = scriptHandler.handle(new SimpleScript(scriptFile, new String[0]), ps, ps);
if (scriptResult.errorOccured()) {
// Close streams before throwing
os.close();
ps.close();
throw new InvalidScriptException("Failed to execute script: " + scriptResult.getException().getMessage(), scriptResult.getException());
}
LOGGER.info(os.toString());
os.reset();
} else
LOGGER.warn("Start script " + scriptPath + " not found");
}
// Close streams
os.close();
ps.close();
}
use of org.ow2.proactive.scripting.Script in project scheduling by ow2-proactive.
the class InternalTask method getDefaultTaskLauncherInitializer.
/**
* Prepare and return the default task launcher initializer (ie the one that works for every launcher)<br>
* Concrete launcher may have to add values to the created initializer to bring more information to the launcher.
*
* @return the default created task launcher initializer
*/
protected TaskLauncherInitializer getDefaultTaskLauncherInitializer(String sessionid) throws IOException {
TaskLauncherInitializer tli = new TaskLauncherInitializer();
tli.setTaskId(getId());
tli.setJobOwner(internalJob.getJobInfo().getJobOwner());
tli.setSchedulerRestUrl(PASchedulerProperties.SCHEDULER_REST_URL.getValueAsStringOrNull());
tli.setCatalogRestUrl(PASchedulerProperties.CATALOG_REST_URL.getValueAsStringOrNull());
tli.setCloudAutomationRestUrl(PASchedulerProperties.CLOUD_AUTOMATION_REST_URL.getValueAsStringOrNull());
tli.setJobPlannerRestUrl(PASchedulerProperties.JOB_PLANNER_REST_URL.getValueAsStringOrNull());
tli.setNotificationServiceRestUrl(PASchedulerProperties.NOTIFICATION_SERVICE_REST_URL.getValueAsStringOrNull());
tli.setSchedulerRestPublicUrl(PASchedulerProperties.SCHEDULER_REST_PUBLIC_URL.getValueAsStringOrNull());
tli.setCatalogRestPublicUrl(PASchedulerProperties.CATALOG_REST_PUBLIC_URL.getValueAsStringOrNull());
tli.setCloudAutomationRestPublicUrl(PASchedulerProperties.CLOUD_AUTOMATION_REST_PUBLIC_URL.getValueAsStringOrNull());
tli.setJobPlannerRestPublicUrl(PASchedulerProperties.JOB_PLANNER_REST_PUBLIC_URL.getValueAsStringOrNull());
tli.setNotificationServiceRestPublicUrl(PASchedulerProperties.NOTIFICATION_SERVICE_REST_PUBLIC_URL.getValueAsStringOrNull());
if (getPreScript() != null) {
tli.setPreScript(getPreScript());
tli.getPreScript().setSessionid(sessionid);
}
if (getPostScript() != null) {
tli.setPostScript(getPostScript());
tli.getPostScript().setSessionid(sessionid);
}
if (getFlowScript() != null) {
tli.setControlFlowScript(getFlowScript());
tli.getControlFlowScript().setSessionid(sessionid);
}
tli.setTaskInputFiles(getInputFilesList());
tli.setTaskOutputFiles(getOutputFilesList());
tli.setNamingService(internalJob.getTaskDataSpaceApplications().get(getId().longValue()).getNamingServiceStub());
tli.setIterationIndex(getIterationIndex());
tli.setReplicationIndex(getReplicationIndex());
Map<String, String> gInfo = getRuntimeGenericInformation();
tli.setGenericInformation(gInfo);
tli.setGlobalGenericInformation(internalJob.getGlobalGenericInformation());
ForkEnvironment environment = getForkEnvironment();
if (environment != null) {
Script environmentScript = environment.getEnvScript();
if ((environmentScript != null) && !isScriptAuthorized(getId(), environmentScript)) {
tli.setAuthorizedForkEnvironmentScript(false);
}
}
tli.setForkEnvironment(environment);
if (tli.getForkEnvironment() != null && tli.getForkEnvironment().getEnvScript() != null) {
tli.getForkEnvironment().getEnvScript().setSessionid(sessionid);
}
if (isWallTimeSet()) {
tli.setWalltime(getRuntimeWallTime());
}
tli.setPreciousLogs(isPreciousLogs());
tli.setJobVariables(internalJob.getVariables());
tli.setGlobalVariables(internalJob.getGlobalVariables());
tli.setTaskVariables(getVariables());
tli.setPingPeriod(PASchedulerProperties.SCHEDULER_NODE_PING_FREQUENCY.getValueAsInt());
tli.setPingAttempts(PASchedulerProperties.SCHEDULER_NODE_PING_ATTEMPTS.getValueAsInt());
tli.setSynchronizationAPI(new SynchronizationWrapper(internalJob.getOwner(), getId(), internalJob.getSynchronizationAPI()));
tli.setSignalAPI(new SignalApiImpl(internalJob.getOwner(), getId(), internalJob.getSynchronizationAPI()));
return tli;
}
use of org.ow2.proactive.scripting.Script in project scheduling by ow2-proactive.
the class InternalTask method loadAuthorizedScriptsSignatures.
private static void loadAuthorizedScriptsSignatures(TaskId id, File folder) {
authorizedSelectionScripts = new HashSet<>();
for (File file : folder.listFiles()) {
if (file.isFile()) {
try {
String script = Script.readFile(file);
logger.debug(id, "Adding authorized script " + file.getAbsolutePath());
authorizedSelectionScripts.add(Script.digest(script.trim()));
} catch (Exception e) {
logger.error(id, e.getMessage(), e);
}
}
}
}
use of org.ow2.proactive.scripting.Script in project scheduling by ow2-proactive.
the class RMRest method executeNodeScript.
@Override
public ScriptResult<Object> executeNodeScript(String sessionId, String nodeUrl, String script, String scriptEngine) throws Throwable {
RMProxyUserInterface rm = checkAccess(sessionId);
List<ScriptResult<Object>> results = orThrowRpe(rm.executeScript(script, scriptEngine, TargetType.NODE_URL.name(), Collections.singleton(nodeUrl)));
checkEmptyScriptResults(results);
return results.get(0);
}
use of org.ow2.proactive.scripting.Script in project scheduling by ow2-proactive.
the class RMRest method executeHostScript.
@Override
public ScriptResult<Object> executeHostScript(String sessionId, String hostname, String script, String scriptEngine) throws Throwable {
RMProxyUserInterface rm = checkAccess(sessionId);
List<ScriptResult<Object>> results = orThrowRpe(rm.executeScript(script, scriptEngine, TargetType.HOSTNAME.name(), Collections.singleton(hostname)));
checkEmptyScriptResults(results);
return results.get(0);
}
Aggregations