2 import java
.util
.GregorianCalendar
;
4 import org
.openafs
.jafs
.*;
14 public class TesterThread
implements Runnable
16 private String user
= null;
17 private String pass
= null;
18 private String cell
= null;
19 private boolean letItRun
= true;
21 public TesterThread(String user
, String pass
, String cell
)
37 Token t
= new Token(user
, pass
, cell
);
38 Cell c
= new Cell(t
, false);
41 for(int j
=0; j
<100; j
++)
43 ACL acl
= new ACL("/afs/." + cell
, true);
47 } catch(Exception e
) {
56 static java
.io
.PrintStream out
= System
.out
;
57 static String firstCellPathRW
= null;
59 static boolean allowDump
= true;
63 static void DumpBegin()
67 for(int i
=0; i
<ident
; i
++)
71 static void Dump(String str
)
81 static void DumpLn(String str
)
88 public static String
getGregDateStr(GregorianCalendar gc
)
93 return gc
.getTime().toString();
96 public static void DumpToken(Token t
)
100 DumpLn("Token: user=" + t
.getUsername() +
101 " cell=" + t
.getCellName() + " expiration=" + t
.getExpiration());
102 } catch(AFSException e
) {
107 public static void DumpFile(org
.openafs
.jafs
.File f
)
113 Dump("File name: " + f
.getPath() + ": ");
114 if (f
.isDirectory()) {
115 Dump("This is a directory.");
116 } else if (f
.isLink()) {
117 Dump("This is a symbolic-link.");
118 Dump(" Its target is: " + f
.getTarget());
121 Dump(" This object is now a file!");
122 } else if (f
.isDirectory()) {
123 Dump(" This object is now a directory!");
124 } else if (f
.isMountPoint()) {
125 Dump(" This object is now a volume mount point!");
127 } else if (f
.isMountPoint()) {
128 Dump(" This is a volume mount point.");
129 } else if (f
.isFile()) {
130 Dump(" This is a file. Size: " + f
.length());
134 ACL acl
= new ACL(f
.getPath());
136 DumpLn(acl
.toString());
138 } catch(AFSException e
) {
143 public static void DumpCell(Cell cell
)
147 DumpLn("Cell: " + cell
.getName());
149 DumpLn("MaxGroupID: " + cell
.getMaxGroupID());
150 DumpLn("MaxUserID: " + cell
.getMaxUserID());
153 //test some queries, don't write to output
155 cell
.getInfoGroups();
156 cell
.getInfoServers();
158 } catch(AFSException e
) {
163 public static void DumpServer(Server s
)
165 DumpLn("Server: " + s
.getName());
169 try //pServer'SLES9 bug:
171 DumpLn("BinaryRestartTime: " + s
.getBinaryRestartTime());
172 } catch(AFSException e
) {
175 DumpLn("TotalFreeSpace:" + s
.getTotalFreeSpace());
176 DumpLn("TotalSpace:" + s
.getTotalSpace());
177 DumpLn("TotalUsedSpace:" + s
.getTotalUsedSpace());
178 DumpLn("GeneralRestartTime:" + s
.getGeneralRestartTime());
180 Dump("ip addresses: ");
181 String
[] ipAddrs
= s
.getIPAddresses();
182 for(int i
=0; i
<ipAddrs
.length
; i
++)
184 Dump(ipAddrs
[i
] + " ");
188 Dump("isFileServer: " + s
.isFileServer());
189 Dump(" isBadFileserver: " + s
.isBadFileServer());
190 Dump(" isDatabase: " + s
.isDatabase());
191 Dump(" isBadDatabase: " + s
.isBadDatabase());
192 } catch(AFSException e
) {
199 //test some queries, don't write to output
204 } catch(AFSException e
) {
207 try //is there any partitions? why parts can be null...
208 { //wrong programming concept: null instead of an empty array !!!
209 s
.getInfoPartitions();
210 } catch(Exception e
) {
213 s
.getInfoProcesses();
214 } catch(AFSException e
) {
219 public static void DumpVolume(Volume v
)
224 Dump("Volume name: " + v
.getName());
225 Dump(" ID: " + v
.getID());
227 } catch(AFSException e
) {
235 Dump("BackupID: " + v
.getBackupID());
236 Dump(" ReadOnlyID: " + v
.getReadOnlyID());
237 Dump(" ReadWriteID: " + v
.getReadWriteID());
240 Dump("LastUpdateDate: " + getGregDateStr(v
.getLastUpdateDate()));
241 Dump(" CreationDate: " + getGregDateStr(v
.getCreationDate()));
242 Dump(" AccessesSinceMidnight: " + v
.getAccessesSinceMidnight());
245 Dump("FileCount: " + v
.getFileCount());
246 Dump(" CurrentSize: " + v
.getCurrentSize());
247 Dump(" TotalFreeSpace: " + v
.getTotalFreeSpace());
250 Dump("Type: " + v
.getType());
251 Dump(" Disposition: " + v
.getDisposition());
254 //test some queries, don't write to output
256 } catch(AFSException e
) {
262 public static void DumpPartition(Partition p
)
267 Dump("Partition name: " + p
.getName());
268 Dump(" ID: " + p
.getID());
269 Dump(" DeviceName: " + p
.getDeviceName());
271 } catch(AFSException e
) {
278 Dump("TotalFreeSpace: " + p
.getTotalFreeSpace());
279 Dump(" TotalQuota: " + p
.getTotalQuota());
280 Dump(" TotalTotalSpace: " + p
.getTotalSpace());
283 //test some queries, don't write to output
286 } catch(AFSException e
) {
292 public static void DumpGroup(Group g
)
297 Dump("Group name: " + g
.getName());
298 Dump(" Type: " + g
.getType());
299 Dump(" UID: " + g
.getUID());
302 //test some queries, don't write to output
304 } catch(AFSException e
) {
309 public static void DumpUser(User u
)
311 DumpLn("User name: " + u
.getName());
316 DumpLn("EncryptionKey" + u
.getEncryptionKey());
318 Dump("DaysToPasswordExpire: " + u
.getDaysToPasswordExpire());
319 Dump(" FailLoginCount: " + u
.getFailLoginCount());
320 Dump(" KeyCheckSum: " + u
.getKeyCheckSum());
323 Dump("UserExpirationDate: " + getGregDateStr(u
.getUserExpirationDate()));
324 Dump(" MaxTicketLifetime: " + u
.getMaxTicketLifetime());
325 Dump(" LockedUntilDate: " + getGregDateStr(u
.getLockedUntilDate()));
329 //test some queries, don't write to output
332 u
.getInfoGroupsOwned();
333 } catch(AFSException e
) {
339 static void DumpProcess(org
.openafs
.jafs
.Process p
)
341 DumpLn("Process name: " + p
.getName());
347 Dump("StartTimeDate: " + getGregDateStr(p
.getStartTimeDate()));
348 Dump(" ExitTimeDate: " + getGregDateStr(p
.getExitTimeDate()));
351 //test some queries, don't write to output
353 } catch(AFSException e
) {
359 public static Token
testToken(String user
, String pass
, String cell
)
364 token
= new Token(user
, pass
, cell
);
367 } catch(AFSException e
) {
373 public static void testFilesRecursive(File dir
)
377 java
.io
.File fj
= new java
.io
.File(dir
.getPath());
378 String
[] strSubdirs
= fj
.list();
379 for(int i
=0; i
<strSubdirs
.length
; i
++)
381 org
.openafs
.jafs
.File f
= new org
.openafs
.jafs
.File(
382 dir
.getPath() + "/" + strSubdirs
[i
]);
385 if (f
.isDirectory() || f
.isMountPoint() || f
.isLink())
387 testFilesRecursive(dir
);
390 } catch(AFSFileException e
) {
395 public static void testFiles()
396 throws AFSException
, AFSFileException
398 org
.openafs
.jafs
.File f
= new org
.openafs
.jafs
.File(firstCellPathRW
);
400 testFilesRecursive(f
);
403 public static void testCell(Token token
)
408 cell
= new Cell(token
, false);
411 } catch(AFSException e
) {
420 Group
[] groups
= cell
.getGroups();
421 for(int i
=0; i
<groups
.length
; i
++)
423 testGroup(groups
[i
]);
426 Server
[] servers
= cell
.getServers();
427 for(int j
=0; j
<servers
.length
; j
++)
429 testServer(servers
[j
]);
431 } catch(AFSException e
) {
440 } catch(AFSException e
) {
445 public static void testServer(Server server
)
452 Partition
[] parts
= server
.getPartitions();
455 for(int i
=0; i
<parts
.length
; i
++)
457 testPartition(parts
[i
]);
461 org
.openafs
.jafs
.Process
[] procs
= server
.getProcesses();
464 for(int i
=0; i
<procs
.length
; i
++)
466 DumpProcess(procs
[i
]);
470 DumpLn("salvage...");
475 server
.getLog("/var/log/openafs/BosLog");
476 } catch(AFSException e
) {
479 //DumpLn("stopAllProcesses...");
480 //server.stopAllProcesses();
481 //DumpLn("startAllProcesses...");
482 //server.startAllProcesses();
483 DumpLn("syncServer...");
485 DumpLn("syncVLDB...");
488 } catch(AFSException e
) {
494 public static void testProcess(org
.openafs
.jafs
.Process p
)
500 public static void testPartition(Partition part
)
506 Volume
[] vols
= part
.getVolumes();
507 for(int i
=0; i
<vols
.length
; i
++)
515 public static void testVolume(Volume vol
)
521 public static void testGroup(Group group
)
527 User
[] users
= group
.getMembers();
528 for(int i
=0; i
<users
.length
; i
++)
536 public static void testUser(User user
)
542 public static void testNewVolume(String cellName
, String userName
, String passString
)
544 if (firstCellPathRW
==null)
546 System
.err
.println("testNewVolume cannot be executed (null args).");
550 String volName
= "myTestJafsVolume92834";
551 String mpName
= firstCellPathRW
+ "/" + volName
;
554 Token token
= new Token(cellName
, userName
, passString
);
555 Cell cell
= new Cell(token
, false);
556 Server
[] servers
= cell
.getServers();
557 if (servers
.length
==0)
559 System
.err
.println("Error: failed to run\"testNewVolume\"!");
562 Partition firstPart
= null;
564 for(i
=0; i
<servers
.length
; i
++)
566 Partition
[] parts
= servers
[i
].getPartitions();
572 firstPart
= parts
[0];
578 System
.err
.println("Error: failed to find any partition on any server - \"testNewVolume\" couldn't be tested!");
582 Volume v
= new Volume(volName
, firstPart
);
583 DumpLn("Creating a new volume " + volName
+ " ...");
589 volName
= "myTestJafsVolume2389";
590 DumpLn("Renaming volume to " + volName
+ " ...");
593 DumpLn("Creating an rw mount point " + mpName
+ " ...");
594 v
.createMountPoint(mpName
, true);
596 DumpLn("Deleting mount point...");
597 java
.lang
.Runtime
.getRuntime().exec("fs rmmount " + mpName
);
599 DumpLn("Creating RO...");
600 Volume volRO
= v
.createReadOnly(firstPart
);
602 DumpLn("Creating backup...");
605 DumpLn("Releaseing volume...");
608 //v.moveTo(); //needs a more careful test env
610 DumpLn("Salvaging volume...");
613 DumpLn("Deleting volume...");
616 DumpLn("Deleting RO site...");
620 } catch(Exception e
) {
625 public static void main(String
[] args
)
632 System
.err
.println("testAFS <user> <pass> <cell_name> <# of cycles>");
636 Class
.forName("org.openafs.jafs.Token"); //initialization...
637 System
.out
.println("Java interface version: " + VersionInfo
.getVersionOfJavaInterface());
638 System
.out
.println("Library version: " + VersionInfo
.getVersionOfLibrary());
639 System
.out
.println("Build info: " + VersionInfo
.getBuildInfo());
641 //first test whether token is valid
642 //and load libraries with it
643 Token t0
= new Token(args
[0], args
[1], args
[2]);
646 System
.out
.print("Starting another tester thread...");
647 testAFS ta
= new testAFS();
648 TesterThread tt
= ta
.new TesterThread(args
[0], args
[1], args
[2]);
649 Thread tTest
= new Thread(tt
);
651 System
.out
.println("started.");
653 firstCellPathRW
= "/afs/." + args
[2];
654 int numOfCycles
= Integer
.parseInt(args
[3]);
655 for(int i
=0; i
<numOfCycles
|| numOfCycles
==0; i
++)
657 testToken(args
[0], args
[1], args
[2]);
661 testNewVolume(args
[0], args
[1], args
[2]);
663 System
.out
.print("ACL excercising...");
665 for(int j
=0; j
<100; j
++)
668 System
.out
.print(".");
670 System
.out
.println();
673 AFSException afs
= new AFSException(1);
675 System
.out
.println("cycle #" + (i
+1) + "/" + numOfCycles
+ " done.");
679 System
.out
.println("All done.");
680 } catch (Exception e
) {