Skip to content

Commit

Permalink
Merge pull request #37 from jmfee-usgs/mt-issues
Browse files Browse the repository at this point in the history
Mt issues
  • Loading branch information
emartinez-usgs committed Apr 20, 2016
2 parents 6763fa7 + 4cf227a commit 0f83b72
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 27 deletions.
10 changes: 10 additions & 0 deletions etc/documentation/userguide/changeLog.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ <h1>Change Log</h1>
<a href="../index.html#documentation">&laquo; Back to User Guide</a>
</p>

<h2>Version 1.10.1 2016-04-07</h2>
<ul>
<li>Add "pdl-client-version" property to products sent using
ProductBuilder (which includes EIDSInputWedge) or CLIProductBuilder</li>
<li>Update moment tensor indexer module to use derived-magnitude-type
property.</li>
<li>Add support for java's "simple" and "xml" log formatters
(as an alternative to the default "pdl" formatter).</li>
</ul>

<h2>Version 1.10.0 2016-02-11</h2>
<ul>
<li>
Expand Down
6 changes: 5 additions & 1 deletion etc/documentation/userguide/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ <h3>Global Properties</h3>
the "logfile" property.</em>
</dd>

<dt>logformat</dt>
<dd>format for logs.
Possible values are "pdl" (default), "simple", and "xml".</dd>

<dt>loglevel</dt>
<dd>How verbose of logging. Default is INFO. Possible values are
SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST.</dd>
Expand Down Expand Up @@ -282,7 +286,7 @@ <h3 id="NotificationListener">NotificationListener</h3>
<dd>(Optional, Default false) Flag to indicate scenario products
should be accepted. Set to &ldquo;true&rdquo; or &ldquo;yes&rdquo; to
enable.</dd>

<dt>includeActuals</dt>
<dd>(Optional, Default true) Flag to indicate actual products
should be accepted. Set to &ldquo;false&rdquo; or &ldquo;no&rdquo; to
Expand Down
38 changes: 32 additions & 6 deletions src/gov/usgs/earthquake/distribution/Bootstrap.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Bootstrap
*
*
* $Id: Bootstrap.java 22520 2014-12-30 19:29:45Z jmfee $
* $URL: https://ghttrac.cr.usgs.gov/websvn/ProductDistribution/trunk/src/gov/usgs/earthquake/distribution/Bootstrap.java $
*/
Expand All @@ -20,19 +20,22 @@
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.logging.ConsoleHandler;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.XMLFormatter;

