2 * @(#)Server.java 1.0 6/29/2001
4 * Copyright (c) 2001 International Business Machines Corp.
7 * This software has been released under the terms of the IBM Public
8 * License. For details, see the LICENSE file in the top-level source
9 * directory or online at http://www.openafs.org/dl/license10.html
11 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
15 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
19 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 package org.openafs.jafs;
26 import java.io.Serializable;
27 import java.text.DecimalFormat;
28 import java.util.ArrayList;
29 import java.util.Calendar;
30 import java.util.GregorianCalendar;
33 * An abstract representation of an AFS server. It holds information about
34 * the server, such as what its processes are.
37 * Constructing an instance of a <code>Server</code> does not mean an actual
38 * AFS server is created and added to a cell -- on the contrary, a
39 * <code>Server</code> object must be a representation of an already existing
40 * AFS server. There is no way to create a new AFS server through this API.
41 * See <a href="http://www.openafs.org">OpenAFS.org</a> for information on how
42 * to create a new AFS server.<BR><BR>
44 * A <code>Server</code> object may represent either an AFS file server,
45 * an AFS database server, or both if the same machine serves both
48 * Each <code>Server</code> object has its own individual set of
49 * <code>Partition</code>s, <code>Process</code>es, and <code>Key</code>s.
50 * This represents the properties and attributes of an actual AFS server.
53 * <!--Example of how to use class-->
54 * The following is a simple example of how to construct and use a Server
55 * object. This example constructs a <code>Server</code> using the
56 * <code>Cell</code> representing teh AFS cell to which the server belongs,
57 * and prints out the names of all the partitions residing on the server.
61 * import org.openafs.jafs.Cell;
62 * import org.openafs.jafs.AFSException;
63 * import org.openafs.jafs.Partition;
64 * import org.openafs.jafs.Server;
70 * private Server server;
72 * public static void main(String[] args) throws Exception
74 * String username = arg[0];
75 * String password = arg[1];
76 * String cellName = arg[2];
77 * String serverName = arg[3];
79 * token = new Token(username, password, cellName);
80 * cell = new Cell(token);
81 * server = new Server(serverName, cell);
83 * System.out.println("Partitions in Server " + server.getName() + ":");
84 * if( server.isFileServer() ) {
85 * Partition[] partitions = server.getPartitions();
86 * for (int i = 0; i < partitions.length; i++) {
87 * System.out.println(" -> " + partitions[i]);
96 public class Server implements Serializable, Comparable
99 * Used for binary restart time types.
101 private static final int RESTART_BINARY = 0;
104 * Used for general restart time types.
106 private static final int RESTART_GENERAL = 1;
108 protected String name;
111 protected long vosHandle;
112 protected long bosHandle;
114 protected boolean database;
115 protected boolean fileServer;
117 // these will be true if the machine is supposedly listed as a server
118 // but that's wrong, or the machine is down
119 protected boolean badFileServer;
120 protected boolean badDatabase;
122 // String IP Address of address[0]
123 protected String[] ipAddresses;
125 protected ArrayList partitionNames;
126 protected ArrayList partitions;
127 protected ArrayList adminNames;
128 protected ArrayList admins;
129 protected ArrayList keys;
130 protected ArrayList processNames;
131 protected ArrayList processes;
133 // Storage information
134 protected int totalSpace;
135 protected int totalQuota;
136 protected int totalFreeSpace;
137 protected int totalUsedSpace;
139 protected ExecutableTime genRestartTime;
140 protected ExecutableTime binRestartTime;
142 protected boolean cachedInfo;
145 * Constructs a new <CODE>Server</CODE> object instance given the
146 * name of the AFS server and the AFS cell, represented by
147 * <CODE>cell</CODE>, to which it belongs. This does not actually
148 * create a new AFS server, it just represents an existing one.
149 * If <code>name</code> is not an actual AFS server, exceptions
150 * will be thrown during subsequent method invocations on this
153 * @param name the name of the server to represent
154 * @param cell the cell to which the server belongs.
155 * @exception AFSException If an error occurs in the native code
157 public Server( String name, Cell cell ) throws AFSException
167 ipAddresses = new String[16];
169 partitionNames = null;
179 * Constructs a new <CODE>Server</CODE> object instance given the name
180 * of the AFS server and the AFS cell, represented by <CODE>cell</CODE>,
181 * to which it belongs. This does not actually
182 * create a new AFS server, it just represents an existing one.
183 * If <code>name</code> is not an actual AFS server, exceptions
184 * will be thrown during subsequent method invocations on this
187 * <P> This constructor is ideal for point-in-time representation and
188 * transient applications. It ensures all data member values are set
189 * and available without calling back to the filesystem at the first
190 * request for them. Use the {@link #refresh()} method to address any
191 * coherency concerns.
193 * @param name the name of the server to represent
194 * @param cell the cell to which the server belongs.
195 * @param preloadAllMembers true will ensure all object members are
196 * set upon construction;
197 * otherwise members will be set upon access,
198 * which is the default behavior.
199 * @exception AFSException If an error occurs in the native code
202 public Server( String name, Cell cell, boolean preloadAllMembers )
206 if (preloadAllMembers) refresh(true);
210 * Constructs a blank <code>Server</code> object instance given the cell to
211 * which the server belongs. This blank object can then be passed into
212 * other methods to fill out its properties.
214 * @param cell the cell to which the server belongs.
215 * @exception AFSException If an error occurs in the native code
217 Server( Cell cell ) throws AFSException
222 /*-------------------------------------------------------------------------*/
225 * Refreshes the properties of this Server object instance with values
226 * from the AFS server it represents. All properties that have been
227 * initialized and/or accessed will be renewed according to the values
228 * of the AFS server this Server object instance represents.
230 * <P>Since in most environments administrative changes can be administered
231 * from an AFS command-line program or an alternate GUI application, this
232 * method provides a means to refresh the Java object representation and
233 * thereby ascertain any possible modifications that may have been made
234 * from such alternate administrative programs. Using this method before
235 * an associated instance accessor will ensure the highest level of
236 * representative accuracy, accommodating changes made external to the
237 * Java application space. If administrative changes to the underlying AFS
238 * system are only allowed via this API, then the use of this method is
241 * @exception AFSException If an error occurs in the native code
243 public void refresh() throws AFSException
249 * Refreshes the properties of this Server object instance with values
250 * from the AFS server it represents. If <CODE>all</CODE> is
251 * <CODE>true</CODE> then <U>all</U> of the properties of this Server
252 * object instance will be set, or renewed, according to the values of the
253 * AFS server it represents, disregarding any previously set properties.
255 * <P> Thus, if <CODE>all</CODE> is <CODE>false</CODE> then properties that
256 * are currently set will be refreshed and properties that are not set
257 * will remain uninitialized.
258 * See {@link #refresh()} for more information.
260 * @param all if true set or renew all object properties;
261 * otherwise renew all set properties
262 * @exception AFSException If an error occurs in the native code
265 protected void refresh(boolean all) throws AFSException
269 refreshProcessNames();
273 refreshPartitionNames();
274 refreshPartitions(all);
276 refreshGeneralRestart();
277 refreshBinaryRestart();
279 if ( processes != null ) refreshProcesses();
280 if ( processNames != null ) refreshProcessNames();
281 if ( keys != null ) refreshKeys();
282 if ( adminNames != null ) refreshAdminNames();
283 if ( admins != null ) refreshAdmins();
284 if ( partitionNames != null ) refreshPartitionNames();
285 if ( partitions != null ) refreshPartitions(all);
286 if ( genRestartTime != null ) refreshGeneralRestart();
287 if ( binRestartTime != null ) refreshBinaryRestart();
288 if ( cachedInfo ) refreshInfo();
293 * Refreshes the information fields of this <code>Server</code> to
294 * reflect the current state of the AFS server. These fields include
295 * the IP addresses and the fileserver types.
297 * @exception AFSException If an error occurs in the native code
299 protected void refreshInfo() throws AFSException
301 getServerInfo( cell.getCellHandle(), name, this );
306 * Refreshes the general restart time fields of this <code>Server</code>
307 * to reflect the current state of the AFS server.
309 * @exception AFSException If an error occurs in the native code
311 protected void refreshGeneralRestart() throws AFSException
313 if (genRestartTime == null) genRestartTime = new ExecutableTime();
314 getRestartTime( getBosHandle(), RESTART_GENERAL, genRestartTime );
318 * Refreshes the binary restart time fields of this <code>Server</code>
319 * to reflect the current state of the AFS server.
321 * @exception AFSException If an error occurs in the native code
323 protected void refreshBinaryRestart() throws AFSException
325 if (binRestartTime == null) binRestartTime = new ExecutableTime();
326 getRestartTime( getBosHandle(), RESTART_BINARY, binRestartTime );
330 * Obtains the most current list of <code>Partition</code> objects
333 * @exception AFSException If an error occurs in the native code
335 protected void refreshPartitions() throws AFSException
337 this.refreshPartitions(false);
341 * Obtains the most current list of <code>Partition</code> objects of
344 * @param refreshVolumes force all volumes contained in each
345 * partition to be refreshed.
347 * @exception AFSException If an error occurs in the native code
349 protected void refreshPartitions(boolean refreshVolumes)
352 if (!isFileServer() || isBadFileServer()) return;
354 Partition currPartition;
356 long iterationID = getPartitionsBegin( cell.getCellHandle(),
359 partitions = new ArrayList();
361 currPartition = new Partition( this );
362 while( getPartitionsNext( iterationID, currPartition ) != 0 ) {
363 //Only volumes are necessary since volume information
364 //is populated at time of construction
365 if (refreshVolumes) currPartition.refreshVolumes();
366 partitions.add( currPartition );
367 currPartition = new Partition( this );
369 getPartitionsDone( iterationID );
377 * Obtains the most current list of partition names of this server.
379 * @exception AFSException If an error occurs in the native code
381 protected void refreshPartitionNames() throws AFSException
383 if (!isFileServer() || isBadFileServer()) return;
387 long iterationID = getPartitionsBegin( cell.getCellHandle(),
390 partitionNames = new ArrayList();
392 while( ( currName = getPartitionsNextString( iterationID ) ) != null ) {
393 partitionNames.add( currName );
395 getPartitionsDone( iterationID );
399 * Obtains the most current list of bos admin names of this server.
401 * @exception AFSException If an error occurs in the native code
403 protected void refreshAdminNames() throws AFSException
407 long iterationID = getBosAdminsBegin( getBosHandle() );
409 adminNames = new ArrayList();
411 while( ( currName = getBosAdminsNextString( iterationID ) ) != null ) {
412 adminNames.add( currName );
414 getBosAdminsDone( iterationID );
418 * Obtains the most current list of admin <code>User</code> objects of
421 * @exception AFSException If an error occurs in the native code
423 protected void refreshAdmins() throws AFSException
427 long iterationID = getBosAdminsBegin( getBosHandle() );
429 admins = new ArrayList();
431 currUser = new User( cell );
432 while( getBosAdminsNext( cell.getCellHandle(), iterationID, currUser )
434 admins.add( currUser );
435 currUser = new User( cell );
437 getBosAdminsDone( iterationID );
441 * Obtains the most current list of <code>Key</code> objects of this server.
443 * @exception AFSException If an error occurs in the native code
445 protected void refreshKeys() throws AFSException
449 long iterationID = getKeysBegin( getBosHandle() );
451 keys = new ArrayList();
453 currKey = new Key( this );
454 while( getKeysNext( iterationID, currKey ) != 0 ) {
456 currKey = new Key( this );
458 getKeysDone( iterationID );
462 * Obtains the most current list of process names of this server.
464 * @exception AFSException If an error occurs in the native code
466 protected void refreshProcessNames() throws AFSException
470 long iterationID = getProcessesBegin( getBosHandle() );
472 processNames = new ArrayList();
474 while( ( currName = getProcessesNextString( iterationID ) ) != null ) {
475 processNames.add( currName );
477 getProcessesDone( iterationID );
481 * Obtains the most current list of <code>Process</code> objects of
484 * @exception AFSException If an error occurs in the native code
486 protected void refreshProcesses() throws AFSException
490 long iterationID = getProcessesBegin( getBosHandle() );
492 processes = new ArrayList();
494 currProcess = new Process( this );
495 while( getProcessesNext( getBosHandle(), iterationID, currProcess )
497 processes.add( currProcess );
498 currProcess = new Process( this );
500 getProcessesDone( iterationID );
504 * Add a bos admin to the UserList file of this server, in order to
505 * given the AFS user represented by <code>admin</code> full bos
506 * administrative privileges on this server.
508 * @param admin the admin to add
509 * @exception AFSException If an error occurs in the native code
511 public void addAdmin( User admin ) throws AFSException
513 String adminName = admin.getName();
515 addBosAdmin( getBosHandle(), adminName );
516 if ( adminNames != null ) {
517 adminNames.add( adminName );
522 * Remove a bos admin from the UserList file of this server, in order to
523 * take away from the AFS user represented by <code>admin</code> bos
524 * administrative privileges on this machine.
526 * @param admin the admin to remove
527 * @exception AFSException If an error occurs in the native code
529 public void removeAdmin( User admin ) throws AFSException
531 String adminName = admin.getName();
533 removeBosAdmin( getBosHandle(), adminName );
534 if ( adminNames != null ) {
535 adminNames.remove( adminNames.indexOf( adminName ) );
536 adminNames.trimToSize();
541 * Syncs this server to the VLDB.
543 * @exception AFSException If an error occurs in the native code
545 public void syncServer() throws AFSException
547 syncServerWithVLDB( cell.getCellHandle(), getVosHandle(), -1 );
551 * Syncs the VLDB to this server.
553 * @exception AFSException If an error occurs in the native code
555 public void syncVLDB() throws AFSException
557 syncVLDBWithServer( cell.getCellHandle(), getVosHandle(), -1, false );
561 * Salvages (restores consistency to) this server. Uses default values for
562 * most salvager options in order to simplify the API.
564 * @exception AFSException If an error occurs in the native code
566 public void salvage() throws AFSException
568 salvage( cell.getCellHandle(), getBosHandle(), null, null, 4, null, null,
569 false, false, false, false, false, false );
573 * Starts up all bos processes on this server.
575 * @exception AFSException If an error occurs in the native code
577 public void startAllProcesses() throws AFSException
579 startAllProcesses( getBosHandle() );
583 * Stops all bos processes on this server.
585 * @exception AFSException If an error occurs in the native code
587 public void stopAllProcesses() throws AFSException
589 stopAllProcesses( getBosHandle() );
593 * Restarts all bos processes on this server.
595 * @exception AFSException If an error occurs in the native code
597 public void restartAllProcesses() throws AFSException
599 restartAllProcesses( getBosHandle(), false );
603 * Restarts bos server and all bos processes on this server.
605 * @exception AFSException If an error occurs in the native code
607 public void restartBosServer() throws AFSException
609 restartAllProcesses( getBosHandle(), true );
613 * Gets the contents of a log file, in one large <code>String</code>.
614 * The log cannot be in AFS file space.
616 * @return a <code>String</code> containing the contents of the log file
617 * @exception AFSException If an error occurs in the native code
619 public String getLog( String logLocation ) throws AFSException
621 return getLog( getBosHandle(), logLocation );
625 * Unauthenticates all server-related tokens that have been obtained by
626 * this <code>Server</code> object, and shuts this server object down.
627 * This method should only be called when this <code>Server</code> or any
628 * of the objects constructed using this <code>Server</code> will not be
629 * used anymore. Note that this does not effect the actual AFS server;
630 * it merely closes the representation.
632 * @exception AFSException If an error occurs in the native code
634 public void close() throws AFSException
636 if ( vosHandle != 0 ) {
637 closeVosServerHandle( vosHandle );
639 if ( bosHandle != 0 ) {
640 closeBosServerHandle( bosHandle );
648 partitionNames = null;
657 //////////////// accessors: ////////////////////////
660 * Returns the name of this server.
662 * @return the name of this server
664 public String getName()
670 * Returns the <code>Cell</code> object with which this <code>Server</code>
671 * was constructed. It represents the actual AFS cell to which this
674 * @return this server's cell
676 public Cell getCell()
682 * Returns the number of BOS administrators assigned to this server.
684 * <P>If the total list of admins or admin names have already been
685 * collected (see {@link #getAdmins()}), then the returning value will
686 * be calculated based upon the current list. Otherwise, AFS will be
687 * explicitly queried for the information.
689 * <P> The product of this method is not saved, and is recalculated
692 * @return the number of admins on this server.
693 * @exception AFSException If an error occurs
694 * in any of the associated native methods
696 * @see #getAdminNames()
698 public int getAdminCount() throws AFSException
700 if (adminNames != null) {
701 return adminNames.size();
702 } else if (admins != null) {
703 return admins.size();
705 return getBosAdminCount(getBosHandle());
710 * Retrieves an array containing all of the admin <code>User</code> objects
711 * associated with this <code>Server</code>, each of which are an abstract
712 * representation of an actual bos administrator of the AFS server.
713 * After this method is called once, it saves the array of
714 * <code>User</code>s and returns that saved array on subsequent calls,
715 * until the {@link #refresh()} method is called and a more current list
718 * @return a <code>User</code> array of the admins of the server.
719 * @exception AFSException If an error occurs in the native code
722 public User[] getAdmins() throws AFSException
724 if ( admins == null ) refreshAdmins();
725 return (User[]) admins.toArray( new User[admins.size()] );
729 * Retrieves an array containing all of the names of bos admins
730 * associated with this <code>Server</code>. After this method
731 * is called once, it saves the array of <code>String</code>s and returns
732 * that saved array on subsequent calls, until the {@link #refresh()} method
733 * is called and a more current list is obtained.
735 * @return a <code>String</code> array of the bos admin of the server.
736 * @exception AFSException If an error occurs in the native code
739 public String[] getAdminNames() throws AFSException
741 if ( adminNames == null ) refreshAdminNames();
742 return (String []) adminNames.toArray( new String[adminNames.size()] );
746 * Returns the number of partitions on this server.
748 * <P>If the total list of partitions or partition names have already been
749 * collected (see {@link #getPartitions()}), then the returning value will
750 * be calculated based upon the current list. Otherwise, AFS will be
751 * explicitly queried for the information.
753 * <P> The product of this method is not saved, and is recalculated
756 * @return the number of partitions on this server.
757 * @exception AFSException If an error occurs
758 * in any of the associated native methods
759 * @see #getPartitions()
760 * @see #getPartitionNames()
762 public int getPartitionCount() throws AFSException
764 if (partitionNames != null) {
765 return partitionNames.size();
766 } else if (partitions != null) {
767 return partitions.size();
769 return getPartitionCount(cell.getCellHandle(), getVosHandle());
774 * Retrieves the <CODE>Partition</CODE> object (which is an abstract
775 * representation of an actual AFS partition of this server) designated
776 * by <code>name</code> (i.e. "/vicepa", etc.). If a partition by
777 * that name does not actually exist in AFS on the server
778 * represented by this object, an {@link AFSException} will be
781 * @param name the name of the partition to retrieve
782 * @return <CODE>Partition</CODE> designated by <code>name</code>.
783 * @exception AFSException If an error occurs in the native code
784 * @exception NullPointerException If <CODE>name</CODE> is
787 public Partition getPartition(String name) throws AFSException
789 if (name == null) throw new NullPointerException();
790 if (isFileServer() && !isBadFileServer()) {
791 Partition partition = new Partition(name, this);
792 partition.refresh(true);
795 //Throw "No such entry" error
796 throw new AFSException("Server is not a file server.", 363524);
801 * Retrieves an array containing all of the <code>Partition</code> objects
802 * associated with this <code>Server</code>, each of which are an abstract
803 * representation of an actual AFS partition of the AFS server.
804 * After this method is called once, it saves the array of
805 * <code>Partition</code>s and returns that saved array on subsequent calls,
806 * until the {@link #refresh()} method is called and a more current list
809 * @return a <code>Partition</code> array of the <code>Partition</code>
810 * objects of the server.
811 * @exception AFSException If an error occurs in the native code
814 public Partition[] getPartitions() throws AFSException
816 if ( partitions == null ) refreshPartitions();
817 if ( partitions != null) {
818 return (Partition []) partitions.toArray( new Partition[partitions.size()] );
825 * Retrieves an array containing all of the names of partitions
826 * associated with this <code>Server</code> (i.e. "vicepa", etc.).
827 * After this method is called once, it saves the array of
828 * <code>String</code>s and returns that saved array on subsequent calls,
829 * until the {@link #refresh()} method is called and a more current
832 * @return a <code>String</code> array of the partitions of the server.
833 * @exception AFSException If an error occurs in the native code
836 public String[] getPartitionNames() throws AFSException
838 if ( partitionNames == null ) refreshPartitionNames();
840 partitionNames.toArray( new String[partitionNames.size()] );
844 * Retrieves the <CODE>Key</CODE> object (which is an abstract
845 * representation of an actual AFS partition of this server) designated
846 * by <code>nkeyVersion</code>. If a key with
847 * that version does not actually exist in AFS on the server
848 * represented by this object, <code>null</code> is returned.
850 * @param keyVersion the version of the key to retrieve
851 * @return <CODE>Key</CODE> designated by <code>keyVersion</code>.
852 * @exception AFSException If an error occurs in the native code
854 public Key getKey(int keyVersion) throws AFSException
857 Key[] keys = this.getKeys();
858 for (int i = 0; i < keys.length; i++) {
859 if (keys[i].getVersion() == keyVersion) {
863 } catch (Exception e) {
870 * Returns the number of keys on this server.
872 * <P>If the total list of keys has already been
873 * collected (see {@link #getKeys()}), then the returning value will
874 * be calculated based upon the current list. Otherwise, AFS will be
875 * explicitly queried for the information.
877 * <P> The product of this method is not saved, and is recalculated
880 * @return the number of keys on this server.
881 * @exception AFSException If an error occurs
882 * in any of the associated native methods
885 public int getKeyCount() throws AFSException
890 return getKeyCount(getBosHandle());
895 * Retrieves an array containing all of the <code>Key</code> objects
896 * associated with this <code>Server</code>, each of which are an abstract
897 * representation of an actual AFS key of the AFS server.
898 * After this method is called once, it saves the array of
899 * <code>Key</code>s and returns that saved array on subsequent calls,
900 * until the {@link #refresh()} method is called and a more current list
903 * @return a <code>Key</code> array of the <code>Key</code> objects
905 * @exception AFSException If an error occurs in the native code
908 public Key[] getKeys() throws AFSException
910 if ( keys == null ) refreshKeys();
911 return (Key[]) keys.toArray( new Key[keys.size()] );
915 * Retrieves the <CODE>Process</CODE> object (which is an abstract
916 * representation of an actual AFS process of this server) designated
917 * by <code>name</code> (i.e. "kaserver", etc.). If a process by
918 * that name does not actually exist in AFS on the server
919 * represented by this object, an {@link AFSException} will be
922 * @param name the name of the process to retrieve
923 * @return <CODE>Process</CODE> designated by <code>name</code>.
924 * @exception AFSException If an error occurs in the native code
925 * @exception NullPointerException If <CODE>name</CODE> is
928 public Process getProcess(String name) throws AFSException
930 if (name == null) throw new NullPointerException();
931 //if (isFileServer() && !isBadFileServer()) {
932 Process process = new Process(name, this);
933 process.refresh(true);
939 * Returns the number of processes hosted by this server.
941 * <P>If the total list of processes or process names have already been
942 * collected (see {@link #getProcesses()}), then the returning value will
943 * be calculated based upon the current list. Otherwise, AFS will be
944 * explicitly queried for the information.
946 * <P> The product of this method is not saved, and is recalculated
949 * @return the number of processes on this server.
950 * @exception AFSException If an error occurs
951 * in any of the associated native methods
952 * @see #getProcesses()
953 * @see #getProcessNames()
955 public int getProcessCount() throws AFSException
957 if (processNames != null) {
958 return processNames.size();
959 } else if (processes != null) {
960 return processes.size();
962 return getProcessCount(getBosHandle());
967 * Retrieves an array containing all of the <code>Process</code> objects
968 * associated with this <code>Server</code>, each of which are an abstract
969 * representation of an actual AFS process of the AFS server.
970 * After this method is called once, it saves the array of
971 * <code>Process</code>es and returns that saved array on subsequent calls,
972 * until the {@link #refresh()} method is called and a more current list
975 * @return a <code>Process</code> array of the <code>Process</code>
976 * objects of the server.
977 * @exception AFSException If an error occurs in the native code
980 public Process[] getProcesses() throws AFSException
982 if ( processes == null ) refreshProcesses();
983 if ( processes != null) {
984 return (Process[]) processes.toArray( new Process[processes.size()] );
990 * Retrieves an array containing all of the names of processes
991 * associated with this <code>Server</code> (i.e. "kaserver", etc.).
992 * After this method is called once, it saves the array of
993 * <code>String</code>s and returns that saved array on subsequent calls,
994 * until the {@link #refresh()} method is called and a more current
997 * @return a <code>String</code> array of the processes of the server.
998 * @exception AFSException If an error occurs in the native code
1001 public String[] getProcessNames() throws AFSException
1003 if ( processNames == null ) refreshProcessNames();
1004 return (String[]) processNames.toArray( new String[processNames.size()] );
1008 * Returns whether or not this server is a database machine, meaning it runs
1009 * processes such as the "kaserver" and "vlserver", and participates in
1012 * @return whether or not this user this server is a database machine.
1013 * @exception AFSException If an error occurs in the native code
1016 public boolean isDatabase() throws AFSException
1018 if (!cachedInfo) refreshInfo();
1023 * Returns whether or not this server is a file server machine, meaning it
1024 * runs the "fs" process and stores AFS volumes.
1026 * @return whether or not this user this server is a file server machine.
1027 * @exception AFSException If an error occurs in the native code
1030 public boolean isFileServer() throws AFSException
1032 if (!cachedInfo) refreshInfo();
1037 * Returns whether or not this server is a database machine AND
1038 * either it isn't in reality (e.g. it's incorrectly configured)
1039 * or it's currently down.
1041 * @return whether or not this server is a database machine
1042 * AND either it isn't in reality or it's currently down
1043 * @exception AFSException If an error occurs in the native code
1046 public boolean isBadDatabase() throws AFSException
1048 if (!cachedInfo) refreshInfo();
1053 * Returns whether this machine thinks it's a file server AND
1054 * either it isn't in reality (e.g. it's incorrectly configured)
1055 * or it's currently down.
1057 * @return whether or not this server is a file server machine AND
1058 * either it isn't in reality or it's currently down
1059 * @exception AFSException If an error occurs in the native code
1062 public boolean isBadFileServer() throws AFSException
1064 if (!cachedInfo) refreshInfo();
1065 return badFileServer;
1069 * Returns this server's IP address as a String. It returns it in
1070 * dotted quad notation (i.e. 123.123.123.123).
1072 * @return this server's IP address as a String
1073 * @exception AFSException If an error occurs in the native code
1076 public String[] getIPAddresses() throws AFSException
1078 if (!cachedInfo) refreshInfo();
1080 for (int i = 0; i < n; i++) {
1081 if (ipAddresses[i] == null) {
1086 String[] addresses = new String[n];
1087 System.arraycopy(ipAddresses, 0, addresses, 0, n);
1092 * Returns the BOS Server's general restart time in the form of an
1093 * ExecutableTime object. This is the time at which the bos server
1094 * restarts itself and all running processes. After this method
1095 * is called once, it saves the time and returns
1096 * that value on subsequent calls, until the {@link #refresh()} method
1097 * is called and a more current value is obtained.
1099 * @return the general restart time
1100 * @exception AFSException If an error occurs in the native code
1101 * @see Server.ExecutableTime
1104 public ExecutableTime getGeneralRestartTime() throws AFSException
1106 if (genRestartTime == null) refreshGeneralRestart();
1107 return genRestartTime;
1111 * Returns the BOS Server's binary restart time in the form of an
1112 * ExecutableTime object. This is the time at which all new or newly
1113 * modified AFS binaries are restarted. After this method
1114 * is called once, it saves the time and returns
1115 * that value on subsequent calls, until the {@link #refresh()} method
1116 * is called and a more current value is obtained.
1118 * @return the binary restart time
1119 * @exception AFSException If an error occurs in the native code
1120 * @see Server.ExecutableTime
1123 public ExecutableTime getBinaryRestartTime() throws AFSException
1125 if (binRestartTime == null) refreshBinaryRestart();
1126 return binRestartTime;
1130 * Returns the total space on this server (a sum of the space of all the
1131 * partitions associated with this server). If this server is not a
1132 * file server, zero will be returned. After this method
1133 * is called once, it saves the total space and returns
1134 * that value on subsequent calls, until the {@link #refresh()} method
1135 * is called and a more current value is obtained.
1137 * @return the total space on this server
1138 * @exception AFSException If an error occurs in the native code
1141 public int getTotalSpace() throws AFSException
1143 if (partitions == null) refreshPartitions(true);
1144 if (!isFileServer() || isBadFileServer()) return 0;
1145 if (totalSpace == 0) {
1146 Partition[] partitions = getPartitions();
1147 for (int i = 0; i < partitions.length; i++) {
1148 totalSpace += partitions[i].getTotalSpace();
1155 * Returns the total free space on this server (a sum of the free space of
1156 * all the partitions associated with this server). If this server is not a
1157 * file server, zero will be returned. After this method
1158 * is called once, it saves the total free space and returns
1159 * that value on subsequent calls, until the {@link #refresh()} method
1160 * is called and a more current value is obtained.
1162 * @return the total free space on this server
1163 * @exception AFSException If an error occurs in the native code
1166 public int getTotalFreeSpace() throws AFSException
1168 if (partitions == null) refreshPartitions(true);
1169 if (!isFileServer() || isBadFileServer()) return 0;
1170 if (totalFreeSpace == 0) {
1171 Partition[] partitions = getPartitions();
1172 for (int i = 0; i < partitions.length; i++) {
1173 totalFreeSpace += partitions[i].getTotalFreeSpace();
1176 return totalFreeSpace;
1180 * Returns the total used space on this server (a sum of the used space of
1181 * all the partitions associated with this server). If this server is not a
1182 * file server, zero will be returned. After this method
1183 * is called once, it saves the total used space and returns
1184 * that value on subsequent calls, until the {@link #refresh()} method
1185 * is called and a more current value is obtained.
1187 * @return the total space on this partition
1188 * @exception AFSException If an error occurs in the native code
1189 * @see #getTotalSpace()
1190 * @see #getTotalFreeSpace()
1192 public int getTotalUsedSpace() throws AFSException
1194 if (totalUsedSpace == 0) {
1195 totalUsedSpace = getTotalSpace() - getTotalFreeSpace();
1197 return totalUsedSpace;
1201 * Returns this server's vos handle.
1203 * @return this server's vos handle
1204 * @exception AFSException If an error occurs in the native code
1206 protected long getVosHandle() throws AFSException
1208 if ( vosHandle == 0 ) {
1209 vosHandle = getVosServerHandle( cell.getCellHandle(), name );
1215 * Returns this server's bos handle.
1217 * @return this server's bos handle
1218 * @exception AFSException If an error occurs in the native code
1220 protected long getBosHandle() throws AFSException
1222 if ( bosHandle == 0 ) {
1223 bosHandle = getBosServerHandle( cell.getCellHandle(), name );
1228 //////////////// mutators: ////////////////////////
1231 * Sets the BOS general restart time. This is the time at which the bos
1232 * server restarts itself and all running processes.
1234 * @param executableTime Executable time object that represents what
1235 * the BOS Server's general restart time should be.
1236 * @exception AFSException If an error occurs in the native code
1237 * @see Server.ExecutableTime
1239 public void setGeneralRestartTime( ExecutableTime executableTime )
1242 this.setRestartTime( getBosHandle(), RESTART_GENERAL, executableTime );
1246 * Sets the BOS binary restart time. This is the time at which all new
1247 * or newly modified AFS binaries are restarted.
1249 * @param executableTime Executable time object that represents what
1250 * the BOS Server's binary restart time should be.
1251 * @exception AFSException If an error occurs in the native code
1252 * @see Server.ExecutableTime
1254 public void setBinaryRestartTime( ExecutableTime executableTime )
1257 this.setRestartTime( getBosHandle(), RESTART_BINARY, executableTime );
1260 /////////////// custom information methods ////////////////////
1263 * Returns a <code>String</code> representation of this <code>Server</code>.
1264 * Contains the information fields and a list of partitions, admin, and
1267 * @return a <code>String</code> representation of the <code>Server</code>
1269 public String getInfo()
1274 r = "Server: " + name + "\n";
1276 r += "\tdatabase: " + isDatabase() + "\t\tfileServer: " +
1277 isFileServer() + "\n";
1278 r += "\tbad database: " + isBadDatabase() + "\tbad fileServer: " +
1279 isBadFileServer() + "\n";
1280 //r += "\tAddress: " + getIPAddress()[0] + "\n";
1283 r += "\tGeneral restart date: " + getGeneralRestartTime() + "\n";
1284 r += "\tBinary restart date: " + getBinaryRestartTime() + "\n";
1286 if ( isFileServer() && !isBadFileServer() ) {
1287 r += "\tPartitions:\n";
1289 String parts[] = getPartitionNames();
1291 for( int i = 0; i < parts.length; i++ ) {
1292 r += "\t\t" + parts[i] + "\n";
1296 if ( (isDatabase() && !isBadDatabase()) ||
1297 (isFileServer() && !isBadFileServer()) ) {
1300 String ads[] = getAdminNames();
1302 for( int i = 0; i < ads.length; i++ ) {
1303 r += "\t\t" + ads[i] + "\n";
1307 if ( (isDatabase() && !isBadDatabase()) ||
1308 (isFileServer() && !isBadFileServer()) ) {
1309 r += "\tProcesses:\n";
1311 String pros[] = getProcessNames();
1313 for( int i = 0; i < pros.length; i++ ) {
1314 r += "\t\t" + pros[i] + "\n";
1318 } catch( Exception e ) {
1319 return e.toString();
1325 * Returns a <code>String</code> containing the <code>String</code>
1326 * representations of all the partitions of this <code>Server</code>.
1328 * @return a <code>String</code> representation of the partitions
1329 * @see Partition#getInfo
1331 public String getInfoPartitions() throws AFSException
1334 r = "Server: " + name + "\n\n";
1335 r += "--Partitions--\n";
1337 Partition parts[] = getPartitions();
1339 for( int i = 0; i < parts.length; i++ ) {
1340 r += parts[i].getInfo() + "\n";
1346 * Returns a <code>String</code> containing the <code>String</code>
1347 * representations of all the keys of this <code>Server</code>.
1349 * @return a <code>String</code> representation of the keys
1352 public String getInfoKeys() throws AFSException
1356 r = "Server: " + name + "\n\n";
1359 Key kys[] = getKeys();
1361 for( int i = 0; i < kys.length; i++ ) {
1362 r += kys[i].getInfo() + "\n";
1369 * Returns a <code>String</code> containing the <code>String</code>
1370 * representations of all the processes of this <code>Server</code>.
1372 * @return a <code>String</code> representation of the processes
1373 * @see Process#getInfo
1375 public String getInfoProcesses() throws AFSException
1379 r = "Server: " + name + "\n\n";
1380 r += "--Processes--\n";
1382 Process pros[] = getProcesses();
1384 for( int i = 0; i < pros.length; i++ ) {
1385 r += pros[i].getInfo() + "\n";
1390 /////////////// custom override methods ////////////////////
1393 * Compares two Server objects respective to their names and does not
1394 * factor any other attribute. Alphabetic case is significant in
1397 * @param server The Server object to be compared to this
1400 * @return Zero if the argument is equal to this Server's name, a
1401 * value less than zero if this Server's name is
1402 * lexicographically less than the argument, or a value greater
1403 * than zero if this Server's name is lexicographically
1404 * greater than the argument
1406 public int compareTo(Server server)
1408 return this.getName().compareTo(server.getName());
1412 * Comparable interface method.
1414 * @see #compareTo(Server)
1416 public int compareTo(Object obj)
1418 return compareTo((Server)obj);
1422 * Tests whether two <code>Server</code> objects are equal, based on their
1423 * names and hosting Cell.
1425 * @param otherServer the Server to test
1426 * @return whether the specifed Server is the same as this Server
1428 public boolean equals( Server otherServer )
1430 return ( name.equals(otherServer.getName()) ) &&
1431 ( this.getCell().equals(otherServer.getCell()) );
1435 * Returns the name of this <CODE>Server</CODE>
1437 * @return the name of this <CODE>Server</CODE>
1439 public String toString()
1444 /////////////// native methods ////////////////////
1447 * Opens a server for administrative vos use, based on the cell handle
1448 * provided. Returns a vos server handle to be used by other
1449 * methods as a means of identification.
1451 * @param cellHandle a cell handle previously returned by
1452 * a call to {@link #getCellHandle}
1453 * @param serverName the name of the server for which to retrieve
1455 * @return a vos handle to the server
1456 * @exception AFSException If an error occurs in the native code
1457 * @see #getCellHandle
1459 protected static native long getVosServerHandle( long cellHandle,
1461 throws AFSException;
1464 * Closes the given currently open vos server handle.
1466 * @param vosHandle the vos server handle to close
1467 * @exception AFSException If an error occurs in the native code
1469 protected static native void closeVosServerHandle( long vosHandle )
1470 throws AFSException;
1473 * Opens a server for administrative bos use, based on the cell handle
1474 * provided. Returns a bos server handle to be used by other methods
1475 * as a means of identification.
1477 * @param cellHandle a cell handle previously returned by a call
1478 * to {@link #getCellHandle}
1479 * @param serverName the name of the server for which to retrieve
1481 * @return a bos handle to the server
1482 * @exception AFSException If an error occurs in the native code
1483 * @see #getCellHandle
1485 protected static native long getBosServerHandle( long cellHandle,
1487 throws AFSException;
1490 * Closes the given currently open bos server handle.
1492 * @param bosHandle the bos server handle to close
1493 * @exception AFSException If an error occurs in the native code
1495 protected static native void closeBosServerHandle( long bosHandle )
1496 throws AFSException;
1499 * Fills in the information fields of the provided <code>Server</code>.
1501 * @param cellHandle the handle of the cell to which the server belongs
1502 * @see Cell#getCellHandle
1503 * @param name the name of the server for which to get the information
1504 * @param server the <code>Server</code> object in which to fill in
1507 * @exception AFSException If an error occurs in the native code
1509 protected static native void getServerInfo( long cellHandle, String name,
1511 throws AFSException;
1514 * Returns the total number of partitions hosted by the server denoted by
1515 * <CODE>serverHandle</CODE>, if the server is a fileserver.
1517 * @param cellHandle the handle of the cell to which the server belongs
1518 * @param serverHandle the vos handle of the server to which the
1520 * @return total number of partitions
1521 * @exception AFSException If an error occurs in the native code
1522 * @see Cell#getCellHandle
1523 * @see #getVosServerHandle
1525 protected static native int getPartitionCount( long cellHandle,
1527 throws AFSException;
1530 * Begin the process of getting the partitions on a server. Returns
1531 * an iteration ID to be used by subsequent calls to
1532 * <code>getPartitionsNext</code> and <code>getPartitionsDone</code>.
1534 * @param cellHandle the handle of the cell to which the server belongs
1535 * @see Cell#getCellHandle
1536 * @param serverHandle the vos handle of the server to which the
1538 * @see #getVosServerHandle
1539 * @return an iteration ID
1540 * @exception AFSException If an error occurs in the native code
1542 protected static native long getPartitionsBegin( long cellHandle,
1544 throws AFSException;
1547 * Returns the next partition of the server. Returns <code>null</code>
1548 * if there are no more partitions.
1550 * @param iterationId the iteration ID of this iteration
1551 * @see #getPartitionsBegin
1552 * @return the name of the next partition of the server
1553 * @exception AFSException If an error occurs in the native code
1555 protected static native String getPartitionsNextString( long iterationId )
1556 throws AFSException;
1559 * Fills the next partition object of the server. Returns 0 if there
1560 * are no more partitions, != 0 otherwise
1562 * @param iterationId the iteration ID of this iteration
1563 * @param thePartition the Partition object in which to fill the
1564 * values of the next partition
1565 * @see #getPartitionsBegin
1566 * @return 0 if there are no more servers, != 0 otherwise
1567 * @exception AFSException If an error occurs in the native code
1569 protected static native int getPartitionsNext( long iterationId,
1570 Partition thePartition )
1571 throws AFSException;
1574 * Signals that the iteration is complete and will not be accessed anymore.
1576 * @param iterationId the iteration ID of this iteration
1577 * @see #getPartitionsBegin
1578 * @exception AFSException If an error occurs in the native code
1580 protected static native void getPartitionsDone( long iterationId )
1581 throws AFSException;
1584 * Returns the total number of processes hosted by the server denoted by
1585 * <CODE>serverHandle</CODE>.
1587 * @param serverHandle the vos handle of the server to which the
1589 * @return total number of processes
1590 * @exception AFSException If an error occurs in the native code
1591 * @see #getVosServerHandle
1593 protected static native int getProcessCount( long serverHandle )
1594 throws AFSException;
1597 * Begin the process of getting the processes on a server. Returns
1598 * an iteration ID to be used by subsequent calls to
1599 * <code>getProcessesNext</code> and <code>getProcessesDone</code>.
1601 * @param serverHandle the bos handle of the server to which the
1603 * @see #getBosServerHandle
1604 * @return an iteration ID
1605 * @exception AFSException If an error occurs in the native code
1607 protected static native long getProcessesBegin( long serverHandle )
1608 throws AFSException;
1611 * Returns the next process of the server. Returns <code>null</code>
1612 * if there are no more processes.
1614 * @param iterationId the iteration ID of this iteration
1615 * @see #getProcessesBegin
1616 * @return the name of the next process of the cell
1617 * @exception AFSException If an error occurs in the native code
1619 protected static native String getProcessesNextString( long iterationId )
1620 throws AFSException;
1623 * Fills the next process object of the server. Returns 0 if there
1624 * are no more processes, != 0 otherwise.
1626 * @param serverHandle the handle of the BOS server that hosts the process
1627 * @see #getBosHandle
1628 * @param iterationId the iteration ID of this iteration
1629 * @param theProcess the Process object in which to fill the
1630 * values of the next process
1631 * @see #getProcessesBegin
1632 * @return 0 if there are no more processes, != otherwise
1633 * @exception AFSException If an error occurs in the native code
1635 protected static native int getProcessesNext( long serverHandle,
1637 Process theProcess )
1638 throws AFSException;
1641 * Signals that the iteration is complete and will not be accessed anymore.
1643 * @param iterationId the iteration ID of this iteration
1644 * @see #getProcessesBegin
1645 * @exception AFSException If an error occurs in the native code
1647 protected static native void getProcessesDone( long iterationId )
1648 throws AFSException;
1651 * Returns the total number of keys hosted by the server denoted by
1652 * <CODE>serverHandle</CODE>.
1654 * @param serverHandle the vos handle of the server to which the
1656 * @return total number of keys
1657 * @exception AFSException If an error occurs in the native code
1658 * @see #getVosServerHandle
1660 protected static native int getKeyCount( long serverHandle )
1661 throws AFSException;
1664 * Begin the process of getting the keys of a server. Returns
1665 * an iteration ID to be used by subsequent calls to
1666 * <code>getKeysNext</code> and <code>getKeysDone</code>.
1668 * @param serverHandle the bos handle of the server to which the keys belong
1669 * @see #getBosServerHandle
1670 * @return an iteration ID
1671 * @exception AFSException If an error occurs in the native code
1673 protected static native long getKeysBegin( long serverHandle )
1674 throws AFSException;
1677 * Returns the next key of the server. Returns 0 if there
1678 * are no more keys, != 0 otherwise.
1680 * @param iterationId the iteration ID of this iteration
1681 * @param theKey a {@link Key Key} object, in which to fill in the
1682 * properties of the next key.
1683 * @see #getKeysBegin
1684 * @return 0 if there are no more keys, != 0 otherwise
1685 * @exception AFSException If an error occurs in the native code
1687 protected static native int getKeysNext( long iterationId, Key theKey )
1688 throws AFSException;
1691 * Signals that the iteration is complete and will not be accessed anymore.
1693 * @param iterationId the iteration ID of this iteration
1694 * @see #getKeysBegin
1695 * @exception AFSException If an error occurs in the native code
1697 protected static native void getKeysDone( long iterationId )
1698 throws AFSException;
1701 * Returns the total number of BOS administrators associated with the server
1702 * denoted by <CODE>serverHandle</CODE>.
1704 * @param serverHandle the vos handle of the server to which the
1706 * @return total number of BOS administrators
1707 * @exception AFSException If an error occurs in the native code
1708 * @see #getVosServerHandle
1710 protected static native int getBosAdminCount( long serverHandle )
1711 throws AFSException;
1714 * Begin the process of getting the bos amdinistrators on a server. Returns
1715 * an iteration ID to be used by subsequent calls to
1716 * <code>getBosAdminsNext</code> and <code>getBosAdminsDone</code>.
1718 * @param serverHandle the bos handle of the server to which the
1720 * @see #getBosServerHandle
1721 * @return an iteration ID
1722 * @exception AFSException If an error occurs in the native code
1724 protected static native long getBosAdminsBegin( long serverHandle )
1725 throws AFSException;
1728 * Returns the next bos admin of the server. Returns <code>null</code>
1729 * if there are no more admins.
1731 * @param iterationId the iteration ID of this iteration
1732 * @see #getBosAdminsBegin
1733 * @return the name of the next admin of the server
1734 * @exception AFSException If an error occurs in the native code
1736 protected static native String getBosAdminsNextString( long iterationId )
1737 throws AFSException;
1740 * Returns the next bos admin of the server. Returns 0 if there
1741 * are no more admins, != 0 otherwise.
1743 * @param cellHandle the handle of the cell to which these admins belong
1744 * @see #getCellHandle
1745 * @param iterationId the iteration ID of this iteration
1746 * @see #getBosAdminsBegin
1747 * @param theUser the user object in which to fill the values of this admin
1748 * @return 0 if no more admins, != 0 otherwise
1749 * @exception AFSException If an error occurs in the native code
1751 protected static native int getBosAdminsNext( long cellHandle,
1752 long iterationId, User theUser )
1753 throws AFSException;
1756 * Signals that the iteration is complete and will not be accessed anymore.
1758 * @param iterationId the iteration ID of this iteration
1759 * @see #getBosAdminsBegin
1760 * @exception AFSException If an error occurs in the native code
1762 protected static native void getBosAdminsDone( long iterationId )
1763 throws AFSException;
1766 * Adds the given to name to the list of bos administrators on that server.
1768 * @param serverHandle the bos handle of the server to which the
1770 * @see #getBosServerHandle
1771 * @param adminName the name of the admin to add to the list
1772 * @exception AFSException If an error occurs in the native code
1774 protected static native void addBosAdmin( long serverHandle,
1776 throws AFSException;
1779 * Removes the given to name from the list of bos administrators on
1782 * @param serverHandle the bos handle of the server to which the
1784 * @see #getBosServerHandle
1785 * @param adminName the name of the admin to remove from the list
1786 * @exception AFSException If an error occurs in the native code
1788 protected static native void removeBosAdmin( long serverHandle,
1790 throws AFSException;
1793 * Salvages (restores consistency to) a volume, partition, or server
1795 * @param cellHandle the handle of the cell to which the volume belongs
1796 * @see #getCellHandle
1797 * @param serverHandle the bos handle of the server on which the
1799 * @see #getBosServerHandle
1800 * @param partitionName the name of the partition to salvage,
1801 * can be <code>null</code> only if volName is
1803 * @param volName the name of the volume to salvage,
1804 * can be <code>null</code>
1805 * @param numSalvagers the number of salvager processes to run in parallel
1806 * @param tempDir directory to place temporary files, can be
1808 * @param logFile where salvager log will be written, can be
1810 * @param inspectAllVolumes whether or not to inspect all volumes,
1811 * not just those marked as active at crash
1812 * @param removeBadlyDamaged whether or not to remove a volume if it's
1814 * @param writeInodes whether or not to record a list of inodes modified
1815 * @param writeRootInodes whether or not to record a list of AFS
1816 * inodes owned by root
1817 * @param forceDirectory whether or not to salvage an entire directory
1819 * @param forceBlockReads whether or not to force the salvager to read
1821 * one block at a time and skip badly damaged
1822 * blocks. Use if partition has disk errors
1824 protected static native void salvage( long cellHandle, long serverHandle,
1825 String partitionName, String volName,
1826 int numSalvagers, String tempDir,
1828 boolean inspectAllVolumes,
1829 boolean removeBadlyDamaged,
1830 boolean writeInodes,
1831 boolean writeRootInodes,
1832 boolean forceDirectory,
1833 boolean forceBlockReads)
1834 throws AFSException;
1837 * Synchronizes a particular server with the volume location database.
1839 * @param cellHandle the handle of the cell to which the server belongs
1840 * @see #getCellHandle
1841 * @param serverHandle the vos handle of the server
1842 * @see #getVosServerHandle
1843 * @param partition the id of the partition to sync, can be -1 to ignore
1844 * @exception AFSException If an error occurs in the native code
1846 protected static native void syncServerWithVLDB( long cellHandle,
1849 throws AFSException;
1852 * Synchronizes the volume location database with a particular server.
1854 * @param cellHandle the handle of the cell to which the server belongs
1855 * @see #getCellHandle
1856 * @param serverHandle the vos handle of the server
1857 * @see #getVosServerHandle
1858 * @param partition the id of the partition to sync, can be -1 to ignore
1859 * @param forceDeletion whether or not to force the deletion of bad volumes
1860 * @exception AFSException If an error occurs in the native code
1862 protected static native void syncVLDBWithServer( long cellHandle,
1865 boolean forceDeletion )
1866 throws AFSException;
1869 * Retrieves a specified bos log from a server. Right now this
1870 * method will simply return a huge String containing the log, but
1871 * hopefully we can devise a better way to make this work more efficiently.
1873 * @param serverHandle the bos handle of the server to which the key belongs
1874 * @see #getBosServerHandle
1875 * @param logLocation the full path and name of the desired bos log
1876 * @exception AFSException If an error occurs in the native code
1878 protected static native String getLog( long serverHandle, String logLocation )
1879 throws AFSException;
1882 * Fills in the restart time fields of the given {@link Server Server}
1885 * @param serverHandle the bos handle of the server to which the key belongs
1886 * @see #getBosServerHandle
1887 * @param restartType whether to get the general or binary restart.
1888 * Acceptable values are:<ul>
1889 * <li>{@link RESTART_BINARY}</li>
1890 * <li>{@link RESTART_GENERAL}</li></ul>
1891 * @param theServer the <code>Server</code> object, in which to fill
1892 * the restart time fields
1893 * @exception AFSException If an error occurs in the native code
1895 private static native void getRestartTime( long serverHandle,
1897 ExecutableTime executableTime )
1898 throws AFSException;
1901 * Sets the restart time of the bos server.
1903 * @param serverHandle the bos handle of the server to which the key belongs
1904 * @see #getBosServerHandle
1905 * @param restartType whether this is to be a general or binary restart.
1906 * Acceptable values are:<ul>
1907 * <li>{@link RESTART_BINARY}</li>
1908 * <li>{@link RESTART_GENERAL}</li></ul>
1909 * @param theServer the server object containing the desired information
1910 * @exception AFSException If an error occurs in the native code
1912 private static native void setRestartTime( long serverHandle,
1914 ExecutableTime executableTime )
1915 throws AFSException;
1918 * Start all server processes.
1920 * @param serverHandle the bos handle of the server to which the
1922 * @see #getBosServerHandle
1923 * @exception AFSException If an error occurs in the native code
1925 protected static native void startAllProcesses( long serverHandle )
1926 throws AFSException;
1929 * Restart all server processes.
1931 * @param serverHandle the bos handle of the server to which the
1933 * @see #getBosServerHandle
1934 * @param restartBosServer whether or not to restart the bos server as well
1935 * @exception AFSException If an error occurs in the native code
1937 protected static native void restartAllProcesses( long serverHandle,
1938 boolean restartBosServer )
1939 throws AFSException;
1942 * Stop all server processes.
1944 * @param serverHandle the bos handle of the server to which the
1946 * @see #getBosServerHandle
1947 * @exception AFSException If an error occurs in the native code
1949 protected static native void stopAllProcesses( long serverHandle )
1950 throws AFSException;
1953 * Reclaims all memory being saved by the server portion of the native
1954 * library. This method should be called when no more <code>Server</code>
1955 * objects are expected to be used.
1957 protected static native void reclaimServerMemory();
1959 /*====================================================================*/
1961 /*====================================================================*/
1962 public static final class ExecutableTime implements Serializable
1964 public static final short NEVER = 0;
1965 public static final short NOW = 1;
1967 public static final short EVERYDAY = -1;
1968 public static final short SUNDAY = 0;
1969 public static final short MONDAY = 1;
1970 public static final short TUESDAY = 2;
1971 public static final short WEDNESDAY = 3;
1972 public static final short THURSDAY = 4;
1973 public static final short FRIDAY = 5;
1974 public static final short SATURDAY = 6;
1976 static final DecimalFormat formatter =
1977 (DecimalFormat)DecimalFormat.getInstance();
1979 private short second;
1980 private short minute;
1983 private boolean now;
1984 private boolean never;
1988 formatter.applyPattern("00");
1992 * Internal constructor used to construct an empty object that will
1993 * be passed to JNI for member synchronization of the BOS Server
1994 * executable time this object represents.
1998 this.second = (short) 0;
1999 this.minute = (short) 0;
2000 this.hour = (short) 0;
2001 this.day = (short) -1;
2007 * Constructs an <code>ExecutableTime</code> object that represents either
2008 * a "<CODE>now</CODE>" <B>or</B> "<CODE>never</CODE>" BOS Executable
2011 * <P>Valid values for the <CODE>type</CODE> parameter are ExecutableTime.NOW
2012 * or ExecutableTime.NEVER. If a value other than these two is used an
2013 * IllegalArgumentException will be thrown.
2015 * @param type either ExecutableTime.NOW or ExecutableTime.NEVER
2016 * @exception IllegalArgumentException
2017 * If a value other than ExecutableTime.NOW or
2018 * ExecutableTime.NEVER is used for the <CODE>type</CODE>
2022 * @see #Server.ExecutableTime(short, short, short)
2024 public ExecutableTime(short type) throws IllegalArgumentException
2029 } else if (type == NEVER) {
2033 throw new IllegalArgumentException("You must specify either " +
2034 "ExecutableTime.NOW or " +
2035 "ExecutableTime.NEVER when " +
2036 "using this constructor.");
2038 this.second = (short) 0;
2039 this.minute = (short) 0;
2040 this.hour = (short) 0;
2041 this.day = (short) -1;
2045 * Constructs an <code>ExecutableTime</code> object that may be used to
2046 * represent a <U>daily</U> BOS Executable Restart Time of a process.
2048 * @param second the second field for this representation of a
2049 * BOS Server restart time value (range: 0-59)
2050 * @param minute the minute field for this representation of a
2051 * BOS Server restart time value (range: 0-59)
2052 * @param hour the hour field for this representation of a BOS
2053 * Server restart time value (range: 0-23)
2054 * @exception IllegalArgumentException
2055 * If any of the parameters values are out of range
2056 * of their respective fields.
2057 * @see #Server.ExecutableTime(short, short, short, short)
2062 public ExecutableTime(short second, short minute, short hour)
2063 throws IllegalArgumentException
2065 this(second, minute, hour, ExecutableTime.EVERYDAY);
2069 * Constructs an <code>ExecutableTime</code> object that may be used to
2070 * represent the BOS Executable Restart Time of a process.
2072 * @param second the second field for this representation of a
2073 * BOS Server restart time value (range: 0-59)
2074 * @param minute the minute field for this representation of a
2075 * BOS Server restart time value (range: 0-59)
2076 * @param hour the hour field for this representation of a BOS
2077 * Server restart time value (range: 0-23)
2078 * @param day the day field for this representation of a BOS
2079 * Server restart time value.<BR><UL>Valid values include:
2080 * <CODE>ExecutableTime.EVERYDAY</CODE> (see also {@link
2081 * #Server.ExecutableTime(short, short, short)})<BR>
2083 * ExecutableTime.SUNDAY<BR>
2084 * ExecutableTime.MONDAY<BR>
2085 * ExecutableTime.TUESDAY<BR>
2086 * ExecutableTime.WEDNESDAY<BR>
2087 * ExecutableTime.THURSDAY<BR>
2088 * ExecutableTime.FRIDAY<BR>
2089 * ExecutableTime.SATURDAY<BR>
2091 * @exception IllegalArgumentException
2092 * If any of the parameters values are out of range
2093 * of their respective fields.
2094 * @see #Server.ExecutableTime(short, short, short)
2100 public ExecutableTime(short second, short minute, short hour, short day)
2102 if ( (0 > second || second > 59) ||
2103 (0 > minute || minute > 59) ||
2104 (0 > hour || hour > 24) ||
2105 (-1 > day || day > 6) ) {
2106 throw new IllegalArgumentException("One of the specified values " +
2109 this.second = second;
2110 this.minute = minute;
2118 * Returns the second of this ExecutableTime object.
2120 * @return the second of this ExecutableTime object.
2121 * @exception IllegalStateException
2122 * If the executable time this object represents has a value of
2123 * "<CODE>now</CODE>" or "<CODE>never</CODE>".
2125 public short getSecond() throws IllegalStateException
2128 throw new IllegalStateException("Executable time is set to 'now' or" +
2135 * Returns the minute of this ExecutableTime object.
2137 * @return the minute of this ExecutableTime object.
2138 * @exception IllegalStateException
2139 * If the executable time this object represents has a value of
2140 * "<CODE>now</CODE>" or "<CODE>never</CODE>".
2142 public short getMinute() throws IllegalStateException
2145 throw new IllegalStateException("Executable time is set to 'now' or" +
2152 * Returns the hour of this ExecutableTime object, in 24 hour time.
2154 * @return the hour of this ExecutableTime object.
2155 * @exception IllegalStateException
2156 * If the executable time this object represents has a value of
2157 * "<CODE>now</CODE>" or "<CODE>never</CODE>".
2159 public short getHour() throws IllegalStateException
2162 throw new IllegalStateException("Executable time is set to 'now' or" +
2169 * Returns a numeric representation of the day of this ExecutableTime
2170 * object. If it is daily, the value of ExecutableTime.EVERYDAY is returned.
2172 * <P>Possible return values are:<BR>
2174 * ExecutableTime.EVERYDAY<BR>
2176 * ExecutableTime.SUNDAY<BR>
2177 * ExecutableTime.MONDAY<BR>
2178 * ExecutableTime.TUESDAY<BR>
2179 * ExecutableTime.WEDNESDAY<BR>
2180 * ExecutableTime.THURSDAY<BR>
2181 * ExecutableTime.FRIDAY<BR>
2182 * ExecutableTime.SATURDAY<BR>
2185 * @return a numeric representation of the day of this ExecutableTime
2187 * @exception IllegalStateException
2188 * If the executable time this object represents has a value of
2189 * "<CODE>now</CODE>" or "<CODE>never</CODE>".
2191 public short getDay() throws IllegalStateException
2194 throw new IllegalStateException("Executable time is set to 'now' or" +
2201 * Returns a String representation, name for the day of the week or
2202 * "Everyday", of this object's day property.
2204 * <P>Possible return values are:
2217 * @return the day of this ExecutableTime object.
2218 * @exception IllegalStateException
2219 * If the executable time this object represents has a value of
2220 * "<CODE>now</CODE>" or "<CODE>never</CODE>".
2223 public String getDayString() throws IllegalStateException
2247 * Returns whether or not the BOS restart time, represented by this
2248 * ExecutableTime object, is set to "<CODE>now</CODE>" or not.
2249 * This means that at some point in the past, when someone set it to
2250 * "<CODE>now</CODE>", the bosserver restarted all its processes,
2253 * @return whether or not the restart time is "<CODE>now</CODE>"
2255 public boolean isNow()
2261 * Returns the second of this ExecutableTime object.
2263 * @return the second of this ExecutableTime object.
2266 * Returns whether or not the BOS restart time, represented by this
2267 * ExecutableTime object, is set to "<CODE>never</CODE>" or not.
2268 * This means that the bosserver will never restart its processes.
2270 * @return whether or not the restart time is "<CODE>never</CODE>"
2272 public boolean isNever()
2278 * Tests whether two <code>ExecutableTime</code> objects are equal,
2280 * comparison of each of their respective properties. If
2281 * "<CODE>now</CODE>" or "<CODE>never</CODE>" is set in either object,
2282 * only those properties are analyzed.
2284 * @param time the ExecutableTime to test against
2285 * @return whether the specifed ExecutableTime is the same as this
2286 * ExecutableTime as defined above
2288 public boolean equals( ExecutableTime time )
2290 boolean same = false;
2292 same = ( (second == time.getSecond()) &&
2293 (minute == time.getMinute()) &&
2294 (hour == time.getHour() ) &&
2295 (day == time.getDay() ) );
2296 } catch (Exception e) {
2297 same = ( (now == time.isNow() ) &&
2298 (never == time.isNever() ) );
2305 * Returns the String representation of time value of this
2306 * <CODE>ExecutableTime</CODE> object.
2308 * <P> Possible return values:<BR>
2311 * <LI> Day and time string in the form:<BR>
2312 * <CODE><day> at <hh>:<MM>[:<ss>]</CODE>
2315 * <B>Example Return Values:</B><PRE>
2317 * Sunday at 05:10:30
2318 * Everyday at 20:00</PRE>
2320 * @return the String representation of this <CODE>ExecutableTime</CODE>
2323 public String toString()
2332 return getDayString() + " at " +
2333 ExecutableTime.formatter.format(hour) + ":" +
2334 ExecutableTime.formatter.format(minute) + ":" +
2335 ExecutableTime.formatter.format(second);
2337 return getDayString() + " at " +
2338 ExecutableTime.formatter.format(hour) + ":" +
2339 ExecutableTime.formatter.format(minute);
2341 } catch (Exception e) {
2348 /*====================================================================*/