From: František Dvořák Date: Fri, 8 Apr 2011 15:15:41 +0000 (+0000) Subject: Searching for message brokers dynamically in BDII. It is used utility from msg-utils... X-Git-Tag: glite-lbjp-common-db_R_3_0_3_1~3 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=36e6e1ebd88492488cc71be65716412ab12082e9;p=jra1mw.git Searching for message brokers dynamically in BDII. It is used utility from msg-utils modified to search brokers with openwire protocol and filter according to the service status in BDII. --- diff --git a/org.glite.lb.doc/src/LBAG-Installation.tex b/org.glite.lb.doc/src/LBAG-Installation.tex index e6130af..6fd38ec 100644 --- a/org.glite.lb.doc/src/LBAG-Installation.tex +++ b/org.glite.lb.doc/src/LBAG-Installation.tex @@ -166,9 +166,6 @@ Available parameters specific to LB server are: %variable&meaning&default value &further details\\ \begin{itemize} \item \texttt{MYSQL\_PASSWORD} -- root password of MySQL server (mandatory) -\item \texttt{GLITE\_WMS\_LCGMON\_FILE} -- pathname of file where job state -export data are written for use by lgcmon/R-GMA -(default: \texttt{/var/glite/logging/status.log}). \emph{Note: This feature is now obsolete and only available in \LBver{1.x}.} \item \texttt{GLITE\_LB\_EXPORT\_PURGE\_ARGS} -- purge timeouts (default: \texttt{--cleared 2d --aborted 15d --cancelled 15d --other 60d}) According to local retention policy you may want to use different purge timeouts (for example WLCG would need \texttt{--cleared 90d --aborted 90d --cancelled 90d --other 90d}). @@ -179,18 +176,23 @@ According to local retention policy you may want to use different purge timeouts (default: \texttt{heppc24.hep.ph.ic.ac.uk} machine certificate) \item \texttt{GLITE\_LB\_SUPER\_USERS} -- additional super-users (default: empty) \item \texttt{GLITE\_LB\_TYPE} -- type of the \LB service: server, proxy, both (default: autodetect, \LB node only: 'server', WMS node only: proxy, \LB and WMS: 'both') -\item \texttt{GLITE\_LB\_HARVESTER\_ENABLED} -- set to \texttt{true} for sending notifications, used mainly for legacy export to MSG publish system (default: \texttt{false}) -\item \texttt{GLITE\_LB\_HARVESTER\_MSG\_OPTIONS} -- additional options for MSG publish (default: \texttt{--wlcg}) \item \texttt{GLITE\_LB\_INDEX\_OWNER} -- when specified, add (\texttt{true}) or drop (\texttt{false}) 'owner' index (default: 'owner' index not touched) -\item \texttt{GLITE\_LB\_MSG\_BROKER} -- hostname and port of MSG broker, empty for disabling MSG notifications (default: empty) +\item \texttt{GLITE\_LB\_MSG\_BROKER} -- URL of the MSG broker, 'auto' for looking in BDII, 'false' for disabling MSG notifications (default: auto) +\item \texttt{GLITE\_LB\_MSG\_NETWORK} -- required network type when searching in BDII (default: PROD) +\item \texttt{LCG\_GFAL\_INFOSYS} -- BDII servers (default: lcg-bdii.cern.ch:2170) \end{itemize} -Additional helper parameters for \LB: +Additional helper or legacy parameters for \LB: \begin{itemize} \item \texttt{GLITE\_LB\_LOCATION} -- \LB prefix (default: /opt/glite or /usr) \item \texttt{GLITE\_LB\_LOCATION\_ETC} -- system config directory (default: /opt/glite/etc or /etc) \item \texttt{GLITE\_LB\_LOCATION\_VAR} -- gLite local state directory (default: /opt/glite/var or /var/glite) \item \texttt{GLITE\_JP\_LOCATION} -- can be used when JP subsystem location differs from LB (default: empty) +\item \texttt{GLITE\_LB\_HARVESTER\_ENABLED} -- set to \texttt{true} for sending notifications, used mainly for legacy export to MSG publish system (default: \texttt{false}) +\item \texttt{GLITE\_LB\_HARVESTER\_MSG\_OPTIONS} -- additional options for MSG publish (default: \texttt{--wlcg}) +\item \texttt{GLITE\_WMS\_LCGMON\_FILE} -- pathname of file where job state +export data are written for use by lgcmon/R-GMA +(default: \texttt{/var/glite/logging/status.log}). \emph{Note: This feature is now obsolete and only available in \LBver{1.x}.} \end{itemize} In addition to those, YAIM LB module uses following parameters: diff --git a/org.glite.lb.logger-msg/Makefile b/org.glite.lb.logger-msg/Makefile index 3038ff7..8e7cc12 100644 --- a/org.glite.lb.logger-msg/Makefile +++ b/org.glite.lb.logger-msg/Makefile @@ -6,6 +6,7 @@ lbprefix=lb package=glite-lb-logger-msg version=0.0.0 PREFIX=/opt/glite +sysconfdir=/opt/glite/etc nothrflavour=gcc32 thrflavour=gcc32pthr @@ -97,15 +98,16 @@ check: install: -mkdir -p ${DESTDIR}${PREFIX}${prefix}/${libdir}/glite-lb/examples - -mkdir -p ${DESTDIR}${PREFIX}${prefix}/share/man/man8 -mkdir -p ${DESTDIR}${PREFIX}${prefix}/share/doc/${package}-${version} -mkdir -p ${DESTDIR}${PREFIX}${prefix}/etc/glite-lb + -mkdir -p ${DESTDIR}${PREFIX}${prefix}/share/glite-lb + -mkdir -p ${DESTDIR}${PREFIX}${sysconfdir}/glite-lb ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${DESTDIR}${PREFIX}${prefix}/share/doc/${package}-${version} ${INSTALL} -m 755 ${PLUGIN_LIB} ${DESTDIR}${PREFIX}${prefix}/${libdir} ${INSTALL} -m 755 ${EXAMPLES} ${DESTDIR}${PREFIX}${prefix}/${libdir}/glite-lb/examples ( cd ${top_srcdir}/project && ${INSTALL} -m 644 ChangeLog package.description package.summary ${DESTDIR}${PREFIX}${prefix}/share/doc/${package}-${version} ) - ${INSTALL} -m 644 ${top_srcdir}/config/msg.conf.example ${DESTDIR}${PREFIX}${prefix}/etc/glite-lb -# ${INSTALL} -m 644 ${MAN_GZ} ${DESTDIR}${PREFIX}${prefix}/share/man/man8 + ${INSTALL} -m 644 ${top_srcdir}/config/msg.conf.example ${DESTDIR}${PREFIX}${sysconfdir}/glite-lb + ${INSTALL} -m 755 ${top_srcdir}/src/msg-brokers-openwire ${DESTDIR}${PREFIX}${prefix}/share/glite-lb %.lo %.o: %.cpp ${COMPILEXX} -c $< -o $@ diff --git a/org.glite.lb.logger-msg/src/msg-brokers-openwire b/org.glite.lb.logger-msg/src/msg-brokers-openwire new file mode 100755 index 0000000..017a033 --- /dev/null +++ b/org.glite.lb.logger-msg/src/msg-brokers-openwire @@ -0,0 +1,344 @@ +#!/usr/bin/perl +#+############################################################################## +# # +# File: msg-brokers # +# # +# Description: manipulate messaging brokers information # +# # +#-############################################################################## + +# +# modules +# + +use strict; +use warnings; +use Getopt::Long; +use Net::LDAP; +use Pod::Usage; +use Time::HiRes qw(); + +# +# constants +# + +use constant LDAP_TIMEOUT => 10; +use constant STOMP_TIMEOUT => 5; + +# +# global variables +# + +our($Action, %Option); + +# +# report a debugging message +# + +sub debug ($$@) { + my($level, $format, @arguments) = @_; + my($message); + + return unless $Option{debug} >= $level; + $message = sprintf($format, @arguments); + $message =~ s/\s+$//; + print(STDERR "# $message\n"); +} + +# +# report a warning message +# + +sub warning ($@) { + my($format, @arguments) = @_; + my($message); + + return if $Option{quiet}; + $message = sprintf($format, @arguments); + $message =~ s/\s+$//; + print(STDERR "* $message\n"); +} + +# +# report a fatal error +# + +sub fatal ($@) { + my($format, @arguments) = @_; + my($message); + + $message = sprintf($format, @arguments); + $message =~ s/\s+$//; + die("msg-brokers: $message\n"); +} + +# +# initialise everything +# + +sub init () { + # defaults + $Option{bdii} = $ENV{LCG_GFAL_INFOSYS}; + $Option{debug} = 0; + # options parsing + GetOptions( + "bdii=s" => \$Option{bdii}, + "cache=s" => \$Option{cache}, + "debug|d+" => \$Option{debug}, + "help|h|?" => \$Option{help}, + "manual|m" => \$Option{manual}, + "network=s" => \$Option{network}, + "quiet|q" => \$Option{quiet}, + "sort|s" => \$Option{sort}, + ) or pod2usage(2); + pod2usage(1) if $Option{help}; + pod2usage(exitstatus => 0, verbose => 2) if $Option{manual}; + # action parsing + pod2usage(2) unless @ARGV; + if ($ARGV[0] =~ /^(find|list)$/) { + $Action = shift(@ARGV); + pod2usage(2) if @ARGV; + } else { + warn("Unknown action: $ARGV[0]\n"); + pod2usage(2); + } +} + +# +# connect to the BDII and return the corresponding Net::LDAP object +# + +sub connect_bdii () { + my($bdii, @list, $ldap, $mesg); + + $bdii = $Option{bdii}; + fatal("unspecified BDII (use --bdii or set \$LCG_GFAL_INFOSYS)") + unless $bdii; + if ($bdii =~ /[\,\;]/) { + # list of BDIIs + @list = split(/[\,\;]+/, $bdii); + debug(1, "using BDII list %s", "@list"); + } else { + # single BDII + @list = ($bdii); + debug(1, "using single BDII %s", $bdii); + } + foreach $bdii (@list) { + $ldap = Net::LDAP->new($bdii, + port => 2170, + timeout => LDAP_TIMEOUT, + async => 1, + ); + last if $ldap; + if (@list == 1) { + fatal("could not connect to BDII %s: %s", $bdii, $@); + } else { + warning("could not connect to BDII %s: %s", $bdii, $@); + } + } + fatal("could not connect to any BDII") unless $ldap; + debug(1, "connected to BDII %s", $ldap->{net_ldap_uri}); + $mesg = $ldap->bind(anonymous => 1); + fatal("could not bind to BDII %s: %s", $ldap->{net_ldap_uri}, $mesg->error()) + if $mesg->code(); + return($ldap); +} + +# +# search the BDII and return the corresponding results +# + +sub search_bdii ($%) { + my($ldap, %option) = @_; + my($mesg); + + $option{base} = "o=grid"; + $option{timelimit} = LDAP_TIMEOUT; + $mesg = $ldap->search(%option); + fatal("could not search BDII %s: %s", $ldap->{net_ldap_uri}, $mesg->error()) + if $mesg->code(); + return($mesg->entries()); +} + +# +# query the BDII and return the list of matching messaging broker URIs +# + +sub list_brokers ($) { + my($ldap, %search, $endpoint, $match, $network, $value, @uris); + my($check) = @_; + + $ldap = connect_bdii(); + %search = ( + filter => "(&(objectClass=GlueService)(GlueServiceType=msg.broker.openwire)", + attrs => [ qw(GlueServiceEndpoint GlueServiceUniqueID) ], + ); + $search{filter} .= "(GlueServiceStatus=OK)" if ($check); + $search{filter} .= ")"; + foreach $endpoint (search_bdii($ldap, %search)) { + $value = $endpoint->get_value("GlueServiceUniqueID"); + debug(2, " found endpoint %s", $value); + %search = ( + filter => "(&(GlueServiceDataKey=cluster)(GlueChunkKey=GlueServiceUniqueID=$value))", + attrs => [ qw(GlueServiceDataValue) ], + ); + $match = 0; + foreach $network (search_bdii($ldap, %search)) { + $value = $network->get_value("GlueServiceDataValue"); + debug(2, " found network %s", $value); + next if defined($Option{network}) and $Option{network} ne $value; + $match++; + } + $value = $endpoint->get_value("GlueServiceEndpoint"); + if ($match) { + push(@uris, $value); + debug(2, " keep URI %s", $value); + } else { + debug(2, " skip URI %s", $value); + } + } + debug(1, "got %d broker URIs from BDII", scalar(@uris)); + warning("got an empty brokers list from BDII") unless @uris; + return(@uris); +} + +# +# report the final list of messaging broker URIs +# + +sub report_brokers (@) { + my(@list) = @_; + my($uri, $fh); + + unless (defined($Option{cache})) { + # report only to STDOUT + foreach $uri (@list) { + print("$uri\n"); + } + return; + } + unless (@list) { + # no brokers so no cache update + warning("no brokers found so cache file not updated"); + return; + } + # update the cache file + open($fh, ">", $Option{cache}) + or fatal("cannot open %s: %s", $Option{cache}, $!); + foreach $uri (@list) { + print($fh "$uri\n"); + } + close($fh) + or fatal("cannot close %s: %s", $Option{cache}, $!); + debug(1, "cache %s updated with %d brokers", $Option{cache}, scalar(@list)); +} + +# +# main part +# + +sub main () { + my(@list); + + if ($Action eq "list") { + @list = list_brokers(0); + } elsif ($Action eq "find") { + @list = list_brokers(1); + } else { + fatal("unexpected action: %s", $Action); + } + report_brokers(@list); +} + +# +# just do it +# + +init(); +main(); + +__END__ + +=head1 NAME + +msg-brokers - manipulate messaging brokers information + +=head1 SYNOPSIS + +B [I] B|B + +=head1 DESCRIPTION + +B has three different modes of operation. In all cases, +it manipulates information about messaging brokers and reports a +(possibly empty) list of broker URIs, one per line. + +=over + +=item B + +list all the URIs declared in the BDII, optionally filtered by network + +=item B + +the B functionality described above plus filter by GlueServiceStatus + +=back + +A fatal error (e.g. cannot contact the BDII) will halt the program. +A warning (e.g. a given URI cannot be contacted) will be reported +unless B<--quiet> is used. Both will be sent to STDERR. + +The exit status will be 0 on success (with or without warnings) or +different from 0 in case of a fatal error. + +=head1 OPTIONS + +=over + +=item B<--bdii> I + +specify the I or I:I of the BDII to contact; +this can also be a list, separated by commas or semicolons; +if not set, it defaults to $LCG_GFAL_INFOSYS + +=item B<--cache> I + +specify the path of a file to update with the list of URIs; +if this is set, nothing will be printed on STDOUT; +note: if the list is empty, the file will I be updated + +=item B<--debug>, B<-d> + +report debugging information; +can be used multiple times for increased verbosity + +=item B<--help>, B<-h>, B<-?> + +show some help + +=item B<--manual>, B<-m> + +show the complete man page + +=item B<--network> I + +consider only the brokers for this network + +=item B<--quiet>, B<-q> + +supress the printing of warnings + +=item B<--sort>, B<-s> + +sort the brokers per elapsed time to perform the test + +=back + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Lionel Cons L diff --git a/org.glite.lb.yaim/config/defaults/glite-lb.pre b/org.glite.lb.yaim/config/defaults/glite-lb.pre index 0141a88..6af4bf9 100644 --- a/org.glite.lb.yaim/config/defaults/glite-lb.pre +++ b/org.glite.lb.yaim/config/defaults/glite-lb.pre @@ -41,7 +41,9 @@ GLITE_LB_RTM_ENABLED='false' # Real Time Monitoring identities (separated by comma) GLITE_LB_RTM_DN='/C=UK/O=eScience/OU=Imperial/L=Physics/CN=heppc24.hep.ph.ic.ac.uk/Email=janusz.martyniak@imperial.ac.uk' # MSG publish -GLITE_LB_MSG_BROKER='tcp://egi-1.msg.cern.ch:6166' +GLITE_LB_MSG_BROKER='true' +GLITE_LB_MSG_NETWORK='PROD' +LCG_GFAL_INFOSYS='lcg-bdii.cern.ch:2170' # # additional options diff --git a/org.glite.lb.yaim/config/functions/config_glite_lb.in b/org.glite.lb.yaim/config/functions/config_glite_lb.in index 7fd8472..8c8afbe 100644 --- a/org.glite.lb.yaim/config/functions/config_glite_lb.in +++ b/org.glite.lb.yaim/config/functions/config_glite_lb.in @@ -368,7 +368,11 @@ EOF if [ "$GLITE_LB_MSG_BROKER" = 'false' ]; then rm -f "$GLITE_LB_LOCATION_ETC/glite-lb/msg.conf" else - cat > "$GLITE_LB_LOCATION_ETC/glite-lb/msg.conf" < "$GLITE_LB_LOCATION_ETC/glite-lb/msg.conf" < { 'lb.client-java' => [ qw/ant:B jdk:B axis:B trustmanager utiljava libtool:B/ ], 'lb.glite-LB' => [ qw/fetchcrl:R gpt:R gip_release:R gip_service:R bdii:R glite_version:R glite_info_templates:R glue_schema:R/ ], - 'lb.yaim' => [ qw/yaim_core:R/ ], + 'lb.yaim' => [ qw/yaim_core:R perl-LDAP:R/ ], 'px.glite-PX' => [qw/myproxy-server:R myproxy-admin:R fetchcrl:R gip_service:R bdii:R glite_version:R gpt:R glue_schema:R/], 'px.myproxy-yaim' => [ qw/yaim_core:R/ ], }, @@ -842,7 +842,7 @@ for my $ext (keys %deps_aux) { need_externs_aux => { 'lb.client-java' => [ qw/ant:B jdk:B axis:B trustmanager trustmanager_axis libtool:B/ ], 'lb.glite-LB' => [ qw/fetchcrl:R gip_release:R gip_service:R bdii:R glite_version:R glue_schema:R/ ], - 'lb.yaim' => [ qw/yaim_core:R yaim_bdii:R/ ], + 'lb.yaim' => [ qw/yaim_core:R yaim_bdii:R perl-LDAP:R/ ], 'px.glite-PX' => [qw/myproxy-server:R myproxy-admin:R fetchcrl:R gip_service:R bdii:R glite_version:R glue_schema:R/], 'px.myproxy-yaim' => [ qw/yaim_core:R yaim_bdii:R/ ], },