http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Cluster.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Cluster.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Cluster.java new file mode 100644 index 0000000..beb5b37 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Cluster.java @@ -0,0 +1,162 @@ +/* + * + * 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.ssh.api; + +import java.util.List; +import java.util.Map; + +import org.apache.airavata.gfac.ssh.api.job.JobDescriptor; +import org.apache.airavata.gfac.ssh.impl.JobStatus; + +import com.jcraft.jsch.Session; + +/** + * This interface represents a Cluster machine + * End users of the API can implement this and come up with their own + * implementations, but mostly this interface is for internal usage. + */ +public interface Cluster { + + /** + * This will submit a job to the cluster with a given pbs file and some parameters + * + * @param pbsFilePath path of the pbs file + * @param workingDirectory working directory where pbs should has to copy + * @return jobId after successful job submission + * @throws SSHApiException throws exception during error + */ + public String submitBatchJobWithScript(String pbsFilePath, String workingDirectory) throws SSHApiException; + + /** + * This will submit the given job and not performing any monitoring + * + * @param jobDescriptor job descriptor to submit to cluster, this contains all the parameter + * @return jobID after successful job submission. + * @throws SSHApiException throws exception during error + */ + public String submitBatchJob(JobDescriptor jobDescriptor) throws SSHApiException; + + /** + * This will copy the localFile to remoteFile location in configured cluster + * + * @param remoteFile remote file location, this can be a directory too + * @param localFile local file path of the file which needs to copy to remote location + * @throws SSHApiException throws exception during error + */ + public void scpTo(String remoteFile, String localFile) throws SSHApiException; + + /** + * This will copy a remote file in path rFile to local file lFile + * @param remoteFile remote file path, this has to be a full qualified path + * @param localFile This is the local file to copy, this can be a directory too + * @throws SSHApiException + */ + public void scpFrom(String remoteFile, String localFile) throws SSHApiException; + + /** + * This will copy a remote file in path rFile to local file lFile + * @param remoteFile remote file path, this has to be a full qualified path + * @param localFile This is the local file to copy, this can be a directory too + * @throws SSHApiException + */ + public void scpThirdParty(String remoteFileSorce, String remoteFileTarget) throws SSHApiException; + + /** + * This will create directories in computing resources + * @param directoryPath the full qualified path for the directory user wants to create + * @throws SSHApiException throws during error + */ + public void makeDirectory(String directoryPath) throws SSHApiException; + + + /** + * This will get the job description of a job which is there in the cluster + * if jbo is not available with the given ID it returns + * @param jobID jobId has to pass + * @return Returns full job description of the job which submitted successfully + * @throws SSHApiException throws exception during error + */ + public JobDescriptor getJobDescriptorById(String jobID) throws SSHApiException; + + /** + * This will delete the given job from the queue + * + * @param jobID jobId of the job which user wants to delete + * @return return the description of the deleted job + * @throws SSHApiException throws exception during error + */ + public JobDescriptor cancelJob(String jobID) throws SSHApiException; + + /** + * This will get the job status of the the job associated with this jobId + * + * @param jobID jobId of the job user want to get the status + * @return job status of the given jobID + * @throws SSHApiException throws exception during error + */ + public JobStatus getJobStatus(String jobID) throws SSHApiException; + /** + * This will get the job status of the the job associated with this jobId + * + * @param jobName jobName of the job user want to get the status + * @return jobId of the given jobName + * @throws SSHApiException throws exception during error + */ + public String getJobIdByJobName(String jobName, String userName) throws SSHApiException; + + /** + * This method can be used to poll the jobstatuses based on the given + * user but we should pass the jobID list otherwise we will get unwanted + * job statuses which submitted by different middleware outside apache + * airavata with the same uername which we are not considering + * @param userName userName of the jobs which required to get the status + * @param jobIDs precises set of jobIDs + * @return + */ + public void getJobStatuses(String userName,Map<String,JobStatus> jobIDs)throws SSHApiException; + /** + * This will list directories in computing resources + * @param directoryPath the full qualified path for the directory user wants to create + * @throws SSHApiException throws during error + */ + public List<String> listDirectory(String directoryPath) throws SSHApiException; + + /** + * This method can be used to get created ssh session + * to reuse the created session. + * @throws SSHApiException + */ + public Session getSession() throws SSHApiException; + + /** + * This method can be used to close the connections initialized + * to handle graceful shutdown of the system + * @throws SSHApiException + */ + public void disconnect() throws SSHApiException; + + /** + * This gives the server Info + * @return + */ + public ServerInfo getServerInfo(); + +}
http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandExecutor.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandExecutor.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandExecutor.java new file mode 100644 index 0000000..024c53d --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandExecutor.java @@ -0,0 +1,278 @@ +/* + * + * 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.ssh.api; + +import com.jcraft.jsch.*; +import org.apache.airavata.gfac.ssh.api.authentication.*; +import org.apache.airavata.gfac.ssh.config.ConfigReader; +import org.apache.airavata.gfac.ssh.jsch.ExtendedJSch; +import org.apache.airavata.gfac.ssh.util.SSHAPIUIKeyboardInteractive; +import org.apache.airavata.gfac.ssh.util.SSHKeyPasswordHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is a generic class which take care of command execution + * in a shell, this is used through out the other places of the API. + */ +public class CommandExecutor { + static { + JSch.setConfig("gssapi-with-mic.x509", "org.apache.airavata.gfac.ssh.GSSContextX509"); + JSch.setConfig("userauth.gssapi-with-mic", "com.jcraft.jsch.UserAuthGSSAPIWithMICGSSCredentials"); + JSch jSch = new JSch(); + } + + private static final Logger log = LoggerFactory.getLogger(CommandExecutor.class); + public static final String X509_CERT_DIR = "X509_CERT_DIR"; + + /** + * This will execute the given command with given session and session is not closed at the end. + * + * @param commandInfo + * @param session + * @param commandOutput + * @throws SSHApiException + */ + public static Session executeCommand(CommandInfo commandInfo, Session session, + CommandOutput commandOutput) throws SSHApiException { + + String command = commandInfo.getCommand(); + + Channel channel = null; + try { + if (!session.isConnected()) { + session.connect(); + } + channel = session.openChannel("exec"); + ((ChannelExec) channel).setCommand(command); + } catch (JSchException e) { +// session.disconnect(); + + throw new SSHApiException("Unable to execute command - ", e); + } + + channel.setInputStream(null); + ((ChannelExec) channel).setErrStream(commandOutput.getStandardError()); + try { + channel.connect(); + } catch (JSchException e) { + + channel.disconnect(); +// session.disconnect(); + throw new SSHApiException("Unable to retrieve command output. Command - " + command, e); + } + + + commandOutput.onOutput(channel); + //Only disconnecting the channel, session can be reused + channel.disconnect(); + return session; + } + + /** + * This will not reuse any session, it will create the session and close it at the end + * + * @param commandInfo Encapsulated information about command. E.g :- executable name + * parameters etc ... + * @param serverInfo The SSHing server information. + * @param authenticationInfo Security data needs to be communicated with remote server. + * @param commandOutput The output of the command. + * @param configReader configuration required for ssh/gshissh connection + * @throws SSHApiException throw exception when error occurs + */ + public static void executeCommand(CommandInfo commandInfo, ServerInfo serverInfo, + AuthenticationInfo authenticationInfo, + CommandOutput commandOutput, ConfigReader configReader) throws SSHApiException { + + if (authenticationInfo instanceof GSIAuthenticationInfo) { + System.setProperty(X509_CERT_DIR, (String) ((GSIAuthenticationInfo)authenticationInfo).getProperties(). + get("X509_CERT_DIR")); + } + + + JSch jsch = new ExtendedJSch(); + + log.debug("Connecting to server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " with user name - " + + serverInfo.getUserName()); + + Session session; + + try { + session = jsch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort()); + } catch (JSchException e) { + throw new SSHApiException("An exception occurred while creating SSH session." + + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName(), e); + } + + java.util.Properties config = configReader.getProperties(); + session.setConfig(config); + + //============================================================= + // Handling vanilla SSH pieces + //============================================================= + if (authenticationInfo instanceof SSHPasswordAuthentication) { + String password = ((SSHPasswordAuthentication) authenticationInfo). + getPassword(serverInfo.getUserName(), serverInfo.getHost()); + + session.setUserInfo(new SSHAPIUIKeyboardInteractive(password)); + + // TODO figure out why we need to set password to session + session.setPassword(password); + + } else if (authenticationInfo instanceof SSHPublicKeyFileAuthentication) { + SSHPublicKeyFileAuthentication sshPublicKeyFileAuthentication + = (SSHPublicKeyFileAuthentication)authenticationInfo; + + String privateKeyFile = sshPublicKeyFileAuthentication. + getPrivateKeyFile(serverInfo.getUserName(), serverInfo.getHost()); + + logDebug("The private key file for vanilla SSH " + privateKeyFile); + + String publicKeyFile = sshPublicKeyFileAuthentication. + getPrivateKeyFile(serverInfo.getUserName(), serverInfo.getHost()); + + logDebug("The public key file for vanilla SSH " + publicKeyFile); + + Identity identityFile; + + try { + identityFile = GSISSHIdentityFile.newInstance(privateKeyFile, null, jsch); + } catch (JSchException e) { + throw new SSHApiException("An exception occurred while initializing keys using files. " + + "(private key and public key)." + + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName() + " private key file - " + privateKeyFile + ", public key file - " + + publicKeyFile, e); + } + + // Add identity to identity repository + GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jsch); + identityRepository.add(identityFile); + + // Set repository to session + session.setIdentityRepository(identityRepository); + + // Set the user info + SSHKeyPasswordHandler sshKeyPasswordHandler + = new SSHKeyPasswordHandler((SSHKeyAuthentication)authenticationInfo); + + session.setUserInfo(sshKeyPasswordHandler); + + } else if (authenticationInfo instanceof SSHPublicKeyAuthentication) { + + SSHPublicKeyAuthentication sshPublicKeyAuthentication + = (SSHPublicKeyAuthentication)authenticationInfo; + + Identity identityFile; + + try { + String name = serverInfo.getUserName() + "_" + serverInfo.getHost(); + identityFile = GSISSHIdentityFile.newInstance(name, + sshPublicKeyAuthentication.getPrivateKey(serverInfo.getUserName(), serverInfo.getHost()), + sshPublicKeyAuthentication.getPublicKey(serverInfo.getUserName(), serverInfo.getHost()), jsch); + } catch (JSchException e) { + throw new SSHApiException("An exception occurred while initializing keys using byte arrays. " + + "(private key and public key)." + + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName(), e); + } + + // Add identity to identity repository + GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jsch); + identityRepository.add(identityFile); + + // Set repository to session + session.setIdentityRepository(identityRepository); + + // Set the user info + SSHKeyPasswordHandler sshKeyPasswordHandler + = new SSHKeyPasswordHandler((SSHKeyAuthentication)authenticationInfo); + + session.setUserInfo(sshKeyPasswordHandler); + + } + + // Not a good way, but we dont have any choice + if (session instanceof ExtendedSession) { + if (authenticationInfo instanceof GSIAuthenticationInfo) { + ((ExtendedSession) session).setAuthenticationInfo((GSIAuthenticationInfo)authenticationInfo); + } + } + + try { + session.connect(); + } catch (JSchException e) { + throw new SSHApiException("An exception occurred while connecting to server." + + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName(), e); + } + + String command = commandInfo.getCommand(); + + Channel channel; + try { + channel = session.openChannel("exec"); + ((ChannelExec) channel).setCommand(command); + } catch (JSchException e) { +// session.disconnect(); + + throw new SSHApiException("Unable to execute command - " + command + + " on server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName(), e); + } + + + channel.setInputStream(null); + ((ChannelExec) channel).setErrStream(commandOutput.getStandardError()); + + try { + channel.connect(); + } catch (JSchException e) { + + channel.disconnect(); +// session.disconnect(); + + throw new SSHApiException("Unable to retrieve command output. Command - " + command + + " on server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName(), e); + } + + commandOutput.onOutput(channel); + + channel.disconnect(); +// session.disconnect(); + } + + private static void logDebug(String message) { + if (log.isDebugEnabled()) { + log.debug(message); + } + } + + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandInfo.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandInfo.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandInfo.java new file mode 100644 index 0000000..e6797ce --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandInfo.java @@ -0,0 +1,34 @@ +package org.apache.airavata.gfac.ssh.api;/* + * + * 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. + * + */ + +/** + * Encapsulates information about + */ +public interface CommandInfo { + + /** + * Gets the executable command as a string. + * @return String encoded command. Should be able to execute + * directly on remote shell. Should includes appropriate parameters. + */ + String getCommand(); + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandOutput.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandOutput.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandOutput.java new file mode 100644 index 0000000..f275ff0 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/CommandOutput.java @@ -0,0 +1,49 @@ +package org.apache.airavata.gfac.ssh.api;/* + * + * 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. + * + */ + + +import com.jcraft.jsch.Channel; + +import java.io.OutputStream; + +/** + * Output of a certain command. TODO rethink + */ +public interface CommandOutput { + + /** + * Gets the output of the command as a stream. + * @param channel Command output as a stream. + */ + void onOutput(Channel channel); + + /** + * Gets standard error as a output stream. + * @return Command error as a stream. + */ + OutputStream getStandardError(); + + /** + * The command exit code. + * @param code The program exit code + */ + void exitCode(int code); +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Core.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Core.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Core.java new file mode 100644 index 0000000..67dd043 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Core.java @@ -0,0 +1,59 @@ +/* + * + * 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.ssh.api; + +import org.apache.airavata.gfac.ssh.api.job.JobDescriptor; + +/** + * This represents a CPU core of a machine in the cluster + */ +public class Core { + private JobDescriptor job; + private String id; + + public Core(String id) { + this.id = id; + this.job = null; + } + + /** + * @return core's id + */ + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * @return job running on the core + */ + public JobDescriptor getJob() { + return job; + } + + public void setJob(JobDescriptor job) { + this.job = job; + } + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Node.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Node.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Node.java new file mode 100644 index 0000000..1515f39 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/Node.java @@ -0,0 +1,104 @@ +/* + * + * 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.ssh.api; + +import java.util.HashMap; + +public class Node { + private String Name; + private Core[] Cores; + private String state; + private HashMap<String, String> status; + private String np; + private String ntype; + + /** + * @return the machine's name + */ + public String getName() { + return Name; + } + + public void setName(String Name) { + this.Name = Name; + } + + /** + * @return machine cores as an array + */ + public Core[] getCores() { + return Cores; + } + + public void setCores(Core[] Cores) { + this.Cores = Cores; + } + + + /** + * @return the machine state + */ + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + /** + * @return the status + */ + public HashMap<String, String> getStatus() { + return status; + } + + public void setStatus(HashMap<String, String> status) { + this.setStatus(status); + } + + + /** + * @return the number of cores in the machine + */ + public String getNp() { + return np; + } + + + public void setNp(String np) { + this.np = np; + } + + /** + * @return the ntype of the machine + */ + public String getNtype() { + return ntype; + } + + + public void setNtype(String ntype) { + this.ntype = ntype; + } + + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/SSHApiException.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/SSHApiException.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/SSHApiException.java new file mode 100644 index 0000000..f78825b --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/SSHApiException.java @@ -0,0 +1,36 @@ +/* + * + * 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.ssh.api; + +/** + * An exception class to wrap SSH command execution related errors. + */ +public class SSHApiException extends Exception { + + public SSHApiException(String message) { + super(message); + } + + public SSHApiException(String message, Exception e) { + super(message, e); + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/ServerInfo.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/ServerInfo.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/ServerInfo.java new file mode 100644 index 0000000..d3c2160 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/ServerInfo.java @@ -0,0 +1,65 @@ +package org.apache.airavata.gfac.ssh.api;/* + * + * 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. + * + */ + +/** + * Encapsulate server information. + */ +public class ServerInfo { + + private String host; + private String userName; + private int port = 22; + + public ServerInfo(String userName, String host) { + this.userName = userName; + this.host = host; + } + + public ServerInfo(String userName,String host, int port) { + this.host = host; + this.userName = userName; + this.port = port; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobDescriptor.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobDescriptor.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobDescriptor.java new file mode 100644 index 0000000..7e936ec --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobDescriptor.java @@ -0,0 +1,473 @@ +/* + * + * 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.ssh.api.job; + +import org.apache.airavata.gfac.ssh.api.CommandOutput; +import org.apache.airavata.gfac.ssh.util.CommonUtils; +import org.apache.airavata.gfac.ssh.x2012.x12.*; +import org.apache.xmlbeans.XmlException; + +import java.util.List; + +/** + * This class define a job with required parameters, based on this configuration API is generating a Pbs script and + * submit the job to the computing resource + */ +public class JobDescriptor { + + private JobDescriptorDocument jobDescriptionDocument; + + + public JobDescriptor() { + jobDescriptionDocument = JobDescriptorDocument.Factory.newInstance(); + jobDescriptionDocument.addNewJobDescriptor(); + } + + public JobDescriptor(JobDescriptorDocument jobDescriptorDocument) { + this.jobDescriptionDocument = jobDescriptorDocument; + } + + + public JobDescriptor(CommandOutput commandOutput) { + jobDescriptionDocument = JobDescriptorDocument.Factory.newInstance(); + jobDescriptionDocument.addNewJobDescriptor(); + } + + + public String toXML() { + return jobDescriptionDocument.xmlText(); + } + + public JobDescriptorDocument getJobDescriptorDocument() { + return this.jobDescriptionDocument; + } + + /** + * With new app catalog thrift object integration, we don't use this + * @param xml + * @return + * @throws XmlException + */ + @Deprecated + public static JobDescriptor fromXML(String xml) + throws XmlException { + JobDescriptorDocument parse = JobDescriptorDocument.Factory + .parse(xml); + JobDescriptor jobDescriptor = new JobDescriptor(parse); + return jobDescriptor; + } + + + //todo write bunch of setter getters to set and get jobdescription parameters + public void setWorkingDirectory(String workingDirectory) { + this.getJobDescriptorDocument().getJobDescriptor().setWorkingDirectory(workingDirectory); + } + + public String getWorkingDirectory() { + return this.getJobDescriptorDocument().getJobDescriptor().getWorkingDirectory(); + } + + public void setShellName(String shellName) { + this.getJobDescriptorDocument().getJobDescriptor().setShellName(shellName); + } + + public void setJobName(String name) { + this.getJobDescriptorDocument().getJobDescriptor().setJobName(name); + } + + public void setExecutablePath(String name) { + this.getJobDescriptorDocument().getJobDescriptor().setExecutablePath(name); + } + + public void setAllEnvExport(boolean name) { + this.getJobDescriptorDocument().getJobDescriptor().setAllEnvExport(name); + } + + public void setMailOptions(String name) { + this.getJobDescriptorDocument().getJobDescriptor().setMailOptions(name); + } + + public void setStandardOutFile(String name) { + this.getJobDescriptorDocument().getJobDescriptor().setStandardOutFile(name); + } + + public void setStandardErrorFile(String name) { + this.getJobDescriptorDocument().getJobDescriptor().setStandardErrorFile(name); + } + + public void setNodes(int name) { + this.getJobDescriptorDocument().getJobDescriptor().setNodes(name); + } + + public void setProcessesPerNode(int name) { + this.getJobDescriptorDocument().getJobDescriptor().setProcessesPerNode(name); + } + + public String getOutputDirectory() { + return this.getJobDescriptorDocument().getJobDescriptor().getOutputDirectory(); + } + + public String getInputDirectory() { + return this.getJobDescriptorDocument().getJobDescriptor().getInputDirectory(); + } + public void setOutputDirectory(String name) { + this.getJobDescriptorDocument().getJobDescriptor().setOutputDirectory(name); + } + + public void setInputDirectory(String name) { + this.getJobDescriptorDocument().getJobDescriptor().setInputDirectory(name); + } + + /** + * Users can pass the minute count for maxwalltime + * @param minutes + */ + public void setMaxWallTime(String minutes) { + this.getJobDescriptorDocument().getJobDescriptor().setMaxWallTime( + CommonUtils.maxWallTimeCalculator(Integer.parseInt(minutes))); + + } + + + public void setMaxWallTimeForLSF(String minutes) { + this.getJobDescriptorDocument().getJobDescriptor().setMaxWallTime( + CommonUtils.maxWallTimeCalculatorForLSF(Integer.parseInt(minutes))); + + } + public void setAcountString(String name) { + this.getJobDescriptorDocument().getJobDescriptor().setAcountString(name); + } + + public void setInputValues(List<String> inputValue) { + InputList inputList = this.getJobDescriptorDocument().getJobDescriptor().addNewInputs(); + inputList.setInputArray(inputValue.toArray(new String[inputValue.size()])); + } + + public void setJobID(String jobID) { + this.getJobDescriptorDocument().getJobDescriptor().setJobID(jobID); + } + + public void setQueueName(String queueName) { + this.getJobDescriptorDocument().getJobDescriptor().setQueueName(queueName); + } + + public void setStatus(String queueName) { + this.getJobDescriptorDocument().getJobDescriptor().setStatus(queueName); + } + + public void setAfterAnyList(String[] afterAnyList) { + AfterAnyList afterAny = this.getJobDescriptorDocument().getJobDescriptor().addNewAfterAny(); + afterAny.setAfterAnyArray(afterAnyList); + } + + public void setAfterOKList(String[] afterOKList) { + AfterOKList afterAnyList = this.getJobDescriptorDocument().getJobDescriptor().addNewAfterOKList(); + afterAnyList.setAfterOKListArray(afterOKList); + } + public void setCTime(String cTime) { + this.getJobDescriptorDocument().getJobDescriptor().setCTime(cTime); + } + public void setQTime(String qTime) { + this.getJobDescriptorDocument().getJobDescriptor().setQTime(qTime); + } + public void setMTime(String mTime) { + this.getJobDescriptorDocument().getJobDescriptor().setMTime(mTime); + } + public void setSTime(String sTime) { + this.getJobDescriptorDocument().getJobDescriptor().setSTime(sTime); + } + public void setCompTime(String compTime) { + this.getJobDescriptorDocument().getJobDescriptor().setCompTime(compTime); + } + public void setOwner(String owner) { + this.getJobDescriptorDocument().getJobDescriptor().setOwner(owner); + } + public void setExecuteNode(String executeNode) { + this.getJobDescriptorDocument().getJobDescriptor().setExecuteNode(executeNode); + } + public void setEllapsedTime(String ellapsedTime) { + this.getJobDescriptorDocument().getJobDescriptor().setEllapsedTime(ellapsedTime); + } + + public void setUsedCPUTime(String usedCPUTime) { + this.getJobDescriptorDocument().getJobDescriptor().setUsedCPUTime(usedCPUTime); + } + public void setCPUCount(int usedCPUTime) { + this.getJobDescriptorDocument().getJobDescriptor().setCpuCount(usedCPUTime); + } + public void setUsedMemory(String usedMemory) { + this.getJobDescriptorDocument().getJobDescriptor().setUsedMem(usedMemory); + } + public void setVariableList(String variableList) { + this.getJobDescriptorDocument().getJobDescriptor().setVariableList(variableList); + } + public void setSubmitArgs(String submitArgs) { + this.getJobDescriptorDocument().getJobDescriptor().setSubmitArgs(submitArgs); + } + + public void setPreJobCommands(String[] commands){ + if(this.getJobDescriptorDocument().getJobDescriptor().getPreJobCommands() == null){ + this.getJobDescriptorDocument().getJobDescriptor().addNewPreJobCommands(); + } + this.getJobDescriptorDocument().getJobDescriptor().getPreJobCommands().setCommandArray(commands); + } + + public void setPostJobCommands(String[] commands){ + if(this.getJobDescriptorDocument().getJobDescriptor().getPostJobCommands() == null){ + this.getJobDescriptorDocument().getJobDescriptor().addNewPostJobCommands(); + } + this.getJobDescriptorDocument().getJobDescriptor().getPostJobCommands().setCommandArray(commands); + } + + public void setModuleLoadCommands(String[] commands) { + if (this.getJobDescriptorDocument().getJobDescriptor().getModuleLoadCommands() == null) { + this.getJobDescriptorDocument().getJobDescriptor().addNewModuleLoadCommands(); + } + this.getJobDescriptorDocument().getJobDescriptor().getModuleLoadCommands().setCommandArray(commands); + } + + public void addModuleLoadCommands(String command) { + if (this.getJobDescriptorDocument().getJobDescriptor().getModuleLoadCommands() == null) { + this.getJobDescriptorDocument().getJobDescriptor().addNewModuleLoadCommands(); + } + this.getJobDescriptorDocument().getJobDescriptor().getModuleLoadCommands().addCommand(command); + } + + public void addPreJobCommand(String command){ + if(this.getJobDescriptorDocument().getJobDescriptor().getPreJobCommands() == null){ + this.getJobDescriptorDocument().getJobDescriptor().addNewPreJobCommands(); + } + this.getJobDescriptorDocument().getJobDescriptor().getPreJobCommands().addCommand(command); + } + + public void addPostJobCommand(String command){ + if(this.getJobDescriptorDocument().getJobDescriptor().getPostJobCommands() == null){ + this.getJobDescriptorDocument().getJobDescriptor().addNewPostJobCommands(); + } + this.getJobDescriptorDocument().getJobDescriptor().getPostJobCommands().addCommand(command); + } + + public void setPartition(String partition){ + this.getJobDescriptorDocument().getJobDescriptor().setPartition(partition); + } + + public void setUserName(String userName){ + this.getJobDescriptorDocument().getJobDescriptor().setUserName(userName); + } + public void setNodeList(String nodeList){ + this.getJobDescriptorDocument().getJobDescriptor().setNodeList(nodeList); + } + public void setJobSubmitter(String jobSubmitter){ + this.getJobDescriptorDocument().getJobDescriptor().setJobSubmitterCommand(jobSubmitter); + } + public String getNodeList(){ + return this.getJobDescriptorDocument().getJobDescriptor().getNodeList(); + } + public String getExecutablePath() { + return this.getJobDescriptorDocument().getJobDescriptor().getExecutablePath(); + } + + public boolean getAllEnvExport() { + return this.getJobDescriptorDocument().getJobDescriptor().getAllEnvExport(); + } + + public String getMailOptions() { + return this.getJobDescriptorDocument().getJobDescriptor().getMailOptions(); + } + + public String getStandardOutFile() { + return this.getJobDescriptorDocument().getJobDescriptor().getStandardOutFile(); + } + + public String getStandardErrorFile() { + return this.getJobDescriptorDocument().getJobDescriptor().getStandardErrorFile(); + } + + public int getNodes(int name) { + return this.getJobDescriptorDocument().getJobDescriptor().getNodes(); + } + + public int getCPUCount(int name) { + return this.getJobDescriptorDocument().getJobDescriptor().getCpuCount(); + } + + public int getProcessesPerNode() { + return this.getJobDescriptorDocument().getJobDescriptor().getProcessesPerNode(); + } + + public String getMaxWallTime() { + return this.getJobDescriptorDocument().getJobDescriptor().getMaxWallTime(); + } + + public String getAcountString() { + return this.getJobDescriptorDocument().getJobDescriptor().getAcountString(); + } + + public String[] getInputValues() { + return this.getJobDescriptorDocument().getJobDescriptor().getInputs().getInputArray(); + } + + public String getJobID() { + return this.getJobDescriptorDocument().getJobDescriptor().getJobID(); + } + + public String getQueueName() { + return this.getJobDescriptorDocument().getJobDescriptor().getQueueName(); + } + + public String getStatus() { + return this.getJobDescriptorDocument().getJobDescriptor().getStatus(); + } + + public String[] getAfterAnyList() { + return this.getJobDescriptorDocument().getJobDescriptor().getAfterAny().getAfterAnyArray(); + } + + public String[] getAfterOKList() { + return this.getJobDescriptorDocument().getJobDescriptor().getAfterOKList().getAfterOKListArray(); + } + public String getCTime() { + return this.getJobDescriptorDocument().getJobDescriptor().getCTime(); + } + public String getQTime() { + return this.getJobDescriptorDocument().getJobDescriptor().getQTime(); + } + public String getMTime() { + return this.getJobDescriptorDocument().getJobDescriptor().getMTime(); + } + public String getSTime() { + return this.getJobDescriptorDocument().getJobDescriptor().getSTime(); + } + public String getCompTime() { + return this.getJobDescriptorDocument().getJobDescriptor().getCompTime(); + } + public String getOwner() { + return this.getJobDescriptorDocument().getJobDescriptor().getOwner(); + } + public String getExecuteNode() { + return this.getJobDescriptorDocument().getJobDescriptor().getExecuteNode(); + } + public String getEllapsedTime() { + return this.getJobDescriptorDocument().getJobDescriptor().getEllapsedTime(); + } + + public String getUsedCPUTime() { + return this.getJobDescriptorDocument().getJobDescriptor().getUsedCPUTime(); + } + + public String getUsedMemory() { + return this.getJobDescriptorDocument().getJobDescriptor().getUsedMem(); + } + public void getShellName() { + this.getJobDescriptorDocument().getJobDescriptor().getShellName(); + } + + public String getJobName() { + return this.getJobDescriptorDocument().getJobDescriptor().getJobName(); + } + + public String getJobId() { + return this.getJobDescriptorDocument().getJobDescriptor().getJobID(); + } + + + public String getVariableList() { + return this.getJobDescriptorDocument().getJobDescriptor().getJobID(); + } + public String getSubmitArgs() { + return this.getJobDescriptorDocument().getJobDescriptor().getJobID(); + } + + public String[] getPostJobCommands(){ + if(this.getJobDescriptorDocument().getJobDescriptor().getPostJobCommands() != null) { + return this.getJobDescriptorDocument().getJobDescriptor().getPostJobCommands().getCommandArray(); + } + return null; + } + + public String[] getModuleCommands() { + if (this.getJobDescriptorDocument().getJobDescriptor().getModuleLoadCommands() != null) { + return this.getJobDescriptorDocument().getJobDescriptor().getModuleLoadCommands().getCommandArray(); + } + return null; + } + + public String[] getPreJobCommands(){ + if(this.getJobDescriptorDocument().getJobDescriptor().getPreJobCommands() != null) { + return this.getJobDescriptorDocument().getJobDescriptor().getPreJobCommands().getCommandArray(); + } + return null; + } + + public String getJobSubmitterCommand(){ + return this.getJobDescriptorDocument().getJobDescriptor().getJobSubmitterCommand(); + } + + public String getPartition(){ + return this.getJobDescriptorDocument().getJobDescriptor().getPartition(); + } + + public String getUserName(){ + return this.getJobDescriptorDocument().getJobDescriptor().getUserName(); + } + + public void setCallBackIp(String ip){ + this.jobDescriptionDocument.getJobDescriptor().setCallBackIp(ip); + } + + public void setCallBackPort(String ip){ + this.jobDescriptionDocument.getJobDescriptor().setCallBackPort(ip); + } + + + public String getCallBackIp(){ + return this.jobDescriptionDocument.getJobDescriptor().getCallBackIp(); + } + public String getCallBackPort(){ + return this.jobDescriptionDocument.getJobDescriptor().getCallBackPort(); + } + + public void setMailType(String emailType) { + this.getJobDescriptorDocument().getJobDescriptor().setMailType(emailType); + } + + public String getMailType() { + return this.getJobDescriptorDocument().getJobDescriptor().getMailType(); + } + public void setMailAddress(String emailAddress) { + this.getJobDescriptorDocument().getJobDescriptor().setMailAddress(emailAddress); + } + + public String getMailAddress() { + return this.getJobDescriptorDocument().getJobDescriptor().getMailAddress(); + } + + public String getChassisName() { + return this.getJobDescriptorDocument().getJobDescriptor().getChassisName(); + } + + public void setChassisName(String chassisName){ + this.getJobDescriptorDocument().getJobDescriptor().setChassisName(chassisName); + } + + +} + http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobManagerConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobManagerConfiguration.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobManagerConfiguration.java new file mode 100644 index 0000000..d58a994 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobManagerConfiguration.java @@ -0,0 +1,51 @@ +/* + * + * 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.ssh.api.job; + +import org.apache.airavata.gfac.ssh.impl.RawCommandInfo; + +public interface JobManagerConfiguration { + + public RawCommandInfo getCancelCommand(String jobID); + + public String getJobDescriptionTemplateName(); + + public RawCommandInfo getMonitorCommand(String jobID); + + public RawCommandInfo getUserBasedMonitorCommand(String userName); + + public RawCommandInfo getJobIdMonitorCommand(String jobName , String userName); + + public String getScriptExtension(); + + public RawCommandInfo getSubmitCommand(String workingDirectory, String pbsFilePath); + + public OutputParser getParser(); + + public String getInstalledPath(); + + public String getBaseCancelCommand(); + + public String getBaseMonitorCommand(); + + public String getBaseSubmitCommand(); + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobType.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobType.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobType.java new file mode 100644 index 0000000..556f4ef --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/JobType.java @@ -0,0 +1,32 @@ +/* + * + * 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.ssh.api.job; + +/** + * Created by IntelliJ IDEA. + * User: lahirugunathilake + * Date: 8/22/13 + * Time: 7:19 AM + * To change this template use File | Settings | File Templates. + */ +public enum JobType { + SERIAL, SINGLE, MPI, MULTIPLE, CONDOR +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/LSFJobConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/LSFJobConfiguration.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/LSFJobConfiguration.java new file mode 100644 index 0000000..f9c7f33 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/LSFJobConfiguration.java @@ -0,0 +1,121 @@ +/* + * + * 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.ssh.api.job; + +import org.apache.airavata.gfac.ssh.impl.RawCommandInfo; +import org.apache.commons.io.FilenameUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; + +public class LSFJobConfiguration implements JobManagerConfiguration { + private final static Logger logger = LoggerFactory.getLogger(LSFJobConfiguration.class); + + private String jobDescriptionTemplateName; + + private String scriptExtension; + + private String installedPath; + + private OutputParser parser; + + public LSFJobConfiguration(){ + // this can be used to construct and use setter methods to set all the params in order + } + public LSFJobConfiguration(String jobDescriptionTemplateName, + String scriptExtension,String installedPath,OutputParser parser) { + this.jobDescriptionTemplateName = jobDescriptionTemplateName; + this.scriptExtension = scriptExtension; + this.parser = parser; + if (installedPath.endsWith("/") || installedPath.isEmpty()) { + this.installedPath = installedPath; + } else { + this.installedPath = installedPath + "/"; + } + } + + @Override + public RawCommandInfo getCancelCommand(String jobID) { + return new RawCommandInfo(this.installedPath + "bkill " + jobID); + } + + @Override + public String getJobDescriptionTemplateName() { + return jobDescriptionTemplateName; + } + + @Override + public RawCommandInfo getMonitorCommand(String jobID) { + return new RawCommandInfo(this.installedPath + "bjobs " + jobID); + } + + @Override + public RawCommandInfo getUserBasedMonitorCommand(String userName) { + return new RawCommandInfo(this.installedPath + "bjobs -u " + userName); + } + + @Override + public RawCommandInfo getJobIdMonitorCommand(String jobName, String userName) { + return new RawCommandInfo(this.installedPath + "bjobs -J " + jobName); + } + + @Override + public String getScriptExtension() { + return scriptExtension; + } + + @Override + public RawCommandInfo getSubmitCommand(String workingDirectory, String pbsFilePath) { + return new RawCommandInfo(this.installedPath + "bsub < " + + workingDirectory + File.separator + FilenameUtils.getName(pbsFilePath)); + } + + @Override + public OutputParser getParser() { + return parser; + } + + public void setParser(OutputParser parser) { + this.parser = parser; + } + + @Override + public String getInstalledPath() { + return installedPath; + } + + + @Override + public String getBaseCancelCommand() { + return "bkill"; + } + + @Override + public String getBaseMonitorCommand() { + return "bjobs"; + } + + @Override + public String getBaseSubmitCommand() { + return "bsub"; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/LSFOutputParser.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/LSFOutputParser.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/LSFOutputParser.java new file mode 100644 index 0000000..c6dea17 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/LSFOutputParser.java @@ -0,0 +1,130 @@ +/* + * + * 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.ssh.api.job; + +import org.apache.airavata.gfac.ssh.api.SSHApiException; +import org.apache.airavata.gfac.ssh.impl.JobStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class LSFOutputParser implements OutputParser { + private final static Logger logger = LoggerFactory.getLogger(LSFOutputParser.class); + + @Override + public void parseSingleJob(JobDescriptor jobDescriptor, String rawOutput) throws SSHApiException { + logger.debug(rawOutput); + //todo we need to implement this but we are not using it airavata runtime + // if someone is using the gsissh as a tool this will be useful to get a descriptive information about a single job + } + + @Override + public String parseJobSubmission(String rawOutput) throws SSHApiException { + logger.debug(rawOutput); + return rawOutput.substring(rawOutput.indexOf("<")+1,rawOutput.indexOf(">")); + } + + @Override + public JobStatus parseJobStatus(String jobID, String rawOutput) throws SSHApiException { + boolean jobFount = false; + logger.debug(rawOutput); + //todo this is not used anymore + return JobStatus.C; + } + + @Override + public void parseJobStatuses(String userName, Map<String, JobStatus> statusMap, String rawOutput) throws SSHApiException { + logger.debug(rawOutput); + + String[] info = rawOutput.split("\n"); +// int lastStop = 0; + for (String jobID : statusMap.keySet()) { + String jobName = jobID.split(",")[1]; + boolean found = false; + for (int i = 0; i < info.length; i++) { + if (info[i].contains(jobName.substring(0,8))) { + // now starts processing this line + logger.info(info[i]); + String correctLine = info[i]; + String[] columns = correctLine.split(" "); + List<String> columnList = new ArrayList<String>(); + for (String s : columns) { + if (!"".equals(s)) { + columnList.add(s); + } + } +// lastStop = i + 1; + try { + statusMap.put(jobID, JobStatus.valueOf(columnList.get(2))); + }catch(IndexOutOfBoundsException e){ + statusMap.put(jobID, JobStatus.valueOf("U")); + } + found = true; + break; + } + } + if(!found) + logger.error("Couldn't find the status of the Job with JobName: " + jobName + "Job Id: " + jobID.split(",")[0]); + } + } + + @Override + public String parseJobId(String jobName, String rawOutput) throws SSHApiException { + String regJobId = "jobId"; + Pattern pattern = Pattern.compile("(?=(?<" + regJobId + ">\\d+)\\s+\\w+\\s+" + jobName + ")"); // regex - look ahead and match + if (rawOutput != null) { + Matcher matcher = pattern.matcher(rawOutput); + if (matcher.find()) { + return matcher.group(regJobId); + } else { + logger.error("No match is found for JobName"); + return null; + } + } else { + logger.error("Error: RawOutput shouldn't be null"); + return null; + } + } + + public static void main(String[] args) { + String test = "Job <2477982> is submitted to queue <short>."; + System.out.println(test.substring(test.indexOf("<")+1, test.indexOf(">"))); + String test1 = "JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME SUBMIT_TIME\n" + + "2636607 lg11w RUN long ghpcc06 c11b02 *069656647 Mar 7 00:58\n" + + "2636582 lg11w RUN long ghpcc06 c02b01 2134490944 Mar 7 00:48"; + Map<String, JobStatus> statusMap = new HashMap<String, JobStatus>(); + statusMap.put("2477983,2134490944", JobStatus.U); + LSFOutputParser lsfOutputParser = new LSFOutputParser(); + try { + lsfOutputParser.parseJobStatuses("cjh", statusMap, test1); + } catch (SSHApiException e) { + logger.error(e.getMessage(), e); + } + System.out.println(statusMap.get("2477983,2134490944")); + + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/OutputParser.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/OutputParser.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/OutputParser.java new file mode 100644 index 0000000..9730c33 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/OutputParser.java @@ -0,0 +1,67 @@ +/* + * + * 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.ssh.api.job; + +import org.apache.airavata.gfac.ssh.api.SSHApiException; +import org.apache.airavata.gfac.ssh.impl.JobStatus; + +import java.util.Map; + +public interface OutputParser { + + /** + * Tihs can be used to fill a jobdescriptor based on the output + * @param descriptor + * @return + */ + public void parseSingleJob(JobDescriptor descriptor, String rawOutput)throws SSHApiException; + + /** + * This can be used to parseSingleJob the result of a job submission to get the JobID + * @param rawOutput + * @return + */ + public String parseJobSubmission(String rawOutput)throws SSHApiException; + + + /** + * This can be used to get the job status from the output + * @param jobID + * @param rawOutput + */ + public JobStatus parseJobStatus(String jobID, String rawOutput)throws SSHApiException; + + /** + * This can be used to parseSingleJob a big output and get multipleJob statuses + * @param statusMap list of status map will return and key will be the job ID + * @param rawOutput + */ + public void parseJobStatuses(String userName, Map<String, JobStatus> statusMap, String rawOutput)throws SSHApiException; + + /** + * filter the jobId value of given JobName from rawOutput + * @param jobName + * @param rawOutput + * @return + * @throws SSHApiException + */ + public String parseJobId(String jobName, String rawOutput) throws SSHApiException; +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/PBSJobConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/PBSJobConfiguration.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/PBSJobConfiguration.java new file mode 100644 index 0000000..0179e01 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/PBSJobConfiguration.java @@ -0,0 +1,119 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ +package org.apache.airavata.gfac.ssh.api.job; + +import org.apache.airavata.gfac.ssh.impl.RawCommandInfo; +import org.apache.commons.io.FilenameUtils; + +import java.io.File; + +public class PBSJobConfiguration implements JobManagerConfiguration { + + private String jobDescriptionTemplateName; + + private String scriptExtension; + + private String installedPath; + + private OutputParser parser; + + public PBSJobConfiguration() { + // this can be used to construct and use setter methods to set all the params in order + } + + public PBSJobConfiguration(String jobDescriptionTemplateName, + String scriptExtension, String installedPath, OutputParser parser) { + this.jobDescriptionTemplateName = jobDescriptionTemplateName; + this.scriptExtension = scriptExtension; + this.parser = parser; + if (installedPath.endsWith("/")) { + this.installedPath = installedPath; + } else { + this.installedPath = installedPath + "/"; + } + } + + public RawCommandInfo getCancelCommand(String jobID) { + return new RawCommandInfo(this.installedPath + "qdel " + jobID); + } + + public String getJobDescriptionTemplateName() { + return jobDescriptionTemplateName; + } + + public void setJobDescriptionTemplateName(String jobDescriptionTemplateName) { + this.jobDescriptionTemplateName = jobDescriptionTemplateName; + } + + public RawCommandInfo getMonitorCommand(String jobID) { + return new RawCommandInfo(this.installedPath + "qstat -f " + jobID); + } + + public String getScriptExtension() { + return scriptExtension; + } + + public RawCommandInfo getSubmitCommand(String workingDirectory, String pbsFilePath) { + return new RawCommandInfo(this.installedPath + "qsub " + + workingDirectory + File.separator + FilenameUtils.getName(pbsFilePath)); + } + + public String getInstalledPath() { + return installedPath; + } + + public void setInstalledPath(String installedPath) { + this.installedPath = installedPath; + } + + public OutputParser getParser() { + return parser; + } + + public void setParser(OutputParser parser) { + this.parser = parser; + } + + public RawCommandInfo getUserBasedMonitorCommand(String userName) { + return new RawCommandInfo(this.installedPath + "qstat -u " + userName); + } + + @Override + public RawCommandInfo getJobIdMonitorCommand(String jobName, String userName) { + // For PBS there is no option to get jobDetails by JobName, so we search with userName + return new RawCommandInfo(this.installedPath + "qstat -u " + userName); + } + + @Override + public String getBaseCancelCommand() { + return "qdel"; + } + + @Override + public String getBaseMonitorCommand() { + return "qstat"; + } + + @Override + public String getBaseSubmitCommand() { + return "qsub "; + } +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/PBSOutputParser.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/PBSOutputParser.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/PBSOutputParser.java new file mode 100644 index 0000000..2f17787 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/PBSOutputParser.java @@ -0,0 +1,212 @@ +/* + * + * 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.ssh.api.job; + +import org.apache.airavata.gfac.ssh.api.SSHApiException; +import org.apache.airavata.gfac.ssh.impl.JobStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class PBSOutputParser implements OutputParser { + private static final Logger log = LoggerFactory.getLogger(PBSOutputParser.class); + + public void parseSingleJob(JobDescriptor jobDescriptor, String rawOutput) { + log.debug(rawOutput); + String[] info = rawOutput.split("\n"); + String[] line; + for (int i = 0; i < info.length; i++) { + if (info[i].contains("=")) { + line = info[i].split("=", 2); + } else { + line = info[i].split(":", 2); + } + if (line.length >= 2) { + String header = line[0].trim(); + log.debug("Header = " + header); + String value = line[1].trim(); + log.debug("value = " + value); + + if (header.equals("Variable_List")) { + while (info[i + 1].startsWith("\t")) { + value += info[i + 1]; + i++; + } + value = value.replaceAll("\t", ""); + jobDescriptor.setVariableList(value); + } else if ("Job Id".equals(header)) { + jobDescriptor.setJobID(value); + } else if ("Job_Name".equals(header)) { + jobDescriptor.setJobName(value); + } else if ("Account_Name".equals(header)) { + jobDescriptor.setAcountString(value); + } else if ("job_state".equals(header)) { + jobDescriptor.setStatus(value); + } else if ("Job_Owner".equals(header)) { + jobDescriptor.setOwner(value); + } else if ("resources_used.cput".equals(header)) { + jobDescriptor.setUsedCPUTime(value); + } else if ("resources_used.mem".equals(header)) { + jobDescriptor.setUsedMemory(value); + } else if ("resources_used.walltime".equals(header)) { + jobDescriptor.setEllapsedTime(value); + } else if ("job_state".equals(header)) { + jobDescriptor.setStatus(value); + } else if ("queue".equals(header)) + jobDescriptor.setQueueName(value); + else if ("ctime".equals(header)) { + jobDescriptor.setCTime(value); + } else if ("qtime".equals(header)) { + jobDescriptor.setQTime(value); + } else if ("mtime".equals(header)) { + jobDescriptor.setMTime(value); + } else if ("start_time".equals(header)) { + jobDescriptor.setSTime(value); + } else if ("comp_time".equals(header)) { + jobDescriptor.setCompTime(value); + } else if ("exec_host".equals(header)) { + jobDescriptor.setExecuteNode(value); + } else if ("Output_Path".equals(header)) { + if (info[i + 1].contains("=") || info[i + 1].contains(":")) + jobDescriptor.setStandardOutFile(value); + else { + jobDescriptor.setStandardOutFile(value + info[i + 1].trim()); + i++; + } + } else if ("Error_Path".equals(header)) { + if (info[i + 1].contains("=") || info[i + 1].contains(":")) + jobDescriptor.setStandardErrorFile(value); + else { + String st = info[i + 1].trim(); + jobDescriptor.setStandardErrorFile(value + st); + i++; + } + + } else if ("submit_args".equals(header)) { + while (i + 1 < info.length) { + if (info[i + 1].startsWith("\t")) { + value += info[i + 1]; + i++; + } else + break; + } + value = value.replaceAll("\t", ""); + jobDescriptor.setSubmitArgs(value); + } + } + } + } + + public String parseJobSubmission(String rawOutput) { + log.debug(rawOutput); + return rawOutput; //In PBS stdout is going to be directly the jobID + } + + public JobStatus parseJobStatus(String jobID, String rawOutput) { + boolean jobFount = false; + log.debug(rawOutput); + String[] info = rawOutput.split("\n"); + String[] line = null; + int index = 0; + for (String anInfo : info) { + index++; + if (anInfo.contains("Job Id:")) { + if (anInfo.contains(jobID)) { + jobFount = true; + break; + } + } + } + if (jobFount) { + for (int i=index;i<info.length;i++) { + String anInfo = info[i]; + if (anInfo.contains("=")) { + line = anInfo.split("=", 2); + if (line.length != 0) { + if (line[0].contains("job_state")) { + return JobStatus.valueOf(line[1].replaceAll(" ", "")); + } + } + } + } + } + return null; + } + + public void parseJobStatuses(String userName, Map<String, JobStatus> statusMap, String rawOutput) { + log.debug(rawOutput); + String[] info = rawOutput.split("\n"); +// int lastStop = 0; + for (String jobID : statusMap.keySet()) { + String jobName = jobID.split(",")[1]; + boolean found = false; + for (int i = 0; i < info.length; i++) { + if (info[i].contains(jobName.substring(0,8))) { + // now starts processing this line + log.info(info[i]); + String correctLine = info[i]; + String[] columns = correctLine.split(" "); + List<String> columnList = new ArrayList<String>(); + for (String s : columns) { + if (!"".equals(s)) { + columnList.add(s); + } + } +// lastStop = i + 1; + try { + statusMap.put(jobID, JobStatus.valueOf(columnList.get(9))); + }catch(IndexOutOfBoundsException e){ + statusMap.put(jobID, JobStatus.valueOf("U")); + } + found = true; + break; + } + } + if(!found) + log.error("Couldn't find the status of the Job with JobName: " + jobName + "Job Id: " + jobID.split(",")[0]); + } + } + + @Override + public String parseJobId(String jobName, String rawOutput) throws SSHApiException { + String regJobId = "jobId"; + Pattern pattern = Pattern.compile("\\s*(?<" + regJobId + ">[^\\s]*).* " + jobName + " "); // regex , JOB_ID will come as first column + if (rawOutput != null) { + Matcher matcher = pattern.matcher(rawOutput); + if (matcher.find()) { + return matcher.group(regJobId); + } else { + log.error("No match is found for JobName"); + return null; + } + } else { + log.error("Error: RawOutput shouldn't be null"); + return null; + } + } + + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/SlurmJobConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/SlurmJobConfiguration.java b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/SlurmJobConfiguration.java new file mode 100644 index 0000000..54d8f40 --- /dev/null +++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/gsi/ssh/api/job/SlurmJobConfiguration.java @@ -0,0 +1,117 @@ +/* + * + * 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.ssh.api.job; + +import org.apache.airavata.gfac.ssh.impl.RawCommandInfo; +import org.apache.commons.io.FilenameUtils; + +import java.io.File; + +public class SlurmJobConfiguration implements JobManagerConfiguration{ + + private String jobDescriptionTemplateName; + + private String scriptExtension; + + private String installedPath; + + private OutputParser parser; + + public SlurmJobConfiguration(){ + // this can be used to construct and use setter methods to set all the params in order + } + public SlurmJobConfiguration(String jobDescriptionTemplateName, + String scriptExtension,String installedPath,OutputParser parser) { + this.jobDescriptionTemplateName = jobDescriptionTemplateName; + this.scriptExtension = scriptExtension; + this.parser = parser; + if (installedPath.endsWith("/")) { + this.installedPath = installedPath; + } else { + this.installedPath = installedPath + "/"; + } + } + + public RawCommandInfo getCancelCommand(String jobID) { + return new RawCommandInfo(this.installedPath + "scancel " + jobID); + } + + public String getJobDescriptionTemplateName() { + return jobDescriptionTemplateName; + } + + public void setJobDescriptionTemplateName(String jobDescriptionTemplateName) { + this.jobDescriptionTemplateName = jobDescriptionTemplateName; + } + + public RawCommandInfo getMonitorCommand(String jobID) { + return new RawCommandInfo(this.installedPath + "squeue -j " + jobID); + } + + public String getScriptExtension() { + return scriptExtension; + } + + public RawCommandInfo getSubmitCommand(String workingDirectory,String pbsFilePath) { + return new RawCommandInfo(this.installedPath + "sbatch " + + workingDirectory + File.separator + FilenameUtils.getName(pbsFilePath)); + } + + public String getInstalledPath() { + return installedPath; + } + + public void setInstalledPath(String installedPath) { + this.installedPath = installedPath; + } + + public OutputParser getParser() { + return parser; + } + + public void setParser(OutputParser parser) { + this.parser = parser; + } + + public RawCommandInfo getUserBasedMonitorCommand(String userName) { + return new RawCommandInfo(this.installedPath + "squeue -u " + userName); + } + + @Override + public RawCommandInfo getJobIdMonitorCommand(String jobName, String userName) { + return new RawCommandInfo(this.installedPath + "squeue -n " + jobName + " -u " + userName); + } + + @Override + public String getBaseCancelCommand() { + return "scancel"; + } + + @Override + public String getBaseMonitorCommand() { + return "squeue"; + } + + @Override + public String getBaseSubmitCommand() { + return "sbatch"; + } +}
