Java AFS Admin API v1.3

org.openafs.jafsadm
Class Partition

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

public class Partition
extends Object
implements Serializable, Comparable

An abstract representation of an AFS partition. It holds information about the partition, such as what its total space is.

Constructing an instance of a Partition does not mean an actual AFS partition is created on a server -- on the contrary, a Partition object must be a representation of an already existing AFS partition. There is no way to create a new AFS partition through this API.

Each Partition object has its own individual set of Volumes. This represents the properties and attributes of an actual AFS cell.

The following is a simple example of how to obtain and use a Partition object. In this example, a list of the Partition objects of a server are obtained, and the name and number of volumes is printed out for each one.

 import org.openafs.jafsadm.Cell;
 import org.openafs.jafsadm.AFSAdminException;
 import org.openafs.jafsadm.Partition;
 import org.openafs.jafsadm.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];
 
     cell   = new Cell(cellName, username, password);
     server = new Server(serverName, cell);
 
     System.out.println("Partitions in Server " + server.getName() + ":");
     Partition[] partitions = server.getPartitions();
     for (int i = 0; i < partitions.length; i++) {
       System.out.print("Partition " + partitions[i].getName());
       System.out.print("hosts " + partitions[i].getVolumeCount());
       System.out.print("volumes.\n");
     }
   }
   ...
 }
 

Version:
1.0, 2/15/02
See Also:
Serialized Form

Constructor Summary
Partition(String name, Server server)
          Constructs a new Partition object instance given the name of the AFS partition and the AFS server, represented by server, to which it belongs.
Partition(String name, Server server, boolean preloadAllMembers)
          Constructs a new Partition object instance given the name of the AFS partition and the AFS server, represented by server, to which it belongs.
 
