]> git.evergreen-ils.org Git - working/Evergreen.git/blob - OpenSRF/src/perlmods/OpenSRF/Utils/SettingsClient.pm
fixed up the magic auto-introspection and made sure we were
[working/Evergreen.git] / OpenSRF / src / perlmods / OpenSRF / Utils / SettingsClient.pm
1 use strict; use warnings;
2 package OpenSRF::Utils::SettingsClient;
3 use OpenSRF::Utils::SettingsParser;
4 use OpenSRF::System;
5 use OpenSRF::AppSession;
6 use OpenSRF::Utils::Config;
7 use OpenSRF::EX qw(:try);
8
9 use vars qw/$host_config/;
10
11
12 sub new {return bless({},shift());}
13 my $session;
14 $host_config = undef;
15
16 # ------------------------------------
17 # utility method for grabbing config info
18 sub config_value {
19         my($self,@keys) = @_;
20
21
22         my $bsconfig = OpenSRF::Utils::Config->current;
23         my $host = $bsconfig->env->hostname;
24         if(!$host_config) { grab_host_config($host); }
25         if(!$host_config) {
26                 throw OpenSRF::EX::Config ("Unable to retrieve host config for $host" );
27         }
28
29         my $hash = $host_config;
30
31         # XXX TO DO, check local config 'version', 
32         # call out to settings server when necessary....
33         try {
34                 for my $key (@keys) {
35                         $hash = $hash->{$key};
36                 }
37
38         } catch Error with {
39                 my $e = shift;
40                 throw OpenSRF::EX::Config ("No Config information for @keys : $e : $@");
41         };
42
43         return $hash;
44
45 }
46
47
48 # XXX make smarter and more robust...
49 sub grab_host_config {
50
51         my $host = shift;
52
53         warn "Grabbing Host config for $host\n";
54         OpenSRF::System::bootstrap_client("system_client");
55         $session = OpenSRF::AppSession->create( "settings" ) unless $session;
56         my $bsconfig = OpenSRF::Utils::Config->current;
57
58         my $resp;
59         my $req;
60         try {
61
62                 if( ! ($session->connect()) ) {die "Settings Connect timed out\n";}
63                 $req = $session->request( "opensrf.settings.host_config.get", $host );
64                 $resp = $req->recv( timeout => 10 );
65
66         } catch OpenSRF::EX with {
67
68                 my $e = shift;
69                 warn "Connection to Settings Failed  $e : $@ ***\n";
70                 die $e;
71         };
72
73         if(!$resp) {
74                 warn "No Response from settings server...going to sleep\n";
75                 sleep;
76         }
77
78         if( $resp && UNIVERSAL::isa( $resp, "OpenSRF::EX" ) ) {
79                 throw $resp;
80         }
81
82         $host_config = $resp->content();
83         $req->finish();
84         $session->finish;
85         $session->disconnect();
86 }
87
88
89
90 1;