use of org.gridlab.gat.resources.JobDescription in project compss by bsc-wdc.
the class SubmitJobCallback method start.
public void start(String brokerURI) throws GATObjectCreationException, URISyntaxException, GATInvocationException {
SoftwareDescription sd = new SoftwareDescription();
sd.setExecutable("/bin/hostname");
File stdout = GAT.createFile("hostname.txt");
sd.setStdout(stdout);
JobDescription jd = new JobDescription(sd);
ResourceBroker broker = GAT.createResourceBroker(new URI(brokerURI));
broker.submitJob(jd, this, "job.status");
synchronized (this) {
try {
wait();
} catch (InterruptedException e) {
// ignore
}
}
}
use of org.gridlab.gat.resources.JobDescription in project compss by bsc-wdc.
the class SubmitJobWithMultipleInputs method main.
public static void main(String[] args) throws Exception {
ResourceBroker broker = GAT.createResourceBroker(new URI(args[0]));
SoftwareDescription sd = new SoftwareDescription();
sd.setExecutable(args[1]);
sd.setStdout(GAT.createFile("stdout.txt"));
sd.setStderr(GAT.createFile("stderr.txt"));
String[] arguments = new String[args.length - 2];
for (int i = 2; i < args.length; i++) {
File tmp = GAT.createFile(args[i]);
sd.addPreStagedFile(tmp);
arguments[i - 2] = tmp.getName();
}
sd.setArguments(arguments);
Job job = broker.submitJob(new JobDescription(sd));
while ((job.getState() != JobState.STOPPED) && (job.getState() != JobState.SUBMISSION_ERROR)) {
Thread.sleep(1000);
}
GAT.end();
}
use of org.gridlab.gat.resources.JobDescription in project compss by bsc-wdc.
the class GATJob method prepareJob.
private JobDescription prepareJob() throws Exception {
// Get the information related to the job
logger.debug("Preparing GAT Job " + this.jobId);
TaskDescription taskParams = this.taskParams;
String targetPath = getResourceNode().getInstallDir();
String targetHost = getResourceNode().getHost();
String targetUser = getResourceNode().getUser();
if (userNeeded && !targetUser.isEmpty()) {
targetUser += "@";
} else {
targetUser = "";
}
SoftwareDescription sd = new SoftwareDescription();
sd.setExecutable(targetPath + WORKER_SCRIPT_PATH + WORKER_SCRIPT_NAME);
ArrayList<String> lArgs = new ArrayList<String>();
// Common arguments: language working_dir lib_path num_obsolete [obs1... obsN] tracing [event_type task_id
// slot_id]
lArgs.add(LANG);
lArgs.add(getResourceNode().getWorkingDir());
lArgs.add(getResourceNode().getLibPath());
LogicalData[] obsoleteFiles = getResource().pollObsoletes();
if (obsoleteFiles != null) {
lArgs.add("" + obsoleteFiles.length);
for (LogicalData ld : obsoleteFiles) {
String renaming = ld.getName();
lArgs.add(renaming);
}
} else {
lArgs.add("0");
}
// Check sandbox working dir
boolean isSpecific = false;
String sandboxDir = null;
AbstractMethodImplementation absImpl = (AbstractMethodImplementation) this.impl;
switch(absImpl.getMethodType()) {
case BINARY:
BinaryImplementation binaryImpl = (BinaryImplementation) absImpl;
sandboxDir = binaryImpl.getWorkingDir();
isSpecific = true;
break;
case MPI:
MPIImplementation mpiImpl = (MPIImplementation) absImpl;
sandboxDir = mpiImpl.getWorkingDir();
isSpecific = true;
break;
case DECAF:
DecafImplementation decafImpl = (DecafImplementation) absImpl;
sandboxDir = decafImpl.getWorkingDir();
isSpecific = true;
break;
case OMPSS:
OmpSsImplementation ompssImpl = (OmpSsImplementation) absImpl;
sandboxDir = ompssImpl.getWorkingDir();
isSpecific = true;
break;
case OPENCL:
OpenCLImplementation openclImpl = (OpenCLImplementation) absImpl;
sandboxDir = openclImpl.getWorkingDir();
isSpecific = true;
break;
case METHOD:
sandboxDir = null;
break;
}
if (sandboxDir == null || sandboxDir.isEmpty() || sandboxDir.equals(Constants.UNASSIGNED)) {
sandboxDir = getResourceNode().getWorkingDir() + File.separator + "sandBox" + File.separator + "job_" + this.jobId;
isSpecific = false;
}
// Processing parameters to get symlinks pairs to create (symlinks) and how to pass parameters in the GAT
// Job(paramArgs)
ArrayList<String> symlinks = new ArrayList<>();
ArrayList<String> paramArgs = new ArrayList<>();
processParameters(sandboxDir, symlinks, paramArgs);
// Adding info to create symlinks between renamed files and original names
lArgs.add(Boolean.toString(isSpecific));
lArgs.add(sandboxDir);
if (symlinks.size() > 0) {
lArgs.add(String.valueOf(symlinks.size()));
lArgs.addAll(symlinks);
} else {
lArgs.add("0");
}
lArgs.add(Boolean.toString(Tracer.isActivated()));
lArgs.add(getHostName());
if (debug) {
logger.debug("hostName " + getHostName());
}
if (Tracer.isActivated()) {
// event type
lArgs.add(String.valueOf(Tracer.getTaskEventsType()));
// task id
lArgs.add(String.valueOf(this.taskParams.getId() + 1));
int slot = Tracer.getNextSlot(targetHost);
// slot id
lArgs.add(String.valueOf(slot));
sd.addAttribute("slot", slot);
}
// Language-dependent arguments: taskSandbox_dir app_dir classpath pythonpath debug storage_conf
// method_impl_type method_impl_params
// numSlaves [slave1,..,slaveN] numCus
// has_target num_params par_type_1 par_1 ... par_type_n par_n
lArgs.add(sandboxDir);
lArgs.add(getResourceNode().getAppDir());
lArgs.add(getClasspath());
lArgs.add(getPythonpath());
lArgs.add(String.valueOf(debug));
lArgs.add(STORAGE_CONF);
lArgs.add(String.valueOf(absImpl.getMethodType()));
switch(absImpl.getMethodType()) {
case METHOD:
MethodImplementation methodImpl = (MethodImplementation) absImpl;
lArgs.add(methodImpl.getDeclaringClass());
String methodName = methodImpl.getAlternativeMethodName();
if (methodName == null || methodName.isEmpty()) {
methodName = taskParams.getName();
}
lArgs.add(methodName);
break;
case MPI:
MPIImplementation mpiImpl = (MPIImplementation) absImpl;
lArgs.add(mpiImpl.getMpiRunner());
lArgs.add(mpiImpl.getBinary());
break;
case DECAF:
DecafImplementation decafImpl = (DecafImplementation) absImpl;
lArgs.add(targetPath + DecafImplementation.SCRIPT_PATH);
String dfScript = decafImpl.getDfScript();
if (!dfScript.startsWith(File.separator)) {
String appPath = getResourceNode().getAppDir();
dfScript = appPath + File.separator + dfScript;
}
lArgs.add(dfScript);
String dfExecutor = decafImpl.getDfExecutor();
if (dfExecutor == null || dfExecutor.isEmpty() || dfExecutor.equals(Constants.UNASSIGNED)) {
dfExecutor = "executor.sh";
}
if (!dfExecutor.startsWith(File.separator) && !dfExecutor.startsWith("./")) {
dfExecutor = "./" + dfExecutor;
}
lArgs.add(dfExecutor);
String dfLib = decafImpl.getDfLib();
if (dfLib == null || dfLib.isEmpty()) {
dfLib = Constants.UNASSIGNED;
}
lArgs.add(dfLib);
lArgs.add(decafImpl.getMpiRunner());
break;
case OMPSS:
OmpSsImplementation ompssImpl = (OmpSsImplementation) absImpl;
lArgs.add(ompssImpl.getBinary());
break;
case OPENCL:
OpenCLImplementation openclImpl = (OpenCLImplementation) absImpl;
lArgs.add(openclImpl.getKernel());
break;
case BINARY:
BinaryImplementation binaryImpl = (BinaryImplementation) absImpl;
lArgs.add(binaryImpl.getBinary());
break;
}
// Slave nodes and cus description
lArgs.add(String.valueOf(slaveWorkersNodeNames.size()));
lArgs.addAll(slaveWorkersNodeNames);
lArgs.add(String.valueOf(((MethodResourceDescription) this.impl.getRequirements()).getTotalCPUComputingUnits()));
// Add parameter arguments already processed
lArgs.addAll(paramArgs);
// Conversion vector -> array
String[] arguments = new String[lArgs.size()];
arguments = lArgs.toArray(arguments);
try {
sd.setArguments(arguments);
} catch (NullPointerException e) {
StringBuilder sb = new StringBuilder("Null argument parameter of job " + this.jobId + " " + absImpl.getMethodDefinition() + "\n");
int i = 0;
for (Parameter param : taskParams.getParameters()) {
sb.append("Parameter ").append(i).append("\n");
DataType type = param.getType();
sb.append("\t Type: ").append(param.getType()).append("\n");
if (type == DataType.FILE_T || type == DataType.OBJECT_T) {
DependencyParameter dPar = (DependencyParameter) param;
DataAccessId dAccId = dPar.getDataAccessId();
sb.append("\t Target: ").append(dPar.getDataTarget()).append("\n");
if (type == DataType.OBJECT_T) {
if (dAccId instanceof RAccessId) {
sb.append("\t Direction: " + "R").append("\n");
} else {
// for the worker to know it must write the object to disk
sb.append("\t Direction: " + "W").append("\n");
}
}
} else if (type == DataType.STRING_T) {
BasicTypeParameter btParS = (BasicTypeParameter) param;
// Check spaces
String value = btParS.getValue().toString();
int numSubStrings = value.split(" ").length;
sb.append("\t Num Substrings: " + Integer.toString(numSubStrings)).append("\n");
sb.append("\t Value:" + value).append("\n");
} else {
// Basic types
BasicTypeParameter btParB = (BasicTypeParameter) param;
sb.append("\t Value: " + btParB.getValue().toString()).append("\n");
}
i++;
}
logger.error(sb.toString());
listener.jobFailed(this, JobEndStatus.SUBMISSION_FAILED);
}
sd.addAttribute("jobId", jobId);
// JEA Changed to allow execution in MN
sd.addAttribute(SoftwareDescription.WALLTIME_MAX, absImpl.getRequirements().getWallClockLimit());
if (absImpl.getRequirements().getHostQueues().size() > 0) {
sd.addAttribute(SoftwareDescription.JOB_QUEUE, absImpl.getRequirements().getHostQueues().get(0));
}
sd.addAttribute("coreCount", absImpl.getRequirements().getTotalCPUComputingUnits());
sd.addAttribute("gpuCount", absImpl.getRequirements().getTotalGPUComputingUnits());
sd.addAttribute("fpgaCount", absImpl.getRequirements().getTotalFPGAComputingUnits());
sd.addAttribute(SoftwareDescription.MEMORY_MAX, absImpl.getRequirements().getMemorySize());
// sd.addAttribute(SoftwareDescription.SANDBOX_ROOT, "/tmp/");
sd.addAttribute(SoftwareDescription.SANDBOX_ROOT, getResourceNode().getWorkingDir());
sd.addAttribute(SoftwareDescription.SANDBOX_USEROOT, "true");
sd.addAttribute(SoftwareDescription.SANDBOX_DELETE, "false");
/*
* sd.addAttribute(SoftwareDescription.SANDBOX_PRESTAGE_STDIN, "false");
* sd.addAttribute(SoftwareDescription.SANDBOX_POSTSTAGE_STDOUT, "false");
* sd.addAttribute(SoftwareDescription.SANDBOX_POSTSTAGE_STDERR, "false");
*/
if (debug) {
// Set standard output file for job
File outFile = GAT.createFile(context, Protocol.ANY_URI.getSchema() + File.separator + JOBS_DIR + "job" + jobId + "_" + this.getHistory() + ".out");
sd.setStdout(outFile);
}
if (debug || usingGlobus) {
// Set standard error file for job
File errFile = GAT.createFile(context, Protocol.ANY_URI.getSchema() + File.separator + JOBS_DIR + "job" + jobId + "_" + this.getHistory() + ".err");
sd.setStderr(errFile);
}
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(RES_ATTR, Protocol.ANY_URI.getSchema() + targetUser + targetHost);
attributes.put("Jobname", "compss_remote_job_" + jobId);
ResourceDescription rd = new HardwareResourceDescription(attributes);
if (debug) {
logger.debug("Ready to submit job " + jobId + ":");
logger.debug(" * Host: " + targetHost);
logger.debug(" * Executable: " + sd.getExecutable());
StringBuilder sb = new StringBuilder(" - Arguments:");
for (String arg : sd.getArguments()) {
sb.append(" ").append(arg);
}
logger.debug(sb.toString());
}
JobDescription jd = new JobDescription(sd, rd);
// jd.setProcessCount(method.getRequirements().getProcessorCoreCount());
return jd;
}
use of org.gridlab.gat.resources.JobDescription in project compss by bsc-wdc.
the class GATTracer method startTracing.
public static Job startTracing(GATWorkerNode worker) {
if (DEBUG) {
LOGGER.debug("Starting trace for woker " + worker.getHost());
}
tracingLevel = 1;
int numTasks = worker.getTotalComputingUnits();
if (numTasks <= 0) {
if (DEBUG) {
LOGGER.debug("Resource " + worker.getName() + " has 0 slots, it won't appear in the trace");
}
return null;
}
int hostId = Tracer.registerHost(worker.getName(), numTasks);
String user;
if (worker.getUser() == null || worker.getUser().isEmpty()) {
user = "";
} else {
user = worker.getUser() + "@";
}
SoftwareDescription sd = new SoftwareDescription();
String uriString = Protocol.ANY_URI.getSchema() + user + worker.getHost();
sd.addAttribute("uri", uriString);
sd.setExecutable(worker.getInstallDir() + Tracer.TRACE_SCRIPT_PATH);
sd.setArguments(new String[] { "init", worker.getWorkingDir(), String.valueOf(hostId), String.valueOf(numTasks) });
if (DEBUG) {
try {
org.gridlab.gat.io.File outFile = GAT.createFile(worker.getContext(), Protocol.ANY_URI.getSchema() + File.separator + System.getProperty(COMPSsConstants.APP_LOG_DIR) + traceOutRelativePath);
sd.setStdout(outFile);
org.gridlab.gat.io.File errFile = GAT.createFile(worker.getContext(), Protocol.ANY_URI.getSchema() + File.separator + System.getProperty(COMPSsConstants.APP_LOG_DIR) + traceErrRelativePath);
sd.setStderr(errFile);
} catch (Exception e) {
ErrorManager.warn("Error initializing tracing system in node " + worker.getHost(), e);
return null;
}
}
sd.addAttribute(SoftwareDescription.SANDBOX_ROOT, File.separator + "tmp" + File.separator);
sd.addAttribute(SoftwareDescription.SANDBOX_USEROOT, "true");
sd.addAttribute(SoftwareDescription.SANDBOX_DELETE, "false");
Job job = null;
try {
URI brokerURI = new URI(uriString);
ResourceBroker broker = GAT.createResourceBroker(worker.getContext(), brokerURI);
LOGGER.debug("Starting tracer init job for worker " + uriString + " submited.");
job = broker.submitJob(new JobDescription(sd));
} catch (Exception e) {
ErrorManager.warn("Error initializing tracing system in node " + worker.getHost(), e);
return null;
}
return job;
}
use of org.gridlab.gat.resources.JobDescription in project compss by bsc-wdc.
the class LoadLevelerResourceBrokerAdaptor method submitJob.
/*
* (non-Javadoc)
*
* @see org.gridlab.gat.resources.ResourceBroker#submitJob(org.gridlab.gat.resources.JobDescription)
*/
public Job submitJob(AbstractJobDescription abstractDescription, MetricListener listener, String metricDefinitionName) throws GATInvocationException {
if (!(abstractDescription instanceof JobDescription)) {
throw new GATInvocationException("can only handle JobDescriptions: " + abstractDescription.getClass());
}
JobDescription description = (JobDescription) abstractDescription;
SoftwareDescription sd = description.getSoftwareDescription();
if (sd == null) {
throw new GATInvocationException("The job description does not contain a software description");
}
if (description.getProcessCount() < 1) {
throw new GATInvocationException("Adaptor cannot handle: process count < 1: " + description.getProcessCount());
}
if (description.getResourceCount() != 1) {
throw new GATInvocationException("Adaptor cannot handle: resource count > 1: " + description.getResourceCount());
}
String home = System.getProperty("user.home");
if (home == null) {
throw new GATInvocationException("loadleveler broker could not get user home dir");
}
Sandbox sandbox = new Sandbox(gatContext, description, "localhost", home, true, true, false, false);
LoadLevelerJob loadlevelerJob = new LoadLevelerJob(gatContext, description, sandbox);
Job job = null;
if (description instanceof WrapperJobDescription) {
WrapperJobCpi tmp = new WrapperJobCpi(gatContext, loadlevelerJob, listener, metricDefinitionName);
listener = tmp;
job = tmp;
} else {
job = loadlevelerJob;
}
if (listener != null && metricDefinitionName != null) {
Metric metric = loadlevelerJob.getMetricDefinitionByName(metricDefinitionName).createMetric(null);
loadlevelerJob.addMetricListener(listener, metric);
}
loadlevelerJob.setState(Job.JobState.PRE_STAGING);
loadlevelerJob.waitForTrigger(Job.JobState.PRE_STAGING);
sandbox.prestage();
String exe;
if (sandbox.getResolvedExecutable() != null) {
exe = sandbox.getResolvedExecutable().getPath();
// try to set the executable bit, it might be lost
/* CDIAZ: The command "exe" can be also in a remote host
* The command must have the right permissions in the remote host
try {
new CommandRunner("chmod", "+x", exe);
} catch (Throwable t) {
// ignore
}
*/
} else {
exe = getExecutable(description);
}
String[] args = getArgumentsArray(description);
// Directory where the loadleveler command will be executed
java.io.File f = new java.io.File(sandbox.getSandboxPath());
if (!f.exists()) {
throw new GATInvocationException("Unable to find directory " + f.getAbsolutePath());
}
// Check and set the environment for a blaunch command
Map<String, Object> env = sd.getEnvironment();
this.prepareBLaunchEnv(env);
// Encapsulate the original command into a blaunch command
String host = brokerURI.getHost();
String newExe = this.getLoadLevelerCommand();
String[] newArgs = this.getLoadLevelerArgs(host, exe, args);
System.out.println("[AFTER] exe: " + newExe);
System.out.println("[AFTER] llspawan.stdio args:");
for (int i = 0; i < newArgs.length; i++) System.out.print(" " + newArgs[i]);
System.out.println();
ProcessBundle bundle = new ProcessBundle(description.getProcessCount(), newExe, newArgs, f, env);
loadlevelerJob.setSubmissionTime();
loadlevelerJob.setState(Job.JobState.SCHEDULED);
try {
loadlevelerJob.setState(Job.JobState.RUNNING);
loadlevelerJob.waitForTrigger(Job.JobState.RUNNING);
loadlevelerJob.setStartTime();
bundle.startBundle();
loadlevelerJob.setProcess(bundle);
if (logger.isDebugEnabled()) {
logger.debug("Job with PID: " + LOADL_PID + " is executed on host " + host);
}
} catch (IOException e) {
throw new CommandNotFoundException("LoadLevelerResourceBrokerAdaptor", e);
}
if (!sd.streamingStderrEnabled()) {
try {
if (sd.getStderr() != null) {
OutputStream err = GAT.createFileOutputStream(gatContext, sd.getStderr());
// to file
StreamForwarder forwarder = new StreamForwarder(bundle.getStderr(), err, sd.getExecutable() + " [stderr]");
loadlevelerJob.setErrorStream(forwarder);
if (logger.isDebugEnabled()) {
logger.debug("Created stderr forwarder to file " + sd.getStderr());
}
} else {
// or throw it away
new StreamForwarder(bundle.getStderr(), null, sd.getExecutable() + " [stderr]");
}
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Unable to create file output stream for stderr!", e);
}
}
if (!sd.streamingStdoutEnabled()) {
// read away the stdout
try {
if (sd.getStdout() != null) {
// to file
OutputStream out = GAT.createFileOutputStream(gatContext, sd.getStdout());
StreamForwarder forwarder = new StreamForwarder(bundle.getStdout(), out, sd.getExecutable() + " [stdout]");
loadlevelerJob.setOutputStream(forwarder);
if (logger.isDebugEnabled()) {
logger.debug("Created stdout forwarder to file " + sd.getStdout());
}
} else {
// or throw it away
new StreamForwarder(bundle.getStdout(), null, sd.getExecutable() + " [stdout]");
}
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Unable to create file output stream for stdout!", e);
}
}
if (!sd.streamingStdinEnabled() && sd.getStdin() != null) {
// forward the stdin from file
try {
InputStream in = GAT.createFileInputStream(gatContext, sd.getStdin());
bundle.setStdin(sd.getExecutable(), in);
} catch (GATObjectCreationException e) {
throw new GATInvocationException("Unable to create file input stream for stdin!", e);
}
}
loadlevelerJob.monitorState();
return job;
}
Aggregations