Java AFS API v1.4

org.openafs.jafs
Class Server

java.lang.Object
  |
  +--org.openafs.jafs.Server
All Implemented Interfaces:
Comparable, Serializable

public class Server
extends Object
implements Serializable, Comparable

An abstract representation of an AFS server. It holds information about the server, such as what its processes are.

Constructing an instance of a Server does not mean an actual AFS server is created and added to a cell -- on the contrary, a Server object must be a representation of an already existing AFS server. There is no way to create a new AFS server through this API. See OpenAFS.org for information on how to create a new AFS server.

A Server object may represent either an AFS file server, an AFS database server, or both if the same machine serves both purposes.

Each Server object has its own individual set of Partitions, Processes, and Keys. This represents the properties and attributes of an actual AFS server.

The following is a simple example of how to construct and use a Server object. This example constructs a Server using the Cell representing teh AFS cell to which the server belongs, and prints out the names of all the partitions residing on the server.

 import org.openafs.jafs.Cell;
 import org.openafs.jafs.AFSException;
 import org.openafs.jafs.Partition;
 import org.openafs.jafs.Server;
 ...
 public class ...
 {
   ...
   private Cell cell;
   private Server server;
   ...
   public static void main(String[] args) throws Exception
   {
     String username   = arg[0];
     String password   = arg[1];
     String cellName   = arg[2];
     String serverName = arg[3];
 
     token = new Token(username, password, cellName);
     cell   = new Cell(token);
     server = new Server(serverName, cell);
 
     System.out.println("Partitions in Server " + server.getName() + ":");
     if( server.isFileServer() ) {
       Partition[] partitions = server.getPartitions();
       for (int i = 0; i < partitions.length; i++) {
         System.out.println(" -> " + partitions[i]);
       }
     }
   }
   ...
 }
 

See Also:
Serialized Form

Nested Class Summary
static class Server.ExecutableTime
           
 
Constructor Summary
Server(String name, Cell cell)
          Constructs a new Server object instance given the name of the AFS server and the AFS cell, represented by cell, to which it belongs.
Server(String name, Cell cell, boolean preloadAllMembers)
          Constructs a new Server object instance given the name of the AFS server and the AFS cell, represented by cell, to which it belongs.
 
