Merge "Issue #2810 Added comparator to BandwidthAllocations Change-Id: I4320d1d5b00bdf69c0969a349ae249090a389b85" into development

Former-commit-id: 4ba272b071 [formerly 7acdf727ce] [formerly 545203a833] [formerly 4ba272b071 [formerly 7acdf727ce] [formerly 545203a833] [formerly 7093d6ff0e [formerly 545203a833 [formerly 79f857137cdc4bba40c3d6804c72dab8a4fe6ae0]]]]
Former-commit-id: 7093d6ff0e
Former-commit-id: e7cc3044e7 [formerly b3dd0a933c] [formerly c343754cdf22b2f328978110a7fef5d5ee9e7d8b [formerly dc429091da]]
Former-commit-id: 0464101d9194c2a1dfd91fc37f920f04e8dde8ce [formerly ecc9eb5268]
Former-commit-id: 21b77c1310
This commit is contained in:
Richard Peter 2014-04-04 14:39:46 -05:00 committed by Gerrit Code Review
commit 0fc963bbc8
6 changed files with 53 additions and 25 deletions

View file

@ -70,6 +70,7 @@ import com.raytheon.uf.common.time.util.TimeUtil;
* to check day of year. removed now unused active period methods. * to check day of year. removed now unused active period methods.
* Jan 28, 2014 2636 mpduff Changed to use GMT calendar. * Jan 28, 2014 2636 mpduff Changed to use GMT calendar.
* Feb 12, 2014 2636 mpduff Return new instance of calculated start and end. * Feb 12, 2014 2636 mpduff Return new instance of calculated start and end.
* Apr 02, 2014 2810 dhladky Priority sorting of subscriptions.
* *
* </pre> * </pre>
* *
@ -81,7 +82,7 @@ import com.raytheon.uf.common.time.util.TimeUtil;
AdhocSubscription.class, SiteSubscription.class, AdhocSubscription.class, SiteSubscription.class,
SharedSubscription.class }) SharedSubscription.class })
public abstract class RecurringSubscription<T extends Time, C extends Coverage> public abstract class RecurringSubscription<T extends Time, C extends Coverage>
implements Serializable, Subscription<T, C> { implements Serializable, Subscription<T, C>, Comparable<Subscription<T, C>> {
private static final long serialVersionUID = -6422673887457060034L; private static final long serialVersionUID = -6422673887457060034L;
@ -1111,4 +1112,13 @@ public abstract class RecurringSubscription<T extends Time, C extends Coverage>
public boolean shouldUpdate() { public boolean shouldUpdate() {
return shouldUpdate; return shouldUpdate;
} }
@Override
public int compareTo(Subscription<T, C> o) {
SubscriptionPriority oPriority = o.getPriority();
SubscriptionPriority myPriority = this.getPriority();
return myPriority.compareTo(oPriority);
}
} }

View file

