Changes to 'refs/tags/spacewalk-schema-1.3.15-1'
by Jan Pazdziora
Tag 'spacewalk-schema-1.3.15-1' created by Jan Pazdziora <jpazdziora(a)redhat.com> at 2011-01-21 13:39 +0000
Tagging package [spacewalk-schema] version [1.3.15-1] in directory [schema/spacewalk/].
Changes since spacewalk-proxy-1.3.11-1:
Jan Pazdziora (18):
Changing run_query to just return the first record, in the query mode.
Use the dashes after heading to find the start of the result.
Do explicit exit; further down there are just subroutine definitions.
Make the run_query only run query, and execute the upgrade with separate sqlplus call.
Do logging by redirecting stdout/stderr of sqlplus.
Change spacewalk-schema-upgrade to use spacewalk-sql.
Removing Oracle-specific commands which are already in spacewalk-sql.
Concatenate strings.
Fixing PE.evr.as_vre_simple() issue on PostgreSQL.
Fixing typo.
Only do the tablespace name replace on Oracle.
PostgreSQL does not know quit, removing, not needed.
Moving database-specific "end" parts off spacewalk-schema-upgrade script, reusing end.sql.
Sadly, the directory name is postgres even if the backend name is postgresql.
Use current_timestamp which works on both database backends.
Mark Oracle-specific schema upgrade scripts as such, teach spacewalk-schema-upgrade to process them.
We cannot EXIT in end.sql because upon schema upgrade, new schema version needs to be set.
Automatic commit of package [spacewalk-schema] release [1.3.15-1].
Tomas Lestach (3):
Introducing spacewalk-server-no-install rhel5 server comps group
aligning server comps to have spacewalk-server-docs and spacewalk-server-no-install group
removing relaxngDatatype* from rhel6 server comps
---
rel-eng/comps/comps-spacewalk-server-fedora13.xml | 22
rel-eng/comps/comps-spacewalk-server-fedora14.xml | 22
rel-eng/comps/comps-spacewalk-server-rhel5.xml | 22
rel-eng/comps/comps-spacewalk-server-rhel6.xml | 18
rel-eng/packages/spacewalk-schema | 2
schema/spacewalk/oracle/end.sql | 4
schema/spacewalk/postgres/end.sql | 2
schema/spacewalk/spacewalk-schema-upgrade | 191 -
schema/spacewalk/spacewalk-schema.spec | 7
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql | 1212 ------
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql.oracle | 1212 ++++++
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql | 4
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql.oracle | 4
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql | 28
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql.oracle | 28
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql | 235 -
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql.oracle | 235 +
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql | 3
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql.oracle | 3
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql | 3
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql.oracle | 3
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql | 33
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql.oracle | 33
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql | 234 -
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql.oracle | 234 +
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql | 54
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql.oracle | 54
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql | 252 -
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql.oracle | 252 +
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql | 1857 ----------
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql.oracle | 1857 ++++++++++
31 files changed, 4066 insertions(+), 4054 deletions(-)
---
13 years, 3 months
rel-eng/packages schema/spacewalk
by Jan Pazdziora
rel-eng/packages/spacewalk-schema | 2 +-
schema/spacewalk/spacewalk-schema.spec | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
New commits:
commit 93f1638f6766e6f2c5a8f3406cc064839d703ed1
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jan 21 14:39:10 2011 +0100
Automatic commit of package [spacewalk-schema] release [1.3.15-1].
diff --git a/rel-eng/packages/spacewalk-schema b/rel-eng/packages/spacewalk-schema
index 14fd128..679e2cb 100644
--- a/rel-eng/packages/spacewalk-schema
+++ b/rel-eng/packages/spacewalk-schema
@@ -1 +1 @@
-1.3.14-1 schema/spacewalk/
+1.3.15-1 schema/spacewalk/
diff --git a/schema/spacewalk/spacewalk-schema.spec b/schema/spacewalk/spacewalk-schema.spec
index 459777f..607d71d 100644
--- a/schema/spacewalk/spacewalk-schema.spec
+++ b/schema/spacewalk/spacewalk-schema.spec
@@ -2,7 +2,7 @@ Name: spacewalk-schema
Group: Applications/Internet
Summary: Oracle SQL schema for Spacewalk server
-Version: 1.3.14
+Version: 1.3.15
Release: 1%{?dist}
Source0: %{name}-%{version}.tar.gz
@@ -66,6 +66,9 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/spacewalk-sql*
%changelog
+* Fri Jan 21 2011 Jan Pazdziora 1.3.15-1
+- Changed spacewalk-schema-upgrade to use spacewalk-sql, to run on PostgreSQL.
+
* Thu Jan 20 2011 Tomas Lestach <tlestach(a)redhat.com> 1.3.14-1
- updating Copyright years for year 2011 (tlestach(a)redhat.com)
- The maximum pagesize is 50000 -- this will prevent the headings to be
13 years, 3 months
2 commits - schema/spacewalk
by Jan Pazdziora
schema/spacewalk/oracle/end.sql | 2
schema/spacewalk/postgres/end.sql | 2
schema/spacewalk/spacewalk-schema-upgrade | 8
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql | 1212 ------
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql.oracle | 1212 ++++++
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql | 4
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql.oracle | 4
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql | 28
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql.oracle | 28
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql | 235 -
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql.oracle | 235 +
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql | 3
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql.oracle | 3
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql | 3
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql.oracle | 3
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql | 33
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql.oracle | 33
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql | 234 -
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql.oracle | 234 +
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql | 54
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql.oracle | 54
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql | 252 -
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql.oracle | 252 +
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql | 1857 ----------
schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql.oracle | 1857 ++++++++++
25 files changed, 3920 insertions(+), 3922 deletions(-)
New commits:
commit 9b4ac845c6a41cb7d6d8ad00658739b26422ca5b
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jan 21 12:18:58 2011 +0100
We cannot EXIT in end.sql because upon schema upgrade, new schema version needs to be set.
diff --git a/schema/spacewalk/oracle/end.sql b/schema/spacewalk/oracle/end.sql
index 4509747..1ef5409 100644
--- a/schema/spacewalk/oracle/end.sql
+++ b/schema/spacewalk/oracle/end.sql
@@ -32,5 +32,3 @@ begin
end;
/
-EXIT
-
diff --git a/schema/spacewalk/postgres/end.sql b/schema/spacewalk/postgres/end.sql
index 6370a73..bb9e9f1 100644
--- a/schema/spacewalk/postgres/end.sql
+++ b/schema/spacewalk/postgres/end.sql
@@ -1,4 +1,4 @@
--- oracle equivalent source sha1 add00c99b59028f5056a3dac6f14c7112ce6d504
+-- oracle equivalent source sha1 0325bfb06a5e48ee7e9b5af3fd88cc92efb46d9f
--
-- Copyright (c) 2010 Red Hat, Inc.
--
commit 5a31d1dc4efa7375258e84eeeae942a0194e2ece
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jan 21 12:06:53 2011 +0100
Mark Oracle-specific schema upgrade scripts as such, teach spacewalk-schema-upgrade to process them.
diff --git a/schema/spacewalk/spacewalk-schema-upgrade b/schema/spacewalk/spacewalk-schema-upgrade
index 1499d05..7908c0b 100755
--- a/schema/spacewalk/spacewalk-schema-upgrade
+++ b/schema/spacewalk/spacewalk-schema-upgrade
@@ -153,16 +153,16 @@ while (@path) {
die "Directory [$SCHEMA_UPGRADE_DIR/$dir] was seen but is lost now.\n";
}
- my @files = match_overrides("$SCHEMA_UPGRADE_DIR/$dir/*.{sql,ref}");
+ my @files = match_overrides("$SCHEMA_UPGRADE_DIR/$dir/*.{sql,ref}", "$SCHEMA_UPGRADE_DIR/$dir/*.{sql,ref}.$options{db_backend}");
for (my $i = 0; $i < @files; $i++) {
- if ($files[$i] =~ /\.ref$/) {
+ if ($files[$i] =~ /\.ref(\.$options{db_backend})?$/) {
my @subfiles;
local *REF;
open REF, $files[$i] or die "Error reading [$files[$i]]: $!\n";
while (<REF>) {
chomp;
next if /^\s*(#|$)/;
- my @newsubfiles = match_overrides("$SCHEMA_UPGRADE_DIR/$_");
+ my @newsubfiles = match_overrides("$SCHEMA_UPGRADE_DIR/$_", "$SCHEMA_UPGRADE_DIR/$_.$options{db_backend}");
if (not @newsubfiles) {
die "Could not find any files matching [$_] from [$files[$i]]\n";
}
@@ -316,7 +316,7 @@ sub get_shortest_path {
}
sub match_overrides {
- return map {-e "$_.override" ? "$_.override" : $_} sort glob shift;
+ return sort map {-e "$_.override" ? "$_.override" : $_} map { glob } @_;
}
1;
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql
deleted file mode 100644
index bdf0508..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql
+++ /dev/null
@@ -1,1212 +0,0 @@
---
--- Copyright (c) 2008--2010 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.
---
-
-CREATE OR REPLACE
-PACKAGE BODY rhn_channel
-IS
- body_version varchar2(100) := '';
-
- -- Cursor that fetches all the possible base channels for a
- -- (server_arch_id, release, org_id) combination
- cursor base_channel_cursor(
- release_in in varchar2,
- server_arch_id_in in number,
- org_id_in in number
- ) return rhnChannel%ROWTYPE is
- select distinct c.*
- from rhnDistChannelMap dcm,
- rhnServerChannelArchCompat scac,
- rhnChannel c,
- rhnChannelPermissions cp
- where cp.org_id = org_id_in
- and cp.channel_id = c.id
- and c.parent_channel is null
- and c.id = dcm.channel_id
- and c.channel_arch_id = dcm.channel_arch_id
- and dcm.release = release_in
- and scac.server_arch_id = server_arch_id_in
- and scac.channel_arch_id = c.channel_arch_id;
-
- procedure obtain_read_lock(channel_family_id_in in number, org_id_in in number)
- is
- read_lock date;
-
- begin
- select created into read_lock
- from rhnPrivateChannelFamily
- where channel_family_id = channel_family_id_in and org_id = org_id_in
- for update;
- end obtain_read_lock;
-
- PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in in number := null, recalcfamily_in number := 1)
- IS
- channel_parent_val rhnChannel.parent_channel%TYPE;
- parent_subscribed BOOLEAN;
- server_has_base_chan BOOLEAN;
- server_already_in_chan BOOLEAN;
- channel_family_id_val NUMBER;
- server_org_id_val NUMBER;
- available_subscriptions NUMBER;
- available_fve_subs NUMBER;
- consenting_user NUMBER;
- allowed number := 0;
- is_fve CHAR(1) := 'N';
- BEGIN
- if user_id_in is not null then
- allowed := rhn_channel.user_role_check(channel_id_in, user_id_in, 'subscribe');
- else
- allowed := 1;
- end if;
-
- if allowed = 0 then
- rhn_exception.raise_exception('no_subscribe_permissions');
- end if;
-
-
- SELECT parent_channel INTO channel_parent_val FROM rhnChannel WHERE id = channel_id_in;
-
- IF channel_parent_val IS NOT NULL
- THEN
- -- child channel; if attempting to cross-subscribe a child to the wrong base, silently ignore
- parent_subscribed := FALSE;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_parent_val)
- LOOP
- parent_subscribed := TRUE;
- END LOOP check_subscription;
-
- IF NOT parent_subscribed
- THEN
- RETURN;
- END IF;
- ELSE
- -- base channel
- server_has_base_chan := FALSE;
- FOR base IN server_base_subscriptions(server_id_in)
- LOOP
- server_has_base_chan := TRUE;
- END LOOP base;
-
- IF server_has_base_chan
- THEN
- rhn_exception.raise_exception('channel_server_one_base');
- END IF;
- END IF;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
- LOOP
- server_already_in_chan := TRUE;
- END LOOP check_subscription;
-
- IF server_already_in_chan
- THEN
- RETURN;
- END IF;
-
- channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
- IF channel_family_id_val IS NULL
- THEN
- rhn_exception.raise_exception('channel_subscribe_no_family');
- END IF;
-
- --
- -- Use the org_id of the server only if the org_id of the channel = NULL.
- -- This is required for subscribing to shared channels.
- --
- SELECT NVL(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
- INTO server_org_id_val
- FROM rhnChannel
- WHERE id = channel_id_in;
-
- begin
- obtain_read_lock(channel_family_id_val, server_org_id_val);
- exception
- when no_data_found then
- rhn_exception.raise_exception('channel_family_no_subscriptions');
- end;
-
- available_subscriptions := rhn_channel.available_family_subscriptions(channel_family_id_val, server_org_id_val);
- available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
-
- IF available_subscriptions IS NULL OR
- available_subscriptions > 0 or
- can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1 OR
- (available_fve_subs > 0 AND can_server_consume_fve(server_id_in) = 1)
- THEN
- if can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 0 AND available_fve_subs > 0 AND can_server_consume_fve(server_id_in) = 1 THEN
- is_fve := 'Y';
- END IF;
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- server_id_in,
- 'subscribed to channel ' || SUBSTR(c.label, 0, 106),
- c.label
- from rhnChannel c
- where c.id = channel_id_in
- );
- UPDATE rhnServer SET channels_changed = sysdate WHERE id = server_id_in;
- INSERT INTO rhnServerChannel (server_id, channel_id, is_fve) VALUES (server_id_in, channel_id_in, is_fve);
- IF recalcfamily_in > 0
- THEN
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- END IF;
- queue_server(server_id_in, immediate_in);
- ELSE
- rhn_exception.raise_exception('channel_family_no_subscriptions');
- END IF;
-
- END subscribe_server;
-
-
-
- FUNCTION can_convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER)
- RETURN NUMBER
- IS
- CURSOR fve_convertible_entries IS
- select 1 from
- rhnServerFveCapable cap
- where cap.server_id = server_id_in
- AND cap.channel_family_id = channel_family_id_val;
- BEGIN
- FOR entry IN fve_convertible_entries LOOP
- return 1;
- END LOOP;
- RETURN 0;
- END can_convert_to_fve;
-
-
-
- -- Converts server channel_family to use a flex entitlement
- PROCEDURE convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER)
- IS
- available_fve_subs NUMBER;
- server_org_id_val NUMBER;
- BEGIN
-
- --
- -- Use the org_id of the server only if the org_id of the channel = NULL.
- -- This is required for subscribing to shared channels.
- --
- SELECT org_id
- INTO server_org_id_val
- FROM rhnServer
- WHERE id = server_id_in;
-
- begin
- obtain_read_lock(channel_family_id_val, server_org_id_val);
- exception
- when no_data_found then
- rhn_exception.raise_exception('channel_family_no_subscriptions');
- end;
- IF (can_convert_to_fve(server_id_in, channel_family_id_val ) = 0)
- THEN
- rhn_exception.raise_exception('server_cannot_convert_to_flex');
- END IF;
-
- available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
-
- IF (available_fve_subs > 0)
- THEN
-
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- server_id_in,
- 'converted to flex entitlement' || SUBSTR(cf.label, 0, 99),
- cf.label
- from rhnChannelFamily cf
- where cf.id = channel_family_id_val
- );
-
- UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
- where sc.server_id = server_id_in and
- sc.channel_id in
- (select cfm.channel_id from rhnChannelFamilyMembers cfm
- where cfm.CHANNEL_FAMILY_ID = channel_family_id_val);
-
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- ELSE
- rhn_exception.raise_exception('not_enough_flex_entitlements');
- END IF;
-
- END convert_to_fve;
-
- function can_server_consume_virt_channl(
- server_id_in in number,
- family_id_in in number )
- return number
- is
-
- cursor server_virt_families is
- select vi.virtual_system_id, cfvsl.channel_family_id
- from
- rhnChannelFamilyVirtSubLevel cfvsl,
- rhnSGTypeVirtSubLevel sgtvsl,
- rhnVirtualInstance vi
- where
- vi.virtual_system_id = server_id_in
- and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
- and cfvsl.channel_family_id = family_id_in
- and exists (
- select 1
- from rhnServerEntitlementView sev
- where vi.host_system_id = sev.server_id
- and sev.server_group_type_id = sgtvsl.server_group_type_id );
- begin
-
- for server_virt_family in server_virt_families loop
- return 1;
- end loop;
-
- return 0;
-
- end;
-
- FUNCTION can_server_consume_fve(server_id_in IN NUMBER)
- RETURN NUMBER
- IS
- CURSOR vi_entries IS
- SELECT 1
- FROM rhnVirtualInstance vi
- WHERE vi.virtual_system_id = server_id_in;
- vi_count NUMBER;
-
- BEGIN
- FOR vi_entry IN VI_ENTRIES LOOP
- return 1;
- END LOOP;
- RETURN 0;
- END;
-
- function guess_server_base(
- server_id_in in number
- ) RETURN number is
- cursor server_cursor is
- select s.server_arch_id, s.release, s.org_id
- from rhnServer s
- where s.id = server_id_in;
- begin
- for s in server_cursor loop
- for channel in base_channel_cursor(s.release,
- s.server_arch_id, s.org_id)
- loop
- return channel.id;
- end loop base_channel_cursor;
- end loop server_cursor;
- -- Server not found, or no base channel applies to it
- return null;
- end;
-
- -- Private function
- function normalize_server_arch(server_arch_in in varchar2)
- return varchar2
- deterministic
- is
- suffix VARCHAR2(128) := '-redhat-linux';
- suffix_len NUMBER := length(suffix);
- begin
- if server_arch_in is NULL then
- return NULL;
- end if;
- if instr(server_arch_in, '-') > 0
- then
- -- Suffix already present
- return server_arch_in;
- end if;
- return server_arch_in || suffix;
- end normalize_server_arch;
-
- --
- --
- -- Raises:
- -- server_arch_not_found
- -- no_subscribe_permissions
- function base_channel_for_release_arch(
- release_in in varchar2,
- server_arch_in in varchar2,
- org_id_in in number := -1,
- user_id_in in number := null
- ) return number is
- server_arch varchar2(256) := normalize_server_arch(server_arch_in);
- server_arch_id number;
- begin
- -- Look up the server arch
- begin
- select id
- into server_arch_id
- from rhnServerArch
- where label = server_arch;
- exception
- when no_data_found then
- rhn_exception.raise_exception('server_arch_not_found');
- end;
- return base_channel_rel_archid(release_in, server_arch_id,
- org_id_in, user_id_in);
- end base_channel_for_release_arch;
-
- function base_channel_rel_archid(
- release_in in varchar2,
- server_arch_id_in in number,
- org_id_in in number := -1,
- user_id_in in number := null
- ) return number is
- denied_channel_id number := null;
- valid_org_id number := org_id_in;
- valid_user_id number := user_id_in;
- channel_subscribable number;
- begin
- if org_id_in = -1 and user_id_in is not null then
- -- Get the org id from the user id
- begin
- select org_id
- into valid_org_id
- from web_contact
- where id = user_id_in;
- exception
- when no_data_found then
- -- User doesn't exist
- -- XXX Only list public stuff for now
- valid_user_id := null;
- valid_org_id := -1;
- end;
- end if;
-
- for c in base_channel_cursor(release_in, server_arch_id_in, valid_org_id)
- loop
- -- This row is a possible match
- if valid_user_id is null then
- -- User ID not specified, so no user to channel permissions to
- -- check
- return c.id;
- end if;
-
- -- Check user to channel permissions
- select loose_user_role_check(c.id, user_id_in, 'subscribe')
- into channel_subscribable
- from dual;
-
- if channel_subscribable = 1 then
- return c.id;
- end if;
-
- -- Base channel exists, but is not subscribable; keep trying
- denied_channel_id := c.id;
- end loop base_channel_fetch;
-
- if denied_channel_id is not null then
- rhn_exception.raise_exception('no_subscribe_permissions');
- end if;
- -- No base channel applies
- return NULL;
- end base_channel_rel_archid;
-
- PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server IN NUMBER := 0,
- update_family_countsYN IN NUMBER := 1)
- IS
- cursor server_channels(server_id_in in number) is
- select s.org_id, sc.channel_id, cfm.channel_family_id
- from rhnServer s,
- rhnServerChannel sc,
- rhnChannelFamilyMembers cfm
- where s.id = server_id_in
- and s.id = sc.server_id
- and sc.channel_id = cfm.channel_id
- order by cfm.channel_family_id;
- last_channel_family_id rhnChannelFamilyMembers.channel_family_id%type := -1;
- last_channel_org_id rhnServer.org_id%type := -1;
- BEGIN
- for channel in server_channels(server_id_in)
- loop
- unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, 0);
- if update_family_countsYN > 0
- and channel.channel_family_id != last_channel_family_id then
- -- update family counts only once
- -- after all channels with same family has been fetched
- if last_channel_family_id != -1 then
- update_family_counts(last_channel_family_id, last_channel_org_id);
- end if;
- last_channel_family_id := channel.channel_family_id;
- last_channel_org_id := channel.org_id;
- end if;
- end loop channel;
- if update_family_countsYN > 0 and last_channel_family_id != -1 then
- -- update the last family fetched
- update_family_counts(last_channel_family_id, last_channel_org_id);
- end if;
- END clear_subscriptions;
-
- PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
- deleting_server IN NUMBER := 0,
- update_family_countsYN IN NUMBER := 1)
- IS
- channel_family_id_val NUMBER;
- server_org_id_val NUMBER;
- available_subscriptions NUMBER;
- server_already_in_chan BOOLEAN;
- cursor channel_family_is_proxy(channel_family_id_in in number) is
- select 1
- from rhnChannelFamily
- where id = channel_family_id_in
- and label = 'rhn-proxy';
- cursor channel_family_is_satellite(channel_family_id_in in number) is
- select 1
- from rhnChannelFamily
- where id = channel_family_id_in
- and label = 'rhn-satellite';
- -- this is *EXACTLY* like check_server_parent_membership, but if we recurse
- -- with the package-level one, we get a "cursor already open", so we need a
- -- copy on our call stack instead. GROAN.
- cursor local_chk_server_parent_memb (
- server_id_in number,
- channel_id_in number ) is
- select c.id
- from rhnChannel c,
- rhnServerChannel sc
- where 1=1
- and c.parent_channel = channel_id_in
- and c.id = sc.channel_id
- and sc.server_id = server_id_in;
- BEGIN
- FOR child IN local_chk_server_parent_memb(server_id_in, channel_id_in)
- LOOP
- if unsubscribe_children_in = 1 then
- unsubscribe_server(server_id_in => server_id_in,
- channel_id_in => child.id,
- immediate_in => immediate_in,
- unsubscribe_children_in => unsubscribe_children_in,
- deleting_server => deleting_server,
- update_family_countsYN => update_family_countsYN);
- else
- rhn_exception.raise_exception('channel_unsubscribe_child_exists');
- end if;
- END LOOP child;
-
- server_already_in_chan := FALSE;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
- LOOP
- server_already_in_chan := TRUE;
- END LOOP check_subscription;
-
- IF NOT server_already_in_chan
- THEN
- RETURN;
- END IF;
-
- if deleting_server = 0 then
-
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- server_id_in,
- 'unsubscribed from channel ' || SUBSTR(c.label, 0, 106),
- c.label
- from rhnChannel c
- where c.id = channel_id_in
- );
-
- UPDATE rhnServer SET channels_changed = sysdate WHERE id = server_id_in;
- end if;
-
- DELETE FROM rhnServerChannel WHERE server_id = server_id_in AND channel_id = channel_id_in;
-
- if deleting_server = 0 then
- queue_server(server_id_in, immediate_in);
- end if;
-
- channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
- IF channel_family_id_val IS NULL
- THEN
- rhn_exception.raise_exception('channel_unsubscribe_no_family');
- END IF;
-
- for ignore in channel_family_is_satellite(channel_family_id_val) loop
- delete from rhnSatelliteInfo where server_id = server_id_in;
- end loop;
-
- for ignore in channel_family_is_proxy(channel_family_id_val) loop
- delete from rhnProxyInfo where server_id = server_id_in;
- end loop;
- SELECT org_id INTO server_org_id_val
- FROM rhnServer
- WHERE id = server_id_in;
-
- if update_family_countsYN = 1 then
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- end if;
- END unsubscribe_server;
-
-
- FUNCTION family_for_channel(channel_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
- BEGIN
- SELECT channel_family_id INTO channel_family_id_val
- FROM rhnChannelFamilyMembers
- WHERE channel_id = channel_id_in;
-
- RETURN channel_family_id_val;
- EXCEPTION
- WHEN NO_DATA_FOUND
- THEN
- RETURN NULL;
- END family_for_channel;
-
- FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- cfp channel_family_perm_cursor%ROWTYPE;
- current_members_val NUMBER;
- max_members_val NUMBER;
- found NUMBER;
- BEGIN
- IF NOT channel_family_perm_cursor%ISOPEN
- THEN
- OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
- END IF;
-
- FETCH channel_family_perm_cursor INTO cfp;
-
- WHILE channel_family_perm_cursor%FOUND
- LOOP
- found := 1;
-
- current_members_val := cfp.current_members;
- max_members_val := cfp.max_members;
-
- FETCH channel_family_perm_cursor INTO cfp;
- END LOOP;
-
- IF channel_family_perm_cursor%ISOPEN
- THEN
- CLOSE channel_family_perm_cursor;
- END IF;
-
- -- not found: either the channel fam doesn't have an entry in cfp, or the org doesn't have access to it.
- -- either way, there are no available subscriptions
-
- IF found IS NULL
- THEN
- RETURN 0;
- END IF;
-
- -- null max members? in that case, pass it on; NULL means infinite
- IF max_members_val IS NULL
- THEN
- RETURN NULL;
- END IF;
-
- -- otherwise, return the delta
- RETURN max_members_val - current_members_val;
- END available_family_subscriptions;
-
- FUNCTION available_fve_family_subs(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- cfp channel_family_perm_cursor%ROWTYPE;
- fve_current_members_val NUMBER;
- fve_max_members_val NUMBER;
- found NUMBER;
-
- BEGIN
- IF NOT channel_family_perm_cursor%ISOPEN THEN
- OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
- END IF;
-
- FETCH channel_family_perm_cursor INTO cfp;
-
- WHILE channel_family_perm_cursor%FOUND LOOP
- found := 1;
- fve_current_members_val := cfp.fve_current_members;
- fve_max_members_val := cfp.fve_max_members;
- FETCH channel_family_perm_cursor INTO cfp;
- END LOOP;
-
- IF channel_family_perm_cursor%ISOPEN THEN
- CLOSE channel_family_perm_cursor;
- END IF;
-
- IF found IS NULL THEN
- RETURN 0;
- END IF;
-
- IF fve_max_members_val IS NULL THEN
- RETURN NULL;
- END IF;
-
- RETURN fve_max_members_val - fve_current_members_val;
-
- END available_fve_family_subs;
-
-
- -- *******************************************************************
- -- FUNCTION: channel_family_current_members
- -- Calculates and returns the actual count of systems consuming
- -- physical channel subscriptions.
- -- Called by: update_family_counts
- -- rhn_entitlements.repoll_virt_guest_entitlements
- -- *******************************************************************
- function channel_family_current_members(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- return number
- is
- current_members_count number := 0;
- begin
- select count(distinct server_id)
- into current_members_count
- from rhnChannelFamilyServerPhysical cfsp
- where cfsp.channel_family_id = channel_family_id_in
- and cfsp.customer_id = org_id_in;
- return current_members_count;
- end;
-
-
- function cfam_curr_fve_members(
- channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- return number
- is
- current_members_count number := 0;
-
- begin
- select count(sc.server_id)
- into current_members_count
- from rhnServerChannel sc,
- rhnChannelFamilyMembers cfm,
- rhnServer s
- where s.org_id = org_id_in
- and s.id = sc.server_id
- and cfm.channel_family_id = channel_family_id_in
- and cfm.channel_id = sc.channel_id
- and exists (
- select 1
- from rhnChannelFamilyServerFve cfsp
- where cfsp.CHANNEL_FAMILY_ID = channel_family_id_in
- and cfsp.server_id = s.id
- );
-
- return current_members_count;
- end;
- PROCEDURE update_family_counts(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- IS
- BEGIN
- update rhnPrivateChannelFamily
- set current_members = ( channel_family_current_members(channel_family_id_in, org_id_in)),
- fve_current_members = ( cfam_curr_fve_members(channel_family_id_in, org_id_in))
- where org_id = org_id_in
- and channel_family_id = channel_family_id_in;
- END update_family_counts;
-
- PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2,
- org_id_in IN NUMBER)
- IS
- BEGIN
- FOR i IN (
- SELECT DISTINCT CFM.channel_family_id, SG.org_id
- FROM rhnChannelFamilyMembers CFM
- JOIN rhnServerChannel SC
- ON SC.channel_id = CFM.channel_id
- JOIN rhnServerGroupMembers SGM
- ON SC.server_id = SGM.server_id
- JOIN rhnServerGroup SG
- ON SGM.server_group_id = SG.id
- JOIN rhnServerGroupType SGT
- ON SG.group_type = SGT.id
- WHERE SGT.label = group_label_in
- AND SG.org_id = org_id_in
- AND SGT.is_base = 'Y'
- ) LOOP
- rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
- END LOOP;
- END update_group_family_counts;
-
- FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER,
- org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
- BEGIN
- SELECT channel_family_id INTO channel_family_id_val
- FROM rhnChannelFamilyMembers
- WHERE channel_id = channel_id_in;
-
- RETURN rhn_channel.available_family_subscriptions(
- channel_family_id_val, org_id_in);
- END available_chan_subscriptions;
-
- FUNCTION available_fve_chan_subs(channel_id_in IN NUMBER,
- org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
-
- BEGIN
- SELECT channel_family_id INTO channel_family_id_val
- FROM rhnChannelFamilyMembers
- WHERE channel_id = channel_id_in;
-
- RETURN rhn_channel.available_fve_family_subs( channel_family_id_val, org_id_in);
- END available_fve_chan_subs;
-
- procedure unsubscribe_server_from_family(server_id_in in number,
- channel_family_id_in in number)
- is
- begin
- delete
- from rhnServerChannel rsc
- where rsc.server_id = server_id_in
- and channel_id in (
- select rcfm.channel_id
- from rhnChannelFamilyMembers rcfm
- where rcfm.channel_family_id = channel_family_id_in);
- end;
-
- function get_org_id(channel_id_in in number)
- return number
- is
- org_id_out number;
- begin
- select org_id into org_id_out
- from rhnChannel
- where id = channel_id_in;
-
- return org_id_out;
- end get_org_id;
-
- function get_cfam_org_access(cfam_id_in in number, org_id_in in number)
- return number
- is
- cursor families is
- select 1
- from rhnOrgChannelFamilyPermissions cfp
- where cfp.org_id = org_id_in;
- begin
- -- the idea: if we get past this query,
- -- the user has the role, else catch the exception and return 0
- for family in families loop
- return 1;
- end loop;
- return 0;
- end;
-
- function get_org_access(channel_id_in in number, org_id_in in number)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query,
- -- the org has access to the channel, else catch the exception and return 0
- select distinct 1 into throwaway
- from rhnChannelFamilyMembers CFM,
- rhnOrgChannelFamilyPermissions CFP
- where cfp.org_id = org_id_in
- and CFM.channel_family_id = CFP.channel_family_id
- and CFM.channel_id = channel_id_in
- and (CFP.max_members > 0 or CFP.max_members is null or CFP.org_id = 1);
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- -- check if a user has a given role, or if such a role is inferrable
- function user_role_check_debug(channel_id_in in number,
- user_id_in in number,
- role_in in varchar2,
- reason_out out varchar2)
- return number
- is
- org_id number;
- begin
- org_id := rhn_user.get_org_id(user_id_in);
-
- -- channel might be shared
- if role_in = 'subscribe' and
- rhn_channel.shared_user_role_check(channel_id_in, user_id_in, role_in) = 1 then
- return 1;
- end if;
-
- if role_in = 'manage' and
- NVL(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
- reason_out := 'channel_not_owned';
- return 0;
- end if;
-
- if role_in = 'subscribe' and
- rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
- reason_out := 'channel_not_available';
- return 0;
- end if;
-
- -- channel admins have all roles
- if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
- reason_out := 'channel_admin';
- return 1;
- end if;
-
- -- the subscribe permission is inferred
- -- UNLESS the not_globally_subscribable flag is set
- if role_in = 'subscribe'
- then
- if rhn_channel.org_channel_setting(channel_id_in,
- org_id,
- 'not_globally_subscribable') = 0 then
- reason_out := 'globally_subscribable';
- return 1;
- end if;
- end if;
-
- -- all other roles (manage right now) are explicitly granted
- reason_out := 'direct_permission';
- return rhn_channel.direct_user_role_check(channel_id_in,
- user_id_in, role_in);
- end;
-
- -- same as above, but with no OUT param; useful in views, etc
- function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway varchar2(256);
- begin
- return rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in, throwaway);
- end;
-
- --
- -- For multiorg phase II, this function simply checks to see if the user's
- -- has a trust relationship that includes this channel by id.
- --
- function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
- return number
- is
- n number;
- oid number;
- begin
- oid := rhn_user.get_org_id(user_id);
- select 1 into n
- from rhnSharedChannelView s
- where s.id = channel_id and s.org_trust_id = oid;
- return 1;
- exception
- when no_data_found then
- return 0;
- end;
-
- -- same as above, but returns 1 if user_id_in is null
- -- This is useful in queries where user_id is not specified
- function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- begin
- if user_id_in is null then
- return 1;
- end if;
- return user_role_check(channel_id_in, user_id_in, role_in);
- end loose_user_role_check;
-
- -- directly checks the table, no inferred permissions
- function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query, the user has the role, else catch the exception and return 0
- select 1 into throwaway
- from rhnChannelPermissionRole CPR,
- rhnChannelPermission CP
- where CP.user_id = user_id_in
- and CP.channel_id = channel_id_in
- and CPR.label = role_in
- and CP.role_id = CPR.id;
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- -- check if an org has a certain setting
- function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
- select 1 into throwaway
- from rhnOrgChannelSettingsType OCST,
- rhnOrgChannelSettings OCS
- where OCS.org_id = org_id_in
- and OCS.channel_id = channel_id_in
- and OCST.label = setting_in
- and OCS.setting_id = OCST.id;
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- FUNCTION channel_priority(channel_id_in IN number)
- RETURN number
- IS
- channel_name varchar2(256);
- priority number;
- end_of_life_val date;
- org_id_val number;
- BEGIN
-
- select name, end_of_life, org_id
- into channel_name, end_of_life_val, org_id_val
- from rhnChannel
- where id = channel_id_in;
-
- if end_of_life_val is not null then
- return -400;
- end if;
-
- if channel_name like 'Red Hat Enterprise Linux%' or channel_name like 'RHEL%' then
- priority := 1000;
- if channel_name not like '%Beta%' then
- priority := priority + 1000;
- end if;
-
- priority := priority +
- case
- when channel_name like '%v. 5%' then 600
- when channel_name like '%v. 4%' then 500
- when channel_name like '%v. 3%' then 400
- when channel_name like '%v. 2%' then 300
- when channel_name like '%v. 1%' then 200
- else 0
- end;
-
- priority := priority +
- case
- when channel_name like 'Red Hat Enterprise Linux (v. 5%' then 60
- when (channel_name like '%AS%' and channel_name not like '%Extras%') then 50
- when (channel_name like '%ES%' and channel_name not like '%Extras%') then 40
- when (channel_name like '%WS%' and channel_name not like '%Extras%') then 30
- when (channel_name like '%Desktop%' and channel_name not like '%Extras%') then 20
- when channel_name like '%Extras%' then 10
- else 0
- end;
-
- priority := priority +
- case
- when channel_name like '%)' then 5
- else 0
- end;
-
- priority := priority +
- case
- when channel_name like '%32-bit x86%' then 4
- when channel_name like '%64-bit Intel Itanium%' then 3
- when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
- else 0
- end;
- elsif channel_name like 'Red Hat Desktop%' then
- priority := 900;
-
- if channel_name not like '%Beta%' then
- priority := priority + 50;
- end if;
-
- priority := priority +
- case
- when channel_name like '%v. 4%' then 40
- when channel_name like '%v. 3%' then 30
- when channel_name like '%v. 2%' then 20
- when channel_name like '%v. 1%' then 10
- else 0
- end;
-
- priority := priority +
- case
- when channel_name like '%32-bit x86%' then 4
- when channel_name like '%64-bit Intel Itanium%' then 3
- when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
- else 0
- end;
-
- elsif org_id_val is not null then
- priority := 600;
- else
- priority := 500;
- end if;
-
- return -priority;
-
- end channel_priority;
-
- -- right now this only does the accounting changes; the cascade
- -- actually does the rhnServerChannel delete.
- procedure delete_server_channels(server_id_in in number)
- is
- begin
- update rhnPrivateChannelFamily
- set current_members = current_members -1
- where org_id in (
- select org_id
- from rhnServer
- where id = server_id_in
- )
- and channel_family_id in (
- select rcfm.channel_family_id
- from rhnChannelFamilyMembers rcfm,
- rhnServerChannel rsc
- where rsc.server_id = server_id_in
- and rsc.channel_id = rcfm.channel_id
- and not exists (
- select 1
- from
- rhnChannelFamilyVirtSubLevel cfvsl,
- rhnSGTypeVirtSubLevel sgtvsl,
- rhnServerEntitlementView sev,
- rhnVirtualInstance vi
- where
- -- system is a virtual instance
- vi.virtual_system_id = server_id_in
- and vi.host_system_id = sev.server_id
- -- system's host has a virt ent
- and sev.label in ('virtualization_host',
- 'virtualization_host_platform')
- and sev.server_group_type_id =
- sgtvsl.server_group_type_id
- -- the host's virt ent grants a cf virt sub level
- and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
- -- the cf is in that virt sub level
- and cfvsl.channel_family_id = rcfm.channel_family_id
- )
- );
- end;
-
- -- this could certainly be optimized to do updates if needs be
- procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)')
- is
- begin
- delete from rhnChannelNewestPackage where channel_id = channel_id_in;
- insert into rhnChannelNewestPackage
- ( channel_id, name_id, evr_id, package_id, package_arch_id )
- ( select channel_id,
- name_id, evr_id,
- package_id, package_arch_id
- from rhnChannelNewestPackageView
- where channel_id = channel_id_in
- );
- insert into rhnChannelNewestPackageAudit (channel_id, caller)
- values (channel_id_in, caller_in);
- update rhnChannel
- set last_modified = greatest(sysdate, last_modified + 1/86400)
- where id = channel_id_in;
- end;
-
- procedure update_channel ( channel_id_in in number, invalidate_ss in number := 0,
- date_to_use in date := sysdate )
- is
-
- channel_last_modified date;
- last_modified_value date;
-
- cursor snapshots is
- select snapshot_id id
- from rhnSnapshotChannel
- where channel_id = channel_id_in;
-
- begin
-
- select last_modified
- into channel_last_modified
- from rhnChannel
- where id = channel_id_in;
-
- last_modified_value := date_to_use;
-
- if last_modified_value <= channel_last_modified then
- last_modified_value := last_modified_value + 1/86400;
- end if;
-
- update rhnChannel set last_modified = last_modified_value
- where id = channel_id_in;
-
- if invalidate_ss = 1 then
- for snapshot in snapshots loop
- update rhnSnapshot
- set invalid = lookup_snapshot_invalid_reason('channel_modified')
- where id = snapshot.id;
- end loop;
- end if;
-
- end update_channel;
-
- procedure update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate )
- is
-
- cursor channels is
- select channel_id
- from rhnChannelPackage
- where package_id = package_id_in
- order by channel_id;
-
- begin
- for channel in channels loop
- -- we want to invalidate the snapshot assocated with the channel when we
- -- do this b/c we know we've added or removed or packages
- rhn_channel.update_channel ( channel.channel_id, 1, date_to_use );
- end loop;
- end update_channels_by_package;
-
-
- procedure update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate )
- is
-
- cursor channels is
- select channel_id
- from rhnChannelErrata
- where errata_id = errata_id_in
- order by channel_id;
-
- begin
- for channel in channels loop
- -- we won't invalidate snapshots, b/c just changing the errata associated with
- -- a channel shouldn't invalidate snapshots
- rhn_channel.update_channel ( channel.channel_id, 0, date_to_use );
- end loop;
- end update_channels_by_errata;
-
- procedure update_needed_cache(channel_id_in in number)
- is
- pragma autonomous_transaction;
- -- update of needed cache ican be commited on a per server basis
- -- b/c failure of update for a server means nothing for the other servers
- begin
- -- we intentionaly do a loop here instead of one huge select
- -- b/c we want to break update into smaller transaction to unblock other sessions
- -- querying rhnServerNeededCache
- for server in (
- select sc.server_id as id
- from rhnServerChannel sc
- where sc.channel_id = channel_id_in
- ) loop
- rhn_server.update_needed_cache(server.id);
- commit;
- end loop;
- end update_needed_cache;
-
-END rhn_channel;
-/
-SHOW ERRORS
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql.oracle
new file mode 100644
index 0000000..bdf0508
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/004-rhn_channel-body.sql.oracle
@@ -0,0 +1,1212 @@
+--
+-- Copyright (c) 2008--2010 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.
+--
+
+CREATE OR REPLACE
+PACKAGE BODY rhn_channel
+IS
+ body_version varchar2(100) := '';
+
+ -- Cursor that fetches all the possible base channels for a
+ -- (server_arch_id, release, org_id) combination
+ cursor base_channel_cursor(
+ release_in in varchar2,
+ server_arch_id_in in number,
+ org_id_in in number
+ ) return rhnChannel%ROWTYPE is
+ select distinct c.*
+ from rhnDistChannelMap dcm,
+ rhnServerChannelArchCompat scac,
+ rhnChannel c,
+ rhnChannelPermissions cp
+ where cp.org_id = org_id_in
+ and cp.channel_id = c.id
+ and c.parent_channel is null
+ and c.id = dcm.channel_id
+ and c.channel_arch_id = dcm.channel_arch_id
+ and dcm.release = release_in
+ and scac.server_arch_id = server_arch_id_in
+ and scac.channel_arch_id = c.channel_arch_id;
+
+ procedure obtain_read_lock(channel_family_id_in in number, org_id_in in number)
+ is
+ read_lock date;
+
+ begin
+ select created into read_lock
+ from rhnPrivateChannelFamily
+ where channel_family_id = channel_family_id_in and org_id = org_id_in
+ for update;
+ end obtain_read_lock;
+
+ PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in in number := null, recalcfamily_in number := 1)
+ IS
+ channel_parent_val rhnChannel.parent_channel%TYPE;
+ parent_subscribed BOOLEAN;
+ server_has_base_chan BOOLEAN;
+ server_already_in_chan BOOLEAN;
+ channel_family_id_val NUMBER;
+ server_org_id_val NUMBER;
+ available_subscriptions NUMBER;
+ available_fve_subs NUMBER;
+ consenting_user NUMBER;
+ allowed number := 0;
+ is_fve CHAR(1) := 'N';
+ BEGIN
+ if user_id_in is not null then
+ allowed := rhn_channel.user_role_check(channel_id_in, user_id_in, 'subscribe');
+ else
+ allowed := 1;
+ end if;
+
+ if allowed = 0 then
+ rhn_exception.raise_exception('no_subscribe_permissions');
+ end if;
+
+
+ SELECT parent_channel INTO channel_parent_val FROM rhnChannel WHERE id = channel_id_in;
+
+ IF channel_parent_val IS NOT NULL
+ THEN
+ -- child channel; if attempting to cross-subscribe a child to the wrong base, silently ignore
+ parent_subscribed := FALSE;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_parent_val)
+ LOOP
+ parent_subscribed := TRUE;
+ END LOOP check_subscription;
+
+ IF NOT parent_subscribed
+ THEN
+ RETURN;
+ END IF;
+ ELSE
+ -- base channel
+ server_has_base_chan := FALSE;
+ FOR base IN server_base_subscriptions(server_id_in)
+ LOOP
+ server_has_base_chan := TRUE;
+ END LOOP base;
+
+ IF server_has_base_chan
+ THEN
+ rhn_exception.raise_exception('channel_server_one_base');
+ END IF;
+ END IF;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
+ LOOP
+ server_already_in_chan := TRUE;
+ END LOOP check_subscription;
+
+ IF server_already_in_chan
+ THEN
+ RETURN;
+ END IF;
+
+ channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
+ IF channel_family_id_val IS NULL
+ THEN
+ rhn_exception.raise_exception('channel_subscribe_no_family');
+ END IF;
+
+ --
+ -- Use the org_id of the server only if the org_id of the channel = NULL.
+ -- This is required for subscribing to shared channels.
+ --
+ SELECT NVL(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
+ INTO server_org_id_val
+ FROM rhnChannel
+ WHERE id = channel_id_in;
+
+ begin
+ obtain_read_lock(channel_family_id_val, server_org_id_val);
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('channel_family_no_subscriptions');
+ end;
+
+ available_subscriptions := rhn_channel.available_family_subscriptions(channel_family_id_val, server_org_id_val);
+ available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
+
+ IF available_subscriptions IS NULL OR
+ available_subscriptions > 0 or
+ can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1 OR
+ (available_fve_subs > 0 AND can_server_consume_fve(server_id_in) = 1)
+ THEN
+ if can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 0 AND available_fve_subs > 0 AND can_server_consume_fve(server_id_in) = 1 THEN
+ is_fve := 'Y';
+ END IF;
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ server_id_in,
+ 'subscribed to channel ' || SUBSTR(c.label, 0, 106),
+ c.label
+ from rhnChannel c
+ where c.id = channel_id_in
+ );
+ UPDATE rhnServer SET channels_changed = sysdate WHERE id = server_id_in;
+ INSERT INTO rhnServerChannel (server_id, channel_id, is_fve) VALUES (server_id_in, channel_id_in, is_fve);
+ IF recalcfamily_in > 0
+ THEN
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ END IF;
+ queue_server(server_id_in, immediate_in);
+ ELSE
+ rhn_exception.raise_exception('channel_family_no_subscriptions');
+ END IF;
+
+ END subscribe_server;
+
+
+
+ FUNCTION can_convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER)
+ RETURN NUMBER
+ IS
+ CURSOR fve_convertible_entries IS
+ select 1 from
+ rhnServerFveCapable cap
+ where cap.server_id = server_id_in
+ AND cap.channel_family_id = channel_family_id_val;
+ BEGIN
+ FOR entry IN fve_convertible_entries LOOP
+ return 1;
+ END LOOP;
+ RETURN 0;
+ END can_convert_to_fve;
+
+
+
+ -- Converts server channel_family to use a flex entitlement
+ PROCEDURE convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER)
+ IS
+ available_fve_subs NUMBER;
+ server_org_id_val NUMBER;
+ BEGIN
+
+ --
+ -- Use the org_id of the server only if the org_id of the channel = NULL.
+ -- This is required for subscribing to shared channels.
+ --
+ SELECT org_id
+ INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+ begin
+ obtain_read_lock(channel_family_id_val, server_org_id_val);
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('channel_family_no_subscriptions');
+ end;
+ IF (can_convert_to_fve(server_id_in, channel_family_id_val ) = 0)
+ THEN
+ rhn_exception.raise_exception('server_cannot_convert_to_flex');
+ END IF;
+
+ available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
+
+ IF (available_fve_subs > 0)
+ THEN
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ server_id_in,
+ 'converted to flex entitlement' || SUBSTR(cf.label, 0, 99),
+ cf.label
+ from rhnChannelFamily cf
+ where cf.id = channel_family_id_val
+ );
+
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id = server_id_in and
+ sc.channel_id in
+ (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = channel_family_id_val);
+
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ ELSE
+ rhn_exception.raise_exception('not_enough_flex_entitlements');
+ END IF;
+
+ END convert_to_fve;
+
+ function can_server_consume_virt_channl(
+ server_id_in in number,
+ family_id_in in number )
+ return number
+ is
+
+ cursor server_virt_families is
+ select vi.virtual_system_id, cfvsl.channel_family_id
+ from
+ rhnChannelFamilyVirtSubLevel cfvsl,
+ rhnSGTypeVirtSubLevel sgtvsl,
+ rhnVirtualInstance vi
+ where
+ vi.virtual_system_id = server_id_in
+ and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
+ and cfvsl.channel_family_id = family_id_in
+ and exists (
+ select 1
+ from rhnServerEntitlementView sev
+ where vi.host_system_id = sev.server_id
+ and sev.server_group_type_id = sgtvsl.server_group_type_id );
+ begin
+
+ for server_virt_family in server_virt_families loop
+ return 1;
+ end loop;
+
+ return 0;
+
+ end;
+
+ FUNCTION can_server_consume_fve(server_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ CURSOR vi_entries IS
+ SELECT 1
+ FROM rhnVirtualInstance vi
+ WHERE vi.virtual_system_id = server_id_in;
+ vi_count NUMBER;
+
+ BEGIN
+ FOR vi_entry IN VI_ENTRIES LOOP
+ return 1;
+ END LOOP;
+ RETURN 0;
+ END;
+
+ function guess_server_base(
+ server_id_in in number
+ ) RETURN number is
+ cursor server_cursor is
+ select s.server_arch_id, s.release, s.org_id
+ from rhnServer s
+ where s.id = server_id_in;
+ begin
+ for s in server_cursor loop
+ for channel in base_channel_cursor(s.release,
+ s.server_arch_id, s.org_id)
+ loop
+ return channel.id;
+ end loop base_channel_cursor;
+ end loop server_cursor;
+ -- Server not found, or no base channel applies to it
+ return null;
+ end;
+
+ -- Private function
+ function normalize_server_arch(server_arch_in in varchar2)
+ return varchar2
+ deterministic
+ is
+ suffix VARCHAR2(128) := '-redhat-linux';
+ suffix_len NUMBER := length(suffix);
+ begin
+ if server_arch_in is NULL then
+ return NULL;
+ end if;
+ if instr(server_arch_in, '-') > 0
+ then
+ -- Suffix already present
+ return server_arch_in;
+ end if;
+ return server_arch_in || suffix;
+ end normalize_server_arch;
+
+ --
+ --
+ -- Raises:
+ -- server_arch_not_found
+ -- no_subscribe_permissions
+ function base_channel_for_release_arch(
+ release_in in varchar2,
+ server_arch_in in varchar2,
+ org_id_in in number := -1,
+ user_id_in in number := null
+ ) return number is
+ server_arch varchar2(256) := normalize_server_arch(server_arch_in);
+ server_arch_id number;
+ begin
+ -- Look up the server arch
+ begin
+ select id
+ into server_arch_id
+ from rhnServerArch
+ where label = server_arch;
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('server_arch_not_found');
+ end;
+ return base_channel_rel_archid(release_in, server_arch_id,
+ org_id_in, user_id_in);
+ end base_channel_for_release_arch;
+
+ function base_channel_rel_archid(
+ release_in in varchar2,
+ server_arch_id_in in number,
+ org_id_in in number := -1,
+ user_id_in in number := null
+ ) return number is
+ denied_channel_id number := null;
+ valid_org_id number := org_id_in;
+ valid_user_id number := user_id_in;
+ channel_subscribable number;
+ begin
+ if org_id_in = -1 and user_id_in is not null then
+ -- Get the org id from the user id
+ begin
+ select org_id
+ into valid_org_id
+ from web_contact
+ where id = user_id_in;
+ exception
+ when no_data_found then
+ -- User doesn't exist
+ -- XXX Only list public stuff for now
+ valid_user_id := null;
+ valid_org_id := -1;
+ end;
+ end if;
+
+ for c in base_channel_cursor(release_in, server_arch_id_in, valid_org_id)
+ loop
+ -- This row is a possible match
+ if valid_user_id is null then
+ -- User ID not specified, so no user to channel permissions to
+ -- check
+ return c.id;
+ end if;
+
+ -- Check user to channel permissions
+ select loose_user_role_check(c.id, user_id_in, 'subscribe')
+ into channel_subscribable
+ from dual;
+
+ if channel_subscribable = 1 then
+ return c.id;
+ end if;
+
+ -- Base channel exists, but is not subscribable; keep trying
+ denied_channel_id := c.id;
+ end loop base_channel_fetch;
+
+ if denied_channel_id is not null then
+ rhn_exception.raise_exception('no_subscribe_permissions');
+ end if;
+ -- No base channel applies
+ return NULL;
+ end base_channel_rel_archid;
+
+ PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server IN NUMBER := 0,
+ update_family_countsYN IN NUMBER := 1)
+ IS
+ cursor server_channels(server_id_in in number) is
+ select s.org_id, sc.channel_id, cfm.channel_family_id
+ from rhnServer s,
+ rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm
+ where s.id = server_id_in
+ and s.id = sc.server_id
+ and sc.channel_id = cfm.channel_id
+ order by cfm.channel_family_id;
+ last_channel_family_id rhnChannelFamilyMembers.channel_family_id%type := -1;
+ last_channel_org_id rhnServer.org_id%type := -1;
+ BEGIN
+ for channel in server_channels(server_id_in)
+ loop
+ unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, 0);
+ if update_family_countsYN > 0
+ and channel.channel_family_id != last_channel_family_id then
+ -- update family counts only once
+ -- after all channels with same family has been fetched
+ if last_channel_family_id != -1 then
+ update_family_counts(last_channel_family_id, last_channel_org_id);
+ end if;
+ last_channel_family_id := channel.channel_family_id;
+ last_channel_org_id := channel.org_id;
+ end if;
+ end loop channel;
+ if update_family_countsYN > 0 and last_channel_family_id != -1 then
+ -- update the last family fetched
+ update_family_counts(last_channel_family_id, last_channel_org_id);
+ end if;
+ END clear_subscriptions;
+
+ PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
+ deleting_server IN NUMBER := 0,
+ update_family_countsYN IN NUMBER := 1)
+ IS
+ channel_family_id_val NUMBER;
+ server_org_id_val NUMBER;
+ available_subscriptions NUMBER;
+ server_already_in_chan BOOLEAN;
+ cursor channel_family_is_proxy(channel_family_id_in in number) is
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-proxy';
+ cursor channel_family_is_satellite(channel_family_id_in in number) is
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-satellite';
+ -- this is *EXACTLY* like check_server_parent_membership, but if we recurse
+ -- with the package-level one, we get a "cursor already open", so we need a
+ -- copy on our call stack instead. GROAN.
+ cursor local_chk_server_parent_memb (
+ server_id_in number,
+ channel_id_in number ) is
+ select c.id
+ from rhnChannel c,
+ rhnServerChannel sc
+ where 1=1
+ and c.parent_channel = channel_id_in
+ and c.id = sc.channel_id
+ and sc.server_id = server_id_in;
+ BEGIN
+ FOR child IN local_chk_server_parent_memb(server_id_in, channel_id_in)
+ LOOP
+ if unsubscribe_children_in = 1 then
+ unsubscribe_server(server_id_in => server_id_in,
+ channel_id_in => child.id,
+ immediate_in => immediate_in,
+ unsubscribe_children_in => unsubscribe_children_in,
+ deleting_server => deleting_server,
+ update_family_countsYN => update_family_countsYN);
+ else
+ rhn_exception.raise_exception('channel_unsubscribe_child_exists');
+ end if;
+ END LOOP child;
+
+ server_already_in_chan := FALSE;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
+ LOOP
+ server_already_in_chan := TRUE;
+ END LOOP check_subscription;
+
+ IF NOT server_already_in_chan
+ THEN
+ RETURN;
+ END IF;
+
+ if deleting_server = 0 then
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ server_id_in,
+ 'unsubscribed from channel ' || SUBSTR(c.label, 0, 106),
+ c.label
+ from rhnChannel c
+ where c.id = channel_id_in
+ );
+
+ UPDATE rhnServer SET channels_changed = sysdate WHERE id = server_id_in;
+ end if;
+
+ DELETE FROM rhnServerChannel WHERE server_id = server_id_in AND channel_id = channel_id_in;
+
+ if deleting_server = 0 then
+ queue_server(server_id_in, immediate_in);
+ end if;
+
+ channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
+ IF channel_family_id_val IS NULL
+ THEN
+ rhn_exception.raise_exception('channel_unsubscribe_no_family');
+ END IF;
+
+ for ignore in channel_family_is_satellite(channel_family_id_val) loop
+ delete from rhnSatelliteInfo where server_id = server_id_in;
+ end loop;
+
+ for ignore in channel_family_is_proxy(channel_family_id_val) loop
+ delete from rhnProxyInfo where server_id = server_id_in;
+ end loop;
+ SELECT org_id INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+ if update_family_countsYN = 1 then
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ end if;
+ END unsubscribe_server;
+
+
+ FUNCTION family_for_channel(channel_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ SELECT channel_family_id INTO channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN channel_family_id_val;
+ EXCEPTION
+ WHEN NO_DATA_FOUND
+ THEN
+ RETURN NULL;
+ END family_for_channel;
+
+ FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ cfp channel_family_perm_cursor%ROWTYPE;
+ current_members_val NUMBER;
+ max_members_val NUMBER;
+ found NUMBER;
+ BEGIN
+ IF NOT channel_family_perm_cursor%ISOPEN
+ THEN
+ OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
+ END IF;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+
+ WHILE channel_family_perm_cursor%FOUND
+ LOOP
+ found := 1;
+
+ current_members_val := cfp.current_members;
+ max_members_val := cfp.max_members;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+ END LOOP;
+
+ IF channel_family_perm_cursor%ISOPEN
+ THEN
+ CLOSE channel_family_perm_cursor;
+ END IF;
+
+ -- not found: either the channel fam doesn't have an entry in cfp, or the org doesn't have access to it.
+ -- either way, there are no available subscriptions
+
+ IF found IS NULL
+ THEN
+ RETURN 0;
+ END IF;
+
+ -- null max members? in that case, pass it on; NULL means infinite
+ IF max_members_val IS NULL
+ THEN
+ RETURN NULL;
+ END IF;
+
+ -- otherwise, return the delta
+ RETURN max_members_val - current_members_val;
+ END available_family_subscriptions;
+
+ FUNCTION available_fve_family_subs(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ cfp channel_family_perm_cursor%ROWTYPE;
+ fve_current_members_val NUMBER;
+ fve_max_members_val NUMBER;
+ found NUMBER;
+
+ BEGIN
+ IF NOT channel_family_perm_cursor%ISOPEN THEN
+ OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
+ END IF;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+
+ WHILE channel_family_perm_cursor%FOUND LOOP
+ found := 1;
+ fve_current_members_val := cfp.fve_current_members;
+ fve_max_members_val := cfp.fve_max_members;
+ FETCH channel_family_perm_cursor INTO cfp;
+ END LOOP;
+
+ IF channel_family_perm_cursor%ISOPEN THEN
+ CLOSE channel_family_perm_cursor;
+ END IF;
+
+ IF found IS NULL THEN
+ RETURN 0;
+ END IF;
+
+ IF fve_max_members_val IS NULL THEN
+ RETURN NULL;
+ END IF;
+
+ RETURN fve_max_members_val - fve_current_members_val;
+
+ END available_fve_family_subs;
+
+
+ -- *******************************************************************
+ -- FUNCTION: channel_family_current_members
+ -- Calculates and returns the actual count of systems consuming
+ -- physical channel subscriptions.
+ -- Called by: update_family_counts
+ -- rhn_entitlements.repoll_virt_guest_entitlements
+ -- *******************************************************************
+ function channel_family_current_members(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ return number
+ is
+ current_members_count number := 0;
+ begin
+ select count(distinct server_id)
+ into current_members_count
+ from rhnChannelFamilyServerPhysical cfsp
+ where cfsp.channel_family_id = channel_family_id_in
+ and cfsp.customer_id = org_id_in;
+ return current_members_count;
+ end;
+
+
+ function cfam_curr_fve_members(
+ channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ return number
+ is
+ current_members_count number := 0;
+
+ begin
+ select count(sc.server_id)
+ into current_members_count
+ from rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm,
+ rhnServer s
+ where s.org_id = org_id_in
+ and s.id = sc.server_id
+ and cfm.channel_family_id = channel_family_id_in
+ and cfm.channel_id = sc.channel_id
+ and exists (
+ select 1
+ from rhnChannelFamilyServerFve cfsp
+ where cfsp.CHANNEL_FAMILY_ID = channel_family_id_in
+ and cfsp.server_id = s.id
+ );
+
+ return current_members_count;
+ end;
+ PROCEDURE update_family_counts(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ IS
+ BEGIN
+ update rhnPrivateChannelFamily
+ set current_members = ( channel_family_current_members(channel_family_id_in, org_id_in)),
+ fve_current_members = ( cfam_curr_fve_members(channel_family_id_in, org_id_in))
+ where org_id = org_id_in
+ and channel_family_id = channel_family_id_in;
+ END update_family_counts;
+
+ PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2,
+ org_id_in IN NUMBER)
+ IS
+ BEGIN
+ FOR i IN (
+ SELECT DISTINCT CFM.channel_family_id, SG.org_id
+ FROM rhnChannelFamilyMembers CFM
+ JOIN rhnServerChannel SC
+ ON SC.channel_id = CFM.channel_id
+ JOIN rhnServerGroupMembers SGM
+ ON SC.server_id = SGM.server_id
+ JOIN rhnServerGroup SG
+ ON SGM.server_group_id = SG.id
+ JOIN rhnServerGroupType SGT
+ ON SG.group_type = SGT.id
+ WHERE SGT.label = group_label_in
+ AND SG.org_id = org_id_in
+ AND SGT.is_base = 'Y'
+ ) LOOP
+ rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
+ END LOOP;
+ END update_group_family_counts;
+
+ FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ SELECT channel_family_id INTO channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN rhn_channel.available_family_subscriptions(
+ channel_family_id_val, org_id_in);
+ END available_chan_subscriptions;
+
+ FUNCTION available_fve_chan_subs(channel_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+
+ BEGIN
+ SELECT channel_family_id INTO channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN rhn_channel.available_fve_family_subs( channel_family_id_val, org_id_in);
+ END available_fve_chan_subs;
+
+ procedure unsubscribe_server_from_family(server_id_in in number,
+ channel_family_id_in in number)
+ is
+ begin
+ delete
+ from rhnServerChannel rsc
+ where rsc.server_id = server_id_in
+ and channel_id in (
+ select rcfm.channel_id
+ from rhnChannelFamilyMembers rcfm
+ where rcfm.channel_family_id = channel_family_id_in);
+ end;
+
+ function get_org_id(channel_id_in in number)
+ return number
+ is
+ org_id_out number;
+ begin
+ select org_id into org_id_out
+ from rhnChannel
+ where id = channel_id_in;
+
+ return org_id_out;
+ end get_org_id;
+
+ function get_cfam_org_access(cfam_id_in in number, org_id_in in number)
+ return number
+ is
+ cursor families is
+ select 1
+ from rhnOrgChannelFamilyPermissions cfp
+ where cfp.org_id = org_id_in;
+ begin
+ -- the idea: if we get past this query,
+ -- the user has the role, else catch the exception and return 0
+ for family in families loop
+ return 1;
+ end loop;
+ return 0;
+ end;
+
+ function get_org_access(channel_id_in in number, org_id_in in number)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query,
+ -- the org has access to the channel, else catch the exception and return 0
+ select distinct 1 into throwaway
+ from rhnChannelFamilyMembers CFM,
+ rhnOrgChannelFamilyPermissions CFP
+ where cfp.org_id = org_id_in
+ and CFM.channel_family_id = CFP.channel_family_id
+ and CFM.channel_id = channel_id_in
+ and (CFP.max_members > 0 or CFP.max_members is null or CFP.org_id = 1);
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ -- check if a user has a given role, or if such a role is inferrable
+ function user_role_check_debug(channel_id_in in number,
+ user_id_in in number,
+ role_in in varchar2,
+ reason_out out varchar2)
+ return number
+ is
+ org_id number;
+ begin
+ org_id := rhn_user.get_org_id(user_id_in);
+
+ -- channel might be shared
+ if role_in = 'subscribe' and
+ rhn_channel.shared_user_role_check(channel_id_in, user_id_in, role_in) = 1 then
+ return 1;
+ end if;
+
+ if role_in = 'manage' and
+ NVL(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
+ reason_out := 'channel_not_owned';
+ return 0;
+ end if;
+
+ if role_in = 'subscribe' and
+ rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
+ reason_out := 'channel_not_available';
+ return 0;
+ end if;
+
+ -- channel admins have all roles
+ if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
+ reason_out := 'channel_admin';
+ return 1;
+ end if;
+
+ -- the subscribe permission is inferred
+ -- UNLESS the not_globally_subscribable flag is set
+ if role_in = 'subscribe'
+ then
+ if rhn_channel.org_channel_setting(channel_id_in,
+ org_id,
+ 'not_globally_subscribable') = 0 then
+ reason_out := 'globally_subscribable';
+ return 1;
+ end if;
+ end if;
+
+ -- all other roles (manage right now) are explicitly granted
+ reason_out := 'direct_permission';
+ return rhn_channel.direct_user_role_check(channel_id_in,
+ user_id_in, role_in);
+ end;
+
+ -- same as above, but with no OUT param; useful in views, etc
+ function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ throwaway varchar2(256);
+ begin
+ return rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in, throwaway);
+ end;
+
+ --
+ -- For multiorg phase II, this function simply checks to see if the user's
+ -- has a trust relationship that includes this channel by id.
+ --
+ function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
+ return number
+ is
+ n number;
+ oid number;
+ begin
+ oid := rhn_user.get_org_id(user_id);
+ select 1 into n
+ from rhnSharedChannelView s
+ where s.id = channel_id and s.org_trust_id = oid;
+ return 1;
+ exception
+ when no_data_found then
+ return 0;
+ end;
+
+ -- same as above, but returns 1 if user_id_in is null
+ -- This is useful in queries where user_id is not specified
+ function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ begin
+ if user_id_in is null then
+ return 1;
+ end if;
+ return user_role_check(channel_id_in, user_id_in, role_in);
+ end loose_user_role_check;
+
+ -- directly checks the table, no inferred permissions
+ function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query, the user has the role, else catch the exception and return 0
+ select 1 into throwaway
+ from rhnChannelPermissionRole CPR,
+ rhnChannelPermission CP
+ where CP.user_id = user_id_in
+ and CP.channel_id = channel_id_in
+ and CPR.label = role_in
+ and CP.role_id = CPR.id;
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ -- check if an org has a certain setting
+ function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
+ select 1 into throwaway
+ from rhnOrgChannelSettingsType OCST,
+ rhnOrgChannelSettings OCS
+ where OCS.org_id = org_id_in
+ and OCS.channel_id = channel_id_in
+ and OCST.label = setting_in
+ and OCS.setting_id = OCST.id;
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ FUNCTION channel_priority(channel_id_in IN number)
+ RETURN number
+ IS
+ channel_name varchar2(256);
+ priority number;
+ end_of_life_val date;
+ org_id_val number;
+ BEGIN
+
+ select name, end_of_life, org_id
+ into channel_name, end_of_life_val, org_id_val
+ from rhnChannel
+ where id = channel_id_in;
+
+ if end_of_life_val is not null then
+ return -400;
+ end if;
+
+ if channel_name like 'Red Hat Enterprise Linux%' or channel_name like 'RHEL%' then
+ priority := 1000;
+ if channel_name not like '%Beta%' then
+ priority := priority + 1000;
+ end if;
+
+ priority := priority +
+ case
+ when channel_name like '%v. 5%' then 600
+ when channel_name like '%v. 4%' then 500
+ when channel_name like '%v. 3%' then 400
+ when channel_name like '%v. 2%' then 300
+ when channel_name like '%v. 1%' then 200
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like 'Red Hat Enterprise Linux (v. 5%' then 60
+ when (channel_name like '%AS%' and channel_name not like '%Extras%') then 50
+ when (channel_name like '%ES%' and channel_name not like '%Extras%') then 40
+ when (channel_name like '%WS%' and channel_name not like '%Extras%') then 30
+ when (channel_name like '%Desktop%' and channel_name not like '%Extras%') then 20
+ when channel_name like '%Extras%' then 10
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like '%)' then 5
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like '%32-bit x86%' then 4
+ when channel_name like '%64-bit Intel Itanium%' then 3
+ when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
+ else 0
+ end;
+ elsif channel_name like 'Red Hat Desktop%' then
+ priority := 900;
+
+ if channel_name not like '%Beta%' then
+ priority := priority + 50;
+ end if;
+
+ priority := priority +
+ case
+ when channel_name like '%v. 4%' then 40
+ when channel_name like '%v. 3%' then 30
+ when channel_name like '%v. 2%' then 20
+ when channel_name like '%v. 1%' then 10
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like '%32-bit x86%' then 4
+ when channel_name like '%64-bit Intel Itanium%' then 3
+ when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
+ else 0
+ end;
+
+ elsif org_id_val is not null then
+ priority := 600;
+ else
+ priority := 500;
+ end if;
+
+ return -priority;
+
+ end channel_priority;
+
+ -- right now this only does the accounting changes; the cascade
+ -- actually does the rhnServerChannel delete.
+ procedure delete_server_channels(server_id_in in number)
+ is
+ begin
+ update rhnPrivateChannelFamily
+ set current_members = current_members -1
+ where org_id in (
+ select org_id
+ from rhnServer
+ where id = server_id_in
+ )
+ and channel_family_id in (
+ select rcfm.channel_family_id
+ from rhnChannelFamilyMembers rcfm,
+ rhnServerChannel rsc
+ where rsc.server_id = server_id_in
+ and rsc.channel_id = rcfm.channel_id
+ and not exists (
+ select 1
+ from
+ rhnChannelFamilyVirtSubLevel cfvsl,
+ rhnSGTypeVirtSubLevel sgtvsl,
+ rhnServerEntitlementView sev,
+ rhnVirtualInstance vi
+ where
+ -- system is a virtual instance
+ vi.virtual_system_id = server_id_in
+ and vi.host_system_id = sev.server_id
+ -- system's host has a virt ent
+ and sev.label in ('virtualization_host',
+ 'virtualization_host_platform')
+ and sev.server_group_type_id =
+ sgtvsl.server_group_type_id
+ -- the host's virt ent grants a cf virt sub level
+ and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
+ -- the cf is in that virt sub level
+ and cfvsl.channel_family_id = rcfm.channel_family_id
+ )
+ );
+ end;
+
+ -- this could certainly be optimized to do updates if needs be
+ procedure refresh_newest_package(channel_id_in in number, caller_in in varchar2 := '(unknown)')
+ is
+ begin
+ delete from rhnChannelNewestPackage where channel_id = channel_id_in;
+ insert into rhnChannelNewestPackage
+ ( channel_id, name_id, evr_id, package_id, package_arch_id )
+ ( select channel_id,
+ name_id, evr_id,
+ package_id, package_arch_id
+ from rhnChannelNewestPackageView
+ where channel_id = channel_id_in
+ );
+ insert into rhnChannelNewestPackageAudit (channel_id, caller)
+ values (channel_id_in, caller_in);
+ update rhnChannel
+ set last_modified = greatest(sysdate, last_modified + 1/86400)
+ where id = channel_id_in;
+ end;
+
+ procedure update_channel ( channel_id_in in number, invalidate_ss in number := 0,
+ date_to_use in date := sysdate )
+ is
+
+ channel_last_modified date;
+ last_modified_value date;
+
+ cursor snapshots is
+ select snapshot_id id
+ from rhnSnapshotChannel
+ where channel_id = channel_id_in;
+
+ begin
+
+ select last_modified
+ into channel_last_modified
+ from rhnChannel
+ where id = channel_id_in;
+
+ last_modified_value := date_to_use;
+
+ if last_modified_value <= channel_last_modified then
+ last_modified_value := last_modified_value + 1/86400;
+ end if;
+
+ update rhnChannel set last_modified = last_modified_value
+ where id = channel_id_in;
+
+ if invalidate_ss = 1 then
+ for snapshot in snapshots loop
+ update rhnSnapshot
+ set invalid = lookup_snapshot_invalid_reason('channel_modified')
+ where id = snapshot.id;
+ end loop;
+ end if;
+
+ end update_channel;
+
+ procedure update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate )
+ is
+
+ cursor channels is
+ select channel_id
+ from rhnChannelPackage
+ where package_id = package_id_in
+ order by channel_id;
+
+ begin
+ for channel in channels loop
+ -- we want to invalidate the snapshot assocated with the channel when we
+ -- do this b/c we know we've added or removed or packages
+ rhn_channel.update_channel ( channel.channel_id, 1, date_to_use );
+ end loop;
+ end update_channels_by_package;
+
+
+ procedure update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate )
+ is
+
+ cursor channels is
+ select channel_id
+ from rhnChannelErrata
+ where errata_id = errata_id_in
+ order by channel_id;
+
+ begin
+ for channel in channels loop
+ -- we won't invalidate snapshots, b/c just changing the errata associated with
+ -- a channel shouldn't invalidate snapshots
+ rhn_channel.update_channel ( channel.channel_id, 0, date_to_use );
+ end loop;
+ end update_channels_by_errata;
+
+ procedure update_needed_cache(channel_id_in in number)
+ is
+ pragma autonomous_transaction;
+ -- update of needed cache ican be commited on a per server basis
+ -- b/c failure of update for a server means nothing for the other servers
+ begin
+ -- we intentionaly do a loop here instead of one huge select
+ -- b/c we want to break update into smaller transaction to unblock other sessions
+ -- querying rhnServerNeededCache
+ for server in (
+ select sc.server_id as id
+ from rhnServerChannel sc
+ where sc.channel_id = channel_id_in
+ ) loop
+ rhn_server.update_needed_cache(server.id);
+ commit;
+ end loop;
+ end update_needed_cache;
+
+END rhn_channel;
+/
+SHOW ERRORS
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql
deleted file mode 100644
index 1b73dd5..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql
+++ /dev/null
@@ -1,4 +0,0 @@
-
-drop package body rhn_package;
-drop package rhn_package;
-
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql.oracle
new file mode 100644
index 0000000..1b73dd5
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/005-rhn_package-drop.sql.oracle
@@ -0,0 +1,4 @@
+
+drop package body rhn_package;
+drop package rhn_package;
+
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql
deleted file mode 100644
index c549d48..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql
+++ /dev/null
@@ -1,28 +0,0 @@
---
--- Copyright (c) 2008--2010 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.
---
---
---
---
-
-CREATE OR REPLACE
-PACKAGE rhn_org
-IS
- procedure delete_org(org_id_in in number);
- procedure delete_user(user_id_in in number, deleting_org in number := 0);
-
-END rhn_org;
-/
-SHOW ERRORS
-
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql.oracle
new file mode 100644
index 0000000..c549d48
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/006-rhn_org.sql.oracle
@@ -0,0 +1,28 @@
+--
+-- Copyright (c) 2008--2010 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.
+--
+--
+--
+--
+
+CREATE OR REPLACE
+PACKAGE rhn_org
+IS
+ procedure delete_org(org_id_in in number);
+ procedure delete_user(user_id_in in number, deleting_org in number := 0);
+
+END rhn_org;
+/
+SHOW ERRORS
+
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql
deleted file mode 100644
index 1ae6f83..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql
+++ /dev/null
@@ -1,235 +0,0 @@
---
--- Copyright (c) 2008--2010 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.
---
---
---
---
-
-CREATE OR REPLACE
-PACKAGE BODY rhn_org
-IS
- procedure delete_org (
- org_id_in in number
- )
- is
- cursor users is
- select id
- from web_contact
- where org_id = org_id_in;
-
- cursor servers(org_id_in in number) is
- select id
- from rhnServer
- where org_id = org_id_in;
-
- cursor config_channels is
- select id
- from rhnConfigChannel
- where org_id = org_id_in;
-
- cursor custom_channels is
- select id
- from rhnChannel
- where org_id = org_id_in;
-
- cursor errata is
- select id
- from rhnErrata
- where org_id = org_id_in;
-
- begin
-
- if org_id_in = 1 then
- rhn_exception.raise_exception('cannot_delete_base_org');
- end if;
-
- -- Delete all users.
- for u in users loop
- rhn_org.delete_user(u.id, 1);
- end loop;
-
- -- Delete all servers.
- for s in servers(org_id_in) loop
- delete_server(s.id);
- end loop;
-
- -- Delete all config channels.
- for c in config_channels loop
- rhn_config.delete_channel(c.id);
- end loop;
-
- -- Delete all custom channels.
- for cc in custom_channels loop
- delete from rhnServerChannel where channel_id = cc.id;
- delete from rhnServerProfilePackage where server_profile_id in (
- select id from rhnServerProfile where base_channel = cc.id
- );
- delete from rhnServerProfile where base_channel = cc.id;
- end loop;
-
- -- Delete all errata packages
- for e in errata loop
- delete from rhnErrataPackage where errata_id = e.id;
- end loop;
-
- -- Give the org's entitlements back to the main org.
- rhn_entitlements.remove_org_entitlements(org_id_in);
-
- -- Clean up tables where we don't have a cascading delete.
- delete from rhnChannel where org_id = org_id_in;
- delete from rhnDailySummaryQueue where org_id = org_id_in;
- delete from rhnOrgQuota where org_id = org_id_in;
- delete from rhnFileList where org_id = org_id_in;
- delete from rhnServerGroup where org_id = org_id_in;
- delete from rhn_check_suites where customer_id = org_id_in;
- delete from rhn_command_target where customer_id = org_id_in;
- delete from rhn_contact_groups where customer_id = org_id_in;
- delete from rhn_notification_formats where customer_id = org_id_in;
- delete from rhn_probe where customer_id = org_id_in;
- delete from rhn_redirects where customer_id = org_id_in;
- delete from rhn_sat_cluster where customer_id = org_id_in;
- delete from rhn_schedules where customer_id = org_id_in;
-
- -- Delete the org.
- delete from web_customer where id = org_id_in;
-
- end delete_org;
-
- procedure delete_user(user_id_in in number, deleting_org in number := 0) is
- cursor servergroups_needing_admins is
- select usgp.server_group_id server_group_id
- from rhnUserServerGroupPerms usgp
- where 1=1
- and usgp.user_id = user_id_in
- and not exists (
- select 1
- from rhnUserServerGroupPerms sq_usgp
- where 1=1
- and sq_usgp.server_group_id = usgp.server_group_id
- and sq_usgp.user_id != user_id_in
- );
- users number;
- our_org_id number;
- other_users number;
- other_org_admin number;
- other_user_id number;
- is_admin number;
- begin
- select wc.org_id
- into our_org_id
- from web_contact wc
- where id = user_id_in;
-
- -- find any other users
- begin
- select id, 1
- into other_user_id, other_users
- from web_contact
- where 1=1
- and org_id = our_org_id
- and id != user_id_in
- and rownum = 1;
- exception
- when no_data_found then
- other_users := 0;
- end;
-
- -- now do org admin stuff
- if other_users != 0 then
- -- is user admin?
- select count(1)
- into is_admin
- from rhnUserGroupType ugt,
- rhnUserGroup ug,
- rhnUserGroupMembers ugm
- where ugm.user_id = user_id_in
- and ugm.user_group_id = ug.id
- and ug.group_type = ugt.id
- and ugt.label = 'org_admin';
- if is_admin > 0 then
- begin
- select new_ugm.user_id
- into other_org_admin
- from rhnUserGroupMembers new_ugm,
- rhnUserGroupType ugt,
- rhnUserGroup ug,
- rhnUserGroupMembers ugm
- where ugm.user_id = user_id_in
- and ugm.user_group_id = ug.id
- and ug.group_type = ugt.id
- and ugt.label = 'org_admin'
- and ug.id = new_ugm.user_group_id
- and new_ugm.user_id != user_id_in
- and rownum = 1;
- exception
- when no_data_found then
- -- If we're deleting the org, we don't want to raise
- -- the exception.
- if deleting_org = 0 then
- rhn_exception.raise_exception('cannot_delete_user');
- end if;
- end;
-
- for sg in servergroups_needing_admins loop
- rhn_user.add_servergroup_perm(other_org_admin,
- sg.server_group_id);
- end loop;
- end if;
- end if;
-
- -- and now things for every user
- delete from rhn_command_queue_sessions where contact_id = user_id_in;
- delete from rhn_contact_groups
- where recid in (
- select contact_group_id
- from rhn_contact_group_members
- where member_contact_method_id in (
- select recid from rhn_contact_methods
- where contact_id = user_id_in
- )
- )
- and not exists (
- select 1
- from rhn_contact_group_members, rhn_contact_methods
- where rhn_contact_groups.recid = rhn_contact_group_members.contact_group_id
- and rhn_contact_group_members.member_contact_method_id = rhn_contact_methods.recid
- and rhn_contact_methods.contact_id <> user_id_in
- );
- delete from rhn_contact_methods where contact_id = user_id_in;
- delete from rhn_redirects where contact_id = user_id_in;
- delete from rhnUserServerPerms where user_id = user_id_in;
- delete from rhnAppInstallSession where user_id = user_id_in;
- update rhnConfigRevision
- set changed_by_id = NULL
- where changed_by_id = user_id_in;
- if other_users != 0 then
- update rhnRegToken
- set user_id = nvl(other_org_admin, other_user_id)
- where org_id = our_org_id
- and user_id = user_id_in;
- end if;
-
- begin
- delete from web_contact where id = user_id_in;
- exception
- when others then
- rhn_exception.raise_exception('cannot_delete_user');
- end;
- return;
- end delete_user;
-
-END rhn_org;
-/
-SHOW ERRORS
-
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql.oracle
new file mode 100644
index 0000000..1ae6f83
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/007-rhn_org-body.sql.oracle
@@ -0,0 +1,235 @@
+--
+-- Copyright (c) 2008--2010 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.
+--
+--
+--
+--
+
+CREATE OR REPLACE
+PACKAGE BODY rhn_org
+IS
+ procedure delete_org (
+ org_id_in in number
+ )
+ is
+ cursor users is
+ select id
+ from web_contact
+ where org_id = org_id_in;
+
+ cursor servers(org_id_in in number) is
+ select id
+ from rhnServer
+ where org_id = org_id_in;
+
+ cursor config_channels is
+ select id
+ from rhnConfigChannel
+ where org_id = org_id_in;
+
+ cursor custom_channels is
+ select id
+ from rhnChannel
+ where org_id = org_id_in;
+
+ cursor errata is
+ select id
+ from rhnErrata
+ where org_id = org_id_in;
+
+ begin
+
+ if org_id_in = 1 then
+ rhn_exception.raise_exception('cannot_delete_base_org');
+ end if;
+
+ -- Delete all users.
+ for u in users loop
+ rhn_org.delete_user(u.id, 1);
+ end loop;
+
+ -- Delete all servers.
+ for s in servers(org_id_in) loop
+ delete_server(s.id);
+ end loop;
+
+ -- Delete all config channels.
+ for c in config_channels loop
+ rhn_config.delete_channel(c.id);
+ end loop;
+
+ -- Delete all custom channels.
+ for cc in custom_channels loop
+ delete from rhnServerChannel where channel_id = cc.id;
+ delete from rhnServerProfilePackage where server_profile_id in (
+ select id from rhnServerProfile where base_channel = cc.id
+ );
+ delete from rhnServerProfile where base_channel = cc.id;
+ end loop;
+
+ -- Delete all errata packages
+ for e in errata loop
+ delete from rhnErrataPackage where errata_id = e.id;
+ end loop;
+
+ -- Give the org's entitlements back to the main org.
+ rhn_entitlements.remove_org_entitlements(org_id_in);
+
+ -- Clean up tables where we don't have a cascading delete.
+ delete from rhnChannel where org_id = org_id_in;
+ delete from rhnDailySummaryQueue where org_id = org_id_in;
+ delete from rhnOrgQuota where org_id = org_id_in;
+ delete from rhnFileList where org_id = org_id_in;
+ delete from rhnServerGroup where org_id = org_id_in;
+ delete from rhn_check_suites where customer_id = org_id_in;
+ delete from rhn_command_target where customer_id = org_id_in;
+ delete from rhn_contact_groups where customer_id = org_id_in;
+ delete from rhn_notification_formats where customer_id = org_id_in;
+ delete from rhn_probe where customer_id = org_id_in;
+ delete from rhn_redirects where customer_id = org_id_in;
+ delete from rhn_sat_cluster where customer_id = org_id_in;
+ delete from rhn_schedules where customer_id = org_id_in;
+
+ -- Delete the org.
+ delete from web_customer where id = org_id_in;
+
+ end delete_org;
+
+ procedure delete_user(user_id_in in number, deleting_org in number := 0) is
+ cursor servergroups_needing_admins is
+ select usgp.server_group_id server_group_id
+ from rhnUserServerGroupPerms usgp
+ where 1=1
+ and usgp.user_id = user_id_in
+ and not exists (
+ select 1
+ from rhnUserServerGroupPerms sq_usgp
+ where 1=1
+ and sq_usgp.server_group_id = usgp.server_group_id
+ and sq_usgp.user_id != user_id_in
+ );
+ users number;
+ our_org_id number;
+ other_users number;
+ other_org_admin number;
+ other_user_id number;
+ is_admin number;
+ begin
+ select wc.org_id
+ into our_org_id
+ from web_contact wc
+ where id = user_id_in;
+
+ -- find any other users
+ begin
+ select id, 1
+ into other_user_id, other_users
+ from web_contact
+ where 1=1
+ and org_id = our_org_id
+ and id != user_id_in
+ and rownum = 1;
+ exception
+ when no_data_found then
+ other_users := 0;
+ end;
+
+ -- now do org admin stuff
+ if other_users != 0 then
+ -- is user admin?
+ select count(1)
+ into is_admin
+ from rhnUserGroupType ugt,
+ rhnUserGroup ug,
+ rhnUserGroupMembers ugm
+ where ugm.user_id = user_id_in
+ and ugm.user_group_id = ug.id
+ and ug.group_type = ugt.id
+ and ugt.label = 'org_admin';
+ if is_admin > 0 then
+ begin
+ select new_ugm.user_id
+ into other_org_admin
+ from rhnUserGroupMembers new_ugm,
+ rhnUserGroupType ugt,
+ rhnUserGroup ug,
+ rhnUserGroupMembers ugm
+ where ugm.user_id = user_id_in
+ and ugm.user_group_id = ug.id
+ and ug.group_type = ugt.id
+ and ugt.label = 'org_admin'
+ and ug.id = new_ugm.user_group_id
+ and new_ugm.user_id != user_id_in
+ and rownum = 1;
+ exception
+ when no_data_found then
+ -- If we're deleting the org, we don't want to raise
+ -- the exception.
+ if deleting_org = 0 then
+ rhn_exception.raise_exception('cannot_delete_user');
+ end if;
+ end;
+
+ for sg in servergroups_needing_admins loop
+ rhn_user.add_servergroup_perm(other_org_admin,
+ sg.server_group_id);
+ end loop;
+ end if;
+ end if;
+
+ -- and now things for every user
+ delete from rhn_command_queue_sessions where contact_id = user_id_in;
+ delete from rhn_contact_groups
+ where recid in (
+ select contact_group_id
+ from rhn_contact_group_members
+ where member_contact_method_id in (
+ select recid from rhn_contact_methods
+ where contact_id = user_id_in
+ )
+ )
+ and not exists (
+ select 1
+ from rhn_contact_group_members, rhn_contact_methods
+ where rhn_contact_groups.recid = rhn_contact_group_members.contact_group_id
+ and rhn_contact_group_members.member_contact_method_id = rhn_contact_methods.recid
+ and rhn_contact_methods.contact_id <> user_id_in
+ );
+ delete from rhn_contact_methods where contact_id = user_id_in;
+ delete from rhn_redirects where contact_id = user_id_in;
+ delete from rhnUserServerPerms where user_id = user_id_in;
+ delete from rhnAppInstallSession where user_id = user_id_in;
+ update rhnConfigRevision
+ set changed_by_id = NULL
+ where changed_by_id = user_id_in;
+ if other_users != 0 then
+ update rhnRegToken
+ set user_id = nvl(other_org_admin, other_user_id)
+ where org_id = our_org_id
+ and user_id = user_id_in;
+ end if;
+
+ begin
+ delete from web_contact where id = user_id_in;
+ exception
+ when others then
+ rhn_exception.raise_exception('cannot_delete_user');
+ end;
+ return;
+ end delete_user;
+
+END rhn_org;
+/
+SHOW ERRORS
+
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql
deleted file mode 100644
index 4e34675..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-
-drop function channel_name_join;
-
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql.oracle
new file mode 100644
index 0000000..4e34675
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/008-channel_name_join-drop.sql.oracle
@@ -0,0 +1,3 @@
+
+drop function channel_name_join;
+
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql
deleted file mode 100644
index b33eb27..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql
+++ /dev/null
@@ -1,3 +0,0 @@
-
-drop type channel_name_t;
-
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql.oracle
new file mode 100644
index 0000000..b33eb27
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/009-channel_name_t-drop.sql.oracle
@@ -0,0 +1,3 @@
+
+drop type channel_name_t;
+
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql
deleted file mode 100644
index 16a059b..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql
+++ /dev/null
@@ -1,33 +0,0 @@
---
--- Copyright (c) 2008--2010 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.
---
---
---
---
--- PL/SQL version of rpmvercompare
---
-
-CREATE OR REPLACE PACKAGE rpm AS
- FUNCTION vercmp(
- e1 VARCHAR2, v1 VARCHAR2, r1 VARCHAR2,
- e2 VARCHAR2, v2 VARCHAR2, r2 VARCHAR2)
- RETURN NUMBER
- DETERMINISTIC
- PARALLEL_ENABLE;
- PRAGMA RESTRICT_REFERENCES(vercmp, WNDS, RNDS);
-
-END rpm;
-/
-SHOW ERRORS;
-
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql.oracle
new file mode 100644
index 0000000..16a059b
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/010-rpm.sql.oracle
@@ -0,0 +1,33 @@
+--
+-- Copyright (c) 2008--2010 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.
+--
+--
+--
+--
+-- PL/SQL version of rpmvercompare
+--
+
+CREATE OR REPLACE PACKAGE rpm AS
+ FUNCTION vercmp(
+ e1 VARCHAR2, v1 VARCHAR2, r1 VARCHAR2,
+ e2 VARCHAR2, v2 VARCHAR2, r2 VARCHAR2)
+ RETURN NUMBER
+ DETERMINISTIC
+ PARALLEL_ENABLE;
+ PRAGMA RESTRICT_REFERENCES(vercmp, WNDS, RNDS);
+
+END rpm;
+/
+SHOW ERRORS;
+
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql
deleted file mode 100644
index 6d45b30..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql
+++ /dev/null
@@ -1,234 +0,0 @@
---
--- Copyright (c) 2008--2010 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.
---
---
---
---
--- PL/SQL version of rpmvercompare
-
-CREATE OR REPLACE PACKAGE BODY rpm AS
-
- FUNCTION isdigit(ch CHAR)
- RETURN BOOLEAN
- deterministic
- IS
- BEGIN
- if ascii(ch) between ascii('0') and ascii('9')
- then
- return TRUE;
- end if;
- return FALSE;
- END isdigit;
-
-
- FUNCTION isalpha(ch CHAR)
- RETURN BOOLEAN
- deterministic
- IS
- BEGIN
- if ascii(ch) between ascii('a') and ascii('z') or
- ascii(ch) between ascii('A') and ascii('Z')
- then
- return TRUE;
- end if;
- return FALSE;
- END isalpha;
-
-
- FUNCTION isalphanum(ch CHAR)
- RETURN BOOLEAN
- deterministic
- IS
- BEGIN
- if ascii(ch) between ascii('a') and ascii('z') or
- ascii(ch) between ascii('A') and ascii('Z') or
- ascii(ch) between ascii('0') and ascii('9')
- then
- return TRUE;
- end if;
- return FALSE;
- END isalphanum;
-
-
- FUNCTION rpmstrcmp (string1 IN VARCHAR2, string2 IN VARCHAR2)
- RETURN NUMBER
- deterministic
- IS
- digits CHAR(10) := '0123456789';
- lc_alpha CHAR(27) := 'abcdefghijklmnopqrstuvwxyz';
- uc_alpha CHAR(27) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- alpha CHAR(54) := lc_alpha || uc_alpha;
- str1 VARCHAR2(32767) := string1;
- str2 VARCHAR2(32767) := string2;
- one VARCHAR2(32767);
- two VARCHAR2(32767);
- isnum BOOLEAN;
- BEGIN
- if str1 is NULL or str2 is NULL
- then
- raise VALUE_ERROR;
- end if;
- -- easy comparison to see if versions are identical
- if str1 = str2
- then
- return 0;
- end if;
- -- loop through each version segment of str1 and str2 and compare them
- one := str1;
- two := str2;
-
- <<segment_loop>>
- while one is not null and two is not null
- loop
- declare
- segm1 VARCHAR2(32767);
- segm2 VARCHAR2(32767);
- begin
- --DBMS_OUTPUT.PUT_LINE('Params: ' || one || ',' || two);
- -- Throw out all non-alphanum characters
- while one is not null and not isalphanum(one)
- loop
- one := substr(one, 2);
- end loop;
- while two is not null and not isalphanum(two)
- loop
- two := substr(two, 2);
- end loop;
- --DBMS_OUTPUT.PUT_LINE('new params: ' || one || ',' || two);
-
- str1 := one;
- str2 := two;
-
- /* grab first completely alpha or completely numeric segment */
- /* leave one and two pointing to the start of the alpha or numeric */
- /* segment and walk str1 and str2 to end of segment */
-
- if str1 is not null and isdigit(str1)
- then
- str1 := ltrim(str1, digits);
- str2 := ltrim(str2, digits);
- isnum := true;
- else
- str1 := ltrim(str1, alpha);
- str2 := ltrim(str2, alpha);
- isnum := false;
- end if;
-
- --DBMS_OUTPUT.PUT_LINE('Len: ' || length(str1) || ',' || length(str2));
- -- Oracle trats the length of an empty string as null
- if str1 is not null
- then segm1 := substr(one, 1, length(one) - length(str1));
- else segm1 := one;
- end if;
-
- if str2 is not null
- then segm2 := substr(two, 1, length(two) - length(str2));
- else segm2 := two;
- end if;
-
- --DBMS_OUTPUT.PUT_LINE('Segments: ' || segm1 || ',' || segm2);
- --DBMS_OUTPUT.PUT_LINE('Rest: ' || str1 || ',' || str2);
- /* take care of the case where the two version segments are */
- /* different types: one numeric and one alpha */
- if segm1 is null then return -1; end if; /* arbitrary */
- if segm2 is null then
- if isnum then
- return 1;
- else
- return -1;
- end if;
- end if;
-
- if isnum
- then
- /* this used to be done by converting the digit segments */
- /* to ints using atoi() - it's changed because long */
- /* digit segments can overflow an int - this should fix that. */
-
- /* throw away any leading zeros - it's a number, right? */
- segm1 := ltrim(segm1, '0');
- segm2 := ltrim(segm2, '0');
-
- /* whichever number has more digits wins */
- -- length of empty string is null
- if segm1 is null and segm2 is not null
- then
- return -1;
- end if;
- if segm1 is not null and segm2 is null
- then
- return 1;
- end if;
- if length(segm1) > length(segm2) then return 1; end if;
- if length(segm2) > length(segm1) then return -1; end if;
- end if;
-
- /* strcmp will return which one is greater - even if the two */
- /* segments are alpha or if they are numeric. don't return */
- /* if they are equal because there might be more segments to */
- /* compare */
-
- if segm1 < segm2 then return -1; end if;
- if segm1 > segm2 then return 1; end if;
-
- one := str1;
- two := str2;
- end;
- end loop segment_loop;
- /* this catches the case where all numeric and alpha segments have */
- /* compared identically but the segment sepparating characters were */
- /* different */
- if one is null and two is null then return 0; end if;
-
- /* whichever version still has characters left over wins */
- if one is null then return -1; end if;
- return 1;
- END rpmstrcmp;
-
-
- FUNCTION vercmp(
- e1 VARCHAR2, v1 VARCHAR2, r1 VARCHAR2,
- e2 VARCHAR2, v2 VARCHAR2, r2 VARCHAR2)
- RETURN NUMBER
- IS
- rc NUMBER;
- BEGIN
- DECLARE
- ep1 NUMBER;
- ep2 NUMBER;
- BEGIN
- if e1 is null then
- ep1 := 0;
- else
- ep1 := TO_NUMBER(e1);
- end if;
- if e2 is null then
- ep2 := 0;
- else
- ep2 := TO_NUMBER(e2);
- end if;
- -- Epochs are non-null; compare them
- if ep1 < ep2 then return -1; end if;
- if ep1 > ep2 then return 1; end if;
- rc := rpmstrcmp(v1, v2);
- if rc != 0 then return rc; end if;
- return rpmstrcmp(r1, r2);
- END;
-
- END vercmp;
-
-END rpm;
-/
-SHOW ERRORS;
-
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql.oracle
new file mode 100644
index 0000000..6d45b30
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/011-rpm-body.sql.oracle
@@ -0,0 +1,234 @@
+--
+-- Copyright (c) 2008--2010 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.
+--
+--
+--
+--
+-- PL/SQL version of rpmvercompare
+
+CREATE OR REPLACE PACKAGE BODY rpm AS
+
+ FUNCTION isdigit(ch CHAR)
+ RETURN BOOLEAN
+ deterministic
+ IS
+ BEGIN
+ if ascii(ch) between ascii('0') and ascii('9')
+ then
+ return TRUE;
+ end if;
+ return FALSE;
+ END isdigit;
+
+
+ FUNCTION isalpha(ch CHAR)
+ RETURN BOOLEAN
+ deterministic
+ IS
+ BEGIN
+ if ascii(ch) between ascii('a') and ascii('z') or
+ ascii(ch) between ascii('A') and ascii('Z')
+ then
+ return TRUE;
+ end if;
+ return FALSE;
+ END isalpha;
+
+
+ FUNCTION isalphanum(ch CHAR)
+ RETURN BOOLEAN
+ deterministic
+ IS
+ BEGIN
+ if ascii(ch) between ascii('a') and ascii('z') or
+ ascii(ch) between ascii('A') and ascii('Z') or
+ ascii(ch) between ascii('0') and ascii('9')
+ then
+ return TRUE;
+ end if;
+ return FALSE;
+ END isalphanum;
+
+
+ FUNCTION rpmstrcmp (string1 IN VARCHAR2, string2 IN VARCHAR2)
+ RETURN NUMBER
+ deterministic
+ IS
+ digits CHAR(10) := '0123456789';
+ lc_alpha CHAR(27) := 'abcdefghijklmnopqrstuvwxyz';
+ uc_alpha CHAR(27) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ alpha CHAR(54) := lc_alpha || uc_alpha;
+ str1 VARCHAR2(32767) := string1;
+ str2 VARCHAR2(32767) := string2;
+ one VARCHAR2(32767);
+ two VARCHAR2(32767);
+ isnum BOOLEAN;
+ BEGIN
+ if str1 is NULL or str2 is NULL
+ then
+ raise VALUE_ERROR;
+ end if;
+ -- easy comparison to see if versions are identical
+ if str1 = str2
+ then
+ return 0;
+ end if;
+ -- loop through each version segment of str1 and str2 and compare them
+ one := str1;
+ two := str2;
+
+ <<segment_loop>>
+ while one is not null and two is not null
+ loop
+ declare
+ segm1 VARCHAR2(32767);
+ segm2 VARCHAR2(32767);
+ begin
+ --DBMS_OUTPUT.PUT_LINE('Params: ' || one || ',' || two);
+ -- Throw out all non-alphanum characters
+ while one is not null and not isalphanum(one)
+ loop
+ one := substr(one, 2);
+ end loop;
+ while two is not null and not isalphanum(two)
+ loop
+ two := substr(two, 2);
+ end loop;
+ --DBMS_OUTPUT.PUT_LINE('new params: ' || one || ',' || two);
+
+ str1 := one;
+ str2 := two;
+
+ /* grab first completely alpha or completely numeric segment */
+ /* leave one and two pointing to the start of the alpha or numeric */
+ /* segment and walk str1 and str2 to end of segment */
+
+ if str1 is not null and isdigit(str1)
+ then
+ str1 := ltrim(str1, digits);
+ str2 := ltrim(str2, digits);
+ isnum := true;
+ else
+ str1 := ltrim(str1, alpha);
+ str2 := ltrim(str2, alpha);
+ isnum := false;
+ end if;
+
+ --DBMS_OUTPUT.PUT_LINE('Len: ' || length(str1) || ',' || length(str2));
+ -- Oracle trats the length of an empty string as null
+ if str1 is not null
+ then segm1 := substr(one, 1, length(one) - length(str1));
+ else segm1 := one;
+ end if;
+
+ if str2 is not null
+ then segm2 := substr(two, 1, length(two) - length(str2));
+ else segm2 := two;
+ end if;
+
+ --DBMS_OUTPUT.PUT_LINE('Segments: ' || segm1 || ',' || segm2);
+ --DBMS_OUTPUT.PUT_LINE('Rest: ' || str1 || ',' || str2);
+ /* take care of the case where the two version segments are */
+ /* different types: one numeric and one alpha */
+ if segm1 is null then return -1; end if; /* arbitrary */
+ if segm2 is null then
+ if isnum then
+ return 1;
+ else
+ return -1;
+ end if;
+ end if;
+
+ if isnum
+ then
+ /* this used to be done by converting the digit segments */
+ /* to ints using atoi() - it's changed because long */
+ /* digit segments can overflow an int - this should fix that. */
+
+ /* throw away any leading zeros - it's a number, right? */
+ segm1 := ltrim(segm1, '0');
+ segm2 := ltrim(segm2, '0');
+
+ /* whichever number has more digits wins */
+ -- length of empty string is null
+ if segm1 is null and segm2 is not null
+ then
+ return -1;
+ end if;
+ if segm1 is not null and segm2 is null
+ then
+ return 1;
+ end if;
+ if length(segm1) > length(segm2) then return 1; end if;
+ if length(segm2) > length(segm1) then return -1; end if;
+ end if;
+
+ /* strcmp will return which one is greater - even if the two */
+ /* segments are alpha or if they are numeric. don't return */
+ /* if they are equal because there might be more segments to */
+ /* compare */
+
+ if segm1 < segm2 then return -1; end if;
+ if segm1 > segm2 then return 1; end if;
+
+ one := str1;
+ two := str2;
+ end;
+ end loop segment_loop;
+ /* this catches the case where all numeric and alpha segments have */
+ /* compared identically but the segment sepparating characters were */
+ /* different */
+ if one is null and two is null then return 0; end if;
+
+ /* whichever version still has characters left over wins */
+ if one is null then return -1; end if;
+ return 1;
+ END rpmstrcmp;
+
+
+ FUNCTION vercmp(
+ e1 VARCHAR2, v1 VARCHAR2, r1 VARCHAR2,
+ e2 VARCHAR2, v2 VARCHAR2, r2 VARCHAR2)
+ RETURN NUMBER
+ IS
+ rc NUMBER;
+ BEGIN
+ DECLARE
+ ep1 NUMBER;
+ ep2 NUMBER;
+ BEGIN
+ if e1 is null then
+ ep1 := 0;
+ else
+ ep1 := TO_NUMBER(e1);
+ end if;
+ if e2 is null then
+ ep2 := 0;
+ else
+ ep2 := TO_NUMBER(e2);
+ end if;
+ -- Epochs are non-null; compare them
+ if ep1 < ep2 then return -1; end if;
+ if ep1 > ep2 then return 1; end if;
+ rc := rpmstrcmp(v1, v2);
+ if rc != 0 then return rc; end if;
+ return rpmstrcmp(r1, r2);
+ END;
+
+ END vercmp;
+
+END rpm;
+/
+SHOW ERRORS;
+
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql
deleted file mode 100644
index 3adfc8e..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql
+++ /dev/null
@@ -1,54 +0,0 @@
---
--- Copyright (c) 2008--2010 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.
---
-
-create or replace
-package rhn_user
-is
- version varchar2(100) := '';
-
- function check_role(user_id_in in number, role_in in varchar2) return number;
- PRAGMA RESTRICT_REFERENCES(check_role, WNDS, RNPS, WNPS);
-
- function check_role_implied(user_id_in in number, role_in in varchar2) return number;
- PRAGMA RESTRICT_REFERENCES(check_role_implied, WNDS, RNPS, WNPS);
-
- function get_org_id(user_id_in in number) return number;
- PRAGMA RESTRICT_REFERENCES(get_org_id, WNDS, RNPS, WNPS);
-
- function find_mailable_address(user_id_in in number) return varchar2;
-
- procedure add_servergroup_perm(
- user_id_in in number,
- server_group_id_in in number
- );
-
- procedure remove_servergroup_perm(
- user_id_in in number,
- server_group_id_in in number
- );
-
- procedure add_to_usergroup(
- user_id_in in number,
- user_group_id_in in number
- );
-
- procedure remove_from_usergroup(
- user_id_in in number,
- user_group_id_in in number
- );
-
-end rhn_user;
-/
-SHOW ERRORS
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql.oracle
new file mode 100644
index 0000000..3adfc8e
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/012-rhn_user.sql.oracle
@@ -0,0 +1,54 @@
+--
+-- Copyright (c) 2008--2010 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.
+--
+
+create or replace
+package rhn_user
+is
+ version varchar2(100) := '';
+
+ function check_role(user_id_in in number, role_in in varchar2) return number;
+ PRAGMA RESTRICT_REFERENCES(check_role, WNDS, RNPS, WNPS);
+
+ function check_role_implied(user_id_in in number, role_in in varchar2) return number;
+ PRAGMA RESTRICT_REFERENCES(check_role_implied, WNDS, RNPS, WNPS);
+
+ function get_org_id(user_id_in in number) return number;
+ PRAGMA RESTRICT_REFERENCES(get_org_id, WNDS, RNPS, WNPS);
+
+ function find_mailable_address(user_id_in in number) return varchar2;
+
+ procedure add_servergroup_perm(
+ user_id_in in number,
+ server_group_id_in in number
+ );
+
+ procedure remove_servergroup_perm(
+ user_id_in in number,
+ server_group_id_in in number
+ );
+
+ procedure add_to_usergroup(
+ user_id_in in number,
+ user_group_id_in in number
+ );
+
+ procedure remove_from_usergroup(
+ user_id_in in number,
+ user_group_id_in in number
+ );
+
+end rhn_user;
+/
+SHOW ERRORS
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql
deleted file mode 100644
index 1330aaf..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql
+++ /dev/null
@@ -1,252 +0,0 @@
---
--- Copyright (c) 2008--2010 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.
---
---
---
---
-
-create or replace
-package body rhn_user
-is
- body_version varchar2(100) := '';
-
- function check_role(user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
- select 1 into throwaway
- from rhnUserGroupType UGT,
- rhnUserGroup UG,
- rhnUserGroupMembers UGM
- where UGM.user_id = user_id_in
- and UGM.user_group_id = UG.id
- and UG.group_type = UGT.id
- and UGT.label = role_in;
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end check_role;
-
- function check_role_implied(user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- if the user directly has the role, they win
- if rhn_user.check_role(user_id_in, role_in) = 1
- then
- return 1;
- end if;
-
- -- config_admin and channel_admin are automatically implied for org admins
- if role_in = 'config_admin' and rhn_user.check_role(user_id_in, 'org_admin') = 1
- then
- return 1;
- end if;
-
- if role_in = 'channel_admin' and rhn_user.check_role(user_id_in, 'org_admin') = 1
- then
- return 1;
- end if;
-
- return 0;
- end check_role_implied;
-
- function get_org_id(user_id_in in number)
- return number
- is
- org_id_out number;
- begin
- select org_id into org_id_out
- from web_contact
- where id = user_id_in;
-
- return org_id_out;
- end get_org_id;
-
- -- paid users often don't have verified email addresses, so
- -- try to find an address that is useful to us.
- function find_mailable_address(user_id_in in number)
- return varchar2 is
- PRAGMA AUTONOMOUS_TRANSACTION;
- -- this would be so much prettier if we just had an order built
- -- into rhnEmailAddressState
- cursor addrs is
- select ea.state_id, ea.address
- from rhnEmailAddressState eas,
- rhnEmailAddress ea
- where ea.user_id = user_id_in
- and eas.label = 'verified'
- and ea.state_id = eas.id
- union all
- select ea.state_id, ea.address
- from rhnEmailAddressState eas,
- rhnEmailAddress ea
- where ea.user_id = user_id_in
- and eas.label = 'unverified'
- and ea.state_id = eas.id
- union all
- select ea.state_id, ea.address
- from rhnEmailAddressState eas,
- rhnEmailAddress ea
- where ea.user_id = user_id_in
- and eas.label = 'pending'
- and ea.state_id = eas.id
- union all
- select ea.state_id, ea.address
- from rhnEmailAddressState eas,
- rhnEmailAddress ea
- where ea.user_id = user_id_in
- and eas.label = 'pending_warned'
- and ea.state_id = eas.id
- union all
- select ea.state_id, ea.address
- from rhnEmailAddressState eas,
- rhnEmailAddress ea
- where ea.user_id = user_id_in
- and eas.label = 'needs_verifying'
- and ea.state_id = eas.id
- union all
- select -1 state_id,
- email address
- from web_user_personal_info
- where web_user_id = user_id_in;
- retval rhnEmailAddress.address%TYPE;
- begin
- for addr in addrs loop
- retval := addr.address;
- if addr.address is null then
- update web_user_contact_permission
- set email = 'N'
- where web_user_id = user_id_in;
- commit;
- return null;
- end if;
- if addr.state_id = -1 then
- insert into rhnEmailAddress (
- id, address,
- user_id, state_id
- ) (
- select rhn_eaddress_id_seq.nextval, addr.address,
- user_id_in, eas.id
- from rhnEmailAddressState eas
- where eas.label = 'unverified'
- );
- end if;
- commit;
- return retval;
- end loop;
- return null;
- end;
-
- procedure add_servergroup_perm(
- user_id_in in number,
- server_group_id_in in number
- ) is
- cursor orgs_match is
- select 1
- from rhnServerGroup sg,
- web_contact u
- where u.id = user_id_in
- and sg.id = server_group_id_in
- and sg.org_id = u.org_id;
- begin
- for okay in orgs_match loop
- insert into rhnUserServerGroupPerms(user_id, server_group_id)
- values (user_id_in, server_group_id_in);
- rhn_cache.update_perms_for_user(user_id_in);
- return;
- end loop;
- rhn_exception.raise_exception('usgp_different_orgs');
- exception when dup_val_on_index then
- rhn_exception.raise_exception('usgp_already_allowed');
- end add_servergroup_perm;
-
- procedure remove_servergroup_perm(
- user_id_in in number,
- server_group_id_in in number
- ) is
- cursor perms is
- select 1
- from rhnUserServerGroupPerms
- where user_id = user_id_in
- and server_group_id = server_group_id_in;
- begin
- for perm in perms loop
- delete from rhnUserServerGroupPerms
- where user_id = user_id_in
- and server_group_id = server_group_id_in;
- rhn_cache.update_perms_for_user(user_id_in);
- return;
- end loop;
- rhn_exception.raise_exception('usgp_not_allowed');
- end remove_servergroup_perm;
-
- procedure add_to_usergroup(
- user_id_in in number,
- user_group_id_in in number
- ) is
- cursor perm_granting_usergroups is
- select user_group_id_in
- from rhnUserGroup ug,
- rhnUserGroupType ugt
- where ugt.label in ('org_admin') -- and server_group_admin ?
- and ug.id = user_group_id_in
- and ug.group_type = ugt.id;
- begin
- insert into rhnUserGroupMembers(user_id, user_group_id)
- values (user_id_in, user_group_id_in);
-
- for ug in perm_granting_usergroups loop
- rhn_cache.update_perms_for_user(user_id_in);
- return;
- end loop;
- end add_to_usergroup;
-
- procedure remove_from_usergroup(
- user_id_in in number,
- user_group_id_in in number
- ) is
- cursor perm_granting_usergroups is
- select label
- from rhnUserGroupType ugt,
- rhnUserGroupMembers ugm,
- rhnUserGroup ug
- where 1=1
- and ug.id = user_group_id_in
- and ugm.user_group_id = user_group_id_in
- and ug.group_type = ugt.id
- and ugm.user_id = user_id_in;
- begin
- -- we only do anything if you're really in the group, because
- -- testing is significantly cheaper than rebuilding the user's
- -- cache for no reason.
- for ug in perm_granting_usergroups loop
- delete from rhnUserGroupMembers
- where user_id = user_id_in
- and user_group_id = user_group_id_in;
- if ug.label in ('org_admin') then
- rhn_cache.update_perms_for_user(user_id_in);
- end if;
- end loop;
- end remove_from_usergroup;
-
-end rhn_user;
-/
-SHOW ERRORS
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql.oracle
new file mode 100644
index 0000000..1330aaf
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/013-rhn_user-body.sql.oracle
@@ -0,0 +1,252 @@
+--
+-- Copyright (c) 2008--2010 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.
+--
+--
+--
+--
+
+create or replace
+package body rhn_user
+is
+ body_version varchar2(100) := '';
+
+ function check_role(user_id_in in number, role_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
+ select 1 into throwaway
+ from rhnUserGroupType UGT,
+ rhnUserGroup UG,
+ rhnUserGroupMembers UGM
+ where UGM.user_id = user_id_in
+ and UGM.user_group_id = UG.id
+ and UG.group_type = UGT.id
+ and UGT.label = role_in;
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end check_role;
+
+ function check_role_implied(user_id_in in number, role_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- if the user directly has the role, they win
+ if rhn_user.check_role(user_id_in, role_in) = 1
+ then
+ return 1;
+ end if;
+
+ -- config_admin and channel_admin are automatically implied for org admins
+ if role_in = 'config_admin' and rhn_user.check_role(user_id_in, 'org_admin') = 1
+ then
+ return 1;
+ end if;
+
+ if role_in = 'channel_admin' and rhn_user.check_role(user_id_in, 'org_admin') = 1
+ then
+ return 1;
+ end if;
+
+ return 0;
+ end check_role_implied;
+
+ function get_org_id(user_id_in in number)
+ return number
+ is
+ org_id_out number;
+ begin
+ select org_id into org_id_out
+ from web_contact
+ where id = user_id_in;
+
+ return org_id_out;
+ end get_org_id;
+
+ -- paid users often don't have verified email addresses, so
+ -- try to find an address that is useful to us.
+ function find_mailable_address(user_id_in in number)
+ return varchar2 is
+ PRAGMA AUTONOMOUS_TRANSACTION;
+ -- this would be so much prettier if we just had an order built
+ -- into rhnEmailAddressState
+ cursor addrs is
+ select ea.state_id, ea.address
+ from rhnEmailAddressState eas,
+ rhnEmailAddress ea
+ where ea.user_id = user_id_in
+ and eas.label = 'verified'
+ and ea.state_id = eas.id
+ union all
+ select ea.state_id, ea.address
+ from rhnEmailAddressState eas,
+ rhnEmailAddress ea
+ where ea.user_id = user_id_in
+ and eas.label = 'unverified'
+ and ea.state_id = eas.id
+ union all
+ select ea.state_id, ea.address
+ from rhnEmailAddressState eas,
+ rhnEmailAddress ea
+ where ea.user_id = user_id_in
+ and eas.label = 'pending'
+ and ea.state_id = eas.id
+ union all
+ select ea.state_id, ea.address
+ from rhnEmailAddressState eas,
+ rhnEmailAddress ea
+ where ea.user_id = user_id_in
+ and eas.label = 'pending_warned'
+ and ea.state_id = eas.id
+ union all
+ select ea.state_id, ea.address
+ from rhnEmailAddressState eas,
+ rhnEmailAddress ea
+ where ea.user_id = user_id_in
+ and eas.label = 'needs_verifying'
+ and ea.state_id = eas.id
+ union all
+ select -1 state_id,
+ email address
+ from web_user_personal_info
+ where web_user_id = user_id_in;
+ retval rhnEmailAddress.address%TYPE;
+ begin
+ for addr in addrs loop
+ retval := addr.address;
+ if addr.address is null then
+ update web_user_contact_permission
+ set email = 'N'
+ where web_user_id = user_id_in;
+ commit;
+ return null;
+ end if;
+ if addr.state_id = -1 then
+ insert into rhnEmailAddress (
+ id, address,
+ user_id, state_id
+ ) (
+ select rhn_eaddress_id_seq.nextval, addr.address,
+ user_id_in, eas.id
+ from rhnEmailAddressState eas
+ where eas.label = 'unverified'
+ );
+ end if;
+ commit;
+ return retval;
+ end loop;
+ return null;
+ end;
+
+ procedure add_servergroup_perm(
+ user_id_in in number,
+ server_group_id_in in number
+ ) is
+ cursor orgs_match is
+ select 1
+ from rhnServerGroup sg,
+ web_contact u
+ where u.id = user_id_in
+ and sg.id = server_group_id_in
+ and sg.org_id = u.org_id;
+ begin
+ for okay in orgs_match loop
+ insert into rhnUserServerGroupPerms(user_id, server_group_id)
+ values (user_id_in, server_group_id_in);
+ rhn_cache.update_perms_for_user(user_id_in);
+ return;
+ end loop;
+ rhn_exception.raise_exception('usgp_different_orgs');
+ exception when dup_val_on_index then
+ rhn_exception.raise_exception('usgp_already_allowed');
+ end add_servergroup_perm;
+
+ procedure remove_servergroup_perm(
+ user_id_in in number,
+ server_group_id_in in number
+ ) is
+ cursor perms is
+ select 1
+ from rhnUserServerGroupPerms
+ where user_id = user_id_in
+ and server_group_id = server_group_id_in;
+ begin
+ for perm in perms loop
+ delete from rhnUserServerGroupPerms
+ where user_id = user_id_in
+ and server_group_id = server_group_id_in;
+ rhn_cache.update_perms_for_user(user_id_in);
+ return;
+ end loop;
+ rhn_exception.raise_exception('usgp_not_allowed');
+ end remove_servergroup_perm;
+
+ procedure add_to_usergroup(
+ user_id_in in number,
+ user_group_id_in in number
+ ) is
+ cursor perm_granting_usergroups is
+ select user_group_id_in
+ from rhnUserGroup ug,
+ rhnUserGroupType ugt
+ where ugt.label in ('org_admin') -- and server_group_admin ?
+ and ug.id = user_group_id_in
+ and ug.group_type = ugt.id;
+ begin
+ insert into rhnUserGroupMembers(user_id, user_group_id)
+ values (user_id_in, user_group_id_in);
+
+ for ug in perm_granting_usergroups loop
+ rhn_cache.update_perms_for_user(user_id_in);
+ return;
+ end loop;
+ end add_to_usergroup;
+
+ procedure remove_from_usergroup(
+ user_id_in in number,
+ user_group_id_in in number
+ ) is
+ cursor perm_granting_usergroups is
+ select label
+ from rhnUserGroupType ugt,
+ rhnUserGroupMembers ugm,
+ rhnUserGroup ug
+ where 1=1
+ and ug.id = user_group_id_in
+ and ugm.user_group_id = user_group_id_in
+ and ug.group_type = ugt.id
+ and ugm.user_id = user_id_in;
+ begin
+ -- we only do anything if you're really in the group, because
+ -- testing is significantly cheaper than rebuilding the user's
+ -- cache for no reason.
+ for ug in perm_granting_usergroups loop
+ delete from rhnUserGroupMembers
+ where user_id = user_id_in
+ and user_group_id = user_group_id_in;
+ if ug.label in ('org_admin') then
+ rhn_cache.update_perms_for_user(user_id_in);
+ end if;
+ end loop;
+ end remove_from_usergroup;
+
+end rhn_user;
+/
+SHOW ERRORS
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql
deleted file mode 100644
index b1bafb4..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql
+++ /dev/null
@@ -1,1857 +0,0 @@
---
--- Copyright (c) 2008--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.
---
---
---
---
-
-create or replace
-package body rhn_entitlements
-is
- body_version varchar2(100) := '';
-
- function find_compatible_sg (
- server_id_in in number,
- type_label_in in varchar2
- ) return number is
-
- cursor servergroups is
- select sg.id id
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServer s,
- rhnServerServerGroupArchCompat ssgac
- where s.id = server_id_in
- and s.org_id = sg.org_id
- and sgt.label = type_label_in
- and sg.group_type = sgt.id
- and ssgac.server_group_type = sgt.id
- and ssgac.server_arch_id = s.server_arch_id
- and not exists (
- select 1
- from rhnServerGroupMembers sgm
- where sgm.server_group_id = sg.id
- and sgm.server_id = s.id);
-
-
- begin
- for servergroup in servergroups loop
- return servergroup.id;
- end loop;
-
- --no servergroup found
- return null;
- end find_compatible_sg;
-
-
- -- *******************************************************************
- -- PROCEDURE: remove_org_entitlements
- --
- -- Removes both system entitlements and channel subscriptions
- -- that are currently assigned to an org and re-assigns to the
- -- master org (org_id = 1).
- --
- -- When we call this we expect everything to already be unentitled
- -- which shoul be handled by delete_org.
- --
- -- Called by: delete_org
- -- *******************************************************************
- procedure remove_org_entitlements(
- org_id_in in number
- )
- is
-
- cursor system_ents is
- select sg.id, sg.max_members, sg.group_type
- from rhnServerGroup sg
- where group_type is not null
- and org_id = org_id_in;
-
- cursor channel_subs is
- select pcf.channel_family_id, pcf.max_members
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = org_id_in
- and pcf.channel_family_id = cf.id
- and cf.org_id is null;
-
- begin
-
- for system_ent in system_ents loop
- update rhnServerGroup
- set max_members = max_members + system_ent.max_members
- where org_id = 1
- and group_type = system_ent.group_type;
- end loop;
-
- update rhnServerGroup
- set max_members = 0
- where org_id = org_id_in;
-
- for channel_sub in channel_subs loop
- update rhnPrivateChannelFamily
- set max_members = max_members + channel_sub.max_members
- where org_id = 1
- and channel_family_id = channel_sub.channel_family_id;
- end loop;
-
- update rhnPrivateChannelFamily
- set max_members = 0
- where org_id = org_id_in;
-
- end remove_org_entitlements;
-
- function entitlement_grants_service (
- entitlement_in in varchar2,
- service_level_in in varchar2
- ) return number is
- begin
- if service_level_in = 'provisioning' then
- if entitlement_in = 'provisioning_entitled' then
- return 1;
- else
- return 0;
- end if;
- elsif service_level_in = 'management' then
- if entitlement_in = 'enterprise_entitled' then
- return 1;
- else
- return 0;
- end if;
- elsif service_level_in = 'monitoring' then
- if entitlement_in = 'monitoring_entitled' then
- return 1;
- end if;
- elsif service_level_in = 'updates' then
- return 1;
- else
- return 0;
- end if;
- end entitlement_grants_service;
-
- function lookup_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number is
- cursor server_groups is
- select sg.id server_group_id
- from rhnServerGroup sg,
- rhnServerGroupType sgt
- where sgt.label = type_label_in
- and sgt.id = sg.group_type
- and sg.org_id = org_id_in;
- begin
- for sg in server_groups loop
- return sg.server_group_id;
- end loop;
- return rhn_entitlements.create_entitlement_group(
- org_id_in,
- type_label_in
- );
- end lookup_entitlement_group;
-
- function create_entitlement_group (
- org_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) return number is
- sg_id_val number;
- begin
- select rhn_server_group_id_seq.nextval
- into sg_id_val
- from dual;
-
- insert into rhnServerGroup (
- id, name, description, max_members, current_members,
- group_type, org_id
- ) (
- select sg_id_val, sgt.label, sgt.label,
- 0, 0, sgt.id, org_id_in
- from rhnServerGroupType sgt
- where sgt.label = type_label_in
- );
-
- return sg_id_val;
- end create_entitlement_group;
-
- function can_entitle_server (
- server_id_in in number,
- type_label_in in varchar2 )
- return number is
- cursor addon_servergroups (base_label_in in varchar2,
- addon_label_in in varchar2) is
- select
- addon_id
- from
- rhnSGTypeBaseAddonCompat
- where base_id = lookup_sg_type (base_label_in)
- and addon_id = lookup_sg_type (addon_label_in);
-
- previous_ent rhn_entitlements.ents_array;
- is_base_in char := 'N';
- is_base_current char := 'N';
- i number := 0;
- sgid number := 0;
-
- begin
-
- previous_ent := rhn_entitlements.ents_array();
- previous_ent := rhn_entitlements.get_server_entitlement(server_id_in);
-
- select distinct is_base
- into is_base_in
- from rhnServerGroupType
- where label = type_label_in;
-
- if previous_ent.count = 0 then
- sgid := find_compatible_sg (server_id_in, type_label_in);
- if (is_base_in = 'Y' and sgid is not null) then
- -- rhn_server.insert_into_servergroup (server_id_in, sgid);
- return 1;
- else
- -- rhn_exception.raise_exception ('invalid_base_entitlement');
- return 0;
- end if;
-
- -- there are previous ents, first make sure we're not trying to entitle a base ent
- elsif is_base_in = 'Y' then
- -- rhn_exception.raise_exception ('invalid_addon_entitlement');
- return 0;
-
- -- it must be an addon, so proceed with the entitlement
- else
-
- -- find the servers base ent
- is_base_current := 'N';
- i := 0;
- while is_base_current = 'N' and i <= previous_ent.count
- loop
- i := i + 1;
- select is_base
- into is_base_current
- from rhnServerGroupType
- where label = previous_ent(i);
- end loop;
-
- -- never found a base ent, that would be strange
- if is_base_current = 'N' then
- -- rhn_exception.raise_exception ('invalid_base_entitlement');
- return 0;
- end if;
-
- -- this for loop verifies the validity of the addon path
- for addon_servergroup in addon_servergroups (previous_ent(i), type_label_in) loop
- -- find an appropriate sgid for the addon and entitle the server
- sgid := find_compatible_sg (server_id_in, type_label_in);
- if sgid is not null then
- -- rhn_server.insert_into_servergroup (server_id_in, sgid);
- return 1;
- else
- -- rhn_exception.raise_exception ('invalid_addon_entitlement');
- return 0;
- end if;
- end loop;
-
- end if;
-
- return 0;
-
- end can_entitle_server;
-
- function can_switch_base (
- server_id_in in integer,
- type_label_in in varchar2
- ) return number is
-
- type_label_in_is_base char(1);
- sgid number;
-
- begin
-
- begin
- select is_base into type_label_in_is_base
- from rhnServerGroupType
- where label = type_label_in;
- exception
- when no_data_found then
- rhn_exception.raise_exception ( 'invalid_entitlement' );
- end;
-
- if type_label_in_is_base = 'N' then
- rhn_exception.raise_exception ( 'invalid_entitlement' );
- else
- sgid := find_compatible_sg ( server_id_in, type_label_in );
- if sgid is not null then
- return 1;
- else
- return 0;
- end if;
- end if;
-
- end can_switch_base;
-
-
- procedure entitle_server (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled'
- ) is
- sgid number := 0;
- is_virt number := 0;
-
- begin
-
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- if is_virt = 0 and (type_label_in = 'virtualization_host' or
- type_label_in = 'virtualization_host_platform') then
-
- is_virt := 1;
- end if;
-
-
-
- if rhn_entitlements.can_entitle_server(server_id_in,
- type_label_in) = 1 then
- sgid := find_compatible_sg (server_id_in, type_label_in);
- if sgid is not null then
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, server_id_in,
- 'added system entitlement ',
- case type_label_in
- when 'enterprise_entitled' then 'Management'
- when 'sw_mgr_entitled' then 'Update'
- when 'provisioning_entitled' then 'Provisioning'
- when 'monitoring_entitled' then 'Monitoring'
- when 'virtualization_host' then 'Virtualization'
- when 'virtualization_host_platform' then
- 'Virtualization Platform' end );
-
- rhn_server.insert_into_servergroup (server_id_in, sgid);
-
- if is_virt = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- else
- rhn_exception.raise_exception ('no_available_server_group');
- end if;
- else
- rhn_exception.raise_exception ('invalid_entitlement');
- end if;
- end entitle_server;
-
- procedure remove_server_entitlement (
- server_id_in in number,
- type_label_in in varchar2 := 'sw_mgr_entitled',
- repoll_virt_guests in number := 1
- ) is
- group_id number;
- type_is_base char;
- is_virt number := 0;
- begin
- begin
-
-
- -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- select sg.id, sgt.is_base
- into group_id, type_is_base
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm,
- rhnServer s
- where s.id = server_id_in
- and s.id = sgm.server_id
- and sgm.server_group_id = sg.id
- and sg.org_id = s.org_id
- and sgt.label = type_label_in
- and sgt.id = sg.group_type;
-
- if ( type_is_base = 'Y' ) then
- -- unentitle_server should handle everything, don't really need to do anything else special here
- unentitle_server ( server_id_in );
- else
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, server_id_in,
- 'removed system entitlement ',
- case type_label_in
- when 'enterprise_entitled' then 'Management'
- when 'sw_mgr_entitled' then 'Update'
- when 'provisioning_entitled' then 'Provisioning'
- when 'monitoring_entitled' then 'Monitoring'
- when 'virtualization_host' then 'Virtualization'
- when 'virtualization_host_platform' then
- 'Virtualization Platforrm' end );
-
- rhn_server.delete_from_servergroup(server_id_in, group_id);
-
- -- special case: clean up related monitornig data
- if type_label_in = 'monitoring_entitled' then
- DELETE
- FROM state_change
- WHERE o_id IN (SELECT probe_id
- FROM rhn_check_probe
- WHERE host_id = server_id_in);
- DELETE /*+index(time_series time_series_probe_id_idx)*/
- FROM time_series
- WHERE SUBSTR(o_id, INSTR(o_id, '-') + 1,
- (INSTR(o_id, '-', INSTR(o_id, '-') + 1) - INSTR(o_id, '-')) - 1)
- IN (SELECT to_char(probe_id)
- FROM rhn_check_probe
- WHERE host_id = server_id_in);
- DELETE
- FROM rhn_probe
- WHERE recid IN (SELECT probe_id
- FROM rhn_check_probe
- WHERE host_id = server_id_in);
- end if;
-
- if is_virt = 1 and repoll_virt_guests = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
- end if;
-
- exception
- when no_data_found then
- rhn_exception.raise_exception('invalid_server_group_member');
- end;
-
- end remove_server_entitlement;
-
-
- procedure unentitle_server (server_id_in in number) is
-
- cursor servergroups is
- select distinct sgt.label, sg.id server_group_id
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServer s,
- rhnServerGroupMembers sgm
- where s.id = server_id_in
- and s.org_id = sg.org_id
- and sg.group_type = sgt.id
- and sgm.server_group_id = sg.id
- and sgm.server_id = s.id;
-
- is_virt number := 0;
-
- begin
-
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- for servergroup in servergroups loop
-
- insert into rhnServerHistory ( id, server_id, summary, details )
- values ( rhn_event_id_seq.nextval, server_id_in,
- 'removed system entitlement ',
- case servergroup.label
- when 'enterprise_entitled' then 'Management'
- when 'sw_mgr_entitled' then 'Update'
- when 'provisioning_entitled' then 'Provisioning'
- when 'monitoring_entitled' then 'Monitoring'
- when 'virtualization_host' then 'Virtualization'
- when 'virtualization_host_platform' then
- 'Virtualization Platform' end );
-
- rhn_server.delete_from_servergroup(server_id_in,
- servergroup.server_group_id );
- end loop;
-
- if is_virt = 1 then
- rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
- end if;
-
- end unentitle_server;
-
-
- -- *******************************************************************
- -- PROCEDURE: repoll_virt_guest_entitlements
- --
- -- Whenever we add/remove a virtualization_host* entitlement from
- -- a host, we can call this procedure to update what type of slots
- -- the guests are consuming.
- --
- -- If you're removing the entitlement, it's
- -- possible the guests will become unentitled if you don't have enough
- -- physical slots to cover them.
- --
- -- If you're adding the entitlement, you end up freeing up physical
- -- slots for other systems.
- --
- -- *******************************************************************
- procedure repoll_virt_guest_entitlements(server_id_in in number)
- is
-
- -- All channel families associated with the guests of server_id_in
- cursor families is
- select distinct cfs.channel_family_id
- from
- rhnChannelFamilyServers cfs,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = cfs.server_id;
-
- -- All of server group types associated with the guests of
- -- server_id_in
- cursor group_types is
- select distinct sg.group_type, sgt.label
- from
- rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = sgm.server_id
- and sgm.server_group_id = sg.id
- and sg.group_type = sgt.id;
-
- -- Virtual servers from a certain family belonging to a speicifc
- -- host that are consuming physical channel slots over the limit.
- cursor virt_servers_cfam(family_id_in in number, quantity_in in number) is
- select virtual_system_id
- from (
- select rownum, vi.virtual_system_id
- from
- rhnChannelFamilyMembers cfm,
- rhnServerChannel sc,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = sc.server_id
- and sc.channel_id = cfm.channel_id
- and cfm.channel_family_id = family_id_in
- order by sc.modified desc
- )
- where rownum <= quantity_in;
-
- -- Virtual servers from a certain family belonging to a speicifc
- -- host that are consuming physical system slots over the limit.
- cursor virt_servers_sgt(group_type_in in number, quantity_in in number) is
- select virtual_system_id
- from (
- select rownum, vi.virtual_system_id
- from
- rhnServerGroup sg,
- rhnServerGroupMembers sgm,
- rhnVirtualInstance vi
- where
- vi.host_system_id = server_id_in
- and vi.virtual_system_id = sgm.server_id
- and sgm.server_group_id = sg.id
- and sg.group_type = group_type_in
- order by sgm.modified desc
- )
- where rownum <= quantity_in;
- -- Get the orgs of Virtual guests
- -- Since they may belong to different orgs
- cursor virt_guest_orgs is
- select distinct (s.org_id)
- from rhnServer s
- inner join rhnVirtualInstance vi on vi.virtual_system_id = s.id
- where
- vi.host_system_id = server_id_in
- and s.org_id <> (select s1.org_id from rhnServer s1 where s1.id = vi.host_system_id) ;
-
-
- org_id_val number;
- max_members_val number;
- max_flex_val number;
- current_members_calc number;
- sg_id number;
- is_virt number := 0;
- begin
- begin
- select 1 into is_virt
- from rhnServerEntitlementView
- where server_id = server_id_in
- and label in ('virtualization_host', 'virtualization_host_platform');
- exception
- when no_data_found then
- is_virt := 0;
- end;
-
- select org_id
- into org_id_val
- from rhnServer
- where id = server_id_in;
-
- -- deal w/ channel entitlements first ...
- for family in families loop
- if is_virt = 0 then
- -- if the host_server does not have virt
- --- find all possible flex slots
- -- and set each of the flex eligible guests to Y
- UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
- where sc.server_id in (
- select virtual_system_id from (
- select rownum, vi.virtual_system_id, sfc.max_members - sfc.current_members as free_slots
- from rhnServerFveCapable sfc
- inner join rhnVirtualInstance vi on vi.virtual_system_id = sfc.server_id
- where vi.host_system_id = server_id_in
- and sfc.channel_family_id = family.channel_family_id
- order by vi.modified desc
- )
- where rownum <= free_slots
- );
- else
- -- if the host_server has virt
- -- set all its flex guests to N
- UPDATE rhnServerChannel sc set sc.is_fve = 'N'
- where
- sc.channel_id in (select cfm.channel_id from rhnChannelFamilyMembers cfm
- where cfm.CHANNEL_FAMILY_ID = family.channel_family_id)
- and sc.is_fve = 'Y'
- and sc.server_id in
- (select vi.virtual_system_id from rhnVirtualInstance vi
- where vi.host_system_id = server_id_in);
- end if;
-
- -- get the current (physical) members of the family
- current_members_calc :=
- rhn_channel.channel_family_current_members(family.channel_family_id,
- org_id_val); -- fixed transposed args
-
- -- get the max members of the family
- select max_members
- into max_members_val
- from rhnPrivateChannelFamily
- where channel_family_id = family.channel_family_id
- and org_id = org_id_val;
-
- select fve_max_members
- into max_flex_val
- from rhnPrivateChannelFamily
- where channel_family_id = family.channel_family_id
- and org_id = org_id_val;
-
- if current_members_calc > max_members_val then
- -- A virtualization_host* ent must have been removed, so we'll
- -- unsubscribe guests from the host first.
-
- -- hm, i don't think max_members - current_members_calc yielding a negative number
- -- will work w/ rownum, swaping 'em in the body of this if...
- for virt_server in virt_servers_cfam(family.channel_family_id,
- current_members_calc - max_members_val) loop
-
- rhn_channel.unsubscribe_server_from_family(
- virt_server.virtual_system_id,
- family.channel_family_id);
- end loop;
-
- -- if we're still over the limit, which would be odd,
- -- just prune the group to max_members
- --
- -- er... wouldn't we actually have to refresh the values of
- -- current_members_calc and max_members_val to actually ever
- -- *skip this??
- if current_members_calc > max_members_val then
- -- argh, transposed again?!
- set_family_count(org_id_val,
- family.channel_family_id,
- max_members_val, max_flex_val);
- --TODO calculate this correctly
- end if;
-
- end if;
-
- -- update current_members for the family. This will set the value
- -- to reflect adding/removing the entitlement.
- --
- -- what's the difference of doing this vs the unavoidable set_family_count above?
- rhn_channel.update_family_counts(family.channel_family_id,
- org_id_val);
-
- -- It is possible that the guests belong to a different org than the host
- -- so we are going to update the family counts in the guests orgs also
- for org in virt_guest_orgs loop
- rhn_channel.update_family_counts(family.channel_family_id,
- org.org_id);
- end loop;
- end loop;
-
- for a_group_type in group_types loop
- -- get the current *physical* members of the system entitlement type for the org...
- --
- -- unlike channel families, it appears the standard rhnServerGroup.max_members represents
- -- *physical* slots, vs physical+virt ... boy that's confusing...
-
- select max_members, id
- into max_members_val, sg_id
- from rhnServerGroup
- where group_type = a_group_type.group_type
- and org_id = org_id_val;
-
-
- select count(sep.server_id) into current_members_calc
- from rhnServerEntitlementPhysical sep
- where sep.server_group_id = sg_id
- and sep.server_group_type_id = a_group_type.group_type;
-
- if current_members_calc > max_members_val then
- -- A virtualization_host* ent must have been removed, and we're over the limit, so unsubscribe guests
- for virt_server in virt_servers_sgt(a_group_type.group_type,
- current_members_calc - max_members_val) loop
- rhn_entitlements.remove_server_entitlement(virt_server.virtual_system_id, a_group_type.label);
-
- -- decrement current_members_calc, we'll use it to reset current_members for the group at the end...
- current_members_calc := current_members_calc - 1;
- end loop;
-
- end if;
-
- update rhnServerGroup set current_members = current_members_calc
- where org_id = org_id_val
- and group_type = a_group_type.group_type;
-
- -- I think that's all the house-keeping we have to do...
- end loop;
-
- end repoll_virt_guest_entitlements;
-
-
- function get_server_entitlement (
- server_id_in in number
- ) return ents_array is
-
- cursor server_groups is
- select sgt.label
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm
- where 1=1
- and sgm.server_id = server_id_in
- and sg.id = sgm.server_group_id
- and sgt.id = sg.group_type
- and sgt.label in (
- 'sw_mgr_entitled','enterprise_entitled',
- 'provisioning_entitled', 'nonlinux_entitled',
- 'monitoring_entitled', 'virtualization_host',
- 'virtualization_host_platform'
- );
-
- ent_array ents_array;
-
- begin
-
- ent_array := ents_array();
-
- for sg in server_groups loop
- ent_array.extend;
- ent_array(ent_array.count) := sg.label;
- end loop;
-
- return ent_array;
-
- end get_server_entitlement;
-
-
- -- this desperately needs to be table driven.
- procedure modify_org_service (
- org_id_in in number,
- service_label_in in varchar2,
- enable_in in char
- ) is
- type roles_v is varray(10) of rhnUserGroupType.label%TYPE;
- roles_to_process roles_v;
- cursor roles(role_label_in in varchar2) is
- select label, id
- from rhnUserGroupType
- where label = role_label_in;
- cursor org_roles(role_label_in in varchar2) is
- select 1
- from rhnUserGroup ug,
- rhnUserGroupType ugt
- where ugt.label = role_label_in
- and ug.org_id = org_id_in
- and ugt.id = ug.group_type;
-
- type ents_v is varray(10) of rhnOrgEntitlementType.label%TYPE;
- ents_to_process ents_v;
- cursor ents(ent_label_in in varchar2) is
- select label, id
- from rhnOrgEntitlementType
- where label = ent_label_in;
- cursor org_ents(ent_label_in in varchar2) is
- select 1
- from rhnOrgEntitlements oe,
- rhnOrgEntitlementType oet
- where oet.label = ent_label_in
- and oe.org_id = org_id_in
- and oet.id = oe.entitlement_id;
- create_row char(1);
- begin
- ents_to_process := ents_v();
- roles_to_process := roles_v();
- -- a bit kludgy, but only for 3.4 really. Certainly no
- -- worse than the old code...
- if service_label_in = 'enterprise' or
- service_label_in = 'management' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'org_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'system_group_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'activation_key_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'org_applicant';
- elsif service_label_in = 'provisioning' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_provisioning';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'system_group_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'activation_key_admin';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- -- another nasty special case...
- if enable_in = 'Y' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
- end if;
- elsif service_label_in = 'monitoring' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_monitor';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'monitoring_admin';
- elsif service_label_in = 'virtualization' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_virtualization';
-
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- elsif service_label_in = 'virtualization_platform' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_virtualization_platform';
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- elsif service_label_in = 'nonlinux' then
- ents_to_process.extend;
- ents_to_process(ents_to_process.count) := 'rhn_nonlinux';
- roles_to_process.extend;
- roles_to_process(roles_to_process.count) := 'config_admin';
- end if;
-
- if enable_in = 'Y' then
- for i in 1..ents_to_process.count loop
- for ent in ents(ents_to_process(i)) loop
- create_row := 'Y';
- for oe in org_ents(ent.label) loop
- create_row := 'N';
- end loop;
- if create_row = 'Y' then
- insert into rhnOrgEntitlements(org_id, entitlement_id)
- values (org_id_in, ent.id);
- end if;
- end loop;
- end loop;
- for i in 1..roles_to_process.count loop
- for role in roles(roles_to_process(i)) loop
- create_row := 'Y';
- for o_r in org_roles(role.label) loop
- create_row := 'N';
- end loop;
- if create_row = 'Y' then
- insert into rhnUserGroup(
- id, name, description, current_members,
- group_type, org_id
- ) (
- select rhn_user_group_id_seq.nextval,
- ugt.name || 's',
- ugt.name || 's for Org ' ||
- o.name || ' ('|| o.id ||')',
- 0, ugt.id, o.id
- from rhnUserGroupType ugt,
- web_customer o
- where o.id = org_id_in
- and ugt.id = role.id
- );
- end if;
- end loop;
- end loop;
- else
- for i in 1..ents_to_process.count loop
- for ent in ents(ents_to_process(i)) loop
- delete from rhnOrgEntitlements
- where org_id = org_id_in
- and entitlement_id = ent.id;
- end loop;
- end loop;
- end if;
- end modify_org_service;
-
- procedure set_customer_enterprise (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'enterprise', 'Y');
- end set_customer_enterprise;
-
- procedure set_customer_provisioning (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'provisioning', 'Y');
- end set_customer_provisioning;
-
- procedure set_customer_monitoring (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'monitoring', 'Y');
- end set_customer_monitoring;
-
- procedure set_customer_nonlinux (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'nonlinux', 'Y');
- end set_customer_nonlinux;
-
- procedure unset_customer_enterprise (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'enterprise', 'N');
- end unset_customer_enterprise;
-
- procedure unset_customer_provisioning (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'provisioning', 'N');
- end unset_customer_provisioning;
-
- procedure unset_customer_monitoring (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'monitoring', 'N');
- end unset_customer_monitoring;
-
- procedure unset_customer_nonlinux (
- customer_id_in in number
- ) is
- begin
- modify_org_service(customer_id_in, 'nonlinux', 'N');
- end unset_customer_nonlinux;
-
- -- *******************************************************************
- -- PROCEDURE: prune_group
- -- Unsubscribes servers consuming physical slots that over the org's
- -- limit.
- -- Called by: set_group_count, repoll_virt_guest_entitlements
- -- *******************************************************************
- procedure prune_group (
- group_id_in in number,
- type_in in char,
- quantity_in in number,
- update_family_countsYN in number := 1
- ) is
- cursor usergroups is
- select user_id, user_group_id, ugt.label
- from rhnUserGroupType ugt,
- rhnUserGroup ug,
- rhnUserGroupMembers ugm
- where 1=1
- and ugm.user_group_id = group_id_in
- and ugm.user_id in (
- select user_id
- from (
- select rownum row_number,
- user_id,
- time
- from (
- select user_id,
- modified time
- from rhnUserGroupMembers
- where user_group_id = group_id_in
- order by time asc
- )
- )
- where row_number > quantity_in
- )
- and ugm.user_group_id = ug.id
- and ug.group_type = ugt.id;
- cursor servergroups is
- select server_id, server_group_id, sgt.id as group_type_id, sgt.label
- from rhnServerGroupType sgt,
- rhnServerGroup sg,
- rhnServerGroupMembers sgm
- where 1=1
- and sgm.server_group_id = group_id_in
- and sgm.server_id in (
- select server_id
- from (
- select rownum row_number,
- server_id,
- time
- from (
- select sep.server_id,
- sep.modified time
- from
- rhnServerEntitlementPhysical sep
- where
- sep.server_group_id = group_id_in
- order by time asc
- )
- )
- where row_number > quantity_in
- )
- and sgm.server_group_id = sg.id
- and sg.group_type = sgt.id;
- type_is_base char;
- begin
- if type_in = 'U' then
- update rhnUserGroup
- set max_members = quantity_in
- where id = group_id_in;
-
- for ug in usergroups loop
- rhn_user.remove_from_usergroup(ug.user_id, ug.user_group_id);
- end loop;
- elsif type_in = 'S' then
- update rhnServerGroup
- set max_members = quantity_in
- where id = group_id_in;
-
- for sg in servergroups loop
- remove_server_entitlement(sg.server_id, sg.label);
-
- select is_base
- into type_is_base
- from rhnServerGroupType sgt
- where sgt.id = sg.group_type_id;
-
- -- if we're removing a base ent, then be sure to
- -- remove the server's channel subscriptions.
- if ( type_is_base = 'Y' ) then
- rhn_channel.clear_subscriptions(sg.server_id,
- update_family_countsYN => update_family_countsYN);
- end if;
-
- end loop;
- end if;
- end prune_group;
-
- -- *******************************************************************
- -- PROCEDURE: assign_system_entitlement
- --
- -- Moves system entitlements from from_org_id_in to to_org_id_in.
- -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
- -- does not have enough entitlements to cover the move.
- -- Takes care of unentitling systems if necessary by calling
- -- set_group_count
- -- *******************************************************************
- procedure assign_system_entitlement(
- group_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number
- )
- is
- prev_ent_count number;
- to_org_prev_ent_count number;
- new_ent_count number;
- new_quantity number;
- group_type number;
- begin
-
- begin
- select max_members
- into prev_ent_count
- from rhnServerGroupType sgt,
- rhnServerGroup sg
- where sg.org_id = from_org_id_in
- and sg.group_type = sgt.id
- and sgt.label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end;
-
- begin
- select max_members
- into to_org_prev_ent_count
- from rhnServerGroupType sgt,
- rhnServerGroup sg
- where sg.org_id = to_org_id_in
- and sg.group_type = sgt.id
- and sgt.label = group_label_in;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count := 0;
- end;
-
- begin
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_server_group');
- end;
-
- new_ent_count := prev_ent_count - quantity_in;
-
- if prev_ent_count > new_ent_count then
- new_quantity := to_org_prev_ent_count + quantity_in;
- end if;
-
- if new_ent_count < 0 then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
-
- rhn_entitlements.set_group_count(from_org_id_in,
- 'S',
- group_type,
- new_ent_count);
-
- rhn_entitlements.set_group_count(to_org_id_in,
- 'S',
- group_type,
- new_quantity);
-
- -- Create or delete the entries in rhnOrgEntitlementType
- if group_label_in = 'enterprise_entitled' then
- if new_quantity > 0 then
- set_customer_enterprise(to_org_id_in);
- else
- unset_customer_enterprise(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'provisioning_entitled' then
- if new_quantity > 0 then
- set_customer_provisioning(to_org_id_in);
- else
- unset_customer_provisioning(to_org_id_in);
- end if;
- end if;
-
- if group_label_in = 'monitoring_entitled' then
- if new_quantity > 0 then
- set_customer_monitoring(to_org_id_in);
- else
- unset_customer_monitoring(to_org_id_in);
- end if;
- end if;
-
- end assign_system_entitlement;
-
- -- *******************************************************************
- -- PROCEDURE: assign_channel_entitlement
- --
- -- Moves channel entitlements from from_org_id_in to to_org_id_in.
- -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
- -- does not have enough entitlements to cover the move.
- -- Takes care of unentitling systems if necessary by calling
- -- set_family_count
- -- *******************************************************************
- procedure assign_channel_entitlement(
- channel_family_label_in in varchar2,
- from_org_id_in in number,
- to_org_id_in in number,
- quantity_in in number,
- flex_in in number
- )
- is
- from_org_prev_ent_count number;
- from_org_prev_ent_count_flex number;
- new_ent_count number;
- new_ent_count_flex number;
- to_org_prev_ent_count number;
- to_org_prev_ent_count_flex number;
- new_quantity number;
- new_flex number;
- cfam_id number;
- begin
-
- begin
- select max_members
- into from_org_prev_ent_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = from_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end;
-
- begin
- select max_members
- into to_org_prev_ent_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = to_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count := 0;
- end;
-
- begin
- select fve_max_members
- into from_org_prev_ent_count_flex
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = from_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'not_enough_flex_entitlements_in_base_org');
- end;
-
- begin
- select fve_max_members
- into to_org_prev_ent_count_flex
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = to_org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- to_org_prev_ent_count_flex := 0;
- end;
-
- begin
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_channel_family');
- end;
-
- new_ent_count := from_org_prev_ent_count - quantity_in;
- new_ent_count_flex := from_org_prev_ent_count_flex - flex_in;
-
- if from_org_prev_ent_count >= new_ent_count then
- new_quantity := to_org_prev_ent_count + quantity_in;
- end if;
-
- if from_org_prev_ent_count_flex >= new_ent_count_flex then
- new_flex := to_org_prev_ent_count_flex + flex_in;
- end if;
-
-
- if new_ent_count < 0 then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- end if;
-
- if new_ent_count_flex < 0 then
- rhn_exception.raise_exception(
- 'not_enough_flex_entitlements_in_base_org');
- end if;
-
-
-
- rhn_entitlements.set_family_count(from_org_id_in, cfam_id,
- new_ent_count, new_ent_count_flex);
-
- rhn_entitlements.set_family_count(to_org_id_in,
- cfam_id,
- new_quantity, new_flex);
-
- end assign_channel_entitlement;
-
- -- *******************************************************************
- -- PROCEDURE: activate_system_entitlement
- --
- -- Sets the values in rhnServerGroup for a given rhnServerGroupType.
- --
- -- Calls: set_group_count to update, prune, or create the group.
- -- Called by: the code that activates a satellite cert.
- --
- -- Raises not_enough_entitlements_in_base_org if all entitlements
- -- in the org are used so the free entitlements would not cover
- -- the difference when descreasing the number of entitlements.
- -- *******************************************************************
- procedure activate_system_entitlement(
- org_id_in in number,
- group_label_in in varchar2,
- quantity_in in number
- )
- is
- prev_ent_count number;
- prev_ent_count_sum number;
- group_type number;
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
- begin
- select current_members
- into prev_ent_count
- from rhnServerGroupType sgt,
- rhnServerGroup sg
- where sg.group_type = sgt.id
- and sgt.label = group_label_in
- and sg.org_id = org_id_in;
- exception
- when NO_DATA_FOUND then
- prev_ent_count := 0;
- end;
-
- begin
- select id
- into group_type
- from rhnServerGroupType
- where label = group_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_server_group');
- end;
-
- -- If we're setting the total entitlemnt count to a lower value,
- -- and that value is less than the allocated count in this org,
- -- we need to raise an exception.
- if quantity_in < prev_ent_count then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- -- don't update family counts after every server
- -- will do bulk update afterwards
- rhn_entitlements.set_group_count(org_id_in,
- 'S',
- group_type,
- quantity_in,
- update_family_countsYN => 0);
- -- bulk update family counts
- rhn_channel.update_group_family_counts(group_label_in, org_id_in);
- end if;
-
-
- end activate_system_entitlement;
-
- -- *******************************************************************
- -- PROCEDURE: activate_channel_entitlement
- --
- -- Calls: set_family_count to update, prune, or create the family
- -- permission bucket.
- -- Called by: the code that activates a satellite cert.
- --
- -- Raises not_enough_entitlements_in_base_org if there are not enough
- -- entitlements in the org to cover the difference when you are
- -- descreasing the number of entitlements.
- --
- -- The backend code in Python is expected to do whatever arithmetics
- -- is needed.
- -- *******************************************************************
- procedure activate_channel_entitlement(
- org_id_in in number,
- channel_family_label_in in varchar2,
- quantity_in in number,
- flex_in in number
-
- )
- is
- prev_ent_count number;
- prev_flex_count number;
- prev_ent_count_sum number;
- cfam_id number;
- reduce_quantity number;
- total_flex_capable number;
- cursor to_convert_reg (channel_family_id_val in number, org_id_in in number, quantity in number)
- is
- select SC.server_id
- from rhnServerChannel SC inner join
- rhnServer S on S.id = SC.server_id
- where
- is_fve = 'Y'
- and S.org_id = org_id_in
- and SC.channel_id in
- (select cfm.channel_id from rhnChannelFamilyMembers cfm
- where cfm.CHANNEL_FAMILY_ID = channel_family_id_val)
- and rownum <= quantity;
- cursor to_convert_flex (channel_family_id_val in number, org_id_in in number, quantity in number)
- is
- select server_id
- from rhnServerFveCapable
- where SERVER_ORG_ID = org_id_in and
- channel_family_id = cfam_id and
- rownum <= quantity;
-
- begin
-
- -- Fetch the current entitlement count for the org
- -- into prev_ent_count
- begin
- select current_members
- into prev_ent_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- prev_ent_count := 0;
- end;
-
- begin
- select pcf.fve_current_members
- into prev_flex_count
- from rhnChannelFamily cf,
- rhnPrivateChannelFamily pcf
- where pcf.org_id = org_id_in
- and pcf.channel_family_id = cf.id
- and cf.label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- prev_flex_count := 0;
- end;
-
-
- begin
- select id
- into cfam_id
- from rhnChannelFamily
- where label = channel_family_label_in;
- exception
- when NO_DATA_FOUND then
- rhn_exception.raise_exception(
- 'invalid_channel_family');
- end;
-
- -- if there are too few flex entitlements
- if flex_in < prev_flex_count then
- -- and if the extra we need is less than or equal to our extra regular entitlements
- if prev_flex_count - flex_in <= quantity_in - prev_ent_count then
- reduce_quantity := prev_flex_count - flex_in;
- -- We need to convert some systems from flex guest to regular
- for system in to_convert_reg(cfam_id, org_id_in, reduce_quantity) loop
- --rhn_channel.convert_to_regular(system.server_id, cfam_id);
- UPDATE rhnServerChannel sc set sc.is_fve = 'N'
- where sc.server_id = system.server_id
- and sc.channel_id in (select cfm.channel_id
- from rhnChannelFamilyMembers cfm
- where cfm.channel_family_id = cfam_id);
- end loop;
-
- --reset previous counts
- prev_ent_count := prev_ent_count + reduce_quantity;
- prev_flex_count := prev_flex_count - reduce_quantity;
- else
- rhn_exception.raise_exception(
- 'not_enough_flex_entitlements_in_base_org');
- end if;
- end if;
-
- -- if there are too few regular entitlements, and extra flex entitlements
- if quantity_in < prev_ent_count and prev_flex_count < flex_in then
- -- how many flex-capable systems (that aren't using flex) do we have
- select count(*)
- into total_flex_capable
- from rhnServerFveCapable
- where SERVER_ORG_ID = org_id_in and
- channel_family_id = cfam_id;
- -- if we have enough flex capable machines that is at least
- -- as many as what we are over on
- if total_flex_capable >= prev_ent_count - quantity_in then
- reduce_quantity := prev_ent_count - quantity_in;
- for system in to_convert_flex(cfam_id, org_id_in, reduce_quantity) loop
--- rhn_channel.convert_to_fve(system.server_id, cfam_id);
- UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
- where sc.server_id = system.server_id
- and sc.channel_id in (select cfm.channel_id
- from rhnChannelFamilyMembers cfm
- where cfm.channel_family_id = cfam_id);
- end loop;
- prev_ent_count := prev_ent_count - reduce_quantity;
- prev_flex_count := prev_flex_count + reduce_quantity;
- end if;
- end if;
-
-
-
-
- -- If we're setting the total entitlemnt count to a lower value,
- -- and that value is less than the count in that one org,
- -- we need to raise an exception.
- if quantity_in < prev_ent_count then
- rhn_exception.raise_exception(
- 'not_enough_entitlements_in_base_org');
- else
- -- even if we've manually converted systems to/from flex above
- -- set_family_count should call update_family_counts, to reset
- -- current used slots
- rhn_entitlements.set_family_count(org_id_in, cfam_id,
- quantity_in, flex_in);
- end if;
-
- end activate_channel_entitlement;
-
-
- procedure set_group_count (
- customer_id_in in number,
- type_in in char,
- group_type_in in number,
- quantity_in in number,
- update_family_countsYN in number := 1
- ) is
- group_id number;
- quantity number;
- begin
- quantity := quantity_in;
- if quantity is not null and quantity < 0 then
- quantity := 0;
- end if;
-
- if type_in = 'U' then
- select rug.id
- into group_id
- from rhnUserGroup rug
- where 1=1
- and rug.org_id = customer_id_in
- and rug.group_type = group_type_in;
- elsif type_in = 'S' then
- select rsg.id
- into group_id
- from rhnServerGroup rsg
- where 1=1
- and rsg.org_id = customer_id_in
- and rsg.group_type = group_type_in;
- end if;
-
- rhn_entitlements.prune_group(
- group_id,
- type_in,
- quantity,
- update_family_countsYN
- );
- exception
- when no_data_found then
- if type_in = 'U' then
- insert into rhnUserGroup (
- id, name, description, max_members, current_members,
- group_type, org_id, created, modified
- ) (
- select rhn_user_group_id_seq.nextval, name, name,
- quantity, 0, id, customer_id_in,
- sysdate, sysdate
- from rhnUserGroupType
- where id = group_type_in
- );
- elsif type_in = 'S' then
- insert into rhnServerGroup (
- id, name, description, max_members, current_members,
- group_type, org_id, created, modified
- ) (
- select rhn_server_group_id_seq.nextval, name, name,
- quantity, 0, id, customer_id_in,
- sysdate, sysdate
- from rhnServerGroupType
- where id = group_type_in
- );
- end if;
- end set_group_count;
-
- -- *******************************************************************
- -- PROCEDURE: prune_family
- -- Unsubscribes servers consuming physical slots from the channel family
- -- that are over the org's limit.
- -- Called by: set_family_count
- -- *******************************************************************
- procedure prune_family (
- customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number,
- flex_in in number
- ) is
- is_fve_in char;
- tmp_quantity number;
-
- cursor serverchannels is
- select sc.server_id,
- sc.channel_id
- from rhnServerChannel sc,
- rhnChannelFamilyMembers cfm
- where 1=1
- and cfm.channel_family_id = channel_family_id_in
- and cfm.channel_id = sc.channel_id
- and server_id in (
- select server_id
- from (
- select server_id, time, rownum row_number
- from (
- select rs.id server_id, rcfm.modified time
- from rhnServerChannel rsc,
- rhnChannelFamilyMembers rcfm,
- rhnServer rs
- where 1=1
- and rs.org_id = customer_id_in
- and rs.id = rsc.server_id
- and rsc.channel_id = rcfm.channel_id
- and rcfm.channel_family_id = channel_family_id_in
- and rsc.is_fve = is_fve_in
- -- we only want to grab servers consuming
- -- physical slots.
- and exists (
- select 1
- from rhnChannelFamilyServerPhysical cfsp
- where cfsp.server_id = rs.id
- and cfsp.channel_family_id =
- channel_family_id_in
- )
- order by time asc
- )
- )
- where row_number > tmp_quantity
- );
- begin
- -- if we get a null customer_id, this is completely bogus.
- if customer_id_in is null then
- return;
- end if;
-
- tmp_quantity := quantity_in;
- is_fve_in := 'N';
-
- for sc in serverchannels loop
- rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
- update_family_countsYN => 0);
-
- tmp_quantity := flex_in;
- is_fve_in := 'Y';
- for sc in serverchannels loop
- rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
- update_family_countsYN => 0);
- end loop;
-
-
-
- end loop;
- rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
- end prune_family;
-
- procedure set_family_count (
- customer_id_in in number,
- channel_family_id_in in number,
- quantity_in in number,
- flex_in in number
- ) is
- cursor privperms is
- select 1
- from rhnPrivateChannelFamily
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
- cursor pubperms is
- select o.id org_id
- from web_customer o,
- rhnPublicChannelFamily pcf
- where pcf.channel_family_id = channel_family_id_in;
- quantity number;
- done number := 0;
- flex number;
- begin
- quantity := quantity_in;
- if quantity is not null and quantity < 0 then
- quantity := 0;
- end if;
- flex := flex_in;
- if flex is not null and flex < 0 then
- flex := 0;
- end if;
-
-
- if customer_id_in is not null then
- for perm in privperms loop
- rhn_entitlements.prune_family(customer_id_in, channel_family_id_in,
- quantity, flex);
-
- update rhnPrivateChannelFamily
- set max_members = quantity
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
-
- update rhnPrivateChannelFamily
- set fve_max_members = flex
- where org_id = customer_id_in
- and channel_family_id = channel_family_id_in;
-
- return;
- end loop;
-
- insert into rhnPrivateChannelFamily (
- channel_family_id, org_id, max_members, current_members, fve_max_members, fve_current_members
- ) values (
- channel_family_id_in, customer_id_in, quantity, 0, flex, 0 );
- return;
- end if;
-
- for perm in pubperms loop
- if quantity = 0 then
- rhn_entitlements.prune_family(
- perm.org_id,
- channel_family_id_in,
- quantity,
- flex
- );
- if done = 0 then
- delete from rhnPublicChannelFamily
- where channel_family_id = channel_family_id_in;
- end if;
- end if;
- done := 1;
- end loop;
- -- if done's not 1, then we don't have any entitlements
- if done != 1 then
- insert into rhnPublicChannelFamily (
- channel_family_id
- ) values (
- channel_family_id_in
- );
- end if;
- end set_family_count;
-
- -- this expects quantity_in to be the number of available slots, not the
- -- max_members of the server group. If you give it too many, it'll fail
- -- and raise servergroup_max_members.
- -- We should NEVER run this unless we're SURE that we won't
- -- be violating the max.
- procedure entitle_last_modified_servers (
- customer_id_in in number,
- type_label_in in varchar2,
- quantity_in in number
- ) is
- -- find the servers that aren't currently in slots
- cursor servers(cid_in in number, quant_in in number) is
- select server_id
- from (
- select rownum row_number,
- server_id
- from (
- select rs.id server_iD
- from rhnServer rs
- where 1=1
- and rs.org_id = cid_in
- and not exists (
- select 1
- from rhnServerGroup sg,
- rhnServerGroupMembers rsgm
- where rsgm.server_id = rs.id
- and rsgm.server_group_id = sg.id
- and sg.group_type is not null
- )
- and not exists (
- select 1
- from rhnVirtualInstance vi
- where vi.virtual_system_id =
- rs.id
- ) order by modified desc
- )
- )
- where row_number <= quant_in;
- begin
- for server in servers(customer_id_in, quantity_in) loop
- rhn_entitlements.entitle_server(server.server_id, type_label_in);
- end loop;
- end entitle_last_modified_servers;
-
- procedure subscribe_newest_servers (
- customer_id_in in number
- ) is
- -- find servers without base channels
- cursor servers(cid_in in number) is
- select s.id
- from rhnServer s
- where 1=1
- and s.org_id = cid_in
- and not exists (
- select 1
- from rhnChannel c,
- rhnServerChannel sc
- where sc.server_id = s.id
- and sc.channel_id = c.id
- and c.parent_channel is null
- )
- and not exists (
- select 1
- from rhnVirtualInstance vi
- where vi.virtual_system_id = s.id
- )
- order by s.modified desc;
- channel_id number;
- begin
- for server in servers(customer_id_in) loop
- channel_id := rhn_channel.guess_server_base(server.id);
- if channel_id is not null then
- begin
- rhn_channel.subscribe_server(server.id, channel_id);
- commit;
- -- exception is really channel_family_no_subscriptions
- exception
- when others then
- null;
- end;
- end if;
- end loop;
- end subscribe_newest_servers;
-end rhn_entitlements;
-/
-show errors
-
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql.oracle
new file mode 100644
index 0000000..b1bafb4
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.2-to-spacewalk-schema-1.3/014-rhn_entitlement_pkb.sql.oracle
@@ -0,0 +1,1857 @@
+--
+-- Copyright (c) 2008--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.
+--
+--
+--
+--
+
+create or replace
+package body rhn_entitlements
+is
+ body_version varchar2(100) := '';
+
+ function find_compatible_sg (
+ server_id_in in number,
+ type_label_in in varchar2
+ ) return number is
+
+ cursor servergroups is
+ select sg.id id
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServer s,
+ rhnServerServerGroupArchCompat ssgac
+ where s.id = server_id_in
+ and s.org_id = sg.org_id
+ and sgt.label = type_label_in
+ and sg.group_type = sgt.id
+ and ssgac.server_group_type = sgt.id
+ and ssgac.server_arch_id = s.server_arch_id
+ and not exists (
+ select 1
+ from rhnServerGroupMembers sgm
+ where sgm.server_group_id = sg.id
+ and sgm.server_id = s.id);
+
+
+ begin
+ for servergroup in servergroups loop
+ return servergroup.id;
+ end loop;
+
+ --no servergroup found
+ return null;
+ end find_compatible_sg;
+
+
+ -- *******************************************************************
+ -- PROCEDURE: remove_org_entitlements
+ --
+ -- Removes both system entitlements and channel subscriptions
+ -- that are currently assigned to an org and re-assigns to the
+ -- master org (org_id = 1).
+ --
+ -- When we call this we expect everything to already be unentitled
+ -- which shoul be handled by delete_org.
+ --
+ -- Called by: delete_org
+ -- *******************************************************************
+ procedure remove_org_entitlements(
+ org_id_in in number
+ )
+ is
+
+ cursor system_ents is
+ select sg.id, sg.max_members, sg.group_type
+ from rhnServerGroup sg
+ where group_type is not null
+ and org_id = org_id_in;
+
+ cursor channel_subs is
+ select pcf.channel_family_id, pcf.max_members
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.org_id is null;
+
+ begin
+
+ for system_ent in system_ents loop
+ update rhnServerGroup
+ set max_members = max_members + system_ent.max_members
+ where org_id = 1
+ and group_type = system_ent.group_type;
+ end loop;
+
+ update rhnServerGroup
+ set max_members = 0
+ where org_id = org_id_in;
+
+ for channel_sub in channel_subs loop
+ update rhnPrivateChannelFamily
+ set max_members = max_members + channel_sub.max_members
+ where org_id = 1
+ and channel_family_id = channel_sub.channel_family_id;
+ end loop;
+
+ update rhnPrivateChannelFamily
+ set max_members = 0
+ where org_id = org_id_in;
+
+ end remove_org_entitlements;
+
+ function entitlement_grants_service (
+ entitlement_in in varchar2,
+ service_level_in in varchar2
+ ) return number is
+ begin
+ if service_level_in = 'provisioning' then
+ if entitlement_in = 'provisioning_entitled' then
+ return 1;
+ else
+ return 0;
+ end if;
+ elsif service_level_in = 'management' then
+ if entitlement_in = 'enterprise_entitled' then
+ return 1;
+ else
+ return 0;
+ end if;
+ elsif service_level_in = 'monitoring' then
+ if entitlement_in = 'monitoring_entitled' then
+ return 1;
+ end if;
+ elsif service_level_in = 'updates' then
+ return 1;
+ else
+ return 0;
+ end if;
+ end entitlement_grants_service;
+
+ function lookup_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number is
+ cursor server_groups is
+ select sg.id server_group_id
+ from rhnServerGroup sg,
+ rhnServerGroupType sgt
+ where sgt.label = type_label_in
+ and sgt.id = sg.group_type
+ and sg.org_id = org_id_in;
+ begin
+ for sg in server_groups loop
+ return sg.server_group_id;
+ end loop;
+ return rhn_entitlements.create_entitlement_group(
+ org_id_in,
+ type_label_in
+ );
+ end lookup_entitlement_group;
+
+ function create_entitlement_group (
+ org_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) return number is
+ sg_id_val number;
+ begin
+ select rhn_server_group_id_seq.nextval
+ into sg_id_val
+ from dual;
+
+ insert into rhnServerGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id
+ ) (
+ select sg_id_val, sgt.label, sgt.label,
+ 0, 0, sgt.id, org_id_in
+ from rhnServerGroupType sgt
+ where sgt.label = type_label_in
+ );
+
+ return sg_id_val;
+ end create_entitlement_group;
+
+ function can_entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 )
+ return number is
+ cursor addon_servergroups (base_label_in in varchar2,
+ addon_label_in in varchar2) is
+ select
+ addon_id
+ from
+ rhnSGTypeBaseAddonCompat
+ where base_id = lookup_sg_type (base_label_in)
+ and addon_id = lookup_sg_type (addon_label_in);
+
+ previous_ent rhn_entitlements.ents_array;
+ is_base_in char := 'N';
+ is_base_current char := 'N';
+ i number := 0;
+ sgid number := 0;
+
+ begin
+
+ previous_ent := rhn_entitlements.ents_array();
+ previous_ent := rhn_entitlements.get_server_entitlement(server_id_in);
+
+ select distinct is_base
+ into is_base_in
+ from rhnServerGroupType
+ where label = type_label_in;
+
+ if previous_ent.count = 0 then
+ sgid := find_compatible_sg (server_id_in, type_label_in);
+ if (is_base_in = 'Y' and sgid is not null) then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ else
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+
+ -- there are previous ents, first make sure we're not trying to entitle a base ent
+ elsif is_base_in = 'Y' then
+ -- rhn_exception.raise_exception ('invalid_addon_entitlement');
+ return 0;
+
+ -- it must be an addon, so proceed with the entitlement
+ else
+
+ -- find the servers base ent
+ is_base_current := 'N';
+ i := 0;
+ while is_base_current = 'N' and i <= previous_ent.count
+ loop
+ i := i + 1;
+ select is_base
+ into is_base_current
+ from rhnServerGroupType
+ where label = previous_ent(i);
+ end loop;
+
+ -- never found a base ent, that would be strange
+ if is_base_current = 'N' then
+ -- rhn_exception.raise_exception ('invalid_base_entitlement');
+ return 0;
+ end if;
+
+ -- this for loop verifies the validity of the addon path
+ for addon_servergroup in addon_servergroups (previous_ent(i), type_label_in) loop
+ -- find an appropriate sgid for the addon and entitle the server
+ sgid := find_compatible_sg (server_id_in, type_label_in);
+ if sgid is not null then
+ -- rhn_server.insert_into_servergroup (server_id_in, sgid);
+ return 1;
+ else
+ -- rhn_exception.raise_exception ('invalid_addon_entitlement');
+ return 0;
+ end if;
+ end loop;
+
+ end if;
+
+ return 0;
+
+ end can_entitle_server;
+
+ function can_switch_base (
+ server_id_in in integer,
+ type_label_in in varchar2
+ ) return number is
+
+ type_label_in_is_base char(1);
+ sgid number;
+
+ begin
+
+ begin
+ select is_base into type_label_in_is_base
+ from rhnServerGroupType
+ where label = type_label_in;
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception ( 'invalid_entitlement' );
+ end;
+
+ if type_label_in_is_base = 'N' then
+ rhn_exception.raise_exception ( 'invalid_entitlement' );
+ else
+ sgid := find_compatible_sg ( server_id_in, type_label_in );
+ if sgid is not null then
+ return 1;
+ else
+ return 0;
+ end if;
+ end if;
+
+ end can_switch_base;
+
+
+ procedure entitle_server (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled'
+ ) is
+ sgid number := 0;
+ is_virt number := 0;
+
+ begin
+
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ if is_virt = 0 and (type_label_in = 'virtualization_host' or
+ type_label_in = 'virtualization_host_platform') then
+
+ is_virt := 1;
+ end if;
+
+
+
+ if rhn_entitlements.can_entitle_server(server_id_in,
+ type_label_in) = 1 then
+ sgid := find_compatible_sg (server_id_in, type_label_in);
+ if sgid is not null then
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, server_id_in,
+ 'added system entitlement ',
+ case type_label_in
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platform' end );
+
+ rhn_server.insert_into_servergroup (server_id_in, sgid);
+
+ if is_virt = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ else
+ rhn_exception.raise_exception ('no_available_server_group');
+ end if;
+ else
+ rhn_exception.raise_exception ('invalid_entitlement');
+ end if;
+ end entitle_server;
+
+ procedure remove_server_entitlement (
+ server_id_in in number,
+ type_label_in in varchar2 := 'sw_mgr_entitled',
+ repoll_virt_guests in number := 1
+ ) is
+ group_id number;
+ type_is_base char;
+ is_virt number := 0;
+ begin
+ begin
+
+
+ -- would be nice if there were a virt attribute of entitlement types, not have to specify 2 different ones...
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ select sg.id, sgt.is_base
+ into group_id, type_is_base
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnServer s
+ where s.id = server_id_in
+ and s.id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.org_id = s.org_id
+ and sgt.label = type_label_in
+ and sgt.id = sg.group_type;
+
+ if ( type_is_base = 'Y' ) then
+ -- unentitle_server should handle everything, don't really need to do anything else special here
+ unentitle_server ( server_id_in );
+ else
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, server_id_in,
+ 'removed system entitlement ',
+ case type_label_in
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platforrm' end );
+
+ rhn_server.delete_from_servergroup(server_id_in, group_id);
+
+ -- special case: clean up related monitornig data
+ if type_label_in = 'monitoring_entitled' then
+ DELETE
+ FROM state_change
+ WHERE o_id IN (SELECT probe_id
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ DELETE /*+index(time_series time_series_probe_id_idx)*/
+ FROM time_series
+ WHERE SUBSTR(o_id, INSTR(o_id, '-') + 1,
+ (INSTR(o_id, '-', INSTR(o_id, '-') + 1) - INSTR(o_id, '-')) - 1)
+ IN (SELECT to_char(probe_id)
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ DELETE
+ FROM rhn_probe
+ WHERE recid IN (SELECT probe_id
+ FROM rhn_check_probe
+ WHERE host_id = server_id_in);
+ end if;
+
+ if is_virt = 1 and repoll_virt_guests = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+ end if;
+
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('invalid_server_group_member');
+ end;
+
+ end remove_server_entitlement;
+
+
+ procedure unentitle_server (server_id_in in number) is
+
+ cursor servergroups is
+ select distinct sgt.label, sg.id server_group_id
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServer s,
+ rhnServerGroupMembers sgm
+ where s.id = server_id_in
+ and s.org_id = sg.org_id
+ and sg.group_type = sgt.id
+ and sgm.server_group_id = sg.id
+ and sgm.server_id = s.id;
+
+ is_virt number := 0;
+
+ begin
+
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ for servergroup in servergroups loop
+
+ insert into rhnServerHistory ( id, server_id, summary, details )
+ values ( rhn_event_id_seq.nextval, server_id_in,
+ 'removed system entitlement ',
+ case servergroup.label
+ when 'enterprise_entitled' then 'Management'
+ when 'sw_mgr_entitled' then 'Update'
+ when 'provisioning_entitled' then 'Provisioning'
+ when 'monitoring_entitled' then 'Monitoring'
+ when 'virtualization_host' then 'Virtualization'
+ when 'virtualization_host_platform' then
+ 'Virtualization Platform' end );
+
+ rhn_server.delete_from_servergroup(server_id_in,
+ servergroup.server_group_id );
+ end loop;
+
+ if is_virt = 1 then
+ rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
+ end if;
+
+ end unentitle_server;
+
+
+ -- *******************************************************************
+ -- PROCEDURE: repoll_virt_guest_entitlements
+ --
+ -- Whenever we add/remove a virtualization_host* entitlement from
+ -- a host, we can call this procedure to update what type of slots
+ -- the guests are consuming.
+ --
+ -- If you're removing the entitlement, it's
+ -- possible the guests will become unentitled if you don't have enough
+ -- physical slots to cover them.
+ --
+ -- If you're adding the entitlement, you end up freeing up physical
+ -- slots for other systems.
+ --
+ -- *******************************************************************
+ procedure repoll_virt_guest_entitlements(server_id_in in number)
+ is
+
+ -- All channel families associated with the guests of server_id_in
+ cursor families is
+ select distinct cfs.channel_family_id
+ from
+ rhnChannelFamilyServers cfs,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = cfs.server_id;
+
+ -- All of server group types associated with the guests of
+ -- server_id_in
+ cursor group_types is
+ select distinct sg.group_type, sgt.label
+ from
+ rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id;
+
+ -- Virtual servers from a certain family belonging to a speicifc
+ -- host that are consuming physical channel slots over the limit.
+ cursor virt_servers_cfam(family_id_in in number, quantity_in in number) is
+ select virtual_system_id
+ from (
+ select rownum, vi.virtual_system_id
+ from
+ rhnChannelFamilyMembers cfm,
+ rhnServerChannel sc,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sc.server_id
+ and sc.channel_id = cfm.channel_id
+ and cfm.channel_family_id = family_id_in
+ order by sc.modified desc
+ )
+ where rownum <= quantity_in;
+
+ -- Virtual servers from a certain family belonging to a speicifc
+ -- host that are consuming physical system slots over the limit.
+ cursor virt_servers_sgt(group_type_in in number, quantity_in in number) is
+ select virtual_system_id
+ from (
+ select rownum, vi.virtual_system_id
+ from
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm,
+ rhnVirtualInstance vi
+ where
+ vi.host_system_id = server_id_in
+ and vi.virtual_system_id = sgm.server_id
+ and sgm.server_group_id = sg.id
+ and sg.group_type = group_type_in
+ order by sgm.modified desc
+ )
+ where rownum <= quantity_in;
+ -- Get the orgs of Virtual guests
+ -- Since they may belong to different orgs
+ cursor virt_guest_orgs is
+ select distinct (s.org_id)
+ from rhnServer s
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = s.id
+ where
+ vi.host_system_id = server_id_in
+ and s.org_id <> (select s1.org_id from rhnServer s1 where s1.id = vi.host_system_id) ;
+
+
+ org_id_val number;
+ max_members_val number;
+ max_flex_val number;
+ current_members_calc number;
+ sg_id number;
+ is_virt number := 0;
+ begin
+ begin
+ select 1 into is_virt
+ from rhnServerEntitlementView
+ where server_id = server_id_in
+ and label in ('virtualization_host', 'virtualization_host_platform');
+ exception
+ when no_data_found then
+ is_virt := 0;
+ end;
+
+ select org_id
+ into org_id_val
+ from rhnServer
+ where id = server_id_in;
+
+ -- deal w/ channel entitlements first ...
+ for family in families loop
+ if is_virt = 0 then
+ -- if the host_server does not have virt
+ --- find all possible flex slots
+ -- and set each of the flex eligible guests to Y
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id in (
+ select virtual_system_id from (
+ select rownum, vi.virtual_system_id, sfc.max_members - sfc.current_members as free_slots
+ from rhnServerFveCapable sfc
+ inner join rhnVirtualInstance vi on vi.virtual_system_id = sfc.server_id
+ where vi.host_system_id = server_id_in
+ and sfc.channel_family_id = family.channel_family_id
+ order by vi.modified desc
+ )
+ where rownum <= free_slots
+ );
+ else
+ -- if the host_server has virt
+ -- set all its flex guests to N
+ UPDATE rhnServerChannel sc set sc.is_fve = 'N'
+ where
+ sc.channel_id in (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = family.channel_family_id)
+ and sc.is_fve = 'Y'
+ and sc.server_id in
+ (select vi.virtual_system_id from rhnVirtualInstance vi
+ where vi.host_system_id = server_id_in);
+ end if;
+
+ -- get the current (physical) members of the family
+ current_members_calc :=
+ rhn_channel.channel_family_current_members(family.channel_family_id,
+ org_id_val); -- fixed transposed args
+
+ -- get the max members of the family
+ select max_members
+ into max_members_val
+ from rhnPrivateChannelFamily
+ where channel_family_id = family.channel_family_id
+ and org_id = org_id_val;
+
+ select fve_max_members
+ into max_flex_val
+ from rhnPrivateChannelFamily
+ where channel_family_id = family.channel_family_id
+ and org_id = org_id_val;
+
+ if current_members_calc > max_members_val then
+ -- A virtualization_host* ent must have been removed, so we'll
+ -- unsubscribe guests from the host first.
+
+ -- hm, i don't think max_members - current_members_calc yielding a negative number
+ -- will work w/ rownum, swaping 'em in the body of this if...
+ for virt_server in virt_servers_cfam(family.channel_family_id,
+ current_members_calc - max_members_val) loop
+
+ rhn_channel.unsubscribe_server_from_family(
+ virt_server.virtual_system_id,
+ family.channel_family_id);
+ end loop;
+
+ -- if we're still over the limit, which would be odd,
+ -- just prune the group to max_members
+ --
+ -- er... wouldn't we actually have to refresh the values of
+ -- current_members_calc and max_members_val to actually ever
+ -- *skip this??
+ if current_members_calc > max_members_val then
+ -- argh, transposed again?!
+ set_family_count(org_id_val,
+ family.channel_family_id,
+ max_members_val, max_flex_val);
+ --TODO calculate this correctly
+ end if;
+
+ end if;
+
+ -- update current_members for the family. This will set the value
+ -- to reflect adding/removing the entitlement.
+ --
+ -- what's the difference of doing this vs the unavoidable set_family_count above?
+ rhn_channel.update_family_counts(family.channel_family_id,
+ org_id_val);
+
+ -- It is possible that the guests belong to a different org than the host
+ -- so we are going to update the family counts in the guests orgs also
+ for org in virt_guest_orgs loop
+ rhn_channel.update_family_counts(family.channel_family_id,
+ org.org_id);
+ end loop;
+ end loop;
+
+ for a_group_type in group_types loop
+ -- get the current *physical* members of the system entitlement type for the org...
+ --
+ -- unlike channel families, it appears the standard rhnServerGroup.max_members represents
+ -- *physical* slots, vs physical+virt ... boy that's confusing...
+
+ select max_members, id
+ into max_members_val, sg_id
+ from rhnServerGroup
+ where group_type = a_group_type.group_type
+ and org_id = org_id_val;
+
+
+ select count(sep.server_id) into current_members_calc
+ from rhnServerEntitlementPhysical sep
+ where sep.server_group_id = sg_id
+ and sep.server_group_type_id = a_group_type.group_type;
+
+ if current_members_calc > max_members_val then
+ -- A virtualization_host* ent must have been removed, and we're over the limit, so unsubscribe guests
+ for virt_server in virt_servers_sgt(a_group_type.group_type,
+ current_members_calc - max_members_val) loop
+ rhn_entitlements.remove_server_entitlement(virt_server.virtual_system_id, a_group_type.label);
+
+ -- decrement current_members_calc, we'll use it to reset current_members for the group at the end...
+ current_members_calc := current_members_calc - 1;
+ end loop;
+
+ end if;
+
+ update rhnServerGroup set current_members = current_members_calc
+ where org_id = org_id_val
+ and group_type = a_group_type.group_type;
+
+ -- I think that's all the house-keeping we have to do...
+ end loop;
+
+ end repoll_virt_guest_entitlements;
+
+
+ function get_server_entitlement (
+ server_id_in in number
+ ) return ents_array is
+
+ cursor server_groups is
+ select sgt.label
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm
+ where 1=1
+ and sgm.server_id = server_id_in
+ and sg.id = sgm.server_group_id
+ and sgt.id = sg.group_type
+ and sgt.label in (
+ 'sw_mgr_entitled','enterprise_entitled',
+ 'provisioning_entitled', 'nonlinux_entitled',
+ 'monitoring_entitled', 'virtualization_host',
+ 'virtualization_host_platform'
+ );
+
+ ent_array ents_array;
+
+ begin
+
+ ent_array := ents_array();
+
+ for sg in server_groups loop
+ ent_array.extend;
+ ent_array(ent_array.count) := sg.label;
+ end loop;
+
+ return ent_array;
+
+ end get_server_entitlement;
+
+
+ -- this desperately needs to be table driven.
+ procedure modify_org_service (
+ org_id_in in number,
+ service_label_in in varchar2,
+ enable_in in char
+ ) is
+ type roles_v is varray(10) of rhnUserGroupType.label%TYPE;
+ roles_to_process roles_v;
+ cursor roles(role_label_in in varchar2) is
+ select label, id
+ from rhnUserGroupType
+ where label = role_label_in;
+ cursor org_roles(role_label_in in varchar2) is
+ select 1
+ from rhnUserGroup ug,
+ rhnUserGroupType ugt
+ where ugt.label = role_label_in
+ and ug.org_id = org_id_in
+ and ugt.id = ug.group_type;
+
+ type ents_v is varray(10) of rhnOrgEntitlementType.label%TYPE;
+ ents_to_process ents_v;
+ cursor ents(ent_label_in in varchar2) is
+ select label, id
+ from rhnOrgEntitlementType
+ where label = ent_label_in;
+ cursor org_ents(ent_label_in in varchar2) is
+ select 1
+ from rhnOrgEntitlements oe,
+ rhnOrgEntitlementType oet
+ where oet.label = ent_label_in
+ and oe.org_id = org_id_in
+ and oet.id = oe.entitlement_id;
+ create_row char(1);
+ begin
+ ents_to_process := ents_v();
+ roles_to_process := roles_v();
+ -- a bit kludgy, but only for 3.4 really. Certainly no
+ -- worse than the old code...
+ if service_label_in = 'enterprise' or
+ service_label_in = 'management' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'org_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'system_group_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'activation_key_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'org_applicant';
+ elsif service_label_in = 'provisioning' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_provisioning';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'system_group_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'activation_key_admin';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ -- another nasty special case...
+ if enable_in = 'Y' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'sw_mgr_enterprise';
+ end if;
+ elsif service_label_in = 'monitoring' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_monitor';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'monitoring_admin';
+ elsif service_label_in = 'virtualization' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_virtualization';
+
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ elsif service_label_in = 'virtualization_platform' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_virtualization_platform';
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ elsif service_label_in = 'nonlinux' then
+ ents_to_process.extend;
+ ents_to_process(ents_to_process.count) := 'rhn_nonlinux';
+ roles_to_process.extend;
+ roles_to_process(roles_to_process.count) := 'config_admin';
+ end if;
+
+ if enable_in = 'Y' then
+ for i in 1..ents_to_process.count loop
+ for ent in ents(ents_to_process(i)) loop
+ create_row := 'Y';
+ for oe in org_ents(ent.label) loop
+ create_row := 'N';
+ end loop;
+ if create_row = 'Y' then
+ insert into rhnOrgEntitlements(org_id, entitlement_id)
+ values (org_id_in, ent.id);
+ end if;
+ end loop;
+ end loop;
+ for i in 1..roles_to_process.count loop
+ for role in roles(roles_to_process(i)) loop
+ create_row := 'Y';
+ for o_r in org_roles(role.label) loop
+ create_row := 'N';
+ end loop;
+ if create_row = 'Y' then
+ insert into rhnUserGroup(
+ id, name, description, current_members,
+ group_type, org_id
+ ) (
+ select rhn_user_group_id_seq.nextval,
+ ugt.name || 's',
+ ugt.name || 's for Org ' ||
+ o.name || ' ('|| o.id ||')',
+ 0, ugt.id, o.id
+ from rhnUserGroupType ugt,
+ web_customer o
+ where o.id = org_id_in
+ and ugt.id = role.id
+ );
+ end if;
+ end loop;
+ end loop;
+ else
+ for i in 1..ents_to_process.count loop
+ for ent in ents(ents_to_process(i)) loop
+ delete from rhnOrgEntitlements
+ where org_id = org_id_in
+ and entitlement_id = ent.id;
+ end loop;
+ end loop;
+ end if;
+ end modify_org_service;
+
+ procedure set_customer_enterprise (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'enterprise', 'Y');
+ end set_customer_enterprise;
+
+ procedure set_customer_provisioning (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'provisioning', 'Y');
+ end set_customer_provisioning;
+
+ procedure set_customer_monitoring (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'monitoring', 'Y');
+ end set_customer_monitoring;
+
+ procedure set_customer_nonlinux (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'nonlinux', 'Y');
+ end set_customer_nonlinux;
+
+ procedure unset_customer_enterprise (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'enterprise', 'N');
+ end unset_customer_enterprise;
+
+ procedure unset_customer_provisioning (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'provisioning', 'N');
+ end unset_customer_provisioning;
+
+ procedure unset_customer_monitoring (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'monitoring', 'N');
+ end unset_customer_monitoring;
+
+ procedure unset_customer_nonlinux (
+ customer_id_in in number
+ ) is
+ begin
+ modify_org_service(customer_id_in, 'nonlinux', 'N');
+ end unset_customer_nonlinux;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_group
+ -- Unsubscribes servers consuming physical slots that over the org's
+ -- limit.
+ -- Called by: set_group_count, repoll_virt_guest_entitlements
+ -- *******************************************************************
+ procedure prune_group (
+ group_id_in in number,
+ type_in in char,
+ quantity_in in number,
+ update_family_countsYN in number := 1
+ ) is
+ cursor usergroups is
+ select user_id, user_group_id, ugt.label
+ from rhnUserGroupType ugt,
+ rhnUserGroup ug,
+ rhnUserGroupMembers ugm
+ where 1=1
+ and ugm.user_group_id = group_id_in
+ and ugm.user_id in (
+ select user_id
+ from (
+ select rownum row_number,
+ user_id,
+ time
+ from (
+ select user_id,
+ modified time
+ from rhnUserGroupMembers
+ where user_group_id = group_id_in
+ order by time asc
+ )
+ )
+ where row_number > quantity_in
+ )
+ and ugm.user_group_id = ug.id
+ and ug.group_type = ugt.id;
+ cursor servergroups is
+ select server_id, server_group_id, sgt.id as group_type_id, sgt.label
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg,
+ rhnServerGroupMembers sgm
+ where 1=1
+ and sgm.server_group_id = group_id_in
+ and sgm.server_id in (
+ select server_id
+ from (
+ select rownum row_number,
+ server_id,
+ time
+ from (
+ select sep.server_id,
+ sep.modified time
+ from
+ rhnServerEntitlementPhysical sep
+ where
+ sep.server_group_id = group_id_in
+ order by time asc
+ )
+ )
+ where row_number > quantity_in
+ )
+ and sgm.server_group_id = sg.id
+ and sg.group_type = sgt.id;
+ type_is_base char;
+ begin
+ if type_in = 'U' then
+ update rhnUserGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for ug in usergroups loop
+ rhn_user.remove_from_usergroup(ug.user_id, ug.user_group_id);
+ end loop;
+ elsif type_in = 'S' then
+ update rhnServerGroup
+ set max_members = quantity_in
+ where id = group_id_in;
+
+ for sg in servergroups loop
+ remove_server_entitlement(sg.server_id, sg.label);
+
+ select is_base
+ into type_is_base
+ from rhnServerGroupType sgt
+ where sgt.id = sg.group_type_id;
+
+ -- if we're removing a base ent, then be sure to
+ -- remove the server's channel subscriptions.
+ if ( type_is_base = 'Y' ) then
+ rhn_channel.clear_subscriptions(sg.server_id,
+ update_family_countsYN => update_family_countsYN);
+ end if;
+
+ end loop;
+ end if;
+ end prune_group;
+
+ -- *******************************************************************
+ -- PROCEDURE: assign_system_entitlement
+ --
+ -- Moves system entitlements from from_org_id_in to to_org_id_in.
+ -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
+ -- does not have enough entitlements to cover the move.
+ -- Takes care of unentitling systems if necessary by calling
+ -- set_group_count
+ -- *******************************************************************
+ procedure assign_system_entitlement(
+ group_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ to_org_prev_ent_count number;
+ new_ent_count number;
+ new_quantity number;
+ group_type number;
+ begin
+
+ begin
+ select max_members
+ into prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.org_id = from_org_id_in
+ and sg.group_type = sgt.id
+ and sgt.label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end;
+
+ begin
+ select max_members
+ into to_org_prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.org_id = to_org_id_in
+ and sg.group_type = sgt.id
+ and sgt.label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end;
+
+ new_ent_count := prev_ent_count - quantity_in;
+
+ if prev_ent_count > new_ent_count then
+ new_quantity := to_org_prev_ent_count + quantity_in;
+ end if;
+
+ if new_ent_count < 0 then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+
+ rhn_entitlements.set_group_count(from_org_id_in,
+ 'S',
+ group_type,
+ new_ent_count);
+
+ rhn_entitlements.set_group_count(to_org_id_in,
+ 'S',
+ group_type,
+ new_quantity);
+
+ -- Create or delete the entries in rhnOrgEntitlementType
+ if group_label_in = 'enterprise_entitled' then
+ if new_quantity > 0 then
+ set_customer_enterprise(to_org_id_in);
+ else
+ unset_customer_enterprise(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'provisioning_entitled' then
+ if new_quantity > 0 then
+ set_customer_provisioning(to_org_id_in);
+ else
+ unset_customer_provisioning(to_org_id_in);
+ end if;
+ end if;
+
+ if group_label_in = 'monitoring_entitled' then
+ if new_quantity > 0 then
+ set_customer_monitoring(to_org_id_in);
+ else
+ unset_customer_monitoring(to_org_id_in);
+ end if;
+ end if;
+
+ end assign_system_entitlement;
+
+ -- *******************************************************************
+ -- PROCEDURE: assign_channel_entitlement
+ --
+ -- Moves channel entitlements from from_org_id_in to to_org_id_in.
+ -- Can raise not_enough_entitlements_in_base_org if from_org_id_in
+ -- does not have enough entitlements to cover the move.
+ -- Takes care of unentitling systems if necessary by calling
+ -- set_family_count
+ -- *******************************************************************
+ procedure assign_channel_entitlement(
+ channel_family_label_in in varchar2,
+ from_org_id_in in number,
+ to_org_id_in in number,
+ quantity_in in number,
+ flex_in in number
+ )
+ is
+ from_org_prev_ent_count number;
+ from_org_prev_ent_count_flex number;
+ new_ent_count number;
+ new_ent_count_flex number;
+ to_org_prev_ent_count number;
+ to_org_prev_ent_count_flex number;
+ new_quantity number;
+ new_flex number;
+ cfam_id number;
+ begin
+
+ begin
+ select max_members
+ into from_org_prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = from_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end;
+
+ begin
+ select max_members
+ into to_org_prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = to_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count := 0;
+ end;
+
+ begin
+ select fve_max_members
+ into from_org_prev_ent_count_flex
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = from_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end;
+
+ begin
+ select fve_max_members
+ into to_org_prev_ent_count_flex
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = to_org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ to_org_prev_ent_count_flex := 0;
+ end;
+
+ begin
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end;
+
+ new_ent_count := from_org_prev_ent_count - quantity_in;
+ new_ent_count_flex := from_org_prev_ent_count_flex - flex_in;
+
+ if from_org_prev_ent_count >= new_ent_count then
+ new_quantity := to_org_prev_ent_count + quantity_in;
+ end if;
+
+ if from_org_prev_ent_count_flex >= new_ent_count_flex then
+ new_flex := to_org_prev_ent_count_flex + flex_in;
+ end if;
+
+
+ if new_ent_count < 0 then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ end if;
+
+ if new_ent_count_flex < 0 then
+ rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+
+
+
+ rhn_entitlements.set_family_count(from_org_id_in, cfam_id,
+ new_ent_count, new_ent_count_flex);
+
+ rhn_entitlements.set_family_count(to_org_id_in,
+ cfam_id,
+ new_quantity, new_flex);
+
+ end assign_channel_entitlement;
+
+ -- *******************************************************************
+ -- PROCEDURE: activate_system_entitlement
+ --
+ -- Sets the values in rhnServerGroup for a given rhnServerGroupType.
+ --
+ -- Calls: set_group_count to update, prune, or create the group.
+ -- Called by: the code that activates a satellite cert.
+ --
+ -- Raises not_enough_entitlements_in_base_org if all entitlements
+ -- in the org are used so the free entitlements would not cover
+ -- the difference when descreasing the number of entitlements.
+ -- *******************************************************************
+ procedure activate_system_entitlement(
+ org_id_in in number,
+ group_label_in in varchar2,
+ quantity_in in number
+ )
+ is
+ prev_ent_count number;
+ prev_ent_count_sum number;
+ group_type number;
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ begin
+ select current_members
+ into prev_ent_count
+ from rhnServerGroupType sgt,
+ rhnServerGroup sg
+ where sg.group_type = sgt.id
+ and sgt.label = group_label_in
+ and sg.org_id = org_id_in;
+ exception
+ when NO_DATA_FOUND then
+ prev_ent_count := 0;
+ end;
+
+ begin
+ select id
+ into group_type
+ from rhnServerGroupType
+ where label = group_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_server_group');
+ end;
+
+ -- If we're setting the total entitlemnt count to a lower value,
+ -- and that value is less than the allocated count in this org,
+ -- we need to raise an exception.
+ if quantity_in < prev_ent_count then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- don't update family counts after every server
+ -- will do bulk update afterwards
+ rhn_entitlements.set_group_count(org_id_in,
+ 'S',
+ group_type,
+ quantity_in,
+ update_family_countsYN => 0);
+ -- bulk update family counts
+ rhn_channel.update_group_family_counts(group_label_in, org_id_in);
+ end if;
+
+
+ end activate_system_entitlement;
+
+ -- *******************************************************************
+ -- PROCEDURE: activate_channel_entitlement
+ --
+ -- Calls: set_family_count to update, prune, or create the family
+ -- permission bucket.
+ -- Called by: the code that activates a satellite cert.
+ --
+ -- Raises not_enough_entitlements_in_base_org if there are not enough
+ -- entitlements in the org to cover the difference when you are
+ -- descreasing the number of entitlements.
+ --
+ -- The backend code in Python is expected to do whatever arithmetics
+ -- is needed.
+ -- *******************************************************************
+ procedure activate_channel_entitlement(
+ org_id_in in number,
+ channel_family_label_in in varchar2,
+ quantity_in in number,
+ flex_in in number
+
+ )
+ is
+ prev_ent_count number;
+ prev_flex_count number;
+ prev_ent_count_sum number;
+ cfam_id number;
+ reduce_quantity number;
+ total_flex_capable number;
+ cursor to_convert_reg (channel_family_id_val in number, org_id_in in number, quantity in number)
+ is
+ select SC.server_id
+ from rhnServerChannel SC inner join
+ rhnServer S on S.id = SC.server_id
+ where
+ is_fve = 'Y'
+ and S.org_id = org_id_in
+ and SC.channel_id in
+ (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = channel_family_id_val)
+ and rownum <= quantity;
+ cursor to_convert_flex (channel_family_id_val in number, org_id_in in number, quantity in number)
+ is
+ select server_id
+ from rhnServerFveCapable
+ where SERVER_ORG_ID = org_id_in and
+ channel_family_id = cfam_id and
+ rownum <= quantity;
+
+ begin
+
+ -- Fetch the current entitlement count for the org
+ -- into prev_ent_count
+ begin
+ select current_members
+ into prev_ent_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ prev_ent_count := 0;
+ end;
+
+ begin
+ select pcf.fve_current_members
+ into prev_flex_count
+ from rhnChannelFamily cf,
+ rhnPrivateChannelFamily pcf
+ where pcf.org_id = org_id_in
+ and pcf.channel_family_id = cf.id
+ and cf.label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ prev_flex_count := 0;
+ end;
+
+
+ begin
+ select id
+ into cfam_id
+ from rhnChannelFamily
+ where label = channel_family_label_in;
+ exception
+ when NO_DATA_FOUND then
+ rhn_exception.raise_exception(
+ 'invalid_channel_family');
+ end;
+
+ -- if there are too few flex entitlements
+ if flex_in < prev_flex_count then
+ -- and if the extra we need is less than or equal to our extra regular entitlements
+ if prev_flex_count - flex_in <= quantity_in - prev_ent_count then
+ reduce_quantity := prev_flex_count - flex_in;
+ -- We need to convert some systems from flex guest to regular
+ for system in to_convert_reg(cfam_id, org_id_in, reduce_quantity) loop
+ --rhn_channel.convert_to_regular(system.server_id, cfam_id);
+ UPDATE rhnServerChannel sc set sc.is_fve = 'N'
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
+ end loop;
+
+ --reset previous counts
+ prev_ent_count := prev_ent_count + reduce_quantity;
+ prev_flex_count := prev_flex_count - reduce_quantity;
+ else
+ rhn_exception.raise_exception(
+ 'not_enough_flex_entitlements_in_base_org');
+ end if;
+ end if;
+
+ -- if there are too few regular entitlements, and extra flex entitlements
+ if quantity_in < prev_ent_count and prev_flex_count < flex_in then
+ -- how many flex-capable systems (that aren't using flex) do we have
+ select count(*)
+ into total_flex_capable
+ from rhnServerFveCapable
+ where SERVER_ORG_ID = org_id_in and
+ channel_family_id = cfam_id;
+ -- if we have enough flex capable machines that is at least
+ -- as many as what we are over on
+ if total_flex_capable >= prev_ent_count - quantity_in then
+ reduce_quantity := prev_ent_count - quantity_in;
+ for system in to_convert_flex(cfam_id, org_id_in, reduce_quantity) loop
+-- rhn_channel.convert_to_fve(system.server_id, cfam_id);
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id = system.server_id
+ and sc.channel_id in (select cfm.channel_id
+ from rhnChannelFamilyMembers cfm
+ where cfm.channel_family_id = cfam_id);
+ end loop;
+ prev_ent_count := prev_ent_count - reduce_quantity;
+ prev_flex_count := prev_flex_count + reduce_quantity;
+ end if;
+ end if;
+
+
+
+
+ -- If we're setting the total entitlemnt count to a lower value,
+ -- and that value is less than the count in that one org,
+ -- we need to raise an exception.
+ if quantity_in < prev_ent_count then
+ rhn_exception.raise_exception(
+ 'not_enough_entitlements_in_base_org');
+ else
+ -- even if we've manually converted systems to/from flex above
+ -- set_family_count should call update_family_counts, to reset
+ -- current used slots
+ rhn_entitlements.set_family_count(org_id_in, cfam_id,
+ quantity_in, flex_in);
+ end if;
+
+ end activate_channel_entitlement;
+
+
+ procedure set_group_count (
+ customer_id_in in number,
+ type_in in char,
+ group_type_in in number,
+ quantity_in in number,
+ update_family_countsYN in number := 1
+ ) is
+ group_id number;
+ quantity number;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+
+ if type_in = 'U' then
+ select rug.id
+ into group_id
+ from rhnUserGroup rug
+ where 1=1
+ and rug.org_id = customer_id_in
+ and rug.group_type = group_type_in;
+ elsif type_in = 'S' then
+ select rsg.id
+ into group_id
+ from rhnServerGroup rsg
+ where 1=1
+ and rsg.org_id = customer_id_in
+ and rsg.group_type = group_type_in;
+ end if;
+
+ rhn_entitlements.prune_group(
+ group_id,
+ type_in,
+ quantity,
+ update_family_countsYN
+ );
+ exception
+ when no_data_found then
+ if type_in = 'U' then
+ insert into rhnUserGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id, created, modified
+ ) (
+ select rhn_user_group_id_seq.nextval, name, name,
+ quantity, 0, id, customer_id_in,
+ sysdate, sysdate
+ from rhnUserGroupType
+ where id = group_type_in
+ );
+ elsif type_in = 'S' then
+ insert into rhnServerGroup (
+ id, name, description, max_members, current_members,
+ group_type, org_id, created, modified
+ ) (
+ select rhn_server_group_id_seq.nextval, name, name,
+ quantity, 0, id, customer_id_in,
+ sysdate, sysdate
+ from rhnServerGroupType
+ where id = group_type_in
+ );
+ end if;
+ end set_group_count;
+
+ -- *******************************************************************
+ -- PROCEDURE: prune_family
+ -- Unsubscribes servers consuming physical slots from the channel family
+ -- that are over the org's limit.
+ -- Called by: set_family_count
+ -- *******************************************************************
+ procedure prune_family (
+ customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number,
+ flex_in in number
+ ) is
+ is_fve_in char;
+ tmp_quantity number;
+
+ cursor serverchannels is
+ select sc.server_id,
+ sc.channel_id
+ from rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm
+ where 1=1
+ and cfm.channel_family_id = channel_family_id_in
+ and cfm.channel_id = sc.channel_id
+ and server_id in (
+ select server_id
+ from (
+ select server_id, time, rownum row_number
+ from (
+ select rs.id server_id, rcfm.modified time
+ from rhnServerChannel rsc,
+ rhnChannelFamilyMembers rcfm,
+ rhnServer rs
+ where 1=1
+ and rs.org_id = customer_id_in
+ and rs.id = rsc.server_id
+ and rsc.channel_id = rcfm.channel_id
+ and rcfm.channel_family_id = channel_family_id_in
+ and rsc.is_fve = is_fve_in
+ -- we only want to grab servers consuming
+ -- physical slots.
+ and exists (
+ select 1
+ from rhnChannelFamilyServerPhysical cfsp
+ where cfsp.server_id = rs.id
+ and cfsp.channel_family_id =
+ channel_family_id_in
+ )
+ order by time asc
+ )
+ )
+ where row_number > tmp_quantity
+ );
+ begin
+ -- if we get a null customer_id, this is completely bogus.
+ if customer_id_in is null then
+ return;
+ end if;
+
+ tmp_quantity := quantity_in;
+ is_fve_in := 'N';
+
+ for sc in serverchannels loop
+ rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
+ update_family_countsYN => 0);
+
+ tmp_quantity := flex_in;
+ is_fve_in := 'Y';
+ for sc in serverchannels loop
+ rhn_channel.unsubscribe_server(sc.server_id, sc.channel_id, 1, 1,
+ update_family_countsYN => 0);
+ end loop;
+
+
+
+ end loop;
+ rhn_channel.update_family_counts(channel_family_id_in, customer_id_in);
+ end prune_family;
+
+ procedure set_family_count (
+ customer_id_in in number,
+ channel_family_id_in in number,
+ quantity_in in number,
+ flex_in in number
+ ) is
+ cursor privperms is
+ select 1
+ from rhnPrivateChannelFamily
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+ cursor pubperms is
+ select o.id org_id
+ from web_customer o,
+ rhnPublicChannelFamily pcf
+ where pcf.channel_family_id = channel_family_id_in;
+ quantity number;
+ done number := 0;
+ flex number;
+ begin
+ quantity := quantity_in;
+ if quantity is not null and quantity < 0 then
+ quantity := 0;
+ end if;
+ flex := flex_in;
+ if flex is not null and flex < 0 then
+ flex := 0;
+ end if;
+
+
+ if customer_id_in is not null then
+ for perm in privperms loop
+ rhn_entitlements.prune_family(customer_id_in, channel_family_id_in,
+ quantity, flex);
+
+ update rhnPrivateChannelFamily
+ set max_members = quantity
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+
+ update rhnPrivateChannelFamily
+ set fve_max_members = flex
+ where org_id = customer_id_in
+ and channel_family_id = channel_family_id_in;
+
+ return;
+ end loop;
+
+ insert into rhnPrivateChannelFamily (
+ channel_family_id, org_id, max_members, current_members, fve_max_members, fve_current_members
+ ) values (
+ channel_family_id_in, customer_id_in, quantity, 0, flex, 0 );
+ return;
+ end if;
+
+ for perm in pubperms loop
+ if quantity = 0 then
+ rhn_entitlements.prune_family(
+ perm.org_id,
+ channel_family_id_in,
+ quantity,
+ flex
+ );
+ if done = 0 then
+ delete from rhnPublicChannelFamily
+ where channel_family_id = channel_family_id_in;
+ end if;
+ end if;
+ done := 1;
+ end loop;
+ -- if done's not 1, then we don't have any entitlements
+ if done != 1 then
+ insert into rhnPublicChannelFamily (
+ channel_family_id
+ ) values (
+ channel_family_id_in
+ );
+ end if;
+ end set_family_count;
+
+ -- this expects quantity_in to be the number of available slots, not the
+ -- max_members of the server group. If you give it too many, it'll fail
+ -- and raise servergroup_max_members.
+ -- We should NEVER run this unless we're SURE that we won't
+ -- be violating the max.
+ procedure entitle_last_modified_servers (
+ customer_id_in in number,
+ type_label_in in varchar2,
+ quantity_in in number
+ ) is
+ -- find the servers that aren't currently in slots
+ cursor servers(cid_in in number, quant_in in number) is
+ select server_id
+ from (
+ select rownum row_number,
+ server_id
+ from (
+ select rs.id server_iD
+ from rhnServer rs
+ where 1=1
+ and rs.org_id = cid_in
+ and not exists (
+ select 1
+ from rhnServerGroup sg,
+ rhnServerGroupMembers rsgm
+ where rsgm.server_id = rs.id
+ and rsgm.server_group_id = sg.id
+ and sg.group_type is not null
+ )
+ and not exists (
+ select 1
+ from rhnVirtualInstance vi
+ where vi.virtual_system_id =
+ rs.id
+ ) order by modified desc
+ )
+ )
+ where row_number <= quant_in;
+ begin
+ for server in servers(customer_id_in, quantity_in) loop
+ rhn_entitlements.entitle_server(server.server_id, type_label_in);
+ end loop;
+ end entitle_last_modified_servers;
+
+ procedure subscribe_newest_servers (
+ customer_id_in in number
+ ) is
+ -- find servers without base channels
+ cursor servers(cid_in in number) is
+ select s.id
+ from rhnServer s
+ where 1=1
+ and s.org_id = cid_in
+ and not exists (
+ select 1
+ from rhnChannel c,
+ rhnServerChannel sc
+ where sc.server_id = s.id
+ and sc.channel_id = c.id
+ and c.parent_channel is null
+ )
+ and not exists (
+ select 1
+ from rhnVirtualInstance vi
+ where vi.virtual_system_id = s.id
+ )
+ order by s.modified desc;
+ channel_id number;
+ begin
+ for server in servers(customer_id_in) loop
+ channel_id := rhn_channel.guess_server_base(server.id);
+ if channel_id is not null then
+ begin
+ rhn_channel.subscribe_server(server.id, channel_id);
+ commit;
+ -- exception is really channel_family_no_subscriptions
+ exception
+ when others then
+ null;
+ end;
+ end if;
+ end loop;
+ end subscribe_newest_servers;
+end rhn_entitlements;
+/
+show errors
+
13 years, 3 months
rel-eng/comps
by Tomas Lestach
rel-eng/comps/comps-spacewalk-server-rhel6.xml | 2 --
1 file changed, 2 deletions(-)
New commits:
commit 5670c16edbc902445f746c8895699c5eb8be32f6
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Fri Jan 21 13:01:04 2011 +0100
removing relaxngDatatype* from rhel6 server comps
diff --git a/rel-eng/comps/comps-spacewalk-server-rhel6.xml b/rel-eng/comps/comps-spacewalk-server-rhel6.xml
index b6e1dc1..3acb80a 100644
--- a/rel-eng/comps/comps-spacewalk-server-rhel6.xml
+++ b/rel-eng/comps/comps-spacewalk-server-rhel6.xml
@@ -51,7 +51,6 @@
<packagereq type="default">quartz</packagereq>
<packagereq type="default">quartz-oracle</packagereq>
<packagereq type="default">redstone-xmlrpc</packagereq>
- <packagereq type="default">relaxngDatatype</packagereq>
<packagereq type="default">rhnpush</packagereq>
<packagereq type="default">SatConfig-bootstrap</packagereq>
<packagereq type="default">SatConfig-bootstrap-server</packagereq>
@@ -144,7 +143,6 @@
<uservisible>false</uservisible>
<packagelist>
<packagereq type="optional">jpam-javadoc</packagereq>
- <packagereq type="optional">relaxngDatatype-javadoc</packagereq>
<packagereq type="optional">tanukiwrapper-javadoc</packagereq>
</packagelist>
</group>
13 years, 3 months
rel-eng/comps
by Tomas Lestach
rel-eng/comps/comps-spacewalk-server-fedora13.xml | 22 +++++++++++++++++++---
rel-eng/comps/comps-spacewalk-server-fedora14.xml | 22 +++++++++++++++++++---
rel-eng/comps/comps-spacewalk-server-rhel5.xml | 12 +++++-------
rel-eng/comps/comps-spacewalk-server-rhel6.xml | 18 +++++++++++++-----
4 files changed, 56 insertions(+), 18 deletions(-)
New commits:
commit f47df4fb4657f375320122a795681decde5ed830
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Fri Jan 21 11:55:39 2011 +0100
aligning server comps to have spacewalk-server-docs and spacewalk-server-no-install group
diff --git a/rel-eng/comps/comps-spacewalk-server-fedora13.xml b/rel-eng/comps/comps-spacewalk-server-fedora13.xml
index e02b648..345dcfe 100644
--- a/rel-eng/comps/comps-spacewalk-server-fedora13.xml
+++ b/rel-eng/comps/comps-spacewalk-server-fedora13.xml
@@ -15,7 +15,6 @@
<packagereq type="default">eventReceivers</packagereq>
<packagereq type="default">heirloom-pkgtools</packagereq>
<packagereq type="default">jpam</packagereq>
- <packagereq type="default">jpam-javadoc</packagereq>
<packagereq type="default">MessageQueue</packagereq>
<packagereq type="default">nocpulse-common</packagereq>
<packagereq type="default">nocpulse-db-perl</packagereq>
@@ -27,13 +26,11 @@
<packagereq type="default">oracle-instantclient-sqlplus-selinux</packagereq>
<packagereq type="default">oracle-lib-compat</packagereq>
<packagereq type="default">oracle-nofcontext-selinux</packagereq>
- <packagereq type="default">oracle-rhnsat-selinux</packagereq>
<packagereq type="default">oracle-selinux</packagereq>
<packagereq type="default">oracle-xe-selinux</packagereq>
<packagereq type="default">osa-dispatcher</packagereq>
<packagereq type="default">osa-dispatcher-selinux</packagereq>
<packagereq type="default">perl-DBD-Oracle</packagereq>
- <packagereq type="default">perl-DBD-Oracle-explain</packagereq>
<packagereq type="default">perl-NOCpulse-CLAC</packagereq>
<packagereq type="default">perl-NOCpulse-Debug</packagereq>
<packagereq type="default">perl-NOCpulse-Gritch</packagereq>
@@ -135,4 +132,23 @@
<packagereq type="default">tsdb</packagereq>
</packagelist>
</group>
+ <group>
+ <id>spacewalk-server-docs</id>
+ <name>Spacewalk Server Documentation</name>
+ <description>Spacewalk Server Documentation Packages</description>
+ <uservisible>false</uservisible>
+ <packagelist>
+ <packagereq type="optional">jpam-javadoc</packagereq>
+ </packagelist>
+ </group>
+ <group>
+ <id>spacewalk-server-no-install</id>
+ <name>Spacewalk Server Junk</name>
+ <description>Spacewalk Server Non-installatble Packages</description>
+ <uservisible>false</uservisible>
+ <packagelist>
+ <packagereq type="optional">oracle-rhnsat-selinux</packagereq>
+ <packagereq type="optional">perl-DBD-Oracle-explain</packagereq>
+ </packagelist>
+ </group>
</comps>
diff --git a/rel-eng/comps/comps-spacewalk-server-fedora14.xml b/rel-eng/comps/comps-spacewalk-server-fedora14.xml
index 2de6104..76a3c67 100644
--- a/rel-eng/comps/comps-spacewalk-server-fedora14.xml
+++ b/rel-eng/comps/comps-spacewalk-server-fedora14.xml
@@ -15,7 +15,6 @@
<packagereq type="default">eventReceivers</packagereq>
<packagereq type="default">heirloom-pkgtools</packagereq>
<packagereq type="default">jpam</packagereq>
- <packagereq type="default">jpam-javadoc</packagereq>
<packagereq type="default">MessageQueue</packagereq>
<packagereq type="default">nocpulse-common</packagereq>
<packagereq type="default">nocpulse-db-perl</packagereq>
@@ -27,13 +26,11 @@
<packagereq type="default">oracle-instantclient-sqlplus-selinux</packagereq>
<packagereq type="default">oracle-lib-compat</packagereq>
<packagereq type="default">oracle-nofcontext-selinux</packagereq>
- <packagereq type="default">oracle-rhnsat-selinux</packagereq>
<packagereq type="default">oracle-selinux</packagereq>
<packagereq type="default">oracle-xe-selinux</packagereq>
<packagereq type="default">osa-dispatcher</packagereq>
<packagereq type="default">osa-dispatcher-selinux</packagereq>
<packagereq type="default">perl-DBD-Oracle</packagereq>
- <packagereq type="default">perl-DBD-Oracle-explain</packagereq>
<packagereq type="default">perl-NOCpulse-CLAC</packagereq>
<packagereq type="default">perl-NOCpulse-Debug</packagereq>
<packagereq type="default">perl-NOCpulse-Gritch</packagereq>
@@ -136,4 +133,23 @@
<packagereq type="default">tsdb</packagereq>
</packagelist>
</group>
+ <group>
+ <id>spacewalk-server-docs</id>
+ <name>Spacewalk Server Documentation</name>
+ <description>Spacewalk Server Documentation Packages</description>
+ <uservisible>false</uservisible>
+ <packagelist>
+ <packagereq type="optional">jpam-javadoc</packagereq>
+ </packagelist>
+ </group>
+ <group>
+ <id>spacewalk-server-no-install</id>
+ <name>Spacewalk Server Junk</name>
+ <description>Spacewalk Server Non-installatble Packages</description>
+ <uservisible>false</uservisible>
+ <packagelist>
+ <packagereq type="optional">oracle-rhnsat-selinux</packagereq>
+ <packagereq type="optional">perl-DBD-Oracle-explain</packagereq>
+ </packagelist>
+ </group>
</comps>
diff --git a/rel-eng/comps/comps-spacewalk-server-rhel5.xml b/rel-eng/comps/comps-spacewalk-server-rhel5.xml
index 2df40ae..bfd2496 100644
--- a/rel-eng/comps/comps-spacewalk-server-rhel5.xml
+++ b/rel-eng/comps/comps-spacewalk-server-rhel5.xml
@@ -15,14 +15,12 @@
<packagereq type="default">bea-stax</packagereq>
<packagereq type="default">bea-stax-api</packagereq>
<packagereq type="default">c3p0</packagereq>
- <packagereq type="default">c3p0-javadoc</packagereq>
<packagereq type="default">cglib</packagereq>
<packagereq type="default">cglib-demo</packagereq>
<packagereq type="default">cglib-nohook</packagereq>
<packagereq type="default">cglib-repolib</packagereq>
<packagereq type="default">chameleon</packagereq>
<packagereq type="default">concurrent</packagereq>
- <packagereq type="default">concurrent-javadoc</packagereq>
<packagereq type="default">concurrent-repolib</packagereq>
<packagereq type="default">cx_Oracle</packagereq>
<packagereq type="default">dom4j</packagereq>
@@ -43,7 +41,6 @@
<packagereq type="default">jaxen-manual</packagereq>
<packagereq type="default">jaxen-repolib</packagereq>
<packagereq type="default">jpam</packagereq>
- <packagereq type="default">jpam-javadoc</packagereq>
<packagereq type="default">MessageQueue</packagereq>
<packagereq type="default">msv</packagereq>
<packagereq type="default">msv-demo</packagereq>
@@ -62,18 +59,15 @@
<packagereq type="default">oracle-instantclient-sqlplus-selinux</packagereq>
<packagereq type="default">oracle-lib-compat</packagereq>
<packagereq type="default">oracle-nofcontext-selinux</packagereq>
- <packagereq type="default">oracle-rhnsat-selinux</packagereq>
<packagereq type="default">oracle-selinux</packagereq>
<packagereq type="default">oracle-xe-selinux</packagereq>
<packagereq type="default">osa-dispatcher</packagereq>
<packagereq type="default">osa-dispatcher-selinux</packagereq>
<packagereq type="default">oscache</packagereq>
- <packagereq type="default">oscache-javadoc</packagereq>
<packagereq type="default">oscache-manual</packagereq>
<packagereq type="default">perl-Class-Loader</packagereq>
<packagereq type="default">perl-DateTime-TimeZone</packagereq>
<packagereq type="default">perl-DBD-Oracle</packagereq>
- <packagereq type="default">perl-DBD-Oracle-explain</packagereq>
<packagereq type="default">perl-Error</packagereq>
<packagereq type="default">perl-FreezeThaw</packagereq>
<packagereq type="default">perl-Mail-RFC822-Address</packagereq>
@@ -108,7 +102,6 @@
<packagereq type="default">scdb</packagereq>
<packagereq type="default">simple-core</packagereq>
<packagereq type="default">sitemesh</packagereq>
- <packagereq type="default">sitemesh-javadoc</packagereq>
<packagereq type="default">SNMPAlerts</packagereq>
<packagereq type="default">spacecmd</packagereq>
<packagereq type="default">spacewalk-admin</packagereq>
@@ -201,18 +194,23 @@
<packagelist>
<packagereq type="optional">asm-javadoc</packagereq>
<packagereq type="optional">bea-stax-javadoc</packagereq>
+ <packagereq type="optional">c3p0-javadoc</packagereq>
<packagereq type="optional">cglib-javadoc</packagereq>
+ <packagereq type="optional">concurrent-javadoc</packagereq>
<packagereq type="optional">dom4j-javadoc</packagereq>
<packagereq type="optional">hibernate3-javadoc</packagereq>
<packagereq type="optional">icu4j-javadoc</packagereq>
<packagereq type="optional">isorelax-javadoc</packagereq>
<packagereq type="optional">jakarta-commons-cli-javadoc</packagereq>
<packagereq type="optional">jaxen-javadoc</packagereq>
+ <packagereq type="optional">jpam-javadoc</packagereq>
<packagereq type="optional">msv-javadoc</packagereq>
<packagereq type="optional">msv-relames-javadoc</packagereq>
<packagereq type="optional">msv-xmlgen-javadoc</packagereq>
<packagereq type="optional">msv-xsdlib-javadoc</packagereq>
+ <packagereq type="optional">oscache-javadoc</packagereq>
<packagereq type="optional">relaxngDatatype-javadoc</packagereq>
+ <packagereq type="optional">sitemesh-javadoc</packagereq>
<packagereq type="optional">tanukiwrapper-javadoc</packagereq>
<packagereq type="optional">ws-jaxme-javadoc</packagereq>
<packagereq type="optional">xom-javadoc</packagereq>
diff --git a/rel-eng/comps/comps-spacewalk-server-rhel6.xml b/rel-eng/comps/comps-spacewalk-server-rhel6.xml
index 36eed71..b6e1dc1 100644
--- a/rel-eng/comps/comps-spacewalk-server-rhel6.xml
+++ b/rel-eng/comps/comps-spacewalk-server-rhel6.xml
@@ -26,13 +26,11 @@
<packagereq type="default">oracle-instantclient-sqlplus-selinux</packagereq>
<packagereq type="default">oracle-lib-compat</packagereq>
<packagereq type="default">oracle-nofcontext-selinux</packagereq>
- <packagereq type="default">oracle-rhnsat-selinux</packagereq>
<packagereq type="default">oracle-selinux</packagereq>
<packagereq type="default">oracle-xe-selinux</packagereq>
<packagereq type="default">osa-dispatcher</packagereq>
<packagereq type="default">osa-dispatcher-selinux</packagereq>
<packagereq type="default">perl-DBD-Oracle</packagereq>
- <packagereq type="default">perl-DBD-Oracle-explain</packagereq>
<packagereq type="default">perl-Mail-RFC822-Address</packagereq>
<packagereq type="default">perl-NOCpulse-CLAC</packagereq>
<packagereq type="default">perl-NOCpulse-Debug</packagereq>
@@ -145,9 +143,19 @@
<description>Spacewalk Server Documentation Packages</description>
<uservisible>false</uservisible>
<packagelist>
- <packagereq type="default">jpam-javadoc</packagereq>
- <packagereq type="default">relaxngDatatype-javadoc</packagereq>
- <packagereq type="default">tanukiwrapper-javadoc</packagereq>
+ <packagereq type="optional">jpam-javadoc</packagereq>
+ <packagereq type="optional">relaxngDatatype-javadoc</packagereq>
+ <packagereq type="optional">tanukiwrapper-javadoc</packagereq>
+ </packagelist>
+ </group>
+ <group>
+ <id>spacewalk-server-no-install</id>
+ <name>Spacewalk Server Junk</name>
+ <description>Spacewalk Server Non-installatble Packages</description>
+ <uservisible>false</uservisible>
+ <packagelist>
+ <packagereq type="optional">oracle-rhnsat-selinux</packagereq>
+ <packagereq type="optional">perl-DBD-Oracle-explain</packagereq>
</packagelist>
</group>
</comps>
13 years, 3 months
schema/spacewalk
by Jan Pazdziora
schema/spacewalk/spacewalk-schema-upgrade | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
New commits:
commit 7bc6c0f577f5a8a292123f75cb8933a0c9aff2e6
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Thu Jan 20 18:25:27 2011 +0100
Use current_timestamp which works on both database backends.
diff --git a/schema/spacewalk/spacewalk-schema-upgrade b/schema/spacewalk/spacewalk-schema-upgrade
index 5b443e0..1499d05 100755
--- a/schema/spacewalk/spacewalk-schema-upgrade
+++ b/schema/spacewalk/spacewalk-schema-upgrade
@@ -141,7 +141,7 @@ my $start = $start_schema_norm;
my $in = <<EOF;
update rhnVersionInfo
set label = 'schema-from-' || to_char(created, 'YYYYMMDD-HH24MISS'),
- modified = sysdate
+ modified = current_timestamp
where label = 'schema';
commit;
EOF
@@ -211,7 +211,7 @@ insert into rhnVersionInfo
( label, name_id, evr_id, created, modified )
values ('schema', lookup_package_name('$my_schema_name'),
lookup_evr(null, '$my_schema_version' , '$my_schema_release' ),
- sysdate, sysdate );
+ current_timestamp, current_timestamp );
commit;
EOF
13 years, 3 months
schema/spacewalk
by Jan Pazdziora
schema/spacewalk/spacewalk-schema-upgrade | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
New commits:
commit 792e2b984ca37f7578b89936ccf66c7fcf256d60
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Thu Jan 20 18:22:24 2011 +0100
Sadly, the directory name is postgres even if the backend name is postgresql.
diff --git a/schema/spacewalk/spacewalk-schema-upgrade b/schema/spacewalk/spacewalk-schema-upgrade
index d55b58b..5b443e0 100755
--- a/schema/spacewalk/spacewalk-schema-upgrade
+++ b/schema/spacewalk/spacewalk-schema-upgrade
@@ -196,7 +196,8 @@ EOF
$start = $t;
}
-my $endfile = "/etc/sysconfig/rhn/$options{db_backend}/upgrade-end.sql";
+my $backend_dir = ( $options{db_backend} eq 'postgresql' ? 'postgres' : $options{db_backend} );
+my $endfile = "/etc/sysconfig/rhn/$backend_dir/upgrade-end.sql";
local * END;
open END, '<', $endfile or die "Error reading [$endfile]: $!\n";
{
13 years, 3 months
schema/spacewalk
by Jan Pazdziora
schema/spacewalk/oracle/end.sql | 2 ++
schema/spacewalk/postgres/end.sql | 2 +-
schema/spacewalk/spacewalk-schema-upgrade | 27 +++++++++------------------
schema/spacewalk/spacewalk-schema.spec | 2 ++
4 files changed, 14 insertions(+), 19 deletions(-)
New commits:
commit 919fceb82aa3251be190e7f686b0c3f2da1a90f8
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jan 21 11:23:34 2011 +0100
Moving database-specific "end" parts off spacewalk-schema-upgrade script, reusing end.sql.
diff --git a/schema/spacewalk/oracle/end.sql b/schema/spacewalk/oracle/end.sql
index 6f03fb5..4509747 100644
--- a/schema/spacewalk/oracle/end.sql
+++ b/schema/spacewalk/oracle/end.sql
@@ -15,6 +15,8 @@
COMMIT;
+exec dbms_utility.compile_schema(user);
+
-- check whether all objects are valid
declare
invalid_objects number;
diff --git a/schema/spacewalk/postgres/end.sql b/schema/spacewalk/postgres/end.sql
index ded9953..6370a73 100644
--- a/schema/spacewalk/postgres/end.sql
+++ b/schema/spacewalk/postgres/end.sql
@@ -1,4 +1,4 @@
--- oracle equivalent source sha1 14209d5b6d662eb00d6a7042f32f68c8677ff9c9
+-- oracle equivalent source sha1 add00c99b59028f5056a3dac6f14c7112ce6d504
--
-- Copyright (c) 2010 Red Hat, Inc.
--
diff --git a/schema/spacewalk/spacewalk-schema-upgrade b/schema/spacewalk/spacewalk-schema-upgrade
index 9102c35..d55b58b 100755
--- a/schema/spacewalk/spacewalk-schema-upgrade
+++ b/schema/spacewalk/spacewalk-schema-upgrade
@@ -196,25 +196,16 @@ EOF
$start = $t;
}
-$in .= <<EOF;
-
-exec dbms_utility.compile_schema(user);
-
--- check whether all objects are valid
-declare
- invalid_objects number;
-begin
- select count(*)
- into invalid_objects
- from user_objects
- where status <> 'VALID' and
- (object_name, object_type) not in (select object_name, type from recyclebin);
- if invalid_objects > 0 then
- RAISE_APPLICATION_ERROR(-20001, 'SCHEMA UPGRADE ENDS WITH INVALD OBJECTS');
- end if;
-end;
-/
+my $endfile = "/etc/sysconfig/rhn/$options{db_backend}/upgrade-end.sql";
+local * END;
+open END, '<', $endfile or die "Error reading [$endfile]: $!\n";
+{
+local $/ = undef;
+$in .= join '', <END>;
+}
+close END;
+$in .= <<EOF;
insert into rhnVersionInfo
( label, name_id, evr_id, created, modified )
values ('schema', lookup_package_name('$my_schema_name'),
diff --git a/schema/spacewalk/spacewalk-schema.spec b/schema/spacewalk/spacewalk-schema.spec
index fa37e4d..459777f 100644
--- a/schema/spacewalk/spacewalk-schema.spec
+++ b/schema/spacewalk/spacewalk-schema.spec
@@ -41,6 +41,8 @@ install -m 0755 -d $RPM_BUILD_ROOT%{oracle}
install -m 0755 -d $RPM_BUILD_ROOT%{postgres}
install -m 0644 oracle/main.sql $RPM_BUILD_ROOT%{oracle}
install -m 0644 postgres/main.sql $RPM_BUILD_ROOT%{postgres}
+install -m 0644 oracle/end.sql $RPM_BUILD_ROOT%{oracle}/upgrade-end.sql
+install -m 0644 postgres/end.sql $RPM_BUILD_ROOT%{postgres}/upgrade-end.sql
install -m 0755 -d $RPM_BUILD_ROOT%{_bindir}
install -m 0755 %{name}-upgrade $RPM_BUILD_ROOT%{_bindir}
install -m 0755 spacewalk-sql $RPM_BUILD_ROOT%{_bindir}
13 years, 3 months
schema/spacewalk
by Jan Pazdziora
schema/spacewalk/spacewalk-schema-upgrade | 2 --
1 file changed, 2 deletions(-)
New commits:
commit 349a4929fdb222ebe20dc034077867c134c11134
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jan 21 11:12:40 2011 +0100
PostgreSQL does not know quit, removing, not needed.
Addressing
ERROR: syntax error at or near "quit"
LINE 1: quit;
^
diff --git a/schema/spacewalk/spacewalk-schema-upgrade b/schema/spacewalk/spacewalk-schema-upgrade
index 0197504..9102c35 100755
--- a/schema/spacewalk/spacewalk-schema-upgrade
+++ b/schema/spacewalk/spacewalk-schema-upgrade
@@ -223,8 +223,6 @@ insert into rhnVersionInfo
commit;
EOF
-$in .= "quit;\n";
-
local *SQL;
open SQL, "> $SCHEMA_UPGRADE_LOGDIR/$stamp-script.sql" or die "Error writing [$SCHEMA_UPGRADE_LOGDIR/$stamp-script.sql]: $!.\n";
print SQL $in;
13 years, 3 months
schema/spacewalk
by Jan Pazdziora
schema/spacewalk/spacewalk-schema-upgrade | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
New commits:
commit 259a6316b0ea8f4b46160f43542f14e52d80a03d
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jan 21 11:10:09 2011 +0100
Only do the tablespace name replace on Oracle.
diff --git a/schema/spacewalk/spacewalk-schema-upgrade b/schema/spacewalk/spacewalk-schema-upgrade
index 74b614a..0197504 100755
--- a/schema/spacewalk/spacewalk-schema-upgrade
+++ b/schema/spacewalk/spacewalk-schema-upgrade
@@ -114,13 +114,16 @@ if (not exists $upgrade_path{$start_schema_norm}) {
my @path = get_shortest_path($upgrade_path{$start_schema_norm}, $target_schema_norm);
print "The path: ", (join " -> ", map "[$_]", $start_schema_norm, @path), "\n";
-my $default_tablespace = run_query(<<EOF);
- select default_tablespace
- from user_users
- where username = sys_context('userenv', 'session_user');
+my $default_tablespace;
+if ($options{db_backend} eq 'oracle') {
+ $default_tablespace = run_query(<<EOF);
+ select default_tablespace
+ from user_users
+ where username = sys_context('userenv', 'session_user');
EOF
-if (not defined $default_tablespace) {
- die "Failed to retrieve default_tablespace from database.\n";
+ if (not defined $default_tablespace) {
+ die "Failed to retrieve default_tablespace from database.\n";
+ }
}
mkdir "/var/log/spacewalk", 0755;
@@ -182,7 +185,7 @@ while (@path) {
}
close FILE;
$f_in =~ s!^--.*\n!!gm;
- $f_in =~ s!\[\[.*?\]\]|__.*?__!$default_tablespace!g;
+ $f_in =~ s!\[\[.*?\]\]|__.*?__!$default_tablespace!g if defined $default_tablespace;
$in .= <<EOF;
select '$dir/$name' from dual;
EOF
13 years, 3 months