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 927d92ce30..f392d9c32e 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 @@ -83,6 +83,7 @@ import com.raytheon.viz.gfe.core.griddata.IGridData; * 02/12/13 #1597 randerso Made save threshold a configurable value. Added detailed * logging for save performance * 04/23/13 #1949 rjpeter Added logging of number of records. + * 06/26/13 #2044 randerso Fixed error message priority * * * @author chammack @@ -313,8 +314,8 @@ public class DbParm extends Parm { // failure else { - statusHandler.handle(Priority.EVENTA, "Unable to get grid for " - + getParmID() + " tr=" + grid.getGridTime() + statusHandler.error("Unable to get grid for " + getParmID() + + " tr=" + grid.getGridTime() + ". Temporarily using default data"); IGridData g = makeEmptyGrid(); g.changeValidTime(grid.getGridTime(), false); diff --git a/deltaScripts/13.6.1/UpdateGfeH5GroupFormat.py b/deltaScripts/13.6.1/UpdateGfeH5GroupFormat.py new file mode 100644 index 0000000000..93af169580 --- /dev/null +++ b/deltaScripts/13.6.1/UpdateGfeH5GroupFormat.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python +## +# 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. +## + +# +# Update GFE HDF5 Group format to include minutes +# +# +# +# SOFTWARE HISTORY +# +# Date Ticket# Engineer Description +# ------------ ---------- ----------- -------------------------- +# 11/18/10 njensen Initial Creation. +# 06/13/13 #2044 randerso Fixed to use correct python +# +# +# +import h5py +import os +import re +import subprocess +import traceback + +hdf5loc = "/awips2/edex/data/hdf5/gfe" +# T::SFC::2013_07_04_06--2013_07_04_07 +oldGroupFormat = re.compile("(.+::.+::)(\d{4})_(\d\d)_(\d\d)_(\d\d)--(\d{4})_(\d\d)_(\d\d)_(\d\d)") + +# T::SFC::20130704_0600--20130704_0700 +newGroupFormat = re.compile("(.+::.+::)(\d{4})(\d\d)(\d\d)_(\d\d)(\d\d)--(\d{4})(\d\d)(\d\d)_(\d\d)(\d\d)") + + +def updateFile(filePath): + print "Updating",filePath + h5File = h5py.File(filePath) + origGroups = h5File.keys() + for groupName in origGroups: + newMatch = newGroupFormat.match(groupName) + oldMatch = oldGroupFormat.match(groupName) + if newMatch: + #print "Found new format:", groupName + pass + elif oldMatch: + #print "Found old format:", groupName + (nameAndLevel, startYear, startMonth, startDay, startHour, endYear, endMonth, endDay, endHour)= oldMatch.groups() + newGroupName = nameAndLevel+startYear+startMonth+startDay+"_"+startHour+"00--"+endYear+endMonth+endDay+"_"+endHour+"00" + #print " New format:", newGroupName + + # if new group already exists (partial conversion) + if newGroupName in origGroups: + newGroup = h5File[newGroupName] + # else create new group + else: + newGroup = h5File.create_group(newGroupName) + + # move datasets from old group to new group + oldGroup = h5File[groupName] + dataSets = oldGroup.keys() + for dataSet in dataSets: + #print " Moving dataSet:",dataSet + newGroup[dataSet] = oldGroup[dataSet] + del oldGroup[dataSet] + + # remove old group + del h5File[groupName] + else: + print "Unrecognized group found:",groupName + + h5File.close() + +def repack(dir): + files = os.listdir(dir) + for file in files: + filePath = os.path.join(dir, file) + if os.path.isfile(filePath) and \ + str(filePath).endswith(".h5") and \ + not str(filePath).endswith("_GridParm.h5"): + repackFilePath = filePath+".repack" + try: + subprocess.check_call(("/awips2/tools/bin/h5repack", filePath, repackFilePath)) + except: + print "h5repack failed:", filePath + continue + + try: + os.remove(filePath) + os.rename(repackFilePath, filePath) + except: + print "error renaming repacked file:", repackFilePath + continue + + +def processDir(dir): + singleton = False + for file in os.listdir(dir): + filePath = os.path.join(dir, file) + if os.path.isfile(filePath) and \ + str(filePath).endswith(".h5"): + if str(filePath).endswith("_GridParm.h5"): + if (str(filePath).endswith("_00000000_0000_GridParm.h5")): + singleton = True + else: + updateFile(filePath) + + elif os.path.isdir(filePath): + # skip the Topo and climo directories (climo is obsolete and should be removed) + if str(file) != 'Topo' and str(file) != 'climo': + processDir(filePath) + + if singleton: + print "repacking singleton database:", dir + repack(dir) + +def main(): + processDir(hdf5loc) + +if __name__ == '__main__': + main() diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-common.xml b/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-common.xml index 9035319bc5..139cafdda7 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-common.xml +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-common.xml @@ -3,110 +3,65 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> - - - - - - + + + + + + - - - - - - + - - - - - - - - - + + + + - - + + + + - - - + + + + - - + + - + - + - + - - - - - - - java.lang.Throwable - - - - - - - + + - - - - - + + + + + java.lang.Throwable - + - - - - - - - - - - - java.lang.Throwable - - - - - - - + + - - + + java.lang.Throwable - + - + diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-request.xml b/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-request.xml index b1b68a4994..1f309ec22d 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-request.xml +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/res/spring/gfe-request.xml @@ -1,667 +1,533 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + - - - - - + + + + + - - - - - + + + + + - - - - - - - - - - - - - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - + + + + + - + - + - - - - - + + + + + - + - - - + - + - + - - - + - - - - - - - - - - java.lang.Throwable - - - - + + + - - - - - - - - - - - - - - - - java.lang.Throwable - - - - - - - - - - - - - - - java.lang.Throwable - - - - - - - - - - - - - - - java.lang.Throwable - - - - - - - - - - - + + + + + + - - + + + java.lang.Throwable + + + + + + + + + + + + + + + + + + + + + java.lang.Throwable + + + + + + + + + + + + + + + java.lang.Throwable + + + + + + + + + + + + + + + java.lang.Throwable + + + + + + + + + + + + + + java.lang.Throwable - - - - - - - - - - - + + + + + + + + + + + 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 d62b84fe78..a5af413870 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 @@ -2,31 +2,34 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -37,144 +40,171 @@ - - - - - - - - - - - - - - - - java.lang.Throwable - - - - - - - - - - - java.lang.Throwable - - - - - - - - - + + + - - - + + + + + + + + + java.lang.Throwable + + + + + + + + + + + java.lang.Throwable + + + + + + + + + + + + + - - - - - + - - + + java.lang.Throwable - + - - - - + + - + java.lang.Throwable - + - + - - - - - - - java.lang.Throwable - - - - - - - - - - - - java.lang.Throwable - - - - - - - - - + + + + + + + + + + + + java.lang.Throwable + + + + + + + + + + + + java.lang.Throwable + + + + + + + + + + + + java.lang.Throwable + + + + + + + + + + + + java.lang.Throwable + + + + + + + + + + - - - - - - - - + + + + + + + + - - - + + + - - - - + + + + - - - - + + + + - - - + + + 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 deleted file mode 100644 index f56c8d9a14..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdCache.java +++ /dev/null @@ -1,393 +0,0 @@ -/** - * 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. - **/ - -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; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; -import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; -import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; -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.server.notify.GfeIngestNotificationFilter; -import com.raytheon.edex.plugin.gfe.util.SendNotifications; -import com.raytheon.uf.common.dataplugin.PluginException; -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.dataplugin.gfe.server.message.ServerResponse; -import com.raytheon.uf.common.dataplugin.gfe.server.notify.DBInvChangeNotification; -import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotification; -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.edex.database.DataAccessLayerException; -import com.raytheon.uf.edex.site.SiteAwareRegistry; - -/** - * This class stores D2D parmIDs for quick and efficient access. - * - *
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * 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.
- * Mar 20, 2013  #1774     randerso    Changed to use GFDD2DDao
- * Apr 01, 2013  #1774     randerso    Moved wind component checking to GfeIngestNotificaionFilter
- * May 14, 2013  #2004     randerso    Added DBInvChangeNotifications when D2D data is purged
- * 
- * 
- * - * @author bphillip - * @version 1.0 - */ -public class D2DParmIdCache { - private static final transient IUFStatusHandler statusHandler = UFStatus - .getHandler(D2DParmIdCache.class); - - /** The name this cache uses when being stored in the SharedObjectProvider */ - public static transient final String CACHE_NAME = "D2DParmIds"; - - private static final Pattern RangeFilter = Pattern - .compile("(.*?)\\d{1,2}hr"); - - /** Map containing the ParmIDs */ - private Map> parmIds; - - private static D2DParmIdCache instance; - - public static synchronized D2DParmIdCache getInstance() { - if (instance == null) { - instance = new D2DParmIdCache(); - } - return instance; - } - - /** - * Constructs a new D2DParmIdCache - */ - public D2DParmIdCache() { - parmIds = new HashMap>(); - } - - /** - * Places a parmId into the cache - * - * @param parmId - * The ParmID to add to the cache - */ - public void putParmID(ParmID parmId) { - - D2DGridDatabase db = null; - try { - - GridDatabase gridDb = GridParmManager.getDb(parmId.getDbId()); - if (gridDb instanceof D2DSatDatabase) { - putParmIDInternal(parmId); - return; - } else if (gridDb instanceof D2DGridDatabase) { - db = (D2DGridDatabase) gridDb; - } else { - putParmIDInternal(parmId); - return; - } - } catch (GfeException e) { - statusHandler.error("Error getting D2DGridDatabase for " - + parmId.getDbId()); - putParmIDInternal(parmId); - return; - } - - if (!db.isParmInfoDefined(parmId)) { - String abbrev = parmId.getParmName(); - Matcher matcher = RangeFilter.matcher(abbrev); - if (matcher.matches()) { - abbrev = matcher.group(1); - ParmID tempParmID = new ParmID(abbrev, parmId.getDbId(), - parmId.getParmLevel()); - if (db.isParmInfoDefined(tempParmID)) { - parmId = tempParmID; - } - } - } - putParmIDInternal(parmId); - } - - 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 (dbParms == null) { - dbParms = new HashSet(); - parmIds.put(dbId, dbParms); - } - - // Insert the ParmID into the map - dbParms.add(parmId); - } - } - - /** - * Places a collection of ParmIDs into the cache - * - * @param parmIds - * The parmIDs to add - */ - public void putParmIDList(Collection parmIds) { - for (ParmID id : parmIds) { - putParmID(id); - } - } - - /** - * Retrieves all the ParmIDs for a given DatabaseID - * - * @param dbId - * The DatabaseID to retrieve the ParmIDs for - * @return The ParmIDs in the given DatabaseID - */ - public List getParmIDs(DatabaseID dbId) { - List parms = Collections.emptyList(); - synchronized (parmIds) { - if (parmIds.containsKey(dbId)) { - parms = new ArrayList(parmIds.get(dbId)); - } - } - return parms; - } - - /** - * Retrieves all the ParmIDs for a given DatabaseID - * - * @param dbId - * The String representation of the DatabaseID to retrieve the - * ParmIDs for - * @return The ParmIDs in the given DatabaseID - */ - public List getParmIDs(String dbId) { - return getParmIDs(new DatabaseID(dbId)); - } - - /** - * Retrieves all DatabaseIDs - * - * @return The list of DatabaseIDs - */ - public List getDatabaseIDs() { - List dbIds = null; - synchronized (parmIds) { - dbIds = new ArrayList(parmIds.keySet()); - } - return dbIds; - } - - public void removeSiteDbs(String siteID) { - - statusHandler.handle(Priority.EVENTA, "Purging " + siteID - + " parmIDs from d2d parmID cache..."); - - List dbInv; - - if (UFStatus.getHandler().isPriorityEnabled(Priority.DEBUG)) { - StringBuffer msg = new StringBuffer(); - msg.append("\nRemoving site information from D2DParmIdCache\nInitial Database Inventory:\n"); - dbInv = getDatabaseIDs(); - for (DatabaseID dbId : dbInv) { - msg.append(dbId.toString()).append("\n"); - } - statusHandler.handle(Priority.DEBUG, msg.toString()); - } - - List dbsToRemove = new ArrayList(); - dbInv = getDatabaseIDs(); - for (DatabaseID dbId : dbInv) { - if (dbId.getSiteId().equalsIgnoreCase(siteID)) { - dbsToRemove.add(dbId); - } - } - - synchronized (this.parmIds) { - for (DatabaseID dbId : dbsToRemove) { - this.parmIds.remove(dbId); - if (UFStatus.getHandler().isPriorityEnabled(Priority.DEBUG)) { - statusHandler.handle(Priority.DEBUG, - "D2dParmIdCache Removed " + dbId); - } - } - } - - if (UFStatus.getHandler().isPriorityEnabled(Priority.DEBUG)) { - StringBuffer msg = new StringBuffer(); - msg.append("\nD2DParmIdCache Post-Purge Database Inventory:\n"); - dbInv = getDatabaseIDs(); - for (DatabaseID dbId : dbInv) { - msg.append(dbId.toString()).append("\n"); - } - statusHandler.handle(Priority.DEBUG, msg.toString()); - } - - statusHandler.handle(Priority.EVENTA, "Successfully purged all " - + siteID + " parmIDs from d2d parmID cache..."); - } - - /** - * Refreshes the cache for the given site. This is called upon site - * activation. Also, the cache is rebuilt when the grib plugin purges its - * data. The grib plugin will put a message on a topic so all members of the - * cluster will know to rebuild their caches with the updated grib - * inventory. - * - * @param site - * The site to rebuild the cache for. If this is null, then that - * means this method is being fired off as the result of a grib - * purge - * @throws PluginException - * If errors occur when interacting with the database. - * @throws GfeConfigurationException - * If errors occur while retrieving the server config for the - * given site - */ - public void buildCache(String site) throws PluginException, - GfeConfigurationException { - String[] activeSites = null; - if (site == null || site.isEmpty()) { - activeSites = SiteAwareRegistry.getInstance().getActiveSites(); - } else { - activeSites = new String[] { site }; - } - for (String siteID : activeSites) { - List dbsToRemove = this.getDatabaseIDs(); - statusHandler.handle(Priority.EVENTA, - "Building D2DParmIdCache for " + siteID + "..."); - IFPServerConfig config = IFPServerConfigManager - .getServerConfig(siteID); - Set parmIds = new HashSet(); - long start = System.currentTimeMillis(); - List d2dModels = config.getD2dModels(); - for (String d2dModelName : d2dModels) { - String gfeModel = config.gfeModelNameMapping(d2dModelName); - - if ((d2dModelName != null) && (gfeModel != null)) { - List dbIds = null; - try { - dbIds = D2DGridDatabase.getD2DDatabaseIdsFromDb(config, - d2dModelName); - } catch (DataAccessLayerException e) { - throw new PluginException( - "Unable to get D2D Database Ids from database!", - e); - } - - if (!dbIds.isEmpty()) { - int versions = Math.min( - config.desiredDbVersions(dbIds.get(0)), - dbIds.size()); - - for (int i = 0; i < versions; i++) { - try { - D2DGridDatabase db = (D2DGridDatabase) GridParmManager - .getDb(dbIds.get(i)); - ServerResponse> sr = db - .getParmList(); - if (sr.isOkay()) { - parmIds.addAll(sr.getPayload()); - } - } catch (GfeException e) { - throw new PluginException( - "Error adding parmIds to D2DParmIdCache!!", - e); - } - } - } - - } - } - parmIds.addAll(D2DSatDatabaseManager.getSatDatabase(siteID) - .getParmList().getPayload()); - removeSiteDbs(siteID); - putParmIDList(parmIds); - List currentDbInventory = this.getDatabaseIDs(); - dbsToRemove.removeAll(currentDbInventory); - List invChgList = new ArrayList( - dbsToRemove.size()); - for (DatabaseID dbId : dbsToRemove) { - invChgList.add(new DBInvChangeNotification(null, Arrays - .asList(dbId), siteID)); - } - SendNotifications.send(invChgList); - - // inform GfeIngestNotificationFilter of removed dbs - GfeIngestNotificationFilter.purgeDbs(dbsToRemove); - - statusHandler.handle(Priority.EVENTA, - "Total time to build D2DParmIdCache for " + siteID - + " took " + (System.currentTimeMillis() - start) - + " ms"); - } - } - - /** - * Counts the number of parmIds currently in the cache - * - * @return The number of parmIds currently in the cache - */ - public long getSize() { - long size = 0; - synchronized (parmIds) { - for (Set parms : parmIds.values()) { - size += parms.size(); - } - } - return size; - } - - public void pluginPurged(String pluginName) - throws GfeConfigurationException, PluginException { - if (pluginName.equals("grid")) { - buildCache(null); - } - } - - public void processGridUpdateNotification(GridUpdateNotification gun) { - ParmID parmId = gun.getParmId(); - putParmID(parmId); - } -} 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 deleted file mode 100644 index c7096adedb..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/d2dparms/D2DParmIdFilter.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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. - **/ - -package com.raytheon.edex.plugin.gfe.cache.d2dparms; - -import java.util.List; - -import com.raytheon.uf.common.dataplugin.gfe.server.notify.GfeNotification; -import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotification; - -/** - * Extracts a ParmID from a GribRecord. This class is used as part of the ESB - * route which updates the D2DParmIdCache as products arrive. - * - *
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * 1/10/09      1674       bphillip    Initial creation
- * 10/06/09     3172       njensen     Based on grib notification
- * 01/18/13     #1504      randerso    Changed to send full GridUpdateNotification 
- *                                     to D2DParmIdCache
- * 
- * 
- * - * @author bphillip - * @version 1.0 - */ -public class D2DParmIdFilter { - - /** - * Extracts ParmIDs and insert times from a list of messages in the - * container. - * - * @param container - * the container of messages - */ - public void updateParmIdCache(List notifications) { - for (GfeNotification notify : notifications) { - if (notify instanceof GridUpdateNotification) { - D2DParmIdCache.getInstance().processGridUpdateNotification( - (GridUpdateNotification) notify); - } - } - } -} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/ifpparms/IFPParmIdCache.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/ifpparms/IFPParmIdCache.java deleted file mode 100644 index 647fe6a7dc..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/cache/ifpparms/IFPParmIdCache.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * 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. - **/ -package com.raytheon.edex.plugin.gfe.cache.ifpparms; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import com.raytheon.edex.plugin.gfe.config.GridDbConfig; -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.status.IUFStatusHandler; -import com.raytheon.uf.common.status.UFStatus; -import com.raytheon.uf.common.status.UFStatus.Priority; - -public class IFPParmIdCache { - private static final transient IUFStatusHandler statusHandler = UFStatus - .getHandler(IFPParmIdCache.class); - - private static IFPParmIdCache instance; - - private Map> parmIds; - - public synchronized static IFPParmIdCache getInstance() { - if (instance == null) { - instance = new IFPParmIdCache(); - } - return instance; - } - - private IFPParmIdCache() { - parmIds = new HashMap>(); - } - - public void removeSiteDbs(String siteID) { - statusHandler.handle(Priority.EVENTA, "Purging " + siteID - + " parmIDs from IFP parmID cache."); - - if (UFStatus.getHandler().isPriorityEnabled(Priority.DEBUG)) { - StringBuffer msg = new StringBuffer(); - msg.append("\nRemoving site information from IFPParmIdCache\nInitial Database Inventory:\n"); - for (DatabaseID dbId : parmIds.keySet()) { - msg.append(dbId.toString()).append("\n"); - } - statusHandler.handle(Priority.DEBUG, msg.toString()); - } - - List dbsToRemove = new ArrayList(); - for (DatabaseID dbId : parmIds.keySet()) { - if (dbId.getSiteId().equalsIgnoreCase(siteID)) { - dbsToRemove.add(dbId); - } - } - - for (DatabaseID db : dbsToRemove) { - parmIds.remove(db); - if (UFStatus.getHandler().isPriorityEnabled(Priority.DEBUG)) { - statusHandler.handle(Priority.DEBUG, "IFPParmIdCache Removed " - + db); - } - } - - if (UFStatus.getHandler().isPriorityEnabled(Priority.DEBUG)) { - StringBuffer msg = new StringBuffer(); - msg.append("\nIFPParmIdCache Post-Purge Database Inventory:\n"); - for (DatabaseID dbId : parmIds.keySet()) { - msg.append(dbId.toString()).append("\n"); - } - statusHandler.handle(Priority.DEBUG, msg.toString()); - } - - statusHandler.handle(Priority.EVENTA, "Successfully purged all " - + siteID + " parmIDs from IFP parmID cache..."); - - } - - public List getParmIds(GridDbConfig gridConfig, DatabaseID dbId) { - synchronized (parmIds) { - if (!parmIds.containsKey(dbId)) { - addParmIds(gridConfig, dbId); - } - } - return parmIds.get(dbId); - - } - - private void addParmIds(GridDbConfig gridConfig, DatabaseID dbId) { - String key = null; - List parmIdList = new ArrayList(); - for (Iterator iterator = gridConfig.get_gridInfoDict().keySet() - .iterator(); iterator.hasNext();) { - key = iterator.next(); - String[] nameLevel = key.split("_"); - parmIdList.add(new ParmID(nameLevel[0], dbId, nameLevel[1])); - } - synchronized (parmIds) { - parmIds.put(dbId, parmIdList); - } - } -} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/GFESiteActivation.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/GFESiteActivation.java index ac19cd6994..0b393256f8 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/GFESiteActivation.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/GFESiteActivation.java @@ -21,9 +21,7 @@ package com.raytheon.edex.plugin.gfe.config; import java.net.InetAddress; import java.net.UnknownHostException; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -31,26 +29,12 @@ import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; import com.google.common.util.concurrent.MoreExecutors; -import com.raytheon.edex.plugin.gfe.cache.d2dparms.D2DParmIdCache; -import com.raytheon.edex.plugin.gfe.cache.gridlocations.GridLocationCache; -import com.raytheon.edex.plugin.gfe.cache.ifpparms.IFPParmIdCache; -import com.raytheon.edex.plugin.gfe.db.dao.IscSendRecordDao; import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException; import com.raytheon.edex.plugin.gfe.exception.GfeMissingConfigurationException; import com.raytheon.edex.plugin.gfe.isc.IRTManager; -import com.raytheon.edex.plugin.gfe.reference.MapManager; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; -import com.raytheon.edex.plugin.gfe.server.database.D2DGridDatabase; -import com.raytheon.edex.plugin.gfe.server.database.D2DSatDatabaseManager; -import com.raytheon.edex.plugin.gfe.server.database.GridDatabase; -import com.raytheon.edex.plugin.gfe.server.database.IFPGridDatabase; -import com.raytheon.edex.plugin.gfe.server.database.NetCDFDatabaseManager; -import com.raytheon.edex.plugin.gfe.server.database.TopoDatabaseManager; -import com.raytheon.edex.plugin.gfe.smartinit.SmartInitRecord; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.edex.site.SiteUtil; import com.raytheon.uf.common.dataplugin.PluginException; -import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; -import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID.DataType; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; import com.raytheon.uf.common.site.notify.SiteActivationNotification; import com.raytheon.uf.common.site.notify.SiteActivationNotification.ACTIVATIONSTATUS; @@ -60,7 +44,6 @@ import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.edex.core.EDEXUtil; import com.raytheon.uf.edex.core.EdexException; -import com.raytheon.uf.edex.core.IMessageProducer; import com.raytheon.uf.edex.database.DataAccessLayerException; import com.raytheon.uf.edex.database.cluster.ClusterLockUtils; import com.raytheon.uf.edex.database.cluster.ClusterLockUtils.LockState; @@ -88,6 +71,7 @@ import com.raytheon.uf.edex.site.notify.SendSiteActivationNotifications; * activation. * Mar 20, 2013 #1774 randerso Changed to use GFED2DDao * May 02, 2013 #1969 randerso Moved updateDbs method into IFPGridDatabase + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -111,7 +95,7 @@ public class GFESiteActivation implements ISiteActivationListener { // minutes private static final int SMART_INIT_TIMEOUT = 1800000; - private static GFESiteActivation instance; + private static GFESiteActivation instance = new GFESiteActivation(); private boolean intialized = false; @@ -119,13 +103,19 @@ public class GFESiteActivation implements ISiteActivationListener { .getExitingExecutorService((ThreadPoolExecutor) Executors .newCachedThreadPool()); - public static synchronized GFESiteActivation getInstance() { - if (instance == null) { - instance = new GFESiteActivation(); - } + /** + * @return the singleton instance + */ + public static GFESiteActivation getInstance() { return instance; } + /** + * private constructor for singleton class + */ + private GFESiteActivation() { + } + @Override public void registered() { this.intialized = true; @@ -257,23 +247,17 @@ public class GFESiteActivation implements ISiteActivationListener { } catch (GfeMissingConfigurationException e) { sendActivationFailedNotification(siteID); // Stack trace is not printed per requirement for DR14360 - statusHandler.handle(Priority.PROBLEM, siteID - + " will not be activated: " + e.getLocalizedMessage()); + statusHandler.warn(siteID + " will not be activated: " + + e.getLocalizedMessage()); throw e; } catch (Exception e) { sendActivationFailedNotification(siteID); - statusHandler.handle(Priority.PROBLEM, siteID - + " Error activating site " + siteID, e); + statusHandler.error(siteID + " Error activating site " + siteID, e); throw e; } sendActivationCompleteNotification(siteID); } - public void cycleSite(String siteID) throws Exception { - this.deactivateSite(siteID); - this.activateSite(siteID); - } - /** * Activate site routine for internal use. * @@ -308,59 +292,12 @@ public class GFESiteActivation implements ISiteActivationListener { IFPServerConfig config = null; try { - statusHandler.handle(Priority.EVENTA, "Activating " + siteID - + "..."); + statusHandler.info("Activating " + siteID + "..."); - statusHandler.handle(Priority.EVENTA, - "IFPServerConfigManager initializing..."); + statusHandler.info("IFPServerConfigManager initializing..."); config = IFPServerConfigManager.initializeSite(siteID); - statusHandler.handle(Priority.EVENTA, - "TopoDatabaseManager initializing..."); - TopoDatabaseManager.initializeTopoDatabase(siteID); - // statusHandler.handle(Priority.EVENTA, - // "ClimoDatabaseManager initializing..."); - // ClimoDatabaseManager.initializeClimoDatabase(siteID); - // statusHandler.handle(Priority.EVENTA, - // "HLSDatabaseManager initializing..."); - // HLSTopoDatabaseManager.initializeHLSTopoDatabase(siteID); - // statusHandler.handle(Priority.EVENTA, - // "D2DSatDatabaseManager initializing..."); - D2DSatDatabaseManager.initializeD2DSatDatabase(siteID, config); - - statusHandler.handle(Priority.EVENTA, - "NetCDFDatabaseManager initializing..."); - NetCDFDatabaseManager.initializeNetCDFDatabases(config); - - statusHandler.handle(Priority.EVENTA, "MapManager initializing..."); - // should be cluster locked - new MapManager(config); - - statusHandler - .handle(Priority.EVENTA, "Getting GFE db inventory..."); - List inventory = GridParmManager.getDbInventory(siteID) - .getPayload(); - Map> ifpInventory = new HashMap>(); - for (DatabaseID dbId : inventory) { - if (!dbId.getDbType().equals("D2D")) { - if (!ifpInventory.keySet().contains(dbId.getSiteId())) { - ifpInventory.put(dbId.getSiteId(), - new ArrayList()); - } - ifpInventory.get(dbId.getSiteId()).add(dbId); - } - } - statusHandler.handle(Priority.EVENTA, - "Checking for IFPGridDatabase updates..."); - for (String site : ifpInventory.keySet()) { - for (DatabaseID dbid : ifpInventory.get(site)) { - GridDatabase db = GridParmManager.getDb(dbid); - // cluster locked since IFPGridDatabase can modify the grids - // based on changes to grid size, etc - if (db instanceof IFPGridDatabase && db.databaseIsValid()) { - ((IFPGridDatabase) db).updateDbs(); - } - } - } + statusHandler.info("Activating IFPServer..."); + IFPServer ifpServer = IFPServer.activateServer(siteID, config); } finally { statusHandler .handle(Priority.INFO, @@ -369,7 +306,7 @@ public class GFESiteActivation implements ISiteActivationListener { } // Doesn't need to be cluster locked - statusHandler.handle(Priority.EVENTA, "Checking ISC configuration..."); + statusHandler.info("Checking ISC configuration..."); if (config.requestISC()) { String host = InetAddress.getLocalHost().getCanonicalHostName(); String gfeHost = config.getServerHost(); @@ -381,116 +318,20 @@ public class GFESiteActivation implements ISiteActivationListener { // but don't hard code request if (host.contains(hostNameToCompare) && System.getProperty("edex.run.mode").equals("request")) { - statusHandler.handle(Priority.EVENTA, "Enabling ISC..."); - IRTManager.getInstance().enableISC(siteID, config.getMhsid()); + statusHandler.info("Enabling ISC..."); + IRTManager.getInstance().enableISC(siteID, config); } else { statusHandler.handle(Priority.EVENTA, "ISC Enabled but will use another EDEX instance"); } } else { - statusHandler.handle(Priority.EVENTA, "ISC is not enabled."); + statusHandler.info("ISC is not enabled."); } // doesn't need to be cluster locked - statusHandler.handle(Priority.EVENTA, "Building the D2DParmIDCache..."); - D2DParmIdCache.getInstance().buildCache(siteID); final IFPServerConfig configRef = config; - // TODO: should only be done once at - // initial start of the configuration, or at least only once per - // startup, use a separate cluster lock that won't run if lock - // within last 5 minutes, move outside of site activation as this - // just need to be done, doesn't matter that site isn't fully - // activated, in fact would be best to only be done once site is - // fully activated. - Runnable smartInit = new Runnable() { - @Override - public void run() { - long startTime = System.currentTimeMillis(); - // wait for system startup or at least 3 minutes - while (!EDEXUtil.isRunning() - || System.currentTimeMillis() > startTime + 180000) { - try { - Thread.sleep(15000); - } catch (InterruptedException e) { - - } - } - - ClusterTask ct = ClusterLockUtils.lookupLock(TASK_NAME, - SMART_INIT_TASK_DETAILS + siteID); - if (ct.getLastExecution() + SMART_INIT_TIMEOUT < System - .currentTimeMillis()) { - ct = ClusterLockUtils.lock(TASK_NAME, - SMART_INIT_TASK_DETAILS + siteID, - SMART_INIT_TIMEOUT, false); - if (LockState.SUCCESSFUL.equals(ct.getLockState())) { - boolean clearTime = false; - try { - List d2dModels = configRef.getD2dModels(); - List> idsByVersion = new ArrayList>( - 5); - for (String d2dModelName : d2dModels) { - - String gfeModel = configRef - .gfeModelNameMapping(d2dModelName); - - if ((d2dModelName != null) - && (gfeModel != null)) { - int versions = configRef - .desiredDbVersions(new DatabaseID( - siteID, DataType.GRID, "", - gfeModel)); - List dbIds = D2DGridDatabase - .getD2DDatabaseIdsFromDb(configRef, - d2dModelName, versions); - - while (versions > idsByVersion.size()) { - idsByVersion.add(new ArrayList( - d2dModels.size())); - } - - int index = 0; - for (DatabaseID id : dbIds) { - List ids = idsByVersion - .get(index++); - ids.add(id.toString()); - } - } - } - IMessageProducer producer = EDEXUtil - .getMessageProducer(); - for (List ids : idsByVersion) { - for (String id : ids) { - statusHandler.handle(Priority.EVENTA, - "Firing smartinit for " + id); - try { - producer.sendAsyncUri( - "jms-generic:queue:manualSmartInit", - id - + ":0::" - + SmartInitRecord.SITE_ACTIVATION_INIT_PRIORITY); - } catch (EdexException e) { - statusHandler.handle(Priority.PROBLEM, - "Failed to fire smart init for: " - + id); - } - } - } - } catch (Exception e) { - statusHandler.handle(Priority.ERROR, - "Error occurred firing Smart Inits", e); - clearTime = true; - } finally { - ClusterLockUtils.unlock(ct, clearTime); - } - } - } - } - }; - postActivationTaskExecutor.submit(smartInit); - if (config.tableFetchTime() > 0) { Runnable activateFetchAT = new Runnable() { @@ -499,7 +340,7 @@ public class GFESiteActivation implements ISiteActivationListener { long startTime = System.currentTimeMillis(); // wait for system startup or at least 3 minutes while (!EDEXUtil.isRunning() - || System.currentTimeMillis() > startTime + 180000) { + || (System.currentTimeMillis() > (startTime + 180000))) { try { Thread.sleep(15000); } catch (InterruptedException e) { @@ -536,11 +377,9 @@ public class GFESiteActivation implements ISiteActivationListener { postActivationTaskExecutor.submit(activateFetchAT); } - statusHandler.handle(Priority.EVENTA, "Adding " + siteID - + " to active sites list."); + statusHandler.info("Adding " + siteID + " to active sites list."); IFPServerConfigManager.addActiveSite(siteID); - statusHandler.handle(Priority.EVENTA, siteID - + " successfully activated"); + statusHandler.info(siteID + " successfully activated"); } /** @@ -552,7 +391,7 @@ public class GFESiteActivation implements ISiteActivationListener { public void deactivateSite(String siteID) throws Exception { sendDeactivationBeginNotification(siteID); - if (!IFPServerConfigManager.getActiveSites().contains(siteID)) { + if (!IFPServer.getActiveSites().contains(siteID)) { statusHandler.handle(Priority.DEBUG, "Site [" + siteID + "] not active. Cannot deactivate."); sendDeactivationCompleteNotification(siteID); @@ -572,37 +411,13 @@ public class GFESiteActivation implements ISiteActivationListener { } - IFPServerConfig config = IFPServerConfigManager - .getServerConfig(siteID); - if (config.requestISC()) { - IRTManager.getInstance().disableISC(config.getMhsid(), siteID); - } - - try { - new IscSendRecordDao().deleteForSite(siteID); - } catch (DataAccessLayerException e) { - statusHandler.handle(Priority.PROBLEM, - "Could not clear IscSendRecords for site " + siteID - + " from queue.", e); - } - - TopoDatabaseManager.removeTopoDatabase(siteID); - // for (String source : ClimoDatabaseManager.getClimoSources()) { - // ClimoDatabaseManager.removeClimoDatabase(siteID, source); - // } - - NetCDFDatabaseManager.removeDatabases(siteID); - - D2DSatDatabaseManager.removeSatDatabase(siteID); - D2DParmIdCache.getInstance().removeSiteDbs(siteID); - IFPParmIdCache.getInstance().removeSiteDbs(siteID); - GridParmManager.purgeDbCache(siteID); - GridLocationCache.removeGridLocationsForSite(siteID); - statusHandler.handle(Priority.EVENTA, siteID - + " successfully deactivated"); + IFPServer.deactivateServer(siteID); + statusHandler.info(siteID + " successfully deactivated"); + // TODO eventually this should go away IFPServerConfigManager.removeSite(siteID); IFPServerConfigManager.removeActiveSite(siteID); + } catch (GfeConfigurationException e) { statusHandler.handle(Priority.PROBLEM, "Unable to get server config for site [" + siteID + "]", e); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/IFPServerConfig.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/IFPServerConfig.java index 7485d4bd0f..c58e3ed5da 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/IFPServerConfig.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/IFPServerConfig.java @@ -53,6 +53,7 @@ import com.raytheon.uf.common.dataplugin.gfe.weather.WxDefinition; * 04/08/08 #875 bphillip Changed exception handling * 06/24/08 #1160 randerso Added a method to get the Topo dbId * 07/09/09 #2590 njensen No longer singleton + * 06/24/13 #2044 randerso Renamed satdirs to satdata to match serverConfig.py * * * @@ -139,7 +140,7 @@ public class IFPServerConfig { private Map _netCDFDirs; - private Map _satDirs; + private Map _satData; private int _tableFetchTime; @@ -433,7 +434,7 @@ public class IFPServerConfig { _mhsid = config.mhsid; _tableFetchTime = config.tableFetchTime; - _satDirs = config.satDirs; + _satData = config.satData; _netCDFDirs = config.netCDFDirs; _prdDir = config.prdDir; _logFilePurgeAfter = config.logFilePurgeAfter; @@ -760,8 +761,8 @@ public class IFPServerConfig { _iscPort = p; } - public Map satDirs() { - return _satDirs; + public Map satData() { + return _satData; } public Map netCDFDirs() { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/SimpleServerConfig.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/SimpleServerConfig.java index 1f4fdd9cc8..2b9d317226 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/SimpleServerConfig.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/config/SimpleServerConfig.java @@ -33,6 +33,7 @@ import com.raytheon.uf.common.dataplugin.gfe.config.ProjectionData; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 03/13/08 #1030 randerso Initial port + * 06/24/13 #2044 randerso Renamed satdirs to satdata to match serverConfig.py * * * @@ -63,7 +64,7 @@ public class SimpleServerConfig { public Map netCDFDirs; - public Map satDirs; + public Map satData; public boolean allowTopoBelowZero; diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFED2DDao.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFED2DDao.java index be7fe5a742..9dca291adf 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFED2DDao.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/db/dao/GFED2DDao.java @@ -56,6 +56,7 @@ import com.raytheon.uf.edex.plugin.grid.dao.GridDao; * suffix first. * 05/22/13 #1974 randerso Fix bug introduced by the previous fix where query for * T (T%hr) returned TP6hr + * 06/13/13 #2044 randerso Cleaned up JavaDoc * * * @@ -64,16 +65,18 @@ import com.raytheon.uf.edex.plugin.grid.dao.GridDao; */ // ********************************************************************** -// TODO: this was moved out of GFEDao and needs to be cleaned up to better -// use the inherited GridDao functionality and hibernate instead of -// SQL/HQL queries. Some parts of the queries could be pushed up to -// GridDao +// TODO: Can this be merged into GridDao/D2DGridDatabase? // ********************************************************************** public class GFED2DDao extends GridDao { private static final String FCST_TIME = "dataTime.fcstTime"; private static final String REF_TIME = "dataTime.refTime"; + /** + * Constructor + * + * @throws PluginException + */ public GFED2DDao() throws PluginException { super(); } @@ -81,8 +84,9 @@ public class GFED2DDao extends GridDao { /** * Retrieves a list of available forecast times * - * @param dbId - * The database ID to get the times for + * @param d2dModelName + * @param refTime + * * @return The list of forecast times associated with the specified * DatabaseID * @throws DataAccessLayerException @@ -105,10 +109,12 @@ public class GFED2DDao extends GridDao { * Retrieves a GridRecord from the grib metadata database based on a ParmID, * TimeRange, and GridParmInfo. * - * @param id - * The parmID of the desired GridRecord + * @param d2dModelName + * @param refTime + * @param d2dParmName + * @param d2dLevel * @param forecastTime - * The foreCast time of the desired GridRecord, null for any + * The forecast time of the desired GridRecord, null for any * record * @param info * The GridParmInfo for the requested d2d grid. @@ -155,8 +161,10 @@ public class GFED2DDao extends GridDao { * database which match the given ParmID. Session passed to allow reuse * across multiple calls. * - * @param id - * The ParmID to search with + * @param d2dModelName + * @param refTime + * @param d2dParmName + * @param d2dLevel * @param s * The database session to use * @return The list of GridRecords from the grib metadata database which @@ -256,8 +264,11 @@ public class GFED2DDao extends GridDao { /** * Retrieve the available Forecast Hours by D2D parm id. * - * @param id - * @return the list of forecast hours + * @param d2dModelName + * @param refTime + * @param d2dParmName + * @param d2dLevel + * @return the list of forecast hours, empty if none * @throws DataAccessLayerException */ public List queryFcstHourByParmId(String d2dModelName, @@ -293,7 +304,7 @@ public class GFED2DDao extends GridDao { * * @param d2dModelName * @param maxRecords - * @return + * @return list of model run times, empty if none * @throws DataAccessLayerException */ public List getModelRunTimes(String d2dModelName, int maxRecords) 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 82b419ab1d..987e28e24b 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 @@ -30,7 +30,6 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import org.hibernate.LockOptions; import org.hibernate.Query; @@ -42,8 +41,8 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import com.raytheon.edex.db.dao.DefaultPluginDao; -import com.raytheon.edex.plugin.gfe.config.GFESiteActivation; import com.raytheon.edex.plugin.gfe.server.GridParmManager; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.edex.plugin.gfe.server.database.GridDatabase; import com.raytheon.edex.plugin.gfe.util.SendNotifications; import com.raytheon.uf.common.dataplugin.PluginException; @@ -93,6 +92,7 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery; * 05/22/13 #2025 dgilling Re-implement functions needed by * GetLatestDbTimeRequest and GetLatestModelDbIdRequest. * 05/20/13 #2127 rjpeter Set session's to read only and switched to stateless where possible. + * 06/13/13 #2044 randerso Refactored to use IFPServer, code cleanup * * * @author bphillip @@ -102,6 +102,9 @@ public class GFEDao extends DefaultPluginDao { // Number of retries on insert of a new DatabaseID private static final int QUERY_RETRY = 2; + /** + * @throws PluginException + */ public GFEDao() throws PluginException { super("gfe"); } @@ -109,6 +112,8 @@ public class GFEDao extends DefaultPluginDao { /** * Creates a new GFE Dao * + * @param pluginName + * * @throws PluginException */ public GFEDao(String pluginName) throws PluginException { @@ -120,7 +125,8 @@ public class GFEDao extends DefaultPluginDao { * the row will be created. * * @param dbId - * @return + * @return a DatabaseID with id field initialized + * @throws DataAccessLayerException */ public DatabaseID getDatabaseId(DatabaseID dbId) throws DataAccessLayerException { @@ -208,10 +214,9 @@ public class GFEDao extends DefaultPluginDao { * Retrieves all known parm ids for the given database id. * * @param dbId - * @return + * @return the list of ParmIDs for the database * @throws DataAccessLayerException */ - @SuppressWarnings("unchecked") public List getParmIds(final DatabaseID dbId) throws DataAccessLayerException { Session sess = null; @@ -229,6 +234,7 @@ public class GFEDao extends DefaultPluginDao { Query query = sess.createQuery("FROM ParmID WHERE dbId = ?"); query.setParameter(0, dbId); + @SuppressWarnings("unchecked") List list = query.list(); tx.commit(); return list; @@ -260,8 +266,9 @@ public class GFEDao extends DefaultPluginDao { * Returns the database row for the passed parmId. If the row does not * exist, the row will be created. * - * @param dbId - * @return + * @param parmId + * @return the ParmID from the database with id field initialized + * @throws DataAccessLayerException */ public ParmID getParmId(final ParmID parmId) throws DataAccessLayerException { @@ -352,15 +359,15 @@ public class GFEDao extends DefaultPluginDao { @Override public void purgeExpiredData() throws PluginException { - Set sites = GFESiteActivation.getInstance().getActiveSites(); - for (String siteID : sites) { + List ifpServers = IFPServer.getActiveServers(); + for (IFPServer ifpServer : ifpServers) { List gridNotifcations = new ArrayList(); List lockNotifications = new ArrayList(); try { - GridParmManager.versionPurge(siteID); - GridParmManager.gridsPurge(gridNotifcations, lockNotifications, - siteID); + GridParmManager gridParmMgr = ifpServer.getGridParmMgr(); + gridParmMgr.versionPurge(); + gridParmMgr.gridsPurge(gridNotifcations, lockNotifications); PurgeLogger.logInfo( "Purging Expired pending isc send requests...", "gfe"); int requestsPurged = new IscSendRecordDao() @@ -377,9 +384,16 @@ public class GFEDao extends DefaultPluginDao { } } + /** + * Purge all DatabaseIDs for a site + * + * @param siteID + * @return number of rows purged + * @throws DataAccessLayerException + */ public int purgeDatabaseForSite(final String siteID) throws DataAccessLayerException { - return (Integer) txTemplate.execute(new TransactionCallback() { + return txTemplate.execute(new TransactionCallback() { @Override public Integer doInTransaction(TransactionStatus status) { return getHibernateTemplate().bulkUpdate( @@ -391,20 +405,12 @@ public class GFEDao extends DefaultPluginDao { /** * * @param records - * @return + * @throws DataAccessLayerException */ public void save(final Collection records) throws DataAccessLayerException { // validate fields for (GFERecord rec : records) { - if (rec.getIdentifier() == null) { - try { - rec.constructDataURI(); - } catch (Exception e) { - e.printStackTrace(); - } - } - if (rec.getInsertTime() == null) { rec.setInsertTime(Calendar.getInstance()); } @@ -455,6 +461,7 @@ public class GFEDao extends DefaultPluginDao { * the record, update all existing histories, and insert all new histories. * * @param existingRecords + * @throws DataAccessLayerException */ public void update(final Collection existingRecords) throws DataAccessLayerException { @@ -540,19 +547,21 @@ public class GFEDao extends DefaultPluginDao { * * @return The list of all database IDs currently being stored in the * database + * @throws DataAccessLayerException */ - @SuppressWarnings("unchecked") public List getDatabaseInventory(final String siteId) throws DataAccessLayerException { - // TODO: Should this be done from GridParmManager? try { - return (List) txTemplate - .execute(new TransactionCallback() { + return txTemplate + .execute(new TransactionCallback>() { @Override public List doInTransaction( TransactionStatus status) { - return getHibernateTemplate().find( - "FROM DatabaseID WHERE siteId = ?", siteId); + @SuppressWarnings("unchecked") + List result = getHibernateTemplate() + .find("FROM DatabaseID WHERE siteId = ?", + siteId); + return result; } }); } catch (Exception e) { @@ -571,7 +580,6 @@ public class GFEDao extends DefaultPluginDao { * @throws DataAccessLayerException * If errors occur during the query */ - @SuppressWarnings("unchecked") public List queryByParmID(final ParmID parmId) throws DataAccessLayerException { Session sess = null; @@ -588,6 +596,7 @@ public class GFEDao extends DefaultPluginDao { Query query = sess.createQuery("FROM GFERecord WHERE parmId = ?"); query.setParameter(0, parmId); + @SuppressWarnings("unchecked") List list = query.list(); tx.commit(); return list; @@ -615,10 +624,11 @@ public class GFEDao extends DefaultPluginDao { } /** + * Get all GFERecords whose time ranges overlap the specificed time range * * @param parmId * @param tr - * @return + * @return map of TimeRanges to GFERecords * @throws DataAccessLayerException */ @SuppressWarnings("unchecked") @@ -765,18 +775,19 @@ public class GFEDao extends DefaultPluginDao { * @return The list of times for a given parm name and level * @throws DataAccessLayerException */ - @SuppressWarnings("unchecked") public List getTimes(final ParmID parmId) throws DataAccessLayerException { try { - return (List) txTemplate - .execute(new TransactionCallback() { + return txTemplate + .execute(new TransactionCallback>() { @Override public List doInTransaction( TransactionStatus status) { - return getHibernateTemplate() + @SuppressWarnings("unchecked") + List result = getHibernateTemplate() .find("SELECT dataTime.validPeriod FROM GFERecord WHERE parmId = ? ORDER BY dataTime.validPeriod.start", parmId); + return result; } }); } catch (Exception e) { @@ -796,15 +807,15 @@ public class GFEDao extends DefaultPluginDao { * @return The list of times for a given parm name and level * @throws DataAccessLayerException */ - @SuppressWarnings("unchecked") public List getOverlappingTimes(final ParmID parmId, final TimeRange tr) throws DataAccessLayerException { try { - return (List) txTemplate - .execute(new TransactionCallback() { + return txTemplate + .execute(new TransactionCallback>() { @Override public List doInTransaction( TransactionStatus status) { + @SuppressWarnings("unchecked") List rval = getHibernateTemplate() .find("SELECT dataTime.validPeriod" + " FROM GFERecord WHERE parmId = ?" @@ -896,6 +907,11 @@ public class GFEDao extends DefaultPluginDao { return history; } + /** + * Remove all GFE records for a particular DatabaseID + * + * @param dbId + */ public void purgeGFEGrids(final DatabaseID dbId) { delete(dbId); } @@ -1003,7 +1019,8 @@ public class GFEDao extends DefaultPluginDao { * @param parmId * @param tr * @param sentTime - * @return + * @return the histories that were updated + * @throws DataAccessLayerException */ @SuppressWarnings("unchecked") public Map> updateSentTime( @@ -1081,6 +1098,13 @@ public class GFEDao extends DefaultPluginDao { return history; } + /** + * Delete a list of records from the database + * + * @param records + * @return number of records deleted + * @throws DataAccessLayerException + */ public int deleteRecords(Collection records) throws DataAccessLayerException { List ids = new ArrayList(records.size()); @@ -1122,7 +1146,13 @@ public class GFEDao extends DefaultPluginDao { } } - @SuppressWarnings("unchecked") + /** + * Return the latest insert time for a database + * + * @param dbId + * @return latest insert time or null if no database has no records + * @throws DataAccessLayerException + */ public Date getMaxInsertTimeByDbId(final DatabaseID dbId) throws DataAccessLayerException { DatabaseQuery query = new DatabaseQuery(this.daoClass); @@ -1132,6 +1162,7 @@ public class GFEDao extends DefaultPluginDao { query.addOrder("insertTime", false); query.setMaxResults(1); + @SuppressWarnings("unchecked") List result = (List) this.queryByCriteria(query); if (!result.isEmpty()) { return result.get(0).getTime(); @@ -1140,21 +1171,31 @@ public class GFEDao extends DefaultPluginDao { } } - @SuppressWarnings("unchecked") + /** + * Find DatabaseID of latest model run + * + * @param siteId + * @param modelName + * the name of the desired model + * @return the DatabaseID or null if none found + * @throws DataAccessLayerException + */ public DatabaseID getLatestDbIdByModelName(final String siteId, final String modelName) throws DataAccessLayerException { // TODO: Should this be done from GridParmManager? List results = Collections.emptyList(); try { final String[] queryParams = { siteId, modelName }; - results = (List) txTemplate - .execute(new TransactionCallback() { + results = txTemplate + .execute(new TransactionCallback>() { @Override public List doInTransaction( TransactionStatus status) { - return getHibernateTemplate() + @SuppressWarnings("unchecked") + List result = getHibernateTemplate() .find("FROM DatabaseID WHERE siteId = ? AND modelName = ? ORDER BY modelTime DESC LIMIT 1", - queryParams); + (Object[]) queryParams); + return result; } }); } catch (Exception e) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/GfeIRT.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/GfeIRT.java index c723397310..ae835c32b4 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/GfeIRT.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/GfeIRT.java @@ -32,8 +32,7 @@ import jep.JepException; import com.raytheon.edex.plugin.gfe.config.GridDbConfig; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; -import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; @@ -60,6 +59,7 @@ import com.raytheon.uf.common.util.FileUtil; * ------------ ---------- ----------- -------------------------- * 07/14/09 1995 bphillip Initial creation * Mar 14, 2013 1794 djohnson FileUtil.listFiles now returns List. + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @@ -75,6 +75,8 @@ public class GfeIRT extends Thread { /** The site ID associated with this IRT thread */ private final String siteID; + private final IFPServerConfig config; + /** The MHS ID associated with this IRT thread */ private final String mhsID; @@ -96,10 +98,11 @@ public class GfeIRT extends Thread { * The site ID to create the GfeIRT object for * @throws GfeException */ - public GfeIRT(String mhsid, String siteid) throws GfeException { + public GfeIRT(String siteid, IFPServerConfig config) throws GfeException { this.setDaemon(true); this.siteID = siteid; - this.mhsID = mhsid; + this.config = config; + this.mhsID = config.getMhsid(); IPathManager pathMgr = PathManagerFactory.getPathManager(); LocalizationContext cx = pathMgr.getContext( LocalizationType.EDEX_STATIC, LocalizationLevel.BASE); @@ -118,7 +121,7 @@ public class GfeIRT extends Thread { } }; java.lang.Runtime.getRuntime().addShutdownHook(hook); - shutdownHooks.put(mhsid + siteid, hook); + shutdownHooks.put(mhsID + siteID, hook); } @Override @@ -132,11 +135,8 @@ public class GfeIRT extends Thread { script = new PythonScript(scriptFile, includePath); Map args = new HashMap(); - IFPServerConfig config = IFPServerConfigManager - .getServerConfig(siteID); GridLocation domain = config.dbDomain(); - String site = config.getSiteID().get(0); List gridDims = new ArrayList(); gridDims.add(domain.getNy()); gridDims.add(domain.getNx()); @@ -150,13 +150,15 @@ public class GfeIRT extends Thread { // determine which parms are wanted List parmsWanted = config.requestedISCparms(); if (parmsWanted.isEmpty()) { - List dbs = GridParmManager.getDbInventory(site) - .getPayload(); + // TODO gridParmMgr should be passed in when GFEIRT created + // whole class needs clean up + List dbs = IFPServer.getActiveServer(siteID) + .getGridParmMgr().getDbInventory().getPayload(); for (int i = 0; i < dbs.size(); i++) { if (dbs.get(i).getModelName().equals("ISC") && dbs.get(i).getDbType().equals("") - && dbs.get(i).getSiteId().equals(site)) { + && dbs.get(i).getSiteId().equals(siteID)) { GridDbConfig gdc = config.gridDbConfig(dbs.get(i)); parmsWanted = gdc.parmAndLevelList(); } @@ -177,7 +179,7 @@ public class GfeIRT extends Thread { LocalizationContext commonStaticConfig = pathMgr.getContext( LocalizationType.COMMON_STATIC, LocalizationLevel.CONFIGURED); - commonStaticConfig.setContextName(site); + commonStaticConfig.setContextName(siteID); File editAreaDir = pathMgr.getFile(commonStaticConfig, "gfe/editAreas"); @@ -187,8 +189,8 @@ public class GfeIRT extends Thread { return name.trim().matches("ISC_\\p{Alnum}{3}\\.xml"); } }; - List editAreas = FileUtil.listFiles(editAreaDir, - filter, false); + List editAreas = FileUtil.listFiles(editAreaDir, filter, + false); String name = ""; for (File f : editAreas) { @@ -206,7 +208,7 @@ public class GfeIRT extends Thread { args.put("serverHost", config.getServerHost()); args.put("serverPort", config.getRpcPort()); args.put("serverProtocol", config.getProtocolVersion()); - args.put("site", site); + args.put("site", siteID); args.put("parmsWanted", config.requestedISCparms()); args.put("gridDims", gridDims); args.put("gridProj", domain.getProjection().getProjectionID() @@ -224,10 +226,6 @@ public class GfeIRT extends Thread { statusHandler .fatal("Error starting GFE ISC. ISC functionality will be unavailable!!", e); - } catch (GfeException e) { - statusHandler - .fatal("Unable to get Mhs ID. ISC functionality will be unavailable!!", - e); } finally { if (script != null) { script.dispose(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IRTManager.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IRTManager.java index ac092a4dfe..b9885bf38a 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IRTManager.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IRTManager.java @@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; /** @@ -39,6 +40,7 @@ import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 08/10/09 1995 bphillip Initial creation + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @@ -81,13 +83,17 @@ public class IRTManager { * * @param siteID * The site to activate ISC functionality for + * @param config + * server configuration * @throws GfeException * If the ISC functionality cannot be activated */ - public void enableISC(String siteID, String mhsID) throws GfeException { + public void enableISC(String siteID, IFPServerConfig config) + throws GfeException { + String mhsID = config.getMhsid(); if (!irtMap.containsKey(mhsID + "--" + siteID)) { - irtMap.put(mhsID + "--" + siteID, new GfeIRT(mhsID, siteID)); + irtMap.put(mhsID + "--" + siteID, new GfeIRT(siteID, config)); } logger.info("Starting IRT registration thread for site [" + siteID diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendJob.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendJob.java index 6e8c94dd2f..e96d5562ad 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendJob.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendJob.java @@ -35,10 +35,11 @@ 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.exception.GfeConfigurationException; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.edex.plugin.gfe.server.database.GridDatabase; import com.raytheon.edex.plugin.gfe.util.SendNotifications; 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.server.message.ServerResponse; import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridHistoryUpdateNotification; @@ -62,6 +63,7 @@ import com.raytheon.uf.edex.core.EDEXUtil; * from queue into run(). * 04/23/13 #1949 rjpeter Move setting of lastSentTime to dao * and removed initial delay. + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @author bphillip @@ -198,24 +200,44 @@ public class IscSendJob implements Runnable { } try { - GridDatabase gridDb = GridParmManager.getDb(id.getDbId()); - ServerResponse>> sr = gridDb - .updateSentTime(id, tr, new Date()); - if (sr.isOkay()) { - WsId wsId = new WsId(InetAddress.getLocalHost(), "ISC", - "ISC"); - List notifications = new ArrayList( - 1); - Map> histories = sr - .getPayload(); - notifications.add(new GridHistoryUpdateNotification(id, - histories, wsId, siteId)); - SendNotifications.send(notifications); + DatabaseID dbId = id.getDbId(); + IFPServer ifpServer = IFPServer.getActiveServer(dbId + .getSiteId()); + if (ifpServer != null) { + GridDatabase gridDb = ifpServer.getGridParmMgr() + .getDatabase(dbId); + if (gridDb != null) { + ServerResponse>> sr = gridDb + .updateSentTime(id, tr, new Date()); + if (sr.isOkay()) { + WsId wsId = new WsId(InetAddress.getLocalHost(), + "ISC", "ISC"); + List notifications = new ArrayList( + 1); + Map> 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()); + } + } else { + // no such database exists + statusHandler + .error("Error processing ISC send request for :" + + dbId + + ", the database does not exist."); + } } else { + // no active server for request statusHandler - .error("Error updating last sent times in GFERecords: " - + sr.getMessages()); + .error("Error processing ISC send request for :" + + dbId + ", no active IFPServer for site."); } } catch (Exception e) { statusHandler.error( diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/ServiceISCRequest.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/ServiceISCRequest.java index 4606ecde26..792ad6d6c1 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/ServiceISCRequest.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/ServiceISCRequest.java @@ -25,9 +25,7 @@ import java.util.List; import com.raytheon.edex.plugin.gfe.config.GridDbConfig; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; -import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; -import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; +import com.raytheon.edex.plugin.gfe.server.IFPServer; 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; @@ -43,6 +41,7 @@ import com.raytheon.uf.common.time.TimeRange; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 08/21/09 1995 bphillip Initial port + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @@ -51,20 +50,25 @@ import com.raytheon.uf.common.time.TimeRange; */ public class ServiceISCRequest { + /** + * @param parmNameAndLevels + * @param requestorDestinationXML + * @param siteID + * @throws GfeException + */ public static void serviceRequest(List parmNameAndLevels, String requestorDestinationXML, String siteID) throws GfeException { - IFPServerConfig config = null; - try { - config = IFPServerConfigManager.getServerConfig(siteID); - } catch (GfeConfigurationException e) { - throw new GfeException("Unable to get Server config for site[" - + siteID + "]", e); + IFPServer ifpServer = IFPServer.getActiveServer(siteID); + if (ifpServer == null) { + throw new GfeException("No active IFPServer for site: " + siteID); } + IFPServerConfig config = ifpServer.getConfig(); + // find the forecast database List parmsAvailable = new ArrayList(); - List dbs = GridParmManager.getDbInventory(siteID) + List dbs = ifpServer.getGridParmMgr().getDbInventory() .getPayload(); DatabaseID db = null; diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/D2DSatParm.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/D2DSatParm.java index 7db2df5dff..276ad33ef7 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/D2DSatParm.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/D2DSatParm.java @@ -20,13 +20,18 @@ package com.raytheon.edex.plugin.gfe.server; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentSkipListSet; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.edex.plugin.satellite.dao.SatelliteDao; +import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; import com.raytheon.uf.common.dataplugin.gfe.RemapGrid; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; @@ -35,13 +40,14 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.TimeConstraints; +import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DByte; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; +import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotification; import com.raytheon.uf.common.dataplugin.gfe.server.request.GetGridRequest; import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; import com.raytheon.uf.common.dataplugin.gfe.slice.ScalarGridSlice; -import com.raytheon.uf.common.dataplugin.satellite.SatMapCoverage; import com.raytheon.uf.common.dataplugin.satellite.SatelliteRecord; import com.raytheon.uf.common.datastorage.records.ByteDataRecord; import com.raytheon.uf.common.status.IUFStatusHandler; @@ -63,6 +69,7 @@ import com.raytheon.uf.edex.database.plugin.PluginFactory; * Mar 25, 2013 1823 dgilling Disassociate data from Source and * CreatingEntity metadata, rely only * on SectorId and PhysicalElement as in A1. + * Jun 13, 2013 2044 randerso Fixed satellite time matching * * * @@ -70,14 +77,12 @@ import com.raytheon.uf.edex.database.plugin.PluginFactory; * @version 1.0 */ -public class D2DSatParm extends GridParm { +public class D2DSatParm { - /** The log handler */ + /** The statusHandler */ private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(D2DSatParm.class); - private static final long TIME_MATCH_FACTOR = 3 * TimeUtil.MILLIS_PER_MINUTE; - /** The ParmID associated with this D2DSatParm */ private ParmID pid; @@ -93,6 +98,10 @@ public class D2DSatParm extends GridParm { /** The physical element for this satellite data */ private String physicalElement; + private ConcurrentSkipListSet inventory; + + private SatelliteDao satDao; + /** * Creates a new D2DSatParm * @@ -104,18 +113,27 @@ public class D2DSatParm extends GridParm { * The databaseID of the satellite database * @param parmName * The parm name + * @throws GfeException */ public D2DSatParm(IFPServerConfig config, String productURI, - DatabaseID dbId, String parmName) { + DatabaseID dbId, String parmName) throws GfeException { this.config = config; this.pid = new ParmID(parmName, dbId); - if (productURI != null && productURI.contains("/")) { + try { + this.satDao = (SatelliteDao) PluginFactory.getInstance() + .getPluginDao("satellite"); + } catch (PluginException e) { + throw new GfeException("Unable to create SatelliteDao", e); + } + + if ((productURI != null) && productURI.contains("/")) { if (productURI.startsWith("/")) { productURI = productURI.substring(1); } String[] tokens = productURI.split("/"); sectorID = tokens[0]; physicalElement = tokens[1]; + this.inventory = getDbInventory(); } } @@ -128,49 +146,51 @@ public class D2DSatParm extends GridParm { return this.pid; } - @Override - public boolean isValid() { - return true; - } - /** - * @return + * @return ServerResponse containing list of available time ranges if + * successful */ - @Override public ServerResponse> getGridInventory() { ServerResponse> sr = new ServerResponse>(); - List inventory = new ArrayList(); - List satInventory = new ArrayList(); - - SatelliteDao satDao = null; - try { - satDao = (SatelliteDao) PluginFactory.getInstance().getPluginDao( - "satellite"); - - satInventory = satDao.getSatelliteInventory(null, null, sectorID, - physicalElement); - } catch (Exception e) { - statusHandler.error("Error getting inventory for sectorID [" - + sectorID + "] and physicalElement [" + physicalElement - + "]. " + e.getLocalizedMessage()); - sr.addMessage("Error getting inventory for sectorID [" + sectorID - + "] and physicalElement [" + physicalElement + "]. " - + e.getLocalizedMessage()); - return sr; - } - - for (Date d : satInventory) { - inventory.add(new TimeRange(d, tc.getDuration() * 1000)); - } - sr.setPayload(inventory); + sr.setPayload(new ArrayList(this.inventory)); return sr; } /** * @return - * + * @throws GfeException + */ + private ConcurrentSkipListSet getDbInventory() + throws GfeException { + List satInventory = new ArrayList(); + int desiredVersions = config.desiredDbVersions(pid.getDbId()); + + try { + satInventory = satDao.getSatelliteInventory(null, null, sectorID, + physicalElement, desiredVersions); + } catch (Exception e) { + throw new GfeException("Error getting inventory for sectorID [" + + sectorID + "] and physicalElement [" + physicalElement + + "].", e); + } + + ConcurrentSkipListSet dbInventory = new ConcurrentSkipListSet(); + for (Date d : satInventory) { + Date start = truncateSeconds(d); + dbInventory.add(new TimeRange(start, tc.getDuration() * 1000)); + } + return dbInventory; + } + + private Date truncateSeconds(Date date) { + // truncate seconds + return new Date((date.getTime() / TimeUtil.MILLIS_PER_MINUTE) + * TimeUtil.MILLIS_PER_MINUTE); + } + + /** + * @return the grid parm info */ - @Override public ServerResponse getGridParmInfo() { ServerResponse gpi = new ServerResponse(); GridParmInfo info = new GridParmInfo(pid, config.dbDomain(), @@ -181,9 +201,9 @@ public class D2DSatParm extends GridParm { } /** - * @return + * @param inventory + * @return map of time ranges to lists of grid histories */ - @Override public ServerResponse>> getGridHistory( List inventory) { ServerResponse>> sr = new ServerResponse>>(); @@ -200,27 +220,25 @@ public class D2DSatParm extends GridParm { } /** - * @return + * @param getRequest + * @param badDataTimes + * @return ServerResponse containing list of grid slices if successful */ - @Override public ServerResponse> getGridData( GetGridRequest getRequest, List badDataTimes) { List timeRanges = getRequest.getTimes(); ServerResponse> sr = new ServerResponse>(); - List inventory = getGridInventory().getPayload(); List gridSlices = new ArrayList(); - List matchedTimes = matchRequestTimes(timeRanges, inventory); - SatelliteDao dao = null; try { dao = (SatelliteDao) PluginFactory.getInstance().getPluginDao( "satellite"); - List satRecords = dao.getSatelliteData(null, null, - sectorID, physicalElement, rangesToDates(matchedTimes)); + List satRecords = dao.getSatelliteData(sectorID, + physicalElement, timeRanges); for (int i = 0; i < satRecords.size(); i++) { - GridLocation satGridLoc = satMapCoverageToGridLocation(satRecords - .get(i).getCoverage()); + GridLocation satGridLoc = new GridLocation(this.pid.toString(), + satRecords.get(i).getCoverage()); ByteDataRecord hdf5Record = (ByteDataRecord) satRecords.get(i) .getMessageData(); Grid2DByte rawData = new Grid2DByte( @@ -252,31 +270,6 @@ public class D2DSatParm extends GridParm { return sr; } - /** - * @param reqTimeRanges - * @param inventory - * @return - */ - private List matchRequestTimes(List reqTimeRanges, - List inventory) { - List retVal = new ArrayList(reqTimeRanges.size()); - - for (TimeRange tr : reqTimeRanges) { - TimeRange matchRange = new TimeRange(tr.getStart().getTime() - - TIME_MATCH_FACTOR, tr.getEnd().getTime() - + TIME_MATCH_FACTOR); - - for (TimeRange invTR : inventory) { - if (matchRange.contains(invTR)) { - retVal.add(invTR); - break; - } - } - } - - return retVal; - } - /** * Utility function to convert byte data to floats * @@ -297,36 +290,87 @@ public class D2DSatParm extends GridParm { } /** - * Converts satellite map coverage data to GFE compatible coverage for use - * with RemapGrid + * Update inventory based on uri notification * - * @param coverage - * The satellite map coverage to be converted - * @return The GFE compatible version of the satellite map coverage + * @param record + * @return GridUpdateNotification to be sent if inventory updated or null */ - private GridLocation satMapCoverageToGridLocation(SatMapCoverage coverage) { - GridLocation location = new GridLocation(); - location.setCrsObject(coverage.getCrs()); - location.setGeometry(coverage.getGeometry()); - location.setNx(coverage.getNx()); - location.setNy(coverage.getNy()); - return location; + public GridUpdateNotification update(SatelliteRecord record) { + GridUpdateNotification notify = null; + Date validTime = record.getDataTime().getValidPeriod().getStart(); + Date start = truncateSeconds(validTime); + TimeRange tr = new TimeRange(start, tc.getDuration() * 1000); + if (!inventory.contains(tr)) { + this.inventory.add(tr); + notify = new GridUpdateNotification(pid, tr, getGridHistory( + Arrays.asList(tr)).getPayload(), null, pid.getDbId() + .getSiteId()); + } + return notify; } /** - * Extracts the start times from a list of time ranges and places them in a - * list + * Update inventory from database and return GridUpdateNotifications * - * @param ranges - * The timeranges to extract the start times from - * @return The list of start time Dates + * @return the list of GridUpdateNotifications */ - private List rangesToDates(List ranges) { - List dates = new ArrayList(); - for (TimeRange range : ranges) { - dates.add(range.getStart()); + public List updateFromDb() { + List notifs; + + try { + ConcurrentSkipListSet newInventory = getDbInventory(); + + List adds = new ArrayList(newInventory); + adds.removeAll(inventory); + + List deletes = new ArrayList(inventory); + deletes.removeAll(newInventory); + + this.inventory = newInventory; + + notifs = new ArrayList(adds.size() + + deletes.size()); + for (TimeRange tr : adds) { + notifs.add(new GridUpdateNotification(pid, tr, getGridHistory( + Arrays.asList(tr)).getPayload(), null, pid.getDbId() + .getSiteId())); + } + + // empty histories map for deletes + Map> histories = Collections + .emptyMap(); + for (TimeRange tr : deletes) { + notifs.add(new GridUpdateNotification(pid, tr, histories, null, + pid.getDbId().getSiteId())); + } + } catch (GfeException e) { + statusHandler.error(e.getLocalizedMessage(), e); + notifs = Collections.emptyList(); + } + + return notifs; + } + + /** + * Update inventory from GridUpdateNotification + * + * @param gun + * the GridUpdateNotification + */ + public void update(GridUpdateNotification gun) { + TimeRange replace = gun.getReplacementTimeRange(); + + Iterator iter = inventory.iterator(); + while (iter.hasNext()) { + TimeRange tr = iter.next(); + if (replace.contains(tr)) { + iter.remove(); + } + } + + for (TimeRange tr : gun.getHistories().keySet()) { + inventory.add(tr); } - return dates; } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParm.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParm.java index 60ef84650d..992f1aa255 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParm.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParm.java @@ -75,6 +75,7 @@ import com.raytheon.uf.edex.database.plugin.PluginFactory; * 03/15/13 #1795 njensen Added updatePublishTime() * 04/23/13 #1949 rjpeter Removed excess validation on retrieval, added * inventory for a given time range. + * 06/13/13 #2044 randerso Refactored to use non-singleton LockManager * * * @author bphillip @@ -92,11 +93,16 @@ public class GridParm { /** The parm ID associated with this GridParm */ private ParmID id; + private LockManager lockMgr; + /** The grid database associated with this GridParm */ private GridDatabase db; List badDataTimes = new ArrayList(); + /** + * @return the bad data times + */ public List getBadDataTimes() { return badDataTimes; } @@ -113,15 +119,20 @@ public class GridParm { * * @param id * The parm ID associated with this GridParm + * @param lockMgr + * the LockManager instance to be used by this GridParm * @param db * The GridDatabase associated with this GridParm */ - public GridParm(ParmID id, GridDatabase db) { + public GridParm(ParmID id, LockManager lockMgr, GridDatabase db) { this.id = id; + this.lockMgr = lockMgr; this.db = db; - } + /** + * @return true if this GridParm's ParmID is valid + */ public boolean isValid() { return id.isValid(); } @@ -139,6 +150,8 @@ public class GridParm { * Returns the grid inventory for this parameter that overlaps the given * timeRange * + * @param tr + * the timeRange * @return The server response containing the grid inventory */ public ServerResponse> getGridInventory(TimeRange tr) { @@ -166,7 +179,7 @@ public class GridParm { * the histories to alter in the database * @param publishTime * the publish time to update to - * @return + * @return ServerResponse containing status only */ public ServerResponse updatePublishTime( Collection> history, Date publishTime) { @@ -213,7 +226,7 @@ public class GridParm { * @return The server response */ public ServerResponse saveGridData(SaveGridRequest saveRequest, - WsId requesterId, String siteID) { + WsId requesterId) { ServerResponse sr = new ServerResponse(); @@ -260,7 +273,7 @@ public class GridParm { // ensure the locks are okay sr.addMessages(checkLocks(saveRequest.getReplacementTimeRange(), - requesterId, siteID)); + requesterId, this.id.getDbId().getSiteId())); if (!sr.isOkay()) { return sr; } @@ -355,7 +368,7 @@ public class GridParm { */ public ServerResponse timePurge(Date purgeTime, List gridNotifications, - List lockNotifications, String siteID) { + List lockNotifications) { ServerResponse sr = new ServerResponse(); lockNotifications.clear(); @@ -375,9 +388,10 @@ public class GridParm { WsId wsId = new WsId(null, "timePurge", "EDEX"); List lts = new ArrayList(0); + String siteID = this.id.getDbId().getSiteId(); LockTableRequest lockreq = new LockTableRequest(this.id); - ServerResponse> ssr2 = LockManager.getInstance() - .getLockTables(lockreq, wsId, siteID); + ServerResponse> ssr2 = this.lockMgr.getLockTables( + lockreq, wsId); sr.addMessages(ssr2); lts = ssr2.getPayload(); if (!sr.isOkay() || (lts.size() != 1)) { @@ -418,8 +432,8 @@ public class GridParm { lreqs.add(new LockRequest(id, tr, LockMode.BREAK_LOCK)); } - ServerResponse> lockResponse = LockManager - .getInstance().requestLockChange(lreqs, wsId, siteID); + ServerResponse> lockResponse = lockMgr + .requestLockChange(lreqs, wsId); sr.addMessages(lockResponse); if (!sr.isOkay()) { sr.addMessage("Cannot timePurge since the break lock failed"); @@ -452,13 +466,6 @@ public class GridParm { } - /** - * Routine to output statistical information about this instance - */ - public void dumpStatistics() { - // TODO: Do we need this method - } - @Override public String toString() { return "ParmID: " + id; @@ -559,8 +566,8 @@ public class GridParm { // Get the lock table for this parameter LockTableRequest req = new LockTableRequest(id); List lockTables = new ArrayList(); - ServerResponse> ssr = LockManager.getInstance() - .getLockTables(req, requestor, siteID); + ServerResponse> ssr = lockMgr.getLockTables(req, + requestor); lockTables = ssr.getPayload(); sr.addMessages(ssr); if (!sr.isOkay() || (lockTables.size() != 1)) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParmManager.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParmManager.java index 110f104736..6365862127 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParmManager.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/GridParmManager.java @@ -17,7 +17,6 @@ * See the AWIPS II Master Rights File ("Master Rights File.pdf") for * further licensing information. **/ - package com.raytheon.edex.plugin.gfe.server; import java.util.ArrayList; @@ -26,29 +25,29 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.SortedSet; import java.util.concurrent.ConcurrentHashMap; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.raytheon.edex.plugin.gfe.cache.d2dparms.D2DParmIdCache; +import com.raytheon.edex.plugin.gfe.config.GridDbConfig; 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.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.server.database.IFPGridDatabase; import com.raytheon.edex.plugin.gfe.server.database.NetCDFDatabaseManager; -import com.raytheon.edex.plugin.gfe.server.database.TopoDatabaseManager; +import com.raytheon.edex.plugin.gfe.server.database.VGridDatabase; +import com.raytheon.edex.plugin.gfe.server.lock.LockManager; +import com.raytheon.edex.plugin.gfe.smartinit.SmartInitQueue; +import com.raytheon.edex.plugin.gfe.smartinit.SmartInitRecord; import com.raytheon.edex.plugin.gfe.util.SendNotifications; -import com.raytheon.edex.util.Util; 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.DatabaseID.DataType; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; @@ -61,6 +60,8 @@ import com.raytheon.uf.common.dataplugin.gfe.server.request.CommitGridRequest; import com.raytheon.uf.common.dataplugin.gfe.server.request.GetGridRequest; import com.raytheon.uf.common.dataplugin.gfe.server.request.SaveGridRequest; import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; +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.status.IPerformanceStatusHandler; import com.raytheon.uf.common.status.IUFStatusHandler; @@ -71,11 +72,14 @@ import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.common.time.util.ITimer; import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.edex.database.DataAccessLayerException; -import com.raytheon.uf.edex.database.plugin.PluginFactory; +import com.raytheon.uf.edex.database.cluster.ClusterLockUtils; +import com.raytheon.uf.edex.database.cluster.ClusterLockUtils.LockState; +import com.raytheon.uf.edex.database.cluster.ClusterTask; import com.raytheon.uf.edex.database.purge.PurgeLogger; /** - * Class used to manage grid parms + * Class used to manage grid parms. Maintains an in memory cache of all known + * GridDatabase objects * *
  * SOFTWARE HISTORY
@@ -100,6 +104,7 @@ import com.raytheon.uf.edex.database.purge.PurgeLogger;
  *                                     Removed inventory from DBInvChangedNotification
  * 05/03/13     #1974      randerso    Fixed error logging to include stack trace
  * 05/14/13     #2004      randerso    Added methods to synch GridParmManager across JVMs
+ * 05/30/13     #2044      randerso    Refactored to better match A1 design. Removed D2DParmIDCache.
  * 
* * @author bphillip @@ -113,54 +118,78 @@ public class GridParmManager { private static final IPerformanceStatusHandler perfLog = PerformanceStatus .getHandler("GFE:"); - /** The data access object for retrieving GFE grid records */ - private static GFEDao gfeDao; + protected static final String TASK_NAME = "GridParmManager"; - /** The logger */ - private static transient Log logger = LogFactory - .getLog(GridParmManager.class); + private static final String SMART_INIT_TASK_DETAILS = "SmartInit:"; - private static Map dbMap = new ConcurrentHashMap(); + // don't rerun the smart init fire if they have been run in the last 30 + // minutes + private static final int SMART_INIT_TIMEOUT = 1800000; - static { - try { - gfeDao = (GFEDao) PluginFactory.getInstance().getPluginDao("gfe"); - } catch (PluginException e) { - logger.error("Unable to get gfe dao", e); - } - } + private String siteID; + + private IFPServerConfig config; + + private LockManager lockMgr; + + private Map dbMap = new ConcurrentHashMap(); /** - * Creates a new GridParm based on a ParmID + * Construct a GridParmManager * - * @param id - * The parmID for the new GridParm - * @return A grid parm + * @param siteID + * @param config + * @param lockMgr + * @throws PluginException + * @throws DataAccessLayerException * @throws GfeException - * If problems occur while accessing the IFPServer config */ - private static GridParm gridParm(ParmID id) throws GfeException { - if (id.getDbId().getModelName().equals("Satellite")) { - D2DSatDatabase satDb = (D2DSatDatabase) getDb(id.getDbId()); - return satDb.findParm(id); + public GridParmManager(String siteID, IFPServerConfig config, + LockManager lockMgr) throws PluginException, + DataAccessLayerException, GfeException { + this.siteID = siteID; + this.config = config; + this.lockMgr = lockMgr; + this.lockMgr.setGridParmMgr(this); - } - return new GridParm(id, getDb(id.getDbId())); + initializeManager(); } /** - * Returns the grid inventory through "trs" for the parmId. Returns the - * status. Zeros trs. Calls gridParm() to look up the parameter. If not - * found, returns the appropriate error. Calls the grid parm's - * getGridInventory() to obtain the inventory. + * Dispose the GridParmManager + */ + public void dispose() { + NetCDFDatabaseManager.removeDatabases(siteID); + } + + private GridParm gridParm(ParmID id) { + GridDatabase db = getDatabase(id.getDbId()); + if (db != null) { + return createParm(id); + } else { + return new GridParm(); + } + } + + private GridParm createParm(ParmID id) { + GridDatabase db = getDatabase(id.getDbId()); + if (db != null) { + return new GridParm(id, lockMgr, db); + } else { + statusHandler + .debug("No matching GridDatabase for requested ParmID in createParm()"); + // TODO: should we return null? + return new GridParm(); + } + } + + /** + * Get inventory for a parm * * @param parmId - * The parmID to get the inventory for - * @param trs - * The resulting time ranges - * @return The server response + * @return server response containing list of TimeRanges */ - public static ServerResponse> getGridInventory(ParmID parmId) { + public ServerResponse> getGridInventory(ParmID parmId) { ServerResponse> sr = new ServerResponse>(); try { @@ -173,8 +202,8 @@ public class GridParmManager { } } catch (Exception e) { sr.addMessage("Unknown Parm: " + parmId + " in getGridInventory()"); - logger.error("Unknown Parm: " + parmId + " in getGridInventory()", - e); + statusHandler.error("Unknown Parm: " + parmId + + " in getGridInventory()", e); } return sr; @@ -192,8 +221,8 @@ public class GridParmManager { * The timeRange to get the inventory for * @return The server response */ - public static ServerResponse> getGridInventory( - ParmID parmId, TimeRange timeRange) { + public ServerResponse> getGridInventory(ParmID parmId, + TimeRange timeRange) { ServerResponse> sr = new ServerResponse>(); try { @@ -206,28 +235,19 @@ public class GridParmManager { } } catch (Exception e) { sr.addMessage("Unknown Parm: " + parmId + " in getGridInventory()"); - logger.error("Unknown Parm: " + parmId + " in getGridInventory()", - e); + statusHandler.error("Unknown Parm: " + parmId + + " in getGridInventory()", e); } return sr; } /** - * Returns the grid history through "history" for the parmId and specified - * grids. Returns the status. - * - * Zeros trs. Calls gridParm() to look up the parameter. If not found, - * returns the appropriate error. Calls the grid parm's getGridHistory() to - * obtain the histories. - * * @param parmId - * The parmID to get the history for * @param trs - * The time ranges to get the history for - * @return The server response + * @return map of TimeRanges to Lists of GridDataHistorys */ - public static ServerResponse>> getGridHistory( + public ServerResponse>> getGridHistory( ParmID parmId, List trs) { ServerResponse>> sr = new ServerResponse>>(); @@ -241,26 +261,20 @@ public class GridParmManager { } } catch (Exception e) { sr.addMessage("Unknown Parm: " + parmId + " in getGridInventory()"); - logger.error("Unknown Parm: " + parmId + " in getGridInventory()", - e); + statusHandler.error("Unknown Parm: " + parmId + + " in getGridInventory()", e); } return sr; } /** - * * Returns the grid parameter information through "info" for the parmId. - * Returns the status. Calls gridParm() to look up the parameter. If not - * found, resets the GridParmInfo and logs the appropriate error. If found, - * calls the grid parm's getGridParmInfo(). + * Get GridParmInfo for a parm * * @param parmId - * The parmID for which to get GridParmInfo for - * @param info - * The grid parm info - * @return The server status + * @return the GridParmInfo */ - public static ServerResponse getGridParmInfo(ParmID parmId) { + public ServerResponse getGridParmInfo(ParmID parmId) { ServerResponse sr = new ServerResponse(); @@ -275,56 +289,39 @@ public class GridParmManager { } } catch (Exception e) { sr.addMessage("Unknown Parm: " + parmId + " in getGridParmInfo()"); - logger.error("Unknown Parm: " + parmId + " in getGridParmInfo()", e); + statusHandler.error("Unknown Parm: " + parmId + + " in getGridParmInfo()", e); } return sr; } /** - * Request to save grid data. The data is in the saveRequest. The changes - * are returned as notifications through "changes". Returns the status. - * - * Zeros "changes". Loop through each save request and do the following: 1) - * get the gridParm() for the request, 2) call the GridParm's saveGridData, - * 3) call dataTime() on the saveRequest and create a GridUpdateNotification - * and append it to changes. + * Save grid data * * @param saveRequest - * The save requests * @param requestorId - * The workstation ID of the requester - * @param changes - * The update notifications - * @return The server status + * @return ServerResponse with status only */ - public static ServerResponse saveGridData( - List saveRequest, WsId requestorId, String siteID) { + public ServerResponse saveGridData(List saveRequest, + WsId requestorId) { - ServerResponse> sr = new ServerResponse>(); + ServerResponse sr = new ServerResponse(); // process each request for (SaveGridRequest req : saveRequest) { ServerResponse ssr = null; GridParm gp = null; - try { - gp = gridParm(req.getParmId()); - if (!gp.isValid()) { - sr.addMessage("Unknown Parm: " + req.getParmId() - + " in saveGridData()"); - logger.error("Unknown Parm: " + req.getParmId() - + " in saveGridData()"); - continue; - } - } catch (GfeException e1) { + gp = gridParm(req.getParmId()); + if (!gp.isValid()) { sr.addMessage("Unknown Parm: " + req.getParmId() + " in saveGridData()"); - logger.error("Unknown Parm: " + req.getParmId() - + " in saveGridData()", e1); + statusHandler.error("Unknown Parm: " + req.getParmId() + + " in saveGridData()"); continue; } // save the data - ssr = gp.saveGridData(req, requestorId, siteID); + ssr = gp.saveGridData(req, requestorId); sr.addMessages(ssr); if (!ssr.isOkay()) { sr.addMessage("Save Grid Data Failed for: " + req.getParmId() @@ -345,24 +342,12 @@ public class GridParmManager { } /** - * Request for grid data. The data is returned through "data". - * - * Zeroes "data". Loop through each getRequest. For each entry, do the - * following: 1) get the gridParm(), 2) call the grid parm's getGridData, 3) - * append the set of returned GridSlices to the returned argument. In case - * of error, zero data. The changes should always be zero length, unless an - * invalid grid is retrieved from the database; the GridParm class handles - * filling up the changes entry. + * Get grid data * * @param getRequest - * The get data requests - * @param data - * The returned data - * @param changes - * The grid update notifications - * @return The server response + * @return list of grid slices */ - public static ServerResponse> getGridData( + public ServerResponse> getGridData( List getRequest) { ServerResponse> sr = new ServerResponse>(); @@ -389,7 +374,7 @@ public class GridParmManager { } catch (Exception e) { sr.addMessage("Unknown Parm: " + req.getParmId() + " in getGridData()"); - logger.error("Unknown Parm: " + req.getParmId() + statusHandler.error("Unknown Parm: " + req.getParmId() + " in getGridData()", e); } } @@ -398,35 +383,16 @@ public class GridParmManager { } /** - * * Request to commit data to the official database. The changes are - * returned through the calling argument "changes". - * - * Zeros changes. Find the GridDatabase* for the official database. - * - * CommitGridRequests can be of type parm, or of type database. This routine - * converts all database-type requests to individual parm-type requests. - * - * Loop through each commit request and do the following: 1) get the - * gridParm*, 2) get the GridParm's inventory, 3) determine the set of time - * ranges for the grids that overlap but are contained within the commit - * request, 4) get the grid data from the source, 5) verify that the - * GridParmInfo for the source and destination are matched (not exactly - * equal though), 6) modify the retrieved DataSlices GridDataHistory and - * parmID to match the destination, 7) call the official GridDatabase's - * saveGridData(), 8) assemble a GridUpdateNotification and append it to - * changes. + * Commit (Publish) grids * * @param request - * The commit grid request * @param requestorId - * The workstation ID of the requester * @param changes - * The grid update notifications - * @return The server response + * @return list of GridUpdateNotifications for updated grids */ - public static ServerResponse> commitGrid( + public ServerResponse> commitGrid( List request, WsId requestorId, - List changes, String siteID) { + List changes) { ServerResponse> sr = new ServerResponse>(); sr.setPayload(new ArrayList()); @@ -450,7 +416,7 @@ public class GridParmManager { return sr; } - logger.info("Publish/Commit Grids Request: " + parmReq); + statusHandler.info("Publish/Commit Grids Request: " + parmReq); List failures = new ArrayList(); ITimer inventoryTimer = TimeUtil.getTimer(); @@ -468,16 +434,8 @@ public class GridParmManager { // for the source data GridParm sourceGP = null; - try { - sourceGP = gridParm(req.getParmId()); - if (!sourceGP.isValid()) { - ssr.addMessage("Unknown Source Parm: " + req.getParmId() - + " in commitGrid()"); - srDetailed.addMessages(ssr); - failures.add(req); - continue; - } - } catch (GfeException e) { + sourceGP = gridParm(req.getParmId()); + if (!sourceGP.isValid()) { ssr.addMessage("Unknown Source Parm: " + req.getParmId() + " in commitGrid()"); srDetailed.addMessages(ssr); @@ -489,16 +447,8 @@ public class GridParmManager { ParmID destParmId = new ParmID(req.getParmId().getParmName(), officialDBid, req.getParmId().getParmLevel()); GridParm destGP = null; - try { - destGP = gridParm(destParmId); - if (!destGP.isValid()) { - ssr.addMessage("Unknown Destination Parm: " + destGP - + " in commitGrid()"); - srDetailed.addMessages(ssr); - failures.add(req); - continue; - } - } catch (GfeException e) { + destGP = gridParm(destParmId); + if (!destGP.isValid()) { ssr.addMessage("Unknown Destination Parm: " + destGP + " in commitGrid()"); srDetailed.addMessages(ssr); @@ -807,211 +757,153 @@ public class GridParmManager { } /** - * Returns the database inventory in "databases". + * Get database inventory * - * Zeros databases. Sequentially goes through _dbs and extracts out the - * database ids. Returns them. Note that no errors can occur from this - * routine although a ServerResponse is returned. - * - * @param databases - * The database inventory - * @return The server response + * @return list of available DatabaseIDs */ - public static ServerResponse> getDbInventory(String siteID) { + public ServerResponse> getDbInventory() { ServerResponse> sr = new ServerResponse>(); - List databases = new ArrayList(); - List gfeDbs = null; - List singletons = null; - List d2dDbs = null; - try { - gfeDbs = gfeDao.getDatabaseInventory(siteID); - } catch (DataAccessLayerException e) { - sr.addMessage("Unable to get IFP databases for site: " + siteID); - logger.error("Unable to get IFP databases for site: " + siteID, e); - return sr; - } + List databases = new ArrayList( + this.dbMap.keySet()); - d2dDbs = D2DParmIdCache.getInstance().getDatabaseIDs(); - - try { - singletons = IFPServerConfigManager.getServerConfig(siteID) - .getSingletonDatabases(); - } catch (GfeException e) { - sr.addMessage("Unable to get singleton databases"); - logger.error("Unable to get singleton databases", e); - return sr; - } - - if (singletons != null) { - for (DatabaseID singleton : singletons) { - if (singleton.getSiteId().equals(siteID)) { - databases.add(singleton); - } - } - } - - for (DatabaseID dbId : gfeDbs) { - if (!databases.contains(dbId)) { - databases.add(dbId); - } - } - - if (d2dDbs != null) { - for (DatabaseID d2d : d2dDbs) { - if (d2d.getSiteId().equals(siteID)) { - databases.add(d2d); - } - } - } - - DatabaseID topoDbId = TopoDatabaseManager.getTopoDbId(siteID); - databases.add(topoDbId); - databases.addAll(NetCDFDatabaseManager.getDatabaseIds(siteID)); sr.setPayload(databases); return sr; } /** - * Command to create a new database. This functions as a no-op if the - * database already exists. A user cannot create a new database which is the - * singleton type -- since that assumes there is no model time. + * Get a database if available * - * Checks if "id" is a Grid-type database. Checks to see if the database - * already exists. If found, then returns okay. If not found, then calls - * createDB() to handle the creation. - * - * @param id - * The database ID of the database to create - * @return The server response + * @param dbId + * @return GridDatabase or null if not available */ - public static ServerResponse createNewDb(DatabaseID id) { - ServerResponse sr = new ServerResponse(); - if (!id.getFormat().equals(DatabaseID.DataType.GRID)) { - sr.addMessage("Invalid database id for createNewDb(): " + id); + public GridDatabase getDatabase(DatabaseID dbId) { + // look up the database in the map + GridDatabase db = this.dbMap.get(dbId); + + // if db not in map try to create it + if (db == null) { + if (dbId.getDbType().equals("D2D")) { + db = D2DGridDatabase.getDatabase(config, dbId); + } else { + ServerResponse status = createDB(dbId); + if (status.isOkay()) { + db = status.getPayload(); + createDbNotification(Arrays.asList(dbId), null); + } + } + + if (db != null) { + this.addDB(db); + } + } + + return db; + } + + /** + * Create a new database + * + * @param dbId + * @return ServerResponse containing the created database + */ + public ServerResponse createNewDb(DatabaseID dbId) { + + ServerResponse sr = new ServerResponse(); + + if (!dbId.getFormat().equals(DataType.GRID)) { + sr.addMessage("Invalid database id for createNewDb(): " + dbId); return sr; } - // Check if this is a singleton database - DatabaseID idWOTime = id.stripModelTime(); - List dbIds; - try { - dbIds = IFPServerConfigManager.getServerConfig(id.getSiteId()) - .getSingletonDatabases(); - } catch (GfeException e) { - sr.addMessage("Error retrieving singleton databases from IFPServerConfig"); - logger.error( - "Error retrieving singleton databases from IFPServerConfig", - e); - return sr; + GridDatabase db = this.getDatabase(dbId); + if (db != null) { + return sr; // database already exists } - if (dbIds.contains(idWOTime)) { - sr.addMessage("Cannot create database " + id + + // is it a singleton database? + DatabaseID idWOTime = dbId.stripModelTime(); + if (this.config.getSingletonDatabases().contains(idWOTime)) { + sr.addMessage("Cannot create database " + dbId + ". It is a singleton database [" + idWOTime); return sr; } - List inv = getDbInventory(id.getSiteId()).getPayload(); - try { - createDB(id); - if (!inv.contains(id)) { - createDbNotification(id.getSiteId(), - Arrays.asList(new DatabaseID[] { id }), - new ArrayList()); - } - } catch (GfeException e) { - sr.addMessage("Unable to create database: " + id); - logger.error("Unable to create database: " + id, e); - return sr; - } - return sr; } - public static ServerResponse deleteDb(DatabaseID id) { + /** + * Delete database + * + * @param dbId + * @return ServerResponse containg status only + */ + public ServerResponse deleteDb(DatabaseID dbId) { ServerResponse sr = new ServerResponse(); - List inv = getDbInventory(id.getSiteId()).getPayload(); - if (!inv.contains(id)) { + GridDatabase db = this.getDatabase(dbId); + if (db == null) { statusHandler.handle(Priority.PROBLEM, "Cannot delete database " - + id + ". It does not exist"); - sr.addMessage("Cannot delete database " + id + + dbId + ". It does not exist"); + sr.addMessage("Cannot delete database " + dbId + ". It does not exist"); return sr; } - DatabaseID idWOTime = id.stripModelTime(); - IFPServerConfig config = null; - try { - config = IFPServerConfigManager.getServerConfig(id.getSiteId()); - } catch (GfeException e) { - sr.addMessage("Error retrieving serverconfig for " + id.getSiteId()); - statusHandler.handle(Priority.PROBLEM, - "Error retrieving serverconfig for " + id.getSiteId(), e); - return sr; - } - - if (config.getSingletonDatabases().contains(idWOTime)) { - sr.addMessage("Cannot delete database " + id + // is it a singleton or official database? + DatabaseID idWOTime = dbId.stripModelTime(); + if (this.config.getSingletonDatabases().contains(idWOTime)) { + sr.addMessage("Cannot delete database " + dbId + ". It is a singleton database"); statusHandler.handle(Priority.PROBLEM, "Cannot delete database " - + id + ". It is a singleton database"); + + dbId + ". It is a singleton database"); return sr; } - if (config.getOfficialDatabases().contains(idWOTime)) { - sr.addMessage("Cannot delete database " + id + if (this.config.getOfficialDatabases().contains(idWOTime)) { + sr.addMessage("Cannot delete database " + dbId + ". It is an official database"); statusHandler.handle(Priority.PROBLEM, "Cannot delete database " - + id + ". It is an official database"); + + dbId + ". It is an official database"); return sr; } - deallocateDb(id, true); + // delete it + deallocateDb(dbId, true); return sr; } /** - * Returns the parameter list for the given database. + * Retrieve the parm list for database * - * Zeros parmList. Looks up the database using "id". Asks the GridDatabase - * for the parm list. - * - * @param id - * The databases ID to get the parameter list for - * @return The server response + * @param dbId + * @return the parm list */ - public static ServerResponse> getParmList(DatabaseID id) { + public ServerResponse> getParmList(DatabaseID dbId) { + ServerResponse> sr = new ServerResponse>(); - try { - GridDatabase db = getDb(id); - if (db != null) { - sr = db.getParmList(); - } else { - sr.addMessage("Database " + id - + " does not exist for getParmList()"); - } - } catch (Exception e) { - sr.addMessage("Error getting db: " + id); - logger.error("Error getting db: " + id, e); + + GridDatabase db = getDatabase(dbId); + + if (db == null) { + sr.addMessage("Database " + dbId + + " does not exist for getParmList()"); + return sr; } + + sr = db.getParmList(); return sr; } /** - * Performs a database version purge. Returns the status. + * Perform database based on versions * - * Gets the current database inventory. Sorts it. Uses the server config to - * get the number of databases required for each category (e.g., Model) and - * determine which ones to delete. Calls deallocateDB() with the deleteFlag - * set to true for each db to delete. - * - * @return The server response + * @return ServerResponse containing status only */ - public static ServerResponse versionPurge(String siteID) { + public ServerResponse versionPurge() { ServerResponse> sr = new ServerResponse>(); - sr = getDbInventory(siteID); + sr = getDbInventory(); if (!sr.isOkay()) { sr.addMessage("VersionPurge failed - couldn't get inventory"); return sr; @@ -1038,12 +930,7 @@ public class GridParmManager { count = 0; // determine desired number of versions - try { - desiredVersions = IFPServerConfigManager.getServerConfig( - siteID).desiredDbVersions(dbId); - } catch (GfeException e) { - logger.error("Error retreiving serverConfig", e); - } + desiredVersions = this.config.desiredDbVersions(dbId); } // process the id and determine whether it should be purged @@ -1055,35 +942,26 @@ public class GridParmManager { } } - // kludge to keep dbMap in synch until GridParmManager/D2DParmICache - // merge/refactor - dbMap.keySet().retainAll(databases); - - createDbNotification(siteID, databases); + createDbNotification(databases); return sr; } /** - * Command to perform grid purging. Returns the status. - * - * Zeroes the notifications. Go sequentially through the _parms sequence and - * get the purge configuration value from the config file for the database - * by calling purgeTime(), call the GridParm's timePurge() and append its - * returned notifications to this functions notifications. + * Purge grids based on time * * @param gridNotifications - * The grid changed notifications + * list to add GridUpdateNotifications * @param lockNotifications - * The lock notifications - * @return The server response + * list to add LockNotifications + * @return ServerResponse containing status only */ - public static ServerResponse gridsPurge( + public ServerResponse gridsPurge( List gridNotifications, - List lockNotifications, String siteID) { + List lockNotifications) { ServerResponse> sr = new ServerResponse>(); - sr = getDbInventory(siteID); + sr = getDbInventory(); if (!sr.isOkay()) { sr.addMessage("GridsPurge failed - couldn't get inventory"); @@ -1093,10 +971,6 @@ public class GridParmManager { List databases = sr.getPayload(); for (DatabaseID dbId : databases) { - if (dbId.getDbType().equals("D2D")) { - continue; - } - Date purgeTime = purgeTime(dbId); if (purgeTime == null) { continue; @@ -1115,21 +989,16 @@ public class GridParmManager { for (ParmID parmId : parmIds) { List gridNotify = new ArrayList(); List lockNotify = new ArrayList(); - GridParm gp = null; - try { - gp = gridParm(parmId); - } catch (GfeException e) { - sr.addMessage("Error getting parm for: " + parmId); - logger.error("Error getting parm for: " + parmId, e); - continue; - } - ServerResponse sr1 = gp.timePurge(purgeTime, - gridNotify, lockNotify, siteID); - sr.addMessages(sr1); - purgedCount += sr1.getPayload(); + GridParm gp = createParm(parmId); + if (gp.isValid()) { + ServerResponse sr1 = gp.timePurge(purgeTime, + gridNotify, lockNotify); + sr.addMessages(sr1); + purgedCount += sr1.getPayload(); - gridNotifications.addAll(gridNotify); - lockNotifications.addAll(lockNotify); + gridNotifications.addAll(gridNotify); + lockNotifications.addAll(lockNotify); + } } PurgeLogger.logInfo("Purge " + purgedCount + " items from " + dbId, @@ -1139,15 +1008,317 @@ public class GridParmManager { return sr; } - public static Date purgeTime(DatabaseID id) { - int numHours = 0; + private ServerResponse createDB(DatabaseID id) { + ServerResponse status = new ServerResponse(); + GridDatabase db = this.dbMap.get(id); + if (db != null) { + status.setPayload(db); + return status; + } // already exists + + if (!id.isValid() || !id.getFormat().equals(DataType.GRID)) { + status.addMessage("Database id " + + id + + " is not valid, or is not a grid-type. Cannot create database."); + return status; + } + + // create the grid database + GridDbConfig dbConfig = this.config.gridDbConfig(id); + if (dbConfig == null) { + status.addMessage("Unable to obtain GridDbConfig information for creation" + + " in createDB() for " + id); + + // TODO: implement A2 equivalent + // make list of files that match this "bad" database + // TextString dir = PathMgr::dirname(filename) + '/'; + // TextString baseName = PathMgr::basename(filename); + // TextString dbName = PathMgr::stripExtension(baseName); + // SeqOf filenames = PathMgr::listDir(dir); + // unsigned pos = 0; + // TextString badTime = + // AbsTime::current().string("/BADDB-%Y%m%d_%H%M-"); + // for (int i = 0; i < filenames.length(); i++) + // if (PathMgr::isFile(dir + filenames[i]) && + // filenames[i].found(dbName, pos)) + // { + // logVerbose << "Deleting Bogus Database:" << filenames[i] + // << std::endl; + // TextString bdir = _config.baseDir() + "/BAD"; + // PathMgr::mkdir(bdir); + // TextString sourceF = dir + filenames[i]; + // TextString destF = bdir + badTime + filenames[i]; + // TextString cmd = "mv " + sourceF + ' ' + destF; + // system(cmd.stringPtr()); + // logProblem << "Bad database moved to: " << destF << std::endl; + // } + + return status; + } + + // we attempt to create the GridDatabase twice, if fails the 1st time, + // we delete it and try again. Singleton databases get two tries, + // non-singletons are simply deleted if invalid. + int trys = 0; + int maxtrys = 2; + if (id.getModelTime().equals(DatabaseID.NO_MODEL_TIME)) { + maxtrys = 1; + } + + while (trys < maxtrys) { + if (trys != 0) { + statusHandler.error("Attempting to recreate: "); + } + + db = new IFPGridDatabase(id, dbConfig); + // ServerResponse sr; + // sr = db->databaseIsValid(); + // if (sr.okay()) + if (db.databaseIsValid()) { + break; // database is okay - continue processing + } + // + // // error on creating database + // logProblem << "Database invalid with id: " << id << std::endl; + // logProblem << sr << std::endl; + // logProblem << "Deleting bogus database: " << id << std::endl; + // + // // make list of files that match this "bad" database + // TextString dir = PathMgr::dirname(filename) + '/'; + // TextString baseName = PathMgr::basename(filename); + // TextString dbName = PathMgr::stripExtension(baseName); + // SeqOf filenames = PathMgr::listDir(dir); + // TextString badTime = + // AbsTime::current().string("/BADDB-%Y%m%d_%H%M-"); + // unsigned int pos = 0; + // for (int i = 0; i < filenames.length(); i++) + // if (PathMgr::isFile(dir + filenames[i]) + // && filenames[i].found(dbName, pos)) + // { + // TextString bdir = _config.baseDir() + "/BAD"; + // PathMgr::mkdir(bdir); + // TextString sourceF = dir + filenames[i]; + // TextString destF = bdir + badTime + filenames[i]; + // TextString cmd = "mv " + sourceF + ' ' + destF; + // system(cmd.stringPtr()); + // logProblem << "Bad database moved to: " << destF << std::endl; + // } + // //db->deleteDb(); // delete the database (not needed since we + // move + // // files to a "BAD" directory + // delete db; + // db = NULL; + if ((trys + 1) == maxtrys) { // final loop + status.addMessage("Database " + id + " is not valid."); + // status += sr; + return null; + } + trys++; + } + + if (db != null) { + addDB(db); + } // add to list of databases if not-NULL + + status.setPayload(db); + return status; + } + + private void deallocateDb(DatabaseID id, boolean deleteFile) { + GridDatabase db = this.dbMap.remove(id); + + if ((db != null) && deleteFile) { + db.deleteDb(); + } + } + + private void initializeManager() throws GfeException, + DataAccessLayerException, PluginException { + // get existing list (of just GRIDs) + GFEDao gfeDao = new GFEDao(); + List inventory = gfeDao.getDatabaseInventory(siteID); + + // get list of singleton databases from config + // and add them if missing from inventory (GRID-type only) + for (DatabaseID manID : this.config.getSingletonDatabases()) { + if (manID.getFormat().equals(DataType.GRID) + && !inventory.contains(manID)) { + inventory.add(manID); + } + } + + // create the databases (the list should now only contain GRID dbs) + ServerResponse sr = new ServerResponse(); + for (DatabaseID dbId : inventory) { + sr = createDB(dbId); + } + if (!sr.isOkay()) { + statusHandler.error(sr.message()); + } + + NetCDFDatabaseManager.initializeNetCDFDatabases(config); + for (DatabaseID dbId : NetCDFDatabaseManager.getDatabaseIds(siteID)) { + GridDatabase db = NetCDFDatabaseManager.getDb(dbId); + addDB(db); + } + + // Fire up the sat database. + D2DSatDatabase satDb = new D2DSatDatabase(config); + addDB(satDb); + + initD2DDbs(); + + // only fire smartInits if queue is instantiated + SmartInitQueue queue = SmartInitQueue.getQueue(); + if (queue != null) { + // acquire cluster lock since only needs to happen once + ClusterTask ct = ClusterLockUtils.lookupLock(TASK_NAME, + SMART_INIT_TASK_DETAILS + siteID); + + // TODO: reconsider this as changes to localConfig may change what + // smartInits should be run + // TODO: re-enable check + // if ((ct.getLastExecution() + SMART_INIT_TIMEOUT) < System + // .currentTimeMillis()) { + ct = ClusterLockUtils.lock(TASK_NAME, SMART_INIT_TASK_DETAILS + + siteID, SMART_INIT_TIMEOUT, false); + if (LockState.SUCCESSFUL.equals(ct.getLockState())) { + boolean clearTime = false; + try { + for (DatabaseID dbId : this.dbMap.keySet()) { + if (dbId.getDbType().equals("D2D")) { + statusHandler.info("Firing smartinit for: " + dbId); + VGridDatabase db = (VGridDatabase) getDatabase(dbId); + SortedSet validTimes = db.getValidTimes(); + for (Date validTime : validTimes) { + queue.queue( + siteID, + config, + dbId, + validTime, + false, + SmartInitRecord.SITE_ACTIVATION_INIT_PRIORITY); + } + } + } + } finally { + ClusterLockUtils.unlock(ct, clearTime); + } + } + // } + } + } + + private void initD2DDbs() throws GfeException { + for (String d2dModelName : config.getD2dModels()) { + try { + // get dbId to get desiredDbVersions (date doesn't matter) + DatabaseID dbId = D2DGridDatabase.getDbId(d2dModelName, + new Date(), config); + int desiredVersions = config.desiredDbVersions(dbId); + + for (Date refTime : D2DGridDatabase.getModelRunTimes( + d2dModelName, desiredVersions)) { + D2DGridDatabase db = new D2DGridDatabase(config, + d2dModelName, refTime); + addDB(db); + } + } catch (Exception e) { + statusHandler.error("Error initializing D2D model: " + + d2dModelName, e); + } + } + } + + /** + * @param gridRecords + */ + public void filterGridRecords(List gridRecords) { + List guns = new LinkedList(); + for (GridRecord record : gridRecords) { + String d2dModelName = record.getDatasetId(); + Date refTime = record.getDataTime().getRefTime(); + DatabaseID dbId = D2DGridDatabase.getDbId(d2dModelName, refTime, + config); + // not a d2d model we care about + if (dbId == null) { + continue; + } + + D2DGridDatabase db = (D2DGridDatabase) this.dbMap.get(dbId); + if (db == null) { + // New database + try { + db = new D2DGridDatabase(config, d2dModelName, refTime); + } catch (GfeException e) { + statusHandler.error("Error creating D2DGridDatabase: " + + dbId, e); + continue; + } + addDB(db); + statusHandler.info("filterGridRecords new D2D database: " + + dbId); + GfeNotification dbInv = new DBInvChangeNotification( + Arrays.asList(dbId), null, siteID); + SendNotifications.send(dbInv); + } + + GridUpdateNotification gun = db.update(record); + if (gun != null) { + guns.add(gun); + + // only fire smartInits if queue is instantiated + SmartInitQueue queue = SmartInitQueue.getQueue(); + if (queue != null) { + Date validTime = gun.getReplacementTimeRange().getStart(); + queue.queue(siteID, config, dbId, validTime, false, + SmartInitRecord.LIVE_SMART_INIT_PRIORITY); + } + } + } + + // send notifications; + try { + SendNotifications.send(guns); + } catch (Exception e) { + statusHandler.error("Unable to send grib ingest notifications", e); + } + } + + /** + * @param records + */ + public void filterSatelliteRecords(List records) { + + DatabaseID dbId = D2DSatDatabase.getDbId(siteID); + D2DSatDatabase db = (D2DSatDatabase) getDatabase(dbId); + + List guns = new LinkedList(); + for (SatelliteRecord record : records) { + GridUpdateNotification gun = db.update(record); + if (gun != null) { + guns.add(gun); + + // only fire smartInits if queue is instantiated + SmartInitQueue queue = SmartInitQueue.getQueue(); + if (queue != null) { + Date validTime = gun.getReplacementTimeRange().getStart(); + queue.queue(siteID, config, dbId, validTime, false, + SmartInitRecord.LIVE_SMART_INIT_PRIORITY); + } + } + } try { - numHours = IFPServerConfigManager.getServerConfig(id.getSiteId()) - .gridPurgeAgeInHours(id); - } catch (GfeException e) { - logger.error("Error calculating purge time", e); + SendNotifications.send(guns); + } catch (Exception e) { + statusHandler.error( + "Unable to send satellite ingest notifications", e); } + } + + private Date purgeTime(DatabaseID id) { + int numHours = this.config.gridPurgeAgeInHours(id); if (numHours < 1) { return null; // don't perform time based purge @@ -1155,117 +1326,18 @@ public class GridParmManager { // calculate purge time based on present time return new Date(System.currentTimeMillis() - - (numHours * Util.MILLI_PER_HOUR)); + - (numHours * TimeUtil.MILLIS_PER_HOUR)); } - /** - * Creates a new database with the given databaseID.
- * This method retrieves the configuration for this database from the - * IFPServerConfig and creates an hdf5 file - * - * @param dbId - * The database to create - */ - private static GridDatabase createDB(DatabaseID dbId) throws GfeException { - - /* - * Validate the database ID. Throws an exception if the database ID is - * invalid - */ - if (!dbId.isValid() || (dbId.getFormat() != DatabaseID.DataType.GRID)) { - throw new GfeException( - "Database id " - + dbId - + " is not valid, or is not a grid-type. Cannot create database."); - } - - /* - * Create the database (create the hdf5 file) - */ - GridDatabase db = getDb(dbId); - - if (!db.databaseIsValid()) { - throw new GfeException("Database invalid with id: " + dbId); - } - return db; - } - - /** - * Utility method to get the correct type of database - * - * @param dbId - * The database ID of the database to retrieve - * @return The Grid Database or null if database not available - * @throws GfeException - */ - public static GridDatabase getDb(DatabaseID dbId) throws GfeException { - GridDatabase db = dbMap.get(dbId); - if (db == null) { - String dbType = dbId.getDbType(); - String siteId = dbId.getSiteId(); - String modelName = dbId.getModelName(); - if ("D2D".equals(dbType)) { - if (modelName.equals("Satellite")) { - db = D2DSatDatabaseManager.getSatDatabase(dbId.getSiteId()); - - } else { - db = NetCDFDatabaseManager.getDb(dbId); - } - if (db == null) { - IFPServerConfig serverConfig = IFPServerConfigManager - .getServerConfig(siteId); - try { - // this is still necessary on other JVMs from where - // ingested - String d2dModelName = serverConfig - .d2dModelNameMapping(modelName); - db = new D2DGridDatabase(serverConfig, d2dModelName, - dbId.getModelTimeAsDate()); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - e.getLocalizedMessage(), e); - db = null; - } - } - } else { - // Check for topo type - String topoModel = TopoDatabaseManager.getTopoDbId(siteId) - .getModelName(); - if (topoModel.equals(modelName)) { - db = TopoDatabaseManager.getTopoDatabase(dbId.getSiteId()); - - } else { - db = new IFPGridDatabase(dbId); - if (db.databaseIsValid()) { - ((IFPGridDatabase) db).updateDbs(); - } - } - } - - if ((db != null) && db.databaseIsValid()) { - dbMap.put(dbId, db); - } - } - return db; - } - - public static void purgeDbCache(String siteID) { - Iterator iter = dbMap.keySet().iterator(); - while (iter.hasNext()) { - DatabaseID dbId = iter.next(); - if (dbId.getSiteId().equals(siteID)) { - iter.remove(); - } - } - } - - private static ServerResponse getOfficialDB( - CommitGridRequest req) { + private ServerResponse getOfficialDB(CommitGridRequest req) { ServerResponse sr = new ServerResponse(); - GridDatabase officialDBPtr = null; - DatabaseID officialID = new DatabaseID(); + GridDatabase db = null; + DatabaseID officialID = null; + + // Extract out the DatabaseID from the CommitGridRequest + // Note that this database id is the source and not the destination DatabaseID requestID = null; if (req.isParmRequest()) { requestID = req.getParmId().getDbId(); @@ -1275,17 +1347,7 @@ public class GridParmManager { // find name of official database corresponding to the Commit Grid // Request - IFPServerConfig config = null; - try { - config = IFPServerConfigManager.getServerConfig(requestID - .getSiteId()); - } catch (GfeException e) { - sr.addMessage("Unable to IFPServerConfig Instance"); - logger.error("Unable to IFPServerConfig Instance", e); - return sr; - } - for (int i = 0; i < config.getOfficialDatabases().size(); i++) { - DatabaseID off = config.getOfficialDatabases().get(i); + for (DatabaseID off : this.config.getOfficialDatabases()) { // for a match, the siteid, type, and format must be the same if (requestID.getSiteId().equals(off.getSiteId()) && requestID.getDbType().equals(off.getDbType()) @@ -1294,44 +1356,50 @@ public class GridParmManager { break; } } - if (officialID.equals(new DatabaseID())) { + if (officialID == null) { sr.addMessage("No official database specified in config that matches request Req=" + req + " OfficialDBs: " + config.getOfficialDatabases()); sr.addMessage("Commit Grid Operation aborted"); return sr; } - try { - officialDBPtr = getDb(officialID); - } catch (GfeException e) { - sr.addMessage("Unable to create database: " + officialID); - logger.error("Unable to create database: " + officialID, e); - return sr; + // now look up the GridDatabase from the name + db = this.dbMap.get(officialID); + if (db == null) { + sr.addMessage("Official Database [" + officialID + + "] does not exist." + " Commit Grid Operation aborted"); + } else { + sr.setPayload(db); } - sr.setPayload(officialDBPtr); return sr; } - private static ServerResponse> convertToParmReq( + private ServerResponse> convertToParmReq( List in) { ServerResponse> sr = new ServerResponse>(); List out = new ArrayList(); - for (int i = 0; i < in.size(); i++) { - if (in.get(i).isParmRequest()) { - out.add(in.get(i)); - } else if (in.get(i).isDatabaseRequest()) { + for (CommitGridRequest req : in) { + if (req.isParmRequest()) { + out.add(req); + + } else if (req.isDatabaseRequest()) { // get the parm list for this database - List parmList = getParmList(in.get(0).getDbId()) - .getPayload(); - for (int p = 0; p < parmList.size(); p++) { - out.add(new CommitGridRequest(parmList.get(0), in.get(i) - .getTimeRange(), in.get(i).isClientSendStatus())); + GridDatabase db = this.getDatabase(req.getDbId()); + if (db != null) { + List parmList = db.getParmList().getPayload(); + for (ParmID pid : parmList) { + out.add(new CommitGridRequest(pid, req.getTimeRange(), + req.isClientSendStatus())); + } + } else { + sr.addMessage("Could not find database for " + + req.getDbId() + " in convertToParmReq()"); } } else { - sr.addMessage("Invalid Commit Grid Request: " + in.get(i) + sr.addMessage("Invalid Commit Grid Request: " + req + " in convertToParmReq()"); break; } @@ -1350,6 +1418,8 @@ public class GridParmManager { GridParmInfo source, GridParmInfo dest) { ServerResponse sr = new ServerResponse(); + // TODO why is this commented out? + // if (!source.getGridLoc().equals(dest.getGridLoc()) // || source.isTimeIndependentParm() != dest // .isTimeIndependentParm() @@ -1370,20 +1440,19 @@ public class GridParmManager { return sr; } - private static void createDbNotification(String siteID, - List prevInventory) { - List newInventory = getDbInventory(siteID).getPayload(); + private void createDbNotification(List prevInventory) { + List newInventory = getDbInventory().getPayload(); List additions = new ArrayList(newInventory); additions.removeAll(prevInventory); List deletions = new ArrayList(prevInventory); deletions.removeAll(newInventory); - createDbNotification(siteID, additions, deletions); + createDbNotification(additions, deletions); } - private static void createDbNotification(String siteID, - List additions, List deletions) { + private void createDbNotification(List additions, + List deletions) { if (!additions.isEmpty() || !deletions.isEmpty()) { DBInvChangeNotification notify = new DBInvChangeNotification( additions, deletions, siteID); @@ -1391,46 +1460,141 @@ public class GridParmManager { } } - private static void deallocateDb(DatabaseID id, boolean deleteFile) { - if (deleteFile) { - try { - getDb(id).deleteDb(); - } catch (GfeException e) { - statusHandler.handle(Priority.PROBLEM, - "Unable to purge model database: " + id, e); - } - } - dbMap.remove(id); - } - - public static void processNotification(Object msg) { - if (msg instanceof List) { - for (Object obj : (List) msg) { - if (obj instanceof GfeNotification) { - handleGfeNotification((GfeNotification) obj); - } - } - } else if (msg instanceof GfeNotification) { - handleGfeNotification((GfeNotification) msg); - } - } - - private static void handleGfeNotification(GfeNotification notif) { + /** + * @param notif + */ + public void handleGfeNotification(GfeNotification notif) { + // TODO: add UUID or some other identifier (hostname/process id?) to + // notif so we can recognize + // and not process notifications sent by this GridParmManager instance if (notif instanceof DBInvChangeNotification) { DBInvChangeNotification invChanged = (DBInvChangeNotification) notif; + ServerResponse sr = new ServerResponse(); for (DatabaseID dbId : invChanged.getAdditions()) { + if (dbId.getDbType().equals("D2D")) { + try { + this.addDB(new D2DGridDatabase(config, dbId)); + statusHandler + .info("handleGfeNotification new D2D database: " + + dbId); + } catch (GfeException e) { + statusHandler.error("Error creating D2DGridDatabase: " + + dbId, e); + } + } else { + sr = this.createDB(dbId); + } + } + if (!sr.isOkay()) { + statusHandler.error("Error updating GridParmManager: " + + sr.message()); + } + + for (DatabaseID dbId : invChanged.getDeletions()) { + statusHandler.info("handleGfeNotification removing database: " + + dbId); + this.dbMap.remove(dbId); + } + } else if (notif instanceof GridUpdateNotification) { + DatabaseID satDbId = D2DSatDatabase.getDbId(siteID); + GridUpdateNotification gun = (GridUpdateNotification) notif; + if (gun.getParmId().getDbId().equals(satDbId)) { + D2DSatDatabase db = (D2DSatDatabase) this.dbMap.get(satDbId); + db.update(gun); + } + } + } + + /** + * @param db + */ + public void addDB(GridDatabase db) { + this.dbMap.put(db.getDbId(), db); + } + + /** + * Process D2D grid data purge notification + */ + public void d2dGridDataPurged() { + List currentInventory = new ArrayList( + this.dbMap.keySet()); + List newInventory = new ArrayList( + currentInventory.size()); + List d2dModels = config.getD2dModels(); + for (String d2dModelName : d2dModels) { + String gfeModel = config.gfeModelNameMapping(d2dModelName); + if (gfeModel != null) { + DatabaseID dbId = D2DGridDatabase.getDbId(d2dModelName, + new Date(), config); + int desiredVersions = config.desiredDbVersions(dbId); try { - getDb(dbId); - } catch (GfeException e) { + List dbIds = D2DGridDatabase + .getD2DDatabaseIdsFromDb(config, d2dModelName, + desiredVersions); + newInventory.addAll(dbIds); + } catch (DataAccessLayerException e) { + statusHandler.error(e.getLocalizedMessage(), e); + } + } + } + + List added = new ArrayList(newInventory); + added.removeAll(currentInventory); + List deleted = new ArrayList(currentInventory); + deleted.removeAll(newInventory); + + // remove satellite database and non-D2D databases from added + DatabaseID satDbid = D2DSatDatabase.getDbId(siteID); + Iterator iter = added.iterator(); + while (iter.hasNext()) { + DatabaseID dbid = iter.next(); + if (!dbid.getDbType().equals("D2D") || dbid.equals(satDbid)) { + iter.remove(); + } else { + // add the new database + try { + D2DGridDatabase db = new D2DGridDatabase(config, dbid); + addDB(db); + statusHandler.info("d2dGridDataPurged new D2D database: " + + dbid); + } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); } } + } - for (DatabaseID dbId : invChanged.getDeletions()) { - dbMap.remove(dbId); + iter = deleted.iterator(); + while (iter.hasNext()) { + DatabaseID dbid = iter.next(); + if (!dbid.getDbType().equals("D2D") || dbid.equals(satDbid)) { + iter.remove(); + } else { + // remove the database + statusHandler.info("d2dGridDataPurged removing database: " + + dbid); + this.dbMap.remove(dbid); } } + + if ((added.size() > 0) || (deleted.size() > 0)) { + DBInvChangeNotification changed = new DBInvChangeNotification( + added, deleted, siteID); + + SendNotifications.send(changed); + } + } + + /** + * Process D2D satellite data purge notification + */ + public void d2dSatDataPurged() { + DatabaseID dbId = D2DSatDatabase.getDbId(siteID); + D2DSatDatabase db = (D2DSatDatabase) getDatabase(dbId); + + List notifs = db.update(); + + SendNotifications.send(notifs); } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/IFPServer.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/IFPServer.java new file mode 100644 index 0000000000..d5045dd1c8 --- /dev/null +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/IFPServer.java @@ -0,0 +1,353 @@ +/** + * 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. + **/ +package com.raytheon.edex.plugin.gfe.server; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.raytheon.edex.plugin.gfe.cache.gridlocations.GridLocationCache; +import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; +import com.raytheon.edex.plugin.gfe.db.dao.IscSendRecordDao; +import com.raytheon.edex.plugin.gfe.isc.IRTManager; +import com.raytheon.edex.plugin.gfe.reference.MapManager; +import com.raytheon.edex.plugin.gfe.server.database.NetCDFDatabaseManager; +import com.raytheon.edex.plugin.gfe.server.database.TopoDatabaseManager; +import com.raytheon.edex.plugin.gfe.server.lock.LockManager; +import com.raytheon.uf.common.dataplugin.PluginException; +import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; +import com.raytheon.uf.common.dataplugin.gfe.server.notify.GfeNotification; +import com.raytheon.uf.common.dataplugin.grid.GridRecord; +import com.raytheon.uf.common.dataplugin.message.DataURINotificationMessage; +import com.raytheon.uf.common.dataplugin.satellite.SatelliteRecord; +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.edex.database.DataAccessLayerException; + +/** + * GFE Server Container + * + * Contains all server objects for a GFE site. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * May 30, 2013       2044 randerso     Initial creation
+ * 
+ * 
+ * + * @author randerso + * @version 1.0 + */ + +public class IFPServer { + /** + * Wrapper class to call static methods from spring/camel + * + *
+     * 
+     * SOFTWARE HISTORY
+     * 
+     * Date         Ticket#    Engineer    Description
+     * ------------ ---------- ----------- --------------------------
+     * Jun 14, 2013            randerso     Initial creation
+     * 
+     * 
+ * + * @author randerso + * @version 1.0 + */ + public static class Wrapper { + /** + * @param pluginName + */ + public void pluginPurged(String pluginName) { + IFPServer.pluginPurged(pluginName); + } + + /** + * @param msg + */ + public void processNotification(Object msg) { + IFPServer.processNotification(msg); + } + + /** + * @param message + * @throws Exception + */ + public void filterDataURINotifications( + DataURINotificationMessage message) throws Exception { + IFPServer.filterDataURINotifications(message); + } + } + + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(IFPServer.class); + + private static Map activeServers = new HashMap(); + + /** + * Activate an IFPServer for a site + * + * @param siteID + * site to be activated + * @param config + * @return the IFPServer instance + * @throws GfeException + * if site already active + */ + public static synchronized IFPServer activateServer(String siteID, + IFPServerConfig config) throws GfeException { + IFPServer instance = activeServers.get(siteID); + if (instance == null) { + try { + instance = new IFPServer(siteID, config); + activeServers.put(siteID, instance); + } catch (Exception e) { + throw new GfeException( + "Error creating IFPServer for " + siteID, e); + } + } else { + throw new GfeException("IFPServer already active for site: " + + siteID); + } + return instance; + } + + /** + * Deactivate the IFPServer for a site + * + * @param siteID + * site to be activated + * @throws GfeException + * if no IFPServer is active for the site + */ + public static synchronized void deactivateServer(String siteID) + throws GfeException { + IFPServer ifp = activeServers.remove(siteID); + if (ifp != null) { + ifp.dispose(); + } else { + throw new GfeException("No active IFPServer for site: " + siteID); + } + } + + /** + * Get list of sites with active IFPServers + * + * @return list of active sites + */ + public static Set getActiveSites() { + return new HashSet(activeServers.keySet()); + } + + /** + * Returns a list of active IFPServers + * + * @return the list of servers + */ + public static List getActiveServers() { + return new ArrayList(activeServers.values()); + } + + /** + * Get the active IFPServer instance for a site + * + * @param siteID + * @return the IFPServer instance or null if there is no active server for + * siteID + */ + public static IFPServer getActiveServer(String siteID) { + return activeServers.get(siteID); + } + + String siteId; + + IFPServerConfig config; + + GridParmManager gridParmMgr; + + LockManager lockMgr; + + TopoDatabaseManager topoMgr; // TODO do we need this? + + private IFPServer(String siteId, IFPServerConfig config) + throws DataAccessLayerException, PluginException, GfeException { + this.siteId = siteId; + this.config = config; + this.lockMgr = new LockManager(siteId, config); + this.gridParmMgr = new GridParmManager(siteId, config, lockMgr); + this.topoMgr = new TopoDatabaseManager(siteId, config, gridParmMgr); + + statusHandler.info("MapManager initializing..."); + new MapManager(config); + } + + private void dispose() { + if (config.requestISC()) { + IRTManager.getInstance().disableISC(config.getMhsid(), siteId); + } + + try { + new IscSendRecordDao().deleteForSite(siteId); + } catch (DataAccessLayerException e) { + statusHandler.handle(Priority.PROBLEM, + "Could not clear IscSendRecords for site " + siteId + + " from queue.", e); + } + + // TODO necessary? + NetCDFDatabaseManager.removeDatabases(siteId); + GridLocationCache.removeGridLocationsForSite(siteId); + + this.gridParmMgr.dispose(); + } + + /** + * @return the siteId + */ + public String getSiteId() { + return siteId; + } + + /** + * @return the config + */ + public IFPServerConfig getConfig() { + return config; + } + + /** + * @return the gridParmMgr + */ + public GridParmManager getGridParmMgr() { + return gridParmMgr; + } + + /** + * @return the lockMgr + */ + public LockManager getLockMgr() { + return lockMgr; + } + + /** + * @return the topoMgr + */ + public TopoDatabaseManager getTopoMgr() { + return topoMgr; + } + + /** + * @param msg + */ + public static void processNotification(Object msg) { + if (msg instanceof List) { + for (Object obj : (List) msg) { + if (obj instanceof GfeNotification) { + handleGfeNotification((GfeNotification) obj); + } + } + } else if (msg instanceof GfeNotification) { + handleGfeNotification((GfeNotification) msg); + } + } + + private static void handleGfeNotification(GfeNotification notif) { + IFPServer ifp = activeServers.get(notif.getSiteID()); + if (ifp != null) { + ifp.gridParmMgr.handleGfeNotification(notif); + } else { + statusHandler.warn("Received " + notif.getClass().getSimpleName() + + " for " + notif.getSiteID() + + " with no active GridParmManager"); + } + } + + /** + * @param pluginName + */ + public static void pluginPurged(String pluginName) { + for (IFPServer ifpServer : getActiveServers()) { + if (pluginName.equals("grid")) { + statusHandler.info("Processing " + pluginName + + " purge notification"); + ifpServer.getGridParmMgr().d2dGridDataPurged(); + } else if (pluginName.equals("satellite")) { + statusHandler.info("Processing " + pluginName + + " purge notification"); + ifpServer.getGridParmMgr().d2dSatDataPurged(); + } + } + } + + /** + * @param message + * @throws Exception + */ + public static void filterDataURINotifications( + DataURINotificationMessage message) throws Exception { + // ITimer timer = TimeUtil.getTimer(); + // timer.start(); + List gridRecords = new LinkedList(); + List satRecords = new LinkedList(); + + for (String dataURI : message.getDataURIs()) { + if (dataURI.startsWith("/grid/")) { + gridRecords.add(new GridRecord(dataURI)); + } else if (dataURI.startsWith("/satellite/")) { + satRecords.add(new SatelliteRecord(dataURI)); + } + } + + for (IFPServer ifpServer : getActiveServers()) { + if (!gridRecords.isEmpty()) { + // TODO: remove this info before check in + String msg = "Processing " + gridRecords.size() + + " grid DataURINotifications"; + statusHandler.info(msg); + + ifpServer.getGridParmMgr().filterGridRecords(gridRecords); + } + if (!satRecords.isEmpty()) { + // TODO: remove this info before check in + String msg = "Processing " + satRecords.size() + + " satellite DataURINotifications"; + statusHandler.info(msg); + + ifpServer.getGridParmMgr().filterSatelliteRecords(satRecords); + } + } + // timer.stop(); + // perfLog.logDuration( + // "GfeIngestNotificationFilter: processing DataURINotificationMessage", + // timer.getElapsedTime()); + } + +} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DGridDatabase.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DGridDatabase.java index 4d398756e0..e6bc2ef4bf 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DGridDatabase.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DGridDatabase.java @@ -43,7 +43,6 @@ import com.raytheon.edex.plugin.gfe.db.dao.GFED2DDao; import com.raytheon.edex.plugin.gfe.paraminfo.GridParamInfo; import com.raytheon.edex.plugin.gfe.paraminfo.GridParamInfoLookup; import com.raytheon.edex.plugin.gfe.paraminfo.ParameterInfo; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.comm.CommunicationException; import com.raytheon.uf.common.dataplugin.PluginException; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; @@ -58,6 +57,7 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.TimeConstraints; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; +import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotification; import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; import com.raytheon.uf.common.dataplugin.gfe.slice.ScalarGridSlice; import com.raytheon.uf.common.dataplugin.gfe.slice.VectorGridSlice; @@ -107,6 +107,7 @@ import com.raytheon.uf.edex.database.DataAccessLayerException; * 04/17/2013 #1913 randerso Added GFE level mapping to replace GridTranslator * 05/02/2013 #1969 randerso Removed unnecessary updateDbs method * 05/03/2013 #1974 randerso Fixed error handling when no D2D level mapping found + * 06/13/2013 #2044 randerso Added convenience methods, general code cleanup * * * @@ -118,17 +119,17 @@ public class D2DGridDatabase extends VGridDatabase { .getHandler(D2DGridDatabase.class); /** - * Retrieve the gfe DatabaseID for a given d2d model run + * Construct the gfe DatabaseID for a given d2d model run * * @param d2dModelName * @param modelTime * @param config - * @return + * @return the DatabaseID */ public static DatabaseID getDbId(String d2dModelName, Date modelTime, IFPServerConfig config) { String gfeModelName = config.gfeModelNameMapping(d2dModelName); - if (gfeModelName == null || gfeModelName.isEmpty()) { + if ((gfeModelName == null) || gfeModelName.isEmpty()) { return null; } return new DatabaseID(getSiteID(config), DataType.GRID, "D2D", @@ -136,63 +137,84 @@ public class D2DGridDatabase extends VGridDatabase { } /** - * Retrieves DatabaseIDs for all model runs of a given d2dModelName + * Get available run times for a D2D model * * @param d2dModelName - * desired d2d model name - * @param gfeModel - * gfe model name to use - * @param siteID - * siteID to use in databaseId * @param maxRecords - * max number of model runs to return - * @return + * @return the model run times * @throws DataAccessLayerException */ - public static List getD2DDatabaseIdsFromDb( - IFPServerConfig config, String d2dModelName) - throws DataAccessLayerException { - return getD2DDatabaseIdsFromDb(config, d2dModelName, -1); + public static List getModelRunTimes(String d2dModelName, + int maxRecords) throws DataAccessLayerException { + try { + GFED2DDao dao = new GFED2DDao(); + List result = dao.getModelRunTimes(d2dModelName, maxRecords); + + return result; + } catch (PluginException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + return Collections.emptyList(); + } + } + + /** + * Get a D2DGridDatabase if it is available + * + * @param config + * configuration for site + * @param dbId + * DatabaseID of desired database + * @return D2DGridDatabase or null if not available + */ + public static D2DGridDatabase getDatabase(IFPServerConfig config, + DatabaseID dbId) { + String gfeModelName = dbId.getModelName(); + Date refTime = dbId.getModelDate(); + + String d2dModelName = config.d2dModelNameMapping(gfeModelName); + try { + GFED2DDao dao = new GFED2DDao(); + // TODO create query for single refTime + List result = dao.getModelRunTimes(d2dModelName, -1); + + if (result.contains(refTime)) { + D2DGridDatabase db = new D2DGridDatabase(config, dbId); + return db; + } + return null; + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + return null; + } } /** * Retrieves DatabaseIDs for the n most recent model runs of a given * d2dModelName * + * @param config * @param d2dModelName * desired d2d model name * @param maxRecords * max number of model runs to return - * @return + * @return the DatabaseIDs * @throws DataAccessLayerException */ public static List getD2DDatabaseIdsFromDb( IFPServerConfig config, String d2dModelName, int maxRecords) throws DataAccessLayerException { - try { - GFED2DDao dao = new GFED2DDao(); - List result = dao.getModelRunTimes(d2dModelName, maxRecords); + List runTimes = getModelRunTimes(d2dModelName, maxRecords); - List dbInventory = new ArrayList(); - for (Date date : result) { - DatabaseID dbId = null; - dbId = getDbId(d2dModelName, date, config); - try { - GridDatabase db = GridParmManager.getDb(dbId); - if ((db != null) && !dbInventory.contains(dbId)) { - dbInventory.add(dbId); - } - } catch (GfeException e) { - statusHandler.handle(Priority.PROBLEM, - e.getLocalizedMessage(), e); - } + List dbInventory = new ArrayList(); + for (Date date : runTimes) { + DatabaseID dbId = null; + dbId = getDbId(d2dModelName, date, config); + if (!dbInventory.contains(dbId)) { + dbInventory.add(dbId); } - return dbInventory; - } catch (PluginException e) { - statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); - return Collections.emptyList(); } + return dbInventory; } // regex to match parmnnhr @@ -204,7 +226,7 @@ public class D2DGridDatabase extends VGridDatabase { private final IPerformanceStatusHandler perfLog = PerformanceStatus .getHandler("GFE:"); - public class D2DParm { + private class D2DParm { private ParmID parmId; private GridParmInfo gpi; @@ -238,6 +260,11 @@ public class D2DGridDatabase extends VGridDatabase { return parmId; } + /** + * Retrieve the GridParmInfo for this parm + * + * @return the GridParmInfo + */ public GridParmInfo getGpi() { return gpi; } @@ -272,6 +299,8 @@ public class D2DGridDatabase extends VGridDatabase { private List availableTimes; + private GFED2DDao d2dDao; + /** The remap object used for resampling grids */ private final Map remap = new HashMap(); @@ -282,27 +311,67 @@ public class D2DGridDatabase extends VGridDatabase { private Map d2dParms = new HashMap(); + /** + * Constructs a new D2DGridDatabase from a DatabaseID + * + * @param config + * @param dbId + * @throws GfeException + */ + public D2DGridDatabase(IFPServerConfig config, DatabaseID dbId) + throws GfeException { + super(config); + + if (!dbId.getDbType().equals("D2D")) { + throw new GfeException( + "Attempting to create D2DGridDatabase for non-D2D DatabaseID: " + + dbId); + } + + String gfeModelName = dbId.getModelName(); + String d2dModelName = this.config.d2dModelNameMapping(gfeModelName); + Date refTime = dbId.getModelDate(); + + init(d2dModelName, refTime); + } + /** * Constructs a new D2DGridDatabase * - * @param dbId - * The database ID of this database + * @param config + * @param d2dModelName + * @param refTime + * + * @throws GfeException */ public D2DGridDatabase(IFPServerConfig config, String d2dModelName, Date refTime) throws GfeException { super(config); + init(d2dModelName, refTime); + } + + private void init(String d2dModelName, Date refTime) throws GfeException { this.d2dModelName = d2dModelName; this.refTime = refTime; + this.dbId = getDbId(this.d2dModelName, this.refTime, this.config); + + try { + this.d2dDao = new GFED2DDao(); + } catch (PluginException e) { + throw new GfeException( + "Error creating GFED2DDao for: " + this.dbId, e); + } + this.modelInfo = GridParamInfoLookup.getInstance().getGridParamInfo( d2dModelName); if (modelInfo == null) { throw new GfeException("No model info for: " + d2dModelName); } + this.availableTimes = modelInfo.getAvailableTimes(refTime); // Get the database id for this database. - this.dbId = getDbId(this.d2dModelName, this.refTime, this.config); this.valid = this.dbId.isValid(); // get the output gloc' @@ -528,11 +597,9 @@ public class D2DGridDatabase extends VGridDatabase { // get database inventory List dbInv = null; try { - GFED2DDao dao = new GFED2DDao(); - // get database inventory where all components are available for (String component : parm.getComponents()) { - List compInv = dao.queryFcstHourByParmId( + List compInv = d2dDao.queryFcstHourByParmId( d2dModelName, refTime, component, parm.getLevel()); if (dbInv == null) { @@ -567,13 +634,6 @@ public class D2DGridDatabase extends VGridDatabase { return sr; } - public boolean isParmInfoDefined(ParmID id) { - String mappedModel = config.d2dModelNameMapping(id.getDbId() - .getModelName()); - return GridParamInfoLookup.getInstance().getParameterInfo(mappedModel, - id.getParmName().toLowerCase()) != null; - } - @Override public ServerResponse getGridParmInfo(ParmID id) { @@ -736,20 +796,28 @@ public class D2DGridDatabase extends VGridDatabase { return sr; } - public ServerResponse> getGridData(ParmID id, + /** + * Get the grid data for a parm for specified time ranges + * + * @param parmId + * @param timeRanges + * @param convertUnit + * @return ServerResponse containing the grid slices + */ + public ServerResponse> getGridData(ParmID parmId, List timeRanges, boolean convertUnit) { List data = new ArrayList(timeRanges.size()); ServerResponse> sr = new ServerResponse>(); for (TimeRange tr : timeRanges) { - GridParmInfo gpi = getGridParmInfo(id).getPayload(); + GridParmInfo gpi = getGridParmInfo(parmId).getPayload(); try { - data.add(getGridSlice(id, gpi, tr, convertUnit)); + data.add(getGridSlice(parmId, gpi, tr, convertUnit)); } catch (GfeException e) { - sr.addMessage("Error getting grid slice for ParmID: " + id + sr.addMessage("Error getting grid slice for ParmID: " + parmId + " TimeRange: " + tr); statusHandler.handle(Priority.PROBLEM, - "Error getting grid slice for ParmID: " + id + "Error getting grid slice for ParmID: " + parmId + " TimeRange: " + tr, e); } } @@ -835,12 +903,6 @@ public class D2DGridDatabase extends VGridDatabase { GridRecord d2dRecord = null; long t0 = System.currentTimeMillis(); - GFED2DDao dao = null; - try { - dao = new GFED2DDao(); - } catch (PluginException e1) { - throw new GfeException("Unable to get GFE dao!", e1); - } try { // Gets the metadata from the grib metadata database @@ -854,7 +916,7 @@ public class D2DGridDatabase extends VGridDatabase { + " for " + parmId); } } - d2dRecord = dao.getGrid(d2dModelName, refTime, + d2dRecord = d2dDao.getGrid(d2dModelName, refTime, parm.getComponents()[0], parm.getLevel(), fcstHr, gpi); } catch (DataAccessLayerException e) { throw new GfeException( @@ -911,8 +973,8 @@ public class D2DGridDatabase extends VGridDatabase { * The grib metadata containing the original unit information * @param data * The float data to convert - * @param gpi - * The grid parm info containing the target unit information + * @param targetUnit + * The desired unit * @throws GfeException * If the source and target units are incompatible */ @@ -958,13 +1020,6 @@ public class D2DGridDatabase extends VGridDatabase { GridParmInfo gpi, Grid2DFloat mag, Grid2DFloat dir) throws GfeException { - GFED2DDao dao = null; - try { - dao = new GFED2DDao(); - } catch (PluginException e1) { - throw new GfeException("Unable to get GFE dao!!", e1); - } - D2DParm windParm = this.gfeParms.get(parmId); Integer fcstHr = windParm.getTimeRangeToFcstHr().get(timeRange); if (fcstHr == null) { @@ -980,9 +1035,9 @@ public class D2DGridDatabase extends VGridDatabase { // Get the metadata from the grib metadata database - uRecord = dao.getGrid(d2dModelName, refTime, "uW", + uRecord = d2dDao.getGrid(d2dModelName, refTime, "uW", windParm.getLevel(), fcstHr, gpi); - vRecord = dao.getGrid(d2dModelName, refTime, "vW", + vRecord = d2dDao.getGrid(d2dModelName, refTime, "vW", windParm.getLevel(), fcstHr, gpi); // Gets the raw grid data from the D2D grib HDF5 files @@ -1016,9 +1071,9 @@ public class D2DGridDatabase extends VGridDatabase { GridRecord dRecord = null; // Get the metadata from the grib metadata database - sRecord = dao.getGrid(d2dModelName, refTime, "WS", + sRecord = d2dDao.getGrid(d2dModelName, refTime, "WS", windParm.getLevel(), fcstHr, gpi); - dRecord = dao.getGrid(d2dModelName, refTime, "WD", + dRecord = d2dDao.getGrid(d2dModelName, refTime, "WD", windParm.getLevel(), fcstHr, gpi); // Gets the raw grid data from the D2D grib HDF5 files @@ -1058,13 +1113,11 @@ public class D2DGridDatabase extends VGridDatabase { private Grid2DFloat getRawGridData(GridRecord d2dRecord) throws GfeException { try { - GFED2DDao dao = new GFED2DDao(); // TODO should we add subgrid support to GridDao or PluginDao - // reimplementing this call here with subgrid support // dao.getHDF5Data(d2dRecord, -1); - IDataStore dataStore = dao.getDataStore(d2dRecord); + IDataStore dataStore = d2dDao.getDataStore(d2dRecord); GridLocation gloc = getOrCreateRemap(d2dRecord.getLocation()) .getSourceGloc(); @@ -1119,7 +1172,7 @@ public class D2DGridDatabase extends VGridDatabase { long start = (times.get(0).getStart().getTime() / TimeUtil.MILLIS_PER_SECOND) % TimeUtil.SECONDS_PER_DAY; - for (int i = 1; i < times.size() - 1; i++) { + for (int i = 1; i < (times.size() - 1); i++) { if (((times.get(i + 1).getStart().getTime() - times.get(i) .getStart().getTime()) / TimeUtil.MILLIS_PER_SECOND) != repeat) { return new TimeConstraints(TimeUtil.SECONDS_PER_HOUR, @@ -1131,15 +1184,15 @@ public class D2DGridDatabase extends VGridDatabase { } private int calcPrecision(float minV, float maxV) { - if (maxV - minV > 250.0) { + if ((maxV - minV) > 250.0) { return 0; - } else if (maxV - minV > 25.0) { + } else if ((maxV - minV) > 25.0) { return 1; - } else if (maxV - minV > 2.5) { + } else if ((maxV - minV) > 2.5) { return 2; - } else if (maxV - minV > 0.25) { + } else if ((maxV - minV) > 0.25) { return 3; - } else if (maxV - minV > 0.025) { + } else if ((maxV - minV) > 0.025) { return 4; } else { return 5; @@ -1156,18 +1209,13 @@ public class D2DGridDatabase extends VGridDatabase { @Override public SortedSet getValidTimes() throws GfeException, DataAccessLayerException { - GFED2DDao dao = null; - try { - dao = new GFED2DDao(); - } catch (PluginException e) { - throw new GfeException("Unable to get GFE dao!!", e); - } - List fcstTimes = dao.getForecastTimes(d2dModelName, refTime); + List fcstTimes = d2dDao + .getForecastTimes(d2dModelName, refTime); SortedSet validTimes = new TreeSet(); for (Integer fcstTime : fcstTimes) { - validTimes.add(new Date(refTime.getTime() + fcstTime - * TimeUtil.MILLIS_PER_SECOND)); + validTimes.add(new Date(refTime.getTime() + + (fcstTime * TimeUtil.MILLIS_PER_SECOND))); } return validTimes; } @@ -1182,7 +1230,7 @@ public class D2DGridDatabase extends VGridDatabase { // no-op } - public D2DParm getD2DParm(String d2dParmName, Level d2dLevel) { + private D2DParm getD2DParm(String d2dParmName, Level d2dLevel) { String gfeParmName = getGfeParmName(d2dParmName); String gfeLevel = getGFELevel(d2dLevel); @@ -1215,6 +1263,12 @@ public class D2DGridDatabase extends VGridDatabase { return parm; } + /** + * Get the GFE name for the specified D2D parm + * + * @param d2dParmName + * @return the gfeParmName + */ public String getGfeParmName(String d2dParmName) { String gfeParmName = null; try { @@ -1227,6 +1281,12 @@ public class D2DGridDatabase extends VGridDatabase { return gfeParmName; } + /** + * Get the D2D parm name for the specified GFE parm + * + * @param gfeParmName + * @return the d2dParmName + */ public String getD2DParmName(String gfeParmName) { String d2dParmName = null; try { @@ -1239,6 +1299,14 @@ public class D2DGridDatabase extends VGridDatabase { return d2dParmName; } + /** + * Get the time range corresponding to the specified forecast hour for a + * parm + * + * @param parmID + * @param fcstHour + * @return the time range or null if none found + */ public TimeRange getTimeRange(ParmID parmID, Integer fcstHour) { D2DParm parm = this.gfeParms.get(parmID); if (parm == null) { @@ -1294,4 +1362,66 @@ public class D2DGridDatabase extends VGridDatabase { } return gfeLevel; } + + /** + * Update with newly ingested data + * + * @param record + * @return GridUpdateNotification or null if none + */ + public GridUpdateNotification update(GridRecord record) { + String d2dParamName = record.getParameter().getAbbreviation(); + Level level = record.getLevel(); + Integer fcstHour = record.getDataTime().getFcstTime(); + + D2DParm parm = getD2DParm(d2dParamName, level); + if (parm == null) { + return null; + } + ParmID parmID = parm.getParmId(); + + // check for wind + String otherComponent = null; + String[] components = parm.getComponents(); + if (components.length > 1) { + if (components[0].equals(d2dParamName)) { + otherComponent = components[1]; + } else { + otherComponent = components[0]; + } + } + + // if wind see if other component is available + if (otherComponent != null) { + // get the other components times + List otherTimes; + try { + // TODO: could just query for desired fcstHour instead of all + otherTimes = d2dDao.queryFcstHourByParmId(d2dModelName, + refTime, otherComponent, parm.getLevel()); + + // if we don't have the other component for this time + if (!otherTimes.contains(fcstHour)) { + // need to wait for other component + return null; + } + } catch (DataAccessLayerException e) { + ParmID otherPid = new ParmID(otherComponent, parmID.getDbId(), + parmID.getParmLevel()); + statusHandler.error("Error retrieving fcstHours for " + + otherPid, e); + return null; + } + } + + TimeRange tr = getTimeRange(parmID, fcstHour); + List histList = new ArrayList(); + histList.add(new GridDataHistory( + GridDataHistory.OriginType.INITIALIZED, parmID, tr, null, + (WsId) null)); + Map> hist = new HashMap>(); + hist.put(tr, histList); + return new GridUpdateNotification(parmID, tr, hist, null, parmID + .getDbId().getSiteId()); + } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DSatDatabase.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DSatDatabase.java index c8c820f0a5..3412048d7b 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DSatDatabase.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DSatDatabase.java @@ -21,8 +21,10 @@ package com.raytheon.edex.plugin.gfe.server.database; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.SortedSet; import java.util.TreeSet; @@ -36,9 +38,13 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; +import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotification; import com.raytheon.uf.common.dataplugin.gfe.server.request.GetGridRequest; import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; +import com.raytheon.uf.common.dataplugin.satellite.SatelliteRecord; 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.time.TimeRange; import com.raytheon.uf.edex.database.DataAccessLayerException; @@ -53,8 +59,9 @@ import com.raytheon.uf.edex.database.DataAccessLayerException; * ------------ ---------- ----------- -------------------------- * May 16, 2011 bphillip Initial creation * May 04, 2012 #574 dgilling Add unimplemented methods from GridDatabase. - * Oct 10 2012 #1260 randerso Added code to set valid flag - * 05/02/13 #1969 randerso Removed unnecessary updateDbs method + * Oct 10 2012 #1260 randerso Added code to set valid flag + * May 02 2013 #1969 randerso Removed unnecessary updateDbs method + * Jun 13 2013 #2044 randerso Added getDbId and update methods * * * @@ -63,33 +70,68 @@ import com.raytheon.uf.edex.database.DataAccessLayerException; */ public class D2DSatDatabase extends VGridDatabase { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(D2DSatDatabase.class); - /** The list of parms contained in the satellite database */ - private List parms; + /** + * Get the Satellite DatabaseID for a given site + * + * @param siteID + * @return the Satellite DatabaseID + */ + public static DatabaseID getDbId(String siteID) { + return new DatabaseID(siteID, DataType.GRID, "D2D", "Satellite", + DatabaseID.NO_MODEL_TIME); + } + + /** map of parmIDs to D2DSatParms */ + private Map pidToParm; + + /** + * Map of product IDs to D2DSatParms
+ *
+ * A product ID consists of the sector ID and physical element of the + * satellite product.
+ *
+ * Examples: + * + *
+     * "East CONUS/Imager Visible"
+     * "East CONUS/Imager 11 micron IR"
+     * "East CONUS/Imager 13 micron (IR)"
+     * "East CONUS/Imager 3.9 micron IR"
+     * 
+ * + */ + private Map idToParm; /** * Creates a new D2DSatDatabase * * @param config * The server config for this site - * @param productURIs - * URI segments which describe the origins of the data in this - * database - * @param parmNames - * The parm names used by GFE to identify this satellite data */ - public D2DSatDatabase(IFPServerConfig config, List productURIs, - List parmNames) { + public D2DSatDatabase(IFPServerConfig config) { super(config); - this.dbId = new DatabaseID(config.getSiteID().get(0), DataType.GRID, - "D2D", "Satellite", "00000000_0000"); + String siteID = config.getSiteID().get(0); + this.dbId = getDbId(siteID); this.valid = this.dbId.isValid(); - parms = new ArrayList(); - for (int i = 0; i < productURIs.size(); i++) { - D2DSatParm parm = new D2DSatParm(config, productURIs.get(i), - this.dbId, parmNames.get(i)); - parms.add(parm); - // D2DParmIdCache.getInstance().putParmID(parm.pid()); + + Map satData = config.satData(); + + pidToParm = new HashMap(satData.size(), 1.0f); + idToParm = new HashMap(satData.size(), 1.0f); + for (Entry entry : satData.entrySet()) { + try { + String productId = entry.getKey(); + String parmName = entry.getValue(); + D2DSatParm parm = new D2DSatParm(config, productId, this.dbId, + parmName); + pidToParm.put(parm.pid(), parm); + idToParm.put(productId, parm); + } catch (GfeException e) { + statusHandler.error(e.getLocalizedMessage(), e); + } } } @@ -102,26 +144,9 @@ public class D2DSatDatabase extends VGridDatabase { return this.dbId; } - /** - * Finds a parm contained in this database - * - * @param pid - * The parm to find - * @return The D2DSatParm associated with the given parmID. null is returned - * if the database does not contain the desired parmID - */ - public D2DSatParm findParm(ParmID pid) { - for (D2DSatParm parm : parms) { - if (pid.equals(parm.pid())) { - return parm; - } - } - return null; - } - @Override public ServerResponse> getGridInventory(ParmID id) { - D2DSatParm p = findParm(id); + D2DSatParm p = pidToParm.get(id); if (p != null) { return p.getGridInventory(); } @@ -133,7 +158,7 @@ public class D2DSatDatabase extends VGridDatabase { @Override public ServerResponse getGridParmInfo(ParmID id) { - D2DSatParm p = findParm(id); + D2DSatParm p = pidToParm.get(id); if (p != null) { return p.getGridParmInfo(); } @@ -145,7 +170,7 @@ public class D2DSatDatabase extends VGridDatabase { @Override public ServerResponse>> getGridHistory( ParmID id, List trs) { - D2DSatParm p = findParm(id); + D2DSatParm p = pidToParm.get(id); if (p != null) { return p.getGridHistory(trs); } @@ -158,8 +183,8 @@ public class D2DSatDatabase extends VGridDatabase { public ServerResponse> getParmList() { ServerResponse> retVal = new ServerResponse>(); List parmIDs = new ArrayList(); - for (int i = 0; i < this.parms.size(); i++) { - parmIDs.add(parms.get(i).pid()); + for (ParmID pid : pidToParm.keySet()) { + parmIDs.add(pid); } retVal.setPayload(parmIDs); return retVal; @@ -178,7 +203,7 @@ public class D2DSatDatabase extends VGridDatabase { public ServerResponse> getGridData(ParmID id, List timeRanges) { - D2DSatParm p = findParm(id); + D2DSatParm p = pidToParm.get(id); if (p != null) { return p.getGridData(new GetGridRequest(id, timeRanges), null); } @@ -203,7 +228,7 @@ public class D2DSatDatabase extends VGridDatabase { public SortedSet getValidTimes() throws GfeException, DataAccessLayerException { SortedSet times = new TreeSet(); - for (D2DSatParm parm : parms) { + for (D2DSatParm parm : pidToParm.values()) { for (TimeRange tr : parm.getGridInventory().getPayload()) { times.add(tr.getStart()); } @@ -221,4 +246,48 @@ public class D2DSatDatabase extends VGridDatabase { public void deleteDb() { // no-op } + + /** + * Update with newly ingested data + * + * @param record + * @return GridUpdateNotification or null if none + */ + public GridUpdateNotification update(SatelliteRecord record) { + GridUpdateNotification notify = null; + + String productId = record.getSectorID() + "/" + record.getPhysicalElement(); + D2DSatParm satParm = idToParm.get(productId); + if (satParm != null) { + notify = satParm.update(record); + } + return notify; + } + + /** + * Update inventory from database after satellite purge + * + * @return list of GridUpdateNotifications to be sent + */ + public List update() { + List notifs = new ArrayList(); + + for (D2DSatParm parm : pidToParm.values()) { + notifs.addAll(parm.updateFromDb()); + } + + return notifs; + } + + /** + * Update parm inventory based on GridUpdateNotification + * + * @param gun + * the GridUpdateNotification + */ + public void update(GridUpdateNotification gun) { + D2DSatParm parm = pidToParm.get(gun.getParmId()); + parm.update(gun); + } + } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DSatDatabaseManager.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DSatDatabaseManager.java deleted file mode 100644 index 5d5f4b3ea6..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/D2DSatDatabaseManager.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * 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. - **/ -package com.raytheon.edex.plugin.gfe.server.database; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; -import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; - -/** - * Database manager for handling instances of D2DSatDatabases - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * May 23, 2011            bphillip     Initial creation
- * 
- * 
- * - * @author bphillip - * @version 1.0 - */ - -public class D2DSatDatabaseManager { - - /** Map of D2DSatDatabases based on site */ - private static Map satDbMap = new HashMap(); - - /** - * Initializes the D2DSatDatabase using the given siteID and configuration - * - * @param siteID - * The siteID to initialize a new D2DSatDatabase for - * @param config - * The configuration - */ - public static void initializeD2DSatDatabase(String siteID, - IFPServerConfig config) { - List dirNames = new ArrayList(); - List parmNames = new ArrayList(); - Map satDirs = config.satDirs(); - if (satDirs != null) { - for (String dirName : satDirs.keySet()) { - dirNames.add(dirName); - parmNames.add(satDirs.get(dirName)); - } - } - D2DSatDatabase db = new D2DSatDatabase(config, dirNames, parmNames); - satDbMap.put(siteID, db); - } - - /** - * Retrieves the D2DSatDatabase instance for the given site - * - * @param siteID - * The site id for which to get the D2DSatDatabase - * @return The D2DSatDatabase instance - */ - public static D2DSatDatabase getSatDatabase(String siteID) { - return satDbMap.get(siteID); - } - - /** - * Removes a site's D2DSatDatabase - * - * @param siteID - * The site to remove the D2DSatDatabase for - */ - public static void removeSatDatabase(String siteID) { - satDbMap.remove(siteID); - } - - /** - * Gets the D2DSatDatabase id for the given site - * - * @param siteID - * the site to get the D2DSatDatabase id for - * @return The D2DSatDatabase database id - */ - public static DatabaseID getSatDbId(String siteID) { - return satDbMap.get(siteID).getDbId(); - } -} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java index e4c26945b3..1f5747478e 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/GridDatabase.java @@ -44,8 +44,6 @@ import com.raytheon.uf.common.datastorage.records.ByteDataRecord; import com.raytheon.uf.common.datastorage.records.FloatDataRecord; import com.raytheon.uf.common.datastorage.records.IDataRecord; 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.time.TimeRange; import com.raytheon.uf.common.util.Pair; @@ -76,15 +74,14 @@ import com.raytheon.uf.common.util.Pair; * 03/15/13 #1795 njensen Added updatePublishTime() * 04/23/13 #1949 rjpeter Added default implementations of history by time range * and cachedParmId - * 05/02/13 #1969 randerso Removed unnecessary updateDbs method + * 05/02/13 #1969 randerso Removed unnecessary updateDbs method + * 06/13/13 #2044 randerso Code cleanup * * * @author bphillip * @version 1.0 */ public abstract class GridDatabase { - private static final transient IUFStatusHandler statusHandler = UFStatus - .getHandler(GridDatabase.class); /** * The base directory where the GFE HDF5 data is stored @@ -120,11 +117,27 @@ public abstract class GridDatabase { this.dbId = dbId; } + /** + * Retrieve the FloatDataRecord for a grid from HDF5 + * + * @param parmId + * @param time + * @return the FloatDataRecord + * @throws GfeException + */ public FloatDataRecord retrieveFromHDF5(ParmID parmId, TimeRange time) throws GfeException { return retrieveFromHDF5(parmId, Arrays.asList(new TimeRange[] { time }))[0]; } + /** + * Retrieve FloatDataRecords for a multiple time ranges from HDF5 + * + * @param parmId + * @param times + * @return the FloatDataRecords + * @throws GfeException + */ public FloatDataRecord[] retrieveFromHDF5(ParmID parmId, List times) throws GfeException { FloatDataRecord[] scalarData = null; @@ -170,12 +183,29 @@ public abstract class GridDatabase { return scalarData; } + /** + * Retrieve the magnitude and direction grids for a vector parm from HDF5 + * + * @param parmId + * @param time + * @return the the magnitude and direction grids + * @throws GfeException + */ public FloatDataRecord[] retrieveVectorFromHDF5(ParmID parmId, TimeRange time) throws GfeException { return retrieveVectorFromHDF5(parmId, Arrays.asList(new TimeRange[] { time }))[0]; } + /** + * Retrieve the magnitude and direction grids for multiple time ranges for a + * vector parm from HDF5 + * + * @param parmId + * @param times + * @return array of magnitude and direction grids + * @throws GfeException + */ public FloatDataRecord[][] retrieveVectorFromHDF5(ParmID parmId, List times) throws GfeException { FloatDataRecord[][] vectorData = null; @@ -196,7 +226,7 @@ public abstract class GridDatabase { IDataRecord[] rawData = entry.getKey().retrieveGroups(groups, Request.ALL); - if (rawData.length != groups.length * 2) { + if (rawData.length != (groups.length * 2)) { throw new IllegalArgumentException( "Invalid number of dataSets returned expected per group, received: " + ((double) rawData.length / groups.length)); @@ -207,7 +237,7 @@ public abstract class GridDatabase { for (TimeRange timeRange : pair.getFirst()) { FloatDataRecord[] recs = new FloatDataRecord[2]; for (int i = 0; i < 2; i++) { - IDataRecord rec = rawData[count * 2 + i]; + IDataRecord rec = rawData[(count * 2) + i]; if ("Mag".equals(rec.getName())) { recs[0] = (FloatDataRecord) rec; } else if ("Dir".equals(rec.getName())) { @@ -236,12 +266,29 @@ public abstract class GridDatabase { return vectorData; } + /** + * Retrieves the data and keys for a Discrete grid from HDF5 + * + * @param parmId + * @param time + * @return ByteDataRecords[] array containing the data and keys + * @throws GfeException + */ public ByteDataRecord[] retrieveDiscreteFromHDF5(ParmID parmId, TimeRange time) throws GfeException { return retrieveDiscreteFromHDF5(parmId, Arrays.asList(new TimeRange[] { time }))[0]; } + /** + * Retrieves the ByteDataRecord for a Discrete grid for multiple time ranges + * from HDF5 + * + * @param parmId + * @param times + * @return array containing the data and keys for the specified times + * @throws GfeException + */ public ByteDataRecord[][] retrieveDiscreteFromHDF5(ParmID parmId, List times) throws GfeException { ByteDataRecord[][] byteRecords = null; @@ -262,7 +309,7 @@ public abstract class GridDatabase { IDataRecord[] rawData = entry.getKey().retrieveGroups(groups, Request.ALL); - if (rawData.length != groups.length * 2) { + if (rawData.length != (groups.length * 2)) { throw new IllegalArgumentException( "Invalid number of dataSets returned expected 2 per group, received: " + ((double) rawData.length / groups.length)); @@ -273,7 +320,7 @@ public abstract class GridDatabase { for (TimeRange timeRange : pair.getFirst()) { ByteDataRecord[] recs = new ByteDataRecord[2]; for (int i = 0; i < 2; i++) { - IDataRecord rec = rawData[count * 2 + i]; + IDataRecord rec = rawData[(count * 2) + i]; if ("Data".equals(rec.getName())) { recs[0] = (ByteDataRecord) rec; @@ -327,6 +374,9 @@ public abstract class GridDatabase { return valid; } + /** + * Delete the database and HDF5 records for this database + */ public abstract void deleteDb(); /** @@ -357,6 +407,8 @@ public abstract class GridDatabase { * * @param id * The parmID to get the inventory for + * @param tr + * the time range * @return The server response */ public ServerResponse> getGridInventory(ParmID id, @@ -415,20 +467,23 @@ public abstract class GridDatabase { * The parmID to get the history for * @param trs * The time ranges to get the history for - * @param history - * The history * @return The server status */ public abstract ServerResponse>> getGridHistory( ParmID id, List trs); + /** + * get the projection ID for this database + * + * @return the projection ID + */ public abstract String getProjectionId(); - public ModelState modelState() { - throw new UnsupportedOperationException("Not implemented for class " - + this.getClass().getName()); - } - + /** + * Retrieve the DatabaseID for this database + * + * @return the DatabaseID + */ public DatabaseID getDbId() { return dbId; } @@ -472,7 +527,7 @@ public abstract class GridDatabase { * the histories to alter in the database * @param publishTime * the publish time to update to - * @return + * @return ServerResponse containing status only */ public ServerResponse updatePublishTime(List history, Date publishTime) { @@ -490,7 +545,7 @@ public abstract class GridDatabase { * the time range to update sent time for * @param sentTime * the sent time to update to - * @return + * @return ServerResponse containing updated histories */ public ServerResponse>> updateSentTime( final ParmID parmId, TimeRange tr, Date sentTime) { @@ -498,6 +553,16 @@ public abstract class GridDatabase { + this.getClass().getName()); } + /** + * Save grid slices + * + * @param parmId + * @param tr + * @param sliceData + * @param requestor + * @param skipDelete + * @return ServerResponse containing status only + */ public ServerResponse saveGridSlices(ParmID parmId, TimeRange tr, List sliceData, WsId requestor, List skipDelete) { @@ -507,14 +572,16 @@ public abstract class GridDatabase { } /** - * Return the internally cache'd parmID for this database implementation. + * Return the internally cached parmID for this database implementation. * * @param parmID - * @return + * @return cached ParmID * @throws GfeException * If the parm does not exist for this database. */ public ParmID getCachedParmID(ParmID parmID) throws GfeException { + // base implementation, must be overridden by Databases that store + // ParmID objects return parmID; } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java index a44ad62234..53c798b1d3 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/IFPGridDatabase.java @@ -111,14 +111,15 @@ import com.vividsolutions.jts.geom.Coordinate; * 07/11/12 15162 ryu No raising exception in c'tor * 02/10/12 #1603 randerso Implemented deleteDb, moved methods down from * GridDatabase that belonged here. - * Removed unncecssary conversion from Lists to/from arrays + * Removed unnecessary conversion from Lists to/from arrays * Added performance logging * 02/12/13 #1608 randerso Changed to explicitly call deleteGroups - * 03/07/13 #1737 njensen Logged getGridData times - * 03/15/13 #1795 njensen Added updatePublishTime() + * 03/07/13 #1737 njensen Logged getGridData times + * 03/15/13 #1795 njensen Added updatePublishTime() * 03/20/13 #1774 randerso Cleanup code to use proper constructors * 04/08/13 #1949 rjpeter Updated to work with normalized database. * 05/02/13 #1969 randerso Removed updateDbs from parent class + * 06/13/13 #2044 randerso Pass in GridDbConfig as construction parameter * * * @author bphillip @@ -163,36 +164,27 @@ public class IFPGridDatabase extends GridDatabase { * * @param dbId * The database ID for this database + * @param gridConfig + * the database configuration */ - public IFPGridDatabase(DatabaseID dbId) { + public IFPGridDatabase(DatabaseID dbId, GridDbConfig gridConfig) { super(dbId); + this.gridConfig = gridConfig; + this.valid = true; + try { - this.gridConfig = IFPServerConfigManager.getServerConfig( - dbId.getSiteId()).gridDbConfig(dbId); - if (this.gridConfig == null) { - throw new GfeException( - "Server config contains no gridDbConfig for database " - + dbId.toString()); - } - valid = true; - } catch (GfeException e) { + // lookup actual database id row from database + // if it doesn't exist, it will be created at this point + GFEDao dao = new GFEDao(); + this.dbId = dao.getDatabaseId(dbId); + } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, - "Unable to get gridConfig for: " + dbId, e); + "Unable to look up database id for ifp database: " + dbId, + e); + this.valid = false; } - if (valid) { - try { - // lookup actual database id row from database - // if it doesn't exist, it will be created at this point - GFEDao dao = new GFEDao(); - this.dbId = dao.getDatabaseId(dbId); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "Unable to look up database id for ifp database: " - + dbId, e); - valid = false; - } - } + this.updateDbs(); } /** @@ -513,6 +505,9 @@ public class IFPGridDatabase extends GridDatabase { rec.setMessageData(vSlice); updatedRecords.add(rec); break; + + default: + // do nothing } } @@ -606,6 +601,9 @@ public class IFPGridDatabase extends GridDatabase { vectorRecord[0].setFloatData(convertedVectorData); rec.setMessageData(vectorRecord); break; + + default: + // do nothing } } this.saveGridsToHdf5(records); @@ -1579,6 +1577,10 @@ public class IFPGridDatabase extends GridDatabase { return true; } + /** + * @param parmAndLevel + * @return string array containing parm name and level + */ public String[] splitNameAndLevel(String parmAndLevel) { String[] retValue = parmAndLevel.split("_"); @@ -1598,12 +1600,6 @@ public class IFPGridDatabase extends GridDatabase { return sr; } - /** - * Gets the HDF5 file containing the grid parm info. Initializes the info if - * necessary - * - * @return The HDF5 file - */ protected void initGridParmInfo() { try { if ((gridConfig != null) @@ -1820,6 +1816,11 @@ public class IFPGridDatabase extends GridDatabase { return dataAttributes; } + /** + * @param dataObjects + * @return Returns records that failed to store + * @throws GfeException + */ public List saveGridsToHdf5(List dataObjects) throws GfeException { return saveGridsToHdf5(dataObjects, null); @@ -1828,8 +1829,10 @@ public class IFPGridDatabase extends GridDatabase { /** * Saves GFERecords to the HDF5 repository * - * @param rec + * @param dataObjects * The GFERecords to be saved + * @param parmStorageInfo + * the parameter storage info * @return Returns records that failed to store * @throws GfeException * If errors occur during the interaction with the HDF5 @@ -2268,7 +2271,7 @@ public class IFPGridDatabase extends GridDatabase { IDataRecord[] rawData = entry.getKey().retrieveGroups(groups, Request.ALL); - if (rawData.length != groups.length * 2) { + if (rawData.length != (groups.length * 2)) { throw new IllegalArgumentException( "Invalid number of dataSets returned expected per group, received: " + ((double) rawData.length / groups.length)); @@ -2283,7 +2286,7 @@ public class IFPGridDatabase extends GridDatabase { // Should be vector data and each group should have had a // Dir and Mag dataset for (int i = 0; i < 2; i++) { - IDataRecord rec = rawData[count * 2 + i]; + IDataRecord rec = rawData[(count * 2) + i]; if ("Mag".equals(rec.getName())) { magRec = rec; } else if ("Dir".equals(rec.getName())) { @@ -2371,14 +2374,14 @@ public class IFPGridDatabase extends GridDatabase { floats = new float[rawBytes.length]; for (int idx = 0; idx < rawBytes.length; idx++) { // hex mask to treat bytes as unsigned - floats[idx] = (rawBytes[idx] & 0xff) / multiplier + offset; + floats[idx] = ((rawBytes[idx] & 0xff) / multiplier) + offset; } } else if ("short".equals(storageType)) { short[] rawShorts = ((ShortDataRecord) rawData).getShortData(); floats = new float[rawShorts.length]; for (int idx = 0; idx < rawShorts.length; idx++) { // shorts are stored as signed, no masking! - floats[idx] = rawShorts[idx] / multiplier + offset; + floats[idx] = (rawShorts[idx] / multiplier) + offset; } } else if ("float".equals(storageType)) { throw new IllegalArgumentException( @@ -2571,6 +2574,13 @@ public class IFPGridDatabase extends GridDatabase { return sr; } + /** + * Retrieve the cached ParmID database object + * + * @param parmNameAndLevel + * @return the cached ParmID + * @throws UnknownParmIdException + */ public ParmID getCachedParmID(String parmNameAndLevel) throws UnknownParmIdException { ParmID rval = parmIdMap.get(parmNameAndLevel); @@ -2605,7 +2615,7 @@ public class IFPGridDatabase extends GridDatabase { * the time range to update sent time for * @param sentTime * the sent time to update to - * @return + * @return map containing updated grid histories */ @Override public ServerResponse>> updateSentTime( diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/ModelState.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/ModelState.java deleted file mode 100644 index b9b33ca9e3..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/ModelState.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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. - **/ -package com.raytheon.edex.plugin.gfe.server.database; - -/** - * TODO Add Description - * - *
- * SOFTWARE HISTORY
- * Date			Ticket#		Engineer	Description
- * ------------	----------	-----------	--------------------------
- * Jun 19, 2008				randerso	Initial creation
- * 
- * 
- * - * @author randerso - * @version 1.0 - */ - -public class ModelState { - // TODO: implement -} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/NetCDFGridDatabase.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/NetCDFGridDatabase.java index 6f5c15b11f..a3b07cc0cd 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/NetCDFGridDatabase.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/NetCDFGridDatabase.java @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.SortedSet; +import java.util.TreeSet; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; @@ -65,6 +66,8 @@ import com.vividsolutions.jts.geom.Coordinate; * ------------ ---------- ----------- -------------------------- * May 14, 2012 randerso Initial creation * Oct 10 2012 #1260 randerso Added check for domain not overlapping the dataset + * Jul 03 2013 #2044 randerso Changed getValidTimes to return empty set instead of null + * Don't create RemapGrid until needed. * * * @@ -127,7 +130,7 @@ public class NetCDFGridDatabase extends VGridDatabase { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((pid == null) ? 0 : pid.hashCode()); + result = (prime * result) + ((pid == null) ? 0 : pid.hashCode()); return result; } @@ -168,6 +171,15 @@ public class NetCDFGridDatabase extends VGridDatabase { private RemapGrid remap; + /** + * Constructor + * + * @param config + * the server configuration + * @param file + * the NetCDFFile + * @throws GfeException + */ public NetCDFGridDatabase(IFPServerConfig config, NetCDFFile file) throws GfeException { super(config); @@ -202,23 +214,19 @@ public class NetCDFGridDatabase extends VGridDatabase { this.subdomain = NetCDFUtils.getSubGridDims(this.inputGloc, this.outputGloc); - if (this.subdomain.isEmpty()) { - statusHandler.warn(this.dbId - + ": GFE domain does not overlap dataset domain."); - this.remap = null; - } else { - GridLocation subGloc = new GridLocation(this.dbId.toString(), - this.inputGloc.getProjection(), new Point( - this.subdomain.width, this.subdomain.height), - new Coordinate(this.subdomain.x, this.subdomain.y), - new Coordinate(this.subdomain.width, - this.subdomain.height), "GMT"); - this.remap = new RemapGrid(subGloc, this.outputGloc); - } loadParms(); } } + /** + * Get the DatabaseID for a NetCDFFile + * + * @param file + * the NetCDFFile + * @param config + * the server configuration + * @return the DatabaseID + */ public static DatabaseID getDBID(NetCDFFile file, IFPServerConfig config) { return new DatabaseID(getSiteID(config), DataType.GRID, "D2D", file.getModelName(), file.getModelTime()); @@ -237,9 +245,9 @@ public class NetCDFGridDatabase extends VGridDatabase { @Override public SortedSet getValidTimes() throws GfeException, DataAccessLayerException { - // do nothing for now, only needed for manual smartInit to run against + // return an empty list, only needed for smartInit to run against // this database which shouldn't be needed - return null; + return new TreeSet(); } @Override @@ -261,15 +269,15 @@ public class NetCDFGridDatabase extends VGridDatabase { // Calculates the precision based on the max/min values. private int calcPrecision(float minV, float maxV) { - if (maxV - minV > 250.0) { + if ((maxV - minV) > 250.0) { return 0; - } else if (maxV - minV > 25.0) { + } else if ((maxV - minV) > 25.0) { return 1; - } else if (maxV - minV > 2.5) { + } else if ((maxV - minV) > 2.5) { return 2; - } else if (maxV - minV > 0.25) { + } else if ((maxV - minV) > 0.25) { return 3; - } else if (maxV - minV > 0.025) { + } else if ((maxV - minV) > 0.025) { return 4; } else { return 5; @@ -285,9 +293,9 @@ public class NetCDFGridDatabase extends VGridDatabase { .getStart().getTime()) / 1000); int start = (int) (times.get(0).getStart().getTime() / 1000) % 86400; - for (int i = 1; i < times.size() - 1; i++) { - if ((times.get(i + 1).getStart().getTime() - times.get(i) - .getStart().getTime()) / 1000 != repeat) { + for (int i = 1; i < (times.size() - 1); i++) { + if (((times.get(i + 1).getStart().getTime() - times.get(i) + .getStart().getTime()) / 1000) != repeat) { return new TimeConstraints(3600, 3600, 0); } } @@ -354,9 +362,10 @@ public class NetCDFGridDatabase extends VGridDatabase { // inventory.setLength(atts.getInventory().getYdim()); for (int time = atts.getInventory().getYdim() - 1; time >= 0; time--) { - if (atts.getInventory().get(level, time) == 0 - || ((accParm) && (time > 0 && this.file.getTpSubPrev(time) && atts - .getInventory().get(level, time - 1) == 0))) { + if ((atts.getInventory().get(level, time) == 0) + || ((accParm) && ((time > 0) + && this.file.getTpSubPrev(time) && (atts + .getInventory().get(level, time - 1) == 0)))) { inventory.remove(time); indices.remove(time); } @@ -402,8 +411,8 @@ public class NetCDFGridDatabase extends VGridDatabase { // inventory.setLength(uatts.getInventory().getYdim()); for (int time = uatts.getInventory().getYdim() - 1; time >= 0; time--) { - if (uatts.getInventory().get(level, time) == 0 - || vatts.getInventory().get(level, time) == 0) { + if ((uatts.getInventory().get(level, time) == 0) + || (vatts.getInventory().get(level, time) == 0)) { inventory.remove(time); indices.remove(time); } @@ -423,13 +432,13 @@ public class NetCDFGridDatabase extends VGridDatabase { // First see if we can make wind. int uindex = parmNames.indexOf("uw"); int vindex = parmNames.indexOf("vw"); - if (uindex != -1 && vindex != -1) { + if ((uindex != -1) && (vindex != -1)) { NetCDFFile.ParmAtts uatts = this.file.getAtts("uw"); NetCDFFile.ParmAtts vatts = this.file.getAtts("vw"); - if (uatts.getInventory().getXdim() == vatts.getInventory() - .getXdim() - && uatts.getInventory().getYdim() == vatts.getInventory() - .getYdim()) { + if ((uatts.getInventory().getXdim() == vatts.getInventory() + .getXdim()) + && (uatts.getInventory().getYdim() == vatts.getInventory() + .getYdim())) { if (uindex < vindex) { int tmp = uindex; uindex = vindex; @@ -444,13 +453,13 @@ public class NetCDFGridDatabase extends VGridDatabase { } else { int sindex = parmNames.indexOf("ws"); int dindex = parmNames.indexOf("wd"); - if (sindex != -1 && dindex != -1) { + if ((sindex != -1) && (dindex != -1)) { NetCDFFile.ParmAtts satts = this.file.getAtts("ws"); NetCDFFile.ParmAtts datts = this.file.getAtts("wd"); - if (satts.getInventory().getXdim() == datts.getInventory() - .getXdim() - && satts.getInventory().getYdim() == datts - .getInventory().getYdim()) { + if ((satts.getInventory().getXdim() == datts.getInventory() + .getXdim()) + && (satts.getInventory().getYdim() == datts + .getInventory().getYdim())) { if (sindex < dindex) { int tmp = sindex; sindex = dindex; @@ -498,7 +507,7 @@ public class NetCDFGridDatabase extends VGridDatabase { // deal with the special tp case, where some of the grids are actually // sums of other grids - if (name.equals("tp") && index > 0 && this.file.getTpSubPrev(index)) { + if (name.equals("tp") && (index > 0) && this.file.getTpSubPrev(index)) { Grid2DFloat prev = new Grid2DFloat(this.file.getGrid(name, index - 1, level, this.subdomain)); for (int x = 0; x < bdata.getXdim(); x++) { @@ -516,7 +525,7 @@ public class NetCDFGridDatabase extends VGridDatabase { } try { - return this.remap.remap(bdata, fillV, maxv, minv, minv); + return getOrCreateRemap().remap(bdata, fillV, maxv, minv, minv); } catch (Exception e) { statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); return null; @@ -593,10 +602,12 @@ public class NetCDFGridDatabase extends VGridDatabase { GridParmInfo gpi = p.getGpi(); GridLocation gloc = gpi.getGridLoc(); + RemapGrid remap = getOrCreateRemap(); + switch (gpi.getGridType()) { case SCALAR: { Grid2DFloat data = null; - if (this.remap == null) { + if (remap == null) { // GFE domain does not overlap D2D grid, return default grid data = new Grid2DFloat(gloc.getNx(), gloc.getNy(), gpi.getMinValue()); @@ -617,7 +628,7 @@ public class NetCDFGridDatabase extends VGridDatabase { Grid2DFloat mag = new Grid2DFloat(gloc.getNx(), gloc.getNy()); Grid2DFloat dir = new Grid2DFloat(gloc.getNx(), gloc.getNy()); - if (this.remap == null) { + if (remap == null) { // GFE domain does not overlap D2D grid, return default grid mag.setAllValues(gpi.getMinValue()); dir.setAllValues(0.0f); @@ -714,4 +725,19 @@ public class NetCDFGridDatabase extends VGridDatabase { String pid = this.outputGloc.getProjection().getProjectionID(); return pid; } + + private RemapGrid getOrCreateRemap() { + if ((this.remap == null) && !this.subdomain.isEmpty()) { + GridLocation subGloc = new GridLocation( + this.dbId.toString(), + this.inputGloc.getProjection(), + new Point(this.subdomain.width, this.subdomain.height), + new Coordinate(this.subdomain.x, this.subdomain.y), + new Coordinate(this.subdomain.width, this.subdomain.height), + "GMT"); + this.remap = new RemapGrid(subGloc, this.outputGloc); + } + + return this.remap; + } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/TopoDatabaseManager.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/TopoDatabaseManager.java index 43f76f7c19..2d53ee7660 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/TopoDatabaseManager.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/database/TopoDatabaseManager.java @@ -23,16 +23,14 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.measure.converter.UnitConverter; import javax.measure.unit.NonSI; import javax.measure.unit.SI; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; -import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; +import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory.OriginType; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; @@ -42,7 +40,6 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.TimeConstraints; -import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DFloat; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; @@ -73,7 +70,9 @@ import com.raytheon.uf.common.topo.TopoQuery; * Jul 10, 2009 njensen Initial creation * May 04, 2012 #574 dgilling Re-port to better match AWIPS1. * Feb 12, 2013 #1608 randerso Changed to use explicit deleteGroups - * Feb 15, 2013 1638 mschenke Deleted topo edex plugin, moved code into common topo + * Feb 15, 2013 #1638 mschenke Deleted topo edex plugin, moved code into common topo + * Jun 13, 2013 #2044 randerso Refactored to use non-singleton GridParmManager, + * code cleanup * * * @@ -86,31 +85,23 @@ public class TopoDatabaseManager { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(TopoDatabaseManager.class); - private static Map topoDbMap = new HashMap(); - private final IFPServerConfig config; private final IDataStore dataStore; - public static void initializeTopoDatabase(String siteID) - throws GfeException { - IFPServerConfig config = IFPServerConfigManager.getServerConfig(siteID); - new TopoDatabaseManager(config, siteID); - } - - public static TopoDatabase getTopoDatabase(String siteID) { - return topoDbMap.get(siteID); - } - - public static void removeTopoDatabase(String siteID) { - topoDbMap.remove(siteID); - } - - public static DatabaseID getTopoDbId(String siteID) { + private DatabaseID getTopoDbId(String siteID) { return new DatabaseID(siteID, DataType.GRID, "EditTopo", "Topo"); } - public TopoDatabaseManager(IFPServerConfig config, String siteID) { + /** + * Constructor + * + * @param siteID + * @param config + * @param gridMgr + */ + public TopoDatabaseManager(String siteID, IFPServerConfig config, + GridParmManager gridMgr) { this.config = config; statusHandler.info("Topography Manager started for " + siteID); @@ -128,7 +119,7 @@ public class TopoDatabaseManager { // Add the topo database. TopoDatabase tdb = new TopoDatabase(this.config, this); if (tdb.databaseIsValid()) { - topoDbMap.put(siteID, tdb); + gridMgr.addDB(tdb); } else { statusHandler.error("Invalid Topo database"); } @@ -141,7 +132,7 @@ public class TopoDatabaseManager { * and the status as a ServerResponse. * * @param gloc - * @return + * @return ServerResponse containing the topo grid slice */ public ServerResponse getTopoData(final GridLocation gloc) { ServerResponse sr = new ServerResponse(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/BaseGfeRequestHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/BaseGfeRequestHandler.java new file mode 100644 index 0000000000..f3ffbe6044 --- /dev/null +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/BaseGfeRequestHandler.java @@ -0,0 +1,54 @@ +/** + * 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. + **/ +package com.raytheon.edex.plugin.gfe.server.handler; + +import com.raytheon.edex.plugin.gfe.server.IFPServer; +import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; +import com.raytheon.uf.common.dataplugin.gfe.request.AbstractGfeRequest; + +/** + * Abstract base class for GFE request handlers + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jun 13, 2013 2044       randerso     Initial creation
+ * 
+ * 
+ * + * @author randerso + * @version 1.0 + */ + +public abstract class BaseGfeRequestHandler { + + protected IFPServer getIfpServer(AbstractGfeRequest request) + throws GfeException { + String siteId = request.getSiteID(); + IFPServer ifpServer = IFPServer.getActiveServer(siteId); + if (ifpServer == null) { + throw new GfeException("No active IFPServer for site: " + siteId); + } + return ifpServer; + } +} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/CommitGridsHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/CommitGridsHandler.java index 3fc2e9a7de..23cf14f815 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/CommitGridsHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/CommitGridsHandler.java @@ -32,7 +32,7 @@ import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException; import com.raytheon.edex.plugin.gfe.isc.IscSendQueue; import com.raytheon.edex.plugin.gfe.isc.IscSendRecord; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.edex.plugin.gfe.server.lock.LockManager; import com.raytheon.edex.plugin.gfe.util.SendNotifications; import com.raytheon.uf.common.dataplugin.gfe.request.CommitGridsRequest; @@ -60,12 +60,14 @@ import com.raytheon.uf.common.time.util.TimeUtil; * 06/16/09 njensen Send notifications * 09/22/09 3058 rjpeter Converted to IRequestHandler * 03/17/13 1773 njensen Log performance + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @author bphillip * @version 1.0 */ -public class CommitGridsHandler implements IRequestHandler { +public class CommitGridsHandler extends BaseGfeRequestHandler implements + IRequestHandler { protected final transient Log logger = LogFactory.getLog(getClass()); private final IPerformanceStatusHandler perfLog = PerformanceStatus @@ -75,6 +77,8 @@ public class CommitGridsHandler implements IRequestHandler { @Override public ServerResponse> handleRequest( CommitGridsRequest request) throws Exception { + IFPServer ifpServer = getIfpServer(request); + ServerResponse> sr = new ServerResponse>(); List commits = request.getCommits(); WsId workstationID = request.getWorkstationID(); @@ -95,7 +99,7 @@ public class CommitGridsHandler implements IRequestHandler { // check that there are not locks for each commit request for (CommitGridRequest commitRequest : commits) { sr.addMessages(lockCheckForCommit(commitRequest, workstationID, - siteID)); + ifpServer.getLockMgr())); } timer.stop(); perfLog.logDuration("Publish Grids: Lock Check For Commit", @@ -105,8 +109,8 @@ public class CommitGridsHandler implements IRequestHandler { timer.reset(); timer.start(); List changes = new ArrayList(); - ServerResponse ssr = GridParmManager.commitGrid(commits, - workstationID, changes, siteID); + ServerResponse ssr = ifpServer.getGridParmMgr().commitGrid( + commits, workstationID, changes); timer.stop(); perfLog.logDuration("Publish Grids: GridParmManager.commitGrid", timer.getElapsedTime()); @@ -124,7 +128,7 @@ public class CommitGridsHandler implements IRequestHandler { .getServerConfig(siteID); String iscrta = serverConfig.iscRoutingTableAddress().get( "ANCF"); - if (sr.isOkay() && iscrta != null + if (sr.isOkay() && (iscrta != null) && serverConfig.sendiscOnPublish() && clientSendStatus && serverConfig.requestISC()) { for (GridUpdateNotification change : changes) { @@ -188,7 +192,7 @@ public class CommitGridsHandler implements IRequestHandler { } private ServerResponse lockCheckForCommit(CommitGridRequest request, - WsId workstationID, String siteID) { + WsId workstationID, LockManager lockMgr) { ServerResponse sr = new ServerResponse(); List lockTables = new ArrayList(); LockTableRequest lockTableRequest = null; @@ -200,8 +204,7 @@ public class CommitGridsHandler implements IRequestHandler { lockTableRequest = new LockTableRequest(request.getDbId()); } - lockTables = LockManager.getInstance() - .getLockTables(lockTableRequest, workstationID, siteID) + lockTables = lockMgr.getLockTables(lockTableRequest, workstationID) .getPayload(); if (sr.isOkay()) { for (int j = 0; j < lockTables.size(); j++) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/CreateNewDbHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/CreateNewDbHandler.java index ef1ee703d1..16b671f802 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/CreateNewDbHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/CreateNewDbHandler.java @@ -19,7 +19,6 @@ **/ package com.raytheon.edex.plugin.gfe.server.handler; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.dataplugin.gfe.request.CreateNewDbRequest; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; import com.raytheon.uf.common.serialization.comm.IRequestHandler; @@ -35,6 +34,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * ------------ ---------- ----------- -------------------------- * May 2, 2013 #1969 randerso Initial creation * May 3, 2013 #1969 randerso Code review comment incorporation + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -42,7 +42,8 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * @version 1.0 */ -public class CreateNewDbHandler implements IRequestHandler { +public class CreateNewDbHandler extends BaseGfeRequestHandler implements + IRequestHandler { /* * (non-Javadoc) @@ -54,7 +55,8 @@ public class CreateNewDbHandler implements IRequestHandler { @Override public ServerResponse handleRequest(CreateNewDbRequest request) throws Exception { - return GridParmManager.createNewDb(request.getDbId()); + return getIfpServer(request).getGridParmMgr().createNewDb( + request.getDbId()); } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetASCIIGridsHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetASCIIGridsHandler.java index 45ad37f5ba..84aaba9393 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetASCIIGridsHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetASCIIGridsHandler.java @@ -52,6 +52,7 @@ import com.raytheon.uf.common.time.TimeRange; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Apr 14, 2011 #8983 dgilling Initial creation + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -59,7 +60,7 @@ import com.raytheon.uf.common.time.TimeRange; * @version 1.0 */ -public class GetASCIIGridsHandler implements +public class GetASCIIGridsHandler extends BaseGfeRequestHandler implements IRequestHandler { /* @@ -72,11 +73,14 @@ public class GetASCIIGridsHandler implements @Override public ServerResponse handleRequest(GetASCIIGridsRequest request) throws Exception { + GridParmManager gridParmMgr = getIfpServer(request).getGridParmMgr(); + ServerResponse sr = new ServerResponse(); // get the grid slices - List gridSlices = getGridSlices(request.getDatabaseIds(), - request.getParmIds(), request.getTimeRange()); + List gridSlices = getGridSlices(gridParmMgr, + request.getDatabaseIds(), request.getParmIds(), + request.getTimeRange()); ASCIIGrid aGrid = new ASCIIGrid(gridSlices, request.getCoordConversionString(), request.getSiteID()); @@ -89,15 +93,15 @@ public class GetASCIIGridsHandler implements return sr; } - private List getGridSlices(List databaseIds, - List parmIds, TimeRange tr) { + private List getGridSlices(GridParmManager gridParmMgr, + List databaseIds, List parmIds, TimeRange tr) { List gridSlices = new ArrayList(); // if parms are specified, get their grid slice if (parmIds.size() > 0) { for (ParmID parmId : parmIds) { // get the time ranges from the inventory - ServerResponse> sr = GridParmManager + ServerResponse> sr = gridParmMgr .getGridInventory(parmId); if (sr.isOkay()) { List timeRanges = sr.getPayload(); @@ -118,7 +122,7 @@ public class GetASCIIGridsHandler implements requests.add(request); // get the grid slices for the parm - ServerResponse> sr2 = GridParmManager + ServerResponse> sr2 = gridParmMgr .getGridData(requests); if (sr2.isOkay()) { gridSlices.addAll(sr2.getPayload()); @@ -131,15 +135,14 @@ public class GetASCIIGridsHandler implements // specified database(s) for (DatabaseID dbId : databaseIds) { // get the parm list for the database - ServerResponse> sr = GridParmManager - .getParmList(dbId); + ServerResponse> sr = gridParmMgr.getParmList(dbId); if (sr.isOkay()) { List parmList = sr.getPayload(); // get the data for each parm for (ParmID parm : parmList) { // get the time ranges from the inventory - ServerResponse> sr2 = GridParmManager + ServerResponse> sr2 = gridParmMgr .getGridInventory(parm); if (sr2.isOkay()) { List timeRanges = sr2.getPayload(); @@ -161,7 +164,7 @@ public class GetASCIIGridsHandler implements requests.add(request); // get the grid slices for the parm - ServerResponse> sr3 = GridParmManager + ServerResponse> sr3 = gridParmMgr .getGridData(requests); if (sr3.isOkay()) { gridSlices.addAll(sr3.getPayload()); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetDbInventoryHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetDbInventoryHandler.java index 29e50b4d8f..afd17ac772 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetDbInventoryHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetDbInventoryHandler.java @@ -22,7 +22,6 @@ package com.raytheon.edex.plugin.gfe.server.handler; import java.util.List; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.request.GetDbInventoryRequest; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; @@ -37,19 +36,20 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * ------------ ---------- ----------- -------------------------- * 04/08/08 #875 bphillip Initial Creation * 09/22/09 3058 rjpeter Converted to IRequestHandler + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @author bphillip * @version 1.0 */ -public class GetDbInventoryHandler implements +public class GetDbInventoryHandler extends BaseGfeRequestHandler implements IRequestHandler { @Override public ServerResponse> handleRequest( GetDbInventoryRequest request) throws Exception { - ServerResponse> sr = GridParmManager - .getDbInventory(request.getSiteID()); + ServerResponse> sr = getIfpServer(request) + .getGridParmMgr().getDbInventory(); return sr; } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridDataHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridDataHandler.java index 4e1ddf6fc3..2be0e9cf5c 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridDataHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridDataHandler.java @@ -22,7 +22,6 @@ package com.raytheon.edex.plugin.gfe.server.handler; import java.util.List; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.dataplugin.gfe.request.GetGridDataRequest; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; @@ -37,15 +36,18 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * ------------ ---------- ----------- -------------------------- * 04/18/08 #875 bphillip Initial Creation * 09/22/09 3058 rjpeter Converted to IRequestHandler + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @author randerso * @version 1.0 */ -public class GetGridDataHandler implements IRequestHandler { +public class GetGridDataHandler extends BaseGfeRequestHandler implements + IRequestHandler { @Override public ServerResponse> handleRequest( GetGridDataRequest request) throws Exception { - return GridParmManager.getGridData(request.getRequests()); + return getIfpServer(request).getGridParmMgr().getGridData( + request.getRequests()); } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridHistoryHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridHistoryHandler.java index 897ccd55f4..2826af4fcb 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridHistoryHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridHistoryHandler.java @@ -22,7 +22,6 @@ package com.raytheon.edex.plugin.gfe.server.handler; import java.util.List; import java.util.Map; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.dataplugin.gfe.GridDataHistory; import com.raytheon.uf.common.dataplugin.gfe.request.GetGridHistoryRequest; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; @@ -39,6 +38,7 @@ import com.raytheon.uf.common.time.TimeRange; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Feb 24, 2011 randerso Initial creation + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -46,7 +46,7 @@ import com.raytheon.uf.common.time.TimeRange; * @version 1.0 */ -public class GetGridHistoryHandler implements +public class GetGridHistoryHandler extends BaseGfeRequestHandler implements IRequestHandler { /* @@ -59,8 +59,8 @@ public class GetGridHistoryHandler implements @Override public ServerResponse>> handleRequest( GetGridHistoryRequest request) throws Exception { - return GridParmManager.getGridHistory(request.getParmID(), - request.getTimeRanges()); + return getIfpServer(request).getGridParmMgr().getGridHistory( + request.getParmID(), request.getTimeRanges()); } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridInventoryHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridInventoryHandler.java index 8f4e2aa04f..4d42471316 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridInventoryHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridInventoryHandler.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.request.GetGridInventoryRequest; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; @@ -41,12 +40,13 @@ import com.raytheon.uf.common.time.TimeRange; * 04/18/08 #875 bphillip Initial Creation * 09/22/09 3058 rjpeter Converted to IRequestHandler * 06/06/13 #2073 dgilling Ensure payload is always populated. + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @author bphillip * @version 1.0 */ -public class GetGridInventoryHandler implements +public class GetGridInventoryHandler extends BaseGfeRequestHandler implements IRequestHandler { @Override public ServerResponse>> handleRequest( @@ -54,8 +54,8 @@ public class GetGridInventoryHandler implements ServerResponse>> sr = new ServerResponse>>(); Map> inventory = new HashMap>(); for (ParmID parmId : request.getParmIds()) { - ServerResponse> timeSr = GridParmManager - .getGridInventory(parmId); + ServerResponse> timeSr = getIfpServer(request) + .getGridParmMgr().getGridInventory(parmId); List times = timeSr.getPayload(); inventory.put(parmId, times); sr.addMessages(timeSr); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridParmInfoHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridParmInfoHandler.java index 370176e9ef..9564ee9530 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridParmInfoHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetGridParmInfoHandler.java @@ -23,7 +23,6 @@ package com.raytheon.edex.plugin.gfe.server.handler; import java.util.ArrayList; import java.util.List; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridParmInfo; import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; import com.raytheon.uf.common.dataplugin.gfe.request.GetGridParmInfoRequest; @@ -39,12 +38,13 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * ------------ ---------- ----------- -------------------------- * 04/08/08 #875 bphillip Initial Creation * 09/22/09 3058 rjpeter Converted to IRequestHandler + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @author bphillip * @version 1.0 */ -public class GetGridParmInfoHandler implements +public class GetGridParmInfoHandler extends BaseGfeRequestHandler implements IRequestHandler { @Override public ServerResponse> handleRequest( @@ -52,8 +52,8 @@ public class GetGridParmInfoHandler implements List parmInfo = new ArrayList(); ServerResponse> sr = new ServerResponse>(); for (ParmID parmId : request.getParmIds()) { - ServerResponse ssr = GridParmManager - .getGridParmInfo(parmId); + ServerResponse ssr = getIfpServer(request) + .getGridParmMgr().getGridParmInfo(parmId); if (ssr.isOkay()) { parmInfo.add(ssr.getPayload()); } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetIscSendStatusHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetIscSendStatusHandler.java index ed15aee591..3abaa809c7 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetIscSendStatusHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetIscSendStatusHandler.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; -import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.uf.common.dataplugin.gfe.request.GetIscSendStatusRequest; import com.raytheon.uf.common.dataplugin.gfe.request.GetIscSendStatusRequest.IscSendStatus; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; @@ -39,6 +39,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jan 21, 2011 #4686 randerso Initial creation + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -46,7 +47,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * @version 1.0 */ -public class GetIscSendStatusHandler implements +public class GetIscSendStatusHandler extends BaseGfeRequestHandler implements IRequestHandler { protected final transient Log logger = LogFactory.getLog(getClass()); @@ -63,8 +64,8 @@ public class GetIscSendStatusHandler implements ServerResponse sr = null; try { - IFPServerConfig config = IFPServerConfigManager - .getServerConfig(request.getSiteID()); + IFPServer ifpServer = getIfpServer(request); + IFPServerConfig config = ifpServer.getConfig(); boolean sendISConSave = config.sendiscOnSave(); boolean sendISConPublish = config.sendiscOnPublish(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetLockTablesHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetLockTablesHandler.java index 49d54fbe02..1cc33e431a 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetLockTablesHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetLockTablesHandler.java @@ -22,7 +22,6 @@ package com.raytheon.edex.plugin.gfe.server.handler; import java.util.List; -import com.raytheon.edex.plugin.gfe.server.lock.LockManager; import com.raytheon.uf.common.dataplugin.gfe.request.GetLockTablesRequest; import com.raytheon.uf.common.dataplugin.gfe.server.lock.LockTable; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; @@ -37,18 +36,20 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * ------------ ---------- ----------- -------------------------- * 04/08/08 #875 bphillip Initial Creation * 09/22/09 3058 rjpeter Converted to IRequestHandler + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @author bphillip * @version 1.0 */ -public class GetLockTablesHandler implements IRequestHandler { +public class GetLockTablesHandler extends BaseGfeRequestHandler implements + IRequestHandler { @Override public ServerResponse> handleRequest( GetLockTablesRequest request) throws Exception { - ServerResponse> sr = LockManager.getInstance() + ServerResponse> sr = getIfpServer(request).getLockMgr() .getLockTables(request.getRequests(), - request.getWorkstationID(), request.getSiteID()); + request.getWorkstationID()); return sr; } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetParmListHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetParmListHandler.java index 7ad7b2d2a6..e51b3f0984 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetParmListHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetParmListHandler.java @@ -22,7 +22,6 @@ package com.raytheon.edex.plugin.gfe.server.handler; import java.util.ArrayList; import java.util.List; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; 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.request.GetParmListRequest; @@ -39,12 +38,14 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * 04/08/08 #875 bphillip Initial Creation * 09/22/09 3058 rjpeter Converted to IRequestHandler * 05/02/13 #1969 randerso Fixed null pointer if getParmList fails + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @author bphillip * @version 1.0 */ -public class GetParmListHandler implements IRequestHandler { +public class GetParmListHandler extends BaseGfeRequestHandler implements + IRequestHandler { @Override public ServerResponse> handleRequest(GetParmListRequest request) throws Exception { @@ -52,7 +53,8 @@ public class GetParmListHandler implements IRequestHandler { List retVal = new ArrayList(); ServerResponse> sr = new ServerResponse>(); for (DatabaseID id : request.getDbIds()) { - ServerResponse> ssr = GridParmManager.getParmList(id); + ServerResponse> ssr = getIfpServer(request) + .getGridParmMgr().getParmList(id); if (ssr.isOkay()) { retVal.addAll(ssr.getPayload()); } else { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetPointDataHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetPointDataHandler.java index b013377fad..c7d09ee0e8 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetPointDataHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetPointDataHandler.java @@ -35,7 +35,6 @@ import org.geotools.coverage.grid.GridGeometry2D; import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord; import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; @@ -69,6 +68,7 @@ import com.vividsolutions.jts.geom.Coordinate; * Aug 11, 2009 njensen Initial creation * Mar 06, 2013 1735 rferrel Change to retrieve multiple points * in a single grid request. + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -76,7 +76,7 @@ import com.vividsolutions.jts.geom.Coordinate; * @version 1.0 */ -public class GetPointDataHandler implements +public class GetPointDataHandler extends BaseGfeRequestHandler implements IRequestHandler { protected final transient Log logger = LogFactory.getLog(getClass()); @@ -168,7 +168,8 @@ public class GetPointDataHandler implements try { ServerResponse> sr = null; if (getSlices) { - sr = GridParmManager.getGridData(reqList); + sr = getIfpServer(request).getGridParmMgr().getGridData( + reqList); } for (Coordinate coordinate : coordinates) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetPythonGridDataHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetPythonGridDataHandler.java index f71557b7e6..439e74cd3b 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetPythonGridDataHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetPythonGridDataHandler.java @@ -22,7 +22,6 @@ package com.raytheon.edex.plugin.gfe.server.handler; import java.util.ArrayList; import java.util.List; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.uf.common.dataplugin.gfe.request.GetPythonGridDataRequest; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; @@ -31,7 +30,7 @@ import com.raytheon.uf.common.dataplugin.gfe.slice.WeatherGridSlice; import com.raytheon.uf.common.serialization.comm.IRequestHandler; /** - * TODO Add Description + * Handler for GetPythonGridDataRequest * *
  * 
@@ -40,9 +39,12 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler;
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Aug 4, 2011            dgilling     Initial creation
+ * Jun 13, 2013     #2044  randerso     Refactored to use IFPServer
  * 
  * 
* + * @deprecated use the Data Access Framework + * * @author dgilling * @version 1.0 */ @@ -51,7 +53,8 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; // DiscreteDefinition/DiscreteKey and WxDefinition/WeatherKey class hierarchy is // ever fully-implemented in Python. -public class GetPythonGridDataHandler implements +@Deprecated +public class GetPythonGridDataHandler extends BaseGfeRequestHandler implements IRequestHandler { /* @@ -66,8 +69,8 @@ public class GetPythonGridDataHandler implements GetPythonGridDataRequest request) throws Exception { ServerResponse> finalResp = new ServerResponse>(); - ServerResponse> sr = GridParmManager - .getGridData(request.getRequests()); + ServerResponse> sr = getIfpServer(request) + .getGridParmMgr().getGridData(request.getRequests()); if (!sr.isOkay()) { finalResp.addMessages(sr); finalResp.setPayload(new ArrayList(0)); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetSelectTimeRangeHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetSelectTimeRangeHandler.java index 1436bf957f..c2b4451acd 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetSelectTimeRangeHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/GetSelectTimeRangeHandler.java @@ -26,7 +26,6 @@ import java.util.NoSuchElementException; import java.util.Scanner; import java.util.TimeZone; -import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; import com.raytheon.uf.common.dataplugin.gfe.request.GetSelectTimeRangeRequest; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; import com.raytheon.uf.common.dataplugin.gfe.time.SelectTimeRange; @@ -54,6 +53,7 @@ import com.raytheon.uf.common.util.FileUtil; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Aug 1, 2012 dgilling Initial creation + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -61,7 +61,7 @@ import com.raytheon.uf.common.util.FileUtil; * @version 1.0 */ -public class GetSelectTimeRangeHandler implements +public class GetSelectTimeRangeHandler extends BaseGfeRequestHandler implements IRequestHandler { private static final transient IUFStatusHandler statusHandler = UFStatus @@ -121,10 +121,8 @@ public class GetSelectTimeRangeHandler implements } if (trFile != null) { - TimeZone localTZ = TimeZone - .getTimeZone(IFPServerConfigManager - .getServerConfig(request.getSiteID()) - .getTimeZones().get(0)); + TimeZone localTZ = TimeZone.getTimeZone(getIfpServer(request) + .getConfig().getTimeZones().get(0)); SelectTimeRange selectTR = loadTimeRange(trFile, localTZ); if (selectTR != null) { TimeRange tr = selectTR.toTimeRange(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscDataRecRequestHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscDataRecRequestHandler.java index 013a94f5dd..1321121258 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscDataRecRequestHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscDataRecRequestHandler.java @@ -27,7 +27,7 @@ import com.raytheon.uf.edex.core.EDEXUtil; /** * Thrift request handler for IscDataRecRequest. Takes request and - * places it on a queue to be executed by IscReceiveSrv. + * places it on a queue to be executed by IscReceiveSrv . * *
  * 
diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/LockChangeHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/LockChangeHandler.java
index 310887c9d7..80f4105982 100644
--- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/LockChangeHandler.java
+++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/LockChangeHandler.java
@@ -23,7 +23,6 @@ package com.raytheon.edex.plugin.gfe.server.handler;
 import java.util.ArrayList;
 import java.util.List;
 
-import com.raytheon.edex.plugin.gfe.server.lock.LockManager;
 import com.raytheon.edex.plugin.gfe.util.SendNotifications;
 import com.raytheon.uf.common.dataplugin.gfe.request.LockChangeRequest;
 import com.raytheon.uf.common.dataplugin.gfe.server.lock.LockTable;
@@ -47,12 +46,15 @@ import com.raytheon.uf.common.status.UFStatus;
  * 04/24/13     1949       rjpeter     Added list sizing
  * 06/12/13     2099       randerso    Send GridUpdateNotifications,
  *                                     clean up error handling
+ * 06/13/13     2044       randerso     Refactored to use IFPServer
  * 
* * @author bphillip * @version 1.0 */ -public class LockChangeHandler implements IRequestHandler { +public class LockChangeHandler extends BaseGfeRequestHandler implements + IRequestHandler { + private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(LockChangeHandler.class); @@ -60,9 +62,9 @@ public class LockChangeHandler implements IRequestHandler { public ServerResponse> handleRequest( LockChangeRequest request) throws Exception { String siteID = request.getSiteID(); - ServerResponse> sr = LockManager.getInstance() + ServerResponse> sr = getIfpServer(request).getLockMgr() .requestLockChange(request.getRequests(), - request.getWorkstationID(), siteID); + request.getWorkstationID()); if (sr.isOkay()) { try { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/PurgeGfeGridsRequestHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/PurgeGfeGridsRequestHandler.java index 8c2911c17b..8724ee36f3 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/PurgeGfeGridsRequestHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/PurgeGfeGridsRequestHandler.java @@ -19,13 +19,13 @@ **/ package com.raytheon.edex.plugin.gfe.server.handler; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; +import java.util.Set; import jep.JepException; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil; import com.raytheon.uf.common.dataplugin.gfe.request.PurgeGfeGridsRequest; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; @@ -41,7 +41,6 @@ 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.FileUtil; -import com.raytheon.uf.edex.site.SiteAwareRegistry; /** * Request handler for PurgeGfeGrids. Will execute the purgeAllGrids.py script @@ -55,6 +54,7 @@ import com.raytheon.uf.edex.site.SiteAwareRegistry; * Sep 23, 2010 dgilling Initial creation * Mar 07, 2013 1759 dgilling Refactored to remove dependency * on GfeScriptExecutor. + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -76,11 +76,11 @@ public class PurgeGfeGridsRequestHandler implements @Override public ServerResponse handleRequest(PurgeGfeGridsRequest request) throws Exception { + // TODO: this could probably be rewritten in Java instead Python ServerResponse sr = new ServerResponse(); sr.setPayload(Boolean.FALSE); - List siteList = Arrays.asList(SiteAwareRegistry.getInstance() - .getActiveSites()); + Set siteList = IFPServer.getActiveSites(); if (!siteList.contains(request.getSiteID())) { sr.addMessage("DatabaseID " + request.getDatabaseID() + " is unknown."); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SaveASCIIGridsHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SaveASCIIGridsHandler.java index 5bb8e905df..6c1ef52bdc 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SaveASCIIGridsHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SaveASCIIGridsHandler.java @@ -24,6 +24,7 @@ import java.util.List; import com.raytheon.edex.plugin.gfe.ifpAG.ASCIIGrid; import com.raytheon.edex.plugin.gfe.server.GridParmManager; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.edex.plugin.gfe.server.lock.LockManager; import com.raytheon.edex.plugin.gfe.util.SendNotifications; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; @@ -36,7 +37,6 @@ import com.raytheon.uf.common.dataplugin.gfe.server.lock.LockTable.LockMode; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerMsg; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; import com.raytheon.uf.common.dataplugin.gfe.server.request.LockRequest; -import com.raytheon.uf.common.dataplugin.gfe.server.request.LockTableRequest; import com.raytheon.uf.common.dataplugin.gfe.server.request.SaveGridRequest; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; @@ -50,7 +50,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; /** - * TODO Add Description + * Request handler SaveASCIIGridsRequest * *
  * 
@@ -60,13 +60,14 @@ import com.raytheon.uf.common.status.UFStatus;
  * ------------ ---------- ----------- --------------------------
  * Apr 21, 2011            dgilling     Initial creation
  * Apr 23, 2013 1949       rjpeter      Removed extra lock table look up
+ * Jun 13, 2013     #2044  randerso     Refactored to use IFPServer
  * 
* * @author dgilling * @version 1.0 */ -public class SaveASCIIGridsHandler implements +public class SaveASCIIGridsHandler extends BaseGfeRequestHandler implements IRequestHandler { private static final transient IUFStatusHandler statusHandler = UFStatus @@ -82,6 +83,10 @@ public class SaveASCIIGridsHandler implements @Override public ServerResponse handleRequest(SaveASCIIGridsRequest request) throws Exception { + IFPServer ifpServer = getIfpServer(request); + GridParmManager gridParmMgr = ifpServer.getGridParmMgr(); + LockManager lockMgr = ifpServer.getLockMgr(); + ServerResponse sr = new ServerResponse(); LocalizationFile tempFile = getTempFile(request.getWorkstationID(), @@ -95,12 +100,11 @@ public class SaveASCIIGridsHandler implements int ngrids = agrid.getGridSlices().size(); for (int i = 0; i < ngrids; i++) { ParmID pid = agrid.getGridSlices().get(i).getGridInfo().getParmID(); - String siteId = pid.getDbId().getSiteId(); // get a list of available databases, see if the grid is part of an - // existing databse. - ServerResponse> srDbInv = GridParmManager - .getDbInventory(siteId); + // existing database. + ServerResponse> srDbInv = gridParmMgr + .getDbInventory(); if (!srDbInv.isOkay()) { msg = "Skipping grid storage [" + (i + 1) + " of " + ngrids + "]. Unable to get database inventory. net: " @@ -112,7 +116,7 @@ public class SaveASCIIGridsHandler implements // if database doesn't exist, then we need to create it if (!databases.contains(pid.getDbId())) { - ServerResponse srCreate = GridParmManager.createNewDb(pid + ServerResponse srCreate = gridParmMgr.createNewDb(pid .getDbId()); if (!srCreate.isOkay()) { msg = "Skipping grid storage [" + (i + 1) + " of " + ngrids @@ -126,7 +130,7 @@ public class SaveASCIIGridsHandler implements // get the grid parm info for this grid slice from the ifpServer. // check for any translation needed and instruct ASCIIGrid to // perform the translation - ServerResponse srGpi = GridParmManager + ServerResponse srGpi = gridParmMgr .getGridParmInfo(pid); if (!srGpi.isOkay()) { msg = "Skipping grid storage [" + (i + 1) + " of " + ngrids @@ -146,17 +150,13 @@ public class SaveASCIIGridsHandler implements } } - // make a LockTableRequest - LockTableRequest ltr = new LockTableRequest(pid); - // make the Lock Request object to lock LockRequest lrl = new LockRequest(pid, agrid.getGridSlices().get(i) .getValidTime(), LockMode.LOCK); // make the request lock change - ServerResponse> srLockChange = LockManager - .getInstance().requestLockChange(lrl, - request.getWorkstationID(), siteId); + ServerResponse> srLockChange = lockMgr + .requestLockChange(lrl, request.getWorkstationID()); if (!srLockChange.isOkay()) { msg = "Skipping grid storage [" + (i + 1) + " of " + ngrids + "]. Unable to obtain lock for " + pid.toString() @@ -179,8 +179,8 @@ public class SaveASCIIGridsHandler implements sgrs.add(sgr); // save the grid - ServerResponse srSave = GridParmManager.saveGridData(sgrs, - request.getWorkstationID(), siteId); + ServerResponse srSave = gridParmMgr.saveGridData(sgrs, + request.getWorkstationID()); if (!srSave.isOkay()) { msg = "Skipping grid storage [" + (i + 1) + " of " + ngrids + "]. Unable to store grid for " + pid.toString() @@ -209,8 +209,8 @@ public class SaveASCIIGridsHandler implements .get(i).getValidTime(), LockMode.UNLOCK); // make the request unlock change - srLockChange = LockManager.getInstance().requestLockChange(lrul, - request.getWorkstationID(), siteId); + srLockChange = lockMgr.requestLockChange(lrul, + request.getWorkstationID()); } tempFile.delete(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SaveGfeGridHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SaveGfeGridHandler.java index d93986e64b..8f5e07c759 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SaveGfeGridHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SaveGfeGridHandler.java @@ -26,7 +26,6 @@ import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; import com.raytheon.edex.plugin.gfe.isc.IscSendQueue; import com.raytheon.edex.plugin.gfe.isc.IscSendRecord; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.edex.plugin.gfe.util.SendNotifications; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; @@ -55,12 +54,14 @@ import com.raytheon.uf.common.time.util.TimeUtil; * 06/24/09 njensen Added sending notifications * 09/22/09 3058 rjpeter Converted to IRequestHandler * 02/12/2013 #1597 randerso Added logging to support GFE Performance investigation + * 06/13/13 2044 randerso Refactored to use IFPServer * * * @author bphillip * @version 1.0 */ -public class SaveGfeGridHandler implements IRequestHandler { +public class SaveGfeGridHandler extends BaseGfeRequestHandler implements + IRequestHandler { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(SaveGfeGridHandler.class); @@ -82,19 +83,21 @@ public class SaveGfeGridHandler implements IRequestHandler { try { ITimer timer = TimeUtil.getTimer(); timer.start(); - sr = GridParmManager.saveGridData(saveRequest, workstationID, - siteID); + sr = getIfpServer(request).getGridParmMgr().saveGridData( + saveRequest, workstationID); timer.stop(); perfLog.logDuration("Save Grids: GridParmManager.saveGridData", timer.getElapsedTime()); + // TODO: move this post processing into GridParmManager // check for sending to ISC timer.reset(); timer.start(); IFPServerConfig serverConfig = IFPServerConfigManager .getServerConfig(siteID); String iscrta = serverConfig.iscRoutingTableAddress().get("ANCF"); - if (serverConfig.requestISC() && clientSendStatus && iscrta != null) { + if (serverConfig.requestISC() && clientSendStatus + && (iscrta != null)) { List iscSendRequests = new ArrayList( saveRequest.size()); for (SaveGridRequest save : saveRequest) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SmartInitRequestHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SmartInitRequestHandler.java index 3492acf6d8..156b053e70 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SmartInitRequestHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/SmartInitRequestHandler.java @@ -23,10 +23,9 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import com.raytheon.edex.plugin.gfe.cache.d2dparms.D2DParmIdCache; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; -import com.raytheon.edex.plugin.gfe.server.database.D2DSatDatabaseManager; +import com.raytheon.edex.plugin.gfe.server.GridParmManager; import com.raytheon.edex.plugin.gfe.smartinit.SmartInitRecord; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.dataplugin.gfe.request.SmartInitRequest; @@ -35,7 +34,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; import com.raytheon.uf.edex.core.EDEXUtil; /** - * TODO Add Description + * Request handler for SmartInitRequest * *
  * 
@@ -43,6 +42,7 @@ import com.raytheon.uf.edex.core.EDEXUtil;
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Oct 12, 2010            dgilling     Initial creation
+ * Jun 13, 2013     #2044  randerso     Refactored to use IFPServer
  * 
  * 
* @@ -50,7 +50,7 @@ import com.raytheon.uf.edex.core.EDEXUtil; * @version 1.0 */ -public class SmartInitRequestHandler implements +public class SmartInitRequestHandler extends BaseGfeRequestHandler implements IRequestHandler { /* @@ -64,6 +64,7 @@ public class SmartInitRequestHandler implements public ServerResponse handleRequest(SmartInitRequest request) throws Exception { ServerResponse sr = new ServerResponse(); + GridParmManager gridParmMgr = getIfpServer(request).getGridParmMgr(); String site = request.getSiteID(); String modelTime = request.getModelTime(); @@ -78,7 +79,7 @@ public class SmartInitRequestHandler implements return sr; } - List inventory = getD2DDatabases(site); + List inventory = getD2DDatabases(gridParmMgr); for (String model : affectedModels) { DatabaseID dbId = findDatabase(model, modelTime, inventory); @@ -124,7 +125,7 @@ public class SmartInitRequestHandler implements Date newestModelTime = new Date(0); DatabaseID newestModel = null; for (DatabaseID dbId : inventory) { - Date toCheck = dbId.getModelTimeAsDate(); + Date toCheck = dbId.getModelDate(); if ((dbId.getModelName().equals(d2dModel)) && (newestModelTime.compareTo(toCheck) < 1)) { newestModel = dbId; @@ -138,13 +139,11 @@ public class SmartInitRequestHandler implements /** * @return */ - private List getD2DDatabases(String siteId) { + private List getD2DDatabases(GridParmManager gridParmMgr) { List d2dDbIds = new ArrayList(); - d2dDbIds.add(D2DSatDatabaseManager.getSatDbId(siteId)); - List gridDbIds = D2DParmIdCache.getInstance() - .getDatabaseIDs(); + List gridDbIds = gridParmMgr.getDbInventory().getPayload(); for (DatabaseID dbId : gridDbIds) { - if (dbId.getSiteId().equalsIgnoreCase(siteId)) { + if (dbId.getDbType().equals("D2D")) { d2dDbIds.add(dbId); } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/lock/LockManager.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/lock/LockManager.java index 60cb3fbaaf..ce19cd4fda 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/lock/LockManager.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/lock/LockManager.java @@ -31,13 +31,11 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; +import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.edex.plugin.gfe.db.dao.GFELockDao; import com.raytheon.edex.plugin.gfe.exception.GfeLockException; import com.raytheon.edex.plugin.gfe.server.GridParmManager; +import com.raytheon.edex.plugin.gfe.server.database.GridDatabase; 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.GridParmInfo; @@ -51,6 +49,8 @@ import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotificatio import com.raytheon.uf.common.dataplugin.gfe.server.request.LockRequest; import com.raytheon.uf.common.dataplugin.gfe.server.request.LockTableRequest; 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.time.TimeRange; import com.raytheon.uf.edex.database.DataAccessLayerException; @@ -65,37 +65,48 @@ import com.raytheon.uf.edex.database.DataAccessLayerException; * 06/17/08 #940 bphillip Implemented GFE Locking * 04/23/13 #1949 rjpeter Updated to work with Normalized Database, * fixed inefficiencies in querying/merging + * 06/13/13 #2044 randerso Converted from singleton to instance per + * site managed by IFPServer * * * @author bphillip * @version 1.0 */ public class LockManager { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(LockManager.class); - /** The logger */ - private final Log logger = LogFactory.getLog(getClass()); + private final String siteId; + + private final IFPServerConfig config; + + private GridParmManager gridParmMgr; private final LockComparator startTimeComparator = new LockComparator(); private final GFELockDao dao = new GFELockDao(); - /** The singleton instance of the LockManager */ - private static LockManager instance = new LockManager(); - /** - * Gets the singleton instance of the LockManager + * Creates a new LockManager * - * @return The singleton instance of the LockManager + * @param siteId + * @param config */ - public static LockManager getInstance() { - return instance; + public LockManager(String siteId, IFPServerConfig config) { + this.siteId = siteId; + this.config = config; } /** - * Creates a new LockManager + * Sets the GridParmManager instance to be used by this LockManager. + * + * Done post construction since GridParmManager and LockManager have + * references to each other + * + * @param gridParmMgr */ - private LockManager() { - + public void setGridParmMgr(GridParmManager gridParmMgr) { + this.gridParmMgr = gridParmMgr; } /** @@ -103,14 +114,12 @@ public class LockManager { * * @param request * The list of lock table requests - * @param wsId + * @param requestor * The workstation ID of the requestor * @return The list of lock tables - * @throws GfeException - * If errors occur while querying the database */ public ServerResponse> getLockTables( - List request, WsId requestor, String siteID) { + List request, WsId requestor) { ServerResponse> sr = new ServerResponse>(); if (request.size() == 0) { @@ -121,9 +130,11 @@ public class LockManager { // extract the ParmIds from the request list Set parmIds = new HashSet(); try { - sr.addMessages(extractParmIds(request, parmIds, siteID)); + sr.addMessages(extractParmIds(request, parmIds)); List nonIfpParmIds = new LinkedList(); + // TODO: is this necessary? There should be no lock requests for + // non-IFP databases // remove parm IDs that are not persisted to database Iterator iter = parmIds.iterator(); while (iter.hasNext()) { @@ -155,7 +166,7 @@ public class LockManager { sr.setPayload(payLoad); } catch (Exception e) { - logger.error("Error getting lock tables for " + parmIds, e); + statusHandler.error("Error getting lock tables for " + parmIds, e); sr.addMessage("Error getting lock tables for " + parmIds); sr.setPayload(new ArrayList(0)); } @@ -171,55 +182,66 @@ public class LockManager { * @param wsId * The workstation ID of the requestor * @return The lock table specified in the LockTableRequest - * @throws GfeException - * If errors occur while retrieving locks */ public ServerResponse> getLockTables( - LockTableRequest request, WsId wsId, String siteID) { - return getLockTables(Arrays.asList(request), wsId, siteID); - } - - public ServerResponse> requestLockChange( - LockRequest request, WsId requestor, String siteID) - throws GfeLockException { - return requestLockChange(request, requestor, siteID, true); + LockTableRequest request, WsId wsId) { + return getLockTables(Arrays.asList(request), wsId); } /** - * Makes a change to a lock in the database. + * Request lock change + * + * @param request + * @param requestor + * @return ServerResponse containing updated lock tables + */ + public ServerResponse> requestLockChange( + LockRequest request, WsId requestor) { + return requestLockChange(request, requestor, true); + } + + /** + * Request lock change * * @param request * The lock request * @param requestor * The workstationID of the requestor - * @throws GfeException - * If errors occur during database interaction + * @param combineLocks + * true if adjacent locks should be combined + * @return ServerResponse containing updated lock tables */ public ServerResponse> requestLockChange( - LockRequest request, WsId requestor, String siteID, - boolean combineLocks) throws GfeLockException { - return requestLockChange(Arrays.asList(request), requestor, siteID, + LockRequest request, WsId requestor, boolean combineLocks) { + return requestLockChange(Arrays.asList(request), requestor, combineLocks); } + /** + * Request lock changes + * + * @param requests + * @param requestor + * @return ServerResponse containing updated lock tables + */ public ServerResponse> requestLockChange( - List requests, WsId requestor, String siteID) { - return requestLockChange(requests, requestor, siteID, true); + List requests, WsId requestor) { + return requestLockChange(requests, requestor, true); } /** - * Makes a change to a lock in the database. + * Request lock changes * * @param requests * The lock requests * @param requestor * The workstationID of the requestor - * @throws GfeException - * If errors occur during database interaction + * @param combineLocks + * true if adjacent locks should be combined + * @return ServerResponse containing updated lock tables */ public ServerResponse> requestLockChange( - List requests, WsId requestor, String siteID, - boolean combineLocks) { + List requests, WsId requestor, boolean combineLocks) { List lockTablesAffected = new LinkedList(); List gridUpdatesAffected = new LinkedList(); @@ -227,7 +249,7 @@ public class LockManager { sr.setPayload(lockTablesAffected); // check for official database locks (which are not allowed) - sr.addMessages(officialDbLockCheck(requests, siteID)); + sr.addMessages(officialDbLockCheck(requests)); if (!sr.isOkay()) { return sr; @@ -247,7 +269,7 @@ public class LockManager { Map lockTableMap; try { // extract the ParmIds from the requests - sr.addMessages(extractParmIdsFromLockReq(req, parmIds, siteID)); + sr.addMessages(extractParmIdsFromLockReq(req, parmIds)); Iterator iter = parmIds.iterator(); while (iter.hasNext()) { @@ -262,7 +284,7 @@ public class LockManager { // get the lock tables specific to the extracted parmIds lockTableMap = dao.getLocks(parmIds, requestor); } catch (Exception e) { - logger.error("Error getting lock tables for " + parmIds, e); + statusHandler.error("Error getting lock tables for " + parmIds, e); sr.addMessage("Error getting lock tables for " + parmIds); return sr; } @@ -287,7 +309,7 @@ public class LockManager { continue; } } catch (Exception e) { - logger.error("Error changing lock", e); + statusHandler.error("Error changing lock", e); sr.addMessage("Requested change lock failed - Exception thrown - " + currentRequest + " LockTable=" @@ -323,7 +345,7 @@ public class LockManager { // the histories that intersect the time ranges instead of the // current two stage query List trs = new ArrayList(); - ServerResponse> ssr = GridParmManager + ServerResponse> ssr = gridParmMgr .getGridInventory(currentParmId, currentTimeRange); sr.addMessages(ssr); trs = ssr.getPayload(); @@ -341,7 +363,7 @@ public class LockManager { } } - ServerResponse>> sr1 = GridParmManager + ServerResponse>> sr1 = gridParmMgr .getGridHistory(currentParmId, updatedGridsTR); Map> histories = null; if (sr1.isOkay()) { @@ -350,7 +372,7 @@ public class LockManager { gridUpdatesAffected.add(new GridUpdateNotification( currentParmId, currentRequest.getTimeRange(), - histories, requestor, siteID)); + histories, requestor, siteId)); } } @@ -398,7 +420,7 @@ public class LockManager { requestorId); replaceLocks(lt, newLock, combineLocks); } catch (DataAccessLayerException e) { - logger.error("Error adding lock", e); + statusHandler.error("Error adding lock", e); throw new GfeLockException("Unable add new lock", e); } } @@ -412,7 +434,7 @@ public class LockManager { + " WorkstationID: " + requestorId); } } else if (ls.equals(LockTable.LockStatus.LOCKED_BY_OTHER)) { - logger.warn("Lock for time range: " + timeRange + statusHandler.warn("Lock for time range: " + timeRange + " already owned"); } else { // Record already unlocked @@ -437,7 +459,7 @@ public class LockManager { * The lock table to examine * @param newLock * The lock to add - * @throws GfeLockException + * @throws DataAccessLayerException * If errors occur when updating the locks in the database */ private void replaceLocks(final LockTable lt, final Lock newLock, @@ -520,7 +542,7 @@ public class LockManager { * The lock table to examine * @param tr * The TimeRange to delete - * @throws GfeLockException + * @throws DataAccessLayerException * If errors occur when updating the locks in the database */ private void deleteLocks(final LockTable lt, final TimeRange tr) @@ -626,7 +648,7 @@ public class LockManager { List parmList = null; if (dbid.getFormat().equals(DatabaseID.DataType.GRID)) { - parmList = GridParmManager.getParmList(dbid).getPayload(); + parmList = gridParmMgr.getParmList(dbid).getPayload(); } else { sr.addMessage("Invalid LockRequest (not GRID type): " + req); return sr; @@ -660,7 +682,8 @@ public class LockManager { ServerResponse sr = new ServerResponse(); if (!req.isParmRequest()) { - logger.error("Expected parm-type request in expandRequestToBoundary"); + statusHandler + .error("Expected parm-type request in expandRequestToBoundary"); } // If this is a break-lock request, then do not expand to time constrts @@ -675,8 +698,8 @@ public class LockManager { switch (dbid.getFormat()) { case GRID: - ServerResponse ssr = GridParmManager - .getGridParmInfo(req.getParmId()); + ServerResponse ssr = gridParmMgr.getGridParmInfo(req + .getParmId()); GridParmInfo gpi = ssr.getPayload(); sr.addMessages(ssr); if (!sr.isOkay()) { @@ -720,7 +743,7 @@ public class LockManager { * @throws GfeException */ private ServerResponse extractParmIds(List ltrList, - Set parmIds, String siteID) throws GfeException { + Set parmIds) throws GfeException { ServerResponse sr = new ServerResponse(); // process each request @@ -729,21 +752,27 @@ public class LockManager { ParmID parmId = ltr.getParmId(); // append parm (if not already in the set) if (!parmIds.contains(parmId)) { - parmIds.add(GridParmManager.getDb(parmId.getDbId()) - .getCachedParmID(parmId)); + GridDatabase db = gridParmMgr.getDatabase(parmId.getDbId()); + if (db != null) { + parmIds.add(db.getCachedParmID(parmId)); + } else { + throw new GfeException( + "Attempt to lock parm in non-existent database: " + + parmId); + } } } else if (ltr.isDatabaseRequest()) { // get all the parmIds for that databaseId - List pids = GridParmManager.getParmList(ltr.getDbId()) + List pids = gridParmMgr.getParmList(ltr.getDbId()) .getPayload(); parmIds.addAll(pids); } else { // get all the parms for all the databases - List dbids = GridParmManager.getDbInventory(siteID) + List dbids = gridParmMgr.getDbInventory() .getPayload(); for (int j = 0; j < dbids.size(); j++) { - List pids = GridParmManager.getParmList( - dbids.get(j)).getPayload(); + List pids = gridParmMgr.getParmList(dbids.get(j)) + .getPayload(); parmIds.addAll(pids); } } @@ -769,7 +798,7 @@ public class LockManager { * If errors occur */ private ServerResponse extractParmIdsFromLockReq(List lrs, - Set parmIds, String siteID) throws GfeException { + Set parmIds) throws GfeException { ServerResponse sr = new ServerResponse(); // process each request @@ -778,12 +807,18 @@ public class LockManager { ParmID parmId = lr.getParmId(); // append parm (if not already in the list) if (!parmIds.contains(parmId)) { - parmIds.add(GridParmManager.getDb(parmId.getDbId()) - .getCachedParmID(parmId)); + GridDatabase db = gridParmMgr.getDatabase(parmId.getDbId()); + if (db != null) { + parmIds.add(db.getCachedParmID(parmId)); + } else { + throw new GfeException( + "Attempt to lock parm in non-existent database: " + + parmId); + } } } else if (lr.isDatabaseRequest()) { - ServerResponse> ssr = GridParmManager - .getParmList(lr.getDbId()); + ServerResponse> ssr = gridParmMgr.getParmList(lr + .getDbId()); sr.addMessages(ssr); List pids = ssr.getPayload(); if (!sr.isOkay()) { @@ -797,15 +832,15 @@ public class LockManager { } else { // get all the parms for all the databases List dbids = new ArrayList(); - ServerResponse> ssr = GridParmManager - .getDbInventory(siteID); + ServerResponse> ssr = gridParmMgr + .getDbInventory(); dbids = ssr.getPayload(); sr.addMessages(ssr); if (!sr.isOkay()) { return sr; } for (int j = 0; j < dbids.size(); j++) { - ServerResponse> ssr1 = GridParmManager + ServerResponse> ssr1 = gridParmMgr .getParmList(dbids.get(j)); sr.addMessages(ssr1); List pids = ssr1.getPayload(); @@ -832,24 +867,15 @@ public class LockManager { * The lock requests * @return The server status */ - private ServerResponse officialDbLockCheck(final List req, - String siteID) { + private ServerResponse officialDbLockCheck(final List req) { ServerResponse sr = new ServerResponse(); Set official = null; - try { - List officialDbs = IFPServerConfigManager - .getServerConfig(siteID).getOfficialDatabases(); - official = new HashSet(officialDbs.size(), 1); + List officialDbs = config.getOfficialDatabases(); + official = new HashSet(officialDbs.size(), 1); - for (DatabaseID offDbId : officialDbs) { - official.add(offDbId.stripModelTime()); - } - } catch (GfeException e) { - sr.addMessage("Unable to get official databases from IFPServer config"); - logger.error( - "Unable to get official database from IFPServer config", e); - return sr; + for (DatabaseID offDbId : officialDbs) { + official.add(offDbId.stripModelTime()); } // process each request - extracting out the databse id w/o modeltime 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 deleted file mode 100644 index fb74c8bfbb..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/notify/GfeIngestNotificationFilter.java +++ /dev/null @@ -1,402 +0,0 @@ -/** - * 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. - **/ -package com.raytheon.edex.plugin.gfe.server.notify; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.raytheon.edex.plugin.gfe.cache.d2dparms.D2DParmIdCache; -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.exception.GfeConfigurationException; -import com.raytheon.edex.plugin.gfe.server.D2DSatParm; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; -import com.raytheon.edex.plugin.gfe.server.database.D2DGridDatabase; -import com.raytheon.edex.plugin.gfe.server.database.D2DGridDatabase.D2DParm; -import com.raytheon.edex.plugin.gfe.server.database.D2DSatDatabase; -import com.raytheon.edex.plugin.gfe.server.database.D2DSatDatabaseManager; -import com.raytheon.edex.plugin.gfe.smartinit.SmartInitQueue; -import com.raytheon.edex.plugin.gfe.smartinit.SmartInitRecord; -import com.raytheon.edex.plugin.gfe.smartinit.SmartInitRecordPK; -import com.raytheon.edex.plugin.gfe.util.SendNotifications; -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.server.notify.DBInvChangeNotification; -import com.raytheon.uf.common.dataplugin.gfe.server.notify.GfeNotification; -import com.raytheon.uf.common.dataplugin.gfe.server.notify.GridUpdateNotification; -import com.raytheon.uf.common.dataplugin.grid.GridRecord; -import com.raytheon.uf.common.dataplugin.message.DataURINotificationMessage; -import com.raytheon.uf.common.dataplugin.level.Level; -import com.raytheon.uf.common.dataplugin.satellite.SatelliteRecord; -import com.raytheon.uf.common.message.WsId; -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.time.TimeRange; -import com.raytheon.uf.edex.core.EDEXUtil; - -/** - * Filters data URI notifications and sends GridUpdate and DbInvChanged - * notifications for new D2D data - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * 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
- * Feb 15, 2013 1638       mschenke     Moved DataURINotificationMessage to uf.common.dataplugin
- * Mar 25, 2013       1823 dgilling     Trigger SAT smart init based only on record's
- *                                      SectorId and PhysicalElement.
- * Mar 20, 2013      #1774 randerso     Refactor to use grid durations from D2DGridDatabase
- * Apr 01, 2013      #1774 randerso     Moved wind component checking to GfeIngestNotificaionFilter
- * Apr 04, 2013      #1787 randerso     Added null check to prevent log spamming for parameters
- *                                      not included in the parameter info file
- * May 2, 2013       #1969 randerso     Updated for change to DBInvChangeNotification
- * 
- * 
- * - * @author dgilling - * @version 1.0 - */ - -public class GfeIngestNotificationFilter { - - private static final transient IUFStatusHandler statusHandler = UFStatus - .getHandler(GfeIngestNotificationFilter.class); - - // private final IPerformanceStatusHandler perfLog = PerformanceStatus - // .getHandler("GFE:"); - - private static Map> windComps = new HashMap>(); - - private SmartInitQueue smartInitQueue = null; - - public void filterDataURINotifications(DataURINotificationMessage message) - throws Exception { - // ITimer timer = TimeUtil.getTimer(); - // timer.start(); - Date arrivalTime = new Date(); - List gridRecords = new ArrayList(500); - List satRecords = new ArrayList(100); - - for (String dataURI : message.getDataURIs()) { - if (dataURI.startsWith("/grid/")) { - gridRecords.add(new GridRecord(dataURI)); - } else if (dataURI.startsWith("/satellite/")) { - satRecords.add(new SatelliteRecord(dataURI)); - } - } - if (!gridRecords.isEmpty()) { - filterGridRecords(gridRecords, arrivalTime); - } - if (!satRecords.isEmpty()) { - filterSatelliteRecords(satRecords, arrivalTime); - } - // timer.stop(); - // perfLog.logDuration( - // "GfeIngestNotificationFilter: processing DataURINotificationMessage", - // timer.getElapsedTime()); - } - - public void filterGridRecords(List gridRecords, Date arrivalTime) - throws Exception { - StringBuilder initNameBuilder = new StringBuilder(120); - - Set activeSites = GFESiteActivation.getInstance() - .getActiveSites(); - for (String site : activeSites) { - // using a map so that the instances can be easily looked up and - // updated - Map inits = new HashMap(); - // Loop through each record received and construct a ParmID - Map> gridInv = new HashMap>(); - Set newDbs = new HashSet(); - - IFPServerConfig config = null; - try { - config = IFPServerConfigManager.getServerConfig(site); - } catch (GfeConfigurationException e) { - statusHandler.error("Unable to retrieve site config for " - + site, e); - continue; - } - for (GridRecord grid : gridRecords) { - String gfeModel = config.gfeModelNameMapping(grid - .getDatasetId()); - DatabaseID dbId = D2DGridDatabase.getDbId(grid.getDatasetId(), - grid.getDataTime().getRefTime(), config); - - // ignore if no mapping - if (dbId != null) { - if ((!D2DParmIdCache.getInstance().getDatabaseIDs() - .contains(dbId)) - && (!newDbs.contains(dbId))) { - List fullInv = GridParmManager - .getDbInventory(site).getPayload(); - fullInv.add(dbId); - newDbs.add(dbId); - GfeNotification dbInv = new DBInvChangeNotification( - Arrays.asList(dbId), null, site); - sendNotification(dbInv); - } - - String d2dParamName = grid.getParameter().getAbbreviation(); - Level level = grid.getLevel(); - Integer fcstHour = grid.getDataTime().getFcstTime(); - - D2DGridDatabase db = (D2DGridDatabase) GridParmManager - .getDb(dbId); - String gfeParamName = db.getGfeParmName(d2dParamName); - - D2DParm parm = db.getD2DParm(d2dParamName, level); - if (parm == null) { - continue; - } - ParmID parmID = parm.getParmId(); - - // check for wind - String otherComponent = null; - String[] components = parm.getComponents(); - if (components.length > 1) { - if (components[0].equals(d2dParamName)) { - otherComponent = components[1]; - } else { - otherComponent = components[0]; - } - } - - // if wind see if other component is available - if (otherComponent != null) { - ParmID otherPid = new ParmID(otherComponent, - parmID.getDbId(), parmID.getParmLevel()); - synchronized (windComps) { - // get the other components times - Set otherTimes = windComps.get(otherPid); - - // if we don't have the other component for this - // fcstHour - if ((otherTimes == null) - || !otherTimes.remove(fcstHour)) { - // need to wait for other component - ParmID compPid = new ParmID(d2dParamName, - parmID.getDbId(), parmID.getParmLevel()); - Set times = windComps.get(compPid); - if (times == null) { - times = new HashSet(); - windComps.put(compPid, times); - } - times.add(fcstHour); - continue; - } - } - } - List trs = gridInv.get(parmID); - if (trs == null) { - trs = new ArrayList(); - gridInv.put(parmID, trs); - } - - TimeRange tr = db.getTimeRange(parmID, fcstHour); - if (tr != null) { - trs.add(tr); - } - - List siteInitModules = config.initModels(gfeModel); - for (String modelName : siteInitModules) { - initNameBuilder.delete(0, initNameBuilder.length()); - initNameBuilder.append(site); - initNameBuilder.append("_GRID_D2D_"); - initNameBuilder.append(modelName); - initNameBuilder.append('_'); - initNameBuilder.append(dbId.getModelTime()); - - SmartInitRecordPK id = new SmartInitRecordPK( - initNameBuilder.toString(), grid.getDataTime() - .getValidPeriod().getStart()); - - SmartInitRecord record = inits.get(id); - if (record == null) { - record = new SmartInitRecord(); - record.setId(id); - record.setInsertTime(arrivalTime); - record.setSmartInit(modelName); - record.setDbName(dbId.toString()); - record.setPriority(SmartInitRecord.LIVE_SMART_INIT_PRIORITY); - inits.put(id, record); - } - } - } - } - - // DR 15442 - move last for loop out of the for loop at line 110 - List guns = new ArrayList(); - for (ParmID parmId : gridInv.keySet()) { - try { - List trs = gridInv.get(parmId); - for (TimeRange time : trs) { - List histList = new ArrayList(); - histList.add(new GridDataHistory( - 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())); - } - } catch (Exception e) { - statusHandler.error("Unable to retrieve grid history for " - + parmId.toString(), e); - } - } - - try { - sendNotifications(guns); - } catch (Exception e) { - statusHandler.error("Unable to send grib ingest notifications", - e); - } - - smartInitQueue.addInits(inits.values()); - } - } - - public void filterSatelliteRecords(List records, - Date arrivalTime) throws Exception { - StringBuilder initNameBuilder = new StringBuilder(120); - - Set activeSites = GFESiteActivation.getInstance() - .getActiveSites(); - for (String site : activeSites) { - // using a map so that the instances can be easily looked up and - // updated - Map inits = new HashMap(); - List guns = new ArrayList(); - - IFPServerConfig config = null; - try { - config = IFPServerConfigManager.getServerConfig(site); - } catch (GfeConfigurationException e) { - statusHandler.error( - "Error retrieiving site config for " + site, e); - continue; - } - - List siteInitModules = config.initModels("Satellite"); - Map satData = config.satDirs(); - D2DSatDatabase satDb = D2DSatDatabaseManager.getSatDatabase(site); - - for (SatelliteRecord msg : records) { - Date validTime = msg.getDataTime().getValidPeriod().getStart(); - String product = msg.getSectorID() + "/" - + msg.getPhysicalElement(); - if (satData.containsKey(product)) { - ParmID pid = new ParmID(satData.get(product), - satDb.getDbId()); - D2DSatParm satParm = satDb.findParm(pid); - TimeRange tr = new TimeRange(validTime, satParm - .getGridParmInfo().getPayload() - .getTimeConstraints().getDuration() * 1000); - GridUpdateNotification notify = new GridUpdateNotification( - pid, tr, satParm.getGridHistory(Arrays.asList(tr)) - .getPayload(), null, site); - guns.add(notify); - - for (String init : siteInitModules) { - initNameBuilder.delete(0, initNameBuilder.length()); - initNameBuilder.append(site); - initNameBuilder.append("_GRID_D2D_"); - initNameBuilder.append(init); - initNameBuilder.append("_00000000_0000"); - SmartInitRecordPK id = new SmartInitRecordPK( - initNameBuilder.toString(), validTime); - if (!inits.containsKey(id)) { - SmartInitRecord record = new SmartInitRecord(); - record.setId(id); - record.setInsertTime(arrivalTime); - record.setSmartInit(init); - record.setDbName(satDb.getDbId().toString()); - record.setPriority(SmartInitRecord.LIVE_SMART_INIT_PRIORITY); - inits.put(id, record); - } - } - } - } - - try { - sendNotifications(guns); - } catch (Exception e) { - statusHandler.error( - "Unable to send satellite ingest notifications", e); - } - - smartInitQueue.addInits(inits.values()); - } - } - - private void sendNotification(GfeNotification notification) - throws Exception { - sendNotifications(Arrays.asList(notification)); - } - - private void sendNotifications(List notifications) - throws Exception { - byte[] message = SerializationUtil.transformToThrift(notifications); - EDEXUtil.getMessageProducer().sendAsyncUri( - "jms-generic:topic:gfeGribNotification?timeToLive=60000", - message); - SendNotifications.send(notifications); - } - - public SmartInitQueue getSmartInitQueue() { - return smartInitQueue; - } - - public void setSmartInitQueue(SmartInitQueue smartInitQueue) { - this.smartInitQueue = smartInitQueue; - } - - public static void purgeDbs(List dbsToRemove) { - 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); - } - } - } - -} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/IFPDB.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/IFPDB.java index bb7735ce51..fb342d4aff 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/IFPDB.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/IFPDB.java @@ -20,13 +20,17 @@ package com.raytheon.edex.plugin.gfe.smartinit; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import com.raytheon.edex.plugin.gfe.server.GridParmManager; +import com.raytheon.edex.plugin.gfe.server.IFPServer; +import com.raytheon.edex.plugin.gfe.server.lock.LockManager; 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.dataplugin.gfe.server.message.ServerResponse; /** * IFP Database, originally C++ <--> Python bridge, ported to Java @@ -35,7 +39,8 @@ import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * May 7, 2008 njensen Initial creation + * May 7, 2008 njensen Initial creation + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -45,30 +50,54 @@ import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; public class IFPDB { - private DatabaseID dbid; + private final DatabaseID dbid; + + private final GridParmManager gridParmMgr; + + private final LockManager lockMgr; private List keys; - public IFPDB(String db) { + /** + * Constructor + * + * @param db + * Database ID in string form + * @throws GfeException + */ + public IFPDB(String db) throws GfeException { dbid = new DatabaseID(db); + if (!dbid.isValid()) { + throw new GfeException("Invalid databaseID: " + db); + } + + IFPServer ifpServer = IFPServer.getActiveServer(dbid.getSiteId()); + if (ifpServer == null) { + throw new GfeException("No active IFPServer for site: " + + dbid.getSiteId()); + } + this.gridParmMgr = ifpServer.getGridParmMgr(); + this.lockMgr = ifpServer.getLockMgr(); + ServerResponse> sr = gridParmMgr.getParmList(dbid); + + if (sr.isOkay()) { + List list = sr.getPayload(); + this.keys = new ArrayList(list.size()); + for (ParmID p : list) { + this.keys.add(p.getCompositeName()); + } + } else { + this.keys = Collections.emptyList(); + throw new GfeException(sr.message()); + } } /** * Returns a list of available parms corresponding to the DatabaseID * - * @return + * @return the list of available parms */ public List getKeys() { - if (keys == null) { - List list = GridParmManager.getParmList(dbid).getPayload(); - - keys = new ArrayList(); - if (list != null) { - for (ParmID p : list) { - keys.add(p.getCompositeName()); - } - } - } return keys; } @@ -77,26 +106,33 @@ public class IFPDB { * * @param parmName * the name of the parm - * @return + * @return IFPWE instance for parm * @throws GfeException */ public IFPWE getItem(String parmName) throws GfeException { - return getItem(parmName,IFPWE.SMART_INIT_USER); + return getItem(parmName, IFPWE.SMART_INIT_USER); } - - public IFPWE getItem(String parmName, String userName){ + + /** + * Returns an IFPWE from the database + * + * @param parmName + * @param userName + * @return IFPWE instance for parmName + */ + public IFPWE getItem(String parmName, String userName) { String[] split = parmName.split("_"); String param = split[0]; String level = split[1]; ParmID pid = new ParmID(param, dbid, level); - return new IFPWE(pid,userName); + return new IFPWE(pid, userName, gridParmMgr, lockMgr); } /** * Returns the time of the database * - * @return + * @return the model time */ public Date getModelTime() { return dbid.getModelDate(); @@ -105,7 +141,7 @@ public class IFPDB { /** * Returns the short model name of the database * - * @return + * @return the short model name */ public String getShortModelIdentifier() { return dbid.getShortModelId(); @@ -114,7 +150,7 @@ public class IFPDB { /** * Returns the name of the database * - * @return + * @return the model name */ public String getModelIdentifier() { return dbid.getModelId(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/IFPWE.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/IFPWE.java index d9e33c964b..de29293f15 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/IFPWE.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/IFPWE.java @@ -83,6 +83,8 @@ import com.raytheon.uf.common.util.Pair; * Scalar/VectorGridSlices, refactor * Discrete/WeatherGridSlices builders. * Jun 05, 2013 #2063 dgilling Port history() from A1. + * Jun 13, 2013 #2044 randerso Refactored to use non-singleton + * GridParmManager and LockManager * * * @@ -92,6 +94,7 @@ import com.raytheon.uf.common.util.Pair; public class IFPWE { + /** The smart init user name */ public static final String SMART_INIT_USER = "smartInit"; private static final transient IUFStatusHandler statusHandler = UFStatus @@ -101,6 +104,10 @@ public class IFPWE { private final String siteId; + private final GridParmManager gridParmMgr; + + private final LockManager lockMgr; + private final GridParmInfo gpi; private List availableTimes; @@ -111,17 +118,18 @@ public class IFPWE { * Constructor * * @param parm - * the parm the IFPWE corresponds to - * @throws GfeException + * @param userName + * @param gridParmMgr + * @param lockMgr */ - public IFPWE(ParmID parm) { - this(parm, SMART_INIT_USER); - } - - public IFPWE(ParmID parm, String userName) { + public IFPWE(ParmID parm, String userName, GridParmManager gridParmMgr, + LockManager lockMgr) { parmId = parm; siteId = parm.getDbId().getSiteId(); - gpi = GridParmManager.getGridParmInfo(parmId).getPayload(); + this.gridParmMgr = gridParmMgr; + this.lockMgr = lockMgr; + + gpi = gridParmMgr.getGridParmInfo(parmId).getPayload(); wsId = new WsId(null, userName, "EDEX"); } @@ -133,7 +141,7 @@ public class IFPWE { public List getKeys() { if (availableTimes == null) { availableTimes = new ArrayList(); - List times = GridParmManager.getGridInventory(parmId) + List times = gridParmMgr.getGridInventory(parmId) .getPayload(); if (times != null) { Collections.sort(times); @@ -182,8 +190,7 @@ public class IFPWE { reqList.add(req); List data = new ArrayList(); - ServerResponse> ssr = GridParmManager - .getGridData(reqList); + ServerResponse> ssr = gridParmMgr.getGridData(reqList); data = ssr.getPayload(); IGridSlice slice = null; @@ -212,8 +219,8 @@ public class IFPWE { public List>> get( List times, boolean histories) { GetGridRequest ggr = new GetGridRequest(parmId, times); - ServerResponse> sr = GridParmManager - .getGridData(Arrays.asList(ggr)); + ServerResponse> sr = gridParmMgr.getGridData(Arrays + .asList(ggr)); if (!sr.isOkay()) { String msg = "Could not retrieve grid data for parm [" + parmId @@ -258,10 +265,9 @@ public class IFPWE { TimeRange timeRangeSpan) throws GfeException { statusHandler.debug("Getting lock for ParmID: " + parmId + " TR: " + timeRangeSpan); - ServerResponse> lockResponse = LockManager - .getInstance().requestLockChange( - new LockRequest(parmId, timeRangeSpan, LockMode.LOCK), - wsId, siteId); + ServerResponse> lockResponse = lockMgr + .requestLockChange(new LockRequest(parmId, timeRangeSpan, + LockMode.LOCK), wsId); if (lockResponse.isOkay()) { statusHandler.debug("LOCKING: Lock granted for: " + wsId + " for time range: " + timeRangeSpan); @@ -283,8 +289,8 @@ public class IFPWE { records); try { - ServerResponse sr = GridParmManager.saveGridData( - Arrays.asList(sgr), wsId, siteId); + ServerResponse sr = gridParmMgr.saveGridData(Arrays.asList(sgr), + wsId); if (sr.isOkay()) { SendNotifications.send(sr.getNotifications()); } else { @@ -293,10 +299,9 @@ public class IFPWE { + sr.message()); } } finally { - ServerResponse> unLockResponse = LockManager - .getInstance().requestLockChange( - new LockRequest(parmId, timeRangeSpan, - LockMode.UNLOCK), wsId, siteId); + ServerResponse> unLockResponse = lockMgr + .requestLockChange(new LockRequest(parmId, timeRangeSpan, + LockMode.UNLOCK), wsId); if (unLockResponse.isOkay()) { statusHandler.debug("LOCKING: Unlocked for: " + wsId + " TR: " + timeRangeSpan); @@ -319,7 +324,7 @@ public class IFPWE { * string format. */ public List history(final TimeRange tr) { - ServerResponse>> sr = GridParmManager + ServerResponse>> sr = gridParmMgr .getGridHistory(parmId, Arrays.asList(tr)); if (!sr.isOkay()) { @@ -357,17 +362,16 @@ public class IFPWE { req.setParmId(parmId); List reqList = new ArrayList(); reqList.add(req); - String siteID = parmId.getDbId().getSiteId(); boolean combineLocks = this.wsId.getUserName().equals(SMART_INIT_USER); if (!combineLocks) { statusHandler.debug("Getting lock for ParmID: " + parmId + " TR: " + req.getReplacementTimeRange()); } - ServerResponse> lockResponse = LockManager - .getInstance().requestLockChange( - new LockRequest(req.getParmId(), - req.getReplacementTimeRange(), LockMode.LOCK), - wsId, siteID, combineLocks); + ServerResponse> lockResponse = lockMgr + .requestLockChange( + new LockRequest(req.getParmId(), req + .getReplacementTimeRange(), LockMode.LOCK), + wsId, combineLocks); if (!lockResponse.isOkay()) { throw new GfeException("Request lock failed. " @@ -377,8 +381,7 @@ public class IFPWE { + " for time range: " + req.getReplacementTimeRange()); } try { - ServerResponse resp = GridParmManager.saveGridData(reqList, - wsId, siteID); + ServerResponse resp = gridParmMgr.saveGridData(reqList, wsId); if (resp.isOkay()) { try { ServerResponse notifyResponse = SendNotifications @@ -404,12 +407,11 @@ public class IFPWE { statusHandler.debug("Releasing lock for ParmID: " + parmId + " TR: " + req.getReplacementTimeRange()); } - ServerResponse> unLockResponse = LockManager - .getInstance().requestLockChange( - new LockRequest(req.getParmId(), - req.getReplacementTimeRange(), - LockMode.UNLOCK), wsId, siteID, - combineLocks); + ServerResponse> unLockResponse = lockMgr + .requestLockChange( + new LockRequest(req.getParmId(), req + .getReplacementTimeRange(), LockMode.UNLOCK), + wsId, combineLocks); if (!unLockResponse.isOkay()) { throw new GfeException("Request unlock failed. " + unLockResponse.message()); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/InitClient.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/InitClient.java index ce65ca3e28..b36344cca3 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/InitClient.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/InitClient.java @@ -19,28 +19,23 @@ **/ package com.raytheon.edex.plugin.gfe.smartinit; -import java.util.ArrayList; import java.util.List; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; import com.raytheon.edex.plugin.gfe.reference.ReferenceMgr; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; -import com.raytheon.edex.plugin.gfe.server.database.TopoDatabaseManager; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.edex.plugin.gfe.util.SendNotifications; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; -import com.raytheon.uf.common.dataplugin.gfe.db.objects.GFERecord; -import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID; +import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation; import com.raytheon.uf.common.dataplugin.gfe.exception.GfeException; import com.raytheon.uf.common.dataplugin.gfe.reference.ReferenceID; import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse; import com.raytheon.uf.common.dataplugin.gfe.server.notify.UserMessageNotification; -import com.raytheon.uf.common.dataplugin.gfe.server.request.GetGridRequest; import com.raytheon.uf.common.dataplugin.gfe.slice.IGridSlice; 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; /** * Init Client used by smart init for retrieving specific info @@ -50,7 +45,8 @@ import com.raytheon.uf.common.time.TimeRange; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Apr 29, 2008 njensen Initial creation - * Jul 25, 2012 #957 dgilling Implement getEditAreaNames(). + * Jul 25, 2012 #957 dgilling Implement getEditAreaNames(). + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer * * * @@ -60,24 +56,38 @@ import com.raytheon.uf.common.time.TimeRange; public class InitClient { - private static final transient IUFStatusHandler logger = UFStatus + private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(InitClient.class); - private DatabaseID destinationDB; + private final DatabaseID destinationDB; - public InitClient(String dbId) { + private final IFPServer ifpServer; + + /** + * @param dbId + * @throws GfeException + */ + public InitClient(String dbId) throws GfeException { destinationDB = new DatabaseID(dbId); + if (!destinationDB.isValid()) { + throw new GfeException("Invalid databaseID: " + dbId); + } + + ifpServer = IFPServer.getActiveServer(destinationDB.getSiteId()); + if (ifpServer == null) { + throw new GfeException("No active IFPServer for site: " + + destinationDB.getSiteId()); + } } /** * Returns a list of the databases in the system * - * @return - * @throws GfeException + * @return list of databases */ - public List getKeys() throws GfeException { - List dbIds = GridParmManager.getDbInventory( - destinationDB.getSiteId()).getPayload(); + public List getKeys() { + List dbIds = ifpServer.getGridParmMgr().getDbInventory() + .getPayload(); return dbIds; } @@ -85,35 +95,35 @@ public class InitClient { * Creates a new database with the specified name * * @param key - * @throws GfeException */ - public void createDB(String key) throws GfeException { + public void createDB(String key) { DatabaseID id = new DatabaseID(key); - GridParmManager.createNewDb(id); + ServerResponse sr = ifpServer.getGridParmMgr().createNewDb(id); + if (!sr.isOkay()) { + statusHandler.error("Error creating database " + id + ": " + + sr.message()); + } } /** * Returns a list of the singleton databases as specified in the server * config * - * @return - * @throws GfeException + * @return list of singleton databases */ - public List getSingletonIDs() throws GfeException { - List list = null; - try { - list = IFPServerConfigManager.getServerConfig( - destinationDB.getSiteId()).getSingletonDatabases(); - } catch (GfeException e) { - throw new GfeException("Error determining singleton databases", e); - } - - return list; + public List getSingletonIDs() { + return ifpServer.getConfig().getSingletonDatabases(); } - // returning an array here instead of a List because arrays get converted to - // Python lists automatically by Jep + /** + * Get list of edit area names + * + * @return array of edit area names, possibly empty + */ public String[] getEditAreaNames() { + // returning an array here instead of a List because arrays get + // converted to + // Python lists automatically by Jep try { String siteId = destinationDB.getSiteId(); IFPServerConfig config = IFPServerConfigManager @@ -130,51 +140,42 @@ public class InitClient { return l; } else { - logger.error("Unable to retrieve edit area inventory: " + statusHandler.error("Unable to retrieve edit area inventory: " + sr.message()); } } catch (Exception e) { - logger.error("Unable to retrieve edit area inventory.", e); + statusHandler.error("Unable to retrieve edit area inventory.", e); } return new String[0]; } + /** + * Get topo data + * + * @return the topo grid slice + * @throws GfeException + */ public IGridSlice getTopo() throws GfeException { IGridSlice topo = null; - try { - List parms = GridParmManager.getParmList( - TopoDatabaseManager.getTopoDbId(destinationDB.getSiteId())) - .getPayload(); - if (parms.size() == 1) { - ParmID p = parms.get(0); - GetGridRequest req = new GetGridRequest(); - req.setParmId(p); - GFERecord gfeRec = new GFERecord(p, TimeRange.allTimes()); - ArrayList gfeList = new ArrayList(); - gfeList.add(gfeRec); - req.setRecords(gfeList); - ArrayList reqList = new ArrayList(); - reqList.add(req); - - List data = GridParmManager.getGridData(reqList) - .getPayload(); - if (data != null && data.size() == 1) { - topo = data.get(0); - } else { - throw new GfeException("Error getting grid data for " - + p.toString() - + ". Smart init requires topo and will stop."); - } - } else { - throw new GfeException("Multiple topos, update InitClient"); - } - } catch (GfeException e) { - throw new GfeException("Error with topography for grid location", e); + GridLocation gloc = ifpServer.getConfig().dbDomain(); + ServerResponse sr = ifpServer.getTopoMgr() + .getTopoData(gloc); + if (sr.isOkay()) { + topo = sr.getPayload(); + } else { + throw new GfeException("Error retrieving topo data: " + + sr.message()); } return topo; } + /** + * Sends a user message + * + * @param msg + * @param group + */ public void sendUserMessage(String msg, String group) { UserMessageNotification message = new UserMessageNotification(msg, Priority.EVENTA, group, destinationDB.getSiteId()); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/InitModules.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/InitModules.java deleted file mode 100644 index b9749fd078..0000000000 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/InitModules.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * 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. - **/ -package com.raytheon.edex.plugin.gfe.smartinit; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.SortedSet; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; -import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; -import com.raytheon.edex.plugin.gfe.server.GridParmManager; -import com.raytheon.edex.plugin.gfe.server.database.VGridDatabase; -import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; - -/** - * Static methods to determine if ingested grib data corresponds to smart inits - * that should run. - * - *
- * SOFTWARE HISTORY
- * Date			Ticket#		Engineer	Description
- * ------------	----------	-----------	--------------------------
- * Apr 23, 2008				njensen	Initial creation
- * 
- * 
- * - * @author njensen - * @version 1.0 - */ - -public class InitModules { - - private static final Log logger = LogFactory.getLog(InitModules.class); - - // Counter used to simply force one full model run to complete a smart init - // before another when many inits started at once - private static long manualOffset = 0; - - public static boolean isManual(String initName) { - return !(initName.endsWith(":0")); - } - - public static Collection splitManual(String initName) { - List rval = new ArrayList(60); - - try { - if (initName == null) { - return rval; - } - - // OAX_GRID_D2D_RUC13_20100923_0900 or - // OAX_GRID_D2D_RUC13_20100923_0900:1 or - // OAX_GRID_D2D_RUC13_20100923_0900:1:myRUC13 - String[] tokens = initName.split("[:]"); - - int index = tokens[0].indexOf("_GRID_D2D_"); - if (index < 0) { - return rval; - } - - DatabaseID dbId = new DatabaseID(tokens[0]); - VGridDatabase db = (VGridDatabase) GridParmManager.getDb(dbId); - - boolean calcAll = true; - if (tokens.length > 1 && tokens[1].equals("0")) { - calcAll = false; - } - - List siteInitModules; - String gfeModel = dbId.getModelName(); - String dbName = dbId.toString(); - - if (tokens.length > 2 && tokens[2].length() > 0) { - siteInitModules = new ArrayList(); - siteInitModules.add(tokens[2]); - } else { - IFPServerConfig config = IFPServerConfigManager - .getServerConfig(dbId.getSiteId()); - siteInitModules = config.initModels(gfeModel); - } - - int priority = SmartInitRecord.MANUAL_SMART_INIT_PRIORITY; - if (tokens.length > 3) { - priority = Integer.parseInt(tokens[3]); - } - - SortedSet validTimes = db.getValidTimes(); - - for (String module : siteInitModules) { - for (Date validTime : validTimes) { - SmartInitRecordPK pk = new SmartInitRecordPK( - dbName.replace(gfeModel, module), validTime); - SmartInitRecord record = new SmartInitRecord(); - record.setId(pk); - record.setInsertTime(new Date(manualOffset++)); - record.setSmartInit(module); - record.setDbName(dbName); - record.setManual(calcAll); - record.setPriority(priority); - rval.add(record); - } - } - } catch (Exception e) { - logger.error("Failed to parse manual smartInit request", e); - } - - return rval; - } -} diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitQueue.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitQueue.java index 7cfc9e940d..7440cc09d4 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitQueue.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitQueue.java @@ -19,11 +19,13 @@ **/ package com.raytheon.edex.plugin.gfe.smartinit; -import java.util.Calendar; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.SortedSet; import org.hibernate.HibernateException; import org.hibernate.LockOptions; @@ -33,6 +35,8 @@ import org.hibernate.Transaction; import com.raytheon.edex.plugin.gfe.config.IFPServerConfig; import com.raytheon.edex.plugin.gfe.config.IFPServerConfigManager; import com.raytheon.edex.plugin.gfe.exception.GfeConfigurationException; +import com.raytheon.edex.plugin.gfe.server.IFPServer; +import com.raytheon.edex.plugin.gfe.server.database.VGridDatabase; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; @@ -48,7 +52,10 @@ import com.raytheon.uf.edex.database.dao.DaoConfig; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Dec 11, 2008 njensen Initial creation - * Oct 6, 2009 3172 njensen Based on GribNotifyMessages + * Oct 6, 2009 3172 njensen Based on GribNotifyMessages + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer, + * moved smartInit queuing code here + * from other modules, general code cleanup * * * @author njensen @@ -56,140 +63,289 @@ import com.raytheon.uf.edex.database.dao.DaoConfig; */ public class SmartInitQueue { - private int smartInitTimeoutMillis = 60000; + protected static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(SmartInitQueue.class); - private Map initSet = new HashMap(); + private static SmartInitQueue queue; - protected static final transient IUFStatusHandler handler = UFStatus - .getHandler(SmartInitQueue.class); + /** + * Create the single instance of the queue. Should only be used by spring. + * + * @return the smartInit queue + */ + public static synchronized SmartInitQueue createQueue() { + if (queue == null) { + queue = new SmartInitQueue(); + } + return queue; + } - public void addInits(Collection initsToAdd) { - // event driven start route etc - mergeInits(initsToAdd); - } + /** + * get single instance of queue if it exists + * + * @return the singleton instance or null + */ + public static SmartInitQueue getQueue() { + return queue; + } - private void mergeInits(Collection inits) { - for (SmartInitRecord record : inits) { - try { - DatabaseID toAdd = new DatabaseID(record.getDbName()); - IFPServerConfig config = IFPServerConfigManager - .getServerConfig(toAdd.getSiteId()); - Calendar modelTime = Calendar.getInstance(); - modelTime.setTime(toAdd.getModelTimeAsDate()); - if (config.initSkip(toAdd.getModelName(), - modelTime.get(Calendar.HOUR_OF_DAY))) { - continue; - } - } catch (GfeConfigurationException e) { - handler.handle(Priority.ERROR, e.getLocalizedMessage(), e); - continue; - } + private Map initSet; - synchronized (this) { - SmartInitRecordPK id = record.getId(); - SmartInitRecord oldRecord = initSet.get(id); - if (oldRecord == null) { - initSet.put(id, record); - } else { - Date newInsertTime = record.getInsertTime(); - if (newInsertTime.getTime() > oldRecord.getInsertTime() - .getTime()) { - oldRecord.setInsertTime(newInsertTime); - } - oldRecord.setManual(oldRecord.isManual() - || record.isManual()); - oldRecord.setPriority(Math.min(oldRecord.getPriority(), - record.getPriority())); - } - } - } - } + private SmartInitQueue() { + initSet = new HashMap(); + } - public void addManualInit(String init) { - Collection manualInits = InitModules.splitManual(init); - mergeInits(manualInits); - // force update the tables - fireSmartInit(); - } + /** + * Queue a SmartInit to be run + * + * @param site + * the site ID + * @param config + * server configuration + * @param dbId + * the Database ID + * @param validTime + * model run time + * @param calcAll + * true to force recalculation of all parameters + * @param priority + * priority for smartInit see constants defined in + * {@link SmartInitRecord} + */ + public void queue(String site, IFPServerConfig config, DatabaseID dbId, + Date validTime, boolean calcAll, int priority) { + String gfeModel = dbId.getModelName(); + List siteInitModules = config.initModels(gfeModel); - public void fireSmartInit() { - Map initsToStore = null; + StringBuilder initNameBuilder = new StringBuilder(120); + List inits = new ArrayList( + siteInitModules.size()); + for (String moduleName : siteInitModules) { + initNameBuilder.setLength(0); + initNameBuilder.append(site); + initNameBuilder.append("_GRID_D2D_"); + initNameBuilder.append(moduleName); + initNameBuilder.append('_'); + initNameBuilder.append(dbId.getModelTime()); - // copy off inits to store, allowing other threads to continue - // accumulating - synchronized (this) { - if (initSet.size() > 0) { - initsToStore = initSet; - initSet = new HashMap( - (int) (initsToStore.size() * 1.25) + 1); - } - } + SmartInitRecord record = new SmartInitRecord( + initNameBuilder.toString(), moduleName, validTime, + dbId.toString(), calcAll, priority); + inits.add(record); + } - if (initsToStore != null) { - CoreDao cd = new CoreDao(DaoConfig.DEFAULT); - Session s = null; - Transaction tx = null; - SmartInitRecord oldRecord = null; + mergeInits(inits); + } - for (SmartInitRecord record : initsToStore.values()) { - try { - s = cd.getHibernateTemplate().getSessionFactory() - .openSession(); - tx = s.beginTransaction(); + private void mergeInits(Collection inits) { + for (SmartInitRecord record : inits) { + try { + DatabaseID toAdd = new DatabaseID(record.getDbName()); + IFPServerConfig config = IFPServerConfigManager + .getServerConfig(toAdd.getSiteId()); + String modelTime = toAdd.getModelTime(); + int hour = Integer.parseInt(modelTime.substring(9, 11)); + if (config.initSkip(toAdd.getModelName(), hour)) { + continue; + } + } catch (GfeConfigurationException e) { + statusHandler + .handle(Priority.ERROR, e.getLocalizedMessage(), e); + continue; + } - oldRecord = (SmartInitRecord) s.get(SmartInitRecord.class, - record.getId(), LockOptions.UPGRADE); + synchronized (this) { + SmartInitRecordPK id = record.getId(); + SmartInitRecord oldRecord = initSet.get(id); + if (oldRecord == null) { + initSet.put(id, record); + } else { + Date newInsertTime = record.getInsertTime(); + if (newInsertTime.getTime() > oldRecord.getInsertTime() + .getTime()) { + oldRecord.setInsertTime(newInsertTime); + } + oldRecord.setManual(oldRecord.isManual() + || record.isManual()); + oldRecord.setPriority(Math.min(oldRecord.getPriority(), + record.getPriority())); + } + } + } + } - if (oldRecord == null) { - s.save(record); - } else { - Date newInsertTime = record.getInsertTime(); - oldRecord.setPriority(Math.min(oldRecord.getPriority(), - record.getPriority())); - if (oldRecord.getInsertTime().getTime() < newInsertTime - .getTime()) { - oldRecord.setInsertTime(newInsertTime); - } - oldRecord.setManual(oldRecord.isManual() - || record.isManual()); - s.update(oldRecord); - } - tx.commit(); - } catch (Throwable t) { - handler.handle(Priority.ERROR, "Error adding smartInit [" - + record.getId() + "] to database queue", t); + /** + * Queue a manual smartInit request + * + * @param init + * init request + * + *
+     *  Examples:
+     *     OAX_GRID_D2D_RUC13_20100923_0900 or
+     *     OAX_GRID_D2D_RUC13_20100923_0900:1 or
+     *     OAX_GRID_D2D_RUC13_20100923_0900:1:myRUC13
+     * 
+ */ + public void addManualInit(String init) { + Collection manualInits = splitManual(init); + mergeInits(manualInits); + // force update the tables + fireSmartInit(); + } - if (tx != null) { - try { - tx.rollback(); - } catch (HibernateException e) { - handler.handle( - Priority.ERROR, - "Error rolling back smart init lock transaction", - e); - } - } - } finally { - if (s != null) { - try { - s.close(); - } catch (HibernateException e) { - handler.handle(Priority.ERROR, - "Error closing smart init lock session", e); - } - } - } - } - } + /** + * Flush the in memory smartInit queue to database. + * + * This is done on a timer to reduce the number of database writes + * + */ + public void fireSmartInit() { + Map initsToStore = null; - } + // copy off inits to store, allowing other threads to continue + // accumulating + synchronized (this) { + if (initSet.size() > 0) { + initsToStore = initSet; + initSet = new HashMap( + (int) (initsToStore.size() * 1.25) + 1); + } + } - public int getSmartInitTimeoutMillis() { - return smartInitTimeoutMillis; - } + if (initsToStore != null) { + CoreDao cd = new CoreDao(DaoConfig.DEFAULT); + Session s = null; + try { + s = cd.getHibernateTemplate().getSessionFactory().openSession(); + Transaction tx = null; + SmartInitRecord oldRecord = null; - public void setSmartInitTimeoutMillis(int smartInitTimeoutMillis) { - this.smartInitTimeoutMillis = smartInitTimeoutMillis; - } + for (SmartInitRecord record : initsToStore.values()) { + try { + tx = s.beginTransaction(); + oldRecord = (SmartInitRecord) s.get( + SmartInitRecord.class, record.getId(), + LockOptions.UPGRADE); + + if (oldRecord == null) { + s.save(record); + } else { + Date newInsertTime = record.getInsertTime(); + oldRecord.setPriority(Math.min( + oldRecord.getPriority(), + record.getPriority())); + if (oldRecord.getInsertTime().getTime() < newInsertTime + .getTime()) { + oldRecord.setInsertTime(newInsertTime); + } + oldRecord.setManual(oldRecord.isManual() + || record.isManual()); + s.update(oldRecord); + } + tx.commit(); + } catch (Throwable t) { + statusHandler.handle(Priority.ERROR, + "Error adding smartInit [" + record.getId() + + "] to database queue", t); + + if (tx != null) { + try { + tx.rollback(); + } catch (HibernateException e) { + statusHandler + .handle(Priority.ERROR, + "Error rolling back smart init lock transaction", + e); + } + } + } + } + } finally { + if (s != null) { + try { + s.close(); + } catch (HibernateException e) { + statusHandler.handle(Priority.ERROR, + "Error closing smart init lock session", e); + } + } + } + } + + } + + private Collection splitManual(String initName) { + List rval = new ArrayList(60); + + try { + if (initName == null) { + return rval; + } + + // OAX_GRID_D2D_RUC13_20100923_0900 or + // OAX_GRID_D2D_RUC13_20100923_0900:1 or + // OAX_GRID_D2D_RUC13_20100923_0900:1:myRUC13 + String[] tokens = initName.split("[:]"); + + int index = tokens[0].indexOf("_GRID_D2D_"); + if (index < 0) { + return rval; + } + + DatabaseID dbId = new DatabaseID(tokens[0]); + if (!dbId.isValid()) { + return rval; + } + + IFPServer ifpServer = IFPServer.getActiveServer(dbId.getSiteId()); + if (ifpServer == null) { + return rval; + } + + VGridDatabase db = (VGridDatabase) ifpServer.getGridParmMgr() + .getDatabase(dbId); + if (db == null) { + return rval; + } + + boolean calcAll = true; + if ((tokens.length > 1) && tokens[1].equals("0")) { + calcAll = false; + } + + List siteInitModules; + String gfeModel = dbId.getModelName(); + String dbName = dbId.toString(); + + if ((tokens.length > 2) && (tokens[2].length() > 0)) { + siteInitModules = new ArrayList(); + siteInitModules.add(tokens[2]); + } else { + IFPServerConfig config = IFPServerConfigManager + .getServerConfig(dbId.getSiteId()); + siteInitModules = config.initModels(gfeModel); + } + + int priority = SmartInitRecord.MANUAL_SMART_INIT_PRIORITY; + if (tokens.length > 3) { + priority = Integer.parseInt(tokens[3]); + } + + SortedSet validTimes = db.getValidTimes(); + for (String module : siteInitModules) { + for (Date validTime : validTimes) { + SmartInitRecord record = new SmartInitRecord( + dbName.replace(gfeModel, module), module, + validTime, dbName, calcAll, priority); + rval.add(record); + } + } + } catch (Exception e) { + statusHandler.error("Failed to parse manual smartInit request", e); + } + + return rval; + } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitRecord.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitRecord.java index 30ab570f2b..02fa1baa3b 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitRecord.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitRecord.java @@ -45,6 +45,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Sep 23, 2010 #7277 rjpeter Initial creation + * Jun 13, 2013 #2044 randerso Created proper constructor, code cleanup * * * @@ -55,14 +56,21 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; @Table(name = "smartinit", uniqueConstraints = { @UniqueConstraint(columnNames = { "initName", "validTime", "state" }) }) @DynamicSerialize -public class SmartInitRecord implements IPersistableDataObject, Serializable, +public class SmartInitRecord implements + IPersistableDataObject, Serializable, ISerializableObject, Cloneable { - public static int LIVE_SMART_INIT_PRIORITY = 20; + /** priority for live smart init requests */ + public static final int LIVE_SMART_INIT_PRIORITY = 20; - public static int MANUAL_SMART_INIT_PRIORITY = 2; + /** priority for manual smart init requests */ + public static final int MANUAL_SMART_INIT_PRIORITY = 2; - public static int SITE_ACTIVATION_INIT_PRIORITY = 99; + /** priority for smart init requests generated at site activation */ + public static final int SITE_ACTIVATION_INIT_PRIORITY = 99; + + /** valid time value to indicate all forecast hours should be processed */ + public static final Date ALL_TIMES = new Date(0); private static final long serialVersionUID = 1L; @@ -89,12 +97,36 @@ public class SmartInitRecord implements IPersistableDataObject, Serializable, @Column @DynamicSerializeElement - @Index(name = "smartInitPriorityIdx") + @Index(name = "smartInitPriorityIdx") private int priority = Integer.MAX_VALUE; + /** + * Constructor (only for serialization) + */ public SmartInitRecord() { } + /** + * Constructor + * + * @param initName + * @param module + * @param validTime + * @param dbName + * @param calcAll + * @param priority + */ + public SmartInitRecord(String initName, String module, Date validTime, + String dbName, boolean calcAll, int priority) { + SmartInitRecordPK pk = new SmartInitRecordPK(initName, validTime); + setId(pk); + setInsertTime(new Date()); + setSmartInit(module); + setDbName(dbName); + setManual(calcAll); + setPriority(priority); + } + public SmartInitRecordPK getId() { return id; } @@ -120,7 +152,7 @@ public class SmartInitRecord implements IPersistableDataObject, Serializable, } @Override - public Object getIdentifier() { + public SmartInitRecordPK getIdentifier() { return id; } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitSrv.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitSrv.java index 5567b535a6..2b68e40722 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitSrv.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/smartinit/SmartInitSrv.java @@ -21,6 +21,7 @@ package com.raytheon.edex.plugin.gfe.smartinit; import java.io.File; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,7 +32,7 @@ import jep.JepException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.raytheon.edex.plugin.gfe.config.GFESiteActivation; +import com.raytheon.edex.plugin.gfe.server.IFPServer; import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID; import com.raytheon.uf.common.localization.IPathManager; import com.raytheon.uf.common.localization.LocalizationContext; @@ -55,6 +56,8 @@ import com.raytheon.uf.edex.core.props.PropertiesFactory; * Jul 28, 2010 #6725 jdynina Manual init support * Aug 27, 2010 #3688 wkwock Find model class for a model * Aug 24, 2013 #1949 rjpeter Updated start up logic + * Jun 13, 2013 #2044 randerso Refactored to use IFPServer, + * added support to run init for all valid times * * * @author njensen @@ -92,7 +95,7 @@ public class SmartInitSrv { // default of 2 minutes private int pendingInitMinTimeMillis = 120000; - private int runningInitTimeOutMillis = 300000; + private int runningInitTimeOutMillis = 600000; private int threadSleepInterval = 30000; @@ -142,10 +145,13 @@ public class SmartInitSrv { String init = record.getSmartInit(); String dbName = record.getDbName() + (record.isManual() ? ":1" : ":0"); + Date validTime = record.getId().getValidTime(); + if (SmartInitRecord.ALL_TIMES.equals(validTime)) { + validTime = null; + } DatabaseID db = new DatabaseID(record.getDbName()); - if (GFESiteActivation.getInstance().getActiveSites() - .contains(db.getSiteId())) { + if (IFPServer.getActiveSites().contains(db.getSiteId())) { try { long id = Thread.currentThread().getId(); initScript = cachedInterpreters.get(id); @@ -186,8 +192,7 @@ public class SmartInitSrv { HashMap argMap = new HashMap(); argMap.put("dbName", dbName); argMap.put("model", init); - argMap.put("validTime", record.getId() - .getValidTime()); + argMap.put("validTime", validTime); initScript.execute(argMap); } catch (Throwable e) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/common_static/base/parameter/alias/gfeParamName.xml b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/common_static/base/parameter/alias/gfeParamName.xml index a71a5a7712..5f16fe2e40 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/common_static/base/parameter/alias/gfeParamName.xml +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/common_static/base/parameter/alias/gfeParamName.xml @@ -4,6 +4,7 @@ sorted lists for ease of update May 07, 2013 #1974 randerso Removed unnecessary TPCSG_ entries (should only need TPCSG-) Changed TP_XXX to tpXXX for RFC total precip + Jul 03, 2013 #2044 randerso Removed mappings from tpXXX to tp_XXX for RFCQPF --> av @@ -226,10 +227,10 @@ refd rhmean rhsprd - routed_flow_c - routed_flow_h - routed_flow_m - routed_flow + routedflowc + routedflowh + routedflowm + routedflow rr rrv s1hr @@ -307,8 +308,6 @@ tp6c8 tpmean6 tpsprd6 - tp_ACR - tp_ALR PSurge4Ft PSurge5Ft PSurge6Ft @@ -343,18 +342,7 @@ PSurge3Ft SloshSurge Surge10Pct - tp_ecmwf - tp_FWR - tp_KRF - tp_MSR - tp_ORN - tp_PTR - tp_RHA - tp_RSA - tp_STR - tp_TAR - tp_TIR - tp_TUA + tpecmwf tpw tsprd ttot @@ -372,7 +360,7 @@ vwerranl vwmean vwsprd - water_depth + waterdepth wderranl wgd wom diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/doConfig.py b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/doConfig.py index deee7c6c03..336455fb56 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/doConfig.py +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/doConfig.py @@ -391,15 +391,15 @@ def netcdfParse(netcdfDirs): return dict -def parseSat(satdirs): +def parseSat(satdata): rval = LinkedHashMap() - for e in satdirs: + for e in satdata: if type(e) is types.TupleType: direct, name = check(e, (str, str), - "Format error in SATDIRS entry", satdirs) + "Format error in SATDATA entry", satdata) rval.put(direct, name) else: - raise SyntaxError, "Invalid syntax for SATDIRS" + `satdirs` + raise SyntaxError, "Invalid syntax for SATDATA" + `satdata` return rval def otherParse(serverhost, mhsid, port, diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/serverConfig.py b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/serverConfig.py index bf5c3e4985..74fca65b69 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/serverConfig.py +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/config/gfe/serverConfig.py @@ -1233,7 +1233,18 @@ else: #######DCS3501 WEST_CONUS #--------------------------------------------------------------------------- # -# This table contains directory names and weather element names. +# This table contains product ID and weather element names for satellite data +# +# A product ID consists of the sector ID and physical element of the +# satellite product. +# +# Examples: +# +# "East CONUS/Imager Visible" +# "East CONUS/Imager 11 micron IR" +# "East CONUS/Imager 13 micron (IR)" +# "East CONUS/Imager 3.9 micron IR" +# # Alaska OCONUS if SID in ALASKA_SITES: @@ -1901,7 +1912,7 @@ def doIt(): IFPConfigServer.timeZone = timeZone IFPConfigServer.d2dModels = doConfig.d2dParse(D2DMODELS) IFPConfigServer.netCDFDirs = doConfig.netcdfParse(NETCDFDIRS) - IFPConfigServer.satDirs = doConfig.parseSat(SATDATA) + IFPConfigServer.satData = doConfig.parseSat(SATDATA) IFPConfigServer.domain = domain (serverHost, mhsid, \ diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/ifpnetCDF.py b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/ifpnetCDF.py index 448fc1e692..f77128a2dd 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/ifpnetCDF.py +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/ifpnetCDF.py @@ -65,6 +65,7 @@ from com.raytheon.uf.common.localization import LocalizationContext_Localization # 04/23/13 1937 dgilling Reimplement WECache to match # A1, big perf improvement. # 05/23/13 1759 dgilling Remove unnecessary imports. +# 06/13/13 2044 randerso Updated for changes to TopoDatabaseManager # # @@ -468,10 +469,7 @@ def storeTopoGrid(client, file, databaseID, maskGrid, clipArea): pDict = gridLoc.getProjection() # Get the topo grid - topoDB = TopoDatabaseManager.getTopoDatabase(DatabaseID(databaseID).getSiteId()) - parmId = topoDB.getParmList().getPayload().get(0) - tr = topoDB.getGridInventory(parmId).getPayload() - topoGrid = topoDB.getGridData(parmId, tr).getPayload().get(0).__numpy__[0] + topoGrid = TopoDatabaseManager.getTopoData(gridLoc).getPayload().get(0).__numpy__[0] topoGrid = clipToExtrema(topoGrid, clipArea) topoGrid = numpy.flipud(topoGrid) diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/localDHM.xml b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/localDHM.xml index 4db122d315..ca8358aaa9 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/localDHM.xml +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/localDHM.xml @@ -14,7 +14,7 @@ 432000 - routed_flow_m + routedflowm Channel Routed Flow cfs @@ -29,7 +29,7 @@ - routed_flow_h + routedflowh Channel Routed Flow cfs @@ -44,7 +44,7 @@ - routed_flow_c + routedflowc Channel Routed Flow cfs @@ -74,7 +74,7 @@ - routed_flow + routedflow Channel Routed Flow cfs @@ -134,7 +134,7 @@ - water_depth + waterdepth Hillslope water depth in diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/qpf218.xml b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/qpf218.xml index a6145f66a4..4d1fbf58b8 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/qpf218.xml +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/qpf218.xml @@ -16,7 +16,7 @@ 259200 - tp_MSR + tpMSR 6 hr Total Precip for RFC-> MSR mm millimeter @@ -31,7 +31,7 @@ - tp_RHA + tpRHA 6 hr Total Precip for RFC-> RHA mm millimeter @@ -46,7 +46,7 @@ - tp_RSA + tpRSA 6 hr Total Precip for RFC-> RSA mm millimeter @@ -61,7 +61,7 @@ - tp_HPC + tpHPC 6 hr Total Precip mm millimeter @@ -76,7 +76,7 @@ - tp_ALR + tpALR 6 hr Total Precip for RFC-> ALR mm millimeter @@ -91,7 +91,7 @@ - tp_FWR + tpFWR 6 hr Total Precip for RFC-> FWR mm millimeter @@ -106,7 +106,7 @@ - tp_TUA + tpTUA 6 hr Total Precip for RFC-> TUA mm millimeter @@ -121,7 +121,7 @@ - tp_TIR + tpTIR 6 hr Total Precip for RFC-> TIR mm millimeter @@ -136,7 +136,7 @@ - tp_ACR + tpACR 6 hr Total Precip for RFC-> ACR mm millimeter @@ -151,7 +151,7 @@ - tp_ORN + tpORN 6 hr Total Precip for RFC-> ORN mm millimeter @@ -166,7 +166,7 @@ - tp_PTR + tpPTR 6 hr Total Precip for RFC-> PTR mm millimeter @@ -181,7 +181,7 @@ - tp_STR + tpSTR 6 hr Total Precip for RFC-> STR mm millimeter @@ -196,7 +196,7 @@ - tp_KRF + tpKRF 6 hr Total Precip for RFC-> KRF mm millimeter @@ -211,7 +211,7 @@ - tp_TAR + tpTAR 6 hr Total Precip for RFC-> TAR mm millimeter diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/ruc130.xml b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/ruc130.xml index 6e535f06fc..d5efd42c9d 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/ruc130.xml +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/grid/parameterInfo/ruc130.xml @@ -1,6 +1,7 @@ @@ -65,7 +66,7 @@ 20000.0 -99999.0 37 - MB 1000-300 by 25 250-100 by 50 FRZ CCTL EL + MB 1000-100 by 25 FRZ CBL CTL CCTL EL MB1000 MB975 @@ -96,11 +97,17 @@ MB350 MB325 MB300 + MB275 MB250 + MB225 MB200 + MB175 MB150 + MB125 MB100 FRZ + CBL + CTL CCTL EL @@ -121,9 +128,9 @@ 20.0 -99999.0 0 - SFC + BL 0>180 - SFC + BL0180 @@ -187,7 +194,7 @@ 330.0 -99999.0 37 - FHAG 2 MB 1000-300 by 25 250-100 by 50 BL 0>30 30>60 60>90 + FHAG 2 MB 1000-100 by 25 BL 0>30 30>60 60>90 90>120 120>150 150>180 TROP FHAG2 @@ -220,9 +227,13 @@ MB350 MB325 MB300 + MB275 MB250 + MB225 MB200 + MB175 MB150 + MB125 MB100 BL030 BL3060 @@ -243,7 +254,7 @@ 2.5 -99999.0 5 - MB 1000-300 by 25 250-100 by 50 + MB 1000-100 by 25 MB1000 MB975 @@ -274,9 +285,13 @@ MB350 MB325 MB300 + MB275 MB250 + MB225 MB200 + MB175 MB150 + MB125 MB100 @@ -311,7 +326,7 @@ 100.0 -99999.0 29 - FHAG 2 MB 1000-300 by 25 250-100 by 50 BL 0>30 30>60 60>90 + FHAG 2 MB 1000-100 by 25 BL 0>30 30>60 60>90 90>120 120>150 150>180 FRZ FHAG2 @@ -344,9 +359,13 @@ MB350 MB325 MB300 + MB275 MB250 + MB225 MB200 + MB175 MB150 + MB125 MB100 FRZ BL030 @@ -492,9 +511,9 @@ -150.0 150.0 0 - SFC + FHAG 6000 - SFC + FHAG06000 @@ -507,7 +526,7 @@ 150.0 -99999.0 37 - FHAG 10 MB 1000-300 by 25 250-100 by 50 TROP MAXW BL 0>30 30>60 60>90 + FHAG 10 MB 1000-100 by 25 TROP MAXW BL 0>30 30>60 60>90 90>120 120>150 150>180 FHAG10 @@ -540,9 +559,13 @@ MB350 MB325 MB300 + MB275 MB250 + MB225 MB200 + MB175 MB150 + MB125 MB100 TROP MAXW @@ -610,7 +633,7 @@ 150.0 -99999.0 37 - FHAG 10 MB 1000-300 by 25 250-100 by 50 TROP MAXW BL 0>30 30>60 60>90 + FHAG 10 MB 1000-100 by 25 TROP MAXW BL 0>30 30>60 60>90 90>120 120>150 150>180 FHAG10 @@ -643,9 +666,13 @@ MB350 MB325 MB300 + MB275 MB250 + MB225 MB200 + MB175 MB150 + MB125 MB100 TROP MAXW @@ -697,9 +724,9 @@ 150.0 -99999.0 0 - SFC + FHAG 6000 - SFC + FHAG06000 diff --git a/edexOsgi/com.raytheon.edex.plugin.satellite/src/com/raytheon/edex/plugin/satellite/dao/SatelliteDao.java b/edexOsgi/com.raytheon.edex.plugin.satellite/src/com/raytheon/edex/plugin/satellite/dao/SatelliteDao.java index ea4e0c4d23..1ad4225630 100644 --- a/edexOsgi/com.raytheon.edex.plugin.satellite/src/com/raytheon/edex/plugin/satellite/dao/SatelliteDao.java +++ b/edexOsgi/com.raytheon.edex.plugin.satellite/src/com/raytheon/edex/plugin/satellite/dao/SatelliteDao.java @@ -53,6 +53,7 @@ import com.raytheon.uf.common.geospatial.interpolation.data.ByteArrayWrapper; import com.raytheon.uf.common.geospatial.interpolation.data.DataDestination; import com.raytheon.uf.common.geospatial.interpolation.data.ShortArrayWrapper; import com.raytheon.uf.common.geospatial.interpolation.data.UnsignedByteArrayWrapper; +import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.edex.core.dataplugin.PluginRegistry; import com.raytheon.uf.edex.database.DataAccessLayerException; import com.raytheon.uf.edex.database.plugin.PluginDao; @@ -73,6 +74,8 @@ import com.raytheon.uf.edex.database.query.DatabaseQuery; * 03/25/2013 1823 dgilling Modified getSatelliteData() and * getSatelliteInventory() to allow optional * input arguments. + * 06/24/2013 2044 randerso Added methods to get data by TimeRange and + * getInventory with maxRecord limit * * * @author bphillip @@ -227,7 +230,6 @@ public class SatelliteDao extends PluginDao { for (Date theDate : dates) { if (!inventory.contains(theDate)) { - System.out.println("Not Found: " + theDate); continue; } DatabaseQuery query = new DatabaseQuery(SatelliteRecord.class); @@ -247,12 +249,66 @@ public class SatelliteDao extends PluginDao { query.addOrder("dataTime.refTime", true); try { PluginDataObject[] pdos = this.getFullRecord(query, 0); - for (int i = 0; i < pdos.length; i++) { - satRecords.add((SatelliteRecord) pdos[i]); - satRecords.get(i) - .setMessageData( - ((IDataRecord[]) satRecords.get(i) - .getMessageData())[0]); + for (PluginDataObject pdo : pdos) { + pdo.setMessageData(((IDataRecord[]) pdo.getMessageData())[0]); + satRecords.add((SatelliteRecord) pdo); + } + } catch (Exception e) { + throw new DataAccessLayerException( + "Error retrieving satellite data!", e); + } + } + return satRecords; + } + + /** + * Retrieves fully populated SatelliteRecords using the provided criteria + * for GFE + * + * @param sectorID + * The sector ID of the satellite data + * @param physicalElement + * The physical element of the satellite data + * @param timeRanges + * The timeRanges to retrieve data for + * @return A list of SatelliteRecords corresponding to the provided criteria + * @throws DataAccessLayerException + * If errors occur while retrieving the data + */ + public List getSatelliteData(String sectorID, + String physicalElement, List timeRanges) + throws DataAccessLayerException { + + List satRecords = new ArrayList(); + + List inventory = getSatelliteInventory(null, null, sectorID, + physicalElement); + + List dates = new ArrayList(timeRanges.size()); + for (TimeRange tr : timeRanges) { + for (Date inv : inventory) { + if (tr.contains(inv)) { + dates.add(inv); + break; + } + } + } + + for (Date theDate : dates) { + DatabaseQuery query = new DatabaseQuery(SatelliteRecord.class); + if (sectorID != null) { + query.addQueryParam("sectorID", sectorID); + } + if (physicalElement != null) { + query.addQueryParam("physicalElement", physicalElement); + } + query.addQueryParam("dataTime.refTime", theDate); + query.addOrder("dataTime.refTime", true); + try { + PluginDataObject[] pdos = this.getFullRecord(query, 0); + for (PluginDataObject pdo : pdos) { + pdo.setMessageData(((IDataRecord[]) pdo.getMessageData())[0]); + satRecords.add((SatelliteRecord) pdo); } } catch (Exception e) { throw new DataAccessLayerException( @@ -274,7 +330,7 @@ public class SatelliteDao extends PluginDao { * The sector ID of the satellite data * @param physicalElement * The physical element of the satellite data - * @return A List of Dates desribing the inventory + * @return A List of Dates describing the inventory * @throws DataAccessLayerException * If errors occur while querying the data repository */ @@ -299,7 +355,52 @@ public class SatelliteDao extends PluginDao { @SuppressWarnings("unchecked") List times = (List) this.queryByCriteria(query); - return new ArrayList(times); + return times; + } + + /** + * Gets the inventory of satellite data contained in the data repository for + * the given criteria + * + * @param source + * The source of the satellite data + * @param creatingEntity + * The creating entity of the satellite data + * @param sectorID + * The sector ID of the satellite data + * @param physicalElement + * The physical element of the satellite data + * @param maxRecords + * max number of records to retrieve, -1 for all + * @return A List of Dates describing the inventory + * @throws DataAccessLayerException + * If errors occur while querying the data repository + */ + public List getSatelliteInventory(String source, + String creatingEntity, String sectorID, String physicalElement, + int maxRecords) throws DataAccessLayerException { + DatabaseQuery query = new DatabaseQuery(this.daoClass); + if (source != null) { + query.addQueryParam("source", source); + } + if (creatingEntity != null) { + query.addQueryParam("creatingEntity", creatingEntity); + } + if (sectorID != null) { + query.addQueryParam("sectorID", sectorID); + } + if (physicalElement != null) { + query.addQueryParam("physicalElement", physicalElement); + } + if (maxRecords > 0) { + query.setMaxResults(maxRecords); + } + query.addReturnedField("dataTime.refTime"); + query.addOrder("dataTime.refTime", false); + + @SuppressWarnings("unchecked") + List times = (List) this.queryByCriteria(query); + return times; } /** diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/RemapGrid.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/RemapGrid.java index 72ea0cddd8..211ff05626 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/RemapGrid.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/RemapGrid.java @@ -23,6 +23,7 @@ package com.raytheon.uf.common.dataplugin.gfe; import java.awt.RenderingHints; import java.awt.image.Raster; import java.awt.image.RenderedImage; +import java.lang.ref.SoftReference; import java.nio.ByteBuffer; import javax.media.jai.BorderExtender; @@ -61,11 +62,12 @@ import com.vividsolutions.jts.geom.Coordinate; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * May 16, 2008 875 bphillip Initial Creation. - * Oct 10, 2012 1260 randerso Added getters for source and destination - * glocs - * Feb 19, 2013 1637 randerso Fixed remapping of byte grids - * Jul 17, 2013 2185 bsteffen Cache computed grid reprojections. + * 5/16/08 875 bphillip Initial Creation. + * 10/10/12 #1260 randerso Added getters for source and destination glocs + * 02/19/13 #1637 randerso Fixed remapping of byte grids + * 07/09/13 #2044 randerso Made SoftReferences to interp and rotation since + * they can be quite large and may not be needed frequently + * 07/17/13 #2185 bsteffen Cache computed grid reprojections. * * * @@ -81,9 +83,7 @@ public class RemapGrid { private boolean rescale = false; - private Grid2DFloat rotation; - - private GridReprojection interp; + private SoftReference rotationRef; /** * Constructs a new RemapGrid with the given input and output grid locations @@ -92,7 +92,6 @@ public class RemapGrid { * The source grid location describing the source data * @param destinationGloc * The destination grid location describing the destination data - * @throws FactoryException */ public RemapGrid(GridLocation sourceGloc, GridLocation destinationGloc) { this(sourceGloc, destinationGloc, false); @@ -107,19 +106,25 @@ public class RemapGrid { * The destination grid location describing the destination data * @param rescale * true if data is to be rescaled - * @throws FactoryException */ public RemapGrid(GridLocation sourceGloc, GridLocation destinationGloc, boolean rescale) { this.sourceGloc = sourceGloc; this.destinationGloc = destinationGloc; this.rescale = rescale; + this.rotationRef = new SoftReference(null); } + /** + * @return source GridLocation + */ public GridLocation getSourceGloc() { return sourceGloc; } + /** + * @return destination GridLocation + */ public GridLocation getDestinationGloc() { return destinationGloc; } @@ -179,8 +184,8 @@ public class RemapGrid { Grid2DByte retVal = null; - if (input.getXdim() != sourceGloc.gridSize().x - || input.getYdim() != sourceGloc.gridSize().y) { + if ((input.getXdim() != sourceGloc.gridSize().x) + || (input.getYdim() != sourceGloc.gridSize().y)) { throw new IllegalArgumentException( "Input grid dimensions do not match source grid location dimensions"); } @@ -207,6 +212,26 @@ public class RemapGrid { return retVal; } + /** + * Returns a Grid2D that has been remapped from the input grid in the + * source GridLocation domain space to the destination GridLocation domain + * space. The input grid must be in the same coordinate system as the source + * GridLocation. The data will be sampled. Points outside the area will be + * assigned the input fillValue. + * + * @param input + * The input byte data + * @param inputFill + * The input fill value + * @param outputFill + * The output fill value + * @return The remapped Grid2DByte object + * @throws TransformException + * @throws FactoryException + * @throws IllegalArgumentException + * If the input dimensions do not match the source dimensions or + * when problems occur during resampling + */ public Grid2DByte remap(final Grid2DByte input, int inputFill, int outputFill) throws FactoryException, TransformException { return remap(input, (byte) inputFill, (byte) outputFill); @@ -252,10 +277,10 @@ public class RemapGrid { float outputFillValue, boolean rotate, boolean flip, Grid2DFloat magGrid, Grid2DFloat dirGrid) throws Exception { - if (uinput.getXdim() != sourceGloc.getNx() - || uinput.getYdim() != sourceGloc.getNy() - || vinput.getXdim() != sourceGloc.getNx() - || vinput.getYdim() != sourceGloc.getNy()) { + if ((uinput.getXdim() != sourceGloc.getNx()) + || (uinput.getYdim() != sourceGloc.getNy()) + || (vinput.getXdim() != sourceGloc.getNx()) + || (vinput.getYdim() != sourceGloc.getNy())) { String error = "Source grid sizes do not match source grid location: \n"; error += "source (" + sourceGloc.getNx() + ", " + sourceGloc.getNy() + ")\n"; @@ -377,7 +402,7 @@ public class RemapGrid { for (int x = 0; x < grid.getXdim(); x++) { for (int y = 0; y < grid.getYdim(); y++) { float val = grid.get(x, y); - if (Float.isNaN(val) || val == inputFill) { + if (Float.isNaN(val) || (val == inputFill)) { grid.set(x, y, outputFillValue); } else if (val != outputFillValue) { if (val < minLimit) { @@ -417,7 +442,8 @@ public class RemapGrid { float uVal = uGrid.get(x, y); float vVal = vGrid.get(x, y); - float magValue = (float) Math.sqrt(uVal * uVal + vVal * vVal); + float magValue = (float) Math.sqrt((uVal * uVal) + + (vVal * vVal)); float dirValue = (float) Math.toDegrees(Math.atan2(uVal, vVal)); if (rotate) { @@ -463,12 +489,8 @@ public class RemapGrid { ByteBuffer resampledData = null; GridGeometry2D destGeometry = MapUtil.getGridGeometry(destinationGloc); - synchronized (this) { - if (interp == null) { - interp = PrecomputedGridReprojection.getReprojection( - sourceGeometry, destGeometry); - } - } + GridReprojection interp = PrecomputedGridReprojection.getReprojection( + sourceGeometry, destGeometry); DataSource source = new ByteBufferWrapper(data, sourceGeometry); resampledData = interp.reprojectedGrid( new NearestNeighborInterpolation(), source, @@ -541,12 +563,9 @@ public class RemapGrid { } else { GridGeometry2D destGeometry = MapUtil .getGridGeometry(destinationGloc); - synchronized (this) { - if (interp == null) { - interp = PrecomputedGridReprojection.getReprojection( - sourceGeometry, destGeometry); - } - } + + GridReprojection interp = PrecomputedGridReprojection + .getReprojection(sourceGeometry, destGeometry); DataSource source = new FloatArrayWrapper(data, sourceGeometry); f1 = interp.reprojectedGrid(new BilinearInterpolation(), source, new FloatArrayWrapper(destGeometry)).getArray(); @@ -593,16 +612,21 @@ public class RemapGrid { } private float getRot(int x, int y) { - if (this.rotation == null || !this.rotation.isValid()) { - this.rotation = new Grid2DFloat(destinationGloc.gridSize().x, - destinationGloc.gridSize().y); - for (int x1 = 0; x1 < rotation.getXdim(); x1++) { - for (int y1 = 0; y1 < rotation.getYdim(); y1++) { - Coordinate llc = destinationGloc - .latLonCenter(new Coordinate(x1, y1)); - this.rotation.set(x1, y1, - (float) (180 - MapUtil.rotation(llc, sourceGloc))); + Grid2DFloat rotation; + synchronized (rotationRef) { + rotation = rotationRef.get(); + if ((rotation == null) || !rotation.isValid()) { + rotation = new Grid2DFloat(destinationGloc.gridSize().x, + destinationGloc.gridSize().y); + for (int x1 = 0; x1 < rotation.getXdim(); x1++) { + for (int y1 = 0; y1 < rotation.getYdim(); y1++) { + Coordinate llc = destinationGloc + .latLonCenter(new Coordinate(x1, y1)); + rotation.set(x1, y1, (float) (180 - MapUtil.rotation( + llc, sourceGloc))); + } } + rotationRef = new SoftReference(rotation); } } return rotation.get(x, y); 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 433811fde7..1cd5a95464 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 @@ -24,21 +24,27 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; +import java.util.Set; import java.util.TimeZone; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.OneToMany; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Transient; import javax.persistence.UniqueConstraint; import org.hibernate.annotations.Immutable; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import com.raytheon.uf.common.dataplugin.annotations.DataURI; import com.raytheon.uf.common.dataplugin.gfe.serialize.DatabaseIDAdapter; @@ -60,6 +66,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdap * 01/18/13 1504 randerso Removed setters since class should be immutable * 03/28/13 1949 rjpeter Normalized database structure. * 06/20/13 2127 rjpeter Removed unused bidirectional relationship. + * 06/13/13 2044 randerso Code cleanup * * * @author bphillip @@ -73,17 +80,18 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeTypeAdap @DynamicSerializeTypeAdapter(factory = DatabaseIDAdapter.class) public class DatabaseID implements Comparable { - private static final long serialVersionUID = 5792890762609478694L; - /** * String signifying this database does not use a model time (i.e. is a * singleton database) */ public static final String NO_MODEL_TIME = "00000000_0000"; + /** + * Format for model run time in a DatabaseID + */ public static final String MODEL_TIME_FORMAT = "yyyyMMdd_HHmm"; - public static final ThreadLocal dateFormat = new ThreadLocal() { + private static final ThreadLocal dateFormat = new ThreadLocal() { @Override protected SimpleDateFormat initialValue() { @@ -97,7 +105,11 @@ public class DatabaseID implements Comparable { /** Denotes what type of database */ public enum DataType { - NONE, GRID + /** Invalid DatabseID */ + NONE, + + /** Normal GRID database */ + GRID }; /** @@ -143,6 +155,15 @@ public class DatabaseID implements Comparable { @Transient private String shortModelId; + /** + * Used only for hibernate mappings to allow a cascade delete to all child + * parmIds when the databaseId is deleted. These should not be loaded by or + * referenced normally from code from this object. + */ + @OneToMany(fetch = FetchType.LAZY, mappedBy = "dbId", cascade = { CascadeType.REMOVE }) + @OnDelete(action = OnDeleteAction.CASCADE) + private Set parmIds; + /** * Creates a new DatabaseID */ @@ -232,7 +253,7 @@ public class DatabaseID implements Comparable { /** * Returns the id field, auto-generated surrogate key. * - * @return + * @return the id */ public int getId() { return id; @@ -490,14 +511,14 @@ public class DatabaseID implements Comparable { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (dbType == null ? 0 : dbType.hashCode()); - result = prime * result + (format == null ? 0 : format.hashCode()); + result = (prime * result) + (dbType == null ? 0 : dbType.hashCode()); + result = (prime * result) + (format == null ? 0 : format.hashCode()); String localModelId = getModelId(); - result = prime * result + result = (prime * result) + (localModelId == null ? 0 : localModelId.hashCode()); - result = prime * result + result = (prime * result) + (modelTime == null ? 0 : modelTime.hashCode()); - result = prime * result + (siteId == null ? 0 : siteId.hashCode()); + result = (prime * result) + (siteId == null ? 0 : siteId.hashCode()); return result; } @@ -519,7 +540,7 @@ public class DatabaseID implements Comparable { } /** - * @return the modelDate + * @return the modelDate or null for singleton databases */ public Date getModelDate() { @@ -535,6 +556,11 @@ public class DatabaseID implements Comparable { } // TODO: DELETE THIS METHOD + /** + * @return the model time as a Date + * @deprecated use getModelDate instead + */ + @Deprecated public Date getModelTimeAsDate() { if (this.modelTime.equals(NO_MODEL_TIME)) { return new Date(0); @@ -560,29 +586,35 @@ public class DatabaseID implements Comparable { * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override - public int compareTo(DatabaseID o) { + public int compareTo(DatabaseID other) { - int site = this.siteId.compareTo(o.getSiteId()); + int site = this.siteId.compareTo(other.getSiteId()); if (site != 0) { return site; } - int format = this.format.compareTo(o.getFormat()); + int format = this.format.compareTo(other.getFormat()); if (format != 0) { return format; } - int type = this.dbType.compareTo(o.getDbType()); + int type = this.dbType.compareTo(other.getDbType()); if (type != 0) { return type; } - int model = this.modelName.compareTo(o.getModelName()); + int model = this.modelName.compareTo(other.getModelName()); if (model != 0) { return model; } - int time = -this.getModelTimeAsDate().compareTo(o.getModelTimeAsDate()); + Date thisDate = this.getModelDate(); + Date otherDate = other.getModelDate(); + + long thisTime = (thisDate == null ? 0 : thisDate.getTime()); + long otherTime = (otherDate == null ? 0 : otherDate.getTime()); + + int time = (thisTime < otherTime ? 1 : (thisTime == otherTime ? 0 : -1)); return time; } } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocation.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocation.java index daa1f61a42..68e5962bf0 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocation.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/db/objects/GridLocation.java @@ -61,7 +61,6 @@ import com.raytheon.uf.common.dataplugin.persist.PersistableDataObject; import com.raytheon.uf.common.geospatial.CRSCache; import com.raytheon.uf.common.geospatial.ISpatialObject; import com.raytheon.uf.common.geospatial.MapUtil; -import com.raytheon.uf.common.gridcoverage.GridCoverage; import com.raytheon.uf.common.serialization.ISerializableObject; import com.raytheon.uf.common.serialization.adapters.CoordAdapter; import com.raytheon.uf.common.serialization.adapters.GeometryAdapter; @@ -81,18 +80,17 @@ import com.vividsolutions.jts.operation.buffer.BufferParameters; import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier; /** - * TODO Add Description + * Contains spatial definition for GFE grids * *
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Apr 24, 2008 @1047      randerso    Added fields to store projection
- *                                     information
- * Oct 10, 2012 1260       randerso    Added new constructor that takes a
- *                                     GridCoverage
- * Jul 16, 2013 2181       bsteffen    Convert geometry types to use hibernate-
- *                                     spatial
+ * 04/24/08       @1047     randerso    Added fields to store projection information
+ * 10/10/12      #1260      randerso    Added new constructor that takes a GridCoverage
+ * 07/10/13      #2044      randerso    Changed constructor to take ISpatialObject instead of GridCoverage
+ * 07/16/13      #2181      bsteffen    Convert geometry types to use hibernate-
+ *                                      spatial
  * 
  * 
  * 
@@ -217,7 +215,7 @@ public class GridLocation extends PersistableDataObject implements java.awt.Point gridSize, Coordinate domainOrigin, Coordinate domainExtent, String timeZone) { try { - if (id == null || id.isEmpty()) { + if ((id == null) || id.isEmpty()) { throw new IllegalArgumentException( "id may not be null or empty"); } @@ -304,8 +302,8 @@ public class GridLocation extends PersistableDataObject implements proj, // new Point( // - proj.getGridPointUR().x - proj.getGridPointLL().x + 1, - proj.getGridPointUR().y - proj.getGridPointLL().y + 1), + (proj.getGridPointUR().x - proj.getGridPointLL().x) + 1, + (proj.getGridPointUR().y - proj.getGridPointLL().y) + 1), new Coordinate(proj.getGridPointLL().x, proj.getGridPointLL().y), new Coordinate( // proj.getGridPointUR().x - proj.getGridPointLL().x, @@ -313,7 +311,7 @@ public class GridLocation extends PersistableDataObject implements "GMT"); } - public GridLocation(String id, GridCoverage coverage) { + public GridLocation(String id, ISpatialObject coverage) { this.siteId = id; this.crsObject = coverage.getCrs(); this.crsWKT = this.crsObject.toWKT(); @@ -869,7 +867,7 @@ public class GridLocation extends PersistableDataObject implements float[] data = (float[]) latLonGrid.getNumPy()[0]; for (int x = 0; x < gloc.getNx(); x++) { for (int y = 0; y < gloc.getNy(); y++) { - int idx = 2 * (x * gloc.ny + y); + int idx = 2 * ((x * gloc.ny) + y); float lon = data[idx]; float lat = data[idx + 1]; System.out.println(x + "," + y + " " + lon + ", " + lat); diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/request/GetPythonGridDataRequest.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/request/GetPythonGridDataRequest.java index 5498e562ba..70a0cb7184 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/request/GetPythonGridDataRequest.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/request/GetPythonGridDataRequest.java @@ -36,6 +36,8 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; * * * + * @deprecated use the Data Access Framework + * * @author dgilling * @version 1.0 */ @@ -43,6 +45,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; // TODO: REMOVE THIS CLASS AND ITS HANDLER if DiscreteDefinition/DiscreteKey and // WxDefinition/WeatherKey class hierarchy is ever fully-implemented in Python. +@Deprecated @DynamicSerialize public class GetPythonGridDataRequest extends GetGridDataRequest { diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/server/notify/GridUpdateNotification.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/server/notify/GridUpdateNotification.java index 466e0404a7..ce34d2d2e7 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/server/notify/GridUpdateNotification.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/server/notify/GridUpdateNotification.java @@ -44,6 +44,7 @@ import com.raytheon.uf.common.time.TimeRange; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 04/08/08 #875 bphillip Initial Creation + * 06/13/13 #2044 randerso JavaDoc cleanup * * * @@ -91,10 +92,12 @@ public class GridUpdateNotification extends GfeNotification implements * The parmID of the updated grid * @param replacementTimeRange * The time range of the update - * @param timeRanges - * The grid times that have been changed + * @param histories + * The histories for the updated grids * @param workstationID * The workstation ID of who changed the grid + * @param siteID + * The site ID */ public GridUpdateNotification(ParmID parmId, TimeRange replacementTimeRange, @@ -134,34 +137,62 @@ public class GridUpdateNotification extends GfeNotification implements } } + /** + * @return the parmId + */ public ParmID getParmId() { return parmId; } + /** + * @param parmId + * the parmId to set + */ public void setParmId(ParmID parmId) { this.parmId = parmId; } + /** + * @return the replacementTimeRange + */ public TimeRange getReplacementTimeRange() { return replacementTimeRange; } + /** + * @param replacementTimeRange + * the replacementTimeRange to set + */ public void setReplacementTimeRange(TimeRange replacementTimeRange) { this.replacementTimeRange = replacementTimeRange; } + /** + * @return the histories + */ public Map> getHistories() { return histories; } + /** + * @param histories + * the histories to set + */ public void setHistories(Map> histories) { this.histories = histories; } + /** + * @return the workstationID + */ public WsId getWorkstationID() { return workstationID; } + /** + * @param workstationID + * the workstationID to set + */ public void setWorkstationID(WsId workstationID) { this.workstationID = workstationID; } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/util/GfeUtil.java b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/util/GfeUtil.java index 41b218148b..2a42ebcc99 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/util/GfeUtil.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.gfe/src/com/raytheon/uf/common/dataplugin/gfe/util/GfeUtil.java @@ -65,6 +65,8 @@ import com.vividsolutions.jts.operation.polygonize.Polygonizer; * 04/08/08 #875 bphillip Initial Creation * 10/10/12 #1260 randerso Removed transformGridCoverage in * favor of new GridLocation constructor + * 06/24/13 #2044 randerso Changed format of hdf5 group to include + * minutes for satellite data * * * @@ -83,7 +85,7 @@ public class GfeUtil { private static final ThreadLocal groupDateFormatter = new ThreadLocal() { @Override protected SimpleDateFormat initialValue() { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmm"); sdf.setTimeZone(TimeZone.getTimeZone("GMT")); return sdf; } diff --git a/edexOsgi/com.raytheon.uf.tools.gfesuite/cli/getNotify.py b/edexOsgi/com.raytheon.uf.tools.gfesuite/cli/getNotify.py index a98e9df0c4..747934d8a3 100644 --- a/edexOsgi/com.raytheon.uf.tools.gfesuite/cli/getNotify.py +++ b/edexOsgi/com.raytheon.uf.tools.gfesuite/cli/getNotify.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python ## # This software was developed and / or modified by Raytheon Company, # pursuant to Contract DG133W-05-CQ-1067 with the US Government. @@ -28,6 +29,7 @@ # Date Ticket# Engineer Description # ------------ ---------- ----------- -------------------------- # 11/18/10 njensen Initial Creation. +# 06/13/13 #2044 randerso Fixed to use correct python # # #