Search in sources :

Example 31 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class SchedulingTaskComparator method computeHashForSelectionScripts.

private void computeHashForSelectionScripts(InternalTask task, InternalJob job) {
    List<SelectionScript> scriptList = SchedulingMethodImpl.resolveScriptVariables(task.getSelectionScripts(), task.getRuntimeVariables());
    for (SelectionScript script : scriptList) {
        SelectionScript modifiedScript = script;
        try {
            Map<String, Serializable> bindings = SchedulingMethodImpl.createBindingsForSelectionScripts(job, task);
            modifiedScript = SchedulingMethodImpl.replaceBindingsInsideScript(script, bindings);
        } catch (Exception e) {
            logger.error("Error while replacing selection script bindings for task " + task.getId(), e);
        }
        try {
            digests.add(new String(modifiedScript.digest()));
        } catch (Exception e) {
            logger.error("Error while replacing selection script bindings for task " + task.getId(), e);
        }
    }
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) Serializable(java.io.Serializable)

Example 32 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class TerminationData method terminateRunningTask.

private void terminateRunningTask(SchedulingService service, TaskTerminationData taskToTerminate, RunningTaskData taskData) {
    Map<String, String> genericInformation = new HashMap<>();
    VariablesMap variables = null;
    if (taskToTerminate.internalJob != null) {
        genericInformation = taskData.getTask().getRuntimeGenericInformation();
    }
    try {
        variables = getStringSerializableMap(service, taskToTerminate);
    } catch (Exception e) {
        logger.error("Exception occurred, fail to get variables into the cleaning script: ", e);
    }
    try {
        if (taskToTerminate.terminationStatus == ABORTED) {
            taskData.getLauncher().kill();
        }
    } catch (Throwable t) {
        logger.info("Cannot terminate task launcher for task '" + taskData.getTask().getId() + "'", t);
        try {
            logger.info("Task launcher that cannot be terminated is identified by " + taskData.getLauncher().toString());
        } catch (Throwable ignore) {
            logger.info("Getting information about Task launcher failed (remote object not accessible?)");
        }
    }
    try {
        logger.debug("Releasing nodes for task '" + taskData.getTask().getId() + "'");
        RMProxiesManager proxiesManager = service.getInfrastructure().getRMProxiesManager();
        proxiesManager.getUserRMProxy(taskData.getUser(), taskData.getCredentials()).releaseNodes(taskData.getNodes(), taskToTerminate.terminationStatus != NODEFAILED ? taskData.getTask().getCleaningScript() : null, variables, genericInformation, taskToTerminate.taskData.getTask().getId(), service.addThirdPartyCredentials(taskData.getCredentials()));
    } catch (Throwable t) {
        logger.info("Failed to release nodes for task '" + taskData.getTask().getId() + "'", t);
    }
}
Also used : HashMap(java.util.HashMap) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) IOException(java.io.IOException) RMProxiesManager(org.ow2.proactive.scheduler.core.rmproxies.RMProxiesManager)

Example 33 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class RMProxyActiveObject method printCleaningScriptInformations.

private void printCleaningScriptInformations(NodeSet nodes, ScriptResult<?> sResult, TaskId taskId) {
    if (logger.isInfoEnabled()) {
        TaskLogger instance = TaskLogger.getInstance();
        String nodeUrl = nodes.get(0).getNodeInformation().getURL();
        if (sResult.errorOccured()) {
            instance.error(taskId, "Exception while running cleaning script on " + nodeUrl, sResult.getException());
        } else {
            instance.info(taskId, "Cleaning script successful.");
        }
        if (sResult.getOutput() != null && !sResult.getOutput().isEmpty()) {
            instance.info(taskId, "Cleaning script output on node " + nodeUrl + ":");
            instance.info(taskId, sResult.getOutput());
        }
    }
}
Also used : TaskLogger(org.ow2.proactive.scheduler.util.TaskLogger)

Example 34 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class RMProxyActiveObject method handleCleaningScript.

/**
 * Execute the given script on the given node.
 * Also register a callback on {@link #cleanCallBack(Future, NodeSet)} method when script has returned.
 * @param nodes           the nodeset on which to start the script
 * @param cleaningScript the script to be executed
 * @param variables
 * @param genericInformation
 * @param taskId
 * @param creds credentials with CredData containing third party credentials
 */
