Merge branch 'master_14.3.1' into master_14.3.2
Former-commit-id:d2f4ae19cb
[formerly62eb3e7a36
[formerly dea7e3843165baa43bde3eeafd94329dc7fd98a7]] Former-commit-id:62eb3e7a36
Former-commit-id:9c374de355
This commit is contained in:
commit
6d00765e77
3 changed files with 130 additions and 111 deletions
|
@ -124,7 +124,7 @@ public class RadarServer implements RadarEventListener {
|
|||
addListener(new DedicatedRadarActivator(this));
|
||||
addListener(new RequestScheduler(this));
|
||||
addListener(new RadarServerAvailable(this));
|
||||
addListener(new RadarWatchdogListener(configuration));
|
||||
addListener(new RadarWatchdogListener(this));
|
||||
}
|
||||
|
||||
public void addListener(RadarEventListener l) {
|
||||
|
|
|
@ -29,7 +29,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.raytheon.rcm.config.Configuration;
|
||||
import com.raytheon.rcm.config.RadarConfig;
|
||||
import com.raytheon.rcm.server.StatusManager.RadarStatus;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -43,6 +44,8 @@ import com.raytheon.rcm.config.Configuration;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------- ---------- ----------- --------------------------
|
||||
* May 12, 2014 DR 16319 dhuffman Initial creation.
|
||||
* Feb 10, 2015 DR 17112 D. Friedman Only alarm on dedicated radars and
|
||||
* once per detected failure.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -56,18 +59,16 @@ public class RadarWatchdog extends Thread {
|
|||
|
||||
protected static class GsmItem {
|
||||
protected String radarID;
|
||||
protected int vcp;
|
||||
protected long time;
|
||||
protected long alarmTime;
|
||||
protected long nextAlarmTime;
|
||||
protected int trackedVcp;
|
||||
protected int currentVcp;
|
||||
protected boolean failed;
|
||||
|
||||
protected GsmItem() {
|
||||
}
|
||||
}
|
||||
|
||||
protected static class RadarItem {
|
||||
protected String radarID;
|
||||
protected String mnemonic;
|
||||
protected boolean isNew;
|
||||
protected long time;
|
||||
protected long messageTime;
|
||||
|
||||
|
@ -75,7 +76,10 @@ public class RadarWatchdog extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
private long startTime = 0;
|
||||
protected static class WatchedRadar {
|
||||
|
||||
}
|
||||
|
||||
private long shortestWait = 0;
|
||||
private static final long fudgeTime = 30;
|
||||
|
||||
|
@ -84,13 +88,13 @@ public class RadarWatchdog extends Thread {
|
|||
private static Map<Integer, Integer> mapDuration = new ConcurrentHashMap<Integer, Integer>();
|
||||
private static List<String> mapMnemonicProducts = new ArrayList<String>();
|
||||
|
||||
protected Configuration configuration;
|
||||
protected RadarServer radarServer;
|
||||
private static String configFileName = "radarWatchdog.txt";
|
||||
|
||||
protected RadarWatchdog(Configuration conf) {
|
||||
protected RadarWatchdog(RadarServer radarServer) {
|
||||
super("Watchdog");
|
||||
setDaemon(true);
|
||||
startTime = System.currentTimeMillis();
|
||||
configuration = conf;
|
||||
this.radarServer = radarServer;
|
||||
|
||||
loadConfigFile(configFileName);
|
||||
|
||||
|
@ -102,112 +106,145 @@ public class RadarWatchdog extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
public GsmItem getGSMItem(final String radarID) {
|
||||
return mapGSM.get(radarID);
|
||||
}
|
||||
|
||||
public void putGSMItem(GsmItem gi) {
|
||||
if (gi != null) {
|
||||
mapGSM.put(gi.radarID, gi);
|
||||
}
|
||||
}
|
||||
|
||||
public RadarItem getRadarItem(final String Mnemonic, final String radarID) {
|
||||
Map<String, RadarItem> mapRadar = mapMnemonic.get(Mnemonic);
|
||||
if (mapRadar != null)
|
||||
return mapRadar.get(radarID);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void putRadarItem(RadarItem ri) {
|
||||
if (ri != null) {
|
||||
Map<String, RadarItem> mapRadar = mapMnemonic.get(ri.mnemonic);
|
||||
if (mapRadar != null) {
|
||||
mapRadar.put(ri.radarID, ri);
|
||||
public synchronized void notifyGsm(String radarID, int vcp) {
|
||||
GsmItem item = mapGSM.get(radarID);
|
||||
if (item != null) {
|
||||
item.currentVcp = vcp;
|
||||
notifyWatchdog();
|
||||
} else {
|
||||
if (isTrackedRadar(radarID)) {
|
||||
item = new GsmItem();
|
||||
item.radarID = radarID;
|
||||
item.currentVcp = vcp;
|
||||
mapGSM.put(radarID, item);
|
||||
notifyWatchdog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isTrackedRadar(String radarID) {
|
||||
RadarConfig rc = radarServer.getConfiguration().getConfigForRadar(radarID);
|
||||
return rc != null && rc.isDedicated();
|
||||
}
|
||||
|
||||
public synchronized void notifyRadarItem(String radarID, String mnemonic, long messageTime, long time) {
|
||||
if (! isTrackedRadar(radarID))
|
||||
return;
|
||||
|
||||
RadarItem ri = getRadarItem(mnemonic, radarID);
|
||||
if (ri != null) {
|
||||
ri.isNew = false;
|
||||
ri.messageTime = messageTime;
|
||||
ri.time = time;
|
||||
}
|
||||
}
|
||||
|
||||
private RadarItem getRadarItem(final String mnemonic, final String radarID) {
|
||||
Map<String, RadarItem> mapRadar = mapMnemonic.get(mnemonic);
|
||||
if (mapRadar != null) {
|
||||
RadarItem ri = mapRadar.get(radarID);
|
||||
if (ri == null) {
|
||||
ri = new RadarItem();
|
||||
ri.isNew = true;
|
||||
mapRadar.put(radarID, ri);
|
||||
}
|
||||
return ri;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long currentTime = 0;
|
||||
shortestWait = 0;
|
||||
while (true) {
|
||||
|
||||
try {
|
||||
synchronized (semifore) {
|
||||
semifore.wait(shortestWait < 800 ? 800 : shortestWait);
|
||||
currentTime = System.currentTimeMillis();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
patrol(currentTime);
|
||||
patrol(System.currentTimeMillis());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void patrol(long currentTime) {
|
||||
private synchronized void patrol(long currentTime) {
|
||||
long duration = 0;
|
||||
long adjustedTime = currentTime - fudgeTime;
|
||||
shortestWait = 0;
|
||||
long earliestCheckTime = 0;
|
||||
Iterator<GsmItem> git = mapGSM.values().iterator();
|
||||
while (git.hasNext()) {
|
||||
GsmItem gi = git.next();
|
||||
if (mapDuration.get(gi.vcp) != null) {
|
||||
duration = mapDuration.get(gi.vcp) * 1000;
|
||||
|
||||
Iterator<String> mnem = mapMnemonicProducts.iterator();
|
||||
while (mnem.hasNext()) {
|
||||
String mn = mnem.next();
|
||||
Map<String, RadarItem> mapRadar = mapMnemonic.get(mn);
|
||||
if (mapRadar == null)
|
||||
continue;
|
||||
RadarItem ri = mapRadar.get(gi.radarID);
|
||||
if (! isTrackedRadar(gi.radarID)) {
|
||||
git.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ri == null) {
|
||||
if (duration + startTime < adjustedTime
|
||||
&& gi.alarmTime != startTime) {
|
||||
alert(duration, gi, mn);
|
||||
gi.alarmTime = startTime;
|
||||
gi.nextAlarmTime = startTime + duration;
|
||||
}
|
||||
|
||||
if (shortestWait < 1 || duration < shortestWait)
|
||||
shortestWait = duration;
|
||||
}
|
||||
/* There will be an alarm when the radar connection goes down, so
|
||||
* do not do any additional alarming.
|
||||
*/
|
||||
RadarStatus rs = radarServer.getStatusManager().getRadarStatus(gi.radarID);
|
||||
if (rs != null && rs.getCurrentGSM() == null) {
|
||||
gi.trackedVcp = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gi.currentVcp != gi.trackedVcp) {
|
||||
for (String mn : mapMnemonicProducts) {
|
||||
RadarItem ri = getRadarItem(mn, gi.radarID);
|
||||
if (ri != null) {
|
||||
ri.isNew = true;
|
||||
}
|
||||
}
|
||||
gi.trackedVcp = gi.currentVcp;
|
||||
}
|
||||
|
||||
if (ri.time + duration < adjustedTime) {
|
||||
if (ri.time <= gi.alarmTime
|
||||
&& gi.nextAlarmTime < currentTime) {
|
||||
alert(duration, gi, ri.mnemonic);
|
||||
gi.alarmTime = ri.time;
|
||||
gi.nextAlarmTime = currentTime + duration;
|
||||
}
|
||||
if (gi.nextAlarmTime < currentTime)
|
||||
gi.alarmTime = ri.time;
|
||||
}
|
||||
if (mapDuration.get(gi.trackedVcp) != null) {
|
||||
boolean allOk = true;
|
||||
duration = (mapDuration.get(gi.trackedVcp) + fudgeTime) * 1000;
|
||||
|
||||
if ((duration + ri.time) - adjustedTime < shortestWait
|
||||
&& 1 <= (duration + ri.time) - adjustedTime)
|
||||
shortestWait = (duration + ri.time) - adjustedTime;
|
||||
if (shortestWait < 1)
|
||||
shortestWait = duration;
|
||||
for (String mn : mapMnemonicProducts) {
|
||||
RadarItem ri = getRadarItem(mn, gi.radarID);
|
||||
if (ri == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ri.isNew) {
|
||||
ri.isNew = false;
|
||||
ri.time = currentTime;
|
||||
} else {
|
||||
long diff = currentTime - ri.time;
|
||||
if (diff < duration) {
|
||||
long nextTime = ri.time + duration;
|
||||
if (earliestCheckTime == 0 || nextTime < earliestCheckTime) {
|
||||
earliestCheckTime = nextTime;
|
||||
}
|
||||
} else {
|
||||
allOk = false;
|
||||
alert(duration, gi, mn);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allOk) {
|
||||
gi.failed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shortestWait = earliestCheckTime > 0 ? earliestCheckTime - currentTime : 0;
|
||||
}
|
||||
|
||||
private void alert(final long duration, final GsmItem gi, final String mn) {
|
||||
String AlertVizMessage = "Watchdog: Radar ";
|
||||
AlertVizMessage += gi.radarID + " has not produced a '" + mn
|
||||
+ "' product in the last " + duration / 1000 + " seconds.";
|
||||
RadarServerAvailable.sendNotification(gi.radarID, AlertVizMessage);
|
||||
if (! gi.failed) {
|
||||
gi.failed = true;
|
||||
String AlertVizMessage = "Watchdog: Radar ";
|
||||
AlertVizMessage += gi.radarID + " has not produced a '" + mn
|
||||
+ "' product in the last " + duration / 1000 + " seconds.";
|
||||
RadarServerAvailable.sendNotification(gi.radarID, AlertVizMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyWatchdog() {
|
||||
|
@ -218,7 +255,8 @@ public class RadarWatchdog extends Thread {
|
|||
|
||||
private boolean loadConfigFile(final String filename) {
|
||||
try {
|
||||
InputStream inFile = configuration.getDropInData(filename);
|
||||
InputStream inFile = radarServer.getConfiguration().
|
||||
getDropInData(filename);
|
||||
InputStreamReader reader = new InputStreamReader(inFile);
|
||||
BufferedReader in = new BufferedReader(reader);
|
||||
String line;
|
||||
|
|
|
@ -44,6 +44,8 @@ import com.raytheon.rcm.server.RadarWatchdog;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------- ---------- ----------- --------------------------
|
||||
* May 12, 2014 DR 16319 dhuffman Initial creation.
|
||||
* Feb 10, 2015 DR 17112 D. Friedman Only alarm on dedicated radars and
|
||||
* once per detected failure.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -61,8 +63,8 @@ public class RadarWatchdogListener extends RadarEventAdapter {
|
|||
mnemonicMap.put("HSW", "SW");
|
||||
}
|
||||
|
||||
public RadarWatchdogListener(Configuration configuration) {
|
||||
radarWatchdog = new RadarWatchdog(configuration);
|
||||
public RadarWatchdogListener(RadarServer radarServer) {
|
||||
radarWatchdog = new RadarWatchdog(radarServer);
|
||||
radarWatchdog.start();
|
||||
}
|
||||
|
||||
|
@ -81,25 +83,14 @@ public class RadarWatchdogListener extends RadarEventAdapter {
|
|||
}
|
||||
|
||||
if (gsm != null) {
|
||||
RadarWatchdog.GsmItem gi = new RadarWatchdog.GsmItem();
|
||||
gi.radarID = event.getRadarID();
|
||||
gi.vcp = gsm.vcp;
|
||||
gi.time = gsm.time.getTimeInMillis();
|
||||
|
||||
RadarWatchdog.GsmItem oldgi = radarWatchdog
|
||||
.getGSMItem(gi.radarID);
|
||||
if (oldgi == null
|
||||
|| (oldgi != null && oldgi.time <= gi.time)) {
|
||||
radarWatchdog.putGSMItem(gi);
|
||||
}
|
||||
radarWatchdog.notifyGsm(event.getRadarID(), gsm.vcp);
|
||||
}
|
||||
|
||||
} else if (16 <= messageCode) {
|
||||
int mcode = 0;
|
||||
PDB pdb = null;
|
||||
RadarWatchdog.RadarItem ri = new RadarWatchdog.RadarItem();
|
||||
mcode = Message.messageCodeOf(msg);
|
||||
ri.messageTime = (Message.decodeHeader(msg).time)
|
||||
long messageTime = (Message.decodeHeader(msg).time)
|
||||
.getTimeInMillis();
|
||||
|
||||
RadarProduct rp = ProductInfo.getInstance().getPoductForCode(
|
||||
|
@ -107,10 +98,9 @@ public class RadarWatchdogListener extends RadarEventAdapter {
|
|||
if (rp == null)
|
||||
return;
|
||||
|
||||
ri.mnemonic = rp.mnemonic;
|
||||
String newMnemonic = mnemonicMap.get(ri.mnemonic);
|
||||
if (newMnemonic != null)
|
||||
ri.mnemonic = newMnemonic;
|
||||
String mnemonic = mnemonicMap.get(rp.mnemonic);
|
||||
if (mnemonic == null)
|
||||
mnemonic = rp.mnemonic;
|
||||
|
||||
try {
|
||||
pdb = GraphicProduct.pdbOfMessage(msg);
|
||||
|
@ -120,17 +110,8 @@ public class RadarWatchdogListener extends RadarEventAdapter {
|
|||
}
|
||||
|
||||
if (pdb != null) {
|
||||
ri.radarID = event.getRadarID();
|
||||
ri.time = System.currentTimeMillis();
|
||||
|
||||
RadarWatchdog.RadarItem oldri = radarWatchdog.getRadarItem(
|
||||
ri.mnemonic, ri.radarID);
|
||||
|
||||
if (oldri == null
|
||||
|| (oldri != null && oldri.messageTime <= ri.messageTime)) {
|
||||
radarWatchdog.putRadarItem(ri);
|
||||
radarWatchdog.notifyWatchdog();
|
||||
}
|
||||
radarWatchdog.notifyRadarItem(event.getRadarID(), mnemonic,
|
||||
messageTime, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue