Search in sources :

Example 6 with RemoteSpace

use of org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace in project scheduling by ow2-proactive.

the class DataTransferTest method testDeleteFile.

@Test
public void testDeleteFile() throws Exception {
    URI srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0));
    File srcFile = new File(new File(srcDirPath), TEMP_FILE_TMP_NAME);
    if (srcFile.exists()) {
        assertTrue(srcFile.delete());
    }
    Files.write(randomFileContents(), srcFile);
    // use standard client
    IDataSpaceClient client = clientInstance();
    RemoteSource source = new RemoteSource(USER, TEMP_FILE_TMP_NAME);
    assertTrue(client.delete(source));
    assertFalse(srcFile.exists());
    // use RemoteSpace API
    Files.write(randomFileContents(), srcFile);
    client.getUserSpace().deleteFile(TEMP_FILE_TMP_NAME);
    assertFalse(srcFile.exists());
}
Also used : URI(java.net.URI) ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) File(java.io.File) Test(org.junit.Test)

Example 7 with RemoteSpace

use of org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace in project scheduling by ow2-proactive.

the class InProcessTaskExecutor method execute.

/**
 * Executes a task inside a task context.
 *
 * @param taskContext Task context to execute.
 * @param output      Standard output sink.
 * @param error       Error sink.
 * @return Returns the task result.
 */
@Override
public TaskResultImpl execute(TaskContext taskContext, PrintStream output, PrintStream error) {
    ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
    String nodesFile = null;
    SchedulerNodeClient schedulerNodeClient = null;
    RemoteSpace userSpaceClient = null;
    RemoteSpace globalSpaceClient = null;
    try {
        nodesFile = writeNodesFile(taskContext);
        VariablesMap variables = new VariablesMap();
        variables.setInheritedMap(taskContextVariableExtractor.getAllNonTaskVariablesInjectNodesFile(taskContext, nodesFile));
        variables.setScopeMap(taskContextVariableExtractor.getScopeVariables(taskContext));
        Map<String, String> resultMetadata = new HashMap<>();
        Map<String, String> thirdPartyCredentials = forkedTaskVariablesManager.extractThirdPartyCredentials(taskContext);
        schedulerNodeClient = forkedTaskVariablesManager.createSchedulerNodeClient(taskContext);
        userSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.USER);
        globalSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.GLOBAL);
        forkedTaskVariablesManager.addBindingsToScriptHandler(scriptHandler, taskContext, variables, thirdPartyCredentials, schedulerNodeClient, userSpaceClient, globalSpaceClient, resultMetadata);
        Stopwatch stopwatch = Stopwatch.createUnstarted();
        TaskResultImpl taskResult;
        try {
            stopwatch.start();
            Serializable result = execute(taskContext, output, error, scriptHandler, thirdPartyCredentials, variables);
            stopwatch.stop();
            taskResult = new TaskResultImpl(taskContext.getTaskId(), result, null, stopwatch.elapsed(TimeUnit.MILLISECONDS));
        } catch (Throwable e) {
            stopwatch.stop();
            e.printStackTrace(error);
            taskResult = new TaskResultImpl(taskContext.getTaskId(), e, null, stopwatch.elapsed(TimeUnit.MILLISECONDS));
        }
        executeFlowScript(taskContext.getControlFlowScript(), scriptHandler, output, error, taskResult);
        taskResult.setPropagatedVariables(SerializationUtil.serializeVariableMap(variables.getPropagatedVariables()));
        taskResult.setMetadata(resultMetadata);
        return taskResult;
    } catch (Throwable e) {
        e.printStackTrace(error);
        return new TaskResultImpl(taskContext.getTaskId(), e);
    } finally {
        if (nodesFile != null && !nodesFile.isEmpty()) {
            FileUtils.deleteQuietly(new File(nodesFile));
        }
    }
}
Also used : RemoteSpace(org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace) Serializable(java.io.Serializable) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) SchedulerNodeClient(org.ow2.proactive.scheduler.task.client.SchedulerNodeClient) HashMap(java.util.HashMap) Stopwatch(com.google.common.base.Stopwatch) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) File(java.io.File) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 8 with RemoteSpace

use of org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace 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 9 with RemoteSpace

use of org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace in project scheduling by ow2-proactive.

