diff options
Diffstat (limited to 'policy-management')
5 files changed, 25 insertions, 959 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApi.java b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApi.java index 8edf394e..27b96999 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApi.java +++ b/policy-management/src/main/java/org/onap/policy/drools/features/PolicyEngineFeatureApi.java @@ -182,7 +182,7 @@ public interface PolicyEngineFeatureApi extends OrderedService { * * @return true if this feature intercepts and takes ownership * of the operation preventing the invocation of - * lower priority features. False, otherwise.. + * lower priority features. False, otherwise. */ default boolean afterLock(PolicyEngine engine) { return false; @@ -281,7 +281,7 @@ public interface PolicyEngineFeatureApi extends OrderedService { * operation preventing the invocation of lower priority features. Null, * otherwise */ - default PolicyResourceLockManager beforeCreateLockManager(PolicyEngine engine, Properties properties) { + default PolicyResourceLockManager beforeCreateLockManager() { return null; } diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java index 0bc2318b..203d6bf2 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java @@ -342,7 +342,7 @@ class PolicyEngineManager implements PolicyEngine { private void createLockManager(Properties properties) { for (PolicyEngineFeatureApi feature : getEngineProviders()) { try { - this.lockManager = feature.beforeCreateLockManager(this, properties); + this.lockManager = feature.beforeCreateLockManager(); if (this.lockManager != null) { logger.info("overridden lock manager is {}", this.lockManager); return; @@ -941,7 +941,7 @@ class PolicyEngineManager implements PolicyEngine { @Override public void run() { try { - doSleep(SHUTDOWN_MAX_GRACE_TIME); + doSleep(); logger.warn("{}: abnormal termination - shutdown graceful time period expiration", PolicyEngineManager.this); } catch (final InterruptedException e) { @@ -960,18 +960,18 @@ class PolicyEngineManager implements PolicyEngine { ex.getMessage(), ex)); logger.info("{}: exit", PolicyEngineManager.this); - doExit(0); + doExit(); } } // these may be overridden by junit tests - protected void doSleep(long sleepMs) throws InterruptedException { - Thread.sleep(sleepMs); + protected void doSleep() throws InterruptedException { + Thread.sleep(ShutdownThread.SHUTDOWN_MAX_GRACE_TIME); } - protected void doExit(int code) { - System.exit(code); + protected void doExit() { + System.exit(0); } } diff --git a/policy-management/src/main/server-gen/bin/db-migrator b/policy-management/src/main/server-gen/bin/db-migrator deleted file mode 100644 index 64d0fcf1..00000000 --- a/policy-management/src/main/server-gen/bin/db-migrator +++ /dev/null @@ -1,635 +0,0 @@ -#!/usr/bin/env sh - -# ============LICENSE_START======================================================= -# ONAP -# ================================================================================ -# Copyright (C) 2017-2022 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END========================================================= - -# ##################################################################### -# -# Upgrade/Downgrade SQL File Name Format: -# -# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql -# -# This tool operates on a migration working directory at -# -# $POLICY_HOME/etc/db/migration -# -# Upgrade/Downgrade files for each schema (aka database) names to be maintained -# by this tool are located at -# -# $POLICY_HOME/etc/db/migration/<schema-name>/sql -# -# The nature of the migration directories is dynamic. -# Other tooling aware of when migrations are needed are in charge to populate -# the migrations directory accordingly. -# -# One of these tools is the 'features' when a feature with DB requirements -# is 'enabled', the upgrade scripts will be made present in the migration directory. -# When a features is 'disabled' downgrade scripts will be made available in the -# migration directory. -# -# The 'policy' tool via its operations 'status' or 'start' will signal the -# need to perform upgrade or downgrade for a given schema. -# -# At any given time the following invariant must be preserved in any given -# $POLICY_HOME/etc/db/migration/<schema-name>/sql directory -# -# There is only upgrade scripts, or only downgrade scripts, or none. -# -# ##################################################################### - -source ${POLICY_HOME}/etc/profile.d/env.sh - -METADATA_DB=migration -METADATA_TABLE=${METADATA_DB}.metadata_versions -MIGRATION_DIR=${POLICY_HOME}/etc/db/migration -ZERO_VERSION="0" -UPGRADE_SQL_SUFFIX=".upgrade.sql" -DOWNGRADE_SQL_SUFFIX=".downgrade.sql" - -SQL_QUOTES="SET SESSION SQL_MODE=ANSI_QUOTES;" - -##################################################### -# usage -##################################################### - -function usage() { - echo - echo -e "syntax: $(basename "$0") " - echo -e "\t -s <schema-name> " - echo -e "\t [-b <migration-dir>] " - echo -e "\t [-f <from-version>]" - echo -e "\t [-t <target-version>]" - echo -e "\t -o <operations> " - echo - echo -e "\t where <operations>=upgrade|downgrade|auto|version|erase|report" - echo - echo - echo -e "Configuration Options:" - echo -e "\t -s|--schema|--database: schema to operate on ('ALL' to apply on all)" - echo -e "\t -b|--basedir: overrides base DB migration directory" - echo -e "\t -f|--from: overrides current release version for operations" - echo -e "\t -t|--target: overrides target release to upgrade/downgrade" - echo - echo -e "Operations:" - echo -e "\t upgrade: upgrade operation" - echo -e "\t downgrade: performs a downgrade operation" - echo -e "\t auto: autonomous operation, determines upgrade or downgrade" - echo -e "\t version: returns current version, and in conjunction if '-f' sets the current version" - echo -e "\t erase: erase all data related <schema> (use with care)" - echo -e "\t report: migration detailed report on an schema" - echo -e "\t ok: is the migration status valid" - echo - echo -} - -##################################################### -# ensure global metadata -##################################################### - -function ensure_metadata -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- ensure_metadata --" - set -x - fi - - local sql rc - - sql="CREATE DATABASE IF NOT EXISTS ${METADATA_DB};" - ${MYSQL} --execute "${sql}" - rc=$? - if [ ${rc} -ne 0 ]; then - return ${rc} - fi - - sql="CREATE TABLE IF NOT EXISTS ${METADATA_TABLE} " - sql=${sql}"(name VARCHAR(60) NOT NULL, version VARCHAR(20), PRIMARY KEY(name));" - ${MYSQL} --execute "${sql}" - return $? -} - - -##################################################### -# ensure metadata on a per schema basis -##################################################### - -function ensure_metadata_schema -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- ensure_metadata_schema --" - set -x - fi - - local sql rc - - sql="CREATE TABLE IF NOT EXISTS ${METADATA_HISTORY} " - sql=${sql}"(script VARCHAR(80) NOT NULL, operation VARCHAR(10), success VARCHAR(1), " - sql=${sql}"atTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " - sql=${sql}"PRIMARY KEY(script));" - ${MYSQL} --execute "${sql}" - rc=$? - if [ ${rc} -ne 0 ]; then - return ${rc} - fi - - sql="CREATE DATABASE IF NOT EXISTS ${SCHEMA_DB};" - ${MYSQL} --execute "${sql}" - return $? -} - - -##################################################### -# target_release -##################################################### - -function target_release -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- target_release --" - set -x - fi - - local sql sqlName upgradeSqls downgradeSqls - - TARGET_UPGRADE_RELEASE=${ZERO_VERSION} - TARGET_DOWNGRADE_RELEASE=${ZERO_VERSION} - - upgradeSqls=$(ls -v -r "${UPGRADE_DIR}"/*"${UPGRADE_SQL_SUFFIX}" 2> /dev/null) - for sql in ${upgradeSqls}; do - sqlName=$(basename "${sql}") - TARGET_UPGRADE_RELEASE="${sqlName%-*}" - break - done - - # default unless overriden - TARGET_DOWNGRADE_RELEASE="${ZERO_VERSION}" -} - -##################################################### -# is_upgrade -##################################################### - -function is_upgrade -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- is_upgrade --" - set -x - fi - - local upgradeSqls - - upgradeSqls=$(ls "${UPGRADE_DIR}"/*"${UPGRADE_SQL_SUFFIX}" 2> /dev/null) - if [ -z "${upgradeSqls}" ]; then - return 1 - else - return 0 - fi -} - - -##################################################### -# is_downgrade -##################################################### - -function is_downgrade -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- is_downgrade --" - set -x - fi - - local downgradeSqls - - downgradeSqls=$(ls "${DOWNGRADE_DIR}"/*"${DOWNGRADE_SQL_SUFFIX}" 2> /dev/null) - if [ -z "${downgradeSqls}" ]; then - return 1 - else - return 0 - fi -} - - -##################################################### -# set_current_release -##################################################### - -function set_current_release -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- set_current_release --" - set -x - fi - - CURRENT_RELEASE="${1}" - - local sql - sql="INSERT INTO ${METADATA_TABLE} (name, version) " - sql=${sql}"VALUES('${SCHEMA}', '${CURRENT_RELEASE}') " - sql=${sql}"ON DUPLICATE KEY UPDATE version='${CURRENT_RELEASE}';" - - ${MYSQL} --execute "${sql}" - return $? -} - -##################################################### -# current_release -##################################################### - -function current_release -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- current_release --" - set -x - fi - - local rc - local query="SELECT version FROM ${METADATA_TABLE} WHERE name='${SCHEMA}'" - - CURRENT_RELEASE=$(${MYSQL} --skip-column-names --silent --execute "${query}") - if [ -z "${CURRENT_RELEASE}" ]; then - set_current_release "${ZERO_VERSION}" - return $? - fi - - return 0 -} - -##################################################### -# execute sql script history -##################################################### - -function track_script -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- track_script $* --" - set -x - fi - - local script="${1}" operation="${2}" success="${3}" - local sql="INSERT INTO ${METADATA_HISTORY}(script,operation,success,atTime) " - sql=${sql}"VALUES ('${script}','${operation}','${success}',now()) " - sql=${sql}"ON DUPLICATE KEY UPDATE operation=values(operation), success=values(success), atTime=values(atTime);" - - ${MYSQL} --execute "${sql}" - return $? -} - - -##################################################### -# execute sql script -##################################################### - -function run_script -{ - if [ "${DEBUG}" == "y" ]; then - echo "-- run_script $* --" - set -x - fi - - local operation="${1}" script="${2}" scriptPath="${3}" - - echo - echo "> ${operation} ${script}" - - ${MYSQL} --verbose < "${scriptPath}" - local rc=$? - if [ ${rc} -ne 0 ]; then - success="0" - else - success="1" - fi - - track_script "${script}" "${operation}" "${success}" - - return ${rc} -} - -##################################################### -# upgrade -##################################################### - -function upgrade -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- upgrade --" - set -x - fi - - local sqlName sqlFile schemaVersion upgradeSqls rc - - ${MYSQL} --execute "USE ${SCHEMA_DB}" - - echo "upgrade: ${CURRENT_RELEASE} -> ${TARGET_UPGRADE_RELEASE}" - - if [ ${CURRENT_RELEASE} \< ${TARGET_UPGRADE_RELEASE} ]; then - upgradeSqls=$(ls -v "${UPGRADE_DIR}"/*"${UPGRADE_SQL_SUFFIX}" 2> /dev/null) - for sqlFile in ${upgradeSqls}; do - sqlName=$(basename "${sqlFile}") - schemaVersion="${sqlName%-*}" - if [ "${schemaVersion}" -gt "${CURRENT_RELEASE}" ] && \ - [ "${schemaVersion}" -le "${TARGET_UPGRADE_RELEASE}" ]; then - run_script "upgrade" "${sqlName}" "${sqlFile}" - rc=$? - if [ ${rc} -ne 0 ]; then - echo "${SCHEMA}: upgrade aborted at ${schemaVersion} by script ${sqlName}" - set_current_release "${schemaVersion}" - return ${rc} - fi - fi - done - - set_current_release "${TARGET_UPGRADE_RELEASE}" - fi - - return 0 -} - -##################################################### -# downgrade -##################################################### - -function downgrade -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- downgrade --" - set -x - fi - - local sqlName sqlFile schemaVersion downgradeSqls rc - - ${MYSQL} --execute "USE ${SCHEMA_DB}" - - echo "downgrade: ${CURRENT_RELEASE} -> ${TARGET_DOWNGRADE_RELEASE}" - - if [ ${CURRENT_RELEASE} \> ${TARGET_DOWNGRADE_RELEASE} ]; then - downgradeSqls=$(ls -v -r "${DOWNGRADE_DIR}"/*"${DOWNGRADE_SQL_SUFFIX}" 2> /dev/null) - for sqlFile in ${downgradeSqls}; do - sqlName=$(basename "${sqlFile}") - schemaVersion="${sqlName%-*}" - if [ "${schemaVersion}" -le "${CURRENT_RELEASE}" ] && \ - [ "${schemaVersion}" -gt "${TARGET_DOWNGRADE_RELEASE}" ]; then - run_script "downgrade" "${sqlName}" "${sqlFile}" - rc=$? - if [ ${rc} -ne 0 ]; then - echo "${SCHEMA}: downgrade aborted at ${schemaVersion} by script ${sqlName}" - set_current_release "${schemaVersion}" - return ${rc} - fi - fi - done - - set_current_release "${TARGET_DOWNGRADE_RELEASE}" - fi - - return 0 -} - -##################################################### -# erase -##################################################### - -function erase -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- erase --" - set -x - fi - - local updateMetadata="UPDATE ${METADATA_TABLE} SET version='${ZERO_VERSION}';" - ${MYSQL} --execute "${updateMetadata}" - - local deleteHistory="DELETE FROM ${METADATA_HISTORY};" - ${MYSQL} --execute "${deleteHistory}" - - local dropDB="DROP DATABASE IF EXISTS ${SCHEMA_DB}"; - ${MYSQL} --execute "${dropDB}" -} - -##################################################### -# report -##################################################### - -function report -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- report --" - set -x - fi - - local versionSql="SELECT * FROM ${METADATA_TABLE} WHERE name='${SCHEMA}';" - ${MYSQL} --execute "${versionSql}" - - local historySql="SELECT * FROM ${METADATA_HISTORY} ORDER BY atTime ASC;" - ${MYSQL} --execute "${historySql}" - - okay -} - -function okay -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- okay --" - set -x - fi - - local rc=0 - if is_upgrade; then - if [ "${CURRENT_RELEASE}" = "${TARGET_UPGRADE_RELEASE}" ]; then - echo "${SCHEMA}: OK @ ${CURRENT_RELEASE}" - else - echo "${SCHEMA}: upgrade available: ${CURRENT_RELEASE} -> ${TARGET_UPGRADE_RELEASE}" - rc=1 - fi - else - if [ "${CURRENT_RELEASE}" = "${TARGET_DOWNGRADE_RELEASE}" ]; then - echo "${SCHEMA}: OK @ ${CURRENT_RELEASE}" - else - echo "${SCHEMA}: downgrade available: ${CURRENT_RELEASE} -> ${TARGET_DOWNGRADE_RELEASE}" - rc=1 - fi - fi - - return ${rc} -} - -##################################################### -# MAIN -##################################################### - -if [ "${DEBUG}" = "y" ]; then - echo "-- $0 $* --" - set -x -fi -until [ -z "$1" ]; do - case $1 in - -s|--schema|--database) shift - SCHEMA=$1 - ;; - -b|--basedir) shift - MIGRATION_DIR=$1 - ;; - -t|--target) shift - INPUT_TARGET_RELEASE=$1 - ;; - -f|--from) shift - INPUT_CURRENT_RELEASE=$1 - ;; - -o|--operation) shift - OPERATION=$1 - ;; - *) usage - exit 1 - ;; - esac - shift -done - -case ${OPERATION} in - upgrade) ;; - downgrade) ;; - auto) ;; - version) ;; - erase) ;; - report) ;; - ok) ;; - *) echo "error: invalid operation provided" - usage - exit 1 - ;; -esac - -if [ -z "${SCHEMA}" ]; then - echo "error: a database name must be provided" - usage - exit 2 -fi - -source "${POLICY_HOME}"/etc/profile.d/env.sh - -if [ -z "${SQL_HOST}" ] || [ -z "${SQL_USER}" ] || [ -z "${SQL_PASSWORD}" ]; then - echo "error: no database has been set up" - exit 4 -fi - -if [ -z "${SQL_PORT}" ]; then - export SQL_PORT=3306 -fi - -if [ -z "$MYSQL_CMD" ]; then - MYSQL_CMD="mysql" -fi - -MYSQL="${MYSQL_CMD} -u${SQL_USER} -p${SQL_PASSWORD} -h ${SQL_HOST} -P ${SQL_PORT}" - -if ! ${MYSQL} --execute "show databases;" > /dev/null 2>&1; then - echo "error: No DB connectivity to ${SQL_HOST} for ${SQL_USER}" - exit 5 -fi - -if [ "${SCHEMA}" = "ALL" ]; then - SCHEMA="*" -fi - -SCHEMA_S=$(ls -d "${MIGRATION_DIR}"/${SCHEMA}/ 2> /dev/null) -if [ -z "${SCHEMA_S}" ]; then - echo "error: no databases available" - exit 0 -fi - -if ! ensure_metadata; then - echo "error: migration metadata not accessible" - exit 7 -fi - -rc=0 -for dbPath in ${SCHEMA_S}; do - SCHEMA=$(basename "${dbPath}") - SCHEMA_DB="\`${SCHEMA}\`" - UPGRADE_DIR="${MIGRATION_DIR}"/"${SCHEMA}"/sql - DOWNGRADE_DIR=${UPGRADE_DIR} - METADATA_HISTORY="${METADATA_DB}.\`${SCHEMA}_history\`" - TARGET_RELEASE=${INPUT_TARGET_RELEASE} - CURRENT_RELEASE=${INPUT_CURRENT_RELEASE} - - if is_upgrade && is_downgrade; then - echo "${SCHEMA}: failure: invalid configuration: ${UPGRADE_SQL_SUFFIX} and "\ - "${DOWNGRADE_SQL_SUFFIX} exist under ${DOWNGRADE_DIR}" - rc=1 - continue - fi - - if [ "${operation}" = "auto" ]; then - if is_upgrade; then - operation=upgrade - else - operation=downgrade - fi - fi - - if ! ensure_metadata_schema; then - echo "${SCHEMA}: failure: metadata not accessible for this schema" - continue - fi - - if [ -z "${TARGET_RELEASE}" ]; then - target_release - else - # user asked to override - TARGET_UPGRADE_RELEASE="${TARGET_RELEASE}" - TARGET_DOWNGRADE_RELEASE="${TARGET_RELEASE}" - fi - - if [ -z "${CURRENT_RELEASE}" ]; then - if ! current_release; then - echo "${SCHEMA}: failure: cannot obtain current release" - continue - fi - else - if ! set_current_release "${CURRENT_RELEASE}"; then - echo "${SCHEMA}: failure: cannot set current release" - continue - fi - fi - - case ${OPERATION} in - upgrade) if upgrade; then - echo "${SCHEMA}: OK: upgrade (${CURRENT_RELEASE})" - else - rc=1 - echo "${SCHEMA}: failure: upgrade to release ${TARGET_UPGRADE_RELEASE} (${CURRENT_RELEASE})" - fi - ;; - downgrade) if downgrade; then - echo "${SCHEMA}: OK: downgrade (${CURRENT_RELEASE})" - else - rc=1 - echo "${SCHEMA}: failure: downgrade to release ${TARGET_DOWNGRADE_RELEASE} (${CURRENT_RELEASE})" - fi - ;; - version) echo "${SCHEMA}: ${CURRENT_RELEASE}" - ;; - erase) erase - ;; - report) report - ;; - ok) okay - ;; - esac - -done -exit $rc diff --git a/policy-management/src/main/server-gen/bin/features b/policy-management/src/main/server-gen/bin/features index 3343ffc4..01b77b1c 100644 --- a/policy-management/src/main/server-gen/bin/features +++ b/policy-management/src/main/server-gen/bin/features @@ -5,6 +5,7 @@ # ONAP POLICY # ================================================================================ # Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. +# Modifications Copyright (C) 2024 Nordix Foundation. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -35,10 +36,6 @@ # | | L─ <dependent-jar>+ # │ L─ feature/ # │ L─ <feature-jar> -# L─ [db]/ -# │ L─ <db-name>/+ -# │ L─ sql/ -# │ L─ <sql-scripts>* # L─ [artifacts]/ # L─ <artifact>+ # L─ [install] @@ -60,16 +57,6 @@ # of pdp-d that are necessary for <feature-name> to operate # correctly. # lib/feature the single feature jar that implements the feature. -# [db] database directory, if the feature contains sql. -# [db]/<db-name> database to which underlying sql scripts should be applied against. -# ideally, <db-name> = <feature-name> so it is easily to associate -# the db data with a feature itself. Ideally, since a feature is -# a somewhat independent isolated unit of functionality,the <db-name> -# database ideally isolates all its data. -# [db]/<db-name>/sql directory with all the sql scripts. -# [db]/<db-name>/sql/<sql-scripts> for this feature sql scripts -# upgrade scripts should be suffixed with ".upgrade.sql" -# downgrade scripts should be suffixed with ".downgrade.sql" # [artifacts] maven artifacts to be deployed in a maven repository. # [artifacts]/<artifact> maven artifact with identifiable maven coordinates embedded # in the artifact. @@ -87,10 +74,10 @@ # Operations: # install: installs a feature # uninstall: uninstalls a feature -# enable : enables 1) dependencies, 2) configuration, 3) binaries 4) database, 5) artifacts, -# 6) feature, 7) customization. -# disable: disables 1) dependencies, 2) configuration, 3) binaries, 4) database, 5) feature, -# 6) customization +# enable : enables 1) dependencies, 2) configuration, 3) binaries 4) artifacts, +# 5) feature, 6) customization. +# disable: disables 1) dependencies, 2) configuration, 3) binaries, 4) feature, +# 5) customization # status : status of a feature # # 'enable' operation details: @@ -99,10 +86,8 @@ # 2. sets symbolic links to feature dependencies in pdp-d classpath ($POLICY_HOME/lib) # 3. sets symbolic links to feature configuration in pdp-d configuration directory ($POLICY_HOME/config) # 4. sets symbolic links to feature executables in pdp-d bin directory ($POLICY_HOME/bin) -# 5. sets symbolic links to feature upgrade scripts and removes links to downgrade scripts (if any) -# in the pdp-d migration directory ($POLICY_HOME/etc/db/migration). -# 6. deploys any maven artifacts in the maven repositories in use (if any) -# 7. cd to the feature 'install' directory an executes (if exists) the 'enable' script to allow for specific +# 5. deploys any maven artifacts in the maven repositories in use (if any) +# 6. cd to the feature 'install' directory an executes (if exists) the 'enable' script to allow for specific # customizations for this feature. # # 'disable' operation details: @@ -111,16 +96,9 @@ # 2. removes symbolic links to feature dependencies in pdp-d classpath ($POLICY_HOME/lib) # 3. removes symbolic links to feature configuration in pdp-d configuration directory ($POLICY_HOME/config) # 4. removes symbolic links to feature executables in pdp-d bin directory ($POLICY_HOME/bin) -# 5. removes symbolic links to feature upgrade scripts and sets links to downgrade scripts (if any) -# in the pdp-d migration directory ($POLICY_HOME/etc/db/migration). -# 6. cd to the feature 'install' directory an executes (if exists) the 'disable' script to allow for specific +# 5. cd to the feature 'install' directory an executes (if exists) the 'disable' script to allow for specific # customizations for this feature. # -# Notes for DB enabled features: -# A. Upgrade/Downgrade SQL File Name Format: -# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql -# B. See related tooling: db-migrator, deploy-artifact, and policy -# # Example: # # POLICY_HOME/ @@ -155,7 +133,6 @@ fi LIB=${POLICY_HOME}/lib CONFIG=${POLICY_HOME}/config BIN=${POLICY_HOME}/bin -DB=${POLICY_HOME}/etc/db/migration FEATURES=${POLICY_HOME}/features if [ ! -d "${LIB}" ]; then @@ -171,10 +148,6 @@ fi # ensure that the directory exists mkdir -p "${FEATURES}" 2> /dev/null -if [ ! -d "${DB}" ]; then - mkdir -p "${DB}" -fi - # relative per Feature Directory Paths FEATURE_DEPS="lib/dependencies" @@ -183,11 +156,6 @@ FEATURE_CONFIG="config" FEATURE_BIN="bin" FEATURE_INSTALL="install" FEATURE_ARTIFACTS="artifacts" -FEATURE_DB="db" -FEATURE_SQL="sql" - -UPGRADE_SQL_SUFFIX=".upgrade.sql" -DOWNGRADE_SQL_SUFFIX=".downgrade.sql" featureJars=$(find "${FEATURES}" -name "feature-*.jar" -type f -exec basename {} \; 2> /dev/null) @@ -386,39 +354,6 @@ function enableBinAnalysis () } # ########################################################## -# enableDbAnalysis (featureName): -# reports on potential db access problems -# featureName: name of the feature -# ########################################################## -function enableDbAnalysis() -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- enableDbAnalysis $* --" - set -x - fi - - local featureName="$1" - local featureSqls - - if [ -z "${featureName}" ]; then - echo "warning: no feature name" - return 1 - fi - - featureSqls=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null) - if [ -z "${featureSqls}" ]; then - return 0 - fi - - source "${POLICY_HOME}"/etc/profile.d/env.sh - if [ -z "${SQL_HOST}" ] || [ -z "${SQL_USER}" ] || [ -z "${SQL_PASSWORD}" ]; then - echo "warning: DB server is not configured" - fi - - return 0 -} - -# ########################################################## # enableFeatureDeps(featureName): # enables feature dependencies # featureName: name of the feature @@ -500,95 +435,6 @@ function enableFeatureBin() } # ########################################################## -# enableFeatureDbSchema(featureName): -# enables feature DB Schema configuration -# featureName: name of the feature -# ########################################################## -function enableFeatureDbSchema() -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- enableFeatureDbSchema $* --" - set -x - fi - - local featureName="$1" - local featureDbPath="$2" - local schemaName="$3" - - if [ -z "${featureName}" ]; then - echo "warning: no feature name" - return 1 - fi - - if [ -z "${featureDbPath}" ]; then - echo "warning: ${featureName} contains no DB path" - return 2 - fi - - if [ -z "${schemaName}" ]; then - echo "warning: feature ${featureName} contains no schema name" - return 3 - fi - - rc=0 - sqlUpgradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${UPGRADE_SQL_SUFFIX} 2> /dev/null) - for sqlUpgradeScript in ${sqlUpgradeScripts}; do - if [ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]; then - mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null - fi - ln -s -f "${sqlUpgradeScript}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/ - done - - sqlDowngradeScripts=$(ls "${featureDbPath%/}"/${FEATURE_SQL}/*${DOWNGRADE_SQL_SUFFIX} 2> /dev/null) - for sqlDowngradeScript in ${sqlDowngradeScripts}; do - if [ -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]; then - sqlName=$(basename "${sqlDowngradeScript}") - rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null - else - echo "warning: feature ${featureName} only contains downgrade scripts" - rc=4 - break - fi - done - - if [ -n "${sqlUpgradeScripts}" ] || [ -n "${sqlDowngradeScripts}" ]; then - DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok - fi - - return ${rc} -} - -# ########################################################## -# enableFeatureDb(featureName): -# enables DB feature configuration -# featureName: name of the feature -# ########################################################## -function enableFeatureDb() -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- enableFeatureDb $* --" - set -x - fi - - local featureName="$1" - local featureDbs featureDbPath schemaName sqls - if [ -z "${featureName}" ]; then - echo "warning: no feature name" - return 1 - fi - - featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null) - for featureDbPath in ${featureDbs}; do - sqls=$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*.sql 2> /dev/null) - if [ -z "${sqls}" ]; then - continue - fi - schemaName=$(basename "${featureDbPath%/}") - enableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}" - done -} - -# ########################################################## # enableFeatureArtifacts(featureName): # deploys maven artifacts # featureName: name of the feature @@ -686,10 +532,6 @@ function enableFeature() if ! enableBinAnalysis "${featureName}"; then return "$?" fi - - if ! enableDbAnalysis "${featureName}"; then - return "$?" - fi # enable feature itself @@ -707,10 +549,6 @@ function enableFeature() enableFeatureBin "${featureName}" - # enable db - - enableFeatureDb "${featureName}" - # enable feature artifacts enableFeatureArtifacts "${featureName}" @@ -839,97 +677,6 @@ function disableFeatureBin() } # ########################################################## -# disableFeatureDbSchema(featureName, featureDbPath, schemaName): -# disables feature db configuration for a schema -# featureName: name of the feature -# ########################################################## -function disableFeatureDbSchema() -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- disableFeatureDbSchema $* --" - set -x - fi - - local featureName="$1" featureDbPath="$2" schemaName="$3" - local upgradeFeatureSqls downgradeFeatureSqls featureSql sqlDir sqlName schemaDir schemaName - - if [ -z "${featureName}" ]; then - echo "warning: no feature name" - return 1 - fi - - if [ -z "${featureDbPath}" ]; then - echo "warning: ${featureName} contains no DB path" - return 2 - fi - - if [ -z "${schemaName}" ]; then - echo "warning: feature ${featureName} contains no schema name" - return 3 - fi - - if [ -z "${featureName}" ]; then - echo "warning: no feature name" - return 1 - fi - - upgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${UPGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null) - for featureSql in ${upgradeFeatureSqls}; do - sqlName=$(basename "${featureSql}") - sqlDir=$(dirname "${featureSql}") - schemaDir=$(dirname "${sqlDir}") - schemaName=$(basename "${schemaDir}") - rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null - done - - downgradeFeatureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/"${schemaName}"/"${FEATURE_SQL}"/*"${DOWNGRADE_SQL_SUFFIX}" -type f -maxdepth 1 2> /dev/null) - for featureSql in ${downgradeFeatureSqls}; do - sqlName=$(basename "${featureSql}") - sqlDir=$(dirname "${featureSql}") - schemaDir=$(dirname "${sqlDir}") - schemaName=$(basename "${schemaDir}") - if [ ! -d "${DB}"/"${schemaName}"/${FEATURE_SQL} ]; then - mkdir -p "${DB}"/"${schemaName}"/${FEATURE_SQL} 2> /dev/null - fi - ln -s -f "${featureSql}" "${DB}"/"${schemaName}"/${FEATURE_SQL}/ - done - - if [ -n "${sqlUpgradeScripts}" ] || [ -n "${sqlDowngradeScripts}" ]; then - DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok - fi -} - -# ########################################################## -# disableFeatureDb(featureName): -# disables feature db configuration -# featureName: name of the feature -# ########################################################## -function disableFeatureDb() -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- disableFeatureDb $* --" - set -x - fi - - local featureName="$1" - local featureDbPath featureDbs schemaName - - if [ -z "${featureName}" ]; then - echo "warning: no feature name" - return 1 - fi - - featureDbs=$(ls -d "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/ 2> /dev/null) - for featureDbPath in ${featureDbs}; do - if [ -z "$(ls "${featureDbPath%/}"/"${FEATURE_SQL}"/*${UPGRADE_SQL_SUFFIX} 2> /dev/null)" ]; then - continue - fi - schemaName=$(basename "${featureDbPath%/}") - disableFeatureDbSchema "${featureName}" "${featureDbPath%/}" "${schemaName}" - done -} - -# ########################################################## # disableFeature(featureName): disables a feature # featureName: name of the feature # ########################################################## @@ -966,10 +713,6 @@ function disableFeature() disableFeatureBin "${featureName}" - # disable DB SQL scripts if any - - disableFeatureDb "${featureName}" - # run custom disable if any customOpScript "${featureName}" "disable" @@ -1080,47 +823,6 @@ function installFeatures fi } -# ########################################################## -# uninstallFeatureDb(featureName): -# uninstalls the feature db configuration -# featureName: name of the feature -# ########################################################## -function uninstallFeatureDb() -{ - if [ "${DEBUG}" = "y" ]; then - echo "-- uninstallFeatureDb $* --" - set -x - fi - - local featureName="$1" - local featureSqls sqlDir sqlName schemaDir schemaName schemaNames leftSqls - - if [ -z "${featureName}" ]; then - echo "warning: no feature name" - return 1 - fi - - featureSqls=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_DB}"/*/${FEATURE_SQL}/*.sql -type f -maxdepth 1 2> /dev/null) - for featureSql in ${featureSqls}; do - sqlName=$(basename "${featureSql}") - sqlDir=$(dirname "${featureSql}") - schemaDir=$(dirname "${sqlDir}") - schemaName=$(basename "${schemaDir}") - schemaNames="${schemaNames} ${schemaName}" - rm -f "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/"${sqlName}" 2> /dev/null - done - for schemaName in ${schemaNames}; - do - leftSqls=$(ls "${DB}"/"${schemaName}"/"${FEATURE_SQL}"/*.sql 2> /dev/null) - if [ -n "${leftSqls}" ]; then - if ! DEBUG=${DEBUG} db-migrator -s "${schemaName}" -o ok; then - echo -n "warning: ${featureName}: ${schemaName}: database data is leftover. " - echo -n "Consider cleaning left over data with 'db-migrator'." - fi - fi - done -} - ############################################################ # uninstallFeature <feature-name> ... ############################################################ @@ -1138,7 +840,6 @@ function uninstallFeature return fi disableFeature "${featureName}" - uninstallFeatureDb "${featureName}" customOpScript "${featureName}" "uninstall" if [ -n "${FEATURES}" ] && [ -n "${featureName}" ]; then diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java index 4006c9ed..8dae42e2 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java @@ -217,7 +217,7 @@ class PolicyEngineManagerTest { when(lockmgr.lock()).thenReturn(true); when(lockmgr.unlock()).thenReturn(true); - when(prov2.beforeCreateLockManager(any(), any())).thenReturn(lockmgr); + when(prov2.beforeCreateLockManager()).thenReturn(lockmgr); when(prov1.getName()).thenReturn(FEATURE1); when(prov2.getName()).thenReturn(FEATURE2); @@ -524,7 +524,7 @@ class PolicyEngineManagerTest { @Test void testCreateLockManagerHaveProvider() { // first provider throws an exception - when(prov1.beforeCreateLockManager(any(), any())).thenThrow(new RuntimeException(EXPECTED)); + when(prov1.beforeCreateLockManager()).thenThrow(new RuntimeException(EXPECTED)); mgr.configure(properties); assertSame(lockmgr, mgr.getLockManager()); @@ -535,7 +535,7 @@ class PolicyEngineManagerTest { */ @Test void testCreateLockManagerSimpleEx() { - when(prov2.beforeCreateLockManager(any(), any())).thenReturn(null); + when(prov2.beforeCreateLockManager()).thenReturn(null); // invalid property for SimpleLockManager properties.setProperty(SimpleLockProperties.EXPIRE_CHECK_SEC, "abc"); @@ -550,7 +550,7 @@ class PolicyEngineManagerTest { */ @Test void testCreateLockManagerSimple() { - when(prov2.beforeCreateLockManager(any(), any())).thenReturn(null); + when(prov2.beforeCreateLockManager()).thenReturn(null); mgr.configure(properties); assertInstanceOf(SimpleLockManager.class, mgr.getLockManager()); @@ -2086,8 +2086,8 @@ class PolicyEngineManagerTest { private class MyShutdown extends ShutdownThread { @Override - protected void doSleep(long sleepMs) throws InterruptedException { - threadSleepMs = sleepMs; + protected void doSleep() throws InterruptedException { + threadSleepMs = 300L; if (shouldInterrupt) { throw new InterruptedException(EXPECTED); @@ -2095,8 +2095,8 @@ class PolicyEngineManagerTest { } @Override - protected void doExit(int code) { - threadExitCode = code; + protected void doExit() { + threadExitCode = 0; } @Override |