Search in sources :

Example 1 with org.ow2.authzforce.core.pdp.api.policy

use of org.ow2.authzforce.core.pdp.api.policy in project scheduling by ow2-proactive.

the class Attribute method createScriptElement.

/**
 * Corresponds to <element name="script">
 *
 * The schema allows the specification of a script either by writing the
 * script code either by providing a file with arguments. Both will result
 * in the same {@link org.ow2.proactive.scripting.Script} object. In the
 * current translation we will always translate a Script object by inlining
 * the script code using a "codeScript"element (first option).
 *
 * The xml specification does not allow addding arguments to a script
 * defined by its code. Therefore, when we translate the script object to
 * xml, if we encounter arguments, we will insert their value directly in
 * the script's code by inserting a line like:
 * <p/>
 * var args = ["argument_1",...,"argument_n"];
 */
private Element createScriptElement(Document doc, Script script) {
    Element scriptElement = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_SCRIPT.getXMLName());
    if (script.getScriptUrl() != null && script.getScript() == null) {
        Element fileE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_FILE.getXMLName());
        setAttribute(fileE, XMLAttributes.SCRIPT_URL, script.getScriptUrl().toExternalForm(), true);
        if (script.getEngineName() != null) {
            setAttribute(fileE, XMLAttributes.LANGUAGE, script.getEngineName(), true);
        }
        Serializable[] params = script.getParameters();
        if (params != null) {
            Element parametersE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_ARGUMENTS.getXMLName());
            for (Serializable param : params) {
                Element parameterE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_ARGUMENT.getXMLName());
                setAttribute(parameterE, XMLAttributes.COMMON_VALUE, param.toString(), true);
                parametersE.appendChild(parameterE);
            }
            fileE.appendChild(parametersE);
        }
        scriptElement.appendChild(fileE);
    } else {
        if (script instanceof SelectionScript) {
            setAttribute(scriptElement, XMLAttributes.TYPE, ((SelectionScript) script).isDynamic() ? "dynamic" : "static", true);
        }
        Element codeE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_CODE.getXMLName());
        setAttribute(codeE, XMLAttributes.LANGUAGE, script.getEngineName(), true);
        codeE.appendChild(doc.createCDATASection(script.getScript()));
        scriptElement.appendChild(codeE);
        Serializable[] params = script.getParameters();
        if (params != null) {
            Element parametersE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_ARGUMENTS.getXMLName());
            for (Serializable param : params) {
                Element parameterE = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), XMLTags.SCRIPT_ARGUMENT.getXMLName());
                setAttribute(parameterE, XMLAttributes.COMMON_VALUE, param.toString(), true);
                parametersE.appendChild(parameterE);
            }
            scriptElement.appendChild(parametersE);
        }
    }
    return scriptElement;
}
Also used : Serializable(java.io.Serializable) SelectionScript(org.ow2.proactive.scripting.SelectionScript) Element(org.w3c.dom.Element)

Example 2 with org.ow2.authzforce.core.pdp.api.policy

use of org.ow2.authzforce.core.pdp.api.policy in project scheduling by ow2-proactive.

the class TestJobFactory method run_.