@ -49,6 +49,7 @@ import com.raytheon.uf.common.datadelivery.registry.Utils.SubscriptionStatus;
* Jan 14, 2014 2459 mpduff Change Subscription status code * Jan 14, 2014 2459 mpduff Change Subscription status code
* Jan 24, 2013 2709 bgonzale Added method inActivePeriodWindow. * Jan 24, 2013 2709 bgonzale Added method inActivePeriodWindow.
* Feb 05, 2014 2677 mpduff Add subscription state getter/setter. * Feb 05, 2014 2677 mpduff Add subscription state getter/setter.
* Apr 02, 2014 2810 dhladky Priority sorting of subscriptions.
* *
* </pre> * </pre>
* *
@ -56,7 +57,7 @@ import com.raytheon.uf.common.datadelivery.registry.Utils.SubscriptionStatus;
* @version 1.0 * @version 1.0
*/ */
public interface Subscription<T extends Time, C extends Coverage> { public interface Subscription<T extends Time, C extends Coverage> extends Comparable<Subscription<T, C>> {
@XmlEnum @XmlEnum
public enum SubscriptionType { public enum SubscriptionType {
@ -78,7 +79,15 @@ public interface Subscription<T extends Time, C extends Coverage> {
/** Enumeration to use for subscription priorities */ /** Enumeration to use for subscription priorities */
@XmlEnum @XmlEnum
public static enum SubscriptionPriority { public static enum SubscriptionPriority implements Comparable<SubscriptionPriority>{
/*
These are in the order in which priorities would
appear for comparator purposes. BE SURE that
if you add any new state enum it is inserted in the order
you wish it to be in for logical ordering in comparison to others.
*/
/** High Priority */ /** High Priority */
@XmlEnumValue("High") @XmlEnumValue("High")
HIGH("High", 1), HIGH("High", 1),

View file

@ -147,6 +147,7 @@ import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException;
* of already scheduled BandwidthAllocations. * of already scheduled BandwidthAllocations.
* Feb 11, 2014 2771 bgonzale Added handler for GET_DATADELIVERY_ID request. * Feb 11, 2014 2771 bgonzale Added handler for GET_DATADELIVERY_ID request.
* Feb 10, 2014 2636 mpduff Changed how retrieval plan is updated over time. * Feb 10, 2014 2636 mpduff Changed how retrieval plan is updated over time.
* Apr 02, 2014 2810 dhladky Priority sorting of subscriptions.
* *
* </pre> * </pre>
* *
@ -1132,13 +1133,18 @@ public abstract class BandwidthManager<T extends Time, C extends Coverage>
* @throws SerializationException * @throws SerializationException
*/ */
protected Set<String> scheduleSubscriptions( protected Set<String> scheduleSubscriptions(
List<Subscription<T, C>> subscriptions) List<Subscription<T, C>> insubscriptions)
throws SerializationException { throws SerializationException {
Set<String> unscheduledSubscriptions = new TreeSet<String>(); Set<String> unscheduledSubscriptions = new TreeSet<String>();
Set<BandwidthAllocation> unscheduledAllocations = new HashSet<BandwidthAllocation>(); Set<BandwidthAllocation> unscheduledAllocations = new HashSet<BandwidthAllocation>();
Map<String, SubscriptionRequestEvent> subscriptionEventsMap = new HashMap<String, SubscriptionRequestEvent>(); Map<String, SubscriptionRequestEvent> subscriptionEventsMap = new HashMap<String, SubscriptionRequestEvent>();
// Order list by Subscription Priority
// We want highest priority subscriptions scheduled first.
List<Subscription<T, C>> subscriptions = new ArrayList<Subscription<T,C>>(insubscriptions.size());
subscriptions.addAll(insubscriptions);
Collections.sort(subscriptions);
for (Subscription<T, C> subscription : subscriptions) { for (Subscription<T, C> subscription : subscriptions) {
List<BandwidthAllocation> unscheduled = subscriptionUpdated(subscription); List<BandwidthAllocation> unscheduled = subscriptionUpdated(subscription);

View file

@ -42,6 +42,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
* Jun 24, 2013 2106 djohnson Add copy constructor. * Jun 24, 2013 2106 djohnson Add copy constructor.
* Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum. * Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum.
* Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil.
* Apr 02, 2014 2810 dhladky Priority sorting of allocations.
* *
* </pre> * </pre>
* *
@ -56,7 +57,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
@DynamicSerialize @DynamicSerialize
@SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_seq", allocationSize = 1, initialValue = 1) @SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_seq", allocationSize = 1, initialValue = 1)
public class BandwidthAllocation implements IPersistableDataObject<Long>, public class BandwidthAllocation implements IPersistableDataObject<Long>,
Serializable, IDeepCopyable<BandwidthAllocation> { Serializable, IDeepCopyable<BandwidthAllocation>, Comparable<BandwidthAllocation> {
private static final long serialVersionUID = 743702044231376839L; private static final long serialVersionUID = 743702044231376839L;
@ -337,17 +338,6 @@ public class BandwidthAllocation implements IPersistableDataObject<Long>,
return sb.toString(); return sb.toString();
} }
/**
* Check whether this allocation is higher priority than another.
*
* @param other
* the other
* @return true if this allocation is higher priority than the other one
*/
public boolean isHigherPriorityThan(BandwidthAllocation other) {
return this.getPriority().isHigherPriorityThan(other.getPriority());
}
/** /**
* @return * @return
*/ */
@ -356,4 +346,13 @@ public class BandwidthAllocation implements IPersistableDataObject<Long>,
return new BandwidthAllocation(this); return new BandwidthAllocation(this);
} }
@Override
public int compareTo(BandwidthAllocation o) {
SubscriptionPriority oPriority = o.priority;
SubscriptionPriority myPriority = this.priority;
return myPriority.compareTo(oPriority);
}
} }

View file

@ -32,6 +32,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
* Jun 25, 2013 2106 djohnson Access bandwidth bucket contents through RetrievalPlan. * Jun 25, 2013 2106 djohnson Access bandwidth bucket contents through RetrievalPlan.
* Dec 17, 2013 2636 bgonzale When adding to buckets, call the constrained method. * Dec 17, 2013 2636 bgonzale When adding to buckets, call the constrained method.
* Feb 14, 2014 2636 mpduff Clean up logging. * Feb 14, 2014 2636 mpduff Clean up logging.
* Apr 02, 2014 2810 dhladky Priority sorting of allocations.
* </pre> * </pre>
* *
* @version 1.0 * @version 1.0
@ -184,14 +185,11 @@ public class PriorityRetrievalScheduler implements IRetrievalScheduler {
for (BandwidthAllocation o : plan for (BandwidthAllocation o : plan
.getBandwidthAllocationsForBucket(bucket)) { .getBandwidthAllocationsForBucket(bucket)) {
long estimatedSizeInBytes = o.getEstimatedSizeInBytes(); long estimatedSizeInBytes = o.getEstimatedSizeInBytes();
// This was bad... we just about released giving lower
// priority requests the ability to unschedule higher priority if (request.compareTo(o) == 1) {
// requests....
if (request.isHigherPriorityThan(o)) {
total += estimatedSizeInBytes; total += estimatedSizeInBytes;
lowerPriorityRequests.add(o); lowerPriorityRequests.add(o);
} }
// See if we have found enough room // See if we have found enough room
if (total >= estimatedSizeInBytes) { if (total >= estimatedSizeInBytes) {
enoughBandwidth = true; enoughBandwidth = true;

View file

@ -9,6 +9,7 @@ import java.util.TreeMap;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.datadelivery.registry.Network; import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription;
import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.common.time.util.TimeUtil;
@ -41,6 +42,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalManagerNotifyEvent;
* Oct 03, 2013 2267 bgonzale Added check for no retrieval plan matching in the proposed retrieval plans. * Oct 03, 2013 2267 bgonzale Added check for no retrieval plan matching in the proposed retrieval plans.
* Jan 30, 2014 2686 dhladky refactor of retrieval. * Jan 30, 2014 2686 dhladky refactor of retrieval.
* Feb 10, 2014 2678 dhladky Prevent duplicate allocations. * Feb 10, 2014 2678 dhladky Prevent duplicate allocations.
* Apr 02, 2014 2810 dhladky Priority sorting of allocations.
* *
* </pre> * </pre>
* *
@ -87,8 +89,12 @@ public class RetrievalManager {
* scheduled * scheduled
*/ */
public <T extends BandwidthAllocation> List<BandwidthAllocation> schedule( public <T extends BandwidthAllocation> List<BandwidthAllocation> schedule(
List<T> bandwidthAllocations) { List<T> inallocations) {
List<BandwidthAllocation> unscheduled = new ArrayList<BandwidthAllocation>(); List<BandwidthAllocation> unscheduled = new ArrayList<BandwidthAllocation>();
// Arrange allocations in priority order
List<BandwidthAllocation> bandwidthAllocations = new ArrayList<BandwidthAllocation>(inallocations.size());
bandwidthAllocations.addAll(inallocations);
Collections.sort(bandwidthAllocations);
for (BandwidthAllocation bandwidthAllocation : bandwidthAllocations) { for (BandwidthAllocation bandwidthAllocation : bandwidthAllocations) {
Network network = bandwidthAllocation.getNetwork(); Network network = bandwidthAllocation.getNetwork();