Issue #2397 Added Bandwidth Bucket usage information to BandwidthGraphData.

Change-Id: I13a859ebc341ad9d1aaf9a31e94cf4783df761ce

Former-commit-id: c7389871fca42adf4cb3ec1c37e0fdffd56f2a43
This commit is contained in:
Brad Gonzales 2013-09-23 12:44:48 -05:00
parent ae3a827130
commit bb27130374
4 changed files with 230 additions and 1 deletions

View file

@ -0,0 +1,157 @@
/**
* 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.datadelivery.bandwidth.data;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
/**
* Describes a bucket, especially the total bytes available and bytes used. Used
* by the UI to display information about buckets. Comparable by startime and
* bucketSize
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 20, 2013 2397 bgonzale Initial creation
*
* </pre>
*
* @author bgonzale
* @version 1.0
*/
@DynamicSerialize
public class BandwidthBucketDescription implements
Comparable<BandwidthBucketDescription> {
@DynamicSerializeElement
private Network network;
// Number of bytes of bandwidth;
@DynamicSerializeElement
private long bucketSize;
// Number of allocated bytes
@DynamicSerializeElement
private long usedBytes;
@DynamicSerializeElement
private long bucketStartTime;
/**
* Default Constructor.
*/
public BandwidthBucketDescription() {
}
/**
* Initialize all fields Constructor.
*
* @param network
* @param bucketSize
* @param usedBytes
* @param bucketStartTime
*/
public BandwidthBucketDescription(Network network, long bucketSize,
long usedBytes, long bucketStartTime) {
this.network = network;
this.bucketSize = bucketSize;
this.usedBytes = usedBytes;
this.bucketStartTime = bucketStartTime;
}
/**
* Compare by bucket start time. If bucket start times are equal, then
* compare by bucket size.
*/
@Override
public int compareTo(BandwidthBucketDescription o) {
long compStart = this.bucketStartTime - o.getBucketStartTime();
int retval = (int) (compStart == 0 ? this.bucketSize - o.bucketSize
: compStart);
return retval;
}
/**
* @return the network
*/
public Network getNetwork() {
return network;
}
/**
* @param network
* the network to set
*/
public void setNetwork(Network network) {
this.network = network;
}
/**
* @return the bucketSize
*/
public long getBucketSize() {
return bucketSize;
}
/**
* @param bucketSize
* the bucketSize to set
*/
public void setBucketSize(long bucketSize) {
this.bucketSize = bucketSize;
}
/**
* @return the usedBytes
*/
public long getUsedBytes() {
return usedBytes;
}
/**
* @param usedBytes
* the usedBytes to set
*/
public void setUsedBytes(long usedBytes) {
this.usedBytes = usedBytes;
}
/**
* @return the bucketStartTime
*/
public long getBucketStartTime() {
return bucketStartTime;
}
/**
* @param bucketStartTime
* the bucketStartTime to set
*/
public void setBucketStartTime(long bucketStartTime) {
this.bucketStartTime = bucketStartTime;
}
}

View file

