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};
278 Returns the type of VOB access
282 =for html <blockquote>
290 =for html </blockquote>
294 =for html <blockquote>
300 Returns either public for public VOBs or private for private VOBs
304 =for html </blockquote>
308 return $self->{access};
318 Returns the mount options
322 =for html <blockquote>
330 =for html </blockquote>
334 =for html <blockquote>
338 =item VOB's mount options
342 =for html </blockquote>
346 return $self->{mopts};
356 Returns the region for this VOB tag
360 =for html <blockquote>
368 =for html </blockquote>
372 =for html <blockquote>
380 =for html </blockquote>
384 return $self->{region};
394 Returns that active status (whether or not the vob is currently mounted) of the
399 =for html <blockquote>
407 =for html </blockquote>
411 =for html <blockquote>
415 =item Returns YES for an active VOB or NO for an inactive one
419 =for html </blockquote>
423 return $self->{active};
426 sub replica_uuid () {
433 Returns the VOBS replica_uuid
437 =for html <blockquote>
445 =for html </blockquote>
449 =for html <blockquote>
453 =item VOB replica_uuid
457 =for html </blockquote>
461 return $self->{replica_uuid};
471 Returns the VOB's host
475 =for html <blockquote>
483 =for html </blockquote>
487 =for html <blockquote>
495 =for html </blockquote>
499 return $self->{host};
509 Returns the VOB's access path
513 =for html <blockquote>
521 =for html </blockquote>
525 =for html <blockquote>
529 =item VOB access path
531 This is the path relative to the VOB's host
535 =for html </blockquote>
539 return $self->{access_path};
549 Returns the VOB family UUID
553 =for html <blockquote>
561 =for html </blockquote>
565 =for html <blockquote>
569 =item VOB family UUID
573 =for html </blockquote>
577 return $self->{family_uuid};
580 sub vob_registry_attributes () {
585 =head2 vob_registry_attributes
587 Returns the VOB Registry Attributes
591 =for html <blockquote>
599 =for html </blockquote>
603 =for html <blockquote>
607 =item VOB Registry Attributes
611 =for html </blockquote>
615 return $self->{vob_registry_attributes};
616 } # vob_registry_attributes
618 sub expand_space () {
621 my ($status, @output) = $Clearcase::CC->execute ("space -vob $self->{tag}");
623 # Initialize fields in case of command failure
625 $self->{admsize} = 0;
628 $self->{srcsize} = 0;
632 if (/(\d*\.\d).*VOB database(.*)/) {
633 $self->{dbsize} = $1;
634 } elsif (/(\d*\.\d).*administration data(.*)/) {
635 $self->{admsize} = $1;
636 } elsif (/(\d*\.\d).*cleartext pool(.*)/) {
637 $self->{ctsize} = $1;
638 } elsif (/(\d*\.\d).*derived object pool(.*)/) {
639 $self->{dosize} = $1;
640 } elsif (/(\d*\.\d).*source pool(.*)/) {
641 $self->{srcsize} = $1;
642 } elsif (/(\d*\.\d).*Subtotal(.*)/) {
653 # Set values to zero in case we cannot get the right values from countdb
654 $self->{elements} = 0;
655 $self->{branches} = 0;
656 $self->{versions} = 0;
658 # Countdb needs to be done in the vob's db directory
662 chdir "$self->{gpath}/db";
664 my $cmd = "$Clearcase::COUNTDB vob_db 2>&1";
676 if (/^ELEMENT\s*:\s*(\d*)/) {
677 $self->{elements} = $1;
678 } elsif (/^BRANCH\s*:\s*(\d*)/) {
679 $self->{branches} = $1;
680 } elsif (/^VERSION\s*:\s*(\d*)/) {
681 $self->{versions} = $1;
697 Returns the number of elements in the VOB (obtained via countdb)
701 =for html <blockquote>
709 =for html </blockquote>
713 =for html <blockquote>
717 =item number of elements
721 =for html </blockquote>
725 $self->countdb if !$self->{elements};
727 return $self->{elements};
737 Returns the number of branch types in the vob
741 =for html <blockquote>
749 =for html </blockquote>
753 =for html <blockquote>
757 =item number of branch types
761 =for html </blockquote>
765 $self->countdb if !$self->{branches};
767 return $self->{branches};
777 Returns the number of element versions in the VOB
781 =for html <blockquote>
789 =for html </blockquote>
793 =for html <blockquote>
797 =item number of element versions
801 =for html </blockquote>
805 $self->countdb if !$self->{versions};
807 return $self->{versions};
817 Returns the size of the VOB's database
821 =for html <blockquote>
829 =for html </blockquote>
833 =for html <blockquote>
841 =for html </blockquote>
845 $self->expand_space if !$self->{dbsize};
847 return $self->{dbsize};
857 Returns the size of administrative data in the VOB
861 =for html <blockquote>
869 =for html </blockquote>
873 =for html <blockquote>
877 =item adminstrative size
881 =for html </blockquote>
885 $self->expand_space if !$self->{admsize};
887 return $self->{admsize};
897 Returns the size of the cleartext pool
901 =for html <blockquote>
909 =for html </blockquote>
913 =for html <blockquote>
917 =item cleartext pool size
921 =for html </blockquote>
925 $self->expand_space if !$self->{ctsize};
927 return $self->{ctsize};
937 Returns the size of the derived object pool
941 =for html <blockquote>
949 =for html </blockquote>
953 =for html <blockquote>
957 =item derived object pool size
961 =for html </blockquote>
965 $self->expand_space if !$self->{dosize};
967 return $self->{dosize};
977 Returns the size of the source pool
981 =for html <blockquote>
989 =for html </blockquote>
993 =for html <blockquote>
997 =item source pool size
1001 =for html </blockquote>
1005 $self->expand_space if !$self->{srcsize};
1007 return $self->{srcsize};
1017 Returns the size of the VOB
1021 =for html <blockquote>
1029 =for html </blockquote>
1033 =for html <blockquote>
1041 =for html </blockquote>
1045 $self->expand_space if !$self->{size};
1047 return $self->{size};
1057 Mount the current VOB
1061 =for html <blockquote>
1069 =for html </blockquote>
1073 =for html <blockquote>
1079 Status of the mount command
1083 An array of lines output from the cleartool mount command
1087 =for html </blockquote>
1091 return 0 if $self->{active} && $self->{active} eq "YES";
1093 my ($status, @output) = $Clearcase::CC->execute ("mount $self->{tag}");
1095 return ($status, @output);
1105 Unmounts the current VOB
1109 =for html <blockquote>
1117 =for html </blockquote>
1121 =for html <blockquote>
1127 Status from cleartool
1131 Ouput from cleartool
1135 =for html </blockquote>
1139 my ($status, @output) = $Clearcase::CC->execute ("umount $self->{tag}");
1141 return ($status, @output);
1151 Returns true or false if the VOB exists
1155 =for html <blockquote>
1163 =for html </blockquote>
1167 =for html <blockquote>
1175 =for html </blockquote>
1179 my ($status, @output) = $Clearcase::CC->execute ("lsvob $self->{tag}");
1184 sub create (;$$$%) {
1185 my ($self, $host, $vbs, $comment, %opts) = @_;
1191 Creates a VOB. First instantiate a VOB object with a tag. Then call create. A
1192 small subset of parameters is supported for create.
1196 =for html <blockquote>
1200 =item $host (optional)
1202 Host to create the vob on. Default is the current host.
1204 =item $vbs (optional)
1206 VOB storage area. This is a global pathname to the VOB storage
1207 area. Default will attempt to use -stgloc -auto.
1209 =item $comment (optional)
1211 Comment for this VOB's creation. Default is -nc
1215 =for html </blockquote>
1219 =for html <blockquote>
1225 Status from cleartool
1229 Ouput from cleartool
1233 =for html </blockquote>
1237 return (0, ()) if $self->exists;
1239 $comment = Clearcase::_setComment $comment;
1241 my ($status, @output);
1243 my $additionalOpts = '';
1246 $additionalOpts .= "-$_ ";
1247 $additionalOpts .= "$opts{$_} " if $opts{$_};
1250 if ($host && $vbs) {
1251 $additionalOpts .= '-ucmproject' if $self->{ucmproject};
1253 ($status, @output) = $Clearcase::CC->execute (
1254 "mkvob -tag $self->{tag} $comment $additionalOpts -host $host -hpath $vbs "
1255 . "-gpath $vbs $vbs");
1257 # Note this requires that -stgloc's work and that using -auto is not a
1259 ($status, @output) =
1260 $Clearcase::CC->execute ("mkvob -tag $self->{tag} $comment $additionalOpts -stgloc -auto");
1263 $self->updateVobInfo;
1265 return ($status, @output);
1279 =for html <blockquote>
1287 =for html </blockquote>
1291 =for html <blockquote>
1297 Status from cleartool
1301 Ouput from cleartool
1305 =for html </blockquote>
1309 return $Clearcase::CC->execute ("rmvob -force $self->{gpath}");
1312 sub updateVobInfo ($$) {
1315 my ($status, @output) = $Clearcase::CC->execute ("lsvob -long $self->{tag}");
1317 # Assuming this vob is an empty shell of an object that the user may possibly
1318 # use the create method on, return our blessings...
1319 return if $status != 0;
1322 if (/Global path: (.*)/) {
1323 $self->{gpath} = $1;
1324 } elsif (/Server host: (.*)/) {
1325 $self->{shost} = $1;
1326 } elsif (/Access: (.*)/) {
1327 $self->{access} = $1;
1328 } elsif (/Mount options: (.*)/) {
1329 $self->{mopts} = $1;
1330 } elsif (/Region: (.*)/) {
1331 $self->{region} = $1;
1332 } elsif (/Active: (.*)/) {
1333 $self->{active} = $1;
1334 } elsif (/Vob tag replica uuid: (.*)/) {
1335 $self->{replica_uuid} = $1;
1336 } elsif (/Vob on host: (.*)/) {
1338 } elsif (/Vob server access path: (.*)/) {
1339 $self->{access_path} = $1;
1340 } elsif (/Vob family uuid: (.*)/) {
1341 $self->{family_uuid} = $1;
1342 } elsif (/Vob registry attributes: (.*)/) {
1343 $self->{vob_registry_attributes} = $1;
1356 =head3 ClearSCM Perl Modules
1358 =for html <p><a href="/php/scm_man.php?file=lib/Clearcase.pm">Clearcase</a></p>
1360 =for html <p><a href="/php/scm_man.php?file=lib/OSDep.pm">OSdep</a></p>
1362 =head2 BUGS AND LIMITATIONS
1364 There are no known bugs in this module
1366 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
1368 =head2 LICENSE AND COPYRIGHT
1370 Copyright (c) 2007, ClearSCM, Inc. All rights reserved.