java/buildconf/builder/config/satellite/default/rhn_web.conf | 3
monitoring/NPalert/AlertDB.pm | 4
monitoring/NPalert/NotificationDB.pm | 4
monitoring/PerlModules/NP/OracleDB/DBRecord.pm | 4
monitoring/PerlModules/NP/OracleDB/OracleDB.pm | 4
monitoring/PerlModules/NP/OracleDB/perl-NOCpulse-OracleDB.spec | 2
monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm | 4
spacewalk/config/var/lib/rhn/rhn-satellite-prep/etc/rhn/rhn.conf | 2
spacewalk/setup/bin/spacewalk-setup | 12
web/conf/rhn_web.conf | 3
web/modules/pxt/PXT/ApacheHandler.pm | 11
web/modules/rhn/RHN/DB.pm | 139 +---------
web/modules/rhn/RHN/DB/DataSource.pm | 2
web/modules/rhn/RHN/DBI.pm | 76 +++++
web/spacewalk-web.spec | 1
15 files changed, 105 insertions(+), 166 deletions(-)
New commits:
commit 352ec92a5da7efb381d55f49eaa265089b1299b0
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Tue Jan 31 14:07:44 2012 +0100
The RHN::DB::connect does not accept any arguments anymore.
diff --git a/web/modules/rhn/RHN/DB/DataSource.pm b/web/modules/rhn/RHN/DB/DataSource.pm
index f1899b9..df75d9d 100644
--- a/web/modules/rhn/RHN/DB/DataSource.pm
+++ b/web/modules/rhn/RHN/DB/DataSource.pm
@@ -67,7 +67,7 @@ sub run_query {
throw "Empty query for mode " . $self->mode()
unless $query_body;
- my $dbh = $params{-transaction} || RHN::DB->connect($self->dsn);
+ my $dbh = $params{-transaction} || RHN::DB->connect();
my $sth;
$sth = $dbh->prepare_cached($query_body);
commit 355a299175a5913e169555241c8c16e7c7706613
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Tue Jan 31 14:00:33 2012 +0100
In monitoring, use RHN::DBI instead of RHN::DB because we do not want to reuse the
connection.
diff --git a/monitoring/NPalert/AlertDB.pm b/monitoring/NPalert/AlertDB.pm
index e0e3c07..fadf552 100644
--- a/monitoring/NPalert/AlertDB.pm
+++ b/monitoring/NPalert/AlertDB.pm
@@ -10,7 +10,7 @@ use Class::MethodMaker
use Data::Dumper; # for debugging
use DBI;
use NOCpulse::Config;
-use RHN::DB;
+use RHN::DBI;
use NOCpulse::Log::Logger;
my $Log = NOCpulse::Log::Logger->new(__PACKAGE__);
@@ -36,7 +36,7 @@ sub connect {
}
# Open a connection to the DB
- my $dbh = RHN::DB->connect;
+ my $dbh = RHN::DBI->connect;
if ($dbh) {
diff --git a/monitoring/NPalert/NotificationDB.pm b/monitoring/NPalert/NotificationDB.pm
index 8b2c034..633ddb1 100644
--- a/monitoring/NPalert/NotificationDB.pm
+++ b/monitoring/NPalert/NotificationDB.pm
@@ -10,7 +10,7 @@ use NOCpulse::Config;
use NOCpulse::Probe::DataSource::AbstractDatabase qw(:constants);
use NOCpulse::Probe::Error;
-use RHN::DB;
+use RHN::DBI;
use base qw(NOCpulse::Probe::DataSource::AbstractDatabase);
use Class::MethodMaker
@@ -76,7 +76,7 @@ sub init {
sub connect {
my ($self, %paramHash) = @_;
# Open a connection to the DB
- $self->dbh(RHN::DB->connect);
+ $self->dbh(RHN::DBI->connect);
return $self->dbh;
}
diff --git a/monitoring/PerlModules/NP/OracleDB/DBRecord.pm
b/monitoring/PerlModules/NP/OracleDB/DBRecord.pm
index 9032575..046592c 100644
--- a/monitoring/PerlModules/NP/OracleDB/DBRecord.pm
+++ b/monitoring/PerlModules/NP/OracleDB/DBRecord.pm
@@ -91,8 +91,8 @@ sub DatabaseConnection
if (NOCpulse::DBRecord->getClassInstVar('DatabaseConnection')) {
return NOCpulse::DBRecord->getClassInstVar('DatabaseConnection');
} else {
- use RHN::DB;
- if (my $dbMain = RHN::DB->connect) {
+ use RHN::DBI;
+ if (my $dbMain = RHN::DBI->connect) {
NOCpulse::DBRecord->setClassVar('DatabaseConnection', $dbMain);
return $dbMain;
}
diff --git a/monitoring/PerlModules/NP/OracleDB/OracleDB.pm
b/monitoring/PerlModules/NP/OracleDB/OracleDB.pm
index 525bd95..5366c1d 100644
--- a/monitoring/PerlModules/NP/OracleDB/OracleDB.pm
+++ b/monitoring/PerlModules/NP/OracleDB/OracleDB.pm
@@ -9,7 +9,7 @@ use strict;
use DBI;
use NOCpulse::Debug;
use NOCpulse::Config;
-use RHN::DB;
+use RHN::DBI;
# Global defaults
my $DEFAULTDATEFORMAT = 'YYYY-MM-DD HH24:MI:SS';
@@ -128,7 +128,7 @@ sub connect {
my $AutoCommit = $paramHash{AutoCommit} || 0;
$self->dprint(2, "Connecting to DB\n");
- my $dbh = RHN::DB->connect;
+ my $dbh = RHN::DBI->connect;
if ($DBI::err) { $@ = $DBI::errstr ; return undef }
diff --git a/monitoring/PerlModules/NP/OracleDB/perl-NOCpulse-OracleDB.spec
b/monitoring/PerlModules/NP/OracleDB/perl-NOCpulse-OracleDB.spec
index 5f6b392..ee726f0 100644
--- a/monitoring/PerlModules/NP/OracleDB/perl-NOCpulse-OracleDB.spec
+++ b/monitoring/PerlModules/NP/OracleDB/perl-NOCpulse-OracleDB.spec
@@ -7,7 +7,7 @@ Source0:
https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}
BuildArch: noarch
Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo
$version))
BuildRequires: perl(NOCpulse::Debug) perl(NOCpulse::Config) perl(NOCpulse::Utils::XML)
perl(NOCpulse::Object)
-BuildRequires: perl(RHN::DB)
+BuildRequires: perl(RHN::DBI)
BuildRequires: perl(DBI) perl(ExtUtils::MakeMaker)
Group: Development/Libraries
License: GPLv2
diff --git a/monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm
b/monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm
index fed39bc..32d384e 100644
--- a/monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm
+++ b/monitoring/nocpulse-common/perl-API/NOCpulse/NOCpulseini.pm
@@ -4,7 +4,7 @@ use strict;
use DBI;
use IO::AtomicFile;
use LWP::UserAgent;
-use RHN::DB;
+use RHN::DBI;
use Class::MethodMaker
get_set =>
@@ -39,7 +39,7 @@ sub connect {
my $self = shift;
# Make DB connection
- my $dbh = RHN::DB->connect;
+ my $dbh = RHN::DBI->connect;
# Set up for graceful exit
$SIG{'INT'} = $self->can('bailout');
unless (defined($dbh)) {
commit a3d0771c35d90cd44e755bd0cc5d6ee4a583cd4b
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Tue Jan 31 11:44:23 2012 +0100
Factor the connection parameters config read to RHN::DBI, start to use it in RHN::DB,
also support just one database connection.
diff --git a/web/modules/rhn/RHN/DB.pm b/web/modules/rhn/RHN/DB.pm
index c1c0ed3..191d290 100644
--- a/web/modules/rhn/RHN/DB.pm
+++ b/web/modules/rhn/RHN/DB.pm
@@ -16,64 +16,12 @@
package RHN::DB;
use strict;
-use DBI;
+use RHN::DBI ();
use Carp;
use RHN::Exception;
-use PXT::Config;
our @ISA = qw/DBI/;
-my %aliases;
-my %handles = ();
-
-# Add an alias, maps dbi connection string to an array of username,
-# password, and params.
-sub add_alias {
- my $class = shift;
- my $dbi_connection_string = shift;
-
- $aliases{$dbi_connection_string} = [ @_ ];
-}
-
-sub lookup_alias {
- my $class = shift;
- my $alias = shift;
-
- return $aliases{$alias};
-}
-
-# Return a DBI connection string based on the given inputs. This is also
-# used as a key in our hash of established connections.
-sub get_dbi_connection_string {
- my $class = shift;
- my $backend = shift;
- my $host = shift;
- my $port = shift;
- my $dbname = shift; # sid for oracle backend
-
- if ($backend eq "oracle") {
- return "dbi:Oracle:$dbname";
- }
- elsif ($backend eq "postgresql") {
- my $q = "dbi:Pg:dbname=$dbname";
- if (defined $host and $host ne '') {
- $q .= ";host=$host";
- if (defined $port and $port ne '') {
- $q .= ";port=$port";
- }
- }
- return $q;
- }
-}
-
-$RHN::DB::default_connection = undef;
-
-sub set_default_connection {
- my $class = shift;
-
- $RHN::DB::default_connection = shift;
-}
-
# this forces connection immediately after form, before first request
# is served. can cause a bit of a rush to the db as a bunch of
# httpd's connect, but should be manageable. typically called in
@@ -81,27 +29,21 @@ sub set_default_connection {
sub apache_child_init_handler {
my $class = shift;
- my @aliases = @_ ? @_ : ($RHN::DB::default_handle);
-
- for my $alias (@aliases) {
- if ($class->lookup_alias($alias)) {
- $class->connect($alias);
- }
- }
+ $class->connect();
}
# called after every request. necessary to cleanup uncommitted
# transactions and such
+my $dbh;
sub connection_cleanup {
my $class = shift;
- for my $alias (keys %handles) {
- my $dbh = $handles{$alias};
+ if (defined $dbh) {
if ($dbh->{ActiveKids}) {
- warn "Database handle '$alias' has active children after request
completion.";
+ warn "Database handle has active children after request completion.";
}
while($dbh->in_nested_transaction) {
@@ -119,86 +61,39 @@ sub connection_cleanup {
sub soft_connect {
my $class = shift;
- my $alias = shift;
- my $ret = eval { $class->connect($alias) };
+ my $ret = eval { $class->connect(@_) };
return $ret;
}
sub connect {
my $class = shift;
- my $alias = shift;
- my $username = shift;
- my $password = shift;
-
- # Store db handlers using an alias which is equal to their DBI
- # connection string. Note that this does not include username or
- # password information and thus we cannot have multiple connections
- # to one db as different users (currently). If this turns out to be
- # a problem, suggest we prepend/append the username in the alias hash
- # key.
-
- # TODO: Once upon a time these aliases were just Oracle dsn's, if the incoming
- # alias is in this format, convert it to an Oracle dbi string?
-
- $alias ||= ($RHN::DB::default_connection ||= $class->get_dbi_connection_string(
-
PXT::Config->get("db_backend"),
-
PXT::Config->get("db_host"),
-
PXT::Config->get("db_port"),
-
PXT::Config->get("db_name")));
-
- if ($handles{$alias} and $handles{$alias}->{Active}) {
- my $dbh = $handles{$alias};
-
- if (not $dbh->ping()) {
- Carp::cluck("Cannot ping database handle for $alias: $DBI::errstr
($@)");
- }
- else {
- return $handles{$alias};
- }
+ if (@_) {
+ Carp::confess "The RHN::DB::connect does not accept any parameters.\n";
}
- # for bug #159720, set the NLS_LANG environment variable from the
- # config option if it is set.
- my $nls_lang = PXT::Config->get('server', 'nls_lang');
- if ($nls_lang) {
- $ENV{NLS_LANG} = $nls_lang;
+ if (defined $dbh and $dbh->ping()) {
+ return $dbh;
}
- $class->add_alias($alias, PXT::Config->get("db_user"),
- PXT::Config->get("db_password"), { });
-
- my $alias_data = $class->lookup_alias($alias);
- Carp::croak "RHN::DB->connect($alias): No such alias '$alias'"
unless $alias_data;
-
- my $params;
- ($username, $password, $params) = @{ $alias_data };
+ my ($dsn, $login, $password, $attr) = RHN::DBI::_get_dbi_connect_parameters();
+ $attr->{HandleError} = \&RHN::DB::handle_error;
+ $attr->{private_rhndb_transaction_level} = 0;
- my $dbh = $handles{$alias} = $class->direct_connect($alias, $username, $password,
- { %$params,
- HandleError => \&RHN::DB::handle_error,
- RaiseError => 1,
- PrintError => 0,
- Taint => 0,
- AutoCommit => 0,
- private_rhndb_transaction_level => 0,
- FetchHashKeyName => 'NAME_uc',
- pg_enable_utf8 => 1,
- });
+ $dbh = $class->direct_connect($dsn, $login, $password, $attr);
# this dbh is from a cache, which means disconnects fail
$dbh->{private_from_cache} = 1;
- Carp::croak "$class->connect($alias) failed: $DBI::errstr" unless $dbh;
+ Carp::croak "$class->connect() failed: $DBI::errstr" unless $dbh;
$dbh->init_db_handle();
$dbh->init_db_session();
if (not $dbh->ping()) {
$dbh->force_disconnect;
- delete $handles{$alias};
- Carp::croak("Cannot ping database handle for $alias: $DBI::errstr");
+ Carp::croak("Cannot ping database handle: $DBI::errstr");
}
return $dbh;
}
diff --git a/web/modules/rhn/RHN/DBI.pm b/web/modules/rhn/RHN/DBI.pm
new file mode 100644
index 0000000..ff3a720
--- /dev/null
+++ b/web/modules/rhn/RHN/DBI.pm
@@ -0,0 +1,76 @@
+#
+# Copyright (c) 2011 Red Hat, Inc.
+#
+# This software is licensed to you under the GNU General Public License,
+# version 2 (GPLv2). There is NO WARRANTY for this software, express or
+# implied, including the implied warranties of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+# along with this software; if not, see
+#
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+#
+# Red Hat trademarks are not licensed under GPLv2. No permission is
+# granted to use or replicate Red Hat trademarks that are incorporated
+# in this software or its documentation.
+#
+
+package RHN::DBI;
+
+use strict;
+use warnings FATAL => 'all';
+use DBI ();
+use PXT::Config ();
+use Carp ();
+
+my %DEFAULT_ATTRIBUTES = (
+ RaiseError => 1,
+ PrintError => 0,
+ Taint => 0,
+ AutoCommit => 0,
+ FetchHashKeyName => 'NAME_uc',
+ pg_enable_utf8 => 1,
+);
+
+# Return a DBI connect parameters, based on data in
+# /etc/rhn/rhn.conf. It will get the configuration values once
+# and use them for subsequent calls.
+my ($DSN, $LOGIN, $PASSWORD);
+sub _get_dbi_connect_parameters {
+ if (not defined $DSN) {
+ my $backend = PXT::Config->get("db_backend");
+ my $dbname = PXT::Config->get("db_name");
+ if ($backend eq "oracle") {
+ $DSN = "dbi:Oracle:$dbname";
+
+ my $nls_lang = PXT::Config->get('server', 'nls_lang');
+ if (defined $nls_lang and $nls_lang ne '') {
+ $ENV{NLS_LANG} = $nls_lang;
+ }
+ } else {
+ $DSN = "dbi:Pg:dbname=$dbname";
+ my $host = PXT::Config->get("db_host");
+ if (defined $host and $host ne '') {
+ $DSN .= ";host=$host";
+ my $port = PXT::Config->get("db_port");
+ if (defined $port and $port ne '') {
+ $DSN .= ";port=$port";
+ }
+ }
+ }
+ $LOGIN = PXT::Config->get("db_user");
+ $PASSWORD = PXT::Config->get("db_password");
+ }
+
+ return ($DSN, $LOGIN, $PASSWORD, { %DEFAULT_ATTRIBUTES });
+}
+
+# Do a connect via DBI to database configured in /etc/rhn/rhn.conf.
+sub connect {
+ my $class = shift;
+ if (@_) {
+ Carp::confess "The RHN::DBI::connect does not accept any parameters.\n";
+ }
+ return DBI->connect(_get_dbi_connect_parameters());
+}
+
+1;
+
diff --git a/web/spacewalk-web.spec b/web/spacewalk-web.spec
index 95a0e09..2b26178 100644
--- a/web/spacewalk-web.spec
+++ b/web/spacewalk-web.spec
@@ -221,6 +221,7 @@ rm -rf $RPM_BUILD_ROOT
%{perl_vendorlib}/RHN/SessionSwap.pm
%{perl_vendorlib}/RHN/Exception.pm
%{perl_vendorlib}/RHN/DB.pm
+%{perl_vendorlib}/RHN/DBI.pm
%{perl_vendorlib}/PXT/Config.pm
%attr(640,root,apache) %{_prefix}/share/rhn/config-defaults/rhn_web.conf
%doc LICENSE
commit 0f660de3fb8f957e105ccc2030d9c87910a92ab8
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Tue Jan 31 11:35:59 2012 +0100
Removing code which is long commented out.
diff --git a/web/modules/pxt/PXT/ApacheHandler.pm b/web/modules/pxt/PXT/ApacheHandler.pm
index 27ad37a..245db3e 100644
--- a/web/modules/pxt/PXT/ApacheHandler.pm
+++ b/web/modules/pxt/PXT/ApacheHandler.pm
@@ -312,17 +312,6 @@ sub initialize_pxt {
PXT::Config->set(base_port => $base_port);
}
-# NOTE: Commenting out as part of PostgreSQL effort, likely unused code.
-# Personalities once used to prepend a token to the cookie to avoid
-# conflicts with RHN cookies. Suspected to now be unused.
-#
-#if ($r->pnotes('hostname_personality')) {
-# my $dsn = $r->pnotes('hostname_personality');
-# if (RHN::DB->lookup_alias($dsn)) {
-# RHN::DB->set_default_handle($dsn);
-# }
-# }
-
if (PXT::Config->get('profile_queries')) {
my $dbh = RHN::DB->connect;
$dbh->enable_profile;
commit f3ac6fb02294310d07ec3ea619427822f193ab7c
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Tue Jan 31 11:33:58 2012 +0100
Monitoring uses RHN::DB, so no need to have the extra connect parameters.
diff --git a/spacewalk/setup/bin/spacewalk-setup b/spacewalk/setup/bin/spacewalk-setup
index 133820b..274e148 100755
--- a/spacewalk/setup/bin/spacewalk-setup
+++ b/spacewalk/setup/bin/spacewalk-setup
@@ -1293,23 +1293,11 @@ sub setup_monitoring {
RHN_ADMIN_EMAIL => $answers->{'admin-email'},
MAIL_MX => $answers->{'mail-mx'} || 'localhost',
MDOM => $answers->{mdom} || $answers->{hostname},
- RHN_DB_NAME => $answers->{'db-name'},
- RHN_DB_USERNAME => $answers->{'db-user'},
- RHN_DB_PASSWD => $answers->{'db-password'},
- RHN_DB_TABLE_OWNER => $answers->{'db-user'},
RHN_SAT_HOSTNAME => $answers->{hostname},
XPROTO => 'https',
RHN_SAT_WEB_PORT => 443
);
- # DB connection params not yet written to rhn.conf, must specify them manually:
- my $connection_string =
- RHN::DB->get_dbi_connection_string($answers->{'db-backend'},
- $answers->{'db-host'}, $answers->{'db-port'},
$answers->{'db-name'});
- RHN::DB->add_alias($connection_string, $answers->{'db-user'},
- $answers->{'db-password'}, { } );
- RHN::DB->set_default_connection($connection_string);
-
update_monitoring_config($answers, \%mon_config);
# Bugzilla 466747: On s390x, stty: standard input: Bad file descriptor
commit 251e06c97f7039363afb79abec5a90bf30a195ed
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Mon Jan 30 16:27:56 2012 +0100
Removing the web.debug_disable_database option -- it is not supported beyond RHN::DB
anyway.
diff --git a/java/buildconf/builder/config/satellite/default/rhn_web.conf
b/java/buildconf/builder/config/satellite/default/rhn_web.conf
index 876e9cd..4785989 100644
--- a/java/buildconf/builder/config/satellite/default/rhn_web.conf
+++ b/java/buildconf/builder/config/satellite/default/rhn_web.conf
@@ -239,9 +239,6 @@ web.trace_session = 0
# email address for feedback
web.rhn_feedback_address = rhn-feedback(a)redhat.com
-# for debugging: act like the db has disappeared
-web.debug_disable_database = 0
-
# max number of sets of isos the "Latest ISOs" page should use
web.max_latest_iso_categories = 3
diff --git a/spacewalk/config/var/lib/rhn/rhn-satellite-prep/etc/rhn/rhn.conf
b/spacewalk/config/var/lib/rhn/rhn-satellite-prep/etc/rhn/rhn.conf
index 7ccbd1d..d08becf 100644
--- a/spacewalk/config/var/lib/rhn/rhn-satellite-prep/etc/rhn/rhn.conf
+++ b/spacewalk/config/var/lib/rhn/rhn-satellite-prep/etc/rhn/rhn.conf
@@ -1,4 +1,3 @@
-traceback_mail = @@traceback_mail@@
mount_point = @@mount_point@@
kickstart_mount_point = @@kickstart_mount_point@@
repomd_cache_mount_point = /var/cache
@@ -42,7 +41,6 @@ hibernate.connection.driver_proto=@@hibernate_driver_proto@@
web.satellite = 1
web.satellite_install = @@satellite_install@@
-web.debug_disable_database = 0
web.session_swap_secret_1 = @@session_swap_secret_1@@
web.session_swap_secret_2 = @@session_swap_secret_2@@
diff --git a/web/conf/rhn_web.conf b/web/conf/rhn_web.conf
index 31276da..874f0d7 100644
--- a/web/conf/rhn_web.conf
+++ b/web/conf/rhn_web.conf
@@ -208,9 +208,6 @@ web.db_password =
# trace all sessions? (never enable in prod!)
web.trace_session = 0
-# for debugging: act like the db has disappeared
-web.debug_disable_database = 0
-
# max number of sets of isos the "Latest ISOs" page should use
web.max_latest_iso_categories = 3
diff --git a/web/modules/rhn/RHN/DB.pm b/web/modules/rhn/RHN/DB.pm
index ddddf93..c1c0ed3 100644
--- a/web/modules/rhn/RHN/DB.pm
+++ b/web/modules/rhn/RHN/DB.pm
@@ -132,8 +132,6 @@ sub connect {
my $username = shift;
my $password = shift;
- return if PXT::Config->get('debug_disable_database');
-
# Store db handlers using an alias which is equal to their DBI
# connection string. Note that this does not include username or
# password information and thus we cannot have multiple connections