Search in sources :

Example 1 with JobDefinitionType

use of org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType in project airavata by apache.

the class BESJobSubmissionTask method execute.

@Override
public TaskStatus execute(TaskContext taskContext) {
    TaskStatus taskStatus = new TaskStatus(TaskState.CREATED);
    StorageClient sc = null;
    ProcessContext processContext = taskContext.getParentProcessContext();
    // FIXME - use original output dir
    setInputOutputLocations(processContext);
    try {
        // con't reuse if UserDN has been changed.
        secProperties = getSecurityConfig(processContext);
    // try secProperties = secProperties.clone() if we can't use already initialized ClientConfigurations.
    } catch (GFacException e) {
        String msg = "Unicorn security context initialization error";
        log.error(msg, e);
        taskStatus.setState(TaskState.FAILED);
        taskStatus.setReason(msg);
        return taskStatus;
    }
    try {
        JobSubmissionProtocol protocol = processContext.getJobSubmissionProtocol();
        JobSubmissionInterface jobSubmissionInterface = GFacUtils.getPreferredJobSubmissionInterface(processContext);
        String factoryUrl = null;
        if (protocol.equals(JobSubmissionProtocol.UNICORE)) {
            UnicoreJobSubmission unicoreJobSubmission = GFacUtils.getUnicoreJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
            factoryUrl = unicoreJobSubmission.getUnicoreEndPointURL();
        }
        EndpointReferenceType eprt = EndpointReferenceType.Factory.newInstance();
        eprt.addNewAddress().setStringValue(factoryUrl);
        String userDN = processContext.getProcessModel().getUserDn();
        CreateActivityDocument cad = CreateActivityDocument.Factory.newInstance();
        // create storage
        StorageCreator storageCreator = new StorageCreator(secProperties, factoryUrl, 5, null);
        sc = storageCreator.createStorage();
        JobDefinitionType jobDefinition = JSDLGenerator.buildJSDLInstance(processContext, sc.getUrl()).getJobDefinition();
        cad.addNewCreateActivity().addNewActivityDocument().setJobDefinition(jobDefinition);
        log.info("Submitted JSDL: " + jobDefinition.getJobDescription());
        // copy files to local
        copyInputFilesToLocal(taskContext);
        // upload files if any
        DataTransferrer dt = new DataTransferrer(processContext, sc);
        dt.uploadLocalFiles();
        JobModel jobDetails = new JobModel();
        jobDetails.setTaskId(taskContext.getTaskId());
        jobDetails.setProcessId(taskContext.getProcessId());
        FactoryClient factory = new FactoryClient(eprt, secProperties);
        log.info("Activity Submitting to {} ... \n", factoryUrl);
        CreateActivityResponseDocument response = factory.createActivity(cad);
        log.info("Activity Submitted to {} ... \n", factoryUrl);
        EndpointReferenceType activityEpr = response.getCreateActivityResponse().getActivityIdentifier();
        log.info("Activity : " + activityEpr.getAddress().getStringValue() + " Submitted.");
        // factory.waitWhileActivityIsDone(activityEpr, 1000);
        jobId = WSUtilities.extractResourceID(activityEpr);
        if (jobId == null) {
            jobId = new Long(Calendar.getInstance().getTimeInMillis()).toString();
        }
        log.info("JobID: " + jobId);
        jobDetails.setJobId(jobId);
        jobDetails.setJobDescription(activityEpr.toString());
        jobDetails.setJobStatuses(Arrays.asList(new JobStatus(JobState.SUBMITTED)));
        processContext.setJobModel(jobDetails);
        GFacUtils.saveJobModel(processContext, jobDetails);
        GFacUtils.saveJobStatus(processContext, jobDetails);
        log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), factory.getActivityStatus(activityEpr).toString()));
        waitUntilDone(eprt, activityEpr, processContext, secProperties);
        ActivityStatusType activityStatus = null;
        activityStatus = getStatus(factory, activityEpr);
        log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), activityStatus.getState().toString()));
        ActivityClient activityClient;
        activityClient = new ActivityClient(activityEpr, secProperties);
        // now use the activity working directory property
        dt.setStorageClient(activityClient.getUspaceClient());
        List<OutputDataObjectType> copyOutput = null;
        if ((activityStatus.getState() == ActivityStateEnumeration.FAILED)) {
            String error = activityStatus.getFault().getFaultcode().getLocalPart() + "\n" + activityStatus.getFault().getFaultstring() + "\n EXITCODE: " + activityStatus.getExitCode();
            log.error(error);
            JobState applicationJobStatus = JobState.FAILED;
            jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
            sendNotification(processContext, jobDetails);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            // What if job is failed before execution and there are not stdouts generated yet?
            log.debug("Downloading any standard output and error files, if they were produced.");
            copyOutput = dt.downloadRemoteFiles();
        } else if (activityStatus.getState() == ActivityStateEnumeration.CANCELLED) {
            JobState applicationJobStatus = JobState.CANCELED;
            jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
            GFacUtils.saveJobStatus(processContext, jobDetails);
            throw new GFacException(processContext.getExperimentId() + "Job Canceled");
        } else if (activityStatus.getState() == ActivityStateEnumeration.FINISHED) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ignored) {
            }
            JobState applicationJobStatus = JobState.COMPLETE;
            jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
            GFacUtils.saveJobStatus(processContext, jobDetails);
            log.info("Job Id: {}, exit code: {}, exit status: {}", jobDetails.getJobId(), activityStatus.getExitCode(), ActivityStateEnumeration.FINISHED.toString());
            // if (activityStatus.getExitCode() == 0) {
            // } else {
            // dt.downloadStdOuts();
            // }
            copyOutput = dt.downloadRemoteFiles();
        }
        if (copyOutput != null) {
            copyOutputFilesToStorage(taskContext, copyOutput);
            for (OutputDataObjectType outputDataObjectType : copyOutput) {
                GFacUtils.saveExperimentOutput(processContext, outputDataObjectType.getName(), outputDataObjectType.getValue());
            }
        }
        // dt.publishFinalOutputs();
        taskStatus.setState(TaskState.COMPLETED);
    } catch (AppCatalogException e) {
        log.error("Error while retrieving UNICORE job submission..", e);
        taskStatus.setState(TaskState.FAILED);
    } catch (Exception e) {
        log.error("BES task failed... ", e);
        taskStatus.setState(TaskState.FAILED);
    }
    return taskStatus;
}
Also used : FactoryClient(de.fzj.unicore.bes.client.FactoryClient) JobSubmissionInterface(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface) EndpointReferenceType(org.w3.x2005.x08.addressing.EndpointReferenceType) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) JobStatus(org.apache.airavata.model.status.JobStatus) UnicoreJobSubmission(org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) JobDefinitionType(org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType) JobState(org.apache.airavata.model.status.JobState) JobModel(org.apache.airavata.model.job.JobModel) ActivityClient(de.fzj.unicore.bes.client.ActivityClient) JobSubmissionProtocol(org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol) StorageClient(de.fzj.unicore.uas.client.StorageClient) TaskStatus(org.apache.airavata.model.status.TaskStatus) URISyntaxException(java.net.URISyntaxException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) TaskException(org.apache.airavata.gfac.core.task.TaskException) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) JSchException(com.jcraft.jsch.JSchException) RegistryException(org.apache.airavata.registry.cpi.RegistryException) AiravataException(org.apache.airavata.common.exception.AiravataException) GFacException(org.apache.airavata.gfac.core.GFacException) SSHApiException(org.apache.airavata.gfac.core.SSHApiException) IOException(java.io.IOException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) GFacException(org.apache.airavata.gfac.core.GFacException)

