Issue #1274 Added Token control for java code and scripts started by RFC Crons.

Added tokens for app control to the Apps_Defaults configuration file.
Added AppsDefaults token checks to the cron java code and scripts.
Updated Executor.start() to load system properties from properties files
in a conf resources properties directory and also to load site specific
properties from a conf resources properties site directory.

Amend:
Removed tabs in MainMethod.java.
Updates from peer review.
Removed old commented out code in ohd cron properties file and commented-out code in MainMethod.execute().

Change-Id: I44e74791dadc9af09c99244d8d099cea581863cc

Former-commit-id: 44e9238fa9 [formerly 96bb97c32f664e015a29ac5c3187e6b27160a872]
Former-commit-id: 68a3a98547
This commit is contained in:
Brad Gonzales 2012-10-18 11:06:48 -05:00 committed by Gerrit Code Review
parent 2b80c2c2b5
commit 75e77feb58
26 changed files with 756 additions and 389 deletions

View file

@ -49,6 +49,7 @@
<delete>
<fileset dir="${edex.root.directory}/conf">
<include name="**" />
<exclude name="**/site/**"/>
</fileset>
</delete>
</target>

View file

@ -0,0 +1,37 @@
<project default="enact.external-rules">
<!-- external deployment rules -->
<!--
TODO: if necessary, these could be read from a properties file.
1) utility -> /awips2/edex/data/utility
2) resources -> /awips2/edex/conf/resources
-->
<target name="enact.external-rules">
<!-- parameters -->
<property name="plugin._directory" value="" />
<property name="deployment._root" value="" />
<!--
* plugin._directory = the full directory path to the plugin
* deployment._root = the directory to deploy the files to
-->
<mkdir dir="${deployment._root}/data/utility" />
<if>
<available file="${plugin._directory}/utility" type="dir" />
<then>
<copy todir="${deployment._root}/data/utility" overwrite="true">
<fileset dir="${plugin._directory}/utility" />
</copy>
</then>
</if>
<mkdir dir="${deployment._root}/conf/resources" />
<if>
<available file="${plugin._directory}/resources" type="dir" />
<then>
<copy todir="${deployment._root}/conf/resources" overwrite="true" verbose="true">
<fileset dir="${plugin._directory}/resources" />
</copy>
</then>
</if>
</target>
</project>

View file

@ -137,9 +137,16 @@
</if>
</else>
</if>
<ant antfile="${basedir}/deploy-common/external-rules.xml"
inheritAll="false">
<property name="plugin._directory"
value="${plugin.base}" />
<property name="deployment._root"
value="${edex.root.directory}" />
</ant>
</sequential>
</macrodef>
<macrodef name="jarPlugin">
<!--
random character suffixes added to

View file

@ -3,22 +3,12 @@
#crontab values
logfilepurger.cron=0+1+1,5,9,13,17,21+*+*+?
ihfsdbpurge.cron=0+45+7+*+*+?
floodarchiver.cron=0+30+6+*+*+?
mpehpefilepurge.cron=0+1+12+*+*+?
mpefieldgen.cron=0+25+*+*+*+?
pointdataretrieval.cron=0+2,17,32,47+*+*+*+?
alarmwhfs.cron=0+7,17,27,37,47,57+*+*+*+?
arealqpegen.cron=0+10,25,40,55+*+*+*+?
subscription.cron=0+*+*+*+*+?
dqcpreprocessor.cron=0+20+0,6,12,18+*+*+?
freezingLevel.cron=0+5+2,8,14,20+*+*+?
rpggenvdata.envdata.cron=0+0+*+*+*+?
rpggenvdata.biastable.cron=0+26,46+*+*+*+?
metartohmdb.cron=0+14+*+*+*+?
distribution.cron=0/5+*+*+*+*+?
mpelightningsrv.cron=0+0/30+*+*+*+?
qc.cron=0+2,7,12,17,22,27,32,37,42,47,52,57+*+*+*+?
acarssounding.cron=00+10,30,50+*+*+*+?
gfe.cron=0+15+*+*+*+?

View file

