Issue #1949: Fix Locks on D2D parms and setting of lastSentTime on histories
Change-Id: I094b88ed190287881c5f0e340c801571c2e38651 Former-commit-id:ff60ca76f7
[formerly 0168cccd15ddb07988d946e3f4d719035dc63fb5] Former-commit-id:f59e4c9de9
This commit is contained in:
parent
c52c101f14
commit
30fc52f742
6 changed files with 134 additions and 51 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
|
||||
List<GridHistoryUpdateNotification> notifications = new ArrayList<GridHistoryUpdateNotification>(
|
||||
1);
|
||||
Map<TimeRange, List<GridDataHistory>> histories = dao
|
||||
GridDatabase gridDb = GridParmManager.getDb(id.getDbId());
|
||||
ServerResponse<Map<TimeRange, List<GridDataHistory>>> sr = gridDb
|
||||
.updateSentTime(id, tr, new Date());
|
||||
notifications.add(new GridHistoryUpdateNotification(id,
|
||||
histories, wsId, siteId));
|
||||
SendNotifications.send(notifications);
|
||||
} catch (PluginException e) {
|
||||
statusHandler.error("Error creating GFE dao!", e);
|
||||
if (sr.isOkay()) {
|
||||
WsId wsId = new WsId(InetAddress.getLocalHost(), "ISC",
|
||||
"ISC");
|
||||
List<GridHistoryUpdateNotification> notifications = new ArrayList<GridHistoryUpdateNotification>(
|
||||
1);
|
||||
Map<TimeRange, List<GridDataHistory>> histories = sr
|
||||
.getPayload();
|
||||
notifications.add(new GridHistoryUpdateNotification(id,
|
||||
histories, wsId, siteId));
|
||||
SendNotifications.send(notifications);
|
||||
|
||||
} 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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue