File Coverage

blib/lib/Citrix/Farm.pm
Criterion Covered Total %
statement 0 40 0.0
branch 0 6 0.0
condition n/a
subroutine 0 8 0.0
pod 7 7 100.0
total 7 61 11.4


line stmt bran cond sub pod time code
1             package Citrix::Farm;
2             # DONE: Change to use new keys, Change POD as well
3             our $VERSION = '0.25';
4              
5             =head1 NAME
6              
7             Citrix::Farm - Citrix Farm Context Configuration.
8              
9             =head1 DESCRIPTION
10              
11             Farm Context (used all over the Citrix::* modules) is a configuration (hash) for single
12             Citrix Farm with following members:
13              
14             =over 4
15              
16             =item farmid - Short ID (typically 2-8 chars) for Farm (to appear as farm ID in an App).
17              
18             =item name - Descriptive / displayable Name for the farm
19              
20             =item masterhost - Master host of the farm, queries will be directed onto this host
21              
22             =item domainsuffix - DNS Domain suffix to add to hostname to make a fully qualified host name
23              
24             =item apps - List of applications available on the farm (a ref to an array with app name strings)
25              
26             =item hosts - List of hosts (Including master host) available on farm
27              
28             =back
29              
30              
31              
32             Citrix Farm Information is expected to be stored and maintained in static configuration
33             file so that there is no need to alter the config at runtime (This may change later).
34             For now the accessor methods or class work only as getters.
35              
36             =head1 METHODS
37              
38             The simple Farm model class contains mostly simple getter methods.
39              
40             =over 4
41              
42             =item $fc->farmid() - Farm ID
43              
44             =item $fc->name() - Farm Name
45              
46             =item $fc->masterhost() - Hostname of masterhost on the farm
47              
48             =item $fc->domainsuffix() - DNS Domain suffix (part after hostname) for farm
49              
50             =item $fc->apps() - Names (IDs) of apps available on Citrix Farm
51              
52             =item $fc->hosts() - Hosts for the farm (serving apps listed above)
53              
54             =back
55              
56             Note once more that these accessor methods only work as getters (see above).
57              
58             =head2 $farminfo = $fc->getfarminfo();
59              
60             Retrieve Farm info about Farm apps/hosts (by Farm Context).
61             This query is possibly slow and unreliable (if some hosts
62             are down on the farm). Return Farm Info as array(ref).
63              
64             =cut
65              
66             #OLD:=item s - Optional Sequence number (to explicitly order farms within farm collection)
67              
68              
69              
70             # Read-only accessors. Config is assumed to be maintained externally and loaded asis
71             # with no need to "tinker".
72 0     0 1   sub farmid {$_[0]->{'farmid'};}
73 0     0 1   sub name {$_[0]->{'name'};}
74 0     0 1   sub masterhost {$_[0]->{'masterhost'};}
75 0     0 1   sub domainsuffix {$_[0]->{'domainsuffix'};}
76 0     0 1   sub apps {$_[0]->{'apps'};}
77 0     0 1   sub hosts {$_[0]->{'hosts'};}
78              
79             # Method Aliases
80             *Citrix::Farm::mh = \&Citrix::Farm::masterhost;
81              
82             sub getfarminfo {
83 0     0 1   my ($fc) = @_;
84             # TODO: Change heuristics
85 0           my $usehost = $fc->masterhost(); # OLD: {'mh'}
86 0           my $cmd = "rsh $usehost $Citrix::binpath/ctxqserver -app";
87             #DEBUG:print("
$cmd:\n",`$cmd`,"
");
88             #my $t = alarm(0);
89 0     0     local $SIG{'ALRM'} = sub {die("RSH Timeout\n");}; # (at $t)
  0            
90 0           alarm(8);
91 0           my $fh;
92 0           eval {
93 0           my $ok = open($fh, "$cmd |");
94 0 0         if (!$ok) {
95 0           $fc->{'msg'} = "$!/$?";print("Failed to open the pipe");
  0            
96             #return(undef);
97 0           die("$!/$?");
98             }
99             };
100 0           alarm(0);
101 0 0         if ($@) {
102 0           $fc->{'msg'} = $@;
103 0           close($fh);
104 0           return(undef);
105             }
106 0           my $arr = [];
107 0           my $atts = ['APPID', 'PROTO', 'SERVER', 'LOAD',];
108            
109 0           my $err = parse($fh, $arr, $atts, 3);
110 0 0         if ($err) {print("Failed ....");return(undef);}
  0            
  0            
111            
112             # Join to context ?
113 0           $fc->{'apphost'} = $arr;
114 0           my %apphost;
115 0           my %hosts = map({
116             #my $s = $_->{'SERVER'};
117 0           $_->{'SERVER'} =~ tr/A-Z/a-z/;
118 0           $apphost{$_->{'APPID'}}->{$_->{'SERVER'}} = 1;
119 0           ($_->{'SERVER'}, 1);
120             } @$arr);
121 0           $fc->{'hosts'} = [sort(keys(%hosts))];
122 0           $fc->{'apps'} = [sort(keys(%apphost))];
123            
124 0           $fc->{'apphost'} = \%apphost; # Index ?!
125 0           return($arr);
126             }
127             __END__