@ -64,7 +64,8 @@ import com.raytheon.uf.common.util.FileUtil;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 22, 2008 randerso Initial creation
* Apr 1, 2009 jelkins added getTokens
* Apr 1, 2009 jelkins added getTokens
* Oct 19, 2012 bgonzale App Context variable setup and token access.
* </pre>
*
* @author randerso
@ -112,6 +113,8 @@ public class AppsDefaults {
private static final Object LOCK = new Object();
private static final String APP_CONTEXT = "APP_CONTEXT";
static {
_trueSet.add("true");
_trueSet.add("on");
@ -873,4 +876,118 @@ public class AppsDefaults {
}
/**
* <pre>
* Set context using the callingContext in the APP_CONTEXT variable.
* if a token for the context is defined and is ON
* then log run and return true.
*
* If the token is defined and is OFF
* then log not run and return false.
* </pre>
*
* Used by java directly initiated by a cron.
*
* @param callingContext
* calling context for the application.
* @return true if context is ON; false otherwise.
*/
public boolean setAppContext(Object callingContext) {
String contextVar = setAppContextVar(callingContext, false);
boolean isOn = getBoolean(contextVar, true);
if (logger.isWarnEnabled()) {
StringBuilder sb = new StringBuilder(
"App Execution Token for App Context ");
sb.append(contextVar);
sb.append(" is ");
sb.append(isOn);
logger.warn(sb.toString());
}
return isOn;
}
/**
* <pre>
* If no token is defined for the expected app context
* or if the token is defined and is ON
* then log run and return true.
*
* If the token is defined and is OFF
* then log not run and return false.
* </pre>
*
* Used by java that was not directly initiated by a cron.
*
* @param callingContext
* calling context for the application.
* @return true if context is ON; false otherwise.
*/
public boolean checkAppContext(Object callingContext) {
String contextVar = setAppContextVar(callingContext, true);
boolean isOn = getBoolean(contextVar, true);
if (logger.isWarnEnabled()) {
StringBuilder sb = new StringBuilder(
"App Execution Token for App Context ");
sb.append(contextVar);
sb.append(" is ");
sb.append(isOn);
logger.warn(sb.toString());
}
return isOn;
}
/**
* Set and return the APP_CONTEXT variable.
*
* <pre>
* Example:
* APP_CONTEXT for class C called by class B
* which was called by class A:
* ClassA___ClassB___ClassC
* </pre>
*
* @param callingContext
* @param useParentContext
* @return context name
*/
private String setAppContextVar(Object callingContext,
boolean useParentContext) {
String context = callingContext.getClass().getSimpleName();
if (useParentContext) {
String existingContext = System.getProperty(APP_CONTEXT, context);
// Check if this context is a part of the existing context
if (!existingContext.endsWith(context)) {
StringBuilder sb = new StringBuilder(existingContext);
context = sb.append(".").append(context).toString();
} else {
context = existingContext;
}
}
System.setProperty(APP_CONTEXT, context);
return context;
}
/**
* Set the APP_CONTEXT variable in the processBuilder environment.
*
* <pre>
* Example:
* APP_CONTEXT for class C called by class B
* which was called by class A:
* ClassA___ClassB___ClassC
* </pre>
*
* @param processBuilder
*/
public void setAppContext(ProcessBuilder processBuilder) {
String appContextVar = System.getProperty(APP_CONTEXT);
if (appContextVar != null) {
processBuilder.environment().put(APP_CONTEXT, appContextVar);
}
}
} // end class AppsDefaults

View file

@ -124,6 +124,7 @@
#07/07/08 - Added sshp_show_unadjusted_states // for sshp
#
#10/01/09 - Added 5 tokens for arcnav application. //only for arcnav for raxum application
#10/03/12 - Added token section for script execution
# ==============================================================================
@ -157,6 +158,27 @@ vsys_dir : $(apps_dir)/rfc/verify #base verify directory
#AWIPS_MODIFICATION_BLOCK_END
#===================== Apps/Script Execution Tokens =================================
WhfsSrv : ON
WhfsSrv.purge_files : ON
WhfsSrv.run_db_purge : ON
WhfsSrv.run_floodseq : ON
PprocSrv : ON
PprocSrv.purge_mpe_files : ON
PprocSrv.purge_hpe_file : ON
MpeFieldGenSrv.run_mpe_fieldgen : ON
WhfsSrv.run_pdc_pp : ON
WhfsSrv.run_alarm_whfs : ON
WhfsSrv.run_alarm_whfs.run_roc_checker : ON
WhfsSrv.run_alarm_whfs.run_report_alarm : ON
WhfsSrv.run_alarm_whfs.run_report_alarm.textdb : ON
ArealQpeGenSrv : ON
DqcPreProcSrv : ON
DqcPreProcSrv.run_dqc_preprocessor : ON
MpeRUCFreezingLevel : ON
MpeLightningSrv : ON
#====================================================================================
# ==============================================================================
# Executable directory tokens.

View file

@ -21,15 +21,21 @@ package com.raytheon.uf.edex.esb.camel;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@ -59,6 +65,8 @@ import com.raytheon.uf.edex.esb.camel.spring.EdexModesContainer;
* Jul 14, 2009 #2950 njensen Basic spring file ordering
* Apr 5, 2010 #3857 njensen Removed file ordering in favor of
* spring's depends-on attribute
* Oct 19, 2012 #1274 bgonzale Load properties from files in conf
* resources directory.
*
* </pre>
*
@ -84,8 +92,40 @@ public class Executor {
List<String> xmlFiles = new ArrayList<String>();
List<File> propertiesFiles = new ArrayList<File>();
File confDir = new File(System.getProperty("edex.home")
+ File.separator + "conf");
File resourcesDir = new File(confDir, "resources");
propertiesFiles.addAll(Arrays.asList(findFiles(resourcesDir,
".properties")));
// load site files after loading the config files so that their
// properties take precedence.
String site = System.getProperty("aw.site.identifier");
File siteResourcesDir = new File(confDir, "resources" + File.separator
+ "site" + File.separator + site);
propertiesFiles.addAll(Arrays.asList(findFiles(siteResourcesDir,
".properties")));
// Add each file to the system properties
for (File propertiesFile : propertiesFiles) {
InputStream is = null;
Reader reader = null;
try {
is = new FileInputStream(propertiesFile);
reader = new InputStreamReader(is);
Properties properties = new Properties();
properties.load(reader);
System.getProperties().putAll(properties);
} finally {
if (reader != null) {
reader.close();
}
if (is != null) {
is.close();
}
}
}
File springDir = new File(confDir, "spring");
File[] springFiles = springDir.listFiles(new FileFilter() {
@ -180,6 +220,28 @@ public class Executor {
}
}
/**
* Finds all files in the specified directory with specified extension.
*
* @param directory
* the directory
* @param extension
* file extension
* @return the file array
*/
private static File[] findFiles(File directory, final String extension) {
File[] files = directory.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.getName().endsWith(extension);
}
});
// If no files were found return an empty array
return (files == null) ? new File[0] : files;
}
private static String printList(List<String> components) {
StringBuffer sb = new StringBuffer();
boolean first = true;

View file

@ -0,0 +1,11 @@
#crontab values
logfilepurger.cron=0+1+1,5,9,13,17,21+*+*+?
ihfsdbpurge.cron=0+45+7+*+*+?
floodarchiver.cron=0+30+6+*+*+?
mpehpefilepurge.cron=0+1+12+*+*+?
mpefieldgen.cron=0+25+*+*+*+?
pointdataretrieval.cron=0+2,17,32,47+*+*+*+?
alarmwhfs.cron=0+7,17,27,37,47,57+*+*+*+?
arealqpegen.cron=0+10,25,40,55+*+*+*+?
dqcpreprocessor.cron=0+20+0,6,12,18+*+*+?
mpelightningsrv.cron=0+0/30+*+*+*+?

View file

@ -30,6 +30,7 @@ import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.raytheon.uf.common.ohd.AppsDefaults;
import com.raytheon.uf.edex.core.props.PropertiesFactory;
/**
@ -49,6 +50,7 @@ import com.raytheon.uf.edex.core.props.PropertiesFactory;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 28, 2008 jelkins Initial creation
* Oct 19, 2012 #1274 bgonzale Set AppContext on the process builder in ctor.
* </pre>
*
* @author jelkins
@ -57,272 +59,273 @@ import com.raytheon.uf.edex.core.props.PropertiesFactory;
public class MainMethod extends Process {
protected Log log;
protected Log log;
private ProcessBuilder processBuilder;
private ProcessBuilder processBuilder;
private Process process;
private Process process;
private BufferedReader fromStdOut;
private BufferedReader fromStdOut;
private BufferedReader fromStdErr;
private BufferedReader fromStdErr;
/**
* Contains the initial command used to initialize the process. This field
* is useful to use when overriding the start method like in the RocChecker
* and RpfBatch classes.
*/
protected ArrayList<String> initialCommand;
/**
* Contains the initial command used to initialize the process. This field
* is useful to use when overriding the start method like in the RocChecker
* and RpfBatch classes.
*/
protected ArrayList<String> initialCommand;
/**
* Thrown when the process has not yet been started.
* <p>
* Make sure to call start()!
*/
public class ProcessNotStartedException extends RuntimeException {
/**
* Thrown when the process has not yet been started.
* <p>
* Make sure to call start()!
*/
public class ProcessNotStartedException extends RuntimeException {
private static final long serialVersionUID = 5620316335774758460L;
private static final long serialVersionUID = 5620316335774758460L;
}
}
/**
* Run a program
*
* @param args
* The first argument in the string list _must_ be only the
* command without any arguments. The arguments to the command
* are given by proceeding elements in the argument string list.
* @return The return value of the program.
*/
public static int runProgram(String... args) {
MainMethod program = new MainMethod(new ProcessBuilder(args));
return program.execute();
}
/**
* Run a program
*
* @param args
* The first argument in the string list _must_ be only the
* command without any arguments. The arguments to the command
* are given by proceeding elements in the argument string list.
* @return The return value of the program.
*/
public static int runProgram(String... args) {
MainMethod program = new MainMethod(new ProcessBuilder(args));
return program.execute();
}
/**
* Default constructor
* <P>
* Constructs a main method process from the given class.
*
* @param arguments
* the string of arguments to pass to the main process
*/
public MainMethod(ProcessBuilder builder) {
/**
* Default constructor
* <P>
* Constructs a main method process from the given class.
*
* @param arguments
* the string of arguments to pass to the main process
*/
public MainMethod(ProcessBuilder builder) {
this.processBuilder = builder;
this.log = LogFactory.getLog(processBuilder.getClass());
this.processBuilder = builder;
this.log = LogFactory.getLog(processBuilder.getClass());
try {
processBuilder.environment().put(
"apps_dir",
new File(PropertiesFactory.getInstance().getEnvProperties()
.getEnvValue("SHAREDIR")
+ File.separator + "hydroapps").getCanonicalPath());
} catch (IOException e) {
log.error("Unable to get apps_dir", e);
}
try {
processBuilder.environment().put(
"apps_dir",
new File(PropertiesFactory.getInstance().getEnvProperties()
.getEnvValue("SHAREDIR")
+ File.separator + "hydroapps").getCanonicalPath());
AppsDefaults.getInstance().setAppContext(processBuilder);
} catch (IOException e) {
log.error("Unable to get apps_dir", e);
}
this.initialCommand = new ArrayList<String>(getProcessBuilder()
.command());
this.initialCommand = new ArrayList<String>(getProcessBuilder()
.command());
}
}
/**
* Execute the method.
* <p>
*
* @return the exit value of the method. Usually 0 if nothing went wrong.
*/
public int execute() {
int exitValue = 0;
// Start the main method
this.start();
try {
this.waitFor();
} catch (InterruptedException e) {
log.error("Native process interrupted!!", e);
} finally {
exitValue = this.exitValue();
this.closeStreams();
this.destroy();
}
/**
* Execute the method.
* <p>
*
* @return the exit value of the method. Usually 0 if nothing went wrong.
*/
public int execute() {
int exitValue = 0;
// Start the main method
this.start();
try {
this.waitFor();
} catch (InterruptedException e) {
log.error("Native process interrupted!!", e);
} finally {
exitValue = this.exitValue();
this.closeStreams();
this.destroy();
}
if (exitValue != 0) {
StringBuffer error = new StringBuffer();
for (int i = 0; i < processBuilder.command().size(); i++) {
error.append(processBuilder.command().get(i)).append(" ");
}
error.append("failed with exit code "+exitValue);
log.error(error);
}
if (exitValue != 0) {
StringBuffer error = new StringBuffer();
for (int i = 0; i < processBuilder.command().size(); i++) {
error.append(processBuilder.command().get(i)).append(" ");
}
error.append("failed with exit code " + exitValue);
log.error(error);
}
return exitValue;
}
return exitValue;
}
/**
* Get the processBuilder object of this process
* <p>
*
* @return the processBuilder
*/
public ProcessBuilder getProcessBuilder() {
return processBuilder;
}
/**
* Get the processBuilder object of this process
* <p>
*
* @return the processBuilder
*/
public ProcessBuilder getProcessBuilder() {
return processBuilder;
}
/**
* Start the process.
* <p>
* Output that would normally be written to stdout and stderror are
* redirected to the log.
*/
private void start() {
try {
process = processBuilder.start();
/**
* Start the process.
* <p>
* Output that would normally be written to stdout and stderror are
* redirected to the log.
*/
private void start() {
try {
process = processBuilder.start();
// TODO seperate the stream readers into threads
// TODO seperate the stream readers into threads
// redirect the normal output to log as info
fromStdOut = new BufferedReader(new InputStreamReader(process
.getInputStream()));
// redirect the normal error to log as error
fromStdErr = new BufferedReader(new InputStreamReader(process
.getErrorStream()));
// redirect the normal output to log as info
fromStdOut = new BufferedReader(new InputStreamReader(
process.getInputStream()));
// redirect the normal error to log as error
fromStdErr = new BufferedReader(new InputStreamReader(
process.getErrorStream()));
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
/**
* @param br
* @return
*/
private String read(BufferedReader br) {
StringBuffer returnString = new StringBuffer();
String line;
try {
while ((line = br.readLine()) != null) {
returnString.append(line).append("\n");
}
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return returnString.toString();
}
/**
* @param br
* @return
*/
private String read(BufferedReader br) {
StringBuffer returnString = new StringBuffer();
String line;
try {
while ((line = br.readLine()) != null) {
returnString.append(line).append("\n");
}
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return returnString.toString();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#destroy()
*/
@Override
public void destroy() {
if (process == null) {
throw new ProcessNotStartedException();
}
process.destroy();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#destroy()
*/
@Override
public void destroy() {
if (process == null) {
throw new ProcessNotStartedException();
}
process.destroy();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#exitValue()
*/
@Override
public int exitValue() {
if (process == null) {
throw new ProcessNotStartedException();
}
return process.exitValue();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#exitValue()
*/
@Override
public int exitValue() {
if (process == null) {
throw new ProcessNotStartedException();
}
return process.exitValue();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#getErrorStream()
*/
@Override
public InputStream getErrorStream() {
if (process == null) {
throw new ProcessNotStartedException();
}
return process.getErrorStream();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#getErrorStream()
*/
@Override
public InputStream getErrorStream() {
if (process == null) {
throw new ProcessNotStartedException();
}
return process.getErrorStream();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#getInputStream()
*/
@Override
public InputStream getInputStream() {
if (process == null) {
throw new ProcessNotStartedException();
}
return process.getInputStream();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#getInputStream()
*/
@Override
public InputStream getInputStream() {
if (process == null) {
throw new ProcessNotStartedException();
}
return process.getInputStream();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#getOutputStream()
*/
@Override
public OutputStream getOutputStream() {
if (process == null) {
throw new ProcessNotStartedException();
}
return process.getOutputStream();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#getOutputStream()
*/
@Override
public OutputStream getOutputStream() {
if (process == null) {
throw new ProcessNotStartedException();
}
return process.getOutputStream();
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#waitFor()
*/
@Override
public int waitFor() throws InterruptedException {
if (process == null) {
throw new ProcessNotStartedException();
}
int retVal = process.waitFor();
String stdOut = read(fromStdOut);
String stdErr = read(fromStdErr);
if (!stdOut.isEmpty()) {
log.info(stdOut);
}
if (!stdErr.isEmpty()) {
log.error(stdErr);
}
return retVal;
}
/*
* (non-Javadoc)
*
* @see java.lang.Process#waitFor()
*/
@Override
public int waitFor() throws InterruptedException {
if (process == null) {
throw new ProcessNotStartedException();
}
int retVal = process.waitFor();
String stdOut = read(fromStdOut);
String stdErr = read(fromStdErr);
if (!stdOut.isEmpty()) {
log.info(stdOut);
}
if (!stdErr.isEmpty()) {
log.error(stdErr);
}
return retVal;
}
public void closeStreams() {
try {
if (this.getInputStream() != null) {
this.getInputStream().close();
}
} catch (IOException e) {
log.error("Unable to close input stream! Resource leak possible.",
e);
}
try {
if (this.getOutputStream() != null) {
this.getOutputStream().close();
}
} catch (IOException e) {
log.error("Unable to close output stream! Resource leak possible",
e);
}
public void closeStreams() {
try {
if (this.getInputStream() != null) {
this.getInputStream().close();
}
} catch (IOException e) {
log.error("Unable to close input stream! Resource leak possible.",
e);
}
try {
if (this.getOutputStream() != null) {
this.getOutputStream().close();
}
} catch (IOException e) {
log.error("Unable to close output stream! Resource leak possible",
e);
}
try {
if (this.getErrorStream() != null) {
this.getErrorStream().close();
}
} catch (IOException e) {
log.error("Unable to close error stream! Resource leadk possible",
e);
}
}
try {
if (this.getErrorStream() != null) {
this.getErrorStream().close();
}
} catch (IOException e) {
log.error("Unable to close error stream! Resource leadk possible",
e);
}
}
}

View file

@ -260,128 +260,134 @@ public class ArealQpeGenSrv {
// gribit environment vars
Map<String, String> envVars = new HashMap<String, String>();
envVars.put("grib_in_dir", gaq_temp_xmrg_dir);
envVars.put("grib_out_dir", gaq_temp_xmrg_dir);
envVars.put("grib_set_subcenter_0", "on");
if (AppsDefaults.getInstance().setAppContext(this)) {
envVars.put("grib_in_dir", gaq_temp_xmrg_dir);
envVars.put("grib_out_dir", gaq_temp_xmrg_dir);
envVars.put("grib_set_subcenter_0", "on");
String pproc_bin = appsDefaults.getToken("pproc_bin");
MainMethod m = new MainMethod(new ProcessBuilder(pproc_bin + "/"
+ GRIBIT));
String pproc_bin = appsDefaults.getToken("pproc_bin");
MainMethod m = new MainMethod(new ProcessBuilder(pproc_bin
+ "/" + GRIBIT));
for (File fr : fa) {
String inFile = "";
String gribOutFile = "";
inFile = fr.getName();
gribOutFile = inFile + ".grib";
envVars.put("grib_in_file", inFile);
envVars.put("grib_out_file", gribOutFile);
if (envVars != null) {
m.getProcessBuilder().environment().putAll(envVars);
}
int exitValue = m.execute();
for (File fr : fa) {
String inFile = "";
String gribOutFile = "";
inFile = fr.getName();
gribOutFile = inFile + ".grib";
envVars.put("grib_in_file", inFile);
envVars.put("grib_out_file", gribOutFile);
if (envVars != null) {
m.getProcessBuilder().environment().putAll(envVars);
}
int exitValue = m.execute();
// Output result
if (exitValue == 0) {
log.info("Areal QPE wrote output grib file: " + gribOutFile);
} else {
log.error("Areal QPE grib file out process terminated with exit code: "
+ exitValue);
return;
}
// Output result
if (exitValue == 0) {
log.info("Areal QPE wrote output grib file: "
+ gribOutFile);
} else {
log.error("Areal QPE grib file out process terminated with exit code: "
+ exitValue);
return;
}
try {
RandomAccessFile raf = new RandomAccessFile(new File(
fr.getParentFile(), gribOutFile), "rw");
raf.seek(0);
try {
RandomAccessFile raf = new RandomAccessFile(new File(
fr.getParentFile(), gribOutFile), "rw");
raf.seek(0);
int idx = 0;
byte b = raf.readByte();
int idx = 0;
byte b = raf.readByte();
boolean found = false;
while (!found) {
if (b == (byte) 'G') {
b = raf.readByte();
if (b == (byte) 'R') {
boolean found = false;
while (!found) {
if (b == (byte) 'G') {
b = raf.readByte();
if (b == (byte) 'I') {
if (b == (byte) 'R') {
b = raf.readByte();
if (b == (byte) 'B') {
found = true;
if (b == (byte) 'I') {
b = raf.readByte();
if (b == (byte) 'B') {
found = true;
} else {
idx += 3;
}
} else {
idx += 3;
idx += 2;
}
} else {
idx += 2;
idx += 1;
}
} else {
idx += 1;
b = raf.readByte();
}
} else {
idx += 1;
b = raf.readByte();
}
// Index 8 bytes for Section 0 of grib spec, and 5 bytes
// for
// Section 1 of grib spec to get to gen process id index
idx += (8 + 5);
// Increment gen process id
raf.seek(idx);
byte gpid = raf.readByte();
raf.seek(idx);
raf.writeByte(gpid + 1);
raf.close();
} catch (Exception e) {
log.error("Error modifying grib output file", e);
return;
}
String newFname = fr.getName() + ".grib";
File mvFile = new File(gaq_grib_dir + "/" + newFname);
File goFile = new File(gaq_temp_xmrg_dir + "/"
+ gribOutFile);
Date dt = new Date();
Calendar cc = Calendar.getInstance(TimeZone
.getTimeZone("GMT"));
cc.setTime(dt);
SimpleDateFormat ffn = new SimpleDateFormat("ddHHmmss");
String dString = ffn.format(cc.getTime());
File gribIngestFile = new File(d2d_input_dir
+ File.separator + "arealQpeGenSrv"
+ File.separator + fr.getName() + "_" + dString
+ ".grib");
log.info("Move and rename grib file " + goFile + " to "
+ mvFile);
boolean fmv = goFile.renameTo(mvFile);
// The move failed. Remove the grib file.
if (fmv == false) {
log.error("Move and rename grib file " + goFile
+ " to " + mvFile + " failed. ");
goFile.delete();
} else {
try {
FileUtil.copyFile(mvFile, gribIngestFile);
log.info("Copied grib file " + mvFile.getName()
+ " to " + d2d_input_dir + File.separator
+ "arealQpeGenSrv" + " for ingest to D2D. ");
} catch (IOException e) {
log.error("Copy grib file " + mvFile.getName()
+ " to " + d2d_input_dir + File.separator
+ "arealQpeGenSrv" + " failed. ");
e.printStackTrace();
}
}
// Index 8 bytes for Section 0 of grib spec, and 5 bytes for
// Section 1 of grib spec to get to gen process id index
idx += (8 + 5);
// Increment gen process id
raf.seek(idx);
byte gpid = raf.readByte();
raf.seek(idx);
raf.writeByte(gpid + 1);
raf.close();
} catch (Exception e) {
log.error("Error modifying grib output file", e);
return;
}
String newFname = fr.getName() + ".grib";
File mvFile = new File(gaq_grib_dir + "/" + newFname);
File goFile = new File(gaq_temp_xmrg_dir + "/" + gribOutFile);
Date dt = new Date();
Calendar cc = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cc.setTime(dt);
SimpleDateFormat ffn = new SimpleDateFormat("ddHHmmss");
String dString = ffn.format(cc.getTime());
File gribIngestFile = new File(d2d_input_dir + File.separator +
"arealQpeGenSrv" + File.separator
+ fr.getName() + "_" + dString + ".grib");
log.info("Move and rename grib file " + goFile + " to "
+ mvFile);
boolean fmv = goFile.renameTo(mvFile);
// The move failed. Remove the grib file.
if (fmv == false) {
log.error("Move and rename grib file " + goFile + " to "
+ mvFile + " failed. ");
goFile.delete();
} else {
try {
FileUtil.copyFile(mvFile, gribIngestFile);
log.info("Copied grib file " + mvFile.getName()
+ " to " + d2d_input_dir + File.separator +
"arealQpeGenSrv"
+ " for ingest to D2D. ");
} catch (IOException e) {
log.error("Copy grib file " + mvFile.getName() + " to "
+ d2d_input_dir + File.separator +
"arealQpeGenSrv" + " failed. ");
e.printStackTrace();
// Remove the xmrg file from the temp directory.
fr.delete();
if (log.isDebugEnabled()) {
log.debug("Removed file " + fr
+ " from rfcqpe_temp directory.");
}
mvFile = null;
goFile = null;
}
// Remove the xmrg file from the temp directory.
fr.delete();
if (log.isDebugEnabled()) {
log.debug("Removed file " + fr
+ " from rfcqpe_temp directory.");
}
mvFile = null;
goFile = null;
m = null;
}
m = null;
} else {
log.info("No QPE mosaic files found in " + gaq_temp_xmrg_dir);
Date dt = new Date();

View file

@ -59,26 +59,28 @@ public class DqcPreProcSrv {
}
int exitValue = 0;
if (dqcArg.matches(DAYS_ARG)) {
logger.info("Executing DQC Preprocessor with argument: " + dqcArg);
exitValue = MainMethod.runProgram("ksh", appsDefaults
.getToken("pproc_bin")
+ "/run_dqc_preprocessor", "-d" + dqcArg);
} else if (DAYS_ARG == null) {
logger
.info("Executing DQC Preprocessor with default number of days: "
+ defaultNumDays);
exitValue = MainMethod.runProgram("ksh", appsDefaults
.getToken("pproc_bin")
+ "/run_dqc_preprocessor", "-d" + defaultNumDays);
}
if (AppsDefaults.getInstance().setAppContext(this)) {
if (dqcArg.matches(DAYS_ARG)) {
logger.info("Executing DQC Preprocessor with argument: "
+ dqcArg);
exitValue = MainMethod.runProgram("ksh",
appsDefaults.getToken("pproc_bin")
+ "/run_dqc_preprocessor", "-d" + dqcArg);
} else if (DAYS_ARG == null) {
logger.info("Executing DQC Preprocessor with default number of days: "
+ defaultNumDays);
exitValue = MainMethod.runProgram("ksh",
appsDefaults.getToken("pproc_bin")
+ "/run_dqc_preprocessor", "-d"
+ defaultNumDays);
}
if (exitValue == 0) {
logger.info("DQC Preprocessor execution successful");
} else {
logger
.error("DQC Preprocessor terminated abnormally with exit code: "
+ exitValue);
if (exitValue == 0) {
logger.info("DQC Preprocessor execution successful");
} else {
logger.error("DQC Preprocessor terminated abnormally with exit code: "
+ exitValue);
}
}
return exitValue;
}

View file

@ -68,21 +68,23 @@ public class MpeFieldGenSrv {
}
int exitValue = 0;
if (mpeArg.matches(HOURS_ARG)) {
logger.info("Executing MPE FieldGen with argument: " + mpeArg);
exitValue = MainMethod.runProgram("ksh", appsDefaults
.getToken("pproc_bin")
+ "/run_mpe_fieldgen", mpeArg);
} else if (mpeArg.matches(HOURS_DATE_ARG)) {
logger.info("Executing MPE FieldGen with arguments: " + mpeArg);
Matcher matcher = HOURS_DATE_PATTERN.matcher(mpeArg);
if (matcher.find()) {
exitValue = MainMethod.runProgram("ksh", appsDefaults
.getToken("pproc_bin")
+ "/run_mpe_fieldgen", matcher.group(1), matcher
.group(2), matcher.group(3));
}
if (appsDefaults.setAppContext(this)) {
if (mpeArg.matches(HOURS_ARG)) {
logger.info("Executing MPE FieldGen with argument: " + mpeArg);
exitValue = MainMethod.runProgram("ksh",
appsDefaults.getToken("pproc_bin")
+ "/run_mpe_fieldgen", mpeArg);
} else if (mpeArg.matches(HOURS_DATE_ARG)) {
logger.info("Executing MPE FieldGen with arguments: " + mpeArg);
Matcher matcher = HOURS_DATE_PATTERN.matcher(mpeArg);
if (matcher.find()) {
exitValue = MainMethod.runProgram("ksh",
appsDefaults.getToken("pproc_bin")
+ "/run_mpe_fieldgen", matcher.group(1),
matcher.group(2), matcher.group(3));
}
}
}
if (exitValue == 0) {

View file

@ -325,6 +325,10 @@ public class MpeRUCFreezingLevel {
* Process the MPE freezing Levels
*/
public void processMpeRuc() {
if (!AppsDefaults.getInstance().setAppContext(this)) {
return;
}
Integer forecastHour = null;
HashMap<String, HashMap<Integer, FreezingLevelXML>> freezingTimeMap = new HashMap<String, HashMap<Integer, FreezingLevelXML>>();
LinkedHashMap<String, Coordinate> freezingStations = new LinkedHashMap<String, Coordinate>();

View file

@ -60,10 +60,12 @@ public class PprocSrv implements ServiceInterface {
@Override
public void execute() throws EdexException {
for (String script : serviceScripts) {
ScriptService s = new ScriptService(scriptDir + File.separatorChar
+ script);
s.execute();
if (AppsDefaults.getInstance().setAppContext(this)) {
for (String script : serviceScripts) {
ScriptService s = new ScriptService(scriptDir
+ File.separatorChar + script);
s.execute();
}
}
}
}

View file

@ -59,11 +59,13 @@ public class WhfsSrv implements ServiceInterface {
*/
@Override
public void execute() throws EdexException {
for (String script : serviceScripts) {
ScriptService s = new ScriptService(scriptDir + File.separatorChar
+ script);
s.execute();
if (AppsDefaults.getInstance().setAppContext(this)) {
s.execute();
}
}
}
}

View file

@ -0,0 +1,80 @@
#!/bin/sh
##
# 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.
##
# Script: check_app_Context
# Script that determines and sets the APP_CONTEXT variable for the
# calling script, and checks if the setting for that value is set to 'ON' or 'OFF'
# If off, this script will exit the calling script.
# get contextName from script name
oldIFS="$IFS"
IFS="/"
n=0
for element in ${0}
do
n=`expr $n + 1`
eval pathPart$n="$element"
done
eval contextName='$pathPart'$n
# parse off file extension if necessary
IFS="."
n=0
for element in $contextName
do
n=`expr $n + 1`
eval contextName="$element"
break
done
# if APP_CONTEXT is not set
if [ "${APP_CONTEXT:-NOTSET}" == "NOTSET" ]
then
eval APP_CONTEXT=${contextName}
else
# check if APP_CONTEXT ends with script's context
# if not, then append it
IFS="."
n=0
for element in $APP_CONTEXT
do
n=`expr $n + 1`
eval currentContextName="$element"
done
if [ "${currentContextName}" != "${contextName}" ]
then
APP_CONTEXT=${APP_CONTEXT}'.'${contextName}
fi
fi
IFS="${oldIFS}"
export APP_CONTEXT
# Determine if on or off from APP_CONTEXT. Default APP_CONTEXT is ON
eval APP_VAR=$(runso rary.ohd.util gad $APP_CONTEXT)
echo "App Execution Token for script ${contextName} with App Context ${APP_CONTEXT} is ${APP_VAR:-ON}"
# if set to not run, exit the calling script
if [ "${APP_VAR:-ON}" == "OFF" ]
then
echo "Script ${contextName} will exit and not run."
exit
fi

View file

@ -34,6 +34,8 @@ RUN_FROM_DIR=`dirname $0`
# set up some environment variables for WHFS applications
. $RUN_FROM_DIR/../../set_hydro_env
. $RUN_FROM_DIR/../../check_app_context
export LIGHTNING_LOG_DIR=$(get_apps_defaults lightning_log_dir)
export GAQ_LOG_DIR=$(get_apps_defaults gaq_log_dir)
export MPE_QPE_SBN_DIR=$(get_apps_defaults mpe_qpe_sbn_dir)

View file

@ -11,6 +11,8 @@ RUN_FROM_DIR=`dirname $0`
# Set up SOME environmental variables.
. $RUN_FROM_DIR/../../set_hydro_env
. $RUN_FROM_DIR/../../check_app_context
export MPE_EDITOR_LOGS_DIR=$(get_apps_defaults mpe_editor_logs_dir)
export PPROC_BIN=$(get_apps_defaults pproc_bin)

View file

@ -6,6 +6,8 @@ RUN_FROM_DIR=`dirname $0`
# set up SOME environment variables for WHFS applications
. $RUN_FROM_DIR/../../set_hydro_env
. $RUN_FROM_DIR/../../check_app_context
export SSHP_INVOKE_MAP_PREPROCESS=$(get_apps_defaults sshp_invoke_map_preprocess)
export SSHP_LOG_DIR=$(get_apps_defaults sshp_log_dir)
export MPE_GAGE_QC=$(get_apps_defaults mpe_gage_qc)

View file

@ -27,6 +27,8 @@ RUN_FROM_DIR=`dirname $0`
# set up SOME environment variables for WHFS applications
. $RUN_FROM_DIR/../../set_hydro_env
. $RUN_FROM_DIR/../../check_app_context
export GAGE_PP_DATA=$(get_apps_defaults gage_pp_data)
export GAGE_PP_LOG=$(get_apps_defaults gage_pp_log)
export SSHP_INGEST_XML_DIR=$(get_apps_defaults sshp_ingest_xml_dir)

View file

@ -12,6 +12,8 @@ RUN_FROM_DIR=`dirname $0`
# set up SOME environment variables for WHFS applications
. $RUN_FROM_DIR/../../set_hydro_env
. $RUN_FROM_DIR/../../check_app_context
export WHFS_UTIL_LOG_DIR=$(get_apps_defaults whfs_util_log_dir)
export WHFS_LOCAL_BIN_DIR=$(get_apps_defaults whfs_bin_dir)

View file

@ -7,6 +7,8 @@ RUN_FROM_DIR=`dirname $0`
# set up SOME environment variables for WHFS applications
. $RUN_FROM_DIR/../../set_hydro_env
. $RUN_FROM_DIR/../../check_app_context
export DB_PURGE_LOG_DIR=$(get_apps_defaults db_purge_log_dir)

View file

@ -6,6 +6,8 @@ RUN_FROM_DIR=`dirname $0`
# set up SOME environment variables for WHFS applications
. $RUN_FROM_DIR/../../set_hydro_env
. $RUN_FROM_DIR/../../check_app_context
export FLOODSEQ_LOG_DIR=$(get_apps_defaults floodseq_log_dir)
export WHFS_BIN_DIR=$(get_apps_defaults whfs_bin_dir)
export DB_NAME=$(get_apps_defaults db_name)

View file

@ -6,6 +6,8 @@ RUN_FROM_DIR=`dirname $0`
# set up SOME environment variables for WHFS applications
. $RUN_FROM_DIR/../../set_hydro_env
. $RUN_FROM_DIR/../../check_app_context
export PDC_PP_LOG_DIR=$(get_apps_defaults pdc_pp_log_dir)
export SYS_JAVA_DIR=$(get_apps_defaults sys_java_dir)
export WHFS_BIN_DIR=$(get_apps_defaults whfs_bin_dir)

View file

@ -15,6 +15,7 @@ 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)

View file

@ -8,6 +8,8 @@ RUN_FROM_DIR=`dirname $0`
# set up SOME environment variables for WHFS applications
# Source set_hydro_env from local bin
. $RUN_FROM_DIR/../../set_hydro_env
. $RUN_FROM_DIR/../../check_app_context
export WHFS_UTIL_LOG_DIR=$(get_apps_defaults whfs_util_log_dir)
export WHFS_BIN_DIR=$(get_apps_defaults whfs_bin_dir)
export DB_NAME=$(get_apps_defaults db_name)