private void run_(String impl) throws Throwable {
    String scriptFolder = new File(getClass().getResource("scripts/").toURI()).getAbsolutePath();
    System.setProperty("jobName", "Job_TaskFlow");
    log("Test Job TASK_FLOW");
    TaskFlowJob tfJob = getJob(jobTaskFlowDescriptor, impl, scriptFolder);
    // Check job properties
    assertEquals("No paquit in its HostName.", tfJob.getDescription());
    assertEquals("Job_TaskFlow", tfJob.getName());
    assertEquals("My_project", tfJob.getProjectName());
    assertEquals(JobPriority.HIGH, tfJob.getPriority());
    assertEquals(OnTaskError.CANCEL_JOB, tfJob.getOnTaskErrorProperty().getValue());
    assertEquals(2, tfJob.getMaxNumberOfExecution());
    assertEquals(RestartMode.ELSEWHERE, tfJob.getRestartTaskOnError());
    assertEquals(JobType.TASKSFLOW, tfJob.getType());
    assertEquals(4, tfJob.getTasks().size());
    assertEquals("input/space", tfJob.getInputSpace());
    assertEquals("output/space", tfJob.getOutputSpace());
    // Check task 1 properties
    Task task1 = tfJob.getTask("task1");
    assertEquals("task1", task1.getName());
    // The job factory overwrites the task settings with the job settings if they are set to none.
    assertEquals(OnTaskError.NONE, task1.getOnTaskErrorProperty().getValue());
    assertEquals(false, task1.isPreciousResult());
    assertEquals(RestartMode.ANYWHERE, task1.getRestartTaskOnError());
    assertEquals(1, task1.getMaxNumberOfExecution());
    assertEquals("Parallel Tasks - Task 1", task1.getDescription());
    assertEquals(2, task1.getSelectionScripts().size());
    assertEquals(false, task1.getSelectionScripts().get(0).isDynamic());
    Assert.assertTrue(task1.getSelectionScripts().get(0).getScript() != null);
    assertEquals(1, task1.getSelectionScripts().get(0).getParameters().length);
    assertEquals("paquit", task1.getSelectionScripts().get(0).getParameters()[0]);
    assertEquals(true, task1.getSelectionScripts().get(1).isDynamic());
    Assert.assertTrue(task1.getSelectionScripts().get(1).getScript() != null);
    assertEquals(2, task1.getSelectionScripts().get(1).getParameters().length);
    assertEquals("test1", task1.getSelectionScripts().get(1).getParameters()[0]);
    assertEquals("test2", task1.getSelectionScripts().get(1).getParameters()[1]);
    Assert.assertTrue(task1.getPreScript().getScript().contains("Beginning of Pre-Script"));
    Assert.assertTrue(task1.getPostScript().getScript().contains("Content is equals to " + scriptFolder + "/unset.js"));
    assertNull(task1.getPostScript().getParameters());
    Assert.assertTrue(task1.getCleaningScript().getScript().contains("Beginning of clean script"));
    assertNull(task1.getCleaningScript().getParameters());
    assertEquals(null, task1.getDependencesList());
    assertEquals(1, task1.getNumberOfNodesNeeded());
    assertEquals(12 * 1000, task1.getWallTime());
    assertEquals(true, task1.isWallTimeSet());
    assertEquals(0, task1.getGenericInformation().size());
    assertNull(task1.getInputFilesList());
    assertNull(task1.getOutputFilesList());
    assertEquals("1", ((JavaTask) task1).getArgument("sleepTime"));
    assertEquals("1", ((JavaTask) task1).getArgument("number"));
    assertEquals("org.ow2.proactive.scheduler.examples.WaitAndPrint", ((JavaTask) task1).getExecutableClassName());
    // Now whether the task is executed in a forked JVM, it's specified by the parameter fork and runasme, instead of forkEnvironment or walltime, since 3.12.
    assertEquals(null, task1.isFork());
    assertEquals(null, task1.getForkEnvironment());
    // Check task 2 properties
    Task task2 = tfJob.getTask("task2");
    assertEquals("task2", task2.getName());
    assertEquals(OnTaskError.NONE, task2.getOnTaskErrorProperty().getValue());
    // the following commented check fails, it is what we expect, because replacement is done in the internal factory.
    // it avoids complex changes during user job creation process.
    // this property is tested in the TestDatabaseCRUD
    // Assert.assertEquals(tfJob.getTask("task2").isCancelJobOnError(),true);
    assertEquals(false, task2.isPreciousResult());
    assertEquals(RestartMode.ELSEWHERE, task2.getRestartTaskOnError());
    assertEquals(2, task2.getMaxNumberOfExecution());
    assertEquals("Parallel Tasks - Task 2", task2.getDescription());
    assertEquals(null, task2.getSelectionScripts());
    Assert.assertTrue(task2.getPreScript().getScript().contains("Beginning of Pre-Script"));
    assertEquals(null, task2.getPostScript());
    assertEquals(null, task2.getCleaningScript());
    assertEquals(null, task2.getDependencesList());
    assertEquals(1, task2.getNumberOfNodesNeeded());
    assertEquals(0, task2.getWallTime());
    assertEquals(false, task2.isWallTimeSet());
    assertEquals(0, task2.getGenericInformation().size());
    Assert.assertTrue(task2.getInputFilesList().get(0).getInputFiles().getIncludes().contains("tata*"));
    Assert.assertTrue(task2.getInputFilesList().get(0).getInputFiles().getExcludes().contains("tata*1"));
    assertEquals(InputAccessMode.TransferFromInputSpace, task2.getInputFilesList().get(0).getMode());
    Assert.assertTrue(task2.getInputFilesList().get(1).getInputFiles().getIncludes().contains("toto*.txt"));
    Assert.assertTrue(task2.getInputFilesList().get(1).getInputFiles().getExcludes().contains("toto*2.txt"));
    assertEquals(InputAccessMode.TransferFromOutputSpace, task2.getInputFilesList().get(1).getMode());
    Assert.assertTrue(task2.getOutputFilesList().get(0).getOutputFiles().getIncludes().contains("titi*"));
    Assert.assertTrue(task2.getOutputFilesList().get(0).getOutputFiles().getExcludes().contains("titi*1"));
    assertEquals(OutputAccessMode.TransferToOutputSpace, task2.getOutputFilesList().get(0).getMode());
    Assert.assertTrue(task2.getOutputFilesList().get(1).getOutputFiles().getIncludes().contains("titi*.txt"));
    Assert.assertTrue(task2.getOutputFilesList().get(1).getOutputFiles().getExcludes().contains("titi*3.txt"));
    assertEquals(OutputAccessMode.TransferToOutputSpace, task2.getOutputFilesList().get(1).getMode());
    assertEquals("12", ((JavaTask) task2).getArgument("sleepTime"));
    assertEquals("21", ((JavaTask) task2).getArgument("number"));
    assertEquals("/bin/java/jdk1.5", ((JavaTask) task2).getArgument("test"));
    assertEquals("org.ow2.proactive.scheduler.examples.WaitAndPrint", ((JavaTask) task2).getExecutableClassName());
    // Now whether the task is executed in a forked JVM, it's specified by the parameter fork and runasme, instead of forkEnvironment or walltime, since 3.12.
    assertEquals(null, task2.isFork());
    assertEquals(false, task2.isWallTimeSet());
    assertEquals("/bin/java/jdk1.5", task2.getForkEnvironment().getJavaHome());
    assertEquals("/bin/java/jdk1.5/toto", task2.getForkEnvironment().getWorkingDir());
    assertEquals("-dparam=12", task2.getForkEnvironment().getJVMArguments().get(0));
    assertEquals("-djhome=/bin/java/jdk1.5", task2.getForkEnvironment().getJVMArguments().get(1));
    Map<String, String> props = task2.getForkEnvironment().getSystemEnvironment();
    assertEquals(2, props.size());
    assertEquals("ioi", props.get("toto"));
    assertEquals("456", props.get("tata"));
    assertEquals("ioi", task2.getForkEnvironment().getSystemEnvironmentVariable("toto"));
    assertEquals("456", task2.getForkEnvironment().getSystemEnvironmentVariable("tata"));
    List<String> addcp = task2.getForkEnvironment().getAdditionalClasspath();
    assertEquals(2, addcp.size());
    assertEquals("a", addcp.get(0));
    assertEquals("b", addcp.get(1));
    Assert.assertNotNull(task2.getForkEnvironment().getEnvScript());
    // Check task 3 properties
    Task task3 = tfJob.getTask("task3");
    assertEquals("task3", task3.getName());
    assertEquals(OnTaskError.NONE, task3.getOnTaskErrorProperty().getValue());
    // the following commented check fails, it is what we expect, because replacement is done in the
    // internal factory.
    // it avoids complex changes during user job creation process.
    // this property is tested in the TestDatabaseCRUD
    // Assert.assertEquals(tfJob.getTask("task3").isCancelJobOnError(),true);
    assertEquals(false, task3.isPreciousResult());
    // the following commented check fails, it is what we expect, because replacement is done in the
    // internal factory.
    // it avoids complex changes during user job creation process.
    // this property is tested in the TestDatabaseCRUD
    // Assert.assertEquals(tfJob.getTask("task3").getRestartTaskOnError(),RestartMode.ELSEWHERE);
    // the following commented check fails, it is what we expect, because replacement is done in the internal factory.
    // it avoids complex changes during user job creation process.
    // this property is tested in the TestDatabaseCRUD
    // Assert.assertEquals(tfJob.getTask("task3").getMaxNumberOfExecution(),2);
    assertEquals("Dependent Tasks - Task 3", task3.getDescription());
    assertEquals(null, task3.getSelectionScripts());
    assertEquals(null, task3.getPreScript());
    Assert.assertTrue(task3.getPostScript().getScript().contains("Unsetting system property user.property1"));
    assertNull(task3.getPostScript().getParameters());
    assertEquals(null, task3.getCleaningScript());
    assertEquals(2, task3.getDependencesList().size());
    assertEquals("task1", task3.getDependencesList().get(0).getName());
    assertEquals("task2", task3.getDependencesList().get(1).getName());
    assertEquals(10 * 60 * 1000 + 53 * 1000, task3.getWallTime());
    assertEquals(true, task3.isWallTimeSet());
    assertEquals(0, task3.getGenericInformation().size());
    assertEquals(1, task3.getInputFilesList().size());
    Assert.assertTrue(task3.getInputFilesList().get(0).getInputFiles().getIncludes().contains("tata*"));
    Assert.assertTrue(task3.getInputFilesList().get(0).getInputFiles().getExcludes().isEmpty());
    assertEquals(InputAccessMode.none, task3.getInputFilesList().get(0).getMode());
    assertNull(task3.getOutputFilesList());
    assertEquals(5, ((NativeTask) task3).getCommandLine().length);
    assertEquals("1", ((NativeTask) task3).getCommandLine()[1]);
    assertEquals("2 2", ((NativeTask) task3).getCommandLine()[2]);
    assertEquals("3", ((NativeTask) task3).getCommandLine()[3]);
    assertEquals("12", ((NativeTask) task3).getCommandLine()[4]);
    assertNull(((NativeTask) task3).getWorkingDir());
    assertEquals(3, task3.getNumberOfNodesNeeded());
    // Check task 4 properties
    Task task4 = tfJob.getTask("task4");
    assertEquals("task4", task4.getName());
    assertEquals(OnTaskError.CANCEL_JOB, task4.getOnTaskErrorProperty().getValue());
    assertEquals(true, task4.isPreciousResult());
    assertEquals(RestartMode.ANYWHERE, task4.getRestartTaskOnError());
    assertEquals(3, task4.getMaxNumberOfExecution());
    assertEquals(null, task4.getDescription());
    assertEquals(null, task4.getSelectionScripts());
    assertEquals(null, task4.getPreScript());
    assertEquals(null, task4.getPostScript());
    assertEquals(null, task4.getCleaningScript());
    assertEquals(1, task4.getDependencesList().size());
    assertEquals("task3", task4.getDependencesList().get(0).getName());
    assertEquals(0, task4.getWallTime());
    assertEquals(false, task4.isWallTimeSet());
    assertEquals("v11", task4.getGenericInformation().get("n11"));
    assertEquals("v22", task4.getGenericInformation().get("n22"));
    assertNull(task4.getInputFilesList());
    assertEquals(5, task4.getOutputFilesList().size());
    Assert.assertTrue(task4.getOutputFilesList().get(0).getOutputFiles().getIncludes().contains("a"));
    Assert.assertTrue(task4.getOutputFilesList().get(1).getOutputFiles().getIncludes().contains("b"));
    Assert.assertTrue(task4.getOutputFilesList().get(2).getOutputFiles().getIncludes().contains("c"));
    Assert.assertTrue(task4.getOutputFilesList().get(3).getOutputFiles().getIncludes().contains("d"));
    Assert.assertTrue(task4.getOutputFilesList().get(4).getOutputFiles().getIncludes().contains("e"));
    Assert.assertTrue(task4.getOutputFilesList().get(0).getOutputFiles().getExcludes().contains("f"));
    Assert.assertTrue(task4.getOutputFilesList().get(1).getOutputFiles().getExcludes().contains("g"));
    Assert.assertTrue(task4.getOutputFilesList().get(2).getOutputFiles().getExcludes().isEmpty());
    Assert.assertTrue(task4.getOutputFilesList().get(3).getOutputFiles().getExcludes().contains("h"));
    Assert.assertTrue(task4.getOutputFilesList().get(4).getOutputFiles().getExcludes().contains("i"));
    assertEquals(OutputAccessMode.TransferToOutputSpace, task4.getOutputFilesList().get(0).getMode());
    assertEquals(OutputAccessMode.none, task4.getOutputFilesList().get(1).getMode());
    assertEquals(OutputAccessMode.none, task4.getOutputFilesList().get(2).getMode());
    assertEquals(OutputAccessMode.TransferToOutputSpace, task4.getOutputFilesList().get(3).getMode());
    assertEquals(OutputAccessMode.none, task4.getOutputFilesList().get(4).getMode());
    assertEquals(null, ((NativeTask) task4).getWorkingDir());
    assertEquals(10, task4.getNumberOfNodesNeeded());
    log("Test Job MULTI_NODES");
    TaskFlowJob mnJob = getJob(jobMultiNodesDescriptor, impl, scriptFolder);
    // Check job properties
    assertEquals("", mnJob.getDescription());
    assertEquals("job_multiNodes", mnJob.getName());
    assertEquals(JobPriority.LOW, mnJob.getPriority());
    assertEquals(OnTaskError.NONE, mnJob.getOnTaskErrorProperty().getValue());
    assertEquals(1, mnJob.getMaxNumberOfExecution());
    assertEquals(RestartMode.ANYWHERE, mnJob.getRestartTaskOnError());
    assertEquals(JobType.TASKSFLOW, mnJob.getType());
    assertEquals("v1", mnJob.getGenericInformation().get("n1"));
    assertEquals("v2", mnJob.getGenericInformation().get("n2"));
    // Check task properties
    JavaTask jt = (JavaTask) mnJob.getTask("Controller");
    assertEquals("100", jt.getArgument("numberToFind"));
    assertEquals(OnTaskError.NONE, jt.getOnTaskErrorProperty().getValue());
    assertEquals(null, jt.getCleaningScript());
    assertEquals(null, jt.getDependencesList());
    assertEquals("Will control the workers in order to find the prime number", jt.getDescription());
    assertEquals("org.ow2.proactive.scheduler.examples.MultiNodeExample", jt.getExecutableClassName());
    assertEquals("v11", jt.getGenericInformation().get("n11"));
    assertEquals("v22", jt.getGenericInformation().get("n22"));
    assertEquals(1, jt.getMaxNumberOfExecution());
    assertEquals("Controller", jt.getName());
    assertEquals(3, jt.getNumberOfNodesNeeded());
    assertEquals(null, jt.getPreScript());
    assertEquals(null, jt.getPostScript());
    assertEquals(RestartMode.ANYWHERE, jt.getRestartTaskOnError());
    assertEquals(null, jt.getSelectionScripts());
    Assert.assertTrue(jt.isPreciousResult());
    log("Test generated task name");
    TaskFlowJob job = new TaskFlowJob();
    for (int i = 0; i < 4; i++) {
        Task t = new NativeTask();
        job.addTask(t);
    }
    Task t1, t2, t3, t4;
    assertNull(job.getTask(SchedulerConstants.TASK_NAME_IFNOTSET + "0"));
    Assert.assertNotNull(t1 = job.getTask(SchedulerConstants.TASK_NAME_IFNOTSET + "1"));
    Assert.assertNotNull(t2 = job.getTask(SchedulerConstants.TASK_NAME_IFNOTSET + "2"));
    Assert.assertNotNull(t3 = job.getTask(SchedulerConstants.TASK_NAME_IFNOTSET + "3"));
    Assert.assertNotNull(t4 = job.getTask(SchedulerConstants.TASK_NAME_IFNOTSET + "4"));
    assertNull(job.getTask(SchedulerConstants.TASK_NAME_IFNOTSET + "5"));
    Assert.assertTrue(t1 != t2);
    Assert.assertTrue(t1 != t3);
    Assert.assertTrue(t1 != t4);
    Assert.assertTrue(t2 != t3);
    Assert.assertTrue(t2 != t4);
    Assert.assertTrue(t3 != t4);
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) File(java.io.File)