Example 2 with JobDefinitionType

use of org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType in project airavata by apache.

the class ApplicationProcessor method createGenericApplication.

public static void createGenericApplication(JobDefinitionType value, String appName) {
    ApplicationType appType = JSDLUtils.getOrCreateApplication(value);
    appType.setApplicationName(appName);
}
Also used : ApplicationType(org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType)

Example 3 with JobDefinitionType

use of org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType in project airavata by apache.

the class ApplicationProcessor method generateJobSpecificAppElements.

public static void generateJobSpecificAppElements(JobDefinitionType value, ProcessContext context) {
    String userName = getUserNameFromContext(context);
    // if (userName.equalsIgnoreCase("admin")){
    // userName = "CN=zdv575, O=Ultrascan Gateway, C=DE";
    // }
    ApplicationDeploymentDescription appDep = context.getApplicationDeploymentDescription();
    String appname = context.getApplicationInterfaceDescription().getApplicationName();
    ApplicationParallelismType parallelism = appDep.getParallelism();
    ApplicationType appType = JSDLUtils.getOrCreateApplication(value);
    appType.setApplicationName(appname);
    // if (appDep.getSetEnvironment().size() > 0) {
    // createApplicationEnvironment(value, appDep.getSetEnvironment(), parallelism);
    // }
    // 
    String stdout = context.getStdoutLocation();
    String stderr = context.getStderrLocation();
    if (stdout != null) {
        stdout = stdout.substring(stdout.lastIndexOf('/') + 1);
    }
    if (stderr != null) {
        stderr = stderr.substring(stderr.lastIndexOf('/') + 1);
    }
    stdout = (stdout == null || stdout.equals("")) ? "stdout" : stdout;
    stderr = (stdout == null || stderr.equals("")) ? "stderr" : stderr;
    if (appDep.getExecutablePath() != null) {
        FileNameType fNameType = FileNameType.Factory.newInstance();
        fNameType.setStringValue(appDep.getExecutablePath());
        if (isParallelJob(context)) {
            JSDLUtils.getOrCreateSPMDApplication(value).setExecutable(fNameType);
            if (parallelism.equals(ApplicationParallelismType.OPENMP_MPI)) {
                JSDLUtils.getSPMDApplication(value).setSPMDVariation(SPMDVariations.OpenMPI.value());
            } else if (parallelism.equals(ApplicationParallelismType.MPI)) {
                JSDLUtils.getSPMDApplication(value).setSPMDVariation(SPMDVariations.MPI.value());
            }
            // setting number of processes
            try {
                String np = getInputAsString(context, BESConstants.NUMBER_OF_PROCESSES);
                if ((np != null) && (Integer.parseInt(np) > 0)) {
                    NumberOfProcessesType num = NumberOfProcessesType.Factory.newInstance();
                    num.setStringValue(np);
                    JSDLUtils.getSPMDApplication(value).setNumberOfProcesses(num);
                }
            } catch (RuntimeException np) {
            // do nothing
            }
            try {
                // setting processes per host
                String pphost = getInputAsString(context, BESConstants.PROCESSES_PER_HOST);
                if ((pphost != null) && (Integer.parseInt(pphost) > 0)) {
                    ProcessesPerHostType pph = ProcessesPerHostType.Factory.newInstance();
                    pph.setStringValue(String.valueOf(pphost));
                    JSDLUtils.getSPMDApplication(value).setProcessesPerHost(pph);
                }
            } catch (RuntimeException np) {
            // do nothing
            }
            int totalThreadCount = context.getProcessModel().getProcessResourceSchedule().getNumberOfThreads();
            // we take it as threads per processes
            if (totalThreadCount > 0) {
                ThreadsPerProcessType tpp = ThreadsPerProcessType.Factory.newInstance();
                tpp.setStringValue(String.valueOf(totalThreadCount));
                JSDLUtils.getSPMDApplication(value).setThreadsPerProcess(tpp);
            }
            if (userName != null) {
                UserNameType userNameType = UserNameType.Factory.newInstance();
                userNameType.setStringValue(userName);
                JSDLUtils.getSPMDApplication(value).setUserName(userNameType);
            }
            if (stdout != null) {
                FileNameType fName = FileNameType.Factory.newInstance();
                fName.setStringValue(stdout);
                JSDLUtils.getOrCreateSPMDApplication(value).setOutput(fName);
            }
            if (stderr != null) {
                FileNameType fName = FileNameType.Factory.newInstance();
                fName.setStringValue(stderr);
                JSDLUtils.getOrCreateSPMDApplication(value).setError(fName);
            }
        } else {
            JSDLUtils.getOrCreatePOSIXApplication(value).setExecutable(fNameType);
            if (userName != null) {
                UserNameType userNameType = UserNameType.Factory.newInstance();
                userNameType.setStringValue(userName);
                JSDLUtils.getOrCreatePOSIXApplication(value).setUserName(userNameType);
            }
            if (stdout != null) {
                FileNameType fName = FileNameType.Factory.newInstance();
                fName.setStringValue(stdout);
                JSDLUtils.getOrCreatePOSIXApplication(value).setOutput(fName);
            }
            if (stderr != null) {
                FileNameType fName = FileNameType.Factory.newInstance();
                fName.setStringValue(stderr);
                JSDLUtils.getOrCreatePOSIXApplication(value).setError(fName);
            }
        }
    }
}
Also used : ApplicationType(org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType) ApplicationDeploymentDescription(org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription) FileNameType(org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.FileNameType) UserNameType(org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.UserNameType) ThreadsPerProcessType(org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.ThreadsPerProcessType) NumberOfProcessesType(org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.NumberOfProcessesType) ApplicationParallelismType(org.apache.airavata.model.parallelism.ApplicationParallelismType) ProcessesPerHostType(org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.ProcessesPerHostType)

