Merge "Issue #2106 Improve BandwidthManager performance - Use copy constructors - Separate BandwidthBucket handling into a DAO - Preparations to remove all in-memory object handling" into development
Former-commit-id: 1a45a8604e35d0b14caf8465905a806e79a2461d
This commit is contained in:
commit
59c1cd7a5e
50 changed files with 2678 additions and 479 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.raytheon.uf.common.datadelivery.registry;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -21,7 +22,8 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
|||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Mar 20, 2011 357 dhladky Initial creation
|
||||
* Mar 20, 2011 0357 dhladky Initial creation
|
||||
* Jun 24, 2013 2106 djohnson Implement serializable.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -32,7 +34,9 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
|||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.NONE)
|
||||
@DynamicSerialize
|
||||
public class Ensemble implements ISerializableObject {
|
||||
public class Ensemble implements ISerializableObject, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 5226308994976901382L;
|
||||
|
||||
/**
|
||||
* names of the various ensemble members
|
||||
|
|
|
@ -60,6 +60,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
|||
* May 21, 2013 2020 mpduff Rename UserSubscription to SiteSubscription.
|
||||
* Jun 12, 2013 2038 djohnson Set registryId from each constructor with arguments.
|
||||
* Jun 13, 2013 2095 djohnson Duplicate 13.5.1 change so bandwidth manager deletes subscriptions correctly.
|
||||
* Jun 24, 2013 2106 djohnson Add copy constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -137,7 +138,7 @@ public class SiteSubscription extends RecurringSubscription {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Subscription copy() {
|
||||
public SiteSubscription copy() {
|
||||
return new SiteSubscription(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* 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.common.util;
|
||||
|
||||
/**
|
||||
* Interface that denotes a class provides a copy method.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 18, 2013 2106 djohnson Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public interface IDeepCopyable<T> {
|
||||
/**
|
||||
* Creates a deep copy of the object.
|
||||
*
|
||||
* @return the copy
|
||||
*/
|
||||
T copy();
|
||||
}
|
|
@ -54,11 +54,12 @@ import com.raytheon.uf.edex.database.DataAccessLayerException;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 07, 2013 1543 djohnson Initial creation
|
||||
* Feb 07, 2013 1543 djohnson Initial creation
|
||||
* 3/18/2013 1802 bphillip Added additional database functions. Enforcing mandatory transaction propogation
|
||||
* 3/27/2013 1802 bphillip Changed transaction propagation of query methods
|
||||
* 4/9/2013 1802 bphillip Modified how arguments are passed in to query methods
|
||||
* May 1st, 2013 1967 njensen Fixed autoboxing for Eclipse 3.8
|
||||
* May 01, 2013 1967 njensen Fixed autoboxing for Eclipse 3.8
|
||||
* Jun 24, 2013 2106 djohnson Use IDENTIFIER generic for method signature.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -142,7 +143,7 @@ public abstract class SessionManagedDao<IDENTIFIER extends Serializable, ENTITY
|
|||
*/
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public ENTITY getById(Serializable id) {
|
||||
public ENTITY getById(IDENTIFIER id) {
|
||||
final Class<ENTITY> entityClass = getEntityClass();
|
||||
return entityClass.cast(template.get(entityClass, id));
|
||||
}
|
||||
|
|
|
@ -9,9 +9,11 @@
|
|||
|
||||
<bean id="SBNRetrievalPlan"
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan">
|
||||
<constructor-arg value="SBN" />
|
||||
<constructor-arg ref="BandwidthMap" />
|
||||
<constructor-arg ref="bandwidthDao" />
|
||||
<property name="network" value="SBN" />
|
||||
<property name="map" ref="BandwidthMap" />
|
||||
<property name="bandwidthDao" ref="bandwidthDao" />
|
||||
<property name="bucketsDao" ref="bandwidthBucketDao" />
|
||||
<property name="associator" ref="bandwidthBucketAllocationAssociator" />
|
||||
<property name="scheduler">
|
||||
<bean
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.PriorityRetrievalScheduler" />
|
||||
|
|
|
@ -30,4 +30,9 @@
|
|||
<property name="bandwidthDataSetUpdateDao" ref="bandwidthDataSetUpdateDao" />
|
||||
</bean>
|
||||
|
||||
<!-- TODO: Switch to use database bandwidth buckets
|
||||
<bean id="hibernateBandwidthBucketDao"
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.BandwidthBucketDao">
|
||||
<property name="sessionFactory" ref="metadataSessionFactory" />
|
||||
</bean> -->
|
||||
</beans>
|
|
@ -26,6 +26,11 @@
|
|||
class="com.raytheon.uf.edex.datadelivery.bandwidth.EdexBandwidthContextFactory">
|
||||
<!-- The bandwidth dao implementation -->
|
||||
<constructor-arg ref="hibernateBandwidthDao" />
|
||||
<!-- TODO: Switch to use database bandwidth buckets
|
||||
<constructor-arg ref="hibernateBandwidthBucketDao" /> -->
|
||||
<constructor-arg>
|
||||
<bean class="com.raytheon.uf.edex.datadelivery.bandwidth.InMemoryBandwidthBucketDao" />
|
||||
</constructor-arg>
|
||||
<!-- The bandwidth manager initializer -->
|
||||
<constructor-arg>
|
||||
<bean
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
|
||||
<bean id="OPSNETRetrievalPlan"
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan">
|
||||
<constructor-arg value="OPSNET" />
|
||||
<constructor-arg ref="BandwidthMap" />
|
||||
<constructor-arg ref="bandwidthDao" />
|
||||
<property name="network" value="OPSNET" />
|
||||
<property name="map" ref="BandwidthMap" />
|
||||
<property name="bandwidthDao" ref="bandwidthDao" />
|
||||
<property name="bucketsDao" ref="bandwidthBucketDao" />
|
||||
<property name="associator" ref="bandwidthBucketAllocationAssociator" />
|
||||
<property name="scheduler">
|
||||
<bean
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.PriorityRetrievalScheduler" />
|
||||
|
@ -23,9 +25,11 @@
|
|||
but the actual retrieval occurs at the NCF -->
|
||||
<bean id="SBNRetrievalPlan"
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan">
|
||||
<constructor-arg value="SBN" />
|
||||
<constructor-arg ref="BandwidthMap" />
|
||||
<constructor-arg ref="bandwidthDao" />
|
||||
<property name="network" value="SBN" />
|
||||
<property name="map" ref="BandwidthMap" />
|
||||
<property name="bandwidthDao" ref="bandwidthDao" />
|
||||
<property name="bucketsDao" ref="bandwidthBucketDao" />
|
||||
<property name="associator" ref="bandwidthBucketAllocationAssociator" />
|
||||
<property name="scheduler">
|
||||
<bean
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.PriorityRetrievalScheduler" />
|
||||
|
|
|
@ -17,6 +17,15 @@
|
|||
<bean id="bandwidthDao" factory-bean="bandwidthContextFactory"
|
||||
factory-method="getBandwidthDao" />
|
||||
|
||||
<bean id="bandwidthBucketDao" factory-bean="bandwidthContextFactory"
|
||||
factory-method="getBandwidthBucketDao" />
|
||||
|
||||
<!-- TODO: Move the associations between a bucket and its allocations into the database -->
|
||||
<bean id="bandwidthBucketAllocationAssociator" class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.InMemoryBandwidthBucketAllocationAssociator">
|
||||
<constructor-arg ref="bandwidthDao" />
|
||||
<constructor-arg ref="bandwidthBucketDao" />
|
||||
</bean>
|
||||
|
||||
<bean id="bandwidthDbInit" factory-bean="bandwidthContextFactory"
|
||||
factory-method="getBandwidthDbInit" />
|
||||
|
||||
|
@ -89,8 +98,7 @@
|
|||
</bean>
|
||||
|
||||
<bean id="retrievalManager"
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager"
|
||||
depends-on="bandwidthDbInit">
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager">
|
||||
<constructor-arg ref="bandwidthDao" />
|
||||
<constructor-arg ref="retrievalAgentNotifier" />
|
||||
<property name="retrievalPlans" ref="retrievalPlans" />
|
||||
|
|
|
@ -38,12 +38,12 @@ import com.raytheon.uf.common.status.UFStatus;
|
|||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.common.time.util.TimeUtil;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthReservation;
|
||||
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.retrieval.RetrievalPlan.BandwidthBucket;
|
||||
|
||||
/**
|
||||
* Adapts the {@link BandwidthManager} formatted data into a GUI usable graphing
|
||||
|
@ -57,6 +57,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan.Bandw
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Dec 06, 2012 1397 djohnson Initial creation
|
||||
* Jan 25, 2013 1528 djohnson Subscription priority is now an enum.
|
||||
* Jun 24, 2013 2106 djohnson Access bucket allocations through RetrievalPlan.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -117,7 +118,8 @@ class BandwidthGraphDataAdapter {
|
|||
// name, and associate all of the bandwidth reservations with their
|
||||
// associated retrievals
|
||||
for (BandwidthBucket bucket : bandwidthBuckets) {
|
||||
final List<BandwidthAllocation> requests = bucket.getRequests();
|
||||
final List<BandwidthAllocation> requests = retrievalPlan
|
||||
.getBandwidthAllocationsForBucket(bucket);
|
||||
for (BandwidthAllocation allocation : requests) {
|
||||
if (allocation instanceof SubscriptionRetrieval) {
|
||||
final SubscriptionRetrieval subRetrieval = (SubscriptionRetrieval) allocation;
|
||||
|
@ -127,8 +129,9 @@ class BandwidthGraphDataAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
final List<BandwidthReservation> bandwidthReservations = bucket
|
||||
.getReservations();
|
||||
final List<BandwidthReservation> bandwidthReservations = retrievalPlan
|
||||
.getBandwidthReservationsForBucket(bucket);
|
||||
|
||||
for (BandwidthReservation reservation : bandwidthReservations) {
|
||||
reservations.put(reservation.getId(), reservation);
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ import com.raytheon.uf.edex.auth.req.AbstractPrivilegedRequestHandler;
|
|||
import com.raytheon.uf.edex.auth.resp.AuthorizationResponse;
|
||||
import com.raytheon.uf.edex.core.EDEXUtil;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthDataSetUpdate;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao;
|
||||
|
@ -81,7 +82,6 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap;
|
|||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthRoute;
|
||||
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.retrieval.RetrievalPlan.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.SubscriptionRetrievalFulfilled;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil;
|
||||
|
@ -121,6 +121,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* Jun 13, 2013 2095 djohnson Improve bandwidth manager speed, and add performance logging.
|
||||
* Jun 18, 2013 2120 dhladky Add times to pointtime array
|
||||
* Jun 20, 2013 1802 djohnson Check several times for the metadata for now.
|
||||
* Jun 24, 2013 2106 djohnson Access BandwidthBucket contents through RetrievalPlan.
|
||||
* </pre>
|
||||
*
|
||||
* @author dhladky
|
||||
|
@ -1227,7 +1228,7 @@ public abstract class BandwidthManager extends
|
|||
long bucketId = request.getId();
|
||||
RetrievalPlan plan = retrievalManager.getPlan(requestNetwork);
|
||||
BandwidthBucket bucket = plan.getBucket(bucketId);
|
||||
response = bucket.showReservations();
|
||||
response = plan.showBucket(bucket);
|
||||
break;
|
||||
|
||||
case SHOW_DEFERRED:
|
||||
|
@ -1614,7 +1615,7 @@ public abstract class BandwidthManager extends
|
|||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
initializer.init(this, dbInit);
|
||||
initializer.init(this, dbInit, retrievalManager);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1669,28 +1670,52 @@ public abstract class BandwidthManager extends
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
public List<BandwidthAllocation> copyState(BandwidthManager copyFrom) {
|
||||
IPerformanceTimer timer = TimeUtil.getPerformanceTimer();
|
||||
timer.start();
|
||||
List<BandwidthAllocation> unscheduled = Collections.emptyList();
|
||||
IBandwidthDao fromDao = copyFrom.bandwidthDao;
|
||||
|
||||
Set<Subscription> actualSubscriptions = new HashSet<Subscription>();
|
||||
for (BandwidthSubscription subscription : fromDao
|
||||
.getBandwidthSubscriptions()) {
|
||||
try {
|
||||
Subscription actualSubscription = subscription
|
||||
.getSubscription();
|
||||
actualSubscriptions.add(actualSubscription);
|
||||
} catch (SerializationException e) {
|
||||
statusHandler
|
||||
.handle(Priority.PROBLEM,
|
||||
"Unable to deserialize a subscription, results may not be accurate for modeling bandwidth changes.",
|
||||
e);
|
||||
final boolean proposingBandwidthChange = retrievalManager
|
||||
.isProposingBandwidthChanges(copyFrom.retrievalManager);
|
||||
if (proposingBandwidthChange) {
|
||||
|
||||
retrievalManager.initRetrievalPlans();
|
||||
|
||||
// Proposing bandwidth changes requires the old way of bringing up a
|
||||
// fresh bandwidth manager and trying the change from scratch
|
||||
unscheduled = Lists.newArrayList();
|
||||
Set<Subscription> actualSubscriptions = new HashSet<Subscription>();
|
||||
for (BandwidthSubscription subscription : fromDao
|
||||
.getBandwidthSubscriptions()) {
|
||||
try {
|
||||
Subscription actualSubscription = subscription
|
||||
.getSubscription();
|
||||
actualSubscriptions.add(actualSubscription);
|
||||
} catch (SerializationException e) {
|
||||
statusHandler
|
||||
.handle(Priority.PROBLEM,
|
||||
"Unable to deserialize a subscription, results may not be accurate for modeling bandwidth changes.",
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
// Now for each subscription, attempt to schedule bandwidth
|
||||
for (Subscription subscription : actualSubscriptions) {
|
||||
unscheduled.addAll(this.schedule(subscription));
|
||||
}
|
||||
} else {
|
||||
// Otherwise we can just copy the entire state of the current system
|
||||
// and attempt the proposed changes
|
||||
bandwidthDao.storeBandwidthSubscriptions(fromDao
|
||||
.getBandwidthSubscriptions());
|
||||
bandwidthDao.store(fromDao.getSubscriptionRetrievals());
|
||||
|
||||
RetrievalManager fromRetrievalManager = copyFrom.retrievalManager;
|
||||
this.retrievalManager.copyState(fromRetrievalManager);
|
||||
}
|
||||
|
||||
// Now for each subscription, attempt to schedule bandwidth
|
||||
List<BandwidthAllocation> unscheduled = new ArrayList<BandwidthAllocation>();
|
||||
for (Subscription subscription : actualSubscriptions) {
|
||||
unscheduled.addAll(this.schedule(subscription));
|
||||
}
|
||||
timer.stop();
|
||||
timer.logLaps("copyingState()", performanceHandler);
|
||||
|
||||
return unscheduled;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
|||
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthContextFactory;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao;
|
||||
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;
|
||||
|
@ -78,6 +79,8 @@ public class EdexBandwidthContextFactory implements BandwidthContextFactory {
|
|||
|
||||
private final IBandwidthDao bandwidthDao;
|
||||
|
||||
private final IBandwidthBucketDao bandwidthBucketDao;
|
||||
|
||||
private final BandwidthInitializer bandwidthInitializer;
|
||||
|
||||
private final IEdexBandwidthManagerCreator bandwidthManagerCreator;
|
||||
|
@ -92,10 +95,12 @@ public class EdexBandwidthContextFactory implements BandwidthContextFactory {
|
|||
* @param findSubscriptionStrategy
|
||||
*/
|
||||
EdexBandwidthContextFactory(IBandwidthDao bandwidthDao,
|
||||
IBandwidthBucketDao bandwidthBucketDao,
|
||||
BandwidthInitializer bandwidthInitializer,
|
||||
IEdexBandwidthManagerCreator bandwidthManagerCreator,
|
||||
IBandwidthDbInit dbInit) {
|
||||
this.bandwidthDao = bandwidthDao;
|
||||
this.bandwidthBucketDao = bandwidthBucketDao;
|
||||
this.bandwidthInitializer = bandwidthInitializer;
|
||||
this.bandwidthManagerCreator = bandwidthManagerCreator;
|
||||
this.dbInit = dbInit;
|
||||
|
@ -112,6 +117,7 @@ public class EdexBandwidthContextFactory implements BandwidthContextFactory {
|
|||
EdexBandwidthContextFactory(BandwidthManager instance) {
|
||||
EdexBandwidthContextFactory.instance = instance;
|
||||
this.bandwidthDao = null;
|
||||
this.bandwidthBucketDao = null;
|
||||
this.bandwidthInitializer = null;
|
||||
this.bandwidthManagerCreator = null;
|
||||
this.dbInit = null;
|
||||
|
@ -172,6 +178,14 @@ public class EdexBandwidthContextFactory implements BandwidthContextFactory {
|
|||
return bandwidthDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public IBandwidthBucketDao getBandwidthBucketDao() {
|
||||
return bandwidthBucketDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,273 @@
|
|||
/**
|
||||
* 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 java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Network;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
||||
|
||||
/**
|
||||
* Extracted from {@link RetrievalPlan}. This will be replaced with a database
|
||||
* version.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 18, 2013 2106 djohnson Extracted from {@link RetrievalPlan}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class InMemoryBandwidthBucketDao implements IBandwidthBucketDao {
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(InMemoryBandwidthBucketDao.class);
|
||||
|
||||
private static final AtomicLong idSequence = new AtomicLong(1);
|
||||
|
||||
private final Map<Network, NavigableMap<Long, BandwidthBucket>> allBuckets = new EnumMap<Network, NavigableMap<Long, BandwidthBucket>>(
|
||||
Network.class);
|
||||
{
|
||||
for (Network network : Network.values()) {
|
||||
allBuckets.put(network, new TreeMap<Long, BandwidthBucket>());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void create(BandwidthBucket bandwidthBucket) {
|
||||
NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(bandwidthBucket.getNetwork());
|
||||
if (bandwidthBucket.getId() == BandwidthUtil.DEFAULT_IDENTIFIER) {
|
||||
bandwidthBucket.setIdentifier(idSequence.incrementAndGet());
|
||||
}
|
||||
buckets.put(bandwidthBucket.getBucketStartTime(), bandwidthBucket);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void update(BandwidthBucket bandwidthBucket) {
|
||||
NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(bandwidthBucket.getNetwork());
|
||||
final long bucketStartTime = bandwidthBucket.getBucketStartTime();
|
||||
if (buckets.containsKey(bucketStartTime)) {
|
||||
buckets.put(bucketStartTime, bandwidthBucket);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void deleteEmptyBucketsUpToTime(long timeToDeleteUpTo,
|
||||
Network network) {
|
||||
NavigableMap<Long, BandwidthBucket> buckets = allBuckets.get(network);
|
||||
NavigableMap<Long, BandwidthBucket> x = buckets.headMap(
|
||||
timeToDeleteUpTo, true);
|
||||
Iterator<Long> itr = x.keySet().iterator();
|
||||
while (itr.hasNext()) {
|
||||
Long key = itr.next();
|
||||
BandwidthBucket b = x.get(key);
|
||||
// If the bucket is empty, remove it from the Map,
|
||||
// which should result in removal from the parent Map,
|
||||
if (b.isEmpty()) {
|
||||
statusHandler.info("resize() - Removing bucket ["
|
||||
+ b.getBucketStartTime() + "]");
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<BandwidthBucket> getAll(Network network) {
|
||||
final NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(network);
|
||||
return copyAndWrapInUnmodifiableList(buckets.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthBucket getLastBucket(Network network) {
|
||||
final NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(network);
|
||||
return buckets.lastEntry().getValue().copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BandwidthBucket> getWhereStartTimeIsLessThanOrEqualTo(
|
||||
long time, Network network) {
|
||||
final NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(network);
|
||||
SortedMap<Long, BandwidthBucket> available = buckets
|
||||
.headMap(time, true);
|
||||
return copyAndWrapInUnmodifiableList(available.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthBucket getFirstBucket(Network network) {
|
||||
final NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(network);
|
||||
return buckets.firstEntry().getValue().copy();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthBucket getByStartTime(long bucketId, Network network) {
|
||||
BandwidthBucket bucket = getActualBucketByStartTime(bucketId, network);
|
||||
return (bucket == null) ? bucket : bucket.copy();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public SortedSet<BandwidthBucket> getBucketsInWindow(Long startMillis,
|
||||
Long endMillis, Network network) {
|
||||
// Get the bucket for the startTime and endTime.
|
||||
Long startKey = ceilingKey(startMillis, network);
|
||||
Long endKey = floorBucket(endMillis, network);
|
||||
|
||||
// Handle the case where an invalid range was somehow specified
|
||||
// (shouldn't happen, so just throw an exception with as much
|
||||
// information as we have)
|
||||
if (startKey == null || endKey == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Invalid start and end times requested for getBucketsInWindow(): start time [%s], end time [%s], bucket start key [%s], bucket end key [%s].",
|
||||
startMillis, endMillis, startKey, endKey));
|
||||
}
|
||||
|
||||
final NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(network);
|
||||
NavigableMap<Long, BandwidthBucket> window = buckets.subMap(startKey,
|
||||
true, endKey, true);
|
||||
return new TreeSet<BandwidthBucket>(
|
||||
copyAndWrapInUnmodifiableList(window.values()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the greatest key less than or equal to the given key, or null if
|
||||
* there is no such key.
|
||||
*
|
||||
* @param key
|
||||
* @return the floored key, or null
|
||||
*/
|
||||
private Long floorBucket(long key, Network network) {
|
||||
final NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(network);
|
||||
return buckets.floorKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the least key greater than or equal to the given key, or null if
|
||||
* there is no such key.
|
||||
*
|
||||
* @param key
|
||||
* @return the ceiling-ed key, or null
|
||||
*/
|
||||
private Long ceilingKey(long key, Network network) {
|
||||
final NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(network);
|
||||
return buckets.ceilingKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void copyState(IBandwidthBucketDao bucketsDao) {
|
||||
this.allBuckets.clear();
|
||||
for (Network network : Network.values()) {
|
||||
final TreeMap<Long, BandwidthBucket> buckets = new TreeMap<Long, BandwidthBucket>();
|
||||
this.allBuckets.put(network, buckets);
|
||||
for (BandwidthBucket bucket : bucketsDao.getAll(network)) {
|
||||
buckets.put(bucket.getBucketStartTime(), bucket.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies each {@link BandwidthBucket} and places them in an unmodifiable
|
||||
* list.
|
||||
*
|
||||
* @param buckets
|
||||
* the buckets
|
||||
* @return the list
|
||||
*/
|
||||
private List<BandwidthBucket> copyAndWrapInUnmodifiableList(
|
||||
Collection<BandwidthBucket> buckets) {
|
||||
List<BandwidthBucket> retVal = Lists.newArrayList();
|
||||
for (BandwidthBucket bucket : buckets) {
|
||||
retVal.add(bucket.copy());
|
||||
}
|
||||
return Collections.unmodifiableList(retVal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the real {@link BandwidthBucket} instance by its start time.
|
||||
*
|
||||
* @return {@link BandwidthBucket}
|
||||
*/
|
||||
private BandwidthBucket getActualBucketByStartTime(long bucketId,
|
||||
Network network) {
|
||||
final NavigableMap<Long, BandwidthBucket> buckets = allBuckets
|
||||
.get(network);
|
||||
BandwidthBucket bucket = buckets.get(bucketId);
|
||||
return bucket;
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ import com.raytheon.uf.common.status.UFStatus;
|
|||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.InMemoryBandwidthManager.InMemoryBandwidthInitializer;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthContextFactory;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao;
|
||||
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;
|
||||
|
@ -45,6 +46,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 24, 2012 1286 djohnson Initial creation
|
||||
* Jun 24, 2013 2106 djohnson Add {@link #getBandwidthBucketDao()}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -61,10 +63,13 @@ class InMemoryBandwidthContextFactory implements BandwidthContextFactory {
|
|||
|
||||
private final IBandwidthDao dao = new InMemoryBandwidthDao();
|
||||
|
||||
private final IBandwidthBucketDao bandwidthBucketsDao = new InMemoryBandwidthBucketDao();
|
||||
|
||||
private final IBandwidthDbInit dbInit = new InMemoryBandwidthDbInit();
|
||||
|
||||
private final BandwidthInitializer initializer = new InMemoryBandwidthInitializer();
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -158,4 +163,12 @@ class InMemoryBandwidthContextFactory implements BandwidthContextFactory {
|
|||
.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public IBandwidthBucketDao getBandwidthBucketDao() {
|
||||
return bandwidthBucketsDao;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import com.raytheon.uf.common.serialization.SerializationException;
|
|||
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.IDeepCopyable;
|
||||
import com.raytheon.uf.common.util.ReflectionUtil;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthDataSetUpdate;
|
||||
|
@ -128,16 +129,11 @@ class InMemoryBandwidthDao implements IBandwidthDao {
|
|||
* @param sourceList
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> ArrayList<T> clone(ConcurrentLinkedQueue<T> sourceList) {
|
||||
ArrayList<T> results;
|
||||
try {
|
||||
results = BandwidthUtil.cheapClone(ArrayList.class,
|
||||
new ArrayList<T>(sourceList));
|
||||
} catch (SerializationException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Unable to clone list, returning empty list.", e);
|
||||
results = new ArrayList<T>();
|
||||
private static <T extends IDeepCopyable<T>> ArrayList<T> clone(
|
||||
ConcurrentLinkedQueue<T> sourceList) {
|
||||
ArrayList<T> results = new ArrayList<T>(sourceList.size());
|
||||
for (T instance : sourceList) {
|
||||
results.add(instance.copy());
|
||||
}
|
||||
|
||||
return results;
|
||||
|
@ -607,8 +603,8 @@ class InMemoryBandwidthDao implements IBandwidthDao {
|
|||
SortedSet<SubscriptionRetrieval> results = getSubscriptionRetrievals(
|
||||
provider, dataSetName, status);
|
||||
|
||||
for (Iterator<SubscriptionRetrieval> iter = results
|
||||
.iterator(); iter.hasNext();) {
|
||||
for (Iterator<SubscriptionRetrieval> iter = results.iterator(); iter
|
||||
.hasNext();) {
|
||||
SubscriptionRetrieval subRetrieval = iter.next();
|
||||
if (earliestDate.after(subRetrieval.getStartTime().getTime())
|
||||
|| latestDate.before(subRetrieval.getStartTime().getTime())) {
|
||||
|
@ -618,4 +614,41 @@ class InMemoryBandwidthDao implements IBandwidthDao {
|
|||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<SubscriptionRetrieval> getSubscriptionRetrievals() {
|
||||
ArrayList<BandwidthAllocation> clone = clone(bandwidthAllocations);
|
||||
List<SubscriptionRetrieval> results = new ArrayList<SubscriptionRetrieval>(
|
||||
bandwidthAllocations.size());
|
||||
|
||||
for (Iterator<BandwidthAllocation> iter = clone.iterator(); iter
|
||||
.hasNext();) {
|
||||
BandwidthAllocation current = iter.next();
|
||||
if (current instanceof SubscriptionRetrieval) {
|
||||
results.add((SubscriptionRetrieval) current);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<BandwidthAllocation> getBandwidthAllocationsForNetworkAndBucketStartTime(
|
||||
Network network, long bucketStartTime) {
|
||||
final List<BandwidthAllocation> bandwidthAllocations = getBandwidthAllocations(network);
|
||||
for (Iterator<BandwidthAllocation> iter = bandwidthAllocations
|
||||
.iterator(); iter.hasNext();) {
|
||||
final BandwidthAllocation allocation = iter.next();
|
||||
if (allocation.getBandwidthBucket() != bucketStartTime) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
return bandwidthAllocations;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil;
|
|||
* Feb 20, 2013 1543 djohnson For now assume all in-memory bandwidth managers are WFOs.
|
||||
* Feb 27, 2013 1644 djohnson Schedule SBN subscriptions.
|
||||
* Apr 16, 2013 1906 djohnson Implements RegistryInitializedListener.
|
||||
* Jun 25, 2013 2106 djohnson init() now takes a {@link RetrievalManager} as well.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -78,7 +79,8 @@ class InMemoryBandwidthManager extends BandwidthManager {
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean init(IBandwidthManager instance, IBandwidthDbInit dbInit) {
|
||||
public boolean init(IBandwidthManager instance,
|
||||
IBandwidthDbInit dbInit, RetrievalManager retrievalManager) {
|
||||
BandwidthManager edexBandwidthManager = EdexBandwidthContextFactory
|
||||
.getInstance();
|
||||
if (instance instanceof InMemoryBandwidthManager) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.raytheon.uf.common.dataplugin.persist.IPersistableDataObject;
|
|||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
import com.raytheon.uf.common.util.IDeepCopyable;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
||||
|
||||
|
@ -37,6 +38,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 12, 2012 0726 djohnson Add SW history, use string version of enum.
|
||||
* Jun 24, 2013 2106 djohnson Add copy constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -51,7 +53,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
@DynamicSerialize
|
||||
@SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_seq", allocationSize = 1, initialValue = 1)
|
||||
public class BandwidthAllocation implements IPersistableDataObject<Long>,
|
||||
ISerializableObject, Serializable {
|
||||
ISerializableObject, Serializable, IDeepCopyable<BandwidthAllocation> {
|
||||
|
||||
private static final long serialVersionUID = 743702044231376839L;
|
||||
|
||||
|
@ -117,6 +119,39 @@ public class BandwidthAllocation implements IPersistableDataObject<Long>,
|
|||
this.bandwidthBucket = request.getBandwidthBucket();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param from
|
||||
*/
|
||||
public BandwidthAllocation(BandwidthAllocation from) {
|
||||
final Calendar fromActualEnd = from.getActualEnd();
|
||||
if (fromActualEnd != null) {
|
||||
this.setActualEnd(BandwidthUtil.copy(fromActualEnd));
|
||||
}
|
||||
final Calendar fromActualStart = from.getActualStart();
|
||||
if (fromActualStart != null) {
|
||||
this.setActualStart(BandwidthUtil.copy(fromActualStart));
|
||||
}
|
||||
final Calendar fromStartTime = from.getStartTime();
|
||||
if (fromStartTime != null) {
|
||||
this.setStartTime(BandwidthUtil.copy(fromStartTime));
|
||||
}
|
||||
final Calendar fromEndTime = from.getEndTime();
|
||||
if (fromEndTime != null) {
|
||||
this.setEndTime(BandwidthUtil.copy(fromEndTime));
|
||||
}
|
||||
|
||||
this.setAgentType(from.getAgentType());
|
||||
this.setBandwidthBucket(from.getBandwidthBucket());
|
||||
this.setEstimatedSize(from.getEstimatedSize());
|
||||
this.setId(from.getId());
|
||||
this.setIdentifier(from.getIdentifier());
|
||||
this.setNetwork(from.getNetwork());
|
||||
this.setPriority(from.getPriority());
|
||||
this.setStatus(from.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actualEnd
|
||||
*/
|
||||
|
@ -310,4 +345,12 @@ public class BandwidthAllocation implements IPersistableDataObject<Long>,
|
|||
return this.getPriority() < other.getPriority();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BandwidthAllocation copy() {
|
||||
return new BandwidthAllocation(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
/**
|
||||
* 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.dao;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.raytheon.uf.common.datadelivery.registry.Network;
|
||||
import com.raytheon.uf.common.dataplugin.persist.IPersistableDataObject;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
import com.raytheon.uf.common.util.IDeepCopyable;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Associates a portion of bandwidth to a given interval of time.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 18, 2013 2106 djohnson Extracted from {@link RetrievalPlan}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "bandwidth_bucket")
|
||||
@SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_seq", allocationSize = 1, initialValue = 1)
|
||||
public class BandwidthBucket implements Comparable<BandwidthBucket>,
|
||||
IPersistableDataObject<Long>, IDeepCopyable<BandwidthBucket> {
|
||||
|
||||
@Id
|
||||
@Column(name = "identifier")
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BANDWIDTH_SEQ")
|
||||
@DynamicSerializeElement
|
||||
private long id = BandwidthUtil.DEFAULT_IDENTIFIER;
|
||||
|
||||
// Number of allocated bytes
|
||||
@Column
|
||||
private long currentSize;
|
||||
|
||||
@Column
|
||||
private Network network;
|
||||
|
||||
// Number of bytes of bandwidth;
|
||||
@Column
|
||||
private long bucketSize;
|
||||
|
||||
@Column
|
||||
private long bucketStartTime;
|
||||
|
||||
public BandwidthBucket() {
|
||||
}
|
||||
|
||||
public BandwidthBucket(long bucketStartTime, long sizeInBytes,
|
||||
Network network) {
|
||||
this.bucketStartTime = bucketStartTime;
|
||||
this.bucketSize = sizeInBytes;
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param from
|
||||
* the instance to copy from
|
||||
*/
|
||||
public BandwidthBucket(BandwidthBucket from) {
|
||||
this.bucketStartTime = from.bucketStartTime;
|
||||
this.bucketSize = from.bucketSize;
|
||||
this.currentSize = from.currentSize;
|
||||
this.network = from.network;
|
||||
this.id = from.id;
|
||||
}
|
||||
|
||||
public long getAvailableBandwidth() {
|
||||
return Math.max(0, bucketSize - currentSize);
|
||||
}
|
||||
|
||||
public long getBucketSize() {
|
||||
return bucketSize;
|
||||
}
|
||||
|
||||
public long getBucketStartTime() {
|
||||
return bucketStartTime;
|
||||
}
|
||||
|
||||
public long getCurrentSize() {
|
||||
return currentSize;
|
||||
}
|
||||
|
||||
public void setCurrentSize(long currentSize) {
|
||||
this.currentSize = currentSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bucketSize
|
||||
* the bucketSize to set
|
||||
*/
|
||||
public void setBucketSize(long bucketSize) {
|
||||
this.bucketSize = bucketSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bucketStartTime
|
||||
* the bucketStartTime to set
|
||||
*/
|
||||
public void setBucketStartTime(long bucketStartTime) {
|
||||
this.bucketStartTime = bucketStartTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param network
|
||||
* the network to set
|
||||
*/
|
||||
public void setNetwork(Network network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getIdentifier() {
|
||||
return Long.valueOf(id);
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setIdentifier(Long identifier) {
|
||||
setId(identifier.longValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Calendar b = BandwidthUtil.now();
|
||||
b.setTimeInMillis(bucketStartTime);
|
||||
sb.append("Bucket [").append(getBucketStartTime()).append("] [")
|
||||
.append(BandwidthUtil.format(b));
|
||||
sb.append("] bandwidth [").append(bucketSize);
|
||||
sb.append("] available [").append(getAvailableBandwidth())
|
||||
.append("]);");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this bucket is empty.
|
||||
*
|
||||
* @return true if empty
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return currentSize == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ (int) (bucketStartTime ^ (bucketStartTime >>> 32));
|
||||
result = prime * result + ((network == null) ? 0 : network.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
BandwidthBucket other = (BandwidthBucket) obj;
|
||||
if (bucketStartTime != other.bucketStartTime)
|
||||
return false;
|
||||
if (network != other.network)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(BandwidthBucket o) {
|
||||
if (this.bucketStartTime > o.bucketStartTime) {
|
||||
return 1;
|
||||
} else if (this.bucketStartTime < o.bucketStartTime) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Network getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthBucket copy() {
|
||||
return new BandwidthBucket(this);
|
||||
}
|
||||
}
|
|
@ -21,7 +21,9 @@ package com.raytheon.uf.edex.datadelivery.bandwidth.dao;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.BandwidthManager;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.IBandwidthManager;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.HibernateBandwidthDbInit;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.interfaces.BandwidthInitializer;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager;
|
||||
|
@ -40,7 +42,8 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthDaoUtil;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 24, 2012 1286 djohnson Initial creation
|
||||
* Oct 24, 2012 1286 djohnson Initial creation
|
||||
* Jun 24, 2013 2106 djohnson Add {@link #getBandwidthBucketDao()}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -63,6 +66,13 @@ public interface BandwidthContextFactory {
|
|||
*/
|
||||
IBandwidthDao getBandwidthDao();
|
||||
|
||||
/**
|
||||
* Retrieve the {@link IBandwidthBucketDao} implementation.
|
||||
*
|
||||
* @return the dao
|
||||
*/
|
||||
IBandwidthBucketDao getBandwidthBucketDao();
|
||||
|
||||
/**
|
||||
* Retrieve the {@link BandwidthInitializer} implementation.
|
||||
*
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.raytheon.uf.common.dataplugin.persist.IPersistableDataObject;
|
|||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
import com.raytheon.uf.common.util.IDeepCopyable;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
||||
|
||||
/**
|
||||
|
@ -31,6 +32,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 19, 2012 0726 djohnson Added SW history.
|
||||
* Jun 24, 2013 2106 djohnson Add copy constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -43,7 +45,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
@SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_datasetupdate_seq", allocationSize = 1)
|
||||
@DynamicSerialize
|
||||
public class BandwidthDataSetUpdate implements IPersistableDataObject<Long>,
|
||||
Serializable, ISerializableObject {
|
||||
Serializable, ISerializableObject, IDeepCopyable<BandwidthDataSetUpdate> {
|
||||
|
||||
private static final long serialVersionUID = 20120723L;
|
||||
|
||||
|
@ -77,6 +79,29 @@ public class BandwidthDataSetUpdate implements IPersistableDataObject<Long>,
|
|||
@DynamicSerializeElement
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public BandwidthDataSetUpdate() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param bandwidthDataSetUpdate
|
||||
* the instance to copy
|
||||
*/
|
||||
public BandwidthDataSetUpdate(BandwidthDataSetUpdate bandwidthDataSetUpdate) {
|
||||
this.dataSetBaseTime = BandwidthUtil
|
||||
.copy(bandwidthDataSetUpdate.dataSetBaseTime);
|
||||
this.dataSetName = bandwidthDataSetUpdate.dataSetName;
|
||||
this.dataSetType = bandwidthDataSetUpdate.dataSetType;
|
||||
this.id = bandwidthDataSetUpdate.id;
|
||||
this.providerName = bandwidthDataSetUpdate.providerName;
|
||||
this.updateTime = BandwidthUtil.copy(bandwidthDataSetUpdate.updateTime);
|
||||
this.url = bandwidthDataSetUpdate.url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataSetBaseTime
|
||||
*/
|
||||
|
@ -198,4 +223,12 @@ public class BandwidthDataSetUpdate implements IPersistableDataObject<Long>,
|
|||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthDataSetUpdate copy() {
|
||||
return new BandwidthDataSetUpdate(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
|||
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.IDeepCopyable;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
||||
|
||||
/**
|
||||
|
@ -40,6 +41,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* Oct 16, 2012 0726 djohnson Added SW history, added length to subscription.
|
||||
* Nov 09, 2012 1286 djohnson Add convenience methods for retrieving the subscription.
|
||||
* Jun 13, 2013 2095 djohnson Add flag for whether or not data set update should be looked for on aggregating.
|
||||
* Jun 24, 2013 2106 djohnson Add copy constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -50,8 +52,9 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
@Table(name = "bandwidth_subscription")
|
||||
@DynamicSerialize
|
||||
@SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_seq", allocationSize = 1, initialValue = 1)
|
||||
public class BandwidthSubscription extends PersistableDataObject<Long> implements
|
||||
Serializable, ISerializableObject {
|
||||
public class BandwidthSubscription extends PersistableDataObject<Long>
|
||||
implements Serializable, ISerializableObject,
|
||||
IDeepCopyable<BandwidthSubscription> {
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(BandwidthSubscription.class);
|
||||
|
@ -159,6 +162,33 @@ public class BandwidthSubscription extends PersistableDataObject<Long> implement
|
|||
// Bean constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bandwidthSubscription
|
||||
*/
|
||||
public BandwidthSubscription(BandwidthSubscription bandwidthSubscription) {
|
||||
this.baseReferenceTime = BandwidthUtil.copy(bandwidthSubscription
|
||||
.getBaseReferenceTime());
|
||||
this.checkForDataSetUpdate = bandwidthSubscription.checkForDataSetUpdate;
|
||||
this.cycle = bandwidthSubscription.cycle;
|
||||
this.dataSetName = bandwidthSubscription.dataSetName;
|
||||
this.estimatedSize = bandwidthSubscription.estimatedSize;
|
||||
this.id = bandwidthSubscription.id;
|
||||
this.identifier = bandwidthSubscription.identifier;
|
||||
this.name = bandwidthSubscription.name;
|
||||
this.owner = bandwidthSubscription.owner;
|
||||
this.priority = bandwidthSubscription.priority;
|
||||
this.provider = bandwidthSubscription.provider;
|
||||
this.registryId = bandwidthSubscription.registryId;
|
||||
this.route = bandwidthSubscription.route;
|
||||
|
||||
if (bandwidthSubscription.subSubscription != null) {
|
||||
final int srcLength = bandwidthSubscription.subSubscription.length;
|
||||
this.subSubscription = new byte[srcLength];
|
||||
System.arraycopy(bandwidthSubscription.subSubscription, 0,
|
||||
this.subSubscription, 0, srcLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the datasetName
|
||||
*/
|
||||
|
@ -345,4 +375,12 @@ public class BandwidthSubscription extends PersistableDataObject<Long> implement
|
|||
public void setSubSubscription(byte[] subSubscription) {
|
||||
this.subSubscription = subSubscription;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthSubscription copy() {
|
||||
return new BandwidthSubscription(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
/**
|
||||
* 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.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import com.raytheon.uf.common.datadelivery.registry.Network;
|
||||
import com.raytheon.uf.edex.database.DataAccessLayerException;
|
||||
|
||||
/**
|
||||
* Interface for a DAO that manages {@link BandwidthBucket} instances.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 18, 2013 2106 djohnson Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public interface IBandwidthBucketDao {
|
||||
|
||||
/**
|
||||
* Create the bandwidth bucket.
|
||||
*
|
||||
* @param bandwidthBucket
|
||||
*/
|
||||
void create(BandwidthBucket bandwidthBucket);
|
||||
|
||||
/**
|
||||
* Update the bandwidth bucket.
|
||||
*
|
||||
* @param bandwidthBucket
|
||||
*/
|
||||
void update(BandwidthBucket bandwidthBucket);
|
||||
|
||||
/**
|
||||
* Delete all bandwidth buckets up to and including the specified time.
|
||||
*
|
||||
* @param timeToDeleteUpTo
|
||||
* @param network
|
||||
* the network
|
||||
* @throws DataAccessLayerException
|
||||
*/
|
||||
void deleteEmptyBucketsUpToTime(long timeToDeleteUpTo, Network network)
|
||||
throws DataAccessLayerException;
|
||||
|
||||
/**
|
||||
* Get all bandwidth buckets.
|
||||
*
|
||||
* @param network
|
||||
* the network
|
||||
* @return all bandwidth buckets for the network
|
||||
*/
|
||||
List<BandwidthBucket> getAll(Network network);
|
||||
|
||||
/**
|
||||
* Get the {@link BandwidthBucket} with the latest start time.
|
||||
*
|
||||
* @param network
|
||||
* the network
|
||||
* @return
|
||||
*/
|
||||
BandwidthBucket getLastBucket(Network network);
|
||||
|
||||
/**
|
||||
* Get the {@link BandwidthBucket} with the earliest start time.
|
||||
*
|
||||
* @param network
|
||||
* the network
|
||||
* @return
|
||||
*/
|
||||
BandwidthBucket getFirstBucket(Network network);
|
||||
|
||||
/**
|
||||
* Get where the bucket start time is less than or equal to the specified
|
||||
* time.
|
||||
*
|
||||
* @param time
|
||||
* the latest time to include
|
||||
* @param network
|
||||
* the network
|
||||
* @return the buckets
|
||||
*/
|
||||
List<BandwidthBucket> getWhereStartTimeIsLessThanOrEqualTo(long time,
|
||||
Network network);
|
||||
|
||||
/**
|
||||
* Get the bucket by its start time.
|
||||
*
|
||||
* @param startTime
|
||||
* @param network
|
||||
* the network
|
||||
* @return
|
||||
*/
|
||||
BandwidthBucket getByStartTime(long startTime, Network network);
|
||||
|
||||
/**
|
||||
* Return the buckets in the specified window, both boundaries are
|
||||
* inclusive. Buckets will be in order of their start time.
|
||||
*
|
||||
* @param startMillis
|
||||
* the start time for buckets to include
|
||||
* @param endMillis
|
||||
* the end time for buckets to include
|
||||
* @param network
|
||||
* the network
|
||||
* @return the buckets in the window, sorted in ascending order of start
|
||||
* time
|
||||
*/
|
||||
public SortedSet<BandwidthBucket> getBucketsInWindow(Long startMillis,
|
||||
Long endMillis, Network network);
|
||||
|
||||
/**
|
||||
* Copy the state from another bucket dao.
|
||||
*
|
||||
* @param bucketsDao
|
||||
*/
|
||||
void copyState(IBandwidthBucketDao bucketsDao);
|
||||
}
|
|
@ -47,6 +47,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus;
|
|||
* Oct 23, 2012 1286 djohnson Initial creation
|
||||
* Jun 03, 2013 2038 djohnson Add method to get subscription retrievals by provider, dataset, and status.
|
||||
* Jun 13, 2013 2095 djohnson Implement ability to store a collection of subscriptions.
|
||||
* Jun 24, 2013 2106 djohnson Add more methods.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -415,4 +416,24 @@ public interface IBandwidthDao {
|
|||
*/
|
||||
List<BandwidthAllocation> getBandwidthAllocationsInState(
|
||||
RetrievalStatus state);
|
||||
|
||||
/**
|
||||
* Get all {@link SubscriptionRetrieval} instances.
|
||||
*
|
||||
* @return the retrievals
|
||||
*/
|
||||
List<SubscriptionRetrieval> getSubscriptionRetrievals();
|
||||
|
||||
/**
|
||||
* Get {@link BandwidthAllocation}s for the specified network and start
|
||||
* time.
|
||||
*
|
||||
* @param network
|
||||
* the network
|
||||
* @param bucketStartTime
|
||||
* the bucket start time
|
||||
* @return the allocations
|
||||
*/
|
||||
List<BandwidthAllocation> getBandwidthAllocationsForNetworkAndBucketStartTime(
|
||||
Network network, long bucketStartTime);
|
||||
}
|
|
@ -31,6 +31,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
|
|||
* Oct 16, 2012 0726 djohnson Added explicit length to subSubscription,
|
||||
* made it nullable for single table strategy.
|
||||
* Nov 09, 2012 1286 djohnson Add reference back to owning BandwidthSubscription.
|
||||
* Jun 24, 2013 2106 djohnson Add copy constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -75,6 +76,33 @@ public class SubscriptionRetrieval extends BandwidthAllocation {
|
|||
@Transient
|
||||
private transient Subscription subscription;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public SubscriptionRetrieval() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param from
|
||||
* the instance to copy from
|
||||
*/
|
||||
public SubscriptionRetrieval(SubscriptionRetrieval from) {
|
||||
super(from);
|
||||
this.setBandwidthSubscription(from.getBandwidthSubscription().copy());
|
||||
this.setDataSetAvailablityDelay(from.dataSetAvailablityDelay);
|
||||
this.setSubscriptionLatency(from.getSubscriptionLatency());
|
||||
this.setSubsumedBy(from.getSubsumedBy());
|
||||
|
||||
if (from.subSubscription != null) {
|
||||
final int srcLength = from.subSubscription.length;
|
||||
this.subSubscription = new byte[srcLength];
|
||||
System.arraycopy(from.subSubscription, 0, this.subSubscription, 0,
|
||||
srcLength);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataSetAvailablityDelay
|
||||
*/
|
||||
|
@ -192,4 +220,12 @@ public class SubscriptionRetrieval extends BandwidthAllocation {
|
|||
public void setSubSubscription(byte[] subSubscription) {
|
||||
this.subSubscription = subSubscription;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public SubscriptionRetrieval copy() {
|
||||
return new SubscriptionRetrieval(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,153 @@
|
|||
/**
|
||||
* 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.List;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Network;
|
||||
import com.raytheon.uf.edex.database.DataAccessLayerException;
|
||||
import com.raytheon.uf.edex.database.dao.SessionManagedDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao;
|
||||
|
||||
/**
|
||||
* Hibernate {@link IBandwidthBucketDao}.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 25, 2013 2106 djohnson Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
public class BandwidthBucketDao extends
|
||||
SessionManagedDao<Long, BandwidthBucket> implements IBandwidthBucketDao {
|
||||
|
||||
private static final String DELETE_EMPTY_UP_TO_TIME = "delete from BandwidthBucket bb where bb.network = :network and bb.currentSize = 0";
|
||||
|
||||
private static final String GET_ALL_FOR_NETWORK = "from BandwidthBucket bb where bb.network = :network";
|
||||
|
||||
private static final String GET_BY_START_TIME = "from BandwidthBucket bb where bb.network = :network and bb.bucketStartTime = :bucketStartTime";
|
||||
|
||||
private static final String GET_WHERE_START_TIME_IS_LESS_THAN_OR_EQUAL = "from BandwidthBucket bb where bb.network = :network and bb.bucketStartTime <= :bucketStartTime";
|
||||
|
||||
private static final String GET_BY_EARLIEST_START_TIME = "from BandwidthBucket bb where bb.network = :network and bb.bucketStartTime = "
|
||||
+ "(select min(bucketStartTime) from BandwidthBucket bb where bb.network = :network)";
|
||||
|
||||
private static final String GET_BY_LATEST_START_TIME = "from BandwidthBucket bb where bb.network = :network and bb.bucketStartTime = "
|
||||
+ "(select max(bucketStartTime) from BandwidthBucket bb where bb.network = :network)";
|
||||
|
||||
private static final String GET_WHERE_START_TIME_IS_BETWEEN_INCLUSIVE = "from BandwidthBucket bb where bb.network = :network and bb.bucketStartTime between :earliestTime and :latestTime";
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void deleteEmptyBucketsUpToTime(long timeToDeleteUpTo,
|
||||
Network network) throws DataAccessLayerException {
|
||||
executeHQLStatement(DELETE_EMPTY_UP_TO_TIME, "network", network);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<BandwidthBucket> getAll(Network network) {
|
||||
return executeHQLQuery(GET_ALL_FOR_NETWORK, "network", network);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthBucket getLastBucket(Network network) {
|
||||
return uniqueResult(GET_BY_LATEST_START_TIME, "network", network);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthBucket getFirstBucket(Network network) {
|
||||
return uniqueResult(GET_BY_EARLIEST_START_TIME, "network", network);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<BandwidthBucket> getWhereStartTimeIsLessThanOrEqualTo(
|
||||
long time, Network network) {
|
||||
return executeHQLQuery(GET_WHERE_START_TIME_IS_LESS_THAN_OR_EQUAL,
|
||||
"network", network, "bucketStartTime", time);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthBucket getByStartTime(long startTime, Network network) {
|
||||
return uniqueResult(GET_BY_START_TIME, "network", network,
|
||||
"bucketStartTime", startTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public SortedSet<BandwidthBucket> getBucketsInWindow(Long startMillis,
|
||||
Long endMillis, Network network) {
|
||||
return Sets.<BandwidthBucket> newTreeSet(this
|
||||
.<BandwidthBucket> executeHQLQuery(
|
||||
GET_WHERE_START_TIME_IS_BETWEEN_INCLUSIVE, "network",
|
||||
network, "earliestTime", startMillis, "latestTime",
|
||||
endMillis));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void copyState(IBandwidthBucketDao bucketsDao) {
|
||||
deleteAll(getAll());
|
||||
for (Network network : Network.values()) {
|
||||
for (BandwidthBucket bucket : bucketsDao.getAll(network)) {
|
||||
create(bucket.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Class<BandwidthBucket> getEntityClass() {
|
||||
return BandwidthBucket.class;
|
||||
}
|
||||
|
||||
}
|
|
@ -37,8 +37,9 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 13, 2013 1543 djohnson Initial creation
|
||||
* Feb 13, 2013 1543 djohnson Initial creation
|
||||
* 4/9/2013 1802 bphillip Changed to use new query method signatures in SessionManagedDao
|
||||
* Jun 24, 2013 2106 djohnson Add ability to retrieve by network and start time.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -53,6 +54,9 @@ abstract class BaseBandwidthAllocationDao<ENTITY extends BandwidthAllocation>
|
|||
|
||||
private static final String GET_BANDWIDTH_ALLOCATIONS_BY_NETWORK = "from %s res where res.network = :network";
|
||||
|
||||
private static final String GET_BANDWIDTH_ALLOCATIONS_BY_NETWORK_AND_BUCKET_START_TIME = GET_BANDWIDTH_ALLOCATIONS_BY_NETWORK
|
||||
+ " and res.bandwidthBucket = :bandwidthBucket";
|
||||
|
||||
private static final String GET_BANDWIDTH_ALLOCATIONS_BY_STATE = "from %s res where res.status = :state";
|
||||
|
||||
private static final String GET_DEFERRED = "from %s alloc where "
|
||||
|
@ -78,6 +82,18 @@ abstract class BaseBandwidthAllocationDao<ENTITY extends BandwidthAllocation>
|
|||
getEntityClass().getSimpleName()), "network", network);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<ENTITY> getByNetworkAndBucketStartTime(Network network,
|
||||
long bucketStartTime) {
|
||||
return query(String.format(
|
||||
GET_BANDWIDTH_ALLOCATIONS_BY_NETWORK_AND_BUCKET_START_TIME,
|
||||
getEntityClass().getSimpleName()), "network", network,
|
||||
"bandwidthBucket", bucketStartTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -57,6 +57,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* Feb 13, 2013 1543 djohnson Converted into a service, created new DAOs as required.
|
||||
* Jun 03, 2013 2038 djohnson Add method to get subscription retrievals by provider, dataset, and status.
|
||||
* Jun 13, 2013 2095 djohnson Implement ability to store a collection of subscriptions.
|
||||
* Jun 24, 2013 2106 djohnson Implement new methods.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -441,4 +442,22 @@ public class HibernateBandwidthDao implements IBandwidthDao {
|
|||
this.bandwidthDataSetUpdateDao = bandwidthDataSetUpdateDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<SubscriptionRetrieval> getSubscriptionRetrievals() {
|
||||
return subscriptionRetrievalDao.getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<BandwidthAllocation> getBandwidthAllocationsForNetworkAndBucketStartTime(
|
||||
Network network, long bucketStartTime) {
|
||||
return bandwidthAllocationDao.getByNetworkAndBucketStartTime(
|
||||
network, bucketStartTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.raytheon.uf.edex.database.init.DbInit;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit;
|
||||
|
||||
/**
|
||||
|
@ -40,6 +41,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit;
|
|||
* Jul 31, 2012 726 jspinks Copied and refactored from ebxml registry DbInit
|
||||
* Oct 26, 2012 1286 djohnson Renamed to Hibernate specific.
|
||||
* Apr 30, 2013 1960 djohnson Extend the generalized DbInit.
|
||||
* Jun 24, 2013 2106 djohnson Add {@link BandwidthBucket} to annotated classes.
|
||||
* </pre>
|
||||
*
|
||||
* @author jspinks
|
||||
|
@ -72,6 +74,7 @@ public class HibernateBandwidthDbInit extends DbInit implements
|
|||
* this Hibernate SessionFactory is aware of
|
||||
*/
|
||||
AnnotationConfiguration aConfig = new AnnotationConfiguration();
|
||||
aConfig.addAnnotatedClass(com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket.class);
|
||||
aConfig.addAnnotatedClass(com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthDataSetUpdate.class);
|
||||
aConfig.addAnnotatedClass(com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription.class);
|
||||
aConfig.addAnnotatedClass(com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval.class);
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.IBandwidthManager;
|
|||
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;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -28,6 +29,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.interfaces.BandwidthInitializ
|
|||
* Feb 20, 2013 1543 djohnson Add SW history, separate how to find subscriptions.
|
||||
* Apr 16, 2013 1906 djohnson Implements RegistryInitializedListener.
|
||||
* Apr 30, 2013 1960 djohnson just call init rather than drop/create tables explicitly.
|
||||
* Jun 25, 2013 2106 djohnson init() now takes a {@link RetrievalManager} as well.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -52,7 +54,8 @@ public class HibernateBandwidthInitializer implements BandwidthInitializer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean init(IBandwidthManager instance, IBandwidthDbInit dbInit) {
|
||||
public boolean init(IBandwidthManager instance, IBandwidthDbInit dbInit,
|
||||
RetrievalManager retrievalManager) {
|
||||
|
||||
this.instance = instance;
|
||||
|
||||
|
@ -67,6 +70,8 @@ public class HibernateBandwidthInitializer implements BandwidthInitializer {
|
|||
"Error generating bandwidth manager tables", e1);
|
||||
}
|
||||
|
||||
retrievalManager.initRetrievalPlans();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 13, 2013 1543 djohnson Initial creation
|
||||
* Jun 24, 2013 2106 djohnson Add ability to retrieve by network and start time.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -64,6 +65,17 @@ interface IBaseBandwidthAllocationDao<ENTITY extends BandwidthAllocation>
|
|||
*/
|
||||
List<ENTITY> getByNetwork(Network network);
|
||||
|
||||
/**
|
||||
* Get by the network and the bucket start time.
|
||||
*
|
||||
* @param network
|
||||
* @param bucketStartTime
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<ENTITY> getByNetworkAndBucketStartTime(Network network,
|
||||
long bucketStartTime);
|
||||
|
||||
/**
|
||||
* Get by retrieval status.
|
||||
*
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.raytheon.uf.edex.datadelivery.bandwidth.interfaces;
|
|||
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.IBandwidthManager;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager;
|
||||
import com.raytheon.uf.edex.registry.ebxml.init.RegistryInitializedListener;
|
||||
|
||||
/**
|
||||
|
@ -18,6 +19,7 @@ import com.raytheon.uf.edex.registry.ebxml.init.RegistryInitializedListener;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 26, 2012 1286 djohnson Initial creation
|
||||
* Apr 16, 2013 1906 djohnson Extends RegistryInitializedListener.
|
||||
* Jun 25, 2013 2106 djohnson init() now takes a {@link RetrievalManager}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -34,8 +36,11 @@ public interface BandwidthInitializer extends RegistryInitializedListener {
|
|||
* initialize.
|
||||
* @param dbInit
|
||||
* a reference to the {@link IBandwidthDbInit} instance
|
||||
* @param retrievalManager
|
||||
* the {@link RetrievalManager} instance
|
||||
*
|
||||
* @return Whether or not the initialization completed successfully.
|
||||
*/
|
||||
boolean init(IBandwidthManager instance, IBandwidthDbInit dbInit);
|
||||
boolean init(IBandwidthManager instance, IBandwidthDbInit dbInit,
|
||||
RetrievalManager retrievalManager);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.raytheon.uf.edex.datadelivery.bandwidth.retrieval;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.raytheon.uf.common.datadelivery.registry.Network;
|
||||
import com.raytheon.uf.common.util.IDeepCopyable;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
||||
|
||||
|
@ -17,12 +19,17 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 02, 2012 726 jspinks Initial release.
|
||||
* Nov 09, 2012 1286 djohnson Add getters for bytes.
|
||||
* Jun 24, 2013 2106 djohnson Add copy constructor.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
public class BandwidthReservation {
|
||||
// TODO: Add Hibernate annotations
|
||||
public class BandwidthReservation implements Serializable,
|
||||
IDeepCopyable<BandwidthReservation> {
|
||||
|
||||
private static final long serialVersionUID = 4556094983346648973L;
|
||||
|
||||
private long id;
|
||||
|
||||
|
@ -68,6 +75,22 @@ public class BandwidthReservation {
|
|||
this.setBandwidthBucket(allocation.getBandwidthBucket());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param from
|
||||
* the instance to copy from
|
||||
*/
|
||||
public BandwidthReservation(BandwidthReservation from) {
|
||||
this.bandwidthBucket = from.bandwidthBucket;
|
||||
this.endTime = BandwidthUtil.copy(from.endTime);
|
||||
this.id = from.id;
|
||||
this.network = from.network;
|
||||
this.priority = from.priority;
|
||||
this.size = from.size;
|
||||
this.startTime = BandwidthUtil.copy(from.startTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -202,4 +225,11 @@ public class BandwidthReservation {
|
|||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public BandwidthReservation copy() {
|
||||
return new BandwidthReservation(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
/**
|
||||
* 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.retrieval;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
|
||||
/**
|
||||
* Provides associations between bandwidth buckets and their allocations.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 25, 2013 2106 djohnson Extracted from {@link BandwidthBucket}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
interface IBandwidthBucketAllocationAssociator {
|
||||
|
||||
/**
|
||||
* Adds the {@link BandwidthAllocation} to the specified bucket.
|
||||
*
|
||||
* @param bucket
|
||||
* the bucket
|
||||
* @param allocation
|
||||
* the allocation
|
||||
* @throws NullPointerException
|
||||
* if the bucket start time is invalid
|
||||
*/
|
||||
void addToBucket(BandwidthBucket bucket, BandwidthAllocation allocation);
|
||||
|
||||
/**
|
||||
* Adds the {@link BandwidthReservation} to the specified bucket.
|
||||
*
|
||||
* @param bucket
|
||||
* the bucket
|
||||
* @param reservation
|
||||
* the reservation
|
||||
* @throws NullPointerException
|
||||
* if the bucket start time is invalid
|
||||
*/
|
||||
void addToBucket(BandwidthBucket bucket, BandwidthReservation reservation);
|
||||
|
||||
/**
|
||||
* Remove the {@link BandwidthAllocation} from the {@link BandwidthBucket}.
|
||||
*
|
||||
* @param bucket
|
||||
* @param reservation
|
||||
*/
|
||||
void removeFromBucket(BandwidthBucket bucket,
|
||||
BandwidthAllocation reservation);
|
||||
|
||||
/**
|
||||
* Remove the {@link BandwidthAllocation} from the
|
||||
* {@link BandwidthReservation}.
|
||||
*
|
||||
* @param bucket
|
||||
* @param reservation
|
||||
*/
|
||||
void removeFromBucket(BandwidthBucket bucket,
|
||||
BandwidthReservation reservation);
|
||||
|
||||
/**
|
||||
* @param bucket
|
||||
* @return
|
||||
*/
|
||||
String showBucket(BandwidthBucket bucket);
|
||||
|
||||
/**
|
||||
* Get the next allocation to be processed.
|
||||
*
|
||||
* @param bucket
|
||||
* @param agentType
|
||||
* the agent type
|
||||
* @return the allocation, or null if there is none to process
|
||||
*/
|
||||
BandwidthAllocation getNextReservation(BandwidthBucket bucket,
|
||||
String agentType);
|
||||
|
||||
/**
|
||||
* Get the {@link BandwidthAllocation}s for the {@link BandwidthBucket}.
|
||||
*
|
||||
* @param bucket
|
||||
* @return
|
||||
*/
|
||||
List<BandwidthAllocation> getBandwidthAllocationsForBucket(
|
||||
BandwidthBucket bucket);
|
||||
|
||||
/**
|
||||
* Get the {@link BandwidthReservation}s for the {@link BandwidthBucket}.
|
||||
*
|
||||
* @param bucket
|
||||
* @return
|
||||
*/
|
||||
List<BandwidthReservation> getBandwidthReservationsForBucket(
|
||||
BandwidthBucket bucket);
|
||||
|
||||
/**
|
||||
* Copy the state from another instance.
|
||||
*
|
||||
* @param other
|
||||
*/
|
||||
void copyState(IBandwidthBucketAllocationAssociator other);
|
||||
}
|
|
@ -0,0 +1,193 @@
|
|||
/**
|
||||
* 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.retrieval;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Network;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao;
|
||||
|
||||
/**
|
||||
* Holds the associations between {@link BandwidthBucket}s and their
|
||||
* {@link BandwidthAllocation}s and {@link BandwidthReservation}s.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 25, 2013 2106 djohnson Extracted from {@link BandwidthBucket} and {@link RetrievalPlan}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class InMemoryBandwidthBucketAllocationAssociator implements
|
||||
IBandwidthBucketAllocationAssociator {
|
||||
|
||||
private final IBandwidthBucketDao bucketsDao;
|
||||
|
||||
private final IBandwidthDao bandwidthDao;
|
||||
|
||||
private final Multimap<Long, BandwidthReservation> reservations = ArrayListMultimap
|
||||
.create();
|
||||
|
||||
private final Multimap<Long, BandwidthAllocation> allocations = ArrayListMultimap
|
||||
.create();
|
||||
|
||||
public InMemoryBandwidthBucketAllocationAssociator(
|
||||
IBandwidthDao bandwidthDao, IBandwidthBucketDao bucketsDao) {
|
||||
this.bandwidthDao = bandwidthDao;
|
||||
this.bucketsDao = bucketsDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void addToBucket(BandwidthBucket bucket,
|
||||
BandwidthAllocation allocation) {
|
||||
allocations.put(bucket.getIdentifier(), allocation);
|
||||
bucketsDao.update(bucket);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void addToBucket(BandwidthBucket bucket,
|
||||
BandwidthReservation reservation) {
|
||||
reservations.put(bucket.getIdentifier(), reservation);
|
||||
bucketsDao.update(bucket);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void removeFromBucket(BandwidthBucket bucket,
|
||||
BandwidthAllocation reservation) {
|
||||
allocations.remove(bucket.getIdentifier(), reservation);
|
||||
bucketsDao.update(bucket);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void removeFromBucket(BandwidthBucket bucket,
|
||||
BandwidthReservation reservation) {
|
||||
reservations.remove(bucket.getIdentifier(), reservation);
|
||||
bucketsDao.update(bucket);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String showBucket(BandwidthBucket bucket) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(bucket.toString()).append("\n");
|
||||
|
||||
for (BandwidthAllocation allocation : allocations.get(bucket
|
||||
.getIdentifier())) {
|
||||
sb.append(" ").append(allocation.toString()).append("\n");
|
||||
}
|
||||
for (BandwidthReservation reservation : reservations.get(bucket
|
||||
.getIdentifier())) {
|
||||
sb.append(" ").append(reservation.toString()).append("\n");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public BandwidthAllocation getNextReservation(BandwidthBucket bucket,
|
||||
String agentType) {
|
||||
BandwidthAllocation allocation = null;
|
||||
for (BandwidthAllocation o : allocations.get(bucket.getIdentifier())) {
|
||||
if (RetrievalStatus.READY.equals(o.getStatus())
|
||||
&& o.getAgentType().equals(agentType)) {
|
||||
allocation = o;
|
||||
allocation.setStatus(RetrievalStatus.PROCESSING);
|
||||
// Persist this change to the database
|
||||
bandwidthDao.createOrUpdate(allocation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return allocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<BandwidthAllocation> getBandwidthAllocationsForBucket(
|
||||
BandwidthBucket bucket) {
|
||||
return new ArrayList<BandwidthAllocation>(allocations.get(bucket
|
||||
.getIdentifier()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<BandwidthReservation> getBandwidthReservationsForBucket(
|
||||
BandwidthBucket bucket) {
|
||||
return new ArrayList<BandwidthReservation>(reservations.get(bucket
|
||||
.getIdentifier()));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void copyState(IBandwidthBucketAllocationAssociator other) {
|
||||
for (Network network : Network.values()) {
|
||||
final List<BandwidthBucket> buckets = bucketsDao.getAll(network);
|
||||
for (BandwidthBucket bucket : buckets) {
|
||||
|
||||
final List<BandwidthAllocation> bandwidthAllocationsForBucket = other
|
||||
.getBandwidthAllocationsForBucket(bucket);
|
||||
for (BandwidthAllocation allocation : bandwidthAllocationsForBucket) {
|
||||
this.addToBucket(bucket, allocation);
|
||||
}
|
||||
|
||||
final List<BandwidthReservation> bandwidthReservationsForBucket = other
|
||||
.getBandwidthReservationsForBucket(bucket);
|
||||
for (BandwidthReservation reservation : bandwidthReservationsForBucket) {
|
||||
this.addToBucket(bucket, reservation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ import java.util.TreeMap;
|
|||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* Oct 17, 2012 0726 djohnson If unable to find a bucket with floorKey, use ceilingKey.
|
||||
* Oct 26, 2012 1286 djohnson Return list of unscheduled allocations.
|
||||
* Jan 25, 2013 1528 djohnson Lower priority requests should not be able to unschedule higher priority requests.
|
||||
* Jun 25, 2013 2106 djohnson Access bandwidth bucket contents through RetrievalPlan.
|
||||
* </pre>
|
||||
*
|
||||
* @version 1.0
|
||||
|
@ -178,7 +179,8 @@ public class PriorityRetrievalScheduler implements IRetrievalScheduler {
|
|||
long total = 0;
|
||||
List<BandwidthAllocation> lowerPriorityRequests = new ArrayList<BandwidthAllocation>();
|
||||
for (BandwidthBucket bucket : window) {
|
||||
for (BandwidthAllocation o : bucket.getRequests()) {
|
||||
for (BandwidthAllocation o : plan
|
||||
.getBandwidthAllocationsForBucket(bucket)) {
|
||||
long estimatedSizeInBytes = o.getEstimatedSizeInBytes();
|
||||
// This was bad... we just about released giving lower
|
||||
// priority requests the ability to unschedule higher priority
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
@ -36,6 +37,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalManagerNotifyEvent;
|
|||
* 3/18/2013 1802 bphillip Event bus registration is now a post-construct operation to ensure proxy is registered with bus
|
||||
* 3/13/2013 1802 bphillip Moved event bus registration from post-construct to spring static method call
|
||||
* Jun 13, 2013 2095 djohnson Can schedule any subclass of BandwidthAllocation.
|
||||
* Jun 25, 2013 2106 djohnson Copy state from another instance, add ability to check for proposed bandwidth throughput changes.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -235,4 +237,55 @@ public class RetrievalManager {
|
|||
notifier.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fromRetrievalManager
|
||||
*/
|
||||
public void copyState(RetrievalManager fromRetrievalManager) {
|
||||
for (Entry<Network, RetrievalPlan> entry : fromRetrievalManager.retrievalPlans
|
||||
.entrySet()) {
|
||||
final Network network = entry.getKey();
|
||||
final RetrievalPlan fromPlan = entry.getValue();
|
||||
final RetrievalPlan toPlan = this.retrievalPlans.get(network);
|
||||
|
||||
toPlan.copyState(fromPlan);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a change in the bandwidth throughput is being proposed.
|
||||
*
|
||||
* @param proposedRetrievalManager
|
||||
* the other retrieval manager with any proposed changes
|
||||
* @return true if a bandwidth throughput change is being proposed
|
||||
*/
|
||||
public boolean isProposingBandwidthChanges(
|
||||
RetrievalManager proposedRetrievalManager) {
|
||||
boolean proposingBandwidthChanges = false;
|
||||
|
||||
// If any retrieval plans have a different value for bandwidth, then
|
||||
// return true
|
||||
for (Entry<Network, RetrievalPlan> entry : this.retrievalPlans
|
||||
.entrySet()) {
|
||||
final RetrievalPlan proposedRetrievalPlan = proposedRetrievalManager.retrievalPlans
|
||||
.get(entry.getKey());
|
||||
if (proposedRetrievalPlan.getDefaultBandwidth() != entry.getValue()
|
||||
.getDefaultBandwidth()) {
|
||||
proposingBandwidthChanges = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return proposingBandwidthChanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the retrieval plans.
|
||||
*/
|
||||
public void initRetrievalPlans() {
|
||||
for (RetrievalPlan retrievalPlan : this.getRetrievalPlans().values()) {
|
||||
retrievalPlan.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,11 @@
|
|||
package com.raytheon.uf.edex.datadelivery.bandwidth.retrieval;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
@ -21,8 +15,12 @@ import com.raytheon.uf.common.datadelivery.registry.Network;
|
|||
import com.raytheon.uf.common.serialization.SerializationException;
|
||||
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.util.TimeUtil;
|
||||
import com.raytheon.uf.edex.database.DataAccessLayerException;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
||||
|
||||
|
@ -40,243 +38,26 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* Oct 16, 2012 0726 djohnson Fix bug never updating allocations in memory.
|
||||
* Oct 23, 2012 1286 djohnson Add ability to get/set the default bandwidth.
|
||||
* Nov 20, 2012 1286 djohnson Handle null bucketIds being returned.
|
||||
* Jun 25, 2013 2106 djohnson Separate state into other classes, promote BandwidthBucket to a class proper.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
// TODO: Need to enable transactions from BandwidthManager forward
|
||||
// @Service
|
||||
// @Transactional(propagation = MANDATORY)
|
||||
public class RetrievalPlan {
|
||||
|
||||
private static final IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(RetrievalPlan.class);
|
||||
|
||||
/**
|
||||
* Representation of a bucket of bandwidth. Any methods that directly access
|
||||
* fields or mutate objects should be private, and all access should go
|
||||
* through {@link RetrievalPlan}.
|
||||
*/
|
||||
public class BandwidthBucket implements Comparable<BandwidthBucket> {
|
||||
|
||||
// Number of allocated bytes
|
||||
private long currentSize;
|
||||
|
||||
private final List<BandwidthReservation> reservations = new ArrayList<BandwidthReservation>();
|
||||
|
||||
private final List<BandwidthAllocation> allocations = new ArrayList<BandwidthAllocation>();
|
||||
|
||||
// Number of bytes of bandwidth;
|
||||
private final long bucketSize;
|
||||
|
||||
private final long bucketStartTime;
|
||||
|
||||
public BandwidthBucket(long bucketStartTime, long sizeInBytes) {
|
||||
this.bucketStartTime = bucketStartTime;
|
||||
this.bucketSize = sizeInBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the allocation. Private because all interaction should go through
|
||||
* RetrievalPlan.
|
||||
*
|
||||
* @param allocation
|
||||
* the allocation to add
|
||||
*/
|
||||
private void add(BandwidthAllocation allocation) {
|
||||
allocations.add(allocation);
|
||||
currentSize += allocation.getEstimatedSizeInBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the reservation. Private because all interaction should go
|
||||
* through RetrievalPlan.
|
||||
*
|
||||
* @param reservation
|
||||
* the reservation to add
|
||||
*/
|
||||
private void add(BandwidthReservation reservation) {
|
||||
reservations.add(reservation);
|
||||
currentSize += reservation.getSizeInBytes();
|
||||
}
|
||||
|
||||
public long getAvailableBandwidth() {
|
||||
return Math.max(0, bucketSize - currentSize);
|
||||
}
|
||||
|
||||
public long getBucketSize() {
|
||||
return bucketSize;
|
||||
}
|
||||
|
||||
public long getBucketStartTime() {
|
||||
return bucketStartTime;
|
||||
}
|
||||
|
||||
public long getCurrentSize() {
|
||||
return currentSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next allocation to be processed. Private because all access
|
||||
* should go through RetrievalPlan.
|
||||
*
|
||||
* @param agentType
|
||||
* the agent type
|
||||
* @return the allocation, or null if there is none to process
|
||||
*/
|
||||
private BandwidthAllocation getNextReservation(String agentType) {
|
||||
BandwidthAllocation allocation = null;
|
||||
for (BandwidthAllocation o : allocations) {
|
||||
if (RetrievalStatus.READY.equals(o.getStatus())
|
||||
&& o.getAgentType().equals(agentType)) {
|
||||
allocation = o;
|
||||
allocation.setStatus(RetrievalStatus.PROCESSING);
|
||||
// Persist this change to the database
|
||||
bandwidthDao.createOrUpdate(allocation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return allocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* A read-only look at what requests are available in this bucket.
|
||||
*
|
||||
* @return the unmodifiable list of requests
|
||||
*/
|
||||
public List<BandwidthAllocation> getRequests() {
|
||||
return Collections.unmodifiableList(allocations);
|
||||
}
|
||||
|
||||
/**
|
||||
* A read-only look at what reservations are available in this bucket.
|
||||
*
|
||||
* @return the unmodifiable list of reservations
|
||||
*/
|
||||
public List<BandwidthReservation> getReservations() {
|
||||
return Collections.unmodifiableList(reservations);
|
||||
}
|
||||
|
||||
public String showReservations() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(toString()).append("\n");
|
||||
|
||||
for (BandwidthAllocation allocation : allocations) {
|
||||
sb.append(" ").append(allocation.toString()).append("\n");
|
||||
}
|
||||
for (BandwidthReservation reservation : reservations) {
|
||||
sb.append(" ").append(reservation.toString()).append("\n");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Calendar b = BandwidthUtil.now();
|
||||
b.setTimeInMillis(bucketStartTime);
|
||||
sb.append("Bucket [").append(BandwidthUtil.format(b));
|
||||
sb.append("] bandwidth [").append(bucketSize);
|
||||
sb.append("] available [").append(getAvailableBandwidth())
|
||||
.append("]);");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the bandwidth allocation or reservation by its id. Private
|
||||
* because all access should go through RetrievalPlan.
|
||||
*
|
||||
* @param id
|
||||
* the id of the allocation/reservation
|
||||
*/
|
||||
private void remove(long id) {
|
||||
|
||||
|
||||
for (Iterator<BandwidthAllocation> itr = allocations.iterator();itr.hasNext();) {
|
||||
BandwidthAllocation reservation = itr.next();
|
||||
if (reservation.getId() == id) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<BandwidthReservation> itr = reservations.iterator();itr.hasNext();) {
|
||||
BandwidthReservation reservation = itr.next();
|
||||
if (reservation.getId() == id) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
|
||||
long totalSize = 0;
|
||||
// Recalculate the current size since
|
||||
for (BandwidthAllocation allocation : allocations) {
|
||||
totalSize += allocation.getEstimatedSizeInBytes();
|
||||
}
|
||||
|
||||
for (BandwidthReservation reservation : reservations) {
|
||||
totalSize += reservation.getSizeInBytes();
|
||||
}
|
||||
currentSize = totalSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this bucket is empty.
|
||||
*
|
||||
* @return true if empty
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return currentSize == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ (int) (bucketStartTime ^ (bucketStartTime >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
BandwidthBucket other = (BandwidthBucket) obj;
|
||||
if (bucketStartTime != other.bucketStartTime)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(BandwidthBucket o) {
|
||||
if (this.bucketStartTime > o.bucketStartTime) {
|
||||
return 1;
|
||||
} else if (this.bucketStartTime < o.bucketStartTime) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final IBandwidthDao bandwidthDao;
|
||||
private IBandwidthDao bandwidthDao;
|
||||
|
||||
// which retrieval plan
|
||||
private final Network network;
|
||||
private Network network;
|
||||
|
||||
private final BandwidthMap map;
|
||||
private BandwidthMap map;
|
||||
|
||||
// The scheduler used to insert retrievals into the plan
|
||||
private IRetrievalScheduler scheduler;
|
||||
|
@ -288,8 +69,10 @@ public class RetrievalPlan {
|
|||
// must acquire the locks in the following order: buckets first, then
|
||||
// requestMap
|
||||
|
||||
// access to buckets should always be synchronized on buckets itself..
|
||||
private final NavigableMap<Long, BandwidthBucket> buckets = new TreeMap<Long, BandwidthBucket>();
|
||||
private IBandwidthBucketDao bucketsDao;
|
||||
|
||||
// access to buckets should always be synchronized on bucketsLock..
|
||||
private final Object bucketsLock = new Object();
|
||||
|
||||
// access to requestMap should always be synchronized on requestMap itself..
|
||||
private final Map<Long, Set<Long>> requestMap = new HashMap<Long, Set<Long>>();
|
||||
|
@ -303,20 +86,19 @@ public class RetrievalPlan {
|
|||
|
||||
private long bytesPerBucket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param network
|
||||
* The Network to create the RetrievalPlan for.
|
||||
*
|
||||
* @param map
|
||||
* The BandwidthMap Object to use to initialize the plan.
|
||||
*/
|
||||
public RetrievalPlan(Network network, BandwidthMap map,
|
||||
IBandwidthDao bandwidthDao) {
|
||||
this.network = network;
|
||||
this.bandwidthDao = bandwidthDao;
|
||||
this.map = map;
|
||||
private IBandwidthBucketAllocationAssociator associator;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public RetrievalPlan() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the retrieval plan. Intentionally package-private as it should
|
||||
* only be called by {@link RetrievalManager}.
|
||||
*/
|
||||
void init() {
|
||||
boolean found = false;
|
||||
BandwidthRoute route = map.getRoute(network);
|
||||
if (route != null) {
|
||||
|
@ -342,10 +124,10 @@ public class RetrievalPlan {
|
|||
// bucket minutes)/bits per byte) ...
|
||||
bytesPerBucket = BandwidthUtil
|
||||
.convertKilobytesPerSecondToBytesPerSpecifiedMinutes(
|
||||
bw,
|
||||
bucketMinutes);
|
||||
bw, bucketMinutes);
|
||||
|
||||
buckets.put(bucket, new BandwidthBucket(bucket, bytesPerBucket));
|
||||
bucketsDao.create(new BandwidthBucket(bucket, bytesPerBucket,
|
||||
network));
|
||||
currentBucket.add(Calendar.MINUTE, bucketMinutes);
|
||||
}
|
||||
} else {
|
||||
|
@ -392,7 +174,7 @@ public class RetrievalPlan {
|
|||
resize();
|
||||
}
|
||||
|
||||
synchronized (buckets) {
|
||||
synchronized (bucketsLock) {
|
||||
return scheduler.schedule(this, bandwidthAllocation);
|
||||
}
|
||||
}
|
||||
|
@ -425,13 +207,13 @@ public class RetrievalPlan {
|
|||
// to make sure that the plan maintains "planDays" of schedule..
|
||||
if (newEndOfPlan.after(planEnd)) {
|
||||
|
||||
synchronized (buckets) {
|
||||
synchronized (bucketsLock) {
|
||||
// Get the last bucket and add buckets to make up the
|
||||
// difference..
|
||||
// Make the buckets...
|
||||
long bucket = buckets.lastKey();
|
||||
BandwidthBucket bucket = bucketsDao.getLastBucket(network);
|
||||
Calendar currentBucket = BandwidthUtil.now();
|
||||
currentBucket.setTimeInMillis(bucket);
|
||||
currentBucket.setTimeInMillis(bucket.getBucketStartTime());
|
||||
|
||||
// Add the buckets minutes to the last bucket and add
|
||||
// buckets until we have the new plan size.
|
||||
|
@ -439,15 +221,15 @@ public class RetrievalPlan {
|
|||
|
||||
while (!currentBucket.after(newEndOfPlan)) {
|
||||
int bw = map.getBandwidth(network, currentBucket);
|
||||
bucket = currentBucket.getTimeInMillis();
|
||||
long bucketStartTime = currentBucket.getTimeInMillis();
|
||||
// Get the bucket size..
|
||||
// buckets are (bandwidth * kilobits/second * 60 seconds *
|
||||
// bucket minutes)/bits per byte) ...
|
||||
bytesPerBucket = BandwidthUtil
|
||||
.convertKilobytesPerSecondToBytesPerSpecifiedMinutes(
|
||||
bw, bucketMinutes);
|
||||
buckets.put(bucket, new BandwidthBucket(bucket,
|
||||
bytesPerBucket));
|
||||
bw, bucketMinutes);
|
||||
bucketsDao.create(new BandwidthBucket(bucketStartTime,
|
||||
bytesPerBucket, network));
|
||||
currentBucket.add(Calendar.MINUTE, bucketMinutes);
|
||||
statusHandler.info("resize() - Adding bucket [" + bucket
|
||||
+ "] bandwidth = [" + bw + "]");
|
||||
|
@ -458,18 +240,12 @@ public class RetrievalPlan {
|
|||
// Now remove buckets from the front of the map whos time slot
|
||||
// is past and are empty
|
||||
long newStart = newStartOfPlan.getTimeInMillis();
|
||||
NavigableMap<Long, BandwidthBucket> x = buckets.headMap(newStart, true);
|
||||
Iterator<Long> itr = x.keySet().iterator();
|
||||
while (itr.hasNext()) {
|
||||
Long key = itr.next();
|
||||
BandwidthBucket b = x.get(key);
|
||||
// If the bucket is empty, remove it from the Map,
|
||||
// which should result in removal from the parent Map,
|
||||
if (b.isEmpty()) {
|
||||
statusHandler.info("resize() - Removing bucket ["
|
||||
+ b.getBucketStartTime() + "]");
|
||||
itr.remove();
|
||||
}
|
||||
|
||||
try {
|
||||
bucketsDao.deleteEmptyBucketsUpToTime(newStart, network);
|
||||
} catch (DataAccessLayerException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Unable to remove empty buckets!", e);
|
||||
}
|
||||
|
||||
this.planStart = newStartOfPlan;
|
||||
|
@ -480,20 +256,33 @@ public class RetrievalPlan {
|
|||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the contents of the {@link RetrievalPlan}.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String showPlan() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
synchronized (buckets) {
|
||||
Iterator<Long> itr = buckets.keySet().iterator();
|
||||
while (itr.hasNext()) {
|
||||
BandwidthBucket bucket = getBucket(itr.next());
|
||||
sb.append(bucket.showReservations());
|
||||
}
|
||||
List<BandwidthBucket> buckets = bucketsDao.getAll(network);
|
||||
for (BandwidthBucket bucket : buckets) {
|
||||
sb.append(showBucket(bucket));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the contents of the {@link BandwidthBucket}.
|
||||
*
|
||||
* @param bucket
|
||||
* the bucket
|
||||
* @return the String to display
|
||||
*/
|
||||
public String showBucket(BandwidthBucket bucket) {
|
||||
return associator.showBucket(bucket);
|
||||
}
|
||||
|
||||
public void setPlanDays(int planDays) {
|
||||
this.planDays = planDays;
|
||||
}
|
||||
|
@ -502,6 +291,26 @@ public class RetrievalPlan {
|
|||
return planDays;
|
||||
}
|
||||
|
||||
public void setNetwork(Network network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public void setMap(BandwidthMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public void setBandwidthDao(IBandwidthDao bandwidthDao) {
|
||||
this.bandwidthDao = bandwidthDao;
|
||||
}
|
||||
|
||||
public void setBucketsDao(IBandwidthBucketDao bucketsDao) {
|
||||
this.bucketsDao = bucketsDao;
|
||||
}
|
||||
|
||||
public void setAssociator(IBandwidthBucketAllocationAssociator associator) {
|
||||
this.associator = associator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next scheduled RetrievalRequest..
|
||||
*
|
||||
|
@ -512,17 +321,18 @@ public class RetrievalPlan {
|
|||
public BandwidthAllocation nextAllocation(String agentType) {
|
||||
BandwidthAllocation reservation = null;
|
||||
|
||||
synchronized (buckets) {
|
||||
synchronized (bucketsLock) {
|
||||
|
||||
// Get the portion of the Map that is before the
|
||||
// current time (DO NOT want to return future reservations)
|
||||
SortedMap<Long, BandwidthBucket> available = buckets
|
||||
.headMap(buckets.ceilingKey(TimeUtil.currentTimeMillis() + 1));
|
||||
final List<BandwidthBucket> buckets = bucketsDao
|
||||
.getWhereStartTimeIsLessThanOrEqualTo(
|
||||
TimeUtil.currentTimeMillis(), network);
|
||||
|
||||
// Iterate over the buckets and find the first
|
||||
// BandwidthAllocation that is in the READY state
|
||||
for (BandwidthBucket bucket : available.values()) {
|
||||
reservation = bucket.getNextReservation(agentType);
|
||||
for (BandwidthBucket bucket : buckets) {
|
||||
reservation = associator.getNextReservation(bucket, agentType);
|
||||
if (reservation != null) {
|
||||
break;
|
||||
}
|
||||
|
@ -532,12 +342,6 @@ public class RetrievalPlan {
|
|||
return reservation;
|
||||
}
|
||||
|
||||
private NavigableMap<Long, BandwidthBucket> getBuckets() {
|
||||
synchronized (buckets) {
|
||||
return buckets;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRequestMapping(long requestId,
|
||||
Set<BandwidthBucket> buckets) {
|
||||
Set<Long> bucketIds = new TreeSet<Long>();
|
||||
|
@ -550,9 +354,42 @@ public class RetrievalPlan {
|
|||
}
|
||||
}
|
||||
|
||||
public void remove(BandwidthAllocation reservation) {
|
||||
/**
|
||||
* Remove the {@link BandwidthAllocation} from the {@link RetrievalPlan}.
|
||||
*
|
||||
* @param allocation
|
||||
* the allocation
|
||||
*/
|
||||
public void remove(BandwidthAllocation allocation) {
|
||||
|
||||
synchronized (buckets) {
|
||||
synchronized (bucketsLock) {
|
||||
// Must have both monitors
|
||||
synchronized (requestMap) {
|
||||
Set<Long> bucketIds = requestMap.get(allocation.getId());
|
||||
if (bucketIds == null) {
|
||||
// This can happen when an allocation/reservation is in a
|
||||
// DEFERRED state, at a minimum
|
||||
return;
|
||||
}
|
||||
for (Long bucketId : bucketIds) {
|
||||
BandwidthBucket bucket = getBucket(bucketId);
|
||||
bucket.setCurrentSize(bucket.getCurrentSize()
|
||||
- allocation.getEstimatedSizeInBytes());
|
||||
associator.removeFromBucket(bucket, allocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the {@link BandwidthReservation} from the {@link RetrievalPlan}.
|
||||
*
|
||||
* @param reservation
|
||||
* the reservation
|
||||
*/
|
||||
public void remove(BandwidthReservation reservation) {
|
||||
|
||||
synchronized (bucketsLock) {
|
||||
// Must have both monitors
|
||||
synchronized (requestMap) {
|
||||
Set<Long> bucketIds = requestMap.get(reservation.getId());
|
||||
|
@ -563,7 +400,9 @@ public class RetrievalPlan {
|
|||
}
|
||||
for (Long bucketId : bucketIds) {
|
||||
BandwidthBucket bucket = getBucket(bucketId);
|
||||
bucket.remove(reservation.getId());
|
||||
bucket.setCurrentSize(bucket.getCurrentSize()
|
||||
- reservation.getSizeInBytes());
|
||||
associator.removeFromBucket(bucket, reservation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -590,7 +429,7 @@ public class RetrievalPlan {
|
|||
*/
|
||||
public void updateBandwidthReservation(BandwidthAllocation allocation) {
|
||||
final long id = allocation.getId();
|
||||
synchronized (buckets) {
|
||||
synchronized (bucketsLock) {
|
||||
// Must have both monitors
|
||||
synchronized (requestMap) {
|
||||
if (!requestMap.containsKey(id)) {
|
||||
|
@ -598,13 +437,11 @@ public class RetrievalPlan {
|
|||
.warn("The request map should always contain a mapping for a bandwidth allocation prior to reaching this point. "
|
||||
+ "Adding to the map manually, but seeing this message without expecting it signifies a logic error, "
|
||||
+ "and bandwidth is not being properly managed!");
|
||||
BandwidthBucket bucket = buckets.firstEntry().getValue();
|
||||
bucket.add(allocation);
|
||||
BandwidthBucket bucket = bucketsDao.getFirstBucket(network);
|
||||
addToBucket(bucket, allocation);
|
||||
allocation.setBandwidthBucket(bucket.getBucketStartTime());
|
||||
bandwidthDao.createOrUpdate(allocation);
|
||||
|
||||
bucket.add(allocation);
|
||||
|
||||
TreeSet<BandwidthBucket> set = Sets.newTreeSet();
|
||||
set.add(bucket);
|
||||
updateRequestMapping(id, set);
|
||||
|
@ -613,26 +450,8 @@ public class RetrievalPlan {
|
|||
Set<Long> bucketIds = requestMap.get(id);
|
||||
for (Long bucketId : bucketIds) {
|
||||
BandwidthBucket bucket = getBucket(bucketId);
|
||||
// Remove the existing version with the same ID and replace
|
||||
// it
|
||||
int indexToReplace = -1;
|
||||
// Direct access to allocations here, because the getter
|
||||
// returns an unmodifiable version for public access
|
||||
List<BandwidthAllocation> requests = bucket.allocations;
|
||||
for (int i = 0; i < requests.size(); i++) {
|
||||
BandwidthAllocation current = requests.get(i);
|
||||
if (current.getId() == id) {
|
||||
indexToReplace = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (indexToReplace > -1) {
|
||||
requests.set(indexToReplace, allocation);
|
||||
} else {
|
||||
statusHandler.warn("Unable to find allocation [" + id
|
||||
+ "] for replacement in the bucket!");
|
||||
}
|
||||
associator.removeFromBucket(bucket, allocation);
|
||||
associator.addToBucket(bucket, allocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -648,34 +467,12 @@ public class RetrievalPlan {
|
|||
* if no bucket exists with the id
|
||||
*/
|
||||
public BandwidthBucket getBucket(long bucketId) {
|
||||
BandwidthBucket bucket = getBuckets().get(bucketId);
|
||||
BandwidthBucket bucket = bucketsDao.getByStartTime(bucketId, network);
|
||||
Preconditions.checkNotNull(bucket,
|
||||
"Unable to find bucket for start time [" + bucketId + "]");
|
||||
return bucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the greatest key less than or equal to the given key, or null if
|
||||
* there is no such key.
|
||||
*
|
||||
* @param key
|
||||
* @return the floored key, or null
|
||||
*/
|
||||
private Long floorBucket(long key) {
|
||||
return getBuckets().floorKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the least key greater than or equal to the given key, or null if
|
||||
* there is no such key.
|
||||
*
|
||||
* @param key
|
||||
* @return the ceiling-ed key, or null
|
||||
*/
|
||||
private Long ceilingKey(long key) {
|
||||
return getBuckets().ceilingKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the buckets in the specified window, both boundaries are
|
||||
* inclusive. Buckets will be in order of their start time.
|
||||
|
@ -687,40 +484,9 @@ public class RetrievalPlan {
|
|||
* @return the buckets in the window, sorted in ascending order of start
|
||||
* time
|
||||
*/
|
||||
public SortedSet<BandwidthBucket> getBucketsInWindow(Long startMillis,
|
||||
Long endMillis) {
|
||||
// Get the bucket for the startTime and endTime.
|
||||
Long startKey = floorBucket(startMillis);
|
||||
if (startKey == null) {
|
||||
// TODO: If this happens a lot (monitor log message frequency)
|
||||
// then change the default behavior to just use a ceilingKey
|
||||
startKey = ceilingKey(startMillis);
|
||||
statusHandler
|
||||
.info(String
|
||||
.format("Unable to find bucket before or up to [%s] using nearest bucket of [%s]",
|
||||
startMillis, startKey));
|
||||
}
|
||||
Long endKey = floorBucket(endMillis);
|
||||
if (endKey == null) {
|
||||
endKey = ceilingKey(startMillis);
|
||||
}
|
||||
|
||||
// Handle the case where an invalid range was somehow specified
|
||||
// (shouldn't happen, so just throw an exception with as much
|
||||
// information as we have)
|
||||
if (startKey == null || endKey == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Invalid start and end times requested for getBucketsInWindow(): start time [%s], end time [%s], bucket start key [%s], bucket end key [%s]. "
|
||||
+ "Plan boundaries: start [%s] end [%s]",
|
||||
startMillis, endMillis, startKey, endKey,
|
||||
BandwidthUtil.format(getPlanStart()),
|
||||
BandwidthUtil.format(getPlanEnd())));
|
||||
}
|
||||
|
||||
NavigableMap<Long, BandwidthBucket> window = getBuckets().subMap(
|
||||
startKey, true, endKey, true);
|
||||
return new TreeSet<BandwidthBucket>(window.values());
|
||||
public SortedSet<BandwidthBucket> getBucketsInWindow(long earliestTime,
|
||||
long latestTime) {
|
||||
return bucketsDao.getBucketsInWindow(earliestTime, latestTime, network);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -733,12 +499,15 @@ public class RetrievalPlan {
|
|||
* @throws NullPointerException
|
||||
* if the bucket start time is invalid
|
||||
*/
|
||||
public void addToBucket(BandwidthBucket bucket, BandwidthAllocation allocation) {
|
||||
public void addToBucket(BandwidthBucket bucket,
|
||||
BandwidthAllocation allocation) {
|
||||
long bucketStartTime = bucket.getBucketStartTime();
|
||||
|
||||
synchronized (buckets) {
|
||||
synchronized (bucketsLock) {
|
||||
BandwidthBucket actualBucket = getBucket(bucketStartTime);
|
||||
actualBucket.add(allocation);
|
||||
actualBucket.setCurrentSize(actualBucket.getCurrentSize()
|
||||
+ allocation.getEstimatedSizeInBytes());
|
||||
associator.addToBucket(actualBucket, allocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -756,12 +525,38 @@ public class RetrievalPlan {
|
|||
BandwidthReservation reservation) {
|
||||
long bucketStartTime = bucket.getBucketStartTime();
|
||||
|
||||
synchronized (buckets) {
|
||||
synchronized (bucketsLock) {
|
||||
BandwidthBucket actualBucket = getBucket(bucketStartTime);
|
||||
actualBucket.add(reservation);
|
||||
actualBucket.setCurrentSize(actualBucket.getCurrentSize()
|
||||
+ reservation.getSizeInBytes());
|
||||
associator.addToBucket(actualBucket, reservation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the {@link BandwidthAllocation}s for a {@link BandwidthBucket}.
|
||||
*
|
||||
* @param bucket
|
||||
* the bucket
|
||||
* @return the bandwidth allocations
|
||||
*/
|
||||
public List<BandwidthAllocation> getBandwidthAllocationsForBucket(
|
||||
BandwidthBucket bucket) {
|
||||
return associator.getBandwidthAllocationsForBucket(bucket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the {@link BandwidthReservation}s for a {@link BandwidthBucket}.
|
||||
*
|
||||
* @param bucket
|
||||
* the bucket
|
||||
* @return the bandwidth reservations
|
||||
*/
|
||||
public List<BandwidthReservation> getBandwidthReservationsForBucket(
|
||||
BandwidthBucket bucket) {
|
||||
return associator.getBandwidthReservationsForBucket(bucket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of minutes each bucket, by default, contains.
|
||||
*
|
||||
|
@ -770,4 +565,23 @@ public class RetrievalPlan {
|
|||
public int getBucketMinutes() {
|
||||
return bucketMinutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy state from the specied {@link RetrievalPlan}.
|
||||
*
|
||||
* @param fromPlan
|
||||
* the other plan
|
||||
*/
|
||||
public void copyState(RetrievalPlan fromPlan) {
|
||||
this.bucketsDao.copyState(fromPlan.bucketsDao);
|
||||
this.bucketMinutes = fromPlan.bucketMinutes;
|
||||
this.bytesPerBucket = fromPlan.bytesPerBucket;
|
||||
this.planDays = fromPlan.planDays;
|
||||
this.planEnd = BandwidthUtil.copy(fromPlan.planEnd);
|
||||
this.planStart = BandwidthUtil.copy(fromPlan.planStart);
|
||||
this.requestMap.clear();
|
||||
this.requestMap.putAll(fromPlan.requestMap);
|
||||
this.associator.copyState(fromPlan.associator);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,7 +47,8 @@ import com.raytheon.uf.edex.datadelivery.retrieval.db.RetrievalRequestRecord;
|
|||
* Oct 10, 2012 0726 djohnson Add generics, constants, defaultPriority.
|
||||
* Nov 26, 2012 dhladky Override default ingest routes based on plugin
|
||||
* Jan 30, 2013 1543 djohnson Should not implement IRetrievalHandler.
|
||||
* Feb 05, 2013 1580 mpduff EventBus refactor.
|
||||
* Feb 05, 2013 1580 mpduff EventBus refactor.
|
||||
* Jun 24, 2013 2106 djohnson Set actual start time when sending to retrieval rather than overwrite scheduled start.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -102,7 +103,7 @@ public class SubscriptionRetrievalAgent extends
|
|||
bundle.setConnection(provider.getConnection());
|
||||
bundle.setSubscription(sub);
|
||||
|
||||
retrieval.setStartTime(TimeUtil.newCalendar());
|
||||
retrieval.setActualStart(TimeUtil.newCalendar());
|
||||
retrieval.setStatus(RetrievalStatus.RETRIEVAL);
|
||||
|
||||
// update database
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.raytheon.uf.edex.datadelivery.bandwidth.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -8,7 +7,6 @@ import com.raytheon.uf.common.datadelivery.registry.DataSetMetaData;
|
|||
import com.raytheon.uf.common.datadelivery.registry.DataType;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Subscription;
|
||||
import com.raytheon.uf.common.serialization.SerializationException;
|
||||
import com.raytheon.uf.common.serialization.SerializationUtil;
|
||||
import com.raytheon.uf.common.time.util.TimeUtil;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthDataSetUpdate;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription;
|
||||
|
@ -28,6 +26,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription;
|
|||
* Dec 11, 2012 1403 djohnson No longer valid to run without bandwidth management.
|
||||
* Feb 14, 2013 1595 djohnson Use subscription rescheduling strategy.
|
||||
* Jun 13, 2013 2095 djohnson Point subscriptions don't check for dataset updates on aggregation.
|
||||
* Jun 25, 2013 2106 djohnson CheapClone was cheap in ease, not performance.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -245,24 +244,6 @@ public class BandwidthUtil {
|
|||
return dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a cheap clone by dynamically serializing (via thrift) the object
|
||||
* and then deserializing it.
|
||||
*
|
||||
* @param clazz
|
||||
* the class type
|
||||
* @param t
|
||||
* the object
|
||||
* @return the cloned object
|
||||
* @throws SerializationException
|
||||
* on error serializing
|
||||
*/
|
||||
public static <T extends Serializable> T cheapClone(Class<T> clazz, T t)
|
||||
throws SerializationException {
|
||||
return SerializationUtil.transformFromThrift(clazz,
|
||||
SerializationUtil.transformToThrift(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the number of kilobytes per second to bytes for the number of
|
||||
* specified minutes.
|
||||
|
|
|
@ -73,12 +73,12 @@ import com.raytheon.uf.common.time.util.TimeUtil;
|
|||
import com.raytheon.uf.common.time.util.TimeUtilTest;
|
||||
import com.raytheon.uf.common.util.TestUtil;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.notification.BandwidthEventBus;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlanTest;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus;
|
||||
import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalManagerNotifyEvent;
|
||||
|
@ -105,6 +105,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalManagerNotifyEvent;
|
|||
* Apr 29, 2013 1910 djohnson Always shutdown bandwidth managers in tests.
|
||||
* Jun 03, 2013 2038 djohnson Add support for point data based subscriptions.
|
||||
* Jun 03, 2013 2095 djohnson Move getPointDataSet to superclass.
|
||||
* Jun 25, 2013 2106 djohnson Set subscription latency, access bucket allocations through RetrievalPlan.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -184,8 +185,7 @@ public class BandwidthManagerIntTest extends AbstractWfoBandwidthManagerIntTest
|
|||
bandwidthManager.subscriptionUpdated(subscription);
|
||||
|
||||
final List<SubscriptionRetrieval> subscriptionRetrievals = bandwidthDao
|
||||
.getSubscriptionRetrievals(providerName,
|
||||
dataSetName);
|
||||
.getSubscriptionRetrievals(providerName, dataSetName);
|
||||
|
||||
// We're going to send in a point data update with a time span that
|
||||
// bridges these two retrievals
|
||||
|
@ -225,8 +225,8 @@ public class BandwidthManagerIntTest extends AbstractWfoBandwidthManagerIntTest
|
|||
bandwidthManager.updatePointDataSetMetaData(metadata);
|
||||
|
||||
final SortedSet<SubscriptionRetrieval> readyRetrievals = bandwidthDao
|
||||
.getSubscriptionRetrievals(providerName,
|
||||
dataSetName, RetrievalStatus.READY);
|
||||
.getSubscriptionRetrievals(providerName, dataSetName,
|
||||
RetrievalStatus.READY);
|
||||
assertThat(readyRetrievals, hasSize(2));
|
||||
assertThat(readyRetrievals, contains(thirdRetrieval, fourthRetrieval));
|
||||
}
|
||||
|
@ -308,6 +308,7 @@ public class BandwidthManagerIntTest extends AbstractWfoBandwidthManagerIntTest
|
|||
// Store the original subscription
|
||||
Subscription subscription = SiteSubscriptionFixture.INSTANCE.get();
|
||||
subscription.getTime().setCycleTimes(Collections.<Integer> emptyList());
|
||||
subscription.setLatencyInMinutes(3);
|
||||
DataDeliveryHandlers.getSubscriptionHandler().store(subscription);
|
||||
|
||||
// The dataset metadata update
|
||||
|
@ -1094,11 +1095,13 @@ public class BandwidthManagerIntTest extends AbstractWfoBandwidthManagerIntTest
|
|||
*/
|
||||
private List<BandwidthAllocation> getRetrievalManagerAllocationsForNetwork(
|
||||
Network network) {
|
||||
final SortedSet<BandwidthBucket> buckets = retrievalManager.getPlan(
|
||||
network).getBucketsInWindow(Long.MIN_VALUE, Long.MAX_VALUE);
|
||||
final RetrievalPlan retrievalPlan = retrievalManager.getPlan(network);
|
||||
final SortedSet<BandwidthBucket> buckets = retrievalPlan
|
||||
.getBucketsInWindow(Long.MIN_VALUE, Long.MAX_VALUE);
|
||||
List<BandwidthAllocation> allocations = new ArrayList<BandwidthAllocation>();
|
||||
for (BandwidthBucket bucket : buckets) {
|
||||
allocations.addAll(bucket.getRequests());
|
||||
allocations.addAll(retrievalPlan
|
||||
.getBandwidthAllocationsForBucket(bucket));
|
||||
}
|
||||
return allocations;
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@ import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPri
|
|||
import com.raytheon.uf.common.serialization.SerializationUtil;
|
||||
import com.raytheon.uf.common.time.util.TimeUtil;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.SubscriptionRetrieval;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
||||
|
||||
/**
|
||||
|
@ -74,6 +74,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
|
|||
* Feb 27, 2013 1644 djohnson Bandwidth service is the WFO version.
|
||||
* May 20, 2013 1650 djohnson Add test for returning required dataset size.
|
||||
* Jun 12, 2013 2038 djohnson Add test for returning required dataset size on subscription update.
|
||||
* Jun 25, 2013 2106 djohnson BandwidthBucket is a big boy class now.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
|
|
@ -22,6 +22,7 @@ package com.raytheon.uf.edex.datadelivery.bandwidth;
|
|||
import java.io.File;
|
||||
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthContextFactory;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit;
|
||||
|
||||
|
@ -36,6 +37,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Oct 24, 2012 1286 djohnson Initial creation
|
||||
* Feb 20, 2013 1543 djohnson Pass additional super-class constructor arguments.
|
||||
* Jun 25, 2013 2106 djohnson Add {@link IBandwidthBucketDao}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -50,11 +52,18 @@ public class IntegrationTestBandwidthContextFactory extends
|
|||
*
|
||||
* @param bandwidthDao
|
||||
* the bandwidthDao
|
||||
* @param bandwidthBucketsDao
|
||||
* @param bandwidthManagerCreator
|
||||
* the creator for the bandwidth manager instance
|
||||
* @param dbInit
|
||||
* the database initializer
|
||||
*/
|
||||
IntegrationTestBandwidthContextFactory(IBandwidthDao bandwidthDao,
|
||||
IBandwidthBucketDao bandwidthBucketsDao,
|
||||
IEdexBandwidthManagerCreator bandwidthManagerCreator,
|
||||
IBandwidthDbInit dbInit) {
|
||||
super(bandwidthDao, new IntegrationTestBandwidthInitializer(),
|
||||
super(bandwidthDao, bandwidthBucketsDao,
|
||||
new IntegrationTestBandwidthInitializer(),
|
||||
bandwidthManagerCreator, dbInit);
|
||||
}
|
||||
|
||||
|
@ -73,6 +82,7 @@ public class IntegrationTestBandwidthContextFactory extends
|
|||
*/
|
||||
public static File getIntegrationTestBandwidthMapConfigFile() {
|
||||
return new IntegrationTestBandwidthContextFactory((IBandwidthDao) null,
|
||||
(IBandwidthBucketDao) null,
|
||||
(IEdexBandwidthManagerCreator) null, (IBandwidthDbInit) null)
|
||||
.getBandwidthMapConfigFile();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package com.raytheon.uf.edex.datadelivery.bandwidth;
|
|||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Integration test {@link BandwidthInitializer}.
|
||||
|
@ -47,7 +48,11 @@ public class IntegrationTestBandwidthInitializer implements
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean init(IBandwidthManager instance, IBandwidthDbInit dbInit) {
|
||||
public boolean init(IBandwidthManager instance, IBandwidthDbInit dbInit,
|
||||
RetrievalManager retrievalManager) {
|
||||
|
||||
retrievalManager.initRetrievalPlans();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
<bean id="bandwidthContextFactory"
|
||||
class="com.raytheon.uf.edex.datadelivery.bandwidth.IntegrationTestBandwidthContextFactory">
|
||||
<constructor-arg ref="hibernateBandwidthDao" />
|
||||
<!-- TODO: Switch to use database bandwidth buckets
|
||||
<constructor-arg ref="hibernateBandwidthBucketDao" /> -->
|
||||
<constructor-arg>
|
||||
<bean class="com.raytheon.uf.edex.datadelivery.bandwidth.InMemoryBandwidthBucketDao" />
|
||||
</constructor-arg>
|
||||
<constructor-arg ref="bandwidthManagerCreator" />
|
||||
<constructor-arg ref="hibernateBandwidthDbInit" />
|
||||
</bean>
|
||||
|
|
|
@ -0,0 +1,440 @@
|
|||
/**
|
||||
* 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.CoreMatchers.not;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
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.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.raytheon.uf.common.datadelivery.registry.Network;
|
||||
import com.raytheon.uf.edex.database.DataAccessLayerException;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthBucket;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao;
|
||||
|
||||
/**
|
||||
* Test {@link IBandwidthBucketDao} implementations.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 19, 2013 2106 djohnson Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
@Ignore
|
||||
public abstract class AbstractBandwidthBucketDaoTest {
|
||||
|
||||
protected IBandwidthBucketDao dao;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
dao = getBandwidthBucketDao();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createdBandwidthBucketIsRetrievable() {
|
||||
BandwidthBucket bucket = new BandwidthBucket(1L, 100, Network.OPSNET);
|
||||
|
||||
dao.create(bucket);
|
||||
|
||||
assertThat(
|
||||
"Should have been able to retrieve the bucket by its start time after creating it!",
|
||||
dao.getByStartTime(bucket.getBucketStartTime(),
|
||||
bucket.getNetwork()), is(equalTo(bucket)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bandwidthBucketIsUpdatable() {
|
||||
BandwidthBucket bucket = new BandwidthBucket(1L, 100, Network.OPSNET);
|
||||
|
||||
dao.create(bucket);
|
||||
|
||||
bucket.setBucketSize(10L);
|
||||
|
||||
dao.update(bucket);
|
||||
|
||||
assertThat(
|
||||
"Should have been able to update the bandwidth bucket!",
|
||||
dao.getByStartTime(bucket.getBucketStartTime(),
|
||||
bucket.getNetwork()).getBucketSize(),
|
||||
is(equalTo(bucket.getBucketSize())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteEmptyBucketsUpToTimeRemovesEmptyBucketsBeforeTime()
|
||||
throws DataAccessLayerException {
|
||||
List<BandwidthBucket> bucketsThatShouldBeDeleted = Arrays.asList(
|
||||
new BandwidthBucket(1L, 100, Network.OPSNET),
|
||||
new BandwidthBucket(2L, 100, Network.OPSNET),
|
||||
new BandwidthBucket(3L, 100, Network.OPSNET));
|
||||
|
||||
for (BandwidthBucket bucket : bucketsThatShouldBeDeleted) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
dao.deleteEmptyBucketsUpToTime(4L, Network.OPSNET);
|
||||
|
||||
assertThat(dao.getByStartTime(1L, Network.OPSNET),
|
||||
is(nullValue(BandwidthBucket.class)));
|
||||
assertThat(dao.getByStartTime(2L, Network.OPSNET),
|
||||
is(nullValue(BandwidthBucket.class)));
|
||||
assertThat(dao.getByStartTime(3L, Network.OPSNET),
|
||||
is(nullValue(BandwidthBucket.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteEmptyBucketsUpToTimeRemovesEmptyBucketAtTime()
|
||||
throws DataAccessLayerException {
|
||||
final BandwidthBucket bucket = new BandwidthBucket(3L, 100,
|
||||
Network.OPSNET);
|
||||
|
||||
dao.create(bucket);
|
||||
|
||||
dao.deleteEmptyBucketsUpToTime(bucket.getBucketStartTime(),
|
||||
bucket.getNetwork());
|
||||
|
||||
assertThat(
|
||||
dao.getByStartTime(bucket.getBucketStartTime(),
|
||||
bucket.getNetwork()),
|
||||
is(nullValue(BandwidthBucket.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteEmptyBucketsUpToTimeDoesNotRemoveNonEmptyBucketsBeforeTime()
|
||||
throws DataAccessLayerException {
|
||||
final BandwidthBucket bucketThatShouldNotBeDeleted = new BandwidthBucket(
|
||||
1L, 100, Network.OPSNET);
|
||||
bucketThatShouldNotBeDeleted.setCurrentSize(1L);
|
||||
|
||||
dao.create(bucketThatShouldNotBeDeleted);
|
||||
|
||||
dao.deleteEmptyBucketsUpToTime(4L,
|
||||
bucketThatShouldNotBeDeleted.getNetwork());
|
||||
|
||||
assertThat(dao.getByStartTime(
|
||||
bucketThatShouldNotBeDeleted.getBucketStartTime(),
|
||||
bucketThatShouldNotBeDeleted.getNetwork()), is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteEmptyBucketsUpToTimeDoesNotRemoveNonEmptyBucketsAtTime()
|
||||
throws DataAccessLayerException {
|
||||
final BandwidthBucket bucketThatShouldNotBeDeleted = new BandwidthBucket(
|
||||
1L, 100, Network.OPSNET);
|
||||
bucketThatShouldNotBeDeleted.setCurrentSize(1L);
|
||||
|
||||
dao.create(bucketThatShouldNotBeDeleted);
|
||||
|
||||
dao.deleteEmptyBucketsUpToTime(
|
||||
bucketThatShouldNotBeDeleted.getBucketStartTime(),
|
||||
bucketThatShouldNotBeDeleted.getNetwork());
|
||||
|
||||
assertThat(dao.getByStartTime(
|
||||
bucketThatShouldNotBeDeleted.getBucketStartTime(),
|
||||
bucketThatShouldNotBeDeleted.getNetwork()), is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteEmptyBucketsUpToTimeDoesNotRemoveEmptyBucketsAfterTime()
|
||||
throws DataAccessLayerException {
|
||||
final BandwidthBucket bucketThatShouldNotBeDeleted = new BandwidthBucket(
|
||||
4L, 100, Network.OPSNET);
|
||||
bucketThatShouldNotBeDeleted.setCurrentSize(100L);
|
||||
|
||||
dao.create(bucketThatShouldNotBeDeleted);
|
||||
|
||||
dao.deleteEmptyBucketsUpToTime(
|
||||
bucketThatShouldNotBeDeleted.getBucketStartTime() - 1,
|
||||
bucketThatShouldNotBeDeleted.getNetwork());
|
||||
|
||||
assertThat(dao.getByStartTime(
|
||||
bucketThatShouldNotBeDeleted.getBucketStartTime(),
|
||||
bucketThatShouldNotBeDeleted.getNetwork()), is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllForNetworkReturnsAllBucketsInNetwork() {
|
||||
Network network = Network.OPSNET;
|
||||
List<BandwidthBucket> bucketsThatShouldBeFound = Arrays.asList(
|
||||
new BandwidthBucket(1L, 100, network), new BandwidthBucket(2L,
|
||||
100, network), new BandwidthBucket(3L, 100, network));
|
||||
|
||||
for (BandwidthBucket bucket : bucketsThatShouldBeFound) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
final List<BandwidthBucket> allForNetwork = dao.getAll(network);
|
||||
|
||||
assertThat(allForNetwork, is(equalTo(bucketsThatShouldBeFound)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllForNetworkDoesNotReturnBucketsNotInNetwork() {
|
||||
Network network = Network.OPSNET;
|
||||
List<BandwidthBucket> bucketsThatShouldNotBeFound = Arrays.asList(
|
||||
new BandwidthBucket(1L, 100, network), new BandwidthBucket(2L,
|
||||
100, network), new BandwidthBucket(3L, 100, network));
|
||||
|
||||
for (BandwidthBucket bucket : bucketsThatShouldNotBeFound) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
final List<BandwidthBucket> allForNetwork = dao.getAll(Network.SBN);
|
||||
|
||||
assertThat(allForNetwork, is(empty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLastBucketForNetworkReturnsLastBucket() {
|
||||
Network network = Network.OPSNET;
|
||||
final BandwidthBucket lastBucket = new BandwidthBucket(3L, 100, network);
|
||||
final List<BandwidthBucket> bucketsForNetwork = Arrays.asList(
|
||||
new BandwidthBucket(1L, 100, network), new BandwidthBucket(2L,
|
||||
100, network), lastBucket);
|
||||
|
||||
for (BandwidthBucket bucket : bucketsForNetwork) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
assertThat(dao.getLastBucket(network), is(equalTo(lastBucket)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhereStartTimeIsLessThanOrEqualToReturnsAllBucketsBeforeGivenTime() {
|
||||
final Network network = Network.OPSNET;
|
||||
List<BandwidthBucket> expectedBuckets = Arrays.asList(
|
||||
new BandwidthBucket(1L, 100, network), new BandwidthBucket(2L,
|
||||
100, network), new BandwidthBucket(3L, 100, network));
|
||||
for (BandwidthBucket bucket : expectedBuckets) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
final List<BandwidthBucket> returned = dao
|
||||
.getWhereStartTimeIsLessThanOrEqualTo(4L, network);
|
||||
|
||||
assertThat(returned, is(equalTo(expectedBuckets)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhereStartTimeIsLessThanOrEqualToReturnsBucketAtGivenTime() {
|
||||
|
||||
final Network network = Network.OPSNET;
|
||||
final BandwidthBucket bucketWithEqualStartTime = new BandwidthBucket(
|
||||
3L, 100, network);
|
||||
List<BandwidthBucket> buckets = Arrays.asList(new BandwidthBucket(1L,
|
||||
100, network), new BandwidthBucket(2L, 100, network),
|
||||
bucketWithEqualStartTime);
|
||||
|
||||
for (BandwidthBucket bucket : buckets) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
final List<BandwidthBucket> returned = dao
|
||||
.getWhereStartTimeIsLessThanOrEqualTo(
|
||||
bucketWithEqualStartTime.getBucketStartTime(),
|
||||
bucketWithEqualStartTime.getNetwork());
|
||||
|
||||
assertThat(returned.contains(bucketWithEqualStartTime), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWhereStartTimeIsLessThanOrEqualToDoesNotReturnBucketAfterGivenTime() {
|
||||
final Network network = Network.OPSNET;
|
||||
final BandwidthBucket bucketWithLaterStartTime = new BandwidthBucket(
|
||||
3L, 100, network);
|
||||
List<BandwidthBucket> buckets = Arrays.asList(new BandwidthBucket(1L,
|
||||
100, network), new BandwidthBucket(2L, 100, network),
|
||||
bucketWithLaterStartTime);
|
||||
|
||||
for (BandwidthBucket bucket : buckets) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
final List<BandwidthBucket> returned = dao
|
||||
.getWhereStartTimeIsLessThanOrEqualTo(2L, network);
|
||||
|
||||
assertThat(returned, not(hasItem(bucketWithLaterStartTime)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstBucketForNetworkReturnsFirstBucket() {
|
||||
Network network = Network.OPSNET;
|
||||
final BandwidthBucket firstBucket = new BandwidthBucket(1L, 100,
|
||||
network);
|
||||
final List<BandwidthBucket> bucketsForNetwork = Arrays.asList(
|
||||
firstBucket, new BandwidthBucket(2L, 100, network),
|
||||
new BandwidthBucket(3L, 100, network));
|
||||
|
||||
for (BandwidthBucket bucket : bucketsForNetwork) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
assertThat(dao.getFirstBucket(network), is(equalTo(firstBucket)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getByStartTimeReturnsBucketWithGivenStartTime() {
|
||||
BandwidthBucket bucket = new BandwidthBucket(1L, 100, Network.OPSNET);
|
||||
BandwidthBucket bucket2 = new BandwidthBucket(1L, 100, Network.SBN);
|
||||
|
||||
dao.create(bucket);
|
||||
dao.create(bucket2);
|
||||
|
||||
assertThat(
|
||||
"Should have been able to retrieve the bucket by its start time after creating it!",
|
||||
dao.getByStartTime(bucket2.getBucketStartTime(),
|
||||
bucket2.getNetwork()), is(equalTo(bucket2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBucketsInWindowsReturnsBucketsBetweenTimes() {
|
||||
|
||||
final Network network = Network.OPSNET;
|
||||
|
||||
List<BandwidthBucket> tooEarlyBuckets = Arrays.asList(
|
||||
new BandwidthBucket(1L, 100, network), new BandwidthBucket(2L,
|
||||
100, network), new BandwidthBucket(3L, 100, network));
|
||||
|
||||
// Leaving 4L open as a boundary range
|
||||
List<BandwidthBucket> expectedBuckets = Arrays.asList(
|
||||
new BandwidthBucket(5L, 100, network), new BandwidthBucket(6L,
|
||||
100, network), new BandwidthBucket(7L, 100, network));
|
||||
|
||||
// Leaving 8L open as a boundary range
|
||||
List<BandwidthBucket> tooLateBuckets = Arrays.asList(
|
||||
new BandwidthBucket(9L, 100, network), new BandwidthBucket(10L,
|
||||
100, network), new BandwidthBucket(11L, 100, network));
|
||||
|
||||
for (BandwidthBucket bucket : tooEarlyBuckets) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
for (BandwidthBucket bucket : expectedBuckets) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
for (BandwidthBucket bucket : tooLateBuckets) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
final SortedSet<BandwidthBucket> returned = dao.getBucketsInWindow(4L,
|
||||
8L, network);
|
||||
|
||||
// Implicitly checks that buckets earlier than the start time and later
|
||||
// than the end time are excluded
|
||||
assertThat(new ArrayList<BandwidthBucket>(returned),
|
||||
is(equalTo(expectedBuckets)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBucketsInWindowsReturnsBucketAtStartTime() {
|
||||
final Network network = Network.OPSNET;
|
||||
|
||||
final BandwidthBucket earliestBucket = new BandwidthBucket(4L, 100,
|
||||
network);
|
||||
List<BandwidthBucket> buckets = Arrays.asList(earliestBucket,
|
||||
new BandwidthBucket(5L, 100, network), new BandwidthBucket(6L,
|
||||
100, network));
|
||||
|
||||
for (BandwidthBucket bucket : buckets) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
final SortedSet<BandwidthBucket> returned = dao.getBucketsInWindow(
|
||||
earliestBucket.getBucketStartTime(), 8L, network);
|
||||
|
||||
assertThat(returned, hasItem(earliestBucket));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBucketsInWindowsReturnsBucketAtEndTime() {
|
||||
|
||||
final Network network = Network.OPSNET;
|
||||
|
||||
final BandwidthBucket latestBucket = new BandwidthBucket(6L, 100,
|
||||
network);
|
||||
List<BandwidthBucket> buckets = Arrays.asList(new BandwidthBucket(4L,
|
||||
100, network), new BandwidthBucket(5L, 100, network),
|
||||
latestBucket);
|
||||
|
||||
for (BandwidthBucket bucket : buckets) {
|
||||
dao.create(bucket);
|
||||
}
|
||||
|
||||
final SortedSet<BandwidthBucket> returned = dao.getBucketsInWindow(3L,
|
||||
latestBucket.getBucketStartTime(), network);
|
||||
|
||||
assertThat(returned, hasItem(latestBucket));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyStateCopiesAllBuckets() {
|
||||
|
||||
InMemoryBandwidthBucketDao daoToCopyFrom = new InMemoryBandwidthBucketDao();
|
||||
|
||||
List<BandwidthBucket> opsnetBuckets = Arrays.asList(
|
||||
new BandwidthBucket(4L, 100, Network.OPSNET),
|
||||
new BandwidthBucket(5L, 100, Network.OPSNET),
|
||||
new BandwidthBucket(6L, 100, Network.OPSNET));
|
||||
List<BandwidthBucket> sbnBuckets = Arrays.asList(new BandwidthBucket(
|
||||
4L, 100, Network.SBN),
|
||||
new BandwidthBucket(5L, 100, Network.SBN), new BandwidthBucket(
|
||||
6L, 100, Network.SBN));
|
||||
|
||||
// Persist all buckets to the source dao
|
||||
for (BandwidthBucket bucket : opsnetBuckets) {
|
||||
daoToCopyFrom.create(bucket);
|
||||
}
|
||||
for (BandwidthBucket bucket : sbnBuckets) {
|
||||
daoToCopyFrom.create(bucket);
|
||||
}
|
||||
|
||||
dao.copyState(daoToCopyFrom);
|
||||
|
||||
assertThat(dao.getAll(Network.OPSNET), is(equalTo(opsnetBuckets)));
|
||||
assertThat(dao.getAll(Network.SBN), is(equalTo(sbnBuckets)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the implementation of {@link IBandwidthBucketDao} that is under
|
||||
* test.
|
||||
*
|
||||
* @return the implementation
|
||||
*/
|
||||
protected abstract IBandwidthBucketDao getBandwidthBucketDao();
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* 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.dao.IBandwidthBucketDao;
|
||||
|
||||
/**
|
||||
* Test {@link InMemoryBandwidthBucketDao}.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 19, 2013 2106 djohnson Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
public class InMemoryBandwidthBucketDaoTest extends
|
||||
AbstractBandwidthBucketDaoTest {
|
||||
|
||||
@Override
|
||||
protected IBandwidthBucketDao getBandwidthBucketDao() {
|
||||
return new InMemoryBandwidthBucketDao();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
/**
|
||||
* 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 org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.TransactionConfiguration;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.raytheon.uf.common.util.SpringFiles;
|
||||
import com.raytheon.uf.common.util.TestUtil;
|
||||
import com.raytheon.uf.edex.database.DataAccessLayerException;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.AbstractBandwidthBucketDaoTest;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthBucketDao;
|
||||
|
||||
/**
|
||||
* Test {@link BandwidthBucketDao}.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 19, 2013 2106 djohnson Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { SpringFiles.UNIT_TEST_DB_BEANS_XML,
|
||||
"bandwidthBucketDaoTest.xml" })
|
||||
@TransactionConfiguration(transactionManager = TestUtil.METADATA_TX_MANAGER, defaultRollback = true)
|
||||
@Transactional
|
||||
public class BandwidthBucketDaoTest extends AbstractBandwidthBucketDaoTest {
|
||||
|
||||
@Autowired
|
||||
private BandwidthBucketDao hibernateDao;
|
||||
|
||||
// Not sure why, but the transaction is not picked up unless I override all
|
||||
// of the superclass test methods. I wish I didn't have to, but here we
|
||||
// are....
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void createdBandwidthBucketIsRetrievable() {
|
||||
super.createdBandwidthBucketIsRetrievable();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void bandwidthBucketIsUpdatable() {
|
||||
super.bandwidthBucketIsUpdatable();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void deleteEmptyBucketsUpToTimeRemovesEmptyBucketsBeforeTime()
|
||||
throws DataAccessLayerException {
|
||||
super.deleteEmptyBucketsUpToTimeRemovesEmptyBucketsBeforeTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void deleteEmptyBucketsUpToTimeRemovesEmptyBucketAtTime()
|
||||
throws DataAccessLayerException {
|
||||
super.deleteEmptyBucketsUpToTimeRemovesEmptyBucketAtTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void deleteEmptyBucketsUpToTimeDoesNotRemoveNonEmptyBucketsBeforeTime()
|
||||
throws DataAccessLayerException {
|
||||
super.deleteEmptyBucketsUpToTimeDoesNotRemoveNonEmptyBucketsBeforeTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void deleteEmptyBucketsUpToTimeDoesNotRemoveNonEmptyBucketsAtTime()
|
||||
throws DataAccessLayerException {
|
||||
super.deleteEmptyBucketsUpToTimeDoesNotRemoveNonEmptyBucketsAtTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void deleteEmptyBucketsUpToTimeDoesNotRemoveEmptyBucketsAfterTime()
|
||||
throws DataAccessLayerException {
|
||||
super.deleteEmptyBucketsUpToTimeDoesNotRemoveEmptyBucketsAfterTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getAllForNetworkReturnsAllBucketsInNetwork() {
|
||||
super.getAllForNetworkReturnsAllBucketsInNetwork();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getAllForNetworkDoesNotReturnBucketsNotInNetwork() {
|
||||
super.getAllForNetworkDoesNotReturnBucketsNotInNetwork();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getLastBucketForNetworkReturnsLastBucket() {
|
||||
super.getLastBucketForNetworkReturnsLastBucket();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getWhereStartTimeIsLessThanOrEqualToReturnsAllBucketsBeforeGivenTime() {
|
||||
super.getWhereStartTimeIsLessThanOrEqualToReturnsAllBucketsBeforeGivenTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getWhereStartTimeIsLessThanOrEqualToReturnsBucketAtGivenTime() {
|
||||
super.getWhereStartTimeIsLessThanOrEqualToReturnsBucketAtGivenTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getWhereStartTimeIsLessThanOrEqualToDoesNotReturnBucketAfterGivenTime() {
|
||||
super.getWhereStartTimeIsLessThanOrEqualToDoesNotReturnBucketAfterGivenTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getFirstBucketForNetworkReturnsFirstBucket() {
|
||||
super.getFirstBucketForNetworkReturnsFirstBucket();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getByStartTimeReturnsBucketWithGivenStartTime() {
|
||||
super.getByStartTimeReturnsBucketWithGivenStartTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getBucketsInWindowsReturnsBucketsBetweenTimes() {
|
||||
super.getBucketsInWindowsReturnsBucketsBetweenTimes();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getBucketsInWindowsReturnsBucketAtStartTime() {
|
||||
super.getBucketsInWindowsReturnsBucketAtStartTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void getBucketsInWindowsReturnsBucketAtEndTime() {
|
||||
super.getBucketsInWindowsReturnsBucketAtEndTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void copyStateCopiesAllBuckets() {
|
||||
super.copyStateCopiesAllBuckets();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBandwidthBucketDao getBandwidthBucketDao() {
|
||||
return hibernateDao;
|
||||
}
|
||||
}
|
|
@ -26,10 +26,11 @@ 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.SiteSubscriptionFixture;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Subscription;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.IBandwidthManager;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalManager;
|
||||
|
||||
/**
|
||||
* Test {@link HibernateBandwidthInitializer}.
|
||||
|
@ -42,6 +43,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDbInit;
|
|||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 18, 2013 1543 djohnson Initial creation
|
||||
* Apr 18, 2013 1914 djohnson Fix broken test.
|
||||
* Jun 25, 2013 2106 djohnson init() now takes a {@link RetrievalManager}.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -58,12 +60,13 @@ public class HibernateBandwidthInitializerTest {
|
|||
IFindSubscriptionsForScheduling strategy = mock(IFindSubscriptionsForScheduling.class);
|
||||
when(strategy.findSubscriptionsToSchedule()).thenReturn(
|
||||
Sets.newHashSet(subscription));
|
||||
|
||||
IBandwidthManager bandwidthManager = mock(IBandwidthManager.class);
|
||||
IBandwidthDbInit dbInit = mock(IBandwidthDbInit.class);
|
||||
|
||||
final HibernateBandwidthInitializer initializer = new HibernateBandwidthInitializer(strategy);
|
||||
initializer.init(bandwidthManager,
|
||||
dbInit);
|
||||
initializer
|
||||
.init(bandwidthManager, dbInit, mock(RetrievalManager.class));
|
||||
initializer.executeAfterRegistryInit();
|
||||
|
||||
verify(bandwidthManager).schedule(subscription);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
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.xsd">
|
||||
|
||||
<bean class="com.raytheon.uf.edex.datadelivery.bandwidth.hibernate.BandwidthBucketDao">
|
||||
<property name="sessionFactory" ref="metadataSessionFactory" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -56,10 +56,12 @@ import com.raytheon.uf.common.localization.PathManagerFactory;
|
|||
import com.raytheon.uf.common.localization.PathManagerFactoryTest;
|
||||
import com.raytheon.uf.common.time.util.TimeUtil;
|
||||
import com.raytheon.uf.common.time.util.TimeUtilTest;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.InMemoryBandwidthBucketDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthAllocation;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.BandwidthSubscription;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.dao.IBandwidthDao;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.BandwidthMap;
|
||||
import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.InMemoryBandwidthBucketAllocationAssociator;
|
||||
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.retrieval.RetrievalStatus;
|
||||
|
@ -77,6 +79,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalStatus;
|
|||
* Feb 07, 2013 1543 djohnson Remove unnecessary test setup methods.
|
||||
* Feb 14, 2013 1595 djohnson Fix retrieval plan/subscription time intersections.
|
||||
* Jun 05, 2013 2038 djohnson Use public API for getting retrieval times.
|
||||
* Jun 25, 2013 2106 djohnson RetrievalPlan uses setters instead of constructor injection now.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -116,12 +119,26 @@ public class BandwidthDaoUtilTest {
|
|||
"datadelivery/bandwidthmap.xml");
|
||||
|
||||
map = BandwidthMap.load(lf.getFile());
|
||||
plan = new RetrievalPlan(Network.OPSNET, map, mockDao);
|
||||
final InMemoryBandwidthBucketDao bucketsDao = new InMemoryBandwidthBucketDao();
|
||||
plan = new RetrievalPlan();
|
||||
plan.setNetwork(Network.OPSNET);
|
||||
plan.setMap(map);
|
||||
plan.setBandwidthDao(mockDao);
|
||||
plan.setBucketsDao(bucketsDao);
|
||||
plan.setAssociator(new InMemoryBandwidthBucketAllocationAssociator(
|
||||
mockDao, bucketsDao));
|
||||
|
||||
Map<Network, RetrievalPlan> retrievalPlans = Maps
|
||||
.newEnumMap(Network.class);
|
||||
retrievalPlans.put(Network.OPSNET, plan);
|
||||
when(retrievalManager.getRetrievalPlans()).thenReturn(retrievalPlans);
|
||||
|
||||
// Just used to initialize the retrieval plans that are used on the mock
|
||||
// retrieval manager
|
||||
final RetrievalManager tmpRetrievalManager = new RetrievalManager(
|
||||
mockDao, new Object());
|
||||
tmpRetrievalManager.setRetrievalPlans(retrievalPlans);
|
||||
tmpRetrievalManager.initRetrievalPlans();
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -260,8 +277,8 @@ public class BandwidthDaoUtilTest {
|
|||
assertThat(numberOfZeroMinuteTimes, is(equalTo(halfTheTimes + 1)));
|
||||
assertThat(numberOfThirtyMinuteTimes, is(equalTo(halfTheTimes)));
|
||||
|
||||
// Would be nice to verify the days and hours, but the cycle based tests already
|
||||
// do that and the code was reused, maybe add it later
|
||||
// Would be nice to verify the days and hours, but the cycle based tests
|
||||
// already do that and the code was reused, maybe add it later
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue