Omaha #4804: Add ability to run text formatters from GFE procedures and tools.
Change-Id: I8f77334dee55b6c55d1422ca314e082926ddf9c9 Former-commit-id: 9b75a6fd19c65cdb8c0a7aa19f2b68953983d3bd
This commit is contained in:
parent
e524aa5148
commit
4290fb208b
4 changed files with 215 additions and 45 deletions
|
@ -442,7 +442,7 @@ class ITool (ISmartScript.ISmartScript):
|
|||
# thread has its own interpreter....
|
||||
# however, running the other way has issue with sampler caches not getting dumped between runs
|
||||
waiter = TextProductFinishWaiter()
|
||||
FormatterUtil.runFormatterScript(productType, vtecMode, database, cmdLineVars, "PRACTICE", drtTime, 0, waiter)
|
||||
FormatterUtil.runFormatterScript(productType, vtecMode, database, cmdLineVars, "PRACTICE", drtTime, 0, waiter, self._dataMgr)
|
||||
fcst = waiter.waitAndGetProduct()
|
||||
state = waiter.getState()
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
# Aug 13, 2015 4704 randerso Added NumpyJavaEnforcer support in createGrids and decodeEditArea
|
||||
# additional code cleanup
|
||||
# Aug 26, 2015 4809 randerso Added option group parameter to editAreaList()
|
||||
# Aug 26, 2015 4804 dgilling Added callTextFormatter().
|
||||
########################################################################
|
||||
import types, string, time, sys
|
||||
from math import *
|
||||
|
@ -101,6 +102,10 @@ from com.raytheon.uf.common.dataplugin.gfe.db.objects import TimeConstraints
|
|||
from com.raytheon.uf.common.dataplugin.gfe.db.objects import GridParmInfo
|
||||
GridType = GridParmInfo.GridType
|
||||
from com.raytheon.uf.common.dataplugin.gfe.server.request import SendISCRequest
|
||||
from com.raytheon.viz.gfe.dialogs.formatterlauncher import ConfigData
|
||||
ProductStateEnum = ConfigData.ProductStateEnum
|
||||
from com.raytheon.viz.gfe.textformatter import FormatterUtil
|
||||
from com.raytheon.viz.gfe.textformatter import TextProductFinishWaiter
|
||||
|
||||
class SmartScript(BaseTool.BaseTool):
|
||||
|
||||
|
@ -2599,4 +2604,36 @@ class SmartScript(BaseTool.BaseTool):
|
|||
textList = fullText.splitlines(True)
|
||||
return textList
|
||||
|
||||
def callTextFormatter(self, productName, dbId, varDict={}, vtecMode=None):
|
||||
"""
|
||||
Execute the requested text product formatter.
|
||||
|
||||
Args:
|
||||
productName: the display name of the formatter to run.
|
||||
dbId: string form of the DatabaseID to use as data source.
|
||||
varDict: optional, product varDict, use an empty dict instead
|
||||
of None to signify a null varDict.
|
||||
vtecMode: optional, for VTEC products specify VTEC mode (one of
|
||||
'O', 'T', 'E' or 'X').
|
||||
|
||||
Returns:
|
||||
The output of the formatter--the content of the requested product.
|
||||
|
||||
Throws:
|
||||
TypeError: If varDict is not a dict.
|
||||
RuntimeError: If the formatter fails during execution.
|
||||
"""
|
||||
if type(varDict) is not dict:
|
||||
raise TypeError("Argument varDict must be a dict.")
|
||||
varDict = str(varDict)
|
||||
|
||||
listener = TextProductFinishWaiter()
|
||||
FormatterUtil.callFromSmartScript(productName, dbId, varDict, vtecMode, self.__dataMgr, listener)
|
||||
product = listener.waitAndGetProduct()
|
||||
state = listener.getState()
|
||||
if not state.equals(ProductStateEnum.Finished):
|
||||
msg = "Formatter " + productName + " terminated before completion with state: " + state.name() + \
|
||||
". Check formatter logs from Process Monitor for more information."
|
||||
raise RuntimeError(msg)
|
||||
return product
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
**/
|
||||
package com.raytheon.viz.gfe.textformatter;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.TimeZone;
|
||||
|
||||
|
@ -46,6 +47,7 @@ import com.raytheon.viz.gfe.tasks.TaskManager;
|
|||
* Fixed hard coded active table mode in runFormatterScript
|
||||
* Jul 30, 2015 4263 dgilling Pass DataManager instance to TextFormatter, stop passing
|
||||
* varDict through.
|
||||
* Aug 26, 2015 4804 dgilling Add methods so SmartScript can run formatters.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -55,8 +57,13 @@ import com.raytheon.viz.gfe.tasks.TaskManager;
|
|||
|
||||
public class FormatterUtil {
|
||||
|
||||
public static String[] VTEC_MODES = { "Normal: NoVTEC", "Normal: O-Vtec",
|
||||
"Normal: E-Vtec", "Normal: X-Vtec", "Test: NoVTEC", "Test: T-Vtec" };
|
||||
public static final String[] VTEC_MODES = { "Normal: NoVTEC",
|
||||
"Normal: O-Vtec", "Normal: E-Vtec", "Normal: X-Vtec",
|
||||
"Test: NoVTEC", "Test: T-Vtec" };
|
||||
|
||||
private FormatterUtil() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a text formatter script for a given product
|
||||
|
@ -78,50 +85,63 @@ public class FormatterUtil {
|
|||
public static void runFormatterScript(DataManager dataMgr,
|
||||
TextProductManager productMgr, String productName, String dbId,
|
||||
String vtecMode, TextProductFinishListener finish) {
|
||||
|
||||
int testMode = 0;
|
||||
ActiveTableMode atMode = ActiveTableMode.OPERATIONAL;
|
||||
CAVEMode caveMode = dataMgr.getOpMode();
|
||||
if (caveMode.equals(CAVEMode.TEST)) {
|
||||
testMode = 1;
|
||||
} else if (caveMode.equals(CAVEMode.PRACTICE)) {
|
||||
atMode = ActiveTableMode.PRACTICE;
|
||||
}
|
||||
|
||||
String shortVtec = null;
|
||||
if (vtecMode.length() == 1) {
|
||||
shortVtec = vtecMode;
|
||||
} else if (vtecMode.equals(VTEC_MODES[1])) {
|
||||
shortVtec = "O";
|
||||
} else if (vtecMode.equals(VTEC_MODES[2])) {
|
||||
shortVtec = "E";
|
||||
} else if (vtecMode.equals(VTEC_MODES[3])) {
|
||||
shortVtec = "X";
|
||||
} else if (vtecMode.equals(VTEC_MODES[4])) {
|
||||
testMode = 1;
|
||||
} else if (vtecMode.equals(VTEC_MODES[5])) {
|
||||
shortVtec = "T";
|
||||
testMode = 1;
|
||||
}
|
||||
|
||||
String activeTable = getActiveTableName(dataMgr);
|
||||
int testMode = getTestMode(dataMgr, vtecMode);
|
||||
String shortVtec = getVTECModeCode(vtecMode);
|
||||
String name = productMgr.getModuleName(productName);
|
||||
String time = getDRTString();
|
||||
|
||||
String time = null;
|
||||
if (!SimulatedTime.getSystemTime().isRealTime()) {
|
||||
SimpleDateFormat gmtFormatter = new SimpleDateFormat(
|
||||
"yyyyMMdd_HHmm");
|
||||
gmtFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
time = gmtFormatter.format(SimulatedTime.getSystemTime().getTime());
|
||||
}
|
||||
runFormatterScript(name, shortVtec, dbId, atMode.name(), time,
|
||||
testMode, finish, dataMgr);
|
||||
runFormatterScript(name, shortVtec, dbId, activeTable, time, testMode,
|
||||
finish, dataMgr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for SmartScript based script objects to run text
|
||||
* formatters. Uses native formatter execution framework, so product may be
|
||||
* queued and not run until other formatters launched interactively have
|
||||
* completed execution.
|
||||
*
|
||||
* @param productName
|
||||
* The display name of the formatter to execute.
|
||||
* @param dbId
|
||||
* String form of the {@code DatabaseID} of the source database.
|
||||
* @param varDict
|
||||
* String form of the formatters variable dictionary.
|
||||
* @param vtecMode
|
||||
* VTEC mode--operational, experimental, test, etc.
|
||||
* @param dataMgr
|
||||
* the {@code DataManager} instance to use.
|
||||
* @param listener
|
||||
* listener to fire when formatter finishes generating product
|
||||
* @throws InterruptedException
|
||||
* If something interrupts this thread before the formatter has
|
||||
* completed.
|
||||
*/
|
||||
public static void callFromSmartScript(String productName, String dbId,
|
||||
String varDict, String vtecMode, DataManager dataMgr,
|
||||
TextProductFinishListener listener) {
|
||||
String activeTable = getActiveTableName(dataMgr);
|
||||
int testMode = getTestMode(dataMgr, vtecMode);
|
||||
String shortVtec = getVTECModeCode(vtecMode);
|
||||
String name = dataMgr.getTextProductMgr().getModuleName(productName);
|
||||
String time = getDRTString();
|
||||
runFormatterScript(name, shortVtec, dbId, varDict, activeTable, time,
|
||||
testMode, listener, dataMgr);
|
||||
}
|
||||
|
||||
public static void runFormatterScript(String name, String vtecMode,
|
||||
String databaseID, String vtecActiveTable, String drtTime,
|
||||
int testMode, TextProductFinishListener finish, DataManager dataMgr) {
|
||||
runFormatterScript(name, vtecMode, databaseID, null, vtecActiveTable,
|
||||
drtTime, testMode, finish, dataMgr);
|
||||
}
|
||||
|
||||
public static void runFormatterScript(String name, String vtecMode,
|
||||
String databaseID, String varDict, String vtecActiveTable,
|
||||
String drtTime, int testMode, TextProductFinishListener finish,
|
||||
DataManager dataMgr) {
|
||||
TextFormatter formatter = new TextFormatter(name, vtecMode, databaseID,
|
||||
vtecActiveTable, drtTime, testMode, finish, dataMgr);
|
||||
varDict, vtecActiveTable, drtTime, testMode, finish, dataMgr);
|
||||
finish.textProductQueued(ConfigData.ProductStateEnum.Queued);
|
||||
TaskManager.getInstance().queueFormatter(formatter);
|
||||
}
|
||||
|
@ -130,4 +150,57 @@ public class FormatterUtil {
|
|||
TimeRange tr2) {
|
||||
return tr1.intersection(tr2).getDuration();
|
||||
}
|
||||
|
||||
private static String getActiveTableName(DataManager dataMgr) {
|
||||
ActiveTableMode atMode = ActiveTableMode.OPERATIONAL;
|
||||
CAVEMode caveMode = dataMgr.getOpMode();
|
||||
if (caveMode.equals(CAVEMode.PRACTICE)) {
|
||||
atMode = ActiveTableMode.PRACTICE;
|
||||
}
|
||||
return atMode.name();
|
||||
}
|
||||
|
||||
private static String getVTECModeCode(String displayString) {
|
||||
String shortVtec = null;
|
||||
if (displayString != null) {
|
||||
if (displayString.length() == 1) {
|
||||
shortVtec = displayString;
|
||||
} else if (displayString.equals(VTEC_MODES[1])) {
|
||||
shortVtec = "O";
|
||||
} else if (displayString.equals(VTEC_MODES[2])) {
|
||||
shortVtec = "E";
|
||||
} else if (displayString.equals(VTEC_MODES[3])) {
|
||||
shortVtec = "X";
|
||||
} else if (displayString.equals(VTEC_MODES[5])) {
|
||||
shortVtec = "T";
|
||||
}
|
||||
}
|
||||
return shortVtec;
|
||||
}
|
||||
|
||||
private static int getTestMode(DataManager dataMgr, String vtecMode) {
|
||||
int testMode = 0;
|
||||
|
||||
CAVEMode caveMode = dataMgr.getOpMode();
|
||||
if (caveMode.equals(CAVEMode.TEST)) {
|
||||
testMode = 1;
|
||||
}
|
||||
|
||||
if (VTEC_MODES[4].equals(vtecMode) || VTEC_MODES[5].equals(vtecMode)
|
||||
|| "T".equals(vtecMode)) {
|
||||
testMode = 1;
|
||||
}
|
||||
|
||||
return testMode;
|
||||
}
|
||||
|
||||
private static String getDRTString() {
|
||||
String time = null;
|
||||
if (!SimulatedTime.getSystemTime().isRealTime()) {
|
||||
DateFormat gmtFormatter = new SimpleDateFormat("yyyyMMdd_HHmm");
|
||||
gmtFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
time = gmtFormatter.format(SimulatedTime.getSystemTime().getTime());
|
||||
}
|
||||
return time;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
import com.raytheon.uf.common.time.SimulatedTime;
|
||||
import com.raytheon.uf.common.time.util.ITimer;
|
||||
import com.raytheon.uf.common.time.util.TimeUtil;
|
||||
import com.raytheon.uf.common.util.StringUtil;
|
||||
import com.raytheon.viz.gfe.core.DataManager;
|
||||
import com.raytheon.viz.gfe.dialogs.formatterlauncher.ConfigData;
|
||||
import com.raytheon.viz.gfe.dialogs.formatterlauncher.ConfigData.ProductStateEnum;
|
||||
|
@ -61,6 +62,8 @@ import com.raytheon.viz.gfe.tasks.AbstractGfeTask;
|
|||
* Jul 28, 2015 4263 dgilling Support changes to FormatterScriptFactory,
|
||||
* get DataManager instance via constructor.
|
||||
* Aug 20, 2015 #4749 dgilling Add cleanUp.
|
||||
* Aug 26, 2015 #4804 dgilling Support ability to run TextFormatters
|
||||
* from SmartScript.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -87,13 +90,63 @@ public class TextFormatter extends AbstractGfeTask {
|
|||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param productName
|
||||
* Name of the python module to execute.
|
||||
* @param vtecMode
|
||||
* Single character code for VTEC mode--Operational,
|
||||
* eXperimental, Test, etc.
|
||||
* @param databaseID
|
||||
* String form of the {@code DatabaseID} of the source database.
|
||||
* @param vtecActiveTable
|
||||
* Name of the active table to use for hazard information.
|
||||
* @param drtTime
|
||||
* DRT time to use in YYYYMMDD_HHmm format.
|
||||
* @param testMode
|
||||
* Whether or not to execute in test VTEC mode.
|
||||
* @param finish
|
||||
* Listener to send status updates to.
|
||||
* @param dataMgr
|
||||
* the {@code DataManager} instance to use.
|
||||
*/
|
||||
public TextFormatter(String productName, String vtecMode,
|
||||
String databaseID, String vtecActiveTable, String drtTime,
|
||||
int testMode, TextProductFinishListener finish, DataManager dataMgr) {
|
||||
super(productName);
|
||||
String addr = null;
|
||||
this(productName, vtecMode, databaseID, null, vtecActiveTable, drtTime,
|
||||
testMode, finish, dataMgr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that allows the varDict to be pre-supplied. Useful for
|
||||
* executing formatters where no GUI popups are desired.
|
||||
*
|
||||
* @param productName
|
||||
* Name of the python module to execute.
|
||||
* @param vtecMode
|
||||
* Single character code for VTEC mode--Operational,
|
||||
* eXperimental, Test, etc.
|
||||
* @param databaseID
|
||||
* String form of the {@code DatabaseID} of the source database.
|
||||
* @param varDict
|
||||
* String form of the formatter's variable dictionary.
|
||||
* @param vtecActiveTable
|
||||
* Name of the active table to use for hazard information.
|
||||
* @param drtTime
|
||||
* DRT time to use in YYYYMMDD_HHmm format.
|
||||
* @param testMode
|
||||
* Whether or not to execute in test VTEC mode.
|
||||
* @param finish
|
||||
* Listener to send status updates to.
|
||||
* @param dataMgr
|
||||
* the {@code DataManager} instance to use.
|
||||
*/
|
||||
public TextFormatter(String productName, String vtecMode,
|
||||
String databaseID, String varDict, String vtecActiveTable,
|
||||
String drtTime, int testMode, TextProductFinishListener finish,
|
||||
DataManager dataMgr) {
|
||||
super(productName);
|
||||
|
||||
String addr = null;
|
||||
try {
|
||||
addr = InetAddress.getLocalHost().getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
|
@ -110,9 +163,12 @@ public class TextFormatter extends AbstractGfeTask {
|
|||
argMap.put("username", System.getProperty("user.name") + ":" + addr);
|
||||
argMap.put("dataMgr", this.dataMgr);
|
||||
argMap.put(ArgDictConstants.VTEC_MODE, vtecMode);
|
||||
|
||||
argMap.put(ArgDictConstants.VTEC_ACTIVE_TABLE, vtecActiveTable);
|
||||
argMap.put("drtTime", drtTime);
|
||||
if (!StringUtil.isEmptyString(varDict)) {
|
||||
argMap.put(ArgDictConstants.CMDLINE_VARDICT, varDict);
|
||||
}
|
||||
|
||||
listener = finish;
|
||||
this.state = ConfigData.ProductStateEnum.Queued;
|
||||
}
|
||||
|
@ -132,12 +188,16 @@ public class TextFormatter extends AbstractGfeTask {
|
|||
.get(ArgDictConstants.FORECAST_LIST);
|
||||
String issuedBy = dataMgr.getTextProductMgr().getIssuedBy();
|
||||
String dbId = (String) argMap.get(ArgDictConstants.DATABASE_ID);
|
||||
String varDict = getVarDict(productName, dataMgr, dbId, issuedBy,
|
||||
script);
|
||||
|
||||
if (varDict != null) {
|
||||
if (!argMap.containsKey(ArgDictConstants.CMDLINE_VARDICT)) {
|
||||
String varDict = getVarDict(productName, dataMgr, dbId,
|
||||
issuedBy, script);
|
||||
argMap.put(ArgDictConstants.CMDLINE_VARDICT, varDict);
|
||||
}
|
||||
|
||||
String varDict = (String) argMap
|
||||
.get(ArgDictConstants.CMDLINE_VARDICT);
|
||||
if (varDict != null) {
|
||||
ITimer timer = TimeUtil.getTimer();
|
||||
timer.start();
|
||||
forecast = (String) script.execute(argMap);
|
||||
|
|
Loading…
Add table
Reference in a new issue