http://git-wip-us.apache.org/repos/asf/airavata/blob/70239916/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/provider/impl/GramProvider.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/provider/impl/GramProvider.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/provider/impl/GramProvider.java deleted file mode 100644 index 2f22e0d..0000000 --- a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/provider/impl/GramProvider.java +++ /dev/null @@ -1,539 +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.gram.provider.impl; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.util.Map; -import java.util.MissingResourceException; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.gfac.GFacException; -import org.apache.airavata.gfac.JobSubmissionFault; -import org.apache.airavata.gfac.core.context.JobExecutionContext; -import org.apache.airavata.gfac.core.notification.events.JobIDEvent; -import org.apache.airavata.gfac.core.notification.events.StartExecutionEvent; -import org.apache.airavata.gfac.core.provider.AbstractProvider; -import org.apache.airavata.gfac.core.provider.GFacProviderException; -import org.apache.airavata.gfac.core.utils.GFacUtils; -import org.apache.airavata.gfac.gram.security.GSISecurityContext; -import org.apache.airavata.gfac.gram.util.GramJobSubmissionListener; -import org.apache.airavata.gfac.gram.util.GramProviderUtils; -import org.apache.airavata.model.workspace.experiment.CorrectiveAction; -import org.apache.airavata.model.workspace.experiment.ErrorCategory; -import org.apache.airavata.model.workspace.experiment.JobState; -import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType; -import org.apache.airavata.schemas.gfac.GlobusHostType; -import org.globus.gram.GramException; -import org.globus.gram.GramJob; -import org.globus.gram.WaitingForCommitException; -import org.globus.gram.internal.GRAMConstants; -import org.globus.gram.internal.GRAMProtocolErrorConstants; -import org.ietf.jgss.GSSCredential; -import org.ietf.jgss.GSSException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class GramProvider extends AbstractProvider { - private static final Logger log = LoggerFactory.getLogger(GramJobSubmissionListener.class); - - private GramJob job; - private GramJobSubmissionListener listener; - private boolean twoPhase = true; - - /** - * If normal job submission fail due to an authorisation failure or script failure we - * will re-attempt to submit the job. In-order to avoid any recursive loop during a continuous - * failure we track whether failure paths are tried or not. Following booleans keeps track whether - * we already tried a failure path or not. - */ - /** - * To track job submissions during a authorisation failure while requesting job. - */ - private boolean renewCredentialsAttempt = false; - /** - * To track job submission during a script error situation. - */ - private boolean reSubmissionInProgress = false; - /** - * To track authorisation failures during status monitoring. - */ - private boolean authorisationFailedAttempt = false; - - private static final Map<String, GramJob> currentlyExecutingJobCache - = new ConcurrentHashMap<String, GramJob>(); - - private static Properties resources; - - static { - try { - - String propFileName = "errors.properties"; - resources = new Properties(); - InputStream inputStream = GramProvider.class.getClassLoader() - .getResourceAsStream(propFileName); - - if (inputStream == null) { - throw new FileNotFoundException("property file '" + propFileName - + "' not found in the classpath"); - } - - resources.load(inputStream); - - } catch (FileNotFoundException mre) { - log.error("errors.properties not found", mre); - } catch (IOException e) { - log.error("Error reading errors.properties file", e); - } - } - - - // This method prepare the environment before the application invocation. - public void initialize(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException { - - try { - super.initialize(jobExecutionContext); - String strTwoPhase = ServerSettings.getSetting("TwoPhase"); - if (strTwoPhase != null) { - twoPhase = Boolean.parseBoolean(strTwoPhase); - log.info("Two phase commit is set to " + twoPhase); - } - } catch (ApplicationSettingsException e) { - log.warn("Error reading TwoPhase property from configurations.", e); - } - - job = GramProviderUtils.setupEnvironment(jobExecutionContext, twoPhase); - listener = new GramJobSubmissionListener(job, jobExecutionContext); - job.addListener(listener); - } - - public void execute(JobExecutionContext jobExecutionContext) throws GFacProviderException, GFacException{ - jobExecutionContext.getNotifier().publish(new StartExecutionEvent()); - GlobusHostType host = (GlobusHostType) jobExecutionContext.getApplicationContext(). - getHostDescription().getType(); - ApplicationDeploymentDescriptionType app = jobExecutionContext.getApplicationContext(). - getApplicationDeploymentDescription().getType(); - - StringBuilder stringBuilder = new StringBuilder(); - try { - - GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext. - getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentials(); - job.setCredentials(gssCred); - // We do not support multiple gatekeepers in XBaya GUI, so we simply pick the 0th element in the array - String gateKeeper = host.getGlobusGateKeeperEndPointArray(0); - log.info("Request to contact:" + gateKeeper); - - stringBuilder.append("Finished launching job, Host = ").append(host.getHostAddress()).append(" RSL = ") - .append(job.getRSL()).append(" working directory = ").append(app.getStaticWorkingDirectory()) - .append(" temp directory = ").append(app.getScratchWorkingDirectory()) - .append(" Globus GateKeeper Endpoint = ").append(gateKeeper); - - log.info(stringBuilder.toString()); - - submitJobs(gateKeeper, jobExecutionContext, host); - - } catch (ApplicationSettingsException e) { - throw new GFacException(e.getMessage(), e); - } finally { - if (job != null) { - try { - /* - * Remove listener - */ - job.removeListener(listener); - } catch (Exception e) { - log.error(e.getMessage()); - } - } - } - } - - private void submitJobs(String gateKeeper, - JobExecutionContext jobExecutionContext, - GlobusHostType globusHostType) throws GFacException, GFacProviderException { - boolean applicationSaved=false; - String taskID = jobExecutionContext.getTaskData().getTaskID(); - - if (twoPhase) { - try { - /* - * The first boolean is to force communication through SSLv3 - * The second boolean is to specify the job is a batch job - use true for interactive and false for - * batch. - * The third boolean is to specify to use the full proxy and not delegate a limited proxy. - */ -// job.request(true, gateKeeper, false, false); - - - // first boolean -> to run job as batch - // second boolean -> to use limited proxy - //TODO: need review? - job.request(gateKeeper, false, false); - - // Single boolean to track all authentication failures, therefore we need to re-initialize - // this here - renewCredentialsAttempt = false; - - } catch (WaitingForCommitException e) { - String jobID = job.getIDAsString(); - - details.setJobID(jobID); - details.setJobDescription(job.getRSL()); - jobExecutionContext.setJobDetails(details); - GFacUtils.saveJobStatus(jobExecutionContext, details, JobState.UN_SUBMITTED); - - applicationSaved=true; - String jobStatusMessage = "Un-submitted JobID= " + jobID; - log.info(jobStatusMessage); - jobExecutionContext.getNotifier().publish(new JobIDEvent(jobStatusMessage)); - - log.info("Two phase commit: sending COMMIT_REQUEST signal; Job id - " + jobID); - - try { - job.signal(GramJob.SIGNAL_COMMIT_REQUEST); - - } catch (GramException gramException) { - throw new GFacException("Error while sending commit request. Job Id - " - + job.getIDAsString(), gramException); - } catch (GSSException gssException) { - - // User credentials are invalid - log.error("Error while submitting commit request - Credentials provided are invalid. Job Id - " - + job.getIDAsString(), e); - log.info("Attempting to renew credentials and re-submit commit signal..."); - GFacUtils.saveErrorDetails(jobExecutionContext, gssException.getLocalizedMessage(), CorrectiveAction.RETRY_SUBMISSION, ErrorCategory.AIRAVATA_INTERNAL_ERROR); - renewCredentials(jobExecutionContext); - - try { - job.signal(GramJob.SIGNAL_COMMIT_REQUEST); - } catch (GramException e1) { - GFacUtils.saveErrorDetails(jobExecutionContext, gssException.getLocalizedMessage(), CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.AIRAVATA_INTERNAL_ERROR); - throw new GFacException("Error while sending commit request. Job Id - " - + job.getIDAsString(), e1); - } catch (GSSException e1) { - GFacUtils.saveErrorDetails(jobExecutionContext, gssException.getLocalizedMessage(), CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.AIRAVATA_INTERNAL_ERROR); - throw new GFacException("Error while sending commit request. Job Id - " - + job.getIDAsString() + ". Credentials provided invalid", e1); - } - } - GFacUtils.updateJobStatus(jobExecutionContext, details, JobState.SUBMITTED); - jobStatusMessage = "Submitted JobID= " + job.getIDAsString(); - log.info(jobStatusMessage); - jobExecutionContext.getNotifier().publish(new JobIDEvent(jobStatusMessage)); - - } catch (GSSException e) { - // Renew credentials and re-submit - GFacUtils.saveErrorDetails(jobExecutionContext, e.getLocalizedMessage(), CorrectiveAction.RETRY_SUBMISSION, ErrorCategory.AIRAVATA_INTERNAL_ERROR); - - reSubmitJob(gateKeeper, jobExecutionContext, globusHostType, e); - - } catch (GramException e) { - GFacUtils.saveErrorDetails(jobExecutionContext, e.getLocalizedMessage(), CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.AIRAVATA_INTERNAL_ERROR); - - throw new GFacException("An error occurred while submitting a job, job id = " + job.getIDAsString(), e); - } - } else { - - /* - * The first boolean is to force communication through SSLv3 - * The second boolean is to specify the job is a batch job - use true for interactive and false for - * batch. - * The third boolean is to specify to use the full proxy and not delegate a limited proxy. - */ - try { - -// job.request(true, gateKeeper, false, false); - - // first boolean -> to run job as batch - // second boolean -> to use limited proxy - //TODO: need review? - job.request(gateKeeper, false, false); - - renewCredentialsAttempt = false; - - } catch (GramException e) { - GFacUtils.saveErrorDetails(jobExecutionContext, e.getLocalizedMessage(), CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.AIRAVATA_INTERNAL_ERROR); - throw new GFacException("An error occurred while submitting a job, job id = " + job.getIDAsString(), e); - } catch (GSSException e) { - GFacUtils.saveErrorDetails(jobExecutionContext, e.getLocalizedMessage(), CorrectiveAction.RETRY_SUBMISSION, ErrorCategory.AIRAVATA_INTERNAL_ERROR); - // Renew credentials and re-submit - reSubmitJob(gateKeeper, jobExecutionContext, globusHostType, e); - } - - String jobStatusMessage = "Un-submitted JobID= " + job.getIDAsString(); - log.info(jobStatusMessage); - jobExecutionContext.getNotifier().publish(new JobIDEvent(jobStatusMessage)); - - } - - currentlyExecutingJobCache.put(job.getIDAsString(), job); - /* - * Wait until job is done - */ - listener.waitFor(); - - checkJobStatus(jobExecutionContext, globusHostType, gateKeeper); - - } - - private void renewCredentials(JobExecutionContext jobExecutionContext) throws GFacException { - - renewCredentials(this.job, jobExecutionContext); - } - - private void renewCredentials(GramJob gramJob, JobExecutionContext jobExecutionContext) throws GFacException { - - try { - GSSCredential gssCred = ((GSISecurityContext)jobExecutionContext. - getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).renewCredentials(); - gramJob.renew(gssCred); - } catch (GramException e1) { - throw new GFacException("Unable to renew credentials. Job Id - " - + gramJob.getIDAsString(), e1); - } catch (GSSException e1) { - throw new GFacException("Unable to renew credentials. Job Id - " - + gramJob.getIDAsString(), e1); - } catch (ApplicationSettingsException e) { - throw new GFacException(e.getLocalizedMessage(), e); - } - } - - private void reSubmitJob(String gateKeeper, - JobExecutionContext jobExecutionContext, - GlobusHostType globusHostType, Exception e) throws GFacException, GFacProviderException { - - if (!renewCredentialsAttempt) { - - renewCredentialsAttempt = true; - - // User credentials are invalid - log.error("Error while submitting job - Credentials provided are invalid. Job Id - " - + job.getIDAsString(), e); - log.info("Attempting to renew credentials and re-submit jobs..."); - - // Remove existing listener and register a new listener - job.removeListener(listener); - listener = new GramJobSubmissionListener(job, jobExecutionContext); - - job.addListener(listener); - - renewCredentials(jobExecutionContext); - - submitJobs(gateKeeper, jobExecutionContext, globusHostType); - - } else { - throw new GFacException("Error while submitting job - Credentials provided are invalid. Job Id - " - + job.getIDAsString(), e); - } - - } - - private void reSubmitJob(String gateKeeper, - JobExecutionContext jobExecutionContext, - GlobusHostType globusHostType) throws GFacException, GFacProviderException { - - // User credentials are invalid - log.info("Attempting to renew credentials and re-submit jobs..."); - - // Remove existing listener and register a new listener - job.removeListener(listener); - listener = new GramJobSubmissionListener(job, jobExecutionContext); - - job.addListener(listener); - - renewCredentials(jobExecutionContext); - - submitJobs(gateKeeper, jobExecutionContext, globusHostType); - - } - - - - public void dispose(JobExecutionContext jobExecutionContext) throws GFacProviderException { - } - - public void cancelJob(JobExecutionContext jobExecutionContext) throws GFacException { - cancelSingleJob(jobExecutionContext.getJobDetails().getJobID(), jobExecutionContext); - } - - - private void cancelSingleJob(String jobId, JobExecutionContext context) throws GFacException { - // First check whether job id is in the cache - if (currentlyExecutingJobCache.containsKey(jobId)) { - - synchronized (this) { - GramJob gramJob = currentlyExecutingJobCache.get(jobId); - - // Even though we check using containsKey, at this point job could be null - if (gramJob != null && (gramJob.getStatus() != GRAMConstants.STATUS_DONE || - gramJob.getStatus() != GRAMConstants.STATUS_FAILED)) { - cancelJob(gramJob, context); - } - } - - } else { - - try { - GSSCredential gssCred = ((GSISecurityContext)context. - getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getGssCredentials(); - - GramJob gramJob = new GramJob(null); - try { - gramJob.setID(jobId); - } catch (MalformedURLException e) { - throw new GFacException("Invalid job id - " + jobId, e); - } - gramJob.setCredentials(gssCred); - - synchronized (this) { - if (gramJob.getStatus() != GRAMConstants.STATUS_DONE || - gramJob.getStatus() != GRAMConstants.STATUS_FAILED) { - cancelJob(gramJob, context); - } - } - } catch (ApplicationSettingsException e) { - throw new GFacException(e); - } - } - } - - private void cancelJob(GramJob gramJob, JobExecutionContext context) throws GFacException{ - - try { - gramJob.cancel(); - } catch (GramException e) { - throw new GFacException("Error cancelling job, id - " + gramJob.getIDAsString(), e); - } catch (GSSException e) { - - log.warn("Credentials invalid to cancel job. Attempting to renew credentials and re-try. " + - "Job id - " + gramJob.getIDAsString()); - renewCredentials(gramJob, context); - - try { - gramJob.cancel(); - gramJob.signal(GramJob.SIGNAL_COMMIT_END); - } catch (GramException e1) { - throw new GFacException("Error cancelling job, id - " + gramJob.getIDAsString(), e1); - } catch (GSSException e1) { - throw new GFacException("Error cancelling job, invalid credentials. Job id - " - + gramJob.getIDAsString(), e); - } - } - - } - - public void initProperties(Map<String, String> properties) throws GFacException { - - } - - private void checkJobStatus(JobExecutionContext jobExecutionContext, GlobusHostType host, String gateKeeper) - throws GFacProviderException { - int jobStatus = listener.getCurrentStatus(); - - if (jobStatus == GramJob.STATUS_FAILED) { - - String errorMsg = "Job " + job.getIDAsString() + " on host " + host.getHostAddress() + " Job Exit Code = " - + listener.getError() + " Error Description = " + getGramErrorString(listener.getError()); - - if (listener.getError() == GRAMProtocolErrorConstants.INVALID_SCRIPT_REPLY) { - - // re-submitting without renewing - // TODO verify why we re-submit jobs when we get a invalid script reply - if (!reSubmissionInProgress) { - reSubmissionInProgress = true; - - log.info("Invalid script reply received. Re-submitting job, id - " + job.getIDAsString()); - try { - reSubmitJob(gateKeeper, jobExecutionContext, host); - } catch (GFacException e) { - throw new GFacProviderException - ("Error during re-submission. Original job submission data - " + errorMsg, e); - } - return; - } - - } else if (listener.getError() == GRAMProtocolErrorConstants.ERROR_AUTHORIZATION) { - - // re-submit with renewed credentials - if (!authorisationFailedAttempt) { - authorisationFailedAttempt = true; - log.info("Authorisation error contacting provider. Re-submitting job with renewed credentials."); - - try { - renewCredentials(jobExecutionContext); - reSubmitJob(gateKeeper, jobExecutionContext, host); - } catch (GFacException e) { - throw new GFacProviderException - ("Error during re-submission. Original job submission data - " + errorMsg, e); - } - - return; - } - - } else if (listener.getError() == GRAMProtocolErrorConstants.USER_CANCELLED) { - - log.info("User successfully cancelled job id " + job.getIDAsString()); - return; - } - - - - log.error(errorMsg); - - synchronized (this) { - currentlyExecutingJobCache.remove(job.getIDAsString()); - } - - throw new JobSubmissionFault(new Exception(errorMsg), host.getHostAddress(), gateKeeper, - job.getRSL(), jobExecutionContext, getGramErrorString(listener.getError()), - listener.getError()); - - } else if (jobStatus == GramJob.STATUS_DONE) { - log.info("Job " + job.getIDAsString() + " on host " + host.getHostAddress() + " is successfully executed."); - - synchronized (this) { - currentlyExecutingJobCache.remove(job.getIDAsString()); - } - } - } - - public String getGramErrorString(int errorCode) { - - if (resources != null) { - try { - return resources.getProperty(String.valueOf(errorCode)); - } catch (MissingResourceException mre) { - log.warn("Error reading globus error descriptions.", mre); - return "Error code: " + errorCode; - } - } else { - return "Error code: " + errorCode; - } - - } - -}
http://git-wip-us.apache.org/repos/asf/airavata/blob/70239916/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/security/GSISecurityContext.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/security/GSISecurityContext.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/security/GSISecurityContext.java deleted file mode 100644 index 395b797..0000000 --- a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/security/GSISecurityContext.java +++ /dev/null @@ -1,275 +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.gram.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.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; - - // 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); - } - - - - /** - * 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); - } - } - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/70239916/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramJobSubmissionListener.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramJobSubmissionListener.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramJobSubmissionListener.java deleted file mode 100644 index 782eee2..0000000 --- a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/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.gram.util; - -import org.apache.airavata.gfac.GFacException; -import org.apache.airavata.gfac.core.context.JobExecutionContext; -import org.apache.airavata.gfac.core.notification.events.StatusChangeEvent; -import org.apache.airavata.gfac.core.utils.GFacUtils; -import org.apache.airavata.gfac.gram.security.GSISecurityContext; -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, context.getJobDetails(), GramProviderUtils.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/70239916/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramProviderUtils.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramProviderUtils.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramProviderUtils.java deleted file mode 100644 index 8dfe78f..0000000 --- a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramProviderUtils.java +++ /dev/null @@ -1,113 +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.gram.util; - -import org.apache.airavata.gfac.ToolsException; -import org.apache.airavata.gfac.core.context.JobExecutionContext; -import org.apache.airavata.gfac.core.provider.GFacProviderException; -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/70239916/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramRSLGenerator.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramRSLGenerator.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GramRSLGenerator.java deleted file mode 100644 index 8ec4cc8..0000000 --- a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/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.gram.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.core.context.JobExecutionContext; -import org.apache.airavata.gfac.core.context.MessageContext; -import org.apache.airavata.gfac.core.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/70239916/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GridFTPContactInfo.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GridFTPContactInfo.java b/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/util/GridFTPContactInfo.java deleted file mode 100644 index f331b0e..0000000 --- a/modules/gfac/gfac-gram/src/main/java/org/apache/airavata/gfac/gram/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.gram.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/70239916/modules/gfac/gfac-gram/src/main/resources/errors.properties ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-gram/src/main/resources/errors.properties b/modules/gfac/gfac-gram/src/main/resources/errors.properties deleted file mode 100644 index 88c41b8..0000000 --- a/modules/gfac/gfac-gram/src/main/resources/errors.properties +++ /dev/null @@ -1,197 +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. -# - -# Directly copied from jglobus. Not a good way to manager error properties. -1 = Parameter not supported -2 = The RSL length is greater than the maximum allowed -3 = No resources available -4 = Bad directory specified -5 = The executable does not exist -6 = Insufficient funds -7 = Authentication with the remote server failed -8 = Job cancelled by user -9 = Job cancelled by system - -10 = Data transfer to the server failed -11 = The stdin file does not exist -12 = The connection to the server failed (check host and port) -13 = The provided RSL 'maxtime' value is invalid (not an integer or must be greater than 0) -14 = The provided RSL 'count' value is invalid (not an integer or must be greater than 0) -15 = The job manager received an invalid RSL -16 = Could not connect to job manager -17 = The job failed when the job manager attempted to run it -18 = Paradyn error -19 = The provided RSL 'jobtype' value is invalid - -20 = The provided RSL 'myjob' value is invalid -21 = The job manager failed to locate an internal script argument file -22 = The job manager failed to create an internal script argument file -23 = The job manager detected an invalid job state -24 = The job manager detected an invalid script response -25 = The job manager detected an invalid job state -26 = The provided RSL 'jobtype' value is not supported by this job manager -27 = Unimplemented -28 = The job manager failed to create an internal script submission file -29 = The job manager cannot find the user proxy - -30 = The job manager failed to open the user proxy -31 = The job manager failed to cancel the job as requested -32 = System memory allocation failed -33 = The interprocess job communication initialization failed -34 = The interprocess job communication setup failed -35 = The provided RSL 'host count' value is invalid -36 = One of the provided RSL parameters is unsupported -37 = The provided RSL 'queue' parameter is invalid -38 = The provided RSL 'project' parameter is invalid -39 = The provided RSL string includes variables that could not be identified - -40 = The provided RSL 'environment' parameter is invalid -41 = The provided RSL 'dryrun' parameter is invalid -42 = The provided RSL is invalid (an empty string) -43 = The job manager failed to stage the executable -44 = The job manager failed to stage the stdin file -45 = The requested job manager type is invalid -46 = The provided RSL 'arguments' parameter is invalid -47 = The gatekeeper failed to run the job manager -48 = The provided RSL could not be properly parsed -49 = There is a version mismatch between GRAM components - -50 = The provided RSL 'arguments' parameter is invalid -51 = The provided RSL 'count' parameter is invalid -52 = The provided RSL 'directory' parameter is invalid -53 = The provided RSL 'dryrun' parameter is invalid -54 = The provided RSL 'environment' parameter is invalid -55 = The provided RSL 'executable' parameter is invalid -56 = The provided RSL 'host_count' parameter is invalid -57 = The provided RSL 'jobtype' parameter is invalid -58 = The provided RSL 'maxtime' parameter is invalid -59 = The provided RSL 'myjob' parameter is invalid - -60 = The provided RSL 'paradyn' parameter is invalid -61 = The provided RSL 'project' parameter is invalid -62 = The provided RSL 'queue' parameter is invalid -63 = The provided RSL 'stderr' parameter is invalid -64 = The provided RSL 'stdin' parameter is invalid -65 = The provided RSL 'stdout' parameter is invalid -66 = The job manager failed to locate an internal script -67 = The job manager failed on the system call pipe() -68 = The job manager failed on the system call fcntl() -69 = The job manager failed to create the temporary stdout filename - -70 = The job manager failed to create the temporary stderr filename -71 = The job manager failed on the system call fork() -72 = The executable file permissions do not allow execution -73 = The job manager failed to open stdout -74 = The job manager failed to open stderr -75 = The cache file could not be opened in order to relocate the user proxy -76 = Cannot access cache files in ~/.globus/.gass_cache, check permissions, quota, and disk space -77 = The job manager failed to insert the contact in the client contact list -78 = The contact was not found in the job manager's client contact list -79 = Connecting to the job manager failed. Possible reasons: job terminated, invalid job contact, network problems, ... - -80 = The syntax of the job contact is invalid -81 = The executable parameter in the RSL is undefined -82 = The job manager service is misconfigured. condor arch undefined -83 = The job manager service is misconfigured. condor os undefined -84 = The provided RSL 'min_memory' parameter is invalid -85 = The provided RSL 'max_memory' parameter is invalid -86 = The RSL 'min_memory' value is not zero or greater -87 = The RSL 'max_memory' value is not zero or greater -88 = The creation of a HTTP message failed -89 = Parsing incoming HTTP message failed - -90 = The packing of information into a HTTP message failed -91 = An incoming HTTP message did not contain the expected information -92 = The job manager does not support the service that the client requested -93 = The gatekeeper failed to find the requested service -94 = The jobmanager does not accept any new requests (shutting down) -95 = The client failed to close the listener associated with the callback URL -96 = The gatekeeper contact cannot be parsed -97 = The job manager could not find the 'poe' command -98 = The job manager could not find the 'mpirun' command -99 = The provided RSL 'start_time' parameter is invalid" -100 = The provided RSL 'reservation_handle' parameter is invalid - -101 = The provided RSL 'max_wall_time' parameter is invalid -102 = The RSL 'max_wall_time' value is not zero or greater -103 = The provided RSL 'max_cpu_time' parameter is invalid -104 = The RSL 'max_cpu_time' value is not zero or greater -105 = The job manager is misconfigured, a scheduler script is missing -106 = The job manager is misconfigured, a scheduler script has invalid permissions -107 = The job manager failed to signal the job -108 = The job manager did not recognize/support the signal type -109 = The job manager failed to get the job id from the local scheduler - -110 = The job manager is waiting for a commit signal -111 = The job manager timed out while waiting for a commit signal -112 = The provided RSL 'save_state' parameter is invalid -113 = The provided RSL 'restart' parameter is invalid -114 = The provided RSL 'two_phase' parameter is invalid -115 = The RSL 'two_phase' value is not zero or greater -116 = The provided RSL 'stdout_position' parameter is invalid -117 = The RSL 'stdout_position' value is not zero or greater -118 = The provided RSL 'stderr_position' parameter is invalid -119 = The RSL 'stderr_position' value is not zero or greater - -120 = The job manager restart attempt failed -121 = The job state file doesn't exist -122 = Could not read the job state file -123 = Could not write the job state file -124 = The old job manager is still alive -125 = The job manager state file TTL expired -126 = It is unknown if the job was submitted -127 = The provided RSL 'remote_io_url' parameter is invalid -128 = Could not write the remote io url file -129 = The standard output/error size is different - -130 = The job manager was sent a stop signal (job is still running) -131 = The user proxy expired (job is still running) -132 = The job was not submitted by original jobmanager -133 = The job manager is not waiting for that commit signal -134 = The provided RSL scheduler specific parameter is invalid -135 = The job manager could not stage in a file -136 = The scratch directory could not be created -137 = The provided 'gass_cache' parameter is invalid -138 = The RSL contains attributes which are not valid for job submission -139 = The RSL contains attributes which are not valid for stdio update - -140 = The RSL contains attributes which are not valid for job restart -141 = The provided RSL 'file_stage_in' parameter is invalid -142 = The provided RSL 'file_stage_in_shared' parameter is invalid -143 = The provided RSL 'file_stage_out' parameter is invalid -144 = The provided RSL 'gass_cache' parameter is invalid -145 = The provided RSL 'file_cleanup' parameter is invalid -146 = The provided RSL 'scratch_dir' parameter is invalid -147 = The provided scheduler-specific RSL parameter is invalid -148 = A required RSL attribute was not defined in the RSL spec -149 = The gass_cache attribute points to an invalid cache directory - -150 = The provided RSL 'save_state' parameter has an invalid value -151 = The job manager could not open the RSL attribute validation file -152 = The job manager could not read the RSL attribute validation file -153 = The provided RSL 'proxy_timeout' is invalid -154 = The RSL 'proxy_timeout' value is not greater than zero -155 = The job manager could not stage out a file -156 = The job contact string does not match any which the job manager is handling -157 = Proxy delegation failed -158 = The job manager could not lock the state lock file - -1000 = Failed to start up callback handler -1003 = Job contact not set http://git-wip-us.apache.org/repos/asf/airavata/blob/70239916/modules/gfac/gfac-gram/src/main/resources/service.properties ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-gram/src/main/resources/service.properties b/modules/gfac/gfac-gram/src/main/resources/service.properties deleted file mode 100644 index 391bfea..0000000 --- a/modules/gfac/gfac-gram/src/main/resources/service.properties +++ /dev/null @@ -1,58 +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. -# -# - - -# -# Class which implemented Scheduler interface. It will be used to determine a Provider -# -scheduler.class= org.apache.airavata.core.gfac.scheduler.impl.SchedulerImpl - -# -# Data Service Plugins classes -# -datachain.classes= org.apache.airavata.core.gfac.extension.data.RegistryDataService - -# -# Pre execution Plugins classes. For example, GridFTP Input Staging -# -prechain.classes= org.apache.airavata.core.gfac.extension.pre.GridFtpInputStaging -prechain.classes= org.apache.airavata.core.gfac.extension.pre.HttpInputStaging - -# -# Post execution Plugins classes. For example, GridFTP Output Staging -# -postchain.classes= org.apache.airavata.core.gfac.extension.post.GridFtpOutputStaging -postchain.classes= org.apache.airavata.core.gfac.extension.post.OutputRegister - -# -# SSH private key location. It will be used by SSHProvider -# -# ssh.key=/home/user/.ssh/id_rsa -# ssh.keypass= -# ssh.username=usernameAtHost - -# -# MyProxy credential. It will be used by GridFTP Plugins and GramProvider. -# -# myproxy.server=myproxy.teragrid.org -# myproxy.user=username -# myproxy.pass=password -# myproxy.life=3600 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/70239916/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 deleted file mode 100644 index a5960d4..0000000 --- a/modules/gfac/gfac-gram/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.gram.security.GSISecurityContext; -import org.apache.log4j.Logger; -import org.junit.BeforeClass; - -/** - * User: AmilaJ ([email protected]) - * 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); - } - -} \ No newline at end of file
