3 =head1 NAME $RCSfile: Vob.pm,v $
5 Object oriented interface to a Clearcase VOB
13 Andrew DeFaria <Andrew@ClearSCM.com>
21 Thu Dec 29 12:07:59 PST 2005
25 $Date: 2011/11/16 19:46:13 $
31 Provides access to information about a Clearcase VOB. Note that information
32 about the number of elements, branches, etc. that is provided by countdb are not
33 initially instantiated with the VOB object, rather those member variables are
34 expanded if and when accessed. This helps the VOB object to be more efficient.
37 my $vob = new Clearcase::Vob (tag => "/vobs/test");
39 # Access member variables...
40 display "Tag:\t\t" . $vob->tag;
41 display "Global path:\t" . $vob->gpath;
42 display "Sever host:\t" . $vob->shost;
43 display "Access:\t\t" . $vob->access;
44 display "Mount options:\t" . $vob->mopts;
45 display "Region:\t\t" . $vob->region;
46 display "Active:\t\t" . $vob->active;
47 display "Replica UUID:\t" . $vob->replica_uuid;
48 display "Host:\t\t" . $vob->host;
49 display "Access path:\t" . $vob->access_path;
50 display "Family UUID:\t" . $vob->family_uuid;
52 # This members are not initially expanded until accessed
53 display "Elements:\t" . $vob->elements;
54 display "Branches:\t" . $vob->branches;
55 display "Versions:\t" . $vob->versions;
56 display "DB Size:\t" . $vob->dbsize;
57 display "Adm Size:\t" . $vob->admsize;
58 display "CT Size:\t" . $vob->ctsize;
59 display "DO Size:\t" . $vob->dbsize;
60 display "Src Size:\t" . $vob->srcsize;
61 display "Size:\t\t" . $vob->size;
64 display "Umounting " . $vob->tag . "...";
68 display "Mounting " . $vob->tag . "...";
74 This module, and others below the Clearcase directory, implement an object
75 oriented approach to Clearcase. In general Clearcase entities are made into
76 objects that can be manipulated easily in Perl. This module is the main or
77 global module. Contained herein are members and methods of a general or global
78 nature. Also contained here is an IPC interface to cleartool such that cleartool
79 runs in the background andcommands are fed to it via the exec method. When
80 making repeated calls to cleartool this can result in a substantial savings of
81 time as most operating systems' fork/exec sequence is time consuming. Factors of
82 8 fold improvement have been measured.
84 Additionally a global variable, $cc, is implemented from this module such that
85 you should not need to instantiate another one, though you could.
89 The following routines are exported:
93 package Clearcase::Vob;
102 my ($class, $tag) = @_;
108 Construct a new Clearcase VOB object. Note that not all members are
109 initially populated because doing so would be time consuming. Such
110 member variables will be expanded when accessed.
114 =for html <blockquote>
120 VOB tag to be instantiated. You can use either an object oriented call
121 (i.e. my $vob = new Clearcase::Vob (tag => "/vobs/test")) or the
122 normal call (i.e. my $vob = new Clearcase::Vob ("/vobs/test")). You
123 can also instantiate a new vob by supplying a tag and then later
124 calling the create method.
128 =for html </blockquote>
132 =for html <blockquote>
136 =item Clearcase VOB object
140 =for html </blockquote>
148 $class->updateVobInfo;
160 Returns the VOB's tag
164 =for html <blockquote>
172 =for html </blockquote>
176 =for html <blockquote>
184 =for html </blockquote>
198 Returns the VOB's global path
202 =for html <blockquote>
210 =for html </blockquote>
214 =for html <blockquote>
222 =for html </blockquote>
226 return $self->{gpath};
236 Returns the VOB's server host
240 =for html <blockquote>
248 =for html </blockquote>
252 =for html <blockquote>
256 =item VOB's server host
260 =for html </blockquote>
264 return $self->{shost};
274 Returns the type of VOB access
278 =for html <blockquote>
286 =for html </blockquote>
290 =for html <blockquote>
296 Returns either public for public VOBs or private for private VOBs
300 =for html </blockquote>
304 return $self->{access};
314 Returns the mount options
318 =for html <blockquote>
326 =for html </blockquote>
330 =for html <blockquote>
334 =item VOB's mount options
338 =for html </blockquote>
342 return $self->{mopts};
352 Returns the region for this VOB tag
356 =for html <blockquote>
364 =for html </blockquote>
368 =for html <blockquote>
376 =for html </blockquote>
380 return $self->{region};
390 Returns that active status (whether or not the vob is currently mounted) of the
395 =for html <blockquote>
403 =for html </blockquote>
407 =for html <blockquote>
411 =item Returns YES for an active VOB or NO for an inactive one
415 =for html </blockquote>
419 return $self->{active};
422 sub replica_uuid () {
429 Returns the VOBS replica_uuid
433 =for html <blockquote>
441 =for html </blockquote>
445 =for html <blockquote>
449 =item VOB replica_uuid
453 =for html </blockquote>
457 return $self->{replica_uuid};
467 Returns the VOB's host
471 =for html <blockquote>
479 =for html </blockquote>
483 =for html <blockquote>
491 =for html </blockquote>
495 return $self->{host};
505 Returns the VOB's access path
509 =for html <blockquote>
517 =for html </blockquote>
521 =for html <blockquote>
525 =item VOB access path
527 This is the path relative to the VOB's host
531 =for html </blockquote>
535 return $self->{access_path};
545 Returns the VOB family UUID
549 =for html <blockquote>
557 =for html </blockquote>
561 =for html <blockquote>
565 =item VOB family UUID
569 =for html </blockquote>
573 return $self->{family_uuid};
576 sub vob_registry_attributes () {
581 =head2 vob_registry_attributes
583 Returns the VOB Registry Attributes
587 =for html <blockquote>
595 =for html </blockquote>
599 =for html <blockquote>
603 =item VOB Registry Attributes
607 =for html </blockquote>
611 return $self->{vob_registry_attributes};
612 } # vob_registry_attributes
614 sub expand_space () {
617 my ($status, @output) = $Clearcase::CC->execute ("space -vob $self->{tag}");
619 # Initialize fields in case of command failure
621 $self->{admsize} = 0;
624 $self->{srcsize} = 0;
628 if (/(\d*\.\d).*VOB database(.*)/) {
629 $self->{dbsize} = $1;
630 } elsif (/(\d*\.\d).*administration data(.*)/) {
631 $self->{admsize} = $1;
632 } elsif (/(\d*\.\d).*cleartext pool(.*)/) {
633 $self->{ctsize} = $1;
634 } elsif (/(\d*\.\d).*derived object pool(.*)/) {
635 $self->{dosize} = $1;
636 } elsif (/(\d*\.\d).*source pool(.*)/) {
637 $self->{srcsize} = $1;
638 } elsif (/(\d*\.\d).*Subtotal(.*)/) {
649 # Set values to zero in case we cannot get the right values from countdb
650 $self->{elements} = 0;
651 $self->{branches} = 0;
652 $self->{versions} = 0;
654 # Countdb needs to be done in the vob's db directory
658 chdir "$self->{gpath}/db";
660 my $cmd = "$Clearcase::COUNTDB vob_db 2>&1";
672 if (/^ELEMENT\s*:\s*(\d*)/) {
673 $self->{elements} = $1;
674 } elsif (/^BRANCH\s*:\s*(\d*)/) {
675 $self->{branches} = $1;
676 } elsif (/^VERSION\s*:\s*(\d*)/) {
677 $self->{versions} = $1;
693 Returns the number of elements in the VOB (obtained via countdb)
697 =for html <blockquote>
705 =for html </blockquote>
709 =for html <blockquote>
713 =item number of elements
717 =for html </blockquote>
721 $self->countdb if !$self->{elements};
723 return $self->{elements};
733 Returns the number of branch types in the vob
737 =for html <blockquote>
745 =for html </blockquote>
749 =for html <blockquote>
753 =item number of branch types
757 =for html </blockquote>
761 $self->countdb if !$self->{branches};
763 return $self->{branches};
773 Returns the number of element versions in the VOB
777 =for html <blockquote>
785 =for html </blockquote>
789 =for html <blockquote>
793 =item number of element versions
797 =for html </blockquote>
801 $self->countdb if !$self->{versions};
803 return $self->{versions};
813 Returns the size of the VOB's database
817 =for html <blockquote>
825 =for html </blockquote>
829 =for html <blockquote>
837 =for html </blockquote>
841 $self->expand_space if !$self->{dbsize};
843 return $self->{dbsize};
853 Returns the size of administrative data in the VOB
857 =for html <blockquote>
865 =for html </blockquote>
869 =for html <blockquote>
873 =item adminstrative size
877 =for html </blockquote>
881 $self->expand_space if !$self->{admsize};
883 return $self->{admsize};
893 Returns the size of the cleartext pool
897 =for html <blockquote>
905 =for html </blockquote>
909 =for html <blockquote>
913 =item cleartext pool size
917 =for html </blockquote>
921 $self->expand_space if !$self->{ctsize};
923 return $self->{ctsize};
933 Returns the size of the derived object pool
937 =for html <blockquote>
945 =for html </blockquote>
949 =for html <blockquote>
953 =item derived object pool size
957 =for html </blockquote>
961 $self->expand_space if !$self->{dosize};
963 return $self->{dosize};
973 Returns the size of the source pool
977 =for html <blockquote>
985 =for html </blockquote>
989 =for html <blockquote>
993 =item source pool size
997 =for html </blockquote>
1001 $self->expand_space if !$self->{srcsize};
1003 return $self->{srcsize};
1013 Returns the size of the VOB
1017 =for html <blockquote>
1025 =for html </blockquote>
1029 =for html <blockquote>
1037 =for html </blockquote>
1041 $self->expand_space if !$self->{size};
1043 return $self->{size};
1053 Mount the current VOB
1057 =for html <blockquote>
1065 =for html </blockquote>
1069 =for html <blockquote>
1075 Status of the mount command
1079 An array of lines output from the cleartool mount command
1083 =for html </blockquote>
1087 return 0 if $self->{active} && $self->{active} eq "YES";
1089 my ($status, @output) = $Clearcase::CC->execute ("mount $self->{tag}");
1091 return ($status, @output);
1101 Unmounts the current VOB
1105 =for html <blockquote>
1113 =for html </blockquote>
1117 =for html <blockquote>
1123 Status from cleartool
1127 Ouput from cleartool
1131 =for html </blockquote>
1135 my ($status, @output) = $Clearcase::CC->execute ("umount $self->{tag}");
1137 return ($status, @output);
1147 Returns true or false if the VOB exists
1151 =for html <blockquote>
1159 =for html </blockquote>
1163 =for html <blockquote>
1171 =for html </blockquote>
1175 my ($status, @output) = $Clearcase::CC->execute ("lsvob $self->{tag}");
1181 my ($self, $host, $vbs, $comment) = @_;
1187 Creates a VOB. First instantiate a VOB object with a tag. Then call create. A
1188 small subset of parameters is supported for create.
1192 =for html <blockquote>
1196 =item $host (optional)
1198 Host to create the vob on. Default is the current host.
1200 =item $vbs (optional)
1202 VOB storage area. This is a global pathname to the VOB storage
1203 area. Default will attempt to use -stgloc -auto.
1205 =item $comment (optional)
1207 Comment for this VOB's creation. Default is -nc
1211 =for html </blockquote>
1215 =for html <blockquote>
1221 Status from cleartool
1225 Ouput from cleartool
1229 =for html </blockquote>
1233 return (0, ()) if $self->exists;
1235 $comment = Clearcase::setComment $comment;
1237 my ($status, @output);
1239 if ($host && $vbs) {
1240 ($status, @output) = $Clearcase::CC->execute (
1241 "mkvob -tag $self->{tag} $comment -host $host -hpath $vbs "
1242 . "-gpath $vbs $vbs");
1244 # Note this requires that -stgloc's work and that using -auto is not a
1246 ($status, @output) =
1247 $Clearcase::CC->execute ("mkvob -tag $self->{tag} $comment "
1251 $self->updateVobInfo;
1253 return ($status, @output);
1267 =for html <blockquote>
1275 =for html </blockquote>
1279 =for html <blockquote>
1285 Status from cleartool
1289 Ouput from cleartool
1293 =for html </blockquote>
1297 return $Clearcase::CC->execute ("rmvob -force $self->{gpath}");
1300 sub updateVobInfo ($$) {
1303 my ($status, @output) = $Clearcase::CC->execute ("lsvob -long $self->{tag}");
1305 # Assuming this vob is an empty shell of an object that the user may possibly
1306 # use the create method on, return our blessings...
1307 return if $status != 0;
1310 if (/Global path: (.*)/) {
1311 $self->{gpath} = $1;
1312 } elsif (/Server host: (.*)/) {
1313 $self->{shost} = $1;
1314 } elsif (/Access: (.*)/) {
1315 $self->{access} = $1;
1316 } elsif (/Mount options: (.*)/) {
1317 $self->{mopts} = $1;
1318 } elsif (/Region: (.*)/) {
1319 $self->{region} = $1;
1320 } elsif (/Active: (.*)/) {
1321 $self->{active} = $1;
1322 } elsif (/Vob tag replica uuid: (.*)/) {
1323 $self->{replica_uuid} = $1;
1324 } elsif (/Vob on host: (.*)/) {
1326 } elsif (/Vob server access path: (.*)/) {
1327 $self->{access_path} = $1;
1328 } elsif (/Vob family uuid: (.*)/) {
1329 $self->{family_uuid} = $1;
1330 } elsif (/Vob registry attributes: (.*)/) {
1331 $self->{vob_registry_attributes} = $1;
1344 =head3 ClearSCM Perl Modules
1346 =for html <p><a href="/php/cvs_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
1348 =for html <p><a href="/php/cvs_man.php?file=lib/OSDep.pm">OSdep</a></p>
1350 =head2 BUGS AND LIMITATIONS
1352 There are no known bugs in this module
1354 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
1356 =head2 LICENSE AND COPYRIGHT
1358 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.