Example 3 with org.ow2.authzforce.core.pdp.api.policy

use of org.ow2.authzforce.core.pdp.api.policy in project scheduling by ow2-proactive.

the class TestGlobalSpace method testGlobalSpace.

@Test
public void testGlobalSpace() throws Throwable {
    File in = tmpFolder.newFolder("input_space");
    String inPath = in.getAbsolutePath();
    File out = tmpFolder.newFolder("output_space");
    String outPath = out.getAbsolutePath();
    writeFiles(inFiles, inPath);
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    job.setInputSpace(in.toURI().toURL().toString());
    job.setOutputSpace(out.toURI().toURL().toString());
    JavaTask A = new JavaTask();
    A.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    A.setName("A");
    for (String[] file : inFiles) {
        A.addInputFiles(file[0], InputAccessMode.TransferFromInputSpace);
        A.addOutputFiles(file[0] + ".glob.A", OutputAccessMode.TransferToGlobalSpace);
    }
    A.setPreScript(new SimpleScript(scriptA, "groovy"));
    A.setForkEnvironment(new ForkEnvironment());
    job.addTask(A);
    JavaTask B = new JavaTask();
    B.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    B.setName("B");
    B.addDependence(A);
    for (String[] file : inFiles) {
        B.addInputFiles(file[0] + ".glob.A", InputAccessMode.TransferFromGlobalSpace);
        B.addOutputFiles(file[0] + ".out", OutputAccessMode.TransferToOutputSpace);
    }
    B.setPreScript(new SimpleScript(scriptB, "groovy"));
    B.setForkEnvironment(new ForkEnvironment());
    job.addTask(B);
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    JobId id = scheduler.submit(job);
    schedulerHelper.waitForEventJobFinished(id);
    assertFalse(schedulerHelper.getJobResult(id).hadException());
    /**
     * check: inFiles > IN > LOCAL A > GLOBAL > LOCAL B > OUT
     */
    for (String[] inFile : inFiles) {
        File f = new File(outPath + File.separator + inFile[0] + ".out");
        assertTrue("File does not exist: " + f.getAbsolutePath(), f.exists());
        Assert.assertEquals("Original and copied files differ", inFile[1], FileUtils.readFileToString(f));
        f.delete();
        File inf = new File(inPath + File.separator + inFile[0]);
        inf.delete();
    }
    /**
     * check that the file produced is accessible in the global user space via the scheduler API
     */
    String globalURI = scheduler.getGlobalSpaceURIs().get(0);
    assertTrue(globalURI.startsWith("file:"));
    String globalPath = new File(new URI(globalURI)).getAbsolutePath();
    FileSystemManager fsManager = VFSFactory.createDefaultFileSystemManager();
    for (String[] file : inFiles) {
        FileObject outFile = fsManager.resolveFile(globalURI + "/" + file[0] + ".glob.A");
        log("Checking existence of " + outFile.getURL());
        assertTrue(outFile.getURL() + " exists", outFile.exists());
        File outFile2 = new File(globalPath, file[0] + ".glob.A");
        log("Checking existence of " + outFile2);
        assertTrue(outFile2 + " exists", outFile2.exists());
    }
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) FileObject(org.apache.commons.vfs2.FileObject) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) URI(java.net.URI) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 4 with org.ow2.authzforce.core.pdp.api.policy

