Skip to content

Commit

Permalink
samples & runtimes for apl 4.2303.0
Browse files Browse the repository at this point in the history
  • Loading branch information
i317814 committed Jan 24, 2023
1 parent 9d7f935 commit 484d4df
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 225 deletions.
Binary file modified dataForHANACloud.tar.gz
Binary file not shown.
Binary file modified runtimes/java/KxJRT.jar
Binary file not shown.
153 changes: 97 additions & 56 deletions sql/check_apl/check_apl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- The purpose of this script is to validate the APL installation by:
-- check APL is actually installed
-- APL plugin is installed
-- Script server is actvated
-- Script server is activated
-- check APL is properly installed:
-- APL low level functions are installed
-- APL high level functions are installed
Expand All @@ -24,16 +24,16 @@
-- Detailed infos on the result of the check (and possibly,a fix)

-- Command line to run this script is:
-- hdbsql -n <HostName>:<port> -u SYSTEM -p <System password> -I .check_apl.sql -g '' -V SYSTEM_PASSWORD=<System password> -j -A
-- /usr/sap/hdbclient/hdbsql -n <HostName>:<port> -u SYSTEM -p <HANA SYSTEM USER's password> -I .check_apl.sql -g '' -V SYSTEM_PASSWORD=<HANA SYSTEM USER's password>,CHECK_APL_PASSWORD=<CHECK_APL Password> -j -A
--
-- Example:
-- hdbsql -n localhost:30041 -u SYSTEM -p Password1 -I ./check_apl.sql -g '' -V SYSTEM_PASSWORD=Password1 -j -A
-- /usr/sap/hdbclient/hdbsql -n localhost:30041 -u SYSTEM -p <HANA SYSTEM USER's password> -I ./check_apl.sql -g '' -V SYSTEM_PASSWORD=<HANA SYSTEM USER's password>,CHECK_APL_PASSWORD=Password1 -j -A

-- A more convenient way to run this script may be:
-- HANA_SYSTEM_PASSWORD=<HANA SYSTEM USER's password>; CHECK_APL_PASSWORD=Password1 ;hdbsql -n HANA host name>:<port> -u SYSTEM -p $HANA_SYSTEM_PASSWORD -g "" -V SYSTEM_PASSWORD=$HANA_SYSTEM_PASSWORD,CHECK_APL_PASSWORD=$CHECK_APL_PASSWORD -j -A -I check_apl.sql
-- HANA_SYSTEM_PASSWORD=<HANA SYSTEM USER's password>; CHECK_APL_PASSWORD=Password1 ;/usr/sap/hdbclient/hdbsql -n HANA host name>:<port> -u SYSTEM -p $HANA_SYSTEM_PASSWORD -g "" -V SYSTEM_PASSWORD=$HANA_SYSTEM_PASSWORD,CHECK_APL_PASSWORD=$CHECK_APL_PASSWORD -j -A -I check_apl.sql

-- Example:
-- HANA_SYSTEM_PASSWORD=Manager1; CHECK_APL_PASSWORD=Password1 ;/usr/sap/hdbclient_2_9_28/hdbsql -n hana:30015 -u SYSTEM -p $HANA_SYSTEM_PASSWORD -g "" -V SYSTEM_PASSWORD=$HANA_SYSTEM_PASSWORD,CHECK_APL_PASSWORD=$CHECK_APL_PASSWORD -j -A -I /SAPDevelop/apl/src/sql/check_apl/check_apl.sql >/tmp/b 2>&1
-- HANA_SYSTEM_PASSWORD=KeepYourSecretSecret; CHECK_APL_PASSWORD=Password1 ;/usr/sap/hdbclient/hdbsql -n hana:30015 -u SYSTEM -p $HANA_SYSTEM_PASSWORD -g "" -V SYSTEM_PASSWORD=$HANA_SYSTEM_PASSWORD,CHECK_APL_PASSWORD=$CHECK_APL_PASSWORD -j -A -I /SAPDevelop/apl/src/sql/check_apl/check_apl.sql >/tmp/b 2>&1

-- More details are available in readme.md

Expand All @@ -42,19 +42,30 @@
connect SYSTEM PASSWORD &SYSTEM_PASSWORD;

DROP USER CHECK_APL CASCADE;
CREATE USER CHECK_APL PASSWORD Password1;
CREATE USER CHECK_APL PASSWORD &CHECK_APL_PASSWORD;
ALTER USER CHECK_APL DISABLE PASSWORD lifetime;

