1 use strict; use warnings;
2 package OpenSRF::Utils::SettingsClient;
3 use OpenSRF::Utils::SettingsParser;
5 use OpenSRF::AppSession;
6 use OpenSRF::Utils::Config;
7 use OpenSRF::EX qw(:try);
9 use vars qw/$host_config/;
12 sub new {return bless({},shift());}
16 # ------------------------------------
17 # utility method for grabbing config info
22 my $bsconfig = OpenSRF::Utils::Config->current;
23 my $host = $bsconfig->env->hostname;
24 if(!$host_config) { grab_host_config($host); }
26 throw OpenSRF::EX::Config ("Unable to retrieve host config for $host" );
29 my $hash = $host_config;
31 # XXX TO DO, check local config 'version',
32 # call out to settings server when necessary....
35 $hash = $hash->{$key};
40 throw OpenSRF::EX::Config ("No Config information for @keys : $e : $@");
48 # XXX make smarter and more robust...
49 sub grab_host_config {
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;
61 if( ! ($session->connect()) ) {die "Settings Connect timed out\n";}
62 my $req = $session->request( "opensrf.settings.host_config.get", $host );
63 $resp = $req->recv( timeout => 10 );
65 } catch OpenSRF::EX with {
68 warn "Connection to Settings Failed $e : $@ ***\n";
73 warn "No Response from settings server...going to sleep\n";
77 if( $resp && UNIVERSAL::isa( $resp, "OpenSRF::EX" ) ) {
81 $host_config = $resp->content();