org/objectweb/proactive/core/process/unicore/UnicoreParameters.java

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 java.util.ArrayList;
00034 import java.util.Iterator;
00035 import java.util.ListIterator;
00036 
00037 import org.unicore.resources.PriorityValue;
00038 
00039 import com.pallas.unicore.extensions.Usite.Type;
00040 
00041 
00047 public class UnicoreParameters implements java.io.Serializable {
00048     private String jobName;
00049     private String keyPassword;
00050     private boolean submitJob;
00051     private boolean saveJob;
00052     private String unicoreDir;
00053     private String keyFilePath;
00054     private String usiteName;
00055     private String usiteType;
00056     private String usiteUrl;
00057     private String vsiteName;
00058     private int vsiteNodes;
00059     private int vsiteProcessors;
00060     private int vsiteMemory;
00061     private int vsiteRuntime; //runtime in seconds
00062     private String vsitePriority;
00063     private String scriptContent;
00064     private ArrayList<String> deployFiles;
00065     private ArrayList<String> deployDirs;
00066     private ArrayList<String> retrieveFiles; //not yet supported
00067     private String fileSep;
00068 
00069     public String toString() {
00070         StringBuilder sb = new StringBuilder();
00071         sb.append("jobName=>").append(jobName).append("\n");
00072         sb.append("keyPassword=>").append(keyPassword).append("\n");
00073         sb.append("submitJob=>").append(submitJob).append("\n");
00074         sb.append("saveJob=>").append(saveJob).append("\n");
00075         sb.append("unicoreDir=>").append(unicoreDir).append("\n");
00076         sb.append("keyFilePath=>").append(keyFilePath).append("\n");
00077         sb.append("usiteName=>").append(usiteName).append("\n");
00078         sb.append("usiteType=>").append(usiteType).append("\n");
00079         sb.append("usiteUrl=>").append(usiteUrl).append("\n");
00080         sb.append("vsiteName=>").append(vsiteName).append("\n");
00081         sb.append("vsiteNodes=>").append(vsiteNodes).append("\n");
00082         sb.append("vsiteProcessors=>").append(vsiteProcessors).append("\n");
00083         sb.append("vsiteMemory=>").append(vsiteMemory).append("\n");
00084         sb.append("vsiteRuntime=>").append(vsiteRuntime).append("\n");
00085         sb.append("vsitePriority=>").append(vsitePriority).append("\n");
00086         sb.append("scriptContent=>").append(scriptContent).append("\n");
00087 
00088         sb.append("FileTransfer Directories:\n");
00089         ListIterator<String> it = deployDirs.listIterator();
00090         while (it.hasNext())
00091             sb.append(it.next()).append("\n");
00092 
00093         sb.append("FileTransfer Files:\n");
00094         it = deployFiles.listIterator();
00095         while (it.hasNext())
00096             sb.append(it.next()).append("\n");
00097 
00098         return sb.toString();
00099     }
00100 
00104     public String getJobName() {
00105         return jobName;
00106     }
00107 
00111     public void setJobName(String jobName) {
00112         this.jobName = jobName;
00113     }
00114 
00118     public String getKeyFilePath() {
00119         return keyFilePath;
00120     }
00121 
00125     public void setKeyFilePath(String keyFilePath) {
00126         this.keyFilePath = keyFilePath;
00127     }
00128 
00132     public String getKeyPassword() {
00133         return keyPassword;
00134     }
00135 
00139     public void setKeyPassword(String keyPassword) {
00140         this.keyPassword = keyPassword;
00141     }
00142 
00146     public boolean isSaveJob() {
00147         return saveJob;
00148     }
00149 
00153     public void setSaveJob(boolean saveJob) {
00154         this.saveJob = saveJob;
00155     }
00156 
00157     public void setSaveJob(String saveJob) {
00158         this.saveJob = Boolean.valueOf(saveJob).booleanValue();
00159     }
00160 
00164     public String getScriptContent() {
00165         return scriptContent;
00166     }
00167 
00171     public void setScriptContent(String scriptContent) {
00172         this.scriptContent = scriptContent;
00173     }
00174 
00178     public boolean isSubmitJob() {
00179         return submitJob;
00180     }
00181 
00185     public void setSubmitJob(boolean submitJob) {
00186         this.submitJob = submitJob;
00187     }
00188 
00189     public void setSubmitJob(String submitJob) {
00190         this.submitJob = Boolean.valueOf(submitJob).booleanValue();
00191     }
00192 
00196     public String getUnicoreDir() {
00197         return unicoreDir;
00198     }
00199 
00203     public void setUnicoreDir(String unicoreDir) {
00204         this.unicoreDir = unicoreDir;
00205     }
00206 
00210     public String getUsiteName() {
00211         return usiteName;
00212     }
00213 
00217     public void setUsiteName(String usiteName) {
00218         this.usiteName = usiteName;
00219     }
00220 
00224     public Type getUsiteType() {
00225         if (usiteType.equalsIgnoreCase("REGISTRY")) {
00226             return Type.REGISTRY;
00227         }
00228 
00229         return Type.CLASSIC;
00230     }
00231 
00235     public void setUsiteType(String usiteType) {
00236         this.usiteType = usiteType;
00237     }
00238 
00242     public String getUsiteUrl() {
00243         return usiteUrl;
00244     }
00245 
00249     public void setUsiteUrl(String usiteUrl) {
00250         this.usiteUrl = usiteUrl;
00251     }
00252 
00256     public int getVsiteMemory() {
00257         return vsiteMemory;
00258     }
00259 
00263     public void setVsiteMemory(int vsiteMemory) {
00264         this.vsiteMemory = vsiteMemory;
00265     }
00266 
00267     public void setVsiteMemory(String vsiteMemory) {
00268         this.vsiteMemory = Integer.parseInt(vsiteMemory);
00269     }
00270 
00274     public String getVsiteName() {
00275         return vsiteName;
00276     }
00277 
00281     public void setVsiteName(String vsiteName) {
00282         this.vsiteName = vsiteName;
00283     }
00284 
00288     public int getVsiteNodes() {
00289         return vsiteNodes;
00290     }
00291 
00295     public void setVsiteNodes(int vsiteNodes) {
00296         this.vsiteNodes = vsiteNodes;
00297     }
00298 
00299     public void setVsiteNodes(String vsiteNodes) {
00300         this.vsiteNodes = Integer.parseInt(vsiteNodes);
00301     }
00302 
00306     public PriorityValue getVsitePriority() {
00307         if (vsitePriority.equalsIgnoreCase("high")) {
00308             return PriorityValue.HIGH;
00309         } else if (vsitePriority.equalsIgnoreCase("low")) {
00310             return PriorityValue.LOW;
00311         } else if (vsitePriority.equalsIgnoreCase("development")) {
00312             return PriorityValue.DEVELOPMENT;
00313         } else if (vsitePriority.equalsIgnoreCase("whenever")) {
00314             return PriorityValue.WHENEVER;
00315         }
00316 
00317         return PriorityValue.NORMAL;
00318     }
00319 
00323     public void setVsitePriority(String vsitePriority) {
00324         this.vsitePriority = vsitePriority;
00325     }
00326 
00330     public int getVsiteProcessors() {
00331         return vsiteProcessors;
00332     }
00333 
00337     public void setVsiteProcessors(int vsiteProcessors) {
00338         this.vsiteProcessors = vsiteProcessors;
00339     }
00340 
00341     public void setVsiteProcessors(String vsiteProcessors) {
00342         this.vsiteProcessors = Integer.parseInt(vsiteProcessors);
00343     }
00344 
00348     public int getVsiteRuntime() {
00349         return vsiteRuntime;
00350     }
00351 
00355     public void setVsiteRuntime(int vsiteRuntime) {
00356         this.vsiteRuntime = vsiteRuntime;
00357     }
00358 
00359     public void setVsiteRuntime(String vsiteRuntime) {
00360         this.vsiteRuntime = Integer.parseInt(vsiteRuntime);
00361     }
00362 
00366     public String getFileSep() {
00367         return fileSep;
00368     }
00369 
00370     public void addDeploymentFile(String f) {
00371 
00372         /* Expected input syntax ("[]" is optional):
00373          *
00374          * srcpath[/|\]srcprefix,dstpath[/|\]dstprefix
00375          *
00376          * TODO improve de syntax error checking with regexp
00377          */
00378         String[] info = f.split(",");
00379 
00380         if (info.length != 2) {
00381             System.err.println("Skipping file, syntax error on file parameter:" +
00382                 f);
00383             return;
00384         }
00385 
00386         deployFiles.add(f);
00387     }
00388 
00389     public void addDeploymentDir(String f) {
00390         String[] info = f.split(",");
00391 
00392         //TODO improve de syntax error checking
00393         if (info.length != 2) {
00394             System.err.println("Skipping file, syntax error on file parameter:" +
00395                 f);
00396             return;
00397         }
00398 
00399         deployDirs.add(f);
00400     }
00401 
00402     public void addRetrieveFile(String f) {
00403         retrieveFiles.add(f);
00404     }
00405 
00406     public void setParameter(String name, String value) {
00407         if ((name.length() < 2) || (value.length() <= 0)) {
00408             return;
00409         }
00410         if (name.charAt(0) == '-') {
00411             name = name.substring(1);
00412         }
00413 
00414         if (name.equalsIgnoreCase("jobname")) {
00415             setJobName(value);
00416         } else if (name.equalsIgnoreCase("keypassword")) {
00417             setKeyPassword(value);
00418         } else if (name.equalsIgnoreCase("submitjob")) {
00419             setSubmitJob(value);
00420         } else if (name.equalsIgnoreCase("savejob")) {
00421             setSaveJob(value);
00422         } else if (name.equalsIgnoreCase("unicoredir")) {
00423             setUnicoreDir(value);
00424         } else if (name.equalsIgnoreCase("keyfilepath")) {
00425             setKeyFilePath(value);
00426         } else if (name.equalsIgnoreCase("usitename")) {
00427             setUsiteName(value);
00428         } else if (name.equalsIgnoreCase("usitetype")) {
00429             setUsiteType(value);
00430         } else if (name.equalsIgnoreCase("usiteurl")) {
00431             setUsiteUrl(value);
00432         } else if (name.equalsIgnoreCase("vsitename")) {
00433             setVsiteName(value);
00434         } else if (name.equalsIgnoreCase("vsitenodes")) {
00435             setVsiteNodes(value);
00436         } else if (name.equalsIgnoreCase("vsiteprocessors")) {
00437             setVsiteProcessors(value);
00438         } else if (name.equalsIgnoreCase("vsitememory")) {
00439             setVsiteMemory(value);
00440         } else if (name.equalsIgnoreCase("vsiteruntime")) {
00441             setVsiteRuntime(value);
00442         } else if (name.equalsIgnoreCase("vsitepriority")) {
00443             setVsitePriority(value);
00444         } else if (name.equalsIgnoreCase("deploymentFile")) {
00445             addDeploymentFile(value);
00446         } else if (name.equalsIgnoreCase("deploymentDir")) {
00447             addDeploymentDir(value);
00448         } else {
00449             System.err.println("Skipping unkown parameter: -" + name + " " +
00450                 value);
00451         }
00452     }
00453 
00454     public String getCommandString() {
00455         StringBuilder sb = new StringBuilder();
00456 
00457         sb.append(
00458             "java org.objectweb.proactive.core.process.unicore.UnicoreProActiveClient ");
00459         sb.append("-jobname " + quoteIfNeeded(jobName) + " ");
00460         if ((keyPassword != null) && (keyPassword.length() > 0)) {
00461             sb.append("-keypassword " + quoteIfNeeded(keyPassword) + " ");
00462         }
00463         sb.append("-submitjob ").append(submitJob).append(" ");
00464         sb.append("-saveJob ").append(saveJob).append(" ");
00465         sb.append("-unicoreDir ").append(quoteIfNeeded(unicoreDir)).append(" ");
00466         sb.append("-keyFilePath ").append(quoteIfNeeded(keyFilePath)).append(" ");
00467         sb.append("-usiteName ").append(quoteIfNeeded(usiteName)).append(" ");
00468         sb.append("-usiteType ").append(quoteIfNeeded(usiteType)).append(" ");
00469         sb.append("-usiteUrl ").append(quoteIfNeeded(usiteUrl)).append(" ");
00470         sb.append("-vsiteName ").append(quoteIfNeeded(vsiteName)).append(" ");
00471         sb.append("-vsiteNodes ").append(vsiteNodes).append(" ");
00472         sb.append("-vsiteProcessors ").append(vsiteProcessors).append(" ");
00473         sb.append("-vsiteMemory ").append(vsiteMemory).append(" ");
00474         sb.append("-vsiteRuntime ").append(vsiteRuntime).append(" ");
00475         sb.append("-vsitePriority ").append(vsitePriority).append(" ");
00476 
00477         //TODO check for white spaces!
00478         Iterator<String> it = deployFiles.iterator();
00479         while (it.hasNext()) {
00480             String s = it.next();
00481             sb.append("-deploymentFile ").append(s).append(" ");
00482         }
00483 
00484         it = deployDirs.iterator();
00485         while (it.hasNext()) {
00486             String s = it.next();
00487             sb.append("-deploymentDir ").append(s).append(" ");
00488         }
00489 
00490         sb.append(scriptContent);
00491         return sb.toString();
00492     }
00493 
00498     public String getDestMoveCommand() {
00499         StringBuilder sb = new StringBuilder();
00500         String[] filesAndDirs = getDeployAllFilesAndDirectories();
00501 
00502         for (int i = 0; i < filesAndDirs.length; i++) {
00503             String[] f = filesAndDirs[i].split(",");
00504 
00505             if (f.length != 2) {
00506                 continue;
00507             }
00508 
00509             String fileSep = guessFileSep(f[1]);
00510 
00511             //skip if no prefix is defined
00512             //Noprefix happens if there is no fileSep 
00513             //in the middle of the String
00514             if ((f[1].indexOf(fileSep) >= 0) &&
00515                     (f[1].indexOf(fileSep) != (f[1].length() - 1))) {
00516                 sb.append("mv ").append(getFileName(f[1])).append(" ")
00517                   .append(f[1]).append("\n");
00518             }
00519         }
00520 
00521         return sb.toString();
00522     }
00523 
00524     private String quoteIfNeeded(String s) {
00525         //if(s.indexOf(" ")>=0)
00526         //      return "\""+s+"\"";
00527         //return s;
00528         //TODO find a real solution to this problem
00529         return s.replaceAll(" ", "_");
00530     }
00531 
00532     public UnicoreParameters() {
00533         fileSep = System.getProperty("file.separator");
00534 
00535         jobName = "ProActiveDescriptorDeployment";
00536         keyPassword = "";
00537         submitJob = true;
00538         saveJob = false;
00539 
00540         unicoreDir = System.getProperty("user.home") + fileSep + ".unicore";
00541         keyFilePath = unicoreDir + fileSep + "keystore";
00542 
00543         usiteName = null;
00544         usiteType = "CLASSIC";
00545         usiteUrl = null;
00546 
00547         vsiteName = null;
00548         vsiteNodes = -1;
00549         vsiteProcessors = -1;
00550         vsiteMemory = -32;
00551         vsiteRuntime = -300;
00552         vsitePriority = "normal";
00553 
00554         scriptContent = "";
00555 
00556         deployFiles = new ArrayList<String>();
00557         deployDirs = new ArrayList<String>();
00558 
00559         retrieveFiles = null; //new ArrayList(); not yet implemented
00560     }
00561 
00565     public String[] getDeployAllFilesAndDirectories() {
00566         ArrayList<String> allFiles = new ArrayList<String>();
00567 
00568         allFiles.addAll(deployFiles);
00569         allFiles.addAll(deployDirs);
00570 
00571         return allFiles.toArray(new String[0]);
00572     }
00573 
00579     public static String getFileName(String fullpathname) {
00580         boolean isDir = false;
00581 
00582         String fileSep = guessFileSep(fullpathname);
00583 
00584         //directory can end with slash
00585         if (fullpathname.endsWith(fileSep)) {
00586             isDir = true;
00587             fullpathname.substring(0, fileSep.length() - 1);
00588         }
00589 
00590         //last element is the one we are looking for
00591         String[] splited = fullpathname.split(fileSep);
00592 
00593         //adding the final fileSep if it's a directory
00594         if (isDir) {
00595             return splited[splited.length - 1] + fileSep;
00596         }
00597 
00598         return splited[splited.length - 1];
00599     }
00600 
00606     private static String guessFileSep(String fullpathname) {
00607         //guess the fileseparator
00608         String fileSep = "/";
00609         if (fullpathname.indexOf("/") < fullpathname.indexOf("\\")) {
00610             fileSep = "\\";
00611         }
00612 
00613         return fileSep;
00614     }
00615 }

Generated on Mon Jan 22 15:16:09 2007 for ProActive by  doxygen 1.5.1