Search in sources :

Example 16 with GATInvocationException

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

the class SshLsfResourceBrokerAdaptor method sshLsfSubmission.

/*private java.io.File createJobScript(JobDescription description)
			throws GATInvocationException {

		java.io.File temp;

		SoftwareDescription sd = description.getSoftwareDescription();

		try {
			temp = java.io.File.createTempFile("lsf-sub", null);
		} catch (IOException e) {
			throw new GATInvocationException("Cannot create file", e);
		}
		PrintWriter job = null;
		try {
			job = new PrintWriter(new BufferedWriter(new FileWriter(temp)));

			job.print("#!/bin/sh\n");
			job.print("# job script\n");

			// Support DIRECTORY
			String dir = sd.getStringAttribute(SoftwareDescription.DIRECTORY, null);
			if (dir != null) {
				job.print("cd " + dir + "\n");
			}

			// Support environment.
			Map<String, Object> env = sd.getEnvironment();
			if (env != null) {
				Set<String> s = env.keySet();
				Object[] keys = s.toArray();

				for (int i = 0; i < keys.length; i++) {
					String val = (String) env.get(keys[i]);
					job.print(keys[i] + "=" + val + " && export " + keys[i] + "\n");
				}
			}

			// Construct command.
			StringBuffer cmd = new StringBuffer();

			cmd.append(sd.getExecutable().toString());
			if (sd.getArguments() != null) {
				String[] args = sd.getArguments();
				for (int i = 0; i < args.length; ++i) {
					cmd.append(" ");
					cmd.append(args[i]);
				}
			}
			job.print(cmd.toString() + "\n");
			//job.print("exit $?\n");
		} catch (Throwable e) {
			throw new GATInvocationException(
					"Cannot create temporary job script file "
							+ temp.getAbsolutePath(), e);
		} finally {
			if (job != null)
				job.close();
		}
		return temp;
	}*/
