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.unicore; 00032 00033 import org.apache.log4j.Logger; 00034 import org.objectweb.proactive.core.process.AbstractExternalProcessDecorator; 00035 import org.objectweb.proactive.core.process.ExternalProcess; 00036 import org.objectweb.proactive.core.process.UniversalProcess; 00037 import org.objectweb.proactive.core.process.filetransfer.FileTransferDefinition; 00038 import org.objectweb.proactive.core.process.filetransfer.FileTransferDefinition.FileDescription; 00039 import org.objectweb.proactive.core.process.filetransfer.FileTransferWorkShop; 00040 import org.objectweb.proactive.core.util.log.Loggers; 00041 import org.objectweb.proactive.core.util.log.ProActiveLogger; 00042 00043 00051 public class UnicoreProcess extends AbstractExternalProcessDecorator { 00052 public UnicoreParameters uParam; 00053 00054 public UnicoreProcess() { 00055 super(); 00056 setCompositionType(GIVE_COMMAND_AS_PARAMETER); 00057 00058 FILE_TRANSFER_DEFAULT_PROTOCOL = "unicore"; 00059 //Create an UnicoreParameters instance 00060 uParam = new UnicoreParameters(); 00061 } 00062 00063 public UnicoreProcess(ExternalProcess targetProcess) { 00064 super(targetProcess); 00065 00066 FILE_TRANSFER_DEFAULT_PROTOCOL = "unicore"; 00067 uParam = new UnicoreParameters(); 00068 } 00069 00070 protected void internalStartProcess(String commandToExecute) 00071 throws java.io.IOException { 00072 if (logger.isDebugEnabled()) { 00073 logger.debug(commandToExecute); 00074 } 00075 00076 /* Depending on the system property UnicoreProActiveClient 00077 * can be forked or called directly. 00078 */ 00079 String forkclient = System.getProperty("proactive.unicore.forkclient"); 00080 00081 if (forkclient.equalsIgnoreCase("false")) { 00082 logger.debug("Not Forking UnicoreProActiveClient"); 00083 UnicoreProActiveClient uProClient; 00084 00085 //Build a UnicoreProActive client with this parameters 00086 uProClient = new UnicoreProActiveClient(uParam); 00087 00088 uProClient.build(); 00089 uProClient.saveJob(); 00090 uProClient.submitJob(); 00091 } else { 00092 logger.debug("Forking UnicoreProActiveClient"); 00093 try { 00094 externalProcess = Runtime.getRuntime().exec(command); 00095 java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader( 00096 externalProcess.getInputStream())); 00097 java.io.BufferedReader err = new java.io.BufferedReader(new java.io.InputStreamReader( 00098 externalProcess.getErrorStream())); 00099 java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.OutputStreamWriter( 00100 externalProcess.getOutputStream())); 00101 handleProcess(in, out, err); 00102 } catch (java.io.IOException e) { 00103 isFinished = true; 00104 //throw e; 00105 e.printStackTrace(); 00106 } 00107 } 00108 } 00109 00110 protected String internalBuildCommand() { 00111 uParam.setScriptContent(targetProcess.getCommand()); 00112 00113 //return command for parent to execute 00114 return uParam.getCommandString(); 00115 } 00116 00117 protected boolean internalFileTransferDefaultProtocol() { 00118 FileTransferWorkShop fts = getFileTransferWorkShopDeploy(); 00119 FileTransferDefinition[] ftDefinitions = fts.getAllFileTransferDefinitions(); 00120 00121 Logger fileTransferLogger = ProActiveLogger.getLogger(Loggers.DEPLOYMENT_FILETRANSFER); 00122 00123 for (int i = 0; i < ftDefinitions.length; i++) { 00124 //Files and Dirs 00125 FileDescription[] files = ftDefinitions[i].getAll(); 00126 for (int j = 0; j < files.length; j++) { 00127 String fullfilename = fts.getAbsoluteSrcPath(files[j]); 00128 00129 //Skipping non existant filenames 00130 if (!FileTransferWorkShop.isLocalReadable(fullfilename)) { 00131 if (fileTransferLogger.isDebugEnabled()) { 00132 fileTransferLogger.debug( 00133 "Skiping. Unreadable for FileTransfer:" + 00134 fullfilename); 00135 } 00136 continue; 00137 } 00138 00139 StringBuilder sb = new StringBuilder(); 00140 00141 sb.append(fullfilename); 00142 00143 if (files[j].isDir()) { 00144 sb.append(fts.srcInfoParams.getFileSeparator()); 00145 } 00146 00147 sb.append(","); 00148 00149 sb.append(fts.getAbsoluteDstPath(files[j])); 00150 00151 if (files[j].isDir()) { 00152 sb.append(fts.dstInfoParams.getFileSeparator()); 00153 } 00154 00155 if (files[j].isDir()) { 00156 uParam.addDeploymentDir(sb.toString()); 00157 } else { //isFile 00158 uParam.addDeploymentFile(sb.toString()); 00159 } 00160 00161 if (fileTransferLogger.isDebugEnabled()) { 00162 fileTransferLogger.debug("Unicore FileTransfer:" + 00163 sb.toString()); 00164 } 00165 } 00166 } 00167 00168 //Because FileTransfer will be submited with the process, 00169 //we return success so no other protocols will be tried. 00170 return true; 00171 } 00172 00173 public String getProcessId() { 00174 return "unicore_" + targetProcess.getProcessId(); 00175 } 00176 00177 public int getNodeNumber() { 00178 return uParam.getVsiteNodes() * uParam.getVsiteProcessors(); 00179 } 00180 00181 public UniversalProcess getFinalProcess() { 00182 checkStarted(); 00183 return targetProcess.getFinalProcess(); 00184 } 00185 00186 public String getFileTransferDefaultCopyProtocol() { 00187 return FILE_TRANSFER_DEFAULT_PROTOCOL; 00188 } 00189 }