diff options
Diffstat (limited to 'policy-management/src/main/server-gen/bin')
11 files changed, 1765 insertions, 1790 deletions
diff --git a/policy-management/src/main/server-gen/bin/add-secured-participant b/policy-management/src/main/server-gen/bin/add-secured-participant index d6843fee..4a776703 100644 --- a/policy-management/src/main/server-gen/bin/add-secured-participant +++ b/policy-management/src/main/server-gen/bin/add-secured-participant @@ -1,17 +1,17 @@ -#! /bin/bash +#!/usr/bin/env ash ### # ============LICENSE_START======================================================= # policy-management # ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2017-2020 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. @@ -21,91 +21,91 @@ ### function usage() { - echo -n "Usage: $(basename $0) " - echo -n "[(-d|--debug)] " - echo -n "(-h|--host) <bus-host> " - echo -n "[(-p|--port) <bus-port>] " - echo -n "(-k|--key) <api-key> " - echo -n "(-s|--secret) <api-secret> " - echo -n "(-P|--producer-key) <producer-key> " - echo -n "(-C|--consumer-key) <consumer-key> " - echo "(-t|--topic) <topic> " + echo -n "Usage: $(basename $0) " + echo -n "[(-d|--debug)] " + echo -n "(-h|--host) <bus-host> " + echo -n "[(-p|--port) <bus-port>] " + echo -n "(-k|--key) <api-key> " + echo -n "(-s|--secret) <api-secret> " + echo -n "(-P|--producer-key) <producer-key> " + echo -n "(-C|--consumer-key) <consumer-key> " + echo "(-t|--topic) <topic> " } BUS_PORT=3904 # command line options parsing -until [[ -z "$1" ]]; do - case $1 in - -d|--debug) set -x - ;; - -h|--host) shift - BUS_HOST=$1 - ;; - -p|--port) shift - BUS_PORT=$1 - ;; - -k|--key) shift - API_KEY=$1 - ;; - -s|--secret) shift - API_SECRET=$1 - ;; - -t|--topic) shift - TOPIC=$1 - ;; - -P|--producer-key) shift - URL_CONTEXT="producers" - PRODUCER_KEY=$1 - KEY=$1 - ;; - -C|--consumer-key) shift - URL_CONTEXT="consumers" - CONSUMER_KEY=$1 - KEY=$1 - ;; - *) usage - exit 1 - ;; - esac - shift +until [ -z "$1" ]; do + case $1 in + -d|--debug) set -x + ;; + -h|--host) shift + BUS_HOST=$1 + ;; + -p|--port) shift + BUS_PORT=$1 + ;; + -k|--key) shift + API_KEY=$1 + ;; + -s|--secret) shift + API_SECRET=$1 + ;; + -t|--topic) shift + TOPIC=$1 + ;; + -P|--producer-key) shift + URL_CONTEXT="producers" + PRODUCER_KEY=$1 + KEY=$1 + ;; + -C|--consumer-key) shift + URL_CONTEXT="consumers" + CONSUMER_KEY=$1 + KEY=$1 + ;; + *) usage + exit 1 + ;; + esac + shift done -if [[ -z ${BUS_HOST} ]]; then - echo "An UEB/DMAAP server must be provided." - echo - usage - exit 1 +if [ -z "${BUS_HOST}" ]; then + echo "An UEB/DMAAP server must be provided." + echo + usage + exit 1 fi -if [[ -z ${API_KEY} ]]; then - echo "The API Key must be provided." - usage - exit 2 +if [ -z "${API_KEY}" ]; then + echo "The API Key must be provided." + usage + exit 2 fi -if [[ -z ${API_SECRET} ]]; then - echo "The API Secret must be provided." - usage - exit 3 +if [ -z "${API_SECRET}" ]; then + echo "The API Secret must be provided." + usage + exit 3 fi -if [[ -z ${TOPIC} ]]; then - echo "The Topic Name must be provided." - usage - exit 3 +if [ -z "${TOPIC}" ]; then + echo "The Topic Name must be provided." + usage + exit 3 fi -if [[ -z ${PRODUCER_KEY} && -z ${CONSUMER_KEY} ]]; then - echo "Either the Producer or Consumer options must be provided." - usage - exit 4 +if [ -z "${PRODUCER_KEY}" ] && [ -z "${CONSUMER_KEY}" ]; then + echo "Either the Producer or Consumer options must be provided." + usage + exit 4 fi -if [[ -n ${PRODUCER_KEY} && -n ${CONSUMER_KEY} ]]; then - echo "Only and only one of the Producer or Consumer options must be provided." - usage - exit 5 +if [ -n "${PRODUCER_KEY}" ] && [ -n "${CONSUMER_KEY}" ]; then + echo "Only and only one of the Producer or Consumer options must be provided." + usage + exit 5 fi @@ -114,9 +114,9 @@ DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | ope unset http_proxy curl --silent -X PUT \ - --header "Accept:" \ - --header "X-CambriaDate: ${DATE}" \ - --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ - --header "Content-Type: application/json" \ - --data "{}" \ - http://${BUS_HOST}:${BUS_PORT}/topics/${TOPIC}/${URL_CONTEXT}/${KEY} + --header "Accept:" \ + --header "X-CambriaDate: ${DATE}" \ + --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ + --header "Content-Type: application/json" \ + --data "{}" \ + http://${BUS_HOST}:${BUS_PORT}/topics/${TOPIC}/${URL_CONTEXT}/${KEY} diff --git a/policy-management/src/main/server-gen/bin/create-api-key b/policy-management/src/main/server-gen/bin/create-api-key index ea0ec7ad..d5af491f 100644 --- a/policy-management/src/main/server-gen/bin/create-api-key +++ b/policy-management/src/main/server-gen/bin/create-api-key @@ -1,17 +1,17 @@ -#! /bin/bash +#!/usr/bin/env ash ### # ============LICENSE_START======================================================= # policy-management # ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2017-2020 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. @@ -21,56 +21,56 @@ ### function usage() { - echo -n "Usage: $(basename $0) " - echo -n "[(-d|--debug)] " - echo -n "(-h|--host) <bus-host> " - echo -n "[(-p|--port) <bus-port>] " - echo "(-e|--email) <email>" + echo -n "Usage: $(basename $0) " + echo -n "[(-d|--debug)] " + echo -n "(-h|--host) <bus-host> " + echo -n "[(-p|--port) <bus-port>] " + echo "(-e|--email) <email>" } BUS_PORT=3904 # command line options parsing -until [[ -z "$1" ]]; do - case $1 in - -d|--debug) set -x - ;; - -h|--host) shift - BUS_HOST=$1 - ;; - -p|--port) shift - BUS_PORT=$1 - ;; - -e|--email) shift - EMAIL=$1 - ;; - *) usage - exit 1 - ;; - esac - shift +until [ -z "$1" ]; do + case $1 in + -d|--debug) set -x + ;; + -h|--host) shift + BUS_HOST=$1 + ;; + -p|--port) shift + BUS_PORT=$1 + ;; + -e|--email) shift + EMAIL=$1 + ;; + *) usage + exit 1 + ;; + esac + shift done -if [[ -z ${BUS_HOST} ]]; then - echo "An UEB/DMAAP server must be provided." - echo - usage - exit 1 +if [ -z "${BUS_HOST}" ]; then + echo "An UEB/DMAAP server must be provided." + echo + usage + exit 1 fi -if [[ -z ${EMAIL} ]]; then - echo "An email address must be provided." - usage - exit 2 +if [ -z "${EMAIL}" ]; then + echo "An email address must be provided." + usage + exit 2 fi -REQUEST_API_KEY_BODY=$(< <(cat <<EOF +REQUEST_API_KEY_BODY=$(cat <<EOF { "email": "${EMAIL}", "description": "Generated by PDP-D $(hostname -f)" } EOF -)) +) unset http_proxy curl -s -X POST --data "${REQUEST_API_KEY_BODY}" --header "Content-Type: application/json" http://${BUS_HOST}:${BUS_PORT}/v1/apiKeys/create diff --git a/policy-management/src/main/server-gen/bin/create-secured-topic b/policy-management/src/main/server-gen/bin/create-secured-topic index b0d4d6f2..6e058142 100644 --- a/policy-management/src/main/server-gen/bin/create-secured-topic +++ b/policy-management/src/main/server-gen/bin/create-secured-topic @@ -1,17 +1,17 @@ -#! /bin/bash +#!/usr/bin/env ash ### # ============LICENSE_START======================================================= # policy-management # ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2017-2020 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. @@ -21,16 +21,16 @@ ### function usage() { - echo -n "Usage: $(basename $0) " - echo -n "[(-d|--debug)] " - echo -n "(-h|--host) <bus-host> " - echo -n "[(-p|--port) <bus-port>] " - echo -n "(-k|--key) <api-key> " - echo -n "(-s|--secret) <api-secret> " - echo -n "[(-P|--partition) <partition-count>] " - echo -n "[(-R|--replication) <replication-count>] " - echo "(-t|--topic) <topic> " - echo "" + echo -n "Usage: $(basename $0) " + echo -n "[(-d|--debug)] " + echo -n "(-h|--host) <bus-host> " + echo -n "[(-p|--port) <bus-port>] " + echo -n "(-k|--key) <api-key> " + echo -n "(-s|--secret) <api-secret> " + echo -n "[(-P|--partition) <partition-count>] " + echo -n "[(-R|--replication) <replication-count>] " + echo "(-t|--topic) <topic> " + echo "" } BUS_PORT=3904 @@ -38,81 +38,81 @@ PARTITION_COUNT=1 REPLICATION_COUNT=1 # command line options parsing -until [[ -z "$1" ]]; do - case $1 in - -d|--debug) set -x - ;; - -h|--host) shift - BUS_HOST=$1 - ;; - -p|--port) shift - BUS_PORT=$1 - ;; - -k|--key) shift - API_KEY=$1 - ;; - -s|--secret) shift - API_SECRET=$1 - ;; - -t|--topic) shift - TOPIC=$1 - ;; - -P|--partition-count) shift - PARTITION_COUNT=$1 - ;; - -R|--replication-count) shift - REPLICATION_COUNT=$1 - ;; - *) usage - exit 1 - ;; - esac - shift +until [ -z "$1" ]; do + case $1 in + -d|--debug) set -x + ;; + -h|--host) shift + BUS_HOST=$1 + ;; + -p|--port) shift + BUS_PORT=$1 + ;; + -k|--key) shift + API_KEY=$1 + ;; + -s|--secret) shift + API_SECRET=$1 + ;; + -t|--topic) shift + TOPIC=$1 + ;; + -P|--partition-count) shift + PARTITION_COUNT=$1 + ;; + -R|--replication-count) shift + REPLICATION_COUNT=$1 + ;; + *) usage + exit 1 + ;; + esac + shift done -if [[ -z ${BUS_HOST} ]]; then - echo "An UEB/DMAAP server must be provided." - echo - usage - exit 1 +if [ -z "${BUS_HOST}" ]; then + echo "An UEB/DMAAP server must be provided." + echo + usage + exit 1 fi -if [[ -z ${API_KEY} ]]; then - echo "The API Key must be provided." - usage - exit 2 +if [ -z "${API_KEY}" ]; then + echo "The API Key must be provided." + usage + exit 2 fi -if [[ -z ${API_SECRET} ]]; then - echo "The API Secret must be provided." - usage - exit 3 +if [ -z "${API_SECRET}" ]; then + echo "The API Secret must be provided." + usage + exit 3 fi -if [[ -z ${TOPIC} ]]; then - echo "The Topic Name must be provided." - usage - exit 3 +if [ -z "${TOPIC}" ]; then + echo "The Topic Name must be provided." + usage + exit 3 fi -if [[ -z ${PARTITION_COUNT} ]]; then - echo "The Partition Count must be provided." - usage - exit 4 +if [ -z "${PARTITION_COUNT}" ]; then + echo "The Partition Count must be provided." + usage + exit 4 fi -if [[ -z ${REPLICATION_COUNT} ]]; then - echo "The Replication Count must be provided." - usage - exit 5 +if [ -z "${REPLICATION_COUNT}" ]; then + echo "The Replication Count must be provided." + usage + exit 5 fi REQUEST_API_KEY_BODY=$(< <(cat <<EOF { - "topicName": "${TOPIC}", - "topicDescription": "Generated by PDP-D $(hostname -f)", - "partitionCount": ${PARTITION_COUNT}, - "replicationCount": ${REPLICATION_COUNT} + "topicName": "${TOPIC}", + "topicDescription": "Generated by PDP-D $(hostname -f)", + "partitionCount": ${PARTITION_COUNT}, + "replicationCount": ${REPLICATION_COUNT} } EOF )) @@ -122,9 +122,9 @@ DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | ope unset http_proxy curl --silent -X POST \ - --header "Accept:" \ - --header "X-CambriaDate: ${DATE}" \ - --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ - --header "Content-Type: application/json" \ - --data "${REQUEST_API_KEY_BODY}" \ - http://${BUS_HOST}:${BUS_PORT}/topics/create + --header "Accept:" \ + --header "X-CambriaDate: ${DATE}" \ + --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ + --header "Content-Type: application/json" \ + --data "${REQUEST_API_KEY_BODY}" \ + http://${BUS_HOST}:${BUS_PORT}/topics/create diff --git a/policy-management/src/main/server-gen/bin/db-migrator b/policy-management/src/main/server-gen/bin/db-migrator index f5029460..db82fc35 100644 --- a/policy-management/src/main/server-gen/bin/db-migrator +++ b/policy-management/src/main/server-gen/bin/db-migrator @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP @@ -20,44 +20,43 @@ # ##################################################################### # -# Upgrade/Downgrade SQL File Name Format: +# Upgrade/Downgrade SQL File Name Format: # -# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql +# <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 +# $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 +# $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. +# 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 +# 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. +# 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 - +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" @@ -69,33 +68,33 @@ SQL_QUOTES="SET SESSION SQL_MODE=ANSI_QUOTES;" ##################################################### 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 + 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 } ##################################################### @@ -104,24 +103,24 @@ function usage() { function ensure_metadata { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - local sql rc - + 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} != 0 ]]; then - return ${rc} - fi - + ${MYSQL} --execute "${sql}" + rc=$? + if [ ${rc} -ne 0 ]; then + return ${rc} + fi + sql="CREATE TABLE IF NOT EXISTS ${METADATA_TABLE} " - sql+="(name VARCHAR(60) NOT NULL, version VARCHAR(20), PRIMARY KEY(name));" - ${MYSQL} --execute "${sql}" - return $? + sql=${sql}"(name VARCHAR(60) NOT NULL, version VARCHAR(20), PRIMARY KEY(name));" + ${MYSQL} --execute "${sql}" + return $? } @@ -131,26 +130,26 @@ function ensure_metadata function ensure_metadata_schema { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - local sql rc - - sql="CREATE TABLE IF NOT EXISTS ${METADATA_HISTORY} " - sql+="(script VARCHAR(80) NOT NULL, operation VARCHAR(10), success VARCHAR(1), " - sql+="atTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " - sql+="PRIMARY KEY(script));" - ${MYSQL} --execute "${sql}" - rc=$? - if [[ ${rc} != 0 ]]; then - return ${rc} - fi - - sql="CREATE DATABASE IF NOT EXISTS ${SCHEMA_DB};" - ${MYSQL} --execute "${sql}" - return $? + 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 $? } @@ -160,25 +159,25 @@ function ensure_metadata_schema function target_release { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - 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}" + 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}" } ##################################################### @@ -187,19 +186,19 @@ function target_release function is_upgrade { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - 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 + 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 } @@ -209,67 +208,66 @@ function is_upgrade function is_downgrade { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - 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 + 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 } ##################################################### -# current_release +# set_current_release ##################################################### -function current_release +function set_current_release { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - 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 -} + 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 $? +} ##################################################### -# set_current_release +# current_release ##################################################### -function set_current_release +function current_release { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - CURRENT_RELEASE="${1}" - - local sql="INSERT INTO ${METADATA_TABLE} (name, version) " - sql+="VALUES('${SCHEMA}', '${CURRENT_RELEASE}') " - sql+="ON DUPLICATE KEY UPDATE version='${CURRENT_RELEASE}';" - - ${MYSQL} --execute "${sql}" - return $? -} + 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 @@ -277,18 +275,18 @@ function set_current_release function track_script { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local script="${1}" operation="${2}" success="${3}" - local sql="INSERT INTO ${METADATA_HISTORY}(script,operation,success,atTime) " - sql+="VALUES ('${script}','${operation}','${success}',now()) " - sql+="ON DUPLICATE KEY UPDATE operation=values(operation), success=values(success), atTime=values(atTime);" - - ${MYSQL} --execute "${sql}" - return $? + 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 $? } @@ -298,27 +296,27 @@ function track_script function run_script { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local operation="${1}" script="${2}" scriptPath="${3}" - - echo - echo "> ${operation} ${script}" - - ${MYSQL} --verbose < "${scriptPath}" - local rc=$? - if [[ ${rc} != 0 ]]; then - success="0" - else - success="1" - fi - - track_script "${script}" "${operation}" "${success}" - - return ${rc} + 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} } ##################################################### @@ -327,38 +325,38 @@ function run_script function upgrade { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - 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} != 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 + 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 } ##################################################### @@ -367,38 +365,38 @@ function upgrade function downgrade { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - 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} != 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 + 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 } ##################################################### @@ -407,19 +405,19 @@ function downgrade function erase { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - 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}" + 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}" } ##################################################### @@ -428,202 +426,201 @@ function erase function report { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - 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 + 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 "-- ${FUNCNAME[0]} --" - 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} + 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 +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 +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 - ;; + 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 +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 +if [ -z "${SQL_HOST}" ] || [ -z "${SQL_USER}" ] || [ -z "${SQL_PASSWORD}" ]; then + echo "error: no database has been set up" + exit 4 fi MYSQL="mysql -u${SQL_USER} -p${SQL_PASSWORD} -h ${SQL_HOST}"; if ! ${MYSQL} -h"${SQL_HOST}" --execute "show databases;" > /dev/null 2>&1; then - echo "error: No DB connectivity to ${SQL_HOST} for ${SQL_USER}" - exit 5 + echo "error: No DB connectivity to ${SQL_HOST} for ${SQL_USER}" + exit 5 fi -if [[ ${SCHEMA} == ALL ]]; then - SCHEMA="*" +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 +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 + 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 + 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} +exit $rc diff --git a/policy-management/src/main/server-gen/bin/deploy-artifact b/policy-management/src/main/server-gen/bin/deploy-artifact index b25aaf9c..2ba42fb9 100644 --- a/policy-management/src/main/server-gen/bin/deploy-artifact +++ b/policy-management/src/main/server-gen/bin/deploy-artifact @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP @@ -56,34 +56,35 @@ function usage() { function init { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- init $* --" set -x fi local artifact="${1}" - if [[ ! -f ${artifact} ]]; then + if [ ! -f "${artifact}" ]; then echo "${artifact}: artifact does not exist" return 1 fi - if [[ ${artifact} != *.jar ]]; then + if [ "${artifact}" = "${artifact%.jar}" ]; then return 0 fi local dir=$(mktemp -d) local jar="${artifact##*/}" + CURRENT_DIR=$PWD WORKING_DIR=$(realpath "${dir}") cp -p "${artifact}" "${WORKING_DIR}/${jar}" - pushd "${dir}" + cd "${WORKING_DIR}" local rc=0 # determine name of 'pom' file within JAR local pom=$(jar tf "${jar}" META-INF | grep '/pom\.xml$' | head -1) - if [[ -n ${pom} ]] ; then + if [ -n "${pom}" ] ; then jar xf "${jar}" "${pom}" WORKING_POM=$(realpath "${pom}") else @@ -91,7 +92,7 @@ function init fi local pomProperties=$(jar tf "${jar}" META-INF | grep '/pom\.properties$' | head -1) - if [[ -n ${pomProperties} ]]; then + if [ -n "${pomProperties}" ]; then jar xf "${jar}" "${pomProperties}" WORKING_POM_PROPERTIES=$(realpath ${pomProperties}) sed -i 's/\r$//' "${WORKING_POM_PROPERTIES}" @@ -99,7 +100,7 @@ function init echo "${artifact}: sourcing in ${WORKING_POM_PROPERTIES}" else echo "${artifact}: pom.properties not found" - if [[ -n ${WORKING_POM} ]]; then + if [ -n "${WORKING_POM}" ]; then if ! getPomAttributes "${WORKING_POM}" artifactId groupId version ; then echo "${WORKING_POM}: cannot extract maven coordinates" rc=1 @@ -109,14 +110,13 @@ function init rc=1 fi fi - - if [[ -z ${version} ]] || [[ -z ${groupId} ]] || [[ -z ${artifactId} ]]; then + if [ -z "${version}" ] || [ -z "${groupId}" ] || [ -z "${artifactId}" ]; then echo "${artifact}: some coordinates cannot be extracted" rc=1 fi echo "${artifact}: coordinates ${groupId}:${artifactId}:${version}" - popd + cd ${CURRENT_DIR} return ${rc} } @@ -129,12 +129,12 @@ function init function cleanup { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- cleanup $* --" set -x fi - if [[ -n ${WORKING_DIR} ]]; then + if [ -n "${WORKING_DIR}" ]; then rm -rf "${WORKING_DIR}" fi } @@ -149,18 +149,18 @@ function cleanup function getPomAttributes { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- getPomAttributes $* --" set -x fi local file="$1" - if [[ ! -f "${file}" ]]; then + if [ ! -f "${file}" ]; then echo "${file}: file does not exist" return 1 fi - local tab=$'\t' rval=0 attr value + local rval=0 attr value shift for attr in "$@" ; do @@ -177,10 +177,10 @@ function getPomAttributes -e '/<packaging>/,/<\/packaging>/d' \ -e '/<modelVersion>/,/<\/modelVersion>/d' \ -e '/<properties>/,/<\/properties>/d' \ - -e "/^[ ${tab}]*<${attr}>\([^<]*\)<\/${attr}>.*/{s//\1/p;}" \ + -e "/^[ \t]*<${attr}>\([^<]*\)<\/${attr}>.*/{s//\1/p;}" \ <"${file}") - if [[ "${value}" == "" ]]; then + if [ -z "${value}" ]; then # need to check parent for parameter value=$(sed -n \ -e '/<dependencies>/,/<\/dependencies>/d' \ @@ -190,10 +190,10 @@ function getPomAttributes -e '/<packaging>/,/<\/packaging>/d' \ -e '/<modelVersion>/,/<\/modelVersion>/d' \ -e '/<properties>/,/<\/properties>/d' \ - -e "/^[ ${tab}]*<${attr}>\([^<]*\)<\/${attr}>.*/{s//\1/p;}" \ + -e "/^[ \t]*<${attr}>\([^<]*\)<\/${attr}>.*/{s//\1/p;}" \ <"${file}") - if [[ "${value}" == "" ]] ; then + if [ -z "${value}" ] ; then echo "${file}: Can't determine ${attr}" rval=1 fi @@ -201,7 +201,7 @@ function getPomAttributes # the following sets an environment variable with the name referred # to by ${attr} - read "${attr}" <<<"${value}" + export ${attr}="${value}" done return ${rval} } @@ -213,16 +213,17 @@ function getPomAttributes # extracting the attributes such as proxy host, port, username and password. # These proxy attributes are set into the global variable for maven proxy # settings to be used as build arguments with maven commands. +# The http proxy format is: http_proxy="http://username:password@proxy.thing.com:8080" ############################################################################## function setMavenProxyArgs { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- setMavenProxyArgs $* --" set -x fi - if [[ -z ${http_proxy} ]]; then + if [ -z "${http_proxy}" ]; then return 0 fi @@ -232,11 +233,11 @@ function setMavenProxyArgs local port="${proxy#*:}" MVN_PROXY_SETTINGS="-DproxyHost=${host} -DproxyPort=${port}" - if [[ "$proxy_creds" == *"@"* ]]; then + if echo "$proxy_creds" | egrep -s '@'; then local creds="${proxy_creds%%@*}" local username="${creds%:*}" local password="${creds#*:}" - MVN_PROXY_SETTINGS+=" -DproxyUsername=${username} -DproxyPassword=${password}" + MVN_PROXY_SETTINGS=${MVN_PROXY_SETTINGS}" -DproxyUsername=${username} -DproxyPassword=${password}" fi } @@ -249,19 +250,19 @@ function setMavenProxyArgs function deployJar { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- deployJar $* --" set -x fi local file="${1}" - if [[ ! -f ${file} ]]; then + if [ ! -f "${file}" ]; then return 1 fi local repoId repoUrl - if [[ "${version}" =~ SNAPSHOT ]] ; then + if echo "$version" | egrep -s 'SNAPSHOT'; then repoId=${SNAPSHOT_REPOSITORY_ID} repoUrl=${SNAPSHOT_REPOSITORY_URL} else @@ -269,7 +270,7 @@ function deployJar repoUrl=${RELEASE_REPOSITORY_URL} fi - if [[ -z ${repoUrl} ]] || [[ -z ${repoId} ]]; then + if [ -z "${repoUrl}" ] || [ -z "${repoId}" ]; then echo "{file}: no repository id/url to deploy jar" return 1 fi @@ -298,14 +299,14 @@ function deployJar function deployPom { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- deployPom $* --" set -x fi local file="${1}" - if [[ ! -f ${file} ]]; then + if [ ! -f "${file}" ]; then return 1 fi @@ -315,7 +316,7 @@ function deployPom fi local repoId repoUrl - if [[ "${version}" =~ SNAPSHOT ]] ; then + if echo "$version" | egrep -s 'SNAPSHOT'; then repoId=${SNAPSHOT_REPOSITORY_ID} repoUrl=${SNAPSHOT_REPOSITORY_URL} else @@ -348,18 +349,18 @@ function deployPom function deployArtifact { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- deployArtifact $* --" set -x fi local file="${1}" - if [[ -z "${file}" ]]; then + if [ -z "${file}" ]; then echo "${file}: artifact file not provided" return 1 fi - if [[ ! -f "${file}" ]]; then + if [ ! -f "${file}" ]; then echo "${file}: artifact file does not exist" return 1 fi @@ -387,19 +388,19 @@ function deployArtifact function installJar { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- installJar $* --" set -x fi local file="${1}" - if [[ ! -f ${file} ]]; then + if [ ! -f "${file}" ]; then return 1 fi mvn ${CUSTOM_SETTINGS} ${MVN_PROXY_SETTINGS} \ - org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile="${file}" + org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=${file} return $? } @@ -412,14 +413,14 @@ function installJar function installPom { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- installPom $* --" set -x fi local file="${1}" - if [[ ! -f ${file} ]]; then + if [ ! -f "${file}" ]; then return 1 fi @@ -440,22 +441,21 @@ function installPom function installArtifact { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- installArtifact $* --" set -x fi local file="${1}" - if [[ -z "${file}" ]]; then + if [ -z "${file}" ]; then echo "${file}: artifact file not provided" return 1 fi - if [[ ! -f "${file}" ]]; then + if [ ! -f "${file}" ]; then echo "${file}: artifact file does not exist" return 1 fi - case "${file}" in *pom.xml|*.pom) installPom "${file}" @@ -480,18 +480,18 @@ function installArtifact function installDependencies { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" + if [ "${DEBUG}" = "y" ]; then + echo "-- installDependencies $* --" set -x fi local file="${1}" - if [[ ! -f ${file} ]]; then + if [ ! -f "${file}" ]; then return 1 fi - if [[ -z ${DEPENDENCY_REPO_URL} ]]; then + if [ -z "${DEPENDENCY_REPO_URL}" ]; then echo "${file}: no repo url to install dependencies" return 1 fi @@ -513,7 +513,7 @@ function installDependencies # MAIN ############################################################################## -if [[ ${DEBUG} == y ]]; then +if [ "${DEBUG}" = "y" ]; then echo "-- $0 $* --" set -x fi @@ -534,7 +534,7 @@ unset MVN_PROXY_SETTINGS # process input -until [[ -z "$1" ]]; do +until [ -z "$1" ]; do case $1 in -a|--artifact) shift ARTIFACT_FILE=$1 @@ -555,13 +555,13 @@ until [[ -z "$1" ]]; do shift done -if [[ -z ${ARTIFACT_FILE} ]]; then +if [ -z "${ARTIFACT_FILE}" ]; then echo "No artifact file provided: $*" usage exit 1 fi -if [[ -n ${SETTINGS_FILE} ]]; then +if [ -n "${SETTINGS_FILE}" ]; then CUSTOM_SETTINGS="--settings=${SETTINGS_FILE}" fi @@ -576,7 +576,7 @@ retval=0 init "${ARTIFACT_FILE}" retval=$? -if [[ ${retval} != 0 ]]; then +if [ ${retval} -ne 0 ]; then cleanup exit ${retval} fi @@ -586,14 +586,14 @@ fi # SNAPSHOT_REPOSITORY_URL and RELEASE_REPOSITORY_URL # are pre-existing environmental variables (base.conf) -if [[ -n ${SNAPSHOT_REPOSITORY_URL} ]] || [[ -n ${RELEASE_REPOSITORY_URL} ]]; then +if [ -n "${SNAPSHOT_REPOSITORY_URL}" ] || [ -n "${RELEASE_REPOSITORY_URL}" ]; then deployArtifact "${ARTIFACT_FILE}" retval=$(( retval + ${?} )) fi # deploy in file repository -if [[ -n ${FILE_REPO_INSTALL} ]]; then +if [ -n "${FILE_REPO_INSTALL}" ]; then FILE_REPO_ID="file-repository" FILE_REPO_URL="file:${HOME}/.m2/file-repository" @@ -609,21 +609,21 @@ fi # install in local repository -if [[ -n ${LOCAL_INSTALL} ]]; then +if [ -n "${LOCAL_INSTALL}" ]; then installArtifact "${ARTIFACT_FILE}" retval=$(( retval + ${?} )) fi # install dependencies in local and/or file repositories -if [[ -n ${INSTALL_DEPS} ]]; then - if [[ -n ${FILE_REPO_INSTALL} ]]; then +if [ -n "${INSTALL_DEPS}" ]; then + if [ -n "${FILE_REPO_INSTALL}" ]; then DEPENDENCY_REPO_URL="${FILE_REPO_URL}" installDependencies "${ARTIFACT_FILE}" retval=$(( retval + ${?} )) fi - if [[ -n ${LOCAL_INSTALL} ]]; then + if [ -n "${LOCAL_INSTALL}" ]; then DEPENDENCY_REPO_URL="file:${HOME}/.m2/repository" installDependencies "${ARTIFACT_FILE}" retval=$(( retval + ${?} )) diff --git a/policy-management/src/main/server-gen/bin/features b/policy-management/src/main/server-gen/bin/features index 2646c04d..fc1f239f 100644 --- a/policy-management/src/main/server-gen/bin/features +++ b/policy-management/src/main/server-gen/bin/features @@ -1,17 +1,17 @@ -#!/usr/bin/env bash +#!/usr/bin/env ash ### # ============LICENSE_START======================================================= # ONAP POLICY # ================================================================================ -# Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. +# Copyright (C) 2017-2020 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. @@ -115,10 +115,10 @@ # 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 # customizations for this feature. -# +# # Notes for DB enabled features: -# A. Upgrade/Downgrade SQL File Name Format: -# <VERSION>-<pdp|feature-name>[-description](.upgrade|.downgrade).sql +# 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: @@ -145,11 +145,11 @@ # L─ feature-healthcheck-1.1.0-SNAPSHOT.jar # ############################################################# -if [[ ${DEBUG} == y ]]; then - echo "-- MAIN --" - set -x +if [ "${DEBUG}" = "y" ]; then + echo "-- MAIN --" + set -x fi - + # The directories at play LIB=${POLICY_HOME}/lib @@ -158,21 +158,21 @@ BIN=${POLICY_HOME}/bin DB=${POLICY_HOME}/etc/db/migration FEATURES=${POLICY_HOME}/features -if [[ ! ( -d "${LIB}" && -x "${LIB}" ) ]]; then - echo "error: no ${LIB} directory" - exit 1 +if [ ! -d "${LIB}" ]; then + echo "error: no ${LIB} directory" + exit 1 fi -if [[ ! ( -d "${CONFIG}" && -x "${CONFIG}" ) ]]; then - echo "error: no ${CONFIG} directory" - exit 2 +if [ ! -d "${CONFIG}" ]; then + echo "error: no ${CONFIG} directory" + exit 2 fi # ensure that the directory exists mkdir -p "${FEATURES}" 2> /dev/null -if [[ ! -d "${DB}" ]]; then - mkdir -p "${DB}" +if [ ! -d "${DB}" ]; then + mkdir -p "${DB}" fi # relative per Feature Directory Paths @@ -197,25 +197,25 @@ versionLength=15 # update field lengths, if needed for jar in ${featureJars} ; do - # get file name without 'jar' suffix - tmp="${jar%\.jar}" - - # remove feature prefix - tmp="${tmp#feature-}" - - # get feature name by removing the version portion - name="${tmp%%-[0-9]*}" - - # extract version portion of name - version="${tmp#${name}-}" - - # grow the size of the name/version field, if needed - if (( "${#name}" > nameLength )) ; then - nameLength="${#name}" - fi - if (( "${#version}" > versionLength )) ; then - versionLength="${#version}" - fi + # get file name without 'jar' suffix + tmp="${jar%\.jar}" + + # remove feature prefix + tmp="${tmp#feature-}" + + # get feature name by removing the version portion + name="${tmp%%-[0-9]*}" + + # extract version portion of name + version="${tmp#${name}-}" + + # grow the size of the name/version field, if needed + if [ ${#name} -gt $nameLength ] ; then + nameLength=${#name} + fi + if [ ${#version} -gt $versionLength ] ; then + versionLength=${#version} + fi done # ########################################################## @@ -238,121 +238,121 @@ function usage EOF } + # ########################################################## # status: dump out status information # ########################################################## function status { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - local tmp name version status - local format="%-${nameLength}s %-${versionLength}s %s\n" - - printf "${format}" "name" "version" "status" - printf "${format}" "----" "-------" "------" - - for jar in ${featureJars} ; do - # get file name without 'jar' suffix - tmp="${jar%\.jar}" - - # remove feature prefix - tmp="${tmp#feature-}" - - # get feature name by removing the version portion - name="${tmp%%-[0-9]*}" - - # extract version portion of name - version="${tmp#${name}-}" - - # determine status - status=disabled - if [[ -e "${LIB}/${jar}" ]] ; then - status=enabled - fi - printf "${format}" "${name}" "${version}" "${status}" - done - echo + if [ "${DEBUG}" = "y" ]; then + echo "-- status --" + set -x + fi + + local tmp name version status + local format="%-${nameLength}s %-${versionLength}s %s\n" + + printf "${format}" "name" "version" "status" + printf "${format}" "----" "-------" "------" + + for jar in ${featureJars} ; do + # get file name without 'jar' suffix + tmp="${jar%\.jar}" + + # remove feature prefix + tmp="${tmp#feature-}" + + # get feature name by removing the version portion + name="${tmp%%-[0-9]*}" + + # extract version portion of name + version="${tmp#${name}-}" + + # determine status + status=disabled + if [ -e "${LIB}/${jar}" ] ; then + status=enabled + fi + printf "${format}" "${name}" "${version}" "${status}" + done + echo } # ########################################################## -# enableDepAnalysis (featureName): +# enableDepAnalysis (featureName): # reports on potential dependency conflicts # featureName: name of the feature # ########################################################## function enableDepAnalysis () { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureDepJars featureDepJarPath depJarName multiVersionJars - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureDepJars=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) - for featureDepJarPath in ${featureDepJars}; do - depJarName=$(basename "${featureDepJarPath}") - - # it could be a base jar - - if [[ -f "${LIB}"/"${depJarName}" ]]; then - echo "warning: dependency ${depJarName} already in use" - continue - fi - - # it could be a link from another feature - - if [[ -L "${LIB}"/"${depJarName}" ]]; then - continue - fi - - # unadvisable if multiple versions exist but the base or - # installed one wins. - - multiVersionJars=$(ls "${LIB}"/"${depJarName%%-[0-9]*.jar}"-*.jar 2> /dev/null) - if [[ -n "${multiVersionJars}" ]]; then - echo "warning: other version of library ${depJarName} present: ${multiVersionJars}" - continue - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableDepAnalysis $* --" + set -x + fi + + local featureName="$1" + local featureDepJars featureDepJarPath depJarName multiVersionJars + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + fi + + featureDepJars=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) + for featureDepJarPath in ${featureDepJars}; do + depJarName=$(basename "${featureDepJarPath}") + + # it could be a base jar + + if [ -f "${LIB}"/"${depJarName}" ]; then + echo "warning: dependency ${depJarName} already in use" + continue + fi + + # it could be a link from another feature + + if [ -L "${LIB}"/"${depJarName}" ]; then + continue + fi + + # unadvisable if multiple versions exist but the base or + # installed one wins. + + multiVersionJars=$(ls "${LIB}"/"${depJarName%%-[0-9]*.jar}"-*.jar 2> /dev/null) + if [ -n "${multiVersionJars}" ]; then + echo "warning: other version of library ${depJarName} present: ${multiVersionJars}" + continue + fi + done } # ########################################################## -# enableConfigAnalysis (featureName): +# enableConfigAnalysis (featureName): # reports on potential dependency conflicts # featureName: name of the feature # ########################################################## function enableConfigAnalysis () { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureConfigs configPath configFileName - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureConfigs=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ 2> /dev/null) - for configPath in ${featureConfigs}; do - configFileName=$(basename "${configPath}") - if [[ -e "${CONFIG}"/"${configFileName}" ]]; then - echo "error: a config file of the same name is already in the base installation: ${configFileName}" - return 2 - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableConfigAnalysis $* --" + set -x + fi + + local featureName="$1" + local featureConfigs configPath configFileName + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureConfigs=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ 2> /dev/null) + for configPath in ${featureConfigs}; do + configFileName=$(basename "${configPath}") + if [ -e "${CONFIG}"/"${configFileName}" ]; then + echo "error: a config file of the same name is already in the base installation: ${configFileName}" + return 2 + fi + done } # ########################################################## @@ -362,232 +362,230 @@ function enableConfigAnalysis () # ########################################################## function enableBinAnalysis () { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureBins binPath binFileName - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureBins=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ 2> /dev/null) - for binPath in ${featureBins}; do - binFileName=$(basename "${binPath}") - if [[ -e "${CONFIG}"/"${binFileName}" ]]; then - echo "error: a bin file of the same name is already in the base installation: ${binFileName}" - return 2 - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableBinAnalysis $* --" + set -x + fi + + local featureName="$1" + local featureBins binPath binFileName + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureBins=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ 2> /dev/null) + for binPath in ${featureBins}; do + binFileName=$(basename "${binPath}") + if [ -e "${CONFIG}"/"${binFileName}" ]; then + echo "error: a bin file of the same name is already in the base installation: ${binFileName}" + return 2 + fi + done } # ########################################################## -# enableDbAnalysis (featureName): +# enableDbAnalysis (featureName): # reports on potential db access problems # featureName: name of the feature # ########################################################## function enableDbAnalysis() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - 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 + 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): +# enableFeatureDeps(featureName): # enables feature dependencies # featureName: name of the feature # ########################################################## function enableFeatureDeps() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureDeps featureDepPath depJarName - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) - for featureDepPath in ${featureDeps}; do - depJarName=$(basename "${featureDepPath}") - if [[ ! -f "${LIB}"/"${depJarName}" ]]; then - ln -s -f "${featureDepPath}" "${LIB}/" - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureDeps $* --" + set -x + fi + + local featureName="$1" + local featureDeps featureDepPath depJarName + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) + for featureDepPath in ${featureDeps}; do + depJarName=$(basename "${featureDepPath}") + if [ ! -f "${LIB}"/"${depJarName}" ]; then + ln -s -f "${featureDepPath}" "${LIB}/" + fi + done } # ########################################################## -# enableFeatureConfig(featureName): +# enableFeatureConfig(featureName): # enables feature configuration # featureName: name of the feature # ########################################################## function enableFeatureConfig() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureConfigs featureConfigPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null) - for featureConfigPath in ${featureConfigs}; do - ln -s -f "${featureConfigPath}" "${CONFIG}/" - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureConfig $* --" + set -x + fi + + local featureName="$1" + local featureConfigs featureConfigPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null) + for featureConfigPath in ${featureConfigs}; do + ln -s -f "${featureConfigPath}" "${CONFIG}/" + done } # ########################################################## -# enableFeatureBin(featureName): -# enables feature binaries +# enableFeatureBin(featureName): enables feature binaries # featureName: name of the feature # ########################################################## function enableFeatureBin() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureBins featureBinPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null) - for featureBinPath in ${featureBins}; do - chmod u+x "${featureBinPath}" - ln -s -f "${featureBinPath}" "${BIN}/" - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureBin $* --" + set -x + fi + + local featureName="$1" + local featureBins featureBinPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null) + for featureBinPath in ${featureBins}; do + chmod u+x "${featureBinPath}" + ln -s -f "${featureBinPath}" "${BIN}/" + done } # ########################################################## -# enableFeatureDbSchema(featureName): +# enableFeatureDbSchema(featureName): # enables feature DB Schema configuration # featureName: name of the feature # ########################################################## function enableFeatureDbSchema() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - 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} + 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): +# enableFeatureDb(featureName): # enables DB feature configuration # featureName: name of the feature # ########################################################## function enableFeatureDb() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - 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 + 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 } # ########################################################## @@ -597,61 +595,59 @@ function enableFeatureDb() # ########################################################## function enableFeatureArtifacts() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local artifacts - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - artifacts=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_ARTIFACTS}"/* 2> /dev/null) - for artifactPath in ${artifacts}; do - deploy-artifact -l -a "${artifactPath}" - done + if [ "${DEBUG}" = "y" ]; then + echo "-- enableFeatureArtifacts $* --" + set -x + fi + + local featureName="$1" + local artifacts + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + artifacts=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_ARTIFACTS}"/* 2> /dev/null) + for artifactPath in ${artifacts}; do + deploy-artifact -l -a "${artifactPath}" + done } # ########################################################## -# customize(featureName): -# executes customized script for an operation. +# customize(featureName): +# executes customized script for an operation. # # featureName - feature name -# operation - operation, ie. +# operation - operation, ie. # 'enable', 'disable', 'install', or 'uninstall' # ########################################################## function customOpScript() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local operation="$2" - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - if [[ -z ${operation} ]]; then - echo "warning: ${featureName} : a custom operation script must be provided" - return 1 - fi - - local customScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/"${operation}" - if [[ -f ${customScript} ]]; then - ( - cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}" - chmod u+x "${customScript}" - ./"$(basename "${customScript}")" - ) - fi + if [ "${DEBUG}" = "y" ]; then + echo "-- customOpScript $* --" + set -x + fi + + local featureName="$1" + local operation="$2" + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + if [ -z "${operation}" ]; then + echo "warning: ${featureName} : a custom operation script must be provided" + return 1 + fi + + local customScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/"${operation}" + if [ -f "${customScript}" ]; then + cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}" + chmod u+x "${customScript}" + ./"$(basename "${customScript}")" + fi } # ########################################################## @@ -661,157 +657,158 @@ function customOpScript() # ########################################################## function enableFeature() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureJar="$2" - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - if [[ -z ${featureJar} ]]; then - echo "warning: no feature jar" - return 2 - fi - - if ! enableDepAnalysis "${featureName}"; then - return "$?" - fi - - if ! enableConfigAnalysis "${featureName}"; then - return "$?" - fi - - if ! enableBinAnalysis "${featureName}"; then - return "$?" - fi - - if ! enableDbAnalysis "${featureName}"; then - return "$?" - fi - - # enable feature itself - - ln -s -f "${featureJar}" "${LIB}/" - - # enable dependent libraries if any - - enableFeatureDeps "${featureName}" - - # enable configuration - - enableFeatureConfig "${featureName}" - - # enable binaries - - enableFeatureBin "${featureName}" - - # enable db - - enableFeatureDb "${featureName}" - - # enable feature artifacts - - enableFeatureArtifacts "${featureName}" - - # run custom enable if any - - customOpScript "${featureName}" "enable" + if [ "$DEBUG" = "y" ]; then + echo "-- enableFeature $* --" + set -x + fi + + local featureName="$1" + local featureJar="$2" + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + if [ -z "${featureJar}" ]; then + echo "warning: no feature jar" + return 2 + fi + + if ! enableDepAnalysis "${featureName}"; then + return "$?" + fi + + if ! enableConfigAnalysis "${featureName}"; then + return "$?" + fi + + if ! enableBinAnalysis "${featureName}"; then + return "$?" + fi + + if ! enableDbAnalysis "${featureName}"; then + return "$?" + fi + + # enable feature itself + + ln -s -f "${featureJar}" "${LIB}/" + + # enable dependent libraries if any + + enableFeatureDeps "${featureName}" + + # enable configuration + + enableFeatureConfig "${featureName}" + + # enable binaries + + enableFeatureBin "${featureName}" + + # enable db + + enableFeatureDb "${featureName}" + + # enable feature artifacts + + enableFeatureArtifacts "${featureName}" + + # run custom enable if any + + customOpScript "${featureName}" "enable" } # ########################################################## -# disableFeatureDeps(featureName): -# disables feature dependencies +# disableFeatureDeps(featureName): +# disables feature dependencies # ########################################################## function disableFeatureDeps() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local xDepsEnabledMap featureBaseDirs aFeatureDir aFeatureName - local featureDeps aFeatureDep - local depJarPath depJarName depJarRealPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - declare -A xDepsEnabledMap - - featureBaseDirs=$(ls -d "${FEATURES}"/*/ 2> /dev/null) - for aFeatureDir in ${featureBaseDirs}; do - aFeatureName=$(basename "${aFeatureDir}") - if [[ "${aFeatureName}" == "${featureName}" ]]; then - continue - fi - - depJarPaths=$(ls "${aFeatureDir}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) - for depJarPath in ${depJarPaths}; do - if [[ "$?" == 0 ]] ; then - depJarName=$(basename "${depJarPath}") - xDepsEnabledMap[${depJarName}]="${depJarPath}" - fi - done - done - - if [[ ${DEBUG} == y ]]; then - echo "${!xDepsEnabledMap[@]}" - echo "${xDepsEnabledMap[@]}" - fi - - featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) - for aFeatureDep in ${featureDeps}; do - depJarName=$(basename "${aFeatureDep}") - if [[ -L "${LIB}"/"${depJarName}" ]]; then - depJarRealPath=$(readlink -f "${LIB}"/"${depJarName}") - if [[ "${depJarRealPath}" == "${aFeatureDep}" ]]; then - rm -f "${LIB}"/"${depJarName}" - - # case there were multiple features using this library - # re-enable link fron an enabled feature - - if [[ -n ${xDepsEnabledMap[${depJarName}]} ]]; then - ln -s -f "${xDepsEnabledMap[${depJarName}]}" "${LIB}/" - fi - fi - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeatureDeps $* --" + set -x + fi + + local featureName="$1" + local aDepsEnabledMap xDepsEnabledMap featureBaseDirs aFeatureDir aFeatureName + local featureDeps aFeatureDep + local depJarPath depJarName depJarRealPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureBaseDirs=$(ls -d "${FEATURES}"/*/ 2> /dev/null) + for aFeatureDir in ${featureBaseDirs}; do + aFeatureName=$(basename "${aFeatureDir}") + if [ "${aFeatureName}" = "${featureName}" ]; then + continue + fi + + depJarPaths=$(ls "${aFeatureDir}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) + for depJarPath in ${depJarPaths}; do + if [ "$?" = "0" ] ; then + depJarName=$(basename "${depJarPath}") + xDepsEnabledMap="${xDepsEnabledMap} ${depJarPath}" + fi + done + done + + if [ "${DEBUG}" = "y" ]; then + echo "${xDepsEnabledMap}" + fi + + featureDeps=$(ls "${FEATURES}"/"${featureName}"/"${FEATURE_DEPS}"/*.jar 2> /dev/null) + for aFeatureDep in ${featureDeps}; do + depJarName=$(basename "${aFeatureDep}") + # + # check if defJarName is a sym-link + # + if [ -L "${LIB}"/"${depJarName}" ]; then + depJarRealPath=$(readlink -f "${LIB}"/"${depJarName}") + if [ "${depJarRealPath}" = "${aFeatureDep}" ]; then + rm -f "${LIB}"/"${depJarName}" + + # case there were multiple features using this library + # re-enable link fron an enabled feature + for aDepsEnabledMap in ${xDepsEnabledMap}; do + if [ $(basename "${aDepsEnabledMap}") = ${depJarName} ]; then + ln -s -f "${aDepsEnabledMap}" "${LIB}/" + fi + done + fi + fi + done } # ########################################################## -# disableFeatureConfig(featureName): +# disableFeatureConfig(featureName): # disables feature configuration # featureName: name of the feature # ########################################################## function disableFeatureConfig() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureConfigs featureConfigPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null) - for featureConfigPath in ${featureConfigs}; do - configFileName=$(basename "${featureConfigPath}") - rm -f "${CONFIG}"/"${configFileName}" 2> /dev/null - done + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeatureConfig $* --" + set -x + fi + + local featureName="$1" + local featureConfigs featureConfigPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureConfigs=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_CONFIG}"/ -type f -maxdepth 1 2> /dev/null) + for featureConfigPath in ${featureConfigs}; do + configFileName=$(basename "${featureConfigPath}") + rm -f "${CONFIG}"/"${configFileName}" 2> /dev/null + done } # ########################################################## @@ -821,116 +818,115 @@ function disableFeatureConfig() # ########################################################## function disableFeatureBin() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - local featureBins featureBinPath - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return 1 - fi - - featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null) - for featureBinPath in ${featureBins}; do - binFileName=$(basename "${featureBinPath}") - rm -f "${BIN}"/"${binFileName}" 2> /dev/null - done + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeatureBin $* --" + set -x + fi + + local featureName="$1" + local featureBins featureBinPath + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return 1 + fi + + featureBins=$(find "${FEATURES}"/"${featureName}"/"${FEATURE_BIN}"/ -type f -maxdepth 1 2> /dev/null) + for featureBinPath in ${featureBins}; do + binFileName=$(basename "${featureBinPath}") + rm -f "${BIN}"/"${binFileName}" 2> /dev/null + done } # ########################################################## -# disableFeatureDbSchema(featureName, featureDbPath, schemaName): -# disables feature db configuration for a schema +# disableFeatureDbSchema(featureName, featureDbPath, schemaName): +# disables feature db configuration for a schema # featureName: name of the feature # ########################################################## function disableFeatureDbSchema() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - 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 + 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 +# disableFeatureDb(featureName): +# disables feature db configuration # featureName: name of the feature # ########################################################## function disableFeatureDb() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - 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 + 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 } # ########################################################## @@ -939,44 +935,44 @@ function disableFeatureDb() # ########################################################## function disableFeature() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return - fi - - # disable feature itself - - ( - cd "${LIB}" - rm -f feature-"${featureName}"-[0-9]*.jar 2> /dev/null - ) - - # disable dependencies if any - - disableFeatureDeps "${featureName}" - - # disable configuration if any - - disableFeatureConfig "${featureName}" - - # disable binaries if any - - disableFeatureBin "${featureName}" - - # disable DB SQL scripts if any - - disableFeatureDb "${featureName}" - - # run custom disable if any - - customOpScript "${featureName}" "disable" + if [ "${DEBUG}" = "y" ]; then + echo "-- disableFeature $* --" + set -x + fi + + local featureName="$1" + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return + fi + + # disable feature itself + + ( + cd "${LIB}" + rm -f feature-"${featureName}"-[0-9]*.jar 2> /dev/null + ) + + # disable dependencies if any + + disableFeatureDeps "${featureName}" + + # disable configuration if any + + disableFeatureConfig "${featureName}" + + # disable binaries if any + + disableFeatureBin "${featureName}" + + # disable DB SQL scripts if any + + disableFeatureDb "${featureName}" + + # run custom disable if any + + customOpScript "${featureName}" "disable" } ############################################################ @@ -985,40 +981,40 @@ function disableFeature() # This was copied from 'policy-drools/docker-install.sh' # in the 'docker' repository, and modified where needed. ############################################################ -function configureFeature() +function configureFeature() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local envConfig=$1 featureRoot=$2 - local sedLine="sed -i" - local sedFiles="" nonBinaryFiles sedFile name value - - while read line || [ -n "${line}" ]; do - if [[ -n ${line} ]] && [[ ${line:0:1} != \# ]]; then - name="${line%%=*}" - value="${line#*=}" - value=$(echo "${value}" | sed -e 's/[\/&]/\\&/g') - if [[ -z ${name} ]] || [[ -z ${value} ]]; then - echo "warning: ${line} missing name or value" - fi - sedLine+=" -e 's/\${{${name}}}/${value}/g' " - fi - done < "${envConfig}" - - nonBinaryFiles=$(find "${featureRoot}" -type f -exec grep -Iq . {} \; -print 2> /dev/null) - for sedFile in ${nonBinaryFiles}; do - if fgrep -l '${{' ${sedFile} > /dev/null 2>&1; then - sedFiles+="${sedFile} " - fi - done - - if [[ -n ${sedFiles} ]]; then - sedLine+=${sedFiles} - eval "${sedLine}" - fi + if [ "$DEBUG" = "y" ]; then + echo "-- configureFeature $* --" + set -x + fi + + local envConfig=$1 featureRoot=$2 + local sedLine="sed -i" + local sedFiles="" nonBinaryFiles sedFile name value + + while read line || [ -n "${line}" ]; do + if [ -n "${line}" ] && [ "${line:0:1}" != \# ]; then + name="${line%%=*}" + value="${line#*=}" + value=$(echo "${value}" | sed -e 's/[\/&]/\\&/g') + if [ -z "${name}" ] || [ -z "${value}" ]; then + echo "warning: ${line} missing name or value" + fi + sedLine+=" -e 's/\${{${name}}}/${value}/g' " + fi + done < "${envConfig}" + + nonBinaryFiles=$(find "${featureRoot}" -type f -exec grep -Iq . {} \; -print 2> /dev/null) + for sedFile in ${nonBinaryFiles}; do + if fgrep -l '${{' ${sedFile} > /dev/null 2>&1; then + sedFiles+="${sedFile} " + fi + done + + if [ -n "${sedFiles}" ]; then + sedLine+=${sedFiles} + eval "${sedLine}" + fi } ############################################################ @@ -1029,121 +1025,100 @@ function configureFeature() ############################################################ function installFeatures { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local name featureConf feature dir conf - - if [[ -d "${FEATURES}" && -x "${FEATURES}" ]]; then - SOURCE_DIR=$PWD - for feature in "$@" ; do - dir= - if [[ "${feature}" == feature-*.zip || - "${feature}" == */feature-*.zip ]] ; then - # the ZIP file is specified -- find the name - name="${feature##*/}" - name="${name#feature-}" - name="${name%%-[0-9]*\.zip}" - - # if the ZIP file has a directory name component, - # set 'dir' accordingly - if [[ "${feature}" =~ / ]] ; then - dir="${feature%/*}" - fi - else - # Doesn't match the ZIP file name convention -- interpret - # this as a feature name, and try to locate a matching ZIP - # file. If there is more than one, choose the one with the - # highest version number. - name="${feature}" - feature=$(ls -v feature-"${name}"-[0-9]*.zip 2>/dev/null|tail -1) - fi - if [[ ! -f "${feature}" ]] ; then - # include the file name in the error message, unless we don't - # have one -- in this case, use the feature name - echo "error: feature file ${feature:-for ${name}} not found" - continue - fi - if [[ -d "${FEATURES}/${name}" ]] ; then - echo "error: feature ${name} has already been installed" - continue - fi - - # extract contents of ZIP file in to feature directory - mkdir -p "${FEATURES}/${name}" > /dev/null 2>&1 - (cd "${FEATURES}/${name}"; jar xf "${SOURCE_DIR}"/"${feature}") - - # if there is a configuration file available, - # use it to configure the feature - featureConf="${dir:+$dir/}feature-${name}.conf" - if [[ -r "${featureConf}" ]]; then - configureFeature "${featureConf}" "${FEATURES}"/"${name}" - cp "${featureConf}" "${POLICY_HOME}"/etc/profile.d - echo "feature ${name} has been installed (configuration present)" - else - echo "feature ${name} has been installed (no configuration present)" - fi - - customOpScript "${name}" "install" - done - - # check the current directory and the 'config' directory for a - # 'base.conf' file -- use the first one that is found - for conf in base.conf ${POLICY_HOME}/config/base.conf ${POLICY_HOME}/etc/profile.d/base.conf; do - if [[ -f "${conf}" ]] ; then - echo "applying base configuration '${conf}' to features" - configureFeature "${conf}" "${FEATURES}" - break - fi - done - else - echo "error: aborting -- ${FEATURES} is not accessible" - exit 1 - fi + if [ "$DEBUG" = "y" ]; then + echo "-- installFeatures $* --" + set -x + fi + + local name featureConf feature conf + if [ -d "${FEATURES}" ]; then + SOURCE_DIR=$PWD + for feature in "$@" ; do + name="${feature}" + feature=$(ls -v feature-"${name}"-[0-9]*.zip 2>/dev/null|tail -1) + if [ ! -f "${feature}" ] ; then + # include the file name in the error message, unless we don't + # have one -- in this case, use the feature name + echo "error: feature file ${feature:-for ${name}} not found" + continue + fi + if [ -d "${FEATURES}/${name}" ] ; then + echo "error: feature ${name} has already been installed" + continue + fi + + # extract contents of ZIP file in to feature directory + mkdir -p "${FEATURES}/${name}" > /dev/null 2>&1 + (cd "${FEATURES}/${name}"; jar xf "${SOURCE_DIR}"/"${feature}") + + # if there is a configuration file available, + # use it to configure the feature + featureConf="${dir:+$dir/}feature-${name}.conf" + if [ -r "${featureConf}" ]; then + configureFeature "${featureConf}" "${FEATURES}"/"${name}" + cp "${featureConf}" "${POLICY_HOME}"/etc/profile.d + echo "feature ${name} has been installed (configuration present)" + else + echo "feature ${name} has been installed (no configuration present)" + fi + + customOpScript "${name}" "install" + done + + # check the current directory and the 'config' directory for a + # 'base.conf' file -- use the first one that is found + for conf in base.conf ${POLICY_HOME}/config/base.conf ${POLICY_HOME}/etc/profile.d/base.conf; do + if [ -f "${conf}" ] ; then + echo "applying base configuration '${conf}' to features" + configureFeature "${conf}" "${FEATURES}" + break + fi + done + else + echo "error: aborting -- ${FEATURES} is not accessible" + exit 1 + fi } # ########################################################## -# uninstallFeatureDb(featureName): -# uninstalls the feature db configuration +# uninstallFeatureDb(featureName): +# uninstalls the feature db configuration # featureName: name of the feature # ########################################################## function uninstallFeatureDb() { - if [[ ${DEBUG} == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - 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+=${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 [[ -z ${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 + 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 } ############################################################ @@ -1151,25 +1126,24 @@ function uninstallFeatureDb() ############################################################ function uninstallFeature { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} $* --" - set -x - fi - - local featureName="$1" - - if [[ -z ${featureName} ]]; then - echo "warning: no feature name" - return - fi - - disableFeature "${featureName}" - uninstallFeatureDb "${featureName}" - customOpScript "${featureName}" "uninstall" - - if [[ -n ${FEATURES} && -n ${featureName} ]]; then - rm -rf "${FEATURES:-???}/${featureName}" - fi + if [ "$DEBUG" = "y" ]; then + echo "-- uninstallFeature $* --" + set -x + fi + + local featureName="$1" + + if [ -z "${featureName}" ]; then + echo "warning: no feature name" + return + fi + disableFeature "${featureName}" + uninstallFeatureDb "${featureName}" + customOpScript "${featureName}" "uninstall" + + if [ -n "${FEATURES}" ] && [ -n "${featureName}" ]; then + rm -rf "${FEATURES:-???}/${featureName}" + fi } ############################################################ @@ -1177,120 +1151,129 @@ function uninstallFeature ############################################################ function uninstallFeatures { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" - set -x - fi - - local name - local allFeatures=$'\n'$(cd ${FEATURES};ls)$'\n' - for name in "$@" ; do - # the following check takes care of potentially troublesome names - # like '.', '..', and names containing '/' - if [[ "${allFeatures}" =~ $'\n'${name}$'\n' ]] ; then - uninstallFeature "${name}" - else - echo "feature ${name} not found" - fi - done + if [ "${DEBUG}" = "y" ]; then + echo "-- uninstallFeatures --" + set -x + fi + + local name + local allFeatures=$(cd ${FEATURES};ls) + local aFeature + local flag + for name in "$@" ; do + flag=false + # the following check takes care of potentially troublesome names + # like '.', '..', and names containing '/' + for aFeature in ${allFeatures}; + do + if [ "${aFeature}" = "${name}" ] ; then + uninstallFeature "${name}" + echo "feature ${name} uninstalled" + flag=true + fi + done + if ! $flag; then + echo "error: feature ${name} not found" + fi + done } case "$1" in - status) - { - # dump out status information - status - };; - - enable) - { - if [[ -f "${POLICY_HOME}"/PID ]]; then - echo "error: enable: not allowed when policy is running .." - echo - status - exit 10 - fi - - # enable the specified options - shift - match= - for name in "$@" ; do - # look for matches - 'file' has the full path name - file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null) - if [[ "$?" != 0 ]] ; then - # no matching file - echo "${name}: no such option" - else - # make sure there is only one feature jar - countFeatureJars=$(echo "${file}" | wc -w) - if [[ ${countFeatureJars} != 1 ]]; then - echo "warning: skipping ${name}, ${countFeatureJars} feature libraries found" - continue - fi - - # found a match (handle multiple matches, just in case) - match=true - - enableFeature "${name}" "${file}" - fi - done - if [[ "${match}" ]] ; then - echo - status - fi - };; - - disable) - { - if [[ -f "${POLICY_HOME}"/PID ]]; then - echo "error: disable: not allowed when policy is running .." - echo - status - exit 11 - fi - - # disable the specified options - shift - match= - for name in "$@" ; do - # look for matches -- 'file' has the last segment of the path name - file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null) - if [[ "$?" != 0 ]] ; then - echo "${name}: no such option" - else - # found a match (handle multiple matches, just in case) - match=true - - disableFeature "${name}" - fi - done - if [[ "${match}" ]] ; then - echo - status - fi - };; - - install) - { - shift - installFeatures "$@" - };; - - uninstall) - { - if [[ -f "${POLICY_HOME}"/PID ]]; then - echo "error: uninstall: not allowed when policy is running .." - echo - status - exit 12 - fi - shift - uninstallFeatures "$@" - };; - - *) - { - usage - };; + status) + { + # dump out status information + status + };; + + enable) + { + if [ -f "${POLICY_HOME}"/PID ]; then + echo "error: enable: not allowed when policy is running .." + echo + status + exit 10 + fi + + # enable the specified options + shift + match= + for name in "$@" ; do + # look for matches - 'file' has the full path name + file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null) + if [ "$?" != "0" ] ; then + # no matching file + echo "enable feature: ${name} failed" + else + # make sure there is only one feature jar + countFeatureJars=$(echo "${file}" | wc -w) + if [ ${countFeatureJars} -ne 1 ]; then + echo "warning: skipping ${name}, ${countFeatureJars} feature libraries found" + continue + fi + + # found a match (handle multiple matches, just in case) + match=true + + enableFeature "${name}" "${file}" + fi + done + if [ "${match}" ] ; then + echo + status + fi + };; + + disable) + { + if [ -f "${POLICY_HOME}"/PID ]; then + echo "error: disable: not allowed when policy is running .." + echo + status + exit 11 + fi + + # disable the specified options + shift + match= + for name in "$@" ; do + # look for matches -- 'file' has the last segment of the path name + file=$(ls "${FEATURES}"/"${name}"/"${FEATURE_LIB}"/feature-"${name}"-[0-9]*.jar 2> /dev/null) + if [ "$?" != "0" ] ; then + echo "${name}: no such option" + else + # found a match (handle multiple matches, just in case) + match=true + + disableFeature "${name}" + fi + done + if [ "${match}" ] ; then + echo + status + fi + };; + + install) + { + shift + installFeatures "$@" + };; + + uninstall) + { + if [ -f "${POLICY_HOME}"/PID ]; then + echo "error: uninstall: not allowed when policy is running .." + echo + status + exit 12 + fi + shift + uninstallFeatures "$@" + };; + + *) + { + usage + };; esac exit diff --git a/policy-management/src/main/server-gen/bin/pdpd-configuration b/policy-management/src/main/server-gen/bin/pdpd-configuration index fc822e18..a704a577 100644 --- a/policy-management/src/main/server-gen/bin/pdpd-configuration +++ b/policy-management/src/main/server-gen/bin/pdpd-configuration @@ -1,4 +1,4 @@ -#! /bin/bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP @@ -8,9 +8,9 @@ # 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. @@ -21,112 +21,111 @@ source ${POLICY_HOME}/etc/profile.d/env.sh function usage() { - echo -n "Usage: $(basename $0) " - echo -n "[(-d|--debug)] " - echo -n "(-h|--host) <bus-host> " - echo -n "[(-p|--port) <bus-port>] " - echo -n "[(-k|--key) <api-key>] " - echo -n "[(-s|--secret) <api-secret>] " - echo -n "[(-r|--request-id) <request-id>] " - echo -n "(-c|--controller-name) <controller-name> " - echo -n "(-o|--operation) <create|update|lock|unlock> " - echo -n "[(-g|--group-id) <group-id> " - echo -n "(-a|--artifact-id) <artifact-id> " - echo -n "(-v|--version) <version>] " - echo -n "[(-t|--topic) <topic>] " - echo "" + echo -n "Usage: $(basename $0) " + echo -n "[(-d|--debug)] " + echo -n "(-h|--host) <bus-host> " + echo -n "[(-p|--port) <bus-port>] " + echo -n "[(-k|--key) <api-key>] " + echo -n "[(-s|--secret) <api-secret>] " + echo -n "[(-r|--request-id) <request-id>] " + echo -n "(-c|--controller-name) <controller-name> " + echo -n "(-o|--operation) <create|update|lock|unlock> " + echo -n "[(-g|--group-id) <group-id> " + echo -n "(-a|--artifact-id) <artifact-id> " + echo -n "(-v|--version) <version>] " + echo -n "[(-t|--topic) <topic>] " + echo "" } BUS_PORT=3904 -ENTITY=controller REQUEST_ID="7f5474ca-16a9-42ac-abc0-d86f62296fbc" TOPIC="PDPD-CONFIGURATION" # command line options parsing -until [[ -z "$1" ]]; do - case $1 in - -d|--debug) set -x - ;; - -h|--host) shift - BUS_HOST=$1 - ;; - -p|--port) shift - BUS_PORT=$1 - ;; - -r|--request-id) shift - REQUEST_ID=$1 - ;; - -k|--key) shift - API_KEY=$1 - ;; - -s|--secret) shift - API_SECRET=$1 - ;; - -c|--controller-name) shift - CONTROLLER_NAME=$1 - ;; - -o|--operation) shift - OPERATION=$1 - ;; - -g|--group-id) shift - GROUP_ID=$1 - ;; - -a|--artifact-id) shift - ARTIFACT_ID=$1 - ;; - -v|--version) shift - VERSION=$1 - ;; - -t|--topic) shift - TOPIC=$1 - ;; - *) usage - exit 1 - ;; - esac - shift +until [ -z "$1" ]; do + case $1 in + -d|--debug) set -x + ;; + -h|--host) shift + BUS_HOST=$1 + ;; + -p|--port) shift + BUS_PORT=$1 + ;; + -r|--request-id) shift + REQUEST_ID=$1 + ;; + -k|--key) shift + API_KEY=$1 + ;; + -s|--secret) shift + API_SECRET=$1 + ;; + -c|--controller-name) shift + CONTROLLER_NAME=$1 + ;; + -o|--operation) shift + OPERATION=$1 + ;; + -g|--group-id) shift + GROUP_ID=$1 + ;; + -a|--artifact-id) shift + ARTIFACT_ID=$1 + ;; + -v|--version) shift + VERSION=$1 + ;; + -t|--topic) shift + TOPIC=$1 + ;; + *) usage + exit 1 + ;; + esac + shift done -if [[ -z ${BUS_HOST} ]]; then - echo "An UEB/DMAAP server must be provided." - echo - usage - exit 1 +if [ -z "${BUS_HOST}" ]; then + echo "An UEB/DMAAP server must be provided." + echo + usage + exit 1 fi -if [[ -z ${CONTROLLER_NAME} ]]; then - echo "The controller-name must be provided." - usage - exit 2 +if [ -z "${CONTROLLER_NAME}" ]; then + echo "The controller-name must be provided." + usage + exit 2 fi -if [[ -z ${OPERATION} ]]; then - echo "The operation must be provided: create|update|lock|unlock" - usage - exit 3 +if [ -z "${OPERATION}" ]; then + echo "The operation must be provided: create|update|lock|unlock" + usage + exit 3 fi -if [[ ${OPERATION} == "create" ]] || [[ ${OPERATION} == "update" ]]; then - if [[ -z ${GROUP_ID} ]]; then - echo "The maven group id must be provided when operation is create|update" - usage - exit 4 - fi - - if [[ -z ${ARTIFACT_ID} ]]; then - echo "The maven artifact id must be provided when operation is create|update" - usage - exit 5 - fi - - if [[ -z ${VERSION} ]]; then - echo "The maven version must be provided when operation is create|update" - usage - exit 6 - fi +if [ "${OPERATION}" = "create" ] || [ "${OPERATION}" = "update" ]; then + if [ -z "${GROUP_ID}" ]; then + echo "The maven group id must be provided when operation is create|update" + usage + exit 4 + fi + + if [ -z "${ARTIFACT_ID}" ]; then + echo "The maven artifact id must be provided when operation is create|update" + usage + exit 5 + fi + + if [ -z "${VERSION}" ]; then + echo "The maven version must be provided when operation is create|update" + usage + exit 6 + fi fi -UPDATE_BODY=$(< <(cat <<EOF +UPDATE_BODY=$(cat <<EOF { "requestID": "${REQUEST_ID}", "entity": "controller", @@ -140,11 +139,10 @@ UPDATE_BODY=$(< <(cat <<EOF "operation": "${OPERATION}" }] } - EOF -)) +) -LOCK_BODY=$(< <(cat <<EOF +LOCK_BODY=$(cat <<EOF { "requestID": "${REQUEST_ID}", "entity": "controller", @@ -155,46 +153,46 @@ LOCK_BODY=$(< <(cat <<EOF } EOF -)) +) unset http_proxy -if [[ ${OPERATION} == "lock" ]] || [[ ${OPERATION} == "unlock" ]]; then - if [[ -n ${API_KEY} ]]; then - DATE=$(date) - DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) - curl --silent -X POST \ - --header "Accept:" \ - --header "X-CambriaDate: ${DATE}" \ - --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ - --header "Content-Type: application/json" \ - --data "${LOCK_BODY}" \ - http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC} - else - curl --silent -X POST \ - --header "Accept:" \ - --header "Content-Type: application/json" \ - --data "${LOCK_BODY}" \ - http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC} - fi +if [ "${OPERATION}" = "lock" ] || [ "${OPERATION}" = "unlock" ]; then + if [ -n "${API_KEY}" ]; then + DATE=$(date) + DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) + curl --silent -X POST \ + --header "Accept:" \ + --header "X-CambriaDate: ${DATE}" \ + --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ + --header "Content-Type: application/json" \ + --data "${LOCK_BODY}" \ + http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC} + else + curl --silent -X POST \ + --header "Accept:" \ + --header "Content-Type: application/json" \ + --data "${LOCK_BODY}" \ + http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC} + fi fi -if [[ ${OPERATION} == "create" ]] || [[ ${OPERATION} == "update" ]]; then - if [[ -n ${API_KEY} ]]; then - DATE=$(date) - DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) - curl --silent -X POST \ - --header "Accept:" \ - --header "X-CambriaDate: ${DATE}" \ - --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ - --header "Content-Type: application/json" \ - --data "${UPDATE_BODY}" \ - http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC} - else - curl --silent -X POST \ - --header "Accept:" \ - --header "Content-Type: application/json" \ - --data "${UPDATE_BODY}" \ - http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC} - fi +if [ "${OPERATION}" = "create" ] || [ "${OPERATION}" = "update" ]; then + if [ -n "${API_KEY}" ]; then + DATE=$(date) + DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) + curl --silent -X POST \ + --header "Accept:" \ + --header "X-CambriaDate: ${DATE}" \ + --header "X-CambriaAuth: ${API_KEY}:${DATE_HASH}" \ + --header "Content-Type: application/json" \ + --data "${UPDATE_BODY}" \ + http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC} + else + curl --silent -X POST \ + --header "Accept:" \ + --header "Content-Type: application/json" \ + --data "${UPDATE_BODY}" \ + http://${BUS_HOST}:${BUS_PORT}/events/${TOPIC} + fi fi diff --git a/policy-management/src/main/server-gen/bin/policy-management-controller b/policy-management/src/main/server-gen/bin/policy-management-controller index 1d9633bc..3d6fb190 100644 --- a/policy-management/src/main/server-gen/bin/policy-management-controller +++ b/policy-management/src/main/server-gen/bin/policy-management-controller @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP POLICY @@ -25,13 +25,13 @@ PNAME=policy-management CLASS=org.onap.policy.drools.system.Main function start() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- start --" set -x fi um_start - if [[ ${RETVAL} != 0 ]]; then + if [ $RETVAL -ne 0 ]; then update_monitor off else update_monitor on @@ -39,8 +39,8 @@ function start() { } function preRunning() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- preRunning --" set -x fi @@ -51,25 +51,24 @@ function preRunning() { source ${POLICY_HOME}/etc/profile.d/env.sh ${POLICY_HOME}/bin/configure-maven - JVM_OPTS=(${JVM_OPTIONS}) # If 'system.properties' exists, convert it into "-D" JVM arguments. # Note that the following also handles property values with spaces. - IFS=$'\n' - systemProperties=($( - if [[ -f $_DIR/config/system.properties ]]; then + + systemProperties=$( + if [ -f "$_DIR/config/system.properties" ]; then sed -n -e 's/^[ \t]*\([^ \t#]*\)[ \t]*=[ \t]*\(.*\)$/-D\1=\2/p' \ $_DIR/config/system.properties fi - )) + ) cd $_DIR } function exec_start() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- exec_start --" set -x fi @@ -80,13 +79,18 @@ function exec_start() { fi preRunning - exec $JAVA_HOME/bin/java "${JVM_OPTS[@]}" -cp $_DIR/config:$_DIR/lib:$CP "${systemProperties[@]}" "$@" $CLASS + exec $JAVA_HOME/bin/java ${JVM_OPTIONS} -cp $_DIR/config:$_DIR/lib:$CP ${systemProperties} "$@" $CLASS +} + +# adding timestamp for stdout and stderr +function timestamp () { + exec awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' } # unmonitored start, does not change monitor status (immutable) function um_start() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- um_start --" set -x fi @@ -104,15 +108,8 @@ function um_start() { if [ -e $_LOGS/$PNAME.err ]; then mv $_LOGS/$PNAME.err $_LOGS/$PNAME.err.1; fi ( - if [[ "${cfg}" != "" ]]; then - # need to make sure that we don't pass the lock file descriptor - # to subprocesses - exec {cfg}>&- - fi - nohup $JAVA_HOME/bin/java "${JVM_OPTS[@]}" -cp $_DIR/config:$_DIR/lib:$CP "${systemProperties[@]}" "$@" $CLASS > >(while read line; do echo "$(date): ${line}"; done >$_LOGS/$PNAME.out) 2> >(while read line; do echo "$(date): ${line}"; done >$_LOGS/$PNAME.err) & - - _PID=$! - echo $_PID >$_PIDFILE + exec 200>&- + ( ( nohup $JAVA_HOME/bin/java ${JVM_OPTIONS} -cp $_DIR/config:$_DIR/lib:$CP ${systemProperties} "$@" $CLASS ) | timestamp > $_LOGS/$PNAME.out ) 2>&1 | timestamp > $_LOGS/$PNAME.err & ) sleep 5 status @@ -127,8 +124,8 @@ function um_start() { } function stop() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- stop --" set -x fi @@ -138,8 +135,8 @@ function stop() { # unmonitored stop, does not change monitor status (immutable) function um_stop() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- um_stop --" set -x fi @@ -148,7 +145,7 @@ function um_stop() { echo $_STATUS remove_pid_file else - if [[ -n ${TELEMETRY_PASSWORD} ]]; then + if [ -n "${TELEMETRY_PASSWORD}" ]; then http_proxy= timeout 10 curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X DELETE https://localhost:${TELEMETRY_PORT}/policy/pdp/engine -o /dev/null else http_proxy= timeout 10 curl -k --silent -X DELETE https://localhost:${TELEMETRY_PORT}/policy/pdp/engine -o /dev/null @@ -174,15 +171,15 @@ function um_stop() { } function status() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- status --" set -x fi if [ -f "${_PIDFILE}" ]; then _PID=$(cat "${_PIDFILE}") check_status_of_pid "$_PID" - elif [[ ${POLICY_DOCKER} == true ]] && _PID=$(pidof -s java); then + elif [ ${POLICY_DOCKER} ] && _PID=$(pidof -s java); then echo "${_PID}" > ${_PIDFILE} check_status_of_pid "$_PID" else @@ -190,7 +187,7 @@ function status() { _RUNNING=0 fi - if [[ $_RUNNING == 1 ]]; then + if [ "$_RUNNING" = "1" ]; then RETVAL=0 else RETVAL=1 @@ -198,8 +195,8 @@ function status() { } function check_status_of_pid() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- check_status_of_pid --" set -x fi @@ -213,8 +210,8 @@ function check_status_of_pid() { } function remove_pid_file() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- remove_pid_file --" set -x fi @@ -224,13 +221,13 @@ function remove_pid_file() { } function update_monitor() { - if [[ $DEBUG == y ]]; then - echo "-- ${FUNCNAME[0]} --" + if [ "$DEBUG" = "y" ]; then + echo "-- update_monitor --" set -x fi STATUS=$1 - if [[ -f ${POLICY_HOME}/etc/monitor/monitor.cfg ]]; then + if [ -f "${POLICY_HOME}"/etc/monitor/monitor.cfg ]; then /bin/sed -i.bak \ -e "s/^${CONTROLLER}=.*/${CONTROLLER}=${STATUS}/g" \ ${POLICY_HOME}/etc/monitor/monitor.cfg @@ -239,7 +236,7 @@ function update_monitor() { # main -if [[ ${DEBUG} == y ]]; then +if [ "${DEBUG}" = "y" ]; then echo "-- $0 $* --" set -x fi @@ -247,7 +244,7 @@ fi _DIR=${POLICY_HOME} _LOGS=${POLICY_LOGS} -if [[ -z ${POLICY_LOGS} ]]; then +if [ -z "${POLICY_LOGS}" ]; then _LOGS="${POLICY_HOME}"/logs fi @@ -263,9 +260,9 @@ status) echo "$_STATUS" ;; start) - if flock ${cfg}; then + if flock 200; then start - fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock + fi 200>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock ;; umstart) um_start @@ -274,19 +271,19 @@ exec) exec_start ;; stop) - if flock ${cfg}; then + if flock 200; then stop - fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock + fi 200>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock ;; umstop) um_stop ;; restart) - if flock ${cfg}; then - stop - sleep 2 - start - fi {cfg}>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock + if flock 200; then + stop + sleep 2 + start + fi 200>>${POLICY_HOME}/etc/monitor/monitor.cfg.lock ;; *) echo "error: invalid option $@" diff --git a/policy-management/src/main/server-gen/bin/rest-add-controller b/policy-management/src/main/server-gen/bin/rest-add-controller index 1c7dfbc1..3bd02be8 100644 --- a/policy-management/src/main/server-gen/bin/rest-add-controller +++ b/policy-management/src/main/server-gen/bin/rest-add-controller @@ -1,4 +1,4 @@ -#! /bin/bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP @@ -8,7 +8,7 @@ # 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 @@ -22,14 +22,14 @@ source $POLICY_HOME/etc/profile.d/env.sh json=$1-controller.rest.json -if [ -f ${json} ]; then - if [[ -n ${TELEMETRY_PASSWORD} ]]; then - curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X POST --data @${json} --header "Content-Type: application/json" \ - https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers - else - curl -k --silent -X POST --data @${json} --header "Content-Type: application/json" \ - https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers - fi +if [ -f "${json}" ]; then + if [ -n "${TELEMETRY_PASSWORD}" ]; then + curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X POST --data @${json} --header "Content-Type: application/json" \ + https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers + else + curl -k --silent -X POST --data @${json} --header "Content-Type: application/json" \ + https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers + fi else - echo "Usage: rest-add-controller.sh closed-loop-sample|reporter|sepc|vsegw|.. (or any other config file ending with *-controller.rest.json)" + echo "Usage: rest-add-controller.sh closed-loop-sample|reporter|sepc|vsegw|.. (or any other config file ending with *-controller.rest.json)" fi diff --git a/policy-management/src/main/server-gen/bin/rest-delete-controller b/policy-management/src/main/server-gen/bin/rest-delete-controller index c2741191..8a8b9f65 100644 --- a/policy-management/src/main/server-gen/bin/rest-delete-controller +++ b/policy-management/src/main/server-gen/bin/rest-delete-controller @@ -1,4 +1,4 @@ -#! /bin/bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP @@ -20,8 +20,8 @@ source $POLICY_HOME/etc/profile.d/env.sh -if [[ -n $1 ]]; then - if [[ -n ${TELEMETRY_PASSWORD} ]]; then +if [ -n "$1" ]; then + if [ -n "${TELEMETRY_PASSWORD}" ]; then curl -k --silent --user ${TELEMETRY_USER}:${TELEMETRY_PASSWORD} -X DELETE --header "Content-Type: application/json" \ https://localhost:${TELEMETRY_PORT}/policy/pdp/engine/controllers/${1} else diff --git a/policy-management/src/main/server-gen/bin/telemetry b/policy-management/src/main/server-gen/bin/telemetry index 9d4b857a..cead3d3a 100644 --- a/policy-management/src/main/server-gen/bin/telemetry +++ b/policy-management/src/main/server-gen/bin/telemetry @@ -1,4 +1,4 @@ -#! /bin/bash +#!/usr/bin/env ash # ============LICENSE_START======================================================= # ONAP @@ -33,7 +33,7 @@ if ! "${POLICY_HOME}"/bin/policy-management-controller status >/dev/null 2>&1; t exit 2 fi -if [[ ! -r ${TELEMETRY_SPEC} ]]; then +if [ ! -r "${TELEMETRY_SPEC}" ]; then echo "generating new spec .." if ! http --verify=no -a "${TELEMETRY_USER}:${TELEMETRY_PASSWORD}" https://localhost:9696/swagger.json >${TELEMETRY_SPEC} 2>/dev/null; then echo "error: cannot generate telemetry spec" |