/**
* Bootstrap is a class used to start an application.
*
*
* It loads a configuration file, sets up initial logging, and starts a
* configurable main method.
*
*
* @author jmfee
*
*
*/
public class Bootstrap {

Expand Down Expand Up @@ -60,6 +63,17 @@ public class Bootstrap {
/** Whether to test config only. */
public static final String CONFIG_TEST_ARGUMENT = "--configTest";

/** Property for log format. */
public static final String LOGFORMAT_PROPERTY_NAME = "logformat";
/** log format value for "pdl" format */
public static final String LOGFORMAT_PDL = "pdl";
/** log format value for java "simple" format */
public static final String LOGFORMAT_SIMPLE = "simple";
/** log format value for java "xml" format */
public static final String LOGFORMAT_XML = "xml";
/** Default log format is "simple". */
public static final String DEFAULT_LOGFORMAT = LOGFORMAT_PDL;

/** Property for log level. */
public static final String LOGLEVEL_PROPERTY_NAME = "loglevel";
/** Default log level is "INFO". */
Expand Down Expand Up @@ -107,7 +121,7 @@ public Bootstrap() {

/**
* Read configuration from inside jar file, and configFile.
*
*
* @param configFile
* config file to load.
* @throws IOException
Expand Down Expand Up @@ -183,7 +197,19 @@ public void setupLogging(final Config config) {
rootLogger.addHandler(handler);
}

SimpleLogFormatter formatter = new SimpleLogFormatter();
Formatter formatter;
String logFormat = config.getProperty(
LOGFORMAT_PROPERTY_NAME, DEFAULT_LOGFORMAT);
if (logFormat.equals(LOGFORMAT_SIMPLE)) {
// built in simple formatter
formatter = new SimpleFormatter();
} else if (logFormat.equals(LOGFORMAT_XML)) {
// built in xml formatter
formatter = new XMLFormatter();
} else {
// pdl style simple formatter
formatter = new SimpleLogFormatter();
}
for (Handler handler : rootLogger.getHandlers()) {
handler.setFormatter(formatter);
}
Expand Down
24 changes: 14 additions & 10 deletions src/gov/usgs/earthquake/distribution/CLIProductBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CLIProductBuilder
*
*
* $Id: CLIProductBuilder.java 20438 2013-11-18 22:49:24Z jmfee $
* $URL: https://ghttrac.cr.usgs.gov/websvn/ProductDistribution/trunk/src/gov/usgs/earthquake/distribution/CLIProductBuilder.java $
*/
Expand Down Expand Up @@ -34,13 +34,13 @@

/**
* Command Line Interface Product Builder.
*
*
* This class is used to build and send products. It is typically called by
* using the --build argument with the standard ProductClient.
*
*
* The CLIProductBuilder implements the Configurable interface and uses the
* following configuration parameters:
*
*
* <dl>
* <dt>senders</dt>
* <dd>(Required). A comma separated list of section names that should be loaded
Expand Down Expand Up @@ -160,10 +160,10 @@ public void setDefaultTrackerURL(URL defaultTrackerURL) {

/**
* Load ProductSenders that will send any built Products.
*
*
* There should be a property "senders" containing a comma delimited list of
* sender names to be loaded.
*
*
* @param config
* the Config to load.
*/
Expand Down Expand Up @@ -220,7 +220,7 @@ public void startup() throws Exception {

/**
* Send a product to all configured ProductSenders.
*
*
* @param product
* the product to send.
* @return exceptions that occured while sending. If map is empty, there
Expand All @@ -244,7 +244,7 @@ public Map<ProductSender, Exception> sendProduct(final Product product) {

/**
* Build a product using command line arguments.
*
*
* @throws Exception
*/
public Product buildProduct() throws Exception {
Expand Down Expand Up @@ -388,6 +388,10 @@ public Product buildProduct() throws Exception {
LOGGER.warning("Product has no content, are you sure this is intended?");
}

// mark which version of client was used to create product
product.getProperties().put(ProductClient.PDL_CLIENT_VERSION_PROPERTY,
ProductClient.RELEASE_VERSION);

if (privateKey != null) {
LOGGER.fine("Signing product");
product.sign(CryptoUtils.readOpenSSHPrivateKey(StreamUtils
Expand Down Expand Up @@ -418,9 +422,9 @@ public static List<ProductSender> parseServers(final String servers,

/**
* Entry point into CLIProductBuilder.
*
*
* Called by Main if the --build argument is present.
*
*
* @param args
* @throws Exception
*/
Expand Down
16 changes: 10 additions & 6 deletions src/gov/usgs/earthquake/distribution/ProductBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

/**
* Essentials for building/sending products.
*
*
* This is the base class for other builders.
*
*
* Supported configurable properties:
* <dl>
* <dt>senders</dt>
Expand Down Expand Up @@ -76,11 +76,11 @@ public ProductBuilder() {

/**
* Send a product.
*
*
* If the product doesn't yet have a tracker URL, assigns current tracker
* URL to product. If the product has not yet been signed, and a privateKey
* is configured, signs the product before sending.
*
*
* @param product
* the product to send.
* @return map of all exceptions thrown, from Sender to corresponding
Expand All @@ -96,6 +96,10 @@ public Map<ProductSender, Exception> sendProduct(final Product product)
product.setTrackerURL(trackerURL);
}

// mark which version of client was used to create product
product.getProperties().put(ProductClient.PDL_CLIENT_VERSION_PROPERTY,
ProductClient.RELEASE_VERSION);

// doesn't already have a signature.
if (privateKey != null && product.getSignature() == null) {
product.sign(privateKey);
Expand Down Expand Up @@ -138,7 +142,7 @@ public List<ProductSender> getProductSenders() {

/**
* Add a ProductSender.
*
*
* @param sender
*/
public void addProductSender(final ProductSender sender) {
Expand All @@ -147,7 +151,7 @@ public void addProductSender(final ProductSender sender) {

/**
* Remove a previously added ProductSender.
*
*
* @param sender
*/
public void removeProductSender(final ProductSender sender) {
Expand Down
5 changes: 4 additions & 1 deletion src/gov/usgs/earthquake/distribution/ProductClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public class ProductClient extends DefaultConfigurable implements
ProductClientMBean, Bootstrappable {

/** The "release" version number. */
public static final String RELEASE_VERSION = "Version 1.10.0 2016-02-11";
public static final String RELEASE_VERSION = "Version 1.10.1 2016-04-07";

/** Property name used on products for current RELEASE_VERSION. */
public static final String PDL_CLIENT_VERSION_PROPERTY = "pdl-client-version";

/** SVN Id property. */
public static final String SVN_VERSION = "$Id: ProductClient.java 23028 2015-04-30 23:28:49Z jmfee $";
Expand Down
10 changes: 7 additions & 3 deletions src/gov/usgs/earthquake/momenttensor/MTIndexerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ protected long getPreferredWeight(ProductSummary summary) {
long weight = super.getPreferredWeight(summary);

// points by type
String tensorType = summary.getProperties().get("beachball-type");
String tensorType = summary.getProperties().get("derived-magnitude-type");
String eventSource = summary.getEventSource();
String derivedMagnitude = summary.getProperties().get("derived-magnitude");
BigDecimal magRange = derivedMagnitude == null ? null : new BigDecimal(derivedMagnitude);

if (tensorType == null) {
tensorType = summary.getProperties().get("beachball-type");
}

if (tensorType != null) {
// Add bonus
if (tensorType.equalsIgnoreCase(TYPE_MWW)) {
Expand All @@ -72,12 +76,12 @@ protected long getPreferredWeight(ProductSummary summary) {
}
}
}

// Add gcmt bonus if required
if (eventSource.equalsIgnoreCase(EVENT_SOURCE_GCMT)) {
weight += EVENT_SOURCE_GCMT_BONUS;
}

return weight;
}
}
}

0 comments on commit 0f83b72

Please sign in to comment.