001 /* 002 * test_jug.java 003 * 004 * Created on July 8, 2004, 5:59 PM 005 * 006 * This file is part of the STAR Scheduler. 007 * Copyright (c) 2002-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 025 package gov.bnl.star.offline.scheduler.util; 026 027 //may be needed 028 import java.math.BigInteger; 029 ////needed for class 030 import java.net.*; 031 import java.io.*; 032 import gov.bnl.star.offline.scheduler.request.Request; 033 import gov.bnl.star.offline.scheduler.util.MD5Hash; 034 035 036 /** Generate a uuid for the request. 037 * note: this needs jug.jar to work 038 * @author Levente Hajdu 039 */ 040 041 public class jobIDGen { 042 043 /** Creates a new instance of test_jug */ 044 public jobIDGen() { 045 } 046 047 /** 048 * @param args the command line arguments 049 */ 050 051 public static void main(String[] args) { 052 053 054 } 055 056 //this is the old type of job id that only takes System.currentTimeMillis() 057 public static String GetJobIDType1(){ 058 return String.valueOf(System.currentTimeMillis()); 059 } 060 061 062 /** 063 * @return A randomly generated job ID 064 */ 065 public static String GetJobIDType2(){ 066 String hashSeed = String.valueOf(System.currentTimeMillis()); 067 068 //gets the ip address of this computer if it has one. 069 try { 070 hashSeed = hashSeed.concat(InetAddress.getLocalHost().getHostAddress()); 071 } catch (UnknownHostException e) {} 072 073 //add the username to the hash seed 074 String user = System.getProperty("user.name"); 075 //System.out.println("DEBUG User is "+user); 076 hashSeed = hashSeed.concat(user); 077 078 try{//run the ps command and get the PID Note: this works for unix and windows xp //If there is not pid command then just don't add it to the string 079 BufferedReader stdInput = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("ps").getInputStream())); 080 String line = " "; 081 while ((line = stdInput.readLine()) != null) 082 hashSeed = hashSeed.concat(line); 083 } catch (Exception e) {} 084 085 String JobID = MD5Hash.hash(hashSeed); 086 //System.out.println("DEBUG hashSeed is " + hashSeed); 087 //System.out.println("DEBUG JobID is "+JobID); 088 return JobID; 089 //return JobID.substring(0,14); 090 } 091 092 }