private void handleCleaningScript(NodeSet nodes, Script<?> cleaningScript, VariablesMap variables, Map<String, String> genericInformation, TaskId taskId, Credentials creds) {
    TaskLogger instance = TaskLogger.getInstance();
    try {
        this.nodesTaskId.put(nodes, taskId);
        // create a decrypter to access scheduler and retrieve Third Party User Credentials
        String privateKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PRIVKEY_PATH.getValueAsString());
        Decrypter decrypter = new Decrypter(Credentials.getPrivateKey(privateKeyPath));
        decrypter.setCredentials(creds);
        HashMap<String, Serializable> dictionary = new HashMap<>();
        dictionary.putAll(variables.getScriptMap());
        dictionary.putAll(variables.getInheritedMap());
        dictionary.putAll(variables.getPropagatedVariables());
        dictionary.putAll(variables.getScopeMap());
        // start handler for binding
        ScriptHandler handler = ScriptLoader.createHandler(nodes.get(0));
        VariablesMap resolvedMap = new VariablesMap();
        resolvedMap.setInheritedMap(VariableSubstitutor.resolveVariables(variables.getInheritedMap(), dictionary));
        resolvedMap.setScopeMap(VariableSubstitutor.resolveVariables(variables.getScopeMap(), dictionary));
        handler.addBinding(SchedulerConstants.VARIABLES_BINDING_NAME, (Serializable) resolvedMap);
        handler.addBinding(SchedulerConstants.GENERIC_INFO_BINDING_NAME, (Serializable) genericInformation);
        // retrieve scheduler URL to bind with schedulerapi, globalspaceapi, and userspaceapi
        String schedulerUrl = PASchedulerProperties.SCHEDULER_REST_URL.getValueAsString();
        logger.debug("Binding schedulerapi...");
        SchedulerNodeClient client = new SchedulerNodeClient(decrypter, schedulerUrl);
        handler.addBinding(SchedulerConstants.SCHEDULER_CLIENT_BINDING_NAME, (Serializable) client);
        logger.debug("Binding globalspaceapi...");
        RemoteSpace globalSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.GLOBAL, schedulerUrl);
        handler.addBinding(SchedulerConstants.DS_GLOBAL_API_BINDING_NAME, (Serializable) globalSpaceClient);
        logger.debug("Binding userspaceapi...");
        RemoteSpace userSpaceClient = new DataSpaceNodeClient(client, IDataSpaceClient.Dataspace.USER, schedulerUrl);
        handler.addBinding(SchedulerConstants.DS_USER_API_BINDING_NAME, (Serializable) userSpaceClient);
        logger.debug("Binding credentials...");
        Map<String, String> resolvedThirdPartyCredentials = VariableSubstitutor.filterAndUpdate(decrypter.decrypt().getThirdPartyCredentials(), dictionary);
        handler.addBinding(SchedulerConstants.CREDENTIALS_VARIABLE, (Serializable) resolvedThirdPartyCredentials);
        ScriptResult<?> future = handler.handle(cleaningScript);
        try {
            PAEventProgramming.addActionOnFuture(future, "cleanCallBack", nodes);
        } catch (IllegalArgumentException e) {
            // TODO - linked to PROACTIVE-936 -> IllegalArgumentException is raised if method name is unknown
            // should be replaced by checked exception
            instance.error(taskId, "ERROR : Callback method won't be executed, node won't be released. This is a critical state, check the callback method name", e);
        }
        instance.info(taskId, "Cleaning Script started on node " + nodes.get(0).getNodeInformation().getURL());
    } catch (Exception e) {
        // if active object cannot be created or script has failed
        instance.error(taskId, "Error while starting cleaning script for task " + taskId + " on " + nodes.get(0), e);
        releaseNodes(nodes).booleanValue();
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SchedulerNodeClient(org.ow2.proactive.scheduler.task.client.SchedulerNodeClient) Decrypter(org.ow2.proactive.scheduler.task.utils.Decrypter) LoginException(javax.security.auth.login.LoginException) TaskLogger(org.ow2.proactive.scheduler.util.TaskLogger) RemoteSpace(org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) DataSpaceNodeClient(org.ow2.proactive.scheduler.task.client.DataSpaceNodeClient) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 35 with Script

use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.

the class InternalScriptTask method display.

@Override
public String display() {
    String nl = System.lineSeparator();
    String answer = super.display();
    Script tscript = ((ScriptExecutableContainer) executableContainer).getScript();
    return answer + nl + "\tScript = " + ((tscript != null) ? tscript.display() : null);
}
Also used : Script(org.ow2.proactive.scripting.Script) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)

Aggregations

Test (org.junit.Test)38 SelectionScript (org.ow2.proactive.scripting.SelectionScript)32 File (java.io.File)31 SimpleScript (org.ow2.proactive.scripting.SimpleScript)28 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)25 ArrayList (java.util.ArrayList)16 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)15 Script (org.ow2.proactive.scripting.Script)15 ScriptResult (org.ow2.proactive.scripting.ScriptResult)15 FlowScript (org.ow2.proactive.scheduler.common.task.flow.FlowScript)13 HashMap (java.util.HashMap)12 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)11 IOException (java.io.IOException)10 JobId (org.ow2.proactive.scheduler.common.job.JobId)10 NodeSet (org.ow2.proactive.utils.NodeSet)10 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)9 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)9 Job (org.ow2.proactive.scheduler.common.job.Job)8 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)8 Serializable (java.io.Serializable)7