Main Tables Views Materialized Views Indexes Constraints Triggers Procedures Functions Packages Sequences Java Sources Sanity Check Index DDL scrips
Arguments Source

DELETE_SERVER

Arguments:

NameData TypeDefault ValueIn/Out
SERVER_ID_INNUMBER(38) IN
DDL script

Source

Legend: comment string keyword reserved word operator
     1: procedure delete_server (
     2: 	server_id_in in number
     3: ) is
     4: 	cursor servergroups is
     5: 		select	server_id, server_group_id
     6: 		from	rhnServerGroupMembers sgm
     7: 		where	sgm.server_id = server_id_in;
     8: 	cursor configchannels is
     9: 		select	cc.id
    10: 		from	rhnConfigChannel cc,
    11: 			rhnConfigChannelType cct,
    12: 			rhnServerConfigChannel scc
    13: 		where	1=1
    14: 			and scc.server_id = server_id_in
    15: 			and scc.config_channel_id = cc.id
    16: 			-- these config channel types are reserved
    17: 			-- for use by a single server, so we don't
    18: 			-- need to check for other servers subscribed
    19: 			and cct.label in
    20: 				('local_override','server_import')
    21: 			and cct.id = cc.confchan_type_id;
    22:         type filelistsid_t is table of rhnServerPreserveFileList.file_list_id%type;
    23:         filelistsid_c filelistsid_t;
    24: 
    25:         type probesid_t is table of rhn_check_probe.probe_id%type;
    26:         probesid_c probesid_t;
    27: 
    28:     is_virt number := 0;
    29: begin
    30: 	rhn_channel.delete_server_channels(server_id_in);
    31: 	-- rhn_channel.clear_subscriptions(server_id_in);
    32: 
    33:         -- filelists
    34: 	select	spfl.file_list_id id bulk collect into filelistsid_c
    35: 	  from	rhnServerPreserveFileList spfl
    36: 	 where	spfl.server_id = server_id_in
    37: 			and not exists (
    38: 				select	1
    39: 				from	rhnServerPreserveFileList
    40: 				where	file_list_id = spfl.file_list_id
    41: 					and server_id != server_id_in
    42: 				union
    43: 				select	1
    44: 				from	rhnKickstartPreserveFileList
    45: 				where	file_list_id = spfl.file_list_id
    46: 			);
    47:         if filelistsid_c.first is not null then
    48:             forall i in filelistsid_c.first..filelistsid_c.last
    49:                 delete from rhnFileList where id = filelistsid_c(i);
    50:         end if;
    51: 
    52: 	for configchannel in configchannels loop
    53: 		rhn_config.delete_channel(configchannel.id);
    54: 	end loop;
    55: 
    56:       select count(1) into is_virt
    57:         from rhnServerEntitlementView
    58:        where server_id = server_id_in
    59:          and label in ('virtualization_host', 'virtualization_host_platform')
    60:          and rownum <= 1;
    61: 
    62: 	for sgm in servergroups loop
    63: 		rhn_server.delete_from_servergroup(
    64: 			sgm.server_id, sgm.server_group_id);
    65: 	end loop;
    66: 
    67:     if is_virt = 1 then
    68:         rhn_entitlements.repoll_virt_guest_entitlements(server_id_in);
    69:     end if;
    70: 
    71: 	-- we're handling this instead of letting an "on delete
    72: 	-- set null" do it so that we don't run the risk
    73: 	-- of setting off the triggers and killing us with a
    74: 	-- mutating table
    75: 
    76: 	-- this is merge of two single updates:
    77:         --  update ... set old_server_id = null where old_server_id = server_id_in;
    78:         --  update ... set new_server_id = null where new_server_id = server_id_in;
    79:         -- so we scan rhnKickstartSession table only once
    80: 	update rhnKickstartSession
    81: 		set old_server_id = case when old_server_id = server_id_in then null else old_server_id end,
    82: 		    new_server_id = case when new_server_id = server_id_in then null else new_server_id end
    83: 		where old_server_id = server_id_in
    84: 		   or new_server_id = server_id_in;
    85: 
    86: 	rhn_channel.clear_subscriptions(server_id_in,1);
    87: 
    88:     	-- A little complicated here, but the goal is to
    89: 	-- delete records from rhnVirtualInstace only if we don't
    90: 	-- care about them anymore.  We don't care about records
    91: 	-- in rhnVirtualInstance if we are deleting the host
    92: 	-- system and the virtual system is already null, or
    93: 	-- vice-versa.  We *do* care about them if either the
    94: 	-- host or virtual system is still registered because we
    95: 	-- still want them to show up in the UI.
    96:     -- If there's a newer row in rhnVirtualInstance with the same
    97:     -- uuid, this guest must have been re-registered, so we can clean
    98:     -- this data up.
    99: 
   100:         delete from rhnVirtualInstance vi
   101: 	      where (host_system_id = server_id_in and virtual_system_id is null)
   102:                  or (virtual_system_id = server_id_in and host_system_id is null)
   103:                  or (vi.virtual_system_id = server_id_in and vi.modified < (select max(vi2.modified)
   104:                     from rhnVirtualInstance vi2 where vi2.uuid = vi.uuid));
   105: 
   106:         -- this is merge of two single updates:
   107:         --  update ... set host_system_id = null where host_system_id = server_id_in;
   108:         --  update ... set virtual_system_id = null where virtual_system_id = server_id_in;
   109:         -- so we scan rhnVirtualInstance table only once
   110:         update rhnVirtualInstance
   111: 	   set host_system_id = case when host_system_id = server_id_in then null else host_system_id end,
   112: 	       virtual_system_id = case when virtual_system_id = server_id_in then null else virtual_system_id end
   113: 	 where host_system_id = server_id_in
   114: 	    or virtual_system_id = server_id_in;
   115: 
   116:         -- this is merge of two single updates:
   117:         --  update ... set old_host_system_id = null when old_host_system_id = server_id_in;
   118:         --  update ... set new_host_system_id = null when new_host_system_id = server_id_in;
   119:         -- so we scan rhnVirtualInstanceEventLog table only once
   120: 	update rhnVirtualInstanceEventLog
   121: 	   set old_host_system_id = case when old_host_system_id = server_id_in then null else old_host_system_id end,
   122:                new_host_system_id = case when new_host_system_id = server_id_in then null else new_host_system_id end
   123:          where old_host_system_id = server_id_in
   124:             or new_host_system_id = server_id_in;
   125: 
   126: 	-- We're deleting everything with a foreign key to rhnServer
   127: 	-- here, now.  I'm hoping this will help aleviate our deadlock
   128: 	-- problem.
   129: 
   130: 	delete from rhnActionConfigChannel where server_id = server_id_in;
   131: 	delete from rhnActionConfigRevision where server_id = server_id_in;
   132: 	delete from rhnActionPackageRemovalFailure where server_id = server_id_in;
   133: 	delete from rhnChannelFamilyLicenseConsent where server_id = server_id_in;
   134: 	delete from rhnClientCapability where server_id = server_id_in;
   135: 	delete from rhnCpu where server_id = server_id_in;
   136: 	-- there's still a cascade here, because the constraint keeps the
   137: 	-- table locked for too long to rebuild it.  Ugh...
   138: 	delete from rhnDevice where server_id = server_id_in;
   139: 	delete from rhnProxyInfo where server_id = server_id_in;
   140: 	delete from rhnRam where server_id = server_id_in;
   141: 	delete from rhnRegToken where server_id = server_id_in;
   142: 	delete from rhnSNPServerQueue where server_id = server_id_in;
   143: 	delete from rhnSatelliteChannelFamily where server_id = server_id_in;
   144: 	delete from rhnSatelliteInfo where server_id = server_id_in;
   145: 	-- this cascades to rhnActionConfigChannel and rhnActionConfigFileName
   146: 	delete from rhnServerAction where server_id = server_id_in;
   147: 	delete from rhnServerActionPackageResult where server_id = server_id_in;
   148: 	delete from rhnServerActionScriptResult where server_id = server_id_in;
   149: 	delete from rhnServerActionVerifyResult where server_id = server_id_in;
   150: 	delete from rhnServerActionVerifyMissing where server_id = server_id_in;
   151: 	-- counts are handled above.  this should be a delete_ function.
   152: 	delete from rhnServerChannel where server_id = server_id_in;
   153: 	delete from rhnServerConfigChannel where server_id = server_id_in;
   154: 	delete from rhnServerCustomDataValue where server_id = server_id_in;
   155: 	delete from rhnServerDMI where server_id = server_id_in;
   156: 	delete from rhnServerMessage where server_id = server_id_in;
   157: 	-- this gets rhnServerMessage (only) on cascade; it's handled just above
   158: 	delete from rhnServerEvent where server_id = server_id_in;
   159: 	delete from rhnServerHistory where server_id = server_id_in;
   160: 	delete from rhnServerInfo where server_id = server_id_in;
   161: 	delete from rhnServerInstallInfo where server_id = server_id_in;
   162: 	delete from rhnServerLocation where server_id = server_id_in;
   163: 	delete from rhnServerLock where server_id = server_id_in;
   164: 	delete from rhnServerNeededCache where server_id = server_id_in;
   165: 	delete from rhnServerNetwork where server_id = server_id_in;
   166: 	delete from rhnServerNotes where server_id = server_id_in;
   167: 	-- I'm not removing the foreign key from rhnServerPackage; that'll
   168: 	-- take forever.  Do the delete anyway.
   169: 	delete from rhnServerPackage where server_id = server_id_in;
   170: 	delete from rhnServerTokenRegs where server_id = server_id_in;
   171: 	delete from rhnSnapshotTag where server_id = server_id_in;
   172: 	-- this cascades to:
   173: 	--   rhnSnapshotChannel, rhnSnapshotConfigChannel, rhnSnapshotPackage,
   174: 	--   rhnSnapshotConfigRevision, rhnSnapshotServerGroup,
   175: 	--   rhnSnapshotTag.
   176: 	-- We may want to consider delete_snapshot() at some point, but
   177: 	--   I don't think we need to yet.
   178: 	delete from rhnSnapshot where server_id = server_id_in;
   179: 	delete from rhnTransaction where server_id = server_id_in;
   180: 	delete from rhnUserServerPrefs where server_id = server_id_in;
   181: 	-- hrm, this one's interesting... we _probably_ should delete
   182: 	-- everything for the parent server_id when we delete the proxy,
   183: 	-- but we don't currently.
   184: 	delete from rhnServerPath where server_id_in in (server_id, proxy_server_id);
   185: 	delete from rhnUserServerPerms where server_id = server_id_in;
   186: 
   187: 	delete from rhn_interface_monitoring where server_id = server_id_in;
   188: 	delete from rhnServerNetInterface where server_id = server_id_in;
   189: 	delete from rhn_server_monitoring_info where recid = server_id_in;
   190: 
   191: 	delete from rhnAppInstallSession where server_id = server_id_in;
   192: 	delete from rhnServerUuid where server_id = server_id_in;
   193:     -- We delete all the probes running directly against this system
   194:     -- and any probes that were using this Server as a Proxy Scout.
   195:      SELECT CP.probe_id bulk collect into probesid_c
   196:        FROM rhn_check_probe CP
   197:       WHERE CP.host_id = server_id_in
   198:          OR CP.sat_cluster_id in
   199:     (SELECT SN.sat_cluster_id
   200:        FROM rhn_sat_node SN
   201:       WHERE SN.server_id = server_id_in);
   202: 
   203:     if probesid_c.first is not null then
   204:         FORALL i IN probesid_c.first..probesid_c.last
   205:             DELETE FROM rhn_probe_state PS WHERE PS.probe_id = probesid_c(i);
   206:         FORALL i IN probesid_c.first..probesid_c.last
   207:             DELETE FROM rhn_probe P  WHERE P.recid = probesid_c(i);
   208:         FORALL i IN probesid_c.first..probesid_c.last
   209:             DELETE /*+index(time_series time_series_probe_id_idx)*/
   210:             FROM time_series
   211:             WHERE substr(o_id, instr(o_id, '-') + 1,
   212:                 (instr(o_id, '-', instr(o_id, '-') + 1) - instr(o_id, '-'))	- 1) = probesid_c(i);
   213:     end if;
   214: 
   215: 	delete from rhn_check_probe where host_id = server_id_in;
   216: 	delete from rhn_host_probe where host_id = server_id_in;
   217: 
   218:     delete from rhn_sat_cluster where recid in
   219:       ( select sat_cluster_id from rhn_sat_node where server_id = server_id_in );
   220: 
   221: 	delete from rhn_sat_node where server_id = server_id_in;
   222: 
   223: 	-- now get rhnServer itself.
   224: 	delete
   225: 	from	rhnServer
   226: 		where id = server_id_in;
   227: 
   228: 	delete
   229: 	from	rhnSet
   230: 	where	1=1
   231: 		and user_id in (
   232: 			select	wc.id
   233: 			from	rhnServer rs,
   234: 				web_contact wc
   235: 			where	rs.id = server_id_in
   236: 				and rs.org_id = wc.org_id
   237: 		)
   238: 		and label = 'system_list'
   239: 		and element = server_id_in;
   240: end delete_server;