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