use of org.ow2.authzforce.core.pdp.api.policy in project scheduling by ow2-proactive.

the class TestWorkflowDataspace method testJavaTask.

private void testJavaTask() throws Throwable {
    String tmpdir = System.getProperty("java.io.tmpdir");
    File inputSpace = new File(tmpdir + File.separator + "inputSpace." + System.currentTimeMillis());
    File outputSpace = new File(tmpdir + File.separator + "outputSpace." + System.currentTimeMillis());
    inputSpace.mkdir();
    outputSpace.mkdir();
    for (int it = 0; it < 3; it++) {
        for (int dup = 0; dup < 3; dup++) {
            File f = new File(inputSpace.getCanonicalPath() + File.separator + it + "_" + dup + ".in");
            f.createNewFile();
            BufferedWriter out = new BufferedWriter(new FileWriter(f));
            out.write("it " + it + " dup " + dup + "\n");
            out.close();
        }
    }
    TaskFlowJob job = new TaskFlowJob();
    job.setName(TestWorkflowDataspace.class.getSimpleName());
    job.setInputSpace(inputSpace.toURI().toURL().toString());
    job.setOutputSpace(outputSpace.toURI().toURL().toString());
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    JavaTask t = new JavaTask();
    t.setName("T");
    t.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    t.setFlowScript(FlowScript.createReplicateFlowScript("runs = 3;"));
    t.setFlowBlock(FlowBlock.START);
    t.setForkEnvironment(forkEnvironment);
    job.addTask(t);
    JavaTask t1 = new JavaTask();
    t1.setName("T1");
    t1.setForkEnvironment(forkEnvironment);
    t1.setExecutableClassName(JobWorkflowDataspace.class.getCanonicalName());
    t1.setForkEnvironment(new ForkEnvironment());
    t1.addDependence(t);
    t1.addInputFiles("$PA_TASK_ITERATION_$PA_TASK_REPLICATION.in", InputAccessMode.TransferFromInputSpace);
    t1.addOutputFiles("$PA_TASK_ITERATION_$PA_TASK_REPLICATION.out", OutputAccessMode.TransferToOutputSpace);
    job.addTask(t1);
    JavaTask t2 = new JavaTask();
    t2.setName("T2");
    t2.setForkEnvironment(forkEnvironment);
    t2.setExecutableClassName("org.ow2.proactive.scheduler.examples.EmptyTask");
    t2.addDependence(t1);
    t2.setFlowScript(// 
    FlowScript.createLoopFlowScript(// 
    "if (variables.get('PA_TASK_ITERATION') < 2) {" + // 
    "loop = true;" + // 
    "} else {" + // 
    "loop = false;" + "}", "T"));
    t2.setFlowBlock(FlowBlock.END);
    job.addTask(t2);
    JobId id = TWorkflowJobs.testJobSubmission(schedulerHelper, job, null);
    TWorkflowJobs.waitForJobFinished(id, schedulerHelper, job, null);
    Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
    for (int it = 0; it < 3; it++) {
        for (int dup = 0; dup < 3; dup++) {
            File f = new File(outputSpace.getCanonicalPath() + File.separator + it + "_" + dup + ".out");
            Assert.assertTrue("Missing output file " + f.getName(), f.exists());
            BufferedReader in = new BufferedReader(new FileReader(f));
            String line = in.readLine();
            Assert.assertTrue("Wrong content for " + f.getCanonicalPath(), line.equals("it " + it + " dup " + dup));
        }
    }
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) JobWorkflowDataspace(functionaltests.workflow.JobWorkflowDataspace) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 5 with org.ow2.authzforce.core.pdp.api.policy

