CoG5
From Java CoG Kit
Contents |
About
This page contains notes about the new Java CoG Kit functionality that we discuss for the release of version 5. In version 5 we will make advantage of the new Java 5 features such as Generics and Collections.
Execution Management
Execution of Shell Scripts
Java CoG Kit 5 contains a new class that allows the convenient execution of small and short shell scripts. An example for its use is:
ScriptExecute script = new ScriptExecute();
script.setCommands("ifconfig -a | fgrep inet");
script.run();
System.out.println("Status: " + script.getStatus());
System.out.println("Output: " + script.getResult());
System.out.println("Output: " + script.getError());
The Status is defined as enumeration and can have the following values:
- ScriptStatus.DONE
- the command is done and returned sucessfully.
- ScriptStatus.FAILED
- the command has failed
- ScriptStatus.RUNNING
- the command is running
- ScriptStatus.PENDING
- the command is known, but we have not yet started the execution.
- ScriptStatus.PREPARING
- the command is prepared for execution
- ScriptStatus.UNDEFINED
- the status is undefined. this can be when a PipedExecute has just been initialized, but no command is jet known to execute
Internally the script is executed by writing it first to a file /tmp/tmp.sh to be executed by /bin/sh. However these are only the default values and can be overwritten by setScriptLocation and setShell. Please, note that the script file will be overwritten with each call.
Argument Parser
Document it here ...
Information Management
Sysinfo
At times it is necessary to cast decissions based on information one obtaines about a compute resource. The SysInfo command allows to query some information of the current system. This can be also useful when reporting bugs.
The Sysinfo class is also available as commandline tool. The man page [put link here] explains in more detail the functionality.
The options of the command are as follows
cog-sysinfo [-help]| [-all] |
[-os] [-user] [-java] [-ant] [-network] [-env]
[-attribute name[,name]*] -xml
-time
In addition to the local machine we will enehnace it to obtain information from remote machines through the following additional options.
[-host <name>] [-port <port> ] [-provider GT2|GT4|SSH ]
The format returned is by default an list of attribute: value pairs.
An example issued on MacOSX is
machine.os: Darwin java.version: 1.5.0_06 hw.memsize: 1073741824 java.class.path: /Users/vonLaszewski/cogkit/dist:... hw.usermem: 974176256 env.PATH: /usr/bin:/bin:/usr/sbin:/sbin env.HOME: /Users/vonlaszewski os.version: 10.4.6 java.class.version: 49.0 os.arch: ppc ant.version: 1.6.2 kern.boottime: Sun May 14 07:02:10 2006 env.APP_ICON_1539: ../Resources/Eclipse.icns java.home: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home env.SECURITYSESSIONID: d880c0 env.JAVA_MAIN_CLASS_1539: org.eclipse.core.launcher.Main user.name: laszewsk machine.name: mini.local os.name: Mac OS X hw.ncpu: 1 machine.kernel.version: 8.6.0 env.JAVA_MAIN_CLASS_22463: org.cogkit.etc.SysInfo env.USER: laszewsk env.SHELL: /bin/bash machine.processor: ppc7450 user.dir: /Users/laszewsk/Documents/workspace/Project8 user.home: /Users/laszewsk machine.processor.generic: powerpc user.cs_path: /usr/bin:/bin:/usr/sbin:/sbin java.vendor: Apple Computer, Inc. ant.path: /usr/bin/ant env.__CF_USER_TEXT_ENCODING: 0x1F6:0:0 ...
Other systems are going to be supported on demand and based on the users contributing them. We are planing Linux, Cygwin, and Windows XP.
The command is not designed for speed nor for frequent updates. it is a simple tool to retrieve some elementary parameters with little programming overhead. To show how fast the routine is we also have provided the ability to return the execution time with the -time option
Timer[0]: 1102 ms (gather information) Timer[1]: 295 ms (print the results)
We know this can be done faster, but as most of the values are not changing much it is not necessary to optimize it.
Please note that dynamic information such as system load, virtual memore, and filesystem use is not reported with SysInfo.
We plan to have a more streamline verion of this or you could use tools such as Ganglia.
Caching
To maintain some information about Objects of a Type T we have introduced an Information Cache interface. It is defined as follows:
package org.cogkit.information;
import java.util.Calendar;
import java.util.List;
public interface InformationCache<T> {
public abstract Calendar getLastAccess();
public abstract Calendar getLastChange();
public abstract Calendar getLastUpdate();
public abstract void set(String key, T value);
public abstract void set(String key, T value, long ttl);
public abstract T get(String key);
public abstract InformationElement<T> getElement(String key);
}
Note: we need to add getLast Function for individual keys
Although one may be tempted to use a normal Hash for this, Our cahce has a number of additional functions that allow us to monitor the access patterns to the cache itself. This is useful to develop advanced monitoring strategies As we will define in some of our more advanced classes.
It for example lets us know when a value was last changed. If we were to store the contents of a Sysinfo call in a Cache, and we would see that the values have not changed, there seems not to even be a reason to execute the sysinfo command. Naturally sysino does not take up much time, but on a Grid it is commen to excute programs that may run a considerable amount of time. Sometimes it seems good to store the results (in case they are costly t reproduce) and to simply refer to them from a cash.
Measuring Time
Often it is necessary to measure the time for a particular block of code. We have provided a simple StopWatch class that helps us to obtain times very easily. Out StopWatch can have n timers and can be controled with the methods start, pause, resurm, and stop. A timer can be individually printed by its number, or we can print out all timers at once.
Here is an example:
StopWatch watch = new StopWatch(2); watch.set(0, "name of timer 0"); watch.set(1, "name of timer 1"); watch.start(0); .... watch.stop(0); ... watch.start(1); .... watch.stop(1); watch.printTimers();
Note: we need to change the print to logger
The putput will look like
Timer[0]: 1102 ms (name of timer 0) Timer[1]: 295 ms (name of timer 1)
