'merge_branch_20_21_src'.
Sprout from branch_2_0 2010-06-15 14:32:26 UTC František Dvořák <valtri@civ.zcu.cz> 'Finalize autotool stuff.'
Delete:
org.glite.lb.client-java/Makefile
org.glite.lb.client-java/README
org.glite.lb.client-java/build.xml
org.glite.lb.client-java/compile.sh
org.glite.lb.client-java/configure
org.glite.lb.client-java/nbproject/build-impl.xml
org.glite.lb.client-java/nbproject/genfiles.properties
org.glite.lb.client-java/nbproject/private/config.properties
org.glite.lb.client-java/nbproject/private/private.properties
org.glite.lb.client-java/nbproject/project.properties
org.glite.lb.client-java/nbproject/project.xml
org.glite.lb.client-java/project/ChangeLog
org.glite.lb.client-java/project/genEventTypes.pl
org.glite.lb.client-java/project/version.properties
org.glite.lb.client-java/src/org/glite/lb/Context.java
org.glite.lb.client-java/src/org/glite/lb/ContextIL.java
org.glite.lb.client-java/src/org/glite/lb/ContextLL.java
org.glite.lb.client-java/src/org/glite/lb/Event.java
org.glite.lb.client-java/src/org/glite/lb/ILFileWriter.java
org.glite.lb.client-java/src/org/glite/lb/ProducerTestIL.java
org.glite.lb.client-java/src/org/glite/lb/ProducerTestLL.java
org.glite.lb.client-java/src/org/glite/lb/SSL.java
org.glite.lb.client-java/src/org/glite/lb/SSLSend.java
org.glite.lb.client-java/src/org/glite/lb/SeqCode.java
org.glite.lb.client-java/src/org/glite/lb/Sources.java
org.glite.lb.client-java/src_c/Makefile
org.glite.lb.client-java/src_c/send_via_proxy.c
org.glite.lb.client-java/src_c/send_via_socket.c
org.glite.lb.harvester/Makefile
org.glite.lb.harvester/configure
org.glite.lb.harvester/doc/INSTALL
org.glite.lb.harvester/doc/README
org.glite.lb.harvester/examples/test.sh
org.glite.lb.harvester/examples/test.sql
org.glite.lb.harvester/project/ChangeLog
org.glite.lb.harvester/project/package.description
org.glite.lb.harvester/project/package.summary
org.glite.lb.harvester/project/version.properties
org.glite.lb.harvester/src/harvester.c
+++ /dev/null
--include Makefile.inc
-
-EXAMPLES := SimpleLLTest.class SSLClient.class SSLServer.class
-# broken: ProducerTestIL.class ProducerTestLL.class
-
-VPATH := examples
-
-certmanagement_jar := $(shell ls ${jglobus_prefix}/lib/cog-certmanagement-*.jar | sort | tail -1)
-jglobus_jar := $(shell ls ${jglobus_prefix}/lib/cog-jglobus-*.jar | sort | tail -1)
-
-all compile:
- JAVA_HOME=${jdk_prefix} \
- ${ant_prefix}/bin/ant -Dno.deps=yes -DstageDir=${stagedir} \
- -Dreference.jobid-api-java.jar=${stagedir}/share/java/jobid-api-java.jar \
- -Dfile.reference.cog-certmanagement.jar=${certmanagement_jar} \
- -Dfile.reference.cog-jglobus.jar=${jglobus_jar}
- cd src_c && make PREFIX=${PREFIX}
-
-examples: ${EXAMPLES}
-
-
-${EXAMPLES}: %.class: %.java
- javac -cp build/classes/:${stagedir}/share/java/jobid-api-java.jar $<
-
-
-check:
- @echo "No check"
-
-install:
- mkdir -p ${PREFIX}/share/java
- cp dist/lb-client-java.jar ${PREFIX}/share/java
- cd src_c && make install PREFIX=${PREFIX}
-
-clean:
- echo TODO
-
-
+++ /dev/null
-How to compile the source code.
-
-Run the script "compile.sh" with arguments:
-All options are required except PATH_TO_JAVA, PREFIX and install or remove.
-
--Dbuild.classes.dir="path to directory where .class files will be saved" \
--Ddist.dir="path to directory where .jar file will be saved" \
--Ddist.javadoc.dir="path to directory where documentation will be saved" \
--Dproject.jobid-api-java="path to directory jobid-api-java" \
--Dreference.jobid-api-java.jar="path to directory where jobid-api-java.jar is" \
-choose one of these: install or compile \
-PREFIX="path to directory where .so file will be saved" \
-PATH_TO_JAVA="path to directory where java is installed" \
-
-How to run locallogger:
-java -Djava.library.path=/path/to/shared/library -cp "/path/to/jobid-api-java.jar:/path/to/lb-client-java.jar" org.glite.test.Test
-
-If you don't set -Djava.library.path messages will not be send via unix socket but only written to specified file.
-
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- You may freely edit this file. See commented blocks below for -->
-<!-- some examples of how to customize the build. -->
-<!-- (If you delete it and reopen the project it will be recreated.) -->
-<project name="lb-client-java" default="default" basedir=".">
- <description>Builds, tests, and runs the project lb-client-java.</description>
- <import file="nbproject/build-impl.xml"/>
-
- <target name="-pre-compile">
- <exec executable="${stageDir}/sbin/glite-lb-at3">
- <arg line="project/genEventTypes.pl src/org/glite/lb"/>
- </exec>
- </target>
- <!--
-
- There exist several targets which are by default empty and which can be
- used for execution of your tasks. These targets are usually executed
- before and after some main targets. They are:
-
- -pre-init: called before initialization of project properties
- -post-init: called after initialization of project properties
- -pre-compile: called before javac compilation
- -post-compile: called after javac compilation
- -pre-compile-single: called before javac compilation of single file
- -post-compile-single: called after javac compilation of single file
- -pre-compile-test: called before javac compilation of JUnit tests
- -post-compile-test: called after javac compilation of JUnit tests
- -pre-compile-test-single: called before javac compilation of single JUnit test
- -post-compile-test-single: called after javac compilation of single JUunit test
- -pre-jar: called before JAR building
- -post-jar: called after JAR building
- -post-clean: called after cleaning build products
-
- (Targets beginning with '-' are not intended to be called on their own.)
-
- Example of inserting an obfuscator after compilation could look like this:
-
- <target name="-post-compile">
- <obfuscate>
- <fileset dir="${build.classes.dir}"/>
- </obfuscate>
- </target>
-
- For list of available properties check the imported
- nbproject/build-impl.xml file.
-
-
- Another way to customize the build is by overriding existing main targets.
- The targets of interest are:
-
- -init-macrodef-javac: defines macro for javac compilation
- -init-macrodef-junit: defines macro for junit execution
- -init-macrodef-debug: defines macro for class debugging
- -init-macrodef-java: defines macro for class execution
- -do-jar-with-manifest: JAR building (if you are using a manifest)
- -do-jar-without-manifest: JAR building (if you are not using a manifest)
- run: execution of project
- -javadoc-build: Javadoc generation
- test-report: JUnit report generation
-
- An example of overriding the target for project execution could look like this:
-
- <target name="run" depends="lb-client-java-impl.jar">
- <exec dir="bin" executable="launcher.exe">
- <arg file="${dist.jar}"/>
- </exec>
- </target>
-
- Notice that the overridden target depends on the jar target and not only on
- the compile target as the regular run target does. Again, for a list of available
- properties which you can use, check the target you are overriding in the
- nbproject/build-impl.xml file.
-
- -->
-</project>
+++ /dev/null
-#!/bin/bash
-cmd1="$1";
-cmd2="$2";
-cmd3="$3";
-cmd4="$4";
-cmd5="$5";
-cmd6="$6";
-cmd7="$7";
-cmd7="$8";
-
-ant $cmd1 $cmd2 $cmd3 $cmd4 $cmd5;
-cd ./src_c
-make $cmd6 $cmd7 $cmd8;
+++ /dev/null
-#!/usr/bin/perl
-
-# WARNING: Don't edit this file unless it is the master copy in org.glite.lb
-#
-# For the purpose of standalone builds of lb/jobid/lbjp-common components
-# it is copied on tagging
-
-# $Header$
-
-use Getopt::Long;
-
-my $pwd = `pwd`; chomp $pwd;
-my $prefix = $pwd.'/stage';
-my $stagedir;
-my $staged;
-my $module;
-my $thrflavour = 'gcc64dbgpthr';
-my $nothrflavour = 'gcc64dbg';
-my $mode = 'build';
-my $help = 0;
-my $listmodules;
-my $version;
-my $output;
-my $lb_tag = '';
-my $lbjp_tag = '';
-my $jp_tag = '';
-my $sec_tag = '';
-my $jobid_tag = '';
-
-my @nodes = qw/client server logger utils client-java doc ws-test db jpprimary jpindex jpclient/;
-my %enable_nodes;
-my %disable_nodes;
-
-my %extern_prefix = (
- cares => '/opt/c-ares',
- classads => '/opt/classads',
- cppunit => '/usr',
- expat => '/usr',
- globus => '/opt/globus',
- gsoap => '/usr',
- mysql => '/usr',
- voms => '/opt/glite',
- gridsite => '/opt/glite',
- lcas => '/opt/glite',
- ant => '/usr',
- jdk => '/usr',
- libtar => '/usr',
-);
-
-my %jar = (
- 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar',
-);
-
-
-my %glite_prefix;
-my %need_externs;
-my %need_externs_type;
-my %need_jars;
-my %extrafull;
-my %extranodmod;
-my %deps;
-my %deps_type;
-my %topbuild;
-
-my %lbmodules = (
- 'lb' => [ qw/client client-java common doc logger server state-machine types utils ws-interface ws-test/],
- 'security' => [qw/gss gsoap-plugin/],
- 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/],
- 'jobid' => [qw/api-c api-cpp api-java/],
- 'jp' => [ qw/client doc index primary server-common ws-interface/ ],
- );
-
-
-my @opts = (
- 'prefix=s' => \$prefix,
- 'staged=s' => \$staged,
- 'module=s' => \$module,
- 'thrflavour=s' => \$thrflavour,
- 'nothrflavour=s' => \$nothrflavour,
- 'mode=s' => \$mode,
- 'listmodules=s' => \$listmodules,
- 'version=s' => \$version,
- 'output=s' => \$output,
- 'stage=s' => \$stagedir,
- 'lb-tag=s' => \$lb_tag,
- 'lbjp-common-tag=s' => \$lbjp_tag,
- 'jp-tag=s' => \$jp_tag,
- 'security-tag=s' => \$sec_tag,
- 'jobid-tag=s' => \$jobid_tag,
- 'help' => \$help,
-);
-
-for (@nodes) {
- $enable_nodes{$_} = 0;
- $disable_nodes{$_} = 0;
-
- push @opts,"disable-$_",\$disable_nodes{$_};
- push @opts,"enable-$_",\$enable_nodes{$_};
-}
-
-push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix;
-push @opts,"with-$_=s",\$jar{$_} for keys %jar;
-
-my @keeparg = @ARGV;
-
-GetOptions @opts or die "Errors parsing command line\n";
-
-if ($help) { usage(); exit 0; }
-
-if ($listmodules) {
- my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}};
- print "@m\n";
- exit 0;
-}
-
-warn "$0: --version and --output make sense only in --mode=etics\n"
- if ($version || $output) && $mode ne 'etics';
-
-my $en;
-for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; }
-
-my $dis;
-for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; }
-
-die "--enable-* and --disable-* are mutually exclusive\n"
- if $en && $dis;
-
-die "--module cannot be used with --enable-* or --disable-*\n"
- if $module && ($en || $dis);
-
-die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}};
-
-if ($dis) {
- for (@nodes) {
- $enable_nodes{$_} = 1 unless $disable_nodes{$_};
- }
-}
-
-if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ;
-
-for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; }
-
-$stagedir = $prefix unless $stagedir;
-
-if ($mode eq 'build') {
- print "Writing config.status\n";
- open CONF,">config.status" or die "config.status: $!\n";
- print CONF "$0 @keeparg\n";
- close CONF;
-}
-
-
-my @modules;
-my %aux;
-
-if ($module) {
-# push @modules,split(/[,.]+/,$module);
- push @modules,$module;
-}
-else {
- @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes));
-
- my $n;
-
- do {
- local $"="\n";
- $n = $#modules;
- push @modules,(map @{$deps{$_}},@modules);
-
- undef %aux; @aux{@modules} = (1) x ($#modules+1);
- @modules = keys %aux;
- } while ($#modules > $n);
-}
-
-@aux{@modules} = (1) x ($#modules+1);
-delete $aux{$_} for (split /,/,$staged);
-@modules = keys %aux;
-
-mode_build() if $mode eq 'build';
-mode_checkout() if $mode eq 'checkout';
-mode_etics($module) if $mode eq 'etics';
-
-sub mode_build {
- print "\nBuilding modules: @modules\n";
-
- my @ext = map @{$need_externs{$_}},@modules;
- my @myjars = map @{$need_jars{$_}},@modules;
- undef %aux; @aux{@ext} = 1;
- @ext = keys %aux;
- undef %aux; @aux{@myjars} = (1) x ($#myjars+1);
- @myjars = keys %aux;
-
- print "\nRequired externals:\n";
- print "\t$_: $extern_prefix{$_}\n" for @ext;
- print "\t$_: $jar{$_}\n" for @myjars;
- print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n";
-
- mkinc($_) for @modules;
-
- print "Creating Makefile\n";
-
- open MAK,">Makefile" or die "Makefile: $!\n";
-
- print MAK "all: @modules\n\nclean:\n";
-
- for (@modules) {
- my $full = full($_);
- my $build = $topbuild{$_} ? '': '/build';
- print MAK "\tcd $full$build && \${MAKE} clean\n"
- }
-
- print MAK "\ndistclean:\n";
-
- for (@modules) {
- my $full = full($_);
- print MAK $topbuild{$_} ?
- "\tcd $full$build && \${MAKE} distclean\n" :
- "\trm -rf $full$build\n"
- }
-
- print MAK "\n";
-
- for (@modules) {
- my %ldeps; undef %ldeps;
- @ldeps{@{$deps{$_}}} = 1;
- for my $x (split /,/,$staged) { delete $ldeps{$x}; }
- my @dnames = $module ? () : keys %ldeps;
-
- my $full = full($_);
- my $build = $topbuild{$_} ? '': '/build';
-
- print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n";
- }
-
- close MAK;
-}
-
-sub mode_checkout() {
- for (@modules) {
- my $module = $_;
- my $tag = "";
- if ($lb_tag){
- for (@{$lbmodules{lb}}){
- if ("lb.".$_ eq $module){
- $tag = '-r '.$lb_tag;
- }
- }
- }
- if ($lbjp_tag){
- for (@{$lbmodules{'lbjp-common'}}){
- if ("lbjp-common.".$_ eq $module){
- $tag = '-r '.$lbjp_tag;
- }
- }
- }
- if ($jp_tag){
- for (@{$lbmodules{'jp'}}){
- if ("jp.".$_ eq $module){
- $tag = '-r '.$jp_tag;
- }
- }
- }
- if ($sec_tag){
- for (@{$lbmodules{security}}){
- if ("security.".$_ eq $module){
- $tag = '-r '.$sec_tag;
- }
- }
- }
- if ($jobid_tag){
- for (@{$lbmodules{jobid}}){
- if ("jobid.".$_ eq $module){
- $tag = '-r '.$jobid_tag;
- }
- }
- }
- #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){
- # print "found";
- #}
- $_ = full($_);
- print "\n*** Checking out $_\n";
- system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n";
- }
-}
-
-BEGIN{
-%need_externs_aux = (
- 'lb.client' => [ qw/cppunit:B classads/ ],
- 'lb.client-java' => [ qw/ant:B/ ],
- 'lb.common' => [ qw/expat cppunit:B classads/ ],
- 'lb.doc' => [],
- 'lb.logger' => [ qw/cppunit:B/ ],
- 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql cppunit:B gsoap:B classads voms lcas gridsite/ ],
- 'lb.state-machine' => [ qw/classads/ ],
- 'lb.utils' => [ qw/cppunit:B/ ],
- 'lb.ws-interface' => [],
- 'lb.ws-test' => [ qw/gsoap:B/ ],
- 'lb.types' => [ qw// ],
- 'lbjp-common.db' => [ qw/mysql/ ],
- 'lbjp-common.maildir' => [ qw// ],
- 'lbjp-common.server-bones' => [ qw// ],
- 'lbjp-common.trio' => [ qw/cppunit:B/ ],
- 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ],
- 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ],
- 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ],
- 'jobid.api-c' => [ qw/cppunit:B/ ],
- 'jobid.api-cpp' => [ qw/cppunit:B/ ],
- 'jobid.api-java' => [ qw/ant:B jdk:B/ ],
- 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ],
- 'jp.doc' => [],
- 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ],
- 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ],
- 'jp.server-common' => [],
- 'jp.ws-interface' => [],
-);
-
-for my $ext (keys %need_externs_aux) {
- for (@{$need_externs_aux{$ext}}) {
- /([^:]*)(?::(.*))?/;
- push @{$need_externs{$ext}},$1;
- my $type = $2 ? $2 : 'BR';
- $need_externs_type{$ext}->{$1} = $type;
- }
-}
-
-%need_jars = (
- 'jobid.api-java' => [ qw/commons-codec/ ],
-);
-
-for my $jar (keys %need_jars) {
- for (@{$need_jars{$jar}}) {
- $need_externs_type{$jar}->{$_} = 'BR'; # XXX
- }
-}
-
-%deps_aux = (
- 'lb.client' => [ qw/
- lb.types:B lb.common
- lbjp-common.trio
- jobid.api-cpp jobid.api-c
- security.gss
- / ],
- 'lb.client-java' => [ qw/
- lb.types:B
- jobid.api-java
- / ],
- 'lb.common' => [ qw/
- jobid.api-cpp jobid.api-c
- lb.types:B lbjp-common.trio security.gss
- / ],
- 'lb.doc' => [ qw/lb.types:B/ ],
- 'lb.logger' => [ qw/
- lbjp-common.trio
- jobid.api-c
- lb.common
- security.gss
- / ],
- 'lb.server' => [ qw/
- lb.ws-interface lb.types:B lb.common lb.state-machine
- lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir
- jobid.api-c
- security.gsoap-plugin security.gss
- / ],
- 'lb.state-machine' => [ qw/lb.common lbjp-common.jp-interface security.gss/ ],
- 'lb.utils' => [ qw/
- lbjp-common.jp-interface
- jobid.api-c
- lbjp-common.trio lbjp-common.maildir
- lb.client lb.state-machine
- / ],
- 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ],
- 'lb.ws-interface' => [ qw/lb.types:B/ ],
- 'lb.types' => [ qw// ],
- 'lbjp-common.db' => [ qw/lbjp-common.trio/ ],
- 'lbjp-common.maildir' => [ qw// ],
- 'lbjp-common.server-bones' => [ qw// ],
- 'lbjp-common.trio' => [ qw// ],
- 'security.gss' => [ qw// ],
- 'security.gsoap-plugin' => [ qw/security.gss/ ],
- 'jobid.api-c' => [ qw// ],
- 'jobid.api-cpp' => [ qw/jobid.api-c/ ],
- 'jobid.api-java' => [ qw// ],
-
- 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ],
-
- 'jp.client' => [ qw/
- jp.ws-interface
- lbjp-common.jp-interface lbjp-common.maildir
- jobid.api-c
- security.gsoap-plugin
- / ],
- 'jp.doc' => [ qw// ],
- 'jp.index' => [ qw/
- jp.server-common jp.ws-interface
- lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones
- security.gsoap-plugin
- / ],
- 'jp.primary' => [ qw/
- jobid.api-c
- jp.server-common jp.ws-interface
- lb.state-machine
- lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones
- security.gsoap-plugin
- / ],
- 'jp.server-common' => [ qw/
- lbjp-common.jp-interface lbjp-common.db
- / ],
- 'jp.ws-interface' => [ qw// ],
-);
-
-for my $ext (keys %deps_aux) {
- for (@{$deps_aux{$ext}}) {
- /([^:]*)(?::(.*))?/;
- push @{$deps{$ext}},$1;
- my $type = $2 ? $2 : 'BR';
- $deps_type{$ext}->{$1} = $type;
- }
-}
-
-
-%extrafull = ( gridsite=>'org.gridsite.core');
-
-#( java => 'client-java' );
-%extranodmod = (
- db => 'lbjp-common.db',
- jpprimary => 'jp.primary',
- jpindex => 'jp.index',
- jpclient => 'jp.client',
-);
-
-my @t = qw/lb.client-java jobid.api-java lb.types/;
-@topbuild{@t} = (1) x ($#t+1);
-}
-
-sub full
-{
- my $short = shift;
- return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short;
-}
-
-sub mkinc
-{
- my %aux;
- undef %aux;
- my @m=qw/
-lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java
-security.gss security.gsoap-plugin
-jobid.api-c jobid.api-cpp jobid.api-java
-lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface
-jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface
-/;
- @aux{@m} = (1) x ($#m+1);
-
- my $short = shift;
- my $full = full $short;
-
- unless ($aux{$short}) {
- print "Makefile.inc not needed in $full\n";
- return;
- }
-
- my $build = '';
-
- unless ($topbuild{$_}) {
- $build = '/build';
- unless (-d "$full/build") {
- mkdir "$full/build" or die "mkdir $full/build: $!\n";
- }
- unlink "$full/build/Makefile";
- symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n";
- }
-
- open MKINC,">$full$build/Makefile.inc"
- or die "$full$build/Makefile.inc: $!\n";
-
- print "Creating $full$build/Makefile.inc\n";
-
- print MKINC qq{
-PREFIX = $prefix
-stagedir = $stagedir
-thrflavour = $thrflavour
-nothrflavour = $nothrflavour
-};
-
- for (@{$need_externs{$short}}) {
- print MKINC "${_}_prefix = $extern_prefix{$_}\n"
- }
-
- for (@{$need_jars{$short}}) {
- print MKINC "${_}_jar = $jar{$_}\n"
- }
-
- my $need_gsoap = 0;
- for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; }
-
- print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap;
-
- close MKINC;
-}
-
-my %etics_externs;
-my %etics_projects;
-BEGIN{
- %etics_externs = (
- globus_essentials=>'vdt_globus_essentials',
- globus=>'globus',
- cares=>'c-ares',
- voms=>'org.glite.security.voms-api-cpp',
- gridsite=>'org.gridsite.shared',
- lcas=>'org.glite.security.lcas',
- );
- %etics_projects = (
- vdt=>[qw/globus globus_essentials/],
- 'org.glite'=>[qw/voms gridsite lcas/],
- );
-};
-
-sub mode_etics {
- $fmod = shift;
-
- die "$0: --module required with --etics\n" unless $fmod;
-
- my ($subsys,$module) = split /\./,$fmod;
-
- my ($major,$minor,$rev,$age);
-
- if ($version) {
- $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/;
- ($major,$minor,$rev,$age) = ($1,$2,$3,$4);
- }
- else {
- open V,"org.glite.$subsys.$module/project/version.properties"
- or die "org.glite.$subsys.$module/project/version.properties: $!\n";
-
- while ($_ = <V>) {
- chomp;
- ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/;
- $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/;
- }
- close V;
- }
-
- my @copts = ();
- my %ge;
- @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1);
-
- for (@{$need_externs{"$subsys.$module"}}) {
- my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_;
- push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}";
- }
-
- for (@{$need_jars{"$subsys.$module"}}) {
- my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_;
-
- push @copts,"--with-$_ \${$eext.location}/$_*.jar";
- }
-
-
- my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}";
- my $file = $output ? $output : "$conf.ini";
- open C,">$file" or die "$file: $!\n";
-
- my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n";
-
- my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..';
-
- print STDERR "Writing $file\n";
- print C qq{
-[Configuration-$conf]
-profile = None
-moduleName = org.glite.$subsys.$module
-displayName = $conf
-description = org.glite.$subsys.$module
-projectName = org.glite
-age = $age
-deploymentType = None
-tag = $conf
-version = $major.$minor.$rev
-path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz
-
-[Platform-default:VcsCommand]
-displayName = None
-description = None
-tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName}
-branch = None
-commit = None
-checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName}
-
-[Platform-default:BuildCommand]
-postpublish = None
-packaging = None
-displayName = None
-description = None
-doc = None
-prepublish = None
-publish = None
-compile = make
-init = None
-install = make install
-clean = make clean
-test = make check
-configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --module $subsys.$module @copts
-checkstyle = None
-
-[Platform-default:Property]
-$buildroot
-
-[Platform-default:DynamicDependency]
-
-};
- for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) {
- my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_;
-
- my $proj = 'externals';
- for my $p (keys %etics_projects) {
- for $m (@{$etics_projects{$p}}) {
- $proj = $p if $m eq $_;
- }
- }
-
- my $type = $need_externs_type{"$subsys.$module"}->{$_};
- print C "$proj|$eext = $type\n";
- }
-
- for (@{$deps{"$subsys.$module"}}) {
- my $type = $deps_type{"$subsys.$module"}->{$_};
- print C "org.glite|org.glite.$_ = $type\n";
- }
-
- close C;
-}
-
-sub gsoap_version {
- local $_;
- my $gsoap_version;
- open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n";
-
- while ($_ = <S>) {
- chomp;
-
- $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/;
- }
- close S;
- return $gsoap_version;
-}
-
-
-sub usage {
- my @ext = keys %extern_prefix;
- my @myjars, keys %jar;
-
- print STDERR qq{
-usage: $0 options
-
-General options (defaults in []):
- --prefix=PREFIX destination directory [./stage]
- --staged=module,module,... what is already in PREFIX (specify without org.glite.)
- --thrflavour=flavour
- --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg]
- --listmodules=subsys list modules of a subsystem
-
-Mode of operation:
- --mode={checkout|build|etics} what to do [build]
-
-What to build:
- --module=module build this module only (mostly in-Etics operation)
- --enable-NODE build this "node" (set of modules) only. Available nodes are
- @{$lbmodules{lb}},@{$lbmodules{security}}
- --disable-NODE don't build this node
- --lb-tag=tag checkout LB modules with specific tag
- --jp-tag=tag checkout JP modules with specific tag
- --lbjp-common-tag=tag checkout lbjp-common modules with specific tag
- --security-tag=tag checkout security modules with specific tag
- --jobid-tag=tag checkout jobid modules with specific tag
-
-Dependencies:
- --with-EXTERNAL=PATH where to look for an external. Required externals
- (not all for all modules) are:
- @ext
- --with-JAR=JAR where to look for jars. Required jars are:
- @myjars
- Summary of what will be used is always printed
-
-};
-
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-*** GENERATED FROM project.xml - DO NOT EDIT ***
-*** EDIT ../build.xml INSTEAD ***
-
-For the purpose of easier reading the script
-is divided into following sections:
-
- - initialization
- - compilation
- - jar
- - execution
- - debugging
- - javadoc
- - junit compilation
- - junit execution
- - junit debugging
- - applet
- - cleanup
-
- -->
-<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="lb-client-java-impl">
- <target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
- <!--
- ======================
- INITIALIZATION SECTION
- ======================
- -->
- <target name="-pre-init">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="-pre-init" name="-init-private">
- <property file="nbproject/private/config.properties"/>
- <property file="nbproject/private/configs/${config}.properties"/>
- <property file="nbproject/private/private.properties"/>
- </target>
- <target depends="-pre-init,-init-private" name="-init-user">
- <property file="${user.properties.file}"/>
- <!-- The two properties below are usually overridden -->
- <!-- by the active platform. Just a fallback. -->
- <property name="default.javac.source" value="1.4"/>
- <property name="default.javac.target" value="1.4"/>
- </target>
- <target depends="-pre-init,-init-private,-init-user" name="-init-project">
- <property file="nbproject/configs/${config}.properties"/>
- <property file="nbproject/project.properties"/>
- </target>
- <target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
- <available file="${manifest.file}" property="manifest.available"/>
- <condition property="manifest.available+main.class">
- <and>
- <isset property="manifest.available"/>
- <isset property="main.class"/>
- <not>
- <equals arg1="${main.class}" arg2="" trim="true"/>
- </not>
- </and>
- </condition>
- <condition property="manifest.available+main.class+mkdist.available">
- <and>
- <istrue value="${manifest.available+main.class}"/>
- <isset property="libs.CopyLibs.classpath"/>
- </and>
- </condition>
- <condition property="have.tests">
- <or>
- <available file="${test.src.dir}"/>
- </or>
- </condition>
- <condition property="have.sources">
- <or>
- <available file="${src.dir}"/>
- </or>
- </condition>
- <condition property="netbeans.home+have.tests">
- <and>
- <isset property="netbeans.home"/>
- <isset property="have.tests"/>
- </and>
- </condition>
- <condition property="no.javadoc.preview">
- <and>
- <isset property="javadoc.preview"/>
- <isfalse value="${javadoc.preview}"/>
- </and>
- </condition>
- <property name="run.jvmargs" value=""/>
- <property name="javac.compilerargs" value=""/>
- <property name="work.dir" value="${basedir}"/>
- <condition property="no.deps">
- <and>
- <istrue value="${no.dependencies}"/>
- </and>
- </condition>
- <property name="javac.debug" value="true"/>
- <property name="javadoc.preview" value="true"/>
- <property name="application.args" value=""/>
- <property name="source.encoding" value="${file.encoding}"/>
- <condition property="javadoc.encoding.used" value="${javadoc.encoding}">
- <and>
- <isset property="javadoc.encoding"/>
- <not>
- <equals arg1="${javadoc.encoding}" arg2=""/>
- </not>
- </and>
- </condition>
- <property name="javadoc.encoding.used" value="${source.encoding}"/>
- <property name="includes" value="**"/>
- <property name="excludes" value=""/>
- <property name="do.depend" value="false"/>
- <condition property="do.depend.true">
- <istrue value="${do.depend}"/>
- </condition>
- <condition property="javac.compilerargs.jaxws" value="-Djava.endorsed.dirs='${jaxws.endorsed.dir}'">
- <and>
- <isset property="jaxws.endorsed.dir"/>
- <available file="nbproject/jaxws-build.xml"/>
- </and>
- </condition>
- </target>
- <target name="-post-init">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
- <fail unless="src.dir">Must set src.dir</fail>
- <fail unless="test.src.dir">Must set test.src.dir</fail>
- <fail unless="build.dir">Must set build.dir</fail>
- <fail unless="dist.dir">Must set dist.dir</fail>
- <fail unless="build.classes.dir">Must set build.classes.dir</fail>
- <fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
- <fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
- <fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
- <fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
- <fail unless="dist.jar">Must set dist.jar</fail>
- </target>
- <target name="-init-macrodef-property">
- <macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
- <attribute name="name"/>
- <attribute name="value"/>
- <sequential>
- <property name="@{name}" value="${@{value}}"/>
- </sequential>
- </macrodef>
- </target>
- <target name="-init-macrodef-javac">
- <macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
- <attribute default="${src.dir}" name="srcdir"/>
- <attribute default="${build.classes.dir}" name="destdir"/>
- <attribute default="${javac.classpath}" name="classpath"/>
- <attribute default="${includes}" name="includes"/>
- <attribute default="${excludes}" name="excludes"/>
- <attribute default="${javac.debug}" name="debug"/>
- <attribute default="" name="sourcepath"/>
- <element name="customize" optional="true"/>
- <sequential>
- <javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" includeantruntime="false" includes="@{includes}" sourcepath="@{sourcepath}" srcdir="@{srcdir}">
- <classpath>
- <path path="@{classpath}"/>
- </classpath>
- <compilerarg line="${javac.compilerargs} ${javac.compilerargs.jaxws}"/>
- <customize/>
- </javac>
- </sequential>
- </macrodef>
- <macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
- <attribute default="${src.dir}" name="srcdir"/>
- <attribute default="${build.classes.dir}" name="destdir"/>
- <attribute default="${javac.classpath}" name="classpath"/>
- <sequential>
- <depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
- <classpath>
- <path path="@{classpath}"/>
- </classpath>
- </depend>
- </sequential>
- </macrodef>
- <macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3">
- <attribute default="${build.classes.dir}" name="destdir"/>
- <sequential>
- <fail unless="javac.includes">Must set javac.includes</fail>
- <pathconvert pathsep="," property="javac.includes.binary">
- <path>
- <filelist dir="@{destdir}" files="${javac.includes}"/>
- </path>
- <globmapper from="*.java" to="*.class"/>
- </pathconvert>
- <delete>
- <files includes="${javac.includes.binary}"/>
- </delete>
- </sequential>
- </macrodef>
- </target>
- <target name="-init-macrodef-junit">
- <macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
- <attribute default="${includes}" name="includes"/>
- <attribute default="${excludes}" name="excludes"/>
- <attribute default="**" name="testincludes"/>
- <sequential>
- <junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true">
- <batchtest todir="${build.test.results.dir}">
- <fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
- <filename name="@{testincludes}"/>
- </fileset>
- </batchtest>
- <classpath>
- <path path="${run.test.classpath}"/>
- </classpath>
- <syspropertyset>
- <propertyref prefix="test-sys-prop."/>
- <mapper from="test-sys-prop.*" to="*" type="glob"/>
- </syspropertyset>
- <formatter type="brief" usefile="false"/>
- <formatter type="xml"/>
- <jvmarg line="${run.jvmargs}"/>
- </junit>
- </sequential>
- </macrodef>
- </target>
- <target name="-init-macrodef-nbjpda">
- <macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
- <attribute default="${main.class}" name="name"/>
- <attribute default="${debug.classpath}" name="classpath"/>
- <attribute default="" name="stopclassname"/>
- <sequential>
- <nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="dt_socket">
- <classpath>
- <path path="@{classpath}"/>
- </classpath>
- </nbjpdastart>
- </sequential>
- </macrodef>
- <macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
- <attribute default="${build.classes.dir}" name="dir"/>
- <sequential>
- <nbjpdareload>
- <fileset dir="@{dir}" includes="${fix.includes}*.class"/>
- </nbjpdareload>
- </sequential>
- </macrodef>
- </target>
- <target name="-init-debug-args">
- <property name="version-output" value="java version "${ant.java.version}"/>
- <condition property="have-jdk-older-than-1.4">
- <or>
- <contains string="${version-output}" substring="java version "1.0"/>
- <contains string="${version-output}" substring="java version "1.1"/>
- <contains string="${version-output}" substring="java version "1.2"/>
- <contains string="${version-output}" substring="java version "1.3"/>
- </or>
- </condition>
- <condition property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
- <istrue value="${have-jdk-older-than-1.4}"/>
- </condition>
- </target>
- <target depends="-init-debug-args" name="-init-macrodef-debug">
- <macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
- <attribute default="${main.class}" name="classname"/>
- <attribute default="${debug.classpath}" name="classpath"/>
- <element name="customize" optional="true"/>
- <sequential>
- <java classname="@{classname}" dir="${work.dir}" fork="true">
- <jvmarg line="${debug-args-line}"/>
- <jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
- <jvmarg line="${run.jvmargs}"/>
- <classpath>
- <path path="@{classpath}"/>
- </classpath>
- <syspropertyset>
- <propertyref prefix="run-sys-prop."/>
- <mapper from="run-sys-prop.*" to="*" type="glob"/>
- </syspropertyset>
- <customize/>
- </java>
- </sequential>
- </macrodef>
- </target>
- <target name="-init-macrodef-java">
- <macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
- <attribute default="${main.class}" name="classname"/>
- <element name="customize" optional="true"/>
- <sequential>
- <java classname="@{classname}" dir="${work.dir}" fork="true">
- <jvmarg line="${run.jvmargs}"/>
- <classpath>
- <path path="${run.classpath}"/>
- </classpath>
- <syspropertyset>
- <propertyref prefix="run-sys-prop."/>
- <mapper from="run-sys-prop.*" to="*" type="glob"/>
- </syspropertyset>
- <customize/>
- </java>
- </sequential>
- </macrodef>
- </target>
- <target name="-init-presetdef-jar">
- <presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
- <jar compress="${jar.compress}" jarfile="${dist.jar}">
- <j2seproject1:fileset dir="${build.classes.dir}"/>
- </jar>
- </presetdef>
- </target>
- <target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar" name="init"/>
- <!--
- ===================
- COMPILATION SECTION
- ===================
- -->
- <target depends="init" name="deps-jar" unless="no.deps">
- <ant antfile="${project.jobid-api-java}/build.xml" inheritall="false" target="jar"/>
- </target>
- <target depends="init,deps-jar" name="-pre-pre-compile">
- <mkdir dir="${build.classes.dir}"/>
- </target>
- <target name="-pre-compile">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target if="do.depend.true" name="-compile-depend">
- <j2seproject3:depend/>
- </target>
- <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
- <j2seproject3:javac/>
- <copy todir="${build.classes.dir}">
- <fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
- </copy>
- </target>
- <target name="-post-compile">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
- <target name="-pre-compile-single">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
- <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
- <j2seproject3:force-recompile/>
- <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.dir}"/>
- </target>
- <target name="-post-compile-single">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="init,deps-jar,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
- <!--
- ====================
- JAR BUILDING SECTION
- ====================
- -->
- <target depends="init" name="-pre-pre-jar">
- <dirname file="${dist.jar}" property="dist.jar.dir"/>
- <mkdir dir="${dist.jar.dir}"/>
- </target>
- <target name="-pre-jar">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="init,compile,-pre-pre-jar,-pre-jar" name="-do-jar-without-manifest" unless="manifest.available">
- <j2seproject1:jar/>
- </target>
- <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class">
- <j2seproject1:jar manifest="${manifest.file}"/>
- </target>
- <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
- <j2seproject1:jar manifest="${manifest.file}">
- <j2seproject1:manifest>
- <j2seproject1:attribute name="Main-Class" value="${main.class}"/>
- </j2seproject1:manifest>
- </j2seproject1:jar>
- <echo>To run this application from the command line without Ant, try:</echo>
- <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
- <property location="${dist.jar}" name="dist.jar.resolved"/>
- <pathconvert property="run.classpath.with.dist.jar">
- <path path="${run.classpath}"/>
- <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
- </pathconvert>
- <echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
- </target>
- <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries">
- <property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
- <pathconvert property="run.classpath.without.build.classes.dir">
- <path path="${run.classpath}"/>
- <map from="${build.classes.dir.resolved}" to=""/>
- </pathconvert>
- <pathconvert pathsep=" " property="jar.classpath">
- <path path="${run.classpath.without.build.classes.dir}"/>
- <chainedmapper>
- <flattenmapper/>
- <globmapper from="*" to="lib/*"/>
- </chainedmapper>
- </pathconvert>
- <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
- <copylibs compress="${jar.compress}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
- <fileset dir="${build.classes.dir}"/>
- <manifest>
- <attribute name="Main-Class" value="${main.class}"/>
- <attribute name="Class-Path" value="${jar.classpath}"/>
- </manifest>
- </copylibs>
- <echo>To run this application from the command line without Ant, try:</echo>
- <property location="${dist.jar}" name="dist.jar.resolved"/>
- <echo>java -jar "${dist.jar.resolved}"</echo>
- </target>
- <target name="-post-jar">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar"/>
- <!--
- =================
- EXECUTION SECTION
- =================
- -->
- <target depends="init,compile" description="Run a main class." name="run">
- <j2seproject1:java>
- <customize>
- <arg line="${application.args}"/>
- </customize>
- </j2seproject1:java>
- </target>
- <target name="-do-not-recompile">
- <property name="javac.includes.binary" value=""/>
- </target>
- <target depends="init,-do-not-recompile,compile-single" name="run-single">
- <fail unless="run.class">Must select one file in the IDE or set run.class</fail>
- <j2seproject1:java classname="${run.class}"/>
- </target>
- <!--
- =================
- DEBUGGING SECTION
- =================
- -->
- <target depends="init" if="netbeans.home" name="-debug-start-debugger">
- <j2seproject1:nbjpdastart name="${debug.class}"/>
- </target>
- <target depends="init,compile" name="-debug-start-debuggee">
- <j2seproject3:debug>
- <customize>
- <arg line="${application.args}"/>
- </customize>
- </j2seproject3:debug>
- </target>
- <target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
- <target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto">
- <j2seproject1:nbjpdastart stopclassname="${main.class}"/>
- </target>
- <target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
- <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single">
- <fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
- <j2seproject3:debug classname="${debug.class}"/>
- </target>
- <target depends="init,-do-not-recompile,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
- <target depends="init" name="-pre-debug-fix">
- <fail unless="fix.includes">Must set fix.includes</fail>
- <property name="javac.includes" value="${fix.includes}.java"/>
- </target>
- <target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
- <j2seproject1:nbjpdareload/>
- </target>
- <target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
- <!--
- ===============
- JAVADOC SECTION
- ===============
- -->
- <target depends="init" name="-javadoc-build">
- <mkdir dir="${dist.javadoc.dir}"/>
- <javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
- <classpath>
- <path path="${javac.classpath}"/>
- </classpath>
- <fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
- <filename name="**/*.java"/>
- </fileset>
- </javadoc>
- </target>
- <target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
- <nbbrowse file="${dist.javadoc.dir}/index.html"/>
- </target>
- <target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
- <!--
- =========================
- JUNIT COMPILATION SECTION
- =========================
- -->
- <target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
- <mkdir dir="${build.test.classes.dir}"/>
- </target>
- <target name="-pre-compile-test">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target if="do.depend.true" name="-compile-test-depend">
- <j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
- </target>
- <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
- <j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
- <copy todir="${build.test.classes.dir}">
- <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
- </copy>
- </target>
- <target name="-post-compile-test">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
- <target name="-pre-compile-test-single">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
- <fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
- <j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
- <j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/>
- <copy todir="${build.test.classes.dir}">
- <fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
- </copy>
- </target>
- <target name="-post-compile-test-single">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
- <!--
- =======================
- JUNIT EXECUTION SECTION
- =======================
- -->
- <target depends="init" if="have.tests" name="-pre-test-run">
- <mkdir dir="${build.test.results.dir}"/>
- </target>
- <target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
- <j2seproject3:junit testincludes="**/*Test.java"/>
- </target>
- <target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
- <fail if="tests.failed">Some tests failed; see details above.</fail>
- </target>
- <target depends="init" if="have.tests" name="test-report"/>
- <target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
- <target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
- <target depends="init" if="have.tests" name="-pre-test-run-single">
- <mkdir dir="${build.test.results.dir}"/>
- </target>
- <target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
- <fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
- <j2seproject3:junit excludes="" includes="${test.includes}"/>
- </target>
- <target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
- <fail if="tests.failed">Some tests failed; see details above.</fail>
- </target>
- <target depends="init,-do-not-recompile,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
- <!--
- =======================
- JUNIT DEBUGGING SECTION
- =======================
- -->
- <target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
- <fail unless="test.class">Must select one file in the IDE or set test.class</fail>
- <property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
- <delete file="${test.report.file}"/>
- <mkdir dir="${build.test.results.dir}"/>
- <j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
- <customize>
- <syspropertyset>
- <propertyref prefix="test-sys-prop."/>
- <mapper from="test-sys-prop.*" to="*" type="glob"/>
- </syspropertyset>
- <arg value="${test.class}"/>
- <arg value="showoutput=true"/>
- <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
- <arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
- </customize>
- </j2seproject3:debug>
- </target>
- <target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
- <j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
- </target>
- <target depends="init,-do-not-recompile,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
- <target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
- <j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
- </target>
- <target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
- <!--
- =========================
- APPLET EXECUTION SECTION
- =========================
- -->
- <target depends="init,compile-single" name="run-applet">
- <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
- <j2seproject1:java classname="sun.applet.AppletViewer">
- <customize>
- <arg value="${applet.url}"/>
- </customize>
- </j2seproject1:java>
- </target>
- <!--
- =========================
- APPLET DEBUGGING SECTION
- =========================
- -->
- <target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
- <fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
- <j2seproject3:debug classname="sun.applet.AppletViewer">
- <customize>
- <arg value="${applet.url}"/>
- </customize>
- </j2seproject3:debug>
- </target>
- <target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
- <!--
- ===============
- CLEANUP SECTION
- ===============
- -->
- <target depends="init" name="deps-clean" unless="no.deps">
- <ant antfile="${project.jobid-api-java}/build.xml" inheritall="false" target="clean"/>
- </target>
- <target depends="init" name="-do-clean">
- <delete dir="${build.dir}"/>
- <delete dir="${dist.dir}"/>
- </target>
- <target name="-post-clean">
- <!-- Empty placeholder for easier customization. -->
- <!-- You can override this target in the ../build.xml file. -->
- </target>
- <target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
-</project>
+++ /dev/null
-build.xml.data.CRC32=2a7fa1fb
-build.xml.script.CRC32=584b0e83
-build.xml.stylesheet.CRC32=be360661
-# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
-# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=2a7fa1fb
-nbproject/build-impl.xml.script.CRC32=1298608d
-nbproject/build-impl.xml.stylesheet.CRC32=f1d9da08
+++ /dev/null
-do.depend=false
-do.jar=true
-javac.debug=true
-javadoc.preview=true
-jaxws.endorsed.dir=/home/pavel/netbeans-6.0.1/java1/modules/ext/jaxws21/api
-project.jobid-api-java=/home/pavel/Desktop/bakalarka/org.glite.jobid.api-java
-user.properties.file=/home/pavel/.netbeans/6.0/build.properties
+++ /dev/null
-application.title=locallogger
-application.vendor=pavel
-build.classes.dir=${build.dir}/classes
-build.classes.excludes=**/*.java,**/*.form
-# This directory is removed when the project is cleaned:
-build.dir=build
-build.generated.dir=${build.dir}/generated
-# Only compile against the classpath explicitly listed here:
-build.sysclasspath=ignore
-build.test.classes.dir=${build.dir}/test/classes
-build.test.results.dir=${build.dir}/test/results
-debug.classpath=\
- ${run.classpath}
-debug.test.classpath=\
- ${run.test.classpath}
-# This directory is removed when the project is cleaned:
-dist.dir=dist
-dist.jar=${dist.dir}/lb-client-java.jar
-dist.javadoc.dir=${dist.dir}/javadoc
-excludes=
-includes=**
-jar.compress=false
-javac.classpath=\
- ${reference.jobid-api-java.jar}:\
- ${file.reference.cog-certmanagement.jar}:\
- ${file.reference.cog-jglobus.jar}
-# Space-separated list of extra javac options
-javac.compilerargs=
-javac.deprecation=false
-javac.source=
-javac.target=
-javac.test.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}:\
- ${libs.junit.classpath}:\
- ${libs.junit_4.classpath}
-javadoc.additionalparam=
-javadoc.author=false
-javadoc.encoding=${source.encoding}
-javadoc.noindex=false
-javadoc.nonavbar=false
-javadoc.notree=false
-javadoc.private=false
-javadoc.splitindex=true
-javadoc.use=true
-javadoc.version=false
-javadoc.windowtitle=
-main.class=org.glite.test.Test
-manifest.file=manifest.mf
-meta.inf.dir=${src.dir}/META-INF
-platform.active=default_platform
-project.jobid-api-java=../jobid-api-java
-reference.jobid-api-java.jar=${project.jobid-api-java}/dist/jobid-api-java.jar
-run.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}
-# Space-separated list of JVM arguments used when running the project
-# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
-# or test-sys-prop.name=value to set system properties for unit tests):
-run.jvmargs=-Djava.library.path=/media/f/skola/bakalarka/locallogger/build/classes/org/glite/lb/
-run.test.classpath=\
- ${javac.test.classpath}:\
- ${build.test.classes.dir}
-source.encoding=UTF-8
-src.dir=src
-test.src.dir=test
-javac.compilerargs.jaxws=
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://www.netbeans.org/ns/project/1">
- <type>org.netbeans.modules.java.j2seproject</type>
- <configuration>
- <data xmlns="http://www.netbeans.org/ns/j2se-project/3">
- <name>lb-client-java</name>
- <minimum-ant-version>1.6.5</minimum-ant-version>
- <source-roots>
- <root id="src.dir"/>
- </source-roots>
- <test-roots>
- <root id="test.src.dir"/>
- </test-roots>
- </data>
- <references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
- <reference>
- <foreign-project>jobid-api-java</foreign-project>
- <artifact-type>jar</artifact-type>
- <script>build.xml</script>
- <target>jar</target>
- <clean-target>clean</clean-target>
- <id>jar</id>
- </reference>
- </references>
- </configuration>
-</project>
+++ /dev/null
-1.0.0-1
-- LB 2.0 release
-
-1.0.0-2
-- fixed configure to work in etics
-
-1.0.0-3
-- Added the dummy 'check' rule to the Makefile
-
-1.0.0-4
-- configure script update (globus flavors added to configure call)
-
-1.0.0-5
-- Added ant_prefix handling to Makefile and configure
-
-1.0.0-6
-- configure script update
-
+++ /dev/null
-@@@LANG: java
-@@@{
- $dest = shift;
-
- for my $e ($event->getTypesOrdered) {
- my $uc = ucfirst $e;
- my $uuc = uc $e;
- print "generating $dest/Event$uc.java\n";
-
- open E,">$dest/Event$uc.java" or die "$dest/Event$uc.java: $!\n";
-
- print E
-qq{
-package org.glite.lb;
-import org.glite.jobid.CheckedString;
-import org.glite.jobid.Jobid;
-
-public class Event$uc extends Event \{
- public Event$uc() \{
- \}
-
- public String getEventType() \{
- return "$uc";
- \}
-};
-
- selectType $event $e;
-
- for ($event->getFieldsOrdered) {
- my $f = selectField $event $_;
- my $fn = $f->{name};
- my $fnu = ucfirst $fn;
- my $fnuu = uc $fn;
- my $t;
-
- while ($fnu =~ /_([a-z])/) {
- my $u = uc $1;
- $fnu =~ s/_$1/$u/;
- }
-
- if ($f->{codes}) {
- local $_;
- $t = $fnu;
- print E
-qq{ public enum $fnu \{
- ${fnuu}_UNDEFINED,
-};
- for (@{$f->{codes}}) {
- my $cu = uc $_->{name};
- print E
-qq{ ${fnuu}_${cu},
-};
- }
- print E
-qq{\}
-};
- }
- else {
- $t = $f->getType;
- }
-
-# XXX: handle nulls in setXX() ?
- print E
-qq{ private $t $fn;
-
- public $t get$fnu() \{
- return $fn;
- \}
-
- public void set$fnu($t val) \{
- this.$fn = val;
- \}
-};
- }
-
- print E
-
-qq{ public String ulm() \{
- return (" " +
-};
-
-
- for ($event->getFieldsOrdered) {
- my $f = selectField $event $_;
- my $fn = $f->{name};
- my $t = getType $f;
- my $fnu = ucfirst $fn;
- my $fnuu = uc $fn;
- my $val = $t eq 'String' ?
- "new CheckedString($fn).toString()" : $fn;
-
- print E
-qq{ "DG.$uuc.$fnuu=\\"" + $val + "\\"" +
-};
- }
-
- print E
-qq{ "");
- \}
-\}
-};
-
- close E;
- }
-
-@@@}
+++ /dev/null
-# $Header$
-module.version=1.0.0
-module.age=6
+++ /dev/null
-package org.glite.lb;
-
-import java.net.UnknownHostException;
-import java.util.Calendar;
-import java.util.Random;
-import org.glite.jobid.Jobid;
-import org.glite.jobid.CheckedString;
-
-/**
- * Class representing a context for some job
- *
- * @author Pavel Piskac (173297@mail.muni.cz)
- * @version 15. 3. 2008
- */
-public abstract class Context {
-
- private int id;
- private int source;
- private int flag;
- private String host;
- private String user;
- private String prog;
- private String srcInstance;
- private Jobid jobid;
- private SeqCode seqCode;
-
- /**
- * Creates new instance of Context class.
- */
- public Context() {
- }
-
- /**
- * Creates new instance of Context class.
- *
- * @param id message id, if null, random number is generated
- * @param source one if paramaters of Sources enumeration
- * @param flag
- * @param host host name, if null or "", the name is get from host name of this computer
- * @param user user name
- * @param prog if null then is used "egd-wms"
- * @param srcInstance if null then it is set as ""
- * @param jobid
- * @throws java.lang.IllegalArgumentException if user or jobid is null
- * or flag < 0 or source <=0 || >= 9
- *
- */
- public Context(int id,
- int source,
- int flag,
- String host,
- String user,
- String prog,
- String srcInstance,
- Jobid jobid) {
- if (id < 0) {
- id = new Random().nextInt();
- }
-
- if (source <= -1 || source > Sources.EDG_WLL_SOURCE_LB_SERVER) {
- throw new IllegalArgumentException("Context source");
- }
-
- if (flag < 0) {
- throw new IllegalArgumentException("Context flag");
- }
-
- if (host == null || host.equals("")) {
- try {
- host = java.net.InetAddress.getLocalHost().getHostName();
- } catch (UnknownHostException ex) {
- System.err.println(ex);
- }
- }
-
- if (user == null) {
- throw new IllegalArgumentException("Context user");
- }
-
- if (prog == null) {
- prog = new String("edg-wms");
- }
-
- if (srcInstance == null) {
- srcInstance = new String("");
- }
-
- if (jobid == null) {
- throw new IllegalArgumentException("Context jobid");
- }
-
- this.id = id;
- this.source = source;
- this.flag = flag;
- this.host = new CheckedString(host).toString();
- this.user = new CheckedString(user).toString();
- this.prog = new CheckedString(prog).toString();
- this.srcInstance = new CheckedString(srcInstance).toString();
- this.jobid = jobid;
- }
-
- /**
- * Converts Sources enum constants to defined string
- * @param sourceEnum Sources enum constant
- * @return String representation of Sources enum constants
- * @throws IllegalArgumentException if wrong source type is set
- */
- private String recognizeSource(int sourceEnum) {
- switch (sourceEnum) {
- case Sources.EDG_WLL_SOURCE_NONE: return "Undefined";
- case Sources.EDG_WLL_SOURCE_USER_INTERFACE: return "UserInterface";
- case Sources.EDG_WLL_SOURCE_NETWORK_SERVER: return "NetworkServer";
- case Sources.EDG_WLL_SOURCE_WORKLOAD_MANAGER: return "WorkloadManager";
- case Sources.EDG_WLL_SOURCE_BIG_HELPER: return "BigHelper";
- case Sources.EDG_WLL_SOURCE_JOB_SUBMISSION: return "JobController";
- case Sources.EDG_WLL_SOURCE_LOG_MONITOR: return "LogMonitor";
- case Sources.EDG_WLL_SOURCE_LRMS: return "LRMS";
- case Sources.EDG_WLL_SOURCE_APPLICATION: return "Application";
- case Sources.EDG_WLL_SOURCE_LB_SERVER: return "LBServer";
- default: throw new IllegalArgumentException("wrong source type");
- }
- }
-
- /**
- * Abstract method which will serve as method for sending messages with events.
- * @param event event for which will be created and send message
- */
- public abstract void log(Event event);
-
- /**
- * Creates message prepared to send
- * @param event event for which is message generated
- * @throws IllegalArgumentException if event, source, user or job is null
- * or flag < 0
- * @return output String with message
- */
- protected String createMessage(Event event) {
- if (event == null) {
- throw new IllegalArgumentException("Context event");
- }
-
- if (jobid == null) {
- throw new IllegalArgumentException("Context jobid");
- }
-
- if (jobid.getBkserver() == null) {
- throw new IllegalArgumentException("Context Jobid bkserver");
- }
-
- if (jobid.getPort() <= 0 || jobid.getPort() >= 65536) {
- throw new IllegalArgumentException("Context Jobid port");
- }
-
- if (jobid.getUnique() == null) {
- throw new IllegalArgumentException("Context Jobid unique");
- }
-
- if (event == null) {
- throw new IllegalArgumentException("Context event");
- }
-
- if (source <= -1 || source > Sources.EDG_WLL_SOURCE_LB_SERVER) {
- throw new IllegalArgumentException("Context source");
- }
-
- if (flag < 0) {
- throw new IllegalArgumentException("Context flag");
- }
-
- if (host == null || host.equals("")) {
- try {
- host = java.net.InetAddress.getLocalHost().getHostName();
- } catch (UnknownHostException ex) {
- System.err.println(ex);
- }
- }
-
- if (prog == null) {
- prog = new String("edg-wms");
- }
-
- if (user == null) {
- throw new IllegalArgumentException("Context user");
- }
-
- if (srcInstance == null) {
- srcInstance = new String("");
- }
-
- String output;
- String date = "";
- String tmp;
- date = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
- tmp = String.valueOf(Calendar.getInstance().get(Calendar.MONTH) + 1);
- date += "00".substring(0, 2 - tmp.length()) + tmp;
- tmp = String.valueOf(Calendar.getInstance().get(Calendar.DATE));
- date += "00".substring(0, 2 - tmp.length()) + tmp;
- tmp = String.valueOf(Calendar.getInstance().get(Calendar.HOUR));
- date += "00".substring(0, 2 - tmp.length()) + tmp;
- tmp = String.valueOf(Calendar.getInstance().get(Calendar.MINUTE));
- date += "00".substring(0, 2 - tmp.length()) + tmp;
- tmp = String.valueOf(Calendar.getInstance().get(Calendar.SECOND));
- date += "00".substring(0, 2 - tmp.length()) + tmp;
- date += ".";
- tmp = String.valueOf(Calendar.getInstance().get(Calendar.MILLISECOND));
- String tmp2 = "000".substring(0, 3 - tmp.length()) + tmp;
- date += tmp2 + "000000".substring(tmp.length(), 6);
-
- seqCode.incrementSeqCode(source);
-
- output = ("DG.LLLID=" + id +
- " DG.USER=\"" + user + "\"" +
- " DATE=" + date +
- " HOST=\"" + host + "\"" +
- " PROG=" + prog +
- " LVL=SYSTEM" +
- " DG.PRIORITY=0" +
- " DG.SOURCE=\"" + recognizeSource(source) + "\"" +
- " DG.SRC_INSTANCE=\"" + srcInstance + "\"" +
- " DG.EVNT=\"" + event.getEventType() + "\"" +
- " DG.JOBID=\"" + jobid + "\"" +
- " DG.SEQCODE=\"" + seqCode + "\"" +
- event.ulm());
-
- return output;
- }
-
- /**
- * Return flag
- *
- * @return flag
- */
- public int getFlag() {
- return flag;
- }
-
- /**
- * Set flag
- *
- * @param flag
- * @throws java.lang.IllegalArgumentException if flag is lower than 0
- */
- public void setFlag(int flag) {
- if (flag < 0) {
- throw new IllegalArgumentException("Context flag");
- }
-
- this.flag = flag;
- }
-
- /**
- * Returns host name
- *
- * @return host name
- */
- public String getHost() {
- return host;
- }
-
- /**
- * Sets host name
- * @param host host name
- * @throws java.lang.IllegalArgumentException if host is null
- */
- public void setHost(String host) {
- if (host == null) {
- throw new IllegalArgumentException("Context host");
- }
-
- this.host = host;
- }
-
- /**
- * Gets message id.
- *
- * @return message id
- */
- public int getId() {
- return id;
- }
-
- /**
- * Sets message id.
- *
- * @param id message id
- * @throws java.lang.IllegalArgumentException if id is lower than 0
- */
- public void setId(int id) {
- if (id < 0) {
- throw new IllegalArgumentException("Context id");
- }
- this.id = id;
- }
-
- /**
- * Gets jobid.
- *
- * @return jobid
- */
- public Jobid getJobid() {
- return jobid;
- }
-
- /**
- * Sets jobid.
- *
- * @param jobid
- * @throws java.lang.IllegalArgumentException if jobid is null
- */
- public void setJobid(Jobid jobid) {
- if (jobid == null) {
- throw new IllegalArgumentException("Context jobid");
- }
-
- this.jobid = jobid;
- }
-
- /**
- * Gets prog.
- * @return prog
- */
- public String getProg() {
- return prog;
- }
-
- /**
- * Sets prog, if prog is null then is set default value "edg-wms"
- * @param prog
- */
- public void setProg(String prog) {
- if (prog == null) {
- prog = new String("edg-wms");
- }
-
- this.prog = (new CheckedString(prog)).toString();
- }
-
- /**
- * Gets sequence code.
- *
- * @return sequence code
- */
- public SeqCode getSeqCode() {
- return seqCode;
- }
-
- /**
- * Sets sequence code.
- * @param seqCode sequence code
- * @throws java.lang.IllegalArgumentException if seqCode is null
- */
- public void setSeqCode(SeqCode seqCode) {
- if (seqCode == null) {
- throw new IllegalArgumentException("Context seqCode");
- }
-
- this.seqCode = seqCode;
- }
-
- /**
- * Gets source which represents which part of sequence code will be changed
- * @return source
- */
- public int getSource() {
- return source;
- }
-
- /**
- * Sets source which represents which part of sequence code will be changed
- * @param source source
- * @throws java.lang.IllegalArgumentException if source is null
- */
- public void setSource(int source) {
- if (source <= -1 || source > Sources.EDG_WLL_SOURCE_LB_SERVER) {
- throw new IllegalArgumentException("Context source");
- }
-
- this.source = source;
- }
-
- /**
- * Gets srcInstance.
- * @return srcInstance
- */
- public String getSrcInstance() {
- return srcInstance;
- }
-
- /**
- * Sets srcInstace, if srcInstace null then is set "".
- * @param srcInstance srcInstance
- */
- public void setSrcInstance(String srcInstance) {
- if (srcInstance == null) {
- srcInstance = new String("");
- }
-
- this.srcInstance = new CheckedString(srcInstance).toString();
- }
-
- /**
- * Gets user name.
- * @return user name
- */
- public String getUser() {
- return user;
- }
-
- /**
- * Sets user name.
- * @param user user name
- * @throws java.lang.IllegalArgumentException if user is null
- */
- public void setUser(String user) {
- if (user == null) {
- throw new IllegalArgumentException("Context user");
- }
-
- this.user = (new CheckedString(user)).toString();
- }
-}
+++ /dev/null
-package org.glite.lb;
-
-import org.glite.jobid.Jobid;
-
-/**
- * Class which is used to send messages to inter-logger using unix socket.
- *
- * @author Pavel Piskac (173297@mail.muni.cz)
- */
-public class ContextIL extends Context {
-
- private String pathToSocket;
- private String pathToNativeLib;
- private String prefix;
- private int repeatWriteToFile = 5;
- private int connAttempts = 3;
- private int timeout = 3;
- private Boolean useUnixSocket = Boolean.TRUE;
-
- //tutorial http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html
- //native method which is written in C and imported to Java
- native int sendToSocket(String socket_path,
- long filepos,
- String msg,
- int msg_size,
- int conn_attempts,
- int timeout);
-
- /**
- * Creates new instance of ContextIL.
- */
- public ContextIL() {
- }
-
- /**
- * Creates new instance of ContextIL.
- *
- * @param pathToSocket path to unix socket
- * @param prefix path where are stored messages
- */
- public ContextIL(String pathToSocket, String prefix) {
- this.prefix = prefix;
- this.pathToSocket = pathToSocket;
- }
-
- /**
- * Creates new instance of ContextIL.
- *
- * @param id message id, if null, random number is generated
- * @param source one if paramaters of Sources enumeration
- * @param flag
- * @param host host name, if null or "", the name is get from host name of this computer
- * @param user user name
- * @param prog if null then is used "egd-wms"
- * @param srcInstance if null then it is set as ""
- * @param jobid jobid
- * @param path path to unix socket
- * @param prefix path where are stored messages
- * @throws java.lang.IllegalArgumentException if source, user, jobid, prefix
- * or path is null or flag < 0
- */
- public ContextIL(int id,
- int source,
- int flag,
- String host,
- String user,
- String prog,
- String srcInstance,
- Jobid jobid,
- String pathToSocket,
- String prefix) {
-
- super(id, source, flag, host, user, prog, srcInstance, jobid);
-
- if (prefix == null) {
- throw new IllegalArgumentException("ContextIL prefix");
- }
-
- if (pathToSocket == null) {
- throw new IllegalArgumentException("ContextIL path");
- }
-
- this.prefix = prefix;
- this.pathToSocket = pathToSocket;
- }
-
- /**
- * Writes file position and message to specified socket.
- *
- * @param pathToSocket path to unix socket
- * @param fileSize size of the file before new message was written there
- * @param message message which will be send
- * @param conn_attempts count of connection attempts
- * @param time_out connection timeout
- */
- private void writeToSocket(String pathToSocket,
- long fileSize,
- String message) {
-
- if (useUnixSocket.booleanValue()) {
- try {
- System.loadLibrary("glite_lb_sendviasocket");
- message += '\n';
- sendToSocket(pathToSocket,
- fileSize,
- message,
- message.length(),
- connAttempts,
- timeout);
-
- } catch (UnsatisfiedLinkError ex) {
- useUnixSocket = Boolean.FALSE;
- System.err.println(ex);
- }
- }
- }
-
- /**
- * Writes event message to the file and socket.
- *
- * @param event event
- * @throws java.lang.IllegalArgumentException if event, prefix or path
- */
- public void log(Event event) {
- if (event == null) {
- throw new IllegalArgumentException("ContextIL event");
- }
-
- if (prefix == null) {
- throw new IllegalArgumentException("ContextIL prefix");
- }
-
- if (pathToSocket == null || pathToSocket.equals("")) {
- pathToSocket = new String("");
- useUnixSocket = Boolean.FALSE;
- }
-
- if (pathToNativeLib == null || pathToNativeLib.equals("")) {
- pathToNativeLib = new String("");
- useUnixSocket = Boolean.FALSE;
- }
-
- String message = super.createMessage(event);
-
- Long fileLength = ILFileWriter.write(prefix, message, repeatWriteToFile);
-
- writeToSocket(pathToSocket, fileLength.longValue(), message);
- }
-
- /**
- * Gets path to socket.
- *
- * @return pathToSocket to socket
- */
- public String getPathToSocket() {
- return pathToSocket;
- }
-
- /**
- * Sets path to socket.
- *
- * @param pathToSocket path to socket
- * @throws java.lang.IllegalArgumentException if path is null
- */
- public void setPathToSocket(String pathToSocket) {
- if (pathToSocket == null) {
- throw new IllegalArgumentException("ContextIL pathToSocket");
- }
-
- this.pathToSocket = pathToSocket;
- }
-
- /**
- * Gets path to nativelib file which is needed to send messages via unix socket
- *
- * @return pathToNativeLib to native library (libnativelib.so)
- */
- public String getPathToNativeLib() {
- return pathToNativeLib;
- }
-
- /**
- * Sets path to nativelib file which is needed to send messages via unix socket
- * @param pathToNativeLib path to shared library (libnativelib.so)
- */
- public void setPathToNativeLib(String pathToNativeLib) {
- if (pathToNativeLib == null) {
- throw new IllegalArgumentException("ContextIL pathToNativeLib");
- }
-
- this.pathToNativeLib = pathToNativeLib;
- }
-
- /**
- * Gets path where are stored messages.
- *
- * @return path where are stored messages
- */
- public String getPrefix() {
- return prefix;
- }
-
- /**
- * Sets path where are stored messages.
- *
- * @param prefix path where are stored messages
- */
- public void setPrefix(String prefix) {
- if (prefix == null) {
- throw new IllegalArgumentException("ContextIL prefix");
- }
-
- this.prefix = prefix;
- }
-
- /**
- * Gets count of repeated write to file if some exception is thrown.
- *
- * @return count of repeated write to file
- */
- public int getRepeatWriteToFile() {
- return repeatWriteToFile;
- }
-
- /**
- * Sets count of repeated write to file if some exception is thrown.
- *
- * @param repeatWriteToFile count of repeated write to file
- */
- public void setRepeatWriteToFile(int repeatWriteToFile) {
- if (repeatWriteToFile < 1) {
- throw new IllegalArgumentException("ContextIL repeatWriteToFile");
- }
-
- this.repeatWriteToFile = repeatWriteToFile;
- }
-
- /**
- * Gets count of connection attempts which is used while sending the message via unix socket.
- *
- * @return count of connection attempts
- */
- public int getConnAttempts() {
- return connAttempts;
- }
-
- /**
- * Sets count of connection attempts while sending the message via unix socket.
- *
- * @param connAttempts count of connection attempts
- */
- public void setConnAttempts(int connAttempts) {
- if (connAttempts < 1) {
- throw new IllegalArgumentException("ContextIL conn_attempts");
- }
-
- this.connAttempts = connAttempts;
- }
-
- /**
- * Gets timeout which is used while sending the message via unix socket.
- *
- * @return timeout
- */
- public int getTimeout() {
- return timeout;
- }
-
- /**
- * Sets timeout which is used while sending the message via unix socket.
- *
- * @param timeout timeout
- */
- public void setTimeout(int timeout) {
- if (timeout < 1) {
- throw new IllegalArgumentException("ContextIL time_out");
- }
-
- this.timeout = timeout;
- }
-
- public Boolean getUseUnixSocket() {
- return useUnixSocket;
- }
-
- public void setUseUnixSocket(Boolean useUnixSocket) {
- if (useUnixSocket == null) {
- throw new IllegalArgumentException("ContextIL useUnixSocket");
- }
-
- this.useUnixSocket = useUnixSocket;
- }
-}
+++ /dev/null
-package org.glite.lb;
-
-import org.glite.jobid.Jobid;
-
-/**
- * This class provides sending messages using network sockets.
- *
- * @author Pavel Piskac (173297@mail.muni.cz)
- */
-public class ContextLL extends Context {
-
- private String address;
- private int port = 9002;
- private String prefix;
- private int repeatWriteToFile = 5;
- private int timeout = 30000; //in milliseconds
- private String pathToCertificate;
- private SSLSend sslSend = null;
-
- public ContextLL() {
- }
-
- public ContextLL(String address, int port, String prefix) {
- this.prefix = prefix;
- this.address = address;
- this.port = port;
- }
-
- public ContextLL(int id,
- int source,
- int flag,
- String host,
- String user,
- String prog,
- String srcInstance,
- Jobid jobid,
- String address,
- int port,
- String prefix) {
-
- super(id, source, flag, host, user, prog, srcInstance, jobid);
-
- if (prefix == null) {
- throw new IllegalArgumentException("ContextLL prefix");
- }
- if (address == null) {
- throw new IllegalArgumentException("ContextLL socket");
- }
- if (port < 0) {
- throw new IllegalArgumentException("ContextLL port");
- }
-
- this.prefix = prefix;
- this.address = address;
- }
-
- @Override
- public void log(Event event) {
- if (event == null) {
- throw new IllegalArgumentException("ContextLL event");
- }
-
- if (prefix == null) {
- throw new IllegalArgumentException("ContextLL prefix");
- }
-
- if (address == null) {
- throw new IllegalArgumentException("ContextLL socket");
- }
-
- if (port < 0) {
- throw new IllegalArgumentException("ContextLL port");
- }
-
- if (sslSend == null) {
- sslSend = new SSLSend();
- }
-
- String message = super.createMessage(event);
-
- ILFileWriter.write(prefix, message, repeatWriteToFile);
-
-
- sslSend.send(pathToCertificate, address, port, timeout, message);
- }
-
- public String getAddress() {
- return address;
- }
-
- public void setAddress(String address) {
- if (address == null) {
- throw new IllegalArgumentException("ContextLL address");
- }
-
- this.address = address;
- }
-
- public int getPort() {
- return port;
- }
-
- public void setPort(int port) {
- if (port < 0) {
- throw new IllegalArgumentException("ContextLL port");
- }
- this.port = port;
- }
-
-
- public String getPrefix() {
- return prefix;
- }
-
- public void setPrefix(String prefix) {
- if (prefix == null) {
- throw new IllegalArgumentException("ContextLL prefix");
- }
-
- this.prefix = prefix;
- }
-
- public int getRepeatWriteToFile() {
- return repeatWriteToFile;
- }
-
- public void setRepeatWriteToFile(int repeatWriteToFile) {
- if (repeatWriteToFile < 1) {
- throw new IllegalArgumentException("ContextLL repeatWriteToFile");
- }
-
- this.repeatWriteToFile = repeatWriteToFile;
- }
-
- public int getTimeout() {
- return timeout;
- }
-
- public void setTimeout(int timeout) {
- if (timeout < 0) {
- throw new IllegalArgumentException("ContextLL timout");
- }
- this.timeout = timeout;
- }
-
- public String getPathToCertificate() {
- return pathToCertificate;
- }
-
- public void setPathToCertificate(String pathToCertificate) {
- if (pathToCertificate == null) {
- throw new IllegalArgumentException("ContextLL pathToCertificate");
- }
-
- this.pathToCertificate = pathToCertificate;
- }
-
-
-}
+++ /dev/null
-package org.glite.lb;
-
-/**
- * Abstract class which serves as base for all events.
- *
- * @author Pavel Piskac (173297@mail.muni.cz)
- */
-public abstract class Event {
-
- /**
- * When implemented, this method returns string which is specific for each event.
- *
- * @return specific string
- */
- public abstract String ulm();
-
- /**
- * When implemented, this method returns name of event type.
- *
- * @return name of event
- */
- public abstract String getEventType();
-}
+++ /dev/null
-package org.glite.lb;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-
-/**
- * This class provides writing messages to some file.
- *
- * @author Pavel Piskac (173297@mail.muni.cz)
- */
-public class ILFileWriter {
-
- public ILFileWriter() {
- }
-
- /**
- * Writes message to a file and returns size of this file before writing the
- * data
- * @param prefix file path
- * @param message message which will be written
- * @param repeatWriteToFile count of attempts to write to file in case of failure
- */
- public static Long write(String prefix, String message, int repeatWriteToFile) {
- FileWriter fileWriter = null;
- Long fileLength = null;
- RandomAccessFile raf = null;
- FileLock fileLock = null;
- File file;
-
- for (int i = 0; i < repeatWriteToFile; i++) {
- try {
- file = new File(prefix);
- raf = new RandomAccessFile(file, "rw");
- FileChannel fileChannel = raf.getChannel();
-
- fileLock = fileChannel.tryLock();
- if (fileLock != null) {
- if (!file.exists()) {
- continue;
- }
- fileLength = new Long(raf.length());
- fileWriter = new FileWriter(file, true);
- //true means append data at the end of file
-
- BufferedWriter bufferedFileWriter = new BufferedWriter(fileWriter);
-
- bufferedFileWriter.write(message + '\n');
- bufferedFileWriter.flush();
-
- if (file.exists()) {
- break;
- }
- }
- } catch (FileNotFoundException ex) {
- System.err.println(ex);
- } catch (IOException ex) {
- System.err.println(ex);
- } catch (Exception ex) {
- System.err.println(ex);
- } finally {
- if (fileLock != null) {
- try {
- fileLock.release();
- } catch (IOException ex) {
- System.err.println(ex);
- }
- }
-
- try {
- raf.close();
- } catch (IOException ex) {
- System.err.println(ex);
- } catch (NullPointerException ex) {
- System.err.println(ex);
- }
- }
- }
-
- return fileLength;
- }
-}
+++ /dev/null
-package org.glite.lb;
-
-import java.util.Random;
-import org.glite.jobid.Jobid;
-
-/**
- * This class shows how to work with ContextIL.
- *
- * @author Pavel Piskac
- */
-public class ProducerTestIL {
-
- public static void main(String[] args) {
-
- if (args.length != 10) {
- System.out.println("How to use test class:\n" +
- "you have to set 10 arguments in this order, if the choice is optional \"\" or text has to be set:\n" +
- "1. jobid in format \"https://somewhere:port/unique_part\" (required)\n" +
- "2. path to shared library written in c to be able to send messages via unix socket (optional)\n" +
- "3. source, enum constant from class Sources, determines which part of sequence code will be increased (required)\n" +
- "4. flag (required)\n" +
- "5. host name, if it is \"\" then is set name of the computer where is test class running (optional)\n" +
- "6. user name (required)\n" +
- "7. srcInstance (optional)\n" +
- "8. path to directory where will be saved files with events for each job (required)\n" +
- "9. path to unix socket (required if path to shared library is set)\n" +
- "10. description for event in this case event running (required)\n");
- } else {
- /* Create new instance of jobid, you can use other constructors too (see org.glite.jobid.api_java.Jobid.java)
- * Examples:
- * Jobid jobid = new Jobid("https://skurut68-2.cesnet.cz:9000/paja6_test2");
- */
- Jobid jobid = new Jobid(args[0]);
- System.out.println("jobid: " + args[0]);
-
- /* Create sequence code
- * Example:
- * SeqCode seqCode = new SeqCode();
- * Insert sequence number in format
- * UI=XXXXXX:NS=XXXXXXXXXX:WM=XXXXXX:BH=XXXXXXXXXX:JSS=XXXXXX:LM=XXXXXX:LRMS=XXXXXX:APP=XXXXXX:LBS=XXXXXX
- * where X is 0-9, or you can just create new instance of SeqCode where all parts are set to 0
- * Example:
- * SeqCode seqCode = new SeqCode();
- * seqCode.getSeqCodeFromString("UI=000001:NS=0000000002:WM=000003:BH=0000000004:" +
- * "JSS=000005:LM=000006:LRMS=000007:APP=000008:LBS=000009");
- * seqCode.incrementSeqCode(Sources.EDG_WLL_SOURCE_USER_INTERFACE);
- * resulting sequence code will be
- * UI=000002:NS=0000000002:WM=000003:BH=0000000004:JSS=000005:LM=000006:LRMS=000007:APP=000008:LBS=000009
- */
- SeqCode seqCode = new SeqCode();
-
- /* Choose type of sending a log messages (at this time is implemented only ContextIL class)
- * You can choose from some constructors (see org.glite.lb.client_java.ContextIL class)
- */
- ContextIL ctx = new ContextIL();
-
- /* If you chose emtpy ContextIL constructor you have to set some attributes.
- * One of them is pathToNativeLib which sais where java can find shared library written in c.
- * Example: ctx.setPathToNativeLib("/home/paja6/locallogger/build/classes/org/glite/lb/");
- */
- ctx.setPathToNativeLib(args[1]);
- System.out.println("pathToNativeLib: " + args[1]);
-
- /* Id of the message is some random unique number.
- */
- ctx.setId(new Random().nextInt(99999999));
-
- /* Source indicates source of the message, it is constant from org.glite.lb.client_java.Sources class
- * and determines which part of sequence number will be increased.
- * Example: ctx.setSource(Sources.EDG_WLL_SOURCE_LRMS);
- * In this case we have to use method which converts args[2] to Sources. In real environment it will
- * not be used.
- */
- ctx.setSource(new Integer(args[2]));
- System.out.println("source: " + args[2]);
-
- /* Flag
- * Example: ctx.setFlag(0);
- */
- ctx.setFlag(new Integer(args[3]));
- System.out.println("flag: " + args[3]);
-
- /* Name of the computer where is locallogger running
- * Example: ctx.setHost("pelargir.ics.muni.cz");
- */
- ctx.setHost(args[4]);
- System.out.println("host: " + args[4]);
-
- /* Name of the user who owns the job.
- * Example: ctx.setUser("Pavel Piskac");
- */
- ctx.setUser(args[5]);
- System.out.println("user: " + args[5]);
-
- /* TODO co to vlastne znamena?
- * Mostly "" is set
- * Example: ctx.setSrcInstance("");
- */
- ctx.setSrcInstance(args[6]);
- System.out.println("srcInstance: " + args[6]);
-
- /* Set the jobid for the context.
- */
- ctx.setJobid(jobid);
-
- /* Set the jobid for the context.
- */
- ctx.setSeqCode(seqCode);
-
- /* Number of connection attempts while sending the message via unix socket.
- * Default value is 3 but you can change it.
- */
- ctx.setConnAttempts(5);
-
- /* Timeout in seconds for the connection while sending the message via unix socket.
- * Default value is 3 but you can change it.
- */
- ctx.setTimeout(2);
-
- /* Path to directory where will be saved files with logs until inter-logger sends
- * the content.
- * Example: ctx.setPrefix("/home/paja6/tmp/dglog." + jobid.getUnique());
- */
- ctx.setPrefix(args[7]);
- System.out.println("prefix: " + args[7]);
-
- /* Path to unix socket.
- * Example: ctx.setPathToSocket("/home/paja6/tmp/il.sock");
- */
- ctx.setPathToSocket(args[8]);
- System.out.println("pathToSocket: " + args[8]);
-
- /* Create new instance of the event which will be logged.
- */
- EventRunning running = new EventRunning();
-
- /* Set some description for the event.
- * Example: running.setNode("worker node");
- */
- running.setNode(args[9]);
- System.out.println("node: " + args[9]);
-
- /* And now is the context and event prepared to work.
- *
- */
- ctx.log(running);
- }
- }
-}
+++ /dev/null
-package org.glite.lb;
-
-import java.util.Random;
-import org.glite.jobid.Jobid;
-
-/**
- * This class shows how to work with ContextIL.
- *
- * @author Pavel Piskac
- */
-public class ProducerTestLL {
-
- public static void main(String[] args) {
-
- if (args.length != 12) {
- System.out.println("How to use test class:\n" +
- "you have to set 13 arguments in this order, if the choice is optional \"\" or text has to be set:\n" +
- "1. jobid in format \"https://somewhere:port/unique_part\" (required)\n" +
- "2. source, enum constant from class Sources, determines which part of sequence code will be increased (required)\n" +
- "3. flag (required)\n" +
- "4. host name, if it is \"\" then is set name of the computer where is test class running (optional)\n" +
- "5. user name (required)\n" +
- "6. srcInstace (optional)\n" +
- "7. connection timeout (optional)\n" +
- "8. proxy server address (required)\n" +
- "9. proxy server port, default value is 9002 (optional)\n" +
- "10. path to user's certificate (required)\n" +
- "11. path to directory where will be saved files with logs until inter-logger sends the content.");
- } else {
- /* Create new instance of jobid, you can use other constructors too (see org.glite.jobid.api_java.Jobid.java)
- * Examples:
- * Jobid jobid = new Jobid("https://skurut68-2.cesnet.cz:9000/paja6_test2");
- * Jobid jobid = new Jobid("https://skurut68-2.cesnet.cz", 9000, "paja6_test2");
- * Jobid jobid = new Jobid("https://skurut68-2.cesnet.cz", 9000); //unique part is automatically generated
- * Jobid jobid = new Jobid();
- * jobid.setBkserver("https://skurut68-2.cesnet.cz");
- * jobid.setPort(9000);
- * jobid.setUnique("paja6_testProxy3");
- */
- Jobid jobid = new Jobid(args[0]);
- System.out.println("jobid: " + args[0]);
-
- /* Create sequence code
- * Example:
- * SeqCode seqCode = new SeqCode();
- * Insert sequence number in format
- * UI=XXXXXX:NS=XXXXXXXXXX:WM=XXXXXX:BH=XXXXXXXXXX:JSS=XXXXXX:LM=XXXXXX:LRMS=XXXXXX:APP=XXXXXX:LBS=XXXXXX
- * where X is 0-9, or you can just create new instance of SeqCode where all parts are set to 0
- * Example:
- * SeqCode seqCode = new SeqCode();
- * seqCode.getSeqCodeFromString("UI=000001:NS=0000000002:WM=000003:BH=0000000004:" +
- * "JSS=000005:LM=000006:LRMS=000007:APP=000008:LBS=000009");
- * seqCode.incrementSeqCode(Sources.USER_INTERFACE);
- * resulting sequence code will be
- * UI=000002:NS=0000000002:WM=000003:BH=0000000004:JSS=000005:LM=000006:LRMS=000007:APP=000008:LBS=000009
- */
- SeqCode seqCode = new SeqCode();
-
- /* Choose type of sending a log messages (at this time is implemented only ContextIL class)
- * You can choose from some constructors (see org.glite.lb.client_java.ContextIL class)
- */
- ContextLL ctx = new ContextLL();
-
- /* Id of the message is some random unique number.
- * This value will be ceplaced by value from proxy.
- */
- ctx.setId(new Random().nextInt(99999999));
-
- /* Source indicates source of the message, it is constant from org.glite.lb.client_java.Sources class
- * and determines which part of sequence number will be increased.
- * Example: ctx.setSource(Sources.EDG_WLL_SOURCE_LRMS);
- * In this case we have to use method which converts args[2] to Sources. In real environment it will
- * not be used.
- */
- ctx.setSource(new Integer(args[1]));
- System.out.println("source: " + args[1]);
-
- /* Flag.
- * Example: ctx.setFlag(0);
- */
- ctx.setFlag(new Integer(args[2]));
- System.out.println("flag: " + args[2]);
-
- /* Name of the computer where is locallogger running
- * Example: ctx.setHost("pelargir.ics.muni.cz");
- */
- ctx.setHost(args[3]);
- System.out.println("host: " + args[3]);
-
- /* Name of the user who owns the job, this attribute will be replaced
- * by value get from certificate.
- * Example: ctx.setUser("Pavel Piskac");
- */
- ctx.setUser(args[4]);
- System.out.println("user: " + args[4]);
-
- /* TODO co to vlastne znamena?
- * Mostly "" is set
- * Example: ctx.setSrcInstance("");
- */
- ctx.setSrcInstance(args[5]);
- System.out.println("srcInstance: " + args[5]);
-
- /* Set the jobid for the context.
- */
- ctx.setJobid(jobid);
-
- /* Set the jobid for the context.
- */
- ctx.setSeqCode(seqCode);
-
- /* Timeout in seconds for the connection while sending the message via unix socket.
- * Default value is 3 but you can change it.
- */
- ctx.setTimeout(new Integer(args[6]));
- System.out.println("timeout: " + args[6]);
-
- /* Address to proxy.
- * Example:
- * ctx.setAddress("147.251.3.62");
- */
- ctx.setAddress(args[7]);
- System.out.println("address: " + args[7]);
-
- /* Proxy server port.
- * Example:
- * ctx.setPort(9002);
- */
- ctx.setPort(new Integer(args[8]));
- System.out.println("port: " + args[8]);
-
- /* Path to user's certificate. Only *.ks and *.p12 certificates are allowed.
- * Example:
- * ctx.setPathToCertificate("/home/paja6/myCertificate.p12");
- */
- ctx.setPathToCertificate(args[9]);
- System.out.println("pathToCertificate: " + args[9]);
-
- /* Path to directory where will be saved files with logs until inter-logger sends
- * the content.
- * Example: ctx.setPrefix("/home/paja6/tmp/dglog." + jobid.getUnique());
- */
- ctx.setPrefix(args[10]);
- System.out.println("prefix: " + args[10]);
-
- /* Create new instance of the event which will be logged.
- */
- EventRunning running = new EventRunning();
-
- /* Set some description for the event.
- * Example: running.setNode("worker node");
- */
- running.setNode(args[11]);
- System.out.println("node: " + args[11]);
-
- /* And now is the context and event prepared to work.
- *
- */
- ctx.log(running);
- }
- }
-}
+++ /dev/null
-package org.glite.lb;
-
-import javax.net.ssl.*;
-import java.net.SocketException;
-import java.io.*;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.security.*;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.util.Enumeration;
-import org.globus.cog.security.cert.request.BouncyCastleOpenSSLKey;
-import org.globus.gsi.GlobusCredential;
-import org.globus.gsi.GlobusCredentialException;
-import org.gridforum.jgss.ExtendedGSSCredential;
-import org.gridforum.jgss.ExtendedGSSManager;
-import org.ietf.jgss.GSSCredential;
-import org.ietf.jgss.GSSException;
-
-public class SSL {
-
- static final String proxyProp = "X509UserProxy";
-
- /**
- * Implementation of abstract class X509KeyManager.
- * It is used to manage X509 certificates which are used to authenticate
- * the local side of a secure socket.
- */
- static class MyX509KeyManager implements X509KeyManager {
-
- private X509Certificate[] certchain;
- private PrivateKey key;
-
- public MyX509KeyManager(Certificate[] cchain, PrivateKey key) {
- this.certchain = new X509Certificate[cchain.length];
- System.arraycopy(cchain, 0, this.certchain, 0, cchain.length);
- this.key = key;
- }
-
- public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket
-socket) {
-/*
- System.out.println("MyX509KeyManager.chooseClientAlias()");
- for (int i = 0; i < keyType.length; i++) {
- System.out.println("MyX509KeyManager.chooseClientAlias() keyType[" + i +
-"]=" + keyType[i]);
- }
- for (int i = 0; i < issuers.length; i++) {
- System.out.println("MyX509KeyManager.chooseClientAlias() issuers[" + i +
-"]=" + issuers[i]);
- }
-*/
- return "";
- }
-
- public String chooseServerAlias(String keyType, Principal[] issuers, Socket
-socket) {
-/*
- System.out.println("MyX509KeyManager.chooseServerAlias(" + keyType + ")");
-
- if (issuers != null) for (int i=0; i<issuers.length; i++)
- System.out.println(" " + issuers[i]);
-*/
-
- return "";
- }
-
- public X509Certificate[] getCertificateChain(String alias) {
-// System.out.println("MyX509KeyManager.getCertificateChain(" + alias + ")");
- return certchain;
- }
-
- public String[] getClientAliases(String keyType, Principal[] issuers) {
-// System.out.println("MyX509KeyManager.getClientAliases(" + keyType + ")");
- return null;
- }
-
- public PrivateKey getPrivateKey(String alias) {
-// System.out.println("MyX509KeyManager.getPrivateKey(" + alias + ")");
- return key;
- }
-
- public String[] getServerAliases(String keyType, Principal[] issuers) {
-// System.out.println("MyX509KeyManager.getServerAliases(" + keyType + ")");
- return null;
- }
- }
-
- /**
- * Implementation of abstract class X509TrustManager.
- * It is used to authenticate the remote side of a secure socket.
- */
- static class MyX509TrustManager implements X509TrustManager {
-
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
-
- public void checkClientTrusted(X509Certificate[] certs, String authType) {
- //System.out.println("X509TrustManager.checkClientTrusted(certs["+certs.length+"],"+authType+")");
- }
-
- public void checkServerTrusted(X509Certificate[] certs, String authType) throws
- CertificateException {
- //System.out.println("----X509TrustManager.checkServerTrusted-----");
- //System.out.println("number of certs: "+certs.length+", authType="+authType);
- //for(int i=0;i<certs.length;i++) {
- // System.out.println("cert["+i+"]="+certs[i].getSubjectDN());
- //}
- //System.out.println("--------------------------------------------");
- }
- }
-
- SSLContext sctx;
- SSLSocket client;
- SSLServerSocket server;
- SSLSession sess;
- String proxy;
-
- void init_ctx() throws KeyStoreException,NoSuchAlgorithmException,KeyManagementException {
- if (sctx == null) {
-
- if (proxy == null) proxy = System.getProperty(proxyProp);
-
- TrustManager[] trustAllCerts = new TrustManager[]{new MyX509TrustManager()};
- X509KeyManager[] myKeyManager = createX509KeyManager(proxy);
-
- if (myKeyManager == null) {
- throw new NullPointerException("myKeyManager is null");
- }
-
- sctx = SSLContext.getInstance("SSLv3");
- sctx.init(myKeyManager, trustAllCerts, null);
- }
- }
-
- public void setProxy(String p) {
- proxy = p;
- }
-
- public Socket connect(String host,int port,int timeout) throws KeyStoreException,NoSuchAlgorithmException,KeyManagementException,SocketException,IOException {
-
- init_ctx();
-
- client = (SSLSocket) sctx.getSocketFactory().createSocket();
-
- client.setEnabledProtocols(new String[]{"SSLv3"});
- client.setUseClientMode(true);
- client.setSoTimeout(timeout); //read timeout
-
- client.connect(new InetSocketAddress(host, port), timeout); //connect timeout
- client.startHandshake();
-
- sess = client.getSession();
- if (sess == null) {
- throw new NullPointerException("null session");
- }
-
- return client;
- //return new PrintStream(client.getOutputStream(),false);
- }
-
- public Socket accept(int port,int timeout)
- throws KeyStoreException,IOException,SocketException,NoSuchAlgorithmException,KeyManagementException
- {
-
- init_ctx();
-
- server = (SSLServerSocket) sctx.getServerSocketFactory().createServerSocket();
-
- server.setEnabledProtocols(new String[]{"SSLv3"});
- server.setSoTimeout(timeout);
-
- server.bind(new InetSocketAddress(port));
-
- SSLSocket conn = (SSLSocket) server.accept();
-
- return conn;
- }
-
- public void close() throws IOException,SocketException {
- client.close();
- }
-
- /**
- * This methods reads user's certificate
- *
- * @param ksfile path to certificate
- * @return instance of KeyStore with certificate
- * @throws java.security.KeyStoreException
- * @throws java.security.cert.CertificateException
- * @throws java.security.NoSuchAlgorithmException
- * @throws java.io.IOException
- */
- X509KeyManager[] createX509KeyManager(String ksfile) throws KeyStoreException {
-
- if (ksfile.endsWith(".pem") || !ksfile.contains(".")) {
- return readPEM(ksfile);
- }
-
- throw new KeyStoreException("Unknown key store");
- }
-
- X509KeyManager[] readPEM(String ksfile) {
- BufferedReader br = null;
- BufferedInputStream pemFile = null;
- ByteArrayInputStream bais = null;
-
- X509KeyManager[] myX509KeyManager = null;
-
- try {
- // read in the credential data
- File f = new File(ksfile);
- pemFile = new BufferedInputStream(new FileInputStream(f));
- byte [] data = new byte[(int)f.length()];
- pemFile.read(data);
-
- GlobusCredential gc = new GlobusCredential(ksfile);
- Certificate[] cert = gc.getCertificateChain();
-
- PrivateKey privateKey = gc.getPrivateKey();
- myX509KeyManager = new X509KeyManager[]{new MyX509KeyManager(cert, privateKey)};
- } catch (IOException ex) {
- System.err.println(ex);
- } catch (GlobusCredentialException ex) {
- System.err.println(ex);
- } finally {
- try {
- pemFile.close();
- } catch (IOException ex) {
- System.err.println(ex);
- }
- }
-
- return myX509KeyManager;
- }
-}
+++ /dev/null
-package org.glite.lb;
-
-import java.io.IOException;
-import java.io.PrintStream;
-import java.security.*;
-import java.net.Socket;
-
-/**
- * This class opens secure connection using SSLv3 and then sends message to set
- * address.
- *
- * @author Pavel Piskac
- */
-public class SSLSend {
-
- private static final String EDG_WLL_LOG_SOCKET_HEADER = "DGLOG";
-
- /**
- * This method is used to send messages using a secure socket.
- *
- * @param keyStoreSender path to user's certificate
- * @param host host name
- * @param port port number
- * @param timeout connection timeout
- * @param message message which will be send
- */
- public void send(String keyStoreSender, String host,
- int port, int timeout, String message)
- throws KeyStoreException,IOException,NoSuchAlgorithmException,KeyManagementException
- {
-
- SSL lbsock = new SSL();
-
- lbsock.setProxy(keyStoreSender);
- Socket sock = lbsock.connect(host,port,timeout);
- PrintStream s = new PrintStream(sock.getOutputStream(),false);
-
- s.print(EDG_WLL_LOG_SOCKET_HEADER);
-
- message = message.replaceFirst("DG.LLLID=[0-9]* ", "");
- message = message.replaceFirst("DG.USER=\\x22[a-zA-Z ]*\\x22 ", "");
-
- int messageSize = message.length() + 2;
- byte revertedInt[] = new byte[4];
- revertedInt[0] = (byte) (messageSize % 256);
- messageSize >>= 8;
- revertedInt[1] = (byte) (messageSize % 256);
- messageSize >>= 8;
- revertedInt[2] = (byte) (messageSize % 256);
- messageSize >>= 8;
- revertedInt[3] = (byte) (messageSize);
-
- s.write(revertedInt,0,4);
- s.print(message + '\n' + '\0');
- s.flush();
- s.close();
- }
-
-}
+++ /dev/null
-package org.glite.lb;
-
-/**
- * This class represents sequence code.
- *
- * @author Pavel Piskac (173297@mail.muni.cz)
- * @version 9. 4. 2008
- */
-public class SeqCode {
-
- private int[] seqCode = {0, 0, 0, 0, 0, 0, 0, 0, 0};
-
- /**
- * Empty constructor which creates new instance of SeqCode with all values
- * equal 0
- */
- public SeqCode() {
- }
-
- /**
- * Constructor which creates new instance of SeqCode with values set by user
- * in input attribute
- *
- * @param seqCodeString
- */
- public SeqCode(String seqCodeString) {
- getSeqCodeFromString(seqCodeString);
- }
-
- /**
- * This method increments one specific part of sequence code given by part attribute
- *
- * @param part part of sequence number which will be increased
- */
- public void incrementSeqCode(int part) {
- if (part <= -1 || part >= Sources.EDG_WLL_SOURCE_LB_SERVER) {
- throw new IllegalArgumentException("SeqCode part");
- }
-
- seqCode[part-1]++;
- }
-
- /**
- * Converts string representation of sequence code to format which is used
- * in this class.
- * Insert sequence codes in format:
- * UI=000000:NS=0000000000:WM=000000:BH=0000000000:JSS=000000:LM=000000:LRMS=000000:APP=000000:LBS=000000
- * @param seqCodeString
- */
- public void getSeqCodeFromString(String seqCodeString) {
-
- if (!seqCodeString.matches("UI=\\d{1,}:NS=\\d{1,}:WM=\\d{1,}:BH=\\d{1,}:" +
- "JSS=\\d{1,}:LM=\\d{1,}:LRMS=\\d{1,}:APP=\\d{1,}:LBS=\\d{1,}")) {
- throw new IllegalArgumentException("this is not correct sequence code");
- }
-
- int currentPosition = 0;
- int equalsPosition = 0;
- int colonPosition = 0;
- for (int i = 0; i <= 8; i++) {
- equalsPosition = seqCodeString.indexOf('=', currentPosition);
- if (i == 8) {
- colonPosition = seqCodeString.length();
- } else {
- colonPosition = seqCodeString.indexOf(':', currentPosition);
- }
- seqCode[i] = (new Integer(seqCodeString.substring(equalsPosition+1, colonPosition))).intValue();
- currentPosition = colonPosition + 1;
- }
-
- }
-
- public String toString() {
- String tmp = Integer.toString(seqCode[0]);
- String output = "UI=";
- output += "000000".substring(0, 6 - tmp.length ()) + tmp;
- output += ":";
- output += "NS=";
- tmp = Integer.toString(seqCode[1]);
- output += "0000000000".substring(0, 10 - tmp.length ()) + tmp;
- output += ":";
- output += "WM=";
- tmp = Integer.toString(seqCode[2]);
- output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
- output += ":";
- output += "BH=";
- tmp = Integer.toString(seqCode[3]);
- output += "0000000000".substring(0, 10 - tmp.length ()) + tmp;
- output += ":";
- output += "JSS=";
- tmp = Integer.toString(seqCode[4]);
- output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
- output += ":";
- output += "LM=";
- tmp = Integer.toString(seqCode[5]);
- output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
- output += ":";
- output += "LMRS=";
- tmp = Integer.toString(seqCode[6]);
- output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
- output += ":";
- output += "APP=";
- tmp = Integer.toString(seqCode[7]);
- output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
- output += ":";
- output += "LBS=";
- tmp = Integer.toString(seqCode[8]);
- output += "0000000000".substring(0, 6 - tmp.length ()) + tmp;
- return output;
- }
-}
+++ /dev/null
-package org.glite.lb;
-
-/**
- * Enum which represents type if sources.
- *
- * @author Pavel Piskac (173297@mail.muni.cz)
- */
-public class Sources {
- public static final int EDG_WLL_SOURCE_NONE = 0; /* uninitialized value */
- public static final int EDG_WLL_SOURCE_USER_INTERFACE = 1;
- public static final int EDG_WLL_SOURCE_NETWORK_SERVER = 2;
- public static final int EDG_WLL_SOURCE_WORKLOAD_MANAGER = 3;
- public static final int EDG_WLL_SOURCE_BIG_HELPER = 4;
- public static final int EDG_WLL_SOURCE_JOB_SUBMISSION = 5;
- public static final int EDG_WLL_SOURCE_LOG_MONITOR = 6;
- public static final int EDG_WLL_SOURCE_LRMS = 7;
- public static final int EDG_WLL_SOURCE_APPLICATION = 8;
- public static final int EDG_WLL_SOURCE_LB_SERVER = 9;
-
- public int source;
-
- public Sources() {
- this.source = 0;
- }
-
- public Sources(int source) {
- this.source = source;
- }
-}
+++ /dev/null
-CC=gcc
-PREFIX=${HOME}/tmp
-PATH_TO_JAVA=${JAVA_HOME}
-
-LIB=libglite_lb_sendviasocket.la
-OBJ=send_via_socket.lo
-
-compile: ${LIB}
-
-${LIB}: ${OBJ}
- libtool --mode=link ${CC} -rpath ${PREFIX}/lib -o $@ ${OBJ}
-
-%.lo: %.c
- libtool --mode=compile ${CC} -I${PATH_TO_JAVA}/include -I${PATH_TO_JAVA}/include/linux -c $<
-
-install: compile
- -mkdir -p ${PREFIX}/lib
- libtool --mode=install install -m 755 ${LIB} ${PREFIX}/lib
+++ /dev/null
-#include <jni.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <pwd.h>
-#include <sys/un.h>
-#include <stdio.h>
-#include <math.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
-
-/**
- *----------------------------------------------------------------------
- * Open a GSS connection to local-logger, send already formatted ULM string
- * and get answer back from local-logger
- * \brief connect to local-logger, send message and get answer back
- * \param[in,out] ctx context to work with,
- * \param[in] logline formated ULM string
- *----------------------------------------------------------------------
- */
-int edg_wll_DoLogEvent(
- edg_wll_Context ctx,
- edg_wll_LogLine logline)
-{
- int ret = 0, answer = EAGAIN;
- int conn;
-
- edg_wll_ResetError(ctx);
- memset(&conn,0,sizeof(conn));
-
- /* connect to local-logger */
- if ((ret = edg_wll_log_connect(ctx,&conn))) {
- fprintf(stderr, "edg_wll_log_connect error");
- goto edg_wll_DoLogEvent_end;
- }
-
- /* send message */
- if ((ret = edg_wll_log_write(ctx,conn,logline)) == -1) {
- fprintf(stderr, "edg_wll_log_write error");
- goto edg_wll_DoLogEvent_end;
- }
-
- /* get answer */
- if ((ret = edg_wll_log_read(ctx,conn)) == -1) {
- fprintf(stderr, "edg_wll_log_read error");
- } else {
- answer = edg_wll_Error(ctx, NULL, NULL);
- }
-
-edg_wll_DoLogEvent_end:
- if (ret) edg_wll_log_close(ctx,conn);
-
- return 0;
-}
-
-/**
- *----------------------------------------------------------------------
- * connect to locallogger
- *----------------------------------------------------------------------
- */
-int edg_wll_log_connect(edg_wll_Context ctx, int *conn)
-{
- int ret, answer=0, index;
- char *my_subject_name = NULL;
- edg_wll_GssStatus gss_stat;
-
- //edg_wll_ResetError(ctx);
- //edg_wll_poolLock();
-
- /* check if connection already in pool */
- if ( (index = ConnectionIndex(ctx, ctx->p_destination, ctx->p_dest_port)) == -1 ) {
- if (ctx->connections->connOpened == ctx->connections->poolSize)
- if (ReleaseConnection(ctx, NULL, 0))
- goto edg_wll_log_connect_end;
- index = AddConnection(ctx, ctx->p_destination, ctx->p_dest_port);
- if (index < 0) {
- edg_wll_SetError(ctx,EAGAIN,"connection pool size exceeded");
- goto edg_wll_log_connect_end;
- }
-#if 0
- /* acquire gss credentials */
- ret = edg_wll_gss_acquire_cred_gsi(
- ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename,
- ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_key_filename,
- &ctx->connections->connPool[index].gsiCred, &my_subject_name, &gss_stat);
- /* give up if unable to acquire prescribed credentials, otherwise go on anonymously */
- if (ret && ctx->p_proxy_filename) {
- edg_wll_SetErrorGss(ctx, "edg_wll_gss_acquire_cred_gsi(): failed to load GSI credentials", &gss_stat);
- goto edg_wll_log_connect_err;
- }
- /* gss_connect */
- if (ctx->connections->connPool[index].gss.context == GSS_C_NO_CONTEXT) {
-
- /* acquire gss credentials */
- ret = edg_wll_gss_acquire_cred_gsi(
- ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename,
- ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_key_filename,
- &ctx->connections->connPool[index].gsiCred, &my_subject_name, &gss_stat);
- /* give up if unable to acquire prescribed credentials, otherwise go on anonymously */
- if (ret && ctx->p_proxy_filename) {
- edg_wll_SetErrorGss(ctx, "edg_wll_gss_acquire_cred_gsi(): failed to load GSI credentials", &gss_stat);
- goto edg_wll_log_connect_err;
- }
- if ((answer = edg_wll_gss_connect(
- ctx->connections->connPool[index].gsiCred,
- ctx->connections->connPool[index].peerName,
- ctx->connections->connPool[index].peerPort,
- &ctx->p_tmp_timeout,
- &ctx->connections->connPool[index].gss,
- &gss_stat)) < 0) {
- answer = handle_gss_failures(ctx,answer,&gss_stat,"edg_wll_gss_connect()");
- goto edg_wll_log_connect_err;
- }
- goto edg_wll_log_connect_end;
- } else goto edg_wll_log_connect_end;
-
-edg_wll_log_connect_err:
- if (index >= 0) CloseConnection(ctx, &index);
- index = -1;
-
-edg_wll_log_connect_end:
- if (index >= 0) edg_wll_connectionTryLock(ctx, index);
- if (my_subject_name) free(my_subject_name);
-
- edg_wll_poolUnlock();
-
- *conn = index;
- return answer;
-}
-
-/**
- *----------------------------------------------------------------------
- * close connection to locallogger
- *----------------------------------------------------------------------
- */
-int edg_wll_log_close(edg_wll_Context ctx, int conn)
-{
- int ret = 0;
-
- if (conn == -1) return 0;
- ret = CloseConnection(ctx,&conn);
- edg_wll_connectionUnlock(ctx,conn);
- return ret;
-}
-
-/**
- *----------------------------------------------------------------------
- * write/send to locallogger
- *----------------------------------------------------------------------
- */
-int edg_wll_log_write(edg_wll_Context ctx, int conn, edg_wll_LogLine logline)
-{
- char header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH+1];
- int err;
- int answer;
- size_t count,sent;
- int size;
- u_int8_t size_end[4];
- edg_wll_GssStatus gss_code;
-
- errno = err = answer = count = sent = 0;
- size = strlen(logline)+1;
- size_end[0] = size & 0xff; size >>= 8;
- size_end[1] = size & 0xff; size >>= 8;
- size_end[2] = size & 0xff; size >>= 8;
- size_end[3] = size;
- size = strlen(logline)+1;
-
- edg_wll_ResetError(ctx);
-
- sprintf(header,"%s",EDG_WLL_LOG_SOCKET_HEADER);
- header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH]='\0';
- if ((err = edg_wll_gss_write_full(&ctx->connections->connPool[conn].gss, header, EDG_WLL_LOG_SOCKET_HEADER_LENGTH, &ctx->p_tmp_timeout, &count, &gss_code)) < 0) {
- switch (answer = handle_gss_failures(ctx,err,&gss_code,"edg_wll_gss_write_full()")) {
- case ENOTCONN:
- edg_wll_log_close(ctx,conn);
- if (edg_wll_log_connect(ctx,&conn) ||
- edg_wll_gss_write_full(&ctx->connections->connPool[conn].gss, header, EDG_WLL_LOG_SOCKET_HEADER_LENGTH, &ctx->p_tmp_timeout, &count, &gss_code) < 0) {
- edg_wll_UpdateError(ctx,answer,"edg_wll_log_write(): error sending header");
- return -1;
- }
- break;
- case 0:
- break;
- default:
- edg_wll_UpdateError(ctx,answer,"edg_wll_log_write(): error sending header");
- return -1;
- }
- }
- sent += count;
-
- count = 0;
- if ((err = edg_wll_gss_write_full(&ctx->connections->connPool[conn].gss, size_end, 4, &ctx->p_tmp_timeout, &count, &gss_code)) < 0) {
- switch (answer = handle_gss_failures(ctx,err,&gss_code,"edg_wll_gss_write_full()")) {
- case ENOTCONN:
- edg_wll_log_close(ctx,conn);
- if (edg_wll_log_connect(ctx,&conn) ||
- edg_wll_gss_write_full(&ctx->connections->connPool[conn].gss, size_end, 4, &ctx->p_tmp_timeout, &count, &gss_code) < 0) {
- edg_wll_UpdateError(ctx,answer,"edg_wll_log_write(): error sending message size");
- return -1;
- }
- break;
- case 0:
- break;
- default:
- edg_wll_UpdateError(ctx,answer,"edg_wll_log_write(): error sending message size");
- return -1;
-
- }
- }
- sent += count;
-
- count = 0;
- if (( err = edg_wll_gss_write_full(&ctx->connections->connPool[conn].gss, logline, size, &ctx->p_tmp_timeout, &count, &gss_code)) < 0) {
- switch (answer = handle_gss_failures(ctx,err,&gss_code,"edg_wll_gss_write_full()")) {
- case ENOTCONN:
- edg_wll_log_close(ctx,conn);
- if (edg_wll_log_connect(ctx,&conn) ||
- edg_wll_gss_write_full(&ctx->connections->connPool[conn].gss, logline, size, &ctx->p_tmp_timeout, &count, &gss_code) < 0) {
- edg_wll_UpdateError(ctx,answer,"edg_wll_log_write(): error sending message");
- return -1;
- }
- break;
- case 0:
- break;
- default:
- edg_wll_UpdateError(ctx,answer,"edg_wll_log_write(): error sending message");
- return -1;
- }
- }
- sent += count;
-
- return sent;
-}
-
-/**
- *----------------------------------------------------------------------
- * read/receive from locallogger
- *----------------------------------------------------------------------
- */
-int edg_wll_log_read(edg_wll_Context ctx, int conn)
-{
- int err;
- int answer;
- u_int8_t answer_end[4];
- size_t count;
- edg_wll_GssStatus gss_code;
-
- errno = err = answer = count = 0;
-
- edg_wll_ResetError(ctx);
-
- count = 0;
- if ((err = edg_wll_gss_read_full(&ctx->connections->connPool[conn].gss, answer_end, 4, &ctx->p_tmp_timeout, &count, &gss_code)) < 0 ) {
- switch (answer = handle_gss_failures(ctx,err,&gss_code,"edg_wll_gss_read_full()")) {
- case ENOTCONN:
- edg_wll_log_close(ctx,conn);
- if (edg_wll_log_connect(ctx,&conn) ||
- edg_wll_gss_read_full(&ctx->connections->connPool[conn].gss, answer_end, 4, &ctx->p_tmp_timeout, &count, &gss_code) < 0 ) {
- edg_wll_UpdateError(ctx,answer,"edg_wll_log_read(): error reading answer from local-logger");
- return -1;
- }
- break;
- case 0:
- break;
- default:
- edg_wll_UpdateError(ctx,answer,"edg_wll_log_read(): error reading answer from local-logger");
- return -1;
- }
- }
- answer = answer_end[3]; answer <<=8;
- answer |= answer_end[2]; answer <<=8;
- answer |= answer_end[1]; answer <<=8;
- answer |= answer_end[0];
- edg_wll_SetError(ctx,answer,"edg_wll_log_read(): answer read from locallogger");
-
- return count;
-}
+++ /dev/null
-#include <jni.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <pwd.h>
-#include <sys/un.h>
-#include <stdio.h>
-#include <math.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
-
-#define tv_sub(a, b) {\
- (a).tv_usec -= (b).tv_usec;\
- (a).tv_sec -= (b).tv_sec;\
- if ((a).tv_usec < 0) {\
- (a).tv_sec--;\
- (a).tv_usec += 1000000;\
- }\
-}
-
-
-/*!
- * Write to socket
- * Needn't write entire buffer. Timeout is applicable only for non-blocking
- * connections
- * \param sock IN: connection to work with
- * \param buf IN: buffer
- * \param bufsize IN: max size to write
- * \param timeout INOUT: max time allowed for operation, remaining time on return
- * \retval bytes written (>0) on success
- * \retval -1 on write error
- */
-static ssize_t
-edg_wll_socket_write(
- int sock,
- const void *buf,
- size_t bufsize,
- struct timeval *timeout)
-{
- ssize_t len = 0;
- fd_set fds;
- struct timeval to, before, after;
-
-
- if ( timeout ) {
- memcpy(&to, timeout, sizeof to);
- gettimeofday(&before, NULL);
- }
- len = write(sock, buf, bufsize);
- if ( len <= 0 && errno == EAGAIN ) {
- FD_ZERO(&fds);
- FD_SET(sock,&fds);
- if ( select(sock+1, NULL, &fds, NULL, timeout? &to: NULL) < 0 ) {
- len = -1;
- } else {
- len = write(sock, buf, bufsize);
- }
- }
- if ( timeout ) {
- gettimeofday(&after, NULL);
- tv_sub(after, before);
- tv_sub(*timeout, after);
- if ( timeout->tv_sec < 0 ) {
- timeout->tv_sec = 0;
- timeout->tv_usec = 0;
- }
- }
-
- return len;
-}
-
-/*!
- * Write specified amount of data to socket
- * Attempts to call edg_wll_socket_write() untill the entire request is satisfied
- * (or times out).
- * \param sock IN: connection to work with
- * \param buf IN: buffer
- * \param bufsize IN: max size to write
- * \param timeout INOUT: max time allowed for operation, remaining time on return
- * \param total OUT: bytes actually written
- * \retval bytes written (>0) on success
- * \retval -1 on write error
- */
-static ssize_t
-edg_wll_socket_write_full(
- int sock,
- void *buf,
- size_t bufsize,
- struct timeval *timeout,
- ssize_t *total)
-{
- ssize_t len;
- *total = 0;
-
- while ( *total < bufsize ) {
- len = edg_wll_socket_write(sock, buf+*total, bufsize-*total, timeout);
- if (len < 0) return len;
- *total += len;
- }
-
- return 0;
-}
-
-/*
- * edg_wll_log_event_send - send event to the socket
- *
- * Returns: 0 if done properly or errno
- *
- */
-/*int edg_wll_log_event_send(
- const char *socket_path,
- long filepos,
- const char *msg,
- int msg_size,
- int conn_attempts,
- int timeout_int)*/
-/*JNIEXPORT jint JNICALL Java_org_glite_lb_ContextIL_edg_wll_log_event_send
- (JNIEnv *env,
- jobject jobj,
- jstring socket_path_j,
- jlong filepos_j,
- jstring msg_j,
- jint msg_size_j,
- jint conn_attempts_j,
- jint timeout_int_j)*/
-JNIEXPORT jint JNICALL Java_org_glite_lb_client_1java_ContextIL_sendToSocket
- (JNIEnv *env,
- jobject jobj,
- jstring socket_path_j,
- jlong filepos_j,
- jstring msg_j,
- jint msg_size_j,
- jint conn_attempts_j,
- jint timeout_int_j)
-
-{
- const char *socket_path = (*env)->GetStringUTFChars(env, socket_path_j, 0);
- const char *msg = (*env)->GetStringUTFChars(env, msg_j, 0);
- int timeout_int = (int) timeout_int_j;
- //int timeout_int = 3;
- long filepos = (long) filepos_j;
- int msg_size = (int) msg_size_j;
- int conn_attempts = (int) conn_attempts_j;
- //int conn_attempts = 3;
- struct timeval timeout;
- timeout.tv_sec = timeout_int;
- timeout.tv_usec = 0;
- struct sockaddr_un saddr;
- int msg_sock,
- flags,
- conn_timeout, i;
- ssize_t count = 0;
-
-
- if ( (msg_sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 ) {
- goto event_send_end;
- }
-
- memset(&saddr, 0, sizeof(saddr));
- saddr.sun_family = AF_UNIX;
- strcpy(saddr.sun_path, socket_path);
-
- if ( (flags = fcntl(msg_sock, F_GETFL, 0)) < 0
- || fcntl(msg_sock, F_SETFL, flags | O_NONBLOCK) < 0 ) {
- goto cleanup;
- }
-
- conn_timeout = floor(timeout.tv_sec/(conn_attempts + 1));
- for ( i = 0; i < conn_attempts; i++) {
- if ( connect(msg_sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0 ) {
- if ( errno == EISCONN ) break;
- else if ((errno == EAGAIN) || (errno == ETIMEDOUT)) {
- sleep(conn_timeout);
- timeout.tv_sec -= conn_timeout;
- continue;
- } else {
- goto cleanup;
- }
- } else break;
- }
-
- if ( edg_wll_socket_write_full(msg_sock, &filepos, sizeof(filepos), &timeout, &count) < 0
-) {
- goto cleanup;
- }
-
- if ( edg_wll_socket_write_full(msg_sock, (void *)msg, msg_size,
-&timeout, &count) < 0 ) {
- goto cleanup;
- }
-
-cleanup:
- close(msg_sock);
-
-event_send_end:
- return 0;
-}
+++ /dev/null
-top_srcdir=..
-stagedir=.
-package=glite-lb-harvester
-module.version=0.0.0
-PREFIX=/opt/glite
-globus_prefix=/opt/globus
-
-archlib:=lib
-thrflavour:=gcc32dbgpthr
-host_cpu:=${shell uname -m}
-ifeq (${host_cpu},x86_64)
- archlib:=lib64
- thrflavour:=gcc64dbgpthr
-endif
-
--include Makefile.inc
--include ../project/version.properties
-version:=${module.version}
-
-CC=gcc
-VPATH=${top_srcdir}/src
-
-GLOBUS_CPPFLAGS:=-I${globus_prefix}/include/${thrflavour}
-CPPFLAGS:=-I${stagedir}/include -D_GNU_SOURCE -D_REENTRANT ${CPPFLAGS}
-CFLAGS:=-W -Wall -g -O2 ${CFLAGS}
-LDFLAGS:=${LDFLAGS}
-LIBS:=-L${stagedir}/${archlib} -L${stagedir}/lib \
- -lglite_lb_common_${thrflavour} \
- -lglite_lb_client_${thrflavour} \
- -lpthread -lglite_security_gss_${thrflavour}
-
-ifneq ($(GLITE_LB_HARVESTER_WITH_LBU_DB),no)
-CPPFLAGS:=$(CPPFLAGS) -DWITH_LBU_DB=1
-LIBS:=$(LIBS) -lglite_lbu_db
-endif
-ifeq ($(GLITE_LB_HARVESTER_WITH_OLD_LB),yes)
-CPPFLAGS:=${GLOBUS_CPPFLAGS} $(CPPFLAGS) -DWITH_OLD_LB=1
-LIBS:=$(LIBS) -lglite_wmsutils_cjobid
-else
-LIBS:=$(LIBS) -lglite_jobid
-endif
-
-COMPILE:=libtool --mode=compile ${CC} ${CPPFLAGS} ${CFLAGS}
-LINK:=libtool --mode=link ${CC} ${LDFLAGS}
-INSTALL:=libtool --mode=install install
-
-default: all
-
-compile all: harvester
-
-check:
-
-debug: harvester-dbg
-
-doc:
-
-stage: compile
- $(MAKE) install PREFIX=${stagedir}
-
-install: compile
- -mkdir -p ${PREFIX}/bin ${PREFIX}/share/doc/${package}-${version}
- ${INSTALL} -m 755 harvester ${PREFIX}/bin/glite-lb-harvester
- ${INSTALL} -m 444 ../doc/README ${PREFIX}/share/doc/${package}-${version}
-
-clean:
- rm -rfv *.o *.lo .libs/ harvester harvester-dbg
- rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/
-
-harvester: harvester.o
- ${LINK} -o $@ $+ ${LIBS}
-
-harvester-dbg: harvester-dbg.o
- ${LINK} -o $@ $+ ${LIBS}
-
-harvester-dbg.o: harvester.c
- ${COMPILE} -Werror -DLOG=1 -DWITH_RTM_SQL_STORAGE=1 -c $< -o $@
-
-%.o: %.c
- ${COMPILE} -c $<
-
-.PHONY: default all compike debug check doc stage install clean
+++ /dev/null
-#!/usr/bin/perl
-
-# WARNING: Don't edit this file unless it is the master copy in org.glite.lb
-#
-# For the purpose of standalone builds of lb/jobid/lbjp-common components
-# it is copied on tagging
-
-# $Header$
-
-use Getopt::Long;
-
-my $pwd = `pwd`; chomp $pwd;
-my $prefix = $pwd.'/stage';
-my $stagedir;
-my $staged;
-my $module;
-my $thrflavour = 'gcc64dbgpthr';
-my $nothrflavour = 'gcc64dbg';
-my $mode = 'build';
-my $help = 0;
-my $listmodules;
-my $version;
-my $output;
-my $lb_tag = '';
-my $lbjp_tag = '';
-my $jp_tag = '';
-my $sec_tag = '';
-my $jobid_tag = '';
-my $libdir = 'lib';
-
-my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient harvester/;
-my %enable_nodes;
-my %disable_nodes;
-
-my %extern_prefix = (
- cares => '/opt/c-ares',
- classads => '/opt/classads',
- cppunit => '/usr',
- expat => '/usr',
- globus => '/opt/globus',
- jglobus => '/opt/globus',
- gsoap => '/usr',
- mysql => '/usr',
- 'mysql-devel' => '',
- 'mysql-server' => '',
- voms => '/opt/glite',
- gridsite => '/opt/glite',
- lcas => '/opt/glite',
- trustmanager => '/opt/glite',
- ant => '/usr',
- jdk => '/usr',
- libtar => '/usr',
- axis => '/usr',
- log4c => '/usr',
- postgresql => '/usr'
-);
-
-my %jar = (
- 'commons-codec' => '/usr/share/java/commons-codec.jar',
- 'commons-lang' => '/usr/share/java/commons-lang.jar',
-);
-
-
-my %glite_prefix;
-my %need_externs;
-my %need_externs_type;
-my %need_jars;
-my %extrafull;
-my %extranodmod;
-my %deps;
-my %deps_type;
-my %topbuild;
-
-my %lbmodules = (
- 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test harvester/],
- 'security' => [qw/gss gsoap-plugin/],
- 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/],
- 'jobid' => [qw/api-c api-cpp api-java/],
- 'jp' => [ qw/client doc index primary server-common ws-interface/ ],
- );
-
-
-my @opts = (
- 'prefix=s' => \$prefix,
- 'staged=s' => \$staged,
- 'module=s' => \$module,
- 'thrflavour=s' => \$thrflavour,
- 'nothrflavour=s' => \$nothrflavour,
- 'mode=s' => \$mode,
- 'listmodules=s' => \$listmodules,
- 'version=s' => \$version,
- 'output=s' => \$output,
- 'stage=s' => \$stagedir,
- 'lb-tag=s' => \$lb_tag,
- 'lbjp-common-tag=s' => \$lbjp_tag,
- 'jp-tag=s' => \$jp_tag,
- 'security-tag=s' => \$sec_tag,
- 'jobid-tag=s' => \$jobid_tag,
- 'help' => \$help,
- 'libdir=s' => \$libdir,
-);
-
-for (@nodes) {
- $enable_nodes{$_} = 0;
- $disable_nodes{$_} = 0;
-
- push @opts,"disable-$_",\$disable_nodes{$_};
- push @opts,"enable-$_",\$enable_nodes{$_};
-}
-
-push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix;
-push @opts,"with-$_=s",\$jar{$_} for keys %jar;
-
-my @keeparg = @ARGV;
-
-GetOptions @opts or die "Errors parsing command line\n";
-
-$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq '';
-$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq '';
-
-if ($help) { usage(); exit 0; }
-
-if ($listmodules) {
- my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}};
- print "@m\n";
- exit 0;
-}
-
-warn "$0: --version and --output make sense only in --mode=etics\n"
- if ($version || $output) && $mode ne 'etics';
-
-my $en;
-for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; }
-
-my $dis;
-for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; }
-
-die "--enable-* and --disable-* are mutually exclusive\n"
- if $en && $dis;
-
-die "--module cannot be used with --enable-* or --disable-*\n"
- if $module && ($en || $dis);
-
-die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}};
-
-if ($dis) {
- for (@nodes) {
- $enable_nodes{$_} = 1 unless $disable_nodes{$_};
- }
-}
-
-if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ;
-
-for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; }
-
-$stagedir = $prefix unless $stagedir;
-
-if ($mode eq 'build') {
- print "Writing config.status\n";
- open CONF,">config.status" or die "config.status: $!\n";
- print CONF "$0 @keeparg\n";
- close CONF;
-}
-
-
-my @modules;
-my %aux;
-
-if ($module) {
-# push @modules,split(/[,.]+/,$module);
- push @modules,$module;
-}
-else {
- @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes));
-
- my $n;
-
- do {
- local $"="\n";
- $n = $#modules;
- push @modules,(map @{$deps{$_}},@modules);
-
- undef %aux; @aux{@modules} = (1) x ($#modules+1);
- @modules = keys %aux;
- } while ($#modules > $n);
-}
-
-@aux{@modules} = (1) x ($#modules+1);
-delete $aux{$_} for (split /,/,$staged);
-@modules = keys %aux;
-
-mode_build() if $mode eq 'build';
-mode_checkout() if $mode eq 'checkout';
-mode_etics($module) if $mode eq 'etics';
-
-sub mode_build {
- print "\nBuilding modules: @modules\n";
-
- my @ext = map @{$need_externs{$_}},@modules;
- my @myjars = map @{$need_jars{$_}},@modules;
- undef %aux; @aux{@ext} = 1;
- @ext = keys %aux;
- undef %aux; @aux{@myjars} = (1) x ($#myjars+1);
- @myjars = keys %aux;
-
- print "\nRequired externals:\n";
- print "\t$_: $extern_prefix{$_}\n" for @ext;
- print "\t$_: $jar{$_}\n" for @myjars;
- print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n";
-
- mkinc($_) for @modules;
-
- print "Creating Makefile\n";
-
- open MAK,">Makefile" or die "Makefile: $!\n";
-
- print MAK "all: @modules\n\nclean:\n";
-
- for (@modules) {
- my $full = full($_);
- my $build = $topbuild{$_} ? '': '/build';
- print MAK "\tcd $full$build && \${MAKE} clean\n"
- }
-
- print MAK "\ndistclean:\n";
-
- for (@modules) {
- my $full = full($_);
- print MAK $topbuild{$_} ?
- "\tcd $full$build && \${MAKE} distclean\n" :
- "\trm -rf $full$build\n"
- }
-
- print MAK "\n";
-
- for (@modules) {
- my %ldeps; undef %ldeps;
- @ldeps{@{$deps{$_}}} = 1;
- for my $x (split /,/,$staged) { delete $ldeps{$x}; }
- my @dnames = $module ? () : keys %ldeps;
-
- my $full = full($_);
- my $build = $topbuild{$_} ? '': '/build';
-
- print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n";
- }
-
- close MAK;
-}
-
-sub mode_checkout() {
- for (@modules) {
- my $module = $_;
- my $tag = "";
- if ($lb_tag){
- for (@{$lbmodules{lb}}){
- if ("lb.".$_ eq $module){
- $tag = '-r '.$lb_tag;
- }
- }
- }
- if ($lbjp_tag){
- for (@{$lbmodules{'lbjp-common'}}){
- if ("lbjp-common.".$_ eq $module){
- $tag = '-r '.$lbjp_tag;
- }
- }
- }
- if ($jp_tag){
- for (@{$lbmodules{'jp'}}){
- if ("jp.".$_ eq $module){
- $tag = '-r '.$jp_tag;
- }
- }
- }
- if ($sec_tag){
- for (@{$lbmodules{security}}){
- if ("security.".$_ eq $module){
- $tag = '-r '.$sec_tag;
- }
- }
- }
- if ($jobid_tag){
- for (@{$lbmodules{jobid}}){
- if ("jobid.".$_ eq $module){
- $tag = '-r '.$jobid_tag;
- }
- }
- }
- #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){
- # print "found";
- #}
- $_ = full($_);
- print "\n*** Checking out $_\n";
- system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n";
- }
-}
-
-BEGIN{
-%need_externs_aux = (
- 'lb.client' => [ qw/cppunit:B classads/ ],
- 'lb.client-java' => [ qw/ant:B jdk:B axis:B trustmanager/ ],
- 'lb.common' => [ qw/expat cares:B cppunit:B classads/ ],
- 'lb.doc' => [],
- 'lb.logger' => [ qw/cppunit:B/ ],
- 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ],
- 'lb.state-machine' => [ qw/classads/ ],
- 'lb.utils' => [ qw/cppunit:B/ ],
- 'lb.ws-interface' => [],
- 'lb.ws-test' => [ qw/gsoap:B/ ],
- 'lb.types' => [ qw// ],
- 'lb.harvester' => [ qw/postgresql:R/ ],
- 'lbjp-common.db' => [ qw/mysql:B mysql-devel:B postgresql:B/ ],
- 'lbjp-common.maildir' => [ qw// ],
- 'lbjp-common.server-bones' => [ qw// ],
- 'lbjp-common.trio' => [ qw/cppunit:B/ ],
- 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ],
- 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ],
- 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares:B gsoap:B/ ],
- 'jobid.api-c' => [ qw/cppunit:B/ ],
- 'jobid.api-cpp' => [ qw/cppunit:B/ ],
- 'jobid.api-java' => [ qw/ant:B jdk:B/ ],
- 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ],
- 'jp.doc' => [],
- 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ],
- 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ],
- 'jp.server-common' => [],
- 'jp.ws-interface' => [],
-);
-
-for my $ext (keys %need_externs_aux) {
- for (@{$need_externs_aux{$ext}}) {
- /([^:]*)(?::(.*))?/;
- push @{$need_externs{$ext}},$1;
- my $type = $2 ? $2 : 'BR';
- $need_externs_type{$ext}->{$1} = $type;
- }
-}
-
-%need_jars = (
- 'jobid.api-java' => [ qw/commons-codec/ ],
- 'lb.client-java' => [ qw/commons-lang/ ],
-);
-
-for my $jar (keys %need_jars) {
- for (@{$need_jars{$jar}}) {
- $need_externs_type{$jar}->{$_} = 'BR'; # XXX
- }
-}
-
-%deps_aux = (
- 'lb.client' => [ qw/
- lb.types:B lb.common
- lbjp-common.trio
- jobid.api-cpp jobid.api-c
- security.gss
- / ],
- 'lb.client-java' => [ qw/
- lb.types:B
- lb.ws-interface:B
- jobid.api-java
- / ],
- 'lb.common' => [ qw/
- jobid.api-cpp jobid.api-c
- lb.types:B lbjp-common.trio security.gss
- / ],
- 'lb.doc' => [ qw/lb.types:B/ ],
- 'lb.logger' => [ qw/
- lbjp-common.trio
- jobid.api-c
- lb.common
- security.gss
- / ],
- 'lb.server' => [ qw/
- lb.ws-interface lb.types:B lb.common lb.state-machine
- lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir
- jobid.api-c
- security.gsoap-plugin security.gss
- / ],
- 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ],
- 'lb.utils' => [ qw/
- lbjp-common.jp-interface
- jobid.api-c
- lbjp-common.trio lbjp-common.maildir
- lb.client lb.state-machine
- / ],
- 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ],
- 'lb.ws-interface' => [ qw/lb.types:B/ ],
- 'lb.types' => [ qw// ],
- 'lb.harvester' => [ qw/
- jobid.api-c lbjp-common.trio lbjp-common.db lb.common lb.client
- security.gss
- / ],
- 'lbjp-common.db' => [ qw/lbjp-common.trio/ ],
- 'lbjp-common.maildir' => [ qw// ],
- 'lbjp-common.server-bones' => [ qw// ],
- 'lbjp-common.trio' => [ qw// ],
- 'security.gss' => [ qw// ],
- 'security.gsoap-plugin' => [ qw/security.gss/ ],
- 'jobid.api-c' => [ qw// ],
- 'jobid.api-cpp' => [ qw/jobid.api-c/ ],
- 'jobid.api-java' => [ qw// ],
-
- 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ],
-
- 'jp.client' => [ qw/
- jp.ws-interface
- lbjp-common.jp-interface lbjp-common.maildir
- jobid.api-c
- security.gsoap-plugin
- / ],
- 'jp.doc' => [ qw// ],
- 'jp.index' => [ qw/
- jp.server-common jp.ws-interface
- lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones
- security.gsoap-plugin
- / ],
- 'jp.primary' => [ qw/
- jobid.api-c
- jp.server-common jp.ws-interface
- lb.state-machine
- lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones
- security.gsoap-plugin
- / ],
- 'jp.server-common' => [ qw/
- lbjp-common.jp-interface lbjp-common.db
- / ],
- 'jp.ws-interface' => [ qw// ],
-);
-
-for my $ext (keys %deps_aux) {
- for (@{$deps_aux{$ext}}) {
- /([^:]*)(?::(.*))?/;
- push @{$deps{$ext}},$1;
- my $type = $2 ? $2 : 'BR';
- $deps_type{$ext}->{$1} = $type;
- }
-}
-
-
-%extrafull = ( gridsite=>'org.gridsite.core');
-
-#( java => 'client-java' );
-%extranodmod = (
- db => 'lbjp-common.db',
- jpprimary => 'jp.primary',
- jpindex => 'jp.index',
- jpclient => 'jp.client',
-);
-
-my @t = qw/lb.client-java jobid.api-java lb.types/;
-@topbuild{@t} = (1) x ($#t+1);
-}
-
-sub full
-{
- my $short = shift;
- return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short;
-}
-
-sub mkinc
-{
- my %aux;
- undef %aux;
- my @m=qw/
-lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java lb.harvester
-security.gss security.gsoap-plugin
-jobid.api-c jobid.api-cpp jobid.api-java
-lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface
-jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface
-/;
- @aux{@m} = (1) x ($#m+1);
-
- my $short = shift;
- my $full = full $short;
-
- unless ($aux{$short}) {
- print "Makefile.inc not needed in $full\n";
- return;
- }
-
- my $build = '';
-
- unless ($topbuild{$_}) {
- $build = '/build';
- unless (-d "$full/build") {
- mkdir "$full/build" or die "mkdir $full/build: $!\n";
- }
- unlink "$full/build/Makefile";
- symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n";
- }
-
- open MKINC,">$full$build/Makefile.inc"
- or die "$full$build/Makefile.inc: $!\n";
-
- print "Creating $full$build/Makefile.inc\n";
-
- print MKINC qq{
-PREFIX = $prefix
-stagedir = $stagedir
-thrflavour = $thrflavour
-nothrflavour = $nothrflavour
-libdir = $libdir
-};
-
- for (@{$need_externs{$short}}) {
- print MKINC "${_}_prefix = $extern_prefix{$_}\n"
- }
-
- for (@{$need_jars{$short}}) {
- print MKINC "${_}_jar = $jar{$_}\n"
- }
-
- my $need_gsoap = 0;
- for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; }
-
- print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap;
-
- close MKINC;
-}
-
-my %etics_externs;
-my %etics_projects;
-BEGIN{
- %etics_externs = (
- globus_essentials=>'vdt_globus_essentials',
- globus=>'globus',
- cares=>'c-ares',
- voms=>'org.glite.security.voms-api-cpp',
- gridsite=>'org.gridsite.shared',
- lcas=>'org.glite.security.lcas',
- trustmanager=>'org.glite.security.trustmanager',
- );
- %etics_projects = (
- vdt=>[qw/globus globus_essentials/],
- 'org.glite'=>[qw/voms gridsite lcas/],
- );
-};
-
-sub mode_etics {
- $fmod = shift;
-
- die "$0: --module required with --etics\n" unless $fmod;
-
- my ($subsys,$module) = split /\./,$fmod;
-
- my ($major,$minor,$rev,$age);
-
- if ($version) {
- $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/;
- ($major,$minor,$rev,$age) = ($1,$2,$3,$4);
- }
- else {
- open V,"org.glite.$subsys.$module/project/version.properties"
- or die "org.glite.$subsys.$module/project/version.properties: $!\n";
-
- while ($_ = <V>) {
- chomp;
- ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/;
- $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/;
- }
- close V;
- }
-
- my @copts = ();
- my %ge;
- @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1);
-
- for (@{$need_externs{"$subsys.$module"}}) {
- if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) {
- my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_;
- push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}";
- }
- }
-
- for (@{$need_jars{"$subsys.$module"}}) {
- my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_;
-
- push @copts,"--with-$_ \${$eext.location}/$_*.jar";
- }
-
-
- my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}";
- my $file = $output ? $output : "$conf.ini";
- open C,">$file" or die "$file: $!\n";
-
- my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n";
-
- my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..';
-
- print STDERR "Writing $file\n";
- print C qq{
-[Configuration-$conf]
-profile = None
-moduleName = org.glite.$subsys.$module
-displayName = $conf
-description = org.glite.$subsys.$module
-projectName = org.glite
-age = $age
-deploymentType = None
-tag = $conf
-version = $major.$minor.$rev
-path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz
-
-[Platform-default:VcsCommand]
-displayName = None
-description = None
-tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName}
-branch = None
-commit = None
-checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName}
-
-[Platform-default:BuildCommand]
-postpublish = None
-packaging = None
-displayName = None
-description = None
-doc = None
-prepublish = None
-publish = None
-compile = make
-init = None
-install = make install
-clean = make clean
-test = make check
-configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts
-checkstyle = None
-
-[Platform-default:Property]
-$buildroot
-
-[Platform-default:DynamicDependency]
-
-};
- for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) {
- my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_;
-
- my $proj = 'externals';
- for my $p (keys %etics_projects) {
- for $m (@{$etics_projects{$p}}) {
- $proj = $p if $m eq $_;
- }
- }
-
- my $type = $need_externs_type{"$subsys.$module"}->{$_};
- print C "$proj|$eext = $type\n";
- }
-
- for (@{$deps{"$subsys.$module"}}) {
- my $type = $deps_type{"$subsys.$module"}->{$_};
- print C "org.glite|org.glite.$_ = $type\n";
- }
-
- close C;
-}
-
-sub gsoap_version {
- local $_;
- my $gsoap_version;
- open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n";
-
- while ($_ = <S>) {
- chomp;
-
- $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/;
- }
- close S;
- return $gsoap_version;
-}
-
-
-sub usage {
- my @ext = keys %extern_prefix;
- my @myjars, keys %jar;
-
- print STDERR qq{
-usage: $0 options
-
-General options (defaults in []):
- --prefix=PREFIX destination directory [./stage]
- --staged=module,module,... what is already in PREFIX (specify without org.glite.)
- --thrflavour=flavour
- --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg]
- --listmodules=subsys list modules of a subsystem
- --libdir=libdir typically [lib,lib64] postfix
-
-Mode of operation:
- --mode={checkout|build|etics} what to do [build]
-
-What to build:
- --module=module build this module only (mostly in-Etics operation)
- --enable-NODE build this "node" (set of modules) only. Available nodes are
- @{$lbmodules{lb}},@{$lbmodules{security}}
- --disable-NODE don't build this node
- --lb-tag=tag checkout LB modules with specific tag
- --jp-tag=tag checkout JP modules with specific tag
- --lbjp-common-tag=tag checkout lbjp-common modules with specific tag
- --security-tag=tag checkout security modules with specific tag
- --jobid-tag=tag checkout jobid modules with specific tag
-
-Dependencies:
- --with-EXTERNAL=PATH where to look for an external. Required externals
- (not all for all modules) are:
- @ext
- --with-JAR=JAR where to look for jars. Required jars are:
- @myjars
- Summary of what will be used is always printed
-
-};
-
-}
+++ /dev/null
-Requirements
-============
-
-1) gLite
-- client L&B libraries:
- - glite-jobid-api-c
- - glite-lb-common
- - glite-lb-client
- - glite-security-gss
- - globus essential libraries (threaded flavour),
- use the vesion with the external SSL, not with bundled SSL (!)
- - glite-lbjp-common-db (build only)
- - mysql-devel (build only)
-2) postgresql-devel
-
-
-Steps
-=====
-
-./configure
-make
-make install
-
-Use './configure --help' for the options.
-
-
-Manual way
-==========
-
-configure is simple script generating Makefile.inc. You can build harvester
-straight away by make defining the variables manually. For example with gLite
-installed in ~/glite/stage:
-
-(rm Makefile.inc)
-make stagedir=$HOME/glite/stage
-
-
-Testing
-=======
-
-Test for basic functionality covered by 'test.sh' script in sources.
-See './test.sh --help'.
+++ /dev/null
-Introduction
-============
-
-L&B Harvester gathers information about jobs from L&B servers using effective
-L&B notification mechanism. It manages notifications and keeps them in
-a persistent storage (file or database table) to reuse later on next launch.
-It takes care about refreshing notifications and queries L&B servers back when
-some notification on expires.
-
-The tool was initially written for Real Time Monitor (project at Imperial
-College in London), later was extended with messaging mechanism for WLCG.
-
-
-Requirements
-============
-
-- lastUpdateTime index on L&B servers
-- harvester identity in super users file on L&B servers
-
-
-Launch (with msg-publish sending messages)
-=========================================
-
-Harvester is sending notifications via msg-publish infrastructure. List of the
-L&B server to harvest is specified via -c option.
-
-1) with newer LB 2.0 servers:
-
- glite-lb-harvester -c servers.txt -C certfile -K keyfile --wlcg
-
-2) with older LB servers (backward compatible but greedy notifications):
-
- glite-lb-harvester -c servers.txt -C certfile -K keyfile --wlcg --old
-
-Custom configuration of messaging:
- --wlcg-binary $HOME/bin/msg-publish
- --wlcg-topic org.wlcg.usage.JobStatus2
- --wlcg-config $HOME/etc/msg-publish.conf.wlcg
-
-
-Launch (Real Time Monitor and storing to the database)
-======================================================
-
-Harvester is using postgres database. Table 'lb20' with L&B servers to
-harvest (read-only), table 'jobs' with result job states (read/write). It's
-possible to specify L&B servers list by file instead of 'lb20' table,
-via -c option.
-
- glite-lb-harvester -C certfile -K keyfile --pg rtm/@:rtm
-
-The connection string after '--pg' is in format:
- USER/PASSWORD@HOST:DATABASE
-Database schema in 'test.sql'.
-
-
-Other recommended options
-=========================
-
-Use 'glite-lb-harvester --help' for additional options.
-
-For example:
- - deamonizing and using syslog:
- '--daemonize --pidfile /var/run/glite-lb-harvester.pid'
- - decreasing verbosity:
- '-d 2' (2 for errors and warnings only)
-
-
-Stop
-====
-
-In non-daemon mode CTRL-C can be used, in daemon mode using specified
-pidfile:
-
- kill `cat /var/run/glite-lb-harvester.pid`
-
-pidfile will vanish after exit.
-
-All notifications are preserved on LB servers, and will expire later. You can
-purge them now, if they won't be needed:
-
- glite-lb-harvester --cleanup
+++ /dev/null
-#! /bin/sh
-
-
-usage() {
-cat <<EOF
-
- ./test.sh
-
- Testing of the L&B harvester using local daemons and databases.
-
- Requirements:
- - working L&B software (ideally with passed org.glite.testsuites.ctb/LB/test)
- - mysql and postgresql databases, with sufficient access
- pg_hba.conf content for example:
- local all all trust all
- - created user \$RTM_NAME (rtm by default) in postgres DB
- - proxy certificate
- - writable working directory with harvester built with -DRTM_SQL_STORAGE_ENABLED=1
- (or via 'make test')
-
- non-default configuration is possible via following env variables or
- using ~/.glite.conf:
- GLITE_LOCATION..................path to glite SW
- GLOBUS_LOCATION.................path to globus SW
- GLITE_HOST_CERT.................path to host certificate
- GLITE_HOST_KEY..................path to host key
- GLITE_LB_TEST_DB................L&B connection string
- (default lbserver/@localhost:lbserver20test,
- autocreating the database when empty)
- GLITE_RTM_TEST_DB...............L&B connection string, existing user with
- privileges required
- (default rtm/@localhost:rtmtest,
- autocreating the database when empty)
- GLITE_MYSQL_ROOT_USER...........mysql root user (default: root)
- GLITE_MYSQL_ROOT_PASSWORD.......mysql root password (default: none)
- GLITE_PG_ROOT_USER..............postgres root user (default: postgres)
- GLITE_LB_TEST_SERVER_PORT.......(default 10000)
- GLITE_LB_TEST_PIDFILE...........(default /tmp/glite-lb-test.pid)
- GLITE_RTM_TEST_PIDFILE..........(default /tmp/glite-rtm-test.pid)
- GLITE_RTM_TEST_TTL..............notif validity (default 60 seconds)
- GLITE_RTM_TEST_ADDITIONAL_ARGS..additional arguments for harvester
-
-EOF
-}
-
-
-init() {
- # get the configuration
- GLITE_LOCATION=${GLITE_LOCATION:-"/opt/glite"}
- [ -f /etc/glite.conf ] && . /etc/glite.conf
- [ -f $HOME/.glite.conf ] && . $HOME/.glite.conf
-
- GLOBUS_LOCATION=${GLOBUS_LOCATION:-"/opt/globus"}
-
- if [ -n "$GLITE_HOST_CERT" -a -n "$GLITE_HOST_KEY" ] ;then
- X509_USER_CERT="$GLITE_HOST_CERT"
- X509_USER_KEY="$GLITE_HOST_KEY"
- fi
-
-# if [ -z "$X509_USER_CERT" -o -z "$X509_USER_KEY" ] ; then
- if [ -e "$GLOBUS_LOCATION/bin/grid-proxy-info" ] ; then
- timeleft=`$GLOBUS_LOCATION/bin/grid-proxy-info 2>&1| \
- grep timeleft| sed 's/^.* //'`
- if [ "$timeleft" = "0:00:00" -o -z "$timeleft" ]; then
- echo "Proxy certificate check failed."\
- " Aborting."
- exit 1
- fi
- else
- echo "Can't check proxy cert (grid-proxy-info not found). If you do not have valid proxy certificate, set GLITE_HOST_KEY/GLITE_HOST_KEY - otherwise tests will fail!"
- fi
-# fi
- identity=`X509_USER_KEY=${X509_USER_KEY} X509_USER_CERT=${X509_USER_CERT} $GLOBUS_LOCATION/bin/grid-proxy-info 2>&1| \
- grep identity| sed 's/^[^/]*//'`
-
- if [ -z "$GLITE_LB_TEST_DB" ]; then
- GLITE_LB_TEST_DB="lbserver/@localhost:lbserver20test"
- need_new_lb_db=1;
- fi
- DB_USER=`echo $GLITE_LB_TEST_DB| sed 's!/.*$!!'`
- DB_HOST=`echo $GLITE_LB_TEST_DB| sed 's!^.*@!!' | sed 's!:.*!!'`
- DB_NAME=`echo $GLITE_LB_TEST_DB| sed 's!^.*:!!'`
- MYSQL_ARGS="-u ${GLITE_MYSQL_ROOT_USER:-root}"
- [ -z "$GLITE_MYSQL_ROOT_PASSWORD" ] || ARGS="--password=${GLITE_MYSQL_ROOT_PASSWORD} $MYSQL_ARGS"
-
- if [ -z "$GLITE_RTM_TEST_DB" ]; then
- GLITE_RTM_TEST_DB="rtm/@localhost:rtmtest"
- need_new_rtm_db=1;
- fi
- RTM_USER=`echo $GLITE_RTM_TEST_DB| sed 's!/.*$!!'`
- RTM_HOST=`echo $GLITE_RTM_TEST_DB| sed 's!^.*@!!' | sed 's!:.*!!'`
- RTM_NAME=`echo $GLITE_RTM_TEST_DB| sed 's!^.*:!!'`
- PG_ARGS="-U ${GLITE_PG_ROOT_USER:-postgres}"
-
- #other stuff
- GLITE_LB_TEST_SERVER_PORT=${GLITE_LB_TEST_SERVER_PORT:-"10000"}
- GLITE_LB_TEST_PIDFILE=${GLITE_LB_TEST_PIDFILE:-"/tmp/glite-lb-test.pid"}
- GLITE_RTM_TEST_PIDFILE=${GLITE_RTM_TEST_PIDFILE:-"/tmp/glite-rtm-test.pid"}
- GLITE_RTM_TEST_TTL=${GLITE_RTM_TEST_TTL:-"60"}
-
- jobreg="$GLITE_LOCATION/examples/glite-lb-job_reg -m `hostname -f`:${GLITE_LB_TEST_SERVER_PORT} -s UserInterface"
- logev="$GLITE_LOCATION/bin/glite-lb-logevent -x -S `pwd`/LB/proxy.sockstore.sock -U localhost"
- for dir in "$GLITE_LOCATION/bin" "`pwd`/../build" "`pwd`"; do
- if [ -x "$dir/glite-lb-harvester-dbg" ]; then
- rtm="$dir/glite-lb-harvester-dbg"
- fi
- if [ -x "$dir/harvester-dbg" ]; then
- rtm="$dir/harvester-dbg"
- fi
- done
- if [ -z "$rtm" ]; then
- echo "glite-lb-harvester-dbg not found"
- return 1
- fi
-
- if echo "$GLITE_RTM_TEST_ADDITIONAL_ARGS" | grep -- '[^-]\?\(--old\>\|-o\>\)' >/dev/null; then
- n_notifs=1
- else
- n_notifs=2
- fi
-
- rm -f log
-}
-
-
-drop_db() {
-return 0
- [ -z "$lb_db_created" ] || mysqladmin -f $MYSQL_ARGS drop "$DB_NAME"
- [ -z "$rtm_db_created" ] || dropdb $PG_ARGS "$RTM_NAME"
-}
-
-
-create_db() {
- echo -n "mysql."
- # create database when needed
- if [ "x$need_new_lb_db" = "x1" ]; then
- mysqladmin -f $MYSQL_ARGS drop $DB_NAME > /dev/null 2>&1
- echo -n "."
- mysqladmin -f $MYSQL_ARGS create $DB_NAME && \
- echo -n "."
- mysql $MYSQL_ARGS -e "GRANT ALL on $DB_NAME.* to $DB_USER@$DB_HOST" && \
- echo -n "."
- mysql -u $DB_USER $DB_NAME -h $DB_HOST < $GLITE_LOCATION/etc/glite-lb-dbsetup.sql || return $?
- echo -n "."
- mkdir -p `pwd`/LB
- cat > `pwd`/LB/glite-lb-index.conf << EOF
-[
- JobIndices = {
- [ type = "system"; name = "lastUpdateTime" ]
- }
-]
-EOF
- LBDB="$GLITE_LB_TEST_DB" $GLITE_LOCATION/bin/glite-lb-bkindex -r `pwd`/LB/glite-lb-index.conf || return $?
- lb_db_created="1"
- echo -n "."
- else
- cleanup_mysql || return $?
- fi
- echo -n "OK psql."
- if [ "x$need_new_rtm_db" = "x1" ]; then
- dropdb $PG_ARGS "$RTM_NAME" >/dev/null 2>&1
- echo -n "."
-# createuser $PG_ARGS -A -D "$RTM_NAME" >/dev/null 2>&1
-# echo -n "."
- createdb $PG_ARGS --encoding "UTF-8" --owner "$RTM_USER" "$RTM_NAME" >psql-create.log 2>&1 || return $?
- rm psql-create.log
- echo -n "."
- rtm_db_created="1"
- echo "\i test.sql" | psql -AtF ',' -U "$RTM_USER" "$RTM_NAME" >/dev/null || return $?
- echo -n "."
- else
- cleanup_pg || return $?
- fi
- echo "OK"
-}
-
-
-cleanup_mysql() {
- cat << EOF | mysql -u $DB_USER $DB_NAME -h $DB_HOST || return $?
-DELETE FROM acls;
-DELETE FROM events;
-DELETE FROM events_flesh;
-DELETE FROM jobs;
-DELETE FROM long_fields;
-DELETE FROM notif_jobs;
-DELETE FROM notif_registrations;
-DELETE FROM server_state;
-DELETE FROM short_fields;
-DELETE FROM states;
-DELETE FROM status_tags;
-DELETE FROM users;
-DELETE FROM zombie_jobs;
-DELETE FROM zombie_prefixes;
-DELETE FROM zombie_suffixes;
-EOF
- echo -n "."
-}
-
-
-cleanup_pg() {
- cat << EOF | psql -AtF ',' -U "$RTM_USER" "$RTM_NAME" >/dev/null || return $?
-DELETE FROM jobs;
-DELETE FROM notifs;
-EOF
- echo -n "."
-}
-
-
-run_daemons() {
- mkdir -p LB/dump LB/purge LB/voms 2>/dev/null
-
- # checks
- if [ -f "${GLITE_LB_TEST_PIDFILE}" ]; then
- echo "L&B server already running (${GLITE_LB_TEST_PIDFILE}, `cat ${GLITE_LB_TEST_PIDFILE}`)"
- quit=1
- fi
- if [ -f "${GLITE_RTM_TEST_PIDFILE}" ]; then
- echo "L&B harvester already running (${GLITE_RTM_TEST_PIDFILE}, `cat ${GLITE_RTM_TEST_PIDFILE}`)"
- quit=1
- fi
- if [ -e "`pwd`/LB/notif.sock" ]; then
- if [ "`lsof -t $(pwd)/LB/notif.sock | wc -l`" != "0" ]; then
- echo "Notification interlogger already running (using LB/notif.sock, `lsof -t $(pwd)/LB/notif.sock`)"
- quit=1
- fi
- fi
- if [ -e "`pwd`/LB/proxy-il.sock" ]; then
- if [ "`lsof -t $(pwd)/LB/proxy-il.sock | wc -l`" != "0" ]; then
- echo "Proxy interlogger already running (using LB/proxy-il.sock, `lsof -t $(pwd)/LB/proxy-il.sock`)"
- quit=1
- fi
- fi
- [ -z "$quit" ] || exit 1
-
- # run L&B server
- echo -n "L"
- X509_USER_KEY=${X509_USER_KEY} X509_USER_CERT=${X509_USER_CERT} \
- $GLITE_LOCATION/bin/glite-lb-bkserverd \
- -m $GLITE_LB_TEST_DB \
- -p $GLITE_LB_TEST_SERVER_PORT -w $(($GLITE_LB_TEST_SERVER_PORT + 3))\
- -i ${GLITE_LB_TEST_PIDFILE} \
- --withproxy -o `pwd`/LB/proxy.sock\
- --proxy-il-sock `pwd`/LB/proxy-il.sock --proxy-il-fprefix `pwd`/LB/proxy-data \
- -D `pwd`/LB/dump -S `pwd`/LB/purge \
- -V `pwd`/LB/voms \
- --notif-il-sock `pwd`/LB/notif.sock --notif-il-fprefix `pwd`/LB/notif-data \
- --super-user "$identity" > `pwd`/LB/glite-lb-test-pre.log 2>&1
- if [ x"$?" != x"0" ]; then
- cat `pwd`/LB/glite-lb-test-pre.log
- echo FAILED
- drop_db;
- exit 1
- fi
- echo -n "B "
-
- # run L&B interlogger
- echo -n "L"
- X509_USER_KEY=${X509_USER_KEY} X509_USER_CERT=${X509_USER_CERT} \
- $GLITE_LOCATION/bin/glite-lb-interlogd \
- --file-prefix `pwd`/LB/proxy-data --socket `pwd`/LB/proxy-il.sock > `pwd`/LB/glite-interlog-test-pre.log 2>&1
- if [ x"$?" != x"0" ]; then
- cat `pwd`/LB/glite-interlog-test-pre.log
- echo FAILED
- kill_bkserver
- drop_db;
- exit 1
- fi
- echo -n "I "
-
- # run L&B notification interlogger
- echo -n "N"
- X509_USER_KEY=${X509_USER_KEY} X509_USER_CERT=${X509_USER_CERT} \
- $GLITE_LOCATION/bin/glite-lb-notif-interlogd \
- --file-prefix `pwd`/LB/notif-data --socket `pwd`/LB/notif.sock > `pwd`/LB/glite-notif-test-pre.log 2>&1
- if [ x"$?" != x"0" ]; then
- cat `pwd`/LB/glite-notif-test-pre.log
- echo FAILED
- kill_daemons
- drop_db;
- exit 1
- fi
- echo -n "I "
-
- if ! start_harvester; then
- kill_daemons;
- drop_db;
- exit 1
- fi
-
- # wait for pidfiles
- i=0
- while [ ! -s "${GLITE_LB_TEST_PIDFILE}" -a $i -lt 20 ]; do
- sleep 0.1
- i=$(($i+1))
- done
- if [ ! -s "${GLITE_LB_TEST_PIDFILE}" ]; then
- echo "Can't startup L&B server."
- kill_daemons;
- drop_db;
- exit 1
- fi
-
- echo -n "notifs."
- pg_wait 20 "SELECT refresh FROM notifs WHERE notifid IS NOT NULL" $n_notifs || return $?
- refresh=`echo "$result" | head -n 1`
- if [ -z "$refresh" ]; then
- echo "FAIL"
- return 1
- fi
-}
-
-
-start_harvester() {
- # run L&B harvester server
- echo -n "R"
- rm -Rf RTM
- mkdir RTM 2>/dev/null
- echo "`hostname -f`:${GLITE_LB_TEST_SERVER_PORT}" > `pwd`/RTM/config.txt
- X509_USER_KEY=${X509_USER_KEY} X509_USER_CERT=${X509_USER_CERT} \
- ${rtm} \
- -m $GLITE_RTM_TEST_DB \
- --pidfile ${GLITE_RTM_TEST_PIDFILE} \
- --ttl ${GLITE_RTM_TEST_TTL} \
- --history $((GLITE_RTM_TEST_TTL / 2)) \
- --debug 12 \
- --config `pwd`/RTM/config.txt \
- --daemonize ${GLITE_RTM_TEST_ADDITIONAL_ARGS} 2>`pwd`/RTM/glite-rtm-test-pre.log >`pwd`/RTM/notifs.log
- if [ x"$?" != x"0" ]; then
- cat `pwd`/RTM/glite-rtm-test-pre.log
- echo FAILED
- return 1
- fi
-
- i=0
- while [ ! -s "${GLITE_RTM_TEST_PIDFILE}" -a $i -lt 20 ]; do
- sleep 0.1
- i=$(($i+1))
- done
- if [ ! -s "${GLITE_RTM_TEST_PIDFILE}" ]; then
- echo "Can't startup L&B harvester."
- kill_daemons;
- drop_db;
- exit 1
- fi
-
- echo -n "M "
-}
-
-
-cleanup_harvester() {
- echo -n "cleaning up..."
- X509_USER_KEY=${X509_USER_KEY} X509_USER_CERT=${X509_USER_CERT} \
- ${rtm} \
- -m $GLITE_RTM_TEST_DB \
- --cleanup \
- --debug 12 ${GLITE_RTM_TEST_ADDITIONAL_ARGS} >`pwd`/RTM/glite-rtm-test-cleanup.log 2>&1
- if [ x"$?" != x"0" ]; then
- cat `pwd`/RTM/glite-rtm-test-cleanup.log
- echo FAILED
- return 1
- fi
- echo -n "OK "
-}
-
-
-kill_daemons() {
- pid1=`cat ${GLITE_LB_TEST_PIDFILE} 2>/dev/null`
- [ -f "${GLITE_RTM_TEST_PIDFILE}" ] && pid2=`cat ${GLITE_RTM_TEST_PIDFILE}`
- pid3=`lsof -t $(pwd)/LB/notif.sock 2>/dev/null`
- pid4=`lsof -t $(pwd)/LB/proxy-il.sock 2>/dev/null`
- [ ! -z "$pid1" ] && kill $pid1
- [ ! -z "$pid2" ] && kill -2 $pid2
- [ ! -z "$pid3" ] && kill $pid3
- [ ! -z "$pid4" ] && kill $pid4
- sleep 1;
- [ ! -z "$pid1" ] && kill -9 $pid1 2>/dev/null
- [ ! -z "$pid2" ] && kill -9 $pid2 2>/dev/null
- [ ! -z "$pid3" ] && kill -9 $pid3 2>/dev/null
- [ ! -z "$pid4" ] && kill -9 $pid4 2>/dev/null
- rm -f "${GLITE_LB_TEST_PIDFILE}" "${GLITE_RTM_TEST_PIDFILE}"
- rm -f `pwd`/LB/*.sock
-}
-
-
-kill_bkserver() {
- pid=`cat ${GLITE_LB_TEST_PIDFILE} 2>/dev/null`
- if [ ! -z "$pid1" ]; then
- kill $pid;
- sleep 1;
- kill -9 $pid
- fi
- rm -f "${GLITE_LB_TEST_PIDFILE}"
-}
-
-
-kill_harvester() {
- pid=`cat ${GLITE_RTM_TEST_PIDFILE} 2>/dev/null`
- if [ ! -z "$pid1" ]; then
- kill $pid
- sleep 1;
- kill -9 $pid 2>/dev/null
- fi
- rm -f "${GLITE_RTM_TEST_PIDFILE}"
-}
-
-
-reg() {
- echo -n "R"
- echo $jobreg $@ >> log
- $jobreg $@ > jobreg.tmp
- if [ $? -ne 0 ]; then
- cat jobreg.tmp
- rm -f jobreg.tmp
- echo " FAIL!"
- return 1;
- fi
- script=`cat jobreg.tmp | tail -n 2`
- rm -f jobreg.tmp
- EDG_JOBID=
- EDG_WL_SEQUENCE=
- eval $script
- if [ -z "$EDG_JOBID" -o -z "$EDG_WL_SEQUENCE" ]; then
- echo " FAIL!"
- return 1;
- fi
- echo -n "G "
-}
-
-
-ev() {
- echo -n "E"
- echo $logev -j "$EDG_JOBID" -c "$EDG_WL_SEQUENCE" "$@" >> log
- $logev -j "$EDG_JOBID" -c "$EDG_WL_SEQUENCE" "$@" 2> logev-err.tmp >logev.tmp
- if [ $? -ne 0 ]; then
- echo " FAIL!"
- return 2;
- fi
- EDG_WL_SEQUENCE=`cat logev.tmp`
- rm logev.tmp logev-err.tmp
- echo -n "V "
-}
-
-
-pg_get() {
- result=
- lines=
- echo "$1" | psql -AtF ',' -U "$RTM_USER" "$RTM_NAME" > psql.tmp
- if [ $? != 0 ]; then
- return $?
- fi
- result="`cat psql.tmp`"
- lines=`wc -l psql.tmp | sed 's/^[ ]*//' | cut -f1 -d' '`
-# rm psql.tmp
- return 0
-}
-
-
-pg_wait() {
- timeout=$(($1*2))
- sql="$2"
- n="$3"
-
- i=0
- found=0
- result=
- echo -n "S"
- echo "`date '+%Y-%m-%d %H:%M:%S'` $sql" >> log
- while [ "$found" = "0" -a $i -lt $timeout ]; do
- pg_get "$sql" || return $?
- echo -n "."
- if [ -z "$n" ]; then
- if [ "$lines" != "0" ]; then found=1; fi
- else
- if [ "$lines" = "$n" ]; then found=1; fi
- fi
- if [ "$found" = "0" ]; then sleep 0.5; fi
- i=$(($i+1))
- done
- echo -n "Q "
- result="$result"
- echo "`date '+%Y-%m-%d %H:%M:%S'` $lines lines" >> log
- if [ ! -z "$result" ]; then
- echo "$result" | sed -e 's/\(.*\)/\t\1/' >> log
- fi
- return 0
-}
-
-
-my_get() {
- result=
- lines=
- echo "`date '+%Y-%m-%d %H:%M:%S'` $1" >> log
- echo "$1" | mysql -B -u "$DB_USER" "$DB_NAME" > mysql.tmp
- if [ $? != 0 ]; then
- return $?
- fi
- result=`cat mysql.tmp | tail -n +2`
- lines=`echo "$result" | grep -v '^$' | wc -l | sed 's/^[ ]*//'`
- echo "`date '+%Y-%m-%d %H:%M:%S'` $lines lines" >> log
- if [ ! -z "$result" ]; then
- echo "$result" | sed -e 's/\(.*\)/\t\1/' >> log
- fi
-# rm -f mysql.tmp
- return 0
-}
-
-
-# notif propagation
-test_basic() {
- ok=0
-
- # submited
- echo -n "submitted..."
- reg || return $?
- pg_wait 10 "SELECT jobid, state FROM jobs WHERE state='Submitted'" || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
-
- # waiting
- echo -n "waiting..."
- ev -s NetworkServer -e Accepted --from='UserInterface' --from_host=`hostname -f` --from_instance="pid$$" || return $?
- pg_wait 10 "SELECT jobid, state FROM jobs WHERE state='Waiting'" || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
-
- # running
- echo -n "running..."
- ev -s LogMonitor -e Running --node="worker node" || return $?
- pg_wait 10 "SELECT jobid, state FROM jobs WHERE state='Running'" || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
-
- ok=1
- echo "OK"
-}
-
-
-# proper notif registration cleanup
-test_rebind() {
- ok=0
-
- # ---- active ---
- echo -n "$n_notifs notifications "
- my_get "SELECT notifid FROM notif_registrations" || return $?
- # STATUS and JDL
- if [ "$lines" != "$n_notifs" ]; then
- echo "FAIL"
- return 0
- fi
- echo -n "OK "
-
- # ---- store & stop ---
- echo -n "store&quit"
- pid=`cat ${GLITE_RTM_TEST_PIDFILE}`
- kill $pid
- i=0
- while [ -s "${GLITE_RTM_TEST_PIDFILE}" -a $i -lt 200 ]; do
- echo -n "."
- sleep 0.5
- i=$(($i+1))
- done
- if [ -s "${GLITE_RTM_TEST_PIDFILE}" ]; then
- echo "FAIL"
- return 0
- fi
- echo -n "OK notifs "
- my_get "SELECT notifid FROM notif_registrations" || return $?
- if [ "$lines" != "$n_notifs" ]; then
- echo "FAIL"
- return 0
- fi
- echo -n "OK "
-
- # ---- launch & rebind ---
- if ! start_harvester; then
- kill_daemons;
- drop_db;
- exit 1
- fi
-
- echo -n "bind"
- pg_wait 20 "SELECT notifid FROM notifs WHERE notifid IS NOT NULL" $n_notifs || return $?
- if [ x"$lines" != x"$n_notifs" ]; then
- echo "FAIL"
- return 0
- fi
-
- echo -n "Done "
- ev -s LogMonitor -e Done --status_code=OK --reason="Finished, yeah!" --exit_code=0 || return $?
- pg_wait 20 "SELECT jobid, state FROM jobs WHERE state='Done'"
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
-
- ok=1
- echo "OK"
-}
-
-
-test_cleanup() {
- ok=0
-
- # ---- deep stop ---
- echo -n "deep quit"
- pid=`cat ${GLITE_RTM_TEST_PIDFILE}`
- kill -2 $pid
- i=0
- while [ -s "${GLITE_RTM_TEST_PIDFILE}" -a $i -lt 200 ]; do
- echo -n "."
- sleep 0.5
- i=$(($i+1))
- done
- if [ -s "${GLITE_RTMTESTPIDFILE}" ]; then
- echo "FAIL"
- return 0
- fi
-
- echo -n "$n_notifs notifications..."
- my_get "SELECT notifid FROM notif_registrations" || return 1
- if [ "$lines" != "$n_notifs" ]; then
- echo "FAIL"
- return 0
- fi
-
- cleanup_harvester || return $?
- echo -n "0 notifications..."
- my_get "SELECT notifid FROM notif_registrations" || return 1
- if [ "$lines" != "0" ]; then
- echo "FAIL"
- return 0
- fi
-
- echo -n "cleandb."
- cleanup_pg || return $?
- start_harvester || return $?
-
- echo -n "notifs."
- pg_wait 20 "SELECT refresh FROM notifs WHERE notifid IS NOT NULL" $n_notifs || return $?
- refresh=`echo "$result" | head -n 1`
- if [ -z "$refresh" ]; then
- echo "FAIL"
- return 0
- fi
-
- ok=1
- echo "OK"
-}
-
-
-test_refresh() {
- ok=0
-
- echo -n "refresh."
- pg_wait $((GLITE_RTM_TEST_TTL * 3 / 4)) "SELECT notifid FROM notifs WHERE notifid IS NOT NULL AND refresh>'$refresh'" $n_notifs || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
-
- ok=1
- echo "OK"
-}
-
-
-test_jdl() {
- ok=0
-
-# kill_daemons
-# cleanup_mysql && cleanup_pg || return $?
-# run_daemons || return $?
-
- # need to wait for notifications to avoid bootstrap
- echo -n "notifs."
- pg_wait 20 "SELECT refresh FROM notifs WHERE notifid IS NOT NULL" $n_notifs || return $?
- refresh=`echo "$result" | head -n 1`
- if [ -z "$refresh" ]; then
- echo "FAIL"
- return 0
- fi
- echo -n "OK "
-
- echo -n "submitted..."
- reg || return $?
- pg_wait 10 "SELECT jobid, state FROM jobs WHERE state='Submitted'" || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
- echo -n "OK "
-
- echo -n "waiting..."
- cat > jdl.txt << EOF
-[
- VirtualOrganisation = "TestingVO";
-]
-EOF
- ev -s NetworkServer -e Accepted --from='UserInterface' --from_host=`hostname -f` --from_instance="pid$$" || return $?
- ev -s NetworkServer -e EnQueued --queue "very long and chaotic queue" --job=`pwd`/jdl.txt --result START || return $?
- ev -s NetworkServer -e EnQueued --queue "very long and chaotic queue" --job="`cat jdl.txt`" --result OK || return $?
- pg_wait 10 "SELECT jobid, state FROM jobs WHERE state='Waiting'" || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
- echo -n "OK "
-
- echo -n "waiting and VO..."
- pg_wait 10 "SELECT jobid, state FROM jobs WHERE state='Waiting' AND vo='TestingVO'" || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
- echo -n "OK "
-
- #
- # test JDL via VO change
- #
- # never do it at home ;-)
- #
-
- echo -n "changed JDL..."
- ev -s NetworkServer -e EnQueued --queue "very long and chaotic queue" --job="[ VirtualOrganisation=\"TestingVO2\";]" --result OK || return $?
- pg_wait 10 "SELECT jobid, state FROM jobs WHERE state='Waiting' AND vo='TestingVO2'" || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
- echo -n "OK"
-
- echo -n "changed after waiting..."
- ev -s WorkloadManager -e EnQueued --queue "very long and chaotic queue" --destination LogMonitor --dest_host localhost --dest_instance pid$$ --job "(car 'testing=true)" --result=OK || return $?
- pg_wait 10 "SELECT jobid, state FROM jobs WHERE state='Ready' AND vo='TestingVO2'" || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
- echo -n "ready..."
- ev -s NetworkServer -e EnQueued --queue "very long and chaotic queue" --job="[ VirtualOrganisation=\"TestingVO3\";]" --result OK || return $?
- pg_wait 10 "SELECT jobid, state FROM jobs WHERE state='Waiting' AND vo='TestingVO3'" || return $?
- if [ -z "$result" ]; then
- echo "FAIL"
- return 0
- fi
-
- ok=1
- echo "OK"
-}
-
-
-quit() {
- if [ x"$started" = x"" ]; then
- kill_daemons
- drop_db
- fi
- exit 1
-}
-
-
-fatal() {
- echo "Fatal error, end"
- quit
-}
-
-
-start() {
- echo -n "Launch: "
- create_db || fatal
- run_daemons || fatal
- echo "OK"
- started=1
-}
-
-
-stop() {
- kill_daemons
- drop_db
-}
-
-
-test() {
- echo -n "Basic: "
- test_basic || fatal
- if [ $ok != 1 ]; then quit; fi
-
- echo -n "Rebind: "
- test_rebind || fatal
- if [ $ok != 1 ]; then quit; fi
-
- echo -n "Cleanup: "
- test_cleanup || fatal
- if [ $ok != 1 ]; then quit; fi
-
- echo -n "Refresh: "
- test_refresh || fatal
- if [ $ok != 1 ]; then quit; fi
-
- echo -n "JDL: "
- test_jdl || fatal
- if [ $ok != 1 ]; then quit; fi
-}
-
-
-case x"$1" in
-xstart)
- init
- start
- ;;
-
-xstop)
- init
- stop
- ;;
-
-xtest)
- init
- test
- ;;
-
-x)
- init
- start
- test
- stop
- ;;
-
-*)
- usage
- exit 1
-esac
+++ /dev/null
---
--- Inicialization (replace pgsql by actual postgres superuser):
---
--- 1) grant privileges, someting like this in $data/pg_hba.conf:
--- local all all trust
---
--- 2) create user:
--- createuser -U pgsql rtm
---
--- 3) crate database:
--- createuser -U pgsql rtm
---
--- 4) create tables:
--- psql -U rtm rtm < test.sql
---
-
-CREATE TABLE "jobs" (
- jobid VARCHAR PRIMARY KEY,
- lb VARCHAR,
- ce VARCHAR,
- queue VARCHAR,
- rb VARCHAR,
- ui VARCHAR,
- state VARCHAR,
- state_entered TIMESTAMP,
- rtm_timestamp TIMESTAMP,
- active BOOLEAN,
- state_changed BOOLEAN,
- registered TIMESTAMP,
- vo VARCHAR
-);
-
-CREATE TABLE "lb20" (
- ip TEXT NOT NULL,
- branch TEXT NOT NULL,
- serv_version TEXT NOT NULL,
- monitored BOOLEAN DEFAULT FALSE,
- last_seen DATE,
- first_seen DATE,
-
- PRIMARY KEY(ip)
-);
-
-CREATE TABLE "notifs" (
- lb VARCHAR,
- port INTEGER,
- notifid VARCHAR,
- notiftype VARCHAR,
- valid TIMESTAMP,
- refresh TIMESTAMP,
- last_update TIMESTAMP,
- errors INTEGER,
-
- PRIMARY KEY(lb, port, notiftype)
-);
+++ /dev/null
-1.0.0-1
-- Initial version
-
+++ /dev/null
-L&B Harvester gathers information about jobs from L&B servers using effective L&B notification mechanism. It manages notifications and keeps them in a persistent storage (file or database table) to reuse later on next launch. It takes care about refreshing notifications and queries L&B servers back when some notification expires.
-
-The tool was initially written for Real Time Monitor (project at Imperial College in London), later was extended with messaging mechanism for WLCG.
+++ /dev/null
-Enhanced L&B notification client.
+++ /dev/null
-module.version=1.0.0
-module.age=1
+++ /dev/null
-#ident "$Header$"
-
-/*
- * Real time monitor.
- */
-
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/wait.h>
-#include <assert.h>
-#include <getopt.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <syslog.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <time.h>
-#include <glite/security/glite_gss.h>
-#ifdef WITH_LBU_DB
-#include <glite/lbu/trio.h>
-#include <glite/lbu/db.h>
-#endif
-#include <glite/lb/context.h>
-#ifndef WITH_OLD_LB
-#include <glite/lb/connpool.h>
-#endif
-#include <glite/lb/notification.h>
-#include <glite/lb/consumer.h>
-
-
-// default number of the threads/sockets
-#define RTM_THREADS 5
-// requested notification life in seconds
-#define RTM_NOTIF_TTL 86400
-// consider end of the notification life sooner
-#define RTM_NOTIF_TTL_TO_DEAD 2
-// poll timeout in seconds
-#define RTM_NOTIF_READ_TIMEOUT 5
-// recheck LB server after error in seconds
-#define RTM_ERROR_REPEAT_RATE 120
-// initial read loop time (can be infinity)
-#define RTM_NOTIF_LOOP_MAX_TIME 1800
-// idle "quit" poll
-#define RTM_IDLE_POLL_TIME 0.5
-// purge & summary jobs poll time
-#define RTM_SUMMARY_POLL_TIME 600
-// preventive suicide against memleaks and ugly things (12 h)
-#define RTM_SUICIDE_TIME 43200
-
-#define RTM_SUMMARY_JOBS 100
-
-#define RTM_DB_TABLE_JOBS "jobs"
-#define RTM_DB_TABLE_LBS "lb20"
-#define DBPAR(N) ("$" (N))
-#define DBAMP "\""
-
-// debug message level: insane, debug, progress, warning, error
-#define INS 4
-#define DBG 3
-#define INF 2
-#define WRN 1
-#define ERR 0
-#define DEBUG_LEVEL_MASK 7
-#define DEBUG_GUARD_MASK 8
-
-// internal quit codes
-#define RTM_QUIT_RUN 0
-#define RTM_QUIT_CLEANUP 1
-#define RTM_QUIT_PRESERVE 2
-#define RTM_QUIT_RELOAD 3
-
-// exit codes
-#define RTM_EXIT_OK 0
-#define RTM_EXIT_RELOAD 1
-#define RTM_EXIT_ERROR 2
-
-#define RTM_NOTIF_TYPE_STATUS 1
-#define RTM_NOTIF_TYPE_JDL 2
-#define RTM_NOTIF_TYPE_OLD 3
-#define RTM_NOTIF_TYPE_DONE 4
-
-#ifdef RTM_NO_COLORS
-#define RTM_TTY_RED ""
-#define RTM_TTY_GREEN ""
-#define RTM_TTY_RST ""
-#else
-#define RTM_TTY_RED "\e[1;31m"
-#define RTM_TTY_GREEN "\e[1;32m"
-#define RTM_TTY_RST "\e[0;39m"
-#endif
-
-#ifndef LINE_MAX
-#define LINE_MAX 1023
-#endif
-
-#define RTM_FILE_NOTIFS "/var/tmp/notifs.txt"
-#define RTM_FILE_NOTIF_PRINTF "%s\t%s\t%s\t%s\t%s\t%d\n"
-#define RTM_FILE_NOTIF_SCANF "%511[^\t]\t%511[^\t]\t%511[^\t]\t%511[^\t]\t%511[^\t]\t%511[^\t\r\n]\n"
-#define RTM_FILE_NOTIF_NUM 6
-
-#define WLCG_FILENAME_TEMPLATE "/tmp/wlcg_%02d_XXXXXX"
-#define WLCG_COMMAND_MESSAGE "/opt/lcg/bin/msg-publish -c /opt/lcg/etc/msg-publish.conf org.wlcg.usage.jobStatus %s"
-#define WLCG_BINARY "/usr/bin/msg-publish"
-#define WLCG_CONFIG "/etc/msg-publish/msg-publish.conf"
-#define WLCG_TOPIC "org.wlcg.usage.jobStatus"
-
-
-#ifdef WITH_OLD_LB
-#define glite_jobid_t edg_wlc_JobId
-#define glite_jobid_create edg_wlc_JobIdCreate
-#define glite_jobid_recreate edg_wlc_JobIdRecreate
-#define glite_jobid_dup edg_wlc_JobIdDup
-#define glite_jobid_free edg_wlc_JobIdFree
-#define glite_jobid_parse edg_wlc_JobIdParse
-#define glite_jobid_unparse edg_wlc_JobIdUnparse
-#define glite_jobid_getServer edg_wlc_JobIdGetServer
-#define glite_jobid_getServerParts edg_wlc_JobIdGetServerParts
-#define glite_jobid_getUnique edg_wlc_JobIdGetUnique
-#define edg_wll_NotifNew(CTX, CONDS, FLAGS, SOCK, LADDR, ID, VALID) edg_wll_NotifNew((CTX), (CONDS), (SOCK), (LADDR), (ID), (VALID))
-#define edg_wll_JDLField(STAT, NAME) NULL
-#ifndef GLITE_JOBID_DEFAULT_PORT
-#define GLITE_JOBID_DEFAULT_PORT GLITE_WMSC_JOBID_DEFAULT_PORT
-#endif
-#endif
-
-// TODO: ipv6? :-)
-
-typedef struct {
- edg_wll_NotifId id; // notification context (after bootstrap/rebind)
- char *id_str; // notification id string
- int type; // for distinguish various notifications on one LB
- char *server; // LB server hostname
- unsigned int port; // LB server port
- time_t valid; // maximal validity of the notification
- time_t refresh; // when try to refresh (before expiration),
- // used for retry time after error too
- double last_update; // last change from the server
- int active; // helper (compare LB servers and notifications,
- // if to save to the persistent storage)
- int error; // errors counter
-} notif_t;
-
-typedef struct {
- int id;
- pthread_t thread;
- notif_t *notifs;
- int nservers;
- time_t next_refresh;
- char time_s[100];
- char *dash_filename;
- int dash_fd;
-#ifdef WITH_LBU_DB
- glite_lbu_DBContext dbctx;
- glite_lbu_Statement insertcmd, updatecmd, updatecmd_vo, updatecmd_mon;
- int dbcaps;
-#endif
-} thread_t;
-
-typedef struct {
- char *local_address;
- int nthreads;
- char *config_file;
- char *notif_file;
- int debug;
- int guard;
- int daemonize;
- char *pidfile;
- int dive;
- char *dbcs; // DB connection string
- char *cert, *key;
- int ttl; // requested time to live (validity) of the notifications
- int cleanup; // if to clean up notifications on LB servers
- int wlcg; // dashboard messaging
- int wlcg_no_remove; // don't remove temporary files (for debugging)
- char *wlcg_binary; // path msg-publish binary
- char *wlcg_config; // msg config file
- char *wlcg_topic; // msg topic
- int wlcg_flush; // send message for eachnotification
- int silly; // old LB 1.9 mode
-
- int nservers;
- notif_t *notifs;
-} config_t;
-
-typedef struct {
- notif_t *notifs;
- int n, maxn;
- pthread_mutex_t lock;
- double last_check;
- int was_summary; // flag for debugging
-#ifdef WITH_LBU_DB
- glite_lbu_DBContext dbctx;
-#endif
-} db_t;
-
-
-static const char rcsid[] = "@(#)$Id$";
-
-static int rtm2syslog[] = {
- LOG_ERR,
- LOG_WARNING,
- LOG_INFO,
- LOG_DEBUG,
- LOG_DEBUG,
-};
-
-static const struct option opts[] = {
- { "wlcg-binary", required_argument, NULL, 0},
- { "wlcg-config", required_argument, NULL, 0},
- { "wlcg-topic", required_argument, NULL, 0},
- { "wlcg-flush", no_argument, NULL, 0},
- { "help", no_argument, NULL, 'h'},
- { "version", no_argument, NULL, 'v'},
- { "threads", required_argument, NULL, 's'},
- { "debug", required_argument, NULL, 'd'},
- { "daemonize", no_argument, NULL, 'D'},
- { "pidfile", required_argument, NULL, 'i'},
- { "ttl", required_argument, NULL, 't'},
- { "history", required_argument, NULL, 'H'},
- { "config", required_argument, NULL, 'c'},
- { "notifs", required_argument, NULL, 'n'},
- { "port", required_argument, NULL, 'p'},
- { "pg", required_argument, NULL, 'm'},
- { "cert", required_argument, NULL, 'C'},
- { "key", required_argument, NULL, 'K'},
- { "wlcg", no_argument, NULL, 'w'},
- { "old", no_argument, NULL, 'o'},
- { "cleanup", no_argument, NULL, 'l'},
- { NULL, no_argument, NULL, 0}
-};
-
-static const char *opts_line = "hvs:d:Di:t:H:c:n:p:m:C:K:wo";
-
-config_t config = {
- local_address: NULL,
- nthreads: RTM_THREADS,
- config_file: NULL,
- notif_file: NULL,
- debug: DBG,
- guard: 1,
- dive: 10800,
- dbcs: NULL,
- cert: NULL,
- key: NULL,
- ttl: RTM_NOTIF_TTL,
- cleanup: 0,
- wlcg: 0,
- silly: 0,
-
- nservers: 0,
- notifs: NULL,
-};
-db_t db = {
- notifs: NULL,
- n: 0,
- maxn: 0,
- lock: PTHREAD_MUTEX_INITIALIZER,
-#ifdef WITH_LBU_DB
- dbctx: NULL
-#endif
-};
-thread_t *threads = NULL;
-volatile sig_atomic_t quit = RTM_QUIT_RUN;
-
-static int listen_port = 0;
-
-#define lprintf(T, LEVEL, FMT, ARGS...) \
- if ((LEVEL) <= config.debug) lprintf_func((T), (LEVEL), (FMT), ##ARGS)
-#define lprintf_ctx(T, LEVEL, CTX, FMT, ARGS...) \
- if ((LEVEL) <= config.debug) lprintf_ctx_func((T), (CTX), (LEVEL), (FMT), ##ARGS)
-#define lprintf_dbctx(T, LEVEL, FMT, ARGS...) \
- if ((LEVEL) <= config.debug) lprintf_dbctx_func((T), (LEVEL), (FMT), ##ARGS)
-
-#ifdef WITH_OLD_LB
-int edg_wll_gss_initialize() {
- if (globus_module_activate(GLOBUS_GSI_GSSAPI_MODULE) != GLOBUS_SUCCESS) return EINVAL;
- return 0;
-}
-#endif
-
-void lvprintf_func(thread_t *t, const char *description, int level, const char *fmt, va_list ap) {
- char prefix[10];
- char *msg, *line;
-
- if (t) snprintf(prefix, sizeof prefix, "[%02d]", t->id);
- else memcpy(prefix, "[main]", 8);
- vasprintf(&msg, fmt, ap);
- if (description) asprintf(&line, "%s %s, %s\n", prefix, msg, description);
- else asprintf(&line, "%s %s\n", prefix, msg);
- free(msg);
-
- if (level <= WRN && !config.daemonize) fprintf(stderr, RTM_TTY_RED);
- if (config.daemonize) {
- openlog(NULL, LOG_PID | LOG_CONS, LOG_DAEMON);
- syslog(rtm2syslog[level], "%s", line);
- closelog();
- } else {
- fputs(line, stderr);
- }
- if (level <= WRN && !config.daemonize) fprintf(stderr, RTM_TTY_RST);
-
- free(line);
-}
-
-
-void lprintf_func(thread_t *t, int level, const char *fmt, ...) {
- va_list ap;
-
- va_start(ap, fmt);
- lvprintf_func(t, NULL, level, fmt, ap);
- va_end(ap);
-}
-
-
-void lprintf_ctx_func(thread_t *t, edg_wll_Context ctx, int level, const char *fmt, ...) {
- va_list ap;
- char *errText, *errDesc, *s;
-
- va_start(ap, fmt);
- edg_wll_Error(ctx, &errText, &errDesc);
- asprintf(&s, "%s: %s", errText, errDesc);
- lvprintf_func(t, s, level, fmt, ap);
- free(errText);
- free(errDesc);
- free(s);
- va_end(ap);
-}
-
-
-#ifdef WITH_LBU_DB
-void lprintf_dbctx_func(thread_t *t, int level, const char *fmt, ...) {
- va_list ap;
- char *errText = NULL, *errDesc = NULL, *s = NULL;
- glite_lbu_DBContext dbctx = t ? t->dbctx : db.dbctx;
-
- va_start(ap, fmt);
- if (dbctx) {
- glite_lbu_DBError(dbctx, &errText, &errDesc);
- asprintf(&s, "%s: %s", errText, errDesc);
- }
- lvprintf_func(t, s, level, fmt, ap);
- free(errText);
- free(errDesc);
- free(s);
- va_end(ap);
-}
-#endif
-
-#ifndef WITH_LBU_DB
-time_t glite_lbu_StrToTime(const char *str) {
- struct tm tm;
-
- memset(&tm,0,sizeof(tm));
- putenv("TZ=UTC"); tzset();
- sscanf(str,"%4d-%02d-%02d %02d:%02d:%02d",
- &tm.tm_year,&tm.tm_mon,&tm.tm_mday,
- &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
- tm.tm_year -= 1900;
- tm.tm_mon--;
-
- return mktime(&tm);
-}
-
-double glite_lbu_StrToTimestamp(const char *str) {
- struct tm tm;
- double sec;
-
- memset(&tm,0,sizeof(tm));
- putenv("TZ=UTC"); tzset();
- sscanf(str,"%4d-%02d-%02d %02d:%02d:%lf",
- &tm.tm_year,&tm.tm_mon,&tm.tm_mday,
- &tm.tm_hour,&tm.tm_min,&sec);
- tm.tm_year -= 1900;
- tm.tm_mon--;
- tm.tm_sec = sec;
-
- return (sec - tm.tm_sec) + mktime(&tm);
-}
-#endif
-
-
-// hacky time->string conversion
-char *time2str(thread_t *t, time_t time) {
- struct tm tm;
-
- if ((int)time <= 0) memcpy(t->time_s, "-", sizeof("-"));
- else {
- localtime_r(&time, &tm);
- strftime(t->time_s, sizeof(t->time_s), "%F %T", &tm);
- }
- return t->time_s;
-}
-
-
-double rtm_gettimeofday() {
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
- return tv.tv_sec + tv.tv_usec / 1000000.0;
-}
-
-
-void rtm_time2str(time_t t, char **str) {
- struct tm *tm;
-
- if (t) {
- tm = gmtime(&t);
- asprintf(str,"%4d-%02d-%02d %02d:%02d:%02d",tm->tm_year+1900,tm->tm_mon+1,
- tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
- } else
- *str = strdup("-");
-}
-
-
-void rtm_timestamp2str(double t, char **str) {
- time_t tsec = t;
- struct tm *tm = gmtime(&tsec);
-
- if (t) {
- t = t - tsec + tm->tm_sec;
- asprintf(str,"%4d-%02d-%02d %02d:%02d:%02.09f",tm->tm_year+1900,tm->tm_mon+1,
- tm->tm_mday,tm->tm_hour,tm->tm_min,t);
- } else
- *str = strdup("-");
-}
-
-
-int rtm_str2time(const char *s) {
- time_t t;
-
- if (s && memcmp(s, "-", 2) != 0) {
- t = glite_lbu_StrToTime(s);
- if (t == (time_t)-1) return 0;
- } else
- t = 0;
-
- return t;
-}
-
-
-int rtm_str2timestamp(const char *s) {
- double t;
-
- if (s && memcmp(s, "-", 2) != 0) {
- t = glite_lbu_StrToTimestamp(s);
- if (t <= 0.5) return 0.0;
- } else
- t = 0.0;
-
- return t;
-}
-
-
-int rtm_str2notiftype(const char *str) {
- if (strcasecmp(str, "STATUS") == 0) return RTM_NOTIF_TYPE_STATUS;
- if (strcasecmp(str, "DONE") == 0) return RTM_NOTIF_TYPE_DONE;
- if (strcasecmp(str, "JDL") == 0) return RTM_NOTIF_TYPE_JDL;
- if (strcasecmp(str, "OLD") == 0) return RTM_NOTIF_TYPE_OLD;
- return -1;
-}
-
-
-const char *rtm_notiftype2str(int type) {
- switch (type) {
- case RTM_NOTIF_TYPE_STATUS: return "STATUS";
- case RTM_NOTIF_TYPE_DONE: return "DONE";
- case RTM_NOTIF_TYPE_JDL: return "JDL";
- case RTM_NOTIF_TYPE_OLD: return "OLD";
- default: return NULL;
- }
-}
-
-
-void wlcg_timeval2str(struct timeval *t, char **str) {
- struct tm *tm;
-
- tm = gmtime(&t->tv_sec);
- asprintf(str,"%4d-%02d-%02dT%02d:%02d:%02dZ",tm->tm_year+1900,tm->tm_mon+1,
- tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
-}
-
-
-int wlcg_store_message(thread_t *t, __attribute((unused))notif_t *notif, edg_wll_JobStat *stat) {
- unsigned int port;
- int status = 0;
- char *jobid_str = NULL, *state_str = NULL, *vo = NULL, *lbhost = NULL;
- char *wlcg_last_update_time_str = NULL, *wlcg_state_start_time_str = NULL;
-
- jobid_str = stat->jobId ? glite_jobid_unparse(stat->jobId) : strdup("Unknown");
- glite_jobid_getServerParts(stat->jobId, &lbhost, &port);
- state_str = edg_wll_StatToString(stat->state);
- vo = edg_wll_JDLField(stat,"VirtualOrganisation") ? : strdup("Unknown");
-
- if (!t->dash_filename || !t->dash_fd) {
- free(t->dash_filename);
- asprintf(&t->dash_filename, WLCG_FILENAME_TEMPLATE, t->id);
- if ((t->dash_fd = mkstemp(t->dash_filename)) == -1) {
- status = errno;
- lprintf(t, ERR, "can't create temporary file '%s': %s", t->dash_filename, strerror(status));
- free(t->dash_filename);
- t->dash_filename = NULL;
- goto quit;
- }
- }
-
- wlcg_timeval2str(&stat->lastUpdateTime, &wlcg_last_update_time_str);
- wlcg_timeval2str(&stat->stateEnterTime, &wlcg_state_start_time_str);
-
- dprintf(t->dash_fd, "jobId: %s\n\
-stateName: %s\n\
-ownerDN: %s\n\
-voname: %s\n\
-bkHost: %s:%d\n\
-networkHost: %s\n\
-lastUpdateTime: %s\n\
-stateStartTime: %s\n\
-exitCode: %d\n\
-DoneCode: %d\n\
-destSite: %s\n\
-condorId: %s\n\
-StatusReason: %s\n\
-EOT\n", jobid_str, state_str, stat->owner, vo, lbhost, port, stat->network_server ? : "unknown", wlcg_last_update_time_str, wlcg_state_start_time_str, stat->exit_code, stat->done_code, stat->destination ? : "NULLByPublisher", stat->condorId ? : "0", stat->reason && stat->reason[strspn(stat->reason, " \t\n\r")] != '\0' ? stat->reason : "UNAVAILABLE By Publisher");
-
- free(wlcg_last_update_time_str);
- free(wlcg_state_start_time_str);
-quit:
- free(jobid_str);
- free(lbhost);
- free(state_str);
- free(vo);
- return status;
-}
-
-
-int wlcg_send_message(thread_t *t) {
- int status = 0;
- char *command;
-
- // WLCG message
- if (t->dash_fd) { // send only if anything to send
- close(t->dash_fd);
- asprintf(&command, "'%s' -c '%s' '%s' '%s'", config.wlcg_binary, config.wlcg_config, config.wlcg_topic, t->dash_filename);
- lprintf(t, DBG, "calling %s", command);
- switch (vfork()) {
- case 0:
- if (execlp("/bin/sh", "/bin/sh", "-c", command, NULL) == -1) {
- lprintf(t, ERR, "can't exec '%s':%s", command, strerror(errno));
- }
- _exit(1);
- break;
- case -1:
- lprintf(t, ERR, "can't fork: %s", strerror(errno));
- break;
- default:
- break;
- }
- wait(&status);
- free(command);
- if (WIFEXITED(status)) {
- status = WEXITSTATUS(status);
- if (status) {
- lprintf(t, WRN, "%s exited with %d", config.wlcg_binary, status);
- } else {
- lprintf(t, INF, "%s exited successfully", config.wlcg_binary);
- if (!config.wlcg_no_remove) remove(t->dash_filename);
- }
- } else {
- lprintf(t, ERR, "%s not exited normally", config.wlcg_binary);
- status = -1;
- }
- free(t->dash_filename);
- t->dash_filename = NULL;
- t->dash_fd = 0;
- }
-
- return status;
-}
-
-
-void notif_free(notif_t *notif) {
- edg_wll_NotifIdFree(notif->id);
- free(notif->id_str);
- free(notif->server);
- memset(notif, 0, sizeof(notif_t));
-}
-
-
-void notif_invalidate(notif_t *notif) {
- edg_wll_NotifIdFree(notif->id);
- free(notif->id_str);
- notif->id = NULL;
- notif->id_str = NULL;
- notif->error = 0;
-}
-
-
-int notif_copy(notif_t *dest, notif_t *src) {
- if (!src || !dest) return EINVAL;
- memset(dest, 0, sizeof(notif_t));
- if (src->id) dest->id = edg_wll_NotifIdDup(src->id);
- if (src->id_str) dest->id_str = strdup(src->id_str);
- dest->type = src->type;
- if (src->server) dest->server = strdup(src->server);
- dest->port = src->port;
- dest->valid = src->valid;
- dest->refresh = src->refresh;
- dest->last_update = src->last_update;
- dest->active = src->active;
- dest->error = src->error;
- return 0;
-}
-
-
-#ifdef WITH_LBU_DB
-static int db_init(thread_t *t, glite_lbu_DBContext *dbctx) {
- int err, dbcaps;
-
- if (config.dbcs) {
- if ((err = glite_lbu_InitDBContext(dbctx, GLITE_LBU_DB_BACKEND_PSQL)) != 0) {
- lprintf_dbctx(t, ERR, "can't initialize DB context");
- return err;
- }
- while ((err = glite_lbu_DBConnect(*dbctx, config.dbcs)) != 0 && !quit) {
- lprintf_dbctx(t, ERR, "can't connect to '%s'", config.dbcs);
- lprintf(t, INF, "still trying...");
- sleep(5);
- }
- if (err == 0) {
- if ((dbcaps = glite_lbu_DBQueryCaps(*dbctx)) == -1) {
- lprintf_dbctx(t, ERR, "can't get database capabilities");
- dbcaps = 0;
- }
- lprintf(t, INF, "DB connected, cs: %s, capabilities: %d", config.dbcs, dbcaps);
- if (t == NULL && (dbcaps & GLITE_LBU_DB_CAP_PREPARED) == 0) {
- lprintf(NULL, WRN, "postgresql server doesn't support SQL prepared commands, recommended version >= 8.2");
- }
- if (t) t->dbcaps = dbcaps;
- return 0;
- } else {
- glite_lbu_FreeDBContext(*dbctx);
- return err;
- }
- } else {
- lprintf(t, DBG, "no DB configured (--pg option)");
- return -1;
- }
-}
-
-
-static void db_free(__attribute((unused))thread_t *t, glite_lbu_DBContext dbctx) {
- if (dbctx) {
- glite_lbu_DBClose(dbctx);
- glite_lbu_FreeDBContext(dbctx);
- }
-}
-#endif
-
-
-static notif_t *db_add_notif(char *notifid, int type, time_t valid, time_t refresh, double last_update, char *server, int port, int active, int errors) {
- void *tmp;
- notif_t *notif;
-
- if (db.n >= db.maxn) {
- db.maxn = db.n + 20;
- if ((tmp = realloc(db.notifs, db.maxn * sizeof(notif_t))) == NULL) return NULL;
- db.notifs = (notif_t *)tmp;
- memset(db.notifs + db.n, 0, (db.maxn - db.n) * sizeof(notif_t));
- }
- notif = db.notifs + db.n;
- notif->id_str = notifid;
- notif->type = type;
- notif->valid = valid;
- notif->refresh = refresh;
- notif->last_update = last_update;
- notif->server = server;
- notif->port = port;
- notif->active = active;
- notif->error = errors;
- db.n++;
-
- return notif;
-}
-
-
-static int db_save_notifs_file(thread_t *t) {
- FILE *f;
- char *filename = NULL;
- int retval = 1;
- notif_t *notif;
- int i;
- char *valid_str = NULL, *refresh_str = NULL, *last_update_str = NULL, *id_str = NULL;
-
- asprintf(&filename, "%s-new", config.notif_file);
- if ((f = fopen(filename, "wt")) == NULL) {
- lprintf(t, ERR, "can't write '%s': %s", filename, strerror(errno));
- goto quit;
- }
-
- for (i = 0; i < db.n; i++) {
- notif = db.notifs + i;
- if (!notif->active) {
- lprintf(t, DBG, "not saving inactive notif %s (%s), server %s:%d", notif->id_str, rtm_notiftype2str(notif->type), notif->server, notif->port);
- continue;
- }
-
- if (notif->id_str) id_str = strdup(notif->id_str);
- else if (notif->error) asprintf(&id_str, "%s:%d", notif->server, notif->port);
- if (id_str) {
- rtm_time2str(notif->valid, &valid_str);
- rtm_time2str(notif->refresh, &refresh_str);
- rtm_timestamp2str(notif->last_update, &last_update_str);
-
- fprintf(f, RTM_FILE_NOTIF_PRINTF, id_str, rtm_notiftype2str(notif->type), valid_str, refresh_str, last_update_str, notif->error);
-
- free(valid_str); valid_str = NULL;
- free(refresh_str); refresh_str = NULL;
- free(last_update_str); last_update_str = NULL;
- }
- free(id_str);
- id_str = NULL;
- }
- fclose(f);
- if (rename(filename, config.notif_file) != 0) {
- lprintf(t, ERR, "can't move new notification file '%s' to '%s': %s", filename, config.notif_file, strerror(errno));
- goto quit;
- }
- retval = 0;
-quit:
- free(filename);
- free(valid_str);
- free(refresh_str);
- free(last_update_str);
- return 0;
-}
-
-
-#if defined(WITH_RTM_SQL_STORAGE) && defined(WITH_LBU_DB)
-static int db_save_notifs_sql(thread_t *t) {
- int retval = 1;
- notif_t *notif;
- int i;
- char *sql = NULL, *valid_str = NULL, *refresh_str = NULL, *last_update_str = NULL;
- const char *type_str, *amp;
-
- for (i = 0; i < db.n; i++) {
- notif = db.notifs + i;
-/*
- if (!notif->active) {
- lprintf(t, INS, "not saving inactive notif %s (%s:%d)", notif->id_str, notif->server, notif->port);
- continue;
- }
-*/
- type_str = rtm_notiftype2str(notif->type);
- if (notif->id_str || notif->error) {
- if (notif->valid) glite_lbu_TimeToDB(db.dbctx, notif->valid, &valid_str);
- else valid_str = strdup("NULL");
- if (notif->refresh) glite_lbu_TimeToDB(db.dbctx, notif->refresh, &refresh_str);
- else refresh_str = strdup("NULL");
- if (notif->last_update) glite_lbu_TimestampToDB(db.dbctx, notif->last_update, &last_update_str);
- else last_update_str = strdup("NULL");
- amp = notif->id_str ? "'" : " ";
- trio_asprintf(&sql, "UPDATE notifs SET notifid=%s%|Ss%s, valid=%s, refresh=%s, last_update=%s, errors=%d WHERE lb='%|Ss' AND port=%d AND notiftype='%|Ss'", amp, notif->id_str ? : "NULL", amp, valid_str, refresh_str, last_update_str, notif->error, notif->server, notif->port, type_str);
- switch (glite_lbu_ExecSQL(db.dbctx, sql, NULL)) {
- case 0:
- // not found - insert
- // can be handy when using file as input of LBs
- free(sql);
- trio_asprintf(&sql, "INSERT INTO notifs (lb, port, notifid, notiftype, valid, refresh, last_update, errors) VALUES ('%|Ss', %d, %s%|Ss%s, '%|Ss', %s, %s, %s, %d)", notif->server, notif->port, amp, notif->id_str ? : "NULL", amp, type_str, valid_str, refresh_str, last_update_str, notif->error);
- switch (glite_lbu_ExecSQL(db.dbctx, sql, NULL)) {
- case -1:
- lprintf_dbctx(t, ERR, "notif '%s' (%s) insert failed", notif->id_str, type_str);
- goto quit;
- case 0:
- lprintf(t, ERR, "notif '%s' (%s) not inserted for unknown reason", type_str);
- break;
- default:
- lprintf(t, INS, "notif '%s' (%s) inserted", notif->id_str, type_str);
- break;
- }
- break;
- case -1:
- lprintf_dbctx(t, ERR, "notif '%s' (%s) update failed", notif->id_str, type_str);
- goto quit;
- default:
- lprintf(t, INS, "notif '%s' updated", notif->id_str);
- break;
- }
- } else {
- trio_asprintf(&sql, "UPDATE notifs SET notifid=NULL, valid=NULL, refresh=NULL, last_update=NULL WHERE lb='%|Ss' AND port=%d AND notiftype='%|Ss'", notif->server, notif->port, type_str);
- switch (glite_lbu_ExecSQL(db.dbctx, sql, NULL)) {
- case 0:
- lprintf(t, INS, "cleared %s notif for %s:%d not found, ok", type_str, notif->server, notif->port);
- break;
- case -1:
- lprintf_dbctx(t, ERR, "clearing notif %s for %s:%d failed", type_str, notif->server, notif->port);
- goto quit;
- default:
- lprintf(t, INS, "cleared notif %s for %s:%d", type_str, notif->server, notif->port);
- break;
- }
- }
- free(sql); sql = NULL;
- free(valid_str); valid_str = NULL;
- free(refresh_str); refresh_str = NULL;
- free(last_update_str); last_update_str = NULL;
- }
- retval = 0;
-quit:
- free(sql);
- free(valid_str);
- free(refresh_str);
- free(last_update_str);
- return 0;
-}
-#endif
-
-
-static int db_save_notifs(thread_t *t) {
-#if 0
- int i;
-
- for (i = 0; i < db.n; i++) {
- notif_t *notif = db.notifs + i;
- lprintf(NULL, DBG, "save: %s (%s), server: %s:%d, active: %d", notif->id_str, rtm_notiftype2str(notif->type), notif->server, notif->port, notif->active);
- }
-#endif
-
-#if defined(WITH_LBU_DB)
- int i, ret;
- notif_t *notif;
-
- //
- // Keep monitored flag when:
- // 1) used and opened DB
- // 2) LB servers not from config file
- //
- if (t && t->dbctx && !config.config_file) {
- for (i = 0; i < t->nservers; i++) {
- notif = t->notifs + i;
-
- if (notif->type == RTM_NOTIF_TYPE_OLD || notif->type == RTM_NOTIF_TYPE_JDL) {
- lprintf(t, DBG, "changing monitored flag of %d. notification for %s:%d to %d", i, notif->server, notif->port, notif->error ? 0 : 1);
- if ((t->dbcaps & GLITE_LBU_DB_CAP_PREPARED) == 0) {
- char *sql;
-
- trio_asprintf(&sql, "UPDATE " DBAMP RTM_DB_TABLE_LBS DBAMP " SET monitored=%s WHERE ip='%|Ss'", notif->error ? "false" : "true", notif->server);
- ret = glite_lbu_ExecSQL(t->dbctx, sql, NULL);
- free(sql);
- } else {
- ret = glite_lbu_ExecPreparedStmt(t->updatecmd_mon, 2,
- GLITE_LBU_DB_TYPE_BOOLEAN, notif->error ? 0 : 1,
- GLITE_LBU_DB_TYPE_VARCHAR, notif->server
- );
- }
- if (ret == -1) {
- lprintf_dbctx(t, ERR, "can't update monitored flag in " RTM_DB_TABLE_LBS " table");
- return 1;
- }
- }
- }
- }
-#endif
-
-#if defined(WITH_RTM_SQL_STORAGE) && defined(WITH_LBU_DB)
- if (!db.dbctx) return db_save_notifs_file(t);
- else return db_save_notifs_sql(t);
-#else
- return db_save_notifs_file(t);
-#endif
-}
-
-
-static notif_t *db_search_notif(notif_t *notifs, int n, const char *notifid) {
- int i;
-
- for (i = 0; i < n && (!notifs[i].id_str || strcmp(notifs[i].id_str, notifid) != 0); i++);
- return i == n ? NULL : notifs + i;
-}
-
-
-static notif_t *db_search_notif_by_server(notif_t *notifs, int n, const char *server, unsigned int port, int type) {
- int i;
-
- for (i = 0; i < n; i++) {
- if (strcmp(notifs[i].server, server) == 0 && notifs[i].port == port && notifs[i].type == type) break;
- }
-
- return i == n ? NULL : notifs + i;
-}
-
-
-static int db_store_change(__attribute((unused))thread_t *t, notif_t *notif, __attribute((unused))int index, edg_wll_JobStat *stat) {
- char *jobid_str = NULL, *state_str = NULL, *sql = NULL, *sql2 = NULL, *state_entered_str = NULL, *rtm_timestamp_str = NULL, *lbhost = NULL, *unique_str = NULL, *regtime_str = NULL,*vo = NULL;
- unsigned int port;
-
- jobid_str = stat->jobId ? glite_jobid_unparse(stat->jobId) : strdup("unknown");
- glite_jobid_getServerParts(stat->jobId, &lbhost, &port);
- unique_str = glite_jobid_getUnique(stat->jobId);
- state_str = edg_wll_StatToString(stat->state);
- vo = edg_wll_JDLField(stat,"VirtualOrganisation");
- printf(RTM_TTY_GREEN "notifid: %s (%s), jobid: %s, state: %s, vo: %s, last time: %lf" RTM_TTY_RST "\n", notif->id_str, rtm_notiftype2str(notif->type), jobid_str, state_str, vo, notif->last_update);
-
-#ifdef WITH_LBU_DB
- if (config.dbcs && t->dbctx) {
- double state_entered, rtm_timestamp;
- char *ce, *queue, *colon, *sql_part;
- const char *rb, *ui, *state, *active, *state_changed, *lb;
- time_t registered;
-
- ce = stat->destination ? : "unknown";
- queue = strchr(ce, '/');
- if (queue) *queue++='\0';
- else queue = "unknown";
- colon = strchr(ce, ':');
- if (colon) colon[0] = '\0';
- rb = stat->network_server ? : "unknown";
- ui = stat->ui_host ? : "unknown";
- state = state_str ? : "unknown";
- state_entered = stat->stateEnterTime.tv_sec + stat->stateEnterTime.tv_usec / 1000000.0;
- rtm_timestamp = rtm_gettimeofday();
- registered = stat->stateEnterTimes[1 + EDG_WLL_JOB_SUBMITTED];
- lb = lbhost;
- active = "true";
- state_changed = "true";
-
- if ((t->dbcaps & GLITE_LBU_DB_CAP_PREPARED) == 0) {
-
- glite_lbu_TimestampToDB(t->dbctx, state_entered, &state_entered_str);
- glite_lbu_TimestampToDB(t->dbctx, rtm_timestamp, &rtm_timestamp_str);
- glite_lbu_TimeToDB(t->dbctx, registered, ®time_str);
-
- if (vo) trio_asprintf(&sql_part, ", vo='%|Ss' ", vo);
- else sql_part = strdup("");
- trio_asprintf(&sql, "UPDATE " RTM_DB_TABLE_JOBS " SET ce='%|Ss', queue='%|Ss', rb='%|Ss', ui='%|Ss', state='%|Ss', state_entered=%s, rtm_timestamp=%s, active=%s, state_changed=%s, registered=%s%sWHERE jobid='%|Ss' AND lb='%|Ss'", ce, queue, rb, ui, state, state_entered_str, rtm_timestamp_str, active, state_changed, regtime_str, sql_part, unique_str, lb);
- free(sql_part);
- lprintf(t, INS, "update: %s", sql);
- switch (glite_lbu_ExecSQL(t->dbctx, sql, NULL)) {
- case -1:
- lprintf_dbctx(t, ERR, "can't get jobs");
- goto quit;
- case 0:
- trio_asprintf(&sql2, "INSERT INTO " RTM_DB_TABLE_JOBS " "
- "(ce, queue, rb, ui, state, state_entered, rtm_timestamp, jobid, lb, active, state_changed, registered, vo) VALUES "
- "('%|Ss', '%|Ss', '%|Ss', '%|Ss', '%|Ss', %s, %s, '%|Ss', '%|Ss', %s, %s, %s, '%|Ss')", ce, queue, rb, ui, state, state_entered_str, rtm_timestamp_str, unique_str, lb, active, state_changed, regtime_str, vo ? : "unknown");
- lprintf(t, INS, "insert: %s", sql2);
- if (glite_lbu_ExecSQL(t->dbctx, sql2, NULL) == -1) {
- lprintf_dbctx(t, ERR, "can't insert job");
- goto quit;
- }
- break;
- default:
- break;
- }
-
- } else { // prepared commands
- int ret;
-
- if (vo) {
- ret = glite_lbu_ExecPreparedStmt(t->updatecmd_vo, 13,
- GLITE_LBU_DB_TYPE_VARCHAR, ce,
- GLITE_LBU_DB_TYPE_VARCHAR, queue,
- GLITE_LBU_DB_TYPE_VARCHAR, rb,
- GLITE_LBU_DB_TYPE_VARCHAR, ui,
- GLITE_LBU_DB_TYPE_VARCHAR, state,
- GLITE_LBU_DB_TYPE_TIMESTAMP, state_entered,
- GLITE_LBU_DB_TYPE_TIMESTAMP, rtm_timestamp,
- GLITE_LBU_DB_TYPE_BOOLEAN, 1, // active
- GLITE_LBU_DB_TYPE_BOOLEAN, 1, // state_changed
- GLITE_LBU_DB_TYPE_TIMESTAMP, (double)registered,
- GLITE_LBU_DB_TYPE_VARCHAR, vo, // VO
-
- GLITE_LBU_DB_TYPE_VARCHAR, unique_str, // jobid
- GLITE_LBU_DB_TYPE_VARCHAR, lb // L&B server
- );
- } else {
- ret = glite_lbu_ExecPreparedStmt(t->updatecmd, 12,
- GLITE_LBU_DB_TYPE_VARCHAR, ce,
- GLITE_LBU_DB_TYPE_VARCHAR, queue,
- GLITE_LBU_DB_TYPE_VARCHAR, rb,
- GLITE_LBU_DB_TYPE_VARCHAR, ui,
- GLITE_LBU_DB_TYPE_VARCHAR, state,
- GLITE_LBU_DB_TYPE_TIMESTAMP, state_entered,
- GLITE_LBU_DB_TYPE_TIMESTAMP, rtm_timestamp,
- GLITE_LBU_DB_TYPE_BOOLEAN, 1, // active
- GLITE_LBU_DB_TYPE_BOOLEAN, 1, // state_changed
- GLITE_LBU_DB_TYPE_TIMESTAMP, (double)registered,
-
- GLITE_LBU_DB_TYPE_VARCHAR, unique_str, // jobid
- GLITE_LBU_DB_TYPE_VARCHAR, lb // L&B server
- );
- }
-
- switch (ret) {
- case -1:
- lprintf_dbctx(t, ERR, "can't update " RTM_DB_TABLE_JOBS " table");
- goto quit;
- case 0:
- if (glite_lbu_ExecPreparedStmt(t->insertcmd, 13,
- GLITE_LBU_DB_TYPE_VARCHAR, ce,
- GLITE_LBU_DB_TYPE_VARCHAR, queue,
- GLITE_LBU_DB_TYPE_VARCHAR, rb,
- GLITE_LBU_DB_TYPE_VARCHAR, ui,
- GLITE_LBU_DB_TYPE_VARCHAR, state,
- GLITE_LBU_DB_TYPE_TIMESTAMP, state_entered,
- GLITE_LBU_DB_TYPE_TIMESTAMP, rtm_timestamp,
- GLITE_LBU_DB_TYPE_VARCHAR, unique_str, // jobid
- GLITE_LBU_DB_TYPE_VARCHAR, lb, // L&B server
- GLITE_LBU_DB_TYPE_BOOLEAN, 1, // active
- GLITE_LBU_DB_TYPE_BOOLEAN, 1, // state_changed
- GLITE_LBU_DB_TYPE_TIMESTAMP, (double)registered,
- GLITE_LBU_DB_TYPE_VARCHAR, vo ? : "unknown" // VO
- ) == -1) {
- lprintf_dbctx(t, ERR, "can't insert to " RTM_DB_TABLE_JOBS " table");
- goto quit;
- }
- break;
- default:
- break;
- }
- } // prepare commands
-
- }
-#endif
-
- // store message
- if (config.wlcg) {
- if (wlcg_store_message(t, notif, stat) != 0) goto quit;
- if (config.wlcg_flush) wlcg_send_message(t);
- }
-
-quit:
- free(jobid_str);
- free(state_str);
- free(sql);
- free(sql2);
- free(state_entered_str);
- free(rtm_timestamp_str);
- free(lbhost);
- free(unique_str);
- free(regtime_str);
- free(vo);
-
- return 0;
-}
-
-
-static int db_summary_getjobids(__attribute((unused))db_t *db, __attribute((unused))int maxn, __attribute((unused))char **jobids, int *n) {
-/*
- switch (db->was_summary) {
- case 0:
- *n = 3;
- jobids[0] = strdup("https://skurut68-2.cesnet.cz:9000/FJldtiAR2EHC12C3Zz8WjQ");
- jobids[1] = strdup("https://skurut68-2.cesnet.cz:9000/AWTCWrUCr3uUh6cuRFaENQ");
- jobids[2] = strdup("https://skurut68-1.cesnet.cz:9000/o73CG2wrNdEQ909mG0Ac1g");
- break;
- case 1:
- *n = 1;
- jobids[0] = strdup("https://skurut68-2.cesnet.cz:9000/-46Qa2ag4gLsA_Ki-3bSLw");
-
- break;
- default: *n = 0; break;
- }
- db->was_summary = (db->was_summary + 1) % 3;
- return 0;
-*/
- *n = 0;
- return 0;
-}
-
-
-static int db_summary_setinfo(__attribute((unused))db_t *db, edg_wll_JobStat *stat) {
- char *jobidstr;
-
- jobidstr = stat->jobId ? glite_jobid_unparse(stat->jobId) : NULL;
- printf(RTM_TTY_GREEN "summary: jobid='%s'" RTM_TTY_RST "\n", jobidstr);
- free(jobidstr);
- return 0;
-}
-
-
-int rtm_summary(edg_wll_Context ctx, db_t *db) {
- char *jobids[RTM_SUMMARY_JOBS];
- edg_wll_QueryRec lbquery[RTM_SUMMARY_JOBS + 1], *qr;
- const edg_wll_QueryRec *lbqueryext[2];
- edg_wll_JobStat *jobstates = NULL;
- int err = 0, ijob = 0, njobs = 0, iquery = 0, k, server_changed = 0;
- glite_jobid_t jid = NULL;
- char *server = NULL, *new_server = NULL;
- unsigned int port = 0, new_port = 0;
-
- lprintf(NULL, INS, "Summary");
-
- lbqueryext[0] = lbquery;
- lbqueryext[1] = NULL;
- memset(lbquery, 0, sizeof(lbquery));
-
- do {
- if (server) {
-
- if ((iquery >= RTM_SUMMARY_JOBS || server_changed || !njobs) && iquery) {
- if ((err = edg_wll_QueryJobsExt(ctx, lbqueryext, 0, NULL, &jobstates)) != 0) {
- lprintf_ctx(NULL, ERR, ctx, "query to '%s:%u' failed: %s", server, port, strerror(err));
- // report error jobids and skip the job (do nothing)
- // TODO
- }
- for (k = 0; k < iquery; k++) glite_jobid_free(lbquery[k].value.j);
-
- if (err == 0) {
- for (k = 0; jobstates[k].state != EDG_WLL_JOB_UNDEF; k++) {
- if ((err = db_summary_setinfo(db, jobstates + k)) != 0) lprintf(NULL, ERR, "Can't store %d. summary info for %s:%u", k, server, port);
- edg_wll_FreeStatus(jobstates + k);
- }
- free(jobstates);
- lprintf(NULL, DBG, "query to '%s:%u' succeed", server, port);
- }
-
- iquery = 0;
- memset(lbquery, 0, sizeof(lbquery));
- if (!njobs) break; // not needed, just spare summary select
-
- server_changed = 0;
- } else {
- lprintf(NULL, DBG, "summary pushed %d. %s\n", iquery, jobids[ijob]);
- qr = lbquery + iquery;
- iquery++;
- qr->attr = EDG_WLL_QUERY_ATTR_JOBID;
- qr->op = EDG_WLL_QUERY_OP_EQUAL;
- glite_jobid_parse(jobids[ijob], &qr->value.j);
- free(jobids[ijob]); jobids[ijob] = NULL;
- ijob++;
- }
-
- } // server
-
- if (ijob >= njobs) {
- ijob = 0;
- memset(jobids, 0, sizeof(jobids));
- njobs = 0;
- if ((err = db_summary_getjobids(db, RTM_SUMMARY_JOBS, jobids, &njobs)) != 0) {
- lprintf(NULL, ERR, "Can't get jobs for the summary");
- return err;
- }
- lprintf(NULL, DBG, "summary for %d jobs", njobs);
- if (!njobs) {
- if (iquery) continue; // do the last query
- else break;
- }
- }
-
- if ((err = glite_jobid_parse(jobids[ijob], &jid)) != 0) {
- lprintf(NULL, ERR, "Can't parse jobid '%s': %s", jobids[ijob], strerror(err));
- // report error jobid and skip the job
- // TODO
- glite_jobid_free(jid); jid = NULL;
- free(jobids[ijob]); jobids[ijob] = NULL;
- ijob++;
- continue;
- }
- free(new_server);
- glite_jobid_getServerParts(jid, &new_server, &new_port);
- glite_jobid_free(jid); jid = NULL;
-
- // first or different LB server
- if (new_server && (!server || strcmp(server, new_server) != 0 || port != new_port)) {
- if (server) server_changed = 1;
-
- free(server);
- server = new_server;
- port = new_port;
-
- new_server = NULL;
- new_port = 0;
-
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server);
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, port);
- lprintf(NULL, INF, "summary LB server '%s:%u'", server, port);
- }
- } while (njobs || iquery);
-
- free(server);
- free(new_server);
-
- return err;
-}
-
-
-/*
- * Updates error counter and retry times on the notification.
- *
- * On errors it lineary increases delay. Minimum delay is
- * RTM_ERROR_REPEAT_RATE, maximum is half of the configured
- * bootstrap time.
- *
- * \param t thread context
- * \param notif updated notification
- * \param[IN] index notification order (for debug printing)
- * \param is_error[IN] error state (to reset or increment error counter)
- *
- */
-static int rtm_update_error_state(thread_t *t, notif_t *notif, int index, int is_error) {
- int old_error, max_count;
-
- old_error = notif->error;
- if (is_error) {
- if (!notif->error++ || !notif->refresh) notif->refresh = time(NULL);
- max_count = config.dive / RTM_ERROR_REPEAT_RATE / 2;
- if (max_count <= 0) max_count = 1;
- notif->refresh += (notif->error <= max_count ? notif->error : max_count) * RTM_ERROR_REPEAT_RATE;
- lprintf(t, DBG, "planned to retry at %s", time2str(t, notif->refresh));
- } else {
- notif->error = 0;
- }
- if (old_error != notif->error) {
- lprintf(t, DBG, "error count of %d. server %s:%d changed from %d to %d", index, notif->server, notif->port, old_error, notif->error);
- }
-
- return 0;
-}
-
-
-/**
- * Updates notifications in persistent storage. Used to send WLCG messages too.
- *
- * \param t thread context
- * \param[IN] new_notif updating notification, NULL = no change in shared memory
- * \param[IN] store 0=light (just shared memory), 1=save (flush, really store)
- * \retval 0 if OK
- */
-int rtm_update_notif(thread_t *t, notif_t *new_notif, int store) {
- notif_t *notif;
- int retval = 1;
-
- pthread_mutex_lock(&db.lock);
-
- if (new_notif) {
- if ((notif = db_search_notif_by_server(db.notifs, db.n, new_notif->server, new_notif->port, new_notif->type)) == NULL) {
- if (db_add_notif(strdup(new_notif->id_str), new_notif->type, new_notif->valid, new_notif->refresh, new_notif->last_update, strdup(new_notif->server), new_notif->port, 1, 0) == NULL) {
- lprintf(t, ERR, "can't realloc");
- goto quit;
- }
- } else {
- notif_free(notif);
- notif_copy(notif, new_notif);
- }
- }
-
- wlcg_send_message(t);
-
- if (store) {
- if (db_save_notifs(t) != 0) goto quit;
- }
- retval = 0;
-
-quit:
- pthread_mutex_unlock(&db.lock);
- return retval;
-}
-
-
-int rtm_drop_notif(thread_t *t, char *notifid, int store) {
- notif_t *notif;
- int retval = 1;
-
- pthread_mutex_lock(&db.lock);
- if ((notif = db_search_notif(db.notifs, db.n, notifid)) != NULL) {
- notif_invalidate(notif);
- if (store)
- if (db_save_notifs(t) != 0) goto quit;
- }
- retval = 0;
-quit:
- pthread_mutex_unlock(&db.lock);
- return retval;
-}
-
-
-int load_notifs_file() {
- FILE *f;
- char *results[5];
- notif_t *new_notif;
- int err;
- char *notifidstr;
- time_t valid, refresh;
- double last_update;
- edg_wll_NotifId id;
- int type, i, errcnt, port;
- int retval = 1;
-
- if ((f = fopen(config.notif_file, "rt")) == NULL) {
- lprintf(NULL, WRN, "WARNING: can't open notification file '%s'", config.notif_file);
- return 0;
- }
-
- results[0] = malloc(RTM_FILE_NOTIF_NUM * 512);
- for (i = 1; i < RTM_FILE_NOTIF_NUM; i++) {
- results[i] = results[0] + i * 512;
- }
- while ((err = fscanf(f, RTM_FILE_NOTIF_SCANF, results[0], results[1], results[2], results[3], results[4], results[5])) == RTM_FILE_NOTIF_NUM) {
- notifidstr = results[0];
- if ((type = rtm_str2notiftype(results[1])) == -1) {
- lprintf(NULL, ERR, "unknown notification type '%s' in '%s'", results[1], notifidstr);
- continue;
- }
-
- valid = rtm_str2time(results[2]);
- refresh = rtm_str2time(results[3]);
- last_update = rtm_str2timestamp(results[4]);
-
- errcnt = 0;
- if (results[5] && strcasecmp(results[5], "-") != 0) {
- errcnt = atoi(results[5]);
- }
-
- if (errcnt) {
- if (sscanf(notifidstr, "%511[^:]:%d", results[1], &port) != 2) {
- lprintf(NULL, WRN, "can't parse server specification '%s'", notifidstr);
- continue;
- }
- if ((new_notif = db_add_notif(NULL, type, valid, refresh, last_update, strdup(results[1]), port, 0, errcnt)) == NULL) {
- lprintf(NULL, ERR, "can't alloc");
- goto quit;
- }
- } else {
- if (edg_wll_NotifIdParse(notifidstr, &id) != 0) {
- lprintf(NULL, WRN, "can't parse notification ID '%s'", notifidstr);
- continue;
- }
- if ((new_notif = db_add_notif(strdup(notifidstr), type, valid, refresh, last_update, NULL, 0, 0, errcnt)) == NULL) {
- lprintf(NULL, ERR, "can't alloc");
- goto quit;
- }
- edg_wll_NotifIdGetServerParts(id, &new_notif->server, &new_notif->port);
- edg_wll_NotifIdFree(id);
- }
- }
- if (err == EOF) retval = 0;
- else lprintf(NULL, ERR, "can't parse notification file '%s'", config.notif_file);
-quit:
- fclose(f);
- free(results[0]);
- return retval;
-}
-
-
-#if defined(WITH_RTM_SQL_STORAGE) && defined(WITH_LBU_DB)
-int load_notifs_sql() {
- notif_t *new_notif;
- int err;
- char *notifidstr;
- time_t valid, refresh;
- double last_update;
- edg_wll_NotifId id;
- int type, i, errcnt;
- int retval = 1;
- glite_lbu_Statement stmt = NULL;
- char *results[8];
-
- if (glite_lbu_ExecSQL(db.dbctx, "SELECT notifid, notiftype, valid, refresh, last_update, errors, lb, port FROM notifs", &stmt) == -1) {
- lprintf_dbctx(NULL, ERR, "fetching notification failed");
- goto quit;
- }
- while ((err = glite_lbu_FetchRow(stmt, 8, NULL, results)) > 0) {
- if (results[0] && results[0][0]) notifidstr = strdup(results[0]);
- else notifidstr = NULL;
- free(results[0]);
- results[0] = NULL;
-
- if ((type = rtm_str2notiftype(results[1])) == -1) {
- lprintf(NULL, ERR, "unknown notification type '%s' in '%s'", results[1], notifidstr);
- for (i = 0; i < 8; i++) free(results[i]);
- free(notifidstr);
- continue;
- }
- free(results[1]);
-
- valid = 0;
- if (results[2] && results[2][0]) {
- valid = glite_lbu_DBToTime(db.dbctx, results[2]);
- }
- free(results[2]);
-
- refresh = 0;
- if (results[3] && results[3][0]) {
- refresh = glite_lbu_DBToTime(db.dbctx, results[3]);
- }
- free(results[3]);
-
- last_update = 0;
- if (results[4] && results[4][0]) {
- last_update = glite_lbu_DBToTimestamp(db.dbctx, results[4]);
- }
- free(results[4]);
-
- errcnt = 0;
- if (results[5] && results[5][0]) errcnt = atoi(results[5]);
- free(results[5]);
-
- if ((new_notif = db_add_notif(notifidstr, type, valid, refresh, last_update, (results[6] && !notifidstr) ? strdup(results[6]) : NULL, atoi(results[7]), 0, errcnt)) == NULL) {
- free(notifidstr);
- free(results[6]);
- free(results[7]);
- lprintf(NULL, ERR, "can't alloc");
- goto quit;
- }
- free(results[6]);
- free(results[7]);
- if (notifidstr) {
- if (edg_wll_NotifIdParse(notifidstr, &id) != 0) {
- lprintf(NULL, WRN, "can't parse notification IDs '%s'", notifidstr);
- notif_free(new_notif);
- db.n--;
- continue;
- }
- edg_wll_NotifIdGetServerParts(id, &new_notif->server, &new_notif->port);
- edg_wll_NotifIdFree(id);
- }
- }
- if (err == 0) retval = 0;
- else lprintf_dbctx(NULL, ERR, "fetching failed");
-quit:
- if (stmt) glite_lbu_FreeStmt(&stmt);
- return retval;
-}
-#endif
-
-
-int load_notifs() {
- int i, ret;
-
- pthread_mutex_lock(&db.lock);
-
-#if defined(WITH_RTM_SQL_STORAGE) && defined(WITH_LBU_DB)
- if (!db.dbctx) ret = load_notifs_file();
- else ret = load_notifs_sql();
-#else
- ret = load_notifs_file();
-#endif
- // try to reconnect on bad notifications immediately
- for (i = 0; i < db.n; i++)
- if (db.notifs[i].error) db.notifs[i].refresh = 0;
-
- pthread_mutex_unlock(&db.lock);
-
- return ret;
-}
-
-
-void db_free_notifs() {
- int i;
-
- for (i = 0; i < db.n; i++) notif_free(db.notifs + i);
- free(db.notifs);
- db.notifs = NULL;
- db.n = db.maxn = 0;
-}
-
-
-void *notify_thread(void *thread_data) {
- struct sockaddr_in addr;
- int i, j, err;
- time_t now, bootstrap;
- edg_wll_NotifId notifid;
- struct timeval to;
- edg_wll_JobStat jobstat, *jobstates;
- notif_t *notif, *notif_jdl;
- edg_wll_QueryRec *conditions[3] = { NULL, NULL, NULL }, condition[2], condition2[2];
- int sock = -1, updated = 0, error = 0, received = 0;
- thread_t *t = (thread_t *)thread_data;
- edg_wll_Context ctx = NULL;
- int flags = 0;
-
- const int one = 1;
-
- lprintf(t, DBG, "thread started");
-
- if (!t->nservers) goto exit;
-
- // LB
- if (edg_wll_InitContext(&ctx) != 0) {
- lprintf(t, ERR, "can't init LB context: %s", strerror(errno));
- goto exit;
- }
- if (config.cert) edg_wll_SetParam(ctx, EDG_WLL_PARAM_X509_CERT, config.cert);
- if (config.key) edg_wll_SetParam(ctx, EDG_WLL_PARAM_X509_KEY, config.key);
-
- // socket
- if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
- lprintf(t, ERR, "can't create socket: %s", strerror(errno));
- goto exit;
- }
- lprintf(t, DBG, "socket created: %d", sock);
-
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
-
- memset(&addr, 0, sizeof addr);
- addr.sin_family = AF_INET;
- if (listen_port) addr.sin_port = htons(listen_port + t->id);
- addr.sin_addr.s_addr = INADDR_ANY;
- if (bind(sock, (const struct sockaddr*)&addr, sizeof addr) != 0) {
- lprintf(t, ERR, "can't bind socket: %s, port = %d", strerror(errno), listen_port ? listen_port + t->id : -1);
- goto exit;
- }
- if (listen(sock, 10) != 0) {
- lprintf(t, ERR, "can't listen on socket: %s", strerror(errno));
- goto exit;
- }
-
-#ifdef WITH_LBU_DB
- if (db_init(t, &t->dbctx) == 0)
- if ((t->dbcaps & GLITE_LBU_DB_CAP_PREPARED) != 0) {
- if (glite_lbu_PrepareStmt(t->dbctx, "INSERT INTO " DBAMP RTM_DB_TABLE_JOBS DBAMP " "
- "(ce, queue, rb, ui, state, state_entered, rtm_timestamp, jobid, lb, active, state_changed, registered, vo)"
- " VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)",
- &t->insertcmd) != 0 || glite_lbu_PrepareStmt(t->dbctx, "UPDATE " DBAMP RTM_DB_TABLE_JOBS DBAMP " "
- "SET ce=$1, queue=$2, rb=$3, ui=$4, state=$5, state_entered=$6, rtm_timestamp=$7, active=$8, state_changed=$9, registered=$10 WHERE jobid=$11 AND lb=$12",
- &t->updatecmd) != 0 || glite_lbu_PrepareStmt(t->dbctx, "UPDATE " DBAMP RTM_DB_TABLE_JOBS DBAMP " "
- "SET ce=$1, queue=$2, rb=$3, ui=$4, state=$5, state_entered=$6, rtm_timestamp=$7, active=$8, state_changed=$9, registered=$10, vo=$11 WHERE jobid=$12 AND lb=$13",
- &t->updatecmd_vo) != 0 || glite_lbu_PrepareStmt(t->dbctx, "UPDATE " DBAMP RTM_DB_TABLE_LBS DBAMP " "
- "SET monitored=$1 WHERE ip=$2",
- &t->updatecmd_mon)) {
- lprintf_dbctx(t, ERR, "can't create prepare commands");
- lprintf(t, DBG, "insertcmd=%p, updatecmd=%p, updatecmd_vo=%p, updatecmd_mon=%p", t->insertcmd, t->updatecmd, t->updatecmd_vo, t->updatecmd_mon);
- quit = RTM_QUIT_PRESERVE;
- }
- }
-#endif
-
- //
- // notifications loop:
- // - refresh/create with bootstrap
- // - receive & store changes
- //
- while (!quit) {
- now = time(NULL);
- t->next_refresh = now + RTM_NOTIF_LOOP_MAX_TIME;
- for (i = 0; i < t->nservers; i++) {
- notif = t->notifs + i;
- if (!notif->active) {
- lprintf(t, INS, "inactive %d. notification '%s' (%s)", i, notif->id_str, rtm_notiftype2str(notif->type));
- continue;
- }
- // skip invalid LBs if not planned yet
- if (notif->error) {
- if (notif->refresh > now) {
- lprintf(t, INS, "not planned to retry previously failed %d. notification '%s' (%s), plan %s", i, notif->id_str, rtm_notiftype2str(notif->type), time2str(t, notif->refresh));
- if (t->next_refresh > notif->refresh) t->next_refresh = notif->refresh;
- continue;
- }
- lprintf(t, DBG, "retry previously failed %d. notification '%s' (%s)", i, notif->id_str, rtm_notiftype2str(notif->type));
- }
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER, notif->server);
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER_PORT, notif->port);
- now = time(NULL);
- if (!notif->valid || notif->valid - RTM_NOTIF_TTL_TO_DEAD <= now || !notif->id_str) {
- // new notification
- lprintf(t, DBG, "host %s:%d, valid %s, notifstr '%s', notifid %p", notif->server, notif->port, time2str(t, notif->valid), notif->id_str, notif->id);
-
- // crazy inter-notif interactions
- switch (notif->type) {
- case RTM_NOTIF_TYPE_STATUS:
- // STATUS must wait for existing JDL notification
- notif_jdl = db_search_notif_by_server(t->notifs, t->nservers, notif->server, notif->port, RTM_NOTIF_TYPE_JDL);
- if (!notif_jdl || !notif_jdl->valid || notif_jdl->valid - RTM_NOTIF_TTL_TO_DEAD <= now || !notif_jdl->id_str) {
- lprintf(t, DBG, "not created %d. notification for %s:%d (%s), waiting for %d. (JDL)", i, notif->server, notif->port, rtm_notiftype2str(notif->type), i + RTM_NOTIF_TYPE_JDL - RTM_NOTIF_TYPE_STATUS);
- // next retry of STATUS stright before the JDL
- if (notif_jdl) {
- notif->refresh = notif_jdl->refresh;
- if (t->next_refresh > notif->refresh) t->next_refresh = notif->refresh;
- }
- continue;
- }
- break;
- default:
- break;
- }
- bootstrap = notif->valid > RTM_NOTIF_TTL_TO_DEAD ? notif->valid - RTM_NOTIF_TTL_TO_DEAD : 0;
- if (config.dive > 0 && now - bootstrap > config.dive) {
- bootstrap = now - config.dive;
- lprintf(t, INS, "dive from %s:%d cut to %s (max. dive %d)", notif->server, notif->port, time2str(t, bootstrap), config.dive);
- }
- // explicitly drop old (failed) notification, if any
- if (notif->id_str) {
- if (notif->id) {
- if (edg_wll_NotifDrop(ctx, notif->id)) lprintf_ctx(t, WRN, ctx, "dropping %d. notification '%s' (%s) failed", i, notif->id_str, rtm_notiftype2str(notif->type));
- }
- // remove from the persistent storage now,
- // invalidate && update
- rtm_drop_notif(t, notif->id_str, 1);
- // free the notification in the current thread
- notif_invalidate(notif);
- now = time(NULL);
- }
- // create the new notification
- notif->valid = now + config.ttl;
-
- memset(conditions, 0, sizeof(conditions));
- memset(condition, 0, sizeof(condition));
- memset(condition2, 0, sizeof(condition2));
- flags = 0;
- switch(notif->type) {
-#ifndef WITH_OLD_LB
- case RTM_NOTIF_TYPE_STATUS:
- conditions[0] = condition;
- condition[0].attr = EDG_WLL_QUERY_ATTR_STATUS;
- condition[0].op = EDG_WLL_QUERY_OP_CHANGED;
- break;
- case RTM_NOTIF_TYPE_JDL:
- conditions[0] = condition;
- conditions[1] = condition2;
- condition[0].attr = EDG_WLL_QUERY_ATTR_STATUS;
- condition[0].op = EDG_WLL_QUERY_OP_EQUAL;
- condition[0].value.i = EDG_WLL_JOB_WAITING;
- condition2[0].attr = EDG_WLL_QUERY_ATTR_JDL_ATTR;
- condition2[0].op = EDG_WLL_QUERY_OP_CHANGED;
- flags = EDG_WLL_STAT_CLASSADS;
- break;
-#endif
- case RTM_NOTIF_TYPE_OLD:
- flags = EDG_WLL_STAT_CLASSADS;
- break;
- case RTM_NOTIF_TYPE_DONE:
- conditions[0] = condition;
- condition[0].attr = EDG_WLL_QUERY_ATTR_STATUS;
- condition[0].op = EDG_WLL_QUERY_OP_EQUAL;
- condition[0].value.i = EDG_WLL_JOB_DONE;
- flags = EDG_WLL_STAT_CHILDREN;
- break;
- default:
- assert(notif->type != notif->type); // unknown type
- break;
- }
- if (edg_wll_NotifNew(ctx, (edg_wll_QueryRec const * const *) conditions, flags, sock, config.local_address, ¬if->id, ¬if->valid)) {
- memset(condition,0,sizeof condition);
- lprintf_ctx(t, ERR, ctx, "can't create notification on %s:%d", notif->server, notif->port);
- notif->valid = 0;
- notif->id = NULL;
- rtm_update_error_state(t, notif, i, 1);
- error = 1;
- goto cont;
- }
- notif->id_str = edg_wll_NotifIdUnparse(notif->id);
- lprintf(t, INF, "created %d. notification '%s' (%s), valid: %s", i, notif->id_str, rtm_notiftype2str(notif->type), time2str(t, notif->valid));
-
- // bootstrap
- memset(condition, 0, sizeof(condition));
- flags = 0;
- switch (notif->type) {
- case RTM_NOTIF_TYPE_STATUS:
- condition[0].attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME;
- condition[0].op = EDG_WLL_QUERY_OP_WITHIN;
- condition[0].value.t.tv_sec = bootstrap;
- condition[0].value2.t.tv_sec = now;
- flags = EDG_WLL_STAT_CLASSADS;
- break;
- case RTM_NOTIF_TYPE_OLD:
- break;
- case RTM_NOTIF_TYPE_JDL:
- break;
- case RTM_NOTIF_TYPE_DONE:
- break;
- default:
- assert(notif->type != notif->type); // unknown type
- break;
- }
-
- if (condition[0].attr) {
-
- lprintf(t, INF, "bootstrap %s:%d (%d), time %s..%d(now)", notif->server, notif->port, i, time2str(t, bootstrap), now);
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, notif->server);
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, notif->port);
- if ((err = edg_wll_QueryJobs(ctx, condition, flags, NULL, &jobstates)) != 0 && err != ENOENT) {
- lprintf_ctx(t, ERR, ctx, "can't bootstrap jobs on %s:%d, time %s..%d(now)", notif->server, notif->port, time2str(t, bootstrap), now);
- //
- // destroy the notification after failed bootstrap
- //
- // This error means there is something nasty on the remote LB server.
- // It could lost some messages between recreating notification,
- // so destroy this notification now.
- //
- if (edg_wll_NotifDrop(ctx, notif->id)) {
- lprintf_ctx(t, WRN, ctx, "dropping %d. notification '%s' (%s) after failed bootstrap failed", i, notif->id_str, rtm_notiftype2str(notif->type));
- } else {
- lprintf(t, INF, "dropped %d. notification '%s' (%s) after failed bootstrap", i, notif->id_str, rtm_notiftype2str(notif->type));
- }
- // free the notification instance in the current thread
- // (not propagated to the persistent storage yet)
- edg_wll_NotifIdFree(notif->id);
- notif->id = NULL;
- free(notif->id_str);
- notif->id_str = NULL;
- notif->valid = 0;
- rtm_update_error_state(t, notif, i, 1);
- error = 1;
- if (t->next_refresh > notif->refresh) t->next_refresh = notif->refresh;
- goto cont;
- } else {
- for (j = 0; jobstates[j].state != EDG_WLL_JOB_UNDEF; j++) {
- notif->last_update = jobstates[j].lastUpdateTime.tv_sec + jobstates[j].lastUpdateTime.tv_usec / 1000000.0;
- db_store_change(t, notif, i, jobstates + j);
- edg_wll_FreeStatus(jobstates + j);
- }
- free(jobstates);
- lprintf(t, INF, "bootstrap %s:%d (%d), found %d jobs", notif->server, notif->port, i, j);
- rtm_update_error_state(t, notif, i, 0);
- updated = 1;
- }
-
- } else {
- rtm_update_error_state(t, notif, i, 0);
- updated = 1;
- }
- } else if (!notif->id) {
- // rebind existing still valid notification
- if (edg_wll_NotifIdParse(notif->id_str, ¬if->id)) {
- lprintf_ctx(t, WRN, ctx, "can't parse %d. notification '%s' (%s)", i, notif->id_str, rtm_notiftype2str(notif->type));
- notif->valid = 0;
- notif->id = NULL;
- i--;
- continue;
- }
- notif->valid = now + config.ttl;
- if (edg_wll_NotifBind(ctx, notif->id, sock, config.local_address, ¬if->valid)) {
- lprintf_ctx(t, WRN, ctx, "can't rebind %d. notification '%s' (%s)", i, notif->id_str, rtm_notiftype2str(notif->type));
- notif->valid = 0;
- edg_wll_NotifIdFree(notif->id);
- notif->id = NULL;
- i--;
- continue;
- }
- lprintf(t, INF, "bound %d. notification '%s' (%s), valid: %s", i, notif->id_str, rtm_notiftype2str(notif->type), time2str(t, notif->valid));
- rtm_update_error_state(t, notif, i, 0);
- // no bootstrap here, reliable delivery will send changes
- updated = 1;
- } else if (!notif->refresh || notif->refresh <= now) {
- // refresh notification
- time_t valid;
-
- valid = now + config.ttl;
- if (edg_wll_NotifRefresh(ctx, notif->id, &valid)) {
- lprintf_ctx(t, WRN, ctx, "can't refresh %d. notification '%s' (%s), will try up to %s...", i, notif->id_str, rtm_notiftype2str(notif->type), time2str(t, notif->valid - RTM_NOTIF_TTL_TO_DEAD));
- // refresh failed, just move the refresh time...
- updated = 1;
- } else {
- notif->valid = valid;
- lprintf(t, INF, "refreshed %d. notification '%s' (%s), valid: %s", i, notif->id_str, rtm_notiftype2str(notif->type), time2str(t, notif->valid));
- rtm_update_error_state(t, notif, i, 0);
- updated = 1;
- }
- } else {
- lprintf(t, INS, "no change in %d. notification '%s' (%s)", i, notif->id_str, rtm_notiftype2str(notif->type));
- }
-
-cont:
- if (updated || error) {
- if (!error) {
- assert(notif->valid);
- notif->refresh = notif->valid ? (now + ((notif->valid - now) >> 1)) : 0;
-
- }
- // create or refresh OK, bootstrap if needed OK, store the new notification
- updated = 0;
- error = 0;
-
- // quicker refresh (or recreate) if needed
- now = time(NULL);
- if (notif->valid && now >= notif->refresh) {
- lprintf(t, WRN, "operation not in time, refreshing/recreating the notification '%s' (%s) now", notif->id_str, rtm_notiftype2str(notif->type));
- i--;
- continue;
- }
- rtm_update_notif(t, notif, 1);
- }
-
- // compute time of the next event from the new refresh on notification
- if (t->next_refresh > notif->refresh) t->next_refresh = notif->refresh;
- }
-
- // receive
- //
- // cycle here locally around NotifReceive, we know about next
- // refresh time
- //
- lprintf(t, DBG, "waiting for the notifications up to %s...", t->next_refresh ? time2str(t, t->next_refresh) : "0 (no wait)");
- while (t->next_refresh > now && !quit) {
- to.tv_sec = t->next_refresh - now;
- if (to.tv_sec > RTM_NOTIF_READ_TIMEOUT) to.tv_sec = RTM_NOTIF_READ_TIMEOUT;
- to.tv_usec = 0;
- memset(&jobstat, 0, sizeof(jobstat));
- notifid = NULL;
- err = edg_wll_NotifReceive(ctx, sock, &to, &jobstat, ¬ifid);
- lprintf(t, INS, "received, err=%d%s", err, err == ETIMEDOUT ? " (timeout)":"");
- if (err != 0) {
- if (err != ETIMEDOUT) {
- lprintf_ctx(t, ERR, ctx, "can't receive notifications");
- // don't cycle too quick...
- sleep(1);
- }
- // lazily refresh persistent storage here, only after timeouts
- if (received) {
- lprintf(t, DBG, "storing notification times");
- rtm_update_notif(t, NULL, 1);
- received = 0;
- }
- } else {
- char *jobidstr, *notifidstr;
- double last_update;
-
- if (notifid) {
- jobidstr = jobstat.jobId ? glite_jobid_unparse(jobstat.jobId) : NULL;
- notifidstr = notifid ? edg_wll_NotifIdUnparse(notifid) : NULL;
- for (i = 0; i < t->nservers && (!t->notifs[i].id_str || strcmp(notifidstr, t->notifs[i].id_str) != 0); i++);
- if (i == t->nservers) {
- lprintf(t, ERR, "received notify '%s' not found", notifidstr);
- } else {
- received = 1;
- notif = t->notifs + i;
- //
- // last changed time from the arrived notification
- //
- last_update = jobstat.lastUpdateTime.tv_sec + jobstat.lastUpdateTime.tv_usec / 1000000.0;
- if (last_update > notif->last_update) notif->last_update = last_update;
- db_store_change(t, notif, i, &jobstat);
- rtm_update_notif(t, notif, 0);
- }
- free(jobidstr);
- free(notifidstr);
- }
- }
- if (jobstat.state != EDG_WLL_JOB_UNDEF) edg_wll_FreeStatus(&jobstat);
- if (notifid) edg_wll_NotifIdFree(notifid);
-
- now = time(NULL);
- } // receive
- } // main loop
-
-exit:
- if (sock != -1) close(sock);
-// for (i = 0; conditions[i]; i++) free(conditions[i]);
- if (t->nservers && quit != RTM_QUIT_PRESERVE && quit != RTM_QUIT_RELOAD) {
- for (i = 0; i < t->nservers; i++) {
- if (t->notifs[i].id) {
- char *notifidstr;
-
- notifidstr = edg_wll_NotifIdUnparse(t->notifs[i].id);
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER, t->notifs[i].server);
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER_PORT, t->notifs[i].port);
- if (edg_wll_NotifDrop(ctx, t->notifs[i].id)) {
- lprintf_ctx(t, WRN, ctx, "can't drop %s (%s)", notifidstr, rtm_notiftype2str(t->notifs[i].type));
- } else {
- lprintf(t, INF, "notification %s (%s) dropped", notifidstr, rtm_notiftype2str(t->notifs[i].type));
- }
- rtm_drop_notif(t, t->notifs[i].id_str, 0);
- free(notifidstr);
- }
- }
- rtm_update_notif(t, NULL, 1);
- }
-#ifdef WITH_LBU_DB
- if (t->insertcmd) glite_lbu_FreeStmt(&t->insertcmd);
- if (t->updatecmd) glite_lbu_FreeStmt(&t->updatecmd);
- if (t->updatecmd_vo) glite_lbu_FreeStmt(&t->updatecmd_vo);
- if (t->updatecmd_mon) glite_lbu_FreeStmt(&t->updatecmd_mon);
- db_free(t, t->dbctx);
-#endif
- if (ctx) edg_wll_FreeContext(ctx);
- lprintf(t, DBG, "thread ended");
- pthread_exit(NULL);
- return NULL;
-}
-
-
-int reconcile_threads() {
- int iserver, ithread, inotif, gran, mod, nnotifs;
- int i, j, oldn, type, typestart, typeend;
- notif_t *a, *b;
- edg_wll_Context ctx = NULL;
- edg_wll_NotifId notifid;
- thread_t *t;
-
- if (!config.cleanup) {
- if (config.silly) {
- typestart = RTM_NOTIF_TYPE_OLD;
- typeend = RTM_NOTIF_TYPE_OLD;
- nnotifs = 1;
- } else {
- typestart = RTM_NOTIF_TYPE_STATUS;
- typeend = RTM_NOTIF_TYPE_JDL;
- nnotifs = 2;
- }
-
- oldn = db.n;
-
- // distribute LB servers between threads
- // (always use existing loaded notification when found)
- threads = (thread_t *)calloc(config.nthreads, sizeof(thread_t));
- gran = config.nservers / config.nthreads, mod = config.nservers % config.nthreads;
- t = NULL;
- ithread = 0;
- inotif = 0;
- for (iserver = 0; iserver < config.nservers; iserver++) {
- // new thread
- if (!t || inotif + nnotifs > t->nservers) {
- assert(ithread < config.nthreads); // proper number of threads
- assert(!t || inotif == t->nservers); // start or exactly distributed
- t = threads + ithread;
- t->nservers = nnotifs * ((ithread < mod) ? gran + 1 : gran);
- t->notifs = (notif_t *)calloc(t->nservers, sizeof(notif_t));
- lprintf(NULL, DBG, "%d. thread: %d notifications", ithread, t->nservers);
- ithread++;
- inotif = 0;
- }
-
- // next configured server
- a = config.notifs + iserver;
- for (type = typestart; type <= typeend; type++) {
- // find or create all notification types
- b = db_search_notif_by_server(db.notifs, oldn, a->server, a->port, type);
- if (!b) b = db_add_notif(NULL, type, 0, 0, 0, strdup(a->server), a->port, 1, 0);
- else {
- if (b->id_str) {
- lprintf(NULL, INF, "found previous notification '%s' (%s)", b->id_str, rtm_notiftype2str(b->type));
- } else {
- lprintf(NULL, INF, "found previous server %s:%d (%s), %d errors", b->server, b->port, rtm_notiftype2str(b->type), b->error);
- }
- b->active = 1;
- }
- // and add each to the thread
- notif_copy(t->notifs + inotif, b);
- lprintf(NULL, INS, "thread[%d][%d] <- %s:%d (%s), id %s", ithread-1, inotif, b->server, b->port, rtm_notiftype2str(b->type), b->id_str);
- inotif++;
- }
- }
- j = 0;
- for (i = 0; i < db.n; i++)
- if (db.notifs[i].active) j++;
- assert(j % nnotifs == 0); // each server all notifs
- }
-
- if (edg_wll_InitContext(&ctx) != 0) {
- lprintf(NULL, ERR, "can't init LB context: %s", strerror(errno));
- return 1;
- }
- if (config.cert) edg_wll_SetParam(ctx, EDG_WLL_PARAM_X509_CERT, config.cert);
- if (config.key) edg_wll_SetParam(ctx, EDG_WLL_PARAM_X509_KEY, config.key);
- for (j = 0; j < db.n; j++) {
- if (!db.notifs[j].active) {
- if (db.notifs[j].id_str) {
- lprintf(NULL, INF, "dropping previous notification '%s' (%s)", db.notifs[j].id_str, rtm_notiftype2str(db.notifs[j].type));
- if (edg_wll_NotifIdParse(db.notifs[j].id_str, ¬ifid)) {
- lprintf(NULL, WRN, "can't parse notification ID '%s'", db.notifs[j].id_str);
- continue;
- }
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER, db.notifs[j].server);
- edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER_PORT, db.notifs[j].port);
- if (edg_wll_NotifDrop(ctx, notifid) != 0) {
- lprintf_ctx(NULL, WRN, ctx, "can't drop %s (%s)", db.notifs[j].id_str, rtm_notiftype2str(db.notifs[j].type));
- }
- edg_wll_NotifIdFree(notifid);
- notif_invalidate(db.notifs + j);
- }
- }
- }
- edg_wll_FreeContext(ctx);
-
- return db_save_notifs(NULL);
-}
-
-
-void usage(const char *prog) {
- fprintf(stderr, "Usage: %s [options]\n"
- " -h, --help display this help\n"
- " -v, --version display version\n"
- " -d, --debug LEVEL debug level (0=error,1=warn,2=info,3=debug,4=insane,\n"
- " +8=not fork)\n"
- " -D, --daemonize daemonize\n"
- " -i, --pidfile the file with process ID\n"
- " -s, --threads N number of slave threads\n"
- " -t, --ttl TIME time to live (validity) of the notifications\n"
- " in seconds (%d)\n"
- " -H, --history historic dive in seconds (<=0 is unlimited)\n"
- " -c, --config config file name (list of LB servers), precedence before " RTM_DB_TABLE_LBS " table\n"
-#ifdef WITH_LBU_DB
- " -m, --pg db connection string (user/pwd@server:dbname) to " RTM_DB_TABLE_LBS " table\n"
-#endif
- " -n, --notifs file for persistent information about active\n"
- " notifications\n"
- " -C, --cert X509 certificate file\n"
- " -K, --key X509 key file\n"
- " -o, --old \"silly\" mode for old L&B 1.9 servers\n"
- " -l, --cleanup clean up the notifications and exit\n"
- " -w, --wlcg enable messaging for dashboard\n"
- " --wlcg-binary full path to msg-publish binary\n"
- " --wlcg-topic topic for msg-publish\n"
- " --wlcg-config config file for msg-publish\n"
- " --wlcg-flush send message on each notification\n"
- , prog, RTM_NOTIF_TTL);
- fprintf(stderr, "\n");
- fprintf(stderr, "List of L&B servers: first it's read the config file if specified (-c option). When config file is not used and connection to database is specified, it's tried DB table " RTM_DB_TABLE_LBS ".\n");
- fprintf(stderr, "\n");
-}
-
-
-int config_preload(int argn, char *argv[]) {
- int opt, intval, index;
- char *err, *s;
-
- while ((opt = getopt_long(argn, argv, opts_line, opts, &index)) != EOF) {
- switch (opt) {
- case 'h':
- case '?':
- usage(argv[0]);
- return 1;
- case 'v':
- fprintf(stderr, "%s: %s\n", argv[0], rcsid);
- return 1;
- case 'd':
- intval = strtol(optarg, &err, 10);
- if (err && err[0]) {
- lprintf(NULL, ERR, "debug level number required");
- return 2;
- }
- config.debug = (intval & DEBUG_LEVEL_MASK);
- config.guard = !(intval & DEBUG_GUARD_MASK);
- break;
- case 'D':
- config.daemonize = 1;
- break;
- case 'i':
- config.pidfile = strdup(optarg);
- break;
- case 's':
- intval = strtol(optarg, &err, 10);
- if (err && err[0]) {
- lprintf(NULL, ERR, "number of threads required");
- return 2;
- }
- config.nthreads = intval;
- break;
- case 't':
- intval = strtol(optarg, &err, 10);
- if (err && err[0]) {
- lprintf(NULL, ERR, "requested validity in seconds required");
- return 2;
- }
- config.ttl = intval;
- break;
- case 'H':
- intval = strtol(optarg, &err, 10);
- if (err && err[0]) {
- lprintf(NULL, ERR, "historic dive in seconds required");
- return 2;
- }
- config.dive = intval;
- break;
- case 'c':
- free(config.config_file);
- config.config_file = strdup(optarg);
- break;
- case 'n':
- free(config.notif_file);
- config.notif_file = strdup(optarg);
- break;
- case 'p':
- listen_port = atoi(optarg);
- break;
- case 'm':
- free(config.dbcs);
- config.dbcs = strdup(optarg);
- break;
- case 'C':
- free(config.cert);
- config.cert = strdup(optarg);
- break;
- case 'K':
- free(config.key);
- config.key = strdup(optarg);
- break;
- case 'l':
- config.cleanup = 1;
- break;
- case 'w':
- config.wlcg = 1;
- break;
- case 'o':
- config.silly = 1;
- break;
- case 0:
- switch(index) {
- case 0:
- config.wlcg_binary = strdup(optarg);
- break;
- case 1:
- config.wlcg_config = strdup(optarg);
- break;
- case 2:
- config.wlcg_topic = strdup(optarg);
- break;
- case 3:
- config.wlcg_flush = 1;
- break;
- default:
- lprintf(NULL, ERR, "crazy option, index %d", index);
- break;
- }
- break;
- }
- }
- if (!config.notif_file) config.notif_file = strdup(RTM_FILE_NOTIFS);
- if (config.wlcg) {
- if (!config.wlcg_binary) config.wlcg_binary = strdup(WLCG_BINARY);
- if (!config.wlcg_config) config.wlcg_config = strdup(WLCG_CONFIG);
- if (!config.wlcg_topic) config.wlcg_topic = strdup(WLCG_TOPIC);
- }
-#ifdef WITH_OLD_LB
- if (!config.silly) {
- lprintf(NULL, WRN, "compiled with older LB library, switching on silly mode");
- config.silly = 1;
- }
-#endif
-
- if ((s = getenv("GLITE_LB_HARVESTER_NO_REMOVE")) != NULL) {
- if (s[0] != '0' && strcasecmp(s, "false") != 0) config.wlcg_no_remove = 1;
- }
-
- if (INF <= config.debug) {
- lprintf(NULL, INF, "threads: %d", config.nthreads);
- lprintf(NULL, INF, "notifs ttl: %d", config.ttl);
- lprintf(NULL, INF, "historic dive: %d", config.dive);
- if (config.dbcs) {
- lprintf(NULL, INF, "database storage: '%s'", config.dbcs);
- } else {
- lprintf(NULL, INF, "file storage: '%s'", config.notif_file);
- }
- lprintf(NULL, INF, "WLCG messaging: %s%s", config.wlcg ? "enabled" : "disabled", config.wlcg_no_remove ? " (not removing tmp files)" : "");
- lprintf(NULL, INF, "debug level: %d", config.debug);
- lprintf(NULL, INF, "daemonize: %s", config.daemonize ? "enabled" : "disabled");
- lprintf(NULL, INF, "fork guard: %s", config.guard ? "enabled" : "disabled");
- lprintf(NULL, INF, "silly compatibility mode: %s", config.silly ? "enabled" : "disabled");
- }
-
- return 0;
-}
-
-
-int config_load() {
- char line[LINE_MAX], *port, *s;
- FILE *f;
- void *tmp;
- int i, n;
- int major, minor, sub, version;
-#ifdef WITH_LBU_DB
- char *results[2];
- char *result = NULL;
- glite_lbu_Statement stmt = NULL;
- int err = 0;
-#endif
-
- if (config.config_file) {
- if ((f = fopen(config.config_file, "rt")) == NULL) {
- lprintf(NULL, ERR, "can't open config file '%s': %s", config.config_file, strerror(errno));
- return 1;
- }
-
- n = 10;
- while (fgets(line, sizeof(line), f) != NULL) {
- if ((s = strpbrk(line, "\n\r")) != NULL) s[0] = '\0';
- if (line[0] == '\0' || line[0] == '#') continue;
- if (config.nservers >= n || !config.notifs) {
- n = 2 * n;
- if ((tmp = (notif_t *)realloc(config.notifs, n * sizeof(notif_t))) == NULL) {
- lprintf(NULL, ERR, "insufficient memory");
- return 1;
- }
- config.notifs = tmp;
- memset(config.notifs + config.nservers, 0, (n - config.nservers) * sizeof(notif_t));
- }
- if ((port = strrchr(line, ':')) != NULL) { port[0] = '\0'; port++; }
- config.notifs[config.nservers].server = strdup(line);
- config.notifs[config.nservers++].port = (port && port[0]) ? atoi(port) : GLITE_JOBID_DEFAULT_PORT;
- }
-
- fclose(f);
- } else
-#ifdef WITH_LBU_DB
- if (db.dbctx) {
- if ((err = glite_lbu_ExecSQL(db.dbctx, "SELECT COUNT(*) FROM " RTM_DB_TABLE_LBS, &stmt)) < 0 ||
- (err = glite_lbu_FetchRow(stmt, 1, NULL, &result)) < 0) {
- goto err;
- }
- if (err == 0) {
- lprintf(NULL, ERR, "can't count LB servers");
- goto err;
- }
- n = atoi(result);
- free(result);
- glite_lbu_FreeStmt(&stmt);
-
- config.notifs = calloc(n, sizeof(notif_t));
- config.nservers = 0;
- if ((err = glite_lbu_ExecSQL(db.dbctx, "SELECT DISTINCT ip, serv_version FROM " RTM_DB_TABLE_LBS, &stmt)) < 0) {
- goto err;
- }
- while (config.nservers < n && (err = glite_lbu_FetchRow(stmt, 2, NULL, results)) > 0) {
- if (sscanf(results[1], "%d.%d.%d", &major, &minor, &sub) != 3) {
- lprintf(NULL, ERR, "can't parse LB server version '%s'", results[1]);
- free(results[1]);
- break;
- }
- version = 10000 * major + 100 * minor + sub;
- if (version >= 20000 || config.silly) {
- config.notifs[config.nservers].server = strdup(results[0]);
- config.notifs[config.nservers++].port = GLITE_JOBID_DEFAULT_PORT;
- } else {
- lprintf(NULL, INF, "skipped older LB server %s (version '%s')", results[0], results[1]);
- }
- free(results[0]);
- free(results[1]);
- }
- if (err < 0) goto err;
- glite_lbu_FreeStmt(&stmt);
- }
-#endif
-
- if (INF <= config.debug) {
- lprintf(NULL, INF, "servers: %d", config.nservers);
- for (i = 0; i < config.nservers; i++) lprintf(NULL, INF, " %s:%d", config.notifs[i].server, config.notifs[i].port);
- }
-
- return 0;
-#ifdef WITH_LBU_DB
-err:
- if (err) lprintf_dbctx(NULL, ERR, "can't get LB servers");
- if (stmt) glite_lbu_FreeStmt(&stmt);
- if (result) free(result);
-#endif
- return 1;
-}
-
-
-void config_free() {
- int i;
-
- for (i = 0; i < config.nservers; i++) free(config.notifs[i].server);
- free(config.config_file);
- free(config.notif_file);
- free(config.pidfile);
- free(config.dbcs);
- free(config.notifs);
- free(config.cert);
- free(config.key);
- free(config.wlcg_binary);
- free(config.wlcg_config);
- free(config.wlcg_topic);
-}
-
-
-// on keyboard cleanup notification, on termination signal break with
-// notification preserved
-void handle_signal(int num) {
- lprintf(NULL, INF, "received signal %d", num);
- switch (num) {
- case SIGINT:
- case SIGTERM:
- default:
- quit = RTM_QUIT_PRESERVE;
- break;
- }
-}
-
-
-int main(int argn, char *argv[]) {
- struct sigaction sa;
- sigset_t sset;
- int i, j;
- double t1, t2, last_summary = 0, start_time;
- thread_t *t;
- struct stat pstat;
- pid_t watched;
- int status;
- edg_wll_Context ctx = NULL;
- int retval = RTM_EXIT_ERROR;
- int cert_mtime = 0;
-
- // load basic configurations
- switch (config_preload(argn, argv)) {
- case 0:
- break;
- case 1:
- retval = RTM_EXIT_OK;
- goto quit_guard0;
- break;
- default:
- retval = RTM_EXIT_ERROR;
- goto quit_guard0;
- }
-
- // daemonize
- if (config.pidfile) {
- FILE *f;
- char s[256];
-
- if ((f = fopen(config.pidfile, "rt"))) {
- if (fscanf(f, "%255[^\n\r]", s) == 1) {
- if (kill(atoi(s),0)) {
- lprintf(NULL, WRN, "stale pidfile, pid = %s, pidfile '%s'", s, config.pidfile);
- fclose(f);
- }
- else {
- lprintf(NULL, ERR, "another instance running, pid = %s, pidfile '%s'", s, config.pidfile);
- fclose(f);
- goto quit_guard0;
- }
- } else {
- lprintf(NULL, ERR, "another instance possibly running, can't read pidfile '%s': %s", config.pidfile, strerror(errno));
- fclose(f);
- goto quit_guard0;
- }
- } else if (errno != ENOENT) {
- lprintf(NULL, ERR, "error opening pidfile '%s': %s", config.pidfile, strerror(errno));
- goto quit_guard0;
- }
- }
- if (config.daemonize) {
- if (daemon(0, 0) == -1) {
- lprintf(NULL, ERR, "can't daemonize: %s", strerror(errno));
- goto quit_guard0;
- }
- }
-
- // disable signals to the guardian
- sigemptyset(&sset);
- sigaddset(&sset, SIGABRT);
- sigaddset(&sset, SIGTERM);
- sigaddset(&sset, SIGINT);
- pthread_sigmask(SIG_BLOCK, &sset, NULL);
-
- if (!config.guard) {
- // not guard
- if (config.pidfile) {
- FILE *f;
-
- if ((f = fopen(config.pidfile, "wt")) == NULL) {
- lprintf(NULL, ERR, "can't create pidfile '%s': %s", config.pidfile, strerror(errno));
- goto quit_guard0;
- }
- fprintf(f, "%d", getpid());
- fclose(f);
- }
- } else
- // guard
- while ((watched = fork()) != 0) {
- if (watched == -1) {
- lprintf(NULL, ERR, "fork() failed: %s", strerror(errno));
- goto quit_guard;
- }
- if (config.pidfile) {
- FILE *f;
-
- if ((f = fopen(config.pidfile, "wt")) == NULL) {
- lprintf(NULL, ERR, "can't create pidfile '%s': %s", config.pidfile, strerror(errno));
- goto quit_guard0;
- }
- fprintf(f, "%d", watched);
- fclose(f);
- }
- if (waitpid(watched, &status, 0) == -1) {
- lprintf(NULL, ERR, "waitpid() failed: %s", strerror(errno));
- // orpaned child will restart later anyway,
- // better to end the child process just now
- kill(watched, SIGTERM);
- goto quit_guard;
- }
- if (WIFSIGNALED(status)) {
- switch (WTERMSIG(status)) {
- case SIGSEGV:
- case SIGILL:
- case SIGABRT:
-#ifdef SIGBUS
- case SIGBUS:
-#endif
- lprintf(NULL, ERR, "caught signal %d from process %d, resurrecting...", WTERMSIG(status), watched);
- // slow down the core generator ;-)
- // disabled signals and ended child in pidfile, live with it
- pthread_sigmask(SIG_UNBLOCK, &sset, NULL);
- if (config.pidfile) {
- if (remove(config.pidfile) == -1) lprintf(NULL, WRN, "can't remove pidfile '%s': %s", config.pidfile, strerror(errno));
- }
- sleep(2);
- pthread_sigmask(SIG_BLOCK, &sset, NULL);
- break;
- default:
- lprintf(NULL, WRN, "ended with signal %d", WTERMSIG(status));
- goto quit_guard;
- }
- } else if (WIFEXITED(status)) {
- retval = WEXITSTATUS(status);
- switch(retval) {
- case RTM_EXIT_OK:
- lprintf(NULL, INF, "exit with status %d, OK", retval);
- goto quit_guard;
- case RTM_EXIT_RELOAD:
- lprintf(NULL, INF, "exit with status %d, reloading", retval);
- break;
- default:
- lprintf(NULL, WRN, "exit with status %d, error", retval);
- goto quit_guard;
- }
- } else {
- lprintf(NULL, ERR, "unknown child status");
- goto quit_guard;
- }
- }
-
- // child continues...
-
- // threads && Globus
- if (edg_wll_gss_initialize()) {
- lprintf(NULL, ERR, "can't initialize GSS");
- goto quit_guard;
- }
-
-#ifndef WITH_OLD_LB
- // connection pool manually (just for tuning memory leaks)
- if (!edg_wll_initConnections()) {
- lprintf(NULL, ERR, "can't initialize LB connections");
- goto quit_guard;
- }
-#endif
-
-#ifdef WITH_LBU_DB
- // database
- switch(db_init(NULL, &db.dbctx)) {
- case 0:
- break;
- case -1:
- // no db
- break;
- default:
- // error
- goto quit;
- }
-#endif
-
- // load configurations
- if (config_load()) goto quit;
-#ifdef WITH_OLD_LB
- // other client certificate settings ignored by older globus,
- // using environment (certificate the same for all threads)
- {
- char *s;
-
- if (config.cert) {
- asprintf(&s, "X509_USER_CERT=%s", config.cert);
- putenv(s);
- }
- if (config.key) {
- asprintf(&s, "X509_USER_KEY=%s", config.key);
- putenv(s);
- }
- }
-#endif
-
- // load previous notifications
- if (load_notifs()) goto quit;
- // compare lb servers from configuration and notifications,
- // or clean up and exit if specified
- if (reconcile_threads()) goto quit;
- if (config.cleanup) {
- retval = RTM_EXIT_OK;
- goto quit;
- }
-
- // signal handler
- sa.sa_handler = handle_signal;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESETHAND;
- if (sigaction(SIGABRT, &sa, NULL) == -1
- || sigaction(SIGTERM, &sa, NULL) == -1
- || sigaction(SIGINT, &sa, NULL) == -1) {
- lprintf(NULL, ERR, "can't handle signal: %s", strerror(errno));
- goto quit;
- }
- // enable signals in main
- pthread_sigmask(SIG_UNBLOCK, &sset, NULL);
-
- // launch the threads
- for (i = 0; i < config.nthreads; i++) {
- t = threads + i;
- t->id = i;
- if (pthread_create(&threads[i].thread, NULL, notify_thread, t) != 0) {
- lprintf(NULL, ERR, "[main] can't create %d. thread: %s\n", i, strerror(errno));
- goto quit;
- }
- }
-
- edg_wll_InitContext(&ctx);
- if (config.cert) edg_wll_SetParam(ctx, EDG_WLL_PARAM_X509_CERT, config.cert);
- if (config.key) edg_wll_SetParam(ctx, EDG_WLL_PARAM_X509_KEY, config.key);
- last_summary = 0;
- start_time = rtm_gettimeofday();
- while (!quit) {
- t1 = rtm_gettimeofday();
- if (t1 - last_summary > RTM_SUMMARY_POLL_TIME) {
- last_summary = t1;
- rtm_summary(ctx, &db);
- }
- if (config.guard) {
- if (t1 - start_time > RTM_SUICIDE_TIME) {
- quit = RTM_QUIT_RELOAD;
- lprintf(NULL, INF, "preventive suicide");
- break;
- }
- if (config.cert) {
- if (stat(config.cert, &pstat) == 0) {
- if (!cert_mtime) cert_mtime = pstat.st_mtime;
- if (cert_mtime < pstat.st_mtime) {
- lprintf(NULL, INF, "certificate '%s' changed, reloading", config.cert);
- quit = RTM_QUIT_RELOAD;
- break;
- }
- } else {
- lprintf(NULL, ERR, "can't check certificate file '%s'", config.cert, strerror(errno));
- }
- }
- }
- t2 = rtm_gettimeofday();
- if (t2 - t1 < RTM_IDLE_POLL_TIME) usleep((RTM_IDLE_POLL_TIME + t1 - t2) * 1000000);
- }
- retval = quit == RTM_QUIT_RELOAD ? RTM_EXIT_RELOAD : RTM_EXIT_OK;
-quit:
- // cleanup on error
- if (!quit) quit = RTM_QUIT_CLEANUP;
- if (threads) {
- for (i = 0; i < config.nthreads; i++) {
- t = threads + i;
- if (t->thread) pthread_join(t->thread, NULL);
- for (j = 0; j < t->nservers; j++) notif_free(t->notifs + j);
- free(t->notifs);
- }
- free(threads);
- }
-
- if (config.pidfile && !config.guard) {
- if (remove(config.pidfile) == -1) lprintf(NULL, WRN, "can't remove pidfile '%s': %s", config.pidfile, strerror(errno));
- }
-
-#ifdef WITH_LBU_DB
- db_free(NULL, db.dbctx);
-#endif
- edg_wll_FreeContext(ctx);
- db_free_notifs();
- config_free();
-#ifndef WITH_OLD_LB
- edg_wll_poolFree();
-#endif
-
- return retval;
-
-quit_guard:
- if (config.pidfile) {
- if (remove(config.pidfile) == -1) lprintf(NULL, WRN, "can't remove pidfile '%s': %s", config.pidfile, strerror(errno));
- }
-quit_guard0:
- config_free();
- return retval;
-}