1 31 package org.objectweb.proactive.core.process.globus; 32 33 import org.apache.log4j.Logger; 34 import org.globus.gram.*; 35 36 import org.globus.io.gass.server.*; 37 38 40 import org.globus.util.deactivator.Deactivator; 41 42 import org.gridforum.jgss.ExtendedGSSManager; 43 44 import org.ietf.jgss.GSSCredential ; 45 46 47 50 public class GridJob implements GramJobListener{ 51 static Logger logger = Logger.getLogger(GridJob.class.getName()); 52 private GassServer m_gassServer; private String m_gassURL = null; private GramJob m_job = null; private String m_jobOutput = ""; private boolean m_batch = false; private String m_remoteHost = null; private String m_jobid = null; int options = 62 org.globus.io.gass.server.GassServer.READ_ENABLE | 63 org.globus.io.gass.server.GassServer.WRITE_ENABLE | 64 org.globus.io.gass.server.GassServer.STDOUT_ENABLE | 65 org.globus.io.gass.server.GassServer.STDERR_ENABLE; 66 67 public GridJob(String Contact, boolean batch) { 69 m_remoteHost = Contact; m_batch = batch; } 72 73 public String GlobusRun(String RSL) { 74 try { 75 ExtendedGSSManager manager = (ExtendedGSSManager) ExtendedGSSManager.getInstance(); 78 GSSCredential cred = manager.createCredential(GSSCredential.INITIATE_AND_ACCEPT); 79 if (cred == null){ 80 logger.error("credential null"); 81 } 82 83 if (!startGassServer(cred)) { 85 throw new Exception ("Unable to start GASS server."); 86 } 87 88 initJobOutListeners(); 90 91 String newRSL = null; 93 94 109 newRSL = "&" + RSL.substring(0, RSL.indexOf('&')) + 110 "(rsl_substitution=(GLOBUSRUN_GASS_URL " + m_gassURL + 111 "))" + RSL.substring(RSL.indexOf('&') + 1, RSL.length())+ 112 "(stdout=$(GLOBUSRUN_GASS_URL)/dev/stdout-5)(stderr=$(GLOBUSRUN_GASS_URL)/dev/sterr-5)"; 113 115 116 Gram.ping(m_remoteHost); 117 System.out.println("ping successfull"); 118 System.out.println(newRSL); 119 m_job = new GramJob(newRSL); 120 121 m_job.setCredentials(cred); 124 125 m_job.addListener(this); 129 131 System.out.println("Sending job request to: " + m_remoteHost); 132 m_job.request(m_remoteHost, m_batch, false); 133 134 m_jobOutput = "Job sent. url=" + m_job.getIDAsString(); 146 } catch (Exception ex) { 148 if (m_gassServer != null) { 149 m_gassServer.unregisterJobOutputStream("err-5"); 151 m_gassServer.unregisterJobOutputStream("out-5"); 152 } 153 154 m_jobOutput = "Error submitting job: " + ex.getClass() + ":" + 155 ex.getMessage(); 156 ex.printStackTrace(); 157 } 158 159 Deactivator.deactivateAll(); 161 return m_jobOutput; 162 } 163 164 168 private boolean startGassServer(GSSCredential cred) { 169 if (m_gassServer != null) { 170 return true; 171 } 172 173 try { 174 m_gassServer = new GassServer(cred, 0); 175 m_gassServer.setOptions(options); 176 m_gassURL = m_gassServer.getURL(); 177 System.out.println("gass server started succesfully "+m_gassURL); 178 } catch (Exception e) { 179 System.err.println("gass server failed to start!"); 180 e.printStackTrace(); 181 182 return false; 183 } 184 185 m_gassServer.registerDefaultDeactivator(); 186 187 return true; 188 } 189 190 193 private void initJobOutListeners() throws Exception { 194 JobOutputListenerImpl outListener = new JobOutputListenerImpl(); 196 JobOutputStream outStream = new JobOutputStream(outListener); 197 m_gassServer.registerJobOutputStream("out-5", outStream); 198 m_gassServer.registerJobOutputStream("err-5", outStream); 199 } 200 201 public void statusChanged(GramJob job) { 202 String status = job.getStatusAsString(); 203 System.out.println("status changed "+status); 204 205 try { 206 if (job.getStatus() == GramJob.STATUS_ACTIVE) { 207 m_jobOutput = "Job sent. url=" + job.getIDAsString(); 209 logger.info(m_jobOutput); 210 211 } 216 } catch (Exception ex) { 217 System.out.println("statusChanged Error:" + ex.getMessage()); 218 ex.printStackTrace(); 219 } 220 } 221 222 223 private class JobOutputListenerImpl implements JobOutputListener { 224 public void outputClosed() { 225 System.out.println("output closed"); 226 } 227 228 public void outputChanged(String output) { 229 m_jobOutput += output; 230 System.out.println("output changed: "+m_jobOutput); 231 } 232 } 233 } 234 | Popular Tags |