001 /* 002 * PackmanSandbox.java 003 * 004 * Created on October 26, 2005, 12:54 PM 005 * 006 * This file is part of the STAR Scheduler. 007 * Copyright (c) 2003-2006 STAR Collaboration - Brookhaven National Laboratory 008 * 009 * STAR Scheduler is free software; you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as published by 011 * the Free Software Foundation; either version 2 of the License, or 012 * (at your option) any later version. 013 * 014 * STAR Scheduler is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * along with STAR Scheduler; if not, write to the Free Software 021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 022 */ 023 024 package gov.bnl.star.offline.scheduler.util.sandbox; 025 026 import gov.bnl.star.offline.scheduler.util.sandbox.Sandbox; 027 import gov.bnl.star.offline.scheduler.request.Request; 028 import gov.bnl.star.offline.scheduler.Job; 029 030 import gov.bnl.star.offline.scheduler.util.ConfigToolkit; 031 032 import java.util.List; 033 import java.util.ArrayList; 034 035 /** A variation of the sandbox using prepackage packman packages. 036 * 037 * It should be noted that this variant of the sandbox does not 038 * build packman packages. The benefit of the packman sandbox is 039 * that when packman installs a package it can select between 040 * multiple OS versions of a package, selecting the correct one 041 * for the target host (if available). 042 * 043 * @author Levente Hajdu 044 */ 045 public class PackmanSandbox implements Sandbox{ 046 047 /** Creates a new instance of PackmanSandbox */ 048 public PackmanSandbox() { 049 } 050 051 public String CopyCommand(SandboxPackage packageObj) { 052 return ""; 053 } 054 055 public boolean MakePackage(SandboxPackage packageObj, Request request) { 056 return true; 057 } 058 059 060 public void Sandbox() { 061 } 062 063 064 /** Write the command with which to setup the users sandbox. 065 * @param packageObj The sandbox package for which the commmand is needed 066 * @param job The job of which the command is being written 067 * @return the sandbox setup command as a string 068 **/ 069 public String installCommand(SandboxPackage packageObj, Job job) { 070 071 String packman_caches = ""; 072 String packmanPackageInstalls = ""; 073 074 if (ConfigToolkit.getToolkit().myLocalSite().getProgramLocations() != null){ 075 if (ConfigToolkit.getToolkit().myLocalSite().getProgramLocations().containsKey("packman_caches")){ 076 packman_caches = (String) ConfigToolkit.getToolkit().myLocalSite().getProgramLocations().get("packman_caches"); 077 } 078 } 079 080 081 if(packman_caches.equals("")){ 082 new RuntimeException().printStackTrace(); 083 throw new RuntimeException("\n\nCould not fine \"packman_caches\" in program locations for this site, unable to write script. Check configuration file.\n"); 084 } 085 086 087 if(packageObj.getPackageName() == null){ 088 new RuntimeException().printStackTrace(); 089 throw new RuntimeException("\n\nError building script all packman sandbox packages must have a name, unable to write script.\n"); 090 091 } 092 093 packmanPackageInstalls = packmanPackageInstalls.concat("pacman -trust-all-caches -get " + packman_caches + ":" + packageObj.getPackageName()); 094 095 return "\n" + packmanPackageInstalls + "\nsource setup.csh"; 096 } 097 098 099 List packages = new ArrayList(); 100 public void addPackage(SandboxPackage sandboxPackage) {packages.add(sandboxPackage); } 101 public java.util.List getPackages() { return packages; } 102 public void setPackages(java.util.List packages) { this.packages = packages; } 103 104 //Because this can not be check 105 public boolean PackageExists(SandboxPackage packageObj){return true; } 106 107 List SandboxedFiles = new ArrayList(); 108 /* Gets the files that the sand box has packed. */ 109 public List getSandboxedFiles(){ return SandboxedFiles; } 110 /* Sets the files that the sand box has packed. */ 111 public void setSandboxedFiles(List SandboxedFiles){ this.SandboxedFiles = SandboxedFiles; } 112 /* Adds a file to the list of sandboxed files. */ 113 public void addSandboxedFiles(String file){ SandboxedFiles.add(file); } 114 115 public String InitializationCommands() { 116 String pacman_bootstrap_command = ""; 117 118 if (ConfigToolkit.getToolkit().myLocalSite().getProgramLocations() != null){ 119 if (ConfigToolkit.getToolkit().myLocalSite().getProgramLocations().containsKey("pacman_bootstrap")){ 120 pacman_bootstrap_command = (String) ConfigToolkit.getToolkit().myLocalSite().getProgramLocations().get("pacman_bootstrap"); 121 } 122 } 123 124 if(pacman_bootstrap_command.equals("")){ 125 System.out.println("The packman boot strap command(s) for you site could not be located in you config file. Assuming packman is already installed."); 126 pacman_bootstrap_command = ""; 127 } 128 129 130 return pacman_bootstrap_command; 131 132 } 133 134 }