Search in sources :

Example 1 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 2 with RemoteSpace

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

the class DataTransferTest method testUploadSingleFile.

@Test
public void testUploadSingleFile() throws Exception {
    File tmpFile = tmpDir.newFile(TEMP_FILE_TMP_NAME);
    Files.write(randomFileContents(), tmpFile);
    // use standard client
    IDataSpaceClient client = clientInstance();
    LocalFileSource source = new LocalFileSource(tmpFile);
    RemoteDestination dest = new RemoteDestination(USER, "testUploadSingleFile/" + TEMP_FILE_TMP_NAME);
    assertTrue(client.upload(source, dest));
    String destDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
    File destFile = new File(destDirPath, "testUploadSingleFile/" + TEMP_FILE_TMP_NAME);
    assertTrue(Files.equal(tmpFile, destFile));
    // use RemoteSpace API
    FileUtils.deleteQuietly(destFile);
    client.getUserSpace().pushFile(tmpFile, "testUploadSingleFile/" + TEMP_FILE_TMP_NAME);
    assertTrue(Files.equal(tmpFile, destFile));
}
Also used : ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) File(java.io.File) Test(org.junit.Test)

Example 3 with RemoteSpace

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

the class DataTransferTest method testUploadSelectedFilesUsingFilenames.

@Test
public void testUploadSelectedFilesUsingFilenames() throws Exception {
    TestFilesToUploadCreator testFiles = new TestFilesToUploadCreator().invoke();
    File tempTextFile = testFiles.getTempTextFile();
    File tempFile = testFiles.getTempFile();
    // use standard client
    IDataSpaceClient client = clientInstance();
    LocalDirSource source = new LocalDirSource(tmpDir.getRoot());
    source.setIncludes("**/" + TEMP_FILE_TMP_NAME);
    RemoteDestination dest = new RemoteDestination(USER, "testUploadSelectedFilesUsingFilenames");
    assertTrue(client.upload(source, dest));
    String destRootUri = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
    File[] destRootFiles = new File(destRootUri, "testUploadSelectedFilesUsingFilenames").listFiles();
    assertEquals(1, destRootFiles.length);
    assertTrue(Files.equal(tempFile, destRootFiles[0]));
    // use RemoteSpace API
    FileUtils.deleteDirectory(new File(destRootUri, "testUploadSelectedFilesUsingFilenames"));
    client.getUserSpace().pushFiles(tmpDir.getRoot(), "**/" + TEMP_FILE_TMP_NAME, "testUploadSelectedFilesUsingFilenames");
    destRootFiles = new File(destRootUri, "testUploadSelectedFilesUsingFilenames").listFiles();
    assertEquals(1, destRootFiles.length);
    assertTrue(Files.equal(tempFile, destRootFiles[0]));
}
Also used : ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) File(java.io.File) Test(org.junit.Test)

Example 4 with RemoteSpace

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

the class DataTransferTest method testDownloadArchiveFile.

private void testDownloadArchiveFile(String archiveFileName, URL archiveSource) throws Exception {
    String srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
    File srcFile = new File(srcDirPath, archiveFileName);
    if (srcFile.exists()) {
        assertTrue(srcFile.delete());
    }
    FileUtils.copyInputStreamToFile(archiveSource.openStream(), srcFile);
    File tmpFile = tmpDir.newFile(archiveFileName);
    if (tmpFile.exists()) {
        assertTrue(tmpFile.delete());
    }
    // use standard client
    IDataSpaceClient client = clientInstance();
    RemoteSource source = new RemoteSource(USER, archiveFileName);
    LocalDestination dest = new LocalDestination(tmpFile);
    assertTrue(client.download(source, dest));
    assertTrue(Files.equal(srcFile, tmpFile));
    // use RemoteSpace API
    FileUtils.deleteQuietly(tmpFile);
    File downloadedFile = client.getUserSpace().pullFile(archiveFileName, tmpFile);
    assertTrue(Files.equal(srcFile, downloadedFile));
}
Also used : ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) File(java.io.File)

Example 5 with RemoteSpace

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

the class DataTransferTest method testDownloadFile.

@Test
public void testDownloadFile() throws Exception {
    String srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
    File srcFile = new File(srcDirPath, TEMP_FILE_TMP_NAME);
    if (srcFile.exists()) {
        assertTrue(srcFile.delete());
    }
    Files.write(randomFileContents(), srcFile);
    File tmpFile = tmpDir.newFile(TEMP_FILE_TMP_NAME);
    if (tmpFile.exists()) {
        assertTrue(tmpFile.delete());
    }
    // use standard client
    IDataSpaceClient client = clientInstance();
    RemoteSource source = new RemoteSource(USER, TEMP_FILE_TMP_NAME);
    LocalDestination dest = new LocalDestination(tmpFile);
    assertTrue(client.download(source, dest));
    assertTrue(Files.equal(srcFile, tmpFile));
    // use RemoteSpace API
    FileUtils.deleteQuietly(tmpFile);
    File downloadedFile = client.getUserSpace().pullFile(TEMP_FILE_TMP_NAME, tmpFile);
    assertTrue(Files.equal(srcFile, downloadedFile));
}
Also used : ListFile(org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile) File(java.io.File) 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