From 6f980bd582e8dd32ac3ada0b261de8b9ca2076b5 Mon Sep 17 00:00:00 2001 From: Ron Anderson Date: Mon, 21 Jan 2013 16:53:47 -0600 Subject: [PATCH] Issue #1504 GFE: Model data not always appearing automatically without CAVE restart Change-Id: I1e52c111ec50a860a226d85bed6f0ab6dfebed58 Former-commit-id: 20b076104894d86a0d4d34d52143f8e9f6ae662e [formerly 62671efc2a5d6f5021dd04ad00db9a2cecdc4d8e [formerly 1fe63a2d5e20226f6124a9ca27b9f6272c49226c]] Former-commit-id: 62671efc2a5d6f5021dd04ad00db9a2cecdc4d8e Former-commit-id: 74cb9aeb53c9b3c7acb5b08dcb45e23227383335 --- .../raytheon/viz/gfe/core/parm/DbParm.java | 10 +- .../common_static/base/python/gfe/ParmID.py | 18 -- .../res/spring/gfe-spring.xml | 4 +- .../gfe/cache/d2dparms/D2DParmIdCache.java | 174 +++++++++------ .../gfe/cache/d2dparms/D2DParmIdFilter.java | 8 +- .../edex/plugin/gfe/db/dao/GFEDao.java | 202 +++++++++--------- .../notify/GfeIngestNotificationFilter.java | 74 ++++--- .../res/spring/satellite-ingest.xml | 2 +- .../dataplugin/gfe/db/objects/DatabaseID.java | 37 +--- .../dataplugin/gfe/db/objects/ParmID.java | 43 +--- .../dataplugin/gfe/db/objects/ParmID.py | 24 +-- 11 files changed, 273 insertions(+), 323 deletions(-) diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/parm/DbParm.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/parm/DbParm.java index 688b4d7f7c..f431498906 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/parm/DbParm.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/parm/DbParm.java @@ -73,6 +73,7 @@ import com.raytheon.viz.gfe.core.griddata.IGridData; * to use IFPClient * 02/23/12 #346 dgilling Implement a dispose method. * 03/01/12 #346 dgilling Re-order dispose method. + * 01/21/12 #1504 randerso Cleaned up old debug logging to improve performance * * * @@ -411,6 +412,7 @@ public class DbParm extends Parm { // normal mode if (normal) { Arrays.sort(grids); + // Now replace the existing grids with the new ones replaceGrids(affectedTimeRange, grids); @@ -757,10 +759,10 @@ public class DbParm extends Parm { List lreq = new ArrayList(timesToSave.size()); for (int i = 0; i < timesToSave.size(); i++) { - String msg = "Reverting " + getParmID() + " tr=" - + timesToSave.get(i); - statusHandler.handle(Priority.DEBUG, msg, new Exception("Debug: " - + msg)); + // String msg = "Reverting " + getParmID() + " tr=" + // + timesToSave.get(i); + // statusHandler.handle(Priority.DEBUG, msg, new Exception("Debug: " + // + msg)); boolean success = true; IGridData[] grids = null; diff --git a/edexOsgi/build.edex/esb/data/utility/common_static/base/python/gfe/ParmID.py b/edexOsgi/build.edex/esb/data/utility/common_static/base/python/gfe/ParmID.py index 98e3fa95a6..ce04548b5b 100644 --- a/edexOsgi/build.edex/esb/data/utility/common_static/base/python/gfe/ParmID.py +++ b/edexOsgi/build.edex/esb/data/utility/common_static/base/python/gfe/ParmID.py @@ -97,24 +97,6 @@ class ParmID(JUtil.JavaWrapperClass): def getParmId(self): return self.__pid.getParmId() - def setParmName(self, parmName): - self.__pid.setParmName(parmName) - - def setParmLevel(self, parmLevel): - self.__pid.setParmLevel(parmLevel) - - def setDbId(self, dbId): - self.__pid.setDbId(dbId.toJavaObj()) - - def setCompositeName(self, compositeName): - self.__pid.setCompositeName(compositeName) - - def setShortParmId(self, shortParmId): - self.__pid.setShortParmId(shortParmId) - - def setParmId(self, parmId): - self.__pid.setParmId(parmId) - @staticmethod def shortSerializer(parmID): return JavaParmID.shortSerializer(parmID.javaParmId()) diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-spring.xml b/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-spring.xml index 2af6e8d17a..f2597f5447 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-spring.xml +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-spring.xml @@ -108,7 +108,7 @@ - + java.lang.Throwable @@ -130,7 +130,7 @@ - + diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdCache.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdCache.java index 18a71b834e..10b9435be1 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdCache.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdCache.java @@ -21,6 +21,7 @@ package com.raytheon.edex.plugin.gfe.cache.d2dparms; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -40,15 +41,18 @@ import com.raytheon.edex.plugin.gfe.server.database.D2DGridDatabase; import com.raytheon.edex.plugin.gfe.server.database.D2DSatDatabase; import com.raytheon.edex.plugin.gfe.server.database.D2DSatDatabaseManager; 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.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; -import com.raytheon.uf.common.parameter.mapping.ParameterMapper; +import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotification; +import com.raytheon.uf.common.message.WsId; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; -import com.raytheon.uf.common.util.mapping.MultipleMappingException; +import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.edex.database.DataAccessLayerException; import com.raytheon.uf.edex.site.SiteAwareRegistry; @@ -62,6 +66,10 @@ import com.raytheon.uf.edex.site.SiteAwareRegistry; * 01/08/09 1674 bphillip Initial creation * 11/05/12 #1310 dgilling Modify cache to listen to plugin * purged topic. + * 01/18/13 #1504 randerso Moved D2D to GFE parameter name translation from + * D2DParmIdCache toGfeIngestNotificationFilter. + * Added code to match wind components and send + * GridUpdateNotifications. * * * @author bphillip @@ -77,8 +85,19 @@ public class D2DParmIdCache { private static final Pattern RangeFilter = Pattern .compile("(.*?)\\d{1,2}hr"); + private static final Map WIND_COMP_PARMS; + static { + WIND_COMP_PARMS = new HashMap(); + WIND_COMP_PARMS.put("uw", "vw"); + WIND_COMP_PARMS.put("vw", "uw"); + WIND_COMP_PARMS.put("ws", "wd"); + WIND_COMP_PARMS.put("wd", "ws"); + } + /** Map containing the ParmIDs */ - private Map> parmIds; + private Map> parmIds; + + private Map> windComps; private static D2DParmIdCache instance; @@ -93,7 +112,8 @@ public class D2DParmIdCache { * Constructs a new D2DParmIdCache */ public D2DParmIdCache() { - parmIds = new HashMap>(); + parmIds = new HashMap>(); + windComps = new HashMap>(); } /** @@ -140,53 +160,18 @@ public class D2DParmIdCache { } private void putParmIDInternal(ParmID parmId) { + DatabaseID dbId = parmId.getDbId(); synchronized (parmIds) { + Set dbParms = parmIds.get(dbId); // Add the database entry to the map if it does not exist - if (!parmIds.containsKey(parmId.getDbId().toString())) { - parmIds.put(parmId.getDbId().toString(), new HashSet()); + if (dbParms == null) { + dbParms = new HashSet(); + parmIds.put(dbId, dbParms); } - // Insert the ParmID into the map - String parmStr = parmId.toString(); - // Ensure that the staticTopo parameter has the correct - // capitalization, or the smart init scripts will not be able to - // find it - String parmName = parmId.getParmName(); - if (parmName.equalsIgnoreCase("staticTopo")) { - parmStr = parmStr.replace("statictopo", "staticTopo"); - } else if (parmName.equalsIgnoreCase("staticspacing")) { - parmStr = parmStr.replace("staticspacing", "staticSpacing"); - } else if (parmName.equalsIgnoreCase("staticXspacing")) { - parmStr = parmStr.replace("staticxspacing", "staticXspacing"); - } else if (parmName.equalsIgnoreCase("staticYspacing")) { - parmStr = parmStr.replace("staticyspacing", "staticYspacing"); - } else if (parmName.equalsIgnoreCase("staticCoriolis")) { - parmStr = parmStr.replace("staticcoriolis", "staticCoriolis"); - } else { - String gfeParamName = null; - try { - gfeParamName = ParameterMapper.getInstance().lookupAlias( - parmId.getParmName(), "gfeParamName"); - } catch (MultipleMappingException e) { - statusHandler.handle(Priority.WARN, - e.getLocalizedMessage(), e); - gfeParamName = e.getArbitraryMapping(); - } - parmStr = parmStr.replaceFirst( - parmId.getParmName(), - gfeParamName); - } - parmIds.get(parmId.getDbId().toString()).add(parmStr); - } - } - /** - * Places a parmId into the cache - * - * @param parmId - * String representation of a ParmID - */ - public void putParmID(String parmId) { - putParmID(new ParmID(parmId)); + // Insert the ParmID into the map + dbParms.add(parmId); + } } /** @@ -209,18 +194,10 @@ public class D2DParmIdCache { * @return The ParmIDs in the given DatabaseID */ public List getParmIDs(DatabaseID dbId) { - Set parmStrings = null; + List parms = Collections.emptyList(); synchronized (parmIds) { if (parmIds.containsKey(dbId.toString())) { - parmStrings = new HashSet(parmIds.get(dbId.toString())); - } - } - - List parms = Collections.emptyList(); - if (parmStrings != null) { - parms = new ArrayList(parmStrings.size()); - for (String parmStr : parmStrings) { - parms.add(new ParmID(parmStr)); + parms = new ArrayList(parmIds.get(dbId)); } } return parms; @@ -244,14 +221,9 @@ public class D2DParmIdCache { * @return The list of DatabaseIDs */ public List getDatabaseIDs() { - Set dbStrs; + List dbIds = null; synchronized (parmIds) { - dbStrs = new HashSet(parmIds.keySet()); - } - - List dbIds = new ArrayList(dbStrs.size()); - for (String dbId : dbStrs) { - dbIds.add(new DatabaseID(dbId)); + dbIds = new ArrayList(parmIds.keySet()); } return dbIds; } @@ -382,6 +354,19 @@ public class D2DParmIdCache { for (DatabaseID dbId : dbsToRemove) { GridParmManager.removeDbFromMap(dbId); } + // purge the windComps + List wcToRemove = new ArrayList(); + synchronized (windComps) { + for (ParmID id : windComps.keySet()) { + if (dbsToRemove.contains(id.getDbId())) { + wcToRemove.add(id); + } + } + for (ParmID id : wcToRemove) { + windComps.remove(id); + } + } + statusHandler.handle(Priority.EVENTA, "Total time to build D2DParmIdCache for " + siteID + " took " + (System.currentTimeMillis() - start) @@ -397,7 +382,7 @@ public class D2DParmIdCache { public long getSize() { long size = 0; synchronized (parmIds) { - for (Set parms : parmIds.values()) { + for (Set parms : parmIds.values()) { size += parms.size(); } } @@ -410,4 +395,63 @@ public class D2DParmIdCache { buildCache(null); } } + + public void processGridUpdateNotification(GridUpdateNotification gun) { + ParmID parmId = gun.getParmId(); + + String otherCompName = WIND_COMP_PARMS.get(parmId.getParmName()); + if (otherCompName == null) { + // if it's not a wind component just add it to the cache + putParmID(parmId); + } else { + Set windTrs = null; + synchronized (windComps) { + // add this parms times to windComps map + Set trs = windComps.get(parmId); + if (trs == null) { + trs = new HashSet(); + windComps.put(parmId, trs); + } + trs.addAll(gun.getHistories().keySet()); + + // get the other components times + ParmID otherCompId = new ParmID(otherCompName, + parmId.getDbId(), parmId.getParmLevel()); + Set otherTrs = windComps.get(otherCompId); + + // if we have both components + if (otherTrs != null) { + // find times where we have both components + windTrs = new HashSet(trs); + windTrs.retainAll(otherTrs); + + // remove the matching times since we don't need them + // anymore + trs.removeAll(windTrs); + otherTrs.removeAll(windTrs); + } + } + + // if we found any matching times for both components + if (windTrs != null && !windTrs.isEmpty()) { + // add the wind parmId to the cache + ParmID windId = new ParmID("wind", parmId.getDbId(), + parmId.getParmLevel()); + putParmID(windId); + + // create GridUpdateNotifications for the wind parm + Map> history = new HashMap>(); + ArrayList guns = new ArrayList( + windTrs.size()); + for (TimeRange tr : windTrs) { + history.put(tr, Arrays.asList(new GridDataHistory( + GridDataHistory.OriginType.INITIALIZED, windId, tr, + null, (WsId) null))); + guns.add(new GridUpdateNotification(windId, tr, history, + null, windId.getDbId().getSiteId())); + } + SendNotifications.send(guns); + } + } + } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdFilter.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdFilter.java index eb523b9f93..c7096adedb 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdFilter.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdFilter.java @@ -34,7 +34,9 @@ import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotificatio * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 1/10/09 1674 bphillip Initial creation - * 10/06/09 3172 njensen Based on grib notification + * 10/06/09 3172 njensen Based on grib notification + * 01/18/13 #1504 randerso Changed to send full GridUpdateNotification + * to D2DParmIdCache * * * @@ -53,8 +55,8 @@ public class D2DParmIdFilter { public void updateParmIdCache(List notifications) { for (GfeNotification notify : notifications) { if (notify instanceof GridUpdateNotification) { - D2DParmIdCache.getInstance().putParmID( - ((GridUpdateNotification) notify).getParmId()); + D2DParmIdCache.getInstance().processGridUpdateNotification( + (GridUpdateNotification) notify); } } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java index 967a62f588..04ff02e012 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFEDao.java @@ -105,9 +105,11 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery; * 08/07/09 #2763 njensen Refactored queryByD2DParmId * 09/10/12 DR15137 ryu Changed for MOSGuide D2D mxt/mnt grids for consistency * with A1. - * 10/10/12 #1260 randerso Added check to ensure db can be created before + * 10/10/12 #1260 randerso Added check to ensure db can be created before * adding it to the inventory * 12/06/12 #1394 rjpeter Optimized D2D grid access. + * 01/21/12 #1504 randerso Back ported change to use ParameterMapper into 13.1.2 + * * * * @author bphillip @@ -321,13 +323,13 @@ public class GFEDao extends DefaultPluginDao { } if (sess != null) { try { - sess.close(); + sess.close(); } catch (Exception e) { statusHandler.error( "Error occurred closing database session", e); - } } } + } return failedToSave.toArray(new GFERecord[failedToSave.size()]); @@ -460,9 +462,9 @@ public class GFEDao extends DefaultPluginDao { dataStore.delete(groupsToDelete); if (statusHandler.isPriorityEnabled(Priority.DEBUG)) { - statusHandler.handle(Priority.DEBUG, - "Deleted: " + Arrays.toString(groupsToDelete) - + " from " + hdf5File.getName()); + statusHandler.handle(Priority.DEBUG, + "Deleted: " + Arrays.toString(groupsToDelete) + + " from " + hdf5File.getName()); } } catch (Exception e) { statusHandler.handle( @@ -657,10 +659,10 @@ public class GFEDao extends DefaultPluginDao { s = getHibernateTemplate().getSessionFactory().openSession(); // TODO: clean up so we only make one db query SortedMap rawTimes = queryByD2DParmId(id, s); - List gribTimes = new ArrayList(); + List gribTimes = new ArrayList(); for (DataTime dt : rawTimes.keySet()) { gribTimes.add(dt.getValidPeriod()); - } + } try { if (isMos(id)) { @@ -670,26 +672,26 @@ public class GFEDao extends DefaultPluginDao { .getValidPeriod(); TimeRange time = info.getTimeConstraints() .constraintTime(gribTime.getEnd()); - if (timeRange.getEnd().equals(time.getEnd()) - || !info.getTimeConstraints().anyConstraints()) { + if (timeRange.getEnd().equals(time.getEnd()) + || !info.getTimeConstraints().anyConstraints()) { GridRecord retVal = (GridRecord) s.get( GridRecord.class, timeEntry.getValue()); - retVal.setPluginName(GridConstants.GRID); - return retVal; - } + retVal.setPluginName(GridConstants.GRID); + return retVal; + } } } else if (D2DGridDatabase.isNonAccumDuration(id, gribTimes)) { for (Map.Entry timeEntry : rawTimes .entrySet()) { TimeRange gribTime = timeEntry.getKey() .getValidPeriod(); - if (timeRange.getStart().equals(gribTime.getEnd()) - || timeRange.equals(gribTime)) { + if (timeRange.getStart().equals(gribTime.getEnd()) + || timeRange.equals(gribTime)) { GridRecord retVal = (GridRecord) s.get( GridRecord.class, timeEntry.getValue()); - retVal.setPluginName(GridConstants.GRID); - return retVal; - } + retVal.setPluginName(GridConstants.GRID); + return retVal; + } } } else { for (Map.Entry timeEntry : rawTimes @@ -698,15 +700,15 @@ public class GFEDao extends DefaultPluginDao { .getValidPeriod(); TimeRange time = info.getTimeConstraints() .constraintTime(gribTime.getStart()); - if ((timeRange.getStart().equals(time.getStart()) || !info - .getTimeConstraints().anyConstraints())) { + if ((timeRange.getStart().equals(time.getStart()) || !info + .getTimeConstraints().anyConstraints())) { GridRecord retVal = (GridRecord) s.get( GridRecord.class, timeEntry.getValue()); - retVal.setPluginName(GridConstants.GRID); - return retVal; - } + retVal.setPluginName(GridConstants.GRID); + return retVal; } } + } } catch (GfeConfigurationException e) { throw new DataAccessLayerException( "Error getting configuration for " @@ -720,7 +722,7 @@ public class GFEDao extends DefaultPluginDao { statusHandler.error( "Error occurred closing database session", e); } - } + } } return null; @@ -743,48 +745,48 @@ public class GFEDao extends DefaultPluginDao { @SuppressWarnings("unchecked") public SortedMap queryByD2DParmId(ParmID id, Session s) throws DataAccessLayerException { - String levelName = GridTranslator.getLevelName(id.getParmLevel()); + String levelName = GridTranslator.getLevelName(id.getParmLevel()); double[] levelValues = GridTranslator.getLevelValue(id.getParmLevel()); - boolean levelOnePresent = (levelValues[0] != Level - .getInvalidLevelValue()); - boolean levelTwoPresent = (levelValues[1] != Level - .getInvalidLevelValue()); - Level level = null; + boolean levelOnePresent = (levelValues[0] != Level + .getInvalidLevelValue()); + boolean levelTwoPresent = (levelValues[1] != Level + .getInvalidLevelValue()); + Level level = null; - // to have a level 2, must have a level one - try { - if (levelOnePresent && levelTwoPresent) { - level = LevelFactory.getInstance().getLevel(levelName, - levelValues[0], levelValues[1]); - } else if (levelOnePresent) { - level = LevelFactory.getInstance().getLevel(levelName, - levelValues[0]); - } else { - level = LevelFactory.getInstance().getLevel(levelName, 0.0); + // to have a level 2, must have a level one + try { + if (levelOnePresent && levelTwoPresent) { + level = LevelFactory.getInstance().getLevel(levelName, + levelValues[0], levelValues[1]); + } else if (levelOnePresent) { + level = LevelFactory.getInstance().getLevel(levelName, + levelValues[0]); + } else { + level = LevelFactory.getInstance().getLevel(levelName, 0.0); + } + } catch (CommunicationException e) { + logger.error(e.getLocalizedMessage(), e); } - } catch (CommunicationException e) { - logger.error(e.getLocalizedMessage(), e); - } - if (level == null) { - logger.warn("Unable to query D2D parms, ParmID " + id - + " does not map to a level"); + if (level == null) { + logger.warn("Unable to query D2D parms, ParmID " + id + + " does not map to a level"); return new TreeMap(); - } + } SQLQuery modelQuery = s.createSQLQuery(SQL_D2D_GRID_PARM_QUERY); modelQuery.setLong("level_id", level.getId()); DatabaseID dbId = id.getDbId(); - try { - IFPServerConfig config = IFPServerConfigManager - .getServerConfig(dbId.getSiteId()); + try { + IFPServerConfig config = IFPServerConfigManager + .getServerConfig(dbId.getSiteId()); modelQuery.setString(GridInfoConstants.DATASET_ID, config.d2dModelNameMapping(dbId.getModelName())); - } catch (GfeConfigurationException e) { - throw new DataAccessLayerException( - "Error occurred looking up model name mapping", e); - } + } catch (GfeConfigurationException e) { + throw new DataAccessLayerException( + "Error occurred looking up model name mapping", e); + } String abbreviation = null; try { @@ -793,38 +795,38 @@ public class GFEDao extends DefaultPluginDao { } catch (MultipleMappingException e) { statusHandler.handle(Priority.WARN, e.getLocalizedMessage(), e); abbreviation = e.getArbitraryMapping(); - } + } - abbreviation = abbreviation.toLowerCase(); + abbreviation = abbreviation.toLowerCase(); modelQuery.setString("abbrev", abbreviation); modelQuery.setString("hourAbbrev", abbreviation + "%hr"); List results = modelQuery.list(); Integer modelId = null; - if (results.size() == 0) { + if (results.size() == 0) { return new TreeMap(); - } else if (results.size() > 1) { - // hours matched, take hour with least number that matches exact - // param - Pattern p = Pattern.compile("^" + abbreviation + "(\\d+)hr$"); - int lowestHr = -1; + } else if (results.size() > 1) { + // hours matched, take hour with least number that matches exact + // param + Pattern p = Pattern.compile("^" + abbreviation + "(\\d+)hr$"); + int lowestHr = -1; for (Object[] rows : (List) results) { String param = ((String) rows[0]).toLowerCase(); - if (param.equals(abbreviation) && (lowestHr < 0)) { + if (param.equals(abbreviation) && (lowestHr < 0)) { modelId = (Integer) rows[1]; - } else { - Matcher matcher = p.matcher(param); - if (matcher.matches()) { - int hr = Integer.parseInt(matcher.group(1)); - if ((lowestHr < 0) || (hr < lowestHr)) { + } else { + Matcher matcher = p.matcher(param); + if (matcher.matches()) { + int hr = Integer.parseInt(matcher.group(1)); + if ((lowestHr < 0) || (hr < lowestHr)) { modelId = (Integer) rows[1]; - lowestHr = hr; + lowestHr = hr; + } } } } - } - } else { + } else { modelId = (Integer) ((Object[]) results.get(0))[1]; - } + } Query timeQuery = s.createQuery(HQL_D2D_GRID_TIME_QUERY); timeQuery.setInteger("info_id", modelId); @@ -832,7 +834,7 @@ public class GFEDao extends DefaultPluginDao { List timeResults = timeQuery.list(); if (timeResults.isEmpty()) { return new TreeMap(); - } + } SortedMap dataTimes = new TreeMap(); for (Object[] rows : timeResults) { @@ -848,7 +850,7 @@ public class GFEDao extends DefaultPluginDao { try { s = getHibernateTemplate().getSessionFactory().openSession(); - if (id.getParmName().equalsIgnoreCase("wind")) { + if (id.getParmName().equalsIgnoreCase("wind")) { String idString = id.toString(); Matcher idWindMatcher = WIND_PATTERN.matcher(idString); @@ -858,53 +860,53 @@ public class GFEDao extends DefaultPluginDao { List uTimeList = new ArrayList( results.size()); for (DataTime o : results.keySet()) { - uTimeList.add(new TimeRange(o.getValidPeriod().getStart(), - 3600 * 1000)); - } + uTimeList.add(new TimeRange(o.getValidPeriod().getStart(), + 3600 * 1000)); + } ParmID vWindId = new ParmID(idWindMatcher.replaceAll("vW")); results = queryByD2DParmId(vWindId, s); Set vTimeList = new HashSet( results.size(), 1); for (DataTime o : results.keySet()) { - vTimeList.add(new TimeRange(o.getValidPeriod().getStart(), - 3600 * 1000)); - } + vTimeList.add(new TimeRange(o.getValidPeriod().getStart(), + 3600 * 1000)); + } - for (TimeRange tr : uTimeList) { - if (vTimeList.contains(tr)) { - timeList.add(new TimeRange(tr.getStart(), tr.getStart())); - } + for (TimeRange tr : uTimeList) { + if (vTimeList.contains(tr)) { + timeList.add(new TimeRange(tr.getStart(), tr.getStart())); } + } - if (!timeList.isEmpty()) { - return timeList; - } + if (!timeList.isEmpty()) { + return timeList; + } ParmID sWindId = new ParmID(idWindMatcher.replaceAll("ws")); results = queryByD2DParmId(sWindId, s); List sTimeList = new ArrayList( results.size()); for (DataTime o : results.keySet()) { - sTimeList.add(new TimeRange(o.getValidPeriod().getStart(), - 3600 * 1000)); - } + sTimeList.add(new TimeRange(o.getValidPeriod().getStart(), + 3600 * 1000)); + } ParmID dWindId = new ParmID(idWindMatcher.replaceAll("wd")); results = queryByD2DParmId(dWindId, s); Set dTimeList = new HashSet( results.size(), 1); for (DataTime o : results.keySet()) { - dTimeList.add(new TimeRange(o.getValidPeriod().getStart(), - 3600 * 1000)); - } + dTimeList.add(new TimeRange(o.getValidPeriod().getStart(), + 3600 * 1000)); + } - for (TimeRange tr : sTimeList) { - if (dTimeList.contains(tr)) { - timeList.add(new TimeRange(tr.getStart(), tr.getStart())); - } + for (TimeRange tr : sTimeList) { + if (dTimeList.contains(tr)) { + timeList.add(new TimeRange(tr.getStart(), tr.getStart())); } - } else { + } + } else { SortedMap results = queryByD2DParmId(id, s); if (isMos(id)) { for (DataTime o : results.keySet()) { @@ -913,10 +915,10 @@ public class GFEDao extends DefaultPluginDao { } } else { for (DataTime o : results.keySet()) { - timeList.add(o.getValidPeriod()); - } + timeList.add(o.getValidPeriod()); } } + } } finally { if (s != null) { try { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/notify/GfeIngestNotificationFilter.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/notify/GfeIngestNotificationFilter.java index 3a6e179a37..7324791473 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/notify/GfeIngestNotificationFilter.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/notify/GfeIngestNotificationFilter.java @@ -21,7 +21,6 @@ package com.raytheon.edex.plugin.gfe.server.notify; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -54,10 +53,13 @@ import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotificatio import com.raytheon.uf.common.dataplugin.grid.GridRecord; import com.raytheon.uf.common.dataplugin.satellite.SatelliteRecord; import com.raytheon.uf.common.message.WsId; +import com.raytheon.uf.common.parameter.mapping.ParameterMapper; import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.time.TimeRange; +import com.raytheon.uf.common.util.mapping.MultipleMappingException; import com.raytheon.uf.edex.core.EDEXUtil; /** @@ -71,6 +73,8 @@ import com.raytheon.uf.edex.core.EDEXUtil; * ------------ ---------- ----------- -------------------------- * Aug 12, 2011 dgilling Initial creation * Sep 19, 2012 jdynina DR 15442 fix + * Jan 18, 2013 #1504 randerso Moved D2D to GFE parameter name translation from + * D2DParmIdCache to GfeIngestNotificationFilter * * * @@ -80,7 +84,7 @@ import com.raytheon.uf.edex.core.EDEXUtil; public class GfeIngestNotificationFilter { - private static final transient IUFStatusHandler handler = UFStatus + private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(GfeIngestNotificationFilter.class); private SmartInitQueue smartInitQueue = null; @@ -106,8 +110,7 @@ public class GfeIngestNotificationFilter { } } - public void filterGridRecords(List gridRecords, - Date arrivalTime) + public void filterGridRecords(List gridRecords, Date arrivalTime) throws Exception { StringBuilder initNameBuilder = new StringBuilder(120); @@ -126,7 +129,8 @@ public class GfeIngestNotificationFilter { try { config = IFPServerConfigManager.getServerConfig(site); } catch (GfeConfigurationException e) { - handler.error("Unable to retrieve site config for " + site, e); + statusHandler.error("Unable to retrieve site config for " + + site, e); continue; } for (GridRecord grid : gridRecords) { @@ -152,24 +156,30 @@ public class GfeIngestNotificationFilter { } String abbrev = grid.getParameter().getAbbreviation(); - String level = GridTranslator.getShortLevelName( -grid - .getLevel().getMasterLevel().getName(), grid - .getLevel().getLevelonevalue(), grid.getLevel() - .getLeveltwovalue()); - ParmID parmID = new ParmID(abbrev, dbId, level); + String gfeParmName = null; + try { + gfeParmName = ParameterMapper.getInstance() + .lookupAlias(abbrev, "gfeParamName"); + } catch (MultipleMappingException e) { + statusHandler.handle(Priority.WARN, + e.getLocalizedMessage(), e); + gfeParmName = e.getArbitraryMapping(); + } - if (!gridInv.containsKey(parmID)) { - gridInv.put(parmID, new ArrayList()); + String level = GridTranslator.getShortLevelName(grid + ParmID parmID = new ParmID(gfeParmName, dbId, level); + + List trs = gridInv.get(parmID); + if (trs == null) { + trs = new ArrayList(); + gridInv.put(parmID, trs); } TimeRange validPeriod = grid.getDataTime().getValidPeriod(); if (validPeriod.getDuration() > 0) { - gridInv.get(parmID).add(validPeriod); + trs.add(validPeriod); } else { - gridInv.get(parmID).add( - new TimeRange(grid.getDataTime() - .getValidPeriod().getStart(), - 3600 * 1000)); + trs.add(new TimeRange(grid.getDataTime() + .getValidPeriod().getStart(), 3600 * 1000)); } List siteInitModules = config.initModels(gfeModel); @@ -201,23 +211,20 @@ grid // DR 15442 - move last for loop out of the for loop at line 110 for (ParmID parmId : gridInv.keySet()) { - Map> hist = new HashMap>(); try { List trs = gridInv.get(parmId); - Collections.sort(trs); for (TimeRange time : trs) { List histList = new ArrayList(); histList.add(new GridDataHistory( - GridDataHistory.OriginType.INITIALIZED, - parmId, time, null, (WsId) null)); + GridDataHistory.OriginType.INITIALIZED, parmId, + time, null, (WsId) null)); + Map> hist = new HashMap>(); hist.put(time, histList); + guns.add(new GridUpdateNotification(parmId, time, hist, + null, parmId.getDbId().getSiteId())); } - guns.add(new GridUpdateNotification(parmId, - new TimeRange(trs.get(0).getStart(), trs.get( - trs.size() - 1).getEnd()), hist, null, - parmId.getDbId().getSiteId())); } catch (Exception e) { - handler.error("Unable to retrieve grid history for " + statusHandler.error("Unable to retrieve grid history for " + parmId.toString(), e); } } @@ -225,7 +232,8 @@ grid try { sendNotifications(guns); } catch (Exception e) { - handler.error("Unable to send grib ingest notifications", e); + statusHandler.error("Unable to send grib ingest notifications", + e); } smartInitQueue.addInits(inits.values()); @@ -233,8 +241,7 @@ grid } public void filterSatelliteRecords(List records, - Date arrivalTime) - throws Exception { + Date arrivalTime) throws Exception { StringBuilder initNameBuilder = new StringBuilder(120); Set activeSites = GFESiteActivation.getInstance() @@ -249,7 +256,8 @@ grid try { config = IFPServerConfigManager.getServerConfig(site); } catch (GfeConfigurationException e) { - handler.error("Error retrieiving site config for " + site, e); + statusHandler.error( + "Error retrieiving site config for " + site, e); continue; } @@ -298,8 +306,8 @@ grid try { sendNotifications(guns); } catch (Exception e) { - handler.error("Unable to send satellite ingest notifications", - e); + statusHandler.error( + "Unable to send satellite ingest notifications", e); } smartInitQueue.addInits(inits.values()); diff --git a/edexOsgi/com.raytheon.edex.plugin.satellite/res/spring/satellite-ingest.xml b/edexOsgi/com.raytheon.edex.plugin.satellite/res/spring/satellite-ingest.xml index 5a00bce173..69820fe074 100644 --- a/edexOsgi/com.raytheon.edex.plugin.satellite/res/spring/satellite-ingest.xml +++ b/edexOsgi/com.raytheon.edex.plugin.satellite/res/spring/satellite-ingest.xml @@ -62,7 +62,7 @@ - + java.lang.Throwable diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/DatabaseID.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/DatabaseID.java index 9cdce457d8..3e1e00fb62 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/DatabaseID.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/DatabaseID.java @@ -50,6 +50,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdap * 8/19/09 2899 njensen Rewrote equals() for performance * 5/08/12 #600 dgilling Implement clone(). * 6/25/12 #766 dgilling Fix isValid(). + * 01/18/13 #1504 randerso Removed setters since class should be immutable * * * @@ -487,42 +488,6 @@ public class DatabaseID implements Serializable, Comparable, return date; } - public void setSiteId(String siteId) { - this.siteId = siteId; - } - - public void setFormat(DataType format) { - this.format = format; - } - - public void setFormat(String format) { - if (format.equals("GRID")) { - this.format = DataType.GRID; - } else { - this.format = DataType.NONE; - } - } - - public void setDbType(String dbType) { - this.dbType = dbType; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public void setModelTime(String modelTime) { - this.modelTime = modelTime; - } - - public void setModelId(String modelId) { - this.modelId = modelId.intern(); - } - - public void setShortModelId(String shortModelId) { - this.shortModelId = shortModelId; - } - public Date getModelTimeAsDate() { if (this.modelTime.equals(NO_MODEL_TIME)) { return new Date(0); diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmID.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmID.java index 5ad9ff1aeb..e8503c2226 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmID.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmID.java @@ -47,6 +47,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdap * ------------ ---------- ----------- -------------------------- * 3/6/08 875 bphillip Initial Creation * 5/8/12 #600 dgilling Implement clone(). + * 01/18/13 #1504 randerso Removed setters since class should be immutable * * * @@ -95,12 +96,7 @@ public class ParmID implements Comparable, Serializable, @Override public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append(parmName).append("_"); - buffer.append(parmLevel).append(":"); - buffer.append(dbId.toString()); - - return buffer.toString(); + return this.parmId; } /* @@ -140,7 +136,6 @@ public class ParmID implements Comparable, Serializable, this.parmName = parmName; this.parmLevel = defaultLevel(); this.dbId = new DatabaseID(parmModel); - this.compositeName = parmName + "_" + defaultLevel(); encodeIdentifier(); } @@ -158,7 +153,6 @@ public class ParmID implements Comparable, Serializable, this.parmName = parmName; this.parmLevel = level; this.dbId = new DatabaseID(parmModel); - this.compositeName = parmName + "_" + level; encodeIdentifier(); } @@ -170,7 +164,6 @@ public class ParmID implements Comparable, Serializable, */ public ParmID(String parmIdentifier) { decodeIdentifier(parmIdentifier); - this.compositeName = this.parmName + "_" + this.parmLevel; encodeIdentifier(); } @@ -186,7 +179,6 @@ public class ParmID implements Comparable, Serializable, this.parmName = parmName; this.parmLevel = defaultLevel(); this.dbId = dbId; - this.compositeName = parmName + "_" + defaultLevel(); encodeIdentifier(); } @@ -204,7 +196,6 @@ public class ParmID implements Comparable, Serializable, this.parmName = parmName; this.parmLevel = level; this.dbId = dbId; - this.compositeName = parmName + "_" + level; encodeIdentifier(); } @@ -333,11 +324,9 @@ public class ParmID implements Comparable, Serializable, */ private void encodeIdentifier() { + this.compositeName = this.parmName + "_" + this.parmLevel; shortParmId = this.compositeName + ":" + dbId.getShortModelId(); - - if (parmId == null || parmId.length() == 0) { - parmId = this.compositeName + ":" + dbId.getModelId(); - } + parmId = this.compositeName + ":" + dbId.getModelId(); } /** @@ -442,30 +431,6 @@ public class ParmID implements Comparable, Serializable, return true; } - public void setParmName(String parmName) { - this.parmName = parmName; - } - - public void setParmLevel(String parmLevel) { - this.parmLevel = parmLevel; - } - - public void setDbId(DatabaseID dbId) { - this.dbId = dbId; - } - - public void setCompositeName(String compositeName) { - this.compositeName = compositeName; - } - - public void setShortParmId(String shortParmId) { - this.shortParmId = shortParmId; - } - - public void setParmId(String parmId) { - this.parmId = parmId; - } - /* * (non-Javadoc) * diff --git a/pythonPackages/dynamicserialize/dstypes/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmID.py b/pythonPackages/dynamicserialize/dstypes/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmID.py index 68d276abfa..2ac291d476 100644 --- a/pythonPackages/dynamicserialize/dstypes/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmID.py +++ b/pythonPackages/dynamicserialize/dstypes/com/raytheon/uf/common/dataplugin/gfe/db/objects/ParmID.py @@ -48,50 +48,30 @@ class ParmID(object): else: self.parmLevel = level - self.compositeName = self.parmName + "_" + self.parmLevel self.__encodeIdentifier() elif parmIdentifier is not None: self.__decodeIdentifier(parmIdentifier) - self.compositeName = self.parmName + "_" + self.parmLevel self.__encodeIdentifier() def getParmName(self): return self.parmName - def setParmName(self, parmName): - self.parmName = parmName - def getParmLevel(self): return self.parmLevel - def setParmLevel(self, parmLevel): - self.parmLevel = parmLevel - def getDbId(self): return self.dbId - def setDbId(self, dbId): - self.dbId = dbId - def getCompositeName(self): return self.compositeName - def setCompositeName(self, compositeName): - self.compositeName = compositeName - def getShortParmId(self): return self.shortParmId - def setShortParmId(self, shortParmId): - self.shortParmId = shortParmId - def getParmId(self): return self.parmId - def setParmId(self, parmId): - self.parmId = parmId - def __decodeIdentifier(self, parmIdentifier): parts = parmIdentifier.split(":") nameLevel = parts[0].split("_") @@ -104,9 +84,9 @@ class ParmID(object): self.parmLevel = self.defaultLevel() def __encodeIdentifier(self): + self.compositeName = self.parmName + "_" + self.parmLevel self.shortParmId = self.compositeName + ":" + self.dbId.getShortModelId() - if self.parmId is None or len(self.parmId) == 0: - self.parmId = self.compositeName + ":" + self.dbId.getModelId() + self.parmId = self.compositeName + ":" + self.dbId.getModelId() def isValid(self): if len(self.parmName) is None or len(self.parmLevel) is None or self.dbId is None: