Rem
Rem $Header: emcore/source/oracle/sysman/emdrep/sql/core/11.2.0.1/events/event_bus_types.sql rbali_oneoff_updated/1 2025/03/14 06:41:12 rbali Exp $
Rem
Rem event_bus_types.sql
Rem
Rem Copyright (c) 2010, 2025, Oracle and/or its affiliates. 
Rem All rights reserved.

Rem BEGIN EMRU_FILE_METADATA
Rem EMRU_SOURCE_FILE:emcore/source/oracle/sysman/emdrep/sql/core/11.2.0.1/events/event_bus_types.sql
Rem EMRU_UNIX_DELIVERABLES:
Rem emcore/source/oracle/sysman/emdrep/sql/core/11.2.0.1/events/event_bus_types.sql

Rem EMRU_FILE_POSTINSTALL:<!!! enter the view based location of the executable file. If there is NONE leave as-is !!!>
Rem EMRU_GENERIC_FLAG:NONE
Rem END EMRU_FILE_METADATA

Rem
Rem    NAME
Rem      event_bus_types.sql - <one-line expansion of the name>
Rem
Rem    DESCRIPTION
Rem      <short description of component this file declares/defines>
Rem
Rem    NOTES
Rem      <other useful comments, qualifications, etc.>
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    gbafna      01/07/25 - make synonyms noneditionable
Rem    rnadidar    02/11/15 - cut over to EBR
Rem    sreddy      04/07/11 - add update details to event update signal
Rem    zeding      12/15/10 - rename signature_id for exception event queue to
Rem                           event_bus_hashing_id 
Rem    rsidlagh    06/21/10 - Changed issue_id, incident_id, problem_id
Rem                           datatype to RAW(16)
Rem    rpatti      07/03/10 - use single event update object
Rem    punjain     06/10/10 - Adding Duration and Repeat message array
Rem    rsidlagh    06/03/10 - Removed ca_execution_id, status, severity from EM_EV_BUS_CA_MSG
Rem    sreddy      01/04/10 - Created
Rem

Rem 
Rem This script requires the following arguments
Rem  1. Name of the repository user
Rem 
Rem EM_REPOS_USER CANNOT BE OVERWRITTEN.  THERE ARE OTHER CODES THAT
Rem USES EM_REPOS_USER

-- DEFINE MY_REPOS_USER           = "&1"
DEFINE MY_REPOS_USER = SYSMAN


ALTER SESSION SET CURRENT_SCHEMA=SYSMAN_TYPES;

--
-- This message is used for queuing administrative messages to event bus.
-- Administrative messages are processed by the event coordinator in the
-- middle tier. 
--
CREATE OR REPLACE TYPE EM_EV_BUS_ADMIN_MSG AS OBJECT
(
    message VARCHAR2(30), -- REASSIGN-Q, REFRESH-RULE, REFRESH-MODEL
    operation NUMBER(2),  -- OP_RESET, OP_ADD, OP_DELETE, OP_UPDATE
    param1 VARCHAR2(512), -- parameter specific to message and operation
    param2 VARCHAR2(512), -- parameter specific to message and operation
    param3 VARCHAR2(512), -- parameter specific to message and operation
    CONSTRUCTOR FUNCTION EM_EV_BUS_ADMIN_MSG
    (
        p_message           IN VARCHAR2,
        p_operation         IN NUMBER       DEFAULT 0,
        p_param1            IN VARCHAR2     DEFAULT NULL,
        p_param2            IN VARCHAR2     DEFAULT NULL,
        p_param3            IN VARCHAR2     DEFAULT NULL
    )
    RETURN SELF AS RESULT 
);
/


grant execute on EM_EV_BUS_ADMIN_MSG to sysman;

create or replace noneditionable synonym SYSMAN.EM_EV_BUS_ADMIN_MSG for EM_EV_BUS_ADMIN_MSG;


--
-- Thie message is used for queuing a repeat signal in the event bus. Event Rule
-- engine enqueues these messages as part of repeat rule processing.
--


CREATE OR REPLACE TYPE EM_EV_BUS_REPEAT_MSG AS OBJECT
(
    msg NUMBER(1), -- EVENT=>1, INCIDENT=>2, PROBLEM=>3
    event_class_name VARCHAR2(20), -- populated when msg is EVENT
    event_inst_id RAW(16), -- populated when msg is EVENT
    event_sequence_id RAW(16), -- populated when msg is EVENT
    signature_id RAW(16), -- populated when msg is EVENT
    incident_id RAW(16),
    problem_id RAW(16),
    rule_id NUMBER,
    repeat_count NUMBER,
    repeat_freq NUMBER, -- in minutes; reevaluate the rules after repeat_freq
    max_repeat_count NUMBER,
    msg_creation_date DATE,
    CONSTRUCTOR FUNCTION EM_EV_BUS_REPEAT_MSG
    (
        p_msg                IN NUMBER,
        p_event_class_name   IN VARCHAR2 DEFAULT NULL,
        p_event_inst_id      IN RAW DEFAULT NULL,
        p_event_sequence_id  IN RAW DEFAULT NULL,
        p_signature_id       IN RAW DEFAULT NULL,
        p_incident_id        IN RAW DEFAULT NULL,
        p_problem_id         IN RAW DEFAULT NULL,
        p_rule_id            IN NUMBER,
        p_repeat_count       IN NUMBER,
        p_repeat_freq        IN NUMBER,
        p_max_repeat_count   IN NUMBER,
        p_msg_creation_date  IN DATE DEFAULT SYSDATE
    )
    RETURN SELF AS RESULT 
);
/

grant execute on EM_EV_BUS_REPEAT_MSG to sysman;

create or replace noneditionable synonym SYSMAN.EM_EV_BUS_REPEAT_MSG for EM_EV_BUS_REPEAT_MSG;



--
-- This message represents a duration signal payload in the event bus.
-- Event rule engine enqueues these messages as part of duration rule
-- processing.
--
CREATE OR REPLACE TYPE EM_EV_BUS_DURATION_MSG AS OBJECT
(
    msg NUMBER(1), -- EVENT=>1, INCIDENT=>2, PROBLEM=>3
    event_class_name VARCHAR2(20), -- populated when msg is EVENT
    event_inst_id RAW(16), -- populated when msg is EVENT
    event_sequence_id RAW(16), -- populated when msg is EVENT
    signature_id RAW(16), -- populated when msg is EVENT
    incident_id RAW(16),
    problem_id RAW(16),
    rule_id NUMBER,
    msg_creation_date DATE,
    duration_value NUMBER, -- duration in minutes
    CONSTRUCTOR FUNCTION EM_EV_BUS_DURATION_MSG
    (
        p_msg                IN NUMBER,
        p_event_class_name   IN VARCHAR2 DEFAULT NULL,
        p_event_inst_id      IN RAW DEFAULT NULL,
        p_event_sequence_id  IN RAW DEFAULT NULL,
        p_signature_id       IN RAW DEFAULT NULL,
        p_incident_id        IN RAW DEFAULT NULL,
        p_problem_id         IN RAW DEFAULT NULL,
        p_rule_id            IN NUMBER,
        p_msg_creation_date  IN DATE DEFAULT SYSDATE,
        p_duration_value     IN NUMBER
    )
    RETURN SELF AS RESULT 
);
/

grant execute on EM_EV_BUS_DURATION_MSG to sysman;

create or replace noneditionable synonym SYSMAN.EM_EV_BUS_DURATION_MSG for EM_EV_BUS_DURATION_MSG;




CREATE OR REPLACE TYPE em_ev_bus_duration_msg_array 
AS VARRAY(100) OF em_ev_bus_duration_msg;
/

GRANT EXECUTE ON em_ev_bus_duration_msg_array TO SYSMAN WITH GRANT OPTION;

CREATE OR REPLACE NONEDITIONABLE SYNONYM SYSMAN.em_ev_bus_duration_msg_array FOR em_ev_bus_duration_msg_array;


--
-- This message represents an execeptional event signal payload in
-- event bus. These messages are enqueued by external systems 
-- through event publishing API.
--
CREATE OR REPLACE TYPE EM_EV_BUS_EXC_EVT_MSG AS OBJECT
(
    event_class_name VARCHAR2(20),
    event_inst_id RAW(16),
    event_sequence_id RAW(16),
    event_bus_hashing_id RAW(16),
    last_event_inst_id RAW(16),
    attr_change_list MGMT_SHORT_STRING_ARRAY,
    processing_status NUMBER(1),
    dedup_status NUMBER(1),
    ref_attribs gc_event_pair_array,
    parameter_pair_values GC_EVENT_PAIR_ARRAY,
    CONSTRUCTOR FUNCTION EM_EV_BUS_EXC_EVT_MSG
    (
        p_event_class_name      IN VARCHAR2,
        p_event_inst_id         IN RAW,
        p_event_sequence_id     IN RAW,
        p_event_bus_hashing_id  IN RAW,
        p_last_event_inst_id    IN RAW DEFAULT NULL,
        p_attr_change_list      IN MGMT_SHORT_STRING_ARRAY DEFAULT NULL,
        p_processing_status     IN NUMBER DEFAULT 1, -- EM_EVENT_UTIL.SEQ_NEW
        p_dedup_status          IN NUMBER DEFAULT 0, -- not a duplicate event
        p_ref_attribs           IN gc_event_pair_array DEFAULT NULL,
        p_parameter_pair_values IN GC_EVENT_PAIR_ARRAY DEFAULT NULL
    )
    RETURN SELF AS RESULT 
);
/

grant execute on EM_EV_BUS_EXC_EVT_MSG to sysman;

create or replace noneditionable synonym SYSMAN.EM_EV_BUS_EXC_EVT_MSG for EM_EV_BUS_EXC_EVT_MSG;


--
-- This message represents an event update in event bus. 
-- used by for handling CA and RCA updates.
--
CREATE OR REPLACE TYPE EM_EV_BUS_EVT_UPD_MSG AS OBJECT
(
    update_type VARCHAR2(10), 
    event_class_name VARCHAR2(20),
    event_inst_id RAW(16),
    event_sequence_id RAW(16),
    signature_id RAW(16),
    attr_change_list MGMT_SHORT_STRING_ARRAY,
    event_update_details gc_event_pair_array,
    CONSTRUCTOR FUNCTION EM_EV_BUS_EVT_UPD_MSG
    (
        p_update_type           IN VARCHAR2,
        p_event_class_name      IN VARCHAR2,
        p_event_inst_id         IN RAW,
        p_event_sequence_id     IN RAW,
        p_signature_id          IN RAW,
        p_attr_change_list      IN MGMT_SHORT_STRING_ARRAY DEFAULT NULL,
        p_event_update_details  IN gc_event_pair_array DEFAULT NULL
    )
    RETURN SELF AS RESULT 
);
/

grant execute on EM_EV_BUS_EVT_UPD_MSG to sysman;

create or replace noneditionable synonym SYSMAN.EM_EV_BUS_EVT_UPD_MSG for EM_EV_BUS_EVT_UPD_MSG;



--
-- This message represents a ticket update msg in the event bus.
-- event_manager's ticket update PLSQL API enqueues this message.
-- 
CREATE OR REPLACE TYPE EM_EV_BUS_TKT_UPDT_MSG AS OBJECT
(
    incident_id RAW(16)
);
/


grant execute on EM_EV_BUS_TKT_UPDT_MSG to sysman;

create or replace noneditionable synonym SYSMAN.EM_EV_BUS_TKT_UPDT_MSG for EM_EV_BUS_TKT_UPDT_MSG;



-- Create message payload object for the AQ
CREATE OR REPLACE TYPE EM_EV_BUS_MSG AS OBJECT
(
    msg_type NUMBER(2),         -- ADMIN_MSG, EXCEPTIONAL_MSG, REPEAT_MSG, ...
    admin_msg EM_EV_BUS_ADMIN_MSG, -- for  msg_type = ADMIN_MSG
    exception_evt_msg EM_EV_BUS_EXC_EVT_MSG, -- for  msg_type = EXCEPTION_EVT_MSG
    repeat_msg EM_EV_BUS_REPEAT_MSG, -- for  msg_type = REPEAT_MSG
    duration_msg EM_EV_BUS_DURATION_MSG, -- for  msg_type = DURATION_MSG
    info_evt_msg EM_EVENT_OBJ, -- for  msg_type = INFO_EVT_MSG
    evt_upd_msg EM_EV_BUS_EVT_UPD_MSG, -- for  msg_type = EVT_UPDATE
    tkt_updt_msg EM_EV_BUS_TKT_UPDT_MSG, -- for msg_type = TKT_UPDATE
    CONSTRUCTOR FUNCTION EM_EV_BUS_MSG
    (
        p_msg_type          IN NUMBER,
        p_admin_msg         IN EM_EV_BUS_ADMIN_MSG     DEFAULT NULL,
        p_exception_evt_msg IN EM_EV_BUS_EXC_EVT_MSG   DEFAULT NULL,
        p_repeat_msg        IN EM_EV_BUS_REPEAT_MSG    DEFAULT NULL,
        p_duration_msg      IN EM_EV_BUS_DURATION_MSG  DEFAULT NULL,
        p_info_evt_msg      IN EM_EVENT_OBJ            DEFAULT NULL,
        p_evt_upd_msg       IN EM_EV_BUS_EVT_UPD_MSG   DEFAULT NULL,
        p_tkt_updt_msg      IN EM_EV_BUS_TKT_UPDT_MSG  DEFAULT NULL
    )
    RETURN SELF AS RESULT,
    MEMBER FUNCTION GET_STRING RETURN VARCHAR2
);
/

grant execute on EM_EV_BUS_MSG to sysman;

create or replace noneditionable synonym SYSMAN.EM_EV_BUS_MSG for EM_EV_BUS_MSG;



ALTER SESSION SET CURRENT_SCHEMA=SYSMAN;

-- Create and start the Event Bus Queue
BEGIN
  DBMS_AQADM.CREATE_QUEUE_TABLE (queue_table => '&MY_REPOS_USER'||'.EM_EVENT_BUS_TABLE',
                                 queue_payload_type => '&MY_REPOS_USER'||'_TYPES.EM_EV_BUS_MSG',
                                 sort_list => 'PRIORITY,ENQ_TIME',
                                 multiple_consumers => TRUE);
  DBMS_AQADM.CREATE_QUEUE (queue_name => '&MY_REPOS_USER'||'.EM_EVENT_BUS',
                           queue_table => '&MY_REPOS_USER'||'.EM_EVENT_BUS_TABLE');
  DBMS_AQADM.START_QUEUE (queue_name => '&MY_REPOS_USER'||'.EM_EVENT_BUS');
END;
/