use of org.ow2.authzforce.core.pdp.api.policy in project scheduling by ow2-proactive.

the class CreateCredentials method main.

/**
 * Entry point
 *
 * @see org.ow2.proactive.authentication.crypto.Credentials
 * @param args arguments, try '-h' for help
 * @throws IOException
 * @throws ParseException
 */
public static void main(String[] args) throws IOException, ParseException {
    SecurityManagerConfigurator.configureSecurityManager(CreateCredentials.class.getResource("/all-permissions.security.policy").toString());
    Console console = System.console();
    /**
     * default values
     */
    boolean interactive = true;
    String pubKeyPath = null;
    PublicKey pubKey = null;
    String login = null;
    String pass = null;
    String keyfile = null;
    String cipher = "RSA/ECB/PKCS1Padding";
    String path = Credentials.getCredentialsPath();
    String rm = null;
    String scheduler = null;
    String url = null;
    Options options = new Options();
    Option opt = new Option("h", "help", false, "Display this help");
    opt.setRequired(false);
    options.addOption(opt);
    OptionGroup group = new OptionGroup();
    group.setRequired(false);
    opt = new Option("F", "file", true, "Public key path on the local filesystem [default:" + Credentials.getPubKeyPath() + "]");
    opt.setArgName("PATH");
    opt.setArgs(1);
    opt.setRequired(false);
    group.addOption(opt);
    opt = new Option("R", "rm", true, "Request the public key to the Resource Manager at URL");
    opt.setArgName("URL");
    opt.setArgs(1);
    opt.setRequired(false);
    group.addOption(opt);
    opt = new Option("S", "scheduler", true, "Request the public key to the Scheduler at URL");
    opt.setArgName("URL");
    opt.setArgs(1);
    opt.setRequired(false);
    group.addOption(opt);
    options.addOptionGroup(group);
    opt = new Option("l", "login", true, "Generate credentials for this specific user, will be asked interactively if not specified");
    opt.setArgName("LOGIN");
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);
    opt = new Option("p", "password", true, "Use this password, will be asked interactively if not specified");
    opt.setArgName("PWD");
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);
    opt = new Option("k", "keyfile", true, "Use specified ssh private key, asked interactively if specified without PATH, not specified otherwise.");
    opt.setArgName("PATH");
    opt.setOptionalArg(true);
    opt.setRequired(false);
    options.addOption(opt);
    opt = new Option("o", "output", true, "Output the resulting credentials to the specified file [default:" + path + "]");
    opt.setArgName("PATH");
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);
    opt = new Option("c", "cipher", true, "Use specified cipher parameters, need to be compatible with the specified key [default:" + cipher + "]");
    opt.setArgName("PARAMS");
    opt.setArgs(1);
    opt.setRequired(false);
    options.addOption(opt);
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(newline + "ERROR : " + e.getMessage() + newline);
        System.out.println("type -h or --help to display help screen");
        System.exit(1);
    }
    if (cmd.hasOption("help")) {
        displayHelp(options);
    }
    if (cmd.hasOption("file")) {
        pubKeyPath = cmd.getOptionValue("file");
    }
    if (cmd.hasOption("rm")) {
        rm = cmd.getOptionValue("rm");
    }
    if (cmd.hasOption("scheduler")) {
        scheduler = cmd.getOptionValue("scheduler");
    }
    if (cmd.hasOption("login")) {
        login = cmd.getOptionValue("login");
    }
    if (cmd.hasOption("password")) {
        pass = cmd.getOptionValue("password");
    }
    if (cmd.hasOption("keyfile") && cmd.getOptionValues("keyfile") != null) {
        keyfile = cmd.getOptionValue("keyfile");
    }
    if (cmd.hasOption("output")) {
        path = cmd.getOptionValue("output");
    }
    if (cmd.hasOption("cipher")) {
        cipher = cmd.getOptionValue("cipher");
    }
    int acc = 0;
    if (pubKeyPath != null) {
        acc++;
    }
    if (scheduler != null) {
        url = URIBuilder.buildURI(Connection.normalize(scheduler), "SCHEDULER").toString();
        acc++;
    }
    if (rm != null) {
        url = URIBuilder.buildURI(Connection.normalize(rm), "RMAUTHENTICATION").toString();
        acc++;
    }
    if (acc > 1) {
        System.out.println("--rm, --scheduler and --file arguments cannot be combined.");
        System.out.println("try -h for help.");
        System.exit(1);
    }
    if (url != null) {
        try {
            Connection<AuthenticationImpl> conn = new Connection<AuthenticationImpl>(AuthenticationImpl.class) {

                public Logger getLogger() {
                    return Logger.getLogger("pa.scheduler.credentials");
                }
            };
            AuthenticationImpl auth = conn.connect(url);
            pubKey = auth.getPublicKey();
        } catch (Exception e) {
            System.err.println("ERROR : Could not retrieve public key from '" + url + "'");
            e.printStackTrace();
            System.exit(3);
        }
        System.out.println("Successfully obtained public key from " + url + newline);
    } else if (pubKeyPath != null) {
        try {
            pubKey = Credentials.getPublicKey(pubKeyPath);
        } catch (KeyException e) {
            System.err.println("ERROR : Could not retrieve public key from '" + pubKeyPath + "' (no such file)");
            System.exit(4);
        }
    } else {
        System.out.println("No public key specified, attempting to retrieve it from default location.");
        pubKeyPath = Credentials.getPubKeyPath();
        try {
            pubKey = Credentials.getPublicKey(pubKeyPath);
        } catch (KeyException e) {
            System.err.println("ERROR : Could not retrieve public key from '" + pubKeyPath + "' (no such file)");
            System.exit(5);
        }
    }
    if (login != null && pass != null && (!cmd.hasOption("keyfile") || cmd.getOptionValues("keyfile") != null)) {
        System.out.println("Running in non-interactive mode." + newline);
        interactive = false;
    } else {
        System.out.println("Running in interactive mode.");
    }
    if (interactive) {
        System.out.println("Please enter Scheduler credentials,");
        System.out.println("they will be stored encrypted on disk for future logins." + newline);
        System.out.print("login: ");
        if (login == null) {
            login = console.readLine();
        } else {
            System.out.println(login);
        }
        System.out.print("password: ");
        if (pass == null) {
            pass = new String(console.readPassword());
        } else {
            System.out.println("*******");
        }
        System.out.print("keyfile: ");
        if (!cmd.hasOption("keyfile")) {
            System.out.println("no key file specified");
        } else if (cmd.hasOption("keyfile") && cmd.getOptionValues("keyfile") != null) {
            System.out.println(keyfile);
        } else {
            keyfile = console.readLine();
        }
    }
    try {
        CredData credData;
        if (keyfile != null && keyfile.length() > 0) {
            byte[] keyfileContent = FileToBytesConverter.convertFileToByteArray(new File(keyfile));
            credData = new CredData(CredData.parseLogin(login), CredData.parseDomain(login), pass, keyfileContent);
        } else {
            System.out.println("--> Ignoring keyfile, credential does not contain SSH key");
            credData = new CredData(CredData.parseLogin(login), CredData.parseDomain(login), pass);
        }
        Credentials cred = Credentials.createCredentials(credData, pubKey, cipher);
        cred.writeToDisk(path);
    } catch (FileNotFoundException e) {
        System.err.println("ERROR : Could not retrieve ssh private key from '" + keyfile + "' (no such file)");
        System.exit(6);
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(7);
    }
    System.out.println("Successfully stored encrypted credentials on disk at :");
    System.out.println("\t" + path);
    System.exit(0);
}
Also used : Options(org.apache.commons.cli.Options) PublicKey(java.security.PublicKey) Connection(org.ow2.proactive.authentication.Connection) FileNotFoundException(java.io.FileNotFoundException) KeyException(java.security.KeyException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.commons.cli.ParseException) KeyException(java.security.KeyException) AuthenticationImpl(org.ow2.proactive.authentication.AuthenticationImpl) CommandLine(org.apache.commons.cli.CommandLine) OptionGroup(org.apache.commons.cli.OptionGroup) Console(java.io.Console) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

Test (org.junit.Test)12 JobId (org.ow2.proactive.scheduler.common.job.JobId)9 File (java.io.File)7 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)6 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 IndeterminateEvaluationException (org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException)4 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)4 EasyByteArrayOutputStream (com.ebmwebsourcing.easycommons.stream.EasyByteArrayOutputStream)3 FileObject (org.apache.commons.vfs2.FileObject)3 URI (java.net.URI)2 KeyException (java.security.KeyException)2 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 Properties (java.util.Properties)2 MessagingException (javax.jbi.messaging.MessagingException)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)2 ProcessDefinitionQuery (org.flowable.engine.repository.ProcessDefinitionQuery)2