Merge "Allowing configuration of truststore password"
[policy/apex-pdp.git] / packages / apex-pdp-package-full / src / main / package / scripts / apexApps.sh
1 #!/usr/bin/env bash
2
3 #-------------------------------------------------------------------------------
4 # ============LICENSE_START=======================================================
5 #  Copyright (C) 2016-2018 Ericsson. All rights reserved.
6 #  Modifications Copyright (C) 2019-2020 Nordix Foundation.
7 # ================================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #      http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20 # SPDX-License-Identifier: Apache-2.0
21 # ============LICENSE_END=========================================================
22 #-------------------------------------------------------------------------------
23 ##
24 ## Script to run APEX Applications, call with '-h' for help
25 ## - requires BASH with associative arrays, bash of at least version 4
26 ## - for BASH examples with arrays see for instance: http://www.artificialworlds.net/blog/2012/10/17/bash-associative-array-examples/
27 ## - adding a new app means to add a command to APEX_APP_MAP and a description to APEX_APP_DESCR_MAP using same/unique key
28 ##
29 ## @package    org.onap.policy.apex
30 ## @author     Sven van der Meer <sven.van.der.meer@ericsson.com>
31 ## @version    v2.0.0
32
33 ##
34 ## DO NOT CHANGE CODE BELOW, unless you know what you are doing
35 ##
36
37 if [ -z $APEX_HOME ]
38 then
39     APEX_HOME="/opt/app/policy/apex-pdp"
40 fi
41
42 if [ ! -d $APEX_HOME ]
43 then
44     echo
45     echo 'Apex directory "'$APEX_HOME'" not set or not a directory'
46     echo "Please set environment for 'APEX_HOME'"
47     exit
48 fi
49
50 ## Environment variables for HTTPS
51 KEYSTORE="${APEX_HOME}/etc/ssl/policy-keystore"
52 TRUSTSTORE="${APEX_HOME}/etc/ssl/policy-truststore"
53
54 ## HTTPS parameters
55 HTTPS_PARAMETERS="-Djavax.net.ssl.keyStore=${KEYSTORE} -Djavax.net.ssl.keyStorePassword=${KEYSTORE_PASSWD:-Pol1cy_0nap} -Djavax.net.ssl.trustStore=$TRUSTSTORE -Djavax.net.ssl.trustStorePassword=${TRUSTSTORE_PASSWD:-Pol1cy_0nap}"
56
57 ## script name for output
58 MOD_SCRIPT_NAME=`basename $0`
59
60 ## check BASH version, we need >=4 for associative arrays
61 if [ "${BASH_VERSION:0:1}" -lt 4 ] ; then
62     echo
63     echo "$MOD_SCRIPT_NAME: requires bash 4 or higher for associative arrays"
64     echo
65     exit
66 fi
67
68 ## config for CP apps
69 _config="${HTTPS_PARAMETERS} -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -Dhazelcast.config=$APEX_HOME/etc/hazelcast.xml -Dhazelcast.mancenter.enabled=false"
70
71 ## jmx test config
72 _jmxconfig="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9911 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false "
73
74 ## Maven/APEX version
75 _version=`cat $APEX_HOME/etc/app-version.txt`
76
77 ## system to get CygWin paths
78 system=`uname -s | cut -c1-6`
79 cpsep=":"
80 if [ "$system" == "CYGWIN" ] ; then
81     APEX_HOME=`cygpath -m ${APEX_HOME}`
82     cpsep=";"
83 fi
84
85 ## CP for CP apps
86 CLASSPATH="$APEX_HOME/etc${cpsep}$APEX_HOME/etc/hazelcast${cpsep}$APEX_HOME/etc/infinispan${cpsep}$APEX_HOME/lib/*"
87
88 ## array of applications with name=command
89 declare -A APEX_APP_MAP
90 APEX_APP_MAP["ws-console"]="java -jar $APEX_HOME/lib/applications/simple-wsclient-$_version-jar-with-dependencies.jar -c"
91 APEX_APP_MAP["ws-echo"]="java -jar $APEX_HOME/lib/applications/simple-wsclient-$_version-jar-with-dependencies.jar"
92 APEX_APP_MAP["tpl-event-json"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.tools.model.generator.model2event.Model2EventMain"
93 APEX_APP_MAP["model-2-cli"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.tools.model.generator.model2cli.Model2ClMain"
94 APEX_APP_MAP["cli-editor"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain"
95 APEX_APP_MAP["cli-tosca-editor"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain"
96 APEX_APP_MAP["engine"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.service.engine.main.ApexMain"
97 APEX_APP_MAP["full-client"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -jar $APEX_HOME/lib/applications/apex-client-full-$_version-full.jar"
98 APEX_APP_MAP["event-gen"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator.EventGenerator"
99 APEX_APP_MAP["onappf"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config org.onap.policy.apex.services.onappf.ApexStarterMain"
100 APEX_APP_MAP["jmx-test"]="java -Dlogback.configurationFile=$APEX_HOME/etc/logback.xml -cp ${CLASSPATH} $_config $_jmxconfig org.onap.policy.apex.service.engine.main.ApexMain"
101
102 ## array of applications with name=description
103 declare -A APEX_APP_DESCR_MAP
104 APEX_APP_DESCR_MAP["ws-console"]="a simple console sending events to APEX, connect to APEX consumer port"
105 APEX_APP_DESCR_MAP["ws-echo"]="a simple echo client printing events received from APEX, connect to APEX producer port"
106 APEX_APP_DESCR_MAP["tpl-event-json"]="provides JSON templates for events generated from a policy model"
107 APEX_APP_DESCR_MAP["model-2-cli"]="generates CLI Editor Commands from a policy model"
108 APEX_APP_DESCR_MAP["cli-editor"]="runs the APEX CLI Editor"
109 APEX_APP_DESCR_MAP["cli-tosca-editor"]="runs the APEX CLI Tosca Editor"
110 APEX_APP_DESCR_MAP["engine"]="starts the APEX engine"
111 APEX_APP_DESCR_MAP["full-client"]="starts the full APEX client (rest editor, deployment, monitoring) in a simple webserver"
112 APEX_APP_DESCR_MAP["event-generator"]="starts the event generator in a simple webserver for performance testing"
113 APEX_APP_DESCR_MAP["onappf"]="starts the ApexStarter which handles the Apex Engine based on instructions from PAP"
114 APEX_APP_DESCR_MAP["jmx-test"]="starts the APEX engine with creating jmx connection configuration"
115
116 ##
117 ## Help screen and exit condition (i.e. too few arguments)
118 ##
119 Help()
120 {
121     echo ""
122     echo "$MOD_SCRIPT_NAME - runs APEX applications"
123     echo ""
124     echo "       Usage:  $MOD_SCRIPT_NAME [options] | [<application> [<application options>]]"
125     echo ""
126     echo "       Options"
127     echo "         -d <app>    - describes an application"
128     echo "         -l          - lists all applications supported by this script"
129     echo "         -h          - this help screen"
130     echo ""
131     echo ""
132     exit 255;
133 }
134 if [ $# -eq 0 ]; then
135     Help
136 fi
137
138
139 ##
140 ## read command line, cannot do as while here due to 2-view CLI
141 ##
142 if [ "$1" == "-l" ]; then
143     echo "$MOD_SCRIPT_NAME: supported applications:"
144     echo " --> ${!APEX_APP_MAP[@]}"
145     echo ""
146     exit 0
147 fi
148 if [ "$1" == "-d" ]; then
149     if [ -z "$2" ]; then
150         echo "$MOD_SCRIPT_NAME: no application given to describe, supported applications:"
151         echo " --> ${!APEX_APP_MAP[@]}"
152         echo ""
153         exit 0;
154     else
155         _cmd=${APEX_APP_DESCR_MAP[$2]}
156         if [ -z "$_cmd" ]; then
157             echo "$MOD_SCRIPT_NAME: unknown application '$2'"
158             echo ""
159             exit 0;
160         fi
161         echo "$MOD_SCRIPT_NAME: application '$2'"
162         echo " --> $_cmd"
163         echo ""
164         exit 0;
165     fi
166 fi
167 if [ "$1" == "-h" ]; then
168     Help
169     exit 0
170 fi
171
172
173 _app=$1
174 shift
175 _cmd=${APEX_APP_MAP[$_app]}
176 if [ -z "$_cmd" ]; then
177     echo "$MOD_SCRIPT_NAME: application '$_app' not supported"
178     exit 1
179 fi
180 _cmd="$_cmd $*"
181 ## echo "$MOD_SCRIPT_NAME: running application '$_app' with command '$_cmd'"
182 exec $_cmd
183