diff --git a/deltaScripts/13.3.1/addRouteToSubscriptionSlots.sh b/deltaScripts/13.3.1/addRouteToSubscriptionSlots.sh new file mode 100644 index 0000000000..bb39119846 --- /dev/null +++ b/deltaScripts/13.3.1/addRouteToSubscriptionSlots.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +SQL_SCRIPT="addRouteToSubscriptionSlots.sql" + +# ensure that the sql script is present +if [ ! -f ${SQL_SCRIPT} ]; then + echo "ERROR: the required sql script - ${SQL_SCRIPT} was not found." + echo "FATAL: the update has failed!" + exit 1 +fi + +echo "INFO: update started" + +# run the update +/awips2/psql/bin/psql -U awips -d ebxml -f ${SQL_SCRIPT} +if [ $? -ne 0 ]; then + echo "FATAL: the update has failed!" + exit 1 +fi + +echo "INFO: the update has completed successfully!" + +exit 0 diff --git a/deltaScripts/13.3.1/addRouteToSubscriptionSlots.sql b/deltaScripts/13.3.1/addRouteToSubscriptionSlots.sql new file mode 100644 index 0000000000..f45e038426 --- /dev/null +++ b/deltaScripts/13.3.1/addRouteToSubscriptionSlots.sql @@ -0,0 +1,72 @@ +/** + * 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. + **/ +\set ON_ERROR_STOP 1 +\connect ebxml; + +-- Create a function that will load plpgsql +CREATE OR REPLACE FUNCTION make_plpgsql() + RETURNS VOID + LANGUAGE SQL + AS $$ + CREATE LANGUAGE plpgsql; +$$; + +-- Load plpgsql if it is not already loaded +SELECT + CASE + WHEN EXISTS( + SELECT 1 + FROM pg_catalog.pg_language + WHERE lanname='plpgsql' + ) + THEN NULL + ELSE make_plpgsql() END; + +-- The function to add a route slot to subscriptions +CREATE OR REPLACE FUNCTION addRouteSlot() RETURNS void AS $$ + DECLARE + registryobject_record RECORD; + value_key INTEGER; + slot_key INTEGER; + registryobjectslot_key INTEGER; + + BEGIN + -- Find all subscription registry objects + FOR registryobject_record IN SELECT id from registryobject where objecttype like '%Subscription' LOOP + -- Create the value for the slot + SELECT INTO value_key nextval('hibernate_sequence'); + INSERT INTO value (dtype, key, stringvalue) VALUES ('StringValueType', value_key, 'OPSNET'); + -- Create the slot entry itself + SELECT INTO slot_key nextval('hibernate_sequence'); + INSERT INTO slot (key, name, slotvalue_key) VALUES (slot_key, 'route', value_key); + -- Create the registryobject_slot entry + SELECT INTO registryobjectslot_key nextval('hibernate_sequence'); + INSERT INTO registryobject_slot (registryobject_id, child_slot_key) VALUES (registryobject_record.id, slot_key); + END LOOP; + + END; +$$ LANGUAGE plpgsql; + +-- Add the route slots to subscriptions +SELECT addRouteSlot(); + +-- Drop functions +DROP FUNCTION make_plpgsql(); +DROP FUNCTION addRouteSlot(); \ No newline at end of file diff --git a/edexOsgi/build.edex/esb/conf/modes.xml b/edexOsgi/build.edex/esb/conf/modes.xml index b5bb35b5d0..f0cb952e82 100644 --- a/edexOsgi/build.edex/esb/conf/modes.xml +++ b/edexOsgi/build.edex/esb/conf/modes.xml @@ -187,14 +187,21 @@ ebxml.*\.xml statsTemplate dataDeliveryTemplate + .*datadelivery-ncf.* - registry + ebxml.*\.xml + statsTemplate + dataDeliveryTemplate + .*datadelivery-wfo.* - registry + ebxml.*\.xml + statsTemplate + dataDeliveryTemplate + .*datadelivery-ncf.* harvester-* crawler-* diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/Subscription.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/Subscription.java index e9ef46fda4..ecf53348a0 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/Subscription.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/Subscription.java @@ -54,6 +54,7 @@ import com.raytheon.uf.common.time.util.TimeUtil; * Dec 12, 2012 1433 bgonzale Refactored Subscription copy ctor into two ctors. * Jan 03, 2013 1441 djohnson Default to no group. * Jan 25, 2013 1528 djohnson Subscription priority is now an enum. + * Feb 20, 2013 1543 djohnson Route is now a slot. * * * @@ -151,6 +152,9 @@ public class Subscription implements ISerializableObject, Serializable { /** Owner slot */ public static final String OWNER_SLOT = "owner"; + /** Route slot */ + public static final String ROUTE_SLOT = "route"; + /** * Constructor. */ @@ -329,6 +333,7 @@ public class Subscription implements ISerializableObject, Serializable { @XmlAttribute @DynamicSerializeElement + @SlotAttribute(Subscription.ROUTE_SLOT) private Network route = Network.OPSNET; @XmlAttribute diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/ebxml/SubscriptionFilterableQuery.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/ebxml/SubscriptionFilterableQuery.java index 2a2572e240..e664a709fe 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/ebxml/SubscriptionFilterableQuery.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/ebxml/SubscriptionFilterableQuery.java @@ -1,11 +1,14 @@ package com.raytheon.uf.common.datadelivery.registry.ebxml; +import java.util.ArrayList; import java.util.Calendar; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; +import com.raytheon.uf.common.datadelivery.registry.Network; +import com.raytheon.uf.common.datadelivery.registry.Subscription; import com.raytheon.uf.common.registry.ebxml.AdhocRegistryQuery; import com.raytheon.uf.common.registry.ebxml.BooleanAttribute; import com.raytheon.uf.common.registry.ebxml.CalendarAttribute; @@ -29,6 +32,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; * Aug 02, 2012 955 djohnson Add generics and results retrieval to registry queries. * Oct 03, 2012 1241 djohnson Move query parameters in from SubscriptionQuery. * Oct 10, 2012 0726 djohnson Add {@link #setActive(boolean)}. + * Feb 20, 2013 1543 djohnson Add ability to filter on routes. * * * @@ -158,4 +162,18 @@ public abstract class SubscriptionFilterableQuery extends public void setProviderNames(List providerNames) { setAttribute("provider", new StringAttribute(providerNames)); } + + /** + * Set the routes to match. + * + * @param routes + * the routes + */ + public void setRoutes(List routes) { + List enumValues = new ArrayList(routes.size()); + for (Network route : routes) { + enumValues.add(route.toString()); + } + setAttribute(Subscription.ROUTE_SLOT, new StringAttribute(enumValues)); + } } diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/handlers/BaseSubscriptionHandler.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/handlers/BaseSubscriptionHandler.java index 1976a993fa..20c556b133 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/handlers/BaseSubscriptionHandler.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/handlers/BaseSubscriptionHandler.java @@ -19,10 +19,12 @@ **/ package com.raytheon.uf.common.datadelivery.registry.handlers; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Subscription; import com.raytheon.uf.common.datadelivery.registry.ebxml.SubscriptionDataSetNameQuery; import com.raytheon.uf.common.datadelivery.registry.ebxml.SubscriptionFilterableQuery; @@ -43,6 +45,7 @@ import com.raytheon.uf.common.registry.handler.RegistryHandlerException; * Sep 18, 2012 1169 djohnson Initial creation * Oct 03, 2012 1241 djohnson More query methods. * Oct 10, 2012 0726 djohnson Add {@link #getActive()}. + * Feb 20, 2013 1543 djohnson Add ability to filter on routes. * * * @@ -155,4 +158,32 @@ abstract class BaseSubscriptionHandler getActiveForRoute(Network route) + throws RegistryHandlerException { + return getActiveForRoutes(route); + } + + /** + * {@inheritDoc} + */ + @Override + public List getActiveForRoutes(Network... routes) + throws RegistryHandlerException { + SubscriptionFilterableQuery query = getQuery(); + query.setActive(true); + query.setRoutes(Arrays.asList(routes)); + + RegistryQueryResponse response = RegistryManager + .getRegistyObjects(query); + + checkResponse(response, "getActiveForRoutes"); + + return response.getResults(); + } + } diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/handlers/IBaseSubscriptionHandler.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/handlers/IBaseSubscriptionHandler.java index e814eea883..7eea38f166 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/handlers/IBaseSubscriptionHandler.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/handlers/IBaseSubscriptionHandler.java @@ -22,6 +22,7 @@ package com.raytheon.uf.common.datadelivery.registry.handlers; import java.util.List; import java.util.Set; +import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Subscription; import com.raytheon.uf.common.registry.handler.IRegistryObjectHandler; import com.raytheon.uf.common.registry.handler.RegistryHandlerException; @@ -39,6 +40,7 @@ import com.raytheon.uf.common.registry.handler.RegistryHandlerException; * Sep 18, 2012 1169 djohnson Initial creation * Oct 03, 2012 1241 djohnson More query methods. * Oct 10, 2012 0726 djohnson Add {@link #getActive()}. + * Feb 20, 2013 1543 djohnson Add ability to filter on routes. * * * @@ -110,4 +112,27 @@ public interface IBaseSubscriptionHandler extends * on error */ List getActive() throws RegistryHandlerException; + + /** + * Retrieve all active subscriptions for the specified route. + * + * @param route + * the route + * @return the list of subscriptions meeting the criteria + * @throws RegistryHandlerException + * on error + */ + List getActiveForRoute(Network route) throws RegistryHandlerException; + + /** + * Retrieve all active subscriptions for the specified route. + * + * @param routes + * the routes + * @return the list of subscriptions meeting the criteria + * @throws RegistryHandlerException + * on error + */ + List getActiveForRoutes(Network... routes) + throws RegistryHandlerException; } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-daos.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-daos.xml index e22222482a..f6a1106276 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-daos.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-daos.xml @@ -1,9 +1,7 @@ + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"> @@ -14,12 +12,12 @@ class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.BandwidthSubscriptionDao"> - + - + diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-edex-impl.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-edex-impl.xml index b8cc4ccd8d..81fec14335 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-edex-impl.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-edex-impl.xml @@ -1,6 +1,5 @@ @@ -12,11 +11,26 @@ - + + - + + + + + + + + + + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-inmemory-impl.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-inmemory-impl.xml index cb688ab59c..d3a4e0c58b 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-inmemory-impl.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-inmemory-impl.xml @@ -1,19 +1,18 @@ + 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-2.0.xsd"> - - + + - + diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-ncf-edex-impl.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-ncf-edex-impl.xml new file mode 100644 index 0000000000..9ab74e7f79 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-ncf-edex-impl.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-ncf.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-ncf.xml new file mode 100644 index 0000000000..7da3dd0a94 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-ncf.xml @@ -0,0 +1,27 @@ + + + + SBN + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-wfo-edex-impl.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-wfo-edex-impl.xml new file mode 100644 index 0000000000..42567407b6 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-wfo-edex-impl.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-wfo.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-wfo.xml new file mode 100644 index 0000000000..380cffdd33 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery-wfo.xml @@ -0,0 +1,44 @@ + + + + OPSNET + SBN + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml index 3dcdf32da4..ad3a0fbf94 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-datadelivery.xml @@ -1,9 +1,7 @@ - + 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-2.0.xsd"> + @@ -14,27 +12,22 @@ - + - - - + + + - - @@ -43,7 +36,7 @@ - + - + - + - - + + @@ -72,11 +68,12 @@ factory-method="load"> - - + + - + @@ -84,19 +81,10 @@ - - - - - - - - - - + - + @@ -122,21 +110,15 @@ depends-on="bandwidthDbInit"> - - - - - - - + - - - - - + + + + + diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-graph-request.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-graph-request.xml index 1e51ab26cb..7189f0ad70 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-graph-request.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/bandwidth-graph-request.xml @@ -1,20 +1,19 @@ - + - - + + - + - - + + - + diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/thrift-bandwidth.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/thrift-bandwidth.xml index 9cac6ecdb0..d2aa4c70b0 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/thrift-bandwidth.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/res/spring/thrift-bandwidth.xml @@ -1,7 +1,6 @@ + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java index 739da3ba5c..d45d72508b 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java @@ -100,6 +100,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Feb 05, 2013 1580 mpduff EventBus refactor. * Feb 14, 2013 1595 djohnson Check with BandwidthUtil whether or not to reschedule subscriptions on update. * Feb 14, 2013 1596 djohnson Do not reschedule allocations when a subscription is removed. + * Feb 20, 2013 1543 djohnson Add try/catch blocks during the shutdown process. * * * @author dhladky @@ -1464,10 +1465,30 @@ abstract class BandwidthManager extends */ @VisibleForTesting void shutdown() { - EventBus.unregister(this); - BandwidthEventBus.unregister(this); - retrievalManager.shutdown(); - scheduler.shutdownNow(); + try { + EventBus.unregister(this); + } catch (Exception e) { + statusHandler.handle(Priority.WARN, + "Unable to unregister from the EventBus.", e); + } + try { + BandwidthEventBus.unregister(this); + } catch (Exception e) { + statusHandler.handle(Priority.WARN, + "Unable to unregister from the BandwidthEventBus.", e); + } + try { + retrievalManager.shutdown(); + } catch (Exception e) { + statusHandler.handle(Priority.WARN, + "Unable to shutdown the retrievalManager.", e); + } + try { + scheduler.shutdownNow(); + } catch (Exception e) { + statusHandler.handle(Priority.WARN, + "Unable to shutdown the scheduler.", e); + } } /** diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthContextFactory.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthContextFactory.java index bec37bf20d..85f0db5646 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthContextFactory.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthContextFactory.java @@ -32,7 +32,6 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDbInit; -import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthInitializer; import com.raytheon.uf.edex.datadelivery.bandwidth.interfaces.BandwidthInitializer; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; @@ -48,6 +47,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Oct 24, 2012 1286 djohnson Initial creation + * Feb 20, 2013 1543 djohnson Add IEdexBandwidthManagerCreator. * * * @@ -56,28 +56,63 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; */ class EdexBandwidthContextFactory implements BandwidthContextFactory { + /** + * Pluggable strategy for how to create the {@link BandwidthManager}. + * Intentionally package-private. + */ + static interface IEdexBandwidthManagerCreator { + + /** + * Get the bandwidth manaager. + * + * @param dbInit + * @param bandwidthDao + * @param retrievalManager + * @param bandwidthDaoUtil + * @return the bandwidth manager + */ + IBandwidthManager getBandwidthManager(IBandwidthDbInit dbInit, + IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, + BandwidthDaoUtil bandwidthDaoUtil); + } + private static BandwidthManager instance; - private IBandwidthDao bandwidthDao; + private final IBandwidthDao bandwidthDao; + + private final BandwidthInitializer bandwidthInitializer; + + private final IEdexBandwidthManagerCreator bandwidthManagerCreator; /** * Intentionally package-private constructor, as it is created from Spring * which is able to reflectively instantiate. * - * @param instance - * the {@link BandwidthManager} instance + * @param bandwidthDao + * @param findSubscriptionStrategy */ - EdexBandwidthContextFactory(IBandwidthDao bandwidthDao) { + EdexBandwidthContextFactory(IBandwidthDao bandwidthDao, + BandwidthInitializer bandwidthInitializer, + IEdexBandwidthManagerCreator bandwidthManagerCreator) { this.bandwidthDao = bandwidthDao; + this.bandwidthInitializer = bandwidthInitializer; + this.bandwidthManagerCreator = bandwidthManagerCreator; } /** - * Intentionally package-private constructor, as it is created from Spring - * which is able to reflectively instantiate. + * Intentionally private constructor, as it is created from Spring which is + * able to reflectively instantiate. It is only used to set the + * {@link BandwidthManager} instance. + * + * @param instance + * the {@link BandwidthManager} instance */ @SuppressWarnings("unused") private EdexBandwidthContextFactory(BandwidthManager instance) { EdexBandwidthContextFactory.instance = instance; + this.bandwidthDao = null; + this.bandwidthInitializer = null; + this.bandwidthManagerCreator = null; } /** @@ -128,7 +163,7 @@ class EdexBandwidthContextFactory implements BandwidthContextFactory { */ @Override public BandwidthInitializer getBandwidthInitializer() { - return new HibernateBandwidthInitializer(); + return bandwidthInitializer; } /** @@ -146,7 +181,7 @@ class EdexBandwidthContextFactory implements BandwidthContextFactory { public IBandwidthManager getBandwidthManager(IBandwidthDbInit dbInit, IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, BandwidthDaoUtil bandwidthDaoUtil) { - return new EdexBandwidthManager(dbInit, bandwidthDao, retrievalManager, - bandwidthDaoUtil); + return bandwidthManagerCreator.getBandwidthManager(dbInit, + bandwidthDao, retrievalManager, bandwidthDaoUtil); } } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthManager.java index 74d1957d8e..c8b53b85e2 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/InMemoryBandwidthManager.java @@ -42,6 +42,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Oct 30, 2012 1286 djohnson Initial creation + * Feb 20, 2013 1543 djohnson For now assume all in-memory bandwidth managers are WFOs. * * * @@ -53,9 +54,12 @@ class InMemoryBandwidthManager extends BandwidthManager { private static final IUFStatusHandler statusHandler = UFStatus .getHandler(InMemoryBandwidthManager.class); + // TODO DPJ: The NCF and WFO bandwidth managers probably each need an + // in-memory version public static final String[] IN_MEMORY_BANDWIDTH_MANAGER_FILES = new String[] { JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-inmemory-impl.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml") }; + JarUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml"), + JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-wfo.xml") }; /** * {@link BandwidthInitializer} which will make a copy of the current diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/NcfBandwidthManagerCreator.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/NcfBandwidthManagerCreator.java new file mode 100644 index 0000000000..b88e4e2e04 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/NcfBandwidthManagerCreator.java @@ -0,0 +1,89 @@ +/** + * 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.uf.edex.datadelivery.bandwidth; + +import com.raytheon.uf.common.util.JarUtil; +import com.raytheon.uf.edex.datadelivery.bandwidth.EdexBandwidthContextFactory.IEdexBandwidthManagerCreator; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; +import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; +import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; + +/** + * {@link IEdexBandwidthManagerCreator} for an NCF bandwidth manager. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 20, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +public class NcfBandwidthManagerCreator implements IEdexBandwidthManagerCreator { + + /** + * NCF {@link BandwidthManager} implementation. + */ + private static class NcfBandwidthManager extends BandwidthManager { + + private static final String[] NCF_BANDWIDTH_MANAGER_FILES = new String[] { + JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-edex-impl.xml"), + JarUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml"), + JarUtil.getResResourcePath("/spring/thrift-bandwidth.xml"), + JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-ncf.xml") }; + + /** + * Constructor. + * + * @param dbInit + * @param bandwidthDao + * @param retrievalManager + * @param bandwidthDaoUtil + */ + public NcfBandwidthManager(IBandwidthDbInit dbInit, + IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, + BandwidthDaoUtil bandwidthDaoUtil) { + super(dbInit, bandwidthDao, retrievalManager, bandwidthDaoUtil); + } + + @Override + protected String[] getSpringFilesForNewInstance() { + return NCF_BANDWIDTH_MANAGER_FILES; + } + } + + /** + * {@inheritDoc} + */ + @Override + public IBandwidthManager getBandwidthManager(IBandwidthDbInit dbInit, + IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, + BandwidthDaoUtil bandwidthDaoUtil) { + return new NcfBandwidthManager(dbInit, bandwidthDao, retrievalManager, + bandwidthDaoUtil); + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerCreator.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerCreator.java new file mode 100644 index 0000000000..e93aeac015 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerCreator.java @@ -0,0 +1,89 @@ +/** + * 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.uf.edex.datadelivery.bandwidth; + +import com.raytheon.uf.common.util.JarUtil; +import com.raytheon.uf.edex.datadelivery.bandwidth.EdexBandwidthContextFactory.IEdexBandwidthManagerCreator; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; +import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; +import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; + +/** + * {@link IEdexBandwidthManagerCreator} for a WFO bandwidth manager. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 20, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +public class WfoBandwidthManagerCreator implements IEdexBandwidthManagerCreator { + + /** + * WFO {@link BandwidthManager} implementation. + */ + private static class WfoBandwidthManager extends BandwidthManager { + + private static final String[] WFO_BANDWIDTH_MANAGER_FILES = new String[] { + JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-edex-impl.xml"), + JarUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml"), + JarUtil.getResResourcePath("/spring/thrift-bandwidth.xml"), + JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-wfo.xml") }; + + /** + * Constructor. + * + * @param dbInit + * @param bandwidthDao + * @param retrievalManager + * @param bandwidthDaoUtil + */ + public WfoBandwidthManager(IBandwidthDbInit dbInit, + IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, + BandwidthDaoUtil bandwidthDaoUtil) { + super(dbInit, bandwidthDao, retrievalManager, bandwidthDaoUtil); + } + + @Override + protected String[] getSpringFilesForNewInstance() { + return WFO_BANDWIDTH_MANAGER_FILES; + } + } + + /** + * {@inheritDoc} + */ + @Override + public IBandwidthManager getBandwidthManager(IBandwidthDbInit dbInit, + IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, + BandwidthDaoUtil bandwidthDaoUtil) { + return new WfoBandwidthManager(dbInit, bandwidthDao, retrievalManager, + bandwidthDaoUtil); + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/HibernateBandwidthInitializer.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/HibernateBandwidthInitializer.java index 4fa64bb142..2a854ad9b8 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/HibernateBandwidthInitializer.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/HibernateBandwidthInitializer.java @@ -4,13 +4,12 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; import org.hibernate.cfg.AnnotationConfiguration; import com.raytheon.uf.common.datadelivery.registry.Subscription; -import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers; import com.raytheon.uf.common.registry.ebxml.RegistryUtil; -import com.raytheon.uf.common.registry.handler.RegistryHandlerException; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -19,11 +18,38 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; import com.raytheon.uf.edex.datadelivery.bandwidth.interfaces.BandwidthInitializer; +/** + * + * {@link BandwidthInitializer} that uses Hibernate. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 20, 2013 1543       djohnson     Add SW history, separate how to find subscriptions.
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ public class HibernateBandwidthInitializer implements BandwidthInitializer { private static final IUFStatusHandler statusHandler = UFStatus .getHandler(HibernateBandwidthInitializer.class); + private final IFindSubscriptionsForScheduling findSubscriptionsStrategy; + + /** + * @param strategy + */ + public HibernateBandwidthInitializer( + IFindSubscriptionsForScheduling findSubscriptionsStrategy) { + this.findSubscriptionsStrategy = findSubscriptionsStrategy; + } + @Override public boolean init(IBandwidthManager instance, IBandwidthDbInit dbInit) { @@ -31,8 +57,8 @@ public class HibernateBandwidthInitializer implements BandwidthInitializer { // fulfilled. In the case were DD has been down for a while // BEFORE removing the tables... - // Empty the bandwidth tables (other than BandwidthDataSetUpdate) on each - // start and reload.. + // Empty the bandwidth tables (other than BandwidthDataSetUpdate) on + // each start and reload.. AnnotationConfiguration aConfig = new AnnotationConfiguration(); aConfig.addAnnotatedClass(com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription.class); aConfig.addAnnotatedClass(com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval.class); @@ -46,14 +72,14 @@ public class HibernateBandwidthInitializer implements BandwidthInitializer { return false; } - List activeSubscriptions = Collections.emptyList(); + Set activeSubscriptions = Collections.emptySet(); try { // Load active subscriptions - activeSubscriptions = DataDeliveryHandlers.getSubscriptionHandler() - .getActive(); - } catch (RegistryHandlerException e) { - statusHandler - .error("Failed to query for available active subscriptions"); + activeSubscriptions = findSubscriptionsStrategy + .findSubscriptionsToSchedule(); + } catch (Exception e) { + statusHandler.error( + "Failed to query for subscriptions to schedule", e); return false; } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/IFindSubscriptionsForScheduling.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/IFindSubscriptionsForScheduling.java new file mode 100644 index 0000000000..17e4f30411 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/IFindSubscriptionsForScheduling.java @@ -0,0 +1,51 @@ +/** + * 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.uf.edex.datadelivery.bandwidth.hibernate; + +import java.util.Set; + +import com.raytheon.uf.common.datadelivery.registry.Subscription; + +/** + * Finds subscriptions that should be scheduled for bandwidth management. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 18, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ + +public interface IFindSubscriptionsForScheduling { + /** + * Finds subscriptions that should be scheduled. + * + * @return subscriptions + * @throws Exception + */ + Set findSubscriptionsToSchedule() throws Exception; +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/FindActiveSubscriptionsForRoute.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/FindActiveSubscriptionsForRoute.java new file mode 100644 index 0000000000..90ad8eee01 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/util/FindActiveSubscriptionsForRoute.java @@ -0,0 +1,85 @@ +/** + * 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.uf.edex.datadelivery.bandwidth.util; + +import java.util.List; +import java.util.Set; + +import com.google.common.collect.Sets; +import com.raytheon.uf.common.datadelivery.registry.Network; +import com.raytheon.uf.common.datadelivery.registry.Subscription; +import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers; +import com.raytheon.uf.common.registry.handler.RegistryHandlerException; +import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.IFindSubscriptionsForScheduling; + +/** + * Returns active subscriptions in the registry. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 18, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ + +public class FindActiveSubscriptionsForRoute implements + IFindSubscriptionsForScheduling { + + private final Network[] routes; + + /** + * Find active subscriptions for a specific route. + * + * @param route + * the route + */ + public FindActiveSubscriptionsForRoute(Network route) { + this(new Network[] { route }); + } + + /** + * Find active subscriptions for specific routes. + * + * @param routes + * the routes + */ + public FindActiveSubscriptionsForRoute(Network... routes) { + this.routes = routes; + } + + /** + * {@inheritDoc} + */ + @Override + public Set findSubscriptionsToSchedule() + throws RegistryHandlerException { + final List activeForRoutes = DataDeliveryHandlers + .getSubscriptionHandler().getActiveForRoutes(routes); + return Sets.newHashSet(activeForRoutes); + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/utility/common_static/base/datadelivery/bandwidthmap.xml b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/utility/common_static/base/datadelivery/bandwidthmap.xml index 0760676f36..ca5e4b1254 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/utility/common_static/base/datadelivery/bandwidthmap.xml +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/utility/common_static/base/datadelivery/bandwidthmap.xml @@ -2,4 +2,6 @@ + + diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/AbstractBandwidthManagerIntTest.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/AbstractBandwidthManagerIntTest.java index 6db3d47b5c..8f1dd04136 100644 --- a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/AbstractBandwidthManagerIntTest.java +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/AbstractBandwidthManagerIntTest.java @@ -19,6 +19,11 @@ **/ package com.raytheon.uf.edex.datadelivery.bandwidth; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + import java.io.IOException; import java.util.Properties; @@ -39,6 +44,7 @@ import com.raytheon.uf.common.time.util.TimeUtilTest; import com.raytheon.uf.common.util.PropertiesUtil; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; +import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; /** @@ -55,6 +61,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Dec 11, 2012 1286 djohnson Use a synchronous event bus for tests. * Dec 11, 2012 1403 djohnson No longer valid to run without bandwidth management. * Feb 07, 2013 1543 djohnson Remove unnecessary test setup methods. + * Feb 20, 2013 1543 djohnson Delegate to sub-classes for which route to create subscriptions for. * * * @@ -118,7 +125,8 @@ public abstract class AbstractBandwidthManagerIntTest { bandwidthDao = IBandwidthDao.class .cast(context.getBean("bandwidthDao")); - fullBucketSize = retrievalManager.getPlan(Network.OPSNET) + fullBucketSize = retrievalManager + .getPlan(getRouteToUseForSubscription()) .getBucket(TimeUtil.currentTimeMillis()).getBucketSize(); halfBucketSize = fullBucketSize / 2; thirdBucketSizeInBytes = fullBucketSize / 3; @@ -186,6 +194,41 @@ public abstract class AbstractBandwidthManagerIntTest { .get(subscriptionSeed++); subscription.setDataSetSize(BandwidthUtil .convertBytesToKilobytes(bytes)); + subscription.setRoute(getRouteToUseForSubscription()); + return subscription; } + + /** + * Retrieve the {@link Network} that subscriptions should be created for. + * + * @return the {@link Network} + */ + protected abstract Network getRouteToUseForSubscription(); + + /** + * Verify the bandwidth manager has a retrieval plan configured for the + * specified route. + * + * @param route + */ + protected void verifyRetrievalPlanExistsForRoute(Network route) { + final RetrievalPlan retrievalPlan = EdexBandwidthContextFactory + .getInstance().retrievalManager.getPlan(route); + + assertThat(retrievalPlan, is(notNullValue(RetrievalPlan.class))); + } + + /** + * Verify the bandwidth manager does not have a retrieval plan configured + * for the specified route. + * + * @param route + */ + protected void verifyRetrievalPlanDoesNotExistForRoute(Network route) { + final RetrievalPlan retrievalPlan = EdexBandwidthContextFactory + .getInstance().retrievalManager.getPlan(route); + + assertThat(retrievalPlan, is(nullValue(RetrievalPlan.class))); + } } diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManagerIntTest.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManagerIntTest.java index 33b92dfc76..3d8a5912bf 100644 --- a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManagerIntTest.java +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManagerIntTest.java @@ -110,8 +110,10 @@ import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalManagerNotifyEvent; @ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML, SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML, SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_WFO_XML, SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_XML, - SpringFiles.BANDWIDTH_DATADELIVERY_XML }) + SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_WFO_XML }) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class BandwidthManagerIntTest extends AbstractBandwidthManagerIntTest { @@ -993,4 +995,12 @@ public class BandwidthManagerIntTest extends AbstractBandwidthManagerIntTest { return allocations; } + /** + * {@inheritDoc} + */ + @Override + protected Network getRouteToUseForSubscription() { + return Network.OPSNET; + } + } diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthServiceIntTest.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthServiceIntTest.java index 038212274c..7016cf217c 100644 --- a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthServiceIntTest.java +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthServiceIntTest.java @@ -75,6 +75,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Oct 22, 2012 1286 djohnson Initial creation * Nov 20, 2012 1286 djohnson Add tests for proposeSchedule methods. * Dec 06, 2012 1397 djohnson Add tests for getting bandwidth graph data. + * Feb 20, 2013 1543 djohnson Use WFO bandwidth manager. * * * @@ -85,8 +86,10 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; @ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML, SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML, SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_WFO_XML, SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_XML, - SpringFiles.BANDWIDTH_DATADELIVERY_XML }) + SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_WFO_XML }) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class BandwidthServiceIntTest extends AbstractBandwidthManagerIntTest { @@ -633,4 +636,12 @@ public class BandwidthServiceIntTest extends AbstractBandwidthManagerIntTest { subscription.getName(), unscheduledSubscriptions.iterator() .next()); } + + /** + * {@inheritDoc} + */ + @Override + protected Network getRouteToUseForSubscription() { + return Network.OPSNET; + } } diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestBandwidthContextFactory.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestBandwidthContextFactory.java index ce296f4d66..2a04eeb644 100644 --- a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestBandwidthContextFactory.java +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestBandwidthContextFactory.java @@ -24,9 +24,6 @@ import java.io.File; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthContextFactory; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; -import com.raytheon.uf.edex.datadelivery.bandwidth.interfaces.BandwidthInitializer; -import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; -import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; /** * The {@link BandwidthContextFactory} implementation for integration tests. @@ -38,6 +35,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Oct 24, 2012 1286 djohnson Initial creation + * Feb 20, 2013 1543 djohnson Pass additional super-class constructor arguments. * * * @@ -53,8 +51,10 @@ public class IntegrationTestBandwidthContextFactory extends * @param bandwidthDao * the bandwidthDao */ - IntegrationTestBandwidthContextFactory(IBandwidthDao bandwidthDao) { - super(bandwidthDao); + IntegrationTestBandwidthContextFactory(IBandwidthDao bandwidthDao, + IEdexBandwidthManagerCreator bandwidthManagerCreator) { + super(bandwidthDao, new IntegrationTestBandwidthInitializer(), + bandwidthManagerCreator); } /** @@ -65,32 +65,14 @@ public class IntegrationTestBandwidthContextFactory extends return new IntegrationTestDbInit(); } - /** - * {@inheritDoc} - */ - @Override - public BandwidthInitializer getBandwidthInitializer() { - return new IntegrationTestBandwidthInitializer(); - } - - /** - * {@inheritDoc} - */ - @Override - public IBandwidthManager getBandwidthManager(IBandwidthDbInit dbInit, - IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, - BandwidthDaoUtil bandwidthDaoUtil) { - return new IntegrationTestBandwidthManager(dbInit, bandwidthDao, - retrievalManager, bandwidthDaoUtil); - } - /** * Get the integration test bandwidth map config file. * * @return the file */ public static File getIntegrationTestBandwidthMapConfigFile() { - return new IntegrationTestBandwidthContextFactory((IBandwidthDao) null) + return new IntegrationTestBandwidthContextFactory((IBandwidthDao) null, + (IEdexBandwidthManagerCreator) null) .getBandwidthMapConfigFile(); } } diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestNcfBandwidthManager.java similarity index 69% rename from edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java rename to tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestNcfBandwidthManager.java index d6626989c7..e2f291a8a9 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestNcfBandwidthManager.java @@ -19,15 +19,16 @@ **/ package com.raytheon.uf.edex.datadelivery.bandwidth; -import com.raytheon.uf.common.util.JarUtil; +import com.raytheon.uf.common.util.SpringFiles; +import com.raytheon.uf.common.util.TestUtil; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; /** - * {@link IBandwidthManager} implementation that runs in EDEX. Intentionally - * package-private to hide implementation details. + * An NCF {@link IBandwidthManager} that runs as an integration test, outside of + * the EDEX container. * *
  * 
@@ -35,7 +36,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil;
  * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * Oct 30, 2012 1286       djohnson     Initial creation
+ * Feb 18, 2013 1543       djohnson     Initial creation
  * 
  * 
* @@ -43,12 +44,12 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; * @version 1.0 */ -class EdexBandwidthManager extends BandwidthManager { +public class IntegrationTestNcfBandwidthManager extends BandwidthManager { - private static final String[] EDEX_BANDWIDTH_MANAGER_FILES = new String[] { - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery-edex-impl.xml"), - JarUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml"), - JarUtil.getResResourcePath("/spring/thrift-bandwidth.xml") }; + static final String[] INTEGRATION_TEST_SPRING_FILES = new String[] { + "/bandwidth/bandwidth-datadelivery-integrationtest-impl.xml", + TestUtil.getResResourcePath(SpringFiles.BANDWIDTH_DATADELIVERY_XML), + TestUtil.getResResourcePath(SpringFiles.BANDWIDTH_DATADELIVERY_NCF_XML) }; /** * Constructor. @@ -58,14 +59,17 @@ class EdexBandwidthManager extends BandwidthManager { * @param retrievalManager * @param bandwidthDaoUtil */ - public EdexBandwidthManager(IBandwidthDbInit dbInit, + public IntegrationTestNcfBandwidthManager(IBandwidthDbInit dbInit, IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, BandwidthDaoUtil bandwidthDaoUtil) { super(dbInit, bandwidthDao, retrievalManager, bandwidthDaoUtil); } + /** + * {@inheritDoc} + */ @Override protected String[] getSpringFilesForNewInstance() { - return EDEX_BANDWIDTH_MANAGER_FILES; + return INTEGRATION_TEST_SPRING_FILES; } } diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestNcfBandwidthManagerCreator.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestNcfBandwidthManagerCreator.java new file mode 100644 index 0000000000..33865f06c1 --- /dev/null +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestNcfBandwidthManagerCreator.java @@ -0,0 +1,57 @@ +/** + * 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.uf.edex.datadelivery.bandwidth; + +import com.raytheon.uf.edex.datadelivery.bandwidth.EdexBandwidthContextFactory.IEdexBandwidthManagerCreator; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; +import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; +import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; + +/** + * Creates {@link IntegrationTestNcfBandwidthManager} instances. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 20, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +public class IntegrationTestNcfBandwidthManagerCreator implements + IEdexBandwidthManagerCreator { + + /** + * {@inheritDoc} + */ + @Override + public IBandwidthManager getBandwidthManager(IBandwidthDbInit dbInit, + IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, + BandwidthDaoUtil bandwidthDaoUtil) { + return new IntegrationTestNcfBandwidthManager(dbInit, bandwidthDao, + retrievalManager, bandwidthDaoUtil); + } +} diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestBandwidthManager.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestWfoBandwidthManager.java similarity index 81% rename from tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestBandwidthManager.java rename to tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestWfoBandwidthManager.java index 04eed298a9..ceaf4f248b 100644 --- a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestBandwidthManager.java +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestWfoBandwidthManager.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.edex.datadelivery.bandwidth; +import com.raytheon.uf.common.util.SpringFiles; import com.raytheon.uf.common.util.TestUtil; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao; import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; @@ -26,8 +27,8 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager; import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil; /** - * An {@link IBandwidthManager} that runs as an integration test, outside of the - * EDEX container. + * A WFO {@link IBandwidthManager} that runs as an integration test, outside of + * the EDEX container. * *
  * 
@@ -43,11 +44,12 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil;
  * @version 1.0
  */
 
-public class IntegrationTestBandwidthManager extends BandwidthManager {
+public class IntegrationTestWfoBandwidthManager extends BandwidthManager {
 
     static final String[] INTEGRATION_TEST_SPRING_FILES = new String[] {
             "/bandwidth/bandwidth-datadelivery-integrationtest-impl.xml",
-        TestUtil.getResResourcePath("/spring/bandwidth-datadelivery.xml") };
+            TestUtil.getResResourcePath(SpringFiles.BANDWIDTH_DATADELIVERY_XML),
+            TestUtil.getResResourcePath(SpringFiles.BANDWIDTH_DATADELIVERY_WFO_XML) };
 
     /**
      * Constructor.
@@ -57,7 +59,7 @@ public class IntegrationTestBandwidthManager extends BandwidthManager {
      * @param retrievalManager
      * @param bandwidthDaoUtil
      */
-    public IntegrationTestBandwidthManager(IBandwidthDbInit dbInit,
+    public IntegrationTestWfoBandwidthManager(IBandwidthDbInit dbInit,
             IBandwidthDao bandwidthDao, RetrievalManager retrievalManager,
             BandwidthDaoUtil bandwidthDaoUtil) {
         super(dbInit, bandwidthDao, retrievalManager, bandwidthDaoUtil);
diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestWfoBandwidthManagerCreator.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestWfoBandwidthManagerCreator.java
new file mode 100644
index 0000000000..f7f2833095
--- /dev/null
+++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/IntegrationTestWfoBandwidthManagerCreator.java
@@ -0,0 +1,57 @@
+/**
+ * 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.uf.edex.datadelivery.bandwidth;
+
+import com.raytheon.uf.edex.datadelivery.bandwidth.EdexBandwidthContextFactory.IEdexBandwidthManagerCreator;
+import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao;
+import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit;
+import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager;
+import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil;
+
+/**
+ * Creates {@link IntegrationTestWfoBandwidthManager} instances.
+ * 
+ * 
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 20, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +public class IntegrationTestWfoBandwidthManagerCreator implements + IEdexBandwidthManagerCreator { + + /** + * {@inheritDoc} + */ + @Override + public IBandwidthManager getBandwidthManager(IBandwidthDbInit dbInit, + IBandwidthDao bandwidthDao, RetrievalManager retrievalManager, + BandwidthDaoUtil bandwidthDaoUtil) { + return new IntegrationTestWfoBandwidthManager(dbInit, bandwidthDao, + retrievalManager, bandwidthDaoUtil); + } +} diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/NcfBandwidthManagerIntTest.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/NcfBandwidthManagerIntTest.java new file mode 100644 index 0000000000..2a60c01640 --- /dev/null +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/NcfBandwidthManagerIntTest.java @@ -0,0 +1,118 @@ +/** + * 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.uf.edex.datadelivery.bandwidth; + +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.ClassMode; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest; +import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest.RequestType; +import com.raytheon.uf.common.datadelivery.registry.Network; +import com.raytheon.uf.common.datadelivery.registry.Subscription; +import com.raytheon.uf.common.util.SpringFiles; +import com.raytheon.uf.edex.database.dao.DatabaseUtil; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval; +import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus; + +/** + * Test an NCF {@link BandwidthManager}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 19, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML, + SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_NCF_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_NCF_XML }) +@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +public class NcfBandwidthManagerIntTest extends AbstractBandwidthManagerIntTest { + + @Test + public void testSchedulesSbnSubscriptionForRetrieval() { + Subscription subscription = createSubscriptionThatFillsAThirdOfABucket(); + + bandwidthManager.schedule(subscription); + + final List subRetrievals = bandwidthDao + .getSubscriptionRetrievals(subscription.getProvider(), + subscription.getDataSetName()); + assertThat(subRetrievals, is(not(empty()))); + + for (SubscriptionRetrieval subRetrieval : subRetrievals) { + assertThat(subRetrieval.getStatus(), is(RetrievalStatus.SCHEDULED)); + } + } + + @Test + public void testDoesNotScheduleOpsnetSubscriptionForRetrieval() { + Subscription subscription = createSubscriptionThatFillsAThirdOfABucket(); + subscription.setRoute(Network.OPSNET); + + bandwidthManager.schedule(subscription); + + final List subRetrievals = bandwidthDao + .getSubscriptionRetrievals(subscription.getProvider(), + subscription.getDataSetName()); + assertThat(subRetrievals, is(empty())); + } + + @Test + public void testReinitializeUsesCorrectSpringFiles() throws Exception { + final IBandwidthRequest request = new IBandwidthRequest(); + request.setRequestType(RequestType.REINITIALIZE); + bandwidthManager.handleRequest(request); + + verifyRetrievalPlanDoesNotExistForRoute(Network.OPSNET); + } + + /** + * {@inheritDoc} + */ + @Override + protected Network getRouteToUseForSubscription() { + return Network.SBN; + } + +} diff --git a/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerIntTest.java b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerIntTest.java new file mode 100644 index 0000000000..4fe349865d --- /dev/null +++ b/tests/integration/com/raytheon/uf/edex/datadelivery/bandwidth/WfoBandwidthManagerIntTest.java @@ -0,0 +1,122 @@ +/** + * 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.uf.edex.datadelivery.bandwidth; + +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.ClassMode; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest; +import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest.RequestType; +import com.raytheon.uf.common.datadelivery.registry.Network; +import com.raytheon.uf.common.datadelivery.registry.Subscription; +import com.raytheon.uf.common.util.SpringFiles; +import com.raytheon.uf.edex.database.dao.DatabaseUtil; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval; +import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus; + +/** + * Test a WFO {@link BandwidthManager}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 19, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { DatabaseUtil.UNIT_TEST_DB_BEANS_XML, + SpringFiles.RETRIEVAL_DATADELIVERY_DAOS_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_DAOS_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_WFO_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_XML, + SpringFiles.BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_WFO_XML }) +@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) +public class WfoBandwidthManagerIntTest extends AbstractBandwidthManagerIntTest { + + @Test + public void testSchedulesSbnSubscriptionForRetrieval() { + Subscription subscription = createSubscriptionThatFillsAThirdOfABucket(); + subscription.setRoute(Network.SBN); + + bandwidthManager.schedule(subscription); + + final List subRetrievals = bandwidthDao + .getSubscriptionRetrievals(subscription.getProvider(), + subscription.getDataSetName()); + assertThat(subRetrievals, is(not(empty()))); + + for (SubscriptionRetrieval subRetrieval : subRetrievals) { + assertThat(subRetrieval.getStatus(), is(RetrievalStatus.SCHEDULED)); + } + } + + @Test + public void testSchedulesOpsnetSubscriptionForRetrieval() { + Subscription subscription = createSubscriptionThatFillsAThirdOfABucket(); + + bandwidthManager.schedule(subscription); + + final List subRetrievals = bandwidthDao + .getSubscriptionRetrievals(subscription.getProvider(), + subscription.getDataSetName()); + assertThat(subRetrievals, is(not(empty()))); + + for (SubscriptionRetrieval subRetrieval : subRetrievals) { + assertThat(subRetrieval.getStatus(), is(RetrievalStatus.SCHEDULED)); + } + } + + @Test + public void testReinitializeUsesCorrectSpringFiles() throws Exception { + final IBandwidthRequest request = new IBandwidthRequest(); + request.setRequestType(RequestType.REINITIALIZE); + bandwidthManager.handleRequest(request); + + verifyRetrievalPlanExistsForRoute(Network.OPSNET); + } + + /** + * {@inheritDoc} + */ + @Override + protected Network getRouteToUseForSubscription() { + return Network.OPSNET; + } + +} diff --git a/tests/resources/bandwidth/bandwidth-datadelivery-integrationtest-impl.xml b/tests/resources/bandwidth/bandwidth-datadelivery-integrationtest-impl.xml index 60de63072b..2400beae35 100644 --- a/tests/resources/bandwidth/bandwidth-datadelivery-integrationtest-impl.xml +++ b/tests/resources/bandwidth/bandwidth-datadelivery-integrationtest-impl.xml @@ -1,12 +1,11 @@ + 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-2.0.xsd"> + + + + + \ No newline at end of file diff --git a/tests/resources/bandwidth/bandwidth-datadelivery-integrationtest-wfo-impl.xml b/tests/resources/bandwidth/bandwidth-datadelivery-integrationtest-wfo-impl.xml new file mode 100644 index 0000000000..8426002260 --- /dev/null +++ b/tests/resources/bandwidth/bandwidth-datadelivery-integrationtest-wfo-impl.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/tests/unit/com/raytheon/uf/common/datadelivery/registry/handlers/BaseMemorySubscriptionHandler.java b/tests/unit/com/raytheon/uf/common/datadelivery/registry/handlers/BaseMemorySubscriptionHandler.java index 31823e9ad2..d0625d5b96 100644 --- a/tests/unit/com/raytheon/uf/common/datadelivery/registry/handlers/BaseMemorySubscriptionHandler.java +++ b/tests/unit/com/raytheon/uf/common/datadelivery/registry/handlers/BaseMemorySubscriptionHandler.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Subscription; import com.raytheon.uf.common.registry.handler.RegistryHandlerException; @@ -37,6 +38,7 @@ import com.raytheon.uf.common.registry.handler.RegistryHandlerException; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Oct 17, 2012 0726 djohnson Initial creation + * Feb 20, 2013 1543 djohnson Implement route filtering. * *
* @@ -138,4 +140,30 @@ public class BaseMemorySubscriptionHandler extends return retVal; } + + /** + * {@inheritDoc} + */ + @Override + public List getActiveForRoute(Network route) + throws RegistryHandlerException { + return getActiveForRoutes(new Network[] { route }); + } + + /** + * {@inheritDoc} + */ + @Override + public List getActiveForRoutes(Network... routes) + throws RegistryHandlerException { + List retVal = new ArrayList(); + for (T obj : getActive()) { + for (Network route : routes) { + if (route == obj.getRoute()) { + retVal.add(obj); + } + } + } + return retVal; + } } diff --git a/tests/unit/com/raytheon/uf/common/util/SpringFiles.java b/tests/unit/com/raytheon/uf/common/util/SpringFiles.java index a237f08fcb..3464bbe948 100644 --- a/tests/unit/com/raytheon/uf/common/util/SpringFiles.java +++ b/tests/unit/com/raytheon/uf/common/util/SpringFiles.java @@ -52,5 +52,13 @@ public class SpringFiles { public static final String BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_XML = "/bandwidth/bandwidth-datadelivery-integrationtest-impl.xml"; + public static final String BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_NCF_XML = "/bandwidth/bandwidth-datadelivery-integrationtest-ncf-impl.xml"; + + public static final String BANDWIDTH_DATADELIVERY_INTEGRATION_TEST_WFO_XML = "/bandwidth/bandwidth-datadelivery-integrationtest-wfo-impl.xml"; + public static final String BANDWIDTH_DATADELIVERY_XML = "/spring/bandwidth-datadelivery.xml"; -} + + public static final String BANDWIDTH_DATADELIVERY_NCF_XML = "/spring/bandwidth-datadelivery-ncf.xml"; + + public static final String BANDWIDTH_DATADELIVERY_WFO_XML = "/spring/bandwidth-datadelivery-wfo.xml"; +} \ No newline at end of file diff --git a/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/HibernateBandwidthInitializerTest.java b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/HibernateBandwidthInitializerTest.java new file mode 100644 index 0000000000..ac1cbba585 --- /dev/null +++ b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/hibernate/HibernateBandwidthInitializerTest.java @@ -0,0 +1,69 @@ +/** + * 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.uf.edex.datadelivery.bandwidth.hibernate; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Test; + +import com.google.common.collect.Sets; +import com.raytheon.uf.common.datadelivery.registry.Subscription; +import com.raytheon.uf.common.datadelivery.registry.SubscriptionFixture; +import com.raytheon.uf.edex.datadelivery.bandwidth.IBandwidthManager; +import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit; + +/** + * Test {@link HibernateBandwidthInitializer}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 18, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ +public class HibernateBandwidthInitializerTest { + + @Test + public void testSchedulesAllSubscriptionReturnedFromIFindSubscriptions() + throws Exception { + final Subscription subscription = SubscriptionFixture.INSTANCE.get(); + + IFindSubscriptionsForScheduling strategy = mock(IFindSubscriptionsForScheduling.class); + when(strategy.findSubscriptionsToSchedule()).thenReturn( + Sets.newHashSet(subscription)); + IBandwidthManager bandwidthManager = mock(IBandwidthManager.class); + IBandwidthDbInit dbInit = mock(IBandwidthDbInit.class); + + new HibernateBandwidthInitializer(strategy).init(bandwidthManager, + dbInit); + + verify(bandwidthManager).schedule(subscription); + } + +} diff --git a/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/util/FindActiveSubscriptionsForRouteTest.java b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/util/FindActiveSubscriptionsForRouteTest.java new file mode 100644 index 0000000000..7cfdc0f56d --- /dev/null +++ b/tests/unit/com/raytheon/uf/edex/datadelivery/bandwidth/util/FindActiveSubscriptionsForRouteTest.java @@ -0,0 +1,101 @@ +/** + * 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.uf.edex.datadelivery.bandwidth.util; + +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Set; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.raytheon.uf.common.datadelivery.registry.Network; +import com.raytheon.uf.common.datadelivery.registry.Subscription; +import com.raytheon.uf.common.datadelivery.registry.SubscriptionBuilder; +import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers; +import com.raytheon.uf.common.datadelivery.registry.handlers.ISubscriptionHandler; +import com.raytheon.uf.common.registry.handler.RegistryHandlerException; +import com.raytheon.uf.common.registry.handler.RegistryObjectHandlersUtil; + +/** + * Test {@link FindActiveSubscriptionsForRoute}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Feb 19, 2013 1543       djohnson     Initial creation
+ * 
+ * 
+ * + * @author djohnson + * @version 1.0 + */ + +public class FindActiveSubscriptionsForRouteTest { + + @BeforeClass + public static void classSetUp() throws RegistryHandlerException { + RegistryObjectHandlersUtil.initMemory(); + final ISubscriptionHandler subscriptionHandler = DataDeliveryHandlers + .getSubscriptionHandler(); + + // Two OPSNET subscriptions + final Subscription opsnetSub1 = new SubscriptionBuilder() + .withName("opsnetSub1").withRoute(Network.OPSNET).build(); + final Subscription opsnetSub2 = new Subscription(opsnetSub1, + "opsnetSub2"); + + // Two SBN subscriptions + final Subscription sbnSub1 = new SubscriptionBuilder() + .withName("sbnSub1").withRoute(Network.SBN).build(); + final Subscription sbnSub2 = new Subscription(sbnSub1, "sbnSub2"); + + // Store all subscriptions + for (Subscription sub : new Subscription[] { opsnetSub1, opsnetSub2, + sbnSub1, sbnSub2 }) { + subscriptionHandler.store(sub); + } + } + + @Test + public void findsSubscriptionForSingleRoute() + throws RegistryHandlerException { + final Set subscriptions = new FindActiveSubscriptionsForRoute( + Network.SBN).findSubscriptionsToSchedule(); + assertThat(subscriptions, hasSize(2)); + for (Subscription subscription : subscriptions) { + assertThat(subscription.getRoute(), is(Network.SBN)); + } + } + + @Test + public void findsSubscriptionsForMultipleRoutes() + throws RegistryHandlerException { + final Set subscriptions = new FindActiveSubscriptionsForRoute( + Network.OPSNET, Network.SBN).findSubscriptionsToSchedule(); + assertThat(subscriptions, hasSize(4)); + } + +} diff --git a/tests/utility/common_static/base/datadelivery/bandwidthmap.xml b/tests/utility/common_static/base/datadelivery/bandwidthmap.xml index 86b38937be..03122377a1 100644 --- a/tests/utility/common_static/base/datadelivery/bandwidthmap.xml +++ b/tests/utility/common_static/base/datadelivery/bandwidthmap.xml @@ -1,4 +1,5 @@ +