Node Director
Static Public Member Functions | Static Public Attributes | List of all members
sfi.director.util.Tools Class Reference

The Tools class is a collection of useful static methods. More...

Static Public Member Functions

static Object saveOurClass (Object anInstance)
 Classes of objects registered via this method are protected against the class garbage collection.
static synchronized String uniqId ()
 Returns a (hopefully) system-wide unique ID.
static String secUniqId ()
static< T > Iterable< T > emptyIfNull (Iterable< T > iterable)
 Return an empty iterable if argument is null, the iterable itself otherwise.
static boolean copy (InputStream fin, OutputStream fout, boolean continuous) throws DirectorException
 Copy all the data from an InputStream to an OutputStream.
static void copy (InputStream fin, OutputStream fout) throws DirectorException
 Copy in non-continuous mode.
static long digestData (InputStream fin, MessageDigest digest) throws IOException
 Read all data from InputStream and update a digest accordingly.
static MessageDigest md5sum (File file) throws DirectorException
 Compute md5 checksum for a file.
static MessageDigest md5sum (InputStream in) throws DirectorException
 Compute md5 checksum for a file.
static long copyData (InputStream fin, OutputStream out) throws IOException
 Copy all data from an InputStream to an OutputStream.
static long copyObject (Object source, OutputStream out, boolean closeOnTerm) throws IOException
 Copy object from into an OutputStream.
static long copyObject (Object source, File out) throws IOException
 Copy object into a file.
static int readEntire (InputStream in, byte buffer[], int offset, int length) throws IOException
 Read a block of data from an InputStream.
static int readEntire (InputStream in, byte buffer[], int length) throws IOException
 Read a block of data from an InputStream.
static String readEntireText (BufferedReader in, boolean closeOnExit) throws IOException
static String readEntireText (File in) throws IOException
static String readEntireText (InputStream in, boolean closeOnExit) throws IOException
static void debug (LogEntry log)
 Log a debug message.
static void debug (int level, String message)
 Log a debug message if debug level is high enough for the message to be logged.
static void log (LogEntry log)
 Log a message.
static void log (int level, String message)
 Log a message at the specified priority level.
static void exit ()
 Exit without an error.
static void exit (int exitcode)
 Exit with specified exit code.
static void waitThreads (long timeout)
static void rememberCleanup (CleanUpable cleanup)
 Mark an object as to be cleaned up by exit().
static String join (Vector list, String separator)
 Join the string representation of a list of objects into one single resulting string.
static String join (Enumeration list, String separator)
 Join the string representation of an enumeration of strings into one single resulting string.
static Hashtable hashtable (Enumeration list)
 build a hash table from an Enumeration with key/value being both the respective objects
static Vector split (String str, String separator)
 Split a string into a vector of strings.
static Vector split (String str)
 Split a string into a vector of strings.
static Hashtable getOpt (String args[], String argopts[]) throws ArgumentException
 Process command line arguments.
static void attachErrorLogger (final Process proc)
 Attach an thread to a process' error stream logging every error message via the default logger.
static void attachErrorLogger (final InputStream in)
static void attachErrorLogger (final Process proc, final OutputStream out)
static void attachErrorLogger (final InputStream in, final OutputStream out)
static Process exec (String cmd) throws IOException
 Execute a command.
static Process exec (String cmd[]) throws IOException
 Execute a command.
static Vector runParsePerl (String split, String code, String args[]) throws DirectorException
static int execWait (String cmd[])
 Execute a command, attach an error logger, wait for the command's termination and return its exit code to the caller.
static String[] ShellCommand (String command)
 Accepts a shell command string, returns a String array containing the same command ready for execution via exec() and the system's command shell.
static int execWait (String cmd[], boolean logErrors)
 Execute a command, optionally attach an error logger, wait for the command's termination and return its exit code to the caller.
static int execWait (String cmd[], boolean logErrors, long timeout)
 Execute a command, optionally attach an error logger, wait for the command's termination and return its exit code to the caller.
static void consume (final InputStream stream)
static int workingWaitFor (Process process, boolean outConsumed, boolean errorConsumed) throws InterruptedException
static int workingWaitFor (Process process, boolean outConsumed, boolean errorConsumed, final long timeout) throws InterruptedException
 do a Process.waitFor() and consume the exec()-ed commands output in order to avoid hangs.
static Enumeration execUtility (String cmd[]) throws DirectorException
 run a command and read its output via an Enumeration.
static Enumeration execUtility (String cmd[], boolean errout) throws DirectorException
static Enumeration execFilter (String cmd[], final Object source) throws DirectorException
static Enumeration execFilter (String cmd[], final Object source, boolean errout) throws DirectorException
 run a command, pipe the source string in and make the output accessible via the returned Enumeration.
static String findAuth (String principal)
 Find an authentication database entry for a given principal (login name).
static int findUidNumber (int start) throws DirectorException
 By using the people database find an unused uid number higher than the specified start limit.
static int findUidNumber (int start, int end) throws DirectorException
 By using the people database find an unused uid between two given limits.
static int findGidNumber (int start) throws DirectorException
 By using the people database find an unused gid number higher than the specified start limit.
static int findGidNumber (int start, int end) throws DirectorException
 By using the people database find an unused uid between two given limits.
static int findFreeNumber (int start, int end, String field) throws DirectorException
 By using the people database find an unused uid or gid number between two given limits.
static int findFreeNumber (int start, int end, String field, String dir) throws DirectorException
static void sort (Vector v, MyComparator c)
 Sort a vector in the order specified by the given comparator.
static void sort (Object arr[], MyComparator c)
 Sort an array in the order specified by the given comparator.
static String expand (String str, final DBObject dbo) throws DirectorException
 Expand variable references in a string using the attributes of the given database entry as variable/value pairs.
static String expand (String str, final ExpandVars expander) throws DirectorException
 Expand variable references in a string using the given ExpandVars class to expand variable names into their values.
static String applyModifier (String modifier, String val, final ExpandVars expander) throws DirectorException
 Apply a variable modifier to a value.
