diff --git a/javaUtilities/com.raytheon.wes2bridge.common/src/com/raytheon/wes2bridge/common/configuration/Wes2BridgeConfiguration.java b/javaUtilities/com.raytheon.wes2bridge.common/src/com/raytheon/wes2bridge/common/configuration/Wes2BridgeConfiguration.java index ee50592e89..150c9fd01c 100644 --- a/javaUtilities/com.raytheon.wes2bridge.common/src/com/raytheon/wes2bridge/common/configuration/Wes2BridgeConfiguration.java +++ b/javaUtilities/com.raytheon.wes2bridge.common/src/com/raytheon/wes2bridge/common/configuration/Wes2BridgeConfiguration.java @@ -1,32 +1,77 @@ /** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. * - */ + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ package com.raytheon.wes2bridge.common.configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.XMLConfiguration; /** + * Reads the edex-environment XML configuration. + * + *
+ * + * SOFTWARE HISTORY + * + * Date Ticket# Engineer Description + * ------------ ---------- ----------- -------------------------- + * Jan 18, 2012 1490 bkowal Added httpdPypiesPort and + * pypiesLoggingPort as configurable + * parameters. + * + *+ * * @author bkowal - * + * @version 1.0 */ /* - * Example: - *
+ * + * SOFTWARE HISTORY + * + * Date Ticket# Engineer Description + * ------------ ---------- ----------- -------------------------- + * Jan 18, 2012 1490 bkowal Pypies is now added to each + * edex-environment instance + * + *+ * * @author bkowal - * - * This java-based utility is used to update a wes2bridge environment. - * This utility is invoked by the wes2bridge management script (bash) - * after the management script spawns a new edex, database, qpid. - * Only "base" files are updated based on the configuration file. The - * new wes2bridge environment will still need to be localized. + * @version 1.0 */ -public class Wes2BridgeManager -{ - private static final String AWIPSII = - "/awips2"; - private static final String AWIPSII_WES2BRIDGE_SCRIPTS = - AWIPSII + "/edex-environment/scripts"; - private static final String WES2BRIDGE_DIRECTORY = - "/usr/local/edex-environment"; +public class Wes2BridgeManager { + private static final String AWIPSII = "/awips2"; + private static final String AWIPSII_WES2BRIDGE_SCRIPTS = AWIPSII + + "/edex-environment/scripts"; + private static final String WES2BRIDGE_DIRECTORY = "/usr/local/edex-environment"; + private static final int GROUP_INDEX_ONE = 1; + private static final int GROUP_INDEX_TWO = 2; + private static final int EXIT_FAILURE = -1; + private static final int EXIT_SUCCESS = 0; + private static final String DEFAULT_HDF5_DIRECTORY = "/edex/data/hdf5"; private Wes2BridgeConfiguration configuration = null; private String wes2BridgeScripts = null; - + /** * */ - public Wes2BridgeManager() - { + public Wes2BridgeManager() { } /** * @param args */ - public static void main(String[] args) - { - if (args.length != 1) - { - System.out.println("ERROR: The configuration file has not been specified."); - System.exit(-1); + public static void main(String[] args) { + if (args.length != 1) { + System.out + .println("ERROR: The configuration file has not been specified."); + System.exit(EXIT_FAILURE); } - + Wes2BridgeManager manager = new Wes2BridgeManager(); - try - { + try { manager.init(args[0]); - } - catch (Exception e1) - { + } catch (Exception e1) { e1.printStackTrace(); - System.exit(-1); + System.exit(EXIT_FAILURE); } - - try - { + + try { manager.reconfigureEdex(); - } - catch (Exception e1) - { + } catch (Exception e1) { e1.printStackTrace(); - System.exit(-1); + System.exit(EXIT_FAILURE); } - - try - { + + try { manager.reconfigurePostgreSQL(); - } - catch (Exception e1) - { + } catch (Exception e1) { e1.printStackTrace(); - System.exit(-1); + System.exit(EXIT_FAILURE); } - - try - { + + try { manager.reconfigureQPID(); - } - catch (Exception e1) - { + } catch (Exception e1) { e1.printStackTrace(); - System.exit(-1); + System.exit(EXIT_FAILURE); } - - System.exit(0); + + try { + manager.reconfigurePypies(); + } catch (Exception e1) { + e1.printStackTrace(); + System.exit(EXIT_FAILURE); + } + + System.exit(EXIT_SUCCESS); } - - public void init(String arg1) - throws ConfigurationException - { + + public void init(String arg1) throws ConfigurationException { configuration = new Wes2BridgeConfiguration(arg1); configuration.init(); - this.wes2BridgeScripts = WES2BRIDGE_DIRECTORY + "/" + - configuration.getTestCaseName() + "/" + - "edex-environment"; + this.wes2BridgeScripts = WES2BRIDGE_DIRECTORY + "/" + + configuration.getTestCaseName() + "/" + "edex-environment"; } - + /* * Updates setup.env and wrapper.conf. */ - public void reconfigureEdex() - throws FileNotFoundException, IOException - { - final String srcEdexDirectory = - AWIPSII + "/" + - "edex"; - final String edexDirectory = - WES2BRIDGE_DIRECTORY + "/" + - this.configuration.getTestCaseName() + "/" + - "edex"; - + public void reconfigureEdex() throws FileNotFoundException, IOException { + final String srcEdexDirectory = AWIPSII + "/" + "edex"; + final String edexDirectory = WES2BRIDGE_DIRECTORY + "/" + + this.configuration.getTestCaseName() + "/" + "edex"; + this.updateEdexSetup(srcEdexDirectory, edexDirectory); this.updateEdexWrapper(srcEdexDirectory, edexDirectory); this.updateEdexCamel(edexDirectory); } - - private void updateEdexSetup(String srcEdexDirectory, - String edexDirectory) - throws FileNotFoundException, IOException - { + + private void updateEdexSetup(String srcEdexDirectory, String edexDirectory) + throws FileNotFoundException, IOException, IllegalStateException { String srcsetup_env = srcEdexDirectory + "/bin/setup.env"; String setup_env = edexDirectory + "/bin/setup.env"; - - File srcFile = new File(srcsetup_env); - File destFile = new File(setup_env); - BufferedReader br = - new BufferedReader(new FileReader(srcFile)); - BufferedWriter bw = - new BufferedWriter(new FileWriter(destFile)); - + + BufferedReader br = this.getBufferedReader(srcsetup_env); + BufferedWriter bw = this.getBufferedWriter(setup_env); + final String line1 = "export DATA_ARCHIVE_ROOT="; final String line2 = "export DB_PORT="; final String line3 = "export BROKER_ADDR="; final String line4 = "export HTTP_PORT="; final String line5 = "export JMS_SERVER="; final String line6 = "export SHARE_DIR="; - - String line = ""; - while ((line = br.readLine()) != null) - { - if (line.startsWith(line1)) - { + final String pypiesServerPattern = "(export PYPIES_SERVER=http://.+:)[1-9][0-9]+"; + final Pattern pattern7 = Pattern.compile(pypiesServerPattern); + + String line = StringUtils.EMPTY; + while ((line = br.readLine()) != null) { + Matcher matcher = pattern7.matcher(line); + + if (line.startsWith(line1)) { line = line1 + this.configuration.getDataArchiveRoot(); - } - else if (line.startsWith(line2)) - { + } else if (line.startsWith(line2)) { line = line2 + this.configuration.getDatabasePort(); - } - else if (line.startsWith(line3)) - { - line = line3 + "localhost:" + - this.configuration.getJmsPort(); - } - else if (line.startsWith(line4)) - { + } else if (line.startsWith(line3)) { + line = line3 + "localhost:" + this.configuration.getJmsPort(); + } else if (line.startsWith(line4)) { line = line4 + this.configuration.getEdexHttpPort(); - } - else if (line.startsWith(line5)) - { - line = line5 + "tcp://localhost:" + - this.configuration.getJmsPort(); - } - else if (line.startsWith(line6)) - { + } else if (line.startsWith(line5)) { + line = line5 + "tcp://localhost:" + + this.configuration.getJmsPort(); + } else if (line.startsWith(line6)) { line = line6 + edexDirectory + "/data/share"; + } else if (matcher.matches()) { + line = matcher.group(GROUP_INDEX_ONE) + + this.configuration.getHttpdPypiesPort(); } - + bw.write(line + "\n"); } br.close(); bw.close(); } - + /* Disable JMX. */ - private void updateEdexWrapper(String srcEdexDirectory, - String edexDirectory) - throws FileNotFoundException, IOException - { - String srcwrapper_conf = srcEdexDirectory + - "/bin/wrapper.conf"; - String wrapper_conf = edexDirectory + - "/bin/wrapper.conf"; - - File srcFile = new File(srcwrapper_conf); - File destFile = new File(wrapper_conf); - BufferedReader br = - new BufferedReader(new FileReader(srcFile)); - BufferedWriter bw = - new BufferedWriter(new FileWriter(destFile)); - + private void updateEdexWrapper(String srcEdexDirectory, String edexDirectory) + throws FileNotFoundException, IOException { + String srcwrapper_conf = srcEdexDirectory + "/bin/wrapper.conf"; + String wrapper_conf = edexDirectory + "/bin/wrapper.conf"; + + BufferedReader br = this.getBufferedReader(srcwrapper_conf); + BufferedWriter bw = this.getBufferedWriter(wrapper_conf); + /* - * We want to replace at least one of the jmx jvm arguments - * with the wes2bridge.instance argument. + * We want to replace at least one of the jmx jvm arguments with the + * wes2bridge.instance argument. */ 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) -Dcom.sun.management.jmxremote.port - * 2) -Dcom.sun.management.jmxremote.authenticate - * 3) -Dcom.sun.management.jmxremote.ssl + * This may apply to multiple jvm arguments including: 1) + * -Dcom.sun.management.jmxremote.port 2) + * -Dcom.sun.management.jmxremote.authenticate 3) + * -Dcom.sun.management.jmxremote.ssl */ final String line1 = "-Dcom.sun.management.jmxremote"; /* Set the web port; used by uengine spring. */ final String line2 = "-Dweb.port"; /* Set the confidential port; used by uengine spring. */ final String line3 = "-Dconfidential.port"; - - String line = ""; - while ((line = br.readLine()) != null) - { - if (line.contains(line1)) - { + + String line = StringUtils.EMPTY; + while ((line = br.readLine()) != null) { + if (line.contains(line1)) { line = this.getJVMArgumentName(line); - if (wes2BridgeInstanceAdded == false) - { - line += "-Dwes2bridge.instance=" + - this.configuration.getTestCaseName(); + if (wes2BridgeInstanceAdded == false) { + line += "-Dwes2bridge.instance=" + + this.configuration.getTestCaseName(); wes2BridgeInstanceAdded = true; } - } - else if (line.contains(line2)) - { + } else if (line.contains(line2)) { line = this.getJVMArgumentName(line); - line += line2 + "=" + - this.configuration.getWebPort(); - } - else if (line.contains(line3)) - { + 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"); } br.close(); bw.close(); } - - private String getJVMArgumentName(String jvmArgument) - { - if (jvmArgument == null) - { + + private String getJVMArgumentName(String jvmArgument) { + if (jvmArgument == null) { System.out.println("ERROR: Invalid wrapper.conf file."); - System.exit(-1); + System.exit(EXIT_FAILURE); } - + String[] splitJVMArg = jvmArgument.split("="); - if (splitJVMArg.length <= 0) - { + if (splitJVMArg.length <= 0) { System.out.println("ERROR: Invalid wrapper.conf file."); - System.exit(-1); + System.exit(EXIT_FAILURE); } - + return splitJVMArg[0] + "="; } - + private void updateEdexCamel(String edexDirectory) - throws FileNotFoundException, IOException - { - final String srcedex_camel = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + - "edex_camel"; + throws FileNotFoundException, IOException { + final String srcedex_camel = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + + "edex_camel"; final String edex_camel = this.wes2BridgeScripts + "/edex_camel"; - - File srcFile = new File(srcedex_camel); - File destFile = new File(edex_camel); - BufferedReader br = - new BufferedReader(new FileReader(srcFile)); - BufferedWriter bw = - new BufferedWriter(new FileWriter(destFile)); - + + BufferedReader br = this.getBufferedReader(srcedex_camel); + BufferedWriter bw = this.getBufferedWriter(edex_camel); + final String line1 = "EDEX_INSTALL="; final String line2 = "export DATA_ARCHIVE_ROOT="; - final String line3 = - "CAMELPROCESS=`ps -ef | grep \"edex.dev.mode\"|grep -c \"edex.run.mode=${1} \" `"; - - String line = ""; - while ((line = br.readLine()) != null) - { - if (line.trim().startsWith(line1)) - { + final String line3 = "CAMELPROCESS=`ps -ef | grep \"edex.dev.mode\"|grep -c \"edex.run.mode=${1} \" `"; + + String line = StringUtils.EMPTY; + while ((line = br.readLine()) != null) { + if (line.trim().startsWith(line1)) { line = line1 + edexDirectory; + } else if (line.trim().startsWith(line2)) { + line = line2 + this.configuration.getDataArchiveRoot(); + } else if (line.trim().startsWith(line3)) { + line = "CAMELPROCESS=`ps -ef | " + + "grep \"wes2bridge.instance=" + + this.configuration.getTestCaseName() + "\" | " + + "grep -c \"edex.run.mode=${1} \" `"; } - else if (line.trim().startsWith(line2)) - { - line = line2 + - this.configuration.getDataArchiveRoot(); - } - else if (line.trim().startsWith(line3)) - { - line = "CAMELPROCESS=`ps -ef | " + - "grep \"wes2bridge.instance=" + - this.configuration.getTestCaseName() + "\" | " + - "grep -c \"edex.run.mode=${1} \" `"; - } - + bw.write(line + "\n"); } br.close(); bw.close(); } - - public void reconfigurePostgreSQL() - throws FileNotFoundException, IOException - { - final String postgresqlRootDirectory = - WES2BRIDGE_DIRECTORY + "/" + - this.configuration.getTestCaseName(); - + + public void reconfigurePostgreSQL() throws FileNotFoundException, + IOException { + final String postgresqlRootDirectory = WES2BRIDGE_DIRECTORY + "/" + + this.configuration.getTestCaseName(); + this.updateEdexPostgres(postgresqlRootDirectory); } - + private void updateEdexPostgres(String postgresqlRootDirectory) - throws FileNotFoundException, IOException - { - final String srcedex_postgres = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + - "edex_postgres"; - final String edex_postgres = this.wes2BridgeScripts + - "/edex_postgres"; - - File srcFile = new File(srcedex_postgres); - File destFile = new File(edex_postgres); - BufferedReader br = - new BufferedReader(new FileReader(srcFile)); - BufferedWriter bw = - new BufferedWriter(new FileWriter(destFile)); - + throws FileNotFoundException, IOException { + final String srcedex_postgres = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + + "edex_postgres"; + final String edex_postgres = this.wes2BridgeScripts + "/edex_postgres"; + + BufferedReader br = this.getBufferedReader(srcedex_postgres); + BufferedWriter bw = this.getBufferedWriter(edex_postgres); + final String line1 = "POSTGRESQL_INSTALL_ROOT="; final String line2 = "PGPORT="; - - String line = ""; - while ((line = br.readLine()) != null) - { - if (line.startsWith(line1)) - { + + 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(); } - else if (line.startsWith(line2)) - { - line = line2 + - this.configuration.getDatabasePort(); - } - + bw.write(line + "\n"); } br.close(); bw.close(); } - - public void reconfigureQPID() - throws FileNotFoundException, IOException - { - final String srcQpidDirectory = - AWIPSII + "/" + - "qpid"; - final String qpidDirectory = - WES2BRIDGE_DIRECTORY + "/" + - this.configuration.getTestCaseName() + "/" + - "qpid"; - + + public void reconfigureQPID() throws FileNotFoundException, IOException { + final String srcQpidDirectory = AWIPSII + "/" + "qpid"; + final String qpidDirectory = WES2BRIDGE_DIRECTORY + "/" + + this.configuration.getTestCaseName() + "/" + "qpid"; + this.updateQpidConf(srcQpidDirectory, qpidDirectory); this.updateQPIDD(qpidDirectory); this.updateQueueCreatorSH(qpidDirectory); } - + /* Updates qpidd.conf */ - private void updateQpidConf(String srcQpidDirectory, - String qpidDirectory) - throws FileNotFoundException, IOException - { - String srcqpidd_conf = srcQpidDirectory + - "/etc/qpidd.conf"; + private void updateQpidConf(String srcQpidDirectory, String qpidDirectory) + throws FileNotFoundException, IOException { + String srcqpidd_conf = srcQpidDirectory + "/etc/qpidd.conf"; String qpidd_conf = qpidDirectory + "/etc/qpidd.conf"; - - File srcFile = new File(srcqpidd_conf); - File destFile = new File(qpidd_conf); - BufferedReader br = - new BufferedReader(new FileReader(srcFile)); - BufferedWriter bw = - new BufferedWriter(new FileWriter(destFile)); - + + BufferedReader br = this.getBufferedReader(srcqpidd_conf); + BufferedWriter bw = this.getBufferedWriter(qpidd_conf); + final String line1 = "data-dir="; final String line2 = "store-dir="; final String line3 = "pid-dir="; @@ -404,91 +350,235 @@ public class Wes2BridgeManager * add the port to qpidd.conf */ final String line4 = "auth=no"; - - String line = ""; - while ((line = br.readLine()) != null) - { - if (line.startsWith(line1)) - { + + String line = StringUtils.EMPTY; + while ((line = br.readLine()) != null) { + if (line.startsWith(line1)) { line = line1 + qpidDirectory + "/data"; - } - else if (line.startsWith(line2)) - { + } else if (line.startsWith(line2)) { line = line2 + qpidDirectory + "/messageStore"; - } - else if (line.startsWith(line3)) - { + } else if (line.startsWith(line3)) { line = line3 + qpidDirectory + "/var/lock"; + } else if (line.startsWith(line4)) { + line = line4 + "\nport=" + this.configuration.getJmsPort(); } - else if (line.startsWith(line4)) - { - line = line4 + "\nport=" + - this.configuration.getJmsPort(); - } - + bw.write(line + "\n"); } br.close(); bw.close(); } - + private void updateQPIDD(String qpidDirectory) - throws FileNotFoundException, IOException - { - final String srcqpidd = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + - "qpidd"; + throws FileNotFoundException, IOException { + final String srcqpidd = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + "qpidd"; final String qpidd = this.wes2BridgeScripts + "/qpidd"; - - File srcFile = new File(srcqpidd); - File destFile = new File(qpidd); - BufferedReader br = - new BufferedReader(new FileReader(srcFile)); - BufferedWriter bw = - new BufferedWriter(new FileWriter(destFile)); - + + BufferedReader br = this.getBufferedReader(srcqpidd); + BufferedWriter bw = this.getBufferedWriter(qpidd); + final String line1 = "QPID_HOME="; - - String line = ""; - while ((line = br.readLine()) != null) - { - if (line.startsWith(line1)) - { + + String line = StringUtils.EMPTY; + while ((line = br.readLine()) != null) { + if (line.startsWith(line1)) { line = line1 + qpidDirectory; } - + bw.write(line + "\n"); } br.close(); bw.close(); } - + private void updateQueueCreatorSH(String qpidDirectory) - throws FileNotFoundException, IOException - { - final String srcqueue = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + - "queueCreator.sh"; - final String queue = qpidDirectory + "/sbin/queueCreator.sh"; - - File srcFile = new File(srcqueue); - File destFile = new File(queue); - BufferedReader br = - new BufferedReader(new FileReader(srcFile)); - BufferedWriter bw = - new BufferedWriter(new FileWriter(destFile)); - + throws FileNotFoundException, IOException { + final String srcqueue = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + + "queueCreator.sh"; + final String queue = qpidDirectory + "/sbin/queueCreator.sh"; + + BufferedReader br = this.getBufferedReader(srcqueue); + BufferedWriter bw = this.getBufferedWriter(queue); + final String line1 = "port="; - - String line = ""; - while ((line = br.readLine()) != null) - { - if (line.startsWith(line1)) - { + + String line = StringUtils.EMPTY; + while ((line = br.readLine()) != null) { + if (line.startsWith(line1)) { line = line1 + this.configuration.getJmsPort(); } - + bw.write(line + "\n"); } br.close(); bw.close(); } + + /* + * This method will: 1) update pypies.cfg 2) update httpd.conf + */ + public void reconfigurePypies() throws FileNotFoundException, IOException { + final String srcPypiesDirectory = AWIPSII + File.separator + "pypies"; + final String pypiesDirectory = WES2BRIDGE_DIRECTORY + File.separator + + this.configuration.getTestCaseName() + File.separator + + "pypies"; + + final String srcHttpdPypiesDirectory = AWIPSII + File.separator + + "httpd_pypies"; + final String httpdPypiesDirectory = WES2BRIDGE_DIRECTORY + + File.separator + this.configuration.getTestCaseName() + + File.separator + "httpd_pypies"; + + this.updatePypiesCfg(srcPypiesDirectory, pypiesDirectory); + this.updateHttpdConf(srcHttpdPypiesDirectory, httpdPypiesDirectory); + this.updateHttpdPypies(httpdPypiesDirectory, pypiesDirectory); + } + + private void updatePypiesCfg(String srcPypiesDirectory, + String pypiesDirectory) throws FileNotFoundException, IOException, + IllegalArgumentException { + final String pypiesCfgPathSuffix = File.separator + "conf" + + File.separator + "pypies.cfg"; + final String srcpypiescfg = srcPypiesDirectory + pypiesCfgPathSuffix; + final String pypiescfg = pypiesDirectory + pypiesCfgPathSuffix; + + // use the default location for the hdf5 root + final String hdf5DirectoryLocation = WES2BRIDGE_DIRECTORY + + File.separator + this.configuration.getTestCaseName() + + DEFAULT_HDF5_DIRECTORY; + final String logFileDirectoryLocation = pypiesDirectory + + File.separator + "logs"; + + BufferedReader br = this.getBufferedReader(srcpypiescfg); + BufferedWriter bw = this.getBufferedWriter(pypiescfg); + + final String hdf5DirPattern = "(hdf5dir=).+"; + final String logFileDirPattern = "(logFileDir=).+"; + final String loggingPortPattern = "(logging_port=)[1-9][0-9]+"; + final Pattern pattern1 = Pattern.compile(hdf5DirPattern); + final Pattern pattern2 = Pattern.compile(logFileDirPattern); + final Pattern pattern3 = Pattern.compile(loggingPortPattern); + + String line = StringUtils.EMPTY; + while ((line = br.readLine()) != null) { + Matcher matcher1 = pattern1.matcher(line); + Matcher matcher2 = pattern2.matcher(line); + Matcher matcher3 = pattern3.matcher(line); + + if (matcher1.matches()) { + line = matcher1.group(GROUP_INDEX_ONE); + line += hdf5DirectoryLocation; + } else if (matcher2.matches()) { + line = matcher2.group(GROUP_INDEX_ONE); + line += logFileDirectoryLocation; + } else if (matcher3.matches()) { + line = matcher3.group(GROUP_INDEX_ONE); + line += this.configuration.getPypiesLoggingPort(); + } + + bw.write(line + "\n"); + } + + br.close(); + bw.close(); + } + + private void updateHttpdConf(String srcHttpdPypiesDirectory, + String httpdPypiesDirectory) throws FileNotFoundException, + IOException { + final String httpdConfPathSuffix = File.separator + "etc" + + File.separator + "httpd" + File.separator + "conf" + + File.separator + "httpd.conf"; + final String srcHttpdConf = srcHttpdPypiesDirectory + + httpdConfPathSuffix; + final String httpdConf = httpdPypiesDirectory + httpdConfPathSuffix; + final String serverRoot = httpdPypiesDirectory + File.separator + "etc" + + File.separator + "httpd"; + + BufferedReader br = this.getBufferedReader(srcHttpdConf); + BufferedWriter bw = this.getBufferedWriter(httpdConf); + + final String listenPattern = "(Listen )[1-9][0-9]+"; + final String serverRootPattern = "(ServerRoot \").+(\")"; + final Pattern pattern1 = Pattern.compile(listenPattern); + final Pattern pattern2 = Pattern.compile(serverRootPattern); + + String line = StringUtils.EMPTY; + while ((line = br.readLine()) != null) { + Matcher matcher1 = pattern1.matcher(line); + Matcher matcher2 = pattern2.matcher(line); + if (matcher1.matches()) { + line = matcher1.group(GROUP_INDEX_ONE); + line += this.configuration.getHttpdPypiesPort(); + } else if (matcher2.matches()) { + line = matcher2.group(GROUP_INDEX_ONE); + line += serverRoot; + line += matcher2.group(GROUP_INDEX_TWO); + } + + bw.write(line + "\n"); + } + + br.close(); + bw.close(); + } + + private void updateHttpdPypies(String httpdPypiesDirectory, + String pypiesDirectory) throws IOException, FileNotFoundException { + final String srchttpd_pypies = AWIPSII_WES2BRIDGE_SCRIPTS + "/" + + "httpd-pypies"; + final String httpd_pypies = this.wes2BridgeScripts + "/httpd-pypies"; + + BufferedReader br = this.getBufferedReader(srchttpd_pypies); + BufferedWriter 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); + + String line = StringUtils.EMPTY; + while ((line = br.readLine()) != null) { + Matcher matcher1 = pattern1.matcher(line); + Matcher matcher2 = pattern2.matcher(line); + Matcher matcher3 = pattern3.matcher(line); + + if (matcher1.matches()) { + line = matcher1.group(GROUP_INDEX_ONE); + line += httpdPypiesDirectory; + } else if (matcher2.matches()) { + line = matcher2.group(GROUP_INDEX_ONE); + line += this.configuration.getTestCaseName(); + line += matcher2.group(GROUP_INDEX_TWO); + } else if (matcher3.matches()) { + line = matcher3.group(GROUP_INDEX_ONE) + pypiesDirectory + + File.separator + "conf" + File.separator + + "pypies.cfg"; + } + + bw.write(line + "\n"); + } + + br.close(); + bw.close(); + } + + /* + * The following functions and usage of the following functions would no + * longer be necessary with Apache Commons IOUtils. + */ + private BufferedReader getBufferedReader(String file) + throws FileNotFoundException { + return new BufferedReader(new FileReader(this.getFile(file))); + } + + private BufferedWriter getBufferedWriter(String file) throws IOException { + return new BufferedWriter(new FileWriter(this.getFile(file))); + } + + private File getFile(String file) { + return new File(file); + } } \ No newline at end of file diff --git a/javaUtilities/com.raytheon.wes2bridge.manager/src/log4j.properties b/javaUtilities/com.raytheon.wes2bridge.manager/src/log4j.properties new file mode 100644 index 0000000000..6e516c4cb7 --- /dev/null +++ b/javaUtilities/com.raytheon.wes2bridge.manager/src/log4j.properties @@ -0,0 +1,6 @@ +log4j.rootLogger=ERROR, CA + +log4j.appender.CA=org.apache.log4j.ConsoleAppender +log4j.appender.CA.layout=org.apache.log4j.PatternLayout + +log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n \ No newline at end of file diff --git a/pythonPackages/pypies/pypies.cfg b/pythonPackages/pypies/pypies.cfg index 1642434851..1c12233382 100644 --- a/pythonPackages/pypies/pypies.cfg +++ b/pythonPackages/pypies/pypies.cfg @@ -28,7 +28,7 @@ # Date Ticket# Engineer Description # ------------ ---------- ----------- -------------------------- # 10/07/10 njensen Initial Creation. -# +# 01/17/13 1490 bkowal Added tcp_logger configuration # # @@ -38,6 +38,11 @@ hdf5dir=/awips2/edex/data/hdf5 [loggers] keys=root,minutes,hours +[tcp_logger] +# default is based on logging.handlers.DEFAULT_TCP_LOGGING_PORT +# at the time this change was made. +logging_port=9020 + [handlers] keys=pypiesHandler,minutesHandler,hoursHandler diff --git a/pythonPackages/pypies/pypies/__init__.py b/pythonPackages/pypies/pypies/__init__.py index 380a0bae2d..5095266b99 100644 --- a/pythonPackages/pypies/pypies/__init__.py +++ b/pythonPackages/pypies/pypies/__init__.py @@ -28,25 +28,58 @@ # Date Ticket# Engineer Description # ------------ ---------- ----------- -------------------------- # 05/27/10 njensen Initial Creation. -# +# 01/17/13 1490 bkowal Retrieve the hdf5 root directory +# and the logging tcp port from +# configuration. # # import IDataStore +import sys, os +import pypies.config.pypiesConfigurationManager -def getLogger(): +def configure(): + pypiesConfigurationManager = pypies.config.pypiesConfigurationManager.PypiesConfigurationManager() + if (not pypiesConfigurationManager.hasConfigurationBeenLoaded()): + # this case is unlikely + print 'Failed to load the pypies configuration!' + sys.exit(-1) + + return pypiesConfigurationManager + +def getLogger(scp): import logging, logging.handlers + + loggingPort = int(scp.get('tcp_logger', 'logging_port')) + logger = logging.getLogger('pypies') logger.setLevel(logging.INFO) - socketHandler = logging.handlers.SocketHandler('localhost', logging.handlers.DEFAULT_TCP_LOGGING_PORT) + socketHandler = logging.handlers.SocketHandler('localhost', loggingPort) # don't bother with a formatter, since a socket handler sends the event as # an unformatted pickle logger.addHandler(socketHandler) return logger -logger = getLogger() +def getHdf5Dir(scp): + # determine the edex hdf5 root + hdf5Dir = scp.get('edex_data', 'hdf5dir') + # add a trailing directory separator (when necessary) + if (not hdf5Dir.endswith('/')): + hdf5Dir = hdf5Dir + '/' + + if not os.path.exists(hdf5Dir): + os.makedirs(hdf5Dir) + infoMessage = 'using hdf5 directory: ' + hdf5Dir + logger.info(infoMessage) + + return hdf5Dir + +pypiesCM = configure() +scp = pypiesCM.getConfiguration() +logger = getLogger(scp) timeMap = {} +hdf5Dir = getHdf5Dir(scp) def pypiesWrapper(request): diff --git a/pythonPackages/pypies/pypies/config/pypiesConfigurationManager.py b/pythonPackages/pypies/pypies/config/pypiesConfigurationManager.py index 6f6e79b71e..af3dd14c9e 100644 --- a/pythonPackages/pypies/pypies/config/pypiesConfigurationManager.py +++ b/pythonPackages/pypies/pypies/config/pypiesConfigurationManager.py @@ -28,9 +28,9 @@ # Date Ticket# Engineer Description # ------------ ---------- ----------- -------------------------- # 01/10/13 bkowal Initial Creation. -# +# 01/17/13 #1490 bkowal The location of pypies.cfg is +# now retrieved from the environment. # -# import os, ConfigParser @@ -46,7 +46,7 @@ class PypiesConfigurationManager: self.__loadConfig() def __initConfigLocation(self): - self.__configLoc = '/awips2/pypies/conf/pypies.cfg' + self.__configLoc = os.environ["PYPIES_CFG"] if not os.path.exists(self.__configLoc): print "Unable to find pypies.cfg at ", self.__configLoc self.__configLoc = None diff --git a/pythonPackages/pypies/pypies/handlers.py b/pythonPackages/pypies/pypies/handlers.py index c74b28b7d5..b9e3a780d1 100644 --- a/pythonPackages/pypies/pypies/handlers.py +++ b/pythonPackages/pypies/pypies/handlers.py @@ -30,6 +30,7 @@ # ------------ ---------- ----------- -------------------------- # 08/17/10 njensen Initial Creation. # 01/11/13 bkowal Pypies will now read the hdf5 root from configuration +# 01/17/13 1490 bkowal Relocated the configuration of pypies # # @@ -37,14 +38,13 @@ from werkzeug import Request, Response, ClosingIterator import time, logging, os import pypies from pypies import IDataStore -import pypies.config.pypiesConfigurationManager import dynamicserialize from dynamicserialize.dstypes.com.raytheon.uf.common.pypies.request import * from dynamicserialize.dstypes.com.raytheon.uf.common.pypies.response import * logger = pypies.logger timeMap = pypies.timeMap -hdf5Dir = None +hdf5Dir = pypies.hdf5Dir from pypies.impl import H5pyDataStore datastore = H5pyDataStore.H5pyDataStore() @@ -62,26 +62,6 @@ datastoreMap = { CopyRequest: (datastore.copy, "CopyRequest") } -pypiesConfigurationManager = pypies.config.pypiesConfigurationManager.PypiesConfigurationManager() -if (pypiesConfigurationManager.hasConfigurationBeenLoaded()): - configLocation = pypiesConfigurationManager.getConfigurationLocation() - infoMessage = 'using ' + configLocation + ' for pypies config' - logger.info(infoMessage) - - # determine the edex hdf5 root - scp = pypiesConfigurationManager.getConfiguration() - hdf5Dir = scp.get('edex_data', 'hdf5dir') - # add a trailing directory separator (when necessary) - if (not hdf5Dir.endswith('/')): - hdf5Dir = hdf5Dir + '/' - - if not os.path.exists(hdf5Dir): - os.makedirs(hdf5Dir) - infoMessage = 'using hdf5 directory: ' + hdf5Dir - logger.info(infoMessage) - -# TODO: error and halt when configuration cannot be loaded - @Request.application def pypies_response(request): timeMap.clear() diff --git a/pythonPackages/pypies/pypies/logging/logConfig.py b/pythonPackages/pypies/pypies/logging/logConfig.py index 1c65f15a18..4d87fa4829 100644 --- a/pythonPackages/pypies/pypies/logging/logConfig.py +++ b/pythonPackages/pypies/pypies/logging/logConfig.py @@ -28,7 +28,7 @@ # Date Ticket# Engineer Description # ------------ ---------- ----------- -------------------------- # 05/13/11 njensen Initial Creation. -# +# 01/17/13 1490 bkowal The logging tcp port is now configurable # # @@ -51,6 +51,7 @@ class LogConfig: self.pypiesLogger = self.__getDefaultLogger() self.minutesLogger = self.pypiesLogger self.hoursLogger = self.pypiesLogger + self.loggingPort = logging.handlers.DEFAULT_TCP_LOGGING_PORT def __configure(self, configurationManager): scp = configurationManager.getConfiguration() @@ -59,7 +60,9 @@ class LogConfig: logFileDir = scp.get('handler_pypiesHandler', 'logFileDir') if not os.path.exists(logFileDir): os.makedirs(logFileDir) - logging.config.fileConfig(configurationManager.getConfigurationLocation()) + logging.config.fileConfig(configurationManager.getConfigurationLocation()) + + self.loggingPort = int(scp.get('tcp_logger', 'logging_port')) def __getDefaultLogger(self): import logging, logging.handlers @@ -81,5 +84,7 @@ class LogConfig: def getHoursLogger(self): return self.hoursLogger - + + def getLoggingPort(self): + return self.loggingPort diff --git a/pythonPackages/pypies/pypies/logging/logProcess.py b/pythonPackages/pypies/pypies/logging/logProcess.py index 42fbf3539b..c0d2ba6904 100644 --- a/pythonPackages/pypies/pypies/logging/logProcess.py +++ b/pythonPackages/pypies/pypies/logging/logProcess.py @@ -30,7 +30,9 @@ # Date Ticket# Engineer Description # ------------ ---------- ----------- -------------------------- # 10/20/10 njensen Initial Creation. -# +# 01/17/13 1490 bkowal Retrieves the logging tcp port +# from configuration instead of +# using the default. # # @@ -116,7 +118,7 @@ class LogRecordSocketReceiver(SocketServer.ThreadingTCPServer): allow_reuse_address = 1 def __init__(self, host='localhost', - port=logging.handlers.DEFAULT_TCP_LOGGING_PORT, + port=logCfg.getLoggingPort(), handler=LogRecordStreamHandler): SocketServer.ThreadingTCPServer.__init__(self, (host, port), handler) self.abort = 0 diff --git a/rpms/awips2.core/Installer.edex-environment/edex/component.spec b/rpms/awips2.core/Installer.edex-environment/edex/component.spec index 97081ccfed..c0b40634ce 100644 --- a/rpms/awips2.core/Installer.edex-environment/edex/component.spec +++ b/rpms/awips2.core/Installer.edex-environment/edex/component.spec @@ -117,6 +117,7 @@ POSTGRES_INITD="${RPM_PROJECT}/awips2.core/Installer.postgresql/scripts/init.d/e QPID_INITD="${RPM_PROJECT}/awips2.qpid/SOURCES/qpidd" QUEUE_SH="${RPM_PROJECT}/awips2.qpid/SOURCES/queueCreator.sh" EDEX_INITD="${RPM_PROJECT}/awips2.edex/Installer.edex-base/scripts/init.d/edex_camel" +HTTPD_PYPIES_INITD="${RPM_PROJECT}/awips2.core/Installer.httpd-pypies/configuration/etc/init.d/httpd-pypies" # Copy the startup scripts. cp ${POSTGRES_INITD} \ @@ -139,6 +140,11 @@ cp ${EDEX_INITD} \ if [ $? -ne 0 ]; then exit 1 fi +cp ${HTTPD_PYPIES_INITD} \ + %{_build_root}%{_installation_directory}/edex-environment/scripts +if [ $? -ne 0 ]; then + exit 1 +fi # Copy the edex-environment macro, functions, and utilities. DELIVERABLES="${RPM_PROJECT}/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables" diff --git a/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/create.sh b/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/create.sh index 0e384570e2..05218c8250 100644 --- a/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/create.sh +++ b/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/create.sh @@ -73,6 +73,18 @@ function createEnvironment() echo "ERROR: Unable to place qpid in the ${env_name} environment." return 1 fi + # /awips2/pypies + cp -r /awips2/pypies ${EDEX_ENV_DIR}/${env_name} + if [ $? -ne 0 ]; then + echo "ERROR: Unable to place pypies in the ${env_name} environment." + return 1 + fi + # /awips2/httpd-pypies + cp -r /awips2/httpd_pypies ${EDEX_ENV_DIR}/${env_name} + if [ $? -ne 0 ]; then + echo "ERROR: Unable to place httpd_pypies in the ${env_name} environment." + return 1 + fi # 3) Update the links in: data/pg_tblspc pushd . > /dev/null 2>&1 @@ -106,7 +118,7 @@ function createEnvironment() exit 1 fi - # 5) Re-configure: Edex, QPID, and PostgreSQL + # 5) Re-configure: Edex, QPID, PostgreSQL, and Pypies /awips2/java/bin/java -jar ${UTILITIES}/Wes2BridgeManager.jar "${config_file}" if [ $? -ne 0 ]; then echo "ERROR: Failed to configure the ${env_name} environment." diff --git a/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/start.sh b/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/start.sh index ab5fd0b76a..85a8e3549a 100644 --- a/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/start.sh +++ b/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/start.sh @@ -46,6 +46,10 @@ function startEnvironmentInternal() echo "ERROR: The ${env_name} environment is corrupt. Recreate it." return 1 fi + if [ ! -f ${EDEX_ENV_DIR}/${env_name}/edex-environment/httpd-pypies ]; then + echo "ERROR: The ${env_name} environment is corrupt. Recreate it." + return 1 + fi if [ ! -f ${EDEX_ENV_DIR}/${env_name}/edex-environment/qpidd ]; then echo "ERROR: The ${env_name} environment is corrupt. Recreate it." return 1 @@ -58,6 +62,10 @@ function startEnvironmentInternal() /bin/bash edex_postgres start echo sleep 10 + # Start httpd-pypies + /bin/bash httpd-pypies start + echo + sleep 10 # Start QPID. /bin/bash qpidd start echo diff --git a/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/stop.sh b/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/stop.sh index e5545500cf..a3a70dfb2d 100644 --- a/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/stop.sh +++ b/rpms/awips2.core/Installer.edex-environment/wes2bridge.files/deliverables/scripts/functions/stop.sh @@ -46,6 +46,10 @@ function stopEnvironmentInternal() echo "ERROR: The ${env_name} environment is corrupt. Recreate it." return 1 fi + if [ ! -f ${EDEX_ENV_DIR}/${env_name}/edex-environment/httpd-pypies ]; then + echo "ERROR: The ${env_name} environment is corrupt. Recreate it." + return 1 + fi if [ ! -f ${EDEX_ENV_DIR}/${env_name}/edex-environment/qpidd ]; then echo "ERROR: The ${env_name} environment is corrupt. Recreate it." return 1 @@ -62,6 +66,10 @@ function stopEnvironmentInternal() /bin/bash qpidd stop echo sleep 10 + # Stop httpd-pypies + /bin/bash httpd-pypies stop + echo + sleep 10 # Stop PostgreSQL. /bin/bash edex_postgres stop echo diff --git a/rpms/awips2.core/Installer.httpd-pypies/component.spec b/rpms/awips2.core/Installer.httpd-pypies/component.spec index 6f972341f7..5f646e979f 100644 --- a/rpms/awips2.core/Installer.httpd-pypies/component.spec +++ b/rpms/awips2.core/Installer.httpd-pypies/component.spec @@ -8,7 +8,7 @@ Summary: Pypies Apache HTTP Server Name: awips2-httpd-pypies Version: 2.2.3 # This Is Officially Release: 22%{?dist} -Release: 29%{?dist} +Release: 30%{?dist} URL: http://httpd.apache.org/ Prefix: /awips2/httpd_pypies Source0: http://www.apache.org/dist/httpd/httpd-%{version}.tar.gz diff --git a/rpms/awips2.core/Installer.httpd-pypies/configuration/etc/init.d/httpd-pypies b/rpms/awips2.core/Installer.httpd-pypies/configuration/etc/init.d/httpd-pypies index dff20cbce4..cdbe6c81ce 100644 --- a/rpms/awips2.core/Installer.httpd-pypies/configuration/etc/init.d/httpd-pypies +++ b/rpms/awips2.core/Installer.httpd-pypies/configuration/etc/init.d/httpd-pypies @@ -29,7 +29,7 @@ INITLOG_ARGS="" # work correctly with a thread-based MPM; notably PHP will refuse to start. # Find the httpd-pypies installation. -HTTPD_PYPIES_INSTALL=`rpm -q --queryformat '%{INSTALLPREFIX}' awips2-httpd-pypies` +HTTPD_PYPIES_INSTALL="/awips2/httpd_pypies" # Path to the apachectl script, server binary, and short-form for messages. apachectl=${HTTPD_PYPIES_INSTALL}/usr/sbin/apachectl @@ -41,6 +41,9 @@ RETVAL=0 PYTHON_INSTALL="/awips2/python" loggingCmd="${PYTHON_INSTALL}/bin/python -u ${PYTHON_INSTALL}/lib/python2.7/site-packages/pypies/logging/logProcess.py" +# pypies configuration location +export PYPIES_CFG=/awips2/pypies/conf/pypies.cfg + # Add to LD_LIBRARY_PATH, if necessary. PYTHON_LIB_DIR="${PYTHON_INSTALL}/lib"