00001 /* 00002 * ################################################################ 00003 * 00004 * ProActive: The Java(TM) library for Parallel, Distributed, 00005 * Concurrent computing with Security and Mobility 00006 * 00007 * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis 00008 * Contact: proactive@objectweb.org 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 * USA 00024 * 00025 * Initial developer(s): The ProActive Team 00026 * http://www.inria.fr/oasis/ProActive/contacts.html 00027 * Contributor(s): 00028 * 00029 * ################################################################ 00030 */ 00031 package org.objectweb.proactive.core.process.ssh; 00032 00033 import org.objectweb.proactive.core.process.AbstractExternalProcessDecorator; 00034 import org.objectweb.proactive.core.process.ExternalProcess; 00035 import org.objectweb.proactive.core.process.SimpleExternalProcess; 00036 import org.objectweb.proactive.core.process.UniversalProcess; 00037 00038 00056 public class SSHProcess extends AbstractExternalProcessDecorator { 00057 public final static String DEFAULT_SSHPATH = "ssh"; 00058 public final static String DEFAULT_SSH_COPYPROTOCOL = "scp"; 00059 00060 // 00061 // -- CONSTRUCTORS ----------------------------------------------- 00062 // 00063 00068 public SSHProcess() { 00069 super(); 00070 00071 FILE_TRANSFER_DEFAULT_PROTOCOL = DEFAULT_SSH_COPYPROTOCOL; 00072 this.command_path = DEFAULT_SSHPATH; 00073 } 00074 00080 public SSHProcess(ExternalProcess targetProcess) { 00081 super(targetProcess); 00082 00083 FILE_TRANSFER_DEFAULT_PROTOCOL = DEFAULT_SSH_COPYPROTOCOL; 00084 this.command_path = DEFAULT_SSHPATH; 00085 } 00086 00087 // 00088 // -- PUBLIC METHODS ----------------------------------------------- 00089 // 00090 00094 public String getProcessId() { 00095 return "ssh_" + targetProcess.getProcessId(); 00096 } 00097 00101 public int getNodeNumber() { 00102 return targetProcess.getNodeNumber(); 00103 } 00104 00108 public UniversalProcess getFinalProcess() { 00109 checkStarted(); 00110 return targetProcess.getFinalProcess(); 00111 } 00112 00113 public static void main(String[] args) { 00114 try { 00115 SSHProcess ssh = new SSHProcess(new SimpleExternalProcess("ls -lsa")); 00116 ssh.setHostname("galere1.inria.fr"); 00117 ssh.startProcess(); 00118 } catch (Exception e) { 00119 e.printStackTrace(); 00120 } 00121 } 00122 00123 // 00124 // -- PROTECTED METHODS ----------------------------------------------- 00125 // 00126 protected String internalBuildCommand() { 00127 return buildSSHCommand() + buildEnvironmentCommand(); 00128 } 00129 00130 protected String buildSSHCommand() { 00131 StringBuilder command = new StringBuilder(); 00132 command.append(command_path); 00133 // append username 00134 if (username != null) { 00135 command.append(" -l "); 00136 command.append(username); 00137 } 00138 00139 // append host 00140 command.append(" "); 00141 command.append(hostname); 00142 command.append(" "); 00143 if (logger.isDebugEnabled()) { 00144 logger.debug(command.toString()); 00145 } 00146 return command.toString(); 00147 } 00148 00149 // 00150 // -- PRIVATE METHODS ----------------------------------------------- 00151 // 00152 }