static void background ()
 Put the current thread into the background (= decrease its priority).
static void executeLocalqueue ()
 Do something reasonable with the jobs in the local job queue.
static void doEvent (DBObject dbo, final DBConnection dir, final Record data, final String type)
static void doEvent (DBObject dbo, final DBConnection dir, final Record data, final String type, boolean warnIfNotApplicable)
 Execute an event for a given database entry and the given corresponding object editor data.
static void makeZip (File what, String prefix, OutputStream out) throws DirectorException
 Zip the given file and send the zip file to the given stream.
static void makeZip (File what, String prefix, ZipOutputStream out) throws DirectorException
static String ticketid ()
static String minTimeStamp ()
 Return a string representing the current time in a format in minute precision only.
static String timeStamp ()
 Return a string representing the current time in a (director) standard format.
static String timeStamp (Date time)
 Return a string representing the passed time in a (director) standard format.
static void main (String args[])
static DBObject fieldToDBObject (Field f)
static Record toDBEditRecord (DBObject dbo)
static DBObject toDBObject (Record rec)
static String getUser ()
static void trackJob (Workflow workflow) throws DirectorException
static String stacktrace (Throwable e)
static Enumeration getHostnames (String name)
 Get all names of a specific host/alias from the hosts directory.
static void removeDir (File dir) throws DirectorException
 Remove a file/directory recursively.
static String asciify (String str)
 translate some international characters in a string into an ASCII representation
static String daytimeStamp (Date time)
 Return a string representing the current day time.
static String daytimeStamp ()
static void setThreadSubStatus (String status)
static void backupFile (File file)
 Same as backupFile(), but saves file without checking if there is already an identical backup copy.
static void backupFile (File target, boolean onlyIfDifferent)
 Save a backup copy of the given file.
static void shutdown ()
 Try to do some cleanup before system shutdown.
static boolean isHostReady (String hostname)
static PrintStream debugfile ()

Static Public Attributes

static int debuglev = 0
 The program's debug level.
static PrintStream debugout = System.err
 The Stream where debug output is sent to.
static Vector classRefs = new Vector()
 Vector used to store references to classes for the saveOurClass mechanism.
static Hashtable progOptions = new Hashtable()
 This hash stores the command line options of the current program.

Detailed Description

The Tools class is a collection of useful static methods.

Note that some of the methods are covered by recent Java versions but are re-implemented here for compatibility reasons.

Member Function Documentation

static String sfi.director.util.Tools.applyModifier ( String  modifier,
String  val,
final ExpandVars  expander 
) throws DirectorException
static
static String sfi.director.util.Tools.asciify ( String  str)
static

translate some international characters in a string into an ASCII representation

Referenced by sfi.director.util.Tools.applyModifier(), sfi.director.repository.transform.AD2Group.transform(), and sfi.director.repository.transform.AD2User.transform().

static void sfi.director.util.Tools.attachErrorLogger ( final Process  proc)
static
static void sfi.director.util.Tools.attachErrorLogger ( final InputStream  in)
static
static void sfi.director.util.Tools.attachErrorLogger ( final Process  proc,
final OutputStream  out 
)
static
static void sfi.director.util.Tools.attachErrorLogger ( final InputStream  in,
final OutputStream  out 
)
static
static void sfi.director.util.Tools.background ( )
static

Put the current thread into the background (= decrease its priority).

Referenced by sfi.director.util.Tools.doEvent().

static void sfi.director.util.Tools.backupFile ( File  file)
static

Same as backupFile(), but saves file without checking if there is already an identical backup copy.

Referenced by sfi.director.retriever.BackupFileRetriever.BackupFile.close(), and sfi.director.application.config.ConfigFileHandler.restore().

static void sfi.director.util.Tools.backupFile ( File  target,
boolean  onlyIfDifferent 
)
static

Save a backup copy of the given file.

The copy is made in the backup directory as configured via the option ConfigBackup.Dir in sfidirector.conf. If the boolean argument is true, then backupFile() checks if there is already an identical backup copy (identical MD5 checksum) in which case no new copy is made. Existing old backup files are rotated, thus multiple versions are kept. The ConfigBackup.Keep sfidirector.conf option defines how many versions are kept.

Parameters
targetThe file to be backed up
onlyIfDifferentif true, the file is only backed up if there is no existing identical backup copy

References sfi.director.system.Files.chgrp(), sfi.director.system.Files.chmod(), sfi.director.system.Files.chown(), sfi.director.util.Tools.copy(), sfi.director.util.Tools.digestData(), sfi.director.system.FileStats.getMtime(), sfi.director.util.MyProperties.getProperty(), sfi.director.util.MyProperties.getPropertyInteger(), sfi.director.util.Tools.log(), sfi.director.util.Setup.properties, sfi.director.system.Files.stat(), and sfi.director.util.Logger.WARNING.

static void sfi.director.util.Tools.consume ( final InputStream  stream)
static
static boolean sfi.director.util.Tools.copy ( InputStream  fin,
OutputStream  fout,
boolean  continuous 
) throws DirectorException
static
static void sfi.director.util.Tools.copy ( InputStream  fin,
OutputStream  fout 
) throws DirectorException
static

Copy in non-continuous mode.

See Also
copy(InputStream,OutputStream,boolean)

References sfi.director.util.Tools.copy().

static long sfi.director.util.Tools.copyData ( InputStream  fin,
OutputStream  out 
) throws IOException
static
static long sfi.director.util.Tools.copyObject ( Object  source,
OutputStream  out,
boolean  closeOnTerm 
) throws IOException
static

Copy object from into an OutputStream.

The behaviour depends on the type of the source object. For most objects the string value of the source object is emitted.

References sfi.director.util.Tools.copyData().

Referenced by sfi.director.util.Tools.copyObject(), sfi.director.application.scripttask.Report.create(), sfi.director.application.scripttask.ChainEvent.create(), and sfi.director.util.Tools.execFilter().

static long sfi.director.util.Tools.copyObject ( Object  source,
File  out 
) throws IOException
static

Copy object into a file.