Example 4 with JobDefinitionType

use of org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType in project airavata by apache.

the class JSDLGenerator method buildJSDLInstance.

public static synchronized JobDefinitionDocument buildJSDLInstance(ProcessContext context, String smsUrl, Object jobDirectoryMode) throws Exception {
    JobDefinitionDocument jobDefDoc = JobDefinitionDocument.Factory.newInstance();
    JobDefinitionType value = jobDefDoc.addNewJobDefinition();
    // build Identification
    createJobIdentification(value, context);
    ResourceProcessor.generateResourceElements(value, context);
    ApplicationProcessor.generateJobSpecificAppElements(value, context);
    UASDataStagingProcessor.generateDataStagingElements(value, context, smsUrl);
    return jobDefDoc;
}
Also used : JobDefinitionDocument(org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument) JobDefinitionType(org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType)

Example 5 with JobDefinitionType

use of org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType in project airavata by apache.

the class JSDLGenerator method buildJSDLInstance.

public static synchronized JobDefinitionDocument buildJSDLInstance(ProcessContext context) throws Exception {
    JobDefinitionDocument jobDefDoc = JobDefinitionDocument.Factory.newInstance();
    JobDefinitionType value = jobDefDoc.addNewJobDefinition();
    // build Identification
    createJobIdentification(value, context);
    ResourceProcessor.generateResourceElements(value, context);
    ApplicationProcessor.generateJobSpecificAppElements(value, context);
    return jobDefDoc;
}
Also used : JobDefinitionDocument(org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument) JobDefinitionType(org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType)

