Search in sources :

Example 6 with File

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

the class TestSubmitGlobus method test.

public void test(final String host) throws Exception {
    final SoftwareDescription sd = new SoftwareDescription();
    sd.setExecutable("/bin/sleep");
    sd.setArguments("10");
    final JobDescription jd = new JobDescription(sd);
    Preferences prefs = new Preferences();
    prefs.put("resourcebroker.adaptor.name", "wsgt4new");
    prefs.put("file.adaptor.name", "local,gridftp");
    CertificateSecurityContext ctxt = new CertificateSecurityContext(new URI(System.getProperty("user.home") + "/.globus/userkey.pem"), new URI(System.getProperty("user.home") + "/.globus/usercert.pem"), getPassphrase());
    final GATContext context = new GATContext();
    context.addPreferences(prefs);
    context.addSecurityContext(ctxt);
    File[] files = new File[NFILES];
    for (int i = 0; i < files.length; i++) {
        files[i] = GAT.createFile(context, "file" + i);
        files[i].createNewFile();
    }
    for (File f : files) {
        sd.addPreStagedFile(f);
        sd.addPostStagedFile(f);
    }
    final ResourceBroker broker = GAT.createResourceBroker(context, new URI(host));
    for (int j = 0; j < NBATCHES; j++) {
        logger.info("Starting a batch of " + NJOBS + " jobs");
        for (int i = 0; i < NJOBS; i++) {
            Thread t = new Thread() {

                public void run() {
                    try {
                        broker.submitJob(jd, TestSubmitGlobus.this, "job.status");
                    } catch (Throwable e) {
                        System.out.println("Submit failed");
                        e.printStackTrace();
                        synchronized (TestSubmitGlobus.this) {
                            finished++;
                            TestSubmitGlobus.this.notifyAll();
                        }
                    }
                }
            };
            t.start();
        }
        synchronized (this) {
            while (finished < NJOBS * (j - BACK)) {
                logger.info("Waiting until at least " + (NJOBS * (j - BACK)) + " jobs are finished");
                try {
                    wait();
                } catch (Throwable e) {
                // ignore
                }
            }
        }
    }
    synchronized (this) {
        while (finished != NJOBS * NBATCHES) {
            try {
                wait();
            } catch (Throwable e) {
            // ignore
            }
        }
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) GATContext(org.gridlab.gat.GATContext) CertificateSecurityContext(org.gridlab.gat.security.CertificateSecurityContext) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) Preferences(org.gridlab.gat.Preferences) URI(org.gridlab.gat.URI) File(org.gridlab.gat.io.File) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 7 with File

use of org.gridlab.gat.io.File 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
        }
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) File(org.gridlab.gat.io.File) URI(org.gridlab.gat.URI) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 8 with File

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

the class SecurityExample method main.

/**
 * This example shows the use of the SecurityContext objects in JavaGAT.
 *
 * This example will attach various security contexts to a GATContext. Then
 * it will try to create the same file with and without this GATContext.
 * Note that you've to replace the arguments of the methods with values that
 * are suitable for your environment. Please don't put passwords and
 * passphrases directly in the source code, but try to retrieve by having
 * the user to type it.
 *
 * @param args
 *                a String representation of a valid JavaGAT uri that points
 *                to a file
 */