References sfi.director.util.Tools.copyObject().

static String sfi.director.util.Tools.daytimeStamp ( Date  time)
static

Return a string representing the current day time.

static String sfi.director.util.Tools.daytimeStamp ( )
static
static void sfi.director.util.Tools.debug ( LogEntry  log)
static

Log a debug message.

References sfi.director.util.Logger.log(), and sfi.director.util.Setup.logger.

Referenced by sfi.director.executor.AppExecutor.accept(), sfi.director.invoker.MasterLoopbackInvoker.accept(), sfi.director.invoker.ShellLoopbackInvoker.accept(), sfi.director.invoker.LoopbackInvoker.accept(), sfi.director.jobs.Job.addNotify(), sfi.director.invoker.StreamConnection.agentlistener(), sfi.director.invoker.SSHInvoker.alternateBootstrap(), sfi.director.repository.LDIFDir.append(), sfi.director.repository.JDBC.append(), sfi.director.repository.config.DirectoryAccess.apply(), sfi.director.schedule.ParallelScheduler.attach(), sfi.director.invoker.InvokerManager.bootstrap(), sfi.director.invoker.RSHInvoker.bootstrap(), sfi.director.application.ClassDefine.ClassDefine(), sfi.director.application.DirectorPackage.cleanUpSub(), sfi.director.invoker.StreamConnection.commonListen(), sfi.director.application.autodoc.DependencyGraph.compute(), sfi.director.invoker.SSLInvoker.connect(), sfi.director.repository.GenericDriver.connect(), sfi.director.retriever.ServerRetriever.connect(), sfi.director.invoker.StreamCmdInvoker.connect(), sfi.director.executor.CmdExecutor.connect(), sfi.director.invoker.RSHInvoker.connect(), sfi.director.application.scripttask.FireEvent.create(), sfi.director.application.scripttask.Report.create(), sfi.director.application.scripttask.WakeOnLan.create(), sfi.director.application.scripttask.EmulateRoot.create(), sfi.director.application.scripttask.GroupOfMembers.create(), sfi.director.application.scripttask.ResolveDependencies.create(), sfi.director.application.scripttask.ReloadService.create(), sfi.director.application.scripttask.UpdateDomainsFor.create(), sfi.director.application.scripttask.ChainEvent.create(), sfi.director.application.scripttask.RemoveUserRef.create(), sfi.director.application.scripttask.SetVHost.create(), sfi.director.application.scripttask.CollectSysinfo.create(), sfi.director.application.scripttask.SetHostIP.create(), sfi.director.application.scripttask.SetUserRef.create(), sfi.director.application.scripttask.StoreAsDBChoice.create(), sfi.director.application.scripttask.ConfigureNetwork.create(), sfi.director.application.scripttask.RepositoryScan.create(), sfi.director.application.scripttask.ScheduleBuildDependingDomains.create(), sfi.director.application.scripttask.ZoneUpdated.create(), sfi.director.application.scripttask.DoAppInventory.create(), sfi.director.application.scripttask.Shell.create(), sfi.director.application.scripttask.CreateHome.create(), sfi.director.application.scripttask.CreateReleaseDir.create(), sfi.director.application.scripttask.ApplyDomainTemplate.create(), sfi.director.application.scripttask.SubscribeApps.create(), sfi.director.application.scripttask.D3HostDefine.create(), sfi.director.application.scripttask.DomainDepends.create(), sfi.director.application.scripttask.BootStrapDirector.create(), sfi.director.application.scripttask.ClassMemberApply.create(), sfi.director.application.scripttask.BuildDependingDomains.create(), sfi.director.application.scripttask.CreateHomeDB.create(), sfi.director.application.scripttask.DomainBuild.create(), sfi.director.application.scripttask.FreezeApplication.create(), sfi.director.application.scripttask.SetServerPassword.create(), sfi.director.application.scripttask.DoAppImport.create(), sfi.director.application.scripttask.INFAppModules.create(), sfi.director.application.scripttask.InjectUserSettings.create(), sfi.director.application.scripttask.CupsDrivers.create(), sfi.director.application.scripttask.ConfigHost.create(), sfi.director.application.scripttask.PublishApplication.create(), sfi.director.application.scripttask.AppInstallHost.create(), sfi.director.application.InstallerOpenLDAP.createConf(), sfi.director.util.Tools.debug(), sfi.director.jobs.Job.die(), sfi.director.application.objevents.Workflow.doEvent(), sfi.director.util.Tools.doEvent(), sfi.director.application.autodoc.DocBuilder.domaindoc(), sfi.director.repository.JDBC.enumerateTables(), sfi.director.application.executor.scanRepositoryPush.exec(), sfi.director.application.scripttask.SetHostIP.exec(), sfi.director.application.scripttask.BuildDependingDomains.exec(), sfi.director.schedule.ParallelScheduler.executeCmd(), sfi.director.schedule.Scheduler.executeCmd(), sfi.director.schedule.Scheduler.executeDSUpdate(), sfi.director.invoker.Recorder.executeJob(), sfi.director.application.autodoc.DocURNHandler.fetchInto(), sfi.director.util.Tools.findAuth(), sfi.director.application.PackageList.findPackage(), sfi.director.application.HostPackages.forPkg(), sfi.director.application.autodoc.Formatsplithtml.generateHTML(), sfi.director.application.autodoc.FormatODF.generateODF(), sfi.director.application.autodoc.DocBuilder.genericObjDoc(), sfi.director.repository.JDBC.getColumns(), sfi.director.application.objevents.EventEnvironment.getConfig(), sfi.director.repository.config.DirectoryAccess.getConfig(), sfi.director.repository.DBManager.getConnection(), sfi.director.repository.JDBC.getConnection(), sfi.director.util.UnixDomainSocket.getConnector(), sfi.director.repository.config.Directory.getDirectory(), sfi.director.schedule.ParallelScheduler.goThroughQueue(), sfi.director.schedule.SimpleScheduler.goThroughVector(), sfi.director.application.FrontendHTTPServer.handleRpc(), sfi.director.application.HostDefine.HostDefine(), sfi.director.application.autodoc.DocBuilder.hostdoc(), sfi.director.invoker.StreamConnection.imDone(), sfi.director.application.autodoc.DocBuilder.insertDependencyGraph(), sfi.director.application.DirectorPackage.install(), sfi.director.application.PackageSession.installPkg(), sfi.director.invoker.InvokerManager.invoke(), sfi.director.invoker.StreamConnection.leanBackAndWait(), sfi.director.application.autodoc.DocBuilder.locationdoc(), sfi.director.util.Lock.Lock(), sfi.director.application.FilePackageHandler.makeAndRunCommand(), sfi.director.invoker.StreamConnection.masterlistener(), sfi.director.jobs.JobNode.Notify(), sfi.director.application.DaemonObjectEdit.ObjectDefine(), sfi.director.application.objevents.Workflow.openMonitor(), sfi.director.schedule.ParallelScheduler.parallelizedExec(), sfi.director.util.Stub.register(), sfi.director.repository.JDBC.replace(), sfi.director.schedule.ParallelScheduler.saveQueue(), sfi.director.schedule.Scheduler.scheduleJob(), sfi.director.repository.LDIFDir.search(), sfi.director.invoker.StreamConnection.send_string(), sfi.director.application.SetPassword.setPasswordByFilter(), sfi.director.jobs.Job.setStatus(), sfi.director.gui.fields.HostClass.setTemplate(), sfi.director.util.Init.setup_base(), sfi.director.retriever.PipeRetriever.setupExec(), sfi.director.repository.JDBC.setURL(), sfi.director.repository.LDAP.setURL(), sfi.director.repository.LDAPndk.setURL(), sfi.director.invoker.RSHInvoker.shellbootstrap(), sfi.director.application.autodoc.DocBuilder.slurpExternalDocs(), and sfi.director.repository.DirectoryServiceMerger.targetJob().