DO BEGIN
DECLARE major INT;
DECLARE nb_import_threads INT;
SELECT CAST(SUBSTR_BEFORE ("VERSION", '.') AS INT) into major FROM "M_DATABASE";
IF :major < 4
THEN
-- this has a meaning only on HANA On Premise

EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM "M_SERVICE_THREADS" WHERE UPPER("THREAD_TYPE") LIKE ''IMPORT%''' INTO nb_import_threads;
IF :nb_import_threads > 0
THEN
SELECT 'Some import process is still running and may impact results of this check. We advise to rerun after end of all imports' AS "!!Warning!!" FROM DUMMY;
END IF;

EXECUTE IMMEDIATE 'GRANT SELECT ON "_SYS_REPO"."DELIVERY_UNITS" TO CHECK_APL';
EXECUTE IMMEDIATE 'GRANT SELECT ON "_SYS_REPO"."ACTIVE_OBJECT" TO CHECK_APL';
SELECT 'Some specific read-only rights have been granted so APL''s Delivery Unit checks can be done' AS "Note" FROM DUMMY;
SELECT 'Some specific read-only rights have been granted to user CHECK_APL so APL''s Delivery Unit checks can be done' AS "Note" FROM DUMMY;
END IF;

EXECUTE IMMEDIATE 'GRANT SERVICE ADMIN TO CHECK_APL';
SELECT 'SERVICE ADMIN rights have been granted to user CHECK_APL so scriptserver can be checked' AS "Note" FROM DUMMY;
END;

-- standard APL rights
Expand All @@ -74,6 +85,10 @@ DO BEGIN
END IF;
END;





-- now we can run analysis

-- use a hdbsql's macro to use the password of CHECK_APL
Expand Down Expand Up @@ -221,9 +236,8 @@ LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS BEGIN
DECLARE nb INT;
DECLARE who_am_i NVARCHAR(1000);
DECLARE who_am_i NVARCHAR(1000) = current_user;

SELECT CURRENT_USER into who_am_i FROM DUMMY;
SELECT COUNT(*) into nb FROM "PUBLIC"."EFFECTIVE_PRIVILEGES"
WHERE "USER_NAME" = :who_am_i
AND "SCHEMA_NAME" = 'SAP_PA_APL'
Expand All @@ -239,6 +253,7 @@ AS BEGIN
END;



-- Don't call this function on hce

CREATE FUNCTION "CAN_CALL_APL_PROC"(IN proc_name NVARCHAR(1000))
Expand All @@ -247,26 +262,25 @@ LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS BEGIN
DECLARE nb INT;
DECLARE who_am_i NVARCHAR(1000);

SELECT CURRENT_USER into who_am_i FROM DUMMY;
SELECT COUNT(*) into nb FROM granted_roles WHERE "GRANTEE"=:who_am_i AND "ROLE_NAME"='sap.pa.apl.base.roles::APL_EXECUTE';
IF :nb<>1
THEN
can_call = 'APL_GLOBAL_ROLE_NOT_GRANTED';
ELSE
SELECT COUNT(*) into nb FROM "PUBLIC"."PROCEDURES" WHERE "SCHEMA_NAME" = 'SAP_PA_APL' AND "PROCEDURE_NAME"=:proc_name;
IF :nb <>1
THEN
can_call = 'APL_GLOBAL_CODE_NOT_HERE';
ELSE
IF "HAS_EFFECTIVE_APL_PROC"(:proc_name) = FALSE
THEN
can_call = 'APL_CODE_NOT_IN_EFFECTIVE_PRIVILEGES';
ELSE
can_call = 'OK';
END IF;
END IF;
DECLARE who_am_i NVARCHAR(1000) = CURRENT_USER;

SELECT COUNT(*) into nb FROM granted_roles WHERE "GRANTEE"=:who_am_i AND "ROLE_NAME"='sap.pa.apl.base.roles::APL_EXECUTE';
IF :nb<>1
THEN
can_call = 'APL_GLOBAL_ROLE_NOT_GRANTED';
ELSE
SELECT COUNT(*) into nb FROM "PUBLIC"."PROCEDURES" WHERE "SCHEMA_NAME" = 'SAP_PA_APL' AND "PROCEDURE_NAME"=:proc_name;
IF :nb <>1
THEN
can_call = 'APL_GLOBAL_CODE_NOT_HERE';
ELSE
IF "HAS_EFFECTIVE_APL_PROC"(:proc_name) = FALSE
THEN
can_call = 'APL_CODE_NOT_IN_EFFECTIVE_PRIVILEGES';
ELSE
can_call = 'OK';
END IF;
END IF;
END IF;
END;

Expand All @@ -277,13 +291,12 @@ LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
BEGIN
DECLARE who_am_i NVARCHAR(1000);
DECLARE who_am_i NVARCHAR(1000) = CURRENT_USER;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
-- DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
:results.insert(('CHECK_TRAIN_PROCEDURE_MODE SQLScript error:', ::SQL_ERROR_CODE, ::SQL_ERROR_MESSAGE));
:results.insert(('CHECK_CAN_CALL_APL_PROCEDURE SQLScript error:', ::SQL_ERROR_CODE, ::SQL_ERROR_MESSAGE));
END;
SELECT CURRENT_USER into who_am_i FROM DUMMY;
SELECT "CAN_CALL_APL_PROC"(:proc_name) into can_call FROM DUMMY;

IF :can_call = 'APL_GLOBAL_CODE_NOT_HERE'
Expand Down Expand Up @@ -321,13 +334,15 @@ BEGIN
DECLARE status_1 NVARCHAR(1000);
DECLARE status_2 NVARCHAR(1000);
DECLARE text_1 NVARCHAR(1000);
DECLARE database_name NVARCHAR(1000);
DECLARE expected_debrief_version NVARCHAR(1000);
DECLARE nb INTEGER;
DECLARE du_version integer;
DECLARE du_date DATETIME = NULL;
DECLARE is_hce BOOLEAN = "IS_HCE"();
DECLARE bad_apis NCLOB;
DECLARE manifest_results "CHECK_RESULTS_T";
DECLARE user_name nvarchar(1000) = CURRENT_USER;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
:results.insert(('CHECK_APL_INSTALL SQLScript error:', ::SQL_ERROR_CODE, ::SQL_ERROR_MESSAGE));
Expand All @@ -340,6 +355,10 @@ BEGIN
:results.insert(('Checking installation of APL plugin','',''));
:results.insert(('____________________________','',''));

SELECT "DATABASE_NAME" into database_name FROM M_DATABASE;
:results.insert(('ANALYSE OF DATABASE','',:database_name));
:results.insert(('as user','',:user_name));

SELECT COUNT(*) into nb FROM M_PLUGIN_MANIFESTS WHERE "PLUGIN_NAME"='SAP_AFL_SDK_APL';
IF :nb = 0
THEN
Expand Down Expand Up @@ -398,6 +417,17 @@ BEGIN
:results.insert(('Good # of descriptions of APL low level calls','OK',:nb));
END IF;

:results.insert(('Checking registration of APL Table Types','',''));
:results.insert(('','',''));
SELECT distinct TABLE_NAME from sys.tables where schema_name='SAP_PA_APL' and table_name like 'sap.pa.apl%';
SELECT count(distinct TABLE_NAME) into nb from sys.tables where schema_name='SAP_PA_APL' and table_name like 'sap.pa.apl%';
IF :nb <95
THEN
:results.insert(('Bad # of APL Table types','ISSUE',:nb));
ELSE
:results.insert(('Good # of APL Table Types','OK',:nb));
END IF;

:results.insert(('Checking registration of high level APL API (APL DU or Hana Cloud SQLAutoContent)','',''));
:results.insert(('','',''));
IF :is_hce = false
Expand All @@ -423,15 +453,25 @@ BEGIN
ELSE
:results.insert(('Main APL role sap.pa.apl.base.roles::APL_EXECUTE is declared','OK',:nb));
END IF;
SELECT COUNT(*) into nb FROM "M_TABLES" WHERE "SCHEMA_NAME" = 'SAP_PA_APL' AND "TABLE_NAME" LIKE 'sap.pa.apl.%';
IF :nb < 170
SELECT COUNT(DISTINCT "TABLE_NAME") into nb FROM "M_TABLES" WHERE "SCHEMA_NAME" = 'SAP_PA_APL' AND "TABLE_NAME" LIKE 'sap.pa.apl.%';
IF :is_hce = false
THEN
:results.insert(('Bad # of APL types and tables','WARNING',:nb || ' instead of at least 170 but maybe you are checking APL < 2209'));
IF :nb < 172
THEN
:results.insert(('Bad # of APL types and tables','WARNING',:nb || ' instead of at least 172 but maybe you are checking APL < 2209'));
ELSE
:results.insert(('Good # of APL types and tables','OK',:nb));
END IF;
ELSE
:results.insert(('Good # of APL types and tables','OK',:nb));
IF :nb < 126
THEN
:results.insert(('Bad # of APL types and tables','WARNING',:nb || ' instead of at least 126 but maybe you are checking APL < 2223'));
ELSE
:results.insert(('Good # of APL types and tables','OK',:nb));
END IF;
END IF;
SELECT COUNT(*) into nb FROM (SELECT "PROCEDURE_NAME" FROM "PUBLIC"."PROCEDURES" WHERE "SCHEMA_NAME" = 'SAP_PA_APL' AND "PROCEDURE_NAME" LIKE 'sap.pa.apl.%' UNION ALL SELECT "FUNCTION_NAME" FROM "PUBLIC"."FUNCTIONS" WHERE "SCHEMA_NAME" = 'SAP_PA_APL' AND "FUNCTION_NAME" LIKE 'sap.pa.apl.%') ;
IF :nb <154
SELECT COUNT(*) into nb FROM (SELECT DISTINCT "PROCEDURE_NAME" FROM "PUBLIC"."PROCEDURES" WHERE "SCHEMA_NAME" = 'SAP_PA_APL' AND "PROCEDURE_NAME" LIKE 'sap.pa.apl.%' UNION ALL SELECT DISTINCT "FUNCTION_NAME" FROM "PUBLIC"."FUNCTIONS" WHERE "SCHEMA_NAME" = 'SAP_PA_APL' AND "FUNCTION_NAME" LIKE 'sap.pa.apl.%') ;
IF :nb <156
THEN
:results.insert(('Bad # of high level APL APIs','WARNING',:nb ||' instead of at least 154 but maybe you are checking APL < 2209'));
ELSE
Expand All @@ -458,7 +498,7 @@ BEGIN
DECLARE is_hce BOOLEAN = "IS_HCE"();
DECLARE apl_apis_available INTEGER;
DECLARE effective_apl_apis_available INTEGER;
DECLARE who_am_i NVARCHAR(1000);
DECLARE who_am_i NVARCHAR(1000) = CURRENT_USER;
DECLARE missing_apis "CHECK_RESULTS_T";
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
Expand All @@ -472,7 +512,6 @@ BEGIN
-- So the check is done only for HANA On Premise
if :is_hce = False
then
SELECT CURRENT_USER into who_am_i FROM DUMMY;
SELECT COUNT(*) into effective_apl_apis_available FROM "PUBLIC"."EFFECTIVE_PRIVILEGES"
WHERE "USER_NAME" = :who_am_i
AND "SCHEMA_NAME" = 'SAP_PA_APL'
Expand Down Expand Up @@ -535,13 +574,13 @@ BEGIN
:results.insert(('____________________________','',''));
:results.insert(('Checking APL basic run time','',''));

:results.insert(('Checking PING (direct mode)','',''));
:results.insert(('Checking PING (direct mode)','',''));
-- use an exec so this code can always be compiled
EXECUTE IMMEDIATE 'CALL _SYS_AFL.APL_AREA_PING_PROC(:ping_direct)' into ping_direct;
ping_results = SELECT 'ping direct' AS "KEY","name" AS "STATUS","value" AS "DETAILS" FROM :ping_direct;
:results.insert(:ping_results);
:results.insert(('Calling direct PING successful','OK',''));
:results.insert(('Checking PING (proc mode)','',''));
EXECUTE IMMEDIATE 'CALL _SYS_AFL.APL_AREA_PING_PROC(:ping_direct)' into ping_direct;
ping_results = SELECT 'ping direct' AS "KEY","name" AS "STATUS","value" AS "DETAILS" FROM :ping_direct;
:results.insert(:ping_results);
:results.insert(('Calling direct PING successful','OK',''));
:results.insert(('Checking PING (proc mode)','',''));
IF is_hce = FALSE
THEN
CALL "CHECK_CAN_CALL_APL_PROCEDURE"('sap.pa.apl.base::PING',can_call_ping,can_call_ping_results);
Expand All @@ -551,8 +590,8 @@ BEGIN
-- use an exec so this code can always been compiled
:results.insert(('Try to really call sap.pa.apl.base::PING)','',''));
-- use an exec so this code can always be compiled
EXECUTE IMMEDIATE 'CALL "SAP_PA_APL"."sap.pa.apl.base::PING"(:ping_proc)' into ping_proc;
ping_results = SELECT 'ping proc' AS "KEY","name" AS "STATUS","value" AS "DETAILS" FROM :ping_proc;
EXECUTE IMMEDIATE 'CALL "SAP_PA_APL"."sap.pa.apl.base::PING"(:ping_proc)' into ping_proc;
ping_results = SELECT 'ping proc' AS "KEY","name" AS "STATUS","value" AS "DETAILS" FROM :ping_proc;
:results.insert(:ping_results);
:results.insert(('Calling proc PING successful','OK',''));
IF :is_hce = true
Expand Down Expand Up @@ -1194,7 +1233,7 @@ BEGIN
DECLARE out_indic "sap.pa.apl.base::BASE.T.INDICATORS";
DECLARE model "sap.pa.apl.base::BASE.T.MODEL_BIN_OID";
DECLARE cancall_results "CHECK_RESULTS_T";
DECLARE who_am_i NVARCHAR(1000);
DECLARE who_am_i NVARCHAR(1000) = CURRENT_USER;
DECLARE can_call_train NVARCHAR(1000);
DECLARE nb INTEGER;
DECLARE is_hce BOOLEAN = "IS_HCE"();
Expand All @@ -1213,7 +1252,6 @@ BEGIN
CALL "CHECK_CAN_CALL_APL_PROCEDURE"('sap.pa.apl.base::CREATE_MODEL_AND_TRAIN',can_call_train,can_call_results);
:results.insert(:can_call_results);
END IF;
SELECT CURRENT_USER into who_am_i FROM DUMMY;
-- we always try to do the call : maybe we missed something
-- use an exec so this code can always been compiled
:results.insert(('Try to really call sap.pa.apl.base::CREATE_MODEL_AND_TRAIN','',''));
Expand Down Expand Up @@ -1250,7 +1288,7 @@ BEGIN
DECLARE train_procedure_results "CHECK_RESULTS_T";
DECLARE who_am_i NVARCHAR(1000);
DECLARE nb_issues INT;
DECLARE has_scriptserver NVARCHAR(100);
DECLARE has_scriptserver NVARCHAR(100) = "HAS_SCRIPTSERVER"();
DECLARE error_message NCLOB;
DECLARE ERROR_APL condition for SQL_ERROR_CODE 10001;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
Expand All @@ -1272,10 +1310,9 @@ BEGIN
ELSE
:prerequisite_results.insert(('===== APL is installed !! =====','OK',''));
END IF;
SELECT "HAS_SCRIPTSERVER"() into has_scriptserver FROM DUMMY;
IF :has_scriptserver = 'MAYBE'
THEN
:prerequisite_results.insert(('===== Script Server cannot be checked !! =====','WARNING','APL needs a script server but it cannot be checked...'));
:prerequisite_results.insert(('===== Script Server cannot be checked !! =====','WARNING','APL needs a script server but it cannot be checked with this user...'));
END IF;
IF :has_scriptserver = 'KO'
THEN
Expand All @@ -1287,22 +1324,26 @@ BEGIN
END IF;
:final_results.insert(:prerequisite_results);

IF "HAS_APL"() = TRUE
IF "HAS_APL"() = TRUE AND :has_scriptserver <> 'KO'
THEN
CALL "CHECK_APL_INSTALL"(:install_results);
:final_results.insert(:install_results);
CALL "CHECK_APL_STRANGE_ISSUES"(:strange_issues_results);
:final_results.insert(:strange_issues_results);
CALL "CHECK_APL_BASIC_RUNTIME"(:basic_runtime_results);
CALL "CHECK_APL_BASIC_RUNTIME"(:basic_runtime_results);
:final_results.insert(:basic_runtime_results);
CALL "CHECK_TRAIN_PROCEDURE_MODE"(:train_procedure_results);
CALL "CHECK_TRAIN_PROCEDURE_MODE"(:train_procedure_results);
:final_results.insert(:train_procedure_results);
CALL "ANALYZE_CHECKS"(:final_results,:analyze_results);
:final_results.insert(('==============================','',''));
:final_results.insert(('==============================','',''));
:final_results.insert(:analyze_results);
:final_results.insert(('==============================','',''));
:final_results.insert(('==============================','',''));
ELSE
:final_results.insert(('==============================','',''));
:final_results.insert(('Cannot proceed to analysis','ISSUE','No Script Server'));
:final_results.insert(('==============================','',''));
END IF;
-- keep using LOWER. This is not a mistake
SELECT LOWER(SESSION_USER) into who_am_i FROM "DUMMY";
Expand Down
Loading

0 comments on commit 484d4df

Please sign in to comment.