Method Summary
 int compareTo(Object obj)
          Comparable interface method.
 int compareTo(Partition partition)
          Compares two Partition objects respective to their names and does not factor any other attribute.
 boolean equals(Partition otherPartition)
          Tests whether two Partition objects are equal, based on their names and hosting server.
 String getDeviceName()
          Returns the device name of this partition (i.e.
 int getID()
          Returns the id of this partition (i.e.
 int getLockFileDescriptor()
          Returns the lock file descriptor of this partition
 String getName()
          Returns the name of this partition.
 Server getServer()
          Returns this partition's hosting server.
 int getTotalFreeSpace()
          Returns the total free space on this partition.
 int getTotalQuota()
          Returns the total combined quota of all volumes on this partition, unless a volume has configured an unlimited quota at which case an AFSAdminException is thrown.
 int getTotalQuota(boolean ignoreUnlimitedQuotas)
          Returns the total combined quota of all volumes on this partition, ignoring volumes with unlimited quotas, if ignoreUnlimitedQuotas is true; otherwise an AFSAdminException is thrown if a volume has an unlimited quota.
 int getTotalSpace()
          Returns the total space on this partition.
 int getUsedSpace()
          Returns the total used space on this partition.
 Volume getVolume(String name)
          Retrieves the Volume object (which is an abstract representation of an actual AFS volume of this partition) designated by name (i.e.
 int getVolumeCount()
          Returns the number of volumes contained in this partition.
 String[] getVolumeNames()
          Retrieves an array containing all of the names of volumes associated with this Partition.
 String[] getVolumeNames(int startIndex, int length)
          Returns an array containing a subset of the names of volumes associated with this Partition.
 Volume[] getVolumes()
          Retrieves an array containing all of the Volume objects associated with this Partition, each of which is an abstract representation of an actual AFS volume of the AFS partition.
 Volume[] getVolumes(int startIndex, int length)
          Returns an array containing a subset of the Volume objects associated with this Partition, each of which is an abstract representation of an actual AFS volume of the AFS partition.
 boolean hasVolumeWithUnlimitedQuota()
          Tests whether this partition contains a volume that has an unlimited quota configured.
 void refresh()
          Refreshes the properties of this Partition object instance with values from the AFS partition it represents.
 void salvage()
          Salvages (restores consistency to) this partition.
 void syncPartition()
          Syncs this partition to the VLDB.
 void syncVLDB()
          Syncs the VLDB to this partition.
 String toString()
          Returns the name of this Partition
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Partition

public Partition(String name,
                 Server server)
          throws AFSAdminException
Constructs a new Partition object instance given the name of the AFS partition and the AFS server, represented by server, to which it belongs. This does not actually create a new AFS partition, it just represents an existing one. If name is not an actual AFS partition, exceptions will be thrown during subsequent method invocations on this object.
Parameters:
name - the name of the partition to represent
server - the server on which the partition resides
Throws:
AFSAdminException - If an error occurs in the native code

Partition

public Partition(String name,
                 Server server,
                 boolean preloadAllMembers)
          throws AFSAdminException
Constructs a new Partition object instance given the name of the AFS partition and the AFS server, represented by server, to which it belongs. This does not actually create a new AFS partition, it just represents an existing one. If name is not an actual AFS partition, 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 partition to represent
server - the server to which the partition 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:
AFSAdminException - If an error occurs in the native code
See Also:
refresh()
Method Detail

refresh

public void refresh()
             throws AFSAdminException
Refreshes the properties of this Partition object instance with values from the AFS partition it represents. All properties that have been initialized and/or accessed will be renewed according to the values of the AFS partition this Partition 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:
AFSAdminException - If an error occurs in the native code

syncPartition

public void syncPartition()
                   throws AFSAdminException
Syncs this partition to the VLDB.
Throws:
AFSAdminException - If an error occurs in the native code

syncVLDB

public void syncVLDB()
              throws AFSAdminException
Syncs the VLDB to this partition.
Throws:
AFSAdminException - If an error occurs in the native code

salvage

public void salvage()
             throws AFSAdminException
Salvages (restores consistency to) this partition. Uses default values for most salvager options in order to simplify the API.
Throws:
AFSAdminException - If an error occurs in the native code

getName

public String getName()
Returns the name of this partition.
Returns:
the name of this partition

getServer

public Server getServer()
Returns this partition's hosting server.
Returns:
this partition's server

getVolumeCount

public int getVolumeCount()
                   throws AFSAdminException
Returns the number of volumes contained in this partition.

If the total list of volumes or volume names have already been collected (see getVolumes()), 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 volumes contained in this partition.
Throws:
AFSAdminException - If an error occurs in any of the associated native methods

getVolume

public Volume getVolume(String name)
                 throws AFSAdminException
Retrieves the Volume object (which is an abstract representation of an actual AFS volume of this partition) designated by name (i.e. "root.afs", etc.). If a volume by that name does not actually exist in AFS on the partition represented by this object, an AFSAdminException will be thrown.
Parameters:
name - the name of the volume to retrieve
Returns:
Volume designated by name.
Throws:
AFSAdminException - If an error occurs in the native code
NullPointerException - If name is null.

getVolumes

public Volume[] getVolumes()
                    throws AFSAdminException
Retrieves an array containing all of the Volume objects associated with this Partition, each of which is an abstract representation of an actual AFS volume of the AFS partition. After this method is called once, it saves the array of Volumes and returns that saved array on subsequent calls, until the refresh() method is called and a more current list is obtained.
Returns:
a Volume array of the Volume objects of the partition.
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
refresh()

getVolumes

public Volume[] getVolumes(int startIndex,
                           int length)
                    throws AFSAdminException
Returns an array containing a subset of the Volume objects associated with this Partition, each of which is an abstract representation of an actual AFS volume of the AFS partition. The subset is a point-in-time list of volumes (Volume objects representing AFS volumes) starting at the complete array's index of startIndex and containing up to length elements. If length is larger than the number of remaining elements, respective to startIndex, then this method will ignore the remaining positions requested by length and return an array that contains the remaining number of elements found in this partition's complete array of volumes.

This method is especially useful when managing iterations of very large lists. getVolumeCount() can be used to determine if iteration management is practical.

This method does not save the resulting data and therefore queries AFS for each call.

Example: If there are more than 50,000 volumes within this partition then only render them in increments of 10,000.

 ...
   Volume[] volumes;
   if (partition.getVolumeCount() > 50000) {
     int index = 0;
     int length = 10000;
     while (index < partition.getVolumeCount()) {
       volumes = partition.getVolumes(index, length);
       for (int i = 0; i < volumes.length; i++) {
         ...
       }
       index += length;
       ...
     }
   } else {
     volumes = partition.getVolumes();
     for (int i = 0; i < volumes.length; i++) {
       ...
     }
   }
 ...
 
Parameters:
startIndex - the base zero index position at which the subset array should start from, relative to the complete list of elements present in AFS.
length - the number of elements that the subset should contain
Returns:
a subset array of volumes hosted by this partition
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
getVolumeCount(), getVolumeNames(int, int), getVolumes()

getVolumeNames

public String[] getVolumeNames()
                        throws AFSAdminException
Retrieves an array containing all of the names of volumes associated with this Partition. 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 volumes of the partition.
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
refresh()

getVolumeNames

public String[] getVolumeNames(int startIndex,
                               int length)
                        throws AFSAdminException
Returns an array containing a subset of the names of volumes associated with this Partition. The subset is a point-in-time list of volume names starting at the complete array's index of startIndex and containing up to length elements. If length is larger than the number of remaining elements, respective to startIndex, then this method will ignore the remaining positions requested by length and return an array that contains the remaining number of elements found in this partition's complete array of volume names.

This method is especially useful when managing iterations of very large lists. getVolumeCount() can be used to determine if iteration management is practical.

This method does not save the resulting data and therefore queries AFS for each call.

Example: If there are more than 50,000 volumes within this partition then only render them in increments of 10,000.

 ...
   String[] volumes;
   if (partition.getVolumeCount() > 50000) {
     int index = 0;
     int length = 10000;
     while (index < partition.getVolumeCount()) {
       volumes = partition.getVolumeNames(index, length);
       for (int i = 0; i < volumes.length; i++) {
         ...
       }
       index += length;
       ...
     }
   } else {
     volumes = partition.getVolumeNames();
     for (int i = 0; i < volumes.length; i++) {
       ...
     }
   }
 ...
 
Parameters:
startIndex - the base zero index position at which the subset array should start from, relative to the complete list of elements present in AFS.
length - the number of elements that the subset should contain
Returns:
a subset array of volume names hosted by this partition
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
getVolumeCount(), getVolumes(int, int), getVolumes()

getID

public int getID()
          throws AFSAdminException
Returns the id of this partition (i.e. "vicepa" = 0, etc.)
Returns:
the id of this partition
Throws:
AFSAdminException - If an error occurs in the native code

getDeviceName

public String getDeviceName()
                     throws AFSAdminException
Returns the device name of this partition (i.e. "hda5", etc.)
Returns:
the device name of this partition
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
refresh()

getLockFileDescriptor

public int getLockFileDescriptor()
                          throws AFSAdminException
Returns the lock file descriptor of this partition
Returns:
the lock file descriptor of this partition
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
refresh()

getTotalSpace

public int getTotalSpace()
                  throws AFSAdminException
Returns the total space on this partition.
Returns:
the total space on this partition
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
refresh()

getTotalFreeSpace

public int getTotalFreeSpace()
                      throws AFSAdminException
Returns the total free space on this partition. 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 partition
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
refresh()

getUsedSpace

public int getUsedSpace()
                 throws AFSAdminException
Returns the total used space on this partition. 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 used space on this partition
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
refresh()

getTotalQuota

public int getTotalQuota()
                  throws AFSAdminException
Returns the total combined quota of all volumes on this partition, unless a volume has configured an unlimited quota at which case an AFSAdminException is thrown.

After this method is called once, it saves the value and returns that value on subsequent calls, until the refresh() method is called and a more current value is obtained.

Returns:
the total combined quota of all volumes on this partition
Throws:
AFSAdminException - If an error occurs while retrieving and calculating, or a volume has an unlimited quota.
See Also:
getTotalQuota(boolean), hasVolumeWithUnlimitedQuota(), Volume.getQuota()

getTotalQuota

public int getTotalQuota(boolean ignoreUnlimitedQuotas)
                  throws AFSAdminException
Returns the total combined quota of all volumes on this partition, ignoring volumes with unlimited quotas, if ignoreUnlimitedQuotas is true; otherwise an AFSAdminException is thrown if a volume has an unlimited quota.

After this method is called once, it saves the value and returns that value on subsequent calls, until the refresh() method is called and a more current value is obtained.

Returns:
the total combined quota of all volumes on this partition
Throws:
AFSAdminException - If an error occurs while retrieving and calculating, or a volume has an unlimited quota.
See Also:
getTotalQuota(), hasVolumeWithUnlimitedQuota(), Volume.getQuota(), refresh()

hasVolumeWithUnlimitedQuota

public boolean hasVolumeWithUnlimitedQuota()
                                    throws AFSAdminException
Tests whether this partition contains a volume that has an unlimited quota configured.
Returns:
true if a contained volume's quota is configured as unlimited; otherwise false.
Throws:
AFSAdminException - If an error occurs in the native code
See Also:
getTotalQuota(), getTotalQuota(boolean), Volume.isQuotaUnlimited(), Volume.getQuota(), refresh()

compareTo

public int compareTo(Partition partition)
Compares two Partition objects respective to their names and does not factor any other attribute. Alphabetic case is significant in comparing names.
Parameters:
partition - The Partition object to be compared to this Partition instance
Returns:
Zero if the argument is equal to this Partition's name, a value less than zero if this Partition's name is lexicographically less than the argument, or a value greater than zero if this Partition'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(Partition)

equals

public boolean equals(Partition otherPartition)
Tests whether two Partition objects are equal, based on their names and hosting server.
Parameters:
otherPartition - the Partition to test
Returns:
whether the specifed Partition is the same as this Partition

toString

public String toString()
Returns the name of this Partition
Overrides:
toString in class Object
Returns:
the name of this Partition

Java AFS Admin (jafsadm) API for OpenAFS

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