Return-Path: X-Original-To: apmail-airavata-commits-archive@www.apache.org Delivered-To: apmail-airavata-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4CF2610F3D for ; Tue, 4 Nov 2014 17:32:20 +0000 (UTC) Received: (qmail 7392 invoked by uid 500); 4 Nov 2014 17:32:20 -0000 Delivered-To: apmail-airavata-commits-archive@airavata.apache.org Received: (qmail 7304 invoked by uid 500); 4 Nov 2014 17:32:20 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 7263 invoked by uid 99); 4 Nov 2014 17:32:19 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Nov 2014 17:32:19 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 49BDB8AE3E1; Tue, 4 Nov 2014 17:32:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: shameera@apache.org To: commits@airavata.apache.org Date: Tue, 04 Nov 2014 17:32:19 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] Integrated appCatalog for ssh and gsi modules, commented out old test classes, need to fix this Repository: airavata Updated Branches: refs/heads/gfac_appcatalog_int bb4fe1226 -> 2dd94e633 http://git-wip-us.apache.org/repos/asf/airavata/blob/2dd94e63/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java b/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java index 7ee5d6a..7e9fa89 100644 --- a/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java +++ b/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java @@ -20,11 +20,13 @@ */ package org.apache.airavata.gfac.ssh.util; +import org.airavata.appcatalog.cpi.AppCatalog; +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.apache.aiaravata.application.catalog.data.impl.AppCatalogFactory; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.common.utils.StringUtil; import org.apache.airavata.commons.gfac.type.ActualParameter; -import org.apache.airavata.commons.gfac.type.HostDescription; import org.apache.airavata.commons.gfac.type.MappingFactory; import org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential; import org.apache.airavata.gfac.Constants; @@ -32,28 +34,36 @@ import org.apache.airavata.gfac.GFacException; import org.apache.airavata.gfac.RequestData; import org.apache.airavata.gfac.core.context.JobExecutionContext; import org.apache.airavata.gfac.core.context.MessageContext; -import org.apache.airavata.gfac.core.utils.GFacUtils; +import org.apache.airavata.gfac.core.states.GfacExperimentState; import org.apache.airavata.gfac.ssh.context.SSHAuthWrapper; import org.apache.airavata.gfac.ssh.security.SSHSecurityContext; import org.apache.airavata.gfac.ssh.security.TokenizedSSHAuthInfo; import org.apache.airavata.gsi.ssh.api.Cluster; -import org.apache.airavata.gsi.ssh.api.SSHApiException; import org.apache.airavata.gsi.ssh.api.ServerInfo; -import org.apache.airavata.gsi.ssh.api.authentication.AuthenticationInfo; import org.apache.airavata.gsi.ssh.api.job.JobDescriptor; -import org.apache.airavata.gsi.ssh.api.job.JobManagerConfiguration; import org.apache.airavata.gsi.ssh.impl.GSISSHAbstractCluster; import org.apache.airavata.gsi.ssh.impl.PBSCluster; -import org.apache.airavata.gsi.ssh.impl.authentication.DefaultPasswordAuthenticationInfo; -import org.apache.airavata.gsi.ssh.impl.authentication.DefaultPublicKeyFileAuthentication; import org.apache.airavata.gsi.ssh.util.CommonUtils; +import org.apache.airavata.model.appcatalog.computeresource.JobSubmissionInterface; +import org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol; +import org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission; +import org.apache.airavata.model.appcatalog.computeresource.SecurityProtocol; import org.apache.airavata.model.workspace.experiment.ComputationalResourceScheduling; import org.apache.airavata.model.workspace.experiment.TaskDetails; -import org.apache.airavata.schemas.gfac.*; +import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType; +import org.apache.airavata.schemas.gfac.FileArrayType; +import org.apache.airavata.schemas.gfac.HpcApplicationDeploymentType; +import org.apache.airavata.schemas.gfac.StringArrayType; +import org.apache.airavata.schemas.gfac.URIArrayType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; public class GFACSSHUtils { private final static Logger logger = LoggerFactory.getLogger(GFACSSHUtils.class); @@ -66,109 +76,113 @@ public class GFACSSHUtils { public static void addSecurityContext(JobExecutionContext jobExecutionContext) throws GFacException, ApplicationSettingsException { - HostDescription registeredHost = jobExecutionContext.getApplicationContext().getHostDescription(); - if (registeredHost.getType() instanceof GlobusHostType || registeredHost.getType() instanceof UnicoreHostType) { + JobSubmissionProtocol preferredJobSubmissionProtocol = jobExecutionContext.getPreferredJobSubmissionProtocol(); + JobSubmissionInterface preferredJobSubmissionInterface = jobExecutionContext.getPreferredJobSubmissionInterface(); + if (preferredJobSubmissionProtocol == JobSubmissionProtocol.GLOBUS || preferredJobSubmissionProtocol == JobSubmissionProtocol.UNICORE) { logger.error("This is a wrong method to invoke to non ssh host types,please check your gfac-config.xml"); - } else if (registeredHost.getType() instanceof SSHHostType - || registeredHost.getType() instanceof GsisshHostType) { - SSHSecurityContext sshSecurityContext = new SSHSecurityContext(); - String credentialStoreToken = jobExecutionContext.getCredentialStoreToken(); // this is set by the framework - RequestData requestData = new RequestData(ServerSettings.getDefaultUserGateway()); - requestData.setTokenId(credentialStoreToken); - - ServerInfo serverInfo = new ServerInfo(null, registeredHost.getType().getHostAddress()); - SSHAuthWrapper sshAuth = (SSHAuthWrapper) jobExecutionContext.getProperty(ADVANCED_SSH_AUTH); - - Cluster pbsCluster = null; + } else if ( preferredJobSubmissionProtocol == JobSubmissionProtocol.SSH ) { try { - TokenizedSSHAuthInfo tokenizedSSHAuthInfo = new TokenizedSSHAuthInfo(requestData); - String installedParentPath = ((HpcApplicationDeploymentType) - jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType()).getInstalledParentPath(); - if (installedParentPath == null) { - installedParentPath = "/"; - } + AppCatalog appCatalog = AppCatalogFactory.getAppCatalog(); + SSHJobSubmission sshJobSubmission = appCatalog.getComputeResource().getSSHJobSubmission(preferredJobSubmissionInterface.getJobSubmissionInterfaceId()); + if (sshJobSubmission.getSecurityProtocol() == SecurityProtocol.GSI) { + SSHSecurityContext sshSecurityContext = new SSHSecurityContext(); + String credentialStoreToken = jobExecutionContext.getCredentialStoreToken(); // this is set by the framework + RequestData requestData = new RequestData(ServerSettings.getDefaultUserGateway()); + requestData.setTokenId(credentialStoreToken); + + ServerInfo serverInfo = new ServerInfo(null, jobExecutionContext.getHostName()); + SSHAuthWrapper sshAuth = (SSHAuthWrapper) jobExecutionContext.getProperty(ADVANCED_SSH_AUTH); + + Cluster pbsCluster = null; + try { + TokenizedSSHAuthInfo tokenizedSSHAuthInfo = new TokenizedSSHAuthInfo(requestData); + String installedParentPath = jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getExecutablePath(); + if (installedParentPath == null) { + installedParentPath = "/"; + } - SSHCredential credentials = tokenizedSSHAuthInfo.getCredentials();// this is just a call to get and set credentials in to this object,data will be used - serverInfo.setUserName(credentials.getPortalUserName()); - jobExecutionContext.getExperiment().setUserName(credentials.getPortalUserName()); - // inside the pbsCluser object + SSHCredential credentials = tokenizedSSHAuthInfo.getCredentials();// this is just a call to get and set credentials in to this object,data will be used + serverInfo.setUserName(credentials.getPortalUserName()); + jobExecutionContext.getExperiment().setUserName(credentials.getPortalUserName()); + // inside the pbsCluser object - String key = credentials.getPortalUserName() + registeredHost.getType().getHostAddress() + - serverInfo.getPort(); - if(sshAuth!=null){ - key=sshAuth.getKey(); - } - boolean recreate = false; - synchronized (clusters) { - if (clusters.containsKey(key) && clusters.get(key).size() < maxClusterCount) { - recreate = true; - } else if (clusters.containsKey(key)) { - int i = new Random().nextInt(Integer.MAX_VALUE) % maxClusterCount; - if (clusters.get(key).get(i).getSession().isConnected()) { - pbsCluster = clusters.get(key).get(i); - } else { - clusters.get(key).remove(i); - recreate = true; + String key = credentials.getPortalUserName() + jobExecutionContext.getHostName() + serverInfo.getPort(); + if(sshAuth!=null){ + key=sshAuth.getKey(); } - if (!recreate) { - try { - pbsCluster.listDirectory("~/"); // its hard to trust isConnected method, so we try to connect if it works we are good,else we recreate - } catch (Exception e) { - clusters.get(key).remove(i); - logger.info("Connection found the connection map is expired, so we create from the scratch"); - maxClusterCount++; - recreate = true; // we make the pbsCluster to create again if there is any exception druing connection + boolean recreate = false; + synchronized (clusters) { + if (clusters.containsKey(key) && clusters.get(key).size() < maxClusterCount) { + recreate = true; + } else if (clusters.containsKey(key)) { + int i = new Random().nextInt(Integer.MAX_VALUE) % maxClusterCount; + if (clusters.get(key).get(i).getSession().isConnected()) { + pbsCluster = clusters.get(key).get(i); + } else { + clusters.get(key).remove(i); + recreate = true; + } + if (!recreate) { + try { + pbsCluster.listDirectory("~/"); // its hard to trust isConnected method, so we try to connect if it works we are good,else we recreate + } catch (Exception e) { + clusters.get(key).remove(i); + logger.info("Connection found the connection map is expired, so we create from the scratch"); + maxClusterCount++; + recreate = true; // we make the pbsCluster to create again if there is any exception druing connection + } + } + logger.info("Re-using the same connection used with the connection string:" + key); + } else { + recreate = true; + } + if (recreate) { + if (sshAuth != null) { + pbsCluster = new PBSCluster(sshAuth.getServerInfo(), sshAuth.getAuthenticationInfo(), + CommonUtils.getPBSJobManager(installedParentPath)); + jobExecutionContext.setProperty(ADVANCED_SSH_AUTH,null); // some other provider might fail + key = sshAuth.getKey(); + } else { + pbsCluster = new PBSCluster(serverInfo, tokenizedSSHAuthInfo, + CommonUtils.getPBSJobManager(installedParentPath)); + } + List pbsClusters = null; + if (!(clusters.containsKey(key))) { + pbsClusters = new ArrayList(); + } else { + pbsClusters = clusters.get(key); + } + pbsClusters.add(pbsCluster); + clusters.put(key, pbsClusters); } } - logger.info("Re-using the same connection used with the connection string:" + key); - } else { - recreate = true; - } - if (recreate) { - if (sshAuth != null) { - pbsCluster = new PBSCluster(sshAuth.getServerInfo(), sshAuth.getAuthenticationInfo(), - CommonUtils.getPBSJobManager(installedParentPath)); - jobExecutionContext.setProperty(ADVANCED_SSH_AUTH,null); // some other provider might fail - key = sshAuth.getKey(); - } else { - pbsCluster = new PBSCluster(serverInfo, tokenizedSSHAuthInfo, - CommonUtils.getPBSJobManager(installedParentPath)); - } - List pbsClusters = null; - if (!(clusters.containsKey(key))) { - pbsClusters = new ArrayList(); - } else { - pbsClusters = clusters.get(key); - } - pbsClusters.add(pbsCluster); - clusters.put(key, pbsClusters); + } catch (Exception e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } + sshSecurityContext.setPbsCluster(pbsCluster); + jobExecutionContext.addSecurityContext(Constants.SSH_SECURITY_CONTEXT, sshSecurityContext); } - } catch (Exception e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } catch (AppCatalogException e) { + throw new GFacException("Error while getting SSH Submission object from app catalog", e); } - sshSecurityContext.setPbsCluster(pbsCluster); - jobExecutionContext.addSecurityContext(Constants.SSH_SECURITY_CONTEXT, sshSecurityContext); } } - public static JobDescriptor createJobDescriptor(JobExecutionContext jobExecutionContext, - ApplicationDeploymentDescriptionType app, Cluster cluster) { + public static JobDescriptor createJobDescriptor(JobExecutionContext jobExecutionContext, Cluster cluster) { JobDescriptor jobDescriptor = new JobDescriptor(); // this is common for any application descriptor jobDescriptor.setCallBackIp(ServerSettings.getIp()); jobDescriptor.setCallBackPort(ServerSettings.getSetting(org.apache.airavata.common.utils.Constants.GFAC_SERVER_PORT, "8950")); - jobDescriptor.setInputDirectory(app.getInputDataDirectory()); - jobDescriptor.setOutputDirectory(app.getOutputDataDirectory()); - jobDescriptor.setExecutablePath(app.getExecutableLocation()); - jobDescriptor.setStandardOutFile(app.getStandardOutput()); - jobDescriptor.setStandardErrorFile(app.getStandardError()); + jobDescriptor.setInputDirectory(jobExecutionContext.getInputDir()); + jobDescriptor.setOutputDirectory(jobExecutionContext.getOutputDir()); + jobDescriptor.setExecutablePath(jobExecutionContext.getApplicationContext() + .getApplicationDeploymentDescription().getExecutablePath()); + jobDescriptor.setStandardOutFile(jobExecutionContext.getStandardOutput()); + jobDescriptor.setStandardErrorFile(jobExecutionContext.getStandardError()); Random random = new Random(); int i = random.nextInt(Integer.MAX_VALUE); jobDescriptor.setJobName(String.valueOf(i + 99999999)); - jobDescriptor.setWorkingDirectory(app.getStaticWorkingDirectory()); - - + jobDescriptor.setWorkingDirectory(jobExecutionContext.getWorkingDir()); List inputValues = new ArrayList(); MessageContext input = jobExecutionContext.getInMessageContext(); Map inputs = input.getParameters(); @@ -194,51 +208,6 @@ public class GFACSSHUtils { } jobDescriptor.setInputValues(inputValues); - // this part will fill out the hpcApplicationDescriptor - if (app instanceof HpcApplicationDeploymentType) { - HpcApplicationDeploymentType applicationDeploymentType - = (HpcApplicationDeploymentType) app; - jobDescriptor.setUserName(((GSISSHAbstractCluster) cluster).getServerInfo().getUserName()); - jobDescriptor.setShellName("/bin/bash"); - jobDescriptor.setAllEnvExport(true); - jobDescriptor.setMailOptions("n"); - jobDescriptor.setNodes(applicationDeploymentType.getNodeCount()); - jobDescriptor.setProcessesPerNode(applicationDeploymentType.getProcessorsPerNode()); - jobDescriptor.setMaxWallTime(String.valueOf(applicationDeploymentType.getMaxWallTime())); - jobDescriptor.setJobSubmitter(applicationDeploymentType.getJobSubmitterCommand()); - jobDescriptor.setCPUCount(applicationDeploymentType.getCpuCount()); - if (applicationDeploymentType.getProjectAccount() != null) { - if (applicationDeploymentType.getProjectAccount().getProjectAccountNumber() != null) { - jobDescriptor.setAcountString(applicationDeploymentType.getProjectAccount().getProjectAccountNumber()); - } - } - if (applicationDeploymentType.getQueue() != null) { - if (applicationDeploymentType.getQueue().getQueueName() != null) { - jobDescriptor.setQueueName(applicationDeploymentType.getQueue().getQueueName()); - } - } - jobDescriptor.setOwner(((PBSCluster) cluster).getServerInfo().getUserName()); - TaskDetails taskData = jobExecutionContext.getTaskData(); - if (taskData != null && taskData.isSetTaskScheduling()) { - ComputationalResourceScheduling computionnalResource = taskData.getTaskScheduling(); - if (computionnalResource.getNodeCount() > 0) { - jobDescriptor.setNodes(computionnalResource.getNodeCount()); - } - if (computionnalResource.getComputationalProjectAccount() != null) { - jobDescriptor.setAcountString(computionnalResource.getComputationalProjectAccount()); - } - if (computionnalResource.getQueueName() != null) { - jobDescriptor.setQueueName(computionnalResource.getQueueName()); - } - if (computionnalResource.getTotalCPUCount() > 0) { - jobDescriptor.setProcessesPerNode(computionnalResource.getTotalCPUCount()); - } - if (computionnalResource.getWallTimeLimit() > 0) { - jobDescriptor.setMaxWallTime(String.valueOf(computionnalResource.getWallTimeLimit())); - } - } - - } return jobDescriptor; } http://git-wip-us.apache.org/repos/asf/airavata/blob/2dd94e63/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/BigRed2TestWithSSHAuth.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/BigRed2TestWithSSHAuth.java b/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/BigRed2TestWithSSHAuth.java index e84848c..c65f386 100644 --- a/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/BigRed2TestWithSSHAuth.java +++ b/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/BigRed2TestWithSSHAuth.java @@ -1,252 +1,252 @@ -/* - * - * 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 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.GFacException; -import org.apache.airavata.gfac.SecurityContext; -import org.apache.airavata.gfac.core.context.ApplicationContext; -import org.apache.airavata.gfac.core.context.JobExecutionContext; -import org.apache.airavata.gfac.core.context.MessageContext; -import org.apache.airavata.gfac.core.cpi.BetterGfacImpl; -import org.apache.airavata.gfac.ssh.security.SSHSecurityContext; -import org.apache.airavata.gsi.ssh.api.Cluster; -import org.apache.airavata.gsi.ssh.api.SSHApiException; -import org.apache.airavata.gsi.ssh.api.ServerInfo; -import org.apache.airavata.gsi.ssh.api.authentication.AuthenticationInfo; -import org.apache.airavata.gsi.ssh.api.job.JobManagerConfiguration; -import org.apache.airavata.gsi.ssh.impl.PBSCluster; -import org.apache.airavata.gsi.ssh.impl.authentication.DefaultPasswordAuthenticationInfo; -import org.apache.airavata.gsi.ssh.impl.authentication.DefaultPublicKeyFileAuthentication; -import org.apache.airavata.gsi.ssh.util.CommonUtils; -import org.apache.airavata.model.workspace.experiment.TaskDetails; -import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory; -import org.apache.airavata.schemas.gfac.*; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.io.File; -import java.net.URL; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.UUID; - -public class BigRed2TestWithSSHAuth { - private JobExecutionContext jobExecutionContext; - - private String userName; - private String password; - private String passPhrase; - private String hostName; - private String workingDirectory; - private String privateKeyPath; - private String publicKeyPath; - - @BeforeClass - public void setUp() throws Exception { - - System.out.println("Test case name " + this.getClass().getName()); -// System.setProperty("ssh.host","bigred2.uits.iu.edu"); //default ssh host -// System.setProperty("ssh.user", "lginnali"); -// System.setProperty("ssh.private.key.path", "/Users/lahirugunathilake/.ssh/id_dsa"); -// System.setProperty("ssh.public.key.path", "/Users/lahirugunathilake/.ssh/id_dsa.pub"); -// System.setProperty("ssh.working.directory", "/tmp"); - - this.hostName = "bigred2.uits.iu.edu"; - this.hostName = System.getProperty("ssh.host"); - this.userName = System.getProperty("ssh.username"); - this.password = System.getProperty("ssh.password"); - this.privateKeyPath = System.getProperty("private.ssh.key"); - this.publicKeyPath = System.getProperty("public.ssh.key"); - this.passPhrase = System.getProperty("ssh.keypass"); - this.workingDirectory = System.getProperty("ssh.working.directory"); - - - if (this.userName == null - || (this.password==null && (this.publicKeyPath == null || this.privateKeyPath == null)) || this.workingDirectory == null) { - System.out.println("########### In order to test you have to either username password or private,public keys"); - System.out.println("Use -Dssh.username=xxx -Dssh.password=yyy -Dssh.keypass=zzz " + - "-Dprivate.ssh.key -Dpublic.ssh.key -Dssh.working.directory "); - } - URL resource = BigRed2TestWithSSHAuth.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); - -// 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(SSHHostType.type); - host.getType().setHostAddress(hostName); - host.getType().setHostName(hostName); - ((SSHHostType)host.getType()).setHpcResource(true); - /* - * 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); - - 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 = "/tmp"; - 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"); - app.setMaxWallTime(5); - app.setJobSubmitterCommand("aprun -n 1"); - app.setInstalledParentPath("/opt/torque/torque-4.2.3.1/bin/"); - - /* - * Service - */ - ServiceDescription serv = new ServiceDescription(); - serv.getType().setName("SimpleEcho"); - - List inputList = new ArrayList(); - - 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 outputList = new ArrayList(); - 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(SSHSecurityContext.SSH_SECURITY_CONTEXT, getSecurityContext(app)); - 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); - - - 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.setRegistry(RegistryFactory.getLoggingRegistry()); - jobExecutionContext.setTaskData(new TaskDetails("11323")); - jobExecutionContext.setOutMessageContext(outMessage); - - } - - - private SecurityContext getSecurityContext(HpcApplicationDeploymentType app) { - try { - - AuthenticationInfo authenticationInfo = null; - if (password != null) { - authenticationInfo = new DefaultPasswordAuthenticationInfo(this.password); - } else { - authenticationInfo = new DefaultPublicKeyFileAuthentication(this.publicKeyPath, this.privateKeyPath, - this.passPhrase); - } - // Server info - ServerInfo serverInfo = new ServerInfo(this.userName, this.hostName); - - Cluster pbsCluster = null; - SSHSecurityContext sshSecurityContext = null; - - JobManagerConfiguration pbsJobManager = CommonUtils.getPBSJobManager(app.getInstalledParentPath()); - pbsCluster = new PBSCluster(serverInfo, authenticationInfo, pbsJobManager); - - - sshSecurityContext = new SSHSecurityContext(); - sshSecurityContext.setPbsCluster(pbsCluster); - sshSecurityContext.setUsername(userName); - sshSecurityContext.setKeyPass(passPhrase); - sshSecurityContext.setPrivateKeyLoc(privateKeyPath); - return sshSecurityContext; - } catch (SSHApiException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } - return null; - } - - @Test - public void testSSHProvider() throws GFacException { - BetterGfacImpl gFacAPI = new BetterGfacImpl(); - gFacAPI.submitJob(jobExecutionContext.getExperimentID(), jobExecutionContext.getTaskData().getTaskID(), jobExecutionContext.getGatewayID()); - org.junit.Assert.assertNotNull(jobExecutionContext.getJobDetails().getJobDescription()); - org.junit.Assert.assertNotNull(jobExecutionContext.getJobDetails().getJobID()); - } - -} +///* +// * +// * 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 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.GFacException; +//import org.apache.airavata.gfac.SecurityContext; +//import org.apache.airavata.gfac.core.context.ApplicationContext; +//import org.apache.airavata.gfac.core.context.JobExecutionContext; +//import org.apache.airavata.gfac.core.context.MessageContext; +//import org.apache.airavata.gfac.core.cpi.BetterGfacImpl; +//import org.apache.airavata.gfac.ssh.security.SSHSecurityContext; +//import org.apache.airavata.gsi.ssh.api.Cluster; +//import org.apache.airavata.gsi.ssh.api.SSHApiException; +//import org.apache.airavata.gsi.ssh.api.ServerInfo; +//import org.apache.airavata.gsi.ssh.api.authentication.AuthenticationInfo; +//import org.apache.airavata.gsi.ssh.api.job.JobManagerConfiguration; +//import org.apache.airavata.gsi.ssh.impl.PBSCluster; +//import org.apache.airavata.gsi.ssh.impl.authentication.DefaultPasswordAuthenticationInfo; +//import org.apache.airavata.gsi.ssh.impl.authentication.DefaultPublicKeyFileAuthentication; +//import org.apache.airavata.gsi.ssh.util.CommonUtils; +//import org.apache.airavata.model.workspace.experiment.TaskDetails; +//import org.apache.airavata.persistance.registry.jpa.impl.RegistryFactory; +//import org.apache.airavata.schemas.gfac.*; +//import org.testng.annotations.BeforeClass; +//import org.testng.annotations.Test; +// +//import java.io.File; +//import java.net.URL; +//import java.util.ArrayList; +//import java.util.Date; +//import java.util.List; +//import java.util.UUID; +// +//public class BigRed2TestWithSSHAuth { +// private JobExecutionContext jobExecutionContext; +// +// private String userName; +// private String password; +// private String passPhrase; +// private String hostName; +// private String workingDirectory; +// private String privateKeyPath; +// private String publicKeyPath; +// +// @BeforeClass +// public void setUp() throws Exception { +// +// System.out.println("Test case name " + this.getClass().getName()); +//// System.setProperty("ssh.host","bigred2.uits.iu.edu"); //default ssh host +//// System.setProperty("ssh.user", "lginnali"); +//// System.setProperty("ssh.private.key.path", "/Users/lahirugunathilake/.ssh/id_dsa"); +//// System.setProperty("ssh.public.key.path", "/Users/lahirugunathilake/.ssh/id_dsa.pub"); +//// System.setProperty("ssh.working.directory", "/tmp"); +// +// this.hostName = "bigred2.uits.iu.edu"; +// this.hostName = System.getProperty("ssh.host"); +// this.userName = System.getProperty("ssh.username"); +// this.password = System.getProperty("ssh.password"); +// this.privateKeyPath = System.getProperty("private.ssh.key"); +// this.publicKeyPath = System.getProperty("public.ssh.key"); +// this.passPhrase = System.getProperty("ssh.keypass"); +// this.workingDirectory = System.getProperty("ssh.working.directory"); +// +// +// if (this.userName == null +// || (this.password==null && (this.publicKeyPath == null || this.privateKeyPath == null)) || this.workingDirectory == null) { +// System.out.println("########### In order to test you have to either username password or private,public keys"); +// System.out.println("Use -Dssh.username=xxx -Dssh.password=yyy -Dssh.keypass=zzz " + +// "-Dprivate.ssh.key -Dpublic.ssh.key -Dssh.working.directory "); +// } +// URL resource = BigRed2TestWithSSHAuth.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); +// +//// 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(SSHHostType.type); +// host.getType().setHostAddress(hostName); +// host.getType().setHostName(hostName); +// ((SSHHostType)host.getType()).setHpcResource(true); +// /* +// * 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); +// +// 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 = "/tmp"; +// 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"); +// app.setMaxWallTime(5); +// app.setJobSubmitterCommand("aprun -n 1"); +// app.setInstalledParentPath("/opt/torque/torque-4.2.3.1/bin/"); +// +// /* +// * Service +// */ +// ServiceDescription serv = new ServiceDescription(); +// serv.getType().setName("SimpleEcho"); +// +// List inputList = new ArrayList(); +// +// 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 outputList = new ArrayList(); +// 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(SSHSecurityContext.SSH_SECURITY_CONTEXT, getSecurityContext(app)); +// 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); +// +// +// 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.setRegistry(RegistryFactory.getLoggingRegistry()); +// jobExecutionContext.setTaskData(new TaskDetails("11323")); +// jobExecutionContext.setOutMessageContext(outMessage); +// +// } +// +// +// private SecurityContext getSecurityContext(HpcApplicationDeploymentType app) { +// try { +// +// AuthenticationInfo authenticationInfo = null; +// if (password != null) { +// authenticationInfo = new DefaultPasswordAuthenticationInfo(this.password); +// } else { +// authenticationInfo = new DefaultPublicKeyFileAuthentication(this.publicKeyPath, this.privateKeyPath, +// this.passPhrase); +// } +// // Server info +// ServerInfo serverInfo = new ServerInfo(this.userName, this.hostName); +// +// Cluster pbsCluster = null; +// SSHSecurityContext sshSecurityContext = null; +// +// JobManagerConfiguration pbsJobManager = CommonUtils.getPBSJobManager(app.getInstalledParentPath()); +// pbsCluster = new PBSCluster(serverInfo, authenticationInfo, pbsJobManager); +// +// +// sshSecurityContext = new SSHSecurityContext(); +// sshSecurityContext.setPbsCluster(pbsCluster); +// sshSecurityContext.setUsername(userName); +// sshSecurityContext.setKeyPass(passPhrase); +// sshSecurityContext.setPrivateKeyLoc(privateKeyPath); +// return sshSecurityContext; +// } catch (SSHApiException e) { +// e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. +// } +// return null; +// } +// +// @Test +// public void testSSHProvider() throws GFacException { +// BetterGfacImpl gFacAPI = new BetterGfacImpl(); +// gFacAPI.submitJob(jobExecutionContext.getExperimentID(), jobExecutionContext.getTaskData().getTaskID(), jobExecutionContext.getGatewayID()); +// org.junit.Assert.assertNotNull(jobExecutionContext.getJobDetails().getJobDescription()); +// org.junit.Assert.assertNotNull(jobExecutionContext.getJobDetails().getJobID()); +// } +// +//} http://git-wip-us.apache.org/repos/asf/airavata/blob/2dd94e63/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTestWithSSHAuth.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTestWithSSHAuth.java b/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTestWithSSHAuth.java index 5cb1200..b115b6c 100644 --- a/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTestWithSSHAuth.java +++ b/modules/gfac/gfac-ssh/src/test/java/org/apache/airavata/core/gfac/services/impl/SSHProviderTestWithSSHAuth.java @@ -1,172 +1,172 @@ -/* - * - * 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.core.context.ApplicationContext; -import org.apache.airavata.gfac.core.context.JobExecutionContext; -import org.apache.airavata.gfac.core.context.MessageContext; -import org.apache.airavata.gfac.core.cpi.BetterGfacImpl; -import org.apache.airavata.gfac.ssh.security.SSHSecurityContext; -import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType; -import org.apache.airavata.schemas.gfac.InputParameterType; -import org.apache.airavata.schemas.gfac.OutputParameterType; -import org.apache.airavata.schemas.gfac.SSHHostType; -import org.apache.airavata.schemas.gfac.StringParameterType; -import org.apache.commons.lang.SystemUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class SSHProviderTestWithSSHAuth { - private JobExecutionContext jobExecutionContext; - @Before - public void setUp() throws Exception { - - URL resource = SSHProviderTestWithSSHAuth.class.getClassLoader().getResource(org.apache.airavata.common.utils.Constants.GFAC_CONFIG_XML); - GFacConfiguration gFacConfiguration = GFacConfiguration.create(new File(resource.getPath()),null); -// gFacConfiguration.s - //have to set InFlwo Handlers and outFlowHandlers - ApplicationContext applicationContext = new ApplicationContext(); - HostDescription host = new HostDescription(SSHHostType.type); - host.getType().setHostName("bigred"); - host.getType().setHostAddress("bigred2.uits.iu.edu"); - applicationContext.setHostDescription(host); - /* - * App - */ - ApplicationDescription appDesc = new ApplicationDescription(); - ApplicationDeploymentDescriptionType app = appDesc.getType(); - ApplicationDeploymentDescriptionType.ApplicationName name = ApplicationDeploymentDescriptionType.ApplicationName.Factory.newInstance(); - name.setStringValue("EchoSSH"); - app.setApplicationName(name); - - /* - * Use bat file if it is compiled on Windows - */ - if (SystemUtils.IS_OS_WINDOWS) { - URL url = this.getClass().getClassLoader().getResource("echo.bat"); - app.setExecutableLocation(url.getFile()); - } else { - //for unix and Mac - app.setExecutableLocation("/bin/echo"); - } - - /* - * Job location - */ - String tempDir = "/tmp"; - String date = (new Date()).toString(); - date = date.replaceAll(" ", "_"); - date = date.replaceAll(":", "_"); - - tempDir = tempDir + File.separator - + "EchoSSH" + "_" + date + "_" + UUID.randomUUID(); - - app.setScratchWorkingDirectory(tempDir); - app.setStaticWorkingDirectory(tempDir); - app.setInputDataDirectory(tempDir + File.separator + "input"); - app.setOutputDataDirectory(tempDir + File.separator + "output"); - app.setStandardOutput(tempDir + File.separator + "echo.stdout"); - app.setStandardError(tempDir + File.separator + "echo.stderr"); - - applicationContext.setApplicationDeploymentDescription(appDesc); - - /* - * Service - */ - ServiceDescription serv = new ServiceDescription(); - serv.getType().setName("EchoSSH"); - - List inputList = new ArrayList(); - 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 outputList = new ArrayList(); - 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()); - jobExecutionContext.setApplicationContext(applicationContext); - - // Add security context - jobExecutionContext.addSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT, getSecurityContext()); - /* - * Host - */ - applicationContext.setServiceDescription(serv); - - MessageContext inMessage = new MessageContext(); - ActualParameter echo_input = new ActualParameter(); - ((StringParameterType)echo_input.getType()).setValue("echo_output=hello"); - inMessage.addParameter("echo_input", echo_input); - - jobExecutionContext.setInMessageContext(inMessage); - - MessageContext outMessage = new MessageContext(); - ActualParameter echo_out = new ActualParameter(); +///* +// * +// * 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.core.context.ApplicationContext; +//import org.apache.airavata.gfac.core.context.JobExecutionContext; +//import org.apache.airavata.gfac.core.context.MessageContext; +//import org.apache.airavata.gfac.core.cpi.BetterGfacImpl; +//import org.apache.airavata.gfac.ssh.security.SSHSecurityContext; +//import org.apache.airavata.schemas.gfac.ApplicationDeploymentDescriptionType; +//import org.apache.airavata.schemas.gfac.InputParameterType; +//import org.apache.airavata.schemas.gfac.OutputParameterType; +//import org.apache.airavata.schemas.gfac.SSHHostType; +//import org.apache.airavata.schemas.gfac.StringParameterType; +//import org.apache.commons.lang.SystemUtils; +//import org.junit.Assert; +//import org.junit.Before; +//import org.junit.Test; +// +//public class SSHProviderTestWithSSHAuth { +// private JobExecutionContext jobExecutionContext; +// @Before +// public void setUp() throws Exception { +// +// URL resource = SSHProviderTestWithSSHAuth.class.getClassLoader().getResource(org.apache.airavata.common.utils.Constants.GFAC_CONFIG_XML); +// GFacConfiguration gFacConfiguration = GFacConfiguration.create(new File(resource.getPath()),null); +//// gFacConfiguration.s +// //have to set InFlwo Handlers and outFlowHandlers +// ApplicationContext applicationContext = new ApplicationContext(); +// HostDescription host = new HostDescription(SSHHostType.type); +// host.getType().setHostName("bigred"); +// host.getType().setHostAddress("bigred2.uits.iu.edu"); +// applicationContext.setHostDescription(host); +// /* +// * App +// */ +// ApplicationDescription appDesc = new ApplicationDescription(); +// ApplicationDeploymentDescriptionType app = appDesc.getType(); +// ApplicationDeploymentDescriptionType.ApplicationName name = ApplicationDeploymentDescriptionType.ApplicationName.Factory.newInstance(); +// name.setStringValue("EchoSSH"); +// app.setApplicationName(name); +// +// /* +// * Use bat file if it is compiled on Windows +// */ +// if (SystemUtils.IS_OS_WINDOWS) { +// URL url = this.getClass().getClassLoader().getResource("echo.bat"); +// app.setExecutableLocation(url.getFile()); +// } else { +// //for unix and Mac +// app.setExecutableLocation("/bin/echo"); +// } +// +// /* +// * Job location +// */ +// String tempDir = "/tmp"; +// String date = (new Date()).toString(); +// date = date.replaceAll(" ", "_"); +// date = date.replaceAll(":", "_"); +// +// tempDir = tempDir + File.separator +// + "EchoSSH" + "_" + date + "_" + UUID.randomUUID(); +// +// app.setScratchWorkingDirectory(tempDir); +// app.setStaticWorkingDirectory(tempDir); +// app.setInputDataDirectory(tempDir + File.separator + "input"); +// app.setOutputDataDirectory(tempDir + File.separator + "output"); +// app.setStandardOutput(tempDir + File.separator + "echo.stdout"); +// app.setStandardError(tempDir + File.separator + "echo.stderr"); +// +// applicationContext.setApplicationDeploymentDescription(appDesc); +// +// /* +// * Service +// */ +// ServiceDescription serv = new ServiceDescription(); +// serv.getType().setName("EchoSSH"); +// +// List inputList = new ArrayList(); +// 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 outputList = new ArrayList(); +// 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()); +// jobExecutionContext.setApplicationContext(applicationContext); +// +// // Add security context +// jobExecutionContext.addSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT, getSecurityContext()); +// /* +// * Host +// */ +// applicationContext.setServiceDescription(serv); +// +// MessageContext inMessage = new MessageContext(); +// ActualParameter echo_input = new ActualParameter(); // ((StringParameterType)echo_input.getType()).setValue("echo_output=hello"); - outMessage.addParameter("echo_output", echo_out); - - jobExecutionContext.setOutMessageContext(outMessage); - - } - - private SSHSecurityContext getSecurityContext() { - SSHSecurityContext context = new SSHSecurityContext(); - context.setUsername("lginnali"); - context.setPrivateKeyLoc("~/.ssh/id_dsa"); - context.setKeyPass("i want to be free"); - return context; - } - - @Test - public void testLocalProvider() throws GFacException { - BetterGfacImpl gFacAPI = new BetterGfacImpl(); - gFacAPI.submitJob(jobExecutionContext.getExperimentID(), jobExecutionContext.getTaskData().getTaskID(), jobExecutionContext.getGatewayID()); - MessageContext outMessageContext = jobExecutionContext.getOutMessageContext(); - Assert.assertEquals(MappingFactory.toString((ActualParameter)outMessageContext.getParameter("echo_output")), "hello"); - } -} +// inMessage.addParameter("echo_input", echo_input); +// +// 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); +// +// } +// +// private SSHSecurityContext getSecurityContext() { +// SSHSecurityContext context = new SSHSecurityContext(); +// context.setUsername("lginnali"); +// context.setPrivateKeyLoc("~/.ssh/id_dsa"); +// context.setKeyPass("i want to be free"); +// return context; +// } +// +// @Test +// public void testLocalProvider() throws GFacException { +// BetterGfacImpl gFacAPI = new BetterGfacImpl(); +// gFacAPI.submitJob(jobExecutionContext.getExperimentID(), jobExecutionContext.getTaskData().getTaskID(), jobExecutionContext.getGatewayID()); +// MessageContext outMessageContext = jobExecutionContext.getOutMessageContext(); +// Assert.assertEquals(MappingFactory.toString((ActualParameter)outMessageContext.getParameter("echo_output")), "hello"); +// } +//}