Package org.globus.gram

Examples of org.globus.gram.GramAttributes


    private static final Logger log = LoggerFactory.getLogger(GramJobSubmissionListener.class);

    public static GramJob setupEnvironment(JobExecutionContext jobExecutionContext) throws GFacProviderException {
        log.debug("Searching for Gate Keeper");
        try {
            GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(jobExecutionContext);
            String rsl = jobAttr.toRSL();

            log.debug("RSL = " + rsl);
            GramJob job = new GramJob(rsl);
            return job;
        } catch (ToolsException te) {
View Full Code Here


    ;

    public static GramAttributes configureRemoteJob(JobExecutionContext context) throws ToolsException {
        HpcApplicationDeploymentType app = (HpcApplicationDeploymentType) context.getApplicationContext().getApplicationDeploymentDescription().getType();
        GramAttributes jobAttr = new GramAttributes();
        jobAttr.setExecutable(app.getExecutableLocation());
        jobAttr.setDirectory(app.getStaticWorkingDirectory());
        jobAttr.setStdout(app.getStandardOutput());
        jobAttr.setStderr(app.getStandardError());

        /*
         * The env here contains the env of the host and the application. i.e the env specified in the host description
         * and application description documents
         */
        NameValuePairType[] env = app.getApplicationEnvironmentArray();
        if (env.length != 0) {
            Map<String, String> nv = new HashMap<String, String>();
            for (int i = 0; i < env.length; i++) {
                String key = env[i].getName();
                String value = env[i].getValue();
                nv.put(key, value);
            }

            for (Map.Entry<String, String> entry : nv.entrySet()) {
                jobAttr.addEnvVariable(entry.getKey(), entry.getValue());
            }
        }
        jobAttr.addEnvVariable(Constants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory());
        jobAttr.addEnvVariable(Constants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory());

        if (app.getMaxWallTime() > 0) {
            log.debug("Setting max wall clock time to " + app.getMaxWallTime());

            if (app.getMaxWallTime() > 30 && app.getQueue() != null && app.getQueue().getQueueName().equals("debug")) {
                throw new ToolsException("NCSA debug Queue only support jobs < 30 minutes");
            }

            jobAttr.setMaxWallTime(app.getMaxWallTime());
            jobAttr.set("proxy_timeout", "1");
        } else {
            jobAttr.setMaxWallTime(30);
        }

        if (app.getStandardInput() != null && !"".equals(app.getStandardInput())) {
            jobAttr.setStdin(app.getStandardInput());
        } else {
            MessageContext input = context.getInMessageContext();;
            Map<String,Object> inputs = input.getParameters();
            Set<String> keys = inputs.keySet();
            for (String paramName : keys ) {
                ActualParameter actualParameter = (ActualParameter) inputs.get(paramName);
                if ("URIArray".equals(actualParameter.getType().getType().toString())) {
                    String[] values = ((URIArrayType) actualParameter.getType()).getValueArray();
                    for (String value : values) {
                        jobAttr.addArgument(value);
                    }
                } else {
                    String paramValue = MappingFactory.toString(actualParameter);
                    jobAttr.addArgument(paramValue);
                }
            }
        }
        // Using the workflowContext Header values if user provided them in the request and overwrite the default values in DD
        //todo finish the scheduling based on workflow execution context
        ContextHeaderDocument.ContextHeader currentContextHeader = context.getContextHeader();
        if(currentContextHeader != null){
        if (currentContextHeader.getWorkflowSchedulingContext() != null) {
            if (currentContextHeader != null &&
                    currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray() != null &&
                    currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray().length > 0) {
                try {
                    int cpuCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getCpuCount();
                    if(cpuCount>0){
                        app.setCpuCount(cpuCount);
                    }
                } catch (NullPointerException e) {
                    log.debug("No Value sent in WorkflowContextHeader for CPU Count, value in the Deployment Descriptor will be used");
                    new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
                }
                try {
                    int nodeCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getNodeCount();
                    if(nodeCount>0){
                        app.setNodeCount(nodeCount);
                    }
                } catch (NullPointerException e) {
                    log.debug("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                     new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
                }
                try {
                    String queueName = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getQueueName();
                    if (queueName != null) {
                        if(app.getQueue() == null){
                            QueueType queueType = app.addNewQueue();
                            queueType.setQueueName(queueName);
                        }else{
                            app.getQueue().setQueueName(queueName);
                        }
                    }
                } catch (NullPointerException e) {
                    log.debug("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                     new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
                }
            }
        }
        if(currentContextHeader.getWorkflowOutputDataHandling() != null){
            if(currentContextHeader.getWorkflowOutputDataHandling().getApplicationOutputDataHandlingArray().length != 0)
            app.setOutputDataDirectory(currentContextHeader.getWorkflowOutputDataHandling().getApplicationOutputDataHandlingArray()[0].getOutputDataDirectory());
        }
        }
        if (app.getNodeCount() > 0) {
            jobAttr.set("hostCount", String.valueOf(app.getNodeCount()));
            log.debug("Setting number of Nodes to " + app.getCpuCount());
        }
        if (app.getCpuCount() > 0) {
            log.debug("Setting number of procs to " + app.getCpuCount());
            jobAttr.setNumProcs(app.getCpuCount());
        }
        if (app.getMinMemory() > 0) {
            log.debug("Setting minimum memory to " + app.getMinMemory());
            jobAttr.setMinMemory(app.getMinMemory());
        }
        if (app.getMaxMemory() > 0) {
            log.debug("Setting maximum memory to " + app.getMaxMemory());
            jobAttr.setMaxMemory(app.getMaxMemory());
        }
        if (app.getProjectAccount() != null) {
            if (app.getProjectAccount().getProjectAccountNumber() != null) {
                log.debug("Setting project to " + app.getProjectAccount().getProjectAccountNumber());
                jobAttr.setProject(app.getProjectAccount().getProjectAccountNumber());
            }
        }
        if (app.getQueue() != null) {
            if (app.getQueue().getQueueName() != null) {
                log.debug("Setting job queue to " + app.getQueue().getQueueName());
                jobAttr.setQueue(app.getQueue().getQueueName());
            }
        }
        String jobType = JobType.SINGLE.toString();
        if (app.getJobType() != null) {
            jobType = app.getJobType().toString();
        }
        if (jobType.equalsIgnoreCase(JobType.SINGLE.toString())) {
            log.debug("Setting job type to single");
            jobAttr.setJobType(GramAttributes.JOBTYPE_SINGLE);
        } if (jobType.equalsIgnoreCase(JobType.SERIAL.toString())) {
            log.debug("Setting job type to single");
            jobAttr.setJobType(GramAttributes.JOBTYPE_SINGLE);
        } else if (jobType.equalsIgnoreCase(JobType.MPI.toString())) {
            log.debug("Setting job type to mpi");
            jobAttr.setJobType(GramAttributes.JOBTYPE_MPI);
        } else if (jobType.equalsIgnoreCase(JobType.MULTIPLE.toString())) {
            log.debug("Setting job type to multiple");
            jobAttr.setJobType(GramAttributes.JOBTYPE_MULTIPLE);
        } else if (jobType.equalsIgnoreCase(JobType.CONDOR.toString())) {
            jobAttr.setJobType(GramAttributes.JOBTYPE_CONDOR);
        }

        return jobAttr;
    }
View Full Code Here

    try {
      GSSCredential gssCred = ((GSISecurityContext) context.getSecurityContext()).getGssCredentails();

      log.info("Host desc = " + context.getExecutionModel().getHostDesc().xmlText());

      GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(context);
      rsl = jobAttr.toRSL();
      job = new GramJob(rsl);
      job.setCredentials(gssCred);

      log.info("RSL = " + rsl);
View Full Code Here

    }
  }

  public static void syncFileSystem(String host, GSSCredential gssCred) {
    try {
      GramAttributes gramAttr = new GramAttributes();
      gramAttr.setExecutable("/bin/sync");
      GramJob job = new GramJob(gramAttr.toRSL());
      job.setCredentials(gssCred);
      log.info("RSL = " + job.getRSL());
      try {
        Gram.request(host, job, false, false);
      } catch (Exception e) {
View Full Code Here

public class GramRSLGenerator {
  protected final static Logger log = LoggerFactory.getLogger(GramRSLGenerator.class);
  private enum JobType{SINGLE,MPI,MULTIPLE,CONDOR};
 
  public static GramAttributes configureRemoteJob(ExecutionContext appExecContext) throws GfacException {
    GramAttributes jobAttr = new GramAttributes();
    jobAttr.setExecutable(appExecContext.getExecutionModel().getExecutable());
    jobAttr.setDirectory(appExecContext.getExecutionModel().getWorkingDir());
    jobAttr.setStdout(appExecContext.getExecutionModel().getStdOut());
    jobAttr.setStderr(appExecContext.getExecutionModel().getStderr());

    // The env here contains the env of the host and the application. i.e
    // the env specified in
    // the host description and application description documents
    Map<String, String> nv = appExecContext.getExecutionModel().getEnv();

    for (String key : nv.keySet()) {
      jobAttr.addEnvVariable(key, nv.get(key));
   

    jobAttr.addEnvVariable(GFacConstants.INPUT_DATA_DIR, appExecContext.getExecutionModel().getInputDataDir());
        String outputDataDir = GFacConstants.OUTPUT_DATA_DIR;
        if(!outputDataDir.isEmpty()){
    jobAttr.addEnvVariable(outputDataDir, appExecContext.getExecutionModel().getOutputDataDir());
        }
    ApplicationDescriptionType app = appExecContext.getExecutionModel().getAplicationDesc();
    WorkflowContextHeader contextHeader = appExecContext.getWorkflowHeader();
    ResourceMapping resourceMapping = null;
    if (contextHeader != null) {
      resourceMapping = contextHeader.getResourceMappings().getResourceMappingArray(0);
    }

    log.info("Configure using App Desc = " + app.xmlText());
    if (resourceMapping != null && resourceMapping.getMaxWallTime() > 0) {
      log.info("Header Setting Max Wall Time" + resourceMapping.getMaxWallTime());
      jobAttr.setMaxWallTime(resourceMapping.getMaxWallTime());

    } else if (app.getMaxWallTime() > 0) {
      log.info("Setting max wall clock time to " + app.getMaxWallTime());

      if (app.getMaxWallTime() > 30 && app.getQueue() != null && app.getQueue().equals("debug")) {
        throw new GfacException("NCSA debug Queue only support jobs < 30 minutes", FaultCode.InvalidConfig);
      }

      jobAttr.setMaxWallTime(app.getMaxWallTime());
      jobAttr.set("proxy_timeout", "1");
    } else {
      jobAttr.setMaxWallTime(29);
    }

    if (appExecContext.getExecutionModel().getStdIn() != null) {
      jobAttr.setStdin(appExecContext.getExecutionModel().getStdIn());
    } else {
      Iterator<String> values = appExecContext.getExecutionModel().getInputParameters().iterator();
      while (values.hasNext()) {
        jobAttr.addArgument(values.next());
      }
    }
   
    if (resourceMapping != null && resourceMapping.getNodeCount() > 0) {
      log.info("Setting number of procs to " + resourceMapping.getNodeCount());
      jobAttr.set("hostCount", String.valueOf(resourceMapping.getNodeCount()));
    }else if (app.getHostCount() > 1) {
      jobAttr.set("hostCount", String.valueOf(app.getHostCount()));
    }
    if (resourceMapping != null && resourceMapping.getCpuCount() > 0) {
      log.info("Setting host count to " + resourceMapping.getCpuCount());
      jobAttr.setNumProcs(resourceMapping.getCpuCount());
     
    } else if (app.getCount() > 1) {
      log.info("Setting number of procs to " + app.getCount());
      jobAttr.setNumProcs(app.getCount());
    }

    if (app.getProject() != null && app.getProject().getProjectName() != null) {
      log.info("Setting project to " + app.getProject());
      jobAttr.setProject(app.getProject().getProjectName());
    }

    if (resourceMapping != null && resourceMapping.getQueueName() != null) {
      jobAttr.setQueue(resourceMapping.getQueueName());
    } else if (app.getQueue() != null && app.getQueue().getQueueName() != null) {
      log.info("Setting job queue to " + app.getQueue());
      jobAttr.setQueue(app.getQueue().getQueueName());
    }
    String jobType = JobType.SINGLE.toString() ;

    if (app.getJobType() != null) {
      jobType = app.getJobType().toString();
    }
    if (jobType.equalsIgnoreCase(JobType.SINGLE.toString())) {
      log.info("Setting job type to single");
      jobAttr.setJobType(GramAttributes.JOBTYPE_SINGLE);
    } else if (jobType.equalsIgnoreCase(JobType.MPI.toString())) {
      log.info("Setting job type to mpi");
      jobAttr.setJobType(GramAttributes.JOBTYPE_MPI);
    } else if (jobType.equalsIgnoreCase(JobType.MULTIPLE.toString())) {
      log.info("Setting job type to multiple");
      jobAttr.setJobType(GramAttributes.JOBTYPE_MULTIPLE);
    } else if (jobType.equalsIgnoreCase(JobType.CONDOR.toString())) {
      jobAttr.setJobType(GramAttributes.JOBTYPE_CONDOR);
    }

    // Support to add the Additional RSL parameters
    RSLParmType[] rslParams = app.getRslparmArray();
    if (rslParams.length > 0) {
      for (RSLParmType rslType : rslParams) {
        log.info("Adding rsl param of [" + rslType.getName() + "," + rslType.getStringValue() + "]");
        if (rslType.getName() != "") {
          jobAttr.set(rslType.getName(), rslType.getStringValue());
        }
      }
    }

    // support urgency/SPRUCE case
    // only add spruce rsl parameter if this host has a spruce jobmanager
    // configured
    if (appExecContext.getWorkflowHeader() != null && appExecContext.getWorkflowHeader().getURGENCY() != null
        //&& GfacUtils.getSpruceGatekeeper(appExecContext) != null
        ) {
      jobAttr.set("urgency", appExecContext.getWorkflowHeader().getURGENCY());
    }

    return jobAttr;
  }
View Full Code Here

            }
    }

    public static void syncFileSystem(String host, GSSCredential gssCred)  {
        try {
            GramAttributes gramAttr = new GramAttributes();
            gramAttr.setExecutable("/bin/sync");
            GramJob job = new GramJob(gramAttr.toRSL());
            job.setCredentials(gssCred);
            logger.info("RSL = " + job.getRSL());
            try {
                Gram.request(host, job, false, false);
            } catch (Exception e) {
View Full Code Here

            gateKeeper = tmp[0];
        }
        log.debug("Using Globus GateKeeper " + gateKeeper);

        try {
            GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(invocationContext);
            String rsl = jobAttr.toRSL();

            log.debug("RSL = " + rsl);

            job = new GramJob(rsl);
            listener = new JobSubmissionListener(job, invocationContext);
View Full Code Here

    ;

    public static GramAttributes configureRemoteJob(InvocationContext context) throws ToolsException {
        HpcApplicationDeploymentType app = (HpcApplicationDeploymentType) context.getExecutionDescription().getApp().getType();
        GramAttributes jobAttr = new GramAttributes();
        jobAttr.setExecutable(app.getExecutableLocation());
        jobAttr.setDirectory(app.getStaticWorkingDirectory());
        jobAttr.setStdout(app.getStandardOutput());
        jobAttr.setStderr(app.getStandardError());

        /*
         * The env here contains the env of the host and the application. i.e the env specified in the host description
         * and application description documents
         */
        NameValuePairType[] env = app.getApplicationEnvironmentArray();
        if (env.length != 0) {
            Map<String, String> nv = new HashMap<String, String>();
            for (int i = 0; i < env.length; i++) {
                String key = env[i].getName();
                String value = env[i].getValue();
                nv.put(key, value);
            }

            for (Entry<String, String> entry : nv.entrySet()) {
                jobAttr.addEnvVariable(entry.getKey(), entry.getValue());
            }
        }
        jobAttr.addEnvVariable(GFacConstants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory());
        jobAttr.addEnvVariable(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory());

        if (app.getMaxWallTime() > 0) {
            log.debug("Setting max wall clock time to " + app.getMaxWallTime());

            if (app.getMaxWallTime() > 30 && app.getQueue() != null && app.getQueue().getQueueName().equals("debug")) {
                throw new ToolsException("NCSA debug Queue only support jobs < 30 minutes");
            }

            jobAttr.setMaxWallTime(app.getMaxWallTime());
            jobAttr.set("proxy_timeout", "1");
        } else {
            jobAttr.setMaxWallTime(30);
        }

        if (app.getStandardInput() != null && !"".equals(app.getStandardInput())) {
            jobAttr.setStdin(app.getStandardInput());
        } else {
            MessageContext<Object> input = context.getInput();
            for (Iterator<String> iterator = input.getNames(); iterator.hasNext(); ) {
                String paramName = iterator.next();
                ActualParameter actualParameter = (ActualParameter) input.getValue(paramName);
                if ("URIArray".equals(actualParameter.getType().getType().toString())) {
                    String[] values = ((URIArrayType) actualParameter.getType()).getValueArray();
                    for (String value : values) {
                        jobAttr.addArgument(value);
                    }
                } else {
                    String paramValue = input.getStringValue(paramName);
                    jobAttr.addArgument(paramValue);
                }
            }
        }
        // Using the workflowContext Header values if user provided them in the request and overwrite the default values in DD
        ContextHeaderDocument.ContextHeader currentContextHeader = WorkflowContextHeaderBuilder.getCurrentContextHeader();
        if (currentContextHeader.getWorkflowSchedulingContext() != null) {
            if (currentContextHeader != null &&
                    currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray() != null &&
                    currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray().length > 0) {
                try {
                    int cpuCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getCpuCount();
                    if(cpuCount>0){
                        app.setCpuCount(cpuCount);
                    }
                } catch (NullPointerException e) {
                    log.debug("No Value sent in WorkflowContextHeader for CPU Count, value in the Deployment Descriptor will be used");
                    context.getExecutionContext().getNotifier().executionFail(context, e, "No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                }
                try {
                    int nodeCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getNodeCount();
                    if(nodeCount>0){
                        app.setNodeCount(nodeCount);
                    }
                } catch (NullPointerException e) {
                    log.debug("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                    context.getExecutionContext().getNotifier().executionFail(context, e, "No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                }
                try {
                    String queueName = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getQueueName();
                    if (queueName != null) {
                        if(app.getQueue() == null){
                            QueueType queueType = app.addNewQueue();
                            queueType.setQueueName(queueName);
                        }else{
                            app.getQueue().setQueueName(queueName);
                        }
                    }
                } catch (NullPointerException e) {
                    log.debug("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                    context.getExecutionContext().getNotifier().executionFail(context, e, "No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                }
            }
        }
        if(currentContextHeader.getWorkflowOutputDataHandling() != null){
            if(currentContextHeader.getWorkflowOutputDataHandling().getApplicationOutputDataHandlingArray().length != 0)
            app.setOutputDataDirectory(currentContextHeader.getWorkflowOutputDataHandling().getApplicationOutputDataHandlingArray()[0].getOutputDataDirectory());
        }
        if (app.getNodeCount() > 0) {
            jobAttr.set("hostCount", String.valueOf(app.getNodeCount()));
            log.debug("Setting number of Nodes to " + app.getCpuCount());
        }
        if (app.getCpuCount() > 0) {
            log.debug("Setting number of procs to " + app.getCpuCount());
            jobAttr.setNumProcs(app.getCpuCount());
        }
        if (app.getMinMemory() > 0) {
            log.debug("Setting minimum memory to " + app.getMinMemory());
            jobAttr.setMinMemory(app.getMinMemory());
        }
        if (app.getMaxMemory() > 0) {
            log.debug("Setting maximum memory to " + app.getMaxMemory());
            jobAttr.setMaxMemory(app.getMaxMemory());
        }
        if (app.getProjectAccount() != null) {
            if (app.getProjectAccount().getProjectAccountNumber() != null) {
                log.debug("Setting project to " + app.getProjectAccount().getProjectAccountNumber());
                jobAttr.setProject(app.getProjectAccount().getProjectAccountNumber());
            }
        }
        if (app.getQueue() != null) {
            if (app.getQueue().getQueueName() != null) {
                log.debug("Setting job queue to " + app.getQueue().getQueueName());
                jobAttr.setQueue(app.getQueue().getQueueName());
            }
        }
        String jobType = JobType.SINGLE.toString();
        if (app.getJobType() != null) {
            jobType = app.getJobType().toString();
        }
        if (jobType.equalsIgnoreCase(JobType.SINGLE.toString())) {
            log.debug("Setting job type to single");
            jobAttr.setJobType(GramAttributes.JOBTYPE_SINGLE);
        } if (jobType.equalsIgnoreCase(JobType.SERIAL.toString())) {
            log.debug("Setting job type to single");
            jobAttr.setJobType(GramAttributes.JOBTYPE_SINGLE);
        } else if (jobType.equalsIgnoreCase(JobType.MPI.toString())) {
            log.debug("Setting job type to mpi");
            jobAttr.setJobType(GramAttributes.JOBTYPE_MPI);
        } else if (jobType.equalsIgnoreCase(JobType.MULTIPLE.toString())) {
            log.debug("Setting job type to multiple");
            jobAttr.setJobType(GramAttributes.JOBTYPE_MULTIPLE);
        } else if (jobType.equalsIgnoreCase(JobType.CONDOR.toString())) {
            jobAttr.setJobType(GramAttributes.JOBTYPE_CONDOR);
        }

        return jobAttr;
    }
View Full Code Here

            gateKeeper = tmp[0];
        }
        log.info("Using Globus GateKeeper " + gateKeeper);

        try {
            GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(invocationContext);
            String rsl = jobAttr.toRSL();

            log.info("RSL = " + rsl);

            job = new GramJob(rsl);
            listener = new JobSubmissionListener(job, invocationContext);
View Full Code Here

    ;

    public static GramAttributes configureRemoteJob(InvocationContext context) throws ToolsException {
        GramApplicationDeploymentType app = (GramApplicationDeploymentType) context.getExecutionDescription().getApp().getType();
        GramAttributes jobAttr = new GramAttributes();
        jobAttr.setExecutable(app.getExecutableLocation());
        jobAttr.setDirectory(app.getStaticWorkingDirectory());
        jobAttr.setStdout(app.getStandardOutput());
        jobAttr.setStderr(app.getStandardError());

        /*
         * The env here contains the env of the host and the application. i.e the env specified in the host description
         * and application description documents
         */
        NameValuePairType[] env = app.getApplicationEnvironmentArray();
        if (env.length != 0) {
            Map<String, String> nv = new HashMap<String, String>();
            for (int i = 0; i < env.length; i++) {
                String key = env[i].getName();
                String value = env[i].getValue();
                nv.put(key, value);
            }

            for (Entry<String, String> entry : nv.entrySet()) {
                jobAttr.addEnvVariable(entry.getKey(), entry.getValue());
            }
        }
        jobAttr.addEnvVariable(GFacConstants.INPUT_DATA_DIR_VAR_NAME, app.getInputDataDirectory());
        jobAttr.addEnvVariable(GFacConstants.OUTPUT_DATA_DIR_VAR_NAME, app.getOutputDataDirectory());

        if (app.getMaxWallTime() > 0) {
            log.info("Setting max wall clock time to " + app.getMaxWallTime());

            if (app.getMaxWallTime() > 30 && app.getQueue() != null && app.getQueue().getQueueName().equals("debug")) {
                throw new ToolsException("NCSA debug Queue only support jobs < 30 minutes");
            }

            jobAttr.setMaxWallTime(app.getMaxWallTime());
            jobAttr.set("proxy_timeout", "1");
        } else {
            jobAttr.setMaxWallTime(30);
        }

        if (app.getStandardInput() != null && !"".equals(app.getStandardInput())) {
            jobAttr.setStdin(app.getStandardInput());
        } else {
            MessageContext<Object> input = context.getInput();
            for (Iterator<String> iterator = input.getNames(); iterator.hasNext(); ) {
                String paramName = iterator.next();
                ActualParameter actualParameter = (ActualParameter) input.getValue(paramName);
                if ("URIArray".equals(actualParameter.getType().getType().toString())) {
                    String[] values = ((URIArrayType) actualParameter.getType()).getValueArray();
                    for (String value : values) {
                        jobAttr.addArgument(value);
                    }
                } else {
                    String paramValue = input.getStringValue(paramName);
                    jobAttr.addArgument(paramValue);
                }
            }
        }
        // Using the workflowContext Header values if user provided them in the request and overwrite the default values in DD
        ContextHeaderDocument.ContextHeader currentContextHeader = WorkflowContextHeaderBuilder.getCurrentContextHeader();
        if (currentContextHeader.getWorkflowSchedulingContext() != null) {
            if (currentContextHeader != null &&
                    currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray() != null &&
                    currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray().length > 0) {
                try {
                    int cpuCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getCpuCount();
                    if(cpuCount>0){
                        app.setCpuCount(cpuCount);
                    }
                } catch (NullPointerException e) {
                    log.info("No Value sent in WorkflowContextHeader for CPU Count, value in the Deployment Descriptor will be used");
                    context.getExecutionContext().getNotifier().executionFail(context, e, "No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                }
                try {
                    int nodeCount = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getNodeCount();
                    if(nodeCount>0){
                        app.setNodeCount(nodeCount);
                    }
                } catch (NullPointerException e) {
                    log.info("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                    context.getExecutionContext().getNotifier().executionFail(context, e, "No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                }
                try {
                    String queueName = currentContextHeader.getWorkflowSchedulingContext().getApplicationSchedulingContextArray()[0].getQueueName();
                    if (queueName != null) {
                        if(app.getQueue() == null){
                            QueueType queueType = app.addNewQueue();
                            queueType.setQueueName(queueName);
                        }else{
                            app.getQueue().setQueueName(queueName);
                        }
                    }
                } catch (NullPointerException e) {
                    log.info("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                    context.getExecutionContext().getNotifier().executionFail(context, e, "No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used");
                }
            }
        }
        if (app.getNodeCount() > 0) {
            jobAttr.set("hostCount", String.valueOf(app.getNodeCount()));
            log.info("Setting number of Nodes to " + app.getCpuCount());
        }
        if (app.getCpuCount() > 0) {
            log.info("Setting number of procs to " + app.getCpuCount());
            jobAttr.setNumProcs(app.getCpuCount());
        }
        if (app.getMinMemory() > 0) {
            log.info("Setting minimum memory to " + app.getMinMemory());
            jobAttr.setMinMemory(app.getMinMemory());
        }
        if (app.getMaxMemory() > 0) {
            log.info("Setting maximum memory to " + app.getMaxMemory());
            jobAttr.setMaxMemory(app.getMaxMemory());
        }
        if (app.getProjectAccount() != null) {
            if (app.getProjectAccount().getProjectAccountNumber() != null) {
                log.info("Setting project to " + app.getProjectAccount().getProjectAccountNumber());
                jobAttr.setProject(app.getProjectAccount().getProjectAccountNumber());
            }
        }
        if (app.getQueue() != null) {
            if (app.getQueue().getQueueName() != null) {
                System.out.println("Testing");
                log.info("Setting job queue to " + app.getQueue().getQueueName());
                jobAttr.setQueue(app.getQueue().getQueueName());
            }
        }
        String jobType = JobType.SINGLE.toString();
        if (app.getJobType() != null) {
            jobType = app.getJobType().toString();
        }
        if (jobType.equalsIgnoreCase(JobType.SINGLE.toString())) {
            log.info("Setting job type to single");
            jobAttr.setJobType(GramAttributes.JOBTYPE_SINGLE);
        } if (jobType.equalsIgnoreCase(JobType.SERIAL.toString())) {
            log.info("Setting job type to single");
            jobAttr.setJobType(GramAttributes.JOBTYPE_SINGLE);
        } else if (jobType.equalsIgnoreCase(JobType.MPI.toString())) {
            log.info("Setting job type to mpi");
            jobAttr.setJobType(GramAttributes.JOBTYPE_MPI);
        } else if (jobType.equalsIgnoreCase(JobType.MULTIPLE.toString())) {
            log.info("Setting job type to multiple");
            jobAttr.setJobType(GramAttributes.JOBTYPE_MULTIPLE);
        } else if (jobType.equalsIgnoreCase(JobType.CONDOR.toString())) {
            jobAttr.setJobType(GramAttributes.JOBTYPE_CONDOR);
        }

        return jobAttr;
    }
View Full Code Here

TOP

Related Classes of org.globus.gram.GramAttributes

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.