Rem
Rem $Header: emcore/source/oracle/sysman/emdrep/sql/emregistry/latest/emlcm_admin_pkgdef.sql /main/2 2023/01/10 06:11:54 spramani Exp $
Rem
Rem emlcm_admin_pkgdef.sql
Rem
Rem Copyright (c) 2022, Oracle and/or its affiliates.
Rem
Rem    NAME
Rem      emlcm_admin_pkgdef.sql - LCM ADMIN user related pkgdef 
Rem
Rem    DESCRIPTION
Rem     Provides LCM ADMIN user related APIs  
Rem
Rem    NOTES
Rem      NONE 
Rem
Rem    BEGIN SQL_FILE_METADATA
Rem    SQL_SOURCE_FILE: emcore/source/oracle/sysman/emdrep/sql/emregistry/latest/emlcm_admin_pkgdef.sql
Rem    SQL_SHIPPED_FILE:
Rem    SQL_PHASE:
Rem    SQL_STARTUP_MODE: NORMAL
Rem    SQL_IGNORABLE_ERRORS: NONE
Rem    END SQL_FILE_METADATA
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    spramani    12/15/22 - cbd container check
Rem    spramani    09/20/22 - review comments
Rem    spramani    09/08/22 - track LCM ADMINs
Rem    spramani    09/04/22 - EM LCM Admin utilities
Rem    spramani    09/04/22 - Created
Rem


DEFINE MY_REPOS_USER = "&1"
DEFINE MY_DBA_USER = "&2"

ALTER SESSION SET CURRENT_SCHEMA=&MY_REPOS_USER;

CREATE OR REPLACE PACKAGE EM_LCM_ADMIN AS

   G_PHASE_CREATE                CONSTANT NUMBER(2) := 1;
   G_PHASE_UPGRADE               CONSTANT NUMBER(2) := 2;
   G_PHASE_PREUPGRADE            CONSTANT NUMBER(2) := 3;
   G_PHASE_DEFERRED              CONSTANT NUMBER(2) := 4;
   G_PHASE_PLUGIN                CONSTANT NUMBER(2) := 5;
   G_PHASE_DROP                  CONSTANT NUMBER(2) := 6;
   G_PHASE_REVERTPRE             CONSTANT NUMBER(2) := 7;
   G_PHASE_OUTOFBOX              CONSTANT NUMBER(2) := 8;
   G_PHASE_PURGECOMP             CONSTANT NUMBER(2) := 9;
   G_PHASE_PURGEPLUGIN           CONSTANT NUMBER(2) := 10;
   G_PHASE_EBRIFY                CONSTANT NUMBER(2) := 11;
   G_PHASE_RUAPPLY               CONSTANT NUMBER(2) := 12;
   G_PHASE_RUROLLBACK            CONSTANT NUMBER(2) := 13;

-- The list of functions here are for out of PLSQL usage
-- Since the constants are not accessible in SQL queries

-- return the constant G_PHASE_CREATE
  FUNCTION phase_create RETURN NUMBER;

-- return the constant G_PHASE_UPGRADE
  FUNCTION phase_upgrade RETURN NUMBER;

-- return the constants G_PHASE_PREUPGRADE
  FUNCTION phase_preupgrade RETURN NUMBER;

-- return the constants G_PHASE_DEFERRED
  FUNCTION phase_deferred RETURN NUMBER;

-- return the constants G_PHASE_PLUGIN
  FUNCTION phase_plugin RETURN NUMBER;

-- return the constants G_PHASE_DROP
  FUNCTION phase_drop RETURN NUMBER;

-- return the constants G_PHASE_REVERTPRE
  FUNCTION phase_revertpre RETURN NUMBER;

-- return the constants G_PHASE_OUTOFBOX
  FUNCTION phase_outofbox RETURN NUMBER;

-- return the constants G_PHASE_PURGECOMP
  FUNCTION phase_purgecomp RETURN NUMBER;

-- return the constants G_PHASE_PURGEPLUGIN
  FUNCTION phase_purgeplugin RETURN NUMBER;

-- return the constants G_PHASE_EBRIFY
  FUNCTION phase_ebrify RETURN NUMBER;


-- return the constants G_PHASE_RUAPPLY
  FUNCTION phase_ruapply RETURN NUMBER;

-- return the constants G_PHASE_RUROLLBACK
  FUNCTION phase_rurollback RETURN NUMBER;

-- returns 'ONP' if on-premise 
FUNCTION IS_ONP
RETURN VARCHAR2; 

-- returns 0 if already a session going on, you can't start a session 
-- else returns non-zero id of a new session 
FUNCTION lcm_op_started_by(p_lcmadmin IN VARCHAR2, p_lcm_op IN NUMBER)
RETURN NUMBER;

-- return 0 in error 
-- returns the id of the LCM session ended 
FUNCTION lcm_op_completed_by(p_lcmadmin IN VARCHAR2, p_lcm_op IN NUMBER)
RETURN NUMBER;

-- returns who did the last LCM including the one from current session 
FUNCTION get_last_lcm_admin
    RETURN VARCHAR2;

-- 0 means not LCM ADMIN 
-- 1 means LCM ADMIN 
FUNCTION is_lcm_adminuser(p_username IN VARCHAR2)
RETURN NUMBER;

-- to return current session's LCM ADMIN user
-- NULL means there is an error 
FUNCTION get_session_lcm_adminuser
RETURN VARCHAR2;

-- 1 means CDB-root  
-- 0 means PDB 
FUNCTION is_cdb_con 
RETURN NUMBER;

END EM_LCM_ADMIN;
/


ALTER SESSION SET CURRENT_SCHEMA=&MY_DBA_USER;

 