Aggregations

POSIXApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.POSIXApplicationType)10 XmlCursor (org.apache.xmlbeans.XmlCursor)8 ApplicationType (org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType)7 JobDefinitionType (org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType)7 JobDefinitionDocument (org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument)6 HPCProfileApplicationType (org.ggf.schemas.jsdl.x2006.x07.jsdlHpcpa.HPCProfileApplicationType)5 SPMDApplicationType (org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.SPMDApplicationType)5 ApplicationDeploymentDescription (org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription)2 URIException (org.apache.commons.httpclient.URIException)2 XmlObject (org.apache.xmlbeans.XmlObject)2 CreationFlagEnumeration (org.ggf.schemas.jsdl.x2005.x11.jsdl.CreationFlagEnumeration)2 DataStagingType (org.ggf.schemas.jsdl.x2005.x11.jsdl.DataStagingType)2 JobDescriptionType (org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDescriptionType)2 JSchException (com.jcraft.jsch.JSchException)1 ActivityClient (de.fzj.unicore.bes.client.ActivityClient)1 FactoryClient (de.fzj.unicore.bes.client.FactoryClient)1 StorageClient (de.fzj.unicore.uas.client.StorageClient)1 ResourceRequestDocument (eu.unicore.jsdl.extensions.ResourceRequestDocument)1 ResourceRequestType (eu.unicore.jsdl.extensions.ResourceRequestType)1 IOException (java.io.IOException)1