the class ForkEnvironmentScriptExecutor method executeForkEnvironmentScript.

/**
 * Executes a fork environment script.
 *
 * @param context    The task context to execute the script in.
 * @param outputSink Standard output sink.
 * @param errorSink  Error output sink.
 * @return Returns a ScriptResult.
 * @throws Exception
 */
public ScriptResult executeForkEnvironmentScript(TaskContext context, PrintStream outputSink, PrintStream errorSink) throws Exception {
    VariablesMap variables = new VariablesMap();
    variables.setInheritedMap(taskContextVariableExtractor.getAllNonTaskVariables(context));
    variables.setScopeMap(taskContextVariableExtractor.getScopeVariables(context));
    Map<String, String> thirdPartyCredentials = forkedTaskVariablesManager.extractThirdPartyCredentials(context);
    ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
    Script<?> script = context.getInitializer().getForkEnvironment().getEnvScript();
    SchedulerNodeClient schedulerNodeClient = forkedTaskVariablesManager.createSchedulerNodeClient(context);
    RemoteSpace userSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(context, schedulerNodeClient, IDataSpaceClient.Dataspace.USER);
    RemoteSpace globalSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(context, schedulerNodeClient, IDataSpaceClient.Dataspace.GLOBAL);
    forkedTaskVariablesManager.addBindingsToScriptHandler(scriptHandler, context, variables, thirdPartyCredentials, schedulerNodeClient, userSpaceClient, globalSpaceClient, Collections.<String, String>emptyMap());
    forkedTaskVariablesManager.replaceScriptParameters(script, thirdPartyCredentials, variables, errorSink);
    ScriptResult scriptResult = scriptHandler.handle(script, outputSink, errorSink);
    if (scriptResult.errorOccured()) {
        throw new Exception("Failed to execute fork environment script", scriptResult.getException());
    }
    return scriptResult;
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) RemoteSpace(org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace) SchedulerNodeClient(org.ow2.proactive.scheduler.task.client.SchedulerNodeClient) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 10 with RemoteSpace

use of org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace in project scheduling by ow2-proactive.

the class DataTransferTest method testListFilesRecursive.

@Test
public void testListFilesRecursive() throws Exception {
    System.out.println("testListFilesRecursive");
    createFilesInUserSpace("testListFilesRecursive");
    // use standard client
    IDataSpaceClient client = clientInstance();
    RemoteSource source = new RemoteSource(USER, "testListFilesRecursive");
    source.setIncludes("**");
    ListFile listFile = client.list(source);
    List<String> directories = listFile.getDirectoryListing();
    System.out.println("Directories : " + directories);
    assertEquals(1, directories.size());
    assertEquals(DataTransferTest.TEMP_DIR_NAME, directories.get(0));
    List<String> files = listFile.getFileListing();
    System.out.println("Files : " + files);
    assertEquals(2, files.size());
    assertEquals(TEMP_FILE_TMP_PATH, files.get(0));
    assertEquals(TEMP_FILE_TXT_NAME, files.get(1));
    // use RemoteSpace API
    List<String> foundFiles = client.getUserSpace().listFiles("testListFilesRecursive", "**");
    System.out.println("Full : " + foundFiles);
    assertEquals(3, foundFiles.size());
    assertArrayEquals(new String[] { TEMP_DIR_NAME, TEMP_FILE_TMP_PATH, TEMP_FILE_TXT_NAME }, foundFiles.toArray(new String[0]));
}
Also used : ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) Test(org.junit.Test)

Aggregations

ListFile (org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)13 File (java.io.File)11 Test (org.junit.Test)11 RemoteSpace (org.ow2.proactive.scheduler.common.task.dataspaces.RemoteSpace)3 SchedulerNodeClient (org.ow2.proactive.scheduler.task.client.SchedulerNodeClient)3 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)3 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Stopwatch (com.google.common.base.Stopwatch)1 URI (java.net.URI)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 LoginException (javax.security.auth.login.LoginException)1 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)1 DataSpaceNodeClient (org.ow2.proactive.scheduler.task.client.DataSpaceNodeClient)1 Decrypter (org.ow2.proactive.scheduler.task.utils.Decrypter)1 TaskLogger (org.ow2.proactive.scheduler.util.TaskLogger)1 ScriptResult (org.ow2.proactive.scripting.ScriptResult)1