Search in sources :

Example 26 with Script

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();
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) PrintStream(java.io.PrintStream) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 27 with Script

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;
}
Also used : Script(org.ow2.proactive.scripting.Script) SignalApiImpl(org.ow2.proactive.scheduler.signal.SignalApiImpl) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) SynchronizationWrapper(org.ow2.proactive.scheduler.synchronization.SynchronizationWrapper)

Example 28 with Script

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);
            }
        }
    }
}
Also used : File(java.io.File) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) NodeException(org.objectweb.proactive.core.node.NodeException) ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException) IOException(java.io.IOException)

Example 29 with Script

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);
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)

Example 30 with Script

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);
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface)

Aggregations

Test (org.junit.Test)46 SelectionScript (org.ow2.proactive.scripting.SelectionScript)40 File (java.io.File)38 SimpleScript (org.ow2.proactive.scripting.SimpleScript)33 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)27 ScriptResult (org.ow2.proactive.scripting.ScriptResult)21 IOException (java.io.IOException)18 HashMap (java.util.HashMap)18 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)16 Script (org.ow2.proactive.scripting.Script)16 JobId (org.ow2.proactive.scheduler.common.job.JobId)13 FlowScript (org.ow2.proactive.scheduler.common.task.flow.FlowScript)13 ArrayList (java.util.ArrayList)12 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)12 Serializable (java.io.Serializable)11 TaskScript (org.ow2.proactive.scripting.TaskScript)11 NodeSet (org.ow2.proactive.utils.NodeSet)11 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)10 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)10 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)9