private String sshLsfSubmission(SshLSFJob lsfJob, JobDescription description, java.io.File bsubFile, ResourceBroker subBroker, Sandbox sandbox) throws GATInvocationException {
    java.io.File slurmResultFile = null;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("***** Doing sandbox prestage " + sandbox.getSandboxPath());
        }
        sandbox.prestage();
        if (logger.isDebugEnabled()) {
            logger.debug("***** Sandbox prestage done " + sandbox.getSandboxPath());
        }
        // Create sbatch job
        SoftwareDescription sd = new SoftwareDescription();
        sd.setExecutable("sh");
        sd.setArguments("-c", "bsub < " + bsubFile.getName() + " 2>submit.err");
        // + " && rm -rf " + bsubFile.getName() + " submit.err");
        sd.setAttributes(description.getSoftwareDescription().getAttributes());
        sd.addAttribute(SoftwareDescription.SANDBOX_USEROOT, "true");
        slurmResultFile = java.io.File.createTempFile("GAT", "tmp");
        try {
            sd.setStdout(GAT.createFile(gatContext, new URI(slurmResultFile.toURI())));
            sd.addPreStagedFile(GAT.createFile(gatContext, new URI(bsubFile.toURI())));
        } catch (Throwable e1) {
            try {
                sandbox.removeSandboxDir();
            } catch (Throwable e) {
            // ignore
            }
            throw new GATInvocationException("Could not create GAT object for temporary " + slurmResultFile.getAbsolutePath(), e1);
        }
        // sd.addAttribute(SoftwareDescription.DIRECTORY, sd.getStringAttribute(SoftwareDescription, defaultVal)));
        JobDescription jd = new JobDescription(sd);
        if (logger.isDebugEnabled()) {
            logger.debug("Submitting lsf job: " + sd);
        }
        Job job = subBroker.submitJob(jd, this, "job.status");
        if (logger.isDebugEnabled()) {
            logger.debug("Job submitted.");
        }
        synchronized (job) {
            while (job.getState() != Job.JobState.STOPPED && job.getState() != Job.JobState.SUBMISSION_ERROR) {
                try {
                    job.wait();
                } catch (InterruptedException e) {
                // ignore
                }
            }
        }
        if (job.getState() != Job.JobState.STOPPED || job.getExitStatus() != 0) {
            try {
                sandbox.removeSandboxDir();
            } catch (Throwable e) {
            // ignore
            }
            logger.debug("jobState = " + job.getState() + ", exit status = " + job.getExitStatus());
            throw new GATInvocationException("Could not submit LSF job");
        }
        // submit success.
        BufferedReader in = new BufferedReader(new FileReader(slurmResultFile.getAbsolutePath()));
        String result = in.readLine();
        if (logger.isDebugEnabled()) {
            logger.debug("bsub result line = " + result);
        }
        // Check for LSF bsub result ...
        // TODO Check if LSF return the same
        String job_prefix = "Job <";
        if (result.contains(job_prefix)) {
            int i = result.indexOf(job_prefix);
            result = result.substring(i + job_prefix.length(), result.indexOf(">", i));
        }
        return result;
    } catch (IOException e) {
        try {
            sandbox.removeSandboxDir();
        } catch (Throwable e1) {
        // ignore
        }
        throw new GATInvocationException("Got IOException", e);
    } finally {
        slurmResultFile.delete();
        bsubFile.delete();
    }
}
Also used : IOException(java.io.IOException) URI(org.gridlab.gat.URI) File(java.io.File) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) JobDescription(org.gridlab.gat.resources.JobDescription) WrapperJobDescription(org.gridlab.gat.resources.WrapperJobDescription) AbstractJobDescription(org.gridlab.gat.resources.AbstractJobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Job(org.gridlab.gat.resources.Job)

Example 17 with GATInvocationException

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

the class SshLsfResourceBrokerAdaptor method createJobStarter.

private java.io.File createJobStarter(JobDescription description, int nproc, java.io.File jobScript) throws GATInvocationException {
    java.io.File temp;
    SoftwareDescription sd = description.getSoftwareDescription();
    try {
        temp = java.io.File.createTempFile("lsf", null);
    } catch (IOException e) {
        throw new GATInvocationException("Cannot create file", e);
    }
    PrintWriter job = null;
    try {
        job = new PrintWriter(new BufferedWriter(new FileWriter(temp)));
        job.print("#!/bin/sh\n");
        job.print("# Job starter script.\n");
        job.print("# The jobs are distributed over the available nodes in round-robin fashion.\n");
        job.print("GAT_MYDIR=`pwd`\n");
        job.print("case X$LSB_HOSTS in\n");
        job.print("X)  GAT_HOSTS=$HOSTNAME\n");
        job.print("    ;;\n");
        job.print("*)  GAT_HOSTS=`cat $LSB_HOSTS | sed 's/ .*//'`\n");
        job.print("    ;;\n");
        job.print("esac\n");
        job.print("GAT_JOBNO=1\n");
        job.print("GAT_JOBS=" + nproc + "\n");
        job.print("set $GAT_HOSTS\n");
        job.print("shift\n");
        job.print("while :\n");
        job.print("do\n");
        job.print("  for GAT_HOST in \"$@\"\n");
        job.print("  do\n");
        job.print("    echo #!/bin/sh > .gat_script.$GAT_JOBNO\n");
        job.print("    echo cd $GAT_MYDIR >> .gat_script.$GAT_JOBNO\n");
        job.print("    echo trap \\\"touch .gat_done.$GAT_JOBNO\\\" 0 1 2 3 15 >> .gat_script.$GAT_JOBNO\n");
        job.print("    cat " + jobScript.getName() + " >> .gat_script.$GAT_JOBNO\n");
        job.print("    chmod +x .gat_script.$GAT_JOBNO\n");
        job.print("    ssh -o StrictHostKeyChecking=false $GAT_HOST \"$GAT_MYDIR/.gat_script.$GAT_JOBNO");
        if (sd.getStdin() != null) {
            job.print(" < $GAT_MYDIR/" + sd.getStdin().getName());
        } else {
            job.print(" < /dev/null");
        }
        job.print(" > $GAT_MYDIR/.out.$GAT_JOBNO 2>$GAT_MYDIR/.err.$GAT_JOBNO &\"\n");
        job.print("    GAT_JOBNO=`expr $GAT_JOBNO + 1`\n");
        job.print("    if expr $GAT_JOBNO \\>= $GAT_JOBS > /dev/null ; then break 2 ; fi\n");
        job.print("  done\n");
        job.print("  set $GAT_HOSTS\n");
        job.print("done\n");
    } catch (Throwable e) {
        throw new GATInvocationException("Cannot create temporary job starter file " + temp.getAbsolutePath(), e);
    } finally {
        if (job != null)
            job.close();
    }
    return temp;
}
Also used : GATInvocationException(org.gridlab.gat.GATInvocationException) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 18 with GATInvocationException

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

the class AllFileAdaptorsTest method printResults.

private static void printResults(AdaptorTestResult[] results, String host) throws IOException {
    File outFile = new File("File-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 19 with GATInvocationException

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

the class AllFileOutputStreamAdaptorsTest method printResults.

private static void printResults(AdaptorTestResult[] results, String host) throws IOException {
    File outFile = new File("FileOutputStream-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 20 with GATInvocationException

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

the class FileAdaptorTest method canWriteTest.

private AdaptorTestResultEntry canWriteTest(GATContext gatContext, Preferences preferences, String host, String filename, int tabs, boolean correctValue) {
    FileInterface file = null;
    try {
        file = GAT.createFile(gatContext, preferences, "any://" + host + "/" + filename).getFileInterface();
    } catch (GATObjectCreationException e) {
        return new AdaptorTestResultEntry(false, 0, e);
    }
    long start = System.currentTimeMillis();
    boolean writable;
    try {
        writable = file.canWrite();
    } catch (GATInvocationException e) {
        return new AdaptorTestResultEntry(false, 0, e);
    }
    long stop = System.currentTimeMillis();
    return new AdaptorTestResultEntry(writable == correctValue, (stop - start), null);
}
Also used : FileInterface(org.gridlab.gat.io.FileInterface) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException)

Aggregations

GATInvocationException (org.gridlab.gat.GATInvocationException)64 GATObjectCreationException (org.gridlab.gat.GATObjectCreationException)46 URISyntaxException (java.net.URISyntaxException)25 SoftwareDescription (org.gridlab.gat.resources.SoftwareDescription)24 URI (org.gridlab.gat.URI)23 JobDescription (org.gridlab.gat.resources.JobDescription)23 File (java.io.File)22 IOException (java.io.IOException)21 Job (org.gridlab.gat.resources.Job)19 ResourceBroker (org.gridlab.gat.resources.ResourceBroker)17 FileInterface (org.gridlab.gat.io.FileInterface)14 BufferedReader (java.io.BufferedReader)7 FileOutputStream (java.io.FileOutputStream)6 ArrayList (java.util.ArrayList)6 PrintWriter (java.io.PrintWriter)5 InputStreamReader (java.io.InputStreamReader)4 StringWriter (java.io.StringWriter)4 AdaptorNotApplicableException (org.gridlab.gat.AdaptorNotApplicableException)4 Preferences (org.gridlab.gat.Preferences)4 File (org.gridlab.gat.io.File)4