00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.process.glite;
00032
00033 import javax.naming.directory.InvalidAttributeValueException;
00034
00035 import org.glite.wms.jdlj.*;
00036 import org.objectweb.proactive.ProActive;
00037 import org.objectweb.proactive.core.ProActiveException;
00038 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00039 import org.objectweb.proactive.core.process.AbstractExternalProcessDecorator;
00040 import org.objectweb.proactive.core.process.ExternalProcess;
00041 import org.objectweb.proactive.core.process.JVMProcess;
00042 import org.objectweb.proactive.core.process.UniversalProcess;
00043 import org.objectweb.proactive.core.process.filetransfer.FileDependant;
00044 import org.objectweb.proactive.core.process.filetransfer.FileTransferDefinition;
00045
00046 import java.util.LinkedList;
00047
00048
00060 public class GLiteProcess extends AbstractExternalProcessDecorator
00061 implements FileDependant {
00062
00066 private static final long serialVersionUID = 1L;
00067 private static final String FILE_SEPARATOR = System.getProperty(
00068 "file.separator");
00069 protected static final String DEFAULT_PROCESSOR_NUMBER = "1";
00070 protected static final String DEFAULT_COMMAND_PATH = "glite-job-submit";
00071 protected static final String DEFAULT_FILE_LOCATION = System.getProperty(
00072 "user.home") + FILE_SEPARATOR + "public" + FILE_SEPARATOR + "JDL";
00073 protected static final String DEFAULT_STDOUPUT = System.getProperty(
00074 "user.home") + FILE_SEPARATOR + "out.log";
00075 protected static final String DEFAULT_CONFIG_FILE = System.getProperty(
00076 "user.home") + FILE_SEPARATOR + "public" + FILE_SEPARATOR + "JDL" +
00077 FILE_SEPARATOR + "vo.conf";
00078 protected int jobID;
00079 protected String hostList;
00080 protected String processor = DEFAULT_PROCESSOR_NUMBER;
00081 protected String command_path = DEFAULT_COMMAND_PATH;
00082 protected String interactive = "false";
00083 protected String filePath = DEFAULT_FILE_LOCATION;
00084 protected String stdOutput = DEFAULT_STDOUPUT;
00085 protected String fileName = "job.jdl";
00086 protected String configFile = DEFAULT_CONFIG_FILE;
00087 protected String remoteFilePath = null;
00088 protected boolean confFileOption = false;
00089 protected boolean jdlRemote = false;
00090 protected String netServer;
00091 protected String logBook;
00092
00093 protected GLiteJobAd jad;
00094 protected int jobNodeNumber = 2;
00095 protected String jobType;
00096 protected String jobJobType;
00097 protected String jobExecutable;
00098 protected String jobStdOutput;
00099 protected String jobStdInput;
00100 protected String jobStdError;
00101 protected String jobOutput_se;
00102 protected String jobVO;
00103 protected String jobRetryCount;
00104 protected String jobMyProxyServer;
00105 protected String jobDataAccessProtocol;
00106 protected String jobStorageIndex;
00107 protected String jobEnvironment;
00108 protected String jobRequirements;
00109 protected String jobRank;
00110 protected String jobFuzzyRank;
00111 protected String jobArgument;
00112 protected LinkedList jobInputSB;
00113 protected LinkedList jobOutputSB;
00114
00119 public GLiteProcess() {
00120 super();
00121 setCompositionType(COPY_FILE_AND_APPEND_COMMAND);
00122 this.hostname = null;
00123 command_path = DEFAULT_COMMAND_PATH;
00124 jad = new GLiteJobAd();
00125 }
00126
00133 public GLiteProcess(ExternalProcess targetProcess) {
00134 super(targetProcess);
00135 setCompositionType(COPY_FILE_AND_APPEND_COMMAND);
00136 this.hostname = null;
00137 jad = new GLiteJobAd();
00138 }
00139
00140
00141 public static void main(String[] args) {
00142 ProActiveDescriptor pad;
00143 try {
00144 pad = ProActive.getProactiveDescriptor(args[0]);
00145 pad.activateMappings();
00146 } catch (ProActiveException e) {
00147 e.printStackTrace();
00148 }
00149 }
00150
00155 public void buildJdlFile() {
00156 StringBuffer gLiteCommand = new StringBuffer();
00157 String args;
00158 gLiteCommand.append(command_path);
00159 String initial_args = ((JVMProcess) getTargetProcess()).getCommand();
00160
00164 if (this.getJobType().equals("MPICH")) {
00165 args = this.getJobExecutable() + initial_args.substring(initial_args.indexOf("/bin/java") + "/bin/java".length());
00166
00167 this.setJobExecutable("gLiteStartRuntime.sh");
00168 } else {
00169 args = initial_args.substring(initial_args.indexOf("/bin/java") + "/bin/java".length());
00170 }
00171
00172 args = checkSyntax(args);
00173
00174 try {
00175
00176 if (this.getJobType().equals("job") && this.getJobJobType().equals("mpich") ) {
00177 this.jad.addAttribute(Jdl.TYPE, "job");
00178 this.jad.addAttribute(Jdl.JOBTYPE, Jdl.JOBTYPE_MPICH);
00179 this.jad.addAttribute(Jdl.NODENUMB, this.getJobNodeNumber());
00180
00181
00182 } else if (this.getJobType() != null) {
00183 this.jad.addAttribute(Jdl.TYPE, "job");
00184 }
00185
00186 if (this.getJobExecutable() != null)
00187 this.jad.addAttribute(Jdl.EXECUTABLE, this.getJobExecutable());
00188
00189 if (this.getJobStdOutput() != null)
00190 this.jad.addAttribute(Jdl.STDOUTPUT, this.getJobStdOutput());
00191
00192 if (this.getJobStdInput() != null)
00193 this.jad.addAttribute(Jdl.STDINPUT, this.getJobStdInput());
00194
00195 if (this.getJobStdError() != null)
00196 this.jad.addAttribute(Jdl.STDERROR, this.getJobStdError());
00197
00198 if (this.getJobOutput_se() != null)
00199 this.jad.addAttribute(Jdl.OUTPUT_SE, this.getJobOutput_se());
00200
00201 if (this.getJobVO() != null)
00202 this.jad.addAttribute(Jdl.VIRTUAL_ORGANISATION, this.getJobVO());
00203
00204 if (this.getJobRetryCount() != null)
00205 this.jad.addAttribute(Jdl.RETRYCOUNT, Integer.parseInt(getJobRetryCount()));
00206
00207 if (this.getJobMyProxyServer() != null)
00208 this.jad.addAttribute(Jdl.MYPROXY, this.getJobMyProxyServer());
00209
00210 if (this.getJobEnvironment() != null)
00211 this.jad.addAttribute(Jdl.ENVIRONMENT, this.getJobEnvironment());
00212
00213 if (this.getJobRequirements() != null)
00214 this.jad.setAttributeExpr(Jdl.REQUIREMENTS, this.getJobRequirements());
00215
00216 if (this.getJobRank() != null)
00217 this.jad.setAttributeExpr(Jdl.RANK, this.getJobRank());
00218
00219 if (this.getJobDataAccessProtocol() != null)
00220 this.jad.addAttribute(Jdl.DATA_ACCESS, this.getJobDataAccessProtocol());
00221
00222 if (this.getJobStorageIndex() != null)
00223 this.jad.addAttribute(Jdl.OD_STORAGE_ELEMENT, this.getJobStorageIndex());
00224
00225 if (this.getJobFuzzyRank() != null)
00226 this.jad.addAttribute(Jdl.FUZZY_RANK, this.getJobFuzzyRank());
00227
00228 if (this.jobInputSB != null && this.jobInputSB.size() > 0) {
00229 for (int i = 0; i < this.jobInputSB.size(); i++) {
00230 String entry = (String) jobInputSB.get(i);
00231 this.jad.addAttribute(Jdl.INPUTSB, entry);
00232 }
00233 }
00234 if (this.jobOutputSB != null && this.jobOutputSB.size() > 0) {
00235 for (int i = 0; i < this.jobOutputSB.size(); i++) {
00236 String entry = (String) jobOutputSB.get(i);
00237 this.jad.addAttribute(Jdl.OUTPUTSB, entry);
00238 }
00239 }
00240
00241 if (jad.hasAttribute(Jdl.ARGUMENTS)) {
00242 jad.delAttribute(Jdl.ARGUMENTS);
00243 }
00244 jad.setAttribute(Jdl.ARGUMENTS, args);
00245 jad.toFile(filePath + "/" + fileName);
00246
00247
00248
00249
00250 } catch (IllegalArgumentException e) {
00251 e.printStackTrace();
00252 } catch (InvalidAttributeValueException e) {
00253 e.printStackTrace();
00254 } catch (Exception e) {
00255 e.printStackTrace();
00256 }
00257 }
00258
00259 protected String internalBuildCommand() {
00260 return buildGLiteCommand();
00261 }
00262
00270 protected String buildGLiteCommand() {
00271 String path = filePath;
00272 buildJdlFile();
00273
00274 if (jdlRemote) {
00275 path = remoteFilePath;
00276 }
00277
00278 if (!confFileOption) {
00279 return DEFAULT_COMMAND_PATH + " " + path + FILE_SEPARATOR +
00280 fileName;
00281 }
00282
00283 return DEFAULT_COMMAND_PATH + " --config-vo " + configFile + " " +
00284 path + FILE_SEPARATOR + fileName;
00285 }
00286
00293 private String checkSyntax(String args) {
00294 String formatted_args = "";
00295 String[] splitted_args = args.split("\\s");
00296 for (int i = 0; i < splitted_args.length; i++) {
00297 if (!(splitted_args[i].indexOf("=") < 0)) {
00298 splitted_args[i] = "\"" + splitted_args[i] + "\"";
00299 }
00300 formatted_args = formatted_args + " " + splitted_args[i];
00301 }
00302 return formatted_args;
00303 }
00304
00311
00312
00313
00314 public String getProcessId() {
00315 return "glite_" + targetProcess.getProcessId();
00316 }
00317
00321 public int getNodeNumber() {
00322 return this.getJobNodeNumber();
00323 }
00324
00328 public String getProcessorNumber() {
00329 return processor;
00330 }
00331
00332 public UniversalProcess getFinalProcess() {
00333 checkStarted();
00334 return targetProcess.getFinalProcess();
00335 }
00336
00340 public String getFileName() {
00341 return fileName;
00342 }
00343
00347 public void setFileName(String fileName) {
00348 this.fileName = fileName;
00349 }
00350
00354 public String getFilePath() {
00355 return filePath;
00356 }
00357
00361 public void setFilePath(String filePath) {
00362 this.filePath = filePath;
00363 }
00364
00368 public String getCommand_path() {
00369 return command_path;
00370 }
00371
00375 public void setCommand_path(String command_path) {
00376 this.command_path = command_path;
00377 }
00378
00382 public GLiteJobAd getJad() {
00383 return jad;
00384 }
00385
00392 public void addAtt(String attrName, Ad attrValue) throws Exception {
00393 jad.addAttribute(attrName, attrValue);
00394 }
00395
00402 public void addAtt(String attrName, int attrValue)
00403 throws Exception {
00404 jad.addAttribute(attrName, attrValue);
00405 }
00406
00413 public void addAtt(String attrName, double attrValue)
00414 throws Exception {
00415 jad.addAttribute(attrName, attrValue);
00416 }
00417
00424 public void addAtt(String attrName, String attrValue)
00425 throws Exception {
00426 jad.addAttribute(attrName, attrValue);
00427 }
00428
00435 public void addAtt(String attrName, boolean attrValue)
00436 throws Exception {
00437 jad.addAttribute(attrName, attrValue);
00438 }
00439
00443 public String getNetServer() {
00444 return netServer;
00445 }
00446
00450 public void setNetServer(String netServer) {
00451 this.netServer = netServer;
00452 }
00453
00457 public String getConfigFile() {
00458 return configFile;
00459 }
00460
00464 public void setConfigFile(String configFile) {
00465 this.configFile = configFile;
00466 }
00467
00468 public void setConfigFileOption(boolean b) {
00469 confFileOption = b;
00470 }
00471
00475 public boolean isJdlRemote() {
00476 return jdlRemote;
00477 }
00478
00482 public void setJdlRemote(boolean jdlRemote) {
00483 this.jdlRemote = jdlRemote;
00484 }
00485
00489 public String getRemoteFilePath() {
00490 return remoteFilePath;
00491 }
00492
00496 public void setRemoteFilePath(String remoteFilePath) {
00497 this.remoteFilePath = remoteFilePath;
00498 }
00499
00500 public FileTransferDefinition getFileTransfertDefiniton() {
00501 FileTransferDefinition ft = new FileTransferDefinition("gliteProcess");
00502 ft.addFile(filePath + "/" + fileName, remoteFilePath + "/" + fileName);
00503 return ft;
00504 }
00505
00510 public int getJobNodeNumber() {
00511 return jobNodeNumber;
00512 }
00513
00518 public void setJobNodeNumber(int jobNodeNumber) {
00519 this.jobNodeNumber = jobNodeNumber;
00520 }
00521
00525 public String getJobType() {
00526 return jobType;
00527 }
00528
00533 public void setJobType(String jobType) {
00534 this.jobType = jobType;
00535 }
00536
00541 public String getJobJobType() {
00542 return jobJobType;
00543 }
00544
00549 public void setJobJobType(String jobJobType) {
00550 this.jobJobType = jobJobType;
00551 }
00552
00557 public String getJobExecutable() {
00558 return jobExecutable;
00559 }
00560
00564 public void setJobExecutable(String jobExecutable) {
00565 this.jobExecutable = jobExecutable;
00566 }
00567
00571 public String getJobStdOutput() {
00572 return jobStdOutput;
00573 }
00574
00578 public void setJobStdOutput(String jobStdOutput) {
00579 this.jobStdOutput = jobStdOutput;
00580 }
00581
00585 public String getJobStdInput() {
00586 return jobStdInput;
00587 }
00588
00592 public void setJobStdInput(String jobStdInput) {
00593 this.jobStdInput = jobStdInput;
00594 }
00595
00599 public String getJobStdError() {
00600 return jobStdError;
00601 }
00602
00606 public void setJobStdError(String jobStdError) {
00607 this.jobStdError = jobStdError;
00608 }
00609
00613 public String getJobOutput_se() {
00614 return jobOutput_se;
00615 }
00616
00620 public void setJobOutput_se(String jobOutput_se) {
00621 this.jobOutput_se = jobOutput_se;
00622 }
00623
00627 public String getJobVO() {
00628 return jobVO;
00629 }
00630
00634 public void setJobVO(String jobVO) {
00635 this.jobVO = jobVO;
00636 }
00637
00641 public String getJobRetryCount() {
00642 return jobRetryCount;
00643 }
00644
00648 public void setJobRetryCount(String jobRetryCount) {
00649 this.jobRetryCount = jobRetryCount;
00650 }
00651
00656 public String getJobMyProxyServer() {
00657 return jobMyProxyServer;
00658 }
00659
00663 public void setJobMyProxyServer(String jobMyProxyServer) {
00664 this.jobMyProxyServer = jobMyProxyServer;
00665 }
00666
00670 public String getJobDataAccessProtocol() {
00671 return jobDataAccessProtocol;
00672 }
00673
00677 public void setJobDataAccessProtocol(String jobDataAccessProtocol) {
00678 this.jobDataAccessProtocol = jobDataAccessProtocol;
00679 }
00680
00681
00685 public String getJobStorageIndex() {
00686 return jobStorageIndex;
00687 }
00688
00692 public void setJobStorageIndex(String jobStorageIndex) {
00693 this.jobStorageIndex = jobStorageIndex;
00694 }
00695
00699 public String getJobEnvironment() {
00700 return jobEnvironment;
00701 }
00702
00706 public void setJobEnvironment(String jobEnvironment) {
00707 this.jobEnvironment = jobEnvironment;
00708 }
00709
00710
00714 public String getJobRequirements() {
00715 return jobRequirements;
00716 }
00717
00722 public void setJobRequirements(String jobRequirements) {
00723 this.jobRequirements = jobRequirements;
00724 }
00725
00729 public String getJobRank() {
00730 return jobRank;
00731 }
00732
00736 public void setJobRank(String jobRank) {
00737 this.jobRank = jobRank;
00738 }
00739
00743 public String getJobFuzzyRank() {
00744 return jobFuzzyRank;
00745 }
00746
00750 public void setJobFuzzyRank(String jobFuzzyRank) {
00751 this.jobFuzzyRank = jobFuzzyRank;
00752 }
00753
00758 public boolean addInputSBEntry(String entry) {
00759 if (jobInputSB == null) jobInputSB = new LinkedList();
00760 return jobInputSB.add(entry);
00761 }
00762
00767 public boolean addOutputSBEntry(String entry) {
00768 if (jobOutputSB == null) jobOutputSB = new LinkedList();
00769 return jobOutputSB.add(entry);
00770 }
00771
00772
00776 public String getJobArgument() {
00777 return jobArgument;
00778 }
00779
00783 public void setJobArgument(String jobArgument) {
00784 this.jobArgument = jobArgument;
00785 }
00786
00787
00788
00789
00790 }