Search in sources :

Example 1 with File

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

the class GATJob method processMetricEvent.

// MetricListener interface implementation
@Override
public void processMetricEvent(MetricEvent value) {
    Job job = (Job) value.getSource();
    JobState newJobState = (JobState) value.getValue();
    JobDescription jd = (JobDescription) job.getJobDescription();
    SoftwareDescription sd = jd.getSoftwareDescription();
    Integer jobId = (Integer) sd.getAttributes().get("jobId");
    logger.debug("Processing job ID = " + jobId);
    /*
         * Check if either the job has finished or there has been a submission error. We don't care about other state
         * transitions
         */
    if (newJobState == JobState.STOPPED) {
        if (Tracer.isActivated()) {
            Integer slot = (Integer) sd.getAttributes().get("slot");
            String host = getResourceNode().getHost();
            Tracer.freeSlot(host, slot);
        }
        /*
             * We must check whether the chosen adaptor is globus In that case, since globus doesn't provide the exit
             * status of a job, we must examine the standard error file
             */
        try {
            if (usingGlobus) {
                File errFile = sd.getStderr();
                // Error file should always be in the same host as the IT
                File localFile = GAT.createFile(context, errFile.toGATURI());
                if (localFile.length() > 0) {
                    GATjob = null;
                    RUNNING_JOBS.remove(this);
                    ErrorManager.warn("Error when creating file.");
                    listener.jobFailed(this, JobEndStatus.EXECUTION_FAILED);
                } else {
                    if (!debug) {
                        localFile.delete();
                    }
                    RUNNING_JOBS.remove(this);
                    listener.jobCompleted(this);
                }
            } else {
                if (job.getExitStatus() == 0) {
                    RUNNING_JOBS.remove(this);
                    listener.jobCompleted(this);
                } else {
                    GATjob = null;
                    RUNNING_JOBS.remove(this);
                    listener.jobFailed(this, JobEndStatus.EXECUTION_FAILED);
                }
            }
        } catch (Exception e) {
            ErrorManager.fatal(CALLBACK_PROCESSING_ERR + ": " + this, e);
        }
    } else if (newJobState == JobState.SUBMISSION_ERROR) {
        if (Tracer.isActivated()) {
            Integer slot = (Integer) sd.getAttributes().get("slot");
            String host = getResourceNode().getHost();
            Tracer.freeSlot(host, slot);
        }
        try {
            if (usingGlobus && job.getInfo().get("resManError").equals("NO_ERROR")) {
                RUNNING_JOBS.remove(this);
                listener.jobCompleted(this);
            } else {
                GATjob = null;
                RUNNING_JOBS.remove(this);
                listener.jobFailed(this, JobEndStatus.SUBMISSION_FAILED);
            }
        } catch (GATInvocationException e) {
            ErrorManager.fatal(CALLBACK_PROCESSING_ERR + ": " + this, e);
        }
    }
}
Also used : JobDescription(org.gridlab.gat.resources.JobDescription) GATInvocationException(org.gridlab.gat.GATInvocationException) JobState(org.gridlab.gat.resources.Job.JobState) Job(org.gridlab.gat.resources.Job) File(org.gridlab.gat.io.File) SoftwareDescription(org.gridlab.gat.resources.SoftwareDescription) GATInvocationException(org.gridlab.gat.GATInvocationException)

Example 2 with File

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

the class GATJob method processParameters.

private void processParameters(String sandboxPath, ArrayList<String> symlinks, ArrayList<String> lArgs) {
    logger.debug("Processing parameters for GAT job " + this.jobId);
    lArgs.add(Boolean.toString(taskParams.hasTargetObject()));
    // Add return type
    if (taskParams.hasReturnValue()) {
        Parameter returnParam = taskParams.getParameters()[taskParams.getParameters().length - 1];
        lArgs.add(Integer.toString(returnParam.getType().ordinal()));
    } else {
        lArgs.add("null");
    }
    // Add parameters
    int numParams = taskParams.getParameters().length;
    if (taskParams.hasReturnValue()) {
        numParams--;
    }
    lArgs.add(Integer.toString(numParams));
    for (Parameter param : taskParams.getParameters()) {
        DataType type = param.getType();
        lArgs.add(Integer.toString(type.ordinal()));
        lArgs.add(Integer.toString(param.getStream().ordinal()));
        String prefix = param.getPrefix();
        if (prefix == null || prefix.isEmpty()) {
            prefix = Constants.PREFIX_EMTPY;
        }
        lArgs.add(param.getPrefix());
        switch(type) {
            case FILE_T:
                DependencyParameter dFilePar = (DependencyParameter) param;
                java.io.File f = new java.io.File(dFilePar.getDataTarget());
                if (!f.getName().equals(dFilePar.getOriginalName())) {
                    // Add file to manage symlinks and renames
                    String originalName = sandboxPath + File.separator + dFilePar.getOriginalName();
                    symlinks.add(dFilePar.getDataTarget());
                    symlinks.add(dFilePar.getOriginalName());
                    lArgs.add(originalName);
                } else {
                    // Original and target is the same nothing to do
                    lArgs.add(dFilePar.getDataTarget());
                }
                break;
            case PSCO_T:
            case EXTERNAL_OBJECT_T:
                logger.error("GAT Adaptor does not support PSCO Types");
                listener.jobFailed(this, JobEndStatus.SUBMISSION_FAILED);
                break;
            case OBJECT_T:
                DependencyParameter dPar = (DependencyParameter) param;
                DataAccessId dAccId = dPar.getDataAccessId();
                lArgs.add(dPar.getDataTarget());
                if (dAccId instanceof RAccessId) {
                    lArgs.add("R");
                } else {
                    // for the worker to know it must write the object to disk
                    lArgs.add("W");
                }
                break;
            case STRING_T:
                BasicTypeParameter btParS = (BasicTypeParameter) param;
                // Check spaces
                String value = btParS.getValue().toString();
                int numSubStrings = value.split(" ").length;
                lArgs.add(Integer.toString(numSubStrings));
                lArgs.add(value);
                break;
            default:
                // Basic Types
                BasicTypeParameter btParB = (BasicTypeParameter) param;
                lArgs.add(btParB.getValue().toString());
                break;
        }
    }
}
Also used : BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) RAccessId(es.bsc.compss.types.data.DataAccessId.RAccessId) Parameter(es.bsc.compss.types.parameter.Parameter) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) BasicTypeParameter(es.bsc.compss.types.parameter.BasicTypeParameter) DataType(es.bsc.compss.types.annotations.parameter.DataType) DependencyParameter(es.bsc.compss.types.parameter.DependencyParameter) File(org.gridlab.gat.io.File) DataAccessId(es.bsc.compss.types.data.DataAccessId)