public static void main(String[] args) {
    GATContext context = new GATContext();
    try {
        // create a certificate security context
        CertificateSecurityContext globusSecurityContext = new CertificateSecurityContext(new URI("userkey.pem"), new URI("usercert.pem"), "grid-proxy-init passphrase");
        // add a note to this security context; it's only to be used for the
        // globus and wsgt4new adaptors
        globusSecurityContext.addNote("adaptors", "globus,wsgt4new");
        context.addSecurityContext(globusSecurityContext);
    } catch (URISyntaxException e) {
    // ignore
    }
    // create a password security context
    PasswordSecurityContext ftpSecurityContext = new PasswordSecurityContext(System.getProperty("user.name"), "ftp password");
    // add a note to this security context; it's only to be used for ftp and
    // only for two hosts, host1 and host2:21
    ftpSecurityContext.addNote("adaptors", "ftp");
    ftpSecurityContext.addNote("hosts", "host1,host2:21");
    context.addSecurityContext(ftpSecurityContext);
    PasswordSecurityContext sshSecurityContext = new PasswordSecurityContext(System.getProperty("user.name"), "ssh password");
    // add a note to this security context; it's only to be used for
    // sshtrilead and commandlinessh and only for one host, host3
    sshSecurityContext.addNote("adaptors", "sshtrilead,commandlinessh");
    sshSecurityContext.addNote("hosts", "host3");
    context.addSecurityContext(sshSecurityContext);
    // contexts attached
    try {
        File file = GAT.createFile(context, new URI(args[0]));
        System.out.println(args[0] + " exists: " + file.exists());
    } catch (Exception e) {
        System.err.println("Failed to check whether '" + args[0] + "' exists: " + e);
    }
    // contexts.
    try {
        File file2 = GAT.createFile(new URI(args[0]));
        System.out.println(args[0] + " exists: " + file2.exists());
    } catch (Exception e) {
        System.err.println("Failed to check whether '" + args[0] + "' exists: " + e);
    }
}
Also used : GATContext(org.gridlab.gat.GATContext) PasswordSecurityContext(org.gridlab.gat.security.PasswordSecurityContext) CertificateSecurityContext(org.gridlab.gat.security.CertificateSecurityContext) URISyntaxException(java.net.URISyntaxException) URI(org.gridlab.gat.URI) File(org.gridlab.gat.io.File) URISyntaxException(java.net.URISyntaxException)

Example 9 with File

use of org.gridlab.gat.io.File 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();
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) ResourceBroker(org.gridlab.gat.resources.ResourceBroker) Job(org.gridlab.gat.resources.Job) URI(org.gridlab.gat.URI) File(org.gridlab.gat.io.File) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription)

Example 10 with File

use of org.gridlab.gat.io.File 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;
}
Also used : MethodImplementation(es.bsc.compss.types.implementations.MethodImplementation) AbstractMethodImplementation(es.bsc.compss.types.implementations.AbstractMethodImplementation) MPIImplementation(es.bsc.compss.types.implementations.MPIImplementation) RAccessId(es.bsc.compss.types.data.DataAccessId.RAccessId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) OpenCLImplementation(es.bsc.compss.types.implementations.OpenCLImplementation) JobDescription(org.gridlab.gat.resources.JobDescription) TaskDescription(es.bsc.compss.types.TaskDescription) DecafImplementation(es.bsc.compss.types.implementations.DecafImplementation) DataType(es.bsc.compss.types.annotations.parameter.DataType) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription) BinaryImplementation(es.bsc.compss.types.implementations.BinaryImplementation) AbstractMethodImplementation(es.bsc.compss.types.implementations.AbstractMethodImplementation) HardwareResourceDescription(org.gridlab.gat.resources.HardwareResourceDescription) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) LogicalData(es.bsc.compss.types.data.LogicalData) MethodResourceDescription(es.bsc.compss.types.resources.MethodResourceDescription) HardwareResourceDescription(org.gridlab.gat.resources.HardwareResourceDescription) ResourceDescription(org.gridlab.gat.resources.ResourceDescription) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) File(org.gridlab.gat.io.File) OmpSsImplementation(es.bsc.compss.types.implementations.OmpSsImplementation) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Aggregations

File (org.gridlab.gat.io.File)14 URI (org.gridlab.gat.URI)8 JobDescription (org.gridlab.gat.resources.JobDescription)8 SoftwareDescription (org.gridlab.gat.resources.SoftwareDescription)8 ResourceBroker (org.gridlab.gat.resources.ResourceBroker)6 GATContext (org.gridlab.gat.GATContext)5 Job (org.gridlab.gat.resources.Job)5 GATInvocationException (org.gridlab.gat.GATInvocationException)4 CertificateSecurityContext (org.gridlab.gat.security.CertificateSecurityContext)4 GATObjectCreationException (org.gridlab.gat.GATObjectCreationException)3 Preferences (org.gridlab.gat.Preferences)3 DataType (es.bsc.compss.types.annotations.parameter.DataType)2 DataAccessId (es.bsc.compss.types.data.DataAccessId)2 RAccessId (es.bsc.compss.types.data.DataAccessId.RAccessId)2 BasicTypeParameter (es.bsc.compss.types.parameter.BasicTypeParameter)2 DependencyParameter (es.bsc.compss.types.parameter.DependencyParameter)2 Parameter (es.bsc.compss.types.parameter.Parameter)2 HardwareResourceDescription (org.gridlab.gat.resources.HardwareResourceDescription)2 ResourceDescription (org.gridlab.gat.resources.ResourceDescription)2 TaskDescription (es.bsc.compss.types.TaskDescription)1