static void sfi.director.util.Tools.debug ( int  level,
String  message 
)
static

Log a debug message if debug level is high enough for the message to be logged.

References sfi.director.util.Logger.DEBUG, and sfi.director.util.Tools.debug().

static PrintStream sfi.director.util.Tools.debugfile ( )
static
static long sfi.director.util.Tools.digestData ( InputStream  fin,
MessageDigest  digest 
) throws IOException
static

Read all data from InputStream and update a digest accordingly.

Referenced by sfi.director.util.Tools.backupFile(), sfi.director.util.Tools.md5sum(), and sfi.director.application.config.ConfigFileHandler.restore().

static void sfi.director.util.Tools.doEvent ( DBObject  dbo,
final DBConnection  dir,
final Record  data,
final String  type 
)
static
static void sfi.director.util.Tools.doEvent ( DBObject  dbo,
final DBConnection  dir,
final Record  data,
final String  type,
boolean  warnIfNotApplicable 
)
static
static <T> Iterable<T> sfi.director.util.Tools.emptyIfNull ( Iterable< T >  iterable)
static
static Process sfi.director.util.Tools.exec ( String  cmd) throws IOException
static
static Process sfi.director.util.Tools.exec ( String  cmd[]) throws IOException
static

Execute a command.

static Enumeration sfi.director.util.Tools.execFilter ( String  cmd[],
final Object  source 
) throws DirectorException
static
static Enumeration sfi.director.util.Tools.execFilter ( String  cmd[],
final Object  source,
boolean  errout 
) throws DirectorException
static
static void sfi.director.util.Tools.executeLocalqueue ( )
static
static Enumeration sfi.director.util.Tools.execUtility ( String  cmd[]) throws DirectorException
static
static Enumeration sfi.director.util.Tools.execUtility ( String  cmd[],
boolean  errout 
) throws DirectorException
static
static int sfi.director.util.Tools.execWait ( String  cmd[])
static
static int sfi.director.util.Tools.execWait ( String  cmd[],
boolean  logErrors 
)
static

Execute a command, optionally attach an error logger, wait for the command's termination and return its exit code to the caller.

See Also
#attachErrorLogger(Process)

References sfi.director.util.Tools.execWait().

static int sfi.director.util.Tools.execWait ( String  cmd[],
boolean  logErrors,
long  timeout 
)
static

Execute a command, optionally attach an error logger, wait for the command's termination and return its exit code to the caller.

Returns after at most timeout msecs.

See Also
#attachErrorLogger(Process)

References sfi.director.util.Tools.attachErrorLogger(), sfi.director.util.Tools.consume(), sfi.director.util.Tools.exec(), and sfi.director.util.Tools.workingWaitFor().

static void sfi.director.util.Tools.exit ( )
static
static void sfi.director.util.Tools.exit ( int  exitcode)
static

Exit with specified exit code.

Programs should always call Tools.exit() when shutting down. Due to Java's broken JVM shutdown mechanism's the program will not gracefully give up resources otherwise.

References sfi.director.util.CleanUpable.cleanup(), sfi.director.util.Tools.execUtility(), sfi.director.util.MyProperties.getPropertyBoolean(), sfi.director.util.Setup.properties, sfi.director.util.Tools.ShellCommand(), sfi.director.util.Tools.shutdown(), and sfi.director.util.Tools.waitThreads().

static String sfi.director.util.Tools.expand ( String  str,
final DBObject  dbo 
) throws DirectorException
static
static String sfi.director.util.Tools.expand ( String  str,
final ExpandVars  expander 
) throws DirectorException
static

Expand variable references in a string using the given ExpandVars class to expand variable names into their values.

See Also
ExpandVars

References sfi.director.util.Tools.applyModifier().

static DBObject sfi.director.util.Tools.fieldToDBObject ( Field  f)
static
static String sfi.director.util.Tools.findAuth ( String  principal)
static

Find an authentication database entry for a given principal (login name).

Returns
the string representation of the DN of the auth database entry or the principal itself if no entry was found

References sfi.director.util.Setup.authdb, sfi.director.repository.DBConnection.completeDN(), sfi.director.util.Tools.debug(), sfi.director.repository.DN.get(), sfi.director.repository.DBObject.getDN(), and sfi.director.repository.DBConnection.search().