Method Summary
 void addAdmin(User admin)
          Add a bos admin to the UserList file of this server, in order to given the AFS user represented by admin full bos administrative privileges on this server.
 void close()
          Unauthenticates all server-related tokens that have been obtained by this Server object, and shuts this server object down.
 int compareTo(Object obj)
          Comparable interface method.
 int compareTo(Server server)
          Compares two Server objects respective to their names and does not factor any other attribute.
 boolean equals(Server otherServer)
          Tests whether two Server objects are equal, based on their names and hosting Cell.
 int getAdminCount()
          Returns the number of BOS administrators assigned to this server.
 String[] getAdminNames()
          Retrieves an array containing all of the names of bos admins associated with this Server.
 User[] getAdmins()
          Retrieves an array containing all of the admin User objects associated with this Server, each of which are an abstract representation of an actual bos administrator of the AFS server.
 Server.ExecutableTime getBinaryRestartTime()
          Returns the BOS Server's binary restart time in the form of an ExecutableTime object.
 Cell getCell()
          Returns the Cell object with which this Server was constructed.
 Server.ExecutableTime getGeneralRestartTime()
          Returns the BOS Server's general restart time in the form of an ExecutableTime object.
 String[] getIPAddresses()
          Returns this server's IP address as a String.
 Key getKey(int keyVersion)
          Retrieves the Key object (which is an abstract representation of an actual AFS partition of this server) designated by nkeyVersion.
 int getKeyCount()
          Returns the number of keys on this server.
 Key[] getKeys()
          Retrieves an array containing all of the Key objects associated with this Server, each of which are an abstract representation of an actual AFS key of the AFS server.
 String getLog(String logLocation)
          Gets the contents of a log file, in one large String.
 String getName()
          Returns the name of this server.
 Partition getPartition(String name)
          Retrieves the Partition object (which is an abstract representation of an actual AFS partition of this server) designated by name (i.e.
 int getPartitionCount()
          Returns the number of partitions on this server.
 String[] getPartitionNames()
          Retrieves an array containing all of the names of partitions associated with this Server (i.e.
 Partition[] getPartitions()
          Retrieves an array containing all of the Partition objects associated with this Server, each of which are an abstract representation of an actual AFS partition of the AFS server.
 Process getProcess(String name)
          Retrieves the Process object (which is an abstract representation of an actual AFS process of this server) designated by name (i.e.
 int getProcessCount()
          Returns the number of processes hosted by this server.
 Process[] getProcesses()
          Retrieves an array containing all of the Process objects associated with this Server, each of which are an abstract representation of an actual AFS process of the AFS server.
 String[] getProcessNames()
          Retrieves an array containing all of the names of processes associated with this Server (i.e.
 int getTotalFreeSpace()
          Returns the total free space on this server (a sum of the free space of all the partitions associated with this server).
 int getTotalSpace()
          Returns the total space on this server (a sum of the space of all the partitions associated with this server).
 int getTotalUsedSpace()
          Returns the total used space on this server (a sum of the used space of all the partitions associated with this server).
 boolean isBadDatabase()
          Returns whether or not this server is a database machine AND either it isn't in reality (e.g. it's incorrectly configured) or it's currently down.
 boolean isBadFileServer()
          Returns whether this machine thinks it's a file server AND either it isn't in reality (e.g. it's incorrectly configured) or it's currently down.
 boolean isDatabase()
          Returns whether or not this server is a database machine, meaning it runs processes such as the "kaserver" and "vlserver", and participates in elections.
 boolean isFileServer()
          Returns whether or not this server is a file server machine, meaning it runs the "fs" process and stores AFS volumes.
 void refresh()
          Refreshes the properties of this Server object instance with values from the AFS server it represents.
 void removeAdmin(User admin)
          Remove a bos admin from the UserList file of this server, in order to take away from the AFS user represented by admin bos administrative privileges on this machine.
 void restartAllProcesses()
          Restarts all bos processes on this server.
 void restartBosServer()
          Restarts bos server and all bos processes on this server.
 void salvage()
          Salvages (restores consistency to) this server.
 void setBinaryRestartTime(Server.ExecutableTime executableTime)
          Sets the BOS binary restart time.
 void setGeneralRestartTime(Server.ExecutableTime executableTime)
          Sets the BOS general restart time.
 void startAllProcesses()
          Starts up all bos processes on this server.
 void stopAllProcesses()
          Stops all bos processes on this server.
 void syncServer()
          Syncs this server to the VLDB.
 void syncVLDB()
          Syncs the VLDB to this server.
 String toString()
          Returns the name of this Server
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Server

public Server(String name,
              Cell cell)
       throws AFSException
Constructs a new Server object instance given the name of the AFS server and the AFS cell, represented by cell, to which it belongs. This does not actually create a new AFS server, it just represents an existing one. If name is not an actual AFS server, exceptions will be thrown during subsequent method invocations on this object.

Parameters:
name - the name of the server to represent
cell - the cell to which the server belongs.
Throws:
AFSException - If an error occurs in the native code

Server

public Server(String name,
              Cell cell,
              boolean preloadAllMembers)
       throws AFSException
Constructs a new Server object instance given the name of the AFS server and the AFS cell, represented by cell, to which it belongs. This does not actually create a new AFS server, it just represents an existing one. If name is not an actual AFS server, exceptions will be thrown during subsequent method invocations on this object.

This constructor is ideal for point-in-time representation and transient applications. It ensures all data member values are set and available without calling back to the filesystem at the first request for them. Use the refresh() method to address any coherency concerns.

Parameters:
name - the name of the server to represent
cell - the cell to which the server belongs.
preloadAllMembers - true will ensure all object members are set upon construction; otherwise members will be set upon access, which is the default behavior.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()
Method Detail

refresh

public void refresh()
             throws AFSException
Refreshes the properties of this Server object instance with values from the AFS server it represents. All properties that have been initialized and/or accessed will be renewed according to the values of the AFS server this Server object instance represents.

Since in most environments administrative changes can be administered from an AFS command-line program or an alternate GUI application, this method provides a means to refresh the Java object representation and thereby ascertain any possible modifications that may have been made from such alternate administrative programs. Using this method before an associated instance accessor will ensure the highest level of representative accuracy, accommodating changes made external to the Java application space. If administrative changes to the underlying AFS system are only allowed via this API, then the use of this method is unnecessary.

Throws:
AFSException - If an error occurs in the native code

addAdmin

public void addAdmin(User admin)
              throws AFSException
Add a bos admin to the UserList file of this server, in order to given the AFS user represented by admin full bos administrative privileges on this server.

Parameters:
admin - the admin to add
Throws:
AFSException - If an error occurs in the native code

removeAdmin

public void removeAdmin(User admin)
                 throws AFSException
Remove a bos admin from the UserList file of this server, in order to take away from the AFS user represented by admin bos administrative privileges on this machine.

Parameters:
admin - the admin to remove
Throws:
AFSException - If an error occurs in the native code

syncServer

public void syncServer()
                throws AFSException
Syncs this server to the VLDB.

Throws:
AFSException - If an error occurs in the native code

syncVLDB

public void syncVLDB()
              throws AFSException
Syncs the VLDB to this server.

Throws:
AFSException - If an error occurs in the native code

salvage

public void salvage()
             throws AFSException
Salvages (restores consistency to) this server. Uses default values for most salvager options in order to simplify the API.

Throws:
AFSException - If an error occurs in the native code

startAllProcesses

public void startAllProcesses()
                       throws AFSException
Starts up all bos processes on this server.

Throws:
AFSException - If an error occurs in the native code

stopAllProcesses

public void stopAllProcesses()
                      throws AFSException
Stops all bos processes on this server.

Throws:
AFSException - If an error occurs in the native code

restartAllProcesses

public void restartAllProcesses()
                         throws AFSException
Restarts all bos processes on this server.

Throws:
AFSException - If an error occurs in the native code

restartBosServer

public void restartBosServer()
                      throws AFSException
Restarts bos server and all bos processes on this server.

Throws:
AFSException - If an error occurs in the native code

getLog

public String getLog(String logLocation)
              throws AFSException
Gets the contents of a log file, in one large String. The log cannot be in AFS file space.

Returns:
a String containing the contents of the log file
Throws:
AFSException - If an error occurs in the native code

close

public void close()
           throws AFSException
Unauthenticates all server-related tokens that have been obtained by this Server object, and shuts this server object down. This method should only be called when this Server or any of the objects constructed using this Server will not be used anymore. Note that this does not effect the actual AFS server; it merely closes the representation.

Throws:
AFSException - If an error occurs in the native code

getName

public String getName()
Returns the name of this server.

Returns:
the name of this server

getCell

public Cell getCell()
Returns the Cell object with which this Server was constructed. It represents the actual AFS cell to which this server belongs.

Returns:
this server's cell

getAdminCount

public int getAdminCount()
                  throws AFSException
Returns the number of BOS administrators assigned to this server.

If the total list of admins or admin names have already been collected (see getAdmins()), then the returning value will be calculated based upon the current list. Otherwise, AFS will be explicitly queried for the information.

The product of this method is not saved, and is recalculated with every call.

Returns:
the number of admins on this server.
Throws:
AFSException - If an error occurs in any of the associated native methods
See Also:
getAdmins(), getAdminNames()

getAdmins

public User[] getAdmins()
                 throws AFSException
Retrieves an array containing all of the admin User objects associated with this Server, each of which are an abstract representation of an actual bos administrator of the AFS server. After this method is called once, it saves the array of Users and returns that saved array on subsequent calls, until the refresh() method is called and a more current list is obtained.

Returns:
a User array of the admins of the server.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getAdminNames

public String[] getAdminNames()
                       throws AFSException
Retrieves an array containing all of the names of bos admins associated with this Server. After this method is called once, it saves the array of Strings and returns that saved array on subsequent calls, until the refresh() method is called and a more current list is obtained.

Returns:
a String array of the bos admin of the server.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getPartitionCount

public int getPartitionCount()
                      throws AFSException
Returns the number of partitions on this server.

If the total list of partitions or partition names have already been collected (see getPartitions()), then the returning value will be calculated based upon the current list. Otherwise, AFS will be explicitly queried for the information.

The product of this method is not saved, and is recalculated with every call.

Returns:
the number of partitions on this server.
Throws:
AFSException - If an error occurs in any of the associated native methods
See Also:
getPartitions(), getPartitionNames()

getPartition

public Partition getPartition(String name)
                       throws AFSException
Retrieves the Partition object (which is an abstract representation of an actual AFS partition of this server) designated by name (i.e. "/vicepa", etc.). If a partition by that name does not actually exist in AFS on the server represented by this object, an AFSException will be thrown.

Parameters:
name - the name of the partition to retrieve
Returns:
Partition designated by name.
Throws:
AFSException - If an error occurs in the native code
NullPointerException - If name is null.

getPartitions

public Partition[] getPartitions()
                          throws AFSException
Retrieves an array containing all of the Partition objects associated with this Server, each of which are an abstract representation of an actual AFS partition of the AFS server. After this method is called once, it saves the array of Partitions and returns that saved array on subsequent calls, until the refresh() method is called and a more current list is obtained.

Returns:
a Partition array of the Partition objects of the server.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getPartitionNames

public String[] getPartitionNames()
                           throws AFSException
Retrieves an array containing all of the names of partitions associated with this Server (i.e. "vicepa", etc.). After this method is called once, it saves the array of Strings and returns that saved array on subsequent calls, until the refresh() method is called and a more current list is obtained.

Returns:
a String array of the partitions of the server.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getKey

public Key getKey(int keyVersion)
           throws AFSException
Retrieves the Key object (which is an abstract representation of an actual AFS partition of this server) designated by nkeyVersion. If a key with that version does not actually exist in AFS on the server represented by this object, null is returned.

Parameters:
keyVersion - the version of the key to retrieve
Returns:
Key designated by keyVersion.
Throws:
AFSException - If an error occurs in the native code

getKeyCount

public int getKeyCount()
                throws AFSException
Returns the number of keys on this server.

If the total list of keys has already been collected (see getKeys()), then the returning value will be calculated based upon the current list. Otherwise, AFS will be explicitly queried for the information.

The product of this method is not saved, and is recalculated with every call.

Returns:
the number of keys on this server.
Throws:
AFSException - If an error occurs in any of the associated native methods
See Also:
getKeys()

getKeys

public Key[] getKeys()
              throws AFSException
Retrieves an array containing all of the Key objects associated with this Server, each of which are an abstract representation of an actual AFS key of the AFS server. After this method is called once, it saves the array of Keys and returns that saved array on subsequent calls, until the refresh() method is called and a more current list is obtained.

Returns:
a Key array of the Key objects of the server.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getProcess

public Process getProcess(String name)
                   throws AFSException
Retrieves the Process object (which is an abstract representation of an actual AFS process of this server) designated by name (i.e. "kaserver", etc.). If a process by that name does not actually exist in AFS on the server represented by this object, an AFSException will be thrown.

Parameters:
name - the name of the process to retrieve
Returns:
Process designated by name.
Throws:
AFSException - If an error occurs in the native code
NullPointerException - If name is null.

getProcessCount

public int getProcessCount()
                    throws AFSException
Returns the number of processes hosted by this server.

If the total list of processes or process names have already been collected (see getProcesses()), then the returning value will be calculated based upon the current list. Otherwise, AFS will be explicitly queried for the information.

The product of this method is not saved, and is recalculated with every call.

Returns:
the number of processes on this server.
Throws:
AFSException - If an error occurs in any of the associated native methods
See Also:
getProcesses(), getProcessNames()

getProcesses

public Process[] getProcesses()
                       throws AFSException
Retrieves an array containing all of the Process objects associated with this Server, each of which are an abstract representation of an actual AFS process of the AFS server. After this method is called once, it saves the array of Processes and returns that saved array on subsequent calls, until the refresh() method is called and a more current list is obtained.

Returns:
a Process array of the Process objects of the server.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getProcessNames

public String[] getProcessNames()
                         throws AFSException
Retrieves an array containing all of the names of processes associated with this Server (i.e. "kaserver", etc.). After this method is called once, it saves the array of Strings and returns that saved array on subsequent calls, until the refresh() method is called and a more current list is obtained.

Returns:
a String array of the processes of the server.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

isDatabase

public boolean isDatabase()
                   throws AFSException
Returns whether or not this server is a database machine, meaning it runs processes such as the "kaserver" and "vlserver", and participates in elections.

Returns:
whether or not this user this server is a database machine.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

isFileServer

public boolean isFileServer()
                     throws AFSException
Returns whether or not this server is a file server machine, meaning it runs the "fs" process and stores AFS volumes.

Returns:
whether or not this user this server is a file server machine.
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

isBadDatabase

public boolean isBadDatabase()
                      throws AFSException
Returns whether or not this server is a database machine AND either it isn't in reality (e.g. it's incorrectly configured) or it's currently down.

Returns:
whether or not this server is a database machine AND either it isn't in reality or it's currently down
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

isBadFileServer

public boolean isBadFileServer()
                        throws AFSException
Returns whether this machine thinks it's a file server AND either it isn't in reality (e.g. it's incorrectly configured) or it's currently down.

Returns:
whether or not this server is a file server machine AND either it isn't in reality or it's currently down
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getIPAddresses

public String[] getIPAddresses()
                        throws AFSException
Returns this server's IP address as a String. It returns it in dotted quad notation (i.e. 123.123.123.123).

Returns:
this server's IP address as a String
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getGeneralRestartTime

public Server.ExecutableTime getGeneralRestartTime()
                                            throws AFSException
Returns the BOS Server's general restart time in the form of an ExecutableTime object. This is the time at which the bos server restarts itself and all running processes. After this method is called once, it saves the time and returns that value on subsequent calls, until the refresh() method is called and a more current value is obtained.

Returns:
the general restart time
Throws:
AFSException - If an error occurs in the native code
See Also:
Server.ExecutableTime, refresh()

getBinaryRestartTime

public Server.ExecutableTime getBinaryRestartTime()
                                           throws AFSException
Returns the BOS Server's binary restart time in the form of an ExecutableTime object. This is the time at which all new or newly modified AFS binaries are restarted. After this method is called once, it saves the time and returns that value on subsequent calls, until the refresh() method is called and a more current value is obtained.

Returns:
the binary restart time
Throws:
AFSException - If an error occurs in the native code
See Also:
Server.ExecutableTime, refresh()

getTotalSpace

public int getTotalSpace()
                  throws AFSException
Returns the total space on this server (a sum of the space of all the partitions associated with this server). If this server is not a file server, zero will be returned. After this method is called once, it saves the total space and returns that value on subsequent calls, until the refresh() method is called and a more current value is obtained.

Returns:
the total space on this server
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getTotalFreeSpace

public int getTotalFreeSpace()
                      throws AFSException
Returns the total free space on this server (a sum of the free space of all the partitions associated with this server). If this server is not a file server, zero will be returned. After this method is called once, it saves the total free space and returns that value on subsequent calls, until the refresh() method is called and a more current value is obtained.

Returns:
the total free space on this server
Throws:
AFSException - If an error occurs in the native code
See Also:
refresh()

getTotalUsedSpace

public int getTotalUsedSpace()
                      throws AFSException
Returns the total used space on this server (a sum of the used space of all the partitions associated with this server). If this server is not a file server, zero will be returned. After this method is called once, it saves the total used space and returns that value on subsequent calls, until the refresh() method is called and a more current value is obtained.

Returns:
the total space on this partition
Throws:
AFSException - If an error occurs in the native code
See Also:
getTotalSpace(), getTotalFreeSpace()

setGeneralRestartTime

public void setGeneralRestartTime(Server.ExecutableTime executableTime)
                           throws AFSException
Sets the BOS general restart time. This is the time at which the bos server restarts itself and all running processes.

Parameters:
executableTime - Executable time object that represents what the BOS Server's general restart time should be.
Throws:
AFSException - If an error occurs in the native code
See Also:
Server.ExecutableTime

setBinaryRestartTime

public void setBinaryRestartTime(Server.ExecutableTime executableTime)
                          throws AFSException
Sets the BOS binary restart time. This is the time at which all new or newly modified AFS binaries are restarted.

Parameters:
executableTime - Executable time object that represents what the BOS Server's binary restart time should be.
Throws:
AFSException - If an error occurs in the native code
See Also:
Server.ExecutableTime

compareTo

public int compareTo(Server server)
Compares two Server objects respective to their names and does not factor any other attribute. Alphabetic case is significant in comparing names.

Parameters:
server - The Server object to be compared to this Server instance
Returns:
Zero if the argument is equal to this Server's name, a value less than zero if this Server's name is lexicographically less than the argument, or a value greater than zero if this Server's name is lexicographically greater than the argument

compareTo

public int compareTo(Object obj)
Comparable interface method.

Specified by:
compareTo in interface Comparable
See Also:
compareTo(Server)

equals

public boolean equals(Server otherServer)
Tests whether two Server objects are equal, based on their names and hosting Cell.

Parameters:
otherServer - the Server to test
Returns:
whether the specifed Server is the same as this Server

toString

public String toString()
Returns the name of this Server

Overrides:
toString in class Object
Returns:
the name of this Server

Java AFS API (jafs) for OpenAFS

Copyright (c) 2001-2002 International Business Machines Corp.
All rights reserved.
See copyright statement.