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/05 16:44:29 UTC

[5/8] changing package names of gfac implementations

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GramProviderUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GramProviderUtils.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GramProviderUtils.java
deleted file mode 100644
index d76b067..0000000
--- a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GramProviderUtils.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- *
- * 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.util;
-
-import org.apache.airavata.gfac.ToolsException;
-import org.apache.airavata.gfac.context.JobExecutionContext;
-import org.apache.airavata.gfac.provider.GFacProviderException;
-import org.apache.airavata.gfac.utils.*;
-import org.apache.airavata.model.workspace.experiment.JobState;
-import org.globus.gram.GramAttributes;
-import org.globus.gram.GramJob;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-public class GramProviderUtils {
-    private static final Logger log = LoggerFactory.getLogger(GramProviderUtils.class);
-
-    public static GramJob setupEnvironment(JobExecutionContext jobExecutionContext, boolean enableTwoPhase) throws GFacProviderException {
-        log.debug("Searching for Gate Keeper");
-        try {
-            GramAttributes jobAttr = GramRSLGenerator.configureRemoteJob(jobExecutionContext);
-            String rsl = jobAttr.toRSL();
-
-            if (enableTwoPhase) {
-                rsl = rsl + "(twoPhase=yes)";
-            }
-
-            log.debug("RSL = " + rsl);
-            GramJob job = new GramJob(rsl);
-            return job;
-        } catch (ToolsException te) {
-            throw new GFacProviderException(te.getMessage(), te);
-        }
-    }
-
-     public static JobState getApplicationJobStatus(int gramStatus) {
-        switch (gramStatus) {
-            case GramJob.STATUS_UNSUBMITTED:
-                return JobState.HELD;
-            case GramJob.STATUS_ACTIVE:
-                return JobState.ACTIVE;
-            case GramJob.STATUS_DONE:
-                return JobState.COMPLETE;
-            case GramJob.STATUS_FAILED:
-                return JobState.FAILED;
-            case GramJob.STATUS_PENDING:
-                return JobState.QUEUED;
-            case GramJob.STATUS_STAGE_IN:
-                return JobState.QUEUED;
-            case GramJob.STATUS_STAGE_OUT:
-                return JobState.COMPLETE;
-            case GramJob.STATUS_SUSPENDED:
-                return JobState.SUSPENDED;
-            default:
-                return JobState.UNKNOWN;
-        }
-    }
-
-    public static 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 URI(buf.toString());
-    }
-
-     public static URI createGsiftpURI(GridFTPContactInfo host, String localPath) throws URISyntaxException {
-        StringBuffer buf = new StringBuffer();
-
-        if (!host.hostName.startsWith("gsiftp://"))
-            buf.append("gsiftp://");
-        buf.append(host).append(":").append(host.port);
-        if (!host.hostName.endsWith("/"))
-            buf.append("/");
-        buf.append(localPath);
-        return new URI(buf.toString());
-    }
-
-    public static String createGsiftpURIAsString(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 buf.toString();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GramRSLGenerator.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GramRSLGenerator.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GramRSLGenerator.java
deleted file mode 100644
index 81782ff..0000000
--- a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GramRSLGenerator.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- *
- * 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.util;
-
-import org.apache.airavata.common.utils.StringUtil;
-import org.apache.airavata.commons.gfac.type.ActualParameter;
-import org.apache.airavata.commons.gfac.type.MappingFactory;
-import org.apache.airavata.gfac.Constants;
-import org.apache.airavata.gfac.ToolsException;
-import org.apache.airavata.gfac.context.JobExecutionContext;
-import org.apache.airavata.gfac.context.MessageContext;
-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.*;
-import org.globus.gram.GramAttributes;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-public class GramRSLGenerator {
-    protected static final Logger log = LoggerFactory.getLogger(GramRSLGenerator.class);
-
-    private enum JobType {
-        SERIAL, SINGLE, MPI, MULTIPLE, CONDOR
-    }
-
-    ;
-
-    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.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()) || "StringArray".equals(actualParameter.getType().getType().toString())
-                        || "FileArray".equals(actualParameter.getType().getType().toString())) {
-                    String[] values = null;
-                    if (actualParameter.getType() instanceof URIArrayType) {
-                        values = ((URIArrayType) actualParameter.getType()).getValueArray();
-                    } else if (actualParameter.getType() instanceof StringArrayType) {
-                        values = ((StringArrayType) actualParameter.getType()).getValueArray();
-                    } else if (actualParameter.getType() instanceof FileArrayType) {
-                        values = ((FileArrayType) actualParameter.getType()).getValueArray();
-                    }
-                    String value = StringUtil.createDelimiteredString(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
-        TaskDetails taskData = context.getTaskData();
-        if(taskData != null && taskData.isSetTaskScheduling()){
-        	 ComputationalResourceScheduling computionnalResource = taskData.getTaskScheduling();
-                try {
-                    int cpuCount = computionnalResource.getTotalCPUCount();
-                    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 = computionnalResource.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 = computionnalResource.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);
-                }
-                try {
-                    int maxwallTime = computionnalResource.getWallTimeLimit();
-                    if(maxwallTime>0){
-                        app.setMaxWallTime(maxwallTime);
-                    }
-                } 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 (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());
-            }
-        }
-        if (app.getMaxWallTime() > 0) {
-            log.debug("Setting max wall clock time to " + app.getMaxWallTime());
-
-            jobAttr.setMaxWallTime(app.getMaxWallTime());
-            jobAttr.set("proxy_timeout", "1");
-        } else {
-            jobAttr.setMaxWallTime(30);
-        }
-        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;
-    }
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GridFTPContactInfo.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GridFTPContactInfo.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GridFTPContactInfo.java
deleted file mode 100644
index d37beba..0000000
--- a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/util/GridFTPContactInfo.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- *
- * 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.util;
-
-import org.apache.airavata.gfac.Constants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class GridFTPContactInfo {
-    protected final static Logger log = LoggerFactory.getLogger(GridFTPContactInfo.class);
-    public String hostName;
-    public int port;
-
-    public GridFTPContactInfo(String hostName, int port) {
-        if (port <= 0 || port == 80) {
-            log.debug(hostName + "port recived " + port + " setting it to " + Constants.DEFAULT_GSI_FTP_PORT);
-            port = Constants.DEFAULT_GSI_FTP_PORT;
-        }
-        this.hostName = hostName;
-        this.port = port;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj instanceof GridFTPContactInfo) {
-            return hostName.equals(((GridFTPContactInfo) obj).hostName) && port == ((GridFTPContactInfo) obj).port;
-        } else {
-            return false;
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        return hostName.hashCode();
-    }
-
-    @Override
-    public String toString() {
-        StringBuffer buf = new StringBuffer();
-        buf.append(hostName).append(":").append(port);
-        return buf.toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GFacBaseTestWithMyProxyAuth.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GFacBaseTestWithMyProxyAuth.java b/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GFacBaseTestWithMyProxyAuth.java
index 24c364c..a5960d4 100644
--- a/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GFacBaseTestWithMyProxyAuth.java
+++ b/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GFacBaseTestWithMyProxyAuth.java
@@ -28,7 +28,7 @@ import org.apache.airavata.common.utils.DerbyUtil;
 import org.apache.airavata.credential.store.store.CredentialReader;
 import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl;
 import org.apache.airavata.gfac.RequestData;
-import org.apache.airavata.gfac.context.security.GSISecurityContext;
+import org.apache.airavata.gfac.gram.security.GSISecurityContext;
 import org.apache.log4j.Logger;
 import org.junit.BeforeClass;
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTestWithMyProxyAuth.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTestWithMyProxyAuth.java b/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTestWithMyProxyAuth.java
index ffaaaae..4fa945e 100644
--- a/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTestWithMyProxyAuth.java
+++ b/modules/gfac/gfac-gram/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTestWithMyProxyAuth.java
@@ -37,7 +37,7 @@ import org.apache.airavata.gfac.GFacException;
 import org.apache.airavata.gfac.context.ApplicationContext;
 import org.apache.airavata.gfac.context.JobExecutionContext;
 import org.apache.airavata.gfac.context.MessageContext;
-import org.apache.airavata.gfac.context.security.GSISecurityContext;
+import org.apache.airavata.gfac.gram.security.GSISecurityContext;
 import org.apache.airavata.gfac.cpi.GFacImpl;
 import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
 import org.apache.airavata.schemas.gfac.GlobusHostType;
@@ -80,8 +80,8 @@ public class GramProviderTestWithMyProxyAuth extends GFacBaseTestWithMyProxyAuth
 //        gFacConfiguration.setMyProxyPassphrase("*****");
 //        gFacConfiguration.setTrustedCertLocation("./certificates");
 //        //have to set InFlwo Handlers and outFlowHandlers
-//        gFacConfiguration.setInHandlers(Arrays.asList(new String[] {"org.apache.airavata.gfac.handler.GramDirectorySetupHandler","org.apache.airavata.gfac.handler.GridFTPInputHandler"}));
-//        gFacConfiguration.setOutHandlers(Arrays.asList(new String[] {"org.apache.airavata.gfac.handler.GridFTPOutputHandler"}));
+//        gFacConfiguration.setInHandlers(Arrays.asList(new String[] {"GramDirectorySetupHandler","GridFTPInputHandler"}));
+//        gFacConfiguration.setOutHandlers(Arrays.asList(new String[] {"GridFTPOutputHandler"}));
 
         /*
            * Host

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gram/src/test/resources/gfac-config.xml
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gram/src/test/resources/gfac-config.xml b/modules/gfac/gfac-gram/src/test/resources/gfac-config.xml
index 85d148d..ad1305e 100644
--- a/modules/gfac/gfac-gram/src/test/resources/gfac-config.xml
+++ b/modules/gfac/gfac-gram/src/test/resources/gfac-config.xml
@@ -21,13 +21,16 @@
     </GlobalHandlers>
 
 
-     <Provider class="org.apache.airavata.gfac.provider.impl.SSHProvider" host="org.apache.airavata.schemas.gfac.impl.SSHHostTypeImpl">
-         <InHandlers>
-            <Handler class="org.apache.airavata.gfac.handler.SSHDirectorySetupHandler"/>
-            <Handler class="org.apache.airavata.gfac.handler.SSHInputHandler"/>
+     <Provider class="org.apache.airavata.gfac.gram.provider.impl.GramProvider" host="org.apache.airavata.schemas.gfac.impl.GlobusHostTypeImpl">
+        <property name="name" value="value"/>
+        <InHandlers>
+            <Handler class="org.apache.airavata.gfac..gram.handler.GramDirectorySetupHandler">
+                    <property name="name" value="value"/>
+            </Handler>
+            <Handler class="org.apache.airavata.gfac..gram.handler.GridFTPInputHandler"/>
         </InHandlers>
         <OutHandlers>
-            <Handler class="org.apache.airavata.gfac.handler.SSHOutputHandler"/>
+            <Handler class="org.apache.airavata.gfac..gram.handler.GridFTPOutputHandler"/>
         </OutHandlers>
     </Provider>
 </GFac>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java
deleted file mode 100644
index 3eb020f..0000000
--- a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- *
- * 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.context.security;
-
-import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.ServerSettings;
-import org.apache.airavata.credential.store.credential.Credential;
-import org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential;
-import org.apache.airavata.credential.store.store.CredentialReader;
-import org.apache.airavata.gfac.AbstractSecurityContext;
-import org.apache.airavata.gfac.Constants;
-import org.apache.airavata.gfac.GFacException;
-import org.apache.airavata.gfac.RequestData;
-import org.apache.airavata.gsi.ssh.api.Cluster;
-import org.globus.gsi.X509Credential;
-import org.globus.gsi.gssapi.GlobusGSSCredentialImpl;
-import org.globus.gsi.provider.GlobusProvider;
-import org.globus.myproxy.GetParams;
-import org.globus.myproxy.MyProxy;
-import org.globus.myproxy.MyProxyException;
-import org.gridforum.jgss.ExtendedGSSCredential;
-import org.ietf.jgss.GSSCredential;
-import org.ietf.jgss.GSSException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.security.Security;
-import java.security.cert.X509Certificate;
-
-/**
- * Handles GRID related security.
- */
-public class GSISecurityContext extends AbstractSecurityContext {
-
-    protected static final Logger log = LoggerFactory.getLogger(GSISecurityContext.class);
-    /*
-     * context name
-     */
-    public static final String GSI_SECURITY_CONTEXT = "gsi";
-
-    public static int CREDENTIAL_RENEWING_THRESH_HOLD = 10 * 90;
-
-    private GSSCredential gssCredentials = null;
-
-    private Cluster pbsCluster = null;
-
-    // Set trusted cert path and add provider
-    static {
-        Security.addProvider(new GlobusProvider());
-        try {
-			setUpTrustedCertificatePath();
-		} catch (ApplicationSettingsException e) {
-			log.error(e.getLocalizedMessage(), e);
-		}
-    }
-
-    public static void setUpTrustedCertificatePath(String trustedCertificatePath) {
-
-        File file = new File(trustedCertificatePath);
-
-        if (!file.exists() || !file.canRead()) {
-            File f = new File(".");
-            log.info("Current directory " + f.getAbsolutePath());
-            throw new RuntimeException("Cannot read trusted certificate path " + trustedCertificatePath);
-        } else {
-            System.setProperty(Constants.TRUSTED_CERTIFICATE_SYSTEM_PROPERTY, file.getAbsolutePath());
-        }
-    }
-
-    private static void setUpTrustedCertificatePath() throws ApplicationSettingsException {
-
-        String trustedCertificatePath  = ServerSettings.getSetting(Constants.TRUSTED_CERT_LOCATION);
-
-        setUpTrustedCertificatePath(trustedCertificatePath);
-    }
-
-    /**
-     * Gets the trusted certificate path. Trusted certificate path is stored in "X509_CERT_DIR"
-     * system property.
-     * @return The trusted certificate path as a string.
-     */
-    public static String getTrustedCertificatePath() {
-        return System.getProperty(Constants.TRUSTED_CERTIFICATE_SYSTEM_PROPERTY);
-    }
-
-
-    public GSISecurityContext(CredentialReader credentialReader, RequestData requestData) {
-        super(credentialReader, requestData);
-    }
-
-
-    public GSISecurityContext(Cluster pbsCluster) {
-        this.setPbsCluster(pbsCluster);
-    }
-
-    /**
-     * Gets GSSCredentials. The process is as follows;
-     * If credentials were queried for the first time create credentials.
-     *   1. Try creating credentials using certificates stored in the credential store
-     *   2. If 1 fails use user name and password to create credentials
-     * If credentials are already created check the remaining life time of the credential. If
-     * remaining life time is less than CREDENTIAL_RENEWING_THRESH_HOLD, then renew credentials.
-     * @return GSSCredentials to be used.
-     * @throws org.apache.airavata.gfac.GFacException If an error occurred while creating credentials.
-     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
-     */
-    public GSSCredential getGssCredentials() throws GFacException, ApplicationSettingsException {
-
-        if (gssCredentials == null) {
-
-            try {
-                gssCredentials = getCredentialsFromStore();
-            } catch (Exception e) {
-                log.error("An exception occurred while retrieving credentials from the credential store. " +
-                        "Will continue with my proxy user name and password.", e);
-            }
-
-            // If store does not have credentials try to get from user name and password
-            if (gssCredentials == null) {
-                gssCredentials = getDefaultCredentials();
-            }
-
-            // if still null, throw an exception
-            if (gssCredentials == null) {
-                throw new GFacException("Unable to retrieve my proxy credentials to continue operation.");
-            }
-        } else {
-            try {
-                if (gssCredentials.getRemainingLifetime() < CREDENTIAL_RENEWING_THRESH_HOLD) {
-                    return renewCredentials();
-                }
-            } catch (GSSException e) {
-                throw new GFacException("Unable to retrieve remaining life time from credentials.", e);
-            }
-        }
-
-        return gssCredentials;
-    }
-
-    /**
-     * Renews credentials. First try to renew credentials as a trusted renewer. If that failed
-     * use user name and password to renew credentials.
-     * @return Renewed credentials.
-     * @throws org.apache.airavata.gfac.GFacException If an error occurred while renewing credentials.
-     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
-     */
-    public GSSCredential renewCredentials() throws GFacException, ApplicationSettingsException {
-
-        // First try to renew credentials as a trusted renewer
-        try {
-            gssCredentials = renewCredentialsAsATrustedHost();
-        } catch (Exception e) {
-            log.warn("Renewing credentials as a trusted renewer failed", e);
-            gssCredentials = getProxyCredentials();
-        }
-
-        return gssCredentials;
-    }
-
-    /**
-     * Reads the credentials from credential store.
-     * @return If token is found in the credential store, will return a valid credential. Else returns null.
-     * @throws Exception If an error occurred while retrieving credentials.
-     */
-    public GSSCredential getCredentialsFromStore() throws Exception {
-
-        if (getCredentialReader() == null) {
-            return null;
-        }
-
-        Credential credential = getCredentialReader().getCredential(getRequestData().getGatewayId(),
-                getRequestData().getTokenId());
-
-        if (credential != null) {
-            if (credential instanceof CertificateCredential) {
-
-                log.info("Successfully found credentials for token id - " + getRequestData().getTokenId() +
-                        " gateway id - " + getRequestData().getGatewayId());
-
-                CertificateCredential certificateCredential = (CertificateCredential) credential;
-
-                X509Certificate[] certificates = certificateCredential.getCertificates();
-                X509Credential newCredential = new X509Credential(certificateCredential.getPrivateKey(), certificates);
-
-                GlobusGSSCredentialImpl cred = new GlobusGSSCredentialImpl(newCredential, GSSCredential.INITIATE_AND_ACCEPT);
-                System.out.print(cred.export(ExtendedGSSCredential.IMPEXP_OPAQUE));
-                return cred;
-                //return new GlobusGSSCredentialImpl(newCredential,
-                //        GSSCredential.INITIATE_AND_ACCEPT);
-            } else {
-                log.info("Credential type is not CertificateCredential. Cannot create mapping globus credentials. " +
-                        "Credential type - " + credential.getClass().getName());
-            }
-        } else {
-            log.info("Could not find credentials for token - " + getRequestData().getTokenId() + " and "
-                    + "gateway id - " + getRequestData().getGatewayId());
-        }
-
-        return null;
-    }
-
-    /**
-     * Gets the default proxy certificate.
-     * @return Default my proxy credentials.
-     * @throws org.apache.airavata.gfac.GFacException If an error occurred while retrieving credentials.
-     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
-     */
-    public GSSCredential getDefaultCredentials() throws GFacException, ApplicationSettingsException{
-        MyProxy myproxy = new MyProxy(getRequestData().getMyProxyServerUrl(), getRequestData().getMyProxyPort());
-        try {
-            return myproxy.get(getRequestData().getMyProxyUserName(), getRequestData().getMyProxyPassword(),
-                    getRequestData().getMyProxyLifeTime());
-        } catch (MyProxyException e) {
-            throw new GFacException("An error occurred while retrieving default security credentials.", e);
-        }
-    }
-
-    /**
-     * Gets a new proxy certificate given current credentials.
-     * @return The short lived GSSCredentials
-     * @throws org.apache.airavata.gfac.GFacException If an error is occurred while retrieving credentials.
-     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
-     */
-    public GSSCredential getProxyCredentials() throws GFacException, ApplicationSettingsException {
-
-        MyProxy myproxy = new MyProxy(getRequestData().getMyProxyServerUrl(), getRequestData().getMyProxyPort());
-        try {
-            return myproxy.get(gssCredentials, getRequestData().getMyProxyUserName(), getRequestData().getMyProxyPassword(),
-                    getRequestData().getMyProxyLifeTime());
-        } catch (MyProxyException e) {
-            throw new GFacException("An error occurred while renewing security credentials using user/password.", e);
-        }
-    }
-
-    /**
-     * Renew GSSCredentials.
-     * Before executing we need to add current host as a trusted renewer. Note to renew credentials
-     * we dont need user name and password.
-     * To do that execute following command
-     * > myproxy-logon -t <LIFETIME></LIFETIME> -s <MY PROXY SERVER> -l <USER NAME>
-     * E.g :- > myproxy-logon -t 264 -s myproxy.teragrid.org -l us3
-     *          Enter MyProxy pass phrase:
-     *          A credential has been received for user us3 in /tmp/x509up_u501.
-     * > myproxy-init -A --cert /tmp/x509up_u501 --key /tmp/x509up_u501 -l ogce -s myproxy.teragrid.org
-     * @return  Renewed credentials.
-     * @throws org.apache.airavata.gfac.GFacException If an error occurred while renewing credentials.
-     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
-     */
-    public GSSCredential renewCredentialsAsATrustedHost() throws GFacException, ApplicationSettingsException {
-        MyProxy myproxy = new MyProxy(getRequestData().getMyProxyServerUrl(), getRequestData().getMyProxyPort());
-        GetParams getParams = new GetParams();
-        getParams.setAuthzCreds(gssCredentials);
-        getParams.setUserName(getRequestData().getMyProxyUserName());
-        getParams.setLifetime(getRequestData().getMyProxyLifeTime());
-        try {
-            return myproxy.get(gssCredentials, getParams);
-        } catch (MyProxyException e) {
-            throw new GFacException("An error occurred while renewing security credentials.", e);
-        }
-    }
-
-    public Cluster getPbsCluster() {
-        return pbsCluster;
-    }
-
-    public void setPbsCluster(Cluster pbsCluster) {
-        this.pbsCluster = pbsCluster;
-    }
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHDirectorySetupHandler.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHDirectorySetupHandler.java b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHDirectorySetupHandler.java
new file mode 100644
index 0000000..0f9e7fc
--- /dev/null
+++ b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHDirectorySetupHandler.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.gsissh.handler;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.gsissh.security.GSISecurityContext;
+import org.apache.airavata.gfac.gsissh.util.GFACGSISSHUtils;
+import org.apache.airavata.gfac.handler.AbstractHandler;
+import org.apache.airavata.gfac.handler.GFacHandlerException;
+import org.apache.airavata.gfac.utils.GFacUtils;
+import org.apache.airavata.gsi.ssh.api.Cluster;
+import org.apache.airavata.gsi.ssh.api.SSHApiException;
+import org.apache.airavata.model.workspace.experiment.*;
+import org.apache.airavata.registry.cpi.ChildDataType;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+public class GSISSHDirectorySetupHandler extends AbstractHandler {
+      private static final Logger log = LoggerFactory.getLogger(GSISSHDirectorySetupHandler.class);
+
+	public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
+        try {
+            if (jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT) == null) {
+                GFACGSISSHUtils.addSecurityContext(jobExecutionContext);
+            }
+        } catch (ApplicationSettingsException e) {
+            log.error(e.getMessage());
+            throw new GFacHandlerException("Error while creating SSHSecurityContext", e, e.getLocalizedMessage());
+        } catch (GFacException e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+
+        log.info("Setup SSH job directorties");
+        super.invoke(jobExecutionContext);
+        makeDirectory(jobExecutionContext);
+	}
+	private void makeDirectory(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
+                try {
+        Cluster cluster = ((GSISecurityContext) jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
+        if (cluster == null) {
+            throw new GFacHandlerException("Security context is not set properly");
+        } else {
+            log.info("Successfully retrieved the Security Context");
+        }
+        ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
+
+            String workingDirectory = app.getScratchWorkingDirectory();
+            cluster.makeDirectory(workingDirectory);
+            cluster.makeDirectory(app.getScratchWorkingDirectory());
+            cluster.makeDirectory(app.getInputDataDirectory());
+            cluster.makeDirectory(app.getOutputDataDirectory());
+            DataTransferDetails detail = new DataTransferDetails();
+            TransferStatus status = new TransferStatus();
+            status.setTransferState(TransferState.DIRECTORY_SETUP);
+            detail.setTransferStatus(status);
+            detail.setTransferDescription("Working directory = " + workingDirectory);
+
+            registry.add(ChildDataType.DATA_TRANSFER_DETAIL, detail, jobExecutionContext.getTaskData().getTaskID());
+
+        } catch (SSHApiException e) {
+            throw new GFacHandlerException("Error executing the Handler: " + GSISSHDirectorySetupHandler.class, e);
+        } catch (Exception e) {
+            DataTransferDetails detail = new DataTransferDetails();
+            TransferStatus status = new TransferStatus();
+            status.setTransferState(TransferState.FAILED);
+            detail.setTransferStatus(status);
+            try {
+                registry.add(ChildDataType.DATA_TRANSFER_DETAIL, detail, jobExecutionContext.getTaskData().getTaskID());
+                GFacUtils.saveErrorDetails(jobExecutionContext, e.getLocalizedMessage(), CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.FILE_SYSTEM_FAILURE);
+            } catch (Exception e1) {
+                throw new GFacHandlerException("Error persisting status", e1, e1.getLocalizedMessage());
+            }
+            throw new GFacHandlerException("Error executing the Handler: " + GSISSHDirectorySetupHandler.class, e);
+        }
+	}
+
+    public void initProperties(Map<String, String> properties) throws GFacHandlerException {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHInputHandler.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHInputHandler.java b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHInputHandler.java
new file mode 100644
index 0000000..ce9102a
--- /dev/null
+++ b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHInputHandler.java
@@ -0,0 +1,138 @@
+/*
+ *
+ * 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.gsissh.handler;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.StringUtil;
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.MappingFactory;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.context.MessageContext;
+import org.apache.airavata.gfac.gsissh.security.GSISecurityContext;
+import org.apache.airavata.gfac.gsissh.util.GFACGSISSHUtils;
+import org.apache.airavata.gfac.handler.AbstractHandler;
+import org.apache.airavata.gfac.handler.GFacHandlerException;
+import org.apache.airavata.gfac.utils.GFacUtils;
+import org.apache.airavata.gsi.ssh.api.Cluster;
+import org.apache.airavata.gsi.ssh.api.SSHApiException;
+import org.apache.airavata.model.workspace.experiment.*;
+import org.apache.airavata.registry.cpi.ChildDataType;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.apache.airavata.schemas.gfac.URIArrayType;
+import org.apache.airavata.schemas.gfac.URIParameterType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+
+public class GSISSHInputHandler extends AbstractHandler {
+    private static final Logger log = LoggerFactory.getLogger(GSISSHInputHandler.class);
+
+
+    public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
+        MessageContext inputNew = new MessageContext();
+        DataTransferDetails detail = new DataTransferDetails();
+        TransferStatus status = new TransferStatus();
+        try {
+            if (jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT) == null) {
+                try {
+                    GFACGSISSHUtils.addSecurityContext(jobExecutionContext);
+                } catch (ApplicationSettingsException e) {
+                    log.error(e.getMessage());
+                    throw new GFacHandlerException("Error while creating SSHSecurityContext", e, e.getLocalizedMessage());
+                }
+            }
+            log.info("Invoking SCPInputHandler");
+            super.invoke(jobExecutionContext);
+
+
+            MessageContext input = jobExecutionContext.getInMessageContext();
+            Set<String> parameters = input.getParameters().keySet();
+            for (String paramName : parameters) {
+                ActualParameter actualParameter = (ActualParameter) input.getParameters().get(paramName);
+                String paramValue = MappingFactory.toString(actualParameter);
+                //TODO: Review this with type
+                if ("URI".equals(actualParameter.getType().getType().toString())) {
+                    ((URIParameterType) actualParameter.getType()).setValue(stageInputFiles(jobExecutionContext, paramValue));
+                } else if ("URIArray".equals(actualParameter.getType().getType().toString())) {
+                    List<String> split = Arrays.asList(StringUtil.getElementsFromString(paramValue));
+                    List<String> newFiles = new ArrayList<String>();
+                    for (String paramValueEach : split) {
+                        String stageInputFiles = stageInputFiles(jobExecutionContext, paramValueEach);
+                        status.setTransferState(TransferState.UPLOAD);
+                        detail.setTransferStatus(status);
+                        detail.setTransferDescription("Input Data Staged: " + stageInputFiles);
+                        registry.add(ChildDataType.DATA_TRANSFER_DETAIL, detail, jobExecutionContext.getTaskData().getTaskID());
+                        newFiles.add(stageInputFiles);
+                    }
+                    ((URIArrayType) actualParameter.getType()).setValueArray(newFiles.toArray(new String[newFiles.size()]));
+                }
+                inputNew.getParameters().put(paramName, actualParameter);
+            }
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            status.setTransferState(TransferState.FAILED);
+            detail.setTransferStatus(status);
+            try {
+                GFacUtils.saveErrorDetails(jobExecutionContext, e.getLocalizedMessage(), CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.FILE_SYSTEM_FAILURE);
+                registry.add(ChildDataType.DATA_TRANSFER_DETAIL, detail, jobExecutionContext.getTaskData().getTaskID());
+            } catch (Exception e1) {
+                throw new GFacHandlerException("Error persisting status", e1, e1.getLocalizedMessage());
+            }
+            throw new GFacHandlerException("Error while input File Staging", e, e.getLocalizedMessage());
+        }
+        jobExecutionContext.setInMessageContext(inputNew);
+    }
+
+    private static String stageInputFiles(JobExecutionContext jobExecutionContext, String paramValue) throws IOException, GFacException {
+        Cluster cluster = null;
+        if (jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT) != null) {
+            cluster = ((GSISecurityContext) jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
+        } else {
+            cluster = ((GSISecurityContext) jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
+        }
+        if (cluster == null) {
+            throw new GFacException("Security context is not set properly");
+        } else {
+            log.info("Successfully retrieved the Security Context");
+        }
+        ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
+        int i = paramValue.lastIndexOf(File.separator);
+        String substring = paramValue.substring(i + 1);
+        try {
+            String targetFile = app.getInputDataDirectory() + File.separator + substring;
+            if (paramValue.startsWith("file")) {
+                paramValue = paramValue.substring(paramValue.indexOf(":") + 1, paramValue.length());
+            }
+            cluster.scpTo(targetFile, paramValue);
+            return targetFile;
+        } catch (SSHApiException e) {
+            throw new GFacHandlerException("Error while input File Staging", e, e.getLocalizedMessage());
+        }
+    }
+
+    public void initProperties(Map<String, String> properties) throws GFacHandlerException {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHOutputHandler.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHOutputHandler.java b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHOutputHandler.java
new file mode 100644
index 0000000..41932d9
--- /dev/null
+++ b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHOutputHandler.java
@@ -0,0 +1,221 @@
+/*
+ *
+ * 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.gsissh.handler;
+
+import net.schmizz.sshj.connection.ConnectionException;
+import net.schmizz.sshj.transport.TransportException;
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.Constants;
+import org.apache.airavata.commons.gfac.type.ActualParameter;
+import org.apache.airavata.commons.gfac.type.ApplicationDescription;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.gsissh.security.GSISecurityContext;
+import org.apache.airavata.gfac.gsissh.util.GFACGSISSHUtils;
+import org.apache.airavata.gfac.handler.AbstractHandler;
+import org.apache.airavata.gfac.handler.GFacHandlerException;
+import org.apache.airavata.gfac.provider.GFacProviderException;
+import org.apache.airavata.gfac.utils.GFacUtils;
+import org.apache.airavata.gfac.utils.OutputUtils;
+import org.apache.airavata.gsi.ssh.api.Cluster;
+import org.apache.airavata.gsi.ssh.api.job.JobDescriptor;
+import org.apache.airavata.model.workspace.experiment.*;
+import org.apache.airavata.registry.cpi.ChildDataType;
+import org.apache.airavata.registry.cpi.DataType;
+import org.apache.airavata.registry.cpi.RegistryException;
+import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
+import org.apache.airavata.schemas.gfac.GsisshHostType;
+import org.apache.airavata.schemas.gfac.URIParameterType;
+import org.apache.xmlbeans.XmlException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class GSISSHOutputHandler extends AbstractHandler {
+    private static final Logger log = LoggerFactory.getLogger(GSISSHOutputHandler.class);
+
+    public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
+        if(jobExecutionContext.getApplicationContext().getHostDescription().getType() instanceof GsisshHostType) { // this is because we don't have the right jobexecution context
+            // so attempting to get it from the registry
+            if (Constants.PUSH.equals(((GsisshHostType) jobExecutionContext.getApplicationContext().getHostDescription().getType()).getMonitorMode())) {
+                log.warn("During the out handler chain jobExecution context came null, so trying to handler");
+                ApplicationDescription applicationDeploymentDescription = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription();
+                TaskDetails taskData = null;
+                try {
+                    taskData = (TaskDetails) jobExecutionContext.getRegistry().get(DataType.TASK_DETAIL, jobExecutionContext.getTaskData().getTaskID());
+                } catch (RegistryException e) {
+                    log.error("Error retrieving job details from Registry");
+                    throw new GFacHandlerException("Error retrieving job details from Registry", e);
+                }
+                JobDetails jobDetails = taskData.getJobDetailsList().get(0);
+                String jobDescription = jobDetails.getJobDescription();
+                if (jobDescription != null) {
+                    JobDescriptor jobDescriptor = null;
+                    try {
+                        jobDescriptor = JobDescriptor.fromXML(jobDescription);
+                    } catch (XmlException e1) {
+                        e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                    }
+                    applicationDeploymentDescription.getType().setScratchWorkingDirectory(
+                            jobDescriptor.getJobDescriptorDocument().getJobDescriptor().getWorkingDirectory());
+                    applicationDeploymentDescription.getType().setInputDataDirectory(jobDescriptor.getInputDirectory());
+                    applicationDeploymentDescription.getType().setOutputDataDirectory(jobDescriptor.getOutputDirectory());
+                    applicationDeploymentDescription.getType().setStandardError(jobDescriptor.getJobDescriptorDocument().getJobDescriptor().getStandardErrorFile());
+                    applicationDeploymentDescription.getType().setStandardOutput(jobDescriptor.getJobDescriptorDocument().getJobDescriptor().getStandardOutFile());
+                }
+            }
+        }
+        try {
+            if (jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT) == null) {
+
+                GFACGSISSHUtils.addSecurityContext(jobExecutionContext);
+            }
+        } catch (ApplicationSettingsException e) {
+            log.error(e.getMessage());
+            throw new GFacHandlerException("Error while creating SSHSecurityContext", e, e.getLocalizedMessage());
+        } catch (GFacException e) {
+            log.error(e.getMessage());
+            throw new GFacHandlerException("Error while creating SSHSecurityContext", e, e.getLocalizedMessage());
+        }
+        super.invoke(jobExecutionContext);
+        DataTransferDetails detail = new DataTransferDetails();
+        TransferStatus status = new TransferStatus();
+
+        ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext()
+                .getApplicationDeploymentDescription().getType();
+        try {
+            Cluster cluster = null;
+            if (jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT) != null) {
+                cluster = ((GSISecurityContext) jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
+            } else {
+                cluster = ((GSISecurityContext) jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
+            }
+            if (cluster == null) {
+                throw new GFacProviderException("Security context is not set properly");
+            } else {
+                log.info("Successfully retrieved the Security Context");
+            }
+
+            // Get the Stdouts and StdErrs
+            String timeStampedServiceName = GFacUtils.createUniqueNameForService(jobExecutionContext.getServiceName());
+
+            TaskDetails taskData = jobExecutionContext.getTaskData();
+            String outputDataDir = null;
+            File localStdOutFile;
+            File localStdErrFile;
+
+            if (taskData.getAdvancedOutputDataHandling() != null) {
+                outputDataDir = taskData.getAdvancedOutputDataHandling().getOutputDataDir();
+            }
+            if (outputDataDir == null) {
+                outputDataDir = File.separator + "tmp";
+            }
+            outputDataDir = outputDataDir + File.separator + jobExecutionContext.getExperimentID() + "-" + jobExecutionContext.getTaskData().getTaskID();
+            (new File(outputDataDir)).mkdirs();
+
+
+            localStdOutFile = new File(outputDataDir + File.separator + timeStampedServiceName + "stdout");
+            localStdErrFile = new File(outputDataDir + File.separator + timeStampedServiceName + "stderr");
+//            cluster.makeDirectory(outputDataDir);
+            cluster.scpFrom(app.getStandardOutput(), localStdOutFile.getAbsolutePath());
+            Thread.sleep(1000);
+            cluster.scpFrom(app.getStandardError(), localStdErrFile.getAbsolutePath());
+            Thread.sleep(1000);
+
+            String stdOutStr = GFacUtils.readFileToString(localStdOutFile.getAbsolutePath());
+            String stdErrStr = GFacUtils.readFileToString(localStdErrFile.getAbsolutePath());
+            status.setTransferState(TransferState.COMPLETE);
+            detail.setTransferStatus(status);
+            detail.setTransferDescription("STDOUT:" + stdOutStr);
+            registry.add(ChildDataType.DATA_TRANSFER_DETAIL, detail, jobExecutionContext.getTaskData().getTaskID());
+
+            status.setTransferState(TransferState.COMPLETE);
+            detail.setTransferStatus(status);
+            detail.setTransferDescription("STDERR:" + stdErrStr);
+            registry.add(ChildDataType.DATA_TRANSFER_DETAIL, detail, jobExecutionContext.getTaskData().getTaskID());
+
+
+            Map<String, ActualParameter> stringMap = new HashMap<String, ActualParameter>();
+            Map<String, Object> output = jobExecutionContext.getOutMessageContext().getParameters();
+            Set<String> keys = output.keySet();
+            for (String paramName : keys) {
+                ActualParameter actualParameter = (ActualParameter) output.get(paramName);
+                if ("URI".equals(actualParameter.getType().getType().toString())) {
+
+                    List<String> outputList = cluster.listDirectory(app.getOutputDataDirectory());
+                    if (outputList.size() == 0 || outputList.get(0).isEmpty()) {
+                        stringMap = OutputUtils.fillOutputFromStdout(output, stdOutStr, stdErrStr);
+                    } else {
+                        String valueList = outputList.get(0);
+                        cluster.scpFrom(app.getOutputDataDirectory() + File.separator + valueList, outputDataDir);
+                        jobExecutionContext.addOutputFile(outputDataDir + File.separator + valueList);
+                        ((URIParameterType) actualParameter.getType()).setValue(valueList);
+                        stringMap = new HashMap<String, ActualParameter>();
+                        stringMap.put(paramName, actualParameter);
+                    }
+                } else {
+                    stringMap = OutputUtils.fillOutputFromStdout(output, stdOutStr, stdErrStr);
+                }
+            }
+            if (stringMap == null || stringMap.isEmpty()) {
+                throw new GFacHandlerException(
+                        "Empty Output returned from the Application, Double check the application"
+                                + "and ApplicationDescriptor output Parameter Names");
+            }
+            status.setTransferState(TransferState.DOWNLOAD);
+            detail.setTransferStatus(status);
+            registry.add(ChildDataType.DATA_TRANSFER_DETAIL, detail, jobExecutionContext.getTaskData().getTaskID());
+
+            app.setStandardError(localStdErrFile.getAbsolutePath());
+            app.setStandardOutput(localStdOutFile.getAbsolutePath());
+            app.setOutputDataDirectory(outputDataDir);
+        } catch (XmlException e) {
+            throw new GFacHandlerException("Cannot read output:" + e.getMessage(), e);
+        } catch (ConnectionException e) {
+            throw new GFacHandlerException(e.getMessage(), e);
+        } catch (TransportException e) {
+            throw new GFacHandlerException(e.getMessage(), e);
+        } catch (IOException e) {
+            throw new GFacHandlerException(e.getMessage(), e);
+        } catch (Exception e) {
+            try {
+                status.setTransferState(TransferState.FAILED);
+                detail.setTransferStatus(status);
+                registry.add(ChildDataType.DATA_TRANSFER_DETAIL, detail, jobExecutionContext.getTaskData().getTaskID());
+                GFacUtils.saveErrorDetails(jobExecutionContext, e.getLocalizedMessage(), CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.FILE_SYSTEM_FAILURE);
+            } catch (Exception e1) {
+                throw new GFacHandlerException("Error persisting status", e1, e1.getLocalizedMessage());
+            }
+            throw new GFacHandlerException("Error in retrieving results", e);
+        }
+
+    }
+
+    public void initProperties(Map<String, String> properties) throws GFacHandlerException {
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/impl/GSISSHProvider.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/impl/GSISSHProvider.java b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/impl/GSISSHProvider.java
new file mode 100644
index 0000000..5ba5ebf
--- /dev/null
+++ b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/impl/GSISSHProvider.java
@@ -0,0 +1,138 @@
+/*
+ *
+ * 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.gsissh.impl;
+
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.context.JobExecutionContext;
+import org.apache.airavata.gfac.gsissh.security.GSISecurityContext;
+import org.apache.airavata.gfac.cpi.GFacImpl;
+import org.apache.airavata.gfac.gsissh.util.GFACGSISSHUtils;
+import org.apache.airavata.gfac.handler.ThreadedHandler;
+import org.apache.airavata.gfac.notification.events.StartExecutionEvent;
+import org.apache.airavata.gfac.provider.AbstractProvider;
+import org.apache.airavata.gfac.provider.GFacProviderException;
+import org.apache.airavata.gfac.utils.GFacUtils;
+import org.apache.airavata.gsi.ssh.api.Cluster;
+import org.apache.airavata.gsi.ssh.api.SSHApiException;
+import org.apache.airavata.gsi.ssh.api.job.JobDescriptor;
+import org.apache.airavata.model.workspace.experiment.CorrectiveAction;
+import org.apache.airavata.model.workspace.experiment.ErrorCategory;
+import org.apache.airavata.model.workspace.experiment.JobDetails;
+import org.apache.airavata.model.workspace.experiment.JobState;
+import org.apache.airavata.schemas.gfac.GsisshHostType;
+import org.apache.airavata.schemas.gfac.HostDescriptionType;
+import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+
+public class GSISSHProvider extends AbstractProvider {
+    private static final Logger log = LoggerFactory.getLogger(GSISSHProvider.class);
+
+    public void initProperties(Map<String, String> properties) throws GFacProviderException, GFacException {
+
+    }
+
+    public void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException {
+    	super.initialize(jobExecutionContext);
+    }
+
+    public void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException {
+        log.info("Invoking GSISSH Provider Invoke ...");
+        jobExecutionContext.getNotifier().publish(new StartExecutionEvent());
+        HostDescriptionType host = jobExecutionContext.getApplicationContext().
+                getHostDescription().getType();
+        HpcApplicationDeploymentType app = (HpcApplicationDeploymentType) jobExecutionContext.getApplicationContext().
+                getApplicationDeploymentDescription().getType();
+        JobDetails jobDetails = new JobDetails();
+     	String taskID = jobExecutionContext.getTaskData().getTaskID();
+        try {
+            Cluster cluster = null;
+            if (jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT) != null) {
+                cluster = ((GSISecurityContext) jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
+            }
+            if (cluster == null) {
+                throw new GFacProviderException("Security context is not set properly");
+            } else {
+                log.info("Successfully retrieved the Security Context");
+            }
+            // This installed path is a mandetory field, because this could change based on the computing resource
+            JobDescriptor jobDescriptor = GFACGSISSHUtils.createJobDescriptor(jobExecutionContext, app, cluster);
+
+            log.info(jobDescriptor.toXML());
+            
+            jobDetails.setJobDescription(jobDescriptor.toXML());
+            
+            String jobID = cluster.submitBatchJob(jobDescriptor);
+            jobExecutionContext.setJobDetails(jobDetails);
+            if(jobID == null){
+                jobDetails.setJobID("none");
+                GFacUtils.saveJobStatus(jobExecutionContext, jobDetails, JobState.FAILED);
+            }else{
+                jobDetails.setJobID(jobID);
+                GFacUtils.saveJobStatus(jobExecutionContext, jobDetails, JobState.SUBMITTED);
+            }
+
+
+            // Now job has submitted to the resource, its up to the Provider to parse the information to daemon handler
+            // to perform monitoring, daemon handlers can be accessed from anywhere
+            List<ThreadedHandler> daemonHandlers = GFacImpl.getDaemonHandlers();
+            ThreadedHandler pullMonitorHandler = null;
+            for(ThreadedHandler threadedHandler:daemonHandlers){
+                if("org.apache.airavata.gfac.monitor.handlers.GridPullMonitorHandler".equals(threadedHandler.getClass().getName())){
+                    pullMonitorHandler = threadedHandler;
+                }
+            }
+            // we know this hos is type GsiSSHHostType
+            String monitorMode = ((GsisshHostType) host).getMonitorMode();
+            if("".equals(monitorMode) || monitorMode == null || org.apache.airavata.common.utils.Constants.PULL.equals(monitorMode)){
+                log.info("Job is launched successfully now parsing it to monitoring in pull mode, JobID Returned:  " + jobID);
+                pullMonitorHandler.invoke(jobExecutionContext);
+            }else{
+                log.error("Currently we only support Pull monitoring");
+            }
+        } catch (SSHApiException e) {
+            String error = "Error submitting the job to host " + host.getHostAddress() + " message: " + e.getMessage();
+            log.error(error);
+            jobDetails.setJobID("none");
+        	GFacUtils.saveJobStatus(jobExecutionContext, jobDetails,JobState.FAILED);
+         	GFacUtils.saveErrorDetails(jobExecutionContext, error, CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.AIRAVATA_INTERNAL_ERROR);
+            throw new GFacProviderException(error, e);
+        } catch (Exception e) {
+        	String error = "Error submitting the job to host " + host.getHostAddress() + " message: " + e.getMessage();
+         	log.error(error);
+            jobDetails.setJobID("none");
+        	GFacUtils.saveJobStatus(jobExecutionContext, jobDetails,JobState.FAILED);
+         	GFacUtils.saveErrorDetails(jobExecutionContext, error, CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.AIRAVATA_INTERNAL_ERROR);
+            throw new GFacProviderException(error, e);
+        }
+    }
+
+    public void dispose(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void cancelJob(String jobId, JobExecutionContext jobExecutionContext) throws GFacException {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/9bb8c2be/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/security/GSISecurityContext.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/security/GSISecurityContext.java b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/security/GSISecurityContext.java
new file mode 100644
index 0000000..a09b72e
--- /dev/null
+++ b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/security/GSISecurityContext.java
@@ -0,0 +1,288 @@
+/*
+ *
+ * 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.gsissh.security;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.credential.store.credential.Credential;
+import org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential;
+import org.apache.airavata.credential.store.store.CredentialReader;
+import org.apache.airavata.gfac.AbstractSecurityContext;
+import org.apache.airavata.gfac.Constants;
+import org.apache.airavata.gfac.GFacException;
+import org.apache.airavata.gfac.RequestData;
+import org.apache.airavata.gsi.ssh.api.Cluster;
+import org.globus.gsi.X509Credential;
+import org.globus.gsi.gssapi.GlobusGSSCredentialImpl;
+import org.globus.gsi.provider.GlobusProvider;
+import org.globus.myproxy.GetParams;
+import org.globus.myproxy.MyProxy;
+import org.globus.myproxy.MyProxyException;
+import org.gridforum.jgss.ExtendedGSSCredential;
+import org.ietf.jgss.GSSCredential;
+import org.ietf.jgss.GSSException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.security.Security;
+import java.security.cert.X509Certificate;
+
+/**
+ * Handles GRID related security.
+ */
+public class GSISecurityContext extends AbstractSecurityContext {
+
+    protected static final Logger log = LoggerFactory.getLogger(GSISecurityContext.class);
+    /*
+     * context name
+     */
+    public static final String GSI_SECURITY_CONTEXT = "gsi";
+
+    public static int CREDENTIAL_RENEWING_THRESH_HOLD = 10 * 90;
+
+    private GSSCredential gssCredentials = null;
+
+    private Cluster pbsCluster = null;
+
+    // Set trusted cert path and add provider
+    static {
+        Security.addProvider(new GlobusProvider());
+        try {
+			setUpTrustedCertificatePath();
+		} catch (ApplicationSettingsException e) {
+			log.error(e.getLocalizedMessage(), e);
+		}
+    }
+
+    public static void setUpTrustedCertificatePath(String trustedCertificatePath) {
+
+        File file = new File(trustedCertificatePath);
+
+        if (!file.exists() || !file.canRead()) {
+            File f = new File(".");
+            log.info("Current directory " + f.getAbsolutePath());
+            throw new RuntimeException("Cannot read trusted certificate path " + trustedCertificatePath);
+        } else {
+            System.setProperty(Constants.TRUSTED_CERTIFICATE_SYSTEM_PROPERTY, file.getAbsolutePath());
+        }
+    }
+
+    private static void setUpTrustedCertificatePath() throws ApplicationSettingsException {
+
+        String trustedCertificatePath  = ServerSettings.getSetting(Constants.TRUSTED_CERT_LOCATION);
+
+        setUpTrustedCertificatePath(trustedCertificatePath);
+    }
+
+    /**
+     * Gets the trusted certificate path. Trusted certificate path is stored in "X509_CERT_DIR"
+     * system property.
+     * @return The trusted certificate path as a string.
+     */
+    public static String getTrustedCertificatePath() {
+        return System.getProperty(Constants.TRUSTED_CERTIFICATE_SYSTEM_PROPERTY);
+    }
+
+
+    public GSISecurityContext(CredentialReader credentialReader, RequestData requestData) {
+        super(credentialReader, requestData);
+    }
+
+
+    public GSISecurityContext(Cluster pbsCluster) {
+        this.setPbsCluster(pbsCluster);
+    }
+
+    /**
+     * Gets GSSCredentials. The process is as follows;
+     * If credentials were queried for the first time create credentials.
+     *   1. Try creating credentials using certificates stored in the credential store
+     *   2. If 1 fails use user name and password to create credentials
+     * If credentials are already created check the remaining life time of the credential. If
+     * remaining life time is less than CREDENTIAL_RENEWING_THRESH_HOLD, then renew credentials.
+     * @return GSSCredentials to be used.
+     * @throws org.apache.airavata.gfac.GFacException If an error occurred while creating credentials.
+     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
+     */
+    public GSSCredential getGssCredentials() throws GFacException, ApplicationSettingsException {
+
+        if (gssCredentials == null) {
+
+            try {
+                gssCredentials = getCredentialsFromStore();
+            } catch (Exception e) {
+                log.error("An exception occurred while retrieving credentials from the credential store. " +
+                        "Will continue with my proxy user name and password.", e);
+            }
+
+            // If store does not have credentials try to get from user name and password
+            if (gssCredentials == null) {
+                gssCredentials = getDefaultCredentials();
+            }
+
+            // if still null, throw an exception
+            if (gssCredentials == null) {
+                throw new GFacException("Unable to retrieve my proxy credentials to continue operation.");
+            }
+        } else {
+            try {
+                if (gssCredentials.getRemainingLifetime() < CREDENTIAL_RENEWING_THRESH_HOLD) {
+                    return renewCredentials();
+                }
+            } catch (GSSException e) {
+                throw new GFacException("Unable to retrieve remaining life time from credentials.", e);
+            }
+        }
+
+        return gssCredentials;
+    }
+
+    /**
+     * Renews credentials. First try to renew credentials as a trusted renewer. If that failed
+     * use user name and password to renew credentials.
+     * @return Renewed credentials.
+     * @throws org.apache.airavata.gfac.GFacException If an error occurred while renewing credentials.
+     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
+     */
+    public GSSCredential renewCredentials() throws GFacException, ApplicationSettingsException {
+
+        // First try to renew credentials as a trusted renewer
+        try {
+            gssCredentials = renewCredentialsAsATrustedHost();
+        } catch (Exception e) {
+            log.warn("Renewing credentials as a trusted renewer failed", e);
+            gssCredentials = getProxyCredentials();
+        }
+
+        return gssCredentials;
+    }
+
+    /**
+     * Reads the credentials from credential store.
+     * @return If token is found in the credential store, will return a valid credential. Else returns null.
+     * @throws Exception If an error occurred while retrieving credentials.
+     */
+    public GSSCredential getCredentialsFromStore() throws Exception {
+
+        if (getCredentialReader() == null) {
+            return null;
+        }
+
+        Credential credential = getCredentialReader().getCredential(getRequestData().getGatewayId(),
+                getRequestData().getTokenId());
+
+        if (credential != null) {
+            if (credential instanceof CertificateCredential) {
+
+                log.info("Successfully found credentials for token id - " + getRequestData().getTokenId() +
+                        " gateway id - " + getRequestData().getGatewayId());
+
+                CertificateCredential certificateCredential = (CertificateCredential) credential;
+
+                X509Certificate[] certificates = certificateCredential.getCertificates();
+                X509Credential newCredential = new X509Credential(certificateCredential.getPrivateKey(), certificates);
+
+                GlobusGSSCredentialImpl cred = new GlobusGSSCredentialImpl(newCredential, GSSCredential.INITIATE_AND_ACCEPT);
+                System.out.print(cred.export(ExtendedGSSCredential.IMPEXP_OPAQUE));
+                return cred;
+                //return new GlobusGSSCredentialImpl(newCredential,
+                //        GSSCredential.INITIATE_AND_ACCEPT);
+            } else {
+                log.info("Credential type is not CertificateCredential. Cannot create mapping globus credentials. " +
+                        "Credential type - " + credential.getClass().getName());
+            }
+        } else {
+            log.info("Could not find credentials for token - " + getRequestData().getTokenId() + " and "
+                    + "gateway id - " + getRequestData().getGatewayId());
+        }
+
+        return null;
+    }
+
+    /**
+     * Gets the default proxy certificate.
+     * @return Default my proxy credentials.
+     * @throws org.apache.airavata.gfac.GFacException If an error occurred while retrieving credentials.
+     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
+     */
+    public GSSCredential getDefaultCredentials() throws GFacException, ApplicationSettingsException{
+        MyProxy myproxy = new MyProxy(getRequestData().getMyProxyServerUrl(), getRequestData().getMyProxyPort());
+        try {
+            return myproxy.get(getRequestData().getMyProxyUserName(), getRequestData().getMyProxyPassword(),
+                    getRequestData().getMyProxyLifeTime());
+        } catch (MyProxyException e) {
+            throw new GFacException("An error occurred while retrieving default security credentials.", e);
+        }
+    }
+
+    /**
+     * Gets a new proxy certificate given current credentials.
+     * @return The short lived GSSCredentials
+     * @throws org.apache.airavata.gfac.GFacException If an error is occurred while retrieving credentials.
+     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
+     */
+    public GSSCredential getProxyCredentials() throws GFacException, ApplicationSettingsException {
+
+        MyProxy myproxy = new MyProxy(getRequestData().getMyProxyServerUrl(), getRequestData().getMyProxyPort());
+        try {
+            return myproxy.get(gssCredentials, getRequestData().getMyProxyUserName(), getRequestData().getMyProxyPassword(),
+                    getRequestData().getMyProxyLifeTime());
+        } catch (MyProxyException e) {
+            throw new GFacException("An error occurred while renewing security credentials using user/password.", e);
+        }
+    }
+
+    /**
+     * Renew GSSCredentials.
+     * Before executing we need to add current host as a trusted renewer. Note to renew credentials
+     * we dont need user name and password.
+     * To do that execute following command
+     * > myproxy-logon -t <LIFETIME></LIFETIME> -s <MY PROXY SERVER> -l <USER NAME>
+     * E.g :- > myproxy-logon -t 264 -s myproxy.teragrid.org -l us3
+     *          Enter MyProxy pass phrase:
+     *          A credential has been received for user us3 in /tmp/x509up_u501.
+     * > myproxy-init -A --cert /tmp/x509up_u501 --key /tmp/x509up_u501 -l ogce -s myproxy.teragrid.org
+     * @return  Renewed credentials.
+     * @throws org.apache.airavata.gfac.GFacException If an error occurred while renewing credentials.
+     * @throws org.apache.airavata.common.exception.ApplicationSettingsException
+     */
+    public GSSCredential renewCredentialsAsATrustedHost() throws GFacException, ApplicationSettingsException {
+        MyProxy myproxy = new MyProxy(getRequestData().getMyProxyServerUrl(), getRequestData().getMyProxyPort());
+        GetParams getParams = new GetParams();
+        getParams.setAuthzCreds(gssCredentials);
+        getParams.setUserName(getRequestData().getMyProxyUserName());
+        getParams.setLifetime(getRequestData().getMyProxyLifeTime());
+        try {
+            return myproxy.get(gssCredentials, getParams);
+        } catch (MyProxyException e) {
+            throw new GFacException("An error occurred while renewing security credentials.", e);
+        }
+    }
+
+    public Cluster getPbsCluster() {
+        return pbsCluster;
+    }
+
+    public void setPbsCluster(Cluster pbsCluster) {
+        this.pbsCluster = pbsCluster;
+    }
+}