Referenced by sfi.director.util.Credentials.findAuth(), and sfi.director.cli.storepassword.run().

static int sfi.director.util.Tools.findFreeNumber ( int  start,
int  end,
String  field 
) throws DirectorException
static

By using the people database find an unused uid or gid number between two given limits.

Referenced by sfi.director.util.Tools.applyModifier(), sfi.director.util.Tools.findGidNumber(), and sfi.director.util.Tools.findUidNumber().

static int sfi.director.util.Tools.findFreeNumber ( int  start,
int  end,
String  field,
String  dir 
) throws DirectorException
static
static int sfi.director.util.Tools.findGidNumber ( int  start) throws DirectorException
static

By using the people database find an unused gid number higher than the specified start limit.

Referenced by sfi.director.util.Tools.applyModifier().

static int sfi.director.util.Tools.findGidNumber ( int  start,
int  end 
) throws DirectorException
static

By using the people database find an unused uid between two given limits.

References sfi.director.util.Tools.findFreeNumber().

static int sfi.director.util.Tools.findUidNumber ( int  start) throws DirectorException
static

By using the people database find an unused uid number higher than the specified start limit.

Referenced by sfi.director.util.Tools.applyModifier(), and sfi.director.cli.debug.debug().

static int sfi.director.util.Tools.findUidNumber ( int  start,
int  end 
) throws DirectorException
static

By using the people database find an unused uid between two given limits.

References sfi.director.util.Tools.findFreeNumber().

static Enumeration sfi.director.util.Tools.getHostnames ( String  name)
static

Get all names of a specific host/alias from the hosts directory.

Also expand "localhost" to the name of the local host, "MasterHost" to the name of the master.

References sfi.director.repository.config.DirectoryAccess.get(), sfi.director.util.Setup.hostname, sfi.director.util.Setup.hostsdir, and sfi.director.util.Setup.masterhost.

Referenced by sfi.director.application.scripttask.DomainBuild.create().

static Hashtable sfi.director.util.Tools.getOpt ( String  args[],
String  argopts[] 
) throws ArgumentException
static

Process command line arguments.

Besides returning processed options to the calling procedure this also sets the progOptions variable.

Parameters
argsThe command line arguments as passed to the main() method
argoptsThe acceptable command line arguments
Returns
a Hashtable where the keys are option names and the elements are vectors of strings containing argument values, resp. a non-null object for 'boolean' arguments
See Also
progOptions

References sfi.director.util.Tools.progOptions.

Referenced by sfi.director.cli.class_define.main(), and sfi.director.cli.sfidirector.main().

static String sfi.director.util.Tools.getUser ( )
static
static Hashtable sfi.director.util.Tools.hashtable ( Enumeration  list)
static

build a hash table from an Enumeration with key/value being both the respective objects

static boolean sfi.director.util.Tools.isHostReady ( String  hostname)
static
static String sfi.director.util.Tools.join ( Vector  list,
String  separator 
)
static
static String sfi.director.util.Tools.join ( Enumeration  list,
String  separator 
)
static

Join the string representation of an enumeration of strings into one single resulting string.

static void sfi.director.util.Tools.log ( LogEntry  log)
static

Log a message.

References sfi.director.util.Logger.log(), and sfi.director.util.Setup.logger.

