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/04/24 22:52:00 UTC
[04/11] creating gfac-bes and gfac-gram out from gfac-core
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/provider/utils/URIUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/provider/utils/URIUtils.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/provider/utils/URIUtils.java
deleted file mode 100644
index 4404a37..0000000
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/provider/utils/URIUtils.java
+++ /dev/null
@@ -1,107 +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.provider.utils;
-
-import org.apache.commons.httpclient.URI;
-import org.apache.commons.httpclient.URIException;
-import org.apache.commons.httpclient.util.URIUtil;
-
-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;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java
index 49ca569..3058909 100644
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GFacUtils.java
@@ -52,7 +52,6 @@ import org.apache.airavata.registry.cpi.CompositeIdentifier;
import org.apache.airavata.registry.cpi.Registry;
import org.apache.airavata.schemas.gfac.*;
import org.apache.axiom.om.OMElement;
-import org.globus.gram.GramJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -127,28 +126,9 @@ public class GFacUtils {
return serviceName + "_" + date + "_" + UUID.randomUUID();
}
- 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 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 String createGsiftpURIAsString(String host, String localPath) throws URISyntaxException {
StringBuffer buf = new StringBuffer();
@@ -649,28 +629,7 @@ public class GFacUtils {
throw new GFacException("Error persisting job status" + e.getLocalizedMessage(),e);
}
}
- 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 Map<String, Object> getMessageContext(List<DataObjectType> experimentData,
Parameter[] parameters) throws GFacException {
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java
deleted file mode 100644
index c8d8de6..0000000
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramJobSubmissionListener.java
+++ /dev/null
@@ -1,141 +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.utils;
-
-import org.apache.airavata.gfac.GFacException;
-import org.apache.airavata.gfac.context.JobExecutionContext;
-import org.apache.airavata.gfac.context.security.GSISecurityContext;
-import org.apache.airavata.gfac.notification.events.StatusChangeEvent;
-import org.apache.airavata.model.workspace.experiment.JobState;
-import org.globus.gram.GramJob;
-import org.globus.gram.GramJobListener;
-import org.ietf.jgss.GSSCredential;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class GramJobSubmissionListener implements GramJobListener{
- private final Logger log = LoggerFactory.getLogger(GramJobSubmissionListener.class);
-
- public static final int NO_ERROR = -42;
- public static final int INITIAL_STATUS = -43;
-
- private volatile boolean jobDone = false;
- private volatile int error = NO_ERROR;
- private int currentStatus = INITIAL_STATUS;
-
- private JobExecutionContext context;
- private GramJob job;
-
- public GramJobSubmissionListener(GramJob job, JobExecutionContext context) {
- this.job = job;
- this.context = context;
- }
-
- /**
- * This method is used to block the process until the currentStatus of the job is DONE or FAILED
- */
- public void waitFor() {
- while (!isJobDone()) {
- synchronized (this) {
- try {
- wait();
- } catch (InterruptedException e) {}
- }
- }
- }
-
-
-
- private synchronized boolean isJobDone() {
- return this.jobDone;
- }
-
- private void setStatus(int status, int error) {
- try {
- GFacUtils.updateJobStatus(context.getJobDetails(), GFacUtils.getApplicationJobStatus(status));
- } catch (GFacException e) {
- log.error("Error persisting status" + e.getLocalizedMessage(), e);
- }
- this.currentStatus = status;
- this.error = error;
-
- switch (this.currentStatus) {
- case GramJob.STATUS_FAILED:
- log.info("Job Error Code: " + error);
- this.jobDone = true;
- notifyAll();
- case GramJob.STATUS_DONE:
- this.jobDone = true;
- notifyAll();
- }
-
- }
-
- public synchronized void statusChanged(GramJob job) {
-
- int jobStatus = job.getStatus();
- String jobStatusMessage = "Status of job " + job.getIDAsString() + "is " + job.getStatusAsString();
- /*
- * Notify currentStatus change
- */
- this.context.getNotifier().publish(new StatusChangeEvent(jobStatusMessage));
-
- /*
- * Set new currentStatus if it is jobDone, notify all wait object
- */
- if (currentStatus != jobStatus) {
- currentStatus = jobStatus;
-
- setStatus(job.getStatus(), job.getError());
-
- // Test to see whether we need to renew credentials
- renewCredentials(job);
- }
- }
-
- private void renewCredentials(GramJob job) {
-
- try {
-
- int proxyExpTime = job.getCredentials().getRemainingLifetime();
- if (proxyExpTime < GSISecurityContext.CREDENTIAL_RENEWING_THRESH_HOLD) {
- log.info("Job proxy expired. Trying to renew proxy");
- GSSCredential gssCred = ((GSISecurityContext)context.
- getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).renewCredentials();
- job.renew(gssCred);
- log.info("MyProxy credentials are renewed .");
- }
-
- } catch (Exception e) {
- log.error("An error occurred while trying to renew credentials. Job id " + job.getIDAsString());
- }
-
-
- }
-
- public synchronized int getError() {
- return error;
- }
-
- public synchronized int getCurrentStatus() {
- return currentStatus;
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramProviderUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramProviderUtils.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramProviderUtils.java
deleted file mode 100644
index eaf9a4a..0000000
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramProviderUtils.java
+++ /dev/null
@@ -1,54 +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.utils;
-
-import org.apache.airavata.gfac.ToolsException;
-import org.apache.airavata.gfac.context.JobExecutionContext;
-import org.apache.airavata.gfac.provider.GFacProviderException;
-import org.globus.gram.GramAttributes;
-import org.globus.gram.GramJob;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class GramProviderUtils {
- private static final Logger log = LoggerFactory.getLogger(GramJobSubmissionListener.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);
- }
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramRSLGenerator.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramRSLGenerator.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramRSLGenerator.java
deleted file mode 100644
index 187d8f1..0000000
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GramRSLGenerator.java
+++ /dev/null
@@ -1,216 +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.utils;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-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.FileArrayType;
-import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
-import org.apache.airavata.schemas.gfac.NameValuePairType;
-import org.apache.airavata.schemas.gfac.QueueType;
-import org.apache.airavata.schemas.gfac.StringArrayType;
-import org.apache.airavata.schemas.gfac.URIArrayType;
-import org.globus.gram.GramAttributes;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-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/13b505ae/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridConfigurationHandler.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridConfigurationHandler.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridConfigurationHandler.java
deleted file mode 100644
index ed7e57e..0000000
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridConfigurationHandler.java
+++ /dev/null
@@ -1,79 +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.utils;
-import org.apache.airavata.common.utils.Version;
-import org.globus.ftp.GridFTPClient;
-
-public interface GridConfigurationHandler {
- public static class GridConfigurationHandlerException extends Exception{
- private static final long serialVersionUID = 4009827774771871814L;
-
- public GridConfigurationHandlerException(String message, Throwable e){
- super(message,e);
- }
- }
-
- /**
- * A unique name for this GridConfigruationHandler
- * @return
- */
- public String getHandlerName();
-
- /**
- * The version of this handler.
- * Note: Given multiple versions of the same handler, the latest version will be used.
- * @return
- */
- public Version getHandlerVersion();
-
- /**
- * Gets triggered if any GridFTP tasks other than mentioned below if called. This is there to
- * support future extensions in GridFTP tasks so that the handlers need not be updated necessarily
- * @param client
- * @param taskDescription - a description of the task that is being carried out.
- * @throws Exception
- */
- public void handleFTPClientConfigurations(GridFTPClient client, String taskDescription) throws GridConfigurationHandlerException;
-
- /**
- * Do the configurations required for the source GridFTPClient object
- * @param source - <code>null</code> if the transfer is from the local file-system
- * @param destination - <code>null</code> if the transfer is to the local file-system
- * @throws Exception
- */
- public void handleFileTransferFTPClientConfigurations(GridFTPClient source, GridFTPClient destination) throws GridConfigurationHandlerException;
-
- /**
- * Do the configurations required for the GridFTPClient object which is going to create a directory
- * @param client
- * @throws Exception
- */
- public void handleMakeDirFTPClientConfigurations(GridFTPClient client, String dirPath) throws GridConfigurationHandlerException;
-
- /**
- * Do the configurations required for the GridFTPClient object which is going to list a directory
- * @param client
- * @param dirPath
- * @throws Exception
- */
- public void handleListDirFTPClientConfigurations(GridFTPClient client, String dirPath) throws GridConfigurationHandlerException;
-}
-
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridFTPContactInfo.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridFTPContactInfo.java b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/GridFTPContactInfo.java
deleted file mode 100644
index 397f4b8..0000000
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/utils/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.utils;
-
-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/13b505ae/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GFacBaseTestWithMyProxyAuth.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GFacBaseTestWithMyProxyAuth.java b/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GFacBaseTestWithMyProxyAuth.java
deleted file mode 100644
index 1cd8ee6..0000000
--- a/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GFacBaseTestWithMyProxyAuth.java
+++ /dev/null
@@ -1,115 +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.core.gfac.services.impl;
-
-import junit.framework.Assert;
-import org.apache.airavata.common.utils.AiravataUtils;
-import org.apache.airavata.common.utils.DatabaseTestCases;
-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.log4j.Logger;
-import org.junit.BeforeClass;
-
-/**
- * User: AmilaJ (amilaj@apache.org)
- * Date: 7/11/13
- * Time: 1:31 AM
- */
-
-public class GFacBaseTestWithMyProxyAuth extends DatabaseTestCases {
-
- private static String myProxyUserName;
- private static String myProxyPassword;
-
- private static final Logger log = Logger.getLogger(GFacBaseTestWithMyProxyAuth.class);
-
-
- @BeforeClass
- public static void setUpClass() throws Exception {
- AiravataUtils.setExecutionAsServer();
-
- myProxyUserName = System.getProperty("myproxy.user");
- myProxyPassword = System.getProperty("myproxy.password");
-
- if (userName == null || password == null || userName.trim().equals("") || password.trim().equals("")) {
- log.error("===== Please set myproxy.user and myproxy.password system properties. =======");
- Assert.fail("Please set myproxy.user and myproxy.password system properties.");
- }
-
- log.info("Using my proxy user name - " + userName);
-
- setUpDatabase();
-
- }
-
-
-
-
- public static void setUpDatabase() throws Exception {
- DerbyUtil.startDerbyInServerMode(getHostAddress(), getPort(), getUserName(), getPassword());
-
- waitTillServerStarts();
-
- /*
- * String createTable = "CREATE TABLE CREDENTIALS\n" + "(\n" + " GATEWAY_NAME VARCHAR(256) NOT NULL,\n" +
- * " COMMUNITY_USER_NAME VARCHAR(256) NOT NULL,\n" + " CREDENTIAL BLOB NOT NULL,\n" +
- * " PRIVATE_KEY BLOB NOT NULL,\n" + " NOT_BEFORE VARCHAR(256) NOT NULL,\n" +
- * " NOT_AFTER VARCHAR(256) NOT NULL,\n" + " LIFETIME INTEGER NOT NULL,\n" +
- * " REQUESTING_PORTAL_USER_NAME VARCHAR(256) NOT NULL,\n" +
- * " REQUESTED_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',\n" +
- * " PRIMARY KEY (GATEWAY_NAME, COMMUNITY_USER_NAME)\n" + ")";
- */
-
- String createTable = "CREATE TABLE CREDENTIALS\n" + "(\n"
- + " GATEWAY_ID VARCHAR(256) NOT NULL,\n"
- + " TOKEN_ID VARCHAR(256) NOT NULL,\n"
- + // Actual token used to identify the credential
- " CREDENTIAL BLOB NOT NULL,\n" + " PORTAL_USER_ID VARCHAR(256) NOT NULL,\n"
- + " TIME_PERSISTED TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n"
- + " PRIMARY KEY (GATEWAY_ID, TOKEN_ID)\n" + ")";
-
- String dropTable = "drop table CREDENTIALS";
-
- try {
- executeSQL(dropTable);
- } catch (Exception e) {
- }
-
- executeSQL(createTable);
-
- }
-
- public GSISecurityContext getSecurityContext() throws Exception {
- GSISecurityContext.setUpTrustedCertificatePath(System.getProperty("gsi.certificate.path"));
- RequestData requestData = new RequestData();
- requestData.setMyProxyServerUrl("myproxy.teragrid.org");
- requestData.setMyProxyUserName(System.getProperty("myproxy.user"));
- requestData.setMyProxyPassword(System.getProperty("myproxy.password"));
- requestData.setMyProxyLifeTime(3600);
- CredentialReader credentialReader = new CredentialReaderImpl(getDbUtil());
- return new GSISecurityContext(credentialReader, requestData);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTestWithMyProxyAuth.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTestWithMyProxyAuth.java b/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTestWithMyProxyAuth.java
deleted file mode 100644
index ffaaaae..0000000
--- a/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/GramProviderTestWithMyProxyAuth.java
+++ /dev/null
@@ -1,225 +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.core.gfac.services.impl;
-
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.airavata.commons.gfac.type.ActualParameter;
-import org.apache.airavata.commons.gfac.type.ApplicationDescription;
-import org.apache.airavata.commons.gfac.type.HostDescription;
-import org.apache.airavata.commons.gfac.type.MappingFactory;
-import org.apache.airavata.commons.gfac.type.ServiceDescription;
-import org.apache.airavata.gfac.GFacConfiguration;
-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.cpi.GFacImpl;
-import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
-import org.apache.airavata.schemas.gfac.GlobusHostType;
-import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
-import org.apache.airavata.schemas.gfac.InputParameterType;
-import org.apache.airavata.schemas.gfac.JobTypeType;
-import org.apache.airavata.schemas.gfac.OutputParameterType;
-import org.apache.airavata.schemas.gfac.ProjectAccountType;
-import org.apache.airavata.schemas.gfac.QueueType;
-import org.apache.airavata.schemas.gfac.StringParameterType;
-import org.apache.airavata.schemas.gfac.URIParameterType;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class GramProviderTestWithMyProxyAuth extends GFacBaseTestWithMyProxyAuth {
- private JobExecutionContext jobExecutionContext;
-
-
-// private static final String hostAddress = "blacklight.psc.teragrid.org";
-// private static final String hostName = "Blacklight";
-// private static final String gridftpAddress = "gsiftp://gridftp.blacklight.psc.teragrid.org:2812";
-// private static final String gramAddress = "";
-
- //FIXME: move job properties to configuration file
- private static final String hostAddress = "trestles.sdsc.edu";
- private static final String hostName = "trestles";
- private static final String gridftpAddress = "gsiftp://trestles.sdsc.edu:2811/";
- private static final String gramAddress = "trestles-login2.sdsc.edu:2119/jobmanager-pbstest2";
-
- @Before
- public void setUp() throws Exception {
- URL resource = GramProviderTestWithMyProxyAuth.class.getClassLoader().getResource(org.apache.airavata.common.utils.Constants.GFAC_CONFIG_XML);
- assert resource != null;
- System.out.println(resource.getFile());
- GFacConfiguration gFacConfiguration = GFacConfiguration.create(new File(resource.getPath()),null,null);
-// gFacConfiguration.setMyProxyLifeCycle(3600);
-// gFacConfiguration.setMyProxyServer("myproxy.teragrid.org");
-// gFacConfiguration.setMyProxyUser("*****");
-// 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"}));
-
- /*
- * Host
- */
- HostDescription host = new HostDescription(GlobusHostType.type);
- host.getType().setHostAddress(hostAddress);
- host.getType().setHostName(hostName);
- ((GlobusHostType)host.getType()).setGlobusGateKeeperEndPointArray(new String[]{gramAddress});
- ((GlobusHostType)host.getType()).setGridFTPEndPointArray(new String[]{gridftpAddress});
- /*
- * App
- */
- ApplicationDescription appDesc = new ApplicationDescription(HpcApplicationDeploymentType.type);
- HpcApplicationDeploymentType app = (HpcApplicationDeploymentType)appDesc.getType();
- ApplicationDeploymentDescriptionType.ApplicationName name = ApplicationDeploymentDescriptionType.ApplicationName.Factory.newInstance();
- name.setStringValue("EchoLocal");
- app.setApplicationName(name);
- ProjectAccountType projectAccountType = app.addNewProjectAccount();
- projectAccountType.setProjectAccountNumber("sds128");
-
- QueueType queueType = app.addNewQueue();
- queueType.setQueueName("development");
-
- app.setCpuCount(1);
- app.setJobType(JobTypeType.SERIAL);
- app.setNodeCount(1);
- app.setProcessorsPerNode(1);
-
- /*
- * Use bat file if it is compiled on Windows
- */
- app.setExecutableLocation("/bin/echo");
-
- /*
- * Default tmp location
- */
- String tempDir = "/scratch/01437/ogce/test/";
- String date = (new Date()).toString();
- date = date.replaceAll(" ", "_");
- date = date.replaceAll(":", "_");
-
- tempDir = tempDir + File.separator
- + "SimpleEcho" + "_" + date + "_" + UUID.randomUUID();
-
- System.out.println(tempDir);
- app.setScratchWorkingDirectory(tempDir);
- app.setStaticWorkingDirectory(tempDir);
- app.setInputDataDirectory(tempDir + File.separator + "inputData");
- app.setOutputDataDirectory(tempDir + File.separator + "outputData");
- app.setStandardOutput(tempDir + File.separator + app.getApplicationName().getStringValue() + ".stdout");
- app.setStandardError(tempDir + File.separator + app.getApplicationName().getStringValue() + ".stderr");
-
-
- /*
- * Service
- */
- ServiceDescription serv = new ServiceDescription();
- serv.getType().setName("SimpleEcho");
-
- List<InputParameterType> inputList = new ArrayList<InputParameterType>();
-
- InputParameterType input = InputParameterType.Factory.newInstance();
- input.setParameterName("echo_input");
- input.setParameterType(StringParameterType.Factory.newInstance());
- inputList.add(input);
-
- InputParameterType input1 = InputParameterType.Factory.newInstance();
- input.setParameterName("myinput");
- URIParameterType uriType = URIParameterType.Factory.newInstance();
- uriType.setValue("gsiftp://gridftp1.ls4.tacc.utexas.edu:2811//home1/01437/ogce/gram_20130215.log");
- input.setParameterType(uriType);
- inputList.add(input1);
-
-
- InputParameterType[] inputParamList = inputList.toArray(new InputParameterType[inputList
-
- .size()]);
- List<OutputParameterType> outputList = new ArrayList<OutputParameterType>();
- OutputParameterType output = OutputParameterType.Factory.newInstance();
- output.setParameterName("echo_output");
- output.setParameterType(StringParameterType.Factory.newInstance());
- outputList.add(output);
-
- OutputParameterType[] outputParamList = outputList
- .toArray(new OutputParameterType[outputList.size()]);
-
- serv.getType().setInputParametersArray(inputParamList);
- serv.getType().setOutputParametersArray(outputParamList);
-
- jobExecutionContext = new JobExecutionContext(gFacConfiguration,serv.getType().getName());
- // Adding security context
- jobExecutionContext.addSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT, getSecurityContext());
- ApplicationContext applicationContext = new ApplicationContext();
- jobExecutionContext.setApplicationContext(applicationContext);
- applicationContext.setServiceDescription(serv);
- applicationContext.setApplicationDeploymentDescription(appDesc);
- applicationContext.setHostDescription(host);
-
- MessageContext inMessage = new MessageContext();
- ActualParameter echo_input = new ActualParameter();
- ((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
- inMessage.addParameter("echo_input", echo_input);
-
- // added extra
- ActualParameter copy_input = new ActualParameter();
- copy_input.getType().changeType(URIParameterType.type);
- ((URIParameterType)copy_input.getType()).setValue("file:///tmp/tmpstrace");
-
- ActualParameter outlocation = new ActualParameter();
- ((StringParameterType)outlocation.getType()).setValue("./outputData/.");
- inMessage.addParameter("copy_input", copy_input);
- inMessage.addParameter("outputlocation", outlocation);
-
- // added extra
-
-
-
- jobExecutionContext.setInMessageContext(inMessage);
-
- MessageContext outMessage = new MessageContext();
- ActualParameter echo_out = new ActualParameter();
-// ((StringParameterType)echo_input.getType()).setValue("echo_output=hello");
- outMessage.addParameter("echo_output", echo_out);
-
- jobExecutionContext.setOutMessageContext(outMessage);
-
- }
-
- @Test
- public void testGramProvider() throws GFacException {
- GFacImpl gFacAPI = new GFacImpl();
- gFacAPI.submitJob(jobExecutionContext);
- MessageContext outMessageContext = jobExecutionContext.getOutMessageContext();
- Assert.assertEquals(MappingFactory.toString((ActualParameter)outMessageContext.getParameter("echo_output")), "hello");
- }
-
- @Test
- public void testGetJdbcUrl() {
- System.out.println(getJDBCUrl());
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTestWithMyProxyAuth.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTestWithMyProxyAuth.java b/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTestWithMyProxyAuth.java
deleted file mode 100644
index 3351b32..0000000
--- a/modules/gfac/gfac-core/src/test/java/org/apache/airavata/core/gfac/services/impl/JSDLGeneratorTestWithMyProxyAuth.java
+++ /dev/null
@@ -1,318 +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.core.gfac.services.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.airavata.commons.gfac.type.ActualParameter;
-import org.apache.airavata.commons.gfac.type.ApplicationDescription;
-import org.apache.airavata.commons.gfac.type.HostDescription;
-import org.apache.airavata.commons.gfac.type.ServiceDescription;
-import org.apache.airavata.gfac.GFacConfiguration;
-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.provider.utils.JSDLGenerator;
-import org.apache.airavata.gfac.provider.utils.JSDLUtils;
-import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType;
-import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType;
-import org.apache.airavata.schemas.gfac.InputParameterType;
-import org.apache.airavata.schemas.gfac.JobTypeType;
-import org.apache.airavata.schemas.gfac.OutputParameterType;
-import org.apache.airavata.schemas.gfac.ProjectAccountType;
-import org.apache.airavata.schemas.gfac.QueueType;
-import org.apache.airavata.schemas.gfac.StringParameterType;
-import org.apache.airavata.schemas.gfac.URIParameterType;
-import org.apache.airavata.schemas.gfac.UnicoreHostType;
-import org.apache.log4j.PropertyConfigurator;
-import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument;
-import org.junit.Before;
-import org.junit.Test;
-
-//public class JSDLGeneratorTestWithMyProxyAuth {
-//
-// public static final String[] hostArray = new String[] { "https://zam1161v01.zam.kfa-juelich.de:8002/INTEROP1/services/BESFactory?res=default_bes_factory" };
-// public static final String gridftpAddress = "gsiftp://gridftp.blacklight.psc.teragrid.org:2811";
-// public static final String hostAddress = "zam1161v01.zam.kfa-juelich.de";
-// public static final String hostName = "DEMO-INTEROP-SITE";
-// public static final String scratchDir = "/scratch/msmemon/airavata";
-//
-// protected JobExecutionContext jobExecutionContext;
-//
-//
-// @Test
-// public void testSerialJSDLWithStdout() throws Exception{
-//
-// JobTypeType jobType = JobTypeType.Factory.newInstance();
-// jobType.set(JobTypeType.SERIAL);
-// ApplicationContext appContext = getApplicationContext();
-// appContext.setApplicationDeploymentDescription(getApplicationDesc(jobType, true));
-// jobExecutionContext.setApplicationContext(appContext);
-//
-// JobDefinitionDocument jobDefDoc = JSDLGenerator.buildJSDLInstance(jobExecutionContext);
-//
-// assertTrue (jobDefDoc.getJobDefinition().getJobDescription().getApplication().toString().contains("/bin/cat"));
-// assertTrue(jobDefDoc.getJobDefinition().getJobDescription().getDataStagingArray().length > 2);
-//
-// assertTrue(jobDefDoc.getJobDefinition().getJobDescription().getJobIdentification().getJobProjectArray().length > 0);
-//
-// assertFalse(JSDLUtils.getPOSIXApplication(jobDefDoc.getJobDefinition())==null);
-//
-// assertEquals("jsdl_stdout", JSDLUtils.getOrCreatePOSIXApplication(jobDefDoc.getJobDefinition()).getOutput().getStringValue().toString());
-//
-// }
-//
-// @Test
-// public void testSerialJSDLWithoutStdout() throws Exception{
-//
-// JobTypeType jobType = JobTypeType.Factory.newInstance();
-// jobType.set(JobTypeType.SERIAL);
-// ApplicationContext appContext = getApplicationContext();
-// appContext.setApplicationDeploymentDescription(getApplicationDesc(jobType, false));
-// jobExecutionContext.setApplicationContext(appContext);
-//
-// JobDefinitionDocument jobDefDoc = JSDLGenerator.buildJSDLInstance(jobExecutionContext);
-//
-// assertTrue (jobDefDoc.getJobDefinition().getJobDescription().getApplication().toString().contains("/bin/cat"));
-// assertTrue(jobDefDoc.getJobDefinition().getJobDescription().getDataStagingArray().length > 2);
-//
-// assertTrue(jobDefDoc.getJobDefinition().getJobDescription().getJobIdentification().getJobProjectArray().length > 0);
-//
-// assertFalse(JSDLUtils.getPOSIXApplication(jobDefDoc.getJobDefinition())==null);
-//
-// assertEquals("stdout", JSDLUtils.getOrCreatePOSIXApplication(jobDefDoc.getJobDefinition()).getOutput().getStringValue().toString());
-// assertEquals("stderr", JSDLUtils.getOrCreatePOSIXApplication(jobDefDoc.getJobDefinition()).getError().getStringValue().toString());
-//
-// }
-//
-//
-// @Test
-// public void testMPIJSDL() throws Exception{
-//
-// JobTypeType jobType = JobTypeType.Factory.newInstance();
-// jobType.set(JobTypeType.MPI);
-// ApplicationContext appContext = getApplicationContext();
-// appContext.setApplicationDeploymentDescription(getApplicationDesc(jobType, true));
-// jobExecutionContext.setApplicationContext(appContext);
-//
-// JobDefinitionDocument jobDefDoc = JSDLGenerator.buildJSDLInstance(jobExecutionContext);
-//
-// assertTrue (jobDefDoc.getJobDefinition().getJobDescription().getApplication().toString().contains("/bin/cat"));
-// assertTrue(jobDefDoc.getJobDefinition().getJobDescription().getDataStagingArray().length > 2);
-//
-// assertTrue(jobDefDoc.getJobDefinition().getJobDescription().getJobIdentification().getJobProjectArray().length > 0);
-//
-// assertEquals("jsdl_stdout", JSDLUtils.getOrCreateSPMDApplication(jobDefDoc.getJobDefinition()).getOutput().getStringValue().toString());
-//
-// assertFalse(JSDLUtils.getSPMDApplication(jobDefDoc.getJobDefinition())==null);
-//
-//
-// }
-//
-// protected GFacConfiguration getGFACConfig() throws Exception{
-// URL resource = BESProviderTestWithMyProxyAuth.class.getClassLoader().getResource(org.apache.airavata.common.utils.Constants.GFAC_CONFIG_XML);
-// System.out.println(resource.getFile());
-// GFacConfiguration gFacConfiguration = GFacConfiguration.create(new File(resource.getPath()),null,null);
-// return gFacConfiguration;
-// }
-//
-//
-// protected ApplicationContext getApplicationContext() {
-// ApplicationContext applicationContext = new ApplicationContext();
-// applicationContext.setHostDescription(getHostDesc());
-//
-// applicationContext.setServiceDescription(getServiceDesc());
-// return applicationContext;
-// }
-//
-// protected ApplicationDescription getApplicationDesc(JobTypeType jobType, boolean setOuput) {
-// ApplicationDescription appDesc = new ApplicationDescription(
-// HpcApplicationDeploymentType.type);
-// HpcApplicationDeploymentType app = (HpcApplicationDeploymentType) appDesc
-// .getType();
-// ApplicationDeploymentDescriptionType.ApplicationName name = ApplicationDeploymentDescriptionType.ApplicationName.Factory
-// .newInstance();
-// name.setStringValue("EchoLocal");
-// app.setApplicationName(name);
-// ProjectAccountType projectAccountType = app.addNewProjectAccount();
-// projectAccountType.setProjectAccountNumber("TG-AST110064");
-//
-// QueueType queueType = app.addNewQueue();
-// queueType.setQueueName("development");
-//
-// app.setCpuCount(1);
-// // TODO: also handle parallel jobs
-// if((jobType.enumValue() == JobTypeType.SERIAL) || (jobType.enumValue() == JobTypeType.SINGLE)) {
-// app.setJobType(JobTypeType.SERIAL);
-// }
-// else if (jobType.enumValue() == JobTypeType.MPI) {
-// app.setJobType(JobTypeType.MPI);
-// }
-// else {
-// app.setJobType(JobTypeType.OPEN_MP);
-// }
-//
-// app.setNodeCount(1);
-// app.setProcessorsPerNode(1);
-//
-// /*
-// * Use bat file if it is compiled on Windows
-// */
-// app.setExecutableLocation("/bin/cat");
-//
-// /*
-// * Default tmp location
-// */
-// String date = (new Date()).toString();
-// date = date.replaceAll(" ", "_");
-// date = date.replaceAll(":", "_");
-//
-// String remoteTempDir = scratchDir + File.separator + "SimpleEcho" + "_" + date + "_"
-// + UUID.randomUUID();
-//
-// System.out.println(remoteTempDir);
-//
-// // no need of these parameters, as unicore manages by itself
-// app.setScratchWorkingDirectory(remoteTempDir);
-// app.setStaticWorkingDirectory(remoteTempDir);
-// app.setInputDataDirectory(remoteTempDir + File.separator + "inputData");
-// app.setOutputDataDirectory(remoteTempDir + File.separator + "outputData");
-//
-// if(setOuput) {
-// app.setStandardOutput(app.getOutputDataDirectory()+"/jsdl_stdout");
-// app.setStandardError(app.getOutputDataDirectory()+"/jsdl_stderr");
-// }
-// return appDesc;
-// }
-//
-// protected HostDescription getHostDesc() {
-// HostDescription host = new HostDescription(UnicoreHostType.type);
-// host.getType().setHostAddress(hostAddress);
-// host.getType().setHostName(hostName);
-// ((UnicoreHostType) host.getType()).setUnicoreBESEndPointArray(hostArray);
-// ((UnicoreHostType) host.getType()).setGridFTPEndPointArray(new String[]{gridftpAddress});
-// return host;
-// }
-//
-// protected ServiceDescription getServiceDesc() {
-// ServiceDescription serv = new ServiceDescription();
-// serv.getType().setName("SimpleCat");
-//
-// List<InputParameterType> inputList = new ArrayList<InputParameterType>();
-// InputParameterType input = InputParameterType.Factory.newInstance();
-// input.setParameterName("echo_input");
-// input.setParameterType(StringParameterType.Factory.newInstance());
-// inputList.add(input);
-// InputParameterType[] inputParamList = inputList
-// .toArray(new InputParameterType[inputList.size()]);
-//
-// List<OutputParameterType> outputList = new ArrayList<OutputParameterType>();
-// OutputParameterType output = OutputParameterType.Factory.newInstance();
-// output.setParameterName("echo_output");
-// output.setParameterType(StringParameterType.Factory.newInstance());
-// outputList.add(output);
-// OutputParameterType[] outputParamList = outputList
-// .toArray(new OutputParameterType[outputList.size()]);
-//
-// serv.getType().setInputParametersArray(inputParamList);
-// serv.getType().setOutputParametersArray(outputParamList);
-//
-//
-// return serv;
-// }
-//
-// protected MessageContext getInMessageContext() {
-// MessageContext inMessage = new MessageContext();
-//
-// ActualParameter i1 = new ActualParameter();
-// i1.getType().changeType(URIParameterType.type);
-// ((URIParameterType)i1.getType()).setValue("file:///tmp/ifile1");
-// inMessage.addParameter("i1", i1);
-//
-// ActualParameter i2 = new ActualParameter();
-// i2.getType().changeType(URIParameterType.type);
-// ((URIParameterType)i2.getType()).setValue("file:///tmp/ifile2");
-// inMessage.addParameter("i2", i2);
-//
-// ActualParameter i3 = new ActualParameter();
-// i2.getType().changeType(URIParameterType.type);
-// ((URIParameterType)i2.getType()).setValue("///tmp/ifile2");
-// inMessage.addParameter("i3", i2);
-//
-// ActualParameter simpleArg = new ActualParameter();
-// simpleArg.getType().changeType(StringParameterType.type);
-// ((StringParameterType)simpleArg.getType()).setValue("argument1");
-// inMessage.addParameter("a1", simpleArg);
-//
-// ActualParameter nameValueArg = new ActualParameter();
-// nameValueArg.getType().changeType(StringParameterType.type);
-// ((StringParameterType)nameValueArg.getType()).setValue("name1=value1");
-// inMessage.addParameter("nameValueArg", nameValueArg);
-//
-// ActualParameter echo_input = new ActualParameter();
-// ((StringParameterType) echo_input.getType())
-// .setValue("echo_output=hello");
-// inMessage.addParameter("echo_input", echo_input);
-//
-// return inMessage;
-// }
-//
-// protected MessageContext getOutMessageContext() {
-// MessageContext om1 = new MessageContext();
-//
-// // TODO: Aint the output parameters are only the name of the files staged out to the gridftp endpoint?
-// ActualParameter o1 = new ActualParameter();
-// ((StringParameterType) o1.getType())
-// .setValue("tempfile");
-// om1.addParameter("o1", o1);
-//
-// ActualParameter o2 = new ActualParameter();
-// o2.getType().changeType(URIParameterType.type);
-//
-// ((URIParameterType)o2.getType()).setValue("http://path/to/upload");
-// om1.addParameter("o2", o2);
-//
-//
-//
-// return om1;
-// }
-//
-// @Before
-// public void initJobContext() throws Exception {
-// PropertyConfigurator.configure("src/test/resources/logging.properties");
-// jobExecutionContext = new JobExecutionContext(getGFACConfig(), getServiceDesc().getType().getName());
-// jobExecutionContext.setApplicationContext(getApplicationContext());
-// jobExecutionContext.setInMessageContext(getInMessageContext());
-// jobExecutionContext.setOutMessageContext(getOutMessageContext());
-// }
-//
-//
-//}
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-gram/pom.xml
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gram/pom.xml b/modules/gfac/gfac-gram/pom.xml
new file mode 100644
index 0000000..47382ae
--- /dev/null
+++ b/modules/gfac/gfac-gram/pom.xml
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--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. -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>gfac</artifactId>
+ <version>0.12-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>airavata-gfac-gram</artifactId>
+ <name>Airavata GFac GRAM implementation</name>
+ <description>This is the extension of GFAC to use GRAM</description>
+ <url>http://airavata.apache.org/</url>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jglobus</groupId>
+ <artifactId>gss</artifactId>
+ <version>${jglobus.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jglobus</groupId>
+ <artifactId>gram</artifactId>
+ <version>${jglobus.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.bouncycastle</groupId>
+ <artifactId>bcprov-jdk16</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.bouncycastle</groupId>
+ <artifactId>bcprov-jdk16</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jglobus</groupId>
+ <artifactId>myproxy</artifactId>
+ <version>${jglobus.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jglobus</groupId>
+ <artifactId>gridftp</artifactId>
+ <version>${jglobus.version}</version>
+ </dependency>
+
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+ <!-- GFAC schemas -->
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-gfac-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- Credential Store -->
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-credential-store</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-server-configuration</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-client-configuration</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+
+ <!-- Test -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>6.1.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- gsi-ssh api dependencies -->
+
+ <dependency>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>airavata-data-models</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jsch</artifactId>
+ <version>0.1.50</version>
+ </dependency>
+ <dependency>
+ <groupId>org.ogce</groupId>
+ <artifactId>bcgss</artifactId>
+ <version>146</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xmlbeans</groupId>
+ <artifactId>xmlbeans</artifactId>
+ <version>${xmlbeans.version}</version>
+ </dependency>
+
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/airavata/blob/13b505ae/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/context/security/GSISecurityContext.java
new file mode 100644
index 0000000..3eb020f
--- /dev/null
+++ b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/context/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.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;
+ }
+}