Search in sources :

Example 6 with TaskLogger

use of org.ow2.proactive.scheduler.util.TaskLogger 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 7 with TaskLogger

use of org.ow2.proactive.scheduler.util.TaskLogger in project scheduling by ow2-proactive.

the class TaskLoggerTest method createFileAppenderTest.

@Test
public void createFileAppenderTest() throws Exception {
    JobId jobid = new JobIdImpl(1000, "job");
    TaskId taskId = TaskIdImpl.createTaskId(jobid, "task", 42L);
    taskLogger = new TaskLogger(taskId, "myhost");
    File logFolder = tempFolder.newFolder("logfolder");
    File logAppender = taskLogger.createFileAppender(logFolder);
    System.out.println(logAppender.getParentFile().getName());
    assertEquals(logAppender.getParentFile().getName(), jobid.value());
    assertEquals(logAppender.getName(), new TaskLoggerRelativePathGenerator(taskId).getFileName());
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) File(java.io.File) TaskLoggerRelativePathGenerator(org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 8 with TaskLogger

use of org.ow2.proactive.scheduler.util.TaskLogger in project scheduling by ow2-proactive.

the class TaskLoggerTest method multipleRemoveLoggers.

@Test
public void multipleRemoveLoggers() throws Exception {
    List<TaskLogger> loggers = new ArrayList<>(1000);
    for (int i = 0; i < 1000; i++) {
        loggers.add(new TaskLogger(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", i), "myhost"));
    }
    for (int i = 0; i < 1000; i++) {
        loggers.get(i).close();
        assertNull(LogManager.exists(loggers.get(i).getName()));
    }
    assertNull(LogManager.exists(Log4JTaskLogs.getLoggerName("" + 1000)));
}
Also used : ArrayList(java.util.ArrayList) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Example 9 with TaskLogger

use of org.ow2.proactive.scheduler.util.TaskLogger in project scheduling by ow2-proactive.

the class TaskLoggerTest method printAndGetLogs.

@Test
public void printAndGetLogs() throws Exception {
    taskLogger = new TaskLogger(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L), "myhost");
    assertEquals("", taskLogger.getLogs().getAllLogs(false));
    taskLogger.getOutputSink().println("hello");
    assertEquals(String.format("hello%n"), taskLogger.getLogs().getAllLogs(false));
    assertEquals(String.format("hello%n"), taskLogger.getLogs().getStdoutLogs(false));
    taskLogger.getErrorSink().println("error");
    assertEquals(String.format("hello%nerror%n"), taskLogger.getLogs().getAllLogs(false));
    assertEquals(String.format("error%n"), taskLogger.getLogs().getStderrLogs(false));
}
Also used : JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)6 StringWriter (java.io.StringWriter)2 PatternLayout (org.apache.log4j.PatternLayout)2 WriterAppender (org.apache.log4j.WriterAppender)2 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)2 AppenderProvider (org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider)2 TaskLogger (org.ow2.proactive.scheduler.util.TaskLogger)2 File (java.io.File)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LoginException (javax.security.auth.login.LoginException)1 JobId (org.ow2.proactive.scheduler.common.job.JobId)1 RemoteSpace (org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace)1 TaskLoggerRelativePathGenerator (org.ow2.proactive.scheduler.common.util.TaskLoggerRelativePathGenerator)1 DataSpaceNodeClient (org.ow2.proactive.scheduler.task.client.DataSpaceNodeClient)1 SchedulerNodeClient (org.ow2.proactive.scheduler.task.client.SchedulerNodeClient)1 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)1