Referenced by sfi.director.invoker.StreamConnection.agentlistener(), sfi.director.repository.DivertDB.append(), sfi.director.repository.config.DirectoryAccess.apply(), sfi.director.util.Tools.applyModifier(), sfi.director.application.DEBPackageHandler.aptPkgFromFile(), sfi.director.util.Tools.attachErrorLogger(), sfi.director.application.HostPackages.autosubscribe(), sfi.director.util.Tools.backupFile(), sfi.director.invoker.RSHInvoker.bootstrap(), sfi.director.cli.build.buildAll(), sfi.director.application.autodoc.ConfigFile.citeFile(), sfi.director.application.autodoc.DocBuilder.cleanDocMedia(), sfi.director.util.Logger.clearLoggers(), sfi.director.application.autodoc.CollectWinWMIHW.collect(), sfi.director.application.autodoc.CollectWinWMIPartitions.collect(), sfi.director.application.autodoc.CollectWinWMIApps.collect(), sfi.director.application.autodoc.CollectLshw.collect(), sfi.director.application.autodoc.CollectServices.collect(), sfi.director.application.autodoc.InfoCollector.collectInto(), sfi.director.repository.GenericDriver.connect(), sfi.director.executor.CmdExecutor.connect(), sfi.director.application.scripttask.FireEvent.create(), sfi.director.application.scripttask.ReloadService.create(), sfi.director.application.scripttask.ZoneUpdated.create(), sfi.director.application.scripttask.D3HostDefine.create(), sfi.director.application.scripttask.BootStrapDirector.create(), sfi.director.application.scripttask.ClassMemberApply.create(), sfi.director.application.scripttask.AppInstallHost.createPackage(), sfi.director.application.config.RestoreConfigEnvironment.currentFilename(), sfi.director.application.InstallerOpenLDAP.delDB(), sfi.director.schedule.ParallelScheduler.detach(), sfi.director.application.objevents.Workflow.doEvent(), sfi.director.util.Tools.doEvent(), sfi.director.application.autodoc.DocBuilder.domaindoc(), sfi.director.cli.create.edit(), sfi.director.application.FrontendHTTPServer.emulateRootUser(), sfi.director.application.scripttask.WakeOnLan.exec(), sfi.director.application.executor.appInventoryPush.exec(), sfi.director.application.executor.scanRepositoryPush.exec(), sfi.director.application.scripttask.ChainEvent.exec(), sfi.director.application.scripttask.ApplyDomainTemplate.exec(), sfi.director.application.scripttask.ZoneUpdated.exec(), sfi.director.application.scripttask.StoreAsDBChoice.exec(), sfi.director.application.executor.InstallFromArchive.exec(), sfi.director.application.scripttask.ReloadService.exec(), sfi.director.application.scripttask.BuildDependingDomains.exec(), sfi.director.application.scripttask.CreateHomeDB.exec(), sfi.director.application.executor.InstallFromZIP.exec(), sfi.director.util.Tools.execFilter(), sfi.director.schedule.ParallelScheduler.executeCmd(), sfi.director.schedule.Scheduler.executeCmd(), sfi.director.application.FrontendInterface.executeCommand(), sfi.director.invoker.Recorder.executeJob(), sfi.director.schedule.Scheduler.executePendingDSUpdate(), sfi.director.util.Credentials.fileCredentials(), sfi.director.schedule.ParallelScheduler.finalize(), sfi.director.application.HostPackages.forPkg(), sfi.director.application.DirectorPackage.freeze(), sfi.director.application.Report.generate(), sfi.director.util.MyProperties.getPropertyBoolean(), sfi.director.util.MyProperties.getPropertyInteger(), sfi.director.schedule.ParallelScheduler.goThroughQueue(), sfi.director.schedule.SimpleScheduler.goThroughVector(), sfi.director.repository.NCUserSettingsFile.init(), sfi.director.application.config.ConfigEngine.init(), sfi.director.application.autodoc.DocBuilder.insertDependencyGraph(), sfi.director.application.DirectorPackage.install(), sfi.director.application.InstallerOpenLDAP.installSchema(), sfi.director.application.DEBPackageHandler.inventory(), sfi.director.invoker.StreamConnection.leanBackAndWait(), sfi.director.application.AdminServer.listen(), sfi.director.util.Lock.Lock(), sfi.director.util.Tools.log(), sfi.director.invoker.StreamConnection.masterlistener(), sfi.director.util.BackgroundProcessMonitor.monitor(), sfi.director.schedule.Scheduler.notifyServer(), sfi.director.application.objevents.Workflow.openMonitor(), sfi.director.schedule.ParallelScheduler.parallelizedExec(), sfi.director.application.SUNPackageHandler.pkgsFromCommand(), sfi.director.cli.serverstatus.printStatus(), sfi.director.schedule.Scheduler.purgeOldJobs(), sfi.director.application.config.GenericFileHandler.readConfig(), sfi.director.schedule.ParallelScheduler.removeOldJobs(), sfi.director.schedule.Scheduler.removeOldJobs(), sfi.director.application.config.RestartServer.restart(), sfi.director.application.config.ConfigFileHandler.restore(), sfi.director.application.config.ConfigEngine.restore(), sfi.director.application.autodoc.DocExtDocu.retrieve(), sfi.director.cli.docrefetch.run(), sfi.director.application.config.RunCommand.run(), sfi.director.cli.init.run(), sfi.director.cli.shutdown.run(), sfi.director.cli.replay.run(), sfi.director.cli.mkdepend.run(), sfi.director.cli.serverstatus.run(), sfi.director.cli.app_subscribe.run(), sfi.director.cli.queueworker.run(), sfi.director.cli.frinterface.run(), sfi.director.schedule.Scheduler.runThroughCmdQueue(), sfi.director.schedule.Scheduler.runThroughLockedQueue(), sfi.director.application.config.ConfigDir.save(), sfi.director.schedule.ParallelScheduler.saveQueue(), sfi.director.application.PackageManager.scanRepository(), sfi.director.application.DirectorPackage.scanRepository(), sfi.director.application.FrontendHTTPServer.serve(), sfi.director.util.Init.set_db(), sfi.director.jobs.Job.setStatus(), sfi.director.util.Init.setup_base(), sfi.director.util.Init.setup_objectregistry(), sfi.director.repository.JDBC.setURL(), sfi.director.repository.LDAP.setURL(), sfi.director.repository.LDAPndk.setURL(), sfi.director.application.AdminServer.startListen(), sfi.director.application.RPMPackageHandler.targetInstallPkgs(), sfi.director.application.DEBPackageHandler.targetInstallPkgs(), sfi.director.application.RPMPackageHandler.targetRemovePkgs(), sfi.director.application.DEBPackageHandler.targetRemovePkgs(), sfi.director.cli.sfidirector.trackJob(), sfi.director.util.Tools.trackJob(), sfi.director.repository.transform.ExpandGroupOfGroups.transform(), sfi.director.repository.DBSet.transform(), sfi.director.util.Lock.unlock(), sfi.director.application.scripttask.ZoneUpdated.updateSerial(), sfi.director.util.Tools.waitThreads(), sfi.director.application.autodoc.CollectWinProxy.wmiData(), and sfi.director.util.Tools.workingWaitFor().

static void sfi.director.util.Tools.log ( int  level,
String  message 
)
static

Log a message at the specified priority level.

References sfi.director.util.Tools.log().

static void sfi.director.util.Tools.main ( String  args[])
static
static void sfi.director.util.Tools.makeZip ( File  what,
String  prefix,
OutputStream  out 
) throws DirectorException
static

Zip the given file and send the zip file to the given stream.

If the file to be zipped is a directory it will be zipped recursively. The name of the file in the ZIP archive is passed via the prefix argument.

Referenced by sfi.director.application.executor.ZIPit.exec(), sfi.director.application.DirectorPackage.freeze(), sfi.director.util.Tools.main(), and sfi.director.util.Tools.makeZip().

static void sfi.director.util.Tools.makeZip ( File  what,
String  prefix,
ZipOutputStream  out 
) throws DirectorException
static
static MessageDigest sfi.director.util.Tools.md5sum ( File  file) throws DirectorException
static

Compute md5 checksum for a file.

Referenced by sfi.director.application.autodoc.InfoCollector.push().

static MessageDigest sfi.director.util.Tools.md5sum ( InputStream  in) throws DirectorException
static

Compute md5 checksum for a file.

References sfi.director.util.Tools.digestData().

static String sfi.director.util.Tools.minTimeStamp ( )
static

Return a string representing the current time in a format in minute precision only.

Referenced by sfi.director.util.Tools.applyModifier().

static int sfi.director.util.Tools.readEntire ( InputStream  in,
byte  buffer[],
int  offset,
int  length 
) throws IOException
static