Example 3 with File

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

the class LoadLevelerJob method waitForTrigger.

// Wait for the creation of a special file (by the application).
void waitForTrigger(JobState state) throws GATInvocationException {
    if (triggerDirectory == null) {
        return;
    }
    if (jobName == null) {
        return;
    }
    if (waiter == null) {
        try {
            waiter = FileWaiter.createFileWaiter(GAT.createFile(gatContext, triggerDirectory));
        } catch (GATObjectCreationException e) {
            throw new GATInvocationException("Could not create", e);
        }
    }
    String filename = jobName + "." + state.toString().substring(0, 3);
    File file;
    try {
        file = GAT.createFile(gatContext, triggerDirectory + "/" + filename);
    } catch (GATObjectCreationException e) {
        throw new GATInvocationException("Could not create");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Waiting for " + filename + " in directory " + triggerDirectory);
    }
    waiter.waitFor(filename);
    if (logger.isDebugEnabled()) {
        logger.debug("Finished waiting for " + filename + " in directory " + triggerDirectory);
    }
    synchronized (this.getClass()) {
        if (!file.delete()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not remove " + file.toGATURI());
            }
        }
    }
}
Also used : GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) File(org.gridlab.gat.io.File)

Example 4 with File

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

the class LsfJob method waitForTrigger.

// Wait for the creation of a special file (by the application).
void waitForTrigger(JobState state) throws GATInvocationException {
    if (triggerDirectory == null) {
        return;
    }
    if (jobName == null) {
        return;
    }
    if (waiter == null) {
        try {
            waiter = FileWaiter.createFileWaiter(GAT.createFile(gatContext, triggerDirectory));
        } catch (GATObjectCreationException e) {
            throw new GATInvocationException("Could not create", e);
        }
    }
    String filename = jobName + "." + state.toString().substring(0, 3);
    File file;
    try {
        file = GAT.createFile(gatContext, triggerDirectory + "/" + filename);
    } catch (GATObjectCreationException e) {
        throw new GATInvocationException("Could not create");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Waiting for " + filename + " in directory " + triggerDirectory);
    }
    waiter.waitFor(filename);
    if (logger.isDebugEnabled()) {
        logger.debug("Finished waiting for " + filename + " in directory " + triggerDirectory);
    }
    synchronized (this.getClass()) {
        if (!file.delete()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not remove " + file.toGATURI());
            }
        }
    }
}
Also used : GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) File(org.gridlab.gat.io.File)

Example 5 with File

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

the class FileExample method start.

public void start(URI uri1, URI uri2, URI uri3) {
    File file1 = null;
    try {
        file1 = GAT.createFile(uri1);
    } catch (GATObjectCreationException e) {
        System.err.println("failed to create file1 at location '" + uri1 + "': " + e);
        return;
    }
    try {
        file1.copy(uri2);
        System.out.println("file1 at location '" + uri1 + "' copied to file2 at location '" + uri2 + "'");
    } catch (GATInvocationException e) {
        System.err.println("failed to copy file1 at location '" + uri1 + "' to file2 at location '" + uri2 + "': " + e);
        return;
    }
    file1.delete();
    System.out.println("file1 at location '" + uri1 + "' deleted");
    File file2 = null;
    try {
        file2 = GAT.createFile(uri2);
    } catch (GATObjectCreationException e) {
        System.err.println("failed to create file2 at location '" + uri2 + "': " + e);
        return;
    }
    try {
        file2.move(uri3);
        System.out.println("file2 at location '" + uri2 + "' moved to file3 at location '" + uri3 + "'");
    } catch (GATInvocationException e) {
        System.err.println("failed to move file2 at location '" + uri2 + "' to file3 at location '" + uri3 + "': " + e);
        return;
    }
}
Also used : GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) GATInvocationException(org.gridlab.gat.GATInvocationException) File(org.gridlab.gat.io.File)

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