aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Hansen <TonyLHansen@gerrit.onap.com>2017-05-05 15:08:05 +0000
committerTony Hansen <tony@att.com>2017-05-05 21:57:32 +0000
commit48feaffcb16e1fd5eb3ce453b99797de1bd15d7a (patch)
tree54f60886e301fe999cff8a33a58bef1c0bf9fb4d
parenta936f09820b61df6d27c0d788c3b185597d1470c (diff)
rebase DCAE Storage Components from OpenECOMP
[145075] Build 1707 DCAE Storage Components from OpenECOMP source Change-Id: Ie395395ad59afb658b46ecda31a079c050e2dd2e Signed-off-by: Tony Hansen <th1395@att.com> Signed-off-by: Tony Hansen <tony@att.com>
-rw-r--r--cdf/src/cdf-prop-value/cdf-prop-value/src/main/java/cdf-prop-value.jarbin1592 -> 1593 bytes
-rw-r--r--cdf/src/cdf-prop-value/cdf-util/src/main/java/cdf-util.jarbin31069 -> 31099 bytes
-rw-r--r--cdf/src/makefile14
-rw-r--r--cdf/src/repackage.json38
-rwxr-xr-xcdf/src/stage/opt/app/cdf/bin/getpropvalue2
-rwxr-xr-xcdf/src/stage/opt/app/cdf/bin/setencryptedvalues2
-rw-r--r--pgaas-post/src/makefile8
-rw-r--r--pgaas-post/src/repackage.json32
-rw-r--r--pgaas-post/src/stage/opt/app/pgaas-post/bin/pgaas-verify-install25
-rw-r--r--pgaas/src/makefile6
-rw-r--r--pgaas/src/repackage.json34
-rwxr-xr-xpgaas/src/stage/opt/app/pgaas/bin/check_cluster28
-rwxr-xr-xpgaas/src/stage/opt/app/pgaas/bin/dcae_admin_db.py74
-rwxr-xr-xpgaas/src/stage/opt/app/pgaas/bin/isrw13
-rwxr-xr-xpgaas/src/stage/opt/app/pgaas/bin/list_masters46
-rw-r--r--pgaas/src/stage/opt/app/pgaas/bin/makefile8
-rw-r--r--pgaas/src/stage/opt/app/pgaas/bin/start_maintenance_mode48
-rw-r--r--pgaas/src/stage/opt/app/pgaas/bin/stop_maintenance_mode28
-rw-r--r--pgaas/src/stage/opt/app/pgaas/man/check_cluster.man12
-rw-r--r--pgaas/src/stage/opt/app/pgaas/man/makefile4
-rw-r--r--pgaas/src/stage/opt/app/pgaas/man/start_maintenance_mode.man28
-rw-r--r--pgaas/src/stage/opt/app/pgaas/man/stop_maintenance_mode.man24
-rw-r--r--postgresql-config/src/makefile9
-rw-r--r--postgresql-config/src/repackage.json28
-rw-r--r--postgresql-config/src/stage/opt/app/postgresql-config/etc/do-post-install29
-rw-r--r--postgresql-config/src/stage/opt/app/postgresql-config/etc/gen-pgpass11
-rwxr-xr-xpostgresql-config/src/stage/opt/app/postgresql-config/etc/makecerts4
-rw-r--r--postgresql-config/src/stage/opt/app/postgresql-config/etc/start-db1
-rwxr-xr-xpostgresql-prep/src/common/postinst23
-rw-r--r--postgresql-prep/src/makefile9
-rw-r--r--postgresql-prep/src/repackage.json36
-rwxr-xr-xpostgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py23
-rw-r--r--postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron2
-rw-r--r--postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service3
-rw-r--r--postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.json58
-rw-r--r--postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.yaml68
36 files changed, 600 insertions, 178 deletions
diff --git a/cdf/src/cdf-prop-value/cdf-prop-value/src/main/java/cdf-prop-value.jar b/cdf/src/cdf-prop-value/cdf-prop-value/src/main/java/cdf-prop-value.jar
index ba5a4a7..041ad93 100644
--- a/cdf/src/cdf-prop-value/cdf-prop-value/src/main/java/cdf-prop-value.jar
+++ b/cdf/src/cdf-prop-value/cdf-prop-value/src/main/java/cdf-prop-value.jar
Binary files differ
diff --git a/cdf/src/cdf-prop-value/cdf-util/src/main/java/cdf-util.jar b/cdf/src/cdf-prop-value/cdf-util/src/main/java/cdf-util.jar
index 8c43f9a..57e01c7 100644
--- a/cdf/src/cdf-prop-value/cdf-util/src/main/java/cdf-util.jar
+++ b/cdf/src/cdf-prop-value/cdf-util/src/main/java/cdf-util.jar
Binary files differ
diff --git a/cdf/src/makefile b/cdf/src/makefile
index 4687dcd..369671a 100644
--- a/cdf/src/makefile
+++ b/cdf/src/makefile
@@ -31,25 +31,23 @@ javadocs:
stage: build clean-stage clean-common
mkdir -p $(INS)
find stage common ! -name makefile ! -name '*~' | cpio -pudmv $(INS)
- cp cdf-prop-value/cdf-prop-value/src/main/java/cdf-prop-value.jar $(INS)/stage/opt/app/cdf/lib/cdf-prop-value-1.0.0.jar
- cp cdf-prop-value/cdf-util/src/main/java/cdf-util.jar $(INS)/stage/opt/app/cdf/lib/jars/cdf-util-1.0.0.jar
+ cp -p cdf-prop-value/cdf-prop-value/src/main/java/cdf-prop-value.jar $(INS)/stage/opt/app/cdf/lib/cdf-prop-value-1.1.0.jar
+ cp -p cdf-prop-value/cdf-prop-value/src/main/java/cdf-prop-value.jar $(INS)/stage/opt/app/cdf/lib/cdf-prop-value.jar
+ cp -p cdf-prop-value/cdf-util/src/main/java/cdf-util.jar $(INS)/stage/opt/app/cdf/lib/jars/cdf-util-1.1.0.jar
+ cp -p cdf-prop-value/cdf-util/src/main/java/cdf-util.jar $(INS)/stage/opt/app/cdf/lib/jars/cdf-util.jar
chmod a+x $(INSCOM)/*
cp -p repackage.* $(INS)
-debian-verify: stage
- repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS)
- @echo debian verify built
-
debian: stage
repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS) -u
- # repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS) -u -B LATEST
+ repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS) -u -B LATEST
@echo debian built
upload-javadocs: javadocs
cd cdf-prop-value && find cdf-*/src/main/java/javadoc -type f | while read f; do \
- curl -k --user "$${OPENECOMP_NEXUS_USER}:$${OPENECOMP_NEXUS_PASSWORD}" --upload-file "$$f" "$${OPENECOMP_NEXUS_JAVADOC}/org.openecomp.dcae.storage.cdf/1.0.0/$$f"; \
+ curl -k --user "$${OPENECOMP_NEXUS_USER}:$${OPENECOMP_NEXUS_PASSWORD}" --upload-file "$$f" "$${OPENECOMP_NEXUS_JAVADOC}/org.openecomp.dcae.storage.cdf/1.1.0/$$f"; \
done
# OPENECOMP_NEXUS_JAVADOC https://ecomp-nexus:8443/repository/dcae-javadoc/
# https://162.242.254.138:8443/#browse/browse/components:dcae-javadoc
diff --git a/cdf/src/repackage.json b/cdf/src/repackage.json
index 546fb0a..ebc287f 100644
--- a/cdf/src/repackage.json
+++ b/cdf/src/repackage.json
@@ -1,29 +1,29 @@
{
- "executionUser": "postgres",
- "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
- "executionGroup": "postgres",
- "directoryTreeTops": {
- "/opt": "/opt/app/cdf"
- },
- "description": " PostgreSQL as a Service main scripts ",
- "docker": {
- "tag": "latest",
- "externalDependencies": []
- },
- "version": "1.1.0",
"applicationName": "cdf",
- "internalDependencies": [],
- "fileGroup": "postgres",
- "fileUser": "postgres",
- "groupId": "org.openecomp.dcae.storage.pgaas",
"debian": {
+ "conflicts": [],
"externalDependencies": [
{
"libgetopt-java": ">= 1.0.14"
}
],
"groupId": "org.openecomp.dcae.storage.pgaas",
- "conflicts": [],
"replaces": []
- }
-}
+ },
+ "description": " PostgreSQL as a Service main scripts ",
+ "directoryTreeTops": {
+ "/opt": "/opt/app/cdf"
+ },
+ "docker": {
+ "externalDependencies": [],
+ "tag": "latest"
+ },
+ "executionGroup": "postgres",
+ "executionUser": "postgres",
+ "fileGroup": "postgres",
+ "fileUser": "postgres",
+ "groupId": "org.openecomp.dcae.storage.pgaas",
+ "internalDependencies": [],
+ "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
+ "version": "1.1.0"
+} \ No newline at end of file
diff --git a/cdf/src/stage/opt/app/cdf/bin/getpropvalue b/cdf/src/stage/opt/app/cdf/bin/getpropvalue
index cd81814..f7525c6 100755
--- a/cdf/src/stage/opt/app/cdf/bin/getpropvalue
+++ b/cdf/src/stage/opt/app/cdf/bin/getpropvalue
@@ -17,7 +17,7 @@ P=/opt/cdf
CDF=/opt/app/cdf
export PATH=/opt/java/jdk/jdk170/bin:$PATH
-export CLASSPATH=$CDF/lib/cdf-prop-value-1.0.0.jar:$CDF/lib/jars/cdf-util-1.0.0.jar
+export CLASSPATH=$CDF/lib/cdf-prop-value.jar:$CDF/lib/jars/cdf-util.jar
if [ -f $CDF/lib/jars/gnu_getopt.jar ]
then CLASSPATH=$CLASSPATH:$CDF/lib/jars/gnu_getopt.jar ]
elif [ -f /usr/share/java/gnu-getopt.jar ]
diff --git a/cdf/src/stage/opt/app/cdf/bin/setencryptedvalues b/cdf/src/stage/opt/app/cdf/bin/setencryptedvalues
index dc5b6d0..8aaeff6 100755
--- a/cdf/src/stage/opt/app/cdf/bin/setencryptedvalues
+++ b/cdf/src/stage/opt/app/cdf/bin/setencryptedvalues
@@ -17,7 +17,7 @@ P=/opt/cdf
CDF=/opt/app/cdf
export PATH=/opt/java/jdk/jdk170/bin:$PATH
-export CLASSPATH=$CDF/lib/cdf-prop-value-1.0.0.jar:$CDF/lib/jars/cdf-util-1.0.0.jar
+export CLASSPATH=$CDF/lib/cdf-prop-value.jar:$CDF/lib/jars/cdf-util.jar
if [ -f $CDF/lib/jars/gnu_getopt.jar ]
then CLASSPATH=$CLASSPATH:$CDF/lib/jars/gnu_getopt.jar ]
elif [ -f /usr/share/java/gnu-getopt.jar ]
diff --git a/pgaas-post/src/makefile b/pgaas-post/src/makefile
index 07c260d..222fcb3 100644
--- a/pgaas-post/src/makefile
+++ b/pgaas-post/src/makefile
@@ -28,13 +28,9 @@ stage: clean-stage clean-common
cp -p repackage.* $(INS)
-debian-verify: stage
- repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS)
- @echo debian verify built
-
debian: stage
- repackage -y repackage.json -b debian -d $(INS) -u
- # repackage -y repackage.json -b debian -d $(INS) -u -B LATEST
+ repackage -b debian -d $(INS) -u
+ repackage -b debian -d $(INS) -u -B LATEST
@echo debian built
upload-javadocs:
diff --git a/pgaas-post/src/repackage.json b/pgaas-post/src/repackage.json
index 43c35c9..2cdce5c 100644
--- a/pgaas-post/src/repackage.json
+++ b/pgaas-post/src/repackage.json
@@ -1,23 +1,23 @@
{
- "version": "1.1.0",
- "executionUser": "root",
- "description": " PostgreSQL as a Service main scripts ",
- "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
+ "applicationName": "pgaas-post",
"debian": {
- "replaces": [],
- "groupId": "org.openecomp.dcae.storage.pgaas",
+ "conflicts": [],
"externalDependencies": [],
- "conflicts": []
+ "groupId": "org.openecomp.dcae.storage.pgaas",
+ "replaces": []
},
- "internalDependencies": [],
- "fileUser": "root",
+ "description": " PostgreSQL as a Service main scripts ",
+ "directoryTreeTops": {},
"docker": {
- "tag": "latest",
- "externalDependencies": []
+ "externalDependencies": [],
+ "tag": "latest"
},
- "directoryTreeTops": {},
- "groupId": "org.openecomp.dcae.storage.pgaas",
+ "executionGroup": "root",
+ "executionUser": "root",
"fileGroup": "root",
- "applicationName": "pgaas-post",
- "executionGroup": "root"
-}
+ "fileUser": "root",
+ "groupId": "org.openecomp.dcae.storage.pgaas",
+ "internalDependencies": [],
+ "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
+ "version": "1.1.0"
+} \ No newline at end of file
diff --git a/pgaas-post/src/stage/opt/app/pgaas-post/bin/pgaas-verify-install b/pgaas-post/src/stage/opt/app/pgaas-post/bin/pgaas-verify-install
index 5bf3962..6e440a4 100644
--- a/pgaas-post/src/stage/opt/app/pgaas-post/bin/pgaas-verify-install
+++ b/pgaas-post/src/stage/opt/app/pgaas-post/bin/pgaas-verify-install
@@ -28,9 +28,10 @@ usage()
b=$(basename $0)
echo "Usage: $b [-v]"
echo "$b runs a variety of tests on the PG VM and database"
- echo "It must be run as root or postgres."
+ echo "It should be run as root or postgres."
echo "If run as root, it will do additional tests that are"
- echo "not possible as a normal user."
+ echo "not possible as a normal user. If not run as root or"
+ echo "postgres, other tests may fail."
echo " -v verbose"
echo " -P do not print VERIFIED"
exit 1
@@ -52,7 +53,7 @@ ROOT=false
case `id` in
*"(root)"* ) ROOT=true ;;
*"(postgres)"* ) ;;
- * ) echo "$0 must be run as either root or postgres" ;;
+ * ) echo "$0 should be run as either root or postgres" ;;
esac
VERIFIEDCOUNT=0
@@ -154,7 +155,16 @@ if [ -s /lib/systemd/system/pgaas-idns.service ]
then verified "found pgaas-idns service properly installed for Ubuntu 16"
elif [ -s /etc/init/pgaas-init.conf ]
then verified "found pgaas-idns service properly installed for Ubuntu 14"
-else failed "pgaas-idns service has not bee installed properly"
+else failed "pgaas-idns service has not been installed properly"
+fi
+
+if ps -ef | grep '[i]DNS-responder' > /dev/null
+then verified "iDNS-responder is running"
+ if ps -fu postgres | grep '[i]DNS-responder' > /dev/null
+ then verified "iDNS-responder is running as postgres"
+ else failed "iDNS-responder is running, but not as postgres"
+ fi
+else failed "postgres does not have a logger process running"
fi
if [ -d /var/run/postgresql ]
@@ -173,7 +183,7 @@ fi
################ postgresql-config ################
################################################################
-if ps -fu postgres | grep "postgres: logger process" > /dev/null
+if ps -fu postgres | grep "[p]ostgres: logger process" > /dev/null
then verified "postgres is running"
else failed "postgres does not have a logger process running"
fi
@@ -205,11 +215,6 @@ else
failed "/opt/app/pgaas/bin/runpsqll is not installed"
fi
-if ps -ef | grep python3 | grep iDNS-responder.py > /dev/null
-then verified "iDNS-responder.py is running"
-else failed "iDNS-responder.py is not running"
-fi
-
if [ -f /opt/app/pgaas/bin/check_cluster ]
then
verified "/opt/app/pgaas/bin/check_cluster is installed"
diff --git a/pgaas/src/makefile b/pgaas/src/makefile
index e76189a..73fe4eb 100644
--- a/pgaas/src/makefile
+++ b/pgaas/src/makefile
@@ -31,13 +31,9 @@ stage: clean-stage
cp -p repackage.* $(INS)
-debian-verify: stage
- repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS)
- @echo debian verify built
-
debian: stage
repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS) -u
- # repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS) -u -B LATEST
+ repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS) -u -B LATEST
@echo debian built
upload-javadocs:
diff --git a/pgaas/src/repackage.json b/pgaas/src/repackage.json
index 58ef15b..4d18188 100644
--- a/pgaas/src/repackage.json
+++ b/pgaas/src/repackage.json
@@ -1,25 +1,25 @@
{
- "executionGroup": "postgres",
- "executionUser": "postgres",
"applicationName": "pgaas",
- "description": " PostgreSQL as a Service main scripts ",
- "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
- "fileUser": "postgres",
- "internalDependencies": [],
- "directoryTreeTops": {
- "/opt": "/opt/app/pgaas"
- },
"debian": {
"conflicts": [],
+ "externalDependencies": [],
"groupId": "org.openecomp.dcae.storage.pgaas",
- "replaces": [],
- "externalDependencies": []
+ "replaces": []
+ },
+ "description": " PostgreSQL as a Service main scripts ",
+ "directoryTreeTops": {
+ "/opt": "/opt/app/pgaas"
},
- "fileGroup": "postgres",
"docker": {
- "tag": "latest",
- "externalDependencies": []
+ "externalDependencies": [],
+ "tag": "latest"
},
- "version": "1.1.0",
- "groupId": "org.openecomp.dcae.storage.pgaas"
-}
+ "executionGroup": "postgres",
+ "executionUser": "postgres",
+ "fileGroup": "postgres",
+ "fileUser": "postgres",
+ "groupId": "org.openecomp.dcae.storage.pgaas",
+ "internalDependencies": [],
+ "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
+ "version": "1.1.0"
+} \ No newline at end of file
diff --git a/pgaas/src/stage/opt/app/pgaas/bin/check_cluster b/pgaas/src/stage/opt/app/pgaas/bin/check_cluster
index 0af6d95..c55d973 100755
--- a/pgaas/src/stage/opt/app/pgaas/bin/check_cluster
+++ b/pgaas/src/stage/opt/app/pgaas/bin/check_cluster
@@ -23,7 +23,7 @@
# -v verbose
#
# DESCRIPTION
-# Loop through the nodes in the cluster, using pgwget to determine how many are masters, secondaries, or not up.
+# Loop through the nodes in the cluster, using pgwget to determine how many are masters, secondaries, down for maintenance, or not up.
# Complain about certain situations.
# If there are multiple masters, and this not the first master in the list, then:
# run pg_ctl_restart
@@ -44,19 +44,22 @@ usage()
{
exec 1>&2
[ $# -gt 0 ] && echo "$@"
- echo "Usage: $0 [-v] [-l] [-t timeout]"
+ echo "Usage: $0 [-v] [-l] [-t timeout] [-d file]"
echo -e " -l do not check localhost first (and restarting the service if necessary)"
echo -e " -t timeout set how long to wait when accessing the servers"
echo -e " -v verbose"
+ echo -e " -d file duplicate the status output to the given file"
exit 1
}
VERBOSE=false
TIMEOUT=10
TESTLOCAL=:
-while getopts lt:v c
+DFILE=
+while getopts d:lt:v c
do
case "$c" in
+ d ) DFILE=$OPTARG ;;
l ) TESTLOCAL=false ;;
t ) TIMEOUT=$OPTARG ;;
v ) VERBOSE=: ;;
@@ -70,13 +73,16 @@ master_count=0
secondary_count=0
total_count=0
down_count=0
+maintenance_count=0
-DOWNS=
MASTERS=
SECONDARIES=
+MAINTENANCES=
+DOWNS=
MSEP=
SSEP=
+BSEP=
DSEP=
HOSTNAME=$(hostname -f)
FOUNDPREVIOUSMASTER=
@@ -86,7 +92,7 @@ if $TESTLOCAL
then
isrw=`pgwget --tries=1 --read-timeout=$TIMEOUT --quiet -O/dev/stdout http://localhost:8000/isrw`
case "$isrw" in
- Master | Secondary ) ;;
+ Master | Secondary | Maintenance ) ;;
* )
echo "$(date)|WARNING|RESTARTED|Local iDNS-responder.py not responding. Restarting."
ps -fu postgres | grep "python3 /opt/app/postgresql-prep/bin/iDNS-responder.py" | grep -v grep | awk '{print "kill " $2}' | sh
@@ -118,6 +124,12 @@ do
SECONDARIES="$SECONDARIES$SSEP$i"
SSEP=" "
;;
+ Maintenance )
+ (( maintenance_count = maintenance_count + 1 ))
+ (( total_count = total_count + 1 ))
+ MAINTENANCES="$MAINTENANCES$BSEP$i"
+ BSEP=" "
+ ;;
* )
DOWNS="$DOWNS$DSEP$i"
DSEP=" "
@@ -130,7 +142,11 @@ done
(( up_count = master_count + secondary_count ))
date=$(date)
-echo "$date|INFO|masters=$master_count $MASTERS|secondaries=$secondary_count $SECONDARIES|down=$down_count $DOWNS|"
+output="$date|INFO|masters=$master_count $MASTERS|secondaries=$secondary_count $SECONDARIES|maintenance=$maintenance_count $MAINTENANCES|down=$down_count $DOWNS|"
+echo "$output"
+if [ -n "$DFILE" ]
+then (umask 022; echo "$output" > $DFILE.tmp && mv $DFILE.tmp $DFILE)
+fi
FORCEROOFF=/var/run/postgresql/force-ro-off
if [ $master_count -lt 1 ]
diff --git a/pgaas/src/stage/opt/app/pgaas/bin/dcae_admin_db.py b/pgaas/src/stage/opt/app/pgaas/bin/dcae_admin_db.py
index 80da148..9d5b05d 100755
--- a/pgaas/src/stage/opt/app/pgaas/bin/dcae_admin_db.py
+++ b/pgaas/src/stage/opt/app/pgaas/bin/dcae_admin_db.py
@@ -121,6 +121,7 @@ def usage(msg = None):
print("dcae_admin_db.py [options] suspend")
print("dcae_admin_db.py [options] resume")
print("dcae_admin_db.py [options] test")
+ print("dcae_admin_db.py [options] newdb dbname admin-pswd user-pswd viewer-pswd")
print("")
print("options:")
print("-H / --dbhost= - host name, defaults to CFG['dcae_admin_db_hostname']")
@@ -282,6 +283,10 @@ def main():
if len(args) != 1:
usage("too many arguments")
testOperations(keyedOptions)
+ elif args[0] == "newdb":
+ if len(args) != 5:
+ usage("wrong number of arguments")
+ newDb(keyedOptions, args[1], args[2], args[3], args[4])
else:
usage("unrecognized operation '%s'" % args[0])
@@ -313,11 +318,14 @@ def testOperations(options):
ret = runProgram(cmd)
# pg_ctl: no server running
# pg_ctl: server is running (PID: 13988)
+ # does /var/run/postgresql/inmaintenance exist? -> YELLOW
cmdRepmgr = ["pgrep", "repmgrd"]
retRepmgr = runProgram(cmdRepmgr)
msg = "????"
- if re.search("no server running", ret):
+ if os.path.isfile("/var/run/postgresql/inmaintenance"):
+ msg = "YELLOW: in maintenance mode"
+ elif re.search("no server running", ret):
msg = "RED: no PG server running"
elif re.search("server is running", ret) and re.search("[0-9]+", retRepmgr):
msg = "GREEN"
@@ -377,6 +385,13 @@ def configurationChanged(options, jsonFile):
if verbose:
dumpJSON(inp, "modified JSON")
+ setupJsonDatabases(options, inp)
+
+def setupDictionaryDatabases(options, inp):
+ """
+ Set up the databases listed in the dictionary
+ """
+
# trace("version=%s" % requireJSON("version", inp, "version"))
requireJSON("databases", inp, "databases")
con = None
@@ -392,6 +407,63 @@ def configurationChanged(options, jsonFile):
con.commit()
con.close()
+def newDb(options, dbName, adminPswd, userPswd, viewerPswd):
+ """
+ Given the database name and passwords, set up a database and corresponding users.
+ For example, with dbname="foo", adminPswd="fooa", userPswd="foou" and viewerPswd="foov",
+ act the same as if we had received the json configuration:
+ {
+ 'databases': {
+ 'foo': {
+ 'ownerRole': 'foo_admin',
+ 'roles': {
+ 'foo_admin': {
+ 'password': 'fooa',
+ 'role': 'admin'
+ },
+ 'foo_user': {
+ 'password': 'foou',
+ 'role': 'writer'
+ },
+ 'foo_viewer': {
+ 'password': 'foov',
+ 'role': 'reader'
+ }
+ }
+ }
+ }
+ }
+ """
+ if not re.match("^[A-Za-z][A-Za-z0-9_]*$", dbName):
+ errorPrint("'%s' is not a valid database name" % dbName)
+ return
+
+ adminName = dbName + "_admin"
+ userName = dbName + "_user"
+ viewerName = dbName + "_viewer"
+
+ setupDictionaryDatabases(options, {
+ 'databases': {
+ dbName: {
+ 'ownerRole': adminName,
+ 'roles': {
+ adminName: {
+ 'password': adminPswd,
+ 'role': 'admin'
+ },
+ userName: {
+ 'password': userPswd,
+ 'role': 'writer'
+ },
+ viewerName: {
+ 'password': viewerPswd,
+ 'role': 'reader'
+ }
+ }
+ }
+ }
+ })
+
def dumpJSON(js, msg):
tracePrint("vvvvvvvvvvvvvvvv %s" % msg)
tracePrint(json.dumps(js, indent=4))
diff --git a/pgaas/src/stage/opt/app/pgaas/bin/isrw b/pgaas/src/stage/opt/app/pgaas/bin/isrw
index 4ec3dcb..817030d 100755
--- a/pgaas/src/stage/opt/app/pgaas/bin/isrw
+++ b/pgaas/src/stage/opt/app/pgaas/bin/isrw
@@ -22,7 +22,12 @@ fi
export PATH=$PATH:/opt/java/jdk/jdk170/bin:/opt/app/cdf/bin:/opt/app/pgaas/bin:$PATH
-case `show_pg_is_in_recovery` in
- *f* ) echo "Master" ;;
- *t* ) echo "Secondary" ;;
-esac
+if [ -f /var/run/postgresql/inmaintenance ]
+then
+ echo "Maintenance"
+else
+ case `show_pg_is_in_recovery` in
+ *f* ) echo "Master" ;;
+ *t* ) echo "Secondary" ;;
+ esac
+fi
diff --git a/pgaas/src/stage/opt/app/pgaas/bin/list_masters b/pgaas/src/stage/opt/app/pgaas/bin/list_masters
index d922739..9e22cd1 100755
--- a/pgaas/src/stage/opt/app/pgaas/bin/list_masters
+++ b/pgaas/src/stage/opt/app/pgaas/bin/list_masters
@@ -27,17 +27,53 @@ else CFGDIR=/opt/app/postgresql-config/
fi
PATH=$PGDIR/bin:$CDF/bin:/opt/app/pgaas/bin:/opt/app/postgresql-prep/bin:$PATH
+usage()
+{
+ exec 1>&2
+ [ $# -gt 0 ] && echo "$@"
+ echo "Usage: $0 [-r] [-v]"
+ echo -e " -r check /ro instead of /rw"
+ echo -e " -v verbose"
+ exit 1
+}
+
+VERBOSE=false
+CMD=rw
+QUIET=--quiet
+OUTPUT=-O/dev/null
+while getopts rvQ c
+do
+ case "$c" in
+ r ) CMD=ro ;;
+ Q ) QUIET= OUTPUT= ;;
+ v ) VERBOSE=: ;;
+ \?) usage ;;
+ esac
+done
+shift $(($OPTIND - 1))
+
# loop through the nodes in the cluster, using pgwget to determine if any are a master. Save in $@
for i in $(getpropvalue -n pgnodes | sed 's/|/ /g')
do
- if pgwget --quiet -O/dev/null http://$i:8000/rw
+ $VERBOSE && echo -n "Checking $i"
+ if pgwget $QUIET $OUTPUT http://$i:8000/$CMD
then set -- "$@" $i
fi
done
echo "$@"
-case $# in
- 1 ) exit 0 ;; # one master exists and is running
- 0 ) exit 1 ;; # no masters exist
- * ) exit 2 ;; # more than one master exist
+case "$CMD" in
+ rw )
+ case $# in
+ 1 ) exit 0 ;; # one master exists and is running
+ 0 ) exit 1 ;; # no masters exist
+ * ) exit 2 ;; # more than one master exist
+ esac
+ ;;
+ ro )
+ case $# in
+ 0 ) exit 1 ;; # no masters exist
+ * ) exit 0 ;; # one or more masters+secondaries exist
+ esac
+ ;;
esac
diff --git a/pgaas/src/stage/opt/app/pgaas/bin/makefile b/pgaas/src/stage/opt/app/pgaas/bin/makefile
index 877f8ba..f3ff097 100644
--- a/pgaas/src/stage/opt/app/pgaas/bin/makefile
+++ b/pgaas/src/stage/opt/app/pgaas/bin/makefile
@@ -26,7 +26,7 @@ SHFILES= check_cluster isrw list_masters \
runpsql runpsqll startpsql setpropvalue show_pg_is_in_recovery show_pg_stat_activity show_pg_stat_archiver show_pg_stat_bgwriter \
show_pg_stat_database show_pg_stat_database_conflicts show_pg_statio_user_functions show_pg_statio_user_indexes \
show_pg_statio_user_sequences show_pg_statio_user_tables show_pg_stat_user_indexes show_pg_stat_user_tables \
- update_var_run_isrw
+ update_var_run_isrw startbackup stopbackup
stage:
rm -rf $(STAGEDIR)/$(DISTPATH)/bin
@@ -40,8 +40,10 @@ stage:
;; \
makefile | *~ ) ;; \
* ) \
- cp $$i $(STAGEDIR)/$(DISTPATH)/bin/$$i; \
- chmod a+x $(STAGEDIR)/$(DISTPATH)/bin/$$i; \
+ if [ -f $$i ]; then \
+ cp $$i $(STAGEDIR)/$(DISTPATH)/bin/$$i; \
+ chmod a+x $(STAGEDIR)/$(DISTPATH)/bin/$$i; \
+ fi; \
;; \
esac; \
done
diff --git a/pgaas/src/stage/opt/app/pgaas/bin/start_maintenance_mode b/pgaas/src/stage/opt/app/pgaas/bin/start_maintenance_mode
new file mode 100644
index 0000000..d1c1827
--- /dev/null
+++ b/pgaas/src/stage/opt/app/pgaas/bin/start_maintenance_mode
@@ -0,0 +1,48 @@
+#!/bin/bash
+# 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 code 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.
+
+PATH=/opt/app/pgaas/bin:/opt/app/postgresql-prep/bin:$PATH
+
+INMAINTENANCE=/var/run/postgresql/inmaintenance
+ISRW=/var/run/postgresql/isrw
+
+if [ -f $INMAINTENANCE ]
+then
+ echo "Already in maintenance mode" 1>&2
+ exit 1
+fi
+
+case `< $ISRW` in
+ Master ) echo "This is a Master system. It cannot be set to maintenance mode" 1>&2
+ exit 2
+ ;;
+esac
+
+echo "Setting maintenance mode"
+echo inmaintenance > $INMAINTENANCE
+
+echo "Shutting down the PostgreSQL server"
+pg_ctl_stop
+
+# the following loop is to allow iDNS to get a chance to mark this system as being down
+echo "Sleeping for 20 seconds"
+for i in `seq 20`
+do
+ echo -n " $i"
+done
+echo " Done"
+
+
+
+
diff --git a/pgaas/src/stage/opt/app/pgaas/bin/stop_maintenance_mode b/pgaas/src/stage/opt/app/pgaas/bin/stop_maintenance_mode
new file mode 100644
index 0000000..fc582ba
--- /dev/null
+++ b/pgaas/src/stage/opt/app/pgaas/bin/stop_maintenance_mode
@@ -0,0 +1,28 @@
+#!/bin/bash
+# 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 code 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.
+
+PATH=/opt/app/pgaas/bin:/opt/app/postgresql-prep/bin:$PATH
+
+INMAINTENANCE=/var/run/postgresql/inmaintenance
+
+if [ ! -f $INMAINTENANCE ]
+then
+ echo "Not in maintenance mode" 1>&2
+ exit 1
+fi
+
+echo "Restarting PostgreSQL server"
+pg_ctl_start
+echo "Returning server to normal rotation"
+rm -f $INMAINTENANCE
diff --git a/pgaas/src/stage/opt/app/pgaas/man/check_cluster.man b/pgaas/src/stage/opt/app/pgaas/man/check_cluster.man
index dc6fcce..ea8f5e9 100644
--- a/pgaas/src/stage/opt/app/pgaas/man/check_cluster.man
+++ b/pgaas/src/stage/opt/app/pgaas/man/check_cluster.man
@@ -14,7 +14,10 @@
.SH NAME
check_cluster - check the state of the cluster
.SH SYNOPSIS
-check_cluster [-v] [-l] [-t timeout]
+check_cluster [-d file] [-v] [-l] [-t timeout]
+.HP 20
+-d file
+duplicate the status output to the given file
.HP 20
-l
do not check localhost first (and restarting the service if necessary)
@@ -25,10 +28,13 @@ set how long to wait when accessing the servers
-v
verbose
.SH DESCRIPTION
-Loop through the nodes in the cluster, using pgwget to determine how many are masters, secondaries, or not up.
+Loop through the nodes in the cluster, using pgwget to determine how many are
+masters, secondaries, in maintenance, or not up.
Complain about certain situations.
If there are multiple masters, and this not the first master in the list, then:
run pg_ctl_restart
-prevent /ro from returning true
+to prevent /ro from returning true
+.PP
+When \-d is used, the filename will have ".tmp" appended, writing the output to that temp filename, and then renaming the ".tmp" file to the given filename.
diff --git a/pgaas/src/stage/opt/app/pgaas/man/makefile b/pgaas/src/stage/opt/app/pgaas/man/makefile
index 9cd2090..92f6292 100644
--- a/pgaas/src/stage/opt/app/pgaas/man/makefile
+++ b/pgaas/src/stage/opt/app/pgaas/man/makefile
@@ -93,5 +93,9 @@ show_pg_stat_user_tables.1: show_pg_stat_user_tables.man
DATE=$$(date +%Y-%m-%d); sed "1s/ {{DATE}} / $$DATE /" < $< | nroff -Tlp -man > $@
startpsql.1: startpsql.man
DATE=$$(date +%Y-%m-%d); sed "1s/ {{DATE}} / $$DATE /" < $< | nroff -Tlp -man > $@
+start_maintenance_mode.1: start_maintenance_mode.man
+ DATE=$$(date +%Y-%m-%d); sed "1s/ {{DATE}} / $$DATE /" < $< | nroff -Tlp -man > $@
+stop_maintenance_mode.1: stop_maintenance_mode.man
+ DATE=$$(date +%Y-%m-%d); sed "1s/ {{DATE}} / $$DATE /" < $< | nroff -Tlp -man > $@
update_var_run_isrw.1: update_var_run_isrw.man
DATE=$$(date +%Y-%m-%d); sed "1s/ {{DATE}} / $$DATE /" < $< | nroff -Tlp -man > $@
diff --git a/pgaas/src/stage/opt/app/pgaas/man/start_maintenance_mode.man b/pgaas/src/stage/opt/app/pgaas/man/start_maintenance_mode.man
new file mode 100644
index 0000000..1906afa
--- /dev/null
+++ b/pgaas/src/stage/opt/app/pgaas/man/start_maintenance_mode.man
@@ -0,0 +1,28 @@
+'\" 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 code 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.
+.TH start_maintenance_mode 1PG {{DATE}} OpenECOMP OpenECOMP
+.SH NAME
+start_maintenance_mode - convert this system to maintenance mode
+.SH SYNOPSIS
+start_maintenance_mode
+.SH DESCRIPTION
+Take this system out of the normal rotation and mark it as being in maintenance mode.
+This command may only be used on a secondary system and not on a master system.
+After this command is run, the PostgreSQL server will be brought down, but may be
+restarted manually using the pg_ctl_start.
+Note that the health checks will not regard this system as being in the normal
+rotation until the command stop_maintenance_mode is executed, allowing the DBA to perform
+whatever is needed to perform a backup or other maintenance routines,
+such as copying the database files.
+.SH FILES
+/var/run/postgresql/inmaintenance
diff --git a/pgaas/src/stage/opt/app/pgaas/man/stop_maintenance_mode.man b/pgaas/src/stage/opt/app/pgaas/man/stop_maintenance_mode.man
new file mode 100644
index 0000000..bc97745
--- /dev/null
+++ b/pgaas/src/stage/opt/app/pgaas/man/stop_maintenance_mode.man
@@ -0,0 +1,24 @@
+'\" 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 code 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.
+.TH stop_maintenance_mode 1PG {{DATE}} OpenECOMP OpenECOMP
+.SH NAME
+stop_maintenance_mode - convert this system to maintenance mode
+.SH SYNOPSIS
+stop_maintenance_mode
+.SH DESCRIPTION
+Mark this system as no longer being in maintenance mode, and
+return this system back to the normal rotation.
+This command may only be used on a secondary system and not on a master system.
+This command will also restart the PostgreSQL server.
+.SH FILES
+/var/run/postgresql/inmaintenance
diff --git a/postgresql-config/src/makefile b/postgresql-config/src/makefile
index aeaea2b..7de2a33 100644
--- a/postgresql-config/src/makefile
+++ b/postgresql-config/src/makefile
@@ -1,7 +1,6 @@
DEVBIN=../../bin
PKG=postgresql-config
-REPACKAGESWMOPTS=
REPACKAGEDEBIANOPTS=
INS= ../install
@@ -29,13 +28,9 @@ stage: clean-stage clean-common
cp -p repackage.* $(INS)
-debian-verify: stage
- repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS)
- @echo debian verify built
-
debian: stage
- repackage -y repackage.json -b debian -d $(INS) -u
- # repackage -y repackage.json -b debian -d $(INS) -u -B LATEST
+ repackage -b debian -d $(INS) -u
+ repackage -b debian -d $(INS) -u -B LATEST
@echo debian built
upload-javadocs:
diff --git a/postgresql-config/src/repackage.json b/postgresql-config/src/repackage.json
index 9e86b04..4a33f03 100644
--- a/postgresql-config/src/repackage.json
+++ b/postgresql-config/src/repackage.json
@@ -1,25 +1,25 @@
{
+ "applicationName": "postgresql-config",
"debian": {
- "replaces": [],
"conflicts": [],
+ "externalDependencies": [],
"groupId": "org.openecomp.dcae.storage.pgaas",
- "externalDependencies": []
+ "replaces": []
},
- "fileGroup": "postgres",
- "version": "1.1.0",
- "applicationName": "postgresql-config",
- "internalDependencies": [],
+ "description": " PostgreSQL as a Service main scripts ",
"directoryTreeTops": {
"/opt": "/opt/app/postgresql-config"
},
- "executionUser": "postgres",
- "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
- "fileUser": "postgres",
"docker": {
- "tag": "latest",
- "externalDependencies": []
+ "externalDependencies": [],
+ "tag": "latest"
},
+ "executionGroup": "postgres",
+ "executionUser": "postgres",
+ "fileGroup": "postgres",
+ "fileUser": "postgres",
"groupId": "org.openecomp.dcae.storage.pgaas",
- "description": " PostgreSQL as a Service main scripts ",
- "executionGroup": "postgres"
-}
+ "internalDependencies": [],
+ "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
+ "version": "1.1.0"
+} \ No newline at end of file
diff --git a/postgresql-config/src/stage/opt/app/postgresql-config/etc/do-post-install b/postgresql-config/src/stage/opt/app/postgresql-config/etc/do-post-install
index 9b25be8..7e8c71b 100644
--- a/postgresql-config/src/stage/opt/app/postgresql-config/etc/do-post-install
+++ b/postgresql-config/src/stage/opt/app/postgresql-config/etc/do-post-install
@@ -40,38 +40,41 @@ $CFGDIR/etc/makecerts
cat $CFGDIR/lib/profile.additions >> ~postgres/.profile
# Determine which system is the master.
-# For central, we look first in /tmp/postgres.conf.
+# For central, we look first in /var/config/DCAE/chef/*-postgres.conf.
# If we don't find that, we look at the pgnodes list and pick the first one.
-# For edge, we ignore /tmp/postgres.conf and go directly to the pgnodes list.
+# For edge, we ignore /var/config/DCAE/chef/*-postgres.conf and go directly to the pgnodes list.
# Each edge site has its own master.
clustertype=$( ${INSTALL_ROOT}/opt/app/cdf/bin/getpropvalue -n cluster )
ismaster=no
case $clustertype in
central )
- CONF=/tmp/postgres.conf
- if [ -f $CONF ] # OpenDCAE
- then
+ CONFDIR=/var/config/DCAE/chef
+ CONFCOUNT=$(ls $CONFDIR/*-postgres.conf 2>/dev/null | wc -l)
+ case "$CONFCOUNT" in
+ 1 ) # OpenDCAE
umask 077
TMP=$(mktemp /tmp/tmp.pi1.XXXXXXXXXX)
trap 'rm -f $TMP' 0 1 2 3 15
- sed -e 's/ *: */="/' -e 's/$/"/' -e 's/=""/="/' -e 's/""$/"/' < $CONF > $TMP
+ sed -e 's/ *: */="/' -e 's/ *$/"/' -e 's/=""/="/' -e 's/""$/"/' < $CONFDIR/*-postgres.conf > $TMP
. $TMP
case `hostname` in
- $master ) ismaster=yes ;;
+ $master ) ismaster=yes ;;
*?* ) ismaster=no ;;
'' ) die "master is not set in $CONF"
esac
PGNODES=$( ${INSTALL_ROOT}/opt/app/cdf/bin/getpropvalue -n pgnodes )
export MASTER=$( gen-repmgr-info -n "$PGNODES" -M "$master" )
[ -n "$MASTER" ] || die "Cannot determine master system. $CONF has '$master' (from env.yaml), which cannot be found in pgnodes."
-
- else
- # not OpenDCAE
+ ;;
+ 0 ) # not OpenDCAE
ismaster=yes
PGNODES=$( ${INSTALL_ROOT}/opt/app/cdf/bin/getpropvalue -n pgnodes )
export MASTER=$( gen-repmgr-info -n "$PGNODES" -m )
- fi
+ ;;
+ * ) die "More than one postgres.conf was found: $(ls $CONFDIR/*-postgres.conf 2>&1)"
+ ;;
+ esac
;;
edge )
host=$( hostname -f )
@@ -86,6 +89,10 @@ esac
ssh_and_cdf_okay=no
+if pgrep postgres
+then pkill postgres
+fi
+
case $ismaster in
yes ) # master
$CFGDIR/etc/create-ssh-master &&
diff --git a/postgresql-config/src/stage/opt/app/postgresql-config/etc/gen-pgpass b/postgresql-config/src/stage/opt/app/postgresql-config/etc/gen-pgpass
index ca99a0f..3ea9fa1 100644
--- a/postgresql-config/src/stage/opt/app/postgresql-config/etc/gen-pgpass
+++ b/postgresql-config/src/stage/opt/app/postgresql-config/etc/gen-pgpass
@@ -17,9 +17,10 @@
postgrespswd=$( ${INSTALL_ROOT}/opt/app/cdf/bin/getpropvalue -x -n postgres )
repmgrpswd=$( ${INSTALL_ROOT}/opt/app/cdf/bin/getpropvalue -x -n repmgr )
umask 077
-if [ -f ~postgres/.pgpaas ]
+pswdfile=~postgres/.pgpass
+if [ -f $pswdfile ]
then
- ed ~postgres/.pgpaas <<-EOF
+ ed $pswdfile <<-EOF
H
g/:postgres:/d
g/:repmgr:/d
@@ -28,6 +29,6 @@ then
EOF
fi
-echo "*:*:*:postgres:$postgrespswd" >> ~postgres/.pgpass
-echo "*:*:*:repmgr:$repmgrpswd" >> ~postgres/.pgpass
-chmod go-rwx ~postgres/.pgpass
+echo "*:*:*:postgres:$postgrespswd" >> $pswdfile
+echo "*:*:*:repmgr:$repmgrpswd" >> $pswdfile
+chmod 600 $pswdfile
diff --git a/postgresql-config/src/stage/opt/app/postgresql-config/etc/makecerts b/postgresql-config/src/stage/opt/app/postgresql-config/etc/makecerts
index a272f7b..46564ab 100755
--- a/postgresql-config/src/stage/opt/app/postgresql-config/etc/makecerts
+++ b/postgresql-config/src/stage/opt/app/postgresql-config/etc/makecerts
@@ -51,6 +51,8 @@ usage()
exit 1
}
+set -x
+
if [ -f "$libdir/ssl-cert-snakeoil.pem" ] && [ -f "$libdir/ssl-cert-snakeoil.key" ]; then
if [ "$1" != "--force-overwrite" ]; then
exit 0
@@ -83,6 +85,8 @@ trap "rm -f $TMPFILE $TMPOUT" EXIT 1 2 3 15
# create the certificate.
+umask 077
+
if ! openssl req -config $TMPFILE -new -x509 -days 3650 -nodes \
-out $libdir/ssl-cert-snakeoil.pem \
-keyout $libdir/ssl-cert-snakeoil.key > $TMPOUT 2>&1
diff --git a/postgresql-config/src/stage/opt/app/postgresql-config/etc/start-db b/postgresql-config/src/stage/opt/app/postgresql-config/etc/start-db
index 2d50b40..a91d16a 100644
--- a/postgresql-config/src/stage/opt/app/postgresql-config/etc/start-db
+++ b/postgresql-config/src/stage/opt/app/postgresql-config/etc/start-db
@@ -29,4 +29,5 @@ die()
[ -n "$CFGDIR" ] || die "CFGDIR is not set"
rm -f $DBROOT/postmaster.pid
+chmod 600 $CFGDIR/lib/*.key
$PGDIR/bin/pg_ctl start -D $DBROOT -o "-c config_file=$CFGDIR/main/postgresql.conf"
diff --git a/postgresql-prep/src/common/postinst b/postgresql-prep/src/common/postinst
index 63a76f2..bad825b 100755
--- a/postgresql-prep/src/common/postinst
+++ b/postgresql-prep/src/common/postinst
@@ -37,23 +37,32 @@ id
umask 022
TMP=$( mktemp /tmp/pgprep.$$.XXXXXXXXXX )
-#### TODO remove comment trap 'rm -f $TMP' 0 1 2 3 15
+trap 'rm -f $TMP' 0 1 2 3 15
if $OPENECOMP
then INSTALL_ROOT=
fi
-if [ -f /tmp/postgres.conf ]
-then
+CONFDIR=/var/config/DCAE/chef
+CONFCOUNT=$(ls $CONFDIR/*-postgres.conf 2>/dev/null | wc -l)
+case "$CONFCOUNT" in
+1 )
+ # master: masternode
+ # master2: secondmasternode
+ # in DCAE, these values could be in postgres.conf or already in the environment
# DRTR_NODE_KSTOREFILE: /opt/app/dcae-certificate/keystore.jks
# DRTR_NODE_KSTOREPASS: "No Certificate"
# DRTR_NODE_PVTKEYPASS: "No Certificate"
# PG_NODES : uiopmno1qwpstg00.research.example.com|asbczw1vepstg00.dcae.simpledemo.openecomp.org
# PG_JAVA_HOME : /opt/app/java/jdk/jdk170
# PG_CLUSTER : global
- sed -e 's/ *: */="/' -e 's/$/"/' -e 's/=""/="/' -e 's/""$/"/' < /tmp/postgres.conf > $TMP
+ sed -e 's/ *: */="/' -e 's/[ ]*$/"/' -e 's/=""/="/' -e 's/""$/"/' < /tmp/postgres.conf > $TMP
. $TMP
-fi
+ ;;
+0 ) ;;
+* )
+ die "More than one postgres.conf was found: $(ls $CONFDIR/*-postgres.conf 2>&1)"
+esac
[ -n "$PG_NODES" ] || die "PG_NODES is not set"
[ -n "$PG_CLUSTER" ] || die "PG_CLUSTER is not set"
@@ -88,7 +97,9 @@ chown -R postgres:postgres ${INSTALL_ROOT}/dbroot ${INSTALL_ROOT}/var/run/postgr
chmod 711 ~postgres
# fix up the CDF package so that it works
-ln -sf /opt/app/cdf /opt/cdf
+if [ ! -L /opt/cdf ]
+then rm -f /opt/cdf; ln -sf /opt/app/cdf /opt/cdf
+fi
# and save some values within
(
diff --git a/postgresql-prep/src/makefile b/postgresql-prep/src/makefile
index 9999fa6..86831d1 100644
--- a/postgresql-prep/src/makefile
+++ b/postgresql-prep/src/makefile
@@ -1,7 +1,6 @@
DEVBIN=../../bin
PKG=postgresql-prep
-REPACKAGESWMOPTS=
REPACKAGEDEBIANOPTS=
INS= ../install
@@ -33,13 +32,9 @@ stage: clean-stage clean-common testlock/testlock
cp -p repackage.* $(INS)
-debian-verify: stage
- repackage -b debian $(REPACKAGEDEBIANOPTS) -d $(INS)
- @echo debian verify built
-
debian: stage
- repackage -y repackage.json -b debian -d $(INS) -u
- # repackage -y repackage.json -b debian -d $(INS) -u -B LATEST
+ repackage -b debian -d $(INS) -u
+ repackage -b debian -d $(INS) -u -B LATEST
@echo debian built
upload-javadocs:
diff --git a/postgresql-prep/src/repackage.json b/postgresql-prep/src/repackage.json
index 94874ed..3b8248d 100644
--- a/postgresql-prep/src/repackage.json
+++ b/postgresql-prep/src/repackage.json
@@ -1,29 +1,29 @@
{
- "description": " PostgreSQL as a Service main scripts ",
- "fileGroup": "root",
- "groupId": "org.openecomp.dcae.storage.pgaas",
- "fileUser": "root",
- "executionGroup": "root",
- "executionUser": "root",
- "internalDependencies": [],
- "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
- "docker": {
- "tag": "latest",
- "externalDependencies": []
- },
"applicationName": "postgresql-prep",
"debian": {
- "groupId": "org.openecomp.dcae.storage.pgaas",
+ "conflicts": [],
"externalDependencies": [
{
"cdf": ">= 1.1.0"
}
],
- "replaces": [],
- "conflicts": []
+ "groupId": "org.openecomp.dcae.storage.pgaas",
+ "replaces": []
},
- "version": "1.1.0",
+ "description": " PostgreSQL as a Service main scripts ",
"directoryTreeTops": {
"/opt": "/opt/app/postgresql-prep"
- }
-}
+ },
+ "docker": {
+ "externalDependencies": [],
+ "tag": "latest"
+ },
+ "executionGroup": "root",
+ "executionUser": "root",
+ "fileGroup": "root",
+ "fileUser": "root",
+ "groupId": "org.openecomp.dcae.storage.pgaas",
+ "internalDependencies": [],
+ "maintainer": "OpenECOMP <dcae@lists.openecomp.org>",
+ "version": "1.1.0"
+} \ No newline at end of file
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py b/postgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py
index b6c5174..14c16b3 100755
--- a/postgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/bin/iDNS-responder.py
@@ -445,10 +445,16 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
elif self.path == '/isrw':
isrw = readFile("/var/run/postgresql/isrw", "n/a")
- debugTrace("/rw: isrw returns %s" % isrw)
+ debugTrace("/isrw: returns %s" % isrw)
resp = 200
msg = isrw
+ elif self.path == '/healthcheck/status':
+ hs = readFile("/var/run/postgresql/check_cluster", "n/a")
+ debugTrace("/healthcheck/status: returns %s" % hs)
+ resp = 429 if hs == "n/a" else 200
+ msg = '{ "output": "' + re.sub('"', "'", re.sub("\n", " ", hs)) + '" }'
+
elif not self.checkAuth():
resp = 401
msg = "not authenticated"
@@ -471,10 +477,18 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
else:
msg = "non-secondary server"
+ elif self.path == '/ismaintenance':
+ msg = ""
+ if os.path.exists("/var/run/postgresql/inmaintenance"):
+ resp = 200
+ msg = "in maintenance mode"
+ else:
+ msg = "not in maintenance mode"
+
elif self.path == '/getpubkey':
try:
resp = 200
- msg = readFile("/home/postgres/.ssh/id_rsa.pub")
+ msg = readFile(os.path.expanduser("~postgres/.ssh/id_rsa.pub"))
except:
traceback.print_exc()
resp = 404
@@ -487,7 +501,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
host = re.sub("[^a-zA-Z0-9_.-]", "", host)
debugTrace("#2: /getssh/ host='%s'" % host)
if self.isValidPgHost(host):
- p = readPipe("scp -o StrictHostKeyChecking=no ~postgres/.ssh/id_rsa* " + host + ":.ssh/ 2>&1")
+ p = readPipe("scp -o StrictHostKeyChecking=no -i ~postgres/.ssh/id_rsa ~postgres/.ssh/id_rsa* postgres@" + host + ":.ssh/ 2>&1")
debugTrace("#3: /getssh/ to '%s' returns '%s'" % (host, p))
msg = "OK " + p
resp = 200
@@ -505,7 +519,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
host = re.sub("[^a-zA-Z0-9_.-]", "", host)
debugTrace("#2: /getcdf/ host='%s'" % host)
if self.isValidPgHost(host):
- p = readPipe("scp -o StrictHostKeyChecking=no " + fi + " " + host + ":/opt/app/cdf/lib/cdf.cfg 2>&1")
+ p = readPipe("scp -o StrictHostKeyChecking=no -i ~postgres/.ssh/id_rsa " + fi + " postgres@" + host + ":/opt/app/cdf/lib/cdf.cfg 2>&1")
debugTrace("#3: /getcdf/ to '%s' returns '%s'" % (host, p))
msg = "OK " + p
resp = 200
@@ -842,6 +856,7 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
<a href='/isrw'>isrw</a> == /var/run/postgresql/isrw
<a href='/ismaster'>ismaster</a> == is master
<a href='/issecondary'>issecondary</a> == is secondary
+ <a href='/ismaintenance'>ismaintenance</a> == is in maintenance mode
<a href='/getpubkey'>getpubkey</a> == retrieve public key
<a href='/hasrepmgr'>hasrepmgr</a> == repmgr id and database are set up
<a href='/status'>status</a> == lots of info
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron b/postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron
index e905633..e08e403 100644
--- a/postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/init/pglogs.cron
@@ -1,4 +1,4 @@
30 * * * * ( date ; find /dbroot/pglogs -type f -mtime +3 -exec rm {} + ) >> /tmp/cleanpglogs.log 2>&1
50 1 * * * ( mv -f /tmp/cleanpglogs.log /tmp/cleanpglogs.log.old ) > /dev/null 2>&1
* * * * * [ -x /opt/app/pgaas/bin/update_var_run_isrw ] && /opt/app/pgaas/bin/update_var_run_isrw
-* * * * * [ -x /opt/app/pgaas/bin/check_cluster ] && /opt/app/pgaas/bin/check_cluster >> /opt/app/log/postgresql/idns/cluster.log
+* * * * * [ -x /opt/app/pgaas/bin/check_cluster ] && /opt/app/pgaas/bin/check_cluster -d /var/run/postgresql/check_cluster >> /opt/app/log/postgresql/idns/cluster.log
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service b/postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service
index bbc28ea..8b9c84e 100644
--- a/postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/init/systemd-pgaas-idns.service
@@ -6,7 +6,10 @@
Description=PGaaS iDNS server
[Service]
+User=postgres
+Group=postgres
ExecStart= /opt/app/postgresql-prep/bin/iDNS-responder.py
+Restart=on-failure
[Install]
WantedBy=multi-user.target
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.json b/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.json
new file mode 100644
index 0000000..2b59cda
--- /dev/null
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.json
@@ -0,0 +1,58 @@
+{
+ "swagger": "2.0",
+ "info": {
+ "version": "1.1.0",
+ "title": "PostgreSQL as a Service REST API"
+ },
+ "paths": {
+ "/rw": {
+ "get": {
+ "description": "Gets a string indicating if this is a PostgreSQL Master server\n",
+ "responses": {
+ "200": {
+ "description": "Successful response",
+ "schema": {
+ "title": "status",
+ "type": "string"
+ }
+ }
+ }
+ }
+ },
+ "/ro": {
+ "get": {
+ "description": "Gets a string indicating if this is either a PostgreSQL Master or Secondary server\n",
+ "responses": {
+ "200": {
+ "description": "Successful response",
+ "schema": {
+ "title": "status",
+ "type": "string"
+ }
+ }
+ }
+ }
+ },
+ "/healthcheck/status": {
+ "get": {
+ "description": "Gets a string indicating the status of this server\n",
+ "responses": {
+ "200": {
+ "description": "Successful response",
+ "schema": {
+ "title": "output",
+ "type": "string"
+ }
+ },
+ "429": {
+ "description": "Error response",
+ "schema": {
+ "title": "output",
+ "type": "string"
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.yaml b/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.yaml
new file mode 100644
index 0000000..5f3ffee
--- /dev/null
+++ b/postgresql-prep/src/stage/opt/app/postgresql-prep/man/iDNS-responder.swagger.yaml
@@ -0,0 +1,68 @@
+# Example YAML to get you started quickly.
+# Be aware that YAML has indentation based scoping.
+# Code completion support is available so start typing for available options.
+swagger: '2.0'
+
+# This is your document metadata
+info:
+ version: "1.1.0"
+ title: PostgreSQL as a Service REST API
+
+# Describe your paths here
+paths:
+ # This is a path endpoint. Change it.
+ /rw:
+ # This is a HTTP operation
+ get:
+ # Describe this verb here. Note: you can use markdown
+ description: |
+ Gets a string indicating if this is a PostgreSQL Master server
+ # Expected responses for this operation:
+ responses:
+ # Response code
+ 200:
+ description: Successful response
+ # A schema describing your response object.
+ # Use JSON Schema format
+ schema:
+ title: status
+ type: string
+ /ro:
+ # This is a HTTP operation
+ get:
+ # Describe this verb here. Note: you can use markdown
+ description: |
+ Gets a string indicating if this is either a PostgreSQL Master or Secondary server
+ # Expected responses for this operation:
+ responses:
+ # Response code
+ 200:
+ description: Successful response
+ # A schema describing your response object.
+ # Use JSON Schema format
+ schema:
+ title: status
+ type: string
+ /healthcheck/status:
+ # This is a HTTP operation
+ get:
+ # Describe this verb here. Note: you can use markdown
+ description: |
+ Gets a string indicating the status of this server
+ # Expected responses for this operation:
+ responses:
+ # Response code
+ 200:
+ description: Successful response
+ # A schema describing your response object.
+ # Use JSON Schema format
+ schema:
+ title: output
+ type: string
+ 429:
+ description: Error response
+ # A schema describing your response object.
+ # Use JSON Schema format
+ schema:
+ title: output
+ type: string