Remote Administration Daemon Developer Guide

Exit Print View

Updated: July 2014
 
 

Rad Namespace

All RAD objects, which are represented in the ADR IDL as <interfaces>, are found by searching the RAD namespace. The key point to note is that to access a RAD object, you need a proxy, which is used to search the RAD namespace. This capability is provided by an interface proxy class, which is defined in each interface's binding module.

The proxy provides the base name (and version details) for interface instances and is structured as follows:

<domain name>:type=<interface name>[,optional additional key value pairs]

The <domain name> and the <interface name> are automatically derived from the ADR IDL definition and are stored in the module binding.

Searching for Objects

The Connection class provides mechanisms for listing objects by name and for obtaining a remote object reference.

Obtaining Reference to a Singleton

If a module developer creates a "singleton" to represent an interface, then this can be accessed very simply. For instance, the zonemgr module defines a singleton interface: ZoneInfo. It contains information about the zone which contains the RAD instance with which we are communicating.

In Java we need to compile our code with the language binding in our CLASSPATH. RAD Java Language bindings are in the:

system/management/rad/client/rad-java package.

The JAR files for the various bindings are installed in /usr/lib/rad/java. Each major interface version is accessible here in a JAR file which is named after the source ADR document and it's major version number. For instance, to access major version 1 of the zonemgr APIs, use /usr/lib/rad/java/zonemgr_1.jar. Symbolic links are provided as an indication of the "default" version a client should use.

Example 3-17  Obtaining Reference to a Singleton
import com.oracle.solaris.rad.connect.Connection;
import com.oracle.solaris.rad.zonemgr.ZoneInfo;

Connection con = Connection.connectUnix();
System.out.println("Connected: " + con.toString());
ZoneInfo zi = con.getObject(new ZoneInfo());
System.out.println("ZoneInfo: " + zi.getname());

We have imported ZoneInfo and Connection from our zonemgr binding and the rad.connect package, connected to the local RAD instance and obtained a remote object reference directly using a proxy instance. Once we have the remote reference we can access properties and method directly. In the RAD Java implementation all properties are accessed using getter/setter syntax. Thus to access the "name" property, we invoke getname().

Listing Instances of an Interface

Most interfaces contain more than one instance of the interface. For instance, the zonemgr module defines a Zone interface and there is an instance for each zone on the system. The Connection class provides the list_objects() method to list interface instances. For instance:

Example 3-18  Listing Interface Instances
import com.oracle.solaris.rad.client.ADRName;
import com.oracle.solaris.rad.connect.Connection;
import com.oracle.solaris.rad.zonemgr.Zone;
  
Connection con = Connection.connectUnix();
System.out.println("Connected: " + con.toString());

for (ADRName name: con.listObjects(new Zone())) {
    System.out.println("ADR Name: " + name.toString());
}

Obtaining a Remote Object Reference from a Name

A list of names (ADRName is the class name) are returned by the list_objects() method from the Connection class. Once we have a "name" we can obtain a remote object reference easily.

Example 3-19   Obtaining a Remote Object Reference from a Name
import com.oracle.solaris.rad.client.ADRName;
import com.oracle.solaris.rad.connect.Connection;
import com.oracle.solaris.rad.zonemgr.Zone;

Connection con = Connection.connectUnix();
System.out.println("Connected: " + con.toString());

for (ADRName name: con.listObjects(new Zone())) {
    Zone zone =  con.getObject(name);
    System.out.println("Name: " + zone.getname());
}

Sophisticated Searching

Clearly, the last example is not a very realistic use case. Rarely are we going to want to just pick a (semi-random) zone from a list and interact with it. More often than not we'll be looking for a zone which has a particular name or id or maybe a set of zones where the names all match some kind of pattern. The key idea to bear in mind is that you can extend the basic definition of a name provided by a Proxy. For instance, if zones are uniquely identified by a key: "name", then we can find a zone with name "test-0" as follows:

Example 3-20  Using Glob Patterns
import com.oracle.solaris.rad.client.ADRName;
import com.oracle.solaris.rad.client.ADRGlobPattern;
import com.oracle.solaris.rad.connect.Connection;
import com.oracle.solaris.rad.zonemgr.Zone;
   
Connection con = Connection.connectUnix();
System.out.println("Connected: " + con.toString());

String keys[] = { "name" };
String values[] = { "test-0" };
ADRGlobPattern pat = new ADRGlobPattern(keys, values);
for (ADRName name: con.listObjects(new Zone(), pat)) {
    System.out.println("ADR Name: " + name.toString());
}

In this example, the ADRGlobPattern class (imported from the com.oracle.solaris.rad.client package) is used to refine the search. The list_objects() method from the Connection class is used, but the search is refined by extending the name definition. ADRGlobPattern takes an array of keys and an array of values and extends the name used in the search.

Glob Pattern Searching

We've already seen how we can use glob pattern searching to find a zone with a specific name. We can also use a glob pattern to find zones with wildcard pattern matching. Keys or Values in the pattern may contain "*" which is interpreted as expected. For instance if we wanted to find all zones with a name which begins with "test":

Example 3-21   Using Glob Patterns with Wildcards
import com.oracle.solaris.rad.client.ADRName;
import com.oracle.solaris.rad.client.ADRGlobPattern;
import com.oracle.solaris.rad.connect.Connection;
import com.oracle.solaris.rad.zonemgr.Zone;

Connection con = Connection.connectUnix();
System.out.println("Connected: " + con.toString());

String keys[] = { "name" };
String values[] = { "test*" };
ADRGlobPattern pat = new ADRGlobPattern(keys, values);
for (ADRName name: con.listObjects(new Zone(), pat)) {
    System.out.println("ADR Name: " + name.toString());
}
Using Maps when Pattern Searching

It can be more convenient to use Maps rather than arrays of keys/values. Here is the previous example re-worked to use a Map of keys/values rather than arrays of keys/values.

Example 3-22   Using Maps with Patterns
import com.oracle.solaris.rad.client.ADRName;
import com.oracle.solaris.rad.client.ADRGlobPattern;
import com.oracle.solaris.rad.connect.Connection;
import com.oracle.solaris.rad.zonemgr.Zone;
    
Connection con = Connection.connectUnix();
System.out.println("Connected: " + con.toString());

Map<String, String> kvpairs = new HashMap<String, String>();
kvpairs.put("name", "test*");
ADRGlobPattern pat = new ADRGlobPattern(kvpairs);
for (ADRName name: con.listObjects(new Zone(), pat)) {
    System.out.println("ADR Name: " + name.toString());
}
Regex Pattern Searching

We can also take advantage of RAD's ERE (Extended Regular Expression) search capabilities. If we wanted to find only zones with name "test-0" or "test-1", then:

Example 3-23   Using Regex Patterns
import com.oracle.solaris.rad.client.ADRName;
import com.oracle.solaris.rad.client.ADRRegexPattern;
import com.oracle.solaris.rad.connect.Connection;
import com.oracle.solaris.rad.zonemgr.Zone;
   
Connection con = Connection.connectUnix();
System.out.println("Connected: " + con.toString());

String keys[] = { "name" };
String values[] = { "test-0|test-1" };
ADRRegexPattern pat = new ADRRegexPattern(keys, values);
for (ADRName name: con.listObjects(new Zone(), pat)) {
    System.out.println("ADR Name: " + name.toString());
}

The key and the value must be valid Extended Regular Expressions as determined by the instance of RAD to which you are connected. (i.e.: the expression is compiled and executed on the server.)