Read a block of data from an InputStream.

Unlike the original InputStream.read() method, this utility function reads exactly the given number of bytes, unless eof is reached.

Returns
the number of bytes that were read

Referenced by sfi.director.application.autodoc.InfoCollector.push(), and sfi.director.util.Tools.readEntire().

static int sfi.director.util.Tools.readEntire ( InputStream  in,
byte  buffer[],
int  length 
) throws IOException
static

Read a block of data from an InputStream.

Unlike the original InputStream.read() method, this utility function reads exactly the given number of bytes, unless eof is reached.

Returns
the number of bytes that were read

References sfi.director.util.Tools.readEntire().

static String sfi.director.util.Tools.readEntireText ( BufferedReader  in,
boolean  closeOnExit 
) throws IOException
static
static String sfi.director.util.Tools.readEntireText ( File  in) throws IOException
static
static String sfi.director.util.Tools.readEntireText ( InputStream  in,
boolean  closeOnExit 
) throws IOException
static
static void sfi.director.util.Tools.rememberCleanup ( CleanUpable  cleanup)
static

Mark an object as to be cleaned up by exit().

Referenced by sfi.director.util.SyslogThread.SyslogThread(), and sfi.director.util.TempFile.TempFile().

static void sfi.director.util.Tools.removeDir ( File  dir) throws DirectorException
static
static Vector sfi.director.util.Tools.runParsePerl ( String  split,
String  code,
String  args[] 
) throws DirectorException
static
static Object sfi.director.util.Tools.saveOurClass ( Object  anInstance)
static

Classes of objects registered via this method are protected against the class garbage collection.

Early versions of Java used to love kicking out classes no matter if they contained valuable static information. Director classes which prefer to keep their static information will register via saveOurClass()

References sfi.director.util.Tools.classRefs.

static String sfi.director.util.Tools.secUniqId ( )
static
static void sfi.director.util.Tools.setThreadSubStatus ( String  status)
static
static String [] sfi.director.util.Tools.ShellCommand ( String  command)
static

Accepts a shell command string, returns a String array containing the same command ready for execution via exec() and the system's command shell.

Typically, e.g. "echo abc" will be translated into { "/bin/sh", "-c", "echo abc" }. This is thought to become platform-independent once we support non-UNIX platforms, so on a windows system this might return something like { "cmd.exe", "/c", "echo abc" }.

References sfi.director.util.Setup.iswindows.

Referenced by sfi.director.application.DEBPackageHandler.aptInstall(), sfi.director.executor.CmdExecutor.connect(), sfi.director.application.scripttask.ZoneUpdated.exec(), sfi.director.application.scripttask.ReloadService.exec(), sfi.director.util.Tools.exit(), sfi.director.application.SUNPackageHandler.install(), sfi.director.application.DEBPackageHandler.inventoryPkg(), sfi.director.application.DEBPackageHandler.makeTaskPackage(), sfi.director.application.autodoc.sinfo.InfoCmd.mkInfo(), sfi.director.application.config.GenericFileHandler.performPostRestore(), sfi.director.application.SUNPackageHandler.remove(), and sfi.director.retriever.PipeRetriever.setupExec().

static void sfi.director.util.Tools.shutdown ( )
static

Try to do some cleanup before system shutdown.

Release locks, force garbage collection, run finalization.

References sfi.director.util.Setup.scheduler, and sfi.director.util.Lock.shutdown().

Referenced by sfi.director.util.Tools.exit().

static void sfi.director.util.Tools.sort ( Vector  v,
MyComparator  c 
)
static
static void sfi.director.util.Tools.sort ( Object  arr[],
MyComparator  c 
)
static

Sort an array in the order specified by the given comparator.

See Also
MyComparator

References sfi.director.util.MyComparator.compare().

static Vector sfi.director.util.Tools.split ( String  str,
String  separator 
)
static

Split a string into a vector of strings.

Split at positions where the separator string is located at the same time dropping the separator string. This is similiar but not identical to using StringTokenizers.

