Issue #2783: Rewrite run_report_alarm script into EDEX service.
Change-Id: I26a5e1c98f1454d57522ede49d3e85f2ebc7d8be Former-commit-id:32719432ff
[formerly32719432ff
[formerly d0ae60f4abaa0bd2c8f966de2e4ed4c5989737fd]] Former-commit-id:de12904c7a
Former-commit-id:1520317c24
This commit is contained in:
parent
ccd90f2d86
commit
474dda75de
21 changed files with 1216 additions and 1599 deletions
|
@ -164,6 +164,18 @@
|
|||
<pattern>%-5p %d [%t] %c{0}: %m%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- ohd log -->
|
||||
<appender name="OhdLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${edex.home}/logs/edex-${edex.run.mode}-ohd-%d{yyyyMMdd}.log</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
|
||||
<encoder>
|
||||
<pattern>%-5p %d [%t] %c{0}: %m%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="ThreadBasedLog" class="com.raytheon.uf.common.status.logback.ThreadBasedAppender">
|
||||
<threadPatterns>RadarLog:radarThreadPool.*;SatelliteLog:satelliteThreadPool.*;ShefLog:shefThreadPool.*;TextLog:textThreadPool.*;SmartInitLog:smartInit.*;PurgeLog:Purge.*;ArchiveLog:Archive.*</threadPatterns>
|
||||
|
@ -300,6 +312,12 @@
|
|||
<level value="ERROR"/>
|
||||
<appender-ref ref="FailedTriggerLog"/>
|
||||
</logger>
|
||||
|
||||
<logger name="com.raytheon.uf.edex.ohd" additivity="false">
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="OhdLog" />
|
||||
<appender-ref ref="console" />
|
||||
</logger>
|
||||
|
||||
<!-- default logging -->
|
||||
<root>
|
||||
|
|
|
@ -6,7 +6,6 @@ Bundle-Version: 1.12.1174.qualifier
|
|||
Eclipse-RegisterBuddy: com.raytheon.edex.common, com.raytheon.uf.common.serialization
|
||||
Bundle-Vendor: RAYTHEON
|
||||
Export-Package: com.raytheon.edex.plugin.shef,
|
||||
com.raytheon.edex.plugin.shef.alarms,
|
||||
com.raytheon.edex.plugin.shef.data,
|
||||
com.raytheon.edex.plugin.shef.data.precip,
|
||||
com.raytheon.edex.plugin.shef.database,
|
||||
|
|
|
@ -1,339 +0,0 @@
|
|||
/**
|
||||
* 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.edex.plugin.shef.alarms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.GnuParser;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.raytheon.edex.textdb.dbapi.impl.TextDB;
|
||||
import com.raytheon.uf.common.dataplugin.text.request.WriteProductRequest;
|
||||
import com.raytheon.uf.common.ohd.AppsDefaults;
|
||||
import com.raytheon.uf.edex.core.EDEXUtil;
|
||||
|
||||
/**
|
||||
* Provides SHEF with the ability to generate alert/alarms report products and
|
||||
* write them to the text database.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* June 15, 2011 9377 jnjanga Initial creation
|
||||
* July 12, 2013 15711 wkwock Fix verbose, observe mode, etc
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jnjanga
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class AlertalarmStdTextProductUtil {
|
||||
|
||||
private static Log log = LogFactory
|
||||
.getLog(AlertalarmStdTextProductUtil.class);
|
||||
|
||||
private static final Options cliOptions = createCmdLineOptions();
|
||||
|
||||
private static ReportWriter reportWriter = null;
|
||||
|
||||
private static ReportOptions reportOptions = null;
|
||||
|
||||
private static File currReport = null;
|
||||
|
||||
private static String reportDir = null;
|
||||
|
||||
/**
|
||||
* this application main entry point
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
loadEnvironment();
|
||||
|
||||
setApplicationSpringContext(Constants.IHFS_CONFIG);
|
||||
|
||||
setReportOptions(args);
|
||||
|
||||
setCurrentReportfile();
|
||||
|
||||
reportAlarm();
|
||||
|
||||
System.exit(reportWriter.getAlarmCount());
|
||||
}
|
||||
|
||||
/*
|
||||
* create the org.apache.commons.cli.Options object
|
||||
*/
|
||||
private static Options createCmdLineOptions() {
|
||||
CmdlineOptions options = new CmdlineOptions();
|
||||
options.addMandatoryOption(CmdlineOptionId.DB_NAME);
|
||||
options.addMandatoryOption(CmdlineOptionId.PRODUCT_ID);
|
||||
options.addOption(CmdlineOptionId.REPORT_MODE);
|
||||
options.addOption(CmdlineOptionId.MINUTES);
|
||||
options.addOption(CmdlineOptionId.FILE_SUFFIX);
|
||||
options.addOption(CmdlineOptionId.FLAGS);
|
||||
options.addOption(CmdlineOptionId.PE);
|
||||
options.addOption(CmdlineOptionId.VERBOSE,false);
|
||||
return options;
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize the ReportOptions object based on command line arguments
|
||||
*/
|
||||
private static void setReportOptions(String[] args) {
|
||||
CommandLine line = null;
|
||||
ReportOptions rptOptions = new ReportOptions();
|
||||
|
||||
// Check CmdLine arguments
|
||||
if (args.length < 3) {
|
||||
System.out.println("Invalid or missing arguments.");
|
||||
printUsage();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// Process CmdLine Arguments
|
||||
GnuParser parser = new GnuParser();
|
||||
try {
|
||||
line = parser.parse(cliOptions, args);
|
||||
} catch (ParseException exp) {
|
||||
System.err.println("Command line Parsing failed. Reason: "
|
||||
+ exp.getMessage());
|
||||
printUsage();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// duplicate options
|
||||
if (hasDuplicateOptions(line)) {
|
||||
System.err.println("Error : Duplicate command line options.");
|
||||
printUsage();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// All user specified options, including mandatory ones
|
||||
// are recognized , and there are no duplicate options.
|
||||
// Query the CmdLine and build the report options object
|
||||
for (CmdlineOptionId optId : CmdlineOptionId.values()) {
|
||||
String optName = optId.toString();
|
||||
System.out.println("optName = " + optName);
|
||||
if (optName.equalsIgnoreCase("v")) {
|
||||
if (line.hasOption(optName)) {
|
||||
System.out.println(" optValue = true");
|
||||
} else {
|
||||
System.out.println(" optValue = false");
|
||||
}
|
||||
} else {
|
||||
System.out.println(" optValue = " + line.getOptionValue(optName));
|
||||
}
|
||||
|
||||
if (line.hasOption(optName)) {
|
||||
|
||||
CmdlineOption option = new CmdlineOption(optId,
|
||||
line.getOptionValue(optName));
|
||||
|
||||
try {
|
||||
rptOptions.addOption(option);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The report options are all valid
|
||||
Set<ReportMode> ignoreMin = new HashSet<ReportMode>();
|
||||
ignoreMin.add(ReportMode.ALL);
|
||||
ignoreMin.add(ReportMode.UNREPORTED);
|
||||
ignoreMin.add(ReportMode.NEAREST);
|
||||
ignoreMin.add(ReportMode.LATEST_MAXFCST);
|
||||
if (rptOptions.isMinutesGiven()
|
||||
&& ignoreMin.contains(rptOptions.getMode()))
|
||||
System.out
|
||||
.println("Usage : -m<minutes> value ignored for this -r<report_mode>");
|
||||
|
||||
reportOptions = rptOptions;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* check whether user has entered duplicate options on the command line
|
||||
*/
|
||||
private static boolean hasDuplicateOptions(CommandLine line) {
|
||||
Option[] userOptions = line.getOptions();
|
||||
Set<String> unique = new HashSet<String>();
|
||||
for (Option option : userOptions)
|
||||
if (!unique.add(option.getOpt()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Display a usage message
|
||||
*/
|
||||
private static void printUsage() {
|
||||
System.out.print("Usage: report_alarm -d<dbase> -p<product_id> ");
|
||||
System.out.print("[-r<report_mode>] [-m<minutes>] [-s<file_suffix>] ");
|
||||
System.out.println("[-f<include_flags>] [-e<PE>] [-v<verbose>]");
|
||||
}
|
||||
|
||||
/*
|
||||
* process alertalarmval data. if there data meets alert/alarm conditions,
|
||||
* report them in a text file and send it to the text database.
|
||||
*/
|
||||
private static void reportAlarm() {
|
||||
Date now = new Date(System.currentTimeMillis());
|
||||
|
||||
// Get the whole data for the report
|
||||
AlertalarmRecord aaRecord = RecordMgr.getAlarmData(reportOptions);
|
||||
|
||||
// write the report
|
||||
reportWriter = new ReportWriter(currReport, reportOptions, now);
|
||||
reportWriter.writeHeader();
|
||||
reportWriter.writeBody(aaRecord);
|
||||
if (reportOptions.getVerbose()) {
|
||||
reportWriter.writeVerboseTrailer();
|
||||
} else {
|
||||
reportWriter.writeReportTrailer();
|
||||
}
|
||||
|
||||
// save it to the text database if indeed
|
||||
// there are alarm events to report.
|
||||
int alarmCount = reportWriter.getAlarmCount();
|
||||
if (alarmCount > 0) {
|
||||
log.info(alarmCount + " alarms reported, report written to "
|
||||
+ reportWriter.getFilename());
|
||||
//saveReportTotextDb();
|
||||
} else {
|
||||
log.info("No alarms reported, info sent to "
|
||||
+ reportWriter.getFilename());
|
||||
log.info("File NOT sent to text database.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* saves the report contents to the text database.
|
||||
*/
|
||||
private static void saveReportTotextDb() {
|
||||
|
||||
setApplicationSpringContext(Constants.FXA_CONFIG);
|
||||
|
||||
WriteProductRequest request = new WriteProductRequest();
|
||||
request.setProductId(reportOptions.getProductId());
|
||||
request.setOperationalMode(true);
|
||||
request.setNotifyAlarmAlert(true);
|
||||
String rptData = reportWriter.getReportData();
|
||||
request.setReportData(rptData);
|
||||
|
||||
log.info("Sending " + reportWriter.getFilename() + " to textdb as id "
|
||||
+ request.getProductId());
|
||||
|
||||
TextDB textdb = new TextDB();
|
||||
long result = textdb.writeProduct(request.getProductId(),
|
||||
request.getReportData(), request.getOperationalMode(), null);
|
||||
|
||||
if (result != Long.MIN_VALUE) {
|
||||
log.info("Product " + request.getProductId()
|
||||
+ " successfully sent to textdb");
|
||||
} else {
|
||||
log.error("Error sending product " + request.getProductId()
|
||||
+ " to textdb. status=" + result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* verify whether necessary application tokens have been defined.
|
||||
*/
|
||||
private static void loadEnvironment() {
|
||||
|
||||
System.setProperty("edex.home", System.getenv("EDEX_HOME"));
|
||||
System.setProperty("db.addr", System.getenv("PGHOST"));
|
||||
System.setProperty("ih.db.name", System.getenv("DB_NAME"));
|
||||
System.setProperty("fxa.db.name", System.getenv("FXA_DB_NAME"));
|
||||
System.setProperty("db.port", System.getenv("PGPORT"));
|
||||
|
||||
AppsDefaults appDefaults = AppsDefaults.getInstance();
|
||||
|
||||
String aalogDir = appDefaults.getToken(Constants.WHFS_UTIL_LOG_DIR);
|
||||
|
||||
if (aalogDir == null) {
|
||||
System.out
|
||||
.println("whfs_util_log_dir directory undefined. Aborting.");
|
||||
}
|
||||
|
||||
reportDir = appDefaults.getToken(Constants.WHFS_PRODUCT_DIR);
|
||||
|
||||
if (reportDir == null) {
|
||||
System.out
|
||||
.println("whfs_product_dir directory undefined . Aborting.");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* initializes a File object that points to the current alert/alarm report
|
||||
*/
|
||||
private static void setCurrentReportfile() {
|
||||
String pid = reportOptions.getProductId();
|
||||
String suffix = reportOptions.getFileSuffix();
|
||||
|
||||
if (suffix.length() > 0)
|
||||
currReport = new File(reportDir + File.separator + pid + "." + suffix);
|
||||
else
|
||||
currReport = new File(reportDir + File.separator + pid);
|
||||
|
||||
try {
|
||||
currReport.createNewFile();
|
||||
} catch (Exception e) {
|
||||
log.fatal("Could not create report file "
|
||||
+ String.valueOf(currReport));
|
||||
log.info("Exiting.");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setApplicationSpringContext(String... configLocations) {
|
||||
if (configLocations.length > 0) {
|
||||
ClassPathXmlApplicationContext ctxt = new ClassPathXmlApplicationContext(
|
||||
configLocations);
|
||||
EDEXUtil edexUtil = new EDEXUtil();
|
||||
edexUtil.setApplicationContext(ctxt);
|
||||
} else {
|
||||
log.fatal("Application spring config location not specified");
|
||||
log.info("Exiting.");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/** 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.edex.plugin.shef.alarms;
|
||||
|
||||
/**
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* June 15, 2011 9377 jnjanga Initial creation
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jnjanga
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class CmdlineOption {
|
||||
|
||||
private CmdlineOptionId Id;
|
||||
|
||||
private String argument;
|
||||
|
||||
public CmdlineOption(CmdlineOptionId Id, String argument) {
|
||||
this.Id = Id;
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
public CmdlineOptionId getId() {
|
||||
return Id;
|
||||
}
|
||||
|
||||
public String getArg() {
|
||||
return argument;
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
/**
|
||||
* 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.edex.plugin.shef.alarms;
|
||||
|
||||
/**
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* June 15, 2011 9377 jnjanga Initial creation
|
||||
* July 12, 2013 15711 wkwock Fix verbose, observe mode, etc
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jnjanga
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public enum CmdlineOptionId {
|
||||
|
||||
DB_NAME("Database Name") {
|
||||
|
||||
public String toString() {
|
||||
return "d";
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
PRODUCT_ID("Product Id") {
|
||||
|
||||
public String toString() {
|
||||
return "p";
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
REPORT_MODE("Report mode") {
|
||||
public String toString() {
|
||||
return "r";
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
MINUTES("minutes") {
|
||||
|
||||
public String toString() {
|
||||
return "m";
|
||||
}
|
||||
},
|
||||
|
||||
FILE_SUFFIX("File Suffix") {
|
||||
public String toString() {
|
||||
return "s";
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
FLAGS("Include Flags") {
|
||||
public String toString() {
|
||||
return "f";
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
PE("Physical Element") {
|
||||
public String toString() {
|
||||
return "e";
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
VERBOSE("Verbose") {
|
||||
public String toString() {
|
||||
return "v";
|
||||
}
|
||||
};
|
||||
|
||||
CmdlineOptionId(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String description() {
|
||||
return this.desc;
|
||||
}
|
||||
|
||||
private String desc;
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/**
|
||||
* 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.edex.plugin.shef.alarms;
|
||||
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
|
||||
/**
|
||||
* Convenience wrapper around org.apache.commons.cli.Options
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* June 15, 2011 9377 jnjanga Initial creation
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jnjanga
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class CmdlineOptions extends Options {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
CmdlineOptions() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void addOption(CmdlineOptionId optId) {
|
||||
Option opt = new Option(optId.toString(), true, optId.description());
|
||||
addOption(opt);
|
||||
}
|
||||
|
||||
public void addOption(CmdlineOptionId optId, boolean hasArg) {
|
||||
Option opt = new Option(optId.toString(), hasArg, optId.description());
|
||||
addOption(opt);
|
||||
}
|
||||
|
||||
public void addMandatoryOption(CmdlineOptionId optId) {
|
||||
Option opt = new Option(optId.toString(), true, optId.description());
|
||||
opt.setRequired(true);
|
||||
addOption(opt);
|
||||
}
|
||||
|
||||
public boolean hasOption(CmdlineOptionId optId) {
|
||||
return hasOption(optId.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,245 +0,0 @@
|
|||
/**
|
||||
* 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.edex.plugin.shef.alarms;
|
||||
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ALARM_CATEGSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ALERT_CATEGSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.DIFF_CHECKSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.LOWER_CHECKSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ROC_CHECKSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.UPPER_CHECKSTR;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.raytheon.uf.edex.database.dao.CoreDao;
|
||||
import com.raytheon.uf.edex.database.dao.DaoConfig;
|
||||
|
||||
/**
|
||||
* Reads Alertalarmval table and creates an organized record.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* June 15, 2011 9377 jnjanga Initial creation
|
||||
* Sep 05, 2013 16549 wkwock Fix the query
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jnjanga
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
class RecordMgr {
|
||||
|
||||
static final int MODE = 101;
|
||||
|
||||
static final int TYPE_SRC = 102;
|
||||
|
||||
static final int AA_CAT = 103;
|
||||
|
||||
static final int AA_CHCK = 104;
|
||||
|
||||
static final int PEFILTER = 105;
|
||||
|
||||
private static Log log = LogFactory
|
||||
.getLog(RecordMgr.class);
|
||||
|
||||
private static ReportOptions options = null;
|
||||
|
||||
public static AlertalarmRecord getAlarmData(ReportOptions opt) {
|
||||
options = opt;
|
||||
StringBuilder query = new StringBuilder(
|
||||
"select aav.lid, "
|
||||
+ "aav.pe, aav.dur, "
|
||||
+ "aav.ts, aav.extremum, "
|
||||
+ "aav.probability, aav.validtime, aav.basistime, "
|
||||
+ "aav.aa_categ, aav.aa_check, "
|
||||
+ "aav.value, aav.suppl_value, "
|
||||
+ "aav.shef_qual_code, aav.quality_code, aav.revision, "
|
||||
+ "aav.product_id, aav.producttime, aav.postingtime, aav.action_time, "
|
||||
+ "location.name from location, alertalarmval aav where location.lid = aav.lid");
|
||||
|
||||
// Build 'where' clause according to report mode
|
||||
// if getting only unreported data, let the query filter out the
|
||||
// reported data
|
||||
query.append(whereSubClauseFor(MODE))
|
||||
.append(whereSubClauseFor(TYPE_SRC))
|
||||
.append(whereSubClauseFor(AA_CAT))
|
||||
.append(whereSubClauseFor(AA_CHCK))
|
||||
.append(whereSubClauseFor(PEFILTER))
|
||||
.append(" AND (aav.ts NOT LIKE 'F%' OR aav.validtime >= current_timestamp) ")
|
||||
.append(" ORDER BY aav.lid ASC, aav.pe, aav.ts, aav.aa_check, aav.validtime DESC ");
|
||||
|
||||
log.info("Query for getting alertalarmval data :" + query.toString());
|
||||
|
||||
Object[] aaData = null;
|
||||
CoreDao dao = null;
|
||||
AlertalarmRecord aaRecord = null;
|
||||
|
||||
// Get the data
|
||||
try {
|
||||
dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname()));
|
||||
aaData = dao.executeSQLQuery(query.toString());
|
||||
if (aaData != null && aaData.length > 0) {
|
||||
aaRecord = AlertalarmRecord.newInstance();
|
||||
for (int i = 0; i < aaData.length; i++) {
|
||||
Object[] aaRow = (Object[]) aaData[i];
|
||||
aaRecord.put(aaRow);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Query = [" + query + "]");
|
||||
log.error(" - PostgresSQL error retrieving from alertalarmval ", e);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
return aaRecord;
|
||||
}
|
||||
|
||||
private static String whereSubClauseFor(int userSelection) {
|
||||
switch (userSelection) {
|
||||
case MODE:
|
||||
return modeSubClause();
|
||||
case TYPE_SRC:
|
||||
return typeSrcSubClause();
|
||||
case AA_CAT:
|
||||
return aaCatSubClause();
|
||||
case AA_CHCK:
|
||||
return aaCheckSubClause();
|
||||
case PEFILTER:
|
||||
return peFilterSubClause();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the query to any PE Filter
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String peFilterSubClause() {
|
||||
String pe = options.getPEfilter();
|
||||
return pe == null ? "" : " AND pe = " + pe;
|
||||
}
|
||||
|
||||
private static String modeSubClause() {
|
||||
if (options.getMode() == ReportMode.UNREPORTED)
|
||||
return " AND action_time IS NULL ";
|
||||
else
|
||||
return " ";
|
||||
}
|
||||
|
||||
private static String typeSrcSubClause() {
|
||||
String flags = options.getFilter();
|
||||
if(flags==null)
|
||||
return " AND aav.ts like '%'";
|
||||
|
||||
if (flags.contains("O") && !flags.contains("F"))
|
||||
return " AND (aav.ts like 'R%' or aav.ts like 'P%')";
|
||||
else if (!flags.contains("O") && flags.contains("F"))
|
||||
return " AND (aav.ts like 'F%' or aav.ts like 'C%')";
|
||||
else
|
||||
return " AND aav.ts like '%'";
|
||||
}
|
||||
|
||||
/**
|
||||
* append the where clause based on the alert/alarm category field
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String aaCatSubClause() {
|
||||
String flags = options.getFilter();
|
||||
if(flags == null)
|
||||
return " ";
|
||||
|
||||
if (flags.contains("T") && !flags.contains("M"))
|
||||
return " AND aav.aa_categ = " + ALERT_CATEGSTR;
|
||||
else if (!flags.contains("T") && flags.contains("M"))
|
||||
return " AND aav.aa_categ = " + ALARM_CATEGSTR;
|
||||
else
|
||||
return " ";
|
||||
}
|
||||
|
||||
/**
|
||||
* append the where clause based on the alert/alarm check field
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String aaCheckSubClause() {
|
||||
String subClause = " AND aa_check in (";
|
||||
String flags = options.getFilter();
|
||||
if(flags == null)
|
||||
return " ";
|
||||
|
||||
boolean rocFlag = flags.contains("R");
|
||||
boolean lowFlag = flags.contains("L");
|
||||
boolean upFlag = flags.contains("U");
|
||||
boolean diffFlag = flags.contains("D");
|
||||
|
||||
if (!rocFlag && !lowFlag && !upFlag && !diffFlag)
|
||||
return " ";
|
||||
else {
|
||||
boolean init = true;
|
||||
|
||||
char[] checks = { 'R', 'L', 'U', 'D' };
|
||||
for (char c : checks) {
|
||||
switch (c) {
|
||||
case 'U':
|
||||
if (upFlag)
|
||||
subClause
|
||||
.concat(aaCheckSubClause(init, UPPER_CHECKSTR));
|
||||
break;
|
||||
case 'L':
|
||||
if (lowFlag)
|
||||
subClause
|
||||
.concat(aaCheckSubClause(init, LOWER_CHECKSTR));
|
||||
break;
|
||||
case 'R':
|
||||
if (rocFlag)
|
||||
subClause.concat(aaCheckSubClause(init, ROC_CHECKSTR));
|
||||
break;
|
||||
case 'D':
|
||||
if (diffFlag)
|
||||
subClause.concat(aaCheckSubClause(init, DIFF_CHECKSTR));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return subClause.concat(" ) ");
|
||||
}
|
||||
|
||||
private static String aaCheckSubClause(boolean initialEntry, String checkStr) {
|
||||
if (initialEntry) {
|
||||
initialEntry = !initialEntry;
|
||||
return checkStr;
|
||||
} else
|
||||
return "," + checkStr;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,267 +0,0 @@
|
|||
/**
|
||||
* 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.edex.plugin.shef.alarms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.shef.util.ShefConstants;
|
||||
|
||||
/**
|
||||
* Place holder for user defined report options
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* June 15, 2011 9377 jnjanga Initial creation
|
||||
* July 12, 2013 15711 wkwock Fix verbose, observe mode, etc
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jnjanga
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
class ReportOptions {
|
||||
|
||||
private String dbname=null;
|
||||
|
||||
private String productId=null;
|
||||
|
||||
private ReportMode mode=null;
|
||||
|
||||
private String filter=null;
|
||||
|
||||
private String PEfilter=null;
|
||||
|
||||
private String fileSuffix=null;
|
||||
|
||||
private float min_val_diff=0;
|
||||
|
||||
private int minutes=0;
|
||||
|
||||
private boolean minGiven=false;
|
||||
|
||||
private boolean verboseFlag=false;
|
||||
|
||||
ReportOptions() {
|
||||
}
|
||||
|
||||
public String getDbname() {
|
||||
return dbname;
|
||||
}
|
||||
|
||||
public String getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(String productId) {
|
||||
int pidlength = productId.length();
|
||||
if (pidlength != 9 && pidlength != 10) {
|
||||
final String msg = "Invalid length for Product_Id : " + pidlength;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
|
||||
public void setDbname(String dbname) {
|
||||
if(!dbname.equals( System.getProperty("ih.db.name"))) {
|
||||
final String msg = "Invalid database name : " + dbname;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
this.dbname = ShefConstants.IHFS;
|
||||
}
|
||||
|
||||
public int getMinutes() {
|
||||
return minutes;
|
||||
}
|
||||
|
||||
public void setMinutes(String minutes) throws IllegalArgumentException {
|
||||
boolean invalid = false;
|
||||
int argl = minutes.length();
|
||||
int tmp = Integer.valueOf(minutes);
|
||||
if (argl == 0 || argl > 6) {
|
||||
invalid = true;
|
||||
} else {
|
||||
invalid = isWithinWindow(tmp);
|
||||
}
|
||||
|
||||
if (invalid) {
|
||||
final String msg = getWindowOptionUsage(tmp);
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
|
||||
this.minutes = tmp;
|
||||
minGiven = true;
|
||||
}
|
||||
|
||||
public boolean isMinutesGiven() {
|
||||
return minGiven;
|
||||
}
|
||||
|
||||
public ReportMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(String mode) throws IllegalArgumentException {
|
||||
try {
|
||||
this.mode = ReportMode.valueOf(mode);
|
||||
} catch (Exception e) {
|
||||
final String msg = "Invalid report mode : " + mode + Constants.EOL
|
||||
+ "Report mode must be either : "
|
||||
+ printValid(ReportMode.values());
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void setFilter(String filter) throws IllegalArgumentException {
|
||||
boolean invalid = false;
|
||||
int fltrlen = filter.length();
|
||||
if (fltrlen == 0 || fltrlen > 8)
|
||||
invalid = true;
|
||||
else
|
||||
invalid = !tokensValid(filter);
|
||||
|
||||
if (invalid) {
|
||||
final String msg = printFilterOptionUsage(filter);
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public String getPEfilter() {
|
||||
return PEfilter;
|
||||
}
|
||||
|
||||
public void setPEfilter(String pEfilter) throws IllegalArgumentException {
|
||||
if (pEfilter.length() != 2) {
|
||||
final String msg = "PE filter option must be two characters";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
PEfilter = pEfilter;
|
||||
}
|
||||
|
||||
public String getFileSuffix() {
|
||||
return fileSuffix;
|
||||
}
|
||||
|
||||
public void setFileSuffix(String fileSuffix) {
|
||||
this.fileSuffix = fileSuffix;
|
||||
}
|
||||
|
||||
public float getMin_val_diff() {
|
||||
return min_val_diff;
|
||||
}
|
||||
|
||||
public void setMin_val_diff(float min_val_diff) {
|
||||
this.min_val_diff = min_val_diff;
|
||||
}
|
||||
|
||||
public boolean getVerbose () {
|
||||
return verboseFlag ;
|
||||
}
|
||||
|
||||
public void setVerbose (boolean verboseFlg) {
|
||||
verboseFlag = verboseFlg;
|
||||
}
|
||||
|
||||
public void addOption(CmdlineOption option) throws IllegalArgumentException {
|
||||
String arg = (String) option.getArg();
|
||||
switch (option.getId()) {
|
||||
case DB_NAME:
|
||||
setDbname(arg);
|
||||
break;
|
||||
case PRODUCT_ID:
|
||||
setProductId(arg);
|
||||
break;
|
||||
case REPORT_MODE:
|
||||
setMode(arg);
|
||||
break;
|
||||
case FLAGS:
|
||||
setFilter(arg);
|
||||
break;
|
||||
case PE:
|
||||
setPEfilter(arg);
|
||||
break;
|
||||
case MINUTES:
|
||||
setMinutes(arg);
|
||||
break;
|
||||
case FILE_SUFFIX:
|
||||
setFileSuffix(arg);
|
||||
break;
|
||||
case VERBOSE:
|
||||
setVerbose(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
str.append("Product_Id = " + productId + Constants.EOL);
|
||||
str.append("Report_Mode = " + mode.toString() + Constants.EOL);
|
||||
str.append("Filter = " + filter + Constants.EOL);
|
||||
str.append("PE Filter = " + PEfilter + Constants.EOL);
|
||||
str.append("File suffix = " + fileSuffix + Constants.EOL);
|
||||
str.append("minutes = " + minutes + Constants.EOL);
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
private static <E> String printValid(E[] array) {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (E element : array)
|
||||
str.append(element.toString() + ", ");
|
||||
str.delete(str.length() - 2, str.length());
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
private boolean isWithinWindow(int min) {
|
||||
return (min <= 0 || min > 999999);
|
||||
}
|
||||
|
||||
private String getWindowOptionUsage(int min) {
|
||||
return "Invalid number of minutes : " + min
|
||||
+ " . Must be between 1 - 999999 ";
|
||||
}
|
||||
|
||||
private String printFilterOptionUsage(String filter) {
|
||||
return "Invalid length or token for filter option : " + filter + Constants.EOL
|
||||
+ "Filter option must be either : "
|
||||
+ printValid(FilterOption.values());
|
||||
}
|
||||
|
||||
private boolean tokensValid(String filter) {
|
||||
ArrayList<Character> validArgs = FilterOption.asList();
|
||||
for (char c : filter.toCharArray())
|
||||
if (!validArgs.contains(c))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -125,6 +125,7 @@
|
|||
#
|
||||
#10/01/09 - Added 5 tokens for arcnav application. //only for arcnav for raxum application
|
||||
#10/03/12 - Added token section for script execution
|
||||
#02/18/14 - Added section for run_report_alarm service configuration.
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
|
@ -179,6 +180,42 @@ MpeRUCFreezingLevel : ON
|
|||
MpeLightningSrv : ON
|
||||
#====================================================================================
|
||||
|
||||
#===================== run_report_alarm Configuration ===============================
|
||||
# These settings modify behavior of the EDEX RunReportAlarmSrv service, which
|
||||
# replaced the original run_report_alarm script ported from A1 hydro.
|
||||
#
|
||||
## Mandatory Arguments:
|
||||
## alarm_product_id : The product id that will be used to write the alarm
|
||||
## report product into the textdb.
|
||||
##
|
||||
## Optional Arguments:
|
||||
## alarm_file_suffix : A Java date/time format string that will be used as
|
||||
## the alarm report's file extension when the product is
|
||||
## written to disk. Product file path is
|
||||
## ${whfs_product_dir}/PRODUCT_ID.FILE_SUFFIX.
|
||||
##
|
||||
## alarm_report_mode : Report mode. Valid values are one of the following:
|
||||
## ALL, FRESH, RECENT, UNREPORTED, NEAREST, NEAR_NOW,
|
||||
## LATEST_MAXFCST, or NEW_OR_INCREASED.
|
||||
##
|
||||
## alarm_filter : Additional filtering options for the product.
|
||||
## Valid values can one or many of the following:
|
||||
## 'O', 'F', 'T', 'M', 'R', 'L', 'U', 'D'.
|
||||
##
|
||||
## alarm_pe_filter : Physical element filter.
|
||||
##
|
||||
## alarm_minutes : For certain report modes, creates a window going back
|
||||
## or forward the specified number of minutes.
|
||||
## Valid values are 1 - 999999.
|
||||
##
|
||||
## alarm_verbose : Whether or not to create a "verbose mode" report.
|
||||
## Valid values are TRUE or FALSE.
|
||||
##
|
||||
|
||||
alarm_product_id : CCCACRXXX
|
||||
alarm_file_suffix : MMdd.HHmm
|
||||
alarm_report_mode : NEAREST
|
||||
|
||||
# ==============================================================================
|
||||
|
||||
# Executable directory tokens.
|
||||
|
|
|
@ -8,7 +8,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
|||
Import-Package: com.raytheon.edex.util,
|
||||
com.raytheon.uf.common.dataplugin.binlightning,
|
||||
com.raytheon.uf.common.dataplugin.grid,
|
||||
com.raytheon.uf.common.dataplugin.shef.util,
|
||||
com.raytheon.uf.common.localization,
|
||||
com.raytheon.uf.common.ohd,
|
||||
com.raytheon.uf.common.serialization.comm,
|
||||
|
@ -21,6 +20,7 @@ Import-Package: com.raytheon.edex.util,
|
|||
org.apache.commons.logging,
|
||||
org.quartz
|
||||
Export-Package: com.raytheon.uf.edex.ohd,
|
||||
com.raytheon.uf.edex.ohd.reportalarm,
|
||||
com.raytheon.uf.edex.ohd.whfs
|
||||
Require-Bundle: com.raytheon.edex.common,
|
||||
com.raytheon.uf.common.mpe;bundle-version="1.11.15",
|
||||
|
@ -29,4 +29,8 @@ Require-Bundle: com.raytheon.edex.common,
|
|||
com.raytheon.uf.common.status;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.monitor,
|
||||
com.raytheon.uf.common.parameter;bundle-version="1.0.0",
|
||||
com.raytheon.uf.common.units;bundle-version="1.0.0"
|
||||
com.raytheon.uf.common.units;bundle-version="1.0.0",
|
||||
com.raytheon.uf.common.dataplugin.shef,
|
||||
com.raytheon.uf.common.dataplugin.text,
|
||||
com.raytheon.edex.textdb,
|
||||
com.raytheon.uf.edex.decodertools
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
<value>run_alarm_whfs</value>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="runReportAlarmSrv" class="com.raytheon.uf.edex.ohd.reportalarm.RunReportAlarmSrv" />
|
||||
|
||||
<camelContext id="alarmWhfs-context"
|
||||
xmlns="http://camel.apache.org/schema/spring"
|
||||
|
@ -23,13 +25,23 @@
|
|||
|
||||
<route id="alarmWhfsScheduledWork">
|
||||
<from uri="jms-generic:queue:alarmWhfsScheduledWork" />
|
||||
<doTry>
|
||||
<bean ref="alarmSrv" method="execute" />
|
||||
<doCatch>
|
||||
<exception>java.lang.Throwable</exception>
|
||||
<to uri="log:alarmWhfs?level=ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
<multicast parallelProcessing="false">
|
||||
<doTry>
|
||||
<bean ref="alarmSrv" method="execute" />
|
||||
<doCatch>
|
||||
<exception>java.lang.Throwable</exception>
|
||||
<to uri="log:alarmWhfs?level=ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
<doTry>
|
||||
<bean ref="runReportAlarmSrv" method="executeRunReportAlarm" />
|
||||
<doCatch>
|
||||
<exception>java.lang.Throwable</exception>
|
||||
<to uri="log:alarmWhfs?level=ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
</multicast>
|
||||
</route>
|
||||
|
||||
</camelContext>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.edex.plugin.shef.alarms;
|
||||
package com.raytheon.uf.edex.ohd.reportalarm;
|
||||
|
||||
|
||||
import java.text.DateFormat;
|
|
@ -17,36 +17,52 @@
|
|||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.edex.plugin.shef.alarms;
|
||||
package com.raytheon.uf.edex.ohd.reportalarm;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.shef.util.ShefConstants;
|
||||
|
||||
|
||||
/**
|
||||
* Constants needed by the run_report_alarm process.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 13, 2014 #2378 dgilling Removed unused constants.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author xxxxxxxx
|
||||
* @version 1.0
|
||||
*/
|
||||
class Constants {
|
||||
|
||||
|
||||
public static final SimpleDateFormat REPORT_TIME_PATTERN = new SimpleDateFormat(
|
||||
"HH:mm:ss z, yyyy.MM.dd ");
|
||||
"HH:mm:ss z, yyyy.MM.dd ");
|
||||
|
||||
public static final int MISSING_VALUE_INT = ShefConstants.SHEF_MISSING_INT;
|
||||
|
||||
|
||||
public static final double MISSING_VALUE_DOUBLE = -9999999.87654321;
|
||||
|
||||
public static final String NEWLINE = System.getProperty("line.separator");
|
||||
|
||||
|
||||
public final static String EOL = NEWLINE;
|
||||
|
||||
public static final String SPACE = " ";
|
||||
|
||||
public static final String REPORT_ALARM_LOG = "report_alarm.log";
|
||||
|
||||
|
||||
public static final String WHFS_PRODUCT_DIR = "whfs_product_dir";
|
||||
|
||||
public static final String WHFS_UTIL_LOG_DIR = "whfs_util_log_dir";
|
||||
|
||||
public static final String IHFS_CONFIG = "/res/spring/ohd-common.xml";
|
||||
|
||||
public static final String FXA_CONFIG = "/res/spring/alertalarm.xml";
|
||||
|
||||
|
||||
/**
|
||||
* A private constructor so that Java does not attempt to create one for us.
|
||||
* As this class should not be instantiated, do not attempt to ever call
|
||||
* this constructor; it will simply throw an AssertionError.
|
||||
*
|
||||
*/
|
||||
private Constants() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
|
@ -17,9 +17,10 @@
|
|||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.edex.plugin.shef.alarms;
|
||||
package com.raytheon.uf.edex.ohd.reportalarm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -28,7 +29,8 @@ import java.util.ArrayList;
|
|||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* June 15, 2011 9377 jnjanga Initial creation
|
||||
* Jun 15, 2011 9377 jnjanga Initial creation
|
||||
* Feb 13, 2014 #2783 dgilling Added fromArg() method.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
|
@ -48,6 +50,7 @@ public enum FilterOption {
|
|||
this.arg = arg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Character.toString(arg);
|
||||
}
|
||||
|
@ -56,10 +59,22 @@ public enum FilterOption {
|
|||
return arg;
|
||||
}
|
||||
|
||||
public static ArrayList<Character> asList() {
|
||||
ArrayList<Character> vals = new ArrayList<Character>();
|
||||
for (FilterOption opt : values())
|
||||
public static List<Character> asList() {
|
||||
List<Character> vals = new ArrayList<Character>();
|
||||
for (FilterOption opt : values()) {
|
||||
vals.add(opt.getArg());
|
||||
}
|
||||
return vals;
|
||||
}
|
||||
|
||||
public static FilterOption fromArg(char arg) {
|
||||
for (FilterOption filter : values()) {
|
||||
if (arg == filter.arg) {
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(arg
|
||||
+ " is not a valid FilterOption.");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,244 @@
|
|||
/**
|
||||
* 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.uf.edex.ohd.reportalarm;
|
||||
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ALARM_CATEGSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ALERT_CATEGSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.DIFF_CHECKSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.LOWER_CHECKSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.ROC_CHECKSTR;
|
||||
import static com.raytheon.uf.common.dataplugin.shef.util.ShefConstants.UPPER_CHECKSTR;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.edex.database.dao.CoreDao;
|
||||
import com.raytheon.uf.edex.database.dao.DaoConfig;
|
||||
|
||||
/**
|
||||
* Reads Alertalarmval table and creates an organized record.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 15, 2011 9377 jnjanga Initial creation
|
||||
* Sep 05, 2013 16549 wkwock Fix the query
|
||||
* Feb 13, 2014 #2783 dgilling Refactored to support running as part
|
||||
* of an EDEX service.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jnjanga
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
class RecordMgr {
|
||||
|
||||
static final int MODE = 101;
|
||||
|
||||
static final int TYPE_SRC = 102;
|
||||
|
||||
static final int AA_CAT = 103;
|
||||
|
||||
static final int AA_CHCK = 104;
|
||||
|
||||
static final int PEFILTER = 105;
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(RecordMgr.class);
|
||||
|
||||
/**
|
||||
* A private constructor so that Java does not attempt to create one for us.
|
||||
* As this class should not be instantiated, do not attempt to ever call
|
||||
* this constructor; it will simply throw an AssertionError.
|
||||
*
|
||||
*/
|
||||
private RecordMgr() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static AlertalarmRecord getAlarmData(ReportOptions opt) {
|
||||
StringBuilder query = new StringBuilder("select aav.lid, ")
|
||||
.append("aav.pe, aav.dur, ")
|
||||
.append("aav.ts, aav.extremum, ")
|
||||
.append("aav.probability, aav.validtime, aav.basistime, ")
|
||||
.append("aav.aa_categ, aav.aa_check, ")
|
||||
.append("aav.value, aav.suppl_value, ")
|
||||
.append("aav.shef_qual_code, aav.quality_code, aav.revision, ")
|
||||
.append("aav.product_id, aav.producttime, aav.postingtime, aav.action_time, ")
|
||||
.append("location.name from location, alertalarmval aav where location.lid = aav.lid");
|
||||
|
||||
// Build 'where' clause according to report mode
|
||||
// if getting only unreported data, let the query filter out the
|
||||
// reported data
|
||||
query.append(whereSubClauseFor(MODE, opt))
|
||||
.append(whereSubClauseFor(TYPE_SRC, opt))
|
||||
.append(whereSubClauseFor(AA_CAT, opt))
|
||||
.append(whereSubClauseFor(AA_CHCK, opt))
|
||||
.append(whereSubClauseFor(PEFILTER, opt))
|
||||
.append(" AND (aav.ts NOT LIKE 'F%' OR aav.validtime >= current_timestamp) ")
|
||||
.append(" ORDER BY aav.lid ASC, aav.pe, aav.ts, aav.aa_check, aav.validtime DESC ");
|
||||
|
||||
statusHandler.info("Query for getting alertalarmval data :"
|
||||
+ query.toString());
|
||||
|
||||
// Get the data
|
||||
AlertalarmRecord aaRecord = null;
|
||||
CoreDao dao = new CoreDao(DaoConfig.forDatabase(opt.getDbname()));
|
||||
Object[] aaData = dao.executeSQLQuery(query.toString());
|
||||
if (aaData != null && aaData.length > 0) {
|
||||
aaRecord = AlertalarmRecord.newInstance();
|
||||
for (int i = 0; i < aaData.length; i++) {
|
||||
Object[] aaRow = (Object[]) aaData[i];
|
||||
aaRecord.put(aaRow);
|
||||
}
|
||||
}
|
||||
|
||||
return aaRecord;
|
||||
}
|
||||
|
||||
private static String whereSubClauseFor(int userSelection,
|
||||
ReportOptions options) {
|
||||
switch (userSelection) {
|
||||
case MODE:
|
||||
return modeSubClause(options.getMode());
|
||||
case TYPE_SRC:
|
||||
return typeSrcSubClause(options.getFilter());
|
||||
case AA_CAT:
|
||||
return aaCatSubClause(options.getFilter());
|
||||
case AA_CHCK:
|
||||
return aaCheckSubClause(options.getFilter());
|
||||
case PEFILTER:
|
||||
return peFilterSubClause(options.getPEfilter());
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the query to any PE Filter
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String peFilterSubClause(String pe) {
|
||||
return pe == null ? "" : " AND pe = " + pe;
|
||||
}
|
||||
|
||||
private static String modeSubClause(ReportMode mode) {
|
||||
if (mode == ReportMode.UNREPORTED) {
|
||||
return " AND action_time IS NULL ";
|
||||
} else {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
private static String typeSrcSubClause(EnumSet<FilterOption> flags) {
|
||||
if (flags == null) {
|
||||
return " AND aav.ts like '%'";
|
||||
}
|
||||
|
||||
if (flags.contains(FilterOption.OBSERVED)
|
||||
&& !flags.contains(FilterOption.FORECAST)) {
|
||||
return " AND (aav.ts like 'R%' or aav.ts like 'P%')";
|
||||
} else if (!flags.contains(FilterOption.OBSERVED)
|
||||
&& flags.contains(FilterOption.FORECAST)) {
|
||||
return " AND (aav.ts like 'F%' or aav.ts like 'C%')";
|
||||
} else {
|
||||
return " AND aav.ts like '%'";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* append the where clause based on the alert/alarm category field
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String aaCatSubClause(EnumSet<FilterOption> flags) {
|
||||
if (flags == null) {
|
||||
return " ";
|
||||
}
|
||||
|
||||
if (flags.contains(FilterOption.ALERTS)
|
||||
&& !flags.contains(FilterOption.ALARMS)) {
|
||||
return " AND aav.aa_categ = " + ALERT_CATEGSTR;
|
||||
} else if (!flags.contains(FilterOption.ALERTS)
|
||||
&& flags.contains(FilterOption.ALARMS)) {
|
||||
return " AND aav.aa_categ = " + ALARM_CATEGSTR;
|
||||
} else {
|
||||
return " ";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* append the where clause based on the alert/alarm check field
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private static String aaCheckSubClause(EnumSet<FilterOption> flags) {
|
||||
String subClause = " AND aa_check in (";
|
||||
if (flags == null) {
|
||||
return " ";
|
||||
}
|
||||
|
||||
boolean rocFlag = flags.contains(FilterOption.RATE_OF_CHANGE);
|
||||
boolean lowFlag = flags.contains(FilterOption.LOWER_LIMIT);
|
||||
boolean upFlag = flags.contains(FilterOption.UPPER_LIMIT);
|
||||
boolean diffFlag = flags.contains(FilterOption.DIFF_LIMIT);
|
||||
|
||||
if (!rocFlag && !lowFlag && !upFlag && !diffFlag) {
|
||||
return " ";
|
||||
} else {
|
||||
boolean init = true;
|
||||
|
||||
if (rocFlag) {
|
||||
subClause.concat(aaCheckSubClause(init, ROC_CHECKSTR));
|
||||
}
|
||||
|
||||
if (lowFlag) {
|
||||
subClause.concat(aaCheckSubClause(init, LOWER_CHECKSTR));
|
||||
}
|
||||
|
||||
if (upFlag) {
|
||||
subClause.concat(aaCheckSubClause(init, UPPER_CHECKSTR));
|
||||
}
|
||||
|
||||
if (diffFlag) {
|
||||
subClause.concat(aaCheckSubClause(init, DIFF_CHECKSTR));
|
||||
}
|
||||
}
|
||||
|
||||
return subClause.concat(" ) ");
|
||||
}
|
||||
|
||||
private static String aaCheckSubClause(boolean initialEntry, String checkStr) {
|
||||
if (initialEntry) {
|
||||
initialEntry = !initialEntry;
|
||||
return checkStr;
|
||||
} else {
|
||||
return "," + checkStr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.edex.plugin.shef.alarms;
|
||||
package com.raytheon.uf.edex.ohd.reportalarm;
|
||||
|
||||
/**
|
||||
*
|
|
@ -0,0 +1,269 @@
|
|||
/**
|
||||
* 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.uf.edex.ohd.reportalarm;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import com.raytheon.uf.common.ohd.AppsDefaults;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.time.util.TimeUtil;
|
||||
import com.raytheon.uf.common.util.StringUtil;
|
||||
|
||||
/**
|
||||
* Place holder for user defined report options
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 15, 2011 9377 jnjanga Initial creation
|
||||
* Jul 12, 2013 15711 wkwock Fix verbose, observe mode, etc
|
||||
* Feb 12, 2014 #2783 dgilling Major refactor, cleanup.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author jnjanga
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
class ReportOptions {
|
||||
|
||||
private static final String DB_NAME = "ihfs";
|
||||
|
||||
private static final String PRODUCT_ID_KEY = "alarm_product_id";
|
||||
|
||||
private static final String REPORT_MODE_KEY = "alarm_report_mode";
|
||||
|
||||
private static final String INCLUDE_FLAGS_KEY = "alarm_filter";
|
||||
|
||||
private static final String PHYSICAL_ELEMENT_KEY = "alarm_pe_filter";
|
||||
|
||||
private static final String FILE_SUFFIX_KEY = "alarm_file_suffix";
|
||||
|
||||
private static final String MINUTES_KEY = "alarm_minutes";
|
||||
|
||||
private static final String VERBOSE_MODE_KEY = "alarm_verbose";
|
||||
|
||||
private static final EnumSet<ReportMode> IGNORE_MINS = EnumSet.of(
|
||||
ReportMode.ALL, ReportMode.UNREPORTED, ReportMode.NEAREST,
|
||||
ReportMode.LATEST_MAXFCST);
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(ReportOptions.class);
|
||||
|
||||
private String productId;
|
||||
|
||||
private ReportMode mode = null;
|
||||
|
||||
private EnumSet<FilterOption> filter = EnumSet.noneOf(FilterOption.class);
|
||||
|
||||
private String PEfilter = null;
|
||||
|
||||
private DateFormat fileSuffix = null;
|
||||
|
||||
private Integer minutes = null;
|
||||
|
||||
private boolean verboseFlag;
|
||||
|
||||
/**
|
||||
* @param appsDefaults
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public ReportOptions(final AppsDefaults appsDefaults)
|
||||
throws IllegalArgumentException {
|
||||
setProductId(appsDefaults.getToken(PRODUCT_ID_KEY));
|
||||
|
||||
if (appsDefaults.getTokens().contains(REPORT_MODE_KEY)) {
|
||||
setMode(appsDefaults.getToken(REPORT_MODE_KEY));
|
||||
}
|
||||
|
||||
if (appsDefaults.getTokens().contains(INCLUDE_FLAGS_KEY)) {
|
||||
setFilter(appsDefaults.getToken(INCLUDE_FLAGS_KEY));
|
||||
}
|
||||
|
||||
if (appsDefaults.getTokens().contains(PHYSICAL_ELEMENT_KEY)) {
|
||||
setPEfilter(appsDefaults.getToken(PHYSICAL_ELEMENT_KEY));
|
||||
}
|
||||
|
||||
if (appsDefaults.getTokens().contains(FILE_SUFFIX_KEY)) {
|
||||
setFileSuffix(appsDefaults.getToken(FILE_SUFFIX_KEY));
|
||||
}
|
||||
|
||||
if (appsDefaults.getTokens().contains(MINUTES_KEY)) {
|
||||
setMinutes(appsDefaults.getInt(MINUTES_KEY, -1));
|
||||
}
|
||||
|
||||
setVerbose(appsDefaults.getBoolean(VERBOSE_MODE_KEY, false));
|
||||
|
||||
if (isMinutesGiven() && IGNORE_MINS.contains(this.mode)) {
|
||||
statusHandler.warn("Minutes value ignored for this report mode.");
|
||||
}
|
||||
}
|
||||
|
||||
public String getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
private void setProductId(String productId) throws IllegalArgumentException {
|
||||
int pidlength = (productId != null) ? productId.length() : 0;
|
||||
if (pidlength != 9 && pidlength != 10) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid length for Product_Id : " + pidlength);
|
||||
}
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public int getMinutes() {
|
||||
return (minutes != null) ? minutes : 0;
|
||||
}
|
||||
|
||||
private void setMinutes(Integer minutes) throws IllegalArgumentException {
|
||||
if (minutes != null && !isWithinWindow(minutes)) {
|
||||
throw new IllegalArgumentException(getWindowOptionUsage(minutes));
|
||||
}
|
||||
|
||||
this.minutes = minutes;
|
||||
}
|
||||
|
||||
public boolean isMinutesGiven() {
|
||||
return (minutes != null);
|
||||
}
|
||||
|
||||
public ReportMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
private void setMode(String mode) throws IllegalArgumentException {
|
||||
try {
|
||||
this.mode = ReportMode.valueOf(mode);
|
||||
} catch (Exception e) {
|
||||
final String msg = "Invalid report mode : " + mode + Constants.EOL
|
||||
+ "Report mode must be either : "
|
||||
+ printValid(ReportMode.values());
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public EnumSet<FilterOption> getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
private void setFilter(String filter) throws IllegalArgumentException {
|
||||
int fltrlen = filter.length();
|
||||
if (fltrlen == 0 || fltrlen > 8) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid number of filter options specified. Filter string must be between 1 and 8 characters long.");
|
||||
}
|
||||
|
||||
this.filter = EnumSet.noneOf(FilterOption.class);
|
||||
for (char flag : filter.toCharArray()) {
|
||||
try {
|
||||
this.filter.add(FilterOption.fromArg(flag));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalArgumentException(printFilterOptionUsage(flag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getPEfilter() {
|
||||
return PEfilter;
|
||||
}
|
||||
|
||||
private void setPEfilter(String pEfilter) throws IllegalArgumentException {
|
||||
if (pEfilter.length() != 2) {
|
||||
throw new IllegalArgumentException(
|
||||
"PE filter option must be two characters");
|
||||
}
|
||||
this.PEfilter = pEfilter;
|
||||
}
|
||||
|
||||
public String getFileSuffix() {
|
||||
String retVal = (fileSuffix != null) ? fileSuffix.format(TimeUtil
|
||||
.newDate()) : "";
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private void setFileSuffix(String fileSuffix) {
|
||||
if (!StringUtil.isEmptyString(fileSuffix)) {
|
||||
this.fileSuffix = new SimpleDateFormat(fileSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getVerbose() {
|
||||
return verboseFlag;
|
||||
}
|
||||
|
||||
private void setVerbose(boolean verboseFlg) {
|
||||
this.verboseFlag = verboseFlg;
|
||||
}
|
||||
|
||||
public String getDbname() {
|
||||
return DB_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append("Product_Id = ").append(productId).append(Constants.EOL);
|
||||
str.append("Report_Mode = ").append(mode.toString())
|
||||
.append(Constants.EOL);
|
||||
str.append("Filter = ").append(filter).append(Constants.EOL);
|
||||
str.append("PE Filter = ").append(PEfilter).append(Constants.EOL);
|
||||
str.append("File suffix = ").append(fileSuffix).append(Constants.EOL);
|
||||
str.append("minutes = ").append(minutes).append(Constants.EOL);
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
private static <E> String printValid(E[] array) {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (E element : array) {
|
||||
str.append(element.toString() + ", ");
|
||||
}
|
||||
str.delete(str.length() - 2, str.length());
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
private boolean isWithinWindow(int min) {
|
||||
return (min >= 0 && min <= 999999);
|
||||
}
|
||||
|
||||
private String getWindowOptionUsage(int min) {
|
||||
return "Invalid number of minutes : " + min
|
||||
+ " . Must be between 1 - 999999 ";
|
||||
}
|
||||
|
||||
private String printFilterOptionUsage(char flag) {
|
||||
return "Invalid token for filter option : " + flag + Constants.EOL
|
||||
+ "Filter option must be either : "
|
||||
+ printValid(FilterOption.values());
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
String retVal = productId;
|
||||
if (fileSuffix != null) {
|
||||
retVal = retVal + '.' + getFileSuffix();
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,159 @@
|
|||
/**
|
||||
* 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.uf.edex.ohd.reportalarm;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import com.raytheon.edex.textdb.dbapi.impl.TextDB;
|
||||
import com.raytheon.uf.common.ohd.AppsDefaults;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.time.util.TimeUtil;
|
||||
import com.raytheon.uf.common.util.FileUtil;
|
||||
|
||||
/**
|
||||
* Provides SHEF with the ability to generate alert/alarms report products and
|
||||
* write them to the text database.
|
||||
* <p>
|
||||
* Based on AlertalarmStdTextProductUtil.java originally written by jnjanga.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 12, 2014 #2783 dgilling Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author dgilling
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public final class RunReportAlarmSrv {
|
||||
|
||||
private static final DateFormat START_END_TIME_FORMAT = new SimpleDateFormat(
|
||||
"EEE MMM dd HH:mm:ss z yyyy");
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(RunReportAlarmSrv.class);
|
||||
|
||||
private RunReportAlarmSrv() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
public static void executeRunReportAlarm() {
|
||||
statusHandler.info("------------------------------ ");
|
||||
String currentTime = START_END_TIME_FORMAT.format(TimeUtil.newDate());
|
||||
statusHandler.info("Invoking report_alarm at " + currentTime);
|
||||
|
||||
try {
|
||||
ReportOptions options = null;
|
||||
try {
|
||||
options = loadConfiguration();
|
||||
} catch (IllegalArgumentException e) {
|
||||
statusHandler
|
||||
.error("Invalid configuration value specified.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
ReportWriter reportWriter;
|
||||
try {
|
||||
AlertalarmRecord aaRecord = RecordMgr.getAlarmData(options);
|
||||
reportWriter = new ReportWriter(options, TimeUtil.newDate());
|
||||
reportWriter.generateReport(aaRecord);
|
||||
} catch (Exception e) {
|
||||
statusHandler.error("Could not generate Alertalarm report.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
File outputFile;
|
||||
try {
|
||||
outputFile = createOutputFile(options.getFileName());
|
||||
reportWriter.writeToDisk(outputFile);
|
||||
} catch (IOException e) {
|
||||
statusHandler.error("Could not write output file.", e);
|
||||
return;
|
||||
}
|
||||
String fileName = outputFile.getPath();
|
||||
|
||||
int alarmCount = reportWriter.getAlarmCount();
|
||||
if (alarmCount == 0) {
|
||||
statusHandler.info("No alarms reported, info sent to "
|
||||
+ fileName);
|
||||
statusHandler.info("File NOT sent to text database.");
|
||||
} else {
|
||||
statusHandler.info(alarmCount
|
||||
+ " alarms reported, report written " + fileName);
|
||||
statusHandler.info("Writing " + fileName + " to textdb as id "
|
||||
+ options.getProductId());
|
||||
|
||||
try {
|
||||
saveProductToTextDb(reportWriter.getReportData(),
|
||||
options.getProductId());
|
||||
} catch (Exception e) {
|
||||
statusHandler.error("Could not write product to textdb", e);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
currentTime = START_END_TIME_FORMAT.format(TimeUtil.newDate());
|
||||
statusHandler.info("Completed report_alarm at " + currentTime);
|
||||
}
|
||||
}
|
||||
|
||||
private static ReportOptions loadConfiguration() {
|
||||
AppsDefaults appsDefaults = AppsDefaults.getInstance();
|
||||
ReportOptions userOptions = new ReportOptions(appsDefaults);
|
||||
return userOptions;
|
||||
}
|
||||
|
||||
private static File createOutputFile(final String fileName)
|
||||
throws IOException {
|
||||
AppsDefaults appDefaults = AppsDefaults.getInstance();
|
||||
String basePath = appDefaults.getToken(Constants.WHFS_PRODUCT_DIR);
|
||||
if (basePath == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"whfs_product_dir directory undefined");
|
||||
}
|
||||
|
||||
String fullPath = FileUtil.join(basePath, fileName);
|
||||
File outFile = new File(fullPath);
|
||||
outFile.createNewFile();
|
||||
|
||||
return outFile;
|
||||
}
|
||||
|
||||
private static void saveProductToTextDb(final String productText,
|
||||
final String productId) throws Exception {
|
||||
TextDB textdb = new TextDB();
|
||||
long statusCode = textdb.writeProduct(productId, productText, true,
|
||||
null);
|
||||
|
||||
if (statusCode != Long.MIN_VALUE) {
|
||||
statusHandler.info("Product successfully sent");
|
||||
} else {
|
||||
statusHandler.error("Product send error detected.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,7 +44,9 @@ echo Starting alarm_whfs at $Dte >> $LOGFILE
|
|||
|
||||
$WHFS_LOCAL_BIN_DIR/run_roc_checker
|
||||
|
||||
$WHFS_LOCAL_BIN_DIR/run_report_alarm
|
||||
# The run_report_alarm script has been replaced by an EDEX service
|
||||
# com.raytheon.uf.edex.ohd.reportalarm.RunReportAlarmSrv
|
||||
# See A2 redmine DR #2783
|
||||
|
||||
Dte=`date -u `
|
||||
echo Completed alarm_whfs at $Dte >> $LOGFILE
|
||||
|
|
|
@ -5,157 +5,21 @@
|
|||
# a product and send them to the text database
|
||||
#
|
||||
|
||||
# Revised:Sep 11, 2012
|
||||
# Revised:Feb 14, 2014
|
||||
######################################################################
|
||||
|
||||
|
||||
# This allows you to call this script from outside of ./standard/bin
|
||||
RUN_FROM_DIR=`dirname $0`
|
||||
|
||||
# set up SOME environment variables for WHFS applications
|
||||
# Run from local bin dir
|
||||
. $RUN_FROM_DIR/../../set_hydro_env
|
||||
. $RUN_FROM_DIR/../../check_app_context
|
||||
|
||||
export EDEX_HOME=/awips2/edex
|
||||
export DB_NAME=$(get_apps_defaults db_name)
|
||||
export FXA_DB_NAME=fxatext
|
||||
export WHFS_UTIL_LOG_DIR=$(get_apps_defaults whfs_util_log_dir)
|
||||
export WHFS_PRODUCT_DIR=$(get_apps_defaults whfs_product_dir)
|
||||
export WHFS_BIN_DIR=$(get_apps_defaults whfs_bin_dir)
|
||||
export SYS_JAVA_DIR=$(get_apps_defaults sys_java_dir)
|
||||
export UTILITYDIR=$EDEX_HOME/data/utility
|
||||
|
||||
|
||||
# This script has been made obsolete by a new java-based service that
|
||||
# runs within the EDEX ingest JVM named
|
||||
# com.raytheon.uf.edex.ohd.reportalarm.RunReportAlarmSrv.
|
||||
#
|
||||
# Report output goes to dedicated files named by product_id and the
|
||||
# file suffix, which is normally set according to the system time.
|
||||
# Log output and error messages should appear in the redirected output of the program.
|
||||
# This new service can still be configured using a site-level override
|
||||
# to the standard Apps_defaults file.
|
||||
#
|
||||
|
||||
LOGFILE=$WHFS_UTIL_LOG_DIR/report_alarm.log
|
||||
TEMPNAME=$WHFS_UTIL_LOG_DIR/report_alarm.tmp
|
||||
|
||||
# setup the AWIPS environment
|
||||
# redirect any output from this script to the log file
|
||||
# Configuration options for that file are defined within the base file.
|
||||
#
|
||||
|
||||
/awips2/fxa/bin/setup.env >> $LOGFILE 2>&1
|
||||
|
||||
|
||||
# Logging for the run_report_alarm process has been moved to
|
||||
# /awips2/edex/logs/edex-ingest-ohd-YYYYMMDD.log.
|
||||
#
|
||||
# save only the latest events in the log file
|
||||
#
|
||||
if [ -e "${LOGFILE}" ]
|
||||
then
|
||||
tail -1200 $LOGFILE > $TEMPNAME
|
||||
mv $TEMPNAME $LOGFILE
|
||||
fi
|
||||
|
||||
# log start of script
|
||||
#
|
||||
echo "------------------------------ " >> $LOGFILE
|
||||
Dte=`date -u`
|
||||
echo Invoking report_alarm at $Dte >> $LOGFILE
|
||||
|
||||
#
|
||||
# program usage:
|
||||
# report_alarm -d<database> -p<product_id> <--required args
|
||||
# -r<report_mode> -s<file_suffix> -m<minutes> <-- optional args
|
||||
# -f<generalfilter> -e<PEfilter> <-- optional args
|
||||
#
|
||||
|
||||
# define the product id as per local needs - SET LOCALLY !!!!!!!!!!!!!!!!!!!!!
|
||||
#
|
||||
|
||||
PRODUCT_ID=CCCACRXXX
|
||||
#
|
||||
# define the file suffix based on the system time
|
||||
# use extr var to avoid SCCS problem
|
||||
|
||||
hstr="%H"
|
||||
SUFFIX=`date -u +%m%d.$hstr%M`
|
||||
|
||||
#
|
||||
# the name of the created file is set according to how the program
|
||||
# builds the name
|
||||
|
||||
FILENAME=$WHFS_PRODUCT_DIR/$PRODUCT_ID.$SUFFIX
|
||||
|
||||
#
|
||||
# To discover dependencies and dynamically
|
||||
# build associated classpath.
|
||||
#
|
||||
|
||||
function buildClassPath {
|
||||
targetDir=$1
|
||||
pattern=$2
|
||||
targetDirListing=`find $targetDir -name "$pattern"`
|
||||
list=
|
||||
for i in $targetDirListing
|
||||
do
|
||||
list=${list}:${i}
|
||||
done
|
||||
printf " $list "
|
||||
}
|
||||
|
||||
|
||||
# set dependencies base directories
|
||||
LOG4J_CONF=$WHFS_BIN_DIR
|
||||
DEPENDENCY_DIR=$EDEX_HOME/lib/dependencies
|
||||
HIBERNATE_DIR=$DEPENDENCY_DIR/org.hibernate
|
||||
CAMEL_DIR=$DEPENDENCY_DIR/org.apache.camel
|
||||
SPRING_ORM_DIR=$DEPENDENCY_DIR/org.springframework
|
||||
|
||||
|
||||
# set patterns for target dependencies
|
||||
PATTERN='*\.jar'
|
||||
COMMONS_PATTERN='commons*\.jar'
|
||||
|
||||
# get dependencies path
|
||||
PLUGINS="$EDEX_HOME/lib/plugins/*"
|
||||
CAMEL="$DEPENDENCY_DIR/org.apache.camel/*"
|
||||
GEOTOOLS="$DEPENDENCY_DIR/org.geotools/*"
|
||||
JAVAX_MEASURE="$DEPENDENCY_DIR/javax.measure/*"
|
||||
JAVAX_PERSISTANCE="$DEPENDENCY_DIR/javax.persistence/*"
|
||||
MCHANGE="$DEPENDENCY_DIR/com.mchange/*"
|
||||
LOG4J="$DEPENDENCY_DIR/org.apache.log4j/*"
|
||||
SLF4J="$DEPENDENCY_DIR/org.slf4j/*"
|
||||
DOM4J="$DEPENDENCY_DIR/org.dom4j/*"
|
||||
SPRING="$DEPENDENCY_DIR/org.springframework/*"
|
||||
HIBERNATE="$DEPENDENCY_DIR/org.hibernate/*"
|
||||
APACHE_COMMONS=`buildClassPath $DEPENDENCY_DIR $COMMONS_PATTERN`
|
||||
|
||||
|
||||
# set the application classpath
|
||||
export CLASSPATH=$HIBERNATE:$SPRING:$DB_DRIVER_PATH:$CAMEL:$GEOTOOLS:$JAVAX_MEASURE:$MCHANGE:$LOG4J:$SLF4J:$JAVAX_PERSISTANCE:$DOM4J:$APACHE_COMMONS:$PLUGINS:$CLASSPATH
|
||||
|
||||
#
|
||||
# run the application
|
||||
#
|
||||
$SYS_JAVA_DIR/bin/java -Xms64m -Xmx512m com.raytheon.edex.plugin.shef.alarms.AlertalarmStdTextProductUtil -d$DB_NAME -p$PRODUCT_ID -s$SUFFIX -rNEAREST >> $LOGFILE 2>&1
|
||||
NUM_ALARMS=$?
|
||||
|
||||
|
||||
if [ $NUM_ALARMS -eq 0 ]
|
||||
then
|
||||
print No alarms reported, info sent to $FILENAME >> $LOGFILE
|
||||
print File NOT sent to text database >> $LOGFILE
|
||||
|
||||
else
|
||||
print $NUM_ALARMS alarms reported, report written to $FILENAME >> $LOGFILE
|
||||
|
||||
echo Writing $FILENAME to textdb as id $PRODUCT_ID >> $LOGFILE
|
||||
/awips2/fxa/bin/textdb -w $PRODUCT_ID < $FILENAME >> $LOGFILE 2>&1
|
||||
RETURN_STATUS=$?
|
||||
|
||||
if [ $RETURN_STATUS -eq 0 ]
|
||||
then
|
||||
print Product successfully sent >> $LOGFILE
|
||||
else
|
||||
print Product send error detected, status= $RETURN_STATUS >> $LOGFILE
|
||||
fi
|
||||
fi
|
||||
|
||||
Dte=`date -u `
|
||||
echo Completed report_alarm at $Dte >> $LOGFILE
|
||||
# For more information on this change please refer to A2 redmine
|
||||
# DR #2783.
|
||||
|
|
Loading…
Add table
Reference in a new issue