Search in sources :

Example 31 with GATObjectCreationException

use of org.gridlab.gat.GATObjectCreationException in project compss by bsc-wdc.

the class AllFileInputStreamAdaptorsTest method printResults.

private static void printResults(AdaptorTestResult[] results, String host) throws IOException {
    File outFile = new File("FileInputStream-results-" + host + ".html");
    if (!outFile.exists()) {
        outFile.createNewFile();
    }
    FileOutputStream out = new FileOutputStream(outFile);
    out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n".getBytes());
    out.write("<html>\n".getBytes());
    out.write("<head>\n".getBytes());
    out.write("<title>JavaGAT test results: File</title>\n".getBytes());
    out.write(("<script>\n" + "function showhide(id){\n" + "\tif (document.getElementById){\n" + "\t\tobj = document.getElementById(id);\n" + "\t\tif (obj.style.display == \"none\"){\n" + "\t\t\tobj.style.display = \"\";\n" + "\t\t} else {\n" + "\t\t\tobj.style.display = \"none\";\n" + "\t\t}\n" + "\t}\n" + "}\n" + "</script>\n").getBytes());
    out.write("</head>\n".getBytes());
    out.write("<body>\n".getBytes());
    out.write("<table frame=box cellpadding=5 cellspacing=0>\n".getBytes());
    out.write("<tr>\n".getBytes());
    out.write("<td></td>\n".getBytes());
    for (AdaptorTestResult result : results) {
        out.write(("<td align=right>" + result.getAdaptor() + "</td>\n").getBytes());
    }
    out.write("</tr>\n".getBytes());
    boolean background = true;
    String[] keys = results[0].getTestResultEntries().keySet().toArray(new String[results[0].getTestResultEntries().size()]);
    Arrays.sort(keys);
    for (String key : keys) {
        if (background) {
            out.write("<tr bgcolor=#DDDDDD>\n".getBytes());
        } else {
            out.write("<tr bgcolor=#FFFFFF>\n".getBytes());
        }
        background = !background;
        out.write(("<td>" + key + "</td>\n").getBytes());
        for (AdaptorTestResult result : results) {
            AdaptorTestResultEntry entry = result.getTestResultEntries().get(key);
            if (entry == null) {
                out.write("<td align=right>not present</td>\n".getBytes());
                continue;
            }
            if (entry.getException() == null && !entry.getResult()) {
                out.write("<td align=right bgcolor=#FFDDDD>".getBytes());
            } else {
                out.write("<td align=right>".getBytes());
            }
            if (entry.getException() == null) {
                out.write((entry.getTime() + " ms").getBytes());
            } else {
                if (entry.getException() instanceof GATInvocationException && ((GATInvocationException) entry.getException()).getExceptions().length > 0 && ((GATInvocationException) entry.getException()).getExceptions()[0] instanceof UnsupportedOperationException) {
                    out.write("n.i.".getBytes());
                } else if (entry.getException() instanceof GATObjectCreationException && ((GATObjectCreationException) entry.getException()).getExceptions().length > 0 && ((GATObjectCreationException) entry.getException()).getExceptions()[0] instanceof GATObjectCreationException && ((GATObjectCreationException) ((GATObjectCreationException) entry.getException()).getExceptions()[0]).getExceptions().length > 0 && ((GATObjectCreationException) ((GATObjectCreationException) entry.getException()).getExceptions()[0]).getExceptions()[0] instanceof AdaptorNotApplicableException) {
                    out.write("n.a.".getBytes());
                } else {
                    out.write(("<div style=\"display: none;\" id=\"" + result.getAdaptor() + key + "\">\n").getBytes());
                    out.write((entry.getException().toString().replace("\n", "<br/>\n") + "\n").getBytes());
                    StringWriter s = new StringWriter();
                    PrintWriter p = new PrintWriter(s);
                    entry.getException().printStackTrace(p);
                    out.write((s.toString().replace("\n", "<br/>\n") + "\n").getBytes());
                    out.write("</div>\n".getBytes());
                    out.write(("<a href=\"#\" onclick=\"showhide('" + result.getAdaptor() + key + "'); return(false);\">show/hide</a>\n").getBytes());
                }
            }
            out.write("</td>\n".getBytes());
        }
        out.write("</tr>\n".getBytes());
    }
    out.write("<tr>\n".getBytes());
    out.write("<td>total</td>\n".getBytes());
    for (AdaptorTestResult result : results) {
        out.write(("<td align=right>" + result.getTotalRunTime() + " ms</td>\n").getBytes());
    }
    out.write("</tr>\n".getBytes());
    out.write("<tr>\n".getBytes());
    out.write("<td>average</td>\n".getBytes());
    for (AdaptorTestResult result : results) {
        out.write(("<td align=right>" + result.getAverageRunTime() + " ms</td>\n").getBytes());
    }
    out.write("</tr>\n".getBytes());
    out.write("</table>\n".getBytes());
    out.write("</body>\n".getBytes());
    out.write("</html>\n".getBytes());
}
Also used : GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) StringWriter(java.io.StringWriter) FileOutputStream(java.io.FileOutputStream) AdaptorNotApplicableException(org.gridlab.gat.AdaptorNotApplicableException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 32 with GATObjectCreationException

use of org.gridlab.gat.GATObjectCreationException in project compss by bsc-wdc.

the class FileInputStreamAdaptorTest method run.

private void run(String host, String script) {
    Preferences preferences = new Preferences();
    preferences.put("resourcebroker.adaptor.name", "commandlinessh,sshtrilead,local");
    preferences.put("file.adaptor.name", "commandlinessh,sshtrilead,local");
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/bash");
    sd.setArguments(script);
    try {
        sd.addPreStagedFile(GAT.createFile(preferences, "tests" + java.io.File.separator + "src" + java.io.File.separator + "benchmarks" + java.io.File.separator + script));
    } catch (GATObjectCreationException e) {
        e.printStackTrace();
        System.exit(1);
    }
    ResourceBroker broker = null;
    try {
        broker = GAT.createResourceBroker(preferences, new URI("any://" + host));
    } catch (GATObjectCreationException e) {
        e.printStackTrace();
        System.exit(1);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        System.exit(1);
    }
    Job job = null;
    try {
        job = broker.submitJob(new JobDescription(sd));
    } catch (GATInvocationException e) {
        e.printStackTrace();
        System.exit(1);
    }
    while (job.getState() != Job.JobState.STOPPED && job.getState() != Job.JobState.SUBMISSION_ERROR) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        // ignored
        }
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) URISyntaxException(java.net.URISyntaxException) Preferences(org.gridlab.gat.Preferences) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 33 with GATObjectCreationException

use of org.gridlab.gat.GATObjectCreationException in project compss by bsc-wdc.

the class ResourceBrokerAdaptorTest method submitJobEasy.

private AdaptorTestResultEntry submitJobEasy(GATContext gatContext, Preferences preferences, String host) {
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/echo");
    sd.setArguments("test", "1", "2", "3");
    Map<String, Object> attributes = new HashMap<String, Object>();
    sd.setAttributes(attributes);
    JobDescription jd = new JobDescription(sd);
    ResourceBroker broker;
    try {
        broker = GAT.createResourceBroker(gatContext, preferences, new URI(host));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    } catch (URISyntaxException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    long start = System.currentTimeMillis();
    try {
        broker.submitJob(jd, this, "job.status");
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    waitForJob();
    long stop = System.currentTimeMillis();
    return new AdaptorTestResultEntry(true, (stop - start), null);
}
Also used : GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) HashMap(java.util.HashMap) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) JobDescription(org.gridlab.gat.resources.JobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException)

Example 34 with GATObjectCreationException

use of org.gridlab.gat.GATObjectCreationException in project compss by bsc-wdc.

the class ResourceBrokerAdaptorTest method submitJobPreStage.

private AdaptorTestResultEntry submitJobPreStage(GATContext gatContext, Preferences preferences, String host) {
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/ls");
    sd.setArguments("floep");
    java.io.File floep = new java.io.File("floep");
    if (!floep.exists()) {
        try {
            floep.createNewFile();
        } catch (IOException e) {
            return new AdaptorTestResultEntry(false, 0L, e);
        }
        floep.deleteOnExit();
    }
    java.io.File tmp = new java.io.File("tmp");
    if (!tmp.exists()) {
        tmp.mkdir();
        tmp.deleteOnExit();
    }
    try {
        sd.addPreStagedFile(GAT.createFile(gatContext, preferences, "floep"));
        sd.addPreStagedFile(GAT.createFile(gatContext, preferences, "tmp"));
        sd.setStdout(GAT.createFile(gatContext, preferences, "stdout"));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    JobDescription jd = new JobDescription(sd);
    ResourceBroker broker;
    try {
        broker = GAT.createResourceBroker(gatContext, preferences, new URI(host));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    } catch (URISyntaxException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    long start = System.currentTimeMillis();
    Job job;
    try {
        job = broker.submitJob(jd, this, "job.status");
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    waitForJob();
    try {
        Map<String, Object> info = job.getInfo();
        Throwable ex = (Throwable) info.get("poststage.exception");
        if (ex != null) {
            return new AdaptorTestResultEntry(false, 0L, ex);
        }
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    long stop = System.currentTimeMillis();
    String result;
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new java.io.FileInputStream("stdout")));
        result = reader.readLine();
        reader.close();
    } catch (Exception e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    return new AdaptorTestResultEntry(result != null, (stop - start), null);
}
Also used : GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) InputStreamReader(java.io.InputStreamReader) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) URISyntaxException(java.net.URISyntaxException) GATInvocationException(org.gridlab.gat.GATInvocationException) IOException(java.io.IOException) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) JobDescription(org.gridlab.gat.resources.JobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) BufferedReader(java.io.BufferedReader) Job(org.gridlab.gat.resources.Job)