Referenced by sfi.director.application.autodoc.ConfigFile.addAlternativeSpec(), sfi.director.application.PackageList.addPackages(), sfi.director.repository.transform.AD2User.applyDefaults(), sfi.director.util.Tools.applyModifier(), sfi.director.system.SystemArchitecture.architecture(), sfi.director.repository.NISTable.close(), sfi.director.application.autodoc.CollectUnixPartitions.collect(), sfi.director.application.autodoc.CollectConfigFiles.collect(), sfi.director.application.autodoc.DependencyGraph.compute(), sfi.director.repository.transform.Script.connect(), sfi.director.application.scripttask.Shell.create(), sfi.director.application.scripttask.PublishApplication.create(), sfi.director.repository.PopmapFile.decode(), sfi.director.repository.ShadowFile.decode(), sfi.director.repository.ApacheGroupFile.decode(), sfi.director.repository.SambaPasswdFile.decode(), sfi.director.repository.BootparamsFile.decode(), sfi.director.repository.MailertableFile.decode(), sfi.director.repository.GroupFile.decode(), sfi.director.repository.AutomounterFile.decode(), sfi.director.repository.FileWrapperDB.decode(), sfi.director.repository.ServicesFile.decode(), sfi.director.repository.HostsFile.decode(), sfi.director.repository.TimezoneFile.decode(), sfi.director.repository.ApachePasswdFile.decode(), sfi.director.repository.ProtocolsFile.decode(), sfi.director.repository.CupsPrintersFile.decode(), sfi.director.repository.PasswdFile.decode(), sfi.director.repository.NidumpFile.decode_nidump(), sfi.director.repository.NetgroupFile.decodeEntry(), sfi.director.application.FrontendHTTPServer.edit_data(), sfi.director.application.config.SendmailMasquerade.emit(), sfi.director.application.config.SendmailCW.emit(), sfi.director.application.config.SimpleKeyHandler.emit(), sfi.director.application.config.NTPConf.emit(), sfi.director.repository.NameListFile.encode(), sfi.director.repository.VirtusertableFile.encode(), sfi.director.repository.transform.NISfromNetgroup.encodeEntry(), sfi.director.repository.NCOdbcIniFile.encodeEntry(), sfi.director.application.executor.scanRepositoryPush.exec(), sfi.director.application.FrontendInterface.executeCommand(), sfi.director.application.DaemonObjectEdit.expand(), sfi.director.gui.importers.PasswordHash.exportRecord(), sfi.director.util.Tools.fieldToDBObject(), sfi.director.application.FrontendHTTPServer.fillRel(), sfi.director.application.PackageList.findPackage(), sfi.director.repository.config.AppPackages.get(), sfi.director.cli.create.getBase(), sfi.director.application.autodoc.DocInfo.getDocOpts(), sfi.director.application.autodoc.DocInfo.getImageOpts(), sfi.director.application.DirectorPackage.getInfo(), sfi.director.util.Options.getOptionsStrings(), sfi.director.repository.SchemaEnforcer.getSchemaEnforcer(), sfi.director.application.autodoc.CollectUnixPartitions.guessDisks(), sfi.director.cli.help.help(), sfi.director.application.autodoc.DocBuilder.hostdoc(), sfi.director.util.ImageInfo.identify(), sfi.director.application.Director3PackageHandler.inventory(), sfi.director.application.RPMPackageHandler.inventory(), sfi.director.application.DEBPackageHandler.makeDependency(), sfi.director.application.executor.InstallFromZIP.mangleName(), sfi.director.application.autodoc.sinfo.InfoCmd.mkInfo(), sfi.director.application.AdminServer.oneConnection(), sfi.director.application.DEBPackageHandler.parseDepends(), sfi.director.repository.JDBC.parseDN(), sfi.director.repository.LDIFTree.path(), sfi.director.repository.LDIFDir.path(), sfi.director.cli.create.prettyPrint(), sfi.director.cli.serverstatus.printStatus(), sfi.director.application.scripttask.AppInstallHost.pushScheduled(), sfi.director.repository.DN.RDNattrs(), sfi.director.application.PackageList.remove(), sfi.director.application.executor.appInventory.rpmInventory(), sfi.director.cli.copy.run(), sfi.director.cli.app_subscribe.run(), sfi.director.cli.frinterface.run(), sfi.director.util.Tools.runParsePerl(), sfi.director.application.scripttask.ConfigHost.save(), sfi.director.application.config.Automounter.saveFile(), sfi.director.application.PackageManager.scanRepository(), sfi.director.application.DirectorPackage.scanRepository(), sfi.director.repository.LDIFTree.search(), sfi.director.repository.LDAP.search(), sfi.director.repository.LDAPndk.search(), sfi.director.application.autodoc.ServiceDepContainer.serviceBySpec(), sfi.director.util.Options.setOption(), sfi.director.application.DirectorPackage.setRelease(), sfi.director.util.Init.setup_base(), sfi.director.application.autodoc.InfoCollector.setupProxy(), sfi.director.repository.OnDemandDBConnection.setURL(), sfi.director.application.executor.appInventory.sfiInventory(), sfi.director.application.PackageList.sort(), sfi.director.util.Tools.split(), sfi.director.application.PackageManager.stringToPkg(), sfi.director.application.DirectorPackage.topkgdb(), sfi.director.gui.fields.Application.toString(), sfi.director.util.LogEntry.toVector(), sfi.director.repository.transform.ADProxyAddresses.transform(), sfi.director.repository.transform.HostAssignedGroups.transform(), sfi.director.repository.transform.NISfromMailaliases.transform(), sfi.director.repository.transform.HostAssignedUsers.transform(), sfi.director.repository.transform.ReDN.transform(), sfi.director.repository.transform.NISfromRevNetgroup.transform(), sfi.director.repository.transform.Mail2Netscape.transform(), and sfi.director.application.PackageList.versionCompare().

static Vector sfi.director.util.Tools.split ( String  str)
static

Split a string into a vector of strings.

Split at whitespace locations where 'whitespace' is one or more spaces or tabs.

References sfi.director.util.Tools.split().

static String sfi.director.util.Tools.stacktrace ( Throwable  e)
static
static String sfi.director.util.Tools.ticketid ( )
static
static String sfi.director.util.Tools.timeStamp ( )
static
static String sfi.director.util.Tools.timeStamp ( Date  time)
static

Return a string representing the passed time in a (director) standard format.

static Record sfi.director.util.Tools.toDBEditRecord ( DBObject  dbo)
static
static DBObject sfi.director.util.Tools.toDBObject ( Record  rec)
static
static void sfi.director.util.Tools.trackJob ( Workflow  workflow) throws DirectorException
static
static synchronized String sfi.director.util.Tools.uniqId ( )
static
static void sfi.director.util.Tools.waitThreads ( long  timeout)
static
static int sfi.director.util.Tools.workingWaitFor ( Process  process,
boolean  outConsumed,
boolean  errorConsumed 
) throws InterruptedException
static
static int sfi.director.util.Tools.workingWaitFor ( Process  process,
boolean  outConsumed,
boolean  errorConsumed,
final long  timeout 
) throws InterruptedException
static

do a Process.waitFor() and consume the exec()-ed commands output in order to avoid hangs.

References sfi.director.util.Tools.consume(), sfi.director.util.Tools.log(), sfi.director.util.StoppableThread.stopGracefully(), and sfi.director.util.Logger.WARNING.

Member Data Documentation

Vector sfi.director.util.Tools.classRefs = new Vector()
static

Vector used to store references to classes for the saveOurClass mechanism.

See Also
saveOurClass( Object )

Referenced by sfi.director.util.Tools.saveOurClass().

int sfi.director.util.Tools.debuglev = 0
static
PrintStream sfi.director.util.Tools.debugout = System.err
static

The Stream where debug output is sent to.

Hashtable sfi.director.util.Tools.progOptions = new Hashtable()
static

This hash stores the command line options of the current program.

Referenced by sfi.director.util.Tools.getOpt().


The documentation for this class was generated from the following file: