Init DB Using envsubst 45/118945/1
authorGuangrongFu <fu.guangrong@zte.com.cn>
Tue, 9 Mar 2021 10:28:13 +0000 (18:28 +0800)
committerGuangrongFu <fu.guangrong@zte.com.cn>
Tue, 9 Mar 2021 10:28:13 +0000 (18:28 +0800)
Change-Id: I764626136258f3fb23561ee90a46653ebdbe9413
Issue-ID: HOLMES-396
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
rulemgt-standalone/src/main/assembly/bin/initDB.sh
rulemgt-standalone/src/main/assembly/bin/run.sh
version.properties

index 46fb1e6..32ba72a 100644 (file)
@@ -25,9 +25,13 @@ host=$5
 echo "Initializing the holmes rule management database..."
 main_path=$HOME/..
 
-sed -i "s|DBNAME|$dbname|g" "$main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql"
-sed -i "s|DBUSER|$user|g" "$main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql"
-sed -i "s|DBPWD|$password|g" "$main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql"
+if [[ -d /opt/hrmconfig ]]; then
+    cp /opt/hrmconfig/onap-holmes_rulemgt-createobj.sql "$main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql"
+else
+    sed -i "s|DBNAME|$dbname|g" "$main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql"
+    sed -i "s|DBUSER|$user|g" "$main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql"
+    sed -i "s|DBPWD|$password|g" "$main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql"
+fi
 
 cat $main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql
 echo "dbname=$dbname"
@@ -35,11 +39,20 @@ echo "user=$user"
 echo "password=$password"
 echo "port=$port"
 echo "host=$host"
-export PGPASSWORD=$password
-psql -U $user -p $port -h $host -d $dbname -f $main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql
-psql -U $user -p $port -h $host -d $dbname --command 'select * from aplus_rule;'
+
+if [[ -z `env | grep PGPASSWORD` ]]; then
+    export PGPASSWORD=$password
+    need_unset=1
+fi
+
+psql -U "$user" -p "$port" -h "$host" -d "$dbname" -f $main_path/dbscripts/postgresql/onap-holmes_rulemgt-createobj.sql
+psql -U "$user" -p "$port" -h "$host" -d "$dbname" --command 'select * from aplus_rule;'
 sql_result=$?
-unset PGPASSWORD
+
+if [[ $need_unset -eq 1 ]]; then
+    unset PGPASSWORD
+fi
+
 echo "sql_result=$sql_result"
 if [ $sql_result != 0 ] ; then
    echo "Failed to initialize the database!"
index bb5884b..3e0ff97 100644 (file)
@@ -48,10 +48,14 @@ if [ -z ${DB_NAME} ]; then
     echo "No database is name is specified. Use the default value \"$DB_NAME\"."
 fi
 
-sed -i "s|user:.*|user: $JDBC_USERNAME|" "$main_path/conf/rulemgt.yml"
-sed -i "s|password:.*|password: $JDBC_PASSWORD|" "$main_path/conf/rulemgt.yml"
-sed -i "s|url:.*|url: jdbc:postgresql://$URL_JDBC/$DB_NAME|" "$main_path/conf/rulemgt.yml"
-sed -i "s|msbServerAddr:.*|msbServerAddr: http://$MSB_ADDR|" "$main_path/conf/rulemgt.yml"
+# if deployed using helm, use the helm-generated configuration file.
+if [[ -d /opt/hrmconfig ]]; then
+    cp /opt/hrmconfig/rulemgt.yml "$main_path/conf/rulemgt.yml"
+else
+    sed -i "s|user:.*|user: $JDBC_USERNAME|" "$main_path/conf/rulemgt.yml"
+    sed -i "s|password:.*|password: $JDBC_PASSWORD|" "$main_path/conf/rulemgt.yml"
+    sed -i "s|url:.*|url: jdbc:postgresql://$URL_JDBC/$DB_NAME|" "$main_path/conf/rulemgt.yml"
+fi
 
 export SERVICE_IP=`hostname -i`
 echo SERVICE_IP=${SERVICE_IP}
@@ -96,7 +100,7 @@ else
 fi
 
 
-${RUNHOME}/initDB.sh $JDBC_USERNAME $JDBC_PASSWORD $DB_NAME $DB_PORT "${URL_JDBC%:*}"
+${RUNHOME}/initDB.sh "$JDBC_USERNAME" "$JDBC_PASSWORD" "$DB_NAME" "$DB_PORT" "${URL_JDBC%:*}"
 
 
 #Register the fronten to MSB
index e4b2e4a..70bc126 100644 (file)
@@ -3,8 +3,8 @@
 # because they are used in Jenkins, whose plug-in doesn't support\r
 \r
 major=1\r
-minor=2\r
-patch=9\r
+minor=3\r
+patch=0\r
 \r
 base_version=${major}.${minor}.${patch}\r
 \r