Merge changes Id2d7981b,I094b88ed into omaha_13.4.1

* changes:
  Issue #1939: Update AlertVizApplication to start NotificationManagerJob
  Issue #1949: Fix Locks on D2D parms and setting of lastSentTime on histories


Former-commit-id: 1e94530814e28cc2a34cc92eab7164da3c3383e6
This commit is contained in:
Ron Anderson 2013-05-08 15:08:40 -05:00 committed by Gerrit Code Review
commit 65923ed892
7 changed files with 145 additions and 55 deletions

View file

@ -44,6 +44,7 @@ import com.raytheon.uf.viz.core.localization.CAVELocalizationNotificationObserve
import com.raytheon.uf.viz.core.localization.LocalizationConstants;
import com.raytheon.uf.viz.core.localization.LocalizationInitializer;
import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.uf.viz.core.notification.jobs.NotificationManagerJob;
/**
*
@ -55,6 +56,7 @@ import com.raytheon.uf.viz.core.localization.LocalizationManager;
* ------------ ---------- ----------- --------------------------
* Sep 29, 2008 #1433 chammack Initial creation
* Jan 12, 2012 #27 rferrel Added createAlertVisualization
* May 08, 2013 1939 rjpeter Updated to start NotificationManagerJob.
* </pre>
*
* @author chammack
@ -128,6 +130,10 @@ public class AlertVizApplication implements IStandaloneComponent {
// Job is not running on port, launch UI.
AlertVisualization av = createAlertVisualization(true, display);
// open JMS connection to allow alerts to be received
NotificationManagerJob.connect();
Throwable t = null;
try {
while (!display.isDisposed()) {
@ -164,6 +170,7 @@ public class AlertVizApplication implements IStandaloneComponent {
boolean runningStandalone, final Display display) {
return new AlertVisualization(runningStandalone, display);
}
protected void initializeObservers() {
CAVELocalizationNotificationObserver.register();
}

View file

@ -997,23 +997,29 @@ public class GFEDao extends DefaultPluginDao {
sess = getHibernateTemplate().getSessionFactory()
.openStatelessSession();
tx = sess.beginTransaction();
// use intersection of time range, UPDATE statement don't auto join
// table so have to manually select the id
Query query = sess
.createQuery("UPDATE GridDataHistory SET lastSentTime = ?"
+ " WHERE parent.parmId = ? AND parent.dataTime.validPeriod.start >= ?"
+ " AND parent.dataTime.validPeriod.end >= ?");
query.setParameter(0, parmId);
query.setTimestamp(1, tr.getStart());
+ " WHERE parent.id in (SELECT id FROM GFERecord "
+ " WHERE parmId = ?"
+ " AND dataTime.validPeriod.start < ?"
+ " AND dataTime.validPeriod.end > ?)");
query.setTimestamp(0, sentTime);
query.setParameter(1, parmId);
query.setTimestamp(2, tr.getEnd());
query.setTimestamp(3, tr.getStart());
query.executeUpdate();
// use intersection of time range
query = sess
.createQuery("SELECT hist.parent.dataTime.validPeriod, hist "
+ "FROM GridDataHistory hist"
+ " WHERE hist.parent.parmId = ? AND hist.parent.dataTime.validPeriod.start >= ?"
+ " AND hist.parent.dataTime.validPeriod.end >= ?");
+ " WHERE hist.parent.parmId = ? AND hist.parent.dataTime.validPeriod.start < ?"
+ " AND hist.parent.dataTime.validPeriod.end > ?");
query.setParameter(0, parmId);
query.setTimestamp(1, tr.getStart());
query.setTimestamp(2, tr.getEnd());
query.setTimestamp(1, tr.getEnd());
query.setTimestamp(2, tr.getStart());
rows = query.list();
tx.commit();
} catch (Exception e) {

View file

@ -75,8 +75,8 @@ public class GFELockDao extends CoreDao {
* If errors occur during database interaction
*/
@SuppressWarnings("unchecked")
public Map<ParmID, LockTable> getLocks(final List<ParmID> parmIds, WsId wsId)
throws DataAccessLayerException {
public Map<ParmID, LockTable> getLocks(final Collection<ParmID> parmIds,
WsId wsId) throws DataAccessLayerException {
// Return if no parmIDs are provided
if (parmIds.isEmpty()) {
return Collections.emptyMap();

View file

@ -34,11 +34,10 @@ import jep.JepException;
import com.raytheon.edex.plugin.gfe.config.GFESiteActivation;
import com.raytheon.edex.plugin.gfe.config.IFPServerConfig;
import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager;
import com.raytheon.edex.plugin.gfe.db.dao.GFEDao;
import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException;
import com.raytheon.edex.plugin.gfe.server.GridParmManager;
import com.raytheon.edex.plugin.gfe.server.database.GridDatabase;
import com.raytheon.edex.plugin.gfe.util.SendNotifications;
import com.raytheon.uf.common.dataplugin.PluginException;
import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID;
import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse;
@ -48,7 +47,6 @@ import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.TimeRange;
import com.raytheon.uf.edex.core.EDEXUtil;
import com.raytheon.uf.edex.database.plugin.PluginFactory;
/**
* Class to for running the isc scripts
@ -200,28 +198,25 @@ public class IscSendJob implements Runnable {
}
try {
// TODO: Interact with IFPGridDatabase
GFEDao dao = (GFEDao) PluginFactory.getInstance().getPluginDao(
"gfe");
ServerResponse<List<TimeRange>> sr = GridParmManager
.getGridInventory(id);
if (!sr.isOkay()) {
statusHandler.error("Error getting inventory for " + id);
return;
}
WsId wsId = new WsId(InetAddress.getLocalHost(), "ISC", "ISC");
GridDatabase gridDb = GridParmManager.getDb(id.getDbId());
ServerResponse<Map<TimeRange, List<GridDataHistory>>> sr = gridDb
.updateSentTime(id, tr, new Date());
if (sr.isOkay()) {
WsId wsId = new WsId(InetAddress.getLocalHost(), "ISC",
"ISC");
List<GridHistoryUpdateNotification> notifications = new ArrayList<GridHistoryUpdateNotification>(
1);
Map<TimeRange, List<GridDataHistory>> histories = dao
.updateSentTime(id, tr, new Date());
Map<TimeRange, List<GridDataHistory>> histories = sr
.getPayload();
notifications.add(new GridHistoryUpdateNotification(id,
histories, wsId, siteId));
SendNotifications.send(notifications);
} catch (PluginException e) {
statusHandler.error("Error creating GFE dao!", e);
} else {
statusHandler
.error("Error updating last sent times in GFERecords: "
+ sr.getMessages());
}
} catch (Exception e) {
statusHandler.error(
"Error updating last sent times in GFERecords.", e);

View file

@ -479,6 +479,24 @@ public abstract class GridDatabase {
+ this.getClass().getName());
}
/**
* Updates the sent time for all histories of passed parmId during the
* timeRange. The histories are then returned in a map by timeRange.
*
* @param parmId
* the parmId to use
* @param tr
* the time range to update sent time for
* @param sentTime
* the sent time to update to
* @return
*/
public ServerResponse<Map<TimeRange, List<GridDataHistory>>> updateSentTime(
final ParmID parmId, TimeRange tr, Date sentTime) {
throw new UnsupportedOperationException("Not implemented for class "
+ this.getClass().getName());
}
public ServerResponse<?> saveGridSlices(ParmID parmId, TimeRange tr,
List<IGridSlice> sliceData, WsId requestor,
List<TimeRange> skipDelete) {

View file

@ -2555,6 +2555,7 @@ public class IFPGridDatabase extends GridDatabase {
public ServerResponse<?> updatePublishTime(List<GridDataHistory> history,
Date publishTime) {
ServerResponse<?> sr = new ServerResponse<String>();
GFEDao dao = null;
try {
dao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe");
@ -2566,6 +2567,7 @@ public class IFPGridDatabase extends GridDatabase {
"Unable to update grid history!", e);
sr.addMessage("Error updating history");
}
return sr;
}
@ -2592,4 +2594,35 @@ public class IFPGridDatabase extends GridDatabase {
return rval;
}
/**
* Updates the sent time for all histories of passed parmId during the
* timeRange. The histories are then returned in a map by timeRange.
*
* @param parmId
* the parmId to use
* @param tr
* the time range to update sent time for
* @param sentTime
* the sent time to update to
* @return
*/
@Override
public ServerResponse<Map<TimeRange, List<GridDataHistory>>> updateSentTime(
final ParmID parmId, TimeRange tr, Date sentTime) {
ServerResponse<Map<TimeRange, List<GridDataHistory>>> sr = new ServerResponse<Map<TimeRange, List<GridDataHistory>>>();
try {
ParmID dbParmId = getCachedParmID(parmId);
GFEDao dao = new GFEDao();
sr.setPayload(dao.updateSentTime(dbParmId, tr, sentTime));
} catch (UnknownParmIdException e) {
sr.addMessage(e.getLocalizedMessage());
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Unable to update grid history last sent time", e);
sr.addMessage("Unable to update grid history last sent time");
}
return sr;
}
}

View file

@ -119,12 +119,41 @@ public class LockManager {
}
// extract the ParmIds from the request list
List<ParmID> parmIds = new ArrayList<ParmID>();
Set<ParmID> parmIds = new HashSet<ParmID>();
try {
sr.addMessages(extractParmIds(request, parmIds, siteID));
List<ParmID> nonIfpParmIds = new LinkedList<ParmID>();
sr.setPayload(new ArrayList<LockTable>(dao.getLocks(parmIds,
requestor).values()));
// remove parm IDs that are not persisted to database
Iterator<ParmID> iter = parmIds.iterator();
while (iter.hasNext()) {
ParmID id = iter.next();
if (id.getId() == 0) {
nonIfpParmIds.add(id);
iter.remove();
}
}
List<LockTable> payLoad = null;
if (!parmIds.isEmpty()) {
Map<ParmID, LockTable> lockMap = dao.getLocks(parmIds,
requestor);
payLoad = new ArrayList<LockTable>(lockMap.size()
+ nonIfpParmIds.size());
payLoad.addAll(lockMap.values());
} else {
payLoad = new ArrayList<LockTable>(nonIfpParmIds.size());
}
if (!nonIfpParmIds.isEmpty()) {
for (ParmID id : nonIfpParmIds) {
payLoad.add(new LockTable(id, new ArrayList<Lock>(0),
requestor));
}
}
sr.setPayload(payLoad);
} catch (Exception e) {
logger.error("Error getting lock tables for " + parmIds, e);
sr.addMessage("Error getting lock tables for " + parmIds);
@ -214,12 +243,22 @@ public class LockManager {
return sr;
}
List<ParmID> parmIds = new LinkedList<ParmID>();
Set<ParmID> parmIds = new HashSet<ParmID>();
Map<ParmID, LockTable> lockTableMap;
try {
// extract the ParmIds from the requests
sr.addMessages(extractParmIdsFromLockReq(req, parmIds, siteID));
Iterator<ParmID> iter = parmIds.iterator();
while (iter.hasNext()) {
ParmID id = iter.next();
// non persisted parm IDs cannot be locked
if (id.getId() == 0) {
sr.addMessage("ParmID " + id + " is not a lockable parm");
iter.remove();
}
}
// get the lock tables specific to the extracted parmIds
lockTableMap = dao.getLocks(parmIds, requestor);
} catch (Exception e) {
@ -681,14 +720,14 @@ public class LockManager {
* @throws GfeException
*/
private ServerResponse<?> extractParmIds(List<LockTableRequest> ltrList,
List<ParmID> parmIds, String siteID) throws GfeException {
Set<ParmID> parmIds, String siteID) throws GfeException {
ServerResponse<?> sr = new ServerResponse<String>();
// process each request
for (LockTableRequest ltr : ltrList) {
if (ltr.isParmRequest()) {
ParmID parmId = ltr.getParmId();
// append parm (if not already in the list)
// append parm (if not already in the set)
if (!parmIds.contains(parmId)) {
parmIds.add(GridParmManager.getDb(parmId.getDbId())
.getCachedParmID(parmId));
@ -697,11 +736,7 @@ public class LockManager {
// get all the parmIds for that databaseId
List<ParmID> pids = GridParmManager.getParmList(ltr.getDbId())
.getPayload();
for (ParmID id : pids) {
if (!parmIds.contains(id)) {
parmIds.add(id);
}
}
parmIds.addAll(pids);
} else {
// get all the parms for all the databases
List<DatabaseID> dbids = GridParmManager.getDbInventory(siteID)
@ -709,11 +744,7 @@ public class LockManager {
for (int j = 0; j < dbids.size(); j++) {
List<ParmID> pids = GridParmManager.getParmList(
dbids.get(j)).getPayload();
for (ParmID id : pids) {
if (!parmIds.contains(id)) {
parmIds.add(id);
}
}
parmIds.addAll(pids);
}
}
}
@ -738,7 +769,7 @@ public class LockManager {
* If errors occur
*/
private ServerResponse<?> extractParmIdsFromLockReq(List<LockRequest> lrs,
List<ParmID> parmIds, String siteID) throws GfeException {
Set<ParmID> parmIds, String siteID) throws GfeException {
ServerResponse<?> sr = new ServerResponse<String>();
// process each request