From b395d8251fffd36040d47c88b1346c5655d56a21 Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Mon, 24 Jul 2017 08:48:51 -0500 Subject: [POLICY-66] consolidate script naming + location consolidate scripting convention by all adopting not .sh for bash scripts. Location is under policy-management/src/main/server-gen/bin/ so they are inherited by lab installations that don't use the packages directory. Change-Id: Ibcbd4bffad38e87cb3b644deb768120b1a6b2cbb Signed-off-by: Jorge Hernandez --- .../main/server-gen/bin/add-secured-participant | 122 ++++ .../main/server-gen/bin/add-secured-participant.sh | 122 ---- .../src/main/server-gen/bin/create-api-key | 76 +++ .../src/main/server-gen/bin/create-api-key.sh | 76 --- .../src/main/server-gen/bin/create-secured-topic | 130 +++++ .../main/server-gen/bin/create-secured-topic.sh | 130 ----- policy-management/src/main/server-gen/bin/features | 640 +++++++++++++++++++++ .../src/main/server-gen/bin/pdpd-configuration | 200 +++++++ .../src/main/server-gen/bin/pdpd-configuration.sh | 200 ------- .../src/main/server-gen/bin/rest-add-controller | 37 ++ .../src/main/server-gen/bin/rest-add-controller.sh | 37 -- .../src/main/server-gen/bin/rest-delete-controller | 43 ++ .../main/server-gen/bin/rest-delete-controller.sh | 43 -- .../src/main/server-gen/bin/telemetry | 44 ++ .../src/main/server-gen/bin/telemetry.sh | 44 -- 15 files changed, 1292 insertions(+), 652 deletions(-) create mode 100644 policy-management/src/main/server-gen/bin/add-secured-participant delete mode 100644 policy-management/src/main/server-gen/bin/add-secured-participant.sh create mode 100644 policy-management/src/main/server-gen/bin/create-api-key delete mode 100644 policy-management/src/main/server-gen/bin/create-api-key.sh create mode 100644 policy-management/src/main/server-gen/bin/create-secured-topic delete mode 100644 policy-management/src/main/server-gen/bin/create-secured-topic.sh create mode 100644 policy-management/src/main/server-gen/bin/features create mode 100644 policy-management/src/main/server-gen/bin/pdpd-configuration delete mode 100644 policy-management/src/main/server-gen/bin/pdpd-configuration.sh create mode 100644 policy-management/src/main/server-gen/bin/rest-add-controller delete mode 100644 policy-management/src/main/server-gen/bin/rest-add-controller.sh create mode 100644 policy-management/src/main/server-gen/bin/rest-delete-controller delete mode 100644 policy-management/src/main/server-gen/bin/rest-delete-controller.sh create mode 100644 policy-management/src/main/server-gen/bin/telemetry delete mode 100644 policy-management/src/main/server-gen/bin/telemetry.sh (limited to 'policy-management/src/main/server-gen/bin') diff --git a/policy-management/src/main/server-gen/bin/add-secured-participant b/policy-management/src/main/server-gen/bin/add-secured-participant new file mode 100644 index 00000000..d6843fee --- /dev/null +++ b/policy-management/src/main/server-gen/bin/add-secured-participant @@ -0,0 +1,122 @@ +#! /bin/bash + +### +# ============LICENSE_START======================================================= +# policy-management +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +function usage() { + echo -n "Usage: $(basename $0) " + echo -n "[(-d|--debug)] " + echo -n "(-h|--host) " + echo -n "[(-p|--port) ] " + echo -n "(-k|--key) " + echo -n "(-s|--secret) " + echo -n "(-P|--producer-key) " + echo -n "(-C|--consumer-key) " + echo "(-t|--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 +done + +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 +fi + +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 +fi + +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 +fi + + +DATE=$(date) +DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) + +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} diff --git a/policy-management/src/main/server-gen/bin/add-secured-participant.sh b/policy-management/src/main/server-gen/bin/add-secured-participant.sh deleted file mode 100644 index d6843fee..00000000 --- a/policy-management/src/main/server-gen/bin/add-secured-participant.sh +++ /dev/null @@ -1,122 +0,0 @@ -#! /bin/bash - -### -# ============LICENSE_START======================================================= -# policy-management -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END========================================================= -### - -function usage() { - echo -n "Usage: $(basename $0) " - echo -n "[(-d|--debug)] " - echo -n "(-h|--host) " - echo -n "[(-p|--port) ] " - echo -n "(-k|--key) " - echo -n "(-s|--secret) " - echo -n "(-P|--producer-key) " - echo -n "(-C|--consumer-key) " - echo "(-t|--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 -done - -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 -fi - -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 -fi - -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 -fi - - -DATE=$(date) -DATE_HASH=$(echo -n "${DATE}" | openssl sha1 -hmac "${API_SECRET}" -binary | openssl base64) - -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} diff --git a/policy-management/src/main/server-gen/bin/create-api-key b/policy-management/src/main/server-gen/bin/create-api-key new file mode 100644 index 00000000..ea0ec7ad --- /dev/null +++ b/policy-management/src/main/server-gen/bin/create-api-key @@ -0,0 +1,76 @@ +#! /bin/bash + +### +# ============LICENSE_START======================================================= +# policy-management +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +function usage() { + echo -n "Usage: $(basename $0) " + echo -n "[(-d|--debug)] " + echo -n "(-h|--host) " + echo -n "[(-p|--port) ] " + echo "(-e|--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 +done + +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 +fi + +REQUEST_API_KEY_BODY=$(< <(cat < " - echo -n "[(-p|--port) ] " - echo "(-e|--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 -done - -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 -fi - -REQUEST_API_KEY_BODY=$(< <(cat < " + echo -n "[(-p|--port) ] " + echo -n "(-k|--key) " + echo -n "(-s|--secret) " + echo -n "[(-P|--partition) ] " + echo -n "[(-R|--replication) ] " + echo "(-t|--topic) " + echo "" +} + +BUS_PORT=3904 +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 +done + +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 +fi + +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 +fi + +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 +fi + +REQUEST_API_KEY_BODY=$(< <(cat < " - echo -n "[(-p|--port) ] " - echo -n "(-k|--key) " - echo -n "(-s|--secret) " - echo -n "[(-P|--partition) ] " - echo -n "[(-R|--replication) ] " - echo "(-t|--topic) " - echo "" -} - -BUS_PORT=3904 -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 -done - -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 -fi - -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 -fi - -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 -fi - -REQUEST_API_KEY_BODY=$(< <(cat <*/ +#     └── [config]/ +#     │   └── * +#     └── lib/ +#     │  └── [dependencies]/ +#     │  │ └── * +#     │  └── feature/ +#     │  └── +#     └── [install] +#      └── [enable] +#      └── [disable] +#      └── [other-future-operations] +#      └── [other-files] +# +# directory should not have the "feature-" prefix. +# preferable with "feature-" prefix. +# +# Example: +# +# POLICY_HOME/ +# └── features/ +# ├── eelf/ +# │   ├── config/ +# │   │   ├── logback-eelf.xml +# │   └── lib/ +# │   │ └── dependencies/ +# │   │ │ └── ECOMP-Logging-1.1.0-SNAPSHOT.jar +# │   │ │ └── eelf-core-1.0.0.jar +# │   │ └── feature/ +# │   │ └── feature-eelf-1.1.0-SNAPSHOT.jar +# │   └── install/ +# │   └── enable +# │   └── disable +# └── healthcheck/ +# ├── config/ +# │   └── feature-healthcheck.properties +# └── lib/ +# └── feature/ +# └── feature-healthcheck-1.1.0-SNAPSHOT.jar +# ############################################################# + +if [[ ${DEBUG} == y ]]; then + echo "-- MAIN --" + set -x +fi + +# The directories at play + +LIB=${POLICY_HOME}/lib +CONFIG=${POLICY_HOME}/config +FEATURES=${POLICY_HOME}/features + +if [[ ! ( -d "${LIB}" && -x "${LIB}" ) ]]; then + echo "ERROR: no ${LIB} directory" + exit 1 +fi + +if [[ ! ( -d "${CONFIG}" && -x "${CONFIG}" ) ]]; then + echo "ERROR: no ${CONFIG} directory" + exit 2 +fi + +if [[ ! ( -d "${FEATURES}" && -x "${FEATURES}" ) ]]; then + echo "ERROR: no ${FEATURES} directory" + exit 3 +fi + +# relative per Feature Directory Paths + +FEATURE_DEPS="lib/dependencies" +FEATURE_LIB="lib/feature" +FEATURE_CONFIG="config" +FEATURE_INSTALL="install" + +featureJars=$(find "${FEATURES}" -name "feature-*.jar" -type f -exec basename {} \; 2> /dev/null) +if [[ -z ${featureJars} ]]; then + echo "no features" + usage + exit 0 +fi + +# default field lengths +nameLength=20 +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 +done + +# ########################################################## +# usage: usage information +# ########################################################## +function usage +{ + # print out usage information + cat >&2 <<-'EOF' + Usage: features status + Get enabled/disabled status on all features + features enable ... + Enable the specified feature + features disable ... + Disable the specified feature + 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 +} + +# ########################################################## +# depEnableAnalysis(featureName): +# reports on potential dependency conflicts +# featureName: name of the feature +# ########################################################## +function depEnableAnalysis() +{ + if [[ ${DEBUG} == y ]]; then + echo "-- ${FUNCNAME[0]} $@ --" + set -x + fi + + local featureName="$1" + local featureDepJars featureDepJarPath depJarName multiVersionJars + + if [[ -z ${featureName} ]]; then + echo "WARN: 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 "WARN: 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 + + multiVersionJars=$(ls "${LIB}"/"${depJarName%%-[0-9]*.jar}"-*.jar 2> /dev/null) + if [[ -n "${multiVersionJars}" ]]; then + echo "WARN: other version of library ${depJarName} present: ${multiVersionJars}" + return 2 + fi + done +} + +# ########################################################## +# configEnableAnalysis(featureName): +# reports on potential dependency conflicts +# featureName: name of the feature +# ########################################################## +function configEnableAnalysis() +{ + if [[ ${DEBUG} == y ]]; then + echo "-- ${FUNCNAME[0]} $@ --" + set -x + fi + + local featureName="$1" + local featureConfigs configPath configFileName + + if [[ -z ${featureName} ]]; then + echo "WARN: 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 "${LIB}"/"${configFileName}" ]]; then + echo "ERROR: a config file of the same name is already in the base: ${configFileName}" + return 2 + fi + done +} + +# ########################################################## +# 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 "WARN: 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): +# 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 "WARN: 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 +} + +# ########################################################## +# enableFeatureOp(featureName): 'enable' feature operation +# featureName: name of the feature +# ########################################################## +function enableFeatureOp() +{ + if [[ ${DEBUG} == y ]]; then + echo "-- ${FUNCNAME[0]} $@ --" + set -x + fi + + local featureName="$1" + + if [[ -z ${featureName} ]]; then + echo "WARN: no feature name" + return 1 + fi + + enableScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/enable + if [[ -f ${enableScript} ]]; then + ( + cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}" + chmod u+x enable + ./enable + ) + fi +} + +# ########################################################## +# enableFeature(featureName, featureJar): enables a feature +# featureName: name of the feature +# featureJar: path to feature jar implementation +# ########################################################## +function enableFeature() +{ + if [[ $DEBUG == y ]]; then + echo "-- ${FUNCNAME[0]} $@ --" + set -x + fi + + local featureName="$1" + local featureJar="$2" + + if [[ -z ${featureName} ]]; then + echo "WARN: no feature name" + return 1 + fi + + if [[ -z ${featureJar} ]]; then + echo "WARN: no feature jar" + return 2 + fi + + if ! depEnableAnalysis "${featureName}"; then + return 3 + fi + + if ! configEnableAnalysis "${featureName}"; then + return 4 + fi + + # enable feature itself + + ln -s -f "${featureJar}" "${LIB}/" + + # enable dependent libraries if any + + enableFeatureDeps "${featureName}" + + # enable configuration + + enableFeatureConfig "${featureName}" + + # TODO: run feature install DB scripts if any + + # run custom enable if any + + enableFeatureOp "${featureName}" +} + +# ########################################################## +# 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 "WARN: 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 +} + +# ########################################################## +# 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 "WARN: 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 +} + +# ########################################################## +# disableFeatureOp(featureName): 'enable' feature operation +# featureName: name of the feature +# ########################################################## +function disableFeatureOp() +{ + if [[ ${DEBUG} == y ]]; then + echo "-- ${FUNCNAME[0]} $@ --" + set -x + fi + + local featureName="$1" + + if [[ -z ${featureName} ]]; then + echo "WARN: no feature name" + return 1 + fi + + disableScript="${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}"/disable + if [[ -f ${disableScript} ]]; then + ( + cd "${FEATURES}"/"${featureName}"/"${FEATURE_INSTALL}" + chmod u+x disable + ./disable + ) + fi +} + +# ########################################################## +# disableFeature(featureName, featureJar): enables a feature +# featureName: name of the feature +# ########################################################## +function disableFeature() +{ + if [[ ${DEBUG} == y ]]; then + echo "-- ${FUNCNAME[0]} $@ --" + set -x + fi + + local featureName="$1" + + if [[ -z ${featureName} ]]; then + echo "WARN: 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}" + + # run feature uninstall DB scripts if any + # TODO: future + + # run custom disable if any + disableFeatureOp "${featureName}" +} + +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 + };; + + *) + { + 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 new file mode 100644 index 00000000..8c553927 --- /dev/null +++ b/policy-management/src/main/server-gen/bin/pdpd-configuration @@ -0,0 +1,200 @@ +#! /bin/bash + +### +# ============LICENSE_START======================================================= +# policy-management +# ================================================================================ +# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +### + +function usage() { + echo -n "Usage: $(basename $0) " + echo -n "[(-d|--debug)] " + echo -n "(-h|--host) " + echo -n "[(-p|--port) ] " + echo -n "[(-k|--key) ] " + echo -n "[(-s|--secret) ] " + echo -n "[(-r|--request-id) ] " + echo -n "(-c|--controller-name) " + echo -n "(-o|--operation) " + echo -n "[(-g|--group-id) " + echo -n "(-a|--artifact-id) " + echo -n "(-v|--version) ] " + echo -n "[(-t|--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 +done + +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 +fi + +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 +fi + +UPDATE_BODY=$(< <(cat < " - echo -n "[(-p|--port) ] " - echo -n "[(-k|--key) ] " - echo -n "[(-s|--secret) ] " - echo -n "[(-r|--request-id) ] " - echo -n "(-c|--controller-name) " - echo -n "(-o|--operation) " - echo -n "[(-g|--group-id) " - echo -n "(-a|--artifact-id) " - echo -n "(-v|--version) ] " - echo -n "[(-t|--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 -done - -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 -fi - -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 -fi - -UPDATE_BODY=$(< <(cat < /dev/null 2>&1; then + echo "error: prerequisite software not found: http-prompt" + exit 1 +fi + +if ! "${POLICY_HOME}"/bin/policy-management-controller status > /dev/null 2>&1; then + echo "error: pdp-d is not running" + exit 2 +fi + +if [[ ! -r ${TELEMETRY_SPEC} ]]; then + echo "generating new spec .." + if ! http -a "${ENGINE_MANAGEMENT_USER}:${ENGINE_MANAGEMENT_PASSWORD}" :9696/swagger.json > ${TELEMETRY_SPEC} 2> /dev/null; then + echo "error: cannot generate telemetry spec" + exit 3 + fi +fi + +exec http-prompt http://localhost:9696/policy/pdp/engine --auth "${ENGINE_MANAGEMENT_USER}:${ENGINE_MANAGEMENT_PASSWORD}" --spec ${TELEMETRY_SPEC} diff --git a/policy-management/src/main/server-gen/bin/telemetry.sh b/policy-management/src/main/server-gen/bin/telemetry.sh deleted file mode 100644 index 397c2508..00000000 --- a/policy-management/src/main/server-gen/bin/telemetry.sh +++ /dev/null @@ -1,44 +0,0 @@ -#! /bin/bash - -### -# ============LICENSE_START======================================================= -# ONAP POLICY -# ================================================================================ -# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END========================================================= -## - -REST_TOOL="http-prompt" -TELEMETRY_SPEC="${POLICY_HOME}/config/telemetry-spec.json" - -if ! type -p "${REST_TOOL}" > /dev/null 2>&1; then - echo "error: prerequisite software not found: http-prompt" - exit 1 -fi - -if ! "${POLICY_HOME}"/bin/policy-management-controller status > /dev/null 2>&1; then - echo "error: pdp-d is not running" - exit 2 -fi - -if [[ ! -r ${TELEMETRY_SPEC} ]]; then - echo "generating new spec .." - if ! http -a "${ENGINE_MANAGEMENT_USER}:${ENGINE_MANAGEMENT_PASSWORD}" :9696/swagger.json > ${TELEMETRY_SPEC} 2> /dev/null; then - echo "error: cannot generate telemetry spec" - exit 3 - fi -fi - -exec http-prompt http://localhost:9696/policy/pdp/engine --auth "${ENGINE_MANAGEMENT_USER}:${ENGINE_MANAGEMENT_PASSWORD}" --spec ${TELEMETRY_SPEC} -- cgit 1.2.3-korg