Example 35 with GATObjectCreationException

use of org.gridlab.gat.GATObjectCreationException in project compss by bsc-wdc.

the class ResourceBrokerAdaptorTest method submitJobStdout.

private AdaptorTestResultEntry submitJobStdout(GATContext gatContext, Preferences preferences, String host) {
    SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/echo");
    // Arguments modified to test against expansion of shell meta characters --Ceriel
    sd.setArguments("test", "1", "2", "'*");
    try {
        sd.setStdout(GAT.createFile(gatContext, preferences, "stdout"));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    JobDescription jd = new JobDescription(sd);
    ResourceBroker broker;
    try {
        broker = GAT.createResourceBroker(gatContext, preferences, new URI(host));
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    } catch (URISyntaxException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    long start = System.currentTimeMillis();
    Job job;
    try {
        job = broker.submitJob(jd, this, "job.status");
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    waitForJob();
    try {
        Map<String, Object> info = job.getInfo();
        Throwable ex = (Throwable) info.get("poststage.exception");
        if (ex != null) {
            return new AdaptorTestResultEntry(false, 0L, ex);
        }
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    long stop = System.currentTimeMillis();
    String result;
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new java.io.FileInputStream("stdout")));
        result = reader.readLine();
        reader.close();
    } catch (Exception e) {
        return new AdaptorTestResultEntry(false, 0L, e);
    }
    return new AdaptorTestResultEntry("test 1 2 '*".equals(result), (stop - start), null);
}
Also used : GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) InputStreamReader(java.io.InputStreamReader) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) URISyntaxException(java.net.URISyntaxException) GATInvocationException(org.gridlab.gat.GATInvocationException) IOException(java.io.IOException) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) JobDescription(org.gridlab.gat.resources.JobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) BufferedReader(java.io.BufferedReader) Job(org.gridlab.gat.resources.Job)

Aggregations

GATObjectCreationException (org.gridlab.gat.GATObjectCreationException)47 GATInvocationException (org.gridlab.gat.GATInvocationException)39 URI (org.gridlab.gat.URI)18 JobDescription (org.gridlab.gat.resources.JobDescription)18 URISyntaxException (java.net.URISyntaxException)17 SoftwareDescription (org.gridlab.gat.resources.SoftwareDescription)17 ResourceBroker (org.gridlab.gat.resources.ResourceBroker)16 FileInterface (org.gridlab.gat.io.FileInterface)14 Job (org.gridlab.gat.resources.Job)14 IOException (java.io.IOException)11 Preferences (org.gridlab.gat.Preferences)9 BufferedReader (java.io.BufferedReader)5 File (java.io.File)5 InputStreamReader (java.io.InputStreamReader)5 FileOutputStream (java.io.FileOutputStream)4 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4 AdaptorNotApplicableException (org.gridlab.gat.AdaptorNotApplicableException)4 GATContext (org.gridlab.gat.GATContext)4 InputStream (java.io.InputStream)3