Issue #2182 - PostgreSQL port is now configurable in postgresql.conf; Java path is no longer relative in wrapper.conf

Amend: wrap file access in try..finally; move StringBuilder outside of a loop

Change-Id: Iafa7493ef79a0a891f36923f1695cefdb47e16da

Former-commit-id: b2550c873b [formerly 0c3b22c8f2] [formerly 43008f4698] [formerly b2550c873b [formerly 0c3b22c8f2] [formerly 43008f4698] [formerly 120ebd045a [formerly 43008f4698 [formerly 71f74d7b8125994537ef5520fe59134a7f86e9af]]]]
Former-commit-id: 120ebd045a
Former-commit-id: a63bda59b4 [formerly 68181d3f62] [formerly 1ab6f3920db4e2de42353fe97a9c4fe694df0851 [formerly fac9d72cc8]]
Former-commit-id: ea54fc6cf0eb39a2eb253d886a1e3180ccf382a0 [formerly 9e0e6662c8]
Former-commit-id: fad82481c1
This commit is contained in:
Bryan Kowal 2013-12-12 10:32:22 -06:00
parent bb8784aab4
commit c8e49142f2
12 changed files with 643 additions and 563 deletions

View file

@ -4,6 +4,7 @@
<property name="src" value="src"></property>
<property name="db.mach.name" value="localhost"/>
<property name="database" value="hd_ob83krf" />
<property name="database.port" value="5432" />
<target name="runJDbGen">
@ -12,7 +13,7 @@
<pathelement location="./bin"/>
<pathelement path="${basedir}/REQUIRED_JARS/postgresql-8.3-603.jdbc3.jar"/>
</classpath>
<arg value="jdbc:postgresql://${db.mach.name}:5432/${database}?user=awips"/> <!-- connectionURL -->
<arg value="jdbc:postgresql://${db.mach.name}:${database.port}/${database}?user=awips"/> <!-- connectionURL -->
<arg value="${basedir}/PreferredTableNames.txt"/> <!--preferredTableNameFilePath -->
<arg value="${database}"/> <!-- dbName -->
<arg value="ohd.hseb.ihfsdb.generated"/> <!-- packageName -->

View file

@ -34,7 +34,7 @@ wrapper.fork_hack=true
wrapper.console.pipestreams=true
# Java Application
wrapper.java.command=${EDEX_HOME}/../java/bin/java
wrapper.java.command=${JAVA_HOME}/bin/java
# necessary for etc/init.d/edex_camel
wrapper.pidfile=${EDEX_HOME}/bin/${EDEX_RUN_MODE}.pid

View file

@ -65,6 +65,9 @@ import com.raytheon.wes2bridge.common.configuration.Wes2BridgeConfiguration;
* edex-environment instance
* Apr 18, 2013 1899 bkowal Updates qpid 0.18 configuration now.
* July 2, 2013 2133 bkowal Updates for yajsw-wrapped qpid
* Dec 11, 2013 2182 bkowal Update the postgresql port in
* postgresql.conf instead of the
* postgresql startup scripts
*
* </pre>
*
@ -173,8 +176,12 @@ public class Wes2BridgeManager {
String srcsetup_env = srcEdexDirectory + "/bin/setup.env";
String setup_env = edexDirectory + "/bin/setup.env";
BufferedReader br = this.getBufferedReader(srcsetup_env);
BufferedWriter bw = this.getBufferedWriter(setup_env);
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = this.getBufferedReader(srcsetup_env);
bw = this.getBufferedWriter(setup_env);
final String line1 = "export DATA_ARCHIVE_ROOT=";
final String line2 = "export DB_PORT=";
@ -194,7 +201,8 @@ public class Wes2BridgeManager {
} else if (line.startsWith(line2)) {
line = line2 + this.configuration.getDatabasePort();
} else if (line.startsWith(line3)) {
line = line3 + "localhost:" + this.configuration.getJmsPort();
line = line3 + "localhost:"
+ this.configuration.getJmsPort();
} else if (line.startsWith(line4)) {
line = line4 + this.configuration.getEdexHttpPort();
} else if (line.startsWith(line5)) {
@ -209,9 +217,11 @@ public class Wes2BridgeManager {
bw.write(line + "\n");
}
} finally {
br.close();
bw.close();
}
}
/* Disable JMX. */
private void updateEdexWrapper(String srcEdexDirectory, String edexDirectory)
@ -219,8 +229,11 @@ public class Wes2BridgeManager {
String srcwrapper_conf = srcEdexDirectory + "/conf/wrapper.conf";
String wrapper_conf = edexDirectory + "/conf/wrapper.conf";
BufferedReader br = this.getBufferedReader(srcwrapper_conf);
BufferedWriter bw = this.getBufferedWriter(wrapper_conf);
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = this.getBufferedReader(srcwrapper_conf);
bw = this.getBufferedWriter(wrapper_conf);
/*
* We want to replace at least one of the jmx jvm arguments with the
@ -229,9 +242,9 @@ public class Wes2BridgeManager {
boolean wes2BridgeInstanceAdded = false;
/*
* Disable JMX Remote and add a new wes2bridge.instance JVM argument so
* that it will be possible to determine which edex instance belongs to
* which test case.
* Disable JMX Remote and add a new wes2bridge.instance JVM argument
* so that it will be possible to determine which edex instance
* belongs to which test case.
*/
/*
* This may apply to multiple jvm arguments including: 1)
@ -259,14 +272,17 @@ public class Wes2BridgeManager {
line += line2 + "=" + this.configuration.getWebPort();
} else if (line.contains(line3)) {
line = this.getJVMArgumentName(line);
line += line3 + "=" + this.configuration.getConfidentialPort();
line += line3 + "="
+ this.configuration.getConfidentialPort();
}
bw.write(line + "\n");
}
} finally {
br.close();
bw.close();
}
}
private String getJVMArgumentName(String jvmArgument) {
if (jvmArgument == null) {
@ -289,8 +305,11 @@ public class Wes2BridgeManager {
+ "edex_camel";
final String edex_camel = this.wes2BridgeScripts + "/edex_camel";
BufferedReader br = this.getBufferedReader(srcedex_camel);
BufferedWriter bw = this.getBufferedWriter(edex_camel);
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = this.getBufferedReader(srcedex_camel);
bw = this.getBufferedWriter(edex_camel);
final String line1 = "EDEX_INSTALL=";
final String line2 = "export DATA_ARCHIVE_ROOT=";
@ -311,16 +330,20 @@ public class Wes2BridgeManager {
bw.write(line + "\n");
}
} finally {
br.close();
bw.close();
}
}
public void reconfigurePostgreSQL() throws FileNotFoundException,
IOException {
final String postgresqlRootDirectory = WES2BRIDGE_DIRECTORY + "/"
+ this.configuration.getTestCaseName();
final String postgresqlRootDirectory = WES2BRIDGE_DIRECTORY
+ File.separator + this.configuration.getTestCaseName();
final String srcDataDirectory = AWIPSII + File.separator + "data";
this.updateEdexPostgres(postgresqlRootDirectory);
this.updatePostgresqlConf(srcDataDirectory);
}
private void updateEdexPostgres(String postgresqlRootDirectory)
@ -329,25 +352,66 @@ public class Wes2BridgeManager {
+ "edex_postgres";
final String edex_postgres = this.wes2BridgeScripts + "/edex_postgres";
BufferedReader br = this.getBufferedReader(srcedex_postgres);
BufferedWriter bw = this.getBufferedWriter(edex_postgres);
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = this.getBufferedReader(srcedex_postgres);
bw = this.getBufferedWriter(edex_postgres);
final String line1 = "POSTGRESQL_INSTALL_ROOT=";
final String line2 = "PGPORT=";
String line = StringUtils.EMPTY;
while ((line = br.readLine()) != null) {
if (line.startsWith(line1)) {
line = line1 + postgresqlRootDirectory;
} else if (line.startsWith(line2)) {
line = line2 + this.configuration.getDatabasePort();
}
bw.write(line + "\n");
}
} finally {
br.close();
bw.close();
}
}
private void updatePostgresqlConf(String srcDataDirectory)
throws FileNotFoundException, IOException {
final String postgresqlConf = "postgresql.conf";
final String srcPostgresqlConf = srcDataDirectory + File.separator
+ postgresqlConf;
final String destPostgresqlConf = WES2BRIDGE_DIRECTORY + File.separator
+ this.configuration.getTestCaseName() + File.separator
+ "data" + File.separator + postgresqlConf;
final String regex1 = "^(port = )([0-9]+)(.+)";
final Pattern pattern1 = Pattern.compile(regex1);
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = this.getBufferedReader(srcPostgresqlConf);
bw = this.getBufferedWriter(destPostgresqlConf);
String line = StringUtils.EMPTY;
// only used once - clearing it will not be necessary
StringBuilder stringBuilder = new StringBuilder();
while ((line = br.readLine()) != null) {
Matcher matcher = pattern1.matcher(line);
if (matcher.matches()) {
stringBuilder.append(matcher.group(1));
stringBuilder.append(this.configuration.getDatabasePort());
stringBuilder.append(matcher.group(3));
line = stringBuilder.toString();
}
bw.write(line + "\n");
}
} finally {
br.close();
bw.close();
}
}
public void reconfigureQPID() throws FileNotFoundException, IOException,
ParserConfigurationException, SAXException,
@ -437,8 +501,11 @@ public class Wes2BridgeManager {
final String srcqpidd = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + "qpidd";
final String qpidd = this.wes2BridgeScripts + "/qpidd";
BufferedReader br = this.getBufferedReader(srcqpidd);
BufferedWriter bw = this.getBufferedWriter(qpidd);
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = this.getBufferedReader(srcqpidd);
bw = this.getBufferedWriter(qpidd);
final String line1 = "QPID_HOME=";
@ -450,9 +517,11 @@ public class Wes2BridgeManager {
bw.write(line + "\n");
}
} finally {
br.close();
bw.close();
}
}
/*
* This method will: 1) update pypies.cfg 2) update httpd.conf
@ -489,8 +558,11 @@ public class Wes2BridgeManager {
final String logFileDirectoryLocation = pypiesDirectory
+ File.separator + "logs";
BufferedReader br = this.getBufferedReader(srcpypiescfg);
BufferedWriter bw = this.getBufferedWriter(pypiescfg);
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = this.getBufferedReader(srcpypiescfg);
bw = this.getBufferedWriter(pypiescfg);
final String hdf5DirPattern = "(hdf5dir=).+";
final String logFileDirPattern = "(logFileDir=).+";
@ -518,10 +590,11 @@ public class Wes2BridgeManager {
bw.write(line + "\n");
}
} finally {
br.close();
bw.close();
}
}
private void updateHttpdConf(String srcHttpdPypiesDirectory,
String httpdPypiesDirectory) throws FileNotFoundException,
@ -535,8 +608,11 @@ public class Wes2BridgeManager {
final String serverRoot = httpdPypiesDirectory + File.separator + "etc"
+ File.separator + "httpd";
BufferedReader br = this.getBufferedReader(srcHttpdConf);
BufferedWriter bw = this.getBufferedWriter(httpdConf);
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = this.getBufferedReader(srcHttpdConf);
bw = this.getBufferedWriter(httpdConf);
final String listenPattern = "(Listen )[1-9][0-9]+";
final String serverRootPattern = "(ServerRoot \").+(\")";
@ -558,10 +634,11 @@ public class Wes2BridgeManager {
bw.write(line + "\n");
}
} finally {
br.close();
bw.close();
}
}
private void updateHttpdPypies(String httpdPypiesDirectory,
String pypiesDirectory) throws IOException, FileNotFoundException {
@ -569,15 +646,19 @@ public class Wes2BridgeManager {
+ "httpd-pypies";
final String httpd_pypies = this.wes2BridgeScripts + "/httpd-pypies";
BufferedReader br = this.getBufferedReader(srchttpd_pypies);
BufferedWriter bw = this.getBufferedWriter(httpd_pypies);
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = this.getBufferedReader(srchttpd_pypies);
bw = this.getBufferedWriter(httpd_pypies);
final String httpdPypiesInstallPattern = "(HTTPD_PYPIES_INSTALL=).+";
final String loggingCommandPattern = "( *nohup su awips -c \"\\$loggingCmd > /tmp/pypiesLoggingService)(.log 2>&1\" > /dev/null &)";
final String pypiesConfigurationPattern = "(export PYPIES_CFG=).+";
final Pattern pattern1 = Pattern.compile(httpdPypiesInstallPattern);
final Pattern pattern2 = Pattern.compile(loggingCommandPattern);
final Pattern pattern3 = Pattern.compile(pypiesConfigurationPattern);
final Pattern pattern3 = Pattern
.compile(pypiesConfigurationPattern);
String line = StringUtils.EMPTY;
while ((line = br.readLine()) != null) {
@ -600,10 +681,11 @@ public class Wes2BridgeManager {
bw.write(line + "\n");
}
} finally {
br.close();
bw.close();
}
}
/*
* The following functions and usage of the following functions would no

View file

@ -3,6 +3,7 @@
<property name="dist" value="dist" />
<property name="src" value="src" />
<property name="db.mach.name" value="localhost" />
<property name="db.port" value="5432" />
<property name="database" value="hd_ob83oax" />
<target name="runJDbGen" depends="prepare">
@ -12,7 +13,7 @@
<pathelement location="./classes"/>
<pathelement path="${basedir}/REQUIRED_JARS/postgresql-8.3-603.jdbc3.jar"/>
</classpath>
<arg value="jdbc:postgresql://${db.mach.name}:5432/${database}?user=awips"/> <!-- connectionURL -->
<arg value="jdbc:postgresql://${db.mach.name}:${db.port}/${database}?user=awips"/> <!-- connectionURL -->
<arg value="${basedir}/PreferredTableNames.txt"/> <!--preferredTableNameFilePath -->
<arg value="${database}"/> <!-- dbName -->
<arg value="ohd.hseb.ihfsdb.generated"/> <!-- packageName -->

View file

@ -60,7 +60,7 @@ listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
port = 5432 # (change requires restart)
max_connections = 300 # (change requires restart)
# Note: Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).

View file

@ -60,7 +60,7 @@ listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
port = 5432 # (change requires restart)
max_connections = 300 # (change requires restart)
# Note: Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).

View file

@ -7,7 +7,7 @@
Summary: Pypies Apache HTTP Server
Name: awips2-httpd-pypies
Version: 2.2.15
Release: 15.3.el6
Release: 15.3-1.el6
URL: http://httpd.apache.org/
Source0: http://archive.apache.org/dist/httpd/httpd-%{version}.tar.gz
Source1: index.html

View file

@ -100,7 +100,9 @@ start() {
stop() {
echo -n $"Stopping $prog: "
/awips2/httpd_pypies/usr/sbin/apachectl -k graceful-stop
${HTTPD_PYPIES_INSTALL}/usr/sbin/apachectl -f \
${HTTPD_PYPIES_INSTALL}/etc/httpd/conf/httpd.conf \
-k graceful-stop
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
@ -148,7 +150,9 @@ reload() {
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
/awips2/httpd_pypies/usr/sbin/apachectl -k graceful
${HTTPD_PYPIES_INSTALL}/usr/sbin/apachectl -f \
${HTTPD_PYPIES_INSTALL}/etc/httpd/conf/httpd.conf \
-k graceful
RETVAL=$?
fi
echo

View file

@ -8,7 +8,7 @@
Name: awips2-postgresql
Summary: AWIPS II PostgreSQL Distribution
Version: %{_postgresql_version}
Release: 1.el6
Release: 2.el6
Group: AWIPSII
BuildRoot: %{_build_root}
BuildArch: %{_build_arch}

View file

@ -36,8 +36,6 @@ PGDATA_DIR="${POSTGRESQL_INSTALL_ROOT}/data"
PGDATA="${PGDATA_DIR}"
# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=awips
# Port to start the database with
PGPORT=5432
# Where to keep a log file
PGLOG="$PGDATA/serverlog"
# The path that is to be used for the script
@ -57,29 +55,29 @@ PGCTL="${POSTGRESQL_INSTALL}/bin/pg_ctl"
case $1 in
start)
echo -n "Starting EDEX PostgreSQL: "
su $PGUSER -c "$DAEMON -D '$PGDATA' -p $PGPORT &" >>$PGLOG 2>&1
su $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo
RETVAL=$?
;;
stop)
echo -n "Stopping EDEX PostgreSQL: "
su $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -o \"-p $PGPORT\""
su $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
echo
RETVAL=$?
;;
restart)
echo -n "Restarting EDEX PostgreSQL: "
su $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w -o \"-p $PGPORT\""
su $PGUSER -c "$DAEMON -D '$PGDATA' -p $PGPORT &" >>$PGLOG 2>&1
su $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
su $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
RETVAL=$?
;;
reload)
echo -n "Reload EDEX PostgreSQL: "
su $PGUSER -c "$PGCTL reload -D '$PGDATA' -s -o \"-p $PGPORT\""
su $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
RETVAL=$?
;;
status)
su $PGUSER -c "$PGCTL status -D '$PGDATA' -o \"-p $PGPORT\""
su $PGUSER -c "$PGCTL status -D '$PGDATA'"
;;
*)
# Print help

View file

@ -11,9 +11,6 @@ prefix="${POSTGRESQL_INSTALL}/postgresql"
# Data Directory
PGDATA="${POSTGRESQL_INSTALL}/data"
# Port to start the database with
PGPORT=5432
# Where to keep a log file
PGLOG="$PGDATA/serverlog"
@ -40,7 +37,7 @@ set -e
test -x $DAEMON || exit 0
echo -n "Starting PostgreSQL: "
$DAEMON -D $PGDATA -p $PGPORT
$DAEMON -D $PGDATA

View file

@ -11,9 +11,6 @@ prefix="${POSTGRESQL_INSTALL}/postgresql"
# Data Directory
PGDATA="${POSTGRESQL_INSTALL}/data"
# Port to start the database with
PGPORT=5432
# Where to keep a log file
PGLOG="$PGDATA/serverlog"
@ -40,7 +37,7 @@ set -e
test -x $DAEMON || exit 0
echo -n "Starting PostgreSQL: "
$DAEMON -D $PGDATA -p $PGPORT
$DAEMON -D $PGDATA