@ -20,13 +20,17 @@
package com.raytheon.uf.common.datadelivery.bandwidth.data;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
@ -43,6 +47,7 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* Nov 25, 2012 1269 lvenable Initial creation.
* Dec 06, 2012 1397 djohnson Add dynamic serialize class annotation.
* Jan 25, 2013 1528 djohnson Subscription priority is now an enum.
* Sep 20, 2013 2397 bgonzale Added Map of Bucket Descriptions.
*
* </pre>
*
@ -59,6 +64,10 @@ public class BandwidthGraphData {
@DynamicSerializeElement
private Map<String, SubscriptionPriority> priorityMap;
/** Network -> Bandwidth Bucket Descriptions */
@DynamicSerializeElement
private Map<Network, SortedSet<BandwidthBucketDescription>> networkBucketMap;
/** Bin duration in minutes */
@DynamicSerializeElement
private int binTimeInMins;
@ -116,6 +125,36 @@ public class BandwidthGraphData {
this.priorityMap = priorityMap;
}
/**
* @return the networkBucketMap
*/
public Map<Network, SortedSet<BandwidthBucketDescription>> getNetworkBucketMap() {
return networkBucketMap;
}
/**
* @param networkBucketMap
* the networkBucketMap to set
*/
public void setNetworkBucketMap(
Map<Network, SortedSet<BandwidthBucketDescription>> networkBucketMap) {
/*
* Ensure bucket description set sorting. This is done like this because
* the thrift version we are using is recreating the SortedSet as a
* HashSet on deserialization and causing
* getNetworkBucketMap().get(Network) to throw
* "java.lang.ClassCastException: java.util.HashSet cannot be cast to java.util.SortedSet"
*/
this.networkBucketMap = new HashMap<Network, SortedSet<BandwidthBucketDescription>>();
for (Entry<Network, SortedSet<BandwidthBucketDescription>> descEntry : networkBucketMap
.entrySet()) {
this.networkBucketMap.put(descEntry.getKey(),
new TreeSet<BandwidthBucketDescription>(
(Collection<BandwidthBucketDescription>) descEntry
.getValue()));
}
}
/**
* @return the binTimeInMins
*/

View file

@ -26,11 +26,14 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedSet;
import java.util.TreeSet;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthBucketDescription;
import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthGraphData;
import com.raytheon.uf.common.datadelivery.bandwidth.data.TimeWindowData;
import com.raytheon.uf.common.datadelivery.registry.Network;
import com.raytheon.uf.common.datadelivery.registry.Subscription.SubscriptionPriority;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
@ -57,6 +60,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.retrieval.RetrievalPlan;
* Jan 25, 2013 1528 djohnson Subscription priority is now an enum.
* Jun 24, 2013 2106 djohnson Access bucket allocations through RetrievalPlan.
* Jul 11, 2013 2106 djohnson Use priority straight from the BandwidthSubscription.
* Sep 20, 2013 2397 bgonzale Add Map of Bucket Descriptions to BandwidthGraphData.
*
* </pre>
*
@ -103,6 +107,7 @@ class BandwidthGraphDataAdapter {
.create();
Multimap<String, SubscriptionRetrieval> subNameToRetrievals = ArrayListMultimap
.create();
Map<Network, SortedSet<BandwidthBucketDescription>> networkBucketMap = new HashMap<Network, SortedSet<BandwidthBucketDescription>>();
Collection<RetrievalPlan> retrievalPlans = retrievalManager
.getRetrievalPlans().values();
@ -113,6 +118,8 @@ class BandwidthGraphDataAdapter {
.getBucketsInWindow(TimeUtil.currentTimeMillis(),
Long.MAX_VALUE);
networkBucketMap.put(retrievalPlan.getNetwork(),
toDescriptions(bandwidthBuckets));
// Add all subscription retrievals to a collection keyed by sub
// name, and associate all of the bandwidth reservations with their
// associated retrievals
@ -170,8 +177,24 @@ class BandwidthGraphDataAdapter {
bandwidthGraphData.setDataMap(dataMap);
bandwidthGraphData.setPriorityMap(priorityMap);
bandwidthGraphData.setNetworkBucketMap(networkBucketMap);
return bandwidthGraphData;
}
/*
* Return BandwithBucketDescription objects for the given BandwidthBuckets.
*/
private SortedSet<BandwidthBucketDescription> toDescriptions(
SortedSet<BandwidthBucket> bandwidthBuckets) {
SortedSet<BandwidthBucketDescription> descriptions = new TreeSet<BandwidthBucketDescription>();
for (BandwidthBucket bucket : bandwidthBuckets) {
BandwidthBucketDescription desc = new BandwidthBucketDescription(
bucket.getNetwork(), bucket.getBucketSize(),
bucket.getCurrentSize(), bucket.getBucketStartTime());
descriptions.add(desc);
}
return descriptions;
}
}

View file

@ -42,6 +42,7 @@ import com.raytheon.uf.common.datadelivery.bandwidth.BandwidthService;
import com.raytheon.uf.common.datadelivery.bandwidth.IBandwidthRequest;
import com.raytheon.uf.common.datadelivery.bandwidth.IProposeScheduleResponse;
import com.raytheon.uf.common.datadelivery.bandwidth.WfoBandwidthService;
import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthBucketDescription;
import com.raytheon.uf.common.datadelivery.bandwidth.data.BandwidthGraphData;
import com.raytheon.uf.common.datadelivery.bandwidth.data.SubscriptionStatusSummary;
import com.raytheon.uf.common.datadelivery.bandwidth.data.TimeWindowData;
@ -59,6 +60,7 @@ 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;
import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil;
/**
@ -529,10 +531,18 @@ public class BandwidthServiceIntTest extends AbstractWfoBandwidthManagerIntTest
service.schedule(subscription2);
BandwidthGraphData graphData = service.getBandwidthGraphData();
RetrievalPlan opsnetPlan = retrievalManager.getPlan(Network.OPSNET);
assertEquals("Incorrect number of subscriptions returned!",
retrievalManager.getPlan(Network.OPSNET).getBucketMinutes(),
opsnetPlan.getBucketMinutes(),
graphData.getBinTimeInMinutes());
SortedSet<BandwidthBucketDescription> descs = graphData
.getNetworkBucketMap().get(Network.OPSNET);
long earliestTime = descs.first().getBucketStartTime();
long latestTime = descs.last().getBucketStartTime();
assertEquals("Incorrect number of buckets returned", opsnetPlan
.getBucketsInWindow(earliestTime, latestTime).size(),
descs.size());
}
@Test