You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2014/05/21 19:56:36 UTC

[22/51] [abbrv] moving gfac-bes classes to new package.

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/FileUploader.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/FileUploader.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/FileUploader.java
new file mode 100644
index 0000000..6c62053
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/FileUploader.java
@@ -0,0 +1,245 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Map;
+
+import org.unigrids.services.atomic.types.ProtocolType;
+
+import de.fzj.unicore.uas.client.FileTransferClient;
+import de.fzj.unicore.uas.client.StorageClient;
+import de.fzj.unicore.uas.client.UFTPConstants;
+import de.fzj.unicore.uas.client.UFTPFileTransferClient;
+import de.fzj.unicore.uas.fts.FiletransferOptions.IMonitorable;
+
+/**
+ * upload local file(s) to a remote location
+ *
+ * @author schuller
+ */
+public class FileUploader extends FileTransferBase{
+
+	public FileUploader(String from, String to, Mode mode)throws FileNotFoundException{
+		this(from,to,mode,true);
+	}
+
+	public FileUploader(String from, String to, Mode mode, boolean failOnError)throws FileNotFoundException{
+		this.to=to;
+		this.from=from;
+		this.mode=mode;
+		this.failOnError=failOnError;
+		checkOK();
+	}
+
+	public String getFrom() {
+		return from;
+	}
+
+	public String getTo() {
+		return to;
+	}
+
+
+	public void perform(StorageClient sms)throws Exception{
+		File fileSpec=new File(from);
+		boolean hasWildCards=false;
+		boolean isDirectory=fileSpec.isDirectory();
+		File[] fileset=null;
+		
+		if(!isDirectory){
+			hasWildCards=hasWildCards(fileSpec);
+		}
+		
+		chosenProtocol=sms.findSupportedProtocol(preferredProtocols.toArray(new ProtocolType.Enum[preferredProtocols.size()]));
+		Map<String,String>extraParameters=makeExtraParameters(chosenProtocol);
+
+		if(!hasWildCards && !isDirectory){
+			//single regular file
+			uploadFile(fileSpec,to,sms,chosenProtocol,extraParameters);
+			return;
+		}
+		
+		//handle wildcards or directory
+		if(hasWildCards){
+			fileset=resolveWildCards(fileSpec);
+		}
+		else{
+			fileset=fileSpec.listFiles();
+		}
+		
+		if(!isValidDirectory(to, sms)){
+			throw new IOException("The specified remote target '"+to+"' is not a directory");
+		}
+		if(to==null)to="/";
+		String target=isDirectory?to+"/"+fileSpec.getName():to;
+		sms.createDirectory(target);
+		uploadFiles(fileset,target,sms,chosenProtocol,extraParameters);
+	}
+
+	/**
+	 * upload a set of files to a remote directory (which must exist)
+	 * 
+	 * @param files
+	 * @param remoteDirectory
+	 * @param sms
+	 * @param protocol
+	 * @param extraParameters
+	 * @param msg
+	 * @throws Exception
+	 */
+	private void uploadFiles(File[]files, String remoteDirectory, StorageClient sms, ProtocolType.Enum protocol, 
+			Map<String,String>extraParameters)throws Exception{
+		for(File localFile: files){
+			String target=remoteDirectory+"/"+localFile.getName();
+			if(localFile.isDirectory()){
+				if(!recurse){
+					System.out.println("Skipping directory "+localFile.getAbsolutePath());
+				}else{
+					File[] fileset=localFile.listFiles();
+					sms.createDirectory(target);
+					uploadFiles(fileset,target,sms,protocol,extraParameters);
+				}
+			}else{
+				uploadFile(localFile,target,sms,protocol,extraParameters);
+			}
+		}
+	}
+
+	/**
+	 * uploads a single regular file
+	 * 
+	 * @param localFile
+	 * @param remotePath
+	 * @param sms
+	 * @param protocol
+	 * @param extraParameters
+	 * @param msg
+	 * @throws Exception
+	 */
+	private void uploadFile(File localFile, String remotePath, StorageClient sms, ProtocolType.Enum protocol, 
+			Map<String,String>extraParameters) throws Exception{
+		long startTime=System.currentTimeMillis();
+		FileInputStream is=null;
+		FileTransferClient ftc=null;
+		try{
+			if(remotePath==null){
+				remotePath="/"+localFile.getName();
+			}
+			else if(remotePath.endsWith("/")){
+				remotePath+=localFile.getName();
+			}
+			System.out.println("Uploading local file '"+localFile.getAbsolutePath()+"' -> '"+sms.getUrl()+"#"+remotePath+"'");
+			is=new FileInputStream(localFile.getAbsolutePath());
+			boolean append=Mode.append.equals(mode);
+			ftc=sms.getImport(remotePath, append, extraParameters, protocol);
+			configure(ftc, extraParameters);
+			if(append)ftc.setAppend(true);
+			String url=ftc.getUrl();
+			System.out.println("File transfer URL : "+url);
+//			ProgressBar p=null;
+			if(ftc instanceof IMonitorable){
+				long size=localFile.length();
+				if(isRange()){
+					size=getRangeSize();
+				}
+//				p=new ProgressBar(localFile.getName(),size,msg);
+//				((IMonitorable) ftc).setProgressListener(p);
+			}
+			if(isRange()){
+				System.out.println("Byte range: "+startByte+" - "+(getRangeSize()>0?endByte:""));
+				long skipped=0;
+				while(skipped<startByte){
+					skipped+=is.skip(startByte);
+				}
+				ftc.writeAllData(is, endByte-startByte+1);
+				
+			}else{
+				ftc.writeAllData(is);
+			}
+			copyProperties(localFile, sms, remotePath);
+			
+//			if(ftc instanceof IMonitorable){
+//				p.finish();
+//			}
+			
+		}finally{
+			if(ftc!=null){
+				try{
+					ftc.destroy();
+				}catch(Exception e1){
+//					msg.error("Could not clean-up the filetransfer at <"+ftc.getUrl()+">",e1);
+				}
+			}
+			try{ if(is!=null)is.close(); }catch(Exception ignored){}
+		}
+		if(timing){
+			long duration=System.currentTimeMillis()-startTime;
+			double rate=(double)localFile.length()/(double)duration;
+			System.out.println("Rate: "+rate+ " kB/sec.");
+		}
+	}
+
+	/**
+	 * if possible, copy the local executable flag to the remote file
+	 * @param sourceFile - local file
+	 * @throws Exception
+	 */
+	private void copyProperties(File sourceFile, StorageClient sms, String target)throws Exception{
+		boolean x=sourceFile.canExecute();
+		try{
+			if(x){
+				sms.changePermissions(target, true, true, x);
+			}
+		}catch(Exception ex){
+//			System.out.println("Can't set exectuable flag on remote file.",ex);
+		}
+	}
+
+	private void checkOK()throws FileNotFoundException{
+		if(!failOnError){
+			return;
+		}
+		File orig=new File(from);
+		if(!orig.isAbsolute()){
+			orig=new File(System.getProperty("user.dir"),from);
+		}
+		File[] files=resolveWildCards(orig);
+		if(files==null){
+			throw new FileNotFoundException("Local import '"+from+"' does not exist.");
+		}
+		for(File f: files){
+			if(!f.exists())throw new FileNotFoundException("Local import '"+from+"' does not exist.");
+		}
+	}
+	
+	private void configure(FileTransferClient ftc, Map<String,String>params){
+		if(ftc instanceof UFTPFileTransferClient){
+			UFTPFileTransferClient u=(UFTPFileTransferClient)ftc;
+			String secret=params.get(UFTPConstants.PARAM_SECRET);
+			u.setSecret(secret);
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/JSDLGenerator.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/JSDLGenerator.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/JSDLGenerator.java
new file mode 100644
index 0000000..5c0b832
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/JSDLGenerator.java
@@ -0,0 +1,103 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.airavata.gfac.bes.utils;
+
+
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * Utility class generates a JSDL instance from JobExecutionContext instance
+ * @author shahbaz memon
+ * 
+ * */
+
+public class JSDLGenerator {
+	
+	protected final Logger log = LoggerFactory.getLogger(this.getClass());
+	
+	
+	public synchronized static JobDefinitionDocument buildJSDLInstance(JobExecutionContext context) throws Exception {
+
+		JobDefinitionDocument jobDefDoc = JobDefinitionDocument.Factory
+				.newInstance();
+		JobDefinitionType value = jobDefDoc.addNewJobDefinition();
+
+		HpcApplicationDeploymentType appDepType = (HpcApplicationDeploymentType) context
+				.getApplicationContext().getApplicationDeploymentDescription()
+				.getType();
+
+		// build Identification
+		createJobIdentification(value, appDepType);
+		
+		ResourceProcessor.generateResourceElements(value, context);
+		
+		ApplicationProcessor.generateJobSpecificAppElements(value, context);
+		
+		DataStagingProcessor.generateDataStagingElements(value, context);
+		
+		
+		return jobDefDoc;
+	}
+
+
+	public synchronized static JobDefinitionDocument buildJSDLInstance(JobExecutionContext context, String smsUrl) throws Exception {
+
+		JobDefinitionDocument jobDefDoc = JobDefinitionDocument.Factory
+				.newInstance();
+		JobDefinitionType value = jobDefDoc.addNewJobDefinition();
+
+		HpcApplicationDeploymentType appDepType = (HpcApplicationDeploymentType) context
+				.getApplicationContext().getApplicationDeploymentDescription()
+				.getType();
+
+		// build Identification
+		createJobIdentification(value, appDepType);
+		
+		ResourceProcessor.generateResourceElements(value, context);
+		
+		ApplicationProcessor.generateJobSpecificAppElements(value, context);
+		
+		UASDataStagingProcessor.generateDataStagingElements(value, context, smsUrl);
+		
+		return jobDefDoc;
+	}
+
+	private static void createJobIdentification(JobDefinitionType value, HpcApplicationDeploymentType appDepType){
+		if( appDepType.getProjectAccount() != null ){
+			
+			if (appDepType.getProjectAccount().getProjectAccountNumber() != null)
+				JSDLUtils.addProjectName(value, appDepType.getProjectAccount()
+						.getProjectAccountNumber());
+
+			if (appDepType.getProjectAccount().getProjectAccountDescription() != null)
+				JSDLUtils.getOrCreateJobIdentification(value).setDescription(
+						appDepType.getProjectAccount()
+								.getProjectAccountDescription());
+		}
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/JSDLUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/JSDLUtils.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/JSDLUtils.java
new file mode 100644
index 0000000..a5cd2a2
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/JSDLUtils.java
@@ -0,0 +1,540 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+
+import javax.xml.namespace.QName;
+
+import org.apache.commons.httpclient.URIException;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.ApplicationType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.BoundaryType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.CPUArchitectureType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.CandidateHostsType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.CreationFlagEnumeration;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.DataStagingType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.ExactType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDescriptionType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobIdentificationType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.OperatingSystemType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.OperatingSystemTypeEnumeration;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.OperatingSystemTypeType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.ProcessorArchitectureEnumeration;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.ResourcesType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.SourceTargetType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.EnvironmentType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.POSIXApplicationDocument;
+import org.ggf.schemas.jsdl.x2005.x11.jsdlPosix.POSIXApplicationType;
+import org.ggf.schemas.jsdl.x2006.x07.jsdlHpcpa.HPCProfileApplicationDocument;
+import org.ggf.schemas.jsdl.x2006.x07.jsdlHpcpa.HPCProfileApplicationType;
+import org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.SPMDApplicationDocument;
+import org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.SPMDApplicationType;
+
+
+/**
+ * 
+ * @author shahbaz memon, bastian demuth
+ *
+ */
+public class JSDLUtils
+{
+
+	public static final int FLAG_OVERWRITE = 1;
+	public static final int FLAG_APPEND = 2;
+	public static final int FLAG_DELETE_ON_TERMINATE = 32;
+
+	public static final QName POSIX_APPLICATION=POSIXApplicationDocument.type.getDocumentElementName();
+	
+	public static final QName HPC_PROFILE_APPLICATION=HPCProfileApplicationDocument.type.getDocumentElementName();
+	
+	public static final QName SPMD_APPLICATION=SPMDApplicationDocument.type.getDocumentElementName();
+	
+	public static final String PROCESSESPERHOST = "ProcessesPerHost"; 
+	public static final String NUMBEROFPROCESSES = "NumberOfProcesses";
+	public static final String THREADSPERHOST = "ThreadsPerHost";
+
+	
+	
+	public static EnvironmentType addEnvVariable(JobDefinitionType def,String name, String value) {
+		POSIXApplicationType posixApp = getOrCreatePOSIXApplication(def);
+		EnvironmentType newEnv = posixApp.addNewEnvironment();
+		newEnv.setName(name);
+		newEnv.setStringValue(value);
+		return newEnv;
+	}
+
+	public static void setApplicationName(JobDefinitionType value, String applicationName) {
+		getOrCreateApplication(value).setApplicationName(applicationName);
+	}
+
+	public static void setApplicationVersion(JobDefinitionType value, String applicationVersion) {
+		getOrCreateApplication(value).setApplicationVersion(applicationVersion);
+	}
+
+	public static void addProjectName(JobDefinitionType value, String projectName) {
+		getOrCreateJobIdentification(value).addNewJobProject().setStringValue(projectName);
+	}
+	
+	public static void addMultipleProjectNames(JobDefinitionType value, String[] projectNames) {
+		for (String name : projectNames) {
+			getOrCreateJobIdentification(value).addNewJobProject().setStringValue(name);
+		}
+	}
+
+	public static void addCandidateHost(JobDefinitionType value, String host) {
+		getOrCreateCandidateHosts(value).addHostName(host);
+
+	}
+	public static void addDataStagingTargetElement(JobDefinitionType value, String fileSystem, String file, String uri) {
+		addDataStagingTargetElement(value,fileSystem, file, uri, 0);
+	}
+
+	public static void addDataStagingTargetElement(JobDefinitionType value, String fileSystem, String file, String uri, int flags) {
+		JobDescriptionType jobDescr = getOrCreateJobDescription(value);
+		DataStagingType newDS = jobDescr.addNewDataStaging();
+		CreationFlagEnumeration.Enum creationFlag = CreationFlagEnumeration.DONT_OVERWRITE;
+		if((flags & FLAG_OVERWRITE) != 0) creationFlag = CreationFlagEnumeration.OVERWRITE;
+		if((flags & FLAG_APPEND) != 0) creationFlag = CreationFlagEnumeration.APPEND;
+		boolean deleteOnTerminate = (flags & FLAG_DELETE_ON_TERMINATE) != 0;
+		newDS.setCreationFlag(creationFlag);
+		newDS.setDeleteOnTermination(deleteOnTerminate);
+		SourceTargetType target = newDS.addNewTarget();
+
+		try {
+			uri = (uri == null) ? null : URIUtils.encodeAll(uri);
+		} catch (URIException e) {
+		}
+		target.setURI(uri);
+		newDS.setFileName(file);
+		if (fileSystem != null && !fileSystem.equals("Work")) {  //$NON-NLS-1$
+			newDS.setFilesystemName(fileSystem);
+		}
+	}
+
+	public static void addDataStagingSourceElement(JobDefinitionType value, String uri, String fileSystem, String file) {
+		addDataStagingSourceElement(value, uri, fileSystem, file, 0);
+	}
+
+	public static void addDataStagingSourceElement(JobDefinitionType value, String uri, String fileSystem, String file, int flags) {
+		JobDescriptionType jobDescr = getOrCreateJobDescription(value);
+
+		try {
+			uri = (uri == null) ? null : URIUtils.encodeAll(uri);
+		} catch (URIException e) {
+		}
+		DataStagingType newDS = jobDescr.addNewDataStaging();
+		CreationFlagEnumeration.Enum creationFlag = CreationFlagEnumeration.DONT_OVERWRITE;
+		if((flags & FLAG_OVERWRITE) != 0) creationFlag = CreationFlagEnumeration.OVERWRITE;
+		if((flags & FLAG_APPEND) != 0) creationFlag = CreationFlagEnumeration.APPEND;
+		boolean deleteOnTerminate = (flags & FLAG_DELETE_ON_TERMINATE) != 0;
+		newDS.setCreationFlag(creationFlag);
+		newDS.setDeleteOnTermination(deleteOnTerminate);
+		SourceTargetType source = newDS.addNewSource();
+		source.setURI(uri);
+		newDS.setFileName(file);
+		if (fileSystem != null && !fileSystem.equals("Work")) {  //$NON-NLS-1$
+			newDS.setFilesystemName(fileSystem);
+		}
+	}
+
+
+	public static ApplicationType getOrCreateApplication(JobDefinitionType value) {
+		JobDescriptionType jobDescr = getOrCreateJobDescription(value);
+		if (!jobDescr.isSetApplication()) {
+			jobDescr.addNewApplication();
+		}
+		return jobDescr.getApplication();
+	}
+
+	public static CandidateHostsType getOrCreateCandidateHosts(JobDefinitionType value) {
+		ResourcesType resources = getOrCreateResources(value);
+		if (!resources.isSetCandidateHosts()) {
+			resources.addNewCandidateHosts();
+		}
+		return resources.getCandidateHosts();
+	}
+
+	public static CPUArchitectureType getOrCreateCPUArchitecture(JobDefinitionType value) {
+
+		ResourcesType jobResources = getOrCreateResources(value);
+		if (!jobResources.isSetCPUArchitecture()) {
+			jobResources.addNewCPUArchitecture();
+		}
+		return jobResources.getCPUArchitecture();
+	}
+
+	public static org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType getOrCreateIndividualCPUCount(JobDefinitionType value) {        
+		ResourcesType jobResources = getOrCreateResources(value);
+		if (!jobResources.isSetIndividualCPUCount()) {
+			jobResources.addNewIndividualCPUCount();
+		}
+		return jobResources.getIndividualCPUCount();
+	}
+
+
+	public static org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType getOrCreateIndividualCPUSpeed(JobDefinitionType value) {
+
+		ResourcesType jobResources = getOrCreateResources(value);
+		if (!jobResources.isSetIndividualCPUSpeed()) {
+			jobResources.addNewIndividualCPUSpeed();
+		}
+		return jobResources.getIndividualCPUSpeed();
+	}
+
+	public static org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType getOrCreateIndividualCPUTime(JobDefinitionType value) {
+
+		ResourcesType jobResources = getOrCreateResources(value);
+		if ( !jobResources.isSetIndividualCPUTime() ) {
+			jobResources.addNewIndividualCPUTime();
+		}
+		return jobResources.getIndividualCPUTime();
+	}
+
+	public static org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType getOrCreateIndividualDiskSpace(JobDefinitionType value) {
+
+		ResourcesType jobResources = getOrCreateResources(value);
+		if (!jobResources.isSetIndividualDiskSpace()) {
+			jobResources.addNewIndividualDiskSpace();
+		}
+		return jobResources.getIndividualDiskSpace();
+	}
+
+	public static org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType getOrCreateIndividualPhysicalMemory(JobDefinitionType value) {
+
+		ResourcesType jobResources = getOrCreateResources(value);
+		if (!jobResources.isSetIndividualPhysicalMemory()) {
+			jobResources.addNewIndividualPhysicalMemory();
+		}
+		return jobResources.getIndividualPhysicalMemory();
+	}
+
+	public static JobDescriptionType getOrCreateJobDescription(JobDefinitionType value) {
+		if (value.getJobDescription() == null) {
+			return value.addNewJobDescription();
+		}
+		return value.getJobDescription();
+	}
+
+	public static JobIdentificationType getOrCreateJobIdentification(JobDefinitionType value) {
+		JobDescriptionType descr = getOrCreateJobDescription(value);
+		if (descr.getJobIdentification() == null) {
+			return descr.addNewJobIdentification();
+		}
+		return descr.getJobIdentification();
+	}
+
+	public static OperatingSystemType getOrCreateOperatingSystem(JobDefinitionType value)
+	{
+		ResourcesType jobResources = getOrCreateResources(value);        
+		if(!jobResources.isSetOperatingSystem()) {
+			jobResources.addNewOperatingSystem();
+		}
+		return jobResources.getOperatingSystem();
+	}
+
+	public static ResourcesType getOrCreateResources(JobDefinitionType value) {
+		JobDescriptionType jobDescr = getOrCreateJobDescription(value);
+		if (!jobDescr.isSetResources()) {
+			jobDescr.addNewResources();
+		}
+		return jobDescr.getResources();
+	}
+
+
+	public static org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType getOrCreateTotalCPUCount(JobDefinitionType value) {
+
+		ResourcesType jobResources = getOrCreateResources(value);
+		if ( !jobResources.isSetTotalCPUCount() ) {
+			jobResources.addNewTotalCPUCount();
+		}
+		return jobResources.getTotalCPUCount();
+	}
+
+
+	public static org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType getOrCreateTotalResourceCount(JobDefinitionType value) {
+
+		ResourcesType jobResources = getOrCreateResources(value);
+		if ( !jobResources.isSetTotalResourceCount())
+		{
+			jobResources.addNewTotalResourceCount();
+		}
+		return jobResources.getTotalResourceCount();
+	}
+
+	public static POSIXApplicationType getOrCreatePOSIXApplication(JobDefinitionType value) {
+		
+		ApplicationType application = getOrCreateApplication(value);
+		
+		if(getHPCProfileApplication(value) != null){
+			//TODO handle: not creating POSIX element if HPCProfile already exists
+			return getPOSIXApplication(value);
+		}
+		
+		if (getPOSIXApplication(value) == null) {
+			XmlCursor acursor = application.newCursor();
+			acursor.toEndToken();
+			acursor.insertElement(POSIX_APPLICATION);
+			acursor.dispose();
+		}
+		return getPOSIXApplication(value);
+	}
+
+	
+	public static SPMDApplicationType getOrCreateSPMDApplication(JobDefinitionType value) {
+		
+		ApplicationType application = getOrCreateApplication(value);
+		
+		if (getSPMDApplication(value) == null) {
+			XmlCursor acursor = application.newCursor();
+			acursor.toEndToken();
+			acursor.insertElement(SPMD_APPLICATION);
+			acursor.dispose();
+		}
+		return getSPMDApplication(value);
+	}
+
+	public static SPMDApplicationType getSPMDApplication(JobDefinitionType value) {
+		if (value != null &&
+				value.getJobDescription() != null && 
+				value.getJobDescription().isSetApplication() ) {
+			XmlCursor acursor = value.getJobDescription().getApplication().newCursor();
+			if (acursor.toFirstChild()) {
+				do {
+					if(acursor.getName().equals(SPMD_APPLICATION)) {
+						XmlObject result = acursor.getObject();
+						acursor.dispose();
+						return (SPMDApplicationType) result;
+					}
+				} while (acursor.toNextSibling());
+				acursor.dispose();
+				return null;
+			} else {
+				acursor.dispose();                               
+				return null;
+			}
+		} else {
+			return null;
+		}
+	}
+
+	
+	
+	public static POSIXApplicationType getPOSIXApplication(JobDefinitionType value) {
+		if (value != null &&
+				value.getJobDescription() != null && 
+				value.getJobDescription().isSetApplication() ) {
+			XmlCursor acursor = value.getJobDescription().getApplication().newCursor();
+			if (acursor.toFirstChild()) {
+				do {
+					if(acursor.getName().equals(POSIX_APPLICATION)) {
+						XmlObject result = acursor.getObject();
+						acursor.dispose();
+						return (POSIXApplicationType) result;
+					}
+				} while (acursor.toNextSibling());
+				acursor.dispose();
+				return null;
+			} else {
+				acursor.dispose();                               
+				return null;
+			}
+		} else {
+			return null;
+		}
+	}
+	
+	
+	
+	public static HPCProfileApplicationType getOrCreateHPCProfileApplication(JobDefinitionType value) {
+
+		ApplicationType application = getOrCreateApplication(value);
+		
+		if(getPOSIXApplication(value) != null){
+			//TODO handle: creating HPC element if POSIX already exists
+			return getHPCProfileApplication(value);
+		}
+		
+		if (getHPCProfileApplication(value) == null) {
+			XmlCursor acursor = application.newCursor();
+			acursor.toEndToken();
+			acursor.insertElement(HPC_PROFILE_APPLICATION);
+			acursor.dispose();
+		}
+		return getHPCProfileApplication(value);
+	}
+
+	
+	public static HPCProfileApplicationType getHPCProfileApplication(JobDefinitionType value) {
+		if (value != null &&
+				value.getJobDescription() != null && 
+				value.getJobDescription().isSetApplication() ) {
+			XmlCursor acursor = value.getJobDescription().getApplication().newCursor();
+			if (acursor.toFirstChild()) {
+				do {
+					if(acursor.getName().equals(HPC_PROFILE_APPLICATION)) {
+						XmlObject result = acursor.getObject();
+						acursor.dispose();
+						return (HPCProfileApplicationType) result;
+					}
+				} while (acursor.toNextSibling());
+				acursor.dispose();
+				return null;
+			} else {
+				acursor.dispose();                               
+				return null;
+			}
+		} else {
+			return null;
+		}
+	}
+
+	
+	
+
+	public static RangeValueType getTotalCPUCountRequirements(JobDefinitionType value) {
+		if(value != null && value.getJobDescription() != null && value.getJobDescription().isSetResources() && 
+				value.getJobDescription().getResources().isSetTotalCPUCount()){
+			return toU6RangeValue(value.getJobDescription().getResources().getTotalCPUCount());
+		}
+		else
+			return null;
+	}
+
+	public static RangeValueType getTotalResourceCountRequirements(JobDefinitionType value) {
+		if(value != null && value.getJobDescription() != null && value.getJobDescription().isSetResources() && 
+				value.getJobDescription().getResources().isSetTotalResourceCount()){
+			return toU6RangeValue(value.getJobDescription().getResources().getTotalResourceCount());
+		}
+		else
+			return null;
+	}
+
+
+	public static RangeValueType toU6RangeValue(org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType jsdlType) {
+		RangeValueType result = new RangeValueType();
+		if(jsdlType.getExactArray().length > 0){
+			result.setExact(jsdlType.getExactArray(0).getDoubleValue());                
+		}
+		if(jsdlType.isSetLowerBoundedRange()){
+			result.setLowerBound(jsdlType.getLowerBoundedRange().getDoubleValue());                
+		}
+		if(jsdlType.isSetUpperBoundedRange()){
+			result.setUpperBound(jsdlType.getUpperBoundedRange().getDoubleValue());                
+		}
+		return result;
+	}
+
+
+
+	public static void setCPUArchitectureRequirements(JobDefinitionType value, ProcessorRequirement cpuArchitecture) { 
+		if(cpuArchitecture == null || cpuArchitecture.getValue() == null) return;
+		CPUArchitectureType cpuArch = getOrCreateCPUArchitecture(value);
+		cpuArch.setCPUArchitectureName(ProcessorArchitectureEnumeration.Enum.forString(cpuArchitecture.getValue()));        
+	}
+
+	public static void setIndividualCPUCountRequirements(JobDefinitionType value, RangeValueType cpuCount) {
+		org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType individualCPUCount = getOrCreateIndividualCPUCount(value);
+		setRangeValue(cpuCount, individualCPUCount);
+	}
+
+	public static void setIndividualCPUSpeedRequirements(JobDefinitionType value, RangeValueType cpuSpeed) {
+		org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType individualCPUSpeed = getOrCreateIndividualCPUSpeed(value);
+		setRangeValue(cpuSpeed, individualCPUSpeed);
+	}
+
+	public static void setIndividualCPUTimeRequirements(JobDefinitionType value, RangeValueType cpuTime) {
+		org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType cpuIndividualTime = getOrCreateIndividualCPUTime(value);       
+		setRangeValue(cpuTime, cpuIndividualTime);
+	}
+
+	public static void setIndividualDiskSpaceRequirements(JobDefinitionType value, RangeValueType diskSpace) {
+		org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType individualDiskSpace = getOrCreateIndividualDiskSpace(value);
+		setRangeValue(diskSpace, individualDiskSpace);
+	}
+
+	public static void setIndividualPhysicalMemoryRequirements(JobDefinitionType value, RangeValueType physicalMemory) {
+		org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType individualPhysicalMemory = getOrCreateIndividualPhysicalMemory(value);
+		setRangeValue(physicalMemory, individualPhysicalMemory);
+	}
+
+
+	public static void setName(JobDefinitionType value, String name) {
+		getOrCreateJobIdentification(value).setJobName(name);
+	}
+
+	public static void setOperatingSystemRequirements(JobDefinitionType value, OSRequirement osType) {
+		if(osType == null || osType.getOSType() == null) return;
+		OperatingSystemType os_Type = getOrCreateOperatingSystem(value);
+		OperatingSystemTypeType ostt = os_Type.addNewOperatingSystemType();
+		ostt.setOperatingSystemName(OperatingSystemTypeEnumeration.Enum.forString(osType.getOSType().getValue()));
+		if(osType.getOSVersion() != null) 
+		{
+			os_Type.setOperatingSystemVersion(osType.getOSVersion());
+		}
+	}
+
+	public static void setRangeValue(RangeValueType u6Type, org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType jsdlType) {
+		Double exact = u6Type.getExact();
+		Double epsilon = u6Type.getEpsilon();
+		Double lower = u6Type.getLowerBound();
+		Double upper = u6Type.getUpperBound();
+
+
+		if(lower.isNaN() && upper.isNaN())
+		{
+			ExactType exactType = jsdlType.getExactArray().length > 0 ? jsdlType.getExactArray(0) : jsdlType.addNewExact();
+			exactType.setDoubleValue(exact);
+			if(!epsilon.isNaN() && epsilon != 0)
+			{
+				exactType.setEpsilon(epsilon);
+			}
+		}
+		else
+		{
+			if(!lower.isNaN())
+			{
+				BoundaryType lowerBound = jsdlType.isSetLowerBoundedRange() ? jsdlType.getLowerBoundedRange() : jsdlType.addNewLowerBoundedRange(); 
+				lowerBound.setDoubleValue(lower);
+				lowerBound.setExclusiveBound(!u6Type.isIncludeLowerBound());
+			}
+
+			if(!upper.isNaN())
+			{
+				BoundaryType upperBound = jsdlType.isSetUpperBoundedRange() ? jsdlType.getUpperBoundedRange() : jsdlType.addNewUpperBoundedRange();
+				upperBound.setDoubleValue(upper);
+				upperBound.setExclusiveBound(!u6Type.isIncludeUpperBound());
+			}
+		}
+	}
+
+	public static void setTotalCPUCountRequirements(JobDefinitionType value, RangeValueType cpuCount) {
+		org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType cpuTotalCount = getOrCreateTotalCPUCount(value);        
+		setRangeValue(cpuCount, cpuTotalCount);
+	}
+
+	public static void setTotalResourceCountRequirements(JobDefinitionType value, RangeValueType resourceCount) {
+		org.ggf.schemas.jsdl.x2005.x11.jsdl.RangeValueType totalCount = getOrCreateTotalResourceCount(value);   
+		setRangeValue(resourceCount, totalCount);
+	}
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/Mode.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/Mode.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/Mode.java
new file mode 100644
index 0000000..2223ecf
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/Mode.java
@@ -0,0 +1,45 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+/**
+ * file creation modes 
+ */
+public enum Mode {
+
+	/**
+	 * overwrite any existing file
+	 */
+	overwrite,
+	
+	/**
+	 * append to an existing file
+	 */
+	append,
+	
+	/**
+	 * do NOT overwrite and fail if the file exists
+	 */
+	nooverwrite
+	
+	
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/OSRequirement.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/OSRequirement.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/OSRequirement.java
new file mode 100644
index 0000000..3938598
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/OSRequirement.java
@@ -0,0 +1,108 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+import org.apache.airavata.gfac.provider.utils.ResourceRequirement;
+
+public class OSRequirement implements ResourceRequirement {
+    private OSType osType;
+    private String version;
+    protected boolean enabled;
+    
+    
+    public OSRequirement() {
+    }
+
+    /**
+     * 
+     * @param type -
+     *            the type of the O/S
+     * @param version -
+     *            the version of the O/S
+     */
+    public OSRequirement(OSType osType, String osVersion) {
+        setOSType(osType);
+        setOSVersion(osVersion);
+    }
+
+    /**
+     * Set the type of the O/S
+     * 
+     * @param type -
+     *            the type of the O/S
+     */
+    public void setOSType(OSType osType) {
+        this.osType = osType;
+    }
+
+    /**
+     * Get the type of the O/S
+     * 
+     * @return the type of the O/S
+     */
+    public OSType getOSType() {
+        return osType;
+    }
+
+    /**
+     * Set the version of the O/S
+     * 
+     * @param version -
+     *            the version of the O/S
+     */
+    public void setOSVersion(String version) {
+        this.version = version;
+    }
+
+    /**
+     * Get the version of the O/S
+     * 
+     * @return the version of the O/S
+     */
+    public String getOSVersion() {
+        return version;
+    }
+
+    /**
+     * 
+     * equals this instance of class with another instance
+     */
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj==null || getClass() != obj.getClass()) return false;
+        final OSRequirement other = (OSRequirement) obj;
+        boolean typeEqual = osType == null ? other.osType == null : osType.equals(other.osType);
+        boolean versionEqual = version == null ? other.version == null : version.equals(other.version);
+        return typeEqual && versionEqual && isEnabled() == other.isEnabled();
+    }
+
+
+
+	public boolean isEnabled() {
+		return enabled;
+	}
+
+	public void setEnabled(boolean enabled) {
+		this.enabled = enabled;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/OSType.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/OSType.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/OSType.java
new file mode 100644
index 0000000..b10c43a
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/OSType.java
@@ -0,0 +1,124 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+public enum OSType {
+
+	unknown("Unknown"), //$NON-NLS-1$
+	linux("LINUX"), //$NON-NLS-1$
+	mac_os("MACOS"), //$NON-NLS-1$
+	win95("WIN95"), //$NON-NLS-1$
+	win98("WIN98"), //$NON-NLS-1$
+	windows_R_Me("Windows_R_Me"), //$NON-NLS-1$
+	winNT("WINNT"), //$NON-NLS-1$
+	windows_2000("Windows_2000"), //$NON-NLS-1$
+	windows_XP("Windows_XP"), //$NON-NLS-1$
+	msdos("MSDOS"), //$NON-NLS-1$
+	solaris("Solaris"), //$NON-NLS-1$
+	sunOS("SunOS"), //$NON-NLS-1$
+	freeBSD("FreeBSD"), //$NON-NLS-1$
+	netBSD("NetBSD"), //$NON-NLS-1$
+	openBSD("OpenBSD"), //$NON-NLS-1$
+	bsdunix("BSDUNIX"), //$NON-NLS-1$
+	aix("AIX"), //$NON-NLS-1$
+	z_OS("z_OS"), //$NON-NLS-1$
+	os_2("OS_2"), //$NON-NLS-1$
+	os9("OS9"), //$NON-NLS-1$
+	netWare("NetWare"), //$NON-NLS-1$
+	tru64_unix("Tru64_UNIX"), //$NON-NLS-1$
+	irix("IRIX"), //$NON-NLS-1$
+	osf("OSF"), //$NON-NLS-1$
+
+	mvs("MVS"), //$NON-NLS-1$
+	os400("OS400"), //$NON-NLS-1$
+	javaVM("JavaVM"), //$NON-NLS-1$
+	win3x("WIN3x"), //$NON-NLS-1$
+	winCE("WINCE"), //$NON-NLS-1$
+	NCR3000("NCR3000"), //$NON-NLS-1$
+	dc_os("DC_OS"), //$NON-NLS-1$
+	reliant_unix("Reliant_UNIX"), //$NON-NLS-1$
+	sco_unixWare("SCO_UnixWare"), //$NON-NLS-1$
+	sco_openServer("SCO_OpenServer"), //$NON-NLS-1$
+	sequent("Sequent"), //$NON-NLS-1$
+	u6000("U6000"), //$NON-NLS-1$
+	aseries("ASERIES"), //$NON-NLS-1$
+	tandemNSK("TandemNSK"), //$NON-NLS-1$
+	tandemNT("TandemNT"), //$NON-NLS-1$
+	bs2000("BS2000"), //$NON-NLS-1$
+	lynx("Lynx"), //$NON-NLS-1$
+	xenix("XENIX"), //$NON-NLS-1$
+	vm("VM"), //$NON-NLS-1$
+	interactive_unix("Interactive_UNIX"), //$NON-NLS-1$
+	gnu_hurd("GNU_Hurd"), //$NON-NLS-1$
+	mach_kernel("MACH_Kernel"), //$NON-NLS-1$
+	inferno("Inferno"), //$NON-NLS-1$
+	qnx("QNX"), //$NON-NLS-1$
+	epoc("EPOC"), //$NON-NLS-1$
+	ixWorks("IxWorks"), //$NON-NLS-1$
+	vxWorks("VxWorks"), //$NON-NLS-1$
+	mint("MiNT"), //$NON-NLS-1$
+	beOS("BeOS"), //$NON-NLS-1$
+	hp_mpe("HP_MPE"), //$NON-NLS-1$
+	nextStep("NextStep"), //$NON-NLS-1$
+	palmPilot("PalmPilot"), //$NON-NLS-1$
+	rhapsody("Rhapsody"), //$NON-NLS-1$
+	dedicated("Dedicated"), //$NON-NLS-1$
+	os_390("OS_390"), //$NON-NLS-1$
+	vse("VSE"), //$NON-NLS-1$
+	tpf("TPF"), //$NON-NLS-1$
+	caldera_open_unix("Caldera_Open_UNIX"), //$NON-NLS-1$
+	attunix("ATTUNIX"), //$NON-NLS-1$
+	dgux("DGUX"), //$NON-NLS-1$
+	decnt("DECNT"), //$NON-NLS-1$
+	openVMS("OpenVMS"), //$NON-NLS-1$
+	hpux("HPUX"), //$NON-NLS-1$
+	other("other"); //$NON-NLS-1$
+
+
+	private OSType(String value) { 
+		this.value = value;
+	}
+
+	private final String value;
+
+	public String getValue() { 
+		return value;
+	}
+
+	public static OSType fromString(String value)
+	{
+		for(OSType type : values())
+		{
+			if(type.value.equals(value))
+			{
+				return type;
+			}
+		}
+		return null;
+	}
+	
+	public String toString()
+	{
+		return value;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/ProcessorRequirement.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/ProcessorRequirement.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/ProcessorRequirement.java
new file mode 100644
index 0000000..0b48dd7
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/ProcessorRequirement.java
@@ -0,0 +1,61 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+package org.apache.airavata.gfac.bes.utils;
+
+public enum ProcessorRequirement{
+	sparc("sparc"), //$NON-NLS-1$
+	powerpc("powerpc"), //$NON-NLS-1$
+	x86("x86"), //$NON-NLS-1$
+	x86_32("x86_32"), //$NON-NLS-1$
+	x86_64("x86_64"), //$NON-NLS-1$
+	parisc("parisc"), //$NON-NLS-1$
+	mips("mips"), //$NON-NLS-1$
+	ia64("ia64"), //$NON-NLS-1$
+	arm("arm"), //$NON-NLS-1$
+	other("other"); //$NON-NLS-1$
+
+	ProcessorRequirement(String value) {
+		this.value = value; 
+	}
+
+	private final String value;
+
+	public String getValue() { 
+		return value; 
+	}
+
+	public static ProcessorRequirement fromString(String value)
+	{
+		for (ProcessorRequirement type : values()) {
+			if (type.value.equals(value)) {
+				return type;
+			}
+		}
+		return other;
+	}
+	
+	public String toString()
+	{
+		return value;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/RangeValueType.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/RangeValueType.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/RangeValueType.java
new file mode 100644
index 0000000..6aec82a
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/RangeValueType.java
@@ -0,0 +1,274 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+import org.apache.airavata.gfac.provider.utils.ResourceRequirement;
+
+public class RangeValueType implements ResourceRequirement {
+	
+
+    private double exact = Double.NaN;
+    private double lowerBound = Double.NEGATIVE_INFINITY;
+    private double upperBound = Double.POSITIVE_INFINITY;
+    
+    private double epsilon = Double.NaN;
+    private boolean includeLowerBound = true;
+    private boolean includeUpperBound = true;
+    
+    private boolean enabled = false;
+    
+    
+    public RangeValueType(double exact, double epsilon, double lowerBound, boolean includeLowerBound, double upperBound, boolean includeUpperBound, boolean enabled) {
+        this.exact = exact;
+    	this.epsilon = epsilon;
+    	this.lowerBound = lowerBound;
+        this.includeLowerBound = includeLowerBound;
+        this.upperBound = upperBound;
+        this.includeUpperBound = includeUpperBound;
+        this.enabled = enabled;
+    }
+   
+    
+    
+    /**
+	 * Create the range requirements
+	 * 
+	 * @param exact -
+	 *            the exact value
+	 * @param lowerBound -
+	 *            the lower bound
+	 * @param upperBound -
+	 *            the upper bound
+	 * @param includelowerBound -
+	 *            true, if lowerBound should be included in range
+	 * @param includeUpperBound -
+	 *            true, if upperBound should be included in range
+	 * 
+	 */
+    public RangeValueType(double exact, double epsilon, double lowerBound, boolean includeLowerBound, double upperBound, boolean includeUpperBound) {
+    	this(exact,epsilon,lowerBound,includeLowerBound,upperBound,includeUpperBound,false);
+        
+    }
+    
+    
+    /**
+	 * Create the range requirements
+	 * 
+	 * @param exact -
+	 *            the exact value
+	 * @param lowerBound -
+	 *            the lower bound
+	 * @param upperBound -
+	 *            the upper bound
+	 */
+    public RangeValueType(double exact, double epsilon, double lowerBound, double upperBound) {
+    	this(exact,epsilon,lowerBound,true,upperBound,true);
+    }
+    
+    
+    public RangeValueType(double exact, double lowerBound, double upperBound) {
+    	this(exact,Double.NaN,lowerBound,true,upperBound,true);
+    }
+
+    /**
+	 * Create the exact requirements
+	 * 
+	 * @param exact -
+	 *            the exact value
+	 * @param epsilon -
+	 *            the epsilon arround exact
+	 * 
+	 */
+    public RangeValueType(double exact, double epsilon) {
+        this(exact,epsilon,Double.NaN,Double.NaN);
+    }
+
+    
+    /**
+	 * Create the exact requirements
+	 * 
+	 * @param exact -
+	 *            the exact value
+	 */
+    public RangeValueType(double exact) {
+        this(exact,Double.NaN);
+    }
+
+    public RangeValueType() {
+    }
+
+    /**
+	 * Get exact requirements
+	 * 
+	 * @return the exact requirements
+	 */
+    public double getExact() {
+        return exact;
+    }
+
+    /**
+	 * Set exact requirements
+	 * 
+	 * @param exact -
+	 *            the exact requirements
+	 */
+    public void setExact(double exact) {
+        this.exact = exact;
+    }
+    
+    /**
+	 * Get epsilon
+	 * 
+	 * @return the epsilon
+	 */
+    public double getEpsilon() {
+        return epsilon;
+    }
+
+    /**
+	 * Set epsilon
+	 * 
+	 * @param epsilon -
+	 *            epsilon belonging to to exact requirements
+	 */
+    public void setEpsilon(double epsilon) {
+        this.epsilon = epsilon;
+    }
+
+    /**
+	 * Get lower bound
+	 * 
+	 * @return the lower bound
+	 */
+    public double getLowerBound() {
+        return lowerBound;
+    }
+
+    /**
+	 * Set lower bound
+	 * 
+	 * @param lowerBound -
+	 *            the lower bound
+	 */
+    public void setLowerBound(double lowerBound) {
+        this.lowerBound = lowerBound;
+    }
+
+    /**
+	 * Get upper bound
+	 * 
+	 * @return the upper bound
+	 */
+    public double getUpperBound() {
+        return upperBound;
+    }
+
+    /**
+	 * Set upper bound
+	 * 
+	 * @param upperBound -
+	 *            the upper bound
+	 */
+    public void setUpperBound(double upperBound) {
+        this.upperBound = upperBound;
+    }
+
+    /**
+	 * Test if requirements are met
+	 * 
+	 * @param value -
+	 *            the tested value
+	 * @return <code>true</code> if value is in the range and not less than
+	 *         the exact value
+	 */
+    public boolean lowerThanDouble(double value) {
+        return (value >= exact && value >= lowerBound && value <= upperBound) ? true : false;
+    }
+
+    public String toString() {
+        if (lowerBound == Double.NEGATIVE_INFINITY && upperBound == Double.POSITIVE_INFINITY) {
+            return Double.toString(exact);
+        }
+        else {
+            return "(e=" + Double.toString(exact) + ",l=" + Double.toString(lowerBound) + ",u=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+                    + Double.toString(upperBound) + ")"; //$NON-NLS-1$
+        }
+    }
+
+
+	public boolean isIncludeLowerBound() {
+		return includeLowerBound;
+	}
+
+
+	public void setIncludeLowerBound(boolean includeLowerBound) {
+		this.includeLowerBound = includeLowerBound;
+	}
+
+
+	public boolean isIncludeUpperBound() {
+		return includeUpperBound;
+	}
+
+
+	public void setIncludeUpperBound(boolean includeUpperBound) {
+		this.includeUpperBound = includeUpperBound;
+	}
+	
+	public RangeValueType clone(){
+		return new RangeValueType(this.exact, this.epsilon, this.lowerBound, this.includeLowerBound, this.upperBound, this.includeUpperBound,this.enabled);
+	}
+
+
+
+	public boolean isEnabled() {
+		return enabled;
+	}
+
+
+
+	public void setEnabled(boolean enabled) {
+		this.enabled = enabled;
+	}
+
+	
+	public boolean equals(Object o)
+	{
+		if(! (o instanceof RangeValueType)) return false;
+		RangeValueType other = (RangeValueType) o;
+		return doublesEqual(getExact(),other.getExact())
+		&& doublesEqual(getEpsilon(), other.getEpsilon())
+		&& doublesEqual(getLowerBound(), other.getLowerBound())
+		&& doublesEqual(getUpperBound(), other.getUpperBound())
+		&& isIncludeLowerBound() == other.isIncludeLowerBound()
+		&& isIncludeUpperBound() == other.isIncludeUpperBound()
+		&& isEnabled() == other.isEnabled();
+	}
+
+	
+	private boolean doublesEqual(double a, double b)
+	{
+		Double A = new Double(a);
+		Double B = new Double(b);
+		return A.equals(B);
+	}
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/ResourceProcessor.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/ResourceProcessor.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/ResourceProcessor.java
new file mode 100644
index 0000000..fc8d6ec
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/ResourceProcessor.java
@@ -0,0 +1,152 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.provider.GFacProviderException;
+import org.apache.airavata.model.workspace.experiment.ComputationalResourceScheduling;
+import org.apache.airavata.model.workspace.experiment.TaskDetails;
+import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
+import org.apache.airavata.schemas.gfac.QueueType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType;
+import org.ogf.schemas.jsdl.x2007.x02.jsdlSpmd.NumberOfProcessesType;
+
+public class ResourceProcessor {
+
+	
+	public static void generateResourceElements(JobDefinitionType value, JobExecutionContext context) throws Exception{
+		
+		HpcApplicationDeploymentType appDepType = (HpcApplicationDeploymentType) context
+				.getApplicationContext().getApplicationDeploymentDescription()
+				.getType();
+		
+		createMemory(value, appDepType);
+		TaskDetails taskData = context.getTaskData();
+	    if(taskData != null && taskData.isSetTaskScheduling()){
+	    	ComputationalResourceScheduling computionResource= taskData.getTaskScheduling();
+                try {
+                    int cpuCount = computionResource.getTotalCPUCount();
+                    if(cpuCount>0){
+//                    	appDepType.setCpuCount(cpuCount);
+                		NumberOfProcessesType num = NumberOfProcessesType.Factory.newInstance();
+    					String processers = Integer.toString(cpuCount);
+						num.setStringValue(processers);
+    					JSDLUtils.getOrCreateSPMDApplication(value).setNumberOfProcesses(num);
+                    }
+                } catch (NullPointerException e) {
+                    new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
+                }
+                try {
+                    int nodeCount = computionResource.getNodeCount();
+                    if(nodeCount>0){
+                    	appDepType.setNodeCount(nodeCount);
+                    }
+                } catch (NullPointerException e) {
+                     new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
+                }
+                try {
+                    String queueName = computionResource.getQueueName();
+                    if (queueName != null) {
+                        if(appDepType.getQueue() == null){
+                            QueueType queueType = appDepType.addNewQueue();
+                            queueType.setQueueName(queueName);
+                        }else{
+                        	appDepType.getQueue().setQueueName(queueName);
+                        }
+                    }
+                } catch (NullPointerException e) {
+                     new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
+                }
+                try {
+                    int maxwallTime = computionResource.getWallTimeLimit();
+                    if(maxwallTime>0){
+                    	appDepType.setMaxWallTime(maxwallTime);
+                    }
+                } catch (NullPointerException e) {
+                     new GFacProviderException("No Value sent in WorkflowContextHeader for Node Count, value in the Deployment Descriptor will be used",e);
+                }
+        }
+		
+		if (appDepType.getCpuCount() > 0) {
+			RangeValueType rangeType = new RangeValueType();
+			rangeType.setLowerBound(Double.NaN);
+			rangeType.setUpperBound(Double.NaN);
+			rangeType.setExact(appDepType.getCpuCount());
+			JSDLUtils.setTotalCPUCountRequirements(value, rangeType);
+		}
+
+		if (appDepType.getProcessorsPerNode() > 0) {
+			RangeValueType rangeType = new RangeValueType();
+			rangeType.setLowerBound(Double.NaN);
+			rangeType.setUpperBound(Double.NaN);
+			rangeType.setExact(appDepType.getProcessorsPerNode());
+			JSDLUtils.setIndividualCPUCountRequirements(value, rangeType);
+		}
+		
+		if (appDepType.getNodeCount() > 0) {
+			RangeValueType rangeType = new RangeValueType();
+			rangeType.setLowerBound(Double.NaN);
+			rangeType.setUpperBound(Double.NaN);
+			rangeType.setExact(appDepType.getNodeCount());
+			JSDLUtils.setTotalResourceCountRequirements(value, rangeType);
+		}
+		
+		if(appDepType.getMaxWallTime() > 0) {
+			RangeValueType cpuTime = new RangeValueType();
+			cpuTime.setLowerBound(Double.NaN);
+			cpuTime.setUpperBound(Double.NaN);
+			long wallTime = appDepType.getMaxWallTime() * 60;
+			cpuTime.setExact(wallTime);
+			JSDLUtils.setIndividualCPUTimeRequirements(value, cpuTime);
+		}
+	}
+	
+	
+	private static void createMemory(JobDefinitionType value, HpcApplicationDeploymentType appDepType){
+		if (appDepType.getMinMemory() > 0 && appDepType.getMaxMemory() > 0) {
+			RangeValueType rangeType = new RangeValueType();
+			rangeType.setLowerBound(appDepType.getMinMemory());
+			rangeType.setUpperBound(appDepType.getMaxMemory());
+			JSDLUtils.setIndividualPhysicalMemoryRequirements(value, rangeType);
+		}
+
+		else if (appDepType.getMinMemory() > 0 && appDepType.getMaxMemory() <= 0) {
+			// TODO set Wall time
+			RangeValueType rangeType = new RangeValueType();
+			rangeType.setLowerBound(appDepType.getMinMemory());
+			JSDLUtils.setIndividualPhysicalMemoryRequirements(value, rangeType);
+		}
+		
+		else if (appDepType.getMinMemory() <= 0 && appDepType.getMaxMemory() > 0) {
+			// TODO set Wall time
+			RangeValueType rangeType = new RangeValueType();
+			rangeType.setUpperBound(appDepType.getMinMemory());
+			JSDLUtils.setIndividualPhysicalMemoryRequirements(value, rangeType);
+		}
+		
+	}
+
+	
+	
+
+	
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SPMDProcessor.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SPMDProcessor.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SPMDProcessor.java
new file mode 100644
index 0000000..8807026
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SPMDProcessor.java
@@ -0,0 +1,33 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType;
+
+public class SPMDProcessor {
+
+	public static void generateSPMDElements(JobDefinitionType value, JobExecutionContext context) {
+		
+	}
+	
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SPMDVariations.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SPMDVariations.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SPMDVariations.java
new file mode 100644
index 0000000..755799c
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/SPMDVariations.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+public enum SPMDVariations {
+
+	MPI ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/MPI"), 
+	GridMPI ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/GridMPI"),
+	IntelMPI ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/IntelMPI"),
+	LAMMPI ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/LAM-MPI"), 
+	MPICH1 ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/MPICH1"),
+	MPICH2 ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/MPICH2"),
+	MPICHGM ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/MPICH-GM"),
+	MPICHMX ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/MPICH-MX"),
+	MVAPICH ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/MVAPICH"),
+	MVAPICH2 ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/MVAPICH2"),
+	OpenMPI ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/OpenMPI"),
+	POE ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/POE"),
+	PVM ("http://www.ogf.org/jsdl/2007/02/jsdl-spmd/PVM");
+	
+	private final String variation;
+	
+	private SPMDVariations(String variation) {
+		this.variation = variation;
+	}
+	
+	public String value(){
+		return variation;
+	}
+	
+}
+
+

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/StorageCreator.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/StorageCreator.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/StorageCreator.java
new file mode 100644
index 0000000..4282b62
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/StorageCreator.java
@@ -0,0 +1,211 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+import java.util.Calendar;
+
+import javax.security.auth.x500.X500Principal;
+
+import org.oasisOpen.docs.wsrf.sg2.EntryType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.unigrids.services.atomic.types.PropertyType;
+import org.unigrids.x2006.x04.services.smf.CreateSMSDocument;
+import org.unigrids.x2006.x04.services.smf.StorageBackendParametersDocument.StorageBackendParameters;
+import org.unigrids.x2006.x04.services.smf.StorageDescriptionType;
+import org.w3.x2005.x08.addressing.EndpointReferenceType;
+
+import de.fzj.unicore.uas.StorageFactory;
+import de.fzj.unicore.uas.client.StorageClient;
+import de.fzj.unicore.uas.client.StorageFactoryClient;
+import de.fzj.unicore.wsrflite.xmlbeans.WSUtilities;
+import de.fzj.unicore.wsrflite.xmlbeans.client.RegistryClient;
+import de.fzj.unicore.wsrflite.xmlbeans.sg.Registry;
+
+
+import eu.unicore.util.httpclient.DefaultClientConfiguration;
+
+public class StorageCreator {
+	 protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+	/**
+	 * the initial lifetime (in days) for newly created SMSs
+	 */
+	private int initialLifeTime;
+
+	/**
+	 * factory URL to use
+	 */
+	private String factoryUrl;
+
+	/**
+	 * site where to create the storage
+	 */
+	private String siteName;
+
+	/**
+	 * storage type to create
+	 */
+	private String storageType;
+
+	private DefaultClientConfiguration secProps;
+	
+	private String userName;
+	
+	public StorageCreator(DefaultClientConfiguration secProps, String besUrl, int initialLifetime, String storageType, String userName) {
+		this.secProps = secProps; 
+		this.factoryUrl = getStorageFactoryUrl(besUrl);
+		this.storageType = storageType;
+		this.initialLifeTime = initialLifetime;
+		this.userName = userName;
+	}
+	
+	
+	public StorageCreator(DefaultClientConfiguration secProps, String besUrl, int initialLifetime, String userName) {
+		this.secProps = secProps; 
+		this.factoryUrl = getStorageFactoryUrl(besUrl);
+		this.initialLifeTime = initialLifetime;
+		this.userName = userName;
+	}
+
+	
+	// The target site must have storage factory deployed with bes factory
+	public StorageClient createStorage() throws Exception{
+		
+		if(factoryUrl == null) {
+			throw new Exception("Cannot create Storage Factory Url");
+		}
+		
+		EndpointReferenceType sfEpr= WSUtilities.makeServiceEPR(factoryUrl, StorageFactory.SMF_PORT);
+		
+		String dn = findServerName(factoryUrl, sfEpr);
+		
+		WSUtilities.addServerIdentity(sfEpr, dn);
+		
+		secProps.getETDSettings().setReceiver(new X500Principal(dn));
+		secProps.getETDSettings().setIssuerCertificateChain(secProps.getCredential().getCertificateChain());
+		
+		// TODO: remove it afterwards
+		if(userName != null) {
+			secProps.getETDSettings().getRequestedUserAttributes2().put("xlogin", new String[]{userName});
+		}
+		
+		StorageFactoryClient sfc = new StorageFactoryClient(sfEpr, secProps);
+		
+		if (log.isDebugEnabled()){
+			log.debug("Using storage factory at <"+sfc.getUrl()+">");
+		}
+		
+		StorageClient sc = null;
+		try{
+			sc=sfc.createSMS(getCreateSMSDocument());
+			
+			String addr=sc.getEPR().getAddress().getStringValue();
+			log.info(addr);
+			
+		}catch(Exception ex){
+			log.error("Could not create storage",ex);
+			throw new Exception(ex);
+		}
+
+		return sc;
+	}
+	
+	protected String findServerName(String besUrl, EndpointReferenceType smsEpr)throws Exception{
+		
+		int besIndex = besUrl.indexOf("StorageFactory?res");
+		String ss = besUrl.substring(0, besIndex);
+		ss = ss + "Registry";
+		
+		EndpointReferenceType eprt = WSUtilities.makeServiceEPR(ss, "default_registry", Registry.REGISTRY_PORT);
+		
+		RegistryClient registry = new RegistryClient(eprt, secProps);
+		
+		//first, check if server name is already in the EPR...
+		String dn=WSUtilities.extractServerIDFromEPR(smsEpr);
+		if(dn!=null){
+			return dn;
+		}
+		//otherwise find a matching service in the registry
+		String url=smsEpr.getAddress().getStringValue();
+		if(url.contains("/services/"))url=url.substring(0,url.indexOf("/services"));
+		if(log.isDebugEnabled()) log.debug("Checking for services at "+url);
+		for(EntryType entry:registry.listEntries()){
+			if(entry.getMemberServiceEPR().getAddress().getStringValue().startsWith(url)){
+				dn=WSUtilities.extractServerIDFromEPR(entry.getMemberServiceEPR());
+				if(dn!=null){
+					return dn;
+				}
+			}
+		}
+		return null;
+	}
+
+	
+	public static String getStorageFactoryUrl(String besUrl){
+		int besIndex = besUrl.indexOf("BESFactory?res");
+		String ss = besUrl.substring(0, besIndex);
+		ss = ss + "StorageFactory?res=default_storage_factory";
+		return ss;
+	}
+	
+	/**
+	 * prepare request
+	 * */
+	protected CreateSMSDocument getCreateSMSDocument(String ...keyValueParams){
+		CreateSMSDocument in=CreateSMSDocument.Factory.newInstance();
+		in.addNewCreateSMS();
+		if(initialLifeTime>0){
+			in.getCreateSMS().addNewTerminationTime().setCalendarValue(getTermTime());
+		}
+		if(storageType!=null){
+			if(log.isDebugEnabled()) {
+				log.debug("Will create storage of type : "+storageType);
+			}
+			StorageDescriptionType desc=in.getCreateSMS().addNewStorageDescription();
+			desc.setStorageBackendType(storageType);
+			if(keyValueParams.length>1){
+				//other parameters from the cmdline as key=value
+				StorageBackendParameters params=desc.addNewStorageBackendParameters();
+				for(int i=1;i<keyValueParams.length;i++){
+					String arg=keyValueParams[i];
+					String[]sp=arg.split("=",2);
+					PropertyType prop=params.addNewProperty();
+					prop.setName(sp[0]);
+					prop.setValue(sp[1]);
+					if(log.isDebugEnabled()) {
+						log.debug("Have parameter : "+arg);
+					}
+				}
+			}
+		}
+		return in;
+	}
+
+	protected Calendar getTermTime(){
+		Calendar c = Calendar.getInstance();
+		c.add(Calendar.DATE, initialLifeTime);
+		return c;
+	}
+
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/UASDataStagingProcessor.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/UASDataStagingProcessor.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/UASDataStagingProcessor.java
new file mode 100644
index 0000000..0284dea
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/UASDataStagingProcessor.java
@@ -0,0 +1,225 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.context.MessageContext;
+import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
+import org.apache.airavata.schemas.gfac.StringArrayType;
+import org.apache.airavata.schemas.gfac.StringParameterType;
+import org.apache.airavata.schemas.gfac.URIArrayType;
+import org.apache.airavata.schemas.gfac.URIParameterType;
+import org.apache.airavata.schemas.gfac.UnicoreHostType;
+import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType;
+
+public class UASDataStagingProcessor {
+	
+	public static void generateDataStagingElements(JobDefinitionType value, JobExecutionContext context, String smsUrl) throws Exception{
+		
+		HpcApplicationDeploymentType appDepType = (HpcApplicationDeploymentType) context
+				.getApplicationContext().getApplicationDeploymentDescription()
+				.getType();
+		
+		smsUrl = "BFT:"+smsUrl;
+       
+		if (context.getInMessageContext().getParameters().size() > 0) {
+			buildDataStagingFromInputContext(context, value, smsUrl, appDepType);
+		}
+		MessageContext outMessage = new MessageContext();
+		ActualParameter a1 = new ActualParameter();
+		a1.getType().changeType(StringParameterType.type);
+		((StringParameterType)a1.getType()).setValue("output/analysis-results.tar");
+		outMessage.addParameter("o1", a1);
+		context.setOutMessageContext(outMessage);
+		
+		if (context.getOutMessageContext().getParameters().size() > 0) {
+			buildFromOutputContext(context, value, smsUrl, appDepType);
+		}
+		createStdOutURIs(value, appDepType, smsUrl, isUnicoreEndpoint(context));
+	}
+	
+	private static void createInURISMSElement(JobDefinitionType value,
+			String smsUrl, String inputDir, ActualParameter inParam)
+			throws Exception {
+		
+		String uri = ((URIParameterType) inParam.getType()).getValue();
+		//TODO: To add this input file name setting part of Airavata API
+		String fileName = "input/" + new File(uri).getName();
+		if (uri.startsWith("file")) {
+			String fileUri = smsUrl+"#/"+fileName;
+		
+			JSDLUtils.addDataStagingSourceElement(value, fileUri, null, fileName);
+		} else if (uri.startsWith("gsiftp") || uri.startsWith("http")
+				|| uri.startsWith("rns")) {
+			// no need to stage-in those files to the input
+			// directory because unicore site will fetch them for the user
+			JSDLUtils.addDataStagingSourceElement(value, uri, null, fileName);
+		}
+
+	}
+
+	private static void createStdOutURIs(JobDefinitionType value,
+			HpcApplicationDeploymentType appDepType, String smsUrl,
+			boolean isUnicore) throws Exception {
+
+		
+		String stdout = ApplicationProcessor.getApplicationStdOut(value, appDepType);
+		
+		String stderr = ApplicationProcessor.getApplicationStdErr(value, appDepType);
+		
+		String stdoutFileName = (stdout == null || stdout.equals("")) ? "stdout"
+				: stdout;
+		String stdoutURI = smsUrl+"#/output/"+stdoutFileName;
+		JSDLUtils.addDataStagingTargetElement(value, null, stdoutFileName,
+				stdoutURI);
+
+		String stderrFileName = (stdout == null || stderr.equals("")) ? "stderr"
+				: stderr;
+		String stderrURI = smsUrl+"#/output/"+stderrFileName;
+		JSDLUtils.addDataStagingTargetElement(value, null, stderrFileName,
+				stderrURI);
+		
+		if(isUnicore) {
+			String scriptExitCodeFName = "UNICORE_SCRIPT_EXIT_CODE";
+			String scriptExitCode = smsUrl+"#/output/"+scriptExitCodeFName;
+			JSDLUtils.addDataStagingTargetElement(value, null,
+					scriptExitCodeFName, scriptExitCode.toString());
+		}
+
+	}
+
+	
+	private static void createOutStringElements(JobDefinitionType value,
+			HpcApplicationDeploymentType appDeptype, String smsUrl, String prmValue) throws Exception {
+		
+		if(prmValue == null || "".equals(prmValue)) return;
+		
+		String finalSMSPath = smsUrl + "#/output/"+prmValue;
+		
+		JSDLUtils.addDataStagingTargetElement(value, null, prmValue,	finalSMSPath);
+	}
+
+	
+	private static void createOutURIElement(JobDefinitionType value,
+			String prmValue) throws Exception {
+		String fileName = new File(prmValue.toString()).getName();
+		JSDLUtils.addDataStagingTargetElement(value, null, fileName, prmValue);
+	}
+
+	
+	private static JobDefinitionType buildFromOutputContext(JobExecutionContext context,
+			JobDefinitionType value, String smsUrl,
+			HpcApplicationDeploymentType appDepType) throws Exception {
+		
+		Map<String, Object> outputParams = context.getOutMessageContext()
+				.getParameters();
+
+		for (String paramKey : outputParams.keySet()) {
+
+			ActualParameter outParam = (ActualParameter) outputParams
+					.get(paramKey);
+
+			// if single urls then convert each url into jsdl source
+			// elements,
+			// that are formed by concat of gridftpurl+inputdir+filename
+
+			String paramDataType = outParam.getType().getType().toString();
+
+			if ("URI".equals(paramDataType)) {
+				String uriPrm = ((URIParameterType) outParam.getType())
+						.getValue();
+				createOutURIElement(value, uriPrm);
+			}
+
+			// string params are converted into the job arguments
+
+			else if (("URIArray").equals(paramDataType)) {
+				String[] uriArray = ((URIArrayType) outParam.getType())
+						.getValueArray();
+				for (String u : uriArray) {
+					
+					createOutURIElement(value, u);
+				}
+
+			}
+			else if ("String".equals(paramDataType)) {
+				String stringPrm = ((StringParameterType) outParam
+						.getType()).getValue();
+				createOutStringElements(value, appDepType, smsUrl, stringPrm);
+			}
+
+			else if ("StringArray".equals(paramDataType)) {
+				String[] valueArray = ((StringArrayType) outParam.getType())
+						.getValueArray();
+				for (String v : valueArray) {
+					createOutStringElements(value, appDepType, smsUrl, v);
+				}
+			}
+		}
+		
+		return value;
+	}
+
+	
+	private static void buildDataStagingFromInputContext(JobExecutionContext context, JobDefinitionType value, String smsUrl, HpcApplicationDeploymentType appDepType) 
+			throws Exception {
+		
+		// TODO set data directory
+		Map<String, Object> inputParams = context.getInMessageContext()
+				.getParameters();
+
+		for (String paramKey : inputParams.keySet()) {
+
+			ActualParameter inParam = (ActualParameter) inputParams
+					.get(paramKey);
+
+			// if single urls then convert each url into jsdl source
+			// elements,
+			// that are formed by concat of gridftpurl+inputdir+filename
+
+			String paramDataType = inParam.getType().getType().toString();
+
+			if ("URI".equals(paramDataType)) {
+				createInURISMSElement(value, smsUrl,
+						appDepType.getInputDataDirectory(), inParam);
+			}
+
+			// string params are converted into the job arguments
+
+			else if ("String".equals(paramDataType)) {
+				String stringPrm = ((StringParameterType) inParam.getType())
+						.getValue();
+				ApplicationProcessor.addApplicationArgument(value, appDepType, stringPrm);
+			}
+		}
+		
+	}
+	
+	public static boolean isUnicoreEndpoint(JobExecutionContext context) {
+		return ( (context.getApplicationContext().getHostDescription().getType() instanceof UnicoreHostType)?true:false );
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/49b6987f/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/URIUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/URIUtils.java b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/URIUtils.java
new file mode 100644
index 0000000..fbc91da
--- /dev/null
+++ b/modules/gfac/gfac-bes/src/main/java/org/apache/airavata/gfac/bes/utils/URIUtils.java
@@ -0,0 +1,119 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.gfac.bes.utils;
+
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.util.URIUtil;
+
+import java.net.URISyntaxException;
+
+public class URIUtils {
+
+	public static String encodeAll(String uri) throws URIException
+	{
+		String result = encodeAuthority(uri);
+		result = encodePath(uri);
+		result = encodeQuery(result );
+		result  = encodeFragment(result );
+		return result;
+	}
+	
+	public static String encodeAuthority(String uri) throws URIException
+	{
+		int start = uri.indexOf("//");
+		if(start == -1) return uri;
+		start++;
+		int end = uri.indexOf("/",start+1);
+		if(end == -1) end = uri.indexOf("?",start+1);
+		if(end == -1) end = uri.indexOf("#",start+1);
+		if(end == -1) end = uri.length();
+		String before = uri.substring(0, start+1);
+		String authority= uri.substring(start+1,end);
+		String after = uri.substring(end);
+		authority = URIUtil.encode(authority, URI.allowed_authority);
+	
+		return before+authority+after;
+	}
+	
+	public static String encodePath(String uri) throws URIException
+	{
+		int doubleSlashIndex = uri.indexOf("//");
+		boolean hasAuthority =  doubleSlashIndex >= 0;
+		int start = -1;
+		if(hasAuthority)
+		{
+			start = uri.indexOf("/",doubleSlashIndex+2);
+		}
+		else
+		{
+			start = uri.indexOf(":");
+		}
+		if(start == -1) return uri;
+		
+		int end = uri.indexOf("?",start+1);
+		if(end == -1) end = uri.indexOf("#",start+1);
+		if(end == -1) end = uri.length();
+		String before = uri.substring(0, start+1);
+		String path= uri.substring(start+1,end);
+		String after = uri.substring(end);
+		path = URIUtil.encode(path, URI.allowed_abs_path);
+		return before+path+after;
+	}
+	
+	
+	public static String encodeQuery(String uri) throws URIException
+	{
+		int queryStart = uri.indexOf("?");
+		if(queryStart == -1) return uri;
+		int queryEnd = uri.indexOf("#");
+		if(queryEnd == -1) queryEnd = uri.length();
+		
+		String beforeQuery = uri.substring(0, queryStart+1);
+		String query = uri.substring(queryStart+1,queryEnd);
+		String afterQuery = uri.substring(queryEnd);
+		query = URIUtil.encode(query, URI.allowed_query);
+		return beforeQuery+query+afterQuery;
+	}
+	
+	
+	public static String encodeFragment(String uri) throws URIException
+	{
+		int fragmentStart = uri.indexOf("#");
+		if(fragmentStart == -1) return uri;
+
+		String beforeFragment = uri.substring(0, fragmentStart+1);
+		String fragment = uri.substring(fragmentStart+1);
+		fragment = URIUtil.encode(fragment, URI.allowed_fragment);
+		return beforeFragment+fragment;
+	}
+    public static java.net.URI createGsiftpURI(String host, String localPath) throws URISyntaxException {
+        StringBuffer buf = new StringBuffer();
+        if (!host.startsWith("gsiftp://"))
+            buf.append("gsiftp://");
+        buf.append(host);
+        if (!host.endsWith("/"))
+            buf.append("/");
+        buf.append(localPath);
+        return new java.net.URI(buf.toString());
